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 DC1F5C369DC for ; Tue, 29 Apr 2025 16:25:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 61E356B0005; Tue, 29 Apr 2025 12:25:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5CBF06B0007; Tue, 29 Apr 2025 12:25:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 447A46B0008; Tue, 29 Apr 2025 12:25:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 20EE96B0005 for ; Tue, 29 Apr 2025 12:25:14 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BF6F5C0A6B for ; Tue, 29 Apr 2025 16:25:15 +0000 (UTC) X-FDA: 83387606190.19.192A970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 2C0CB160006 for ; Tue, 29 Apr 2025 16:25:13 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Gtc58P3h; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf08.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=1745943913; a=rsa-sha256; cv=none; b=mkIzfLdjZ12j5bZo+p17O6Al+xySRe0bwyOheCfYfsSYV6K5zi4IXxZrfFsxHjnCf7ibNp MT+7qnvzwqEqoPQXdx7P4QcKZh1gYxgYaEib+1yRmiFICZwn1NGlt1gRDB/DW9g2Lk1lUO Bd9IrVvHkeVfTXtBXufeq95rd7mZSEc= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Gtc58P3h; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf08.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=1745943913; 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=KDB+A8JwGIjcFsXzh2F+2beUTgBrxjq5rWh4M65ziJ4=; b=i+EUBQcthj4+3FjBq96mUfGcx6oOUbB8L/aoSozz9Q7X/hmUKGe1hJsU6fhDc6khnrLlGv NUMWN+gcztXhPQezWkhOgJQC9Z+jbah1/SYBVuMZywCGD8itDhSUz95ok4Ml1Y7oQflSCy IKxtr5RGElNOkNopknMJ+wn+D9BZYuM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745943912; 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=KDB+A8JwGIjcFsXzh2F+2beUTgBrxjq5rWh4M65ziJ4=; b=Gtc58P3hLfAg6FWY1K4bWTxyyG2w0ek/nBKoakgxY2vVfc5ajsR6y6ER0bYJFQ79Vnzfsw bXe18Pg+btoufxzCbUTkwNx9T0qe98mDUcojtNMEcG/SwIPktSZPLKnSfdbxDM9pBpuPzL XJZiyebIk5YEXLCqQxWXNCitT1GrI0g= 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-407-bm3VNoShPHyG89--ALpeVg-1; Tue, 29 Apr 2025 12:25:10 -0400 X-MC-Unique: bm3VNoShPHyG89--ALpeVg-1 X-Mimecast-MFC-AGG-ID: bm3VNoShPHyG89--ALpeVg_1745943909 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43cec217977so31168765e9.0 for ; Tue, 29 Apr 2025 09:25:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745943909; x=1746548709; 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=KDB+A8JwGIjcFsXzh2F+2beUTgBrxjq5rWh4M65ziJ4=; b=fNdREeVD+CgZYMXEcGdzlSBs6lmR3cEAX6dFz303KlraEaYivorUMaCIxdyhoJkM9u aNUcY3cPogltz7kP8mvBjtHDgGBHzGBX4SgO1pPD1ELaDnf+dnbnqLt5U4ZVnpkNQU1y jXenxkzzc9JIjhzfjJEZ+nwnnooZhA/TDF+dJPP8B/d3QQOPO2CCvmOkZr5QxLYHNH2u lr6y5EQHLtaqpYTeBW3U6qRkdvjGVV6h62OBrG28Q3pWa81L8upM/jfqx19J3yAg+CUH 31t34NPx78BNycSHtIf17xMjE6fxU1RGJISD9pF0nLve9cWEpAaU3Amd+d6hSlSIXRa3 kQ8g== X-Forwarded-Encrypted: i=1; AJvYcCVX+Xp6GL5W+XXKvI+vavefs4EKiXHKjeVSsKtr7bjto4ILWoQ6gsqS7Pq5H9k0MyKUHi+Ve8m2ow==@kvack.org X-Gm-Message-State: AOJu0Yx7uaLm3TV/hx4+bxUd27dOTUTTGOiq1AamJ0E2XhFEUnPv04Rq BA8ozwBtSgCUIDxxfgE/qpSzu9pLtVoLS3m31riYU5O2GE0KP/Nmk21rqT9M+8pGUjeKdUTFrVH 6ltdYL9+eHOgt7cZxEW4iSsRueDgPnp4r6bBIKCgAjYS5SIyD X-Gm-Gg: ASbGncs4JhyC1d1jDDwkZ0l2p7xB1V4nTUk/U+tIc8AhwAnw+4vYvJikYEt63iEBdbW HyYpl0yB8EI83NroAQTP5Rrw0dFA9qPb+qYE0oXwY5kDapeL0JVLVJ6tL2xdpp5UZC2HvG84mbB 4BMNrZwpIsrvkcxNdPSDVncK40w7dn0AAYju8Po52/yzWzfnOCEWUdCufY5i/dv5vzNlq0o1uq5 AX5jXOkApkyHbUT+eY9S7u9yPlswAS8GVOHg6K+N141jlXjQL+Pey+BeTzL383KzKmVfDHdKZUr yMWP7J+BOzayl02VArXkmdlYC/fEcYT8+tzT/X6WgChGxqsDiMeYCRVIMcWpW1oSUOQmlWapDRX qPCDUBk5pfqY/Ju+oT8hq3qx4+D+Cyf2l9YbgNbU= X-Received: by 2002:a05:600c:34c7:b0:43d:b3:fb1 with SMTP id 5b1f17b1804b1-440ab8713a1mr114409495e9.27.1745943909436; Tue, 29 Apr 2025 09:25:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGPyseW42aAVvTvcPwXt1Q40dQmqumdD/rMq2TgAupyw7prLhxicloCCNmw5GFsMeHBi1jj+Q== X-Received: by 2002:a05:600c:34c7:b0:43d:b3:fb1 with SMTP id 5b1f17b1804b1-440ab8713a1mr114409015e9.27.1745943908861; Tue, 29 Apr 2025 09:25:08 -0700 (PDT) Received: from ?IPV6:2003:cb:c73b:fa00:8909:2d07:8909:6a5a? (p200300cbc73bfa0089092d0789096a5a.dip0.t-ipconnect.de. [2003:cb:c73b:fa00:8909:2d07:8909:6a5a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4409d2ad112sm193653355e9.24.2025.04.29.09.25.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 29 Apr 2025 09:25:08 -0700 (PDT) Message-ID: <4a57e772-51f5-4341-a249-dd1b8fcf23b0@redhat.com> Date: Tue, 29 Apr 2025 18:25:06 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 02/11] mm: convert track_pfn_insert() to pfnmap_sanitize_pgprot() 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-3-david@redhat.com> <78f88303-6b00-42cf-8977-bf7541fa45a9@redhat.com> <75998f7c-93d2-4b98-bb53-8d858b2c108e@redhat.com> <57f9480c-2f8c-4be8-864c-406fec917eb1@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 PXFNNgV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ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+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: WZ6NhjaXVsDMf2JsepDp-w8qKBb-e1Wg2ozZJ-9w5fo_1745943909 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Queue-Id: 2C0CB160006 X-Rspamd-Server: rspam04 X-Stat-Signature: 7dsow59nnh81zbnbkf1xidmqfceqo1sm X-HE-Tag: 1745943913-693429 X-HE-Meta: U2FsdGVkX1/yAGM0GSXYazwrKUQlFLd5K/OXHAgDAtCHf/JSGvbVf0EFLyDRoZgAgoGW2lOtGt/HuQtyxSJ9VJ39g/bA0k2mHFO75CsZ3eSRxiIXzVxTrMoUe3xK5mtr/HMGX6wUtlpWwYH/XPjW+eXqUfyxzNhnxcwUE5kgyXPnv/NIG9wEKpy8hHub7IRVJCHvOB4eGyAMr7NCA42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Abyy5481JgimNX4I5I0P+WPYItyCi7f5L7QSQqOzzUnOFVOajWoCUkoihiFeiQn/KfbnnkLD5eQEszbtjQSIdmx3w9SSkxSgjFi+pf6oj8+WUkcNpp6rG4RE5D7r2cd5YxTyDCzIIy58PaCP2jr4FIYCTRperXEkw4p0MuZL03mdFrZ7aLzRbP2inmPCql 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 29.04.25 15:44, Peter Xu wrote: > On Mon, Apr 28, 2025 at 10:37:49PM +0200, David Hildenbrand wrote: >> On 28.04.25 18:21, Peter Xu wrote: >>> On Mon, Apr 28, 2025 at 04:58:46PM +0200, David Hildenbrand wrote: >>>> >>>>>> What it does on PAT (only implementation so far ...) is looking up the >>>>>> memory type to select the caching mode that can be use. >>>>>> >>>>>> "sanitize" was IMHO a good fit, because we must make sure that we don't use >>>>>> the wrong caching mode. >>>>>> >>>>>> update/setup/... don't make that quite clear. Any other suggestions? >>>>> >>>>> I'm very poor on naming.. :( So far anything seems slightly better than >>>>> sanitize to me, as the word "sanitize" is actually also used in memtype.c >>>>> for other purpose.. see sanitize_phys(). >>>> >>>> Sure, one can sanitize a lot of things. Here it's the cachemode/pgrpot, in >>>> the other functions it's an address. >>>> >>>> Likely we should just call it pfnmap_X_cachemode()/ >>>> >>>> Set/update don't really fit for X in case pfnmap_X_cachemode() is a NOP. >>>> >>>> pfnmap_setup_cachemode() ? Hm. >>> >>> Sounds good here. >> >> Okay, I'll use that one. If ever something else besides PAT would require >> different semantics, they can bother with finding a better name :) >> >>> >>>> >>>>> >>>>>> >>>>>>> >>>>>>>> + * @pfn: the start of the pfn range >>>>>>>> + * @size: the size of the pfn range >>>>>>>> + * @prot: the pgprot to sanitize >>>>>>>> + * >>>>>>>> + * Sanitize the given pgprot for a pfn range, for example, adjusting the >>>>>>>> + * cachemode. >>>>>>>> + * >>>>>>>> + * This function cannot fail for a single page, but can fail for multiple >>>>>>>> + * pages. >>>>>>>> + * >>>>>>>> + * Returns 0 on success and -EINVAL on error. >>>>>>>> + */ >>>>>>>> +int pfnmap_sanitize_pgprot(unsigned long pfn, unsigned long size, >>>>>>>> + pgprot_t *prot); >>>>>>>> extern int track_pfn_copy(struct vm_area_struct *dst_vma, >>>>>>>> struct vm_area_struct *src_vma, unsigned long *pfn); >>>>>>>> extern void untrack_pfn_copy(struct vm_area_struct *dst_vma, >>>>>>>> diff --git a/mm/huge_memory.c b/mm/huge_memory.c >>>>>>>> index fdcf0a6049b9f..b8ae5e1493315 100644 >>>>>>>> --- a/mm/huge_memory.c >>>>>>>> +++ b/mm/huge_memory.c >>>>>>>> @@ -1455,7 +1455,9 @@ vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf, pfn_t pfn, bool write) >>>>>>>> return VM_FAULT_OOM; >>>>>>>> } >>>>>>>> - track_pfn_insert(vma, &pgprot, pfn); >>>>>>>> + if (pfnmap_sanitize_pgprot(pfn_t_to_pfn(pfn), PAGE_SIZE, &pgprot)) >>>>>>>> + return VM_FAULT_FALLBACK; >>>>>>> >>>>>>> Would "pgtable" leak if it fails? If it's PAGE_SIZE, IIUC it won't ever >>>>>>> trigger, though. >>>>>>> >>>>>>> Maybe we could have a "void pfnmap_sanitize_pgprot_pfn(&pgprot, pfn)" to >>>>>>> replace track_pfn_insert() and never fail? Dropping vma ref is definitely >>>>>>> a win already in all cases. >>>>>> >>>>>> It could be a simple wrapper around pfnmap_sanitize_pgprot(), yes. That's >>>>>> certainly helpful for the single-page case. >>>>>> >>>>>> Regarding never failing here: we should check the whole range. We have to >>>>>> make sure that none of the pages has a memory type / caching mode that is >>>>>> incompatible with what we setup. >>>>> >>>>> Would it happen in real world? >>>>>> IIUC per-vma registration needs to happen first, which checks for >>>> memtype >>>>> conflicts in the first place, or reserve_pfn_range() could already have >>>>> failed. >>>>>> Here it's the fault path looking up the memtype, so I would expect it is >>>>> guaranteed all pfns under the same vma is following the verified (and same) >>>>> memtype? >>>> >>>> The whole point of track_pfn_insert() is that it is used when we *don't* use >>>> reserve_pfn_range()->track_pfn_remap(), no? >>>> >>>> track_pfn_remap() would check the whole range that gets mapped, so >>>> track_pfn_insert() user must similarly check the whole range that gets >>>> mapped. >>>> >>>> Note that even track_pfn_insert() is already pretty clear on the intended >>>> usage: "called when a _new_ single pfn is established" >>> >>> We need to define "new" then.. But I agree it's not crystal clear at >>> least. I think I just wasn't the first to assume it was reserved, see this >>> (especially, the "Expectation" part..): >>> >>> commit 5180da410db6369d1f95c9014da1c9bc33fb043e >>> Author: Suresh Siddha >>> Date: Mon Oct 8 16:28:29 2012 -0700 >>> >>> x86, pat: separate the pfn attribute tracking for remap_pfn_range and vm_insert_pfn >>> With PAT enabled, vm_insert_pfn() looks up the existing pfn memory >>> attribute and uses it. Expectation is that the driver reserves the >>> memory attributes for the pfn before calling vm_insert_pfn(). >> >> It's all confusing. >> >> We do have the following functions relevant in pat code: >> >> (1) memtype_reserve(): used by ioremap and set_memory_XX >> >> (2) memtype_reserve_io(): used by iomap >> >> (3) reserve_pfn_range(): only remap_pfn_range() calls it >> >> (4) arch_io_reserve_memtype_wc() >> >> >> Which one would perform the reservation for, say, vfio? > > My understanding is it was done via barmap. See this stack: > > vfio_pci_core_mmap > pci_iomap > pci_iomap_range > ... > __ioremap_caller > memtype_reserve > >> >> >> I agree that if there would be a guarantee/expectation that all PFNs have >> the same memtype (from previous reservation), it would be sufficient to >> check a single PFN, and we could document that. I just don't easily see >> where that reservation is happening. >> >> So a pointer to that would be appreciated! > > I am not aware of any pointer.. maybe others could chime in. > > IMHO, if there's anything uncertain, for this one we could always decouple > this issue from the core issue you're working on, so at least it keeps the > old behavior (which is pure lookup on pfn injections) until a solid issue > occurs? It avoids the case where we could introduce unnecessary code but > then it's much harder to justify a removal. What do you think? I'll use the _pfn variant and document the behavior. I do wonder why we even have to lookup the memtype again if the caller apparently reserved it (which implied checking it). All a bit weird. -- Cheers, David / dhildenb