Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796126570; b=M+j9OWQTJt/SrMp9PJAWwHsx7TCCLI89/gmTtMAbO6Fed56nMce+OCCoD35tBvmtulbL L2lON0+qnyjn1zQOvLNIKKW86yU6AdCHT5ck50oPcpoStp9DZ40kc1ql5e/CItJf4KHWG yN7exQ2OThKLAlhInjkiJFl16UF7+8sFRqMP+gqNjcf2pNl2KVgCCA5+JSnihdlCw0pGU maoQuGNDNGprCvwPGlgEd2ZZ35ypHB5x2hTLlj9CqSf0vx/iW+SZW4lefSZ9OEXtWu0b4 hs9SR3gs68z3XLHCRXDrtgnE7cD7pP8+JzvVg2htIUrmaBjOiE5m7qbjl2c7SVjs1Jw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796126570; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=PFLXXNGAhlMn2SkemVFES+9JO6OwNT/1b+ah0hEaj4w=; b=vrynLzLOSBEwTKbw+A0jdeGdK8KgvIlH/guImblLTLn6Zc2lLE9FB88hXPZhashHTTQz jhpUi6nnxk4ggIARV2Cr3TkFONhxgUudvZN7YwvSPI9XyOrEvoQwZDPwctwMrh9JT0ugH 2M47jOZBEsne9M/dZJZeGsztRhsb0CEYCBjfoACqDIHsYVUXR1oRO4qAgg7Amj6az4YW7 VUKqvxdzWIwD/b8VgCEtMcgNbk9Hr3j5Vhx7NbuYKWt1g2STeW9WiC2cvcD/7yykADHx8 6rtQZlpMBm+RXaoz/71qFfI/gdUIOETs687CtzV4Ovy6Oz8m+p5oLW8IDKqZX+30wPA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=EtTLn1fs; arc=none smtp.remote-ip=209.85.221.49 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98028606A32A for ; Tue, 1 Dec 2026 12:02:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 98028606A32A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=EtTLn1fs Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-491971ac844so10153568f8f.2 for ; Tue, 01 Dec 2026 04:02:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796126568; x=1796731368; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=PFLXXNGAhlMn2SkemVFES+9JO6OwNT/1b+ah0hEaj4w=; b=EtTLn1fsB4TodKzU9wnVd0cgnacPhGlnTkkrn3Waw21q6zoYpJM+OKyCZYkEs5I/OA kbxkI3HbbeGGDKQeh/jDKy1gjOC0PMUpj/vp+B9f621mtbZpbGIng8eV9EEi2rF0CCs8 bYdyOQqCCTsMocb65vmkc36cmyEtVw9FYBTaL05KgLg2nb5yHyo3AqQt53xQAIVP72f8 4EzWrKcQ9MiQ/0jdNMXJATr4N/Est9o/X0XEe5gYzDylp1RudOmCc0MtkRxbNoHgtDq9 PsLCPprNIptq5efjqNZWIjxmyL1WS9uuwR7s6OEmh1J/BfnIHmJWcLklA0bwb0Kt/jlr HRaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796126568; x=1796731368; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=PFLXXNGAhlMn2SkemVFES+9JO6OwNT/1b+ah0hEaj4w=; b=mlRem2M+KJEz/7/692N/SVOT6YzisKrUspKFq3bNbkwMtjXeCSvADR5srfw2y5YkGf pe40RQJZ14Rghpwy6J+35sUUDblNrW9GdQVpAkTkQUTiKK3uz+6gk5OjEwSihaGa23B/ AnyHK8DqXobhBiSDwudXjvcWieKe70/7Ce/G+MFdAPlLexOFfpa1H27Cvk168niLBkPi NkCAD7al9MuYa8PLZuWIpfWa1aWVGSeeLGg/eDlP2O09Y2FZ0tbt/h4/5ev8XOK/iMEP uan9jEBkVHMo2hYvtUfHBPiuCsXXLJWy53OjsS0n1crulK51d+K50+rze0hg+OMpOmki emQg== X-Forwarded-Encrypted: i=1; AL+hErHpRBdCfi4pnXE1Uh0AWFcPhCFHWEc/kN+LK4x8YzihU5c/1Lswrk4jwODTq5GE/w+qTIxn709JIBU=@vger.kernel.org X-Gm-Message-State: APuU4Z+pTxrV03YW0Kl8k0bPkxYnQ1EmxqZHMOcCt6IR2isxr5/fuOHQ J0kp75qvl84EZCKo8BKJnX+aMJHsGf43hqhjiVoxjOdcnV2TxTx5Q0U/ X-Gm-Gg: AZFdTZdUvX4BFezBQrLiNKLcoencnvGY2+oLcFMoYjZLCFovNF3FPOdyTwsR4byfhDm 44Fh5IQfiOWWzLfZao1T2L5pAHqrMPJq2bLGJwpCARvhB/lpbp+o/Zzu6W30IH4n0kNVPreK1lz 8msptk0nJlxbqlT9UQgS/xN99Yg6y50cazmaVfDHPqnE5mgBbiJ0aVJ9v5/y1+hgoY+7jS3jZjT zmH6mUJUzCckbSlLFmLdawKH9rxOt9xXu5r5WozMrpBOT9EyynSyaItNKJOGvlIUvu/fOIf69hr TQUM4RZmzozOk1wXj8Pnn3bHwhHGDjnJ8ldqc0aiE/ecuhW/v9JcOHndrkJpN3OdRYh3eFbNGC6 ebasJc+Fn0QyDvYVh0f+M8kPBJeDYclFNSS1SNYuSrU9KMendnEs3s+7CrnuAsKb+ey2JrqGeaN pj/b2sdIFz9mq4SpvzKYY8fsnajkeJZCvGMqz4A8zoFJUIy/r2hnKlO2uxY4Lc1yfAMMgG+e/hk gpG9sCs98QfgPV6+oOgwXBVRnjUmhF17f55xYB9T6YKjWFB/vFTCxjCkrZ1oqQvRtT6XxnfLVxm LRT7ggJIweFE4fAGSLW48XMQlYmervETgWzZrywf8ugvT/8Gy+seL3k= X-Received: by 2002:a05:6000:26ca:b0:4a7:8406:1e6f with SMTP id ffacd0b85a97d-4abb0c5d691mr65772785f8f.17.1796126567785; Tue, 01 Dec 2026 04:02:47 -0800 (PST) Received: from [192.168.1.22] ([83.231.69.9]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6a68048esm74100747f8f.29.2026.12.01.04.02.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Dec 2026 04:02:47 -0800 (PST) Message-ID: <499c2776-eb2f-4419-8a89-baae30224a7b@gmail.com> Date: Tue, 1 Dec 2026 13:02:42 +0100 X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 15/32] mm/huge_memory: don't map huge PFN entries if the arch restricts PFNs To: "David Hildenbrand (Arm)" , Hugh Dickins , Baolin Wang , Andrew Morton , Mike Rapoport , Peter Xu , Michal Hocko , Kiryl Shutsemau , Manfred Spraul , Davidlohr Bueso , Cyrill Gorcunov , Zi Yan , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Lorenzo Stoakes , Rik van Riel , Vlastimil Babka , Harry Yoo , Jann Horn , Yang Shi , Zach O'Keefe , Song Liu , David Stevens , Kefeng Wang , Alex Williamson , Suren Baghdasaryan , Dave Jiang , Matthew Wilcox , Miaohe Lin , David Rientjes , Shakeel Butt , Jan Kara , Mel Gorman , Jason Gunthorpe , John Hubbard , Gerd Hoffmann , Vivek Kasireddy , Dave Airlie , Matthew Brost , Joshua Hahn , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Hagen Paul Pfeifer , James Bottomley , Felix Kuehling , Alex Sierra , Balbir Singh , Kairui Song , Qi Zheng , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Oscar Salvador , Muchun Song , Dan Williams , Rakie Kim , Hao Li , Christoph Lameter , Roman Gushchin , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Alexei Starovoitov , Xu Xin , Chengming Zhou , Shivank Garg Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-cxl@vger.kernel.org, linux-rt-devel@lists.linux.dev, SJ Park , stable@vger.kernel.org, Chris Mason References: <20261129-fixes_core_3-v1-0-f66094116801@kernel.org> <20261129-fixes_core_3-v1-15-f66094116801@kernel.org> <4db79aac-b8bd-4dcc-ab19-9008eeb8fb74@gmail.com> Content-Language: en-US From: "Jose A. Perez de Azpillaga" In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/1/26 10:54 AM, David Hildenbrand (Arm) wrote: > On 11/29/26 21:41, Jose A. Perez de Azpillaga wrote: >> On 11/29/26 11:06 AM, David Hildenbrand (Arm) wrote: >>> change_huge_pmd() and change_huge_pud() temporarily invalidate huge >>> entries, for example during mprotect(). The invalidated entry is not >>> present, but still contains the PFN. >>> >>> On x86 with L1TF, we invert the PFN of a not-present entry, which for a >>> PFN at or above l1tf_pfn_limit() points into the lower half of the >>> physical address space, where RAM might be. That's why >>> pfn_modify_allowed() forbids such entries for unprivileged users. But >>> we never check it when mapping huge PFN entries. >>> >>> This was not a problem as long as only DAX used huge PFN mappings, >>> where all PFNs have a memory map. But vfio-pci now maps BARs, which can >>> be at or above the limit, with huge entries. >>> >>> Consequently, an unprivileged user with access to such a BAR can make us >>> temporarily create not-present entries that point at RAM, which is what >>> the L1TF mitigation is supposed to prevent. >>> >>> Let's fix it by not mapping huge PFN entries at all in >>> vmf_insert_pfn_pmd() and vmf_insert_pfn_pud() if the architecture >>> restricts PFN modifications, and fall back to PTEs instead. We clear >>> PTEs instead of invalidating them when modifying them, and mprotect() >>> already checks for PROT_NONE PTEs. >>> >>> This only affects old CPUs that suffer from L1TF; not worth optimizing >>> for. >>> >>> This has low urgency, as it requires a CPU affected by L1TF and access >>> to a vfio-pci device. >>> >>> Fixes: f9e54c3a2f5b ("vfio/pci: implement huge_fault support") >>> Cc: stable@vger.kernel.org >>> Reported-by: Chris Mason >>> Signed-off-by: David Hildenbrand (Arm) >>> --- >>> mm/huge_memory.c | 14 ++++++++++++++ >>> 1 file changed, 14 insertions(+) >>> >>> diff --git a/mm/huge_memory.c b/mm/huge_memory.c >>> index 0b4834f843c73..38b16333d3987 100644 >>> --- a/mm/huge_memory.c >>> +++ b/mm/huge_memory.c >>> @@ -1732,6 +1732,13 @@ vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf, unsigned long pfn, >>> if (unlikely(is_huge_zero_pfn(pfn))) >>> return VM_FAULT_SIGBUS; >>> >>> + /* >>> + * Disallow huge mappings if we cannot reliably temporarily invalidate >>> + * them later. >>> + */ >>> + if (arch_has_pfn_modify_check()) >>> + return VM_FAULT_FALLBACK; >> >> if I'm not wrong, that only checks the CPU, not the PFN, so >> drm_gem_shmem RAM pages lose the PMD mappings too. is that okay? > > I'd say, people running on these old buggy CPUs should have other problems than > benefiting from huge PMD/PUD entries for somne odd things. > > Not interested in adding more hacks to core-mm to make that work. :) > > Long story short: I thing this is just fone. > okay, then: Reviewed-by: Jose A. Perez de Azpillaga -- cheers, jose a. p-a