From patchwork Tue Feb 7 07:28:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Gross X-Patchwork-Id: 53765 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2708288wrn; Mon, 6 Feb 2023 23:51:09 -0800 (PST) X-Google-Smtp-Source: AK7set8g3PPsEs9WXOd1ouNcj5xIx/Fs/jeqLKvEfEEEppZEA3mlwx2+bjAwdw4vW4mOZarfC40c X-Received: by 2002:a17:906:f8d9:b0:88c:a43d:81ba with SMTP id lh25-20020a170906f8d900b0088ca43d81bamr2339473ejb.11.1675756268868; Mon, 06 Feb 2023 23:51:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675756268; cv=none; d=google.com; s=arc-20160816; b=hH9S5EvDAncjNyCMxfGFVGx9Ahv2UAEqG9yzN6ca4wl+wF/m17UvPzvfxK+gL5NRWe LNv3ZEcCzNk2gCIjI0JFLoLYWvt5Yk/f53FmMaFGmuo3L0vzIA0SOvMcyc+qud0wnVrC AmZtDQeVtlGksDJNDPdlvKqFVeTZPr5nq3decENoYsAhYlgEdGTFSMmBO1dgK6ZsNWmX YKUF4MHNO0mxvqfEqVomeAnyOvkJowEeWYYw64OVuTLXHu6sbfQfBeQ0WyVZxPn9cNyi Mi7hSKm9at4gQCpQw3ZboEnSTEXXUBrWDQGNj6g4IRE/tEMSjbUp63JUNcU6zY1KJ8Zt dr+Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MDR6p3EEVdt6aI87yhW7ogY5yoUM9JM3hkrFmMLxzCQ=; b=tWd+oaeOqcpBKagFEs6tmiUaNW/JKD5mIGTt38yeL2QQtMm7POvZdQ4nb1I2Ek24pO WGlOhqiHXz2D612YD8dTNCxft5FFGA0UaOXcRBoSjt/B3cg15bNS0UadIYlghwBnINZy SGR0lpyn5n2vHgsJxN0Jn9wKVs0dlA+HiqW0pAoa8Ry9Fmx2LbY7Dc0Vk1uUuBw70VZx Fs9uRMLy7odrxAXi35hyQfj9oG36X6xg8OOvmCSCjWEHM2EaK6y7/qrxYM4SYfuIksxy 9XQUfX8xDCR+Cxy+h46OU0CUP4UfCVOt+QKdBKrU2y957K2ex4pmRwpU8kLAbMPLSVIF gRZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=tDbv7vnL; 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 gj32-20020a170907742000b00880823a20a3si15195606ejc.120.2023.02.06.23.50.45; Mon, 06 Feb 2023 23:51: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=tDbv7vnL; 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 S230193AbjBGH3Y (ORCPT + 99 others); Tue, 7 Feb 2023 02:29:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229890AbjBGH3T (ORCPT ); Tue, 7 Feb 2023 02:29:19 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA67836089 for ; Mon, 6 Feb 2023 23:29:17 -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-out2.suse.de (Postfix) with ESMTPS id 68AE860F1F; Tue, 7 Feb 2023 07:29:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1675754956; 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: in-reply-to:in-reply-to:references:references; bh=MDR6p3EEVdt6aI87yhW7ogY5yoUM9JM3hkrFmMLxzCQ=; b=tDbv7vnL7LeZnXzm7xPgZ0dgekKLu5Kq2IaGD8+x2/lhyO2fRjp33UC/eYHyw/oto49Z3l ui0fwheHnag2U7JLyNI+QwYEdOnhKIZRbuOMWZCJXEj5R9HbI/ooM4AhK751VnRmDKBsfr HRJ+nvkd9mP2RgasyzPodZaYgpy8G4g= 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 1160313A8C; Tue, 7 Feb 2023 07:29:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id n5fiAsz94WO4UQAAMHmgww (envelope-from ); Tue, 07 Feb 2023 07:29:16 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: lists@nerdbynature.de, mikelley@microsoft.com, torvalds@linux-foundation.org, Juergen Gross , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Subject: [PATCH 2/6] x86/pat: check for MTRRs enabled in memtype_reserve() Date: Tue, 7 Feb 2023 08:28:58 +0100 Message-Id: <20230207072902.5528-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230207072902.5528-1-jgross@suse.com> References: <20230207072902.5528-1-jgross@suse.com> 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?1757157805132599085?= X-GMAIL-MSGID: =?utf-8?q?1757157805132599085?= Today memtype_reserve() bails out early if pat_enabled() returns false. The same can be done in case MTRRs aren't enabled. This will reinstate the behavior of memtype_reserve() before commit 72cbc8f04fe2 ("x86/PAT: Have pat_enabled() properly reflect state when running on Xen"). There have been reports about that commit breaking SEV-SNP guests under Hyper-V, which was tried to be resolved by commit 90b926e68f50 ("x86/pat: Fix pat_x_mtrr_type() for MTRR disabled case"), but that again resulted in problems with Xen PV guests. Fixes: 72cbc8f04fe2 ("x86/PAT: Have pat_enabled() properly reflect state when running on Xen") Fixes: 90b926e68f50 ("x86/pat: Fix pat_x_mtrr_type() for MTRR disabled case") Signed-off-by: Juergen Gross --- arch/x86/mm/pat/memtype.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index fb4b1b5e0dea..18f612b43763 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -557,8 +557,12 @@ int memtype_reserve(u64 start, u64 end, enum page_cache_mode req_type, return -EINVAL; } - if (!pat_enabled()) { - /* This is identical to page table setting without PAT */ + /* + * PAT disabled or MTRRs disabled don't require any memory type + * tracking or type adjustments, as there can't be any conflicts + * between PAT and MTRRs with at least one of both being disabled. + */ + if (!pat_enabled() || !mtrr_enabled()) { if (new_type) *new_type = req_type; return 0; @@ -627,7 +631,7 @@ int memtype_free(u64 start, u64 end) int is_range_ram; struct memtype *entry_old; - if (!pat_enabled()) + if (!pat_enabled() || !mtrr_enabled()) return 0; start = sanitize_phys(start);