From patchwork Mon Mar 6 12:32:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Gross X-Patchwork-Id: 64631 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1818396wrd; Mon, 6 Mar 2023 04:48:08 -0800 (PST) X-Google-Smtp-Source: AK7set9GOGh0fRt3aAhTHSTRWVcHnUQg8pay/4i2T5xkoe6iJUCoJRtESMGcj+OEed6Eik+nHZGs X-Received: by 2002:a17:907:6e01:b0:8e0:4baf:59d7 with SMTP id sd1-20020a1709076e0100b008e04baf59d7mr13507093ejc.31.1678106888194; Mon, 06 Mar 2023 04:48:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678106888; cv=none; d=google.com; s=arc-20160816; b=Zv4k/wDtMH9O+Ozr7v96o5LiOnjOaEpj1fVuB+k3bHKEu48kR7fm/VK9POp/B/Hofb o/9F4JEnkuweuLDsXzxsyvXgHWNFrso/SFiOBZtO5BbsIh6MSrOG4IGA5xEc217nXaq+ 8Xzc1tA2B8iQ0xaigEWwCTGN93cJF/3iCwFLLZFHRFo7jF8eH/aChn6A948RJFkNRpj9 uWIjKXjCE4O3eipgoRx0BNiYBWdl6R1TV+psldxhiE3ahRBxOFCcEnMU3Y0rG0Svave1 48vHq+J88hcXinSATMZlpYoqh8ariN7zDsC7PMVJndZSh7GsWLmTEIvnGGSZ3jBjod6s U/MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=s/y2FB1IEinG/gjbF3dWgVIgpuliqb+hlxxRtawK2eA=; b=KFLHkBglnulyfB1UYDIO/Yb9/JCvxYs9dYT9/twI65RmHzAgF//aceeVw4I1QAGnXu Werc0xTfm+ayrHV7XOH91no/P1dkIiaRIkoLl/XEwkXmhUwHb2OXoc6laDQy7LJOZEmp NqGi7CSmXpu0qSvindHA8v1SDvjArLZvDXv4YvXUuRn2kef0Mu2ZqZYQIsNfN9SXrbrM vnmGSxJbhUKPqoStqF5ZMUgUSXN7LPftwwhjJxKaJKXFRyNy55FCChNzDCRw/1nIYJUA oa0opD8Y2mfFK15gcY+jLVlQ5wbcQWKw51QDOiq4xW1pO14JwxWP2+rbvdDxWsSHkGCi ZuqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=faICikPi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b11-20020aa7d48b000000b004aeeae11454si6872527edr.140.2023.03.06.04.47.44; Mon, 06 Mar 2023 04:48:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=faICikPi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229876AbjCFMdH (ORCPT + 99 others); Mon, 6 Mar 2023 07:33:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229528AbjCFMdF (ORCPT ); Mon, 6 Mar 2023 07:33:05 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FA68168AC for ; Mon, 6 Mar 2023 04:33:03 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id CE2792226B; Mon, 6 Mar 2023 12:33:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1678105981; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=s/y2FB1IEinG/gjbF3dWgVIgpuliqb+hlxxRtawK2eA=; b=faICikPi51lggIWUnCQqbqaFDK0qngZeh29eI+w4D9/imVpUV3o4yqXNpVh4m30qRky9cL aETcAJuvTdBQ8zzMB6RAjbCX3hrZA8Pc7PWUwcllFLsoRgASE/Z6utkY3bbAvL1WH96qEp xP6QCSRkjQMqq9+tQrrGPUr0LcN4S50= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 910CB13A66; Mon, 6 Mar 2023 12:33:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id BTEdIn3dBWRxQAAAMHmgww (envelope-from ); Mon, 06 Mar 2023 12:33:01 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH] x86/mm: fix __swp_entry_to_pte() for Xen PV guests Date: Mon, 6 Mar 2023 13:32:59 +0100 Message-Id: <20230306123259.12461-1-jgross@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759622607948584541?= X-GMAIL-MSGID: =?utf-8?q?1759622607948584541?= Normally __swp_entry_to_pte() is never called with a value translating to a valid PTE. The only known exception is pte_swap_tests(), resulting in a WARN splat in Xen PV guests, as __pte_to_swp_entry() did translate the PFN of the valid PTE to a guest local PFN, while __swp_entry_to_pte() doesn't do the opposite translation. Fix that by using __pte() in __swp_entry_to_pte() instead of open coding the native variant of it. For correctness do the similar conversion for __swp_entry_to_pmd(). Fixes: 05289402d717 ("mm/debug_vm_pgtable: add tests validating arch helpers for core MM features") Signed-off-by: Juergen Gross --- arch/x86/include/asm/pgtable_64.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h index 7929327abe00..a629b1b9f65a 100644 --- a/arch/x86/include/asm/pgtable_64.h +++ b/arch/x86/include/asm/pgtable_64.h @@ -237,8 +237,8 @@ static inline void native_pgd_clear(pgd_t *pgd) #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val((pte)) }) #define __pmd_to_swp_entry(pmd) ((swp_entry_t) { pmd_val((pmd)) }) -#define __swp_entry_to_pte(x) ((pte_t) { .pte = (x).val }) -#define __swp_entry_to_pmd(x) ((pmd_t) { .pmd = (x).val }) +#define __swp_entry_to_pte(x) (__pte((x).val)) +#define __swp_entry_to_pmd(x) (__pmd((x).val)) extern void cleanup_highmap(void);