From patchwork Tue Jan 10 16:31:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 41539 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2846994wrt; Tue, 10 Jan 2023 08:33:04 -0800 (PST) X-Google-Smtp-Source: AMrXdXtlSSycfW5leISkY5RPuuqynBUnmGIbCsg/W+a65fOkaGfNk9wAlunX/Ob6XusSJT+LUyx7 X-Received: by 2002:a17:90a:7f82:b0:226:e11c:e20c with SMTP id m2-20020a17090a7f8200b00226e11ce20cmr15473131pjl.0.1673368384557; Tue, 10 Jan 2023 08:33:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673368384; cv=none; d=google.com; s=arc-20160816; b=F10Yo4xpdVlV/40z+U8uGZaZXhrQMR09hskKZ5UtGJuPKuVBZQEQt7pKvgmU0I0juI GwEJ3JV/h9VmhEA5NjLwbyK9sSDgFAu1fNGtQe5Z/MisCiMmcLbsZm64vNsvlMVFsvgy U4AE1n1GjJl/CZRsmSZsfM8kr/bCOjNoVhQN0ZaKaxK0ZLFketF+8OQmFytLM3zsb1b3 NdOvs7pkGA4hRIH82Dx+cMYGmb2oKGKuXFF0b2y7j0QG0Ocxlj6FO+qc/qo1mTG+kvkN OEFkM68Ut6Ds9mn+D6+JZzNoIU7PGrX1BRt/Y2TELtMvuiRNcdKoqUtR3VIVfhG4HrTL 0JOA== 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=ttxt13H5J51Gqr1Xn/jMJHwCS/g2F1Jlbgm/N+cRYAM=; b=G/1SUDtaXTWBfHvFXi9qzWlPIGY7ueO7v5iLTOBm8SWOmnqMBL2pHt52xArLh/T5/0 7oKMuNo4JD1xpR9o+cUSsI/k3s0q7oEBrLwdV4JjoG1bN9IIC9+8rsW/hQo4dd/oicUt G0Hd7/n4byWTTCKMrgX75ooqOYTmGNzLzJY1VTS4dVw8rYuod5rA0Zv3lOBg8ZkQC/q3 pEjUDn8xF85LV8krr1B5FfZNycFBhfl0z+DVIehgsob3Qm3scuctIdm+r3PVYm8vt2R1 HyeG9i71YaxtHPSM9r8Pvy1no2eCxWrtQPvg23t+Isw4aWGG8MLYIG/mtHNb22O2aSuh e1Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GziND44N; dkim=neutral (no key) header.i=@linutronix.de; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r6-20020a63d906000000b00477c2326410si12320883pgg.298.2023.01.10.08.32.51; Tue, 10 Jan 2023 08:33:04 -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=@linutronix.de header.s=2020 header.b=GziND44N; dkim=neutral (no key) header.i=@linutronix.de; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238529AbjAJQcW (ORCPT + 99 others); Tue, 10 Jan 2023 11:32:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238880AbjAJQcD (ORCPT ); Tue, 10 Jan 2023 11:32:03 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 328ED84099; Tue, 10 Jan 2023 08:32:01 -0800 (PST) Date: Tue, 10 Jan 2023 16:31:58 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1673368319; 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=ttxt13H5J51Gqr1Xn/jMJHwCS/g2F1Jlbgm/N+cRYAM=; b=GziND44NHtHJpTpTJI4rkQlAVdumD7TbsumT9wqcOvkijawpUThT5zg7u9calm0ntwPLG2 Vs9sg/Xdr/waj3vi5xdUf6suWHFVHEYSute4Sot8/jszcw8p8cO0iqIW0GJYNpwY4yJHEv x3nqSJQGTiBYbBk8LbaYf1YUQbr2ez2qmjPZ9U4ruVOVM8rlP1RotXmCeYIIFIjFYC0qvH tOjPL5zkgRrPff0sxhEnNKOV8jEtIgUfJWyDfhA6G/G5SK6TJkJnJXVo6fCGx+jtYLutYa 3meVv/zZe5SUnkyir2aOc72Ve8izqmGWRFrleuOp+1IdP3QiFcOLql9GS/8r/w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1673368319; 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=ttxt13H5J51Gqr1Xn/jMJHwCS/g2F1Jlbgm/N+cRYAM=; b=wZF48rBvO2VBvLT70dlkh7zQyyD0v5rNFM1p8m+F6n+LZ7qD6INSMJ5MdcXD7ifVL6ztpu myMdW2zdLUZtEEBA== From: "tip-bot2 for Juergen Gross" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/pat: Fix pat_x_mtrr_type() for MTRR disabled case Cc: "Michael Kelley (LINUX)" , Juergen Gross , "Borislav Petkov (AMD)" , , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230110065427.20767-1-jgross@suse.com> References: <20230110065427.20767-1-jgross@suse.com> MIME-Version: 1.0 Message-ID: <167336831878.4906.1036202649956155536.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails 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?1754653927450409809?= X-GMAIL-MSGID: =?utf-8?q?1754653927450409809?= The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 90b926e68f500844dff16b5bcea178dc55cf580a Gitweb: https://git.kernel.org/tip/90b926e68f500844dff16b5bcea178dc55cf580a Author: Juergen Gross AuthorDate: Tue, 10 Jan 2023 07:54:27 +01:00 Committer: Borislav Petkov (AMD) CommitterDate: Tue, 10 Jan 2023 17:21:53 +01:00 x86/pat: Fix pat_x_mtrr_type() for MTRR disabled case Since 72cbc8f04fe2 ("x86/PAT: Have pat_enabled() properly reflect state when running on Xen") PAT can be enabled without MTRR. This has resulted in problems e.g. for a SEV-SNP guest running under Hyper-V, when trying to establish a new mapping via memremap() with WB caching mode, as pat_x_mtrr_type() will call mtrr_type_lookup(), which in turn is returning MTRR_TYPE_INVALID due to MTRR being disabled in this configuration. The result is a mapping with UC- caching, leading to severe performance degradation. Fix that by handling MTRR_TYPE_INVALID the same way as MTRR_TYPE_WRBACK in pat_x_mtrr_type() because MTRR_TYPE_INVALID means MTRRs are disabled. [ bp: Massage commit message. ] Fixes: 72cbc8f04fe2 ("x86/PAT: Have pat_enabled() properly reflect state when running on Xen") Reported-by: Michael Kelley (LINUX) Signed-off-by: Juergen Gross Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Michael Kelley Tested-by: Michael Kelley Cc: Link: https://lore.kernel.org/r/20230110065427.20767-1-jgross@suse.com --- arch/x86/mm/pat/memtype.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index 46de9cf..fb4b1b5 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -387,7 +387,8 @@ static unsigned long pat_x_mtrr_type(u64 start, u64 end, u8 mtrr_type, uniform; mtrr_type = mtrr_type_lookup(start, end, &uniform); - if (mtrr_type != MTRR_TYPE_WRBACK) + if (mtrr_type != MTRR_TYPE_WRBACK && + mtrr_type != MTRR_TYPE_INVALID) return _PAGE_CACHE_MODE_UC_MINUS; return _PAGE_CACHE_MODE_WB;