From patchwork Thu Nov 10 12:21:57 2022 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: 18106 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp112612wru; Thu, 10 Nov 2022 04:25:39 -0800 (PST) X-Google-Smtp-Source: AMsMyM508hL+Vl9qsZhmCAqV+CD89zzySnIYyf1lk+IlyIZHDYgtFP2Y79gR7Plyx5Gohzavukwc X-Received: by 2002:a63:603:0:b0:464:3f16:e2b0 with SMTP id 3-20020a630603000000b004643f16e2b0mr2346908pgg.566.1668083139204; Thu, 10 Nov 2022 04:25:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668083139; cv=none; d=google.com; s=arc-20160816; b=hO9lf6iAAYrTm11DErR/M47/G1+dZ9xSjJDFZj5X9HB3VEakrtw+RvIl4jKDinHKw7 aSU9/fgIUIlFa/DvQHCDW+KZokVqDCgSnAloqfPuY9iq2aPQU5B9X2VgayRvkW6FIHw6 TuIukqAQs2WcV+KdEzL97n5n/a6mit7fqiGhSocePwWlkOl17dadZsHeUvUklVbunuan bnfIgflCEKNgNY6PUXyFPFT1lmSVQkgEch6f7E/BPVwdrFy+rj3t15s2+Y/manQl/D/H yyV4vHbe6CL0lab6ZCNitU7hSWopQxZTLlGTXvAAn/p6hNIsPNzb4u9bkaIQynzxc2TN T3vw== 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=aLcUelJ2A0i8y7/IOu2BtBIP0gHvDvi3R6Me7UncgnA=; b=x8OPojdDA65GTEZcm05sXn3AVEFB6kquMNbqVJ5l+cXpI+X0T9kPKQdMWPw4QhXGCg 4DKOIAZG7adi1j4Z+D16xtmSgvDniD+LRrT6WVSXGFhRmLIDmfiTRwBHfXPcUP5XCKJL mASdBS+XAD5HOVHzJSjhBygLrOZW3rpbJJj1S3+hDtN17hp39uiWq6/74ey5jv21I1g3 Z2AlZ1Kp1xu1Dw7C9leFBIGsNqs54BZC9PkYf88LuETKgMqEWf1DIZvqWD40t1tuR+ex nyfCCmFVprZ6Guga6KMfaXMxjRYF2GewzkO7zHfqaMUVO+j2jFTFPrIyUXFBrgdRsvXn r2+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=scZwJADq; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 e11-20020a63544b000000b0046afed15623si20328670pgm.372.2022.11.10.04.25.25; Thu, 10 Nov 2022 04:25:39 -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=scZwJADq; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S229932AbiKJMWe (ORCPT + 99 others); Thu, 10 Nov 2022 07:22:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231150AbiKJMWA (ORCPT ); Thu, 10 Nov 2022 07:22:00 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9BC071F39; Thu, 10 Nov 2022 04:21:59 -0800 (PST) Date: Thu, 10 Nov 2022 12:21:57 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668082918; 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=aLcUelJ2A0i8y7/IOu2BtBIP0gHvDvi3R6Me7UncgnA=; b=scZwJADqttdDQB9jffBstrgW81K6mAgWff7VZKY1fWj+5384ZOhuNC4rTEcy0lvZjmdS6L 96FkYdlUF1cbInbsFHNfe/hnqrSiNPsVIEUY4kDgT5nlBkqEmMw1Ege7rwOIp5CnX7iv7f WWeO0fbpg20OxoZom+c+5oNaeG+YgjC2BN2QE2myB1ynjAul0FrOFIs8CNoechn7D8y+te ot7+manaS4h7ZnmtwCQORfdp9SKoaav/hiFY0zD508mTyW0KHLAtujEGX3alhF7mp0BEX1 uxG6dHEbKdz6FbOZUJ9RjOikDDbboaz50CqpW0JB2IW4xlCd42cU/5c/txA2tg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668082918; 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=aLcUelJ2A0i8y7/IOu2BtBIP0gHvDvi3R6Me7UncgnA=; b=NgEPCkQ0BgAQ7ue9reic0Tlgpp3jX/A13kmYg8NpnBEn2nHKYfxrWQi5X0bYOwGtIBfJ5i 8t/LOCprNybL26Dg== 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/cpu] x86/mtrr: Split MTRR-specific handling from cache dis/enabling Cc: Juergen Gross , Borislav Petkov , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20221102074713.21493-6-jgross@suse.com> References: <20221102074713.21493-6-jgross@suse.com> MIME-Version: 1.0 Message-ID: <166808291702.4906.9360364596007729426.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?1749111945668757050?= X-GMAIL-MSGID: =?utf-8?q?1749111945668757050?= The following commit has been merged into the x86/cpu branch of tip: Commit-ID: 4ad7149e46d048d3a543c96d35c1d255208dd33a Gitweb: https://git.kernel.org/tip/4ad7149e46d048d3a543c96d35c1d255208dd33a Author: Juergen Gross AuthorDate: Wed, 02 Nov 2022 08:47:02 +01:00 Committer: Borislav Petkov CommitterDate: Thu, 10 Nov 2022 13:12:44 +01:00 x86/mtrr: Split MTRR-specific handling from cache dis/enabling Split the MTRR-specific actions from cache_disable() and cache_enable() into new functions mtrr_disable() and mtrr_enable(). Signed-off-by: Juergen Gross Signed-off-by: Borislav Petkov Link: https://lore.kernel.org/r/20221102074713.21493-6-jgross@suse.com Signed-off-by: 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 76d7260..12a16ca 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 2f3fc28..0db0770 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);