From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795947103; b=U35bEo7mTyHDGnZ2yyqAoiDvAzlVzSFibqsK5puSgVvxesKeJaABhBuU6J/qabiu3Xat Ei0/ObECNY5ZroNd4slqStlpoZQLd87WMW1X2wWC6yBKs7xZbslYrXc3Bf1RFMAq+OkK5 9Pha0EYTEQn1vlrt8GpSiqFY79bnkPkYShHK25UC5ePVJ5+Mu3uE87tMbxNP7855HGu7U WaZDZesANtzGAsh64Tzrh3hI+DASdqQsYR5UMvDUPASR+teE6dO306dyq47vG3W+cHx1X sFkVlP+n8x1j+1qz+ksjITNtraofEDl+qlnZhypD+WBqkaru4uOcDZog/+/8SXQl1ow== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795947103; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=A2kY553suwUJl0h0kmuq9QYP5HlDOjFDuihFbcVHU10=; b=cO+LxOIJyDm5CABxUcG9hb8Xdl707PelDnLSSMsvt2pjHEiGy/g1cqu/8T9XANLYaNt0 GXihgdZ5yXCT9xeIDCmbeJ3FTuiuLkt2msoBb8Ee3Z9m4b+ytI77piTeubAkFC0LOMtNC E36/HjIelN7dEZzKvVCXUAF64zIy3pJRlnZ0M3WsO4ZjY+nuZ/FS8Vljvqo+XNLdjZAqf XW8FNqA9SlO6OFTd3jQKLT9YcP/Zxv/i6/JfIZu7YaKJNh92+r298hSkvQn33qxfQ8Pha 7HYVi3OP8YRKen2vr4CHBn4WhJEDSUVgIgXCrkuQxfK1te8fjQH+8XdOCgWAINH4tbQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BnEflsql; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3CBC606A31C; Sun, 29 Nov 2026 10:11:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BnEflsql Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF3F31F0089B; Sun, 29 Nov 2026 10:11:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795947102; bh=A2kY553suwUJl0h0kmuq9QYP5HlDOjFDuihFbcVHU10=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=BnEflsqlqsoJ7W5N6FCuVXmqKr1y0+i+3x6pmBt1DdEjpKq5EoPZ6VJgTYikSUhn1 Vb1lgTD5+4kAz1do2cuSpFY3UTY/bUkn4vlqQde1q2V+PA9GXucPCbe6YaIufq/AKE 3GVHcQU9mXuPYqAK9oM/SI+8BsZd+NAO+iO0iLJ/HMJODtD5IZMty5jZEO31tjYbNq 1lgA8fSmowtjmWsCE6/ZMFLhYWWTnVFTN79nDuC1Guln0lG1rhQYQlH+s9lkuXyQk6 loqYKVc3UR9CtxIzx2X/eOaLV3qc8sxpayZa0XG1yMw+SiswQ3nlWmg23m/KXmS+s2 JiZXw18SSvEJw== From: "David Hildenbrand (Arm)" Date: Sun, 29 Nov 2026 11:06:46 +0100 Subject: [PATCH 15/32] mm/huge_memory: don't map huge PFN entries if the arch restricts PFNs X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261129-fixes_core_3-v1-15-f66094116801@kernel.org> References: <20261129-fixes_core_3-v1-0-f66094116801@kernel.org> In-Reply-To: <20261129-fixes_core_3-v1-0-f66094116801@kernel.org> To: 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 , "David Hildenbrand (Arm)" , stable@vger.kernel.org, Chris Mason X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2779; i=david@kernel.org; h=from:subject:message-id; bh=JXLuyY6j8R74YUHpvUM2EWezeQOl6lWjbPNH5I6VxJ4=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLK5f+qk2dyRZlxYk/UsQ+f23qK892178ydPf5DtZxUs5 tHXztbeUcrCIMbBICumyBIUfN/g5ct1tdVufMwwc1iZQIYwcHEKwESy3jL8ZMy3zjTMOvqu/qlj wCEv/rKML48VLUPfWz107mWYXexkz/C/2uPz/OmxLw995b3wks1c+NBj5+3Tr3DoN4gmaixce8K FEwA= X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A 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; + pfnmap_setup_cachemode_pfn(pfn, &pgprot); return insert_pmd(vma, addr, vmf->pmd, fop, pgprot, write); @@ -1848,6 +1855,13 @@ vm_fault_t vmf_insert_pfn_pud(struct vm_fault *vmf, unsigned long pfn, VM_WARN_ON_ONCE(vma_test_all(vma, VMA_PFNMAP_BIT, VMA_MIXEDMAP_BIT)); VM_WARN_ON_ONCE(vma_test(vma, VMA_PFNMAP_BIT) && vma_is_cow_mapping(vma)); + /* + * Disallow huge mappings if we cannot reliably temporarily invalidate + * them later. + */ + if (arch_has_pfn_modify_check()) + return VM_FAULT_FALLBACK; + pfnmap_setup_cachemode_pfn(pfn, &pgprot); return insert_pud(vma, addr, vmf->pud, fop, pgprot, write); -- 2.56.1