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 ||