From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795984881; b=gTRbqE9/IUP/R3RAkpQUpMJUx3j0S4cWl/XZnCzIKitxYZcOynVKNK/FYz8Jy+IzicPx oaC9UQpevsNb8pz/+lLlJYUvt4HOkws0ib9BiNuGro3DHjA0RIJ1GjgC8tlPl4bEnGU/o M3+/3oTlzObWACiZ3Zq/NL0OG0iyiWcAeqpVwh35h87xxzoCMO3KWK10qXw8IhE1++Bit 4cT1lP5POWwyAz7ANVJ4LFPO3we0eZNZ//FDFTnaXo66jBIxcbO7Qky4NSgClf/XMr+VE t6xvAJVvFVG0LttVir1+zhLcPt/LXYkEX/CHoJyo3dZqsvziCDDvxTErsxyJg4QuBxA== 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=yUuMdaplI9X7hMk49DYjsVYuHLYIfjHjh1dN+0Yb/gij1vDvPJAwg7JM11JXO6U9erGT XhUkzST/Zu2/epwQqQxHyBGTGwLRtotHZbOFWvicbyBMzOoow+b+Sc1zST3AI8XIEzsxr TNLPPXn5238BvLXXFC3oohHf0q3ppvkVQEIjMwucsPrqCXH+/UQXB+YWevLQHbLShTrWc cv970AOJ6raSdIhJC3QQ1FV78DSyTZDrtZ8rR2gGQuZfpuj0kJlkMhK/7SjlK0pSdAv9x 7djKemHoF7eH2XykavMWqgJOQQY9mnMFoQ5Npyj8EJWkwPgsYiIVeqNcFxWRxrGGWcg== 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.42 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 29294606A325 for ; Sun, 29 Nov 2026 20:41:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 29294606A325 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-f42.google.com with SMTP id ffacd0b85a97d-4ad6219f7d8so8875129f8f.0 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=whIwGiKYD7oQpX22iYmPDHEVAvgHzZU+WFONCOXtkii9bUhudLG+R5HuVOJ8vUQrlg 55cfOOq/fSGeNPEPIla6gSziC1X+7xi+8m1aTqWnCs6/N31/De70COzUDVtdRBQ6vdzT SEoHbeDzkl2ykeG18wFedKINGSJ4+Nse80QjmpRtOy6+fqZzqZDUL++a2fb195Ahf5ju qcQbD4IWoy8Urp+FgtBU3EdwapvzvpENXm3RMsDNKbq/fiiOruyiJXCMbruPJvB8x1X2 o4mQEIyVxsJCKvCatQ8xgY9wjFm3N+qeZJfpfIKchCPx1jH/+C3mcBR610zqzPTA+YJt aHVg== X-Forwarded-Encrypted: i=1; AL+hErH1Y8xot6Bw7jo8Io5tWnOZvBIvzsai9w2IDDdlsm9HV92WB1WMvwvBiKVlw5p8T+O0CUgy8GkN3oJplNc=@vger.kernel.org X-Gm-Message-State: APuU4Z8tDYOhwz2v48XyqqQ3YZa8eOm8Qw8Px1+0YKzLoglm/5q25k5V UXMtS71s/hlmePyqKMGd8CTt+NoDHXMpqBOFFLJXuWJl1XmQHywyOgUn X-Gm-Gg: AZFdTZeHc9+frzp9a72MinqDnj+36XfN9AtN44qNTmiST224nr1zDTJiFzqYoc7zYw+ 4qpW/aoufd/2ijFfl5C2KYbpS7eBQn3LF8PLPi0ukNTq3Sw09bVtn/soLkhEuONG3eIlbUKpMz8 B7e+FVMPvwPiA8bxSii5z51iLCYdTpWpJvdu8k7qoGmI3jpfqR+mQgjReU9Q9oGZJ6k18vELFO9 uoByJWcinZcDHFQo2V7L66/YFPA9X/HPrsM3gzMYX3bd/WjkCBDdzvWUvIFFyuuDTjREsO4SwsU 9ZH9qfJLojIsyFahZRvEiBph4mqEAGy3B+VDt3IG0BtocK1KC2QNN8I+ndxldSmyQA2osYzoGbE zNbjXN6pbhBi4XzLl5DX9wsvWmQuI6igblCO1Lg9DbptB1GwPCFBv9OQLhVMjbUDVpnOyfzmdJD KIJtMIsbxXHTnchwIEGzZM9SICl5+HkrNFupy0JP8iHE7yFLVOVOnRdgoa36txt9McTM5VQIcyN oSq1jhFoI//eQgRPNgWpLP/3PpEVJJVSReM0Tn/uGCT/ZUM+mlJf6+sMCPGRFlxZ9mo8EyBzD9O zFgZZdtl6OiDkLT99hktwuEv 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-kernel@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