Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp156429rwb; Tue, 4 Oct 2022 02:01:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Ql4vfx6pg4AXkT5IbY0riSb7b5l+JJoFddE7gttYf2aiXE6/tw19D+isUu4LPvrOlMK11 X-Received: by 2002:a05:6402:f83:b0:458:8c97:29af with SMTP id eh3-20020a0564020f8300b004588c9729afmr16280944edb.210.1664874091492; Tue, 04 Oct 2022 02:01:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664874091; cv=none; d=google.com; s=arc-20160816; b=jsixHEJKYisEV9xKZkdV50FVrXCetulosglU5fHnC4e9SE+EFYumhqHprd/SdwvlqL 7+ITfpqVKmXyyHBBpw8xdnkppjeh5WJEUtlH/5C0stZIMfkKSBTu/9aGZJCz7/pNrNsK 4m9IS27yn/SzwoLd4eVCWkcbp+/UAGQB4Qy0ysCp5eRsrS4Alal4F2s5wubs0PJ4JA8r +8+oLEAjxVDIEEMUK3lA2gOKsCkp3OPv7wWQZu8ws3lJZgV+KOse9aty7pGV3c+nW5ey HAq01eg1dzOPhyJyRdzLjL/haTpBypHYlUoSdTb2odbT9PHDyaRIZV+4nVkCUHp1yEfS 9XQg== 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=BdNeASTIsigsn6I6gmyehllEZ5HmkU4n1YF0DHyGpbk=; b=EsJub2ZIjJkMspchmHThQt/HfsdpJLnU2y6f9sHsnnCdtk8qQTZfAIw4xHzsDOm3OK J941W5K+njeIOfQ5w71kd/1bviQvLkx1LjJ3jIdFFEKZ2X5FubZ77kt1QSp8cSopIMwZ QPT0jzqkHVPDo/RY0AmXhyxYI5wMh/lGRaXG63ELWnycY3JrVDsfqM3x96KvNminxRaN qZbcBDRYGip1tmHjeFXVRJYxUi3FgYerCr5FgvbHuStRk8tXf3FoIn9EWIArkmexEU3g YQ1TZSsW2mrmorRk++ajOym2qAJFWpRqpoqCafpiD2XfqfJGJpcHHyAZ07hp4aOeKqK8 ue5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=Ix0S2B9l; 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 hr2-20020a1709073f8200b00787796077a0si10818107ejc.429.2022.10.04.02.00.57; Tue, 04 Oct 2022 02:01:31 -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=Ix0S2B9l; 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 S229959AbiJDIMa (ORCPT + 99 others); Tue, 4 Oct 2022 04:12:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229846AbiJDILt (ORCPT ); Tue, 4 Oct 2022 04:11:49 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8332838C for ; Tue, 4 Oct 2022 01:10:57 -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 4C8E1219BD; Tue, 4 Oct 2022 08:10:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1664871055; 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=BdNeASTIsigsn6I6gmyehllEZ5HmkU4n1YF0DHyGpbk=; b=Ix0S2B9lhA4qEUjm+JLZOCjYCs/xP8J4zXUnkK6JaypVlLNIcDCZ5kJQYpvfJyqsoMYgUk 5k6xl8jVh0n4Pgq4XmMDSdAl0Ho3+5c16a33gQSr9hiiw7fnkmcD8glAFy7vK2K2eHIDpa crTzy2P1dMQQRDuD5Y+1T6F/RmP/4ms= 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 14949139EF; Tue, 4 Oct 2022 08:10:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MpbcA4/qO2NTSAAAMHmgww (envelope-from ); Tue, 04 Oct 2022 08:10:55 +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 v4 05/16] x86/mtrr: split MTRR specific handling from cache dis/enabling Date: Tue, 4 Oct 2022 10:10:12 +0200 Message-Id: <20221004081023.32402-6-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221004081023.32402-1-jgross@suse.com> References: <20221004081023.32402-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) --- 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..164d753e9867 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 (boot_cpu_has(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 (boot_cpu_has(X86_FEATURE_MTRR)) + mtrr_enable(); /* Enable caches */ write_cr0(read_cr0() & ~X86_CR0_CD); -- 2.35.3