Received: by 10.223.185.116 with SMTP id b49csp1115655wrg; Fri, 23 Feb 2018 12:11:41 -0800 (PST) X-Google-Smtp-Source: AH8x225fThLrhWxl8Rj5k2TH2+aVF94HBhcRE3BK4JsKupIMt48NEyUAUCaPtjuv9rhlRLByycm6 X-Received: by 2002:a17:902:4222:: with SMTP id g31-v6mr2671127pld.335.1519416701500; Fri, 23 Feb 2018 12:11:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519416701; cv=none; d=google.com; s=arc-20160816; b=f+ysMAnAEEBGAnk8YQdtc3f4Xru8Pvfs57vahaUkWi24VWOjqyLagFtLV1ue8+vV1E WCbTVss5elOCEmdVTMbWSW5T7C8wAr5c4xWIfr9zumpI+xc5IDWUE5gB/vbrFxKNZMd0 csD4TOsYAnJUKuRdLI4FuAz1qvPTyo9B1+ZPzBr+RzPXgTqg8NdqJX5mHfTDjVtOoucg 8pckPw9JeuhkIJzP3AwMYmEuf8adfhXcHYVTeHBZGTQ6c01UOV/hIWGJuZahzbRFykGm qTZUkRw6hH8GrRzxkYTt9aJ2OmkeCQNROeJAE7aJS4te1k1r26HlkEYuKFaYuaw1NYsk DnrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=CHHpWrK7ahODgRw/W3prm9UobT+7NUzlND8KburwavM=; b=xPD1DaGhE1tixkcyxg2s2Vbupp5wv8pvccKap62piw7UDxt4H3PgEcWNENKPnNE5yW rXAOEczBRiBU8SlA8u9OGjeBcmprNQX/EZ67gpchvV3UrJA/RcEIUZ6Ze4AauykiqxTH 9EOgXo1h+qPs1HTqu0UHqRSNZroeoyyi5beqqSDMjMpKRzjbG2rOns0joUWs2zGvlHl/ pkr1fMY0/i4dWHk0SBHwp+7kgOSlujy4X613zjnRJKaNxM3yT9ezmm9AZTx/wzgvwbOe PVToJD0ZQoLWD0xMmy+SlwcuS1Nmh+b/XhUY4rjdoLfvcGwIS5LSuqq7p7nW238bFSkz ZHTQ== 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 l10si2298972pfc.203.2018.02.23.12.11.27; Fri, 23 Feb 2018 12:11:41 -0800 (PST) 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 S933179AbeBWUKY (ORCPT + 99 others); Fri, 23 Feb 2018 15:10:24 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:41134 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932531AbeBWSmC (ORCPT ); Fri, 23 Feb 2018 13:42:02 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BC5BEDAB; Fri, 23 Feb 2018 18:42:01 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Borislav Petkov , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Arnd Bergmann Subject: [PATCH 4.4 161/193] x86/microcode/AMD: Change load_microcode_amd()s param to bool to fix preemptibility bug Date: Fri, 23 Feb 2018 19:26:34 +0100 Message-Id: <20180223170351.126349872@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170325.997716448@linuxfoundation.org> References: <20180223170325.997716448@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Borislav Petkov commit dac6ca243c4c49a9ca7507d3d66140ebfac8b04b upstream. With CONFIG_DEBUG_PREEMPT enabled, I get: BUG: using smp_processor_id() in preemptible [00000000] code: swapper/0/1 caller is debug_smp_processor_id CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.12.0-rc2+ #2 Call Trace: dump_stack check_preemption_disabled debug_smp_processor_id save_microcode_in_initrd_amd ? microcode_init save_microcode_in_initrd ... because, well, it says it above, we're using smp_processor_id() in preemptible code. But passing the CPU number is not really needed. It is only used to determine whether we're on the BSP, and, if so, to save the microcode patch for early loading. [ We don't absolutely need to do it on the BSP but we do that customarily there. ] Instead, convert that function parameter to a boolean which denotes whether the patch should be saved or not, thereby avoiding the use of smp_processor_id() in preemptible code. Signed-off-by: Borislav Petkov Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/20170528200414.31305-1-bp@alien8.de Signed-off-by: Ingo Molnar [arnd: rebased to 4.9, after running into warning: arch/x86/kernel/cpu/microcode/amd.c:881:30: self-comparison always evaluates to true] Signed-off-by: Arnd Bergmann Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/microcode_amd.h | 1 - arch/x86/kernel/cpu/microcode/amd.c | 17 +++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) --- a/arch/x86/include/asm/microcode_amd.h +++ b/arch/x86/include/asm/microcode_amd.h @@ -59,7 +59,6 @@ static inline u16 find_equiv_id(struct e extern int __apply_microcode_amd(struct microcode_amd *mc_amd); extern int apply_microcode_amd(int cpu); -extern enum ucode_state load_microcode_amd(int cpu, u8 family, const u8 *data, size_t size); #define PATCH_MAX_SIZE PAGE_SIZE extern u8 amd_ucode_patch[PATCH_MAX_SIZE]; --- a/arch/x86/kernel/cpu/microcode/amd.c +++ b/arch/x86/kernel/cpu/microcode/amd.c @@ -131,6 +131,9 @@ static size_t compute_container_size(u8 return size; } +static enum ucode_state +load_microcode_amd(bool save, u8 family, const u8 *data, size_t size); + /* * Early load occurs before we can vmalloc(). So we look for the microcode * patch container file in initrd, traverse equivalent cpu table, look for a @@ -438,7 +441,7 @@ int __init save_microcode_in_initrd_amd( eax = cpuid_eax(0x00000001); eax = ((eax >> 8) & 0xf) + ((eax >> 20) & 0xff); - ret = load_microcode_amd(smp_processor_id(), eax, container, container_size); + ret = load_microcode_amd(true, eax, container, container_size); if (ret != UCODE_OK) retval = -EINVAL; @@ -854,7 +857,8 @@ static enum ucode_state __load_microcode return UCODE_OK; } -enum ucode_state load_microcode_amd(int cpu, u8 family, const u8 *data, size_t size) +static enum ucode_state +load_microcode_amd(bool save, u8 family, const u8 *data, size_t size) { enum ucode_state ret; @@ -868,8 +872,8 @@ enum ucode_state load_microcode_amd(int #ifdef CONFIG_X86_32 /* save BSP's matching patch for early load */ - if (cpu_data(cpu).cpu_index == boot_cpu_data.cpu_index) { - struct ucode_patch *p = find_patch(cpu); + if (save) { + struct ucode_patch *p = find_patch(0); if (p) { memset(amd_ucode_patch, 0, PATCH_MAX_SIZE); memcpy(amd_ucode_patch, p->data, min_t(u32, ksize(p->data), @@ -901,11 +905,12 @@ static enum ucode_state request_microcod { char fw_name[36] = "amd-ucode/microcode_amd.bin"; struct cpuinfo_x86 *c = &cpu_data(cpu); + bool bsp = c->cpu_index == boot_cpu_data.cpu_index; enum ucode_state ret = UCODE_NFOUND; const struct firmware *fw; /* reload ucode container only on the boot cpu */ - if (!refresh_fw || c->cpu_index != boot_cpu_data.cpu_index) + if (!refresh_fw || !bsp) return UCODE_OK; if (c->x86 >= 0x15) @@ -922,7 +927,7 @@ static enum ucode_state request_microcod goto fw_release; } - ret = load_microcode_amd(cpu, c->x86, fw->data, fw->size); + ret = load_microcode_amd(bsp, c->x86, fw->data, fw->size); fw_release: release_firmware(fw);