Message ID | 170073547546.398.2637807593174571076.tip-bot2@tip-bot2 |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp348278vqx; Thu, 23 Nov 2023 02:32:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcWTwl5K87nN1MsP+KbbJNcFbx4/+p5Lw5diuDklcwkrQBOPvhpsq5i2mt2EmrpbKQa0m2 X-Received: by 2002:a17:902:bf4b:b0:1cc:4eb0:64cf with SMTP id u11-20020a170902bf4b00b001cc4eb064cfmr4558729pls.52.1700735525804; Thu, 23 Nov 2023 02:32:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700735525; cv=none; d=google.com; s=arc-20160816; b=TcTrlLDmd7VLzxfPe0zk6rMb/HXCrFh1vzujLN1QyaHVCqpFkyphI4CSyk8Z2ZW27L cYPrCWUQ+95lIcB2riSK8FoGzWOddzXqLN8cx+OJsDmy4R60f8z3XdJElPXnB4Yg+dFg 20rSSxruvnpYeasgAsoraxj/drgDIV/FCmbrl67JnnVrsXmTZ7HbkTX7MVyrea2ntyLb W05dN746NuCt5PGhPEuIOSkS1ny2dgMCmqbox0NdAJfBRNICozJCWlq2d/6/sb2BNicG XIXt1BJb55reQ0QLzknCNxZ5BZ6fwtXzo71fh3A2S5GK3ycDSeFdj+R9qGRcPxmEAGCG 4TQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=lGiLDGmbqrWlSjfhkQgPnYZ8qvWq9oDF9VGMNYqyrrM=; fh=G2l4zxLS5Nu3fV3h8GEg4oukFtsSa1ghTB+y279seUM=; b=hI0yAcIxeD0y4bojoBwevMnzw7nwIGa9XyLQlv2TulCnRcs5MQt/2BTG51ONc0Z9Jz M/U5CcZwUj3FUH0h5LXZL6HYzgxBq7T4u8U50NfyD5fqhc45DN+xYLfNK6PNrDzMaBqg NBPU/GME4urmRc4sSpy3rx4X4iMoMahaDU24y3VbXAfKd3vnPAuayfrh/yajcdTx4X1l pdLzxZM5LtnezKpw43bfcMrYwE84q5c51rubZom2Zy51DfwAwpDQAORobReNBcXboozN dIdZfaNxjpBN94HSq9Rij9ogaGJHqQYPXECMcE6Bjzdss3d4sSQfffpGR7WdEWnpXgqi LKxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zDSlhhUk; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id x19-20020a170902821300b001cc30cb3f9asi837689pln.14.2023.11.23.02.32.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 02:32:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zDSlhhUk; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id E07FC83212A8; Thu, 23 Nov 2023 02:31:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344575AbjKWKbN (ORCPT <rfc822;ouuuleilei@gmail.com> + 99 others); Thu, 23 Nov 2023 05:31:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229477AbjKWKbM (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 23 Nov 2023 05:31:12 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A74D719D; Thu, 23 Nov 2023 02:31:18 -0800 (PST) Date: Thu, 23 Nov 2023 10:31:15 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1700735476; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lGiLDGmbqrWlSjfhkQgPnYZ8qvWq9oDF9VGMNYqyrrM=; b=zDSlhhUkPXrzP8nf2RHbRQ7QC3w8aKKmUQ2PtJaeIJ3iA3F4zIDPGhGha6b7EovSNZPGNK y5p+K63x+0jqu6e+kbw08RcFqVtCwwHS49EhicvTAZOutuY8FO5iifRbz4YGDt8GOaCZjB z36gGiSaTR3QLylKsth6RDo5V9YS1RUJv1Z8gQ5W0VD5s9qR6ZuhjdXO6ySebxUYJKumCY ao6b//fYnB2dRSFH2hkAIPnd3V3AnQctBbuY6Y/PaleKLABZb9hSEaoR/8XhuHAcsO+jcv WHSovPEmtUHeREE2qwlU7KIjabCvmjDSJk/BAFMh0l2bMJFV0Xosgs+khhjLgQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1700735476; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lGiLDGmbqrWlSjfhkQgPnYZ8qvWq9oDF9VGMNYqyrrM=; b=oiJLfsg/JzQBjq5/beKwYJ+STInXf6rZ9sGhMDJesGJDliSdLwI7T0izhWq7N6ndofhSYj e8Hrnt0HgoxwbVDw== From: "tip-bot2 for Michael Roth" <tip-bot2@linutronix.de> Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/mm] x86/mm: Ensure input to pfn_to_kaddr() is treated as a 64-bit type Cc: Dave Hansen <dave.hansen@intel.com>, "H. Peter Anvin" <hpa@zytor.com>, Michael Roth <michael.roth@amd.com>, Ingo Molnar <mingo@kernel.org>, Andy Lutomirski <luto@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Rik van Riel <riel@surriel.com>, Linus Torvalds <torvalds@linux-foundation.org>, x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231122163700.400507-1-michael.roth@amd.com> References: <20231122163700.400507-1-michael.roth@amd.com> MIME-Version: 1.0 Message-ID: <170073547546.398.2637807593174571076.tip-bot2@tip-bot2> Robot-ID: <tip-bot2@linutronix.de> Robot-Unsubscribe: Contact <mailto:tglx@linutronix.de> to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 23 Nov 2023 02:31:26 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783350454561072171 X-GMAIL-MSGID: 1783350454561072171 |
Series |
[tip:,x86/mm] x86/mm: Ensure input to pfn_to_kaddr() is treated as a 64-bit type
|
|
Commit Message
tip-bot2 for Thomas Gleixner
Nov. 23, 2023, 10:31 a.m. UTC
The following commit has been merged into the x86/mm branch of tip: Commit-ID: 8e5647a723c49d73b9f108a8bb38e8c29d3948ea Gitweb: https://git.kernel.org/tip/8e5647a723c49d73b9f108a8bb38e8c29d3948ea Author: Michael Roth <michael.roth@amd.com> AuthorDate: Wed, 22 Nov 2023 10:37:00 -06:00 Committer: Ingo Molnar <mingo@kernel.org> CommitterDate: Thu, 23 Nov 2023 11:13:21 +01:00 x86/mm: Ensure input to pfn_to_kaddr() is treated as a 64-bit type On 64-bit platforms, the pfn_to_kaddr() macro requires that the input value is 64 bits in order to ensure that valid address bits don't get lost when shifting that input by PAGE_SHIFT to calculate the physical address to provide a virtual address for. One such example is in pvalidate_pages() (used by SEV-SNP guests), where the GFN in the struct used for page-state change requests is a 40-bit bit-field, so attempts to pass this GFN field directly into pfn_to_kaddr() ends up causing guest crashes when dealing with addresses above the 1TB range due to the above. Fix this issue with SEV-SNP guests, as well as any similar cases that might cause issues in current/future code, by using an inline function, instead of a macro, so that the input is implicitly cast to the expected 64-bit input type prior to performing the shift operation. While it might be argued that the issue is on the caller side, other archs/macros have taken similar approaches to deal with instances like this, such as ARM explicitly casting the input to phys_addr_t: e48866647b48 ("ARM: 8396/1: use phys_addr_t in pfn_to_kaddr()") A C inline function is even better though. [ mingo: Refined the changelog some more & added __always_inline. ] Fixes: 6c3211796326 ("x86/sev: Add SNP-specific unaccepted memory support") Suggested-by: Dave Hansen <dave.hansen@intel.com> Suggested-by: H. Peter Anvin <hpa@zytor.com> Signed-off-by: Michael Roth <michael.roth@amd.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20231122163700.400507-1-michael.roth@amd.com Cc: Andy Lutomirski <luto@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rik van Riel <riel@surriel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> --- arch/x86/include/asm/page.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
Comments
On Thu, 23 Nov 2023 at 02:31, tip-bot2 for Michael Roth <tip-bot2@linutronix.de> wrote: > > On 64-bit platforms, the pfn_to_kaddr() macro requires that the input > value is 64 bits in order to ensure that valid address bits don't get > lost when shifting that input by PAGE_SHIFT to calculate the physical > address to provide a virtual address for. Bah. The commit is obviously fine, but can we please just get rid of that broken pfn_to_kaddr() thing entirely? It's a bogus mis-spelling of pfn_to_virt(), and I don't know why that horrid thing exists. In *all* other situations we talk about "virt" for kernel virtual addresses, I don't know where that horrid "kaddr" came from (ie "virt_to_page()" and friends). Most notably, we have "virt_to_pfn()" being quite commonly used. We don't even have that kaddr_to_pfn(), which just shows *how* bogus this whole "pfn_to_kaddr()" crud is. The good news is that there aren't a ton of users. Anybody willing to just do a search-and-replace and get rid of this pointless and wrong thing? Using "pfn_to_virt()" has the added advantage that we have a generic implementation of it that isn't duplicated pointlessly for N architectures, and that didn't have this bug: static inline void *pfn_to_virt(unsigned long pfn) { return __va(pfn) << PAGE_SHIFT; } #define pfn_to_virt pfn_to_virt Hmm? Amusingly (or sadly), we have s390 holding up the flag of sanity, and having #define pfn_to_kaddr(pfn) pfn_to_virt(pfn) and then we'd only need to fix the hexagon version of that macro (since Hexagon made its own version, with the old bug - but I guess Hexagon is 32-bit only and hopefully never grows 64-bit (??) so maybe nobody cares). Linus
diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h index d18e5c3..1b93ff8 100644 --- a/arch/x86/include/asm/page.h +++ b/arch/x86/include/asm/page.h @@ -66,10 +66,14 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr, * virt_addr_valid(kaddr) returns true. */ #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) -#define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) extern bool __virt_addr_valid(unsigned long kaddr); #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr)) +static __always_inline void *pfn_to_kaddr(unsigned long pfn) +{ + return __va(pfn << PAGE_SHIFT); +} + static __always_inline u64 __canonical_address(u64 vaddr, u8 vaddr_bits) { return ((s64)vaddr << (64 - vaddr_bits)) >> (64 - vaddr_bits);