From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F3C6C369DC for ; Thu, 1 May 2025 14:45:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF8636B008A; Thu, 1 May 2025 10:45:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA6346B008C; Thu, 1 May 2025 10:45:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96CA96B0092; Thu, 1 May 2025 10:45:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 776506B008A for ; Thu, 1 May 2025 10:45:45 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3475CC0B0B for ; Thu, 1 May 2025 14:45:46 +0000 (UTC) X-FDA: 83394613092.06.B20AB1A Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) by imf19.hostedemail.com (Postfix) with ESMTP id 1ED801A0018 for ; Thu, 1 May 2025 14:45:43 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hHbXWvbK; spf=pass (imf19.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.51 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1746110744; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=A/PNYkGGtPiw3g++R9ZmM8f1jEt69W6Oqakscd5WR2E=; b=46t0kJTXgHMbc7DHMNttSW3nmPQdFJkT/MIzK2j1MX3oW/xt6JjAMjhtA7pMu7cTVaE9+C PxWyR4n8Y8+b9v/ZDzBbOBi4vKwNJB2v5fvYFkajtqfwlayR5krnqiXQrFGYB6XX+Sa4eN jC4dxVTDqaN0O5PUg98OpO7V+7Dy6V8= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hHbXWvbK; spf=pass (imf19.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.51 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1746110744; a=rsa-sha256; cv=none; b=sPoJDBL2nTGNeQBpJbugOQGL3wIZPjOf8xkxd9AVnG1Fr9WdU8x6UGAIvXM8lRCV4uXabX nNSM+9jZapQTUGqfGTj9VyF31lciGBAIJRJIVKs69pgB4cbdhIFWmr11joa7/QID9TRBJo G1qaN9wmRU968QkElfCKbpvKxp1XUxA= Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-5f861d16622so1676516a12.2 for ; Thu, 01 May 2025 07:45:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746110742; x=1746715542; darn=kvack.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=A/PNYkGGtPiw3g++R9ZmM8f1jEt69W6Oqakscd5WR2E=; b=hHbXWvbKinWDsLG7SO7xObxDbkxfEWwnsaegRwJUih5X4wi2HUAr8T42o3pLzM5F5P A34p6n/vKTKmyvwAAv0cE5hkWZLrVxo7TyFfzsoTrkgXVhpgYyH8pC7GH9Jxa9yFXBK4 w6AdRFvYS+tDl/6hNA7CqtDGGsfgemrj8zb9PWBagTHCSg71gy4BjYebNyZs4YT2qoXj /rMJ+prbxpUz5oY0dJtTqWpzvveqNTOzb/QhlT0pfXmNOVJkyKDzIBgIVUUc4e594h78 +3UwWVf/aplCDB7ZCtNs3QEwemBBxjlmdvNPiE4rvAcsHC40nIoUrwGgk5UQhHyeXH1p Nxyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746110742; x=1746715542; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=A/PNYkGGtPiw3g++R9ZmM8f1jEt69W6Oqakscd5WR2E=; b=PG3UytcqX+EmkF0Gxk5phvhSke05lTS/VtGZCNeaChs8Hl7MbykBKa1UTbyHWPEGnL EXc6SgvtOZg94Uv8jKP8N+Y11GMOckBnGp9jl6OBAdugFP2wlMSwg3ZmRKMTMUgKYGJF 7UzisawIhsZM7BxBK3Gz4uZodBxEkMjZcsLSGE4dcWdceZLnJnwK4TcmZeoCbXdkPtD3 UpxyWgUpI5NSEqU6ebrXEkfli65j2t9v4iGbtbFWSoiFsvdi33HVGh3tLjI7NiYpIFhs vq8T7II/WWxAoFScuKIKSUZwBTKx+jPd7hPB4vfvvUnnaYjdPmSv6hsJs61PRM8waupl uUJA== X-Forwarded-Encrypted: i=1; AJvYcCVpSExJDPYwV4lRm8W5ERKkk2G0U/50K1kVZ13lM+EEJogSD5gxnNISj2K6C0UM368sJB7UCQSu0w==@kvack.org X-Gm-Message-State: AOJu0YxTjL7o0r9LIeGGjquTAxo5swlybhalQudYdnzBFsyHreQdnKSU AcD/XbsVNRCVnXZ7dtQ62UXvO9tnOp5CNvBNYr4OhctVB+6ewMGN X-Gm-Gg: ASbGncsC6tmCe3nQBRWurijUjAzfNStD/g0sxG/1KhCuA5Kh8D7k5bRspMBNsHzzgHO U/InEloGOfI+aqTJOwKZWInDL258tizPBdtqyEfg9u97xpUToQiU4cpuYAggOsEzzAHgIa8VBiY 930KTfrPt7tjBEYQHwFTBT1Kk6zjO5K7Z/KRtcQvX5i9GOmxO3m9HuVbjGEJday48+wxEWxLgMw wRtq3kec6E/c3wgjOMxEY55c+TezjHSs1TD22WFufytwCn9e9Ct/W3eeW0pOrtq0TEfGelSVpVm NYFDuf8saa+Lkxx4wuLcGU+VUciAUkgmx4M42Dq8 X-Google-Smtp-Source: AGHT+IEdLdKDP7OKtB/a/YGewCohp+/rqNcarTV24wBQ6ZwmiSwboNEpCHi1icKomylcpK83qnYMrw== X-Received: by 2002:a05:6402:50c7:b0:5f6:59e5:5c6e with SMTP id 4fb4d7f45d1cf-5f91350932dmr2748533a12.26.1746110742200; Thu, 01 May 2025 07:45:42 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5f92febcbe7sm518804a12.53.2025.05.01.07.45.41 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 May 2025 07:45:41 -0700 (PDT) Date: Thu, 1 May 2025 14:45:41 +0000 From: Wei Yang To: Lorenzo Stoakes Cc: Wei Yang , akpm@linux-foundation.org, david@redhat.com, riel@surriel.com, vbabka@suse.cz, harry.yoo@oracle.com, jannh@google.com, baohua@kernel.org, linux-mm@kvack.org Subject: Re: [RFC Patch 2/5] anon_vma: add skeleton code for userland testing of anon_vma logic Message-ID: <20250501144541.cd2q23y5sonypelx@master> Reply-To: Wei Yang References: <20250429090639.784-1-richard.weiyang@gmail.com> <20250429090639.784-3-richard.weiyang@gmail.com> <20250501013127.rzaos7co7b63so4r@master> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 1ED801A0018 X-Stat-Signature: gmepq9n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mPwY5gGOL4SAks++FCZx+67kb8M+5uwB9zS63B8dFl8I4plYcoBooSKJdKAB0DbYPSD2/ElFYjgPBGPH2Bbos+Y7e5S1i07Sn3r4bDv8mJVXgYZToq39ANwWrxeHzVm7fuLCIXB8vfXMdIyej4CXLfcMmSSx65dt/tbdwnVhH3PfFkplQFsxtY7u8Woq0UyyGmJN7YERkzL9OAdgMAzeLSD4exQj0q2utctHK8U2szZ4k7LPf2VS82MpX6CPwA8ztcTQu4IogLoGqEsnSGSFEx1tWttF4OtRPJKZW/HhzOVthQH7JJ7/LdiRoevchTe/QiaIgCU5mide99mGF40NShWMOGfAFLf9+umRF1wOojAGCgMi3zrgAsbZe/q4BrMWd+HqkDXQAVspIODAFP9AxbXqO8Mv2PT8ks636v5MlZy1915yF21iYcSW/Zldf59/nPDeRDE0pZgraNI+A7NltRHpXn/D59lf3aigL1VuRodwD2LxkYD9Kanix/0qp1HPH7Y9qhQw4yQv4DU+RGEgfr5BOeDfGQfe16b+zz+KcgtXEELPPI4XjT1UBUZh3mpxsrTXC4tYJBARRmkTZt7eBpkRK5j8qzOMrQQPs7lXlAr0X2SJlLcwdmelQ6HZlKrNpB+ZZ4DQsOnXVPCl1ItPYNBnA2enpNTYyYfcrTwULLeenKHcqDKltTG7CY7iA3up4l4ANA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, May 01, 2025 at 10:41:54AM +0100, Lorenzo Stoakes wrote: >On Thu, May 01, 2025 at 01:31:27AM +0000, Wei Yang wrote: >> On Tue, Apr 29, 2025 at 09:06:36AM +0000, Wei Yang wrote: >> [...] >> >+ >> >+static bool test_fork_grand_child(void) >> >+{ >> >+ struct vm_area_struct *root_vma, *grand_vma, *vma1, *vma2; >> >+ struct anon_vma_chain *avc; >> >+ struct anon_vma *root_anon_vma; >> >+ DECLARE_BITMAP(expected, 10); >> >+ DECLARE_BITMAP(found, 10); >> >+ >> >+ bitmap_zero(expected, 10); >> >+ bitmap_zero(found, 10); >> >+ >> >+ /* >> >+ * root_anon_vma root_vma >> >+ * +-----------+ +-----------+ >> >+ * | | ---> | | >> >+ * +-----------+ +-----------+ >> >+ */ >> >+ >> >+ root_vma = alloc_vma(0x3000, 0x5000, 3); >> >+ /* First fault on parent anonymous vma. */ >> >+ __anon_vma_prepare(root_vma); >> >+ root_anon_vma = root_vma->anon_vma; >> >+ ASSERT_NE(NULL, root_anon_vma); >> >+ bitmap_set(expected, root_vma->index, 1); >> >+ >> >+ /* First fork */ >> >+ /* >> >+ * root_anon_vma root_vma >> >+ * +-----------+ +-----------+ >> >+ * | | ---> | | >> >+ * +-----------+ +-----------+ >> >+ * \ >> >+ * \ vma1 >> >+ * \ +-----------+ >> >+ * > | | >> >+ * +-----------+ >> >+ */ >> >+ vma1 = alloc_vma(0x3000, 0x5000, 3); >> >+ anon_vma_fork(vma1, root_vma); >> >+ ASSERT_NE(NULL, vma1->anon_vma); >> >+ bitmap_set(expected, vma1->index, 1); >> >+ /* Parent/Root is root_vma->anon_vma */ >> >+ ASSERT_EQ(vma1->anon_vma->parent, root_vma->anon_vma); >> >+ ASSERT_EQ(vma1->anon_vma->root, root_vma->anon_vma); >> >+ >> >+ /* Second fork */ >> >+ /* >> >+ * root_anon_vma root_vma >> >+ * +-----------+ +-----------+ >> >+ * | | ---> | | >> >+ * +-----------+ +-----------+ >> >+ * \ >> >+ * \------------------+ >> >+ * \ vma1 \ vma2 >> >+ * \ +-----------+ \ +-----------+ >> >+ * > | | > | | >> >+ * +-----------+ +-----------+ >> >+ */ >> >+ vma2 = alloc_vma(0x3000, 0x5000, 3); >> >+ anon_vma_fork(vma2, root_vma); >> >+ ASSERT_NE(NULL, vma2->anon_vma); >> >+ bitmap_set(expected, vma2->index, 1); >> >+ /* Parent/Root is root_vma->anon_vma */ >> >+ ASSERT_EQ(vma2->anon_vma->parent, root_vma->anon_vma); >> >+ ASSERT_EQ(vma2->anon_vma->root, root_vma->anon_vma); >> >+ dump_anon_vma_interval_tree(root_vma->anon_vma); >> >+ >> >+ /* Fork grand child from second child */ >> >+ /* >> >+ * root_anon_vma root_vma >> >+ * +-----------+ +-----------+ >> >+ * | | ---> | | >> >+ * +-----------+ +-----------+ >> >+ * \ >> >+ * \------------------+ >> >+ * |\ vma1 \ vma2 >> >+ * | \ +-----------+ \ +-----------+ >> >+ * | > | | > | | >> >+ * | +-----------+ +-----------+ >> >+ * \ >> >+ * \ grand_vma >> >+ * \ +-----------+ >> >+ * > | | >> >+ * +-----------+ >> >+ */ >> >+ grand_vma = alloc_vma(0x3000, 0x5000, 3); >> >+ anon_vma_fork(grand_vma, vma2); >> >+ ASSERT_NE(NULL, grand_vma->anon_vma); >> >+ bitmap_set(expected, grand_vma->index, 1); >> >+ /* Root is root_vma->anon_vma */ >> >+ ASSERT_EQ(grand_vma->anon_vma->root, root_vma->anon_vma); >> >+ /* Parent is vma2->anon_vma */ >> >+ ASSERT_EQ(grand_vma->anon_vma->parent, vma2->anon_vma); >> >> Hi, Lorenzo >> >> Here is the case I am talking about in another thread[1]. >> >> The naming is a little different from that. >> >> * root_vma is VMA A >> * vma2 is VMA B >> * grand_vma is VMA C >> >> If you add following debug code here. >> >> ``` >> printf("root num_children %d\n", root_vma->anon_vma->num_children); >> printf("vma2 num_children %d\n", vma2->anon_vma->num_children); >> printf("grand_vma num_children %d\n", grand_vma->anon_vma->num_children); >> ``` >> >> You would see vma2 num_children is 1, but it has a child. >> >> If I missed something, feel free to correct me. >> >> [1]: https://lkml.kernel.org/r/20250501011845.ktbfgymor4oz5sok@master >> > >See the thread over there. This explanation isn't quite right, and the >diagram is wrong, but indeed anon_vma reuse is a thing that needs >addressing. > >Having looked at this more I'm not a huge fan of these tests, you're >essentially open-coding fork over and over again, any change in overlying >fork logic will break. > >The VMA and maple tree, etc. unit tests work much better as the whole thing >essentially can be separated out, but in this case you really can't. This >is obviously in addition to the aforementioned issues with causing >separation in an area where I want to try to unify. > >So I definitely think that, again, you'd be better off looking at tests as >suggested by David, but moreover I think looking at bugs etc. is more >helpful. Sure. Thank you and David, pointing me a correct direction. And yes, bug has higher priority. > >This report was in effect reporting a bug before it happened so all good >for this kind of thing :>) and that is _always_ welcome. But do try to be >more direct and to the point if you can be. Ah, I am glad you like it. Would try to be more clear on expressing my point next time. And thanks for your patience on reading my "confusing" mail. > >Thanks! > > >> >+ >> >+ /* Expect to find only vmas from second fork */ >> >+ anon_vma_interval_tree_foreach(avc, &vma2->anon_vma->rb_root, 3, 4) { >> >+ ASSERT_TRUE(avc->vma == vma2 || avc->vma == grand_vma); >> >+ } >> >+ >> >+ anon_vma_interval_tree_foreach(avc, &root_vma->anon_vma->rb_root, 3, 4) { >> >+ bitmap_set(found, avc->vma->index, 1); >> >+ } >> >+ /* Expect to find all vma including child and grand child. */ >> >+ ASSERT_TRUE(bitmap_equal(expected, found, 10)); >> >+ >> >+ /* Root process exit or unmap root_vma. */ >> >+ /* >> >+ * root_anon_vma >> >+ * +-----------+ >> >+ * | | >> >+ * +-----------+ >> >+ * \ >> >+ * \------------------+ >> >+ * |\ vma1 \ vma2 >> >+ * | \ +-----------+ \ +-----------+ >> >+ * | > | | > | | >> >+ * | +-----------+ +-----------+ >> >+ * \ >> >+ * \ grand_vma >> >+ * \ +-----------+ >> >+ * > | | >> >+ * +-----------+ >> >+ */ >> >+ bitmap_clear(expected, root_vma->index, 1); >> >+ unlink_anon_vmas(root_vma); >> >+ ASSERT_EQ(0, root_anon_vma->num_active_vmas); >> >+ >> >+ bitmap_zero(found, 10); >> >+ anon_vma_interval_tree_foreach(avc, &root_anon_vma->rb_root, 3, 4) { >> >+ bitmap_set(found, avc->vma->index, 1); >> >+ } >> >+ /* Expect to find all vmas even root_vma released. */ >> >+ ASSERT_TRUE(bitmap_equal(expected, found, 10)); >> >+ >> >+ cleanup(); >> >+ >> >+ ASSERT_EQ(0, nr_allocated); >> >+ return true; >> >+} >> >+ >> >> >> -- >> Wei Yang >> Help you, Help me >> -- Wei Yang Help you, Help me