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 699AAD637AB for ; Wed, 13 Nov 2024 19:05:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CDC2E6B0089; Wed, 13 Nov 2024 14:05:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C8C326B008A; Wed, 13 Nov 2024 14:05:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7AD56B008C; Wed, 13 Nov 2024 14:05:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 979F06B0089 for ; Wed, 13 Nov 2024 14:05:51 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4810540D49 for ; Wed, 13 Nov 2024 19:05:51 +0000 (UTC) X-FDA: 82781999622.06.707573A Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by imf26.hostedemail.com (Postfix) with ESMTP id 9CC2514000C for ; Wed, 13 Nov 2024 19:05:16 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=mwf7KIPJ; spf=pass (imf26.hostedemail.com: domain of surenb@google.com designates 209.85.160.175 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731524693; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1L2eSjt39DWBZHReFjtJm4KZ8bjjYkrHutw63mTeJbg=; b=CqmFyVxSzfN4gRTrxA/Ipj3boZxCMTfvXLUo3F99ZZSi32OoGrixONMKvvfxfHU639G4O5 Uk3Z+HBHDlYrcAWps3SwisgZdLp/6NoZACSbkYhy+nX+LgFcAW58szvtBN3DpHKWR0ghXk WzFyTwROaqg6qwNkhGyBOUM29ffwrUc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731524693; a=rsa-sha256; cv=none; b=PimtEBKi68DzRaR+222Is1TUPPprMoFTwNeeAn/LT2ma+ur5mKPuTMsiFFVqOIkb5Ltunp BTH17eLh/BroxpRPH1J5qYHLgxqMMvN4OfB1RlWMp5/GFV91krKoEFDh8XSpMalCv6qAgd 5+kTAqR0b3p25sN5jZoKOLc7/EZZuRk= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=mwf7KIPJ; spf=pass (imf26.hostedemail.com: domain of surenb@google.com designates 209.85.160.175 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-qt1-f175.google.com with SMTP id d75a77b69052e-460969c49f2so2291cf.0 for ; Wed, 13 Nov 2024 11:05:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731524748; x=1732129548; darn=kvack.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=1L2eSjt39DWBZHReFjtJm4KZ8bjjYkrHutw63mTeJbg=; b=mwf7KIPJEic8PraqupF4N8CFUXYLqzAAG2/t6yZO4DJB7tjPD1Cyu/wHB2hVJilL45 S6pSsye6rEo2VhYqnig5tGC5YCGfoZPFR9lFJhUNlcQrVQQTAhyBrSKaTmul3mdiso3m sW33pzmQV/FkUlfsoV8a0TIlNHa1hawhgNYSWBNKG4bde9lgfBD4C5MBElZCMGGYI/Wu NwYAhSRUdgudVgV8nbzDZl/JKyOal1b7pErPoogOJYI+Jffsa3X4dgcD0SncQkdmEAy2 CS+4JQvtCdb6H8rzKu8wg6qZlhf+W4NI1p3DbFmbS8z9fjP1FCNIFA23D4JsJuBA9dHY HCyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731524748; x=1732129548; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1L2eSjt39DWBZHReFjtJm4KZ8bjjYkrHutw63mTeJbg=; b=SjfAeEUAXGJz6SlHSKc4arq7t/fY9/z/+m0gHDj1MhX2KzzSfK6BG2zWyPcgdlLNFJ EFXikP08WibTeY5S0DBB+vhTI5u8N5hpLMFHGe5yFTj2Gbi+Df9ZKoJsFxezz8xqFaj2 JZpm2pAZgLKF6ILGPyfagwIld+m466gFSEYg5YvlsAGUYa4ucABCXEW8KOwukTclIFGR H8jWMgN/u6X6YqvRPZ8fHCeNFPOmRkOhylzqg0IULtPeNRv4O0QghFCW3DECYd0+klG/ BcUBVpJi+uZ4VdYVBPqqIzGITrYk6jJI9X4t4hEivRGZB/wJlBgPXSP3rONs+N3Sy0L3 ai1g== X-Forwarded-Encrypted: i=1; AJvYcCXdhJ65B1HcA19Bxakoe0BBVE+HkrCX59vgCczs3NbTZuT/cMwBw9dkFICTI/wNnzpvUXNtGgyjtQ==@kvack.org X-Gm-Message-State: AOJu0YwXeEzQ8LB0hJF5T48uUln6+6hBhkCgUCOdLzmwgjtlmhA7iDNZ 5/QnH6TRy3Q2qxxq86TInNBSnSMDDpJb4VQwqhdVXEybPjNxPCzd5K5OHEoISN8AKrishLKUNmr bQRIfLOSHyEr/LMsas3dGspXPdPQd8dlRCNPU X-Gm-Gg: ASbGncslUHQnu0Xf4MRp2sCaK8vwRI8oowhpbsjdlaqlcGEKvyB5nUBC7cbofMubJuT oIQF1eXiop+lqPkT8dLO/nXNGGvNdxk6zSuBUehz464ZdNz/bcEaNeEpadtg8LQ== X-Google-Smtp-Source: AGHT+IHoHO98WMRzNyetaySvO8OR0gF0FQUXeoenh0wgXvlww7UjEdrjlOKFkAWdqi7CtycVgmyp+eC83bjW3/I1rS0= X-Received: by 2002:a05:622a:1817:b0:461:48f9:4852 with SMTP id d75a77b69052e-463572a9c71mr83811cf.28.1731524748240; Wed, 13 Nov 2024 11:05:48 -0800 (PST) MIME-Version: 1.0 References: <20241112194635.444146-1-surenb@google.com> <20241112194635.444146-5-surenb@google.com> <54b8d0b9-a1c7-4c1b-a588-2e5308a977fb@suse.cz> In-Reply-To: From: Suren Baghdasaryan Date: Wed, 13 Nov 2024 11:05:36 -0800 Message-ID: Subject: Re: [PATCH v2 4/5] mm: make vma cache SLAB_TYPESAFE_BY_RCU To: "Liam R. Howlett" , Suren Baghdasaryan , Matthew Wilcox , Vlastimil Babka , akpm@linux-foundation.org, lorenzo.stoakes@oracle.com, mhocko@suse.com, hannes@cmpxchg.org, mjguzik@gmail.com, oliver.sang@intel.com, mgorman@techsingularity.net, david@redhat.com, peterx@redhat.com, oleg@redhat.com, dave@stgolabs.net, paulmck@kernel.org, brauner@kernel.org, dhowells@redhat.com, hdanton@sina.com, hughd@google.com, minchan@google.com, jannh@google.com, shakeel.butt@linux.dev, souravpanda@google.com, pasha.tatashin@soleen.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: rqhrqba6fc3tw9hmhid615b3wsbf4c8z X-Rspam-User: X-Rspamd-Queue-Id: 9CC2514000C X-Rspamd-Server: rspam02 X-HE-Tag: 1731524716-841200 X-HE-Meta: U2FsdGVkX1+EwDL8VZfBsWO3DC9mI+hwo2MLxhpql311vYYOYf/ZHuQ9qsmusDt5JhclFG8IMvFQLXJdbmjWySUL9D2IMHKDNAcCtWJpGDT5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pc4WHitsRVIADP+AQSuxGT6shyMeUp10xH4Ml9iUSoI28UzFuJqedEYO7C6Dxg4ux0YR7w4spcd5QcjoROCkv55ZbzYXvSPW5LYvE0xn7wVEoNPLPK4d6Pwhz25QXheKOqt2iixC3PFkJydZmVW5mVSVdRji5hXV+uke/KSUvlxUamO5w== 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 Wed, Nov 13, 2024 at 7:47=E2=80=AFAM Suren Baghdasaryan wrote: > > On Wed, Nov 13, 2024 at 7:29=E2=80=AFAM Liam R. Howlett wrote: > > > > * Suren Baghdasaryan [241113 10:25]: > > > On Wed, Nov 13, 2024 at 7:23=E2=80=AFAM 'Liam R. Howlett' via kernel-= team > > > wrote: > > > > > > > > * Matthew Wilcox [241113 08:57]: > > > > > On Wed, Nov 13, 2024 at 07:38:02AM -0500, Liam R. Howlett wrote: > > > > > > > Hi, I was wondering if we actually need the detached flag. Co= uldn't > > > > > > > "detached" simply mean vma->vm_mm =3D=3D NULL and we save 4 b= ytes? Do we ever > > > > > > > need a vma that's detached but still has a mm pointer? I'd ho= pe the places > > > > > > > that set detached to false have the mm pointer around so it's= not inconvenient. > > > > > > > > > > > > I think the gate vmas ruin this plan. > > > > > > > > > > But the gate VMAs aren't to be found in the VMA tree. Used to be= that > > > > > was because the VMA tree was the injective RB tree and so VMAs co= uld > > > > > only be in one tree at a time. We could change that now! > > > > > > > > \o/ > > > > > > > > > > > > > > Anyway, we could use (void *)1 instead of NULL to indicate a "det= ached" > > > > > VMA if we need to distinguish between a detached VMA and a gate V= MA. > > > > > > > > I was thinking a pointer to itself vma->vm_mm =3D vma, then a check= for > > > > this, instead of null like we do today. > > > > > > The motivation for having a separate detached flag was that vma->vm_m= m > > > is used when read/write locking the vma, so it has to stay valid even > > > when vma gets detached. Maybe we can be more cautious in > > > vma_start_read()/vma_start_write() about it but I don't recall if > > > those were the only places that was an issue. > > > > We have the mm form the callers though, so it could be passed in? > > Let me try and see if something else blows up. When I was implementing > per-vma locks I thought about using vma->vm_mm to indicate detached > state but there were some issues that caused me reconsider. Yeah, a quick change reveals the first mine explosion: [ 2.838900] BUG: kernel NULL pointer dereference, address: 0000000000000= 480 [ 2.840671] #PF: supervisor read access in kernel mode [ 2.841958] #PF: error_code(0x0000) - not-present page [ 2.843248] PGD 800000010835a067 P4D 800000010835a067 PUD 10835b067 PMD = 0 [ 2.844920] Oops: Oops: 0000 [#1] PREEMPT SMP PTI [ 2.846078] CPU: 2 UID: 0 PID: 1 Comm: init Not tainted 6.12.0-rc6-00258-ga587fcd91b06-dirty #111 [ 2.848277] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 [ 2.850673] RIP: 0010:unmap_vmas+0x84/0x190 [ 2.851717] Code: 00 00 00 00 48 c7 44 24 48 00 00 00 00 48 c7 44 24 18 00 00 00 00 48 89 44 24 28 4c 89 44 24 38 e8 b1 c0 d1 00 48 8b 44 24 28 <48> 83 b8 80 04 00 00 00 0f 85 dd 00 00 00 45 0f b6 ed 49 83 ec 01 [ 2.856287] RSP: 0000:ffffa298c0017a18 EFLAGS: 00010246 [ 2.857599] RAX: 0000000000000000 RBX: 00007f48ccbb4000 RCX: 00007f48ccb= b4000 [ 2.859382] RDX: ffff8918c26401e0 RSI: ffffa298c0017b98 RDI: ffffa298c00= 17ab0 [ 2.861156] RBP: 00007f48ccdb6000 R08: 00007f48ccdb6000 R09: 00000000000= 00001 [ 2.862941] R10: 0000000000000040 R11: ffff8918c2637108 R12: 00000000000= 00001 [ 2.864719] R13: 0000000000000001 R14: ffff8918c26401e0 R15: ffffa298c00= 17b98 [ 2.866472] FS: 0000000000000000(0000) GS:ffff8927bf080000(0000) knlGS:0000000000000000 [ 2.868439] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 2.869877] CR2: 0000000000000480 CR3: 000000010263e000 CR4: 00000000007= 50ef0 [ 2.871661] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 00000000000= 00000 [ 2.873419] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 00000000000= 00400 [ 2.875185] PKRU: 55555554 [ 2.875871] Call Trace: [ 2.876503] [ 2.877047] ? __die+0x1e/0x60 [ 2.877824] ? page_fault_oops+0x17b/0x4a0 [ 2.878857] ? exc_page_fault+0x6b/0x150 [ 2.879841] ? asm_exc_page_fault+0x26/0x30 [ 2.880886] ? unmap_vmas+0x84/0x190 [ 2.881783] ? unmap_vmas+0x7f/0x190 [ 2.882680] vms_clear_ptes+0x106/0x160 [ 2.883621] vms_complete_munmap_vmas+0x53/0x170 [ 2.884762] do_vmi_align_munmap+0x15e/0x1d0 [ 2.885838] do_vmi_munmap+0xcb/0x160 [ 2.886760] __vm_munmap+0xa4/0x150 [ 2.887637] elf_load+0x1c4/0x250 [ 2.888473] load_elf_binary+0xabb/0x1680 [ 2.889476] ? __kernel_read+0x111/0x320 [ 2.890458] ? load_misc_binary+0x1bc/0x2c0 [ 2.891510] bprm_execve+0x23e/0x5e0 [ 2.892408] kernel_execve+0xf3/0x140 [ 2.893331] ? __pfx_kernel_init+0x10/0x10 [ 2.894356] kernel_init+0xe5/0x1c0 [ 2.895241] ret_from_fork+0x2c/0x50 [ 2.896141] ? __pfx_kernel_init+0x10/0x10 [ 2.897164] ret_from_fork_asm+0x1a/0x30 [ 2.898148] Looks like we are detaching VMAs and then unmapping them, where vms_clear_ptes() uses vms->vma->vm_mm. I'll try to clean up this and other paths and will see how many changes are required to make this work. > > > > > > > > > > > > > > Either way, we should make it a function so it's easier to reuse fo= r > > > > whatever we need in the future, wdyt? > > > > > > > > To unsubscribe from this group and stop receiving emails from it, s= end an email to kernel-team+unsubscribe@android.com. > > > >