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 4DAF5C3ABA5 for ; Mon, 28 Apr 2025 16:21:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 82BDE6B00A8; Mon, 28 Apr 2025 12:21:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7DA006B00A9; Mon, 28 Apr 2025 12:21:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67B806B00AC; Mon, 28 Apr 2025 12:21:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 458646B00A8 for ; Mon, 28 Apr 2025 12:21:25 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 05B92140BE7 for ; Mon, 28 Apr 2025 16:21:27 +0000 (UTC) X-FDA: 83383967814.22.11E4D84 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 9BC49C0008 for ; Mon, 28 Apr 2025 16:21:24 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RP11Cptf; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1745857284; a=rsa-sha256; cv=none; b=4pmO6O9g9lZeCCfKSIWh4BgMXcKddjS69fLxDBo8RWF0pHpWOFYAnpNc/cLMrnvhGTcFuU SYWwWlFono4pttqnBeuLYLDbbPV5Ef5L+6dsbnoWtWZeC+rbNMs7meOrd35v4ykFFjsG5A DTtv955XYZ3u5aUMyOpDfMPl1/oELck= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RP11Cptf; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1745857284; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ICKzzB8taBJD0eGbxcxv8f4DsFK3m+kwUBskNGBQM7I=; b=TBGgsuhwOfb/SxgN5jSofUnuFRTT9+gXnMr6HAc3kGomj5Lo8MamZE+JM4ZikLSnpQRMjU Jdj8XbngOUFxxDiijFRRXcCiCb9Y9CgACtwPjucCvFvP8ZlWjiKTznIHyBVMaV37qTsUOd xdkYtZ7hlH+OFfw8gFLrGTyfN1u4B/E= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745857284; 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: in-reply-to:in-reply-to:references:references; bh=ICKzzB8taBJD0eGbxcxv8f4DsFK3m+kwUBskNGBQM7I=; b=RP11Cptf6B2oHHbDG8zp9ipsIcmI0sOuu+wB7F1ZY5+EObDRdVAYbJ2vKTOFfsNcS5TtUw 3lEnPW2aeI0UPi2WCt2WODN5ZhwlibjfOKpc9+fci5eUaf3wvZ1/g/wvCbag0QUUEmU0sP 4OY6XeoRppztbG/11vOUkNIWxxJ6TXk= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-83-q0lA0EAbOkqn05IIAR4AbA-1; Mon, 28 Apr 2025 12:21:22 -0400 X-MC-Unique: q0lA0EAbOkqn05IIAR4AbA-1 X-Mimecast-MFC-AGG-ID: q0lA0EAbOkqn05IIAR4AbA_1745857281 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7c5c77aff55so1270939685a.3 for ; Mon, 28 Apr 2025 09:21:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745857281; x=1746462081; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ICKzzB8taBJD0eGbxcxv8f4DsFK3m+kwUBskNGBQM7I=; b=DGqD9+qMUTdbVQOrcEgziwzfjiscpMWmV0MNUnuqEycVnQRUbvV+p2fZ5yJRcA95UA TIWyW2UsSmm29gyyLxSuyQ15r+H8k0bgq2dhwAi/384CvOcyoKlwJHVH4ZkUc6LPQgwI iMg40jctEqGfRza6jLc6sEwrb+ZAVtQiM+LHwQHDmFXydpBfJHYq2vguWaxiv0eO3Z/Q n6us4q7dgCyjTo19puMeKrYrMXsb/HTl2v+FfKhJhNf92nLzqvE7KFSamGmay+WngtV0 6FVOnTVPvX+ZicEvfncGrzMq4QU51LrqzVfRb3c25Ed3Io6Q3gS6nVQ40xjs6UzoIwbO +aWA== X-Forwarded-Encrypted: i=1; AJvYcCX0DftBRB2t68RcMCPSZhvIB2zm7UnwtGzhHWPKPxA55xFp0uVzaNhg6XddPtNx+7Jg9hDU7obcwA==@kvack.org X-Gm-Message-State: AOJu0Yz4LrmQwavjaIMLL+4QFdQOUD2sjQrtxxnSHCivdBCjNSVSjHrw hdfl2uMcPMJclCIrSq1zdBDazRv4LOQtsZEQ6GdFLwJlos5bYCxsy1sLt5WWrcskcuMVmHf7Wxt 4wbtmJptnTW+dSVcsKGWjuN19RzOdGIKzV96P7l9gtmt4GqOo X-Gm-Gg: ASbGnct+NNhf85Y8czQTvBI7nqHDJWjGCk8PlBBfG+aQbeco/GH6U8uSPiUslnW6QLq MvVBFy8R6N30Gfd8hq+jkYqpgaOhqMnadRY24VuLNpSOWKq+NFPwMYpVGNkpOXhzpYoFLfxVkKE srXMziNYucfxf7O/aFji9O5BtahBX7oYRYY0ezuleVEB9qgoxp8cMajk9Vvi/Lg1/m05UTyN0QI 9v4Z9xqQmkL1P4ShrbhfntCOOnAs6NL1pAnzZ2w1jUxp/cu5rtOLX5G8Qix5ljISsASLJizVARK X8c= X-Received: by 2002:a05:620a:19a3:b0:7c5:7a03:8467 with SMTP id af79cd13be357-7c9668d1d61mr1640816185a.55.1745857281508; Mon, 28 Apr 2025 09:21:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQz1zkMFXlMEPUAS7D8yAHGiL/XnLPod9B0w30kVOxZ+K3YH+CRaciRSMW1T3Yxr1P4D1AmQ== X-Received: by 2002:a05:620a:19a3:b0:7c5:7a03:8467 with SMTP id af79cd13be357-7c9668d1d61mr1640808385a.55.1745857280905; Mon, 28 Apr 2025 09:21:20 -0700 (PDT) Received: from x1.local ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c958e9fdaesm639851585a.95.2025.04.28.09.21.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Apr 2025 09:21:20 -0700 (PDT) Date: Mon, 28 Apr 2025 12:21:16 -0400 From: Peter Xu To: David Hildenbrand 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 Subject: Re: [PATCH v1 02/11] mm: convert track_pfn_insert() to pfnmap_sanitize_pgprot() Message-ID: 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> MIME-Version: 1.0 In-Reply-To: <75998f7c-93d2-4b98-bb53-8d858b2c108e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: RedKrmvevovIDOgV7jJAi9QYKFH_h1_HSk2n1hiaGow_1745857281 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 9BC49C0008 X-Stat-Signature: 81ow3y6zyx58cirxb8sygeqg8jwok3xz X-Rspam-User: X-HE-Tag: 1745857284-1109 X-HE-Meta: U2FsdGVkX18VyTxmq5BFI6JF3tvBLehYTtkdmCTz7eoYsHj4hBhK+fMK92uiTKm8+Y9n+JUthnPfi2hkV9UzlcRzINeUvhmJpV1UVaxBB6ZbLNWWU0Tm4TA5EPAd6FnQN9N4eCIKhhZ1fRLTHWO8F7PZlA7owUBXiKxFFxX5l7nqVpiiOaXpwG/Zp5C0GhoDNfYcjeeGVYgrcxvXuIHN+XzQ/BPFMzIqKNGQ5O7fc4t9Z838w2dfdRHR2srbp02juwuFEv06gQiVq8qRJESxor7IMmFqAUBBzZqtaCZHpifXFr0g8aNJsPAXuXsEdZeRMIYfysxTuqx0CWPBj9JkpDIhkF12TsJFk5i07BKFgsAtqW+rQ0WODrjDRl6+W5UaV1lpli3JdFpf0UPs0lUF2FYgaLsKzdemGxBpZ0+Q3+DsqWHeSBD0D6RVL7p32WL2GLrAVV4z2JR3u32cxwM6xtdGXYPZ6gaw5C43cvXb0pLJ7c6yaIVR7gNayvndx0qnVXep4XTB+wacWoaiKLpaTgQ6CGeoTFvM5jfP8o9bLAabFVYNZtTyj9URPOSt3myqXRlPbHgGe66ebzAD9VoUMQZbf7NwwGalkmSFe0hhMX3cyrpQHjN89MUiwrG4levjbncwmLos0fC1jqedsi8aKKE+2LQbOZgJUMD5yo64Xe7VeH47OHUHpTm2uXRe9rpV8Qg6/qQGTQsVZOU2/ru/YLp/1ASdztV8NMENl2cYzOOFVgG6FQsXozCoL6GN3mCb29nOaoOguIXl1AYv/KwXbLuJxPYMECmMelyONW3143DgVzEr3Mx/LnuqDtBU7B25HQMrsLX3I2u6nObj4yBuAuRRqDOoMkr3Wh1KPlyToHb6gwElJlmz3ICTnFSOQiJdweJ8zKgTEsocQI3Too64QdIX7Hr1rJcA0aqdz+rF7oOmDuytx/ZENhpe2ySJhhEGRwLXzaxHlm+5OFGER5R eG+X1EoS PCz/EXIRu59LFwOIlm1TsyOTNePjUjxOHjuB1kHBogxqx8dPOeGAnAgcPOIgAxRf7r62stmqYhpOdtPGe2o6kXhUtXVO6QjXV4QtT4vnEELVoWkxxieTaqb3VLkUnhEY/pWDz7TR4AAGPPM7NxIupHanR0mxuC0z1T+kCU4Lq+bREukb2qPS/9wcnI1FQXhEN8deSLpJkur3rDGA8V0Jsq8COhyzGNBFlk7YOBc8G+NPFeF4WiwIt+r0B+B9idhYksTlLd3BsUuDNaZUnGxwZFN0u+fDgrI2rf9uYFgiuiaezGwmCBXIPBhCb/rahDVQ+o8UfjQt9ZuTCR7AySqdQ7N70ZNwKGQcIR8D9Ad58JDuMNACPp/nWJ51aUOrGnosPaw4ZitCT+OjRZQ/jwe17m91q+8E4+UpvQQlx 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 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. > > > > > > > > > > > > > > > + * @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(). -- Peter Xu