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 79045C369D5 for ; Fri, 25 Apr 2025 20:37:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 183986B0007; Fri, 25 Apr 2025 16:37:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 10BBF6B0008; Fri, 25 Apr 2025 16:37:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA10F6B000A; Fri, 25 Apr 2025 16:37:04 -0400 (EDT) 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 C6B306B0007 for ; Fri, 25 Apr 2025 16:37:04 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 09B505C444 for ; Fri, 25 Apr 2025 20:37:05 +0000 (UTC) X-FDA: 83373725610.03.E043A0E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 619181A0008 for ; Fri, 25 Apr 2025 20:37:02 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=McbFkg1D; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1745613422; a=rsa-sha256; cv=none; b=turAb3tbriQxaOwOVzdBseHlsIBsXbjnTNQXY73k2OhrqUkHv6ejPrhf0Gkn+p5Vte7+rl vKHfoaBpqGaK58Mm5zSxE7JTDvKsARkX1z9KRD6Xdzooom8faZdooVyTkSCOg01nrF4djG 67GYpt8gz74Ofv35Rbfz08gJv2OEEME= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=McbFkg1D; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1745613422; h=from:from:sender: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CpUFuT49QYK3fR0dsNMkxP3fgvhL7PUWCGb2oz6iPXc=; b=NXFSci14DrJEmx/giOYpCFzCttGQ+7d9aI2kEHYm4OZGpdDye2ylhbPBjhZrAj1SKSHBwN np/dNuxajKrPhV+knDQNJrMvqzpcKKlucEPLTKmaDPXXczR4lK15IgzlRZISRk8Yq4QbOw NS1JFl0ul+WShnDlvQJA23R/vC37AB4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745613421; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=CpUFuT49QYK3fR0dsNMkxP3fgvhL7PUWCGb2oz6iPXc=; b=McbFkg1DRY6wCeKKRGwRMB2hO6suJp4d9GCXku60AEXKSAJkBnT7NKlA6YIuASvM8RXuvw glG4avrTBd8siVCrS7TfK+Mn4ZQz/HHVa2RbTinnv14jUWbJ1hsOBTQKVJkLdRYsBj/XZR LS6a9mhFNh9PUiLx1H1uLlaCyns2yhA= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-111-ZWQWtiBvMwy0XoCM_QVlvQ-1; Fri, 25 Apr 2025 16:36:59 -0400 X-MC-Unique: ZWQWtiBvMwy0XoCM_QVlvQ-1 X-Mimecast-MFC-AGG-ID: ZWQWtiBvMwy0XoCM_QVlvQ_1745613418 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43ceeaf1524so11536735e9.1 for ; Fri, 25 Apr 2025 13:36:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745613418; x=1746218218; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=CpUFuT49QYK3fR0dsNMkxP3fgvhL7PUWCGb2oz6iPXc=; b=d/XUGt0sCXFU0IYSjMzNQ0n7USocTUVEckGvkyfrOcn/0qLeJpbkDuZPUvusI5Qc26 IydpTvX+DaLjSTmUeY+8q+lU1ujEDExM/IY4cPYQow2twpE0Ogo/qfGcyNmep8uDObie 3b5s4qoiFbH7k/uDIMoA4hbYbpzlaHTxcgFRBMlLnk75za6nzdhKuCo9bXtYknmsAq66 O+RMilkPaXdjulF/MeM9v/UWp/qMR3h5hrCFIu84BOfqq/h1hmWGTD3jSX5SBzp0nF1h WoiIZEbiwgj1mj5V+n8vkNDKDEa5yUh7amDAPW2Dh8aNy/jc19VAd6YrfKvtgDw0R4r8 wlRA== X-Forwarded-Encrypted: i=1; AJvYcCUhjYvQdQ8KVZ52VlVY6+zPkqy9HG5sqNztBmlGAQzun3iy7WW15nOUNV9Pin4XyK5TpJu+rAeIAQ==@kvack.org X-Gm-Message-State: AOJu0YxVmWLuiKLLDlbRx1rNKQGaxYOyLnRuhzLvlcDt/PhY2QE4Uzty 5bkbtctH+XTn/HEnzb7JC5Qbw90MUWtHT66kYXH92YeiNoRJvtThu9Zd0SCMWdFgPWx2YyqyyWy Wdw0b77OyvZ5xJrqf0+/QPlQIi/AVBXnnWfmFnlKD9UgFhoawH20O1jCgnkY= X-Gm-Gg: ASbGncvWzcIqotTpM4SP4oBKFhP83/IFBXF59odk13f8mDSmKYCfwOPqGFUfYWHlyHi JzJOV6Qbv+PcghZ9pAv0xA66K+a0FKCVQ8ZS/MnnGOhQ7PhCjzeT6/7YXU8mfEBz/mHZSYJl7Pt D3PklmxoiAhom93n1b+nhPuMjsmVgEmDqqNbYns53o39WUSoo4mUOmYGvSq0k7/BtqOeuBMVd6Q NKVXViW/d5jv5UghuJ17bTK+kAG0sMOMBLq1HxC9sgL4uYxGgg1p38YClPZEjxTD/hYbV6A1Ni7 ftIJY7bc1ywbppryn3du5/ThmPt9eXFAlRySEheh8Rs9wwfk60emmprZzBGyy1d8flEfU72ethr 7yS2O5akdRC2ksElPG8qKxOFqhQPCw/qIdRD8 X-Received: by 2002:a05:600c:c88:b0:439:5f04:4f8d with SMTP id 5b1f17b1804b1-440a6693e9fmr30390475e9.12.1745613418379; Fri, 25 Apr 2025 13:36:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEdS9ZymIYN4ZA6xIbkv21zMROrnjORxXDTOvJmAPXiktbH2fpnT6UD8wE/LlrXVF31B+MV2w== X-Received: by 2002:a05:600c:c88:b0:439:5f04:4f8d with SMTP id 5b1f17b1804b1-440a6693e9fmr30390315e9.12.1745613417913; Fri, 25 Apr 2025 13:36:57 -0700 (PDT) Received: from ?IPV6:2003:cb:c70f:6900:6c56:80f8:c14:6d2a? (p200300cbc70f69006c5680f80c146d2a.dip0.t-ipconnect.de. [2003:cb:c70f:6900:6c56:80f8:c14:6d2a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4409d2ac5a9sm68318335e9.23.2025.04.25.13.36.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Apr 2025 13:36:57 -0700 (PDT) Message-ID: Date: Fri, 25 Apr 2025 22:36:55 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 05/11] mm: convert VM_PFNMAP tracking to pfnmap_track() + pfnmap_untrack() To: Peter Xu Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-trace-kernel@vger.kernel.org, Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Simona Vetter , Andrew Morton , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , "Liam R. Howlett" , Lorenzo Stoakes , Vlastimil Babka , Jann Horn , Pedro Falcato References: <20250425081715.1341199-1-david@redhat.com> <20250425081715.1341199-6-david@redhat.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZY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zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 23lxQzZhENOLMnzPW4taI6sfR1OqG2CGaLvGX9OplNc_1745613418 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 619181A0008 X-Stat-Signature: a7hy6rrmk5r1qdeny9b1iaboq9smtweb X-Rspam-User: X-HE-Tag: 1745613422-49419 X-HE-Meta: U2FsdGVkX18GKP28G5xPGfZZ42XSwtIk1ZYWp6U8OIjr4fg8VgLfr6o30KwCSdrF+PPw7NX6nPyNtQsdYa03ZIRo3dhuIYj852iqGJH/0MeWMKq7QUgjEDxIvkOhgd1siro+OhjvmjkYGG9JmBinhwNwAJubUhXev83FDlUXi5Hsu0QOZKm+JzqAfcnco3Op02wk4adNeu2xQz6v6NcTPvI8nM1+6/zVFNpADhqyxpfAATLqd6PJ1Rjkfqpk5zdyDYnE9fwFrdmaT/k7LZNcI+Upk+WU4Oy4jf2RchwVFG1JJxf/JPXhV74t1V6MRe09i75/edh7xEwxzwmAA42DDREyjWyEySZMhz4KazYz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jIkjO4PPB1hf6k0xbqbEjTXx2LF 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 25.04.25 22:23, Peter Xu wrote: > On Fri, Apr 25, 2025 at 10:17:09AM +0200, David Hildenbrand wrote: >> Let's use our new interface. In remap_pfn_range(), we'll now decide >> whether we have to track (full VMA covered) or only sanitize the pgprot >> (partial VMA covered). >> >> Remember what we have to untrack by linking it from the VMA. When >> duplicating VMAs (e.g., splitting, mremap, fork), we'll handle it similar >> to anon VMA names, and use a kref to share the tracking. >> >> Once the last VMA un-refs our tracking data, we'll do the untracking, >> which simplifies things a lot and should sort our various issues we saw >> recently, for example, when partially unmapping/zapping a tracked VMA. >> >> This change implies that we'll keep tracking the original PFN range even >> after splitting + partially unmapping it: not too bad, because it was >> not working reliably before. The only thing that kind-of worked before >> was shrinking such a mapping using mremap(): we managed to adjust the >> reservation in a hacky way, now we won't adjust the reservation but >> leave it around until all involved VMAs are gone. >> >> Signed-off-by: David Hildenbrand >> --- >> include/linux/mm_inline.h | 2 + >> include/linux/mm_types.h | 11 ++++++ >> kernel/fork.c | 54 ++++++++++++++++++++++++-- >> mm/memory.c | 81 +++++++++++++++++++++++++++++++-------- >> mm/mremap.c | 4 -- >> 5 files changed, 128 insertions(+), 24 deletions(-) >> >> diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h >> index f9157a0c42a5c..89b518ff097e6 100644 >> --- a/include/linux/mm_inline.h >> +++ b/include/linux/mm_inline.h >> @@ -447,6 +447,8 @@ static inline bool anon_vma_name_eq(struct anon_vma_name *anon_name1, >> >> #endif /* CONFIG_ANON_VMA_NAME */ >> >> +void pfnmap_track_ctx_release(struct kref *ref); >> + >> static inline void init_tlb_flush_pending(struct mm_struct *mm) >> { >> atomic_set(&mm->tlb_flush_pending, 0); >> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h >> index 56d07edd01f91..91124761cfda8 100644 >> --- a/include/linux/mm_types.h >> +++ b/include/linux/mm_types.h >> @@ -764,6 +764,14 @@ struct vma_numab_state { >> int prev_scan_seq; >> }; >> >> +#ifdef __HAVE_PFNMAP_TRACKING >> +struct pfnmap_track_ctx { >> + struct kref kref; >> + unsigned long pfn; >> + unsigned long size; >> +}; >> +#endif >> + >> /* >> * This struct describes a virtual memory area. There is one of these >> * per VM-area/task. A VM area is any part of the process virtual memory >> @@ -877,6 +885,9 @@ struct vm_area_struct { >> struct anon_vma_name *anon_name; >> #endif >> struct vm_userfaultfd_ctx vm_userfaultfd_ctx; >> +#ifdef __HAVE_PFNMAP_TRACKING >> + struct pfnmap_track_ctx *pfnmap_track_ctx; >> +#endif > > So this was originally the small concern (or is it small?) that this will > grow every vma on x86, am I right? Yeah, and last time I looked into this, it would have grown it such that it would require a bigger slab. Right now: Before this change: struct vm_area_struct { union { struct { long unsigned int vm_start; /* 0 8 */ long unsigned int vm_end; /* 8 8 */ }; /* 0 16 */ freeptr_t vm_freeptr; /* 0 8 */ }; /* 0 16 */ struct mm_struct * vm_mm; /* 16 8 */ pgprot_t vm_page_prot; /* 24 8 */ union { const vm_flags_t vm_flags; /* 32 8 */ vm_flags_t __vm_flags; /* 32 8 */ }; /* 32 8 */ unsigned int vm_lock_seq; /* 40 4 */ /* XXX 4 bytes hole, try to pack */ struct list_head anon_vma_chain; /* 48 16 */ /* --- cacheline 1 boundary (64 bytes) --- */ struct anon_vma * anon_vma; /* 64 8 */ const struct vm_operations_struct * vm_ops; /* 72 8 */ long unsigned int vm_pgoff; /* 80 8 */ struct file * vm_file; /* 88 8 */ void * vm_private_data; /* 96 8 */ atomic_long_t swap_readahead_info; /* 104 8 */ struct mempolicy * vm_policy; /* 112 8 */ struct vma_numab_state * numab_state; /* 120 8 */ /* --- cacheline 2 boundary (128 bytes) --- */ refcount_t vm_refcnt __attribute__((__aligned__(64))); /* 128 4 */ /* XXX 4 bytes hole, try to pack */ struct { struct rb_node rb __attribute__((__aligned__(8))); /* 136 24 */ long unsigned int rb_subtree_last; /* 160 8 */ } __attribute__((__aligned__(8))) shared __attribute__((__aligned__(8))); /* 136 32 */ struct anon_vma_name * anon_name; /* 168 8 */ struct vm_userfaultfd_ctx vm_userfaultfd_ctx; /* 176 0 */ /* size: 192, cachelines: 3, members: 18 */ /* sum members: 168, holes: 2, sum holes: 8 */ /* padding: 16 */ /* forced alignments: 2, forced holes: 1, sum forced holes: 4 */ } __attribute__((__aligned__(64))); After this change: struct vm_area_struct { union { struct { long unsigned int vm_start; /* 0 8 */ long unsigned int vm_end; /* 8 8 */ }; /* 0 16 */ freeptr_t vm_freeptr; /* 0 8 */ }; /* 0 16 */ struct mm_struct * vm_mm; /* 16 8 */ pgprot_t vm_page_prot; /* 24 8 */ union { const vm_flags_t vm_flags; /* 32 8 */ vm_flags_t __vm_flags; /* 32 8 */ }; /* 32 8 */ unsigned int vm_lock_seq; /* 40 4 */ /* XXX 4 bytes hole, try to pack */ struct list_head anon_vma_chain; /* 48 16 */ /* --- cacheline 1 boundary (64 bytes) --- */ struct anon_vma * anon_vma; /* 64 8 */ const struct vm_operations_struct * vm_ops; /* 72 8 */ long unsigned int vm_pgoff; /* 80 8 */ struct file * vm_file; /* 88 8 */ void * vm_private_data; /* 96 8 */ atomic_long_t swap_readahead_info; /* 104 8 */ struct mempolicy * vm_policy; /* 112 8 */ struct vma_numab_state * numab_state; /* 120 8 */ /* --- cacheline 2 boundary (128 bytes) --- */ refcount_t vm_refcnt __attribute__((__aligned__(64))); /* 128 4 */ /* XXX 4 bytes hole, try to pack */ struct { struct rb_node rb __attribute__((__aligned__(8))); /* 136 24 */ long unsigned int rb_subtree_last; /* 160 8 */ } __attribute__((__aligned__(8))) shared __attribute__((__aligned__(8))); /* 136 32 */ struct anon_vma_name * anon_name; /* 168 8 */ struct vm_userfaultfd_ctx vm_userfaultfd_ctx; /* 176 0 */ struct pfnmap_track_ctx * pfnmap_track_ctx; /* 176 8 */ /* size: 192, cachelines: 3, members: 19 */ /* sum members: 176, holes: 2, sum holes: 8 */ /* padding: 8 */ /* forced alignments: 2, forced holes: 1, sum forced holes: 4 */ } __attribute__((__aligned__(64))); Observe that we allocate 192 bytes with or without pfnmap_track_ctx. (IIRC, slab sizes are ... 128, 192, 256, 512, ...) > > After all pfnmap vmas are the minority, I was thinking whether we could > work it out without extending vma struct. Heh, similar to userfaultfd on most systems, or ones with a mempolicy, or anon vma names, ... :) But yeah, pfnmap is certainly a minority as well. > > I had a quick thought quite a while ago, but never tried out (it was almost > off-track since vfio switched away from remap_pfn_range..), which is to > have x86 maintain its own mapping of vma <-> pfn tracking using a global > stucture. After all, the memtype code did it already with the > memtype_rbroot, so I was thinking if vma info can be memorized as well, so > as to get rid of get_pat_info() too. > > Maybe it also needs the 2nd layer like what you did with the track ctx, but > the tree maintains the mapping instead of adding the ctx pointer into vma. > > Maybe it could work with squashing the two layers (or say, extending > memtype rbtree), but maybe not.. > > It could make it slightly slower than vma->pfnmap_track_ctx ref when > looking up pfn when holding a vma ref, but I assume it's ok considering > that track/untrack should be slow path for pfnmaps, and pfnmaps shouldn't > be a huge lot. > > I didn't think further, but if that'll work it'll definitely avoids the > additional fields on x86 vmas. I'm curious whether you explored that > direction, or maybe it's a known decision that the 8 bytes isn't a concern. When discussing this approach with Lorenzo, I raised that we could simply map using an xarray the VMA to that structure. But then, if we're not effectively allocating any more space, then probably not worth adding more complexity right now. -- Cheers, David / dhildenb