Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2025620rwl; Fri, 31 Mar 2023 23:38:03 -0700 (PDT) X-Google-Smtp-Source: AKy350YZdvKi9KAZ8d1d+T9BOhdlqpHqHf9he26xgwWBASkiRfQos71fLRGu145kbgx/I1VTUZAG X-Received: by 2002:a05:6a20:8e07:b0:db:91fd:92b0 with SMTP id y7-20020a056a208e0700b000db91fd92b0mr11221486pzj.1.1680331082900; Fri, 31 Mar 2023 23:38:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680331082; cv=none; d=google.com; s=arc-20160816; b=EJg5dnPAhxWd9v4QNTn0WmH+t0uHet1soT+i5DgzvkB6X8dRUCCh6UovCHjR1r6Lli 5YyOPeWZZlTa5GPcj0SmdPENUP/md9nScJnBNdkCOftzaAQn8euWpWlz1oW1z18Eo5hl XmmCG7Q/0r+OxeP/dRBtglFNS/K0iSBuVD+8vH2aaGdz9E6sUEdJODXUT2VYEfNcczLF So+o7f6DeSbjwR7YmQVs9mqE6zBTouPfDEMaBoYID6ieY573oe/4Y9WvnQdE1WQ+UzL6 6kEsiKpPrZKt98SZ4/lnor91kPaMdDSYw9xT6EnA507WgC03IS1TzyNq3/6IqVldaXZt 7T3A== 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=gsM8JG+0YjKpprMSP0WcpLzh0EmtHSX+OEFp6YWu4DY=; b=QkQr7UY9k7u0xuBGiWhCyFphBVBlWVxN1oEEj53lBK0flj24yTN+Z87dLVM8JbR1OE 4UIMHE3G0y2kxlGZgWE/VLKMQ8QJg7pb6DFz52ALmlnuyOWpOAOp+tIN7mPjrVfNVwc7 eJrl1kHAmlKCqbNSkMGJBFDUlU3kIQPVpWiO66r/tcqkSkQv8Gj8y9ehrWmHrbKvEhjE tqRw63tv9z+y5Zw/PP0Y/noeyUqhF+Nq2MNOdLgDVO7B9tPSy/MwIPBcnTsX5N7t4By2 HerPeBX7ONIF+xnkRrSz2acGFl197f1YT0G/YV0FXvyd/LGVnh6b2ExKEjDhNA7SKs7b LOrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=g8DLE9Ug; 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 s32-20020a635260000000b004ce5301edd5si3966945pgl.711.2023.03.31.23.37.51; Fri, 31 Mar 2023 23:38:02 -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=g8DLE9Ug; 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 S233237AbjDAGhH (ORCPT + 99 others); Sat, 1 Apr 2023 02:37:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233230AbjDAGhG (ORCPT ); Sat, 1 Apr 2023 02:37:06 -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 90EC51E73B for ; Fri, 31 Mar 2023 23:37:02 -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 324471FD78; Sat, 1 Apr 2023 06:37:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680331021; 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=gsM8JG+0YjKpprMSP0WcpLzh0EmtHSX+OEFp6YWu4DY=; b=g8DLE9Ug7PYEkqHVYmdV+X8Cg3YN7OhOO2THjBCiMltqzaduccgavEz5vuQLMoxChKwp7O qiXUoviI00yYbavx/BgEsUy+5Y3Kx9swildIQ6yxKHyyaa7PyZiTk9m953mG3IWXpviIqP GMlpfHJbaMPFJgIH7WxAVxFFzSG57rc= 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 E29F9134FB; Sat, 1 Apr 2023 06:37:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0IT8NQzRJ2QSdwAAMHmgww (envelope-from ); Sat, 01 Apr 2023 06:37:00 +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" , Michael Kelley Subject: [PATCH v5 01/15] x86/mtrr: split off physical address size calculation Date: Sat, 1 Apr 2023 08:36:38 +0200 Message-Id: <20230401063652.23522-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230401063652.23522-1-jgross@suse.com> References: <20230401063652.23522-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 Move the calculation of the physical address size in mtrr_bp_init() into a helper function. This will be needed later. Do only the pure code movement without optimizing it. Signed-off-by: Juergen Gross Tested-by: Michael Kelley --- V2: - new patch V3: - only move code, split off optimizations (Boris Petkov) --- arch/x86/kernel/cpu/mtrr/mtrr.c | 57 ++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.c b/arch/x86/kernel/cpu/mtrr/mtrr.c index 783f3210d582..8310bdb111d0 100644 --- a/arch/x86/kernel/cpu/mtrr/mtrr.c +++ b/arch/x86/kernel/cpu/mtrr/mtrr.c @@ -620,22 +620,14 @@ static struct syscore_ops mtrr_syscore_ops = { int __initdata changed_by_mtrr_cleanup; #define SIZE_OR_MASK_BITS(n) (~((1ULL << ((n) - PAGE_SHIFT)) - 1)) -/** - * mtrr_bp_init - initialize mtrrs on the boot CPU - * - * This needs to be called early; before any of the other CPUs are - * initialized (i.e. before smp_init()). - * - */ -void __init mtrr_bp_init(void) + +static unsigned int __init mtrr_calc_physbits(bool generic) { - const char *why = "(not available)"; - u32 phys_addr; + unsigned int phys_addr; phys_addr = 32; - if (boot_cpu_has(X86_FEATURE_MTRR)) { - mtrr_if = &generic_mtrr_ops; + if (generic) { size_or_mask = SIZE_OR_MASK_BITS(36); size_and_mask = 0x00f00000; phys_addr = 36; @@ -667,29 +659,44 @@ void __init mtrr_bp_init(void) size_and_mask = 0; phys_addr = 32; } + } else { + size_or_mask = SIZE_OR_MASK_BITS(32); + size_and_mask = 0; + } + + return phys_addr; +} + +/** + * mtrr_bp_init - initialize mtrrs on the boot CPU + * + * This needs to be called early; before any of the other CPUs are + * initialized (i.e. before smp_init()). + * + */ +void __init mtrr_bp_init(void) +{ + const char *why = "(not available)"; + unsigned int phys_addr; + + phys_addr = mtrr_calc_physbits(boot_cpu_has(X86_FEATURE_MTRR)); + + if (boot_cpu_has(X86_FEATURE_MTRR)) { + mtrr_if = &generic_mtrr_ops; } else { switch (boot_cpu_data.x86_vendor) { case X86_VENDOR_AMD: - if (cpu_feature_enabled(X86_FEATURE_K6_MTRR)) { - /* Pre-Athlon (K6) AMD CPU MTRRs */ + /* Pre-Athlon (K6) AMD CPU MTRRs */ + if (cpu_feature_enabled(X86_FEATURE_K6_MTRR)) mtrr_if = &amd_mtrr_ops; - size_or_mask = SIZE_OR_MASK_BITS(32); - size_and_mask = 0; - } break; case X86_VENDOR_CENTAUR: - if (cpu_feature_enabled(X86_FEATURE_CENTAUR_MCR)) { + if (cpu_feature_enabled(X86_FEATURE_CENTAUR_MCR)) mtrr_if = ¢aur_mtrr_ops; - size_or_mask = SIZE_OR_MASK_BITS(32); - size_and_mask = 0; - } break; case X86_VENDOR_CYRIX: - if (cpu_feature_enabled(X86_FEATURE_CYRIX_ARR)) { + if (cpu_feature_enabled(X86_FEATURE_CYRIX_ARR)) mtrr_if = &cyrix_mtrr_ops; - size_or_mask = SIZE_OR_MASK_BITS(32); - size_and_mask = 0; - } break; default: break; -- 2.35.3