Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7381193rwl; Mon, 9 Jan 2023 23:22:34 -0800 (PST) X-Google-Smtp-Source: AMrXdXuFaJuBJZ8+mGoDWIBIDHdOS7e/Te03G5eL7+8YuifuTnZj6iREYvPOAOU1bJRYh/bmtdUr X-Received: by 2002:a05:6402:299b:b0:499:70a8:f91a with SMTP id eq27-20020a056402299b00b0049970a8f91amr6805323edb.19.1673335354624; Mon, 09 Jan 2023 23:22:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673335354; cv=none; d=google.com; s=arc-20160816; b=wZRpaGaA27oZQtPoAY9CdNc5ojDZTx7wTNPLe2qHSvcv6q/mGFNi+gkIrKzOmEYNrJ 51yVg3QaCr8f9Oa8v4ncPVoCaxGJ/9wcSylpjFPu5tRgnuuxYNjGbQ7DsfU5kGhZsA9d 3Hrp8LtN76VvN7R0OfpLE2TD416oP/ZsuvApo5EnU2kGzaXC3rKJyahvZd5zQRI2zJju rlmFwUV+PZGCqxQMQ4BNNkZ8LU1WUfbqJmHbN6R0P4ojERXznG2CCO1rTI+x73J/cfGS wAKd33Rae/2Av22r589judonv4SUHoxLADHTCzctvG9cWo6osnja3v0i3Xg9MAcXBYrp Xa4A== 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=EY5VTFqEZnBurGAFOn7Hf0q4d99CjK26BXkX9qKxYzI=; b=KZzPshiVSgvLgJIW447DAQ4SsFAd1R+hyTHOIQ+LzT0YJIcSV6ZX29FqUMDMxXS+i7 K6T4y6xtXch9N1iHtrE7VY7JM2EZUk2PcJG2hFSEWhi+qhXLGjUrUGo/bTgWlaIGP5bf 1Jdv7BKsEybG7gmmgiyLzuHadIf04ZO3ddVLGHyJ9OkBEBKKZzQaKTu1jWZ4F1qA16NH LK7NIvN761zUGuhXJxQ/5kJl/XyxSM2vXIeuC4CokZrVeA8xHWWP0LbWCNzoMchJiq+B MfAS0hLBgS0kZl61f6YOUB25bYuCmAqpEUN8mGpmzspaWkrtDCNM8RGE2RYFbE1Ajg8i Cdfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=uCasEm8p; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bc25-20020a056402205900b004542c9947c1si10464291edb.217.2023.01.09.23.22.21; Mon, 09 Jan 2023 23:22:34 -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=uCasEm8p; 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 S230123AbjAJGyi (ORCPT + 55 others); Tue, 10 Jan 2023 01:54:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229727AbjAJGyb (ORCPT ); Tue, 10 Jan 2023 01:54:31 -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 EC1666329 for ; Mon, 9 Jan 2023 22:54:30 -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 0DAFB4DF19; Tue, 10 Jan 2023 06:54:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673333669; 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=EY5VTFqEZnBurGAFOn7Hf0q4d99CjK26BXkX9qKxYzI=; b=uCasEm8pmLDgbmNRkOO2o0yoCwC7zvpOG0NPvrbSwLbuuhPWzB8Y+xF4BgoTJNpEq4fNEl cVL/mwX0zuB609+SoTlHs2FvOyGoa97lYSQ/H9iAnpAJ0KtmnvKMbpy6N627DNzF03jEpU VaKzrQAXDZLB0BG5xT8xAo2QysnUvOE= 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 B049113338; Tue, 10 Jan 2023 06:54:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id z5GqKaQLvWN4YQAAMHmgww (envelope-from ); Tue, 10 Jan 2023 06:54:28 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: mikelley@microsoft.com, Juergen Gross , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Subject: [PATCH] x86/pat: fix pat_x_mtrr_type() for MTRR disabled case Date: Tue, 10 Jan 2023 07:54:27 +0100 Message-Id: <20230110065427.20767-1-jgross@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Since commit 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(). Fixes: 72cbc8f04fe2 ("x86/PAT: Have pat_enabled() properly reflect state when running on Xen") Reported-by: Michael Kelley (LINUX) Signed-off-by: Juergen Gross --- 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 46de9cf5c91d..fb4b1b5e0dea 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; -- 2.35.3