From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795984881; b=K8gaiJp+jm0gC2VgZ7YenvFU6di4H8SZyNDkuaunQgpTYzZ6ZioJWu5dLcUSiywQ3qTT n+3rCMfgoqmlIkQkctEpWUZmq/V/yQ1koy3zRWsnBJqCJwkTWZmfK0uNhPw2/IrhkJOkE GDOKsSxeDToCY07cNWdEndLyK6LKYqFpraCpx3NkHW+H9K4Q95iLj0vI/sW1ZPJgkgiu5 SXd/30LDUzwx5ZsIBoAGhT9PKjFHUu0QgKYCHgIha1FRbySYYcSpJS0/mV7VIsJkXhr2n 3QC2ZNVPB+vypQP0KphpzmJFBVA7fVv7WF/kOyCTQRfIwwInwG2yxwPDMkkyrmuDcSw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795984881; 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=w8XdXS0ZQeqoY1FOiYsXmmoui0VIdIdhn7QsfPJFtnY=; b=H40pftuSITffR9ku3tA2rSC0jG+LdKsaipn9oqL7knksajnFy2wFRGxjhbK5L7N5NmQZ Gvf/6FjYsPA2J/y8FWXd7B+QuFlblAe1m4SQ64bjYWfYRhHQnpf2fZtNk9ZFTuJYg38tY xwJWxxd0461aHT7Q/GN9sclnr0lE8g55/L01eK/lJ7Hutq0D/XHc3LfZHeaReoKOyxKQu QVEBffaOtf9/B2RkwdY4xSnAsYtkJmn8Qrkaavq4VV+mKHE84YPOicMUQZv/xHu1uFLx5 F7luDCYELE432PVOGgp2zSh0hxsKOagJxQ9or1wjEfPvJGjepTZ9sOW4PGUW8B0+y3w== 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=f9Vt9Hhm; arc=none smtp.remote-ip=209.85.221.47 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 32EB2606A32A for ; Sun, 29 Nov 2026 20:41:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 32EB2606A32A 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=f9Vt9Hhm Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-4c4b8e58cfeso369946f8f.3 for ; Sun, 29 Nov 2026 12:41:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795984879; x=1796589679; 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=w8XdXS0ZQeqoY1FOiYsXmmoui0VIdIdhn7QsfPJFtnY=; b=f9Vt9HhmSq28pAy3OwEOryZOlyZLkfG4SyXfJiK260XAZAIzloPrl3SFd4uw7Dpfg+ Z98YWUjDuir++x8WPN2dbmwsD0fNu9+HTCy+RHGdg6o0Qdfm941eHlGshpuskNU2O2Ow 8oP9M/zGo0qYqQTbL8BiHxr9ztvJDrMCJeVransxGAr7m7w+Ye0kic6w+fisrONytDsh VpvRSpD1P/YRQpEb71znEXIHgJMZEB9wCScRrGxWP9y3gOZhF3EMh24PTl5PwJDz1Kmn HOcwH/VsSaw3nVg1cljJ4L/LdCO2ucGIWIRr51rgPYoPv/T11Oq+2rkYMcRiM1hTOilz Bp/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795984879; x=1796589679; 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=w8XdXS0ZQeqoY1FOiYsXmmoui0VIdIdhn7QsfPJFtnY=; b=CiTaO6lcOA0FsEKWpXCAov7YsodXBWKAj/dnrZ2QTlD3zpJf0O4nAPkdn3gO5NG3W7 LTfmxG3/qQcW5LK/gxYHEFIWXPdVkEkzfxcxTZez2HrZLDfcTdsQxprqIiFtH3dolbmW /ynbXLmynfxFrvMpccUQaQvSyjISDV15zhsl1pzC/TbrosooO1bf2YyOW8VBhgjCaF81 /lJCzA07cVdRF96tey1kekplH6IwKB9v3JrWJOoZzYWhZYkSDTibaZB+9GGBIGl/oeuo DrW6mnsrS/h/thw7DfygAjAQS2RtcxjX0QMMVXIlFwlCQx7Ad1fzyNcRSScyCx2nSiA8 Wvjw== X-Forwarded-Encrypted: i=1; AL+hErFcZLfywTTnFyLZ2MFFvHXSo68qm3HQoK1vWKM/Gjd/2XEZg8QkIfGFG4Ic+aKfyQKyPBBSCT/ShqOKvk18@vger.kernel.org X-Gm-Message-State: APuU4Z8JBu1qKslvIt6PKjq11SLXezxyit9KJ1Lzc2935QpU4QvNmLho 9jlNP2ecxeAmGzuNS9DyIRHGb3Px9sGJJFUU3Bdd7HspPnhwDcG92k0j X-Gm-Gg: AZFdTZd+eA+z4aKgbvBeJc79/+EOjLe1E7EWigQm7jwIqHeU94OQlF4DXAbmyHz+e4h SdHI0bMlo3GRklrJykH8zjcLAOTygyLODPYunXDxEWw61Ez06qBFYPU/JSISiOdA1ck0WbWUfBN FNLuQf2aSLpa0SYF66c5mY9GvLS1tZgSJYZwB9qiwDoDsVITHrzzpZHJMIl+1SsDbIJ9ZdYSJQu dXbsRtvnd+GFnE2/DzaLmpJwgWamC+WlUARIhjnDsPX6vsfYKpicxoCSI/z3EehymkXcx86x7Kt DjP2IWs/okcCIWNEzOeFugm+80HTf5isL6aPQJadI04xQ0Ud3ngQTJgJ7QjEH7cuR7ImEfeumwN aW7aaiwv3EFQKd3rF2joiWhHklGWLfmYN05TupDxyrGC0I25FWVU/earKyLnjrHO+lqldoiW0kw XtkT0vkb9K0KAWtsbsjZuxtZzVxRRlVD5aKDVDcTBL8DmvfYAX17pX+mwAEBwNDaVkO7HI2xqM0 cV+B5ug3xybt6W6WuQ4R8rYJjB4XaP4ijWCqnfrwIGst2xqM8XGwB5zhCVko0CgIkE/fVhEYbf/ NgUJ/yzg4eapEH7sxhkhl7NB X-Received: by 2002:a5d:5888:0:b0:48c:4a62:9af7 with SMTP id ffacd0b85a97d-4abb70d6148mr54471697f8f.28.1795984879213; Sun, 29 Nov 2026 12:41:19 -0800 (PST) Received: from [192.168.1.22] ([83.231.69.9]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6bc8ce06sm57584924f8f.47.2026.11.29.12.41.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 29 Nov 2026 12:41:18 -0800 (PST) Message-ID: <4db79aac-b8bd-4dcc-ab19-9008eeb8fb74@gmail.com> Date: Sun, 29 Nov 2026 21:41:14 +0100 X-Mailing-List: linux-fsdevel@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> Content-Language: en-US From: "Jose A. Perez de Azpillaga" In-Reply-To: <20261129-fixes_core_3-v1-15-f66094116801@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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? -- cheers, jose a. p-a