Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp3646243rwi; Wed, 2 Nov 2022 01:11:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7IrE8VqpHeWjIT9+NXPLeJd9qFGTLlNeYRsKdSkYWd/4ObOqRjHIQrbtlThVpDaQWzO4Bg X-Received: by 2002:a17:907:6d9b:b0:78d:ce6a:3300 with SMTP id sb27-20020a1709076d9b00b0078dce6a3300mr21150430ejc.91.1667376698917; Wed, 02 Nov 2022 01:11:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667376698; cv=none; d=google.com; s=arc-20160816; b=MlCCRQpzOZ5f4ruYkJDx5WuPs63ZT9tjoCde/0luNmI6k2u9/Pz3drm5TMznQNPoJh Ud0LBgOUhCZc9o/BElRm4Eocmh4hrE82FZBcttD+XBH7z1zB6BKBcEO1zkFfJmcFfbSv oz6G+8K6+J1K4iw58i22KbbKlDIa/QgWmLiA680q+rzoW69kbvcLfjh1UiDrpGTu6zVX Yrls8NMVJi0Zd0z40Y2ZrZjgC24ct9qhxmrfSey4EFp6jPIUvXwJBnS7MzeS7BpctdE6 wi8xSqLTA83PoKEm96c+Tbu7zqDUg0qgnNx+VZDOP+1PLhTWsNe6S9A458sP8eq4Je5m iVcA== 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=Wg1ltP5S2ST2D2shywYpbJwrHqpg2nHmgpqKBsh6EzQ=; b=kOBARt+aBSTvBL4Zz5YiqjrXTbOaApeEJpqAfRixPN1NLvoZSdP13tsRB9a5AHa3C1 Am1cEi/Rex9EqHtZF0qzuN7BGLDtE9qIs1i7mR7xRN4559bJeaeY53I0RGDZb31jzoMj yBwm2OZL9q56yRRrX/rs1ikiLZ1gLbg4cq6S1CN+NyVno0YHM/T4VOGtP6yhcq75SgoA 2AEIdwryMNgDYUxz/GNccCYbzJJjJLRUv7A0Ou9lCywR2lX0WAwCEMpr/cCeN230Z1fe EUhRgjr07wvaTd2O/qlwqhjclhTgUkeD+ZZvKIdqLsUPdMFXnmkO9jkChDoNPpvHLl39 sZ/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=MPB5tr1N; 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 y20-20020a056402359400b00462f4ea167esi18543805edc.315.2022.11.02.01.11.15; Wed, 02 Nov 2022 01:11:38 -0700 (PDT) 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=MPB5tr1N; 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 S230525AbiKBHsF (ORCPT + 96 others); Wed, 2 Nov 2022 03:48:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230468AbiKBHr5 (ORCPT ); Wed, 2 Nov 2022 03:47:57 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41F2825EA8 for ; Wed, 2 Nov 2022 00:47:45 -0700 (PDT) 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 EA2E43373A; Wed, 2 Nov 2022 07:47:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667375263; 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=Wg1ltP5S2ST2D2shywYpbJwrHqpg2nHmgpqKBsh6EzQ=; b=MPB5tr1NRV+9NntC9d7piW075UGauYq/F0wIwl3hrWXHrOLpkt91GvuDjQ/bqOTrZjDpEU QX1BhBHf7jqkHc6qAYj9wTU4zVgjLARKDa3oAWOcyUM9u1SYh2gdoCx+sKKvTRrgd+a9qB owZ9Lyo3qx/EzoklDjpwBt/Ya9F0nZs= 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 B225A1376E; Wed, 2 Nov 2022 07:47:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Zk5BKp8gYmO9cgAAMHmgww (envelope-from ); Wed, 02 Nov 2022 07:47:43 +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 v5 05/16] x86/mtrr: split MTRR specific handling from cache dis/enabling Date: Wed, 2 Nov 2022 08:47:02 +0100 Message-Id: <20221102074713.21493-6-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221102074713.21493-1-jgross@suse.com> References: <20221102074713.21493-1-jgross@suse.com> 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 Split the MTRR specific actions from cache_disable() and cache_enable() into the new functions mtrr_disable() and mtrr_enable(). Signed-off-by: Juergen Gross --- V4: - carved out from other patch (Borislav Petkov) V5: - use cpu_feature_enabled() (Borislav Petkov) --- arch/x86/include/asm/mtrr.h | 4 ++++ arch/x86/kernel/cpu/mtrr/generic.c | 26 +++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/mtrr.h b/arch/x86/include/asm/mtrr.h index 76d726074c16..12a16caed395 100644 --- a/arch/x86/include/asm/mtrr.h +++ b/arch/x86/include/asm/mtrr.h @@ -48,6 +48,8 @@ extern void mtrr_aps_init(void); extern void mtrr_bp_restore(void); extern int mtrr_trim_uncached_memory(unsigned long end_pfn); extern int amd_special_default_mtrr(void); +void mtrr_disable(void); +void mtrr_enable(void); # else static inline u8 mtrr_type_lookup(u64 addr, u64 end, u8 *uniform) { @@ -87,6 +89,8 @@ static inline void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi) #define set_mtrr_aps_delayed_init() do {} while (0) #define mtrr_aps_init() do {} while (0) #define mtrr_bp_restore() do {} while (0) +#define mtrr_disable() do {} while (0) +#define mtrr_enable() do {} while (0) # endif #ifdef CONFIG_COMPAT diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c index aebdc90a2489..4edf0827f7ee 100644 --- a/arch/x86/kernel/cpu/mtrr/generic.c +++ b/arch/x86/kernel/cpu/mtrr/generic.c @@ -716,6 +716,21 @@ static unsigned long set_mtrr_state(void) return change_mask; } +void mtrr_disable(void) +{ + /* Save MTRR state */ + rdmsr(MSR_MTRRdefType, deftype_lo, deftype_hi); + + /* Disable MTRRs, and set the default type to uncached */ + mtrr_wrmsr(MSR_MTRRdefType, deftype_lo & ~0xcff, deftype_hi); +} + +void mtrr_enable(void) +{ + /* Intel (P6) standard MTRRs */ + mtrr_wrmsr(MSR_MTRRdefType, deftype_lo, deftype_hi); +} + /* * Disable and enable caches. Needed for changing MTRRs and the PAT MSR. * @@ -764,11 +779,8 @@ void cache_disable(void) __acquires(cache_disable_lock) count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ALL); flush_tlb_local(); - /* Save MTRR state */ - rdmsr(MSR_MTRRdefType, deftype_lo, deftype_hi); - - /* Disable MTRRs, and set the default type to uncached */ - mtrr_wrmsr(MSR_MTRRdefType, deftype_lo & ~0xcff, deftype_hi); + if (cpu_feature_enabled(X86_FEATURE_MTRR)) + mtrr_disable(); /* Again, only flush caches if we have to. */ if (!static_cpu_has(X86_FEATURE_SELFSNOOP)) @@ -781,8 +793,8 @@ void cache_enable(void) __releases(cache_disable_lock) count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ALL); flush_tlb_local(); - /* Intel (P6) standard MTRRs */ - mtrr_wrmsr(MSR_MTRRdefType, deftype_lo, deftype_hi); + if (cpu_feature_enabled(X86_FEATURE_MTRR)) + mtrr_enable(); /* Enable caches */ write_cr0(read_cr0() & ~X86_CR0_CD); -- 2.35.3