From patchwork Wed Nov 2 07:47:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Gross X-Patchwork-Id: 14066 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3470435wru; Wed, 2 Nov 2022 00:54:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM53BzOOLZY31fa/fUDit2b9MgnBENz1+2RiANw9Z6t80GVrBQUJ1nJiH3wUq+A/T2hB+KxQ X-Received: by 2002:a17:907:d26:b0:78e:20c6:9f77 with SMTP id gn38-20020a1709070d2600b0078e20c69f77mr22298702ejc.243.1667375651304; Wed, 02 Nov 2022 00:54:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667375651; cv=none; d=google.com; s=arc-20160816; b=udBYNk7TkSiDAfsfy7/EcDhA/aViPbAxi9oEBS6bQZyKpdpmqbaVixIaujP3DZEsfg 0jW+3E5/27Om/kRrclNt2Q95QRiHr3REUKik8WsanEGGomhEtOIpCKK9C9AyEEAGgKKx r8VIg28PtLkmacl4EZczolip6RddObC0V3kcz5JvAPuWJmZklZF2v+8qnXVT4R0BsSeU QuZqo9btxQNE8Q/s5AJgKMx1HTD327vU3vn2/0IkqXXXywLPU0WTF9VlnrpXGfXob3Rl ANimDweUjJaTqgg0tD1IINxr1LqVedkrah7Y2CBxlntcFBJqO8ilH5JaXMAs5nZOLSyU 3qhw== 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=dqXfly+nuyRzVNoX1Dc+OjXV+YnmKzCTWh6bGlPZ0fg=; b=U1eEJrgzINVfEGDZVQ5kreIUYN/iFZAr26qM17uTSstAIKI2d8P0KnmscZ3nBWyGeB nW54chKH9COIxBXVzZhnx9jHcBpjSyENMYWBg9PrCRd6w3OR3mpWsh4cgkwgJoofwUF8 yKFCcSHi1CdFINuvv2q92eDV2dXvPBTeRY0RmLTPpGl77KpmH5yqXcv9+zNuQ+naWl/o lcKcY4rVIDHH7KtDeRqDTEbi3czhJpItPbBLTqVaK2ko8Z9MPZ1vdG6RFrWgc+R9TDkL Sl65X2U+wPjO8WHp76BE8U2KbF4v4zl9/VSHfz3Gg/TLMntyMwQGCMIOPKvKsiTnPMYE twbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=hxa617IN; 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 dm5-20020a170907948500b0077ef3eece57si15146734ejc.144.2022.11.02.00.53.48; Wed, 02 Nov 2022 00:54:11 -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=hxa617IN; 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 S230467AbiKBHs3 (ORCPT + 99 others); Wed, 2 Nov 2022 03:48:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229587AbiKBHsI (ORCPT ); Wed, 2 Nov 2022 03:48:08 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6A4E2714C for ; Wed, 2 Nov 2022 00:48:07 -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-out2.suse.de (Postfix) with ESMTPS id 9C5951F8D0; Wed, 2 Nov 2022 07:48:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667375286; 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=dqXfly+nuyRzVNoX1Dc+OjXV+YnmKzCTWh6bGlPZ0fg=; b=hxa617INPh9fzqGr3kbyQUayFOCFuaBCZ9uLqj9xvG3+RNrZTyxB82el3RtRth37stdlHA J4i2OeSAf5G16bqL1/J+s5/YCNMwmpSK8XygJ/W+Ji3j3BqwUCziIEg/0RrIoHYebSsAmB 3W66PBNkCuWC+EDBJdyNJFZ6eLEzM0g= 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 65F781376E; Wed, 2 Nov 2022 07:48:06 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id i0a+F7YgYmP3cgAAMHmgww (envelope-from ); Wed, 02 Nov 2022 07:48:06 +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 09/16] x86/mtrr: simplify mtrr_bp_init() Date: Wed, 2 Nov 2022 08:47:06 +0100 Message-Id: <20221102074713.21493-10-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 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?1748370090726187654?= X-GMAIL-MSGID: =?utf-8?q?1748370090726187654?= In case of the generic cache interface being used (Intel CPUs or a 64-bit system), the initialization sequence of the boot CPU is more complicated than necessary: - check if MTRR enabled, if yes, call mtrr_bp_pat_init() which will disable caching, set the PAT MSR, and reenable caching - call mtrr_cleanup(), in case that changed anything, call cache_cpu_init() doing the same caching disable/enable dance as above, but this time with setting the (modified) MTRR state (even if MTRR was disabled) AND setting the PAT MSR (again even with disabled MTRR) The sequence can be simplified a lot while removing potential inconsistencies: - check if MTRR enabled, if yes, call mtrr_cleanup() and then cache_cpu_init() This ensures to: - no longer disable/enable caching more than once - avoid to set MTRRs and/or the PAT MSR on the boot processor in case of MTRR cleanups even if MTRRs meant to be disabled With that mtrr_bp_pat_init() can be removed. Signed-off-by: Juergen Gross --- V2: - new patch --- arch/x86/kernel/cpu/mtrr/generic.c | 14 -------------- arch/x86/kernel/cpu/mtrr/mtrr.c | 6 +----- arch/x86/kernel/cpu/mtrr/mtrr.h | 1 - 3 files changed, 1 insertion(+), 20 deletions(-) diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c index af8422c96b92..2f2485d6657f 100644 --- a/arch/x86/kernel/cpu/mtrr/generic.c +++ b/arch/x86/kernel/cpu/mtrr/generic.c @@ -442,20 +442,6 @@ static void __init print_mtrr_state(void) pr_debug("TOM2: %016llx aka %lldM\n", mtrr_tom2, mtrr_tom2>>20); } -/* PAT setup for BP. We need to go through sync steps here */ -void __init mtrr_bp_pat_init(void) -{ - unsigned long flags; - - local_irq_save(flags); - cache_disable(); - - pat_init(); - - cache_enable(); - local_irq_restore(flags); -} - /* Grab all of the MTRR state for this CPU into *state */ bool __init get_mtrr_state(void) { diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.c b/arch/x86/kernel/cpu/mtrr/mtrr.c index a44b510ced0e..a468be5d778f 100644 --- a/arch/x86/kernel/cpu/mtrr/mtrr.c +++ b/arch/x86/kernel/cpu/mtrr/mtrr.c @@ -764,12 +764,8 @@ void __init mtrr_bp_init(void) __mtrr_enabled = get_mtrr_state(); if (mtrr_enabled()) { - mtrr_bp_pat_init(); memory_caching_control |= CACHE_MTRR | CACHE_PAT; - } - - if (mtrr_cleanup(phys_addr)) { - changed_by_mtrr_cleanup = 1; + changed_by_mtrr_cleanup = mtrr_cleanup(phys_addr); cache_cpu_init(); } } diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h index 3b1883185185..c98928ceee6a 100644 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h @@ -50,7 +50,6 @@ void set_mtrr_prepare_save(struct set_mtrr_context *ctxt); void fill_mtrr_var_range(unsigned int index, u32 base_lo, u32 base_hi, u32 mask_lo, u32 mask_hi); bool get_mtrr_state(void); -void mtrr_bp_pat_init(void); extern void __init set_mtrr_ops(const struct mtrr_ops *ops);