Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2026580rwl; Fri, 31 Mar 2023 23:39:32 -0700 (PDT) X-Google-Smtp-Source: AKy350bfRrUsXGON5xz3PkRSDL1WoBTTqqgZa5e9sNrtVAL8ttJ83ncM2BVSXP2431EW6mH2/uDM X-Received: by 2002:a05:6402:42c2:b0:502:ffd:74a1 with SMTP id i2-20020a05640242c200b005020ffd74a1mr30897725edc.2.1680331172222; Fri, 31 Mar 2023 23:39:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680331172; cv=none; d=google.com; s=arc-20160816; b=dH9jxpyEKmD5ITYdU/2DZADPzATiHC620Wh36E2E3GMpgMQ9R+kiFj38mp2gpcsqF/ yWVdIXhEZmJf4cPo5VtBD1dNG79mhkIAhxdCRwu+X7TyDeSKFjm9QXDSb/KaFCDnT1VU 3Gbicn96JhUgHgcoUqOWZm3vooG22PThCX3xSnkrCJhQvIFpDoPouTjiTl1RP0uyx21i J8Rl8WtuQ8oPIhzcMY5oXaIwEC1AGtA+S2rdGN1rDWgTHU8dJqj38Dt1ZeGzt9CgnM8n ou3WbqcbHyhrrjRTqQo+ChFZ6RJbIFWTxejByBi4h3LicjyLBsUejM0hMkA9siJs8u4a +35A== 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=K2ik7sM7MKDAhj6hnR4NNX3zRxA2aEkPlgWNeKuOI4M=; b=0Q7yU9z4+7av4UseGScPvq5/jHJ8KRYc9TsjUcWknx9Jl7UHjX3OhVj3IVq6uv6Uws jOgy7aBe16blQ60tX81/xYOKX8qfKR0rNj5s9sKZObn2rEbxumPIU5sq2ZDu7W1VAb1D JabcfLP9POB8zqGUCRrxoJzHzDPfj2C5XajSxSdL/boX0fsl+JDdDKWTKGUFzdphAbB6 fbA4zYCcmWKGptDiREty2g/96ujmF6Ci1gIQBEll9EvdphMtB1zT0GIIO+OsGuuE+KRU NMLqpLdwWBb7RLm2VLzAwlq/l5wTBYPRMiLKYejl6iozkV9TRAZGyzVvCPqaFHsQ9M5S jVNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=lX+D5Iwc; 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 w20-20020a056402129400b004c0e614f887si3560912edv.94.2023.03.31.23.39.08; Fri, 31 Mar 2023 23:39:32 -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=lX+D5Iwc; 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 S233354AbjDAGi2 (ORCPT + 99 others); Sat, 1 Apr 2023 02:38:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233459AbjDAGiW (ORCPT ); Sat, 1 Apr 2023 02:38:22 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE0E021A9A for ; Fri, 31 Mar 2023 23:37:52 -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 D244821A73; Sat, 1 Apr 2023 06:37:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680331066; 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=K2ik7sM7MKDAhj6hnR4NNX3zRxA2aEkPlgWNeKuOI4M=; b=lX+D5IwceSzE0cz8ypRJFts7mCMjDq0IimYmxMR5U7LkjWBGFqNw6+mlan32M26qL1QJEE A1v83q6XYc0XyzElJNX+aB2GPCOHzFtG+BMHB93lAZ0AiJSvd0BUGCNKWyndw00psTYQ6J 3+84JSzgIK60gZvRgUfdBSHCERV2GnI= 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 8F059134FB; Sat, 1 Apr 2023 06:37:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 9+OrITrRJ2RpdwAAMHmgww (envelope-from ); Sat, 01 Apr 2023 06:37:46 +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 09/15] x86/mtrr: allocate mtrr_value array dynamically Date: Sat, 1 Apr 2023 08:36:46 +0200 Message-Id: <20230401063652.23522-10-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 The mtrr_value[] array is a static variable, which is used only in a few configurations. Consuming 6kB is ridiculous for this case, especially as the array doesn't need to be that large and it can easily be allocated dynamically. The "few configurations" are all 32-bit ones, so put the code inside a CONFIG_X86_32 #ifdef. Signed-off-by: Juergen Gross Tested-by: Michael Kelley --- V5: - check for allocation failure (Kai Huang, Boris Petkov) - add #ifdef --- arch/x86/kernel/cpu/mtrr/mtrr.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.c b/arch/x86/kernel/cpu/mtrr/mtrr.c index 4fa3d0f94f39..76f5b5e1128b 100644 --- a/arch/x86/kernel/cpu/mtrr/mtrr.c +++ b/arch/x86/kernel/cpu/mtrr/mtrr.c @@ -560,8 +560,10 @@ int arch_phys_wc_index(int handle) } EXPORT_SYMBOL_GPL(arch_phys_wc_index); -/* The suspend/resume methods are only for CPU without MTRR. CPU using generic - * MTRR driver doesn't require this +#ifdef CONFIG_X86_32 +/* + * The suspend/resume methods are only for CPUs without MTRR. CPUs using generic + * MTRR driver don't require this. */ struct mtrr_value { mtrr_type ltype; @@ -569,12 +571,15 @@ struct mtrr_value { unsigned long lsize; }; -static struct mtrr_value mtrr_value[MTRR_MAX_VAR_RANGES]; +static struct mtrr_value *mtrr_value; static int mtrr_save(void) { int i; + if (!mtrr_value) + return -ENOMEM; + for (i = 0; i < num_var_ranges; i++) { mtrr_if->get(i, &mtrr_value[i].lbase, &mtrr_value[i].lsize, @@ -596,12 +601,11 @@ static void mtrr_restore(void) } } - - static struct syscore_ops mtrr_syscore_ops = { .suspend = mtrr_save, .resume = mtrr_restore, }; +#endif /* CONFIG_X86_32 */ int __initdata changed_by_mtrr_cleanup; @@ -730,15 +734,20 @@ static int __init mtrr_init_finialize(void) return 0; } +#ifdef CONFIG_X86_32 + mtrr_value = kcalloc(num_var_ranges, sizeof(*mtrr_value), GFP_KERNEL); + /* * The CPU has no MTRR and seems to not support SMP. They have * specific drivers, we use a tricky method to support - * suspend/resume for them. + * suspend/resume for them. In case above allocation failed we can't + * support suspend/resume (handled in mtrr_save()). * * TBD: is there any system with such CPU which supports * suspend/resume? If no, we should remove the code. */ register_syscore_ops(&mtrr_syscore_ops); +#endif return 0; } -- 2.35.3