Received: by 10.213.65.68 with SMTP id h4csp590077imn; Tue, 13 Mar 2018 14:08:42 -0700 (PDT) X-Google-Smtp-Source: AG47ELtAGV800rVEFUE+SN7Uh8zMN3yRPocTe7d8XAWcD8v+ManNK9x+z3Fe5Uzz/IkR7zFROlqF X-Received: by 10.99.55.70 with SMTP id g6mr1615026pgn.284.1520975322446; Tue, 13 Mar 2018 14:08:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520975322; cv=none; d=google.com; s=arc-20160816; b=HW5mm82tqlxA+niprjTxQEREUUz4SOsPboQMJf4WQdj2PikZO4+wqNcmKakJnyrYDw YI0DBPCw3JZO8O9HoQBVUqcBIHakTBE0trCbziMrJT+NjThx2esHQAr/PKzAS8W7OUb3 OJZ7V7nkqbMV/hJg9/DojeoWCWHs2UAJ7HDxnN1QmkFved9l+zYY7dTHUstAEcwJsS2d 4dPNB0Oe0zZsc8mnkTq5hSImaIEQONBhQrmzdH8GgEEiZ9C8DHOfOZKH5mMuDdztkVrY NzeaDIhXNLYBHcCltssrAbnPoOTHRTI4CelxueS/Zxbhk4fC5t/7Hy/ILKgiMdh9Krt0 eJJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:subject:from:arc-authentication-results; bh=BghaIlWQPO3HyDUxkmc2DdRKXzDN8/tUg5W4ecDT8EM=; b=EzIdVsnD4Z5JM3i0GScvkFAy4slcgZFf6ZGyN2II1guKupWRRZmGP+snly+XUvnl1c h1xMB4sAC/fCgREuuKEHDZlRPVRmFgCqicE6N/qtLB/32XAux4NRplFhb1l5FTwkR6lW pdeEgZZ1XsSmZDlMrHVFBljVsEIjXKpRvKvtn69KAUGNMeEoKRA3oa4YQyobL05pbVBX A3LjZTC97N031vOaefGJ26fy2pyEW+xZtKA2CD+duYwIBqMhQfyzlpLTJ2Fz7AW9cYDQ imtdJHMFoxfbXUtzVw/MQ3V4CaK7DX1mqJAr1f60gLe1Eh/Bv5Am5xAJ1y3Qjgx9DO5Q mKjA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q11si770909pfd.242.2018.03.13.14.08.28; Tue, 13 Mar 2018 14:08:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752959AbeCMVGw (ORCPT + 99 others); Tue, 13 Mar 2018 17:06:52 -0400 Received: from vps-vb.mhejs.net ([37.28.154.113]:46596 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751903AbeCMVGu (ORCPT ); Tue, 13 Mar 2018 17:06:50 -0400 Received: by vps-vb.mhejs.net with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) (envelope-from ) id 1evr8C-0004SP-LS; Tue, 13 Mar 2018 22:06:48 +0100 From: "Maciej S. Szmigiero" Subject: [PATCH v3 4/9] x86/microcode/AMD: automatically compute the PATCH_MAX_SIZE macro To: Borislav Petkov Cc: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org References: Message-ID: Date: Tue, 13 Mar 2018 22:06:48 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=iso-8859-2 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The PATCH_MAX_SIZE macro should contain the maximum of all family patch sizes, computed automatically so that future changes there don't cause an inconsistency. Unfortunately, we can't use a standard max{,3} macros for this since they only work inside a function (they use a compound statement as an expression) and we have a static array using this macro value as its length. This macro is specific to amd.c file so let's move it there (the max sizes for families are in this file already). Signed-off-by: Maciej S. Szmigiero --- arch/x86/include/asm/microcode_amd.h | 2 -- arch/x86/kernel/cpu/microcode/amd.c | 22 ++++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/microcode_amd.h b/arch/x86/include/asm/microcode_amd.h index 209492849566..365bfa85a06b 100644 --- a/arch/x86/include/asm/microcode_amd.h +++ b/arch/x86/include/asm/microcode_amd.h @@ -41,8 +41,6 @@ struct microcode_amd { unsigned int mpb[0]; }; -#define PATCH_MAX_SIZE PAGE_SIZE - #ifdef CONFIG_MICROCODE_AMD extern void __init load_ucode_amd_bsp(unsigned int family); extern void load_ucode_amd_ap(unsigned int family); diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c index d20c327c960b..b9f6c06bdc16 100644 --- a/arch/x86/kernel/cpu/microcode/amd.c +++ b/arch/x86/kernel/cpu/microcode/amd.c @@ -40,6 +40,22 @@ static struct equiv_cpu_entry *equiv_cpu_table; +/* Maximum patch size for a particular family */ +#define F1XH_MPB_MAX_SIZE 2048 +#define F14H_MPB_MAX_SIZE 1824 +#define F15H_MPB_MAX_SIZE 4096 +#define F16H_MPB_MAX_SIZE 3458 +#define F17H_MPB_MAX_SIZE 3200 + +/* Can't use a standard max{,3} since they only work inside a function */ +#define SIMPLE_MAX(x, y) ((x) > (y) ? (x) : (y)) +#define SIMPLE_MAX3(x, y, z) SIMPLE_MAX(SIMPLE_MAX(x, y), z) + +/* Maximum of all the above families */ +#define PATCH_MAX_SIZE SIMPLE_MAX3(F1XH_MPB_MAX_SIZE, F14H_MPB_MAX_SIZE, \ + SIMPLE_MAX3(F15H_MPB_MAX_SIZE, F16H_MPB_MAX_SIZE, \ + F17H_MPB_MAX_SIZE)) + /* * This points to the current valid container of microcode patches which we will * save from the initrd/builtin before jettisoning its contents. @mc is the @@ -473,12 +489,6 @@ static unsigned int verify_patch_size(u8 family, u32 patch_size, { u32 max_size; -#define F1XH_MPB_MAX_SIZE 2048 -#define F14H_MPB_MAX_SIZE 1824 -#define F15H_MPB_MAX_SIZE 4096 -#define F16H_MPB_MAX_SIZE 3458 -#define F17H_MPB_MAX_SIZE 3200 - switch (family) { case 0x14: max_size = F14H_MPB_MAX_SIZE;