From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795984882; b=u7u4BA1O1/Kj2RVGR2dkwkoSjowGyaQEVj1xTltZvu/MKxouF4LavzRYzf+RM/HJM/ge kNFplaBMOOvNYvEydGtTNSfVff/iccxCBZkO/OSGJAgsQbtRxGG1Zo9rr+kfNNaDeUa4c FaSMXVkXsc88QN3yt7LjCvQI378LTWLC0v8FclnxW5kJ9vsjbtdxF0iZDnwZkmc9UG3As wCRQh4hfxajsirYSQ3zjqxoEh60ZYkHeJR5GLmO/INv/oV1GGTLacjvA3a6r20uK9iwxO tmw9oVyrCfZH7WimXP6xqp6plOUNBldEZtht3ougoRdXHK0lilJj0bfmzRQRBM0arVg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795984882; 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=4wD3a4NNYVE2mnDB0Z1pex6sjbhsZr9tk2by28TJBuAJeuU9yt1x7zKk3R198KseH94n UacQSkmuPu0UnqhrsLanYs5LF/HJn5Kqq4oprC4r3QRQv1VS//3aGrAni27s3eZii6ajc 2sdy1SBcBqxJvLXmscZXwLNpq2IhCJayYFWyhV3JJOvWOT//4g/3y0CnD23JONog3Hxdq J1zuoAkuWxcvPiZItO6F5Co3PaXV8XRC7wrZlsmxGvMXsMy0jNyoLtZp3/+P1mDJsl3VQ 0YUP5CmttdiVPq1bjLTeaLl+ajIipKF4mubZV4kWJ68Ideh21D9NWjyWWZKkXXT1C4Q== 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.53 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 2931D606A327 for ; Sun, 29 Nov 2026 20:41:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2931D606A327 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-f53.google.com with SMTP id ffacd0b85a97d-48dfc0421d9so8867553f8f.1 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=ieHGzu20XFnhPbE5UUcxXXvX+vyPeHl/EXZTWwXnonqD8PKbvM8Izz3f3ETweu8ayv 1EDwbkVjaq+lqkHoxZSaT/I+loKU71wT/T0OUlBiTPlNt7cqC7Uqvu9/u6Hh1hstdDvC 9G+L7IzAiCoAOuQPBLkrJ+clqXIdl8T3wofggyw+WrA2ybNJqtmecrMygwkBQxUNix7f p2tONlyX33UEvAllfk321+HA0NV1UneZwhnidGTisyKAAHZ+QmuocRQh1PjYUuR8jila 5nVwQpIS/zUPFl0+vFb3ug61QWgFGg+/0T1kQf+ddOT4j/NcVbioG0LoaxHItMaCBvH7 PAfA== X-Forwarded-Encrypted: i=1; AL+hErEwQ02/4Z76TaX1enq1qCom0+uSCp3q5v6oUXDGALDl6bhRwl+BpOxJQfib331hFXqDryTrhZY=@vger.kernel.org X-Gm-Message-State: APuU4Z+CerxZGztlx/CSfqvcARCRvnvV9hoIHCOxr8XaSXZr+Du/v2Vs 0i6vLxhQwfvAXrRBbnUJxdieTRfzAPD7B5XTYPxTz6TPbs0a3n7KwSmm X-Gm-Gg: AZFdTZdzb8yidXeH2i0KC/R9meysjHV4ccDgwVvSWzkC0gYISZ3kKzybndwwGLav52S TsvCJxCEtyyIAz33VKRAi5M/6F9O7TBkTuEiFl7jYctYE+qkQHBxOFRSDsw2YY5tAFrnES9TMCu GIwTfq+zW0VM1fLH0aKUY22xODRe6RcFVHM2TW97yYbrKJfXByshkKVbu24BP8w9TxQgNWaGGvb 2dTDR5Dc5Q/Lf5uCGjvuG8qupHUWkk72/G7HwHWyh4mbCFFtK6I97hIdvZwKT1KBQbKnUoTYQ3T BmmFFP3MBF0pMRMrAurQD2sIN/bresE0ahVjjT9cor0fU8TRtgKbahqSOxoqTNVHO1T+cQErZkB pz7Anl3tLbo+CBhdiH2pUqYWEC6GsQ6+18EJrVNywRKUDonYUzFDed7S5enWQToRctYGhT55tdw 8fQV4E+NdEuIAi5nCC+wzfBB7Y1asqKldYQdkmJr1+PiP0nhqCyi/o65FsDrjlhttOLfXrl5+2M vcmU0bnQ8NWp6S2f1uAyu7L7wofVhW1Mo5ybE9Ptc3Jh0bqk67B44mhM1wUX4yUckspTdPXEhBG LWHW6nj2hDNfqXID+YA2PKJI 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: stable@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