From patchwork Wed Dec 18 01:32:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eslam Elnikety X-Patchwork-Id: 11299283 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 0C11014B7 for ; Wed, 18 Dec 2019 01:34:41 +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 DBE6621582 for ; Wed, 18 Dec 2019 01:34:40 +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="WdNGK2Z3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DBE6621582 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 1ihODh-0005xD-Rm; Wed, 18 Dec 2019 01:33:45 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihODg-0005ww-MV for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 01:33:44 +0000 X-Inumbo-ID: 6668b312-2136-11ea-88e7-bc764e2007e4 Received: from smtp-fw-6002.amazon.com (unknown [52.95.49.90]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6668b312-2136-11ea-88e7-bc764e2007e4; Wed, 18 Dec 2019 01:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1576632812; x=1608168812; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=woBHRDSKm54ARLN5YytkBGBwJxc+m97Qhe1raLgjMb4=; b=WdNGK2Z3Rti9n2gDSFMMgz07MxaNzPKFZAHQyPWLtldaDbevc3tJcOyN qlCcRl/SmAEzy0UNpEhQmE6fMwwwikQ5+cYaL4Zo9m4PhG+pF/zFvUUEl DK0fBEvLTrG3nPeOdE9DfsYycbt1fUP9Fxv8CiMs+AxMl2905XMkdYGhp M=; IronPort-SDR: WG0zjMbp7D6xmr4Lzj1EhZrqqoTQL4sCntqMwAvdHlzQ0ro/Vf6Eb8YBun8G0NUiHBNnfBxVeE IQTI897ugh1A== X-IronPort-AV: E=Sophos;i="5.69,327,1571702400"; d="scan'208";a="8101741" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-e7be2041.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 18 Dec 2019 01:33:31 +0000 Received: from EX13MTAUEB002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-e7be2041.us-west-2.amazon.com (Postfix) with ESMTPS id 87E8AA21D9; Wed, 18 Dec 2019 01:33:29 +0000 (UTC) Received: from EX13D08UEB001.ant.amazon.com (10.43.60.245) by EX13MTAUEB002.ant.amazon.com (10.43.60.12) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 18 Dec 2019 01:33:29 +0000 Received: from EX13MTAUEA002.ant.amazon.com (10.43.61.77) by EX13D08UEB001.ant.amazon.com (10.43.60.245) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 18 Dec 2019 01:33:28 +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.169) with Microsoft SMTP Server id 15.0.1236.3 via Frontend Transport; Wed, 18 Dec 2019 01:33:28 +0000 Received: by dev-dsk-elnikety-1b-cd63f796.eu-west-1.amazon.com (Postfix, from userid 6438462) id A191CA0141; Wed, 18 Dec 2019 01:33:28 +0000 (UTC) From: Eslam Elnikety To: Date: Wed, 18 Dec 2019 01:32:56 +0000 Message-ID: <068a32f917937baca179d7ff4c483ec1584defb4.1576630344.git.elnikety@amazon.com> X-Mailer: git-send-email 2.16.5 In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v2 1/4] x86/microcode: Improve documentation and 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 , Jan Beulich , David Woodhouse Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Decouple the microcode referencing mechanism when using GRUB to that when using EFI. This allows us to avoid the "unspecified effect" of using ` | scan` along xen.efi. With that, Xen can explicitly ignore those named options when using EFI. As an added benefit, we get a straightfoward parsing of the ucode parameter. While at it, simplify the logic in microcode_grab_module(). Update the command line documentation for consistency. Also, drop the leading comment for parse_ucode_param. (No practical use for it given this commit). Signed-off-by: Eslam Elnikety --- docs/misc/xen-command-line.pandoc | 18 ++++++++--- xen/arch/x86/microcode.c | 51 ++++++++++++++----------------- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line.pandoc index 7a1be84ca9..40faf3bc3a 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -2128,7 +2128,13 @@ 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 or in +a stop_machine context. '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 @@ -2136,10 +2142,7 @@ 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 -entry; see [EFI configuration file description](efi.html)). +image). 'scan' instructs the hypervisor to scan the multiboot images for an cpio image that contains microcode. Depending on the platform the blob with the @@ -2151,6 +2154,11 @@ microcode in the cpio name space must be: stop_machine context. In NMI handler, even NMIs are blocked, which is considered safer. The default value is `true`. +Note: When booting via EFI, both options 'integer' and 'scan' are ignored. +Here, the concept of modules does not exist. The microcode update blob for +early loading gets specified via the `ucode=` config file/section +entry; see [EFI configuration file description](efi.html)). + ### unrestricted_guest (Intel) > `= ` diff --git a/xen/arch/x86/microcode.c b/xen/arch/x86/microcode.c index 6ced293d88..8b4d87782c 100644 --- a/xen/arch/x86/microcode.c +++ b/xen/arch/x86/microcode.c @@ -60,7 +60,7 @@ static module_t __initdata ucode_mod; static signed int __initdata ucode_mod_idx; -static bool_t __initdata ucode_mod_forced; +static signed int __initdata ucode_mod_efi_idx; static unsigned int nr_cores; /* @@ -105,16 +105,10 @@ static struct microcode_patch *microcode_cache; void __init microcode_set_module(unsigned int idx) { - ucode_mod_idx = idx; - ucode_mod_forced = 1; + ucode_mod_efi_idx = idx; } -/* - * 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) +static int __init parse_ucode_param(const char *s) { const char *ss; int val, rc = 0; @@ -126,18 +120,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; @@ -145,7 +136,7 @@ static int __init parse_ucode(const char *s) return rc; } -custom_param("ucode", parse_ucode); +custom_param("ucode", parse_ucode_param); /* * 8MB ought to be enough. @@ -228,14 +219,18 @@ void __init microcode_grab_module( { module_t *mod = (module_t *)__va(mbi->mods_addr); - if ( ucode_mod_idx < 0 ) + if ( ucode_mod_efi_idx ) /* Microcode specified by EFI */ + { + ucode_mod = mod[ucode_mod_efi_idx]; + return; + } + + if ( ucode_mod_idx < 0 ) /* Count from the end? */ ucode_mod_idx += mbi->mods_count; - if ( ucode_mod_idx <= 0 || ucode_mod_idx >= mbi->mods_count || - !__test_and_clear_bit(ucode_mod_idx, module_map) ) - goto scan; - ucode_mod = mod[ucode_mod_idx]; -scan: - if ( ucode_scan ) + if ( ucode_mod_idx > 0 && ucode_mod_idx < mbi->mods_count && + __test_and_clear_bit(ucode_mod_idx, module_map) ) + ucode_mod = mod[ucode_mod_idx]; + else if ( ucode_scan ) microcode_scan_module(module_map, mbi); }