From patchwork Wed Jan 22 22:30:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eslam Elnikety X-Patchwork-Id: 11346473 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 75F2117EA for ; Wed, 22 Jan 2020 22:32:33 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5085224673 for ; Wed, 22 Jan 2020 22:32:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="DxUb1RJL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5085224673 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuOXA-0001LR-TY; Wed, 22 Jan 2020 22:31:36 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuOX9-0001LC-K5 for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 22:31:35 +0000 X-Inumbo-ID: ed48a77e-3d66-11ea-9fd7-bc764e2007e4 Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ed48a77e-3d66-11ea-9fd7-bc764e2007e4; Wed, 22 Jan 2020 22:31:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1579732287; x=1611268287; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=fAU7RXcVYKM4RzTTmYku+vAXd+8d0igXKYPM4rM5cTk=; b=DxUb1RJLiMLbtKMVG9I1Qcdadx9UeNo+XhKBe3ElZJpffi2qfLpm1rYp 4e1A2pq9cCj3VlEBCCezpDtv10plp9qUn0NQIAObmJUipLXxolQ96Kl8P 3bsy1MQBeHhjz6+ztMcq/uhYPMwDy6HWRZ9Ey11ubVAT8QvCN59dD3J5A w=; IronPort-SDR: HAS62dKdjtrt3cp+6ROnN/LOwJ0Vf/gJFpG80jEA6E0R1s1Zx4NQ7o7lkIZtmEkhk38xoRFA8K fB+9l0ifbY5A== X-IronPort-AV: E=Sophos;i="5.70,351,1574121600"; d="scan'208";a="21840651" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-6e2fc477.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 22 Jan 2020 22:31:16 +0000 Received: from EX13MTAUEE002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-6e2fc477.us-west-2.amazon.com (Postfix) with ESMTPS id 12FD3A1DA4; Wed, 22 Jan 2020 22:31:14 +0000 (UTC) Received: from EX13D08UEE001.ant.amazon.com (10.43.62.126) by EX13MTAUEE002.ant.amazon.com (10.43.62.24) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 22 Jan 2020 22:31:13 +0000 Received: from EX13MTAUEA001.ant.amazon.com (10.43.61.82) by EX13D08UEE001.ant.amazon.com (10.43.62.126) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 22 Jan 2020 22:31:13 +0000 Received: from dev-dsk-elnikety-1b-cd63f796.eu-west-1.amazon.com (10.15.63.96) by mail-relay.amazon.com (10.43.61.243) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Wed, 22 Jan 2020 22:31:13 +0000 Received: by dev-dsk-elnikety-1b-cd63f796.eu-west-1.amazon.com (Postfix, from userid 6438462) id 30E0CA013F; Wed, 22 Jan 2020 22:31:13 +0000 (UTC) From: Eslam Elnikety To: Date: Wed, 22 Jan 2020 22:30:43 +0000 Message-ID: <29772dcab47696af624d9c0a9026af38ac3be577.1579727989.git.elnikety@amazon.com> X-Mailer: git-send-email 2.16.6 In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v1 1/4] x86/microcode: Improve documentation for ucode= X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Eslam Elnikety , Paul Durrant , David Woodhouse Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Specify applicability and the default value. Also state that, in case of EFI, the microcode update blob specified in the EFI cfg takes precedence over `ucode=scan`, if the latter is specified on Xen commend line. No functional changes. Signed-off-by: Eslam Elnikety Reviewed-by: Jan Beulich --- docs/misc/xen-command-line.pandoc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line.pandoc index 981a5e2381..ebec6d387e 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -2134,7 +2134,12 @@ logic applies: ### ucode (x86) > `= List of [ | scan=, nmi= ]` -Specify how and where to find CPU microcode update blob. + Applicability: x86 + Default: `nmi` + +Controls for CPU microcode loading. For early loading, this parameter can +specify how and where to find the microcode update blob. For late loading, +this parameter specifies if the update happens within a NMI handler. 'integer' specifies the CPU microcode update blob module index. When positive, this specifies the n-th module (in the GrUB entry, zero based) to be used @@ -2152,6 +2157,7 @@ image that contains microcode. Depending on the platform the blob with the microcode in the cpio name space must be: - on Intel: kernel/x86/microcode/GenuineIntel.bin - on AMD : kernel/x86/microcode/AuthenticAMD.bin +If EFI boot, the `ucode=` config takes precendence over `scan`. 'nmi' determines late loading is performed in NMI handler or just in stop_machine context. In NMI handler, even NMIs are blocked, which is From patchwork Wed Jan 22 22:30:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eslam Elnikety X-Patchwork-Id: 11346469 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 106191580 for ; Wed, 22 Jan 2020 22:32:18 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E086D2465A for ; Wed, 22 Jan 2020 22:32:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="fKuPlmNp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E086D2465A Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuOWw-0001It-JN; Wed, 22 Jan 2020 22:31:22 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuOWv-0001If-8d for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 22:31:21 +0000 X-Inumbo-ID: e9e8abec-3d66-11ea-8e9a-bc764e2007e4 Received: from smtp-fw-4101.amazon.com (unknown [72.21.198.25]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e9e8abec-3d66-11ea-8e9a-bc764e2007e4; Wed, 22 Jan 2020 22:31:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1579732281; x=1611268281; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=m88SymQhWYJsFn/a/6K8UsMRfgoU0u5Lte066UUwfz4=; b=fKuPlmNp36x3Ye55MUxDsVnZpl95el35xq9ygnt0z/5+WhHAkYAZWM6h xw3fWyg6zC2AelHln020foR4xbOzjBORrYq5aJUXBv0WNhE/H+fMLbPDp eik4k2L/tYEOAHpa90DC5bHLik91woczXeGOevqW1V4b86Z0WRxhF9du8 A=; IronPort-SDR: kaQnJaGf0yD00u07wNHosPW3Z6y4jZZi1CggqU1TpSyzxv/4gR5QKLzFPeKpUGecpkM2MrQps/ qEqVZPkNENXA== X-IronPort-AV: E=Sophos;i="5.70,351,1574121600"; d="scan'208";a="13688933" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-22cc717f.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 22 Jan 2020 22:31:19 +0000 Received: from EX13MTAUEE002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-22cc717f.us-west-2.amazon.com (Postfix) with ESMTPS id 3325DA1CC0; Wed, 22 Jan 2020 22:31:18 +0000 (UTC) Received: from EX13D08UEE003.ant.amazon.com (10.43.62.118) by EX13MTAUEE002.ant.amazon.com (10.43.62.24) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 22 Jan 2020 22:31:17 +0000 Received: from EX13MTAUWC001.ant.amazon.com (10.43.162.135) by EX13D08UEE003.ant.amazon.com (10.43.62.118) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 22 Jan 2020 22:31:17 +0000 Received: from dev-dsk-elnikety-1b-cd63f796.eu-west-1.amazon.com (10.15.63.96) by mail-relay.amazon.com (10.43.162.232) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Wed, 22 Jan 2020 22:31:16 +0000 Received: by dev-dsk-elnikety-1b-cd63f796.eu-west-1.amazon.com (Postfix, from userid 6438462) id 39AF7A013F; Wed, 22 Jan 2020 22:31:16 +0000 (UTC) From: Eslam Elnikety To: Date: Wed, 22 Jan 2020 22:30:44 +0000 Message-ID: X-Mailer: git-send-email 2.16.6 In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v1 2/4] x86/microcode: Improve parsing for ucode= X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Eslam Elnikety , Paul Durrant , David Woodhouse , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Decouple the microcode indexing mechanism when using GRUB to that when using EFI. This allows us to avoid the "unspecified effect" of using `` when booting via EFI. With that, Xen can explicitly ignore that option when using EFI. This is the only functinal change this commit introduces. Update the command line documentation for consistency. As an added benefit, the 'parse_ucode' logic becomes independent of GRUB vs. EFI. While at it, drop the leading comment for parse_ucode. No practical use for it given this commit. Signed-off-by: Eslam Elnikety --- docs/misc/xen-command-line.pandoc | 6 ++--- xen/arch/x86/microcode.c | 38 +++++++++++++++++-------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line.pandoc index ebec6d387e..821b9281a1 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -2147,9 +2147,9 @@ for updating CPU micrcode. When negative, counting starts at the end of the modules in the GrUB entry (so with the blob commonly being last, one could specify `ucode=-1`). Note that the value of zero is not valid here (entry zero, i.e. the first module, is always the Dom0 kernel -image). Note further that use of this option has an unspecified effect -when used with xen.efi (there the concept of modules doesn't exist, and -the blob gets specified via the `ucode=` config file/section +image). This option should be used only with legacy boot, as it is explicitly +ignored in EFI boot. When booting via EFI, the microcode update blob for +early loading can be specified via the `ucode=` config file/section entry; see [EFI configuration file description](efi.html)). 'scan' instructs the hypervisor to scan the multiboot images for an cpio diff --git a/xen/arch/x86/microcode.c b/xen/arch/x86/microcode.c index 6ced293d88..e1d98fa55e 100644 --- a/xen/arch/x86/microcode.c +++ b/xen/arch/x86/microcode.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -61,6 +62,7 @@ static module_t __initdata ucode_mod; static signed int __initdata ucode_mod_idx; static bool_t __initdata ucode_mod_forced; +static unsigned int __initdata ucode_mod_efi_idx; static unsigned int nr_cores; /* @@ -105,15 +107,10 @@ static struct microcode_patch *microcode_cache; void __init microcode_set_module(unsigned int idx) { - ucode_mod_idx = idx; + ucode_mod_efi_idx = idx; ucode_mod_forced = 1; } -/* - * The format is '[|scan=, nmi=]'. Both options are - * optional. If the EFI has forced which of the multiboot payloads is to be - * used, only nmi= is parsed. - */ static int __init parse_ucode(const char *s) { const char *ss; @@ -126,18 +123,15 @@ static int __init parse_ucode(const char *s) if ( (val = parse_boolean("nmi", s, ss)) >= 0 ) ucode_in_nmi = val; - else if ( !ucode_mod_forced ) /* Not forced by EFI */ + else if ( (val = parse_boolean("scan", s, ss)) >= 0 ) + ucode_scan = val; + else { - if ( (val = parse_boolean("scan", s, ss)) >= 0 ) - ucode_scan = val; - else - { - const char *q; - - ucode_mod_idx = simple_strtol(s, &q, 0); - if ( q != ss ) - rc = -EINVAL; - } + const char *q; + + ucode_mod_idx = simple_strtol(s, &q, 0); + if ( q != ss ) + rc = -EINVAL; } s = ss + 1; @@ -228,6 +222,16 @@ void __init microcode_grab_module( { module_t *mod = (module_t *)__va(mbi->mods_addr); + if ( efi_enabled(EFI_BOOT) ) + { + if ( ucode_mod_forced ) /* Microcode specified by EFI */ + { + ucode_mod = mod[ucode_mod_efi_idx]; + return; + } + goto scan; + } + if ( ucode_mod_idx < 0 ) ucode_mod_idx += mbi->mods_count; if ( ucode_mod_idx <= 0 || ucode_mod_idx >= mbi->mods_count || From patchwork Wed Jan 22 22:30:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eslam Elnikety X-Patchwork-Id: 11346477 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB5171580 for ; Wed, 22 Jan 2020 22:32:36 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B5E412465A for ; Wed, 22 Jan 2020 22:32:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="RW6LN0pZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B5E412465A Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuOXH-0001O1-Cp; Wed, 22 Jan 2020 22:31:43 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuOXF-0001NV-N7 for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 22:31:41 +0000 X-Inumbo-ID: f327afb4-3d66-11ea-9fd7-bc764e2007e4 Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f327afb4-3d66-11ea-9fd7-bc764e2007e4; Wed, 22 Jan 2020 22:31:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1579732297; x=1611268297; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=XVLnbyI/SlwGUPRjs+LfGlAsyj5+DZwVuaaPD2CCjk8=; b=RW6LN0pZRAj0xLz71cDKqawj8IDSXLTzy3Pqmp3extN3HFOKh8hg/64t /kbXX/yOPIBk2xeR6hbo65TX7KNrv6HfwL5BbbtP0nVcZLRHKdXrtCl6c BvR9wq1O2ajS81I1rPFojg0//nbIRK2RLEJOci6P4mC6hjLZS/vCqaL7p c=; IronPort-SDR: b/Cb17eUpl4Be2938vgHk5NAZy3cIy9n9cb0geHYXKkQ2tfcqvLkDhOXUgaAleZRwlO3Rl2NdF gcU48Ayv1tUQ== X-IronPort-AV: E=Sophos;i="5.70,351,1574121600"; d="scan'208";a="21840710" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-c5104f52.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 22 Jan 2020 22:31:36 +0000 Received: from EX13MTAUEE002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-c5104f52.us-west-2.amazon.com (Postfix) with ESMTPS id B03F2A187F; Wed, 22 Jan 2020 22:31:35 +0000 (UTC) Received: from EX13D08UEE004.ant.amazon.com (10.43.62.182) by EX13MTAUEE002.ant.amazon.com (10.43.62.24) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 22 Jan 2020 22:31:20 +0000 Received: from EX13MTAUWC001.ant.amazon.com (10.43.162.135) by EX13D08UEE004.ant.amazon.com (10.43.62.182) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 22 Jan 2020 22:31:19 +0000 Received: from dev-dsk-elnikety-1b-cd63f796.eu-west-1.amazon.com (10.15.63.96) by mail-relay.amazon.com (10.43.162.232) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Wed, 22 Jan 2020 22:31:18 +0000 Received: by dev-dsk-elnikety-1b-cd63f796.eu-west-1.amazon.com (Postfix, from userid 6438462) id B5D7EA013F; Wed, 22 Jan 2020 22:31:18 +0000 (UTC) From: Eslam Elnikety To: Date: Wed, 22 Jan 2020 22:30:45 +0000 Message-ID: X-Mailer: git-send-email 2.16.6 In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v1 3/4] x86/microcode: avoid unnecessary xmalloc/memcpy of ucode data X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Konrad Rzeszutek Wilk , Andrew Cooper , Eslam Elnikety , Paul Durrant , David Woodhouse , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" When using `ucode=scan` and if a matching module is found, the microcode payload is maintained in an xmalloc()'d region. This is unnecessary since the bootmap would just do. Remove the xmalloc and xfree on the microcode module scan path. This commit also does away with the restriction on the microcode module size limit. The concern that a large microcode module would consume too much memory preventing guests launch is misplaced since this is all the init path. While having such safeguards is valuable, this should apply across the board for all early/late microcode loading. Having it just on the `scan` path is confusing. Looking forward, we are a bit closer (i.e., one xmalloc down) to pulling the early microcode loading of the BSP a bit earlier in the early boot process. This commit is the low hanging fruit. There is still a sizable amount of work to get there as there are still a handful of xmalloc in microcode_{amd,intel}.c. First, there are xmallocs on the path of finding a matching microcode update. Similar to the commit at hand, searching through the microcode blob can be done on the already present buffer with no need to xmalloc any further. Even better, do the filtering in microcode.c before requesting the microcode update on all CPUs. The latter requires careful restructuring and exposing the arch-specific logic for iterating over patches and declaring a match. Second, there are xmallocs for the microcode cache. Here, we would need to ensure that the cache corresponding to the BSP gets xmalloc()'d and populated after the fact. Signed-off-by: Eslam Elnikety Acked-by: Jan Beulich --- xen/arch/x86/microcode.c | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/xen/arch/x86/microcode.c b/xen/arch/x86/microcode.c index e1d98fa55e..a662a7f438 100644 --- a/xen/arch/x86/microcode.c +++ b/xen/arch/x86/microcode.c @@ -141,11 +141,6 @@ static int __init parse_ucode(const char *s) } custom_param("ucode", parse_ucode); -/* - * 8MB ought to be enough. - */ -#define MAX_EARLY_CPIO_MICROCODE (8 << 20) - void __init microcode_scan_module( unsigned long *module_map, const multiboot_info_t *mbi) @@ -190,31 +185,12 @@ void __init microcode_scan_module( cd = find_cpio_data(p, _blob_start, _blob_size, &offset /* ignore */); if ( cd.data ) { - /* - * This is an arbitrary check - it would be sad if the blob - * consumed most of the memory and did not allow guests - * to launch. - */ - if ( cd.size > MAX_EARLY_CPIO_MICROCODE ) - { - printk("Multiboot %d microcode payload too big! (%ld, we can do %d)\n", - i, cd.size, MAX_EARLY_CPIO_MICROCODE); - goto err; - } - ucode_blob.size = cd.size; - ucode_blob.data = xmalloc_bytes(cd.size); - if ( !ucode_blob.data ) - cd.data = NULL; - else - memcpy(ucode_blob.data, cd.data, cd.size); + ucode_blob.size = cd.size; + ucode_blob.data = cd.data; + break; } bootstrap_map(NULL); - if ( cd.data ) - break; } - return; -err: - bootstrap_map(NULL); } void __init microcode_grab_module( unsigned long *module_map, @@ -734,7 +710,7 @@ static int __init microcode_init(void) */ if ( ucode_blob.size ) { - xfree(ucode_blob.data); + bootstrap_map(NULL); ucode_blob.size = 0; ucode_blob.data = NULL; } From patchwork Wed Jan 22 22:30:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eslam Elnikety X-Patchwork-Id: 11346475 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BC9DE1580 for ; Wed, 22 Jan 2020 22:32:35 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 993082465A for ; Wed, 22 Jan 2020 22:32:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="txEajif6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 993082465A Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuOXI-0001Oq-Mf; Wed, 22 Jan 2020 22:31:44 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuOXH-0001Nz-Cb for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 22:31:43 +0000 X-Inumbo-ID: f6d3de30-3d66-11ea-9fd7-bc764e2007e4 Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f6d3de30-3d66-11ea-9fd7-bc764e2007e4; Wed, 22 Jan 2020 22:31:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1579732303; x=1611268303; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=RXakqAv07gSm+Bln1odnWQRor3fccRpXMFbY/j5+SBw=; b=txEajif6CQjSSYdZvstUVes6JQJU9vwRZNjDSr7XdhlGR80X1MStj/xK NUhrLjqgDF3+9reUxi34wkF/7GH527RSSSUAgX9+EaTVvv2Q1IFZN8cMy hI/OA/ZRrMwkmGuuBHiIyN6jSE9aQljpanB8rr64Uw+5/S2dLbvw4cqdg Y=; IronPort-SDR: efg0gYaZ8OlIjBJ/8AewE/qThhw//qZO+pqJiTRKCvqOm3udt/Zm0f2L7MOwArpGLDwpYicBDd 9EWVODbL0zpw== X-IronPort-AV: E=Sophos;i="5.70,351,1574121600"; d="scan'208";a="20473235" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-d0be17ee.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 22 Jan 2020 22:31:23 +0000 Received: from EX13MTAUEB002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-d0be17ee.us-west-2.amazon.com (Postfix) with ESMTPS id AC1AAA248F; Wed, 22 Jan 2020 22:31:22 +0000 (UTC) Received: from EX13D08UEB003.ant.amazon.com (10.43.60.11) by EX13MTAUEB002.ant.amazon.com (10.43.60.12) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 22 Jan 2020 22:31:22 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX13D08UEB003.ant.amazon.com (10.43.60.11) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 22 Jan 2020 22:31:21 +0000 Received: from dev-dsk-elnikety-1b-cd63f796.eu-west-1.amazon.com (10.15.63.96) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Wed, 22 Jan 2020 22:31:21 +0000 Received: by dev-dsk-elnikety-1b-cd63f796.eu-west-1.amazon.com (Postfix, from userid 6438462) id AA3E1A013F; Wed, 22 Jan 2020 22:31:20 +0000 (UTC) From: Eslam Elnikety To: Date: Wed, 22 Jan 2020 22:30:46 +0000 Message-ID: <934b1959c740f9ee401f2740478d61cdaa138c72.1579727989.git.elnikety@amazon.com> X-Mailer: git-send-email 2.16.6 In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v1 4/4] x86/microcode: use const qualifier for microcode buffer X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Konrad Rzeszutek Wilk , Andrew Cooper , Eslam Elnikety , Paul Durrant , David Woodhouse , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The buffer holding the microcode bits should be marked as const. Signed-off-by: Eslam Elnikety Acked-by: Jan Beulich --- xen/arch/x86/microcode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/microcode.c b/xen/arch/x86/microcode.c index a662a7f438..0639551173 100644 --- a/xen/arch/x86/microcode.c +++ b/xen/arch/x86/microcode.c @@ -88,7 +88,7 @@ static enum { * memory. */ struct ucode_mod_blob { - void *data; + const void *data; size_t size; }; @@ -753,7 +753,7 @@ int microcode_update_one(bool start_update) int __init early_microcode_update_cpu(void) { int rc = 0; - void *data = NULL; + const void *data = NULL; size_t len; struct microcode_patch *patch;