From patchwork Mon Oct 26 17:25:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11857889 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 99F20139F for ; Mon, 26 Oct 2020 17:26:47 +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 6394B2224A for ; Mon, 26 Oct 2020 17:26:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="heZv7/3T" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6394B2224A Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.12501.32570 (Exim 4.92) (envelope-from ) id 1kX6Fr-0004Vs-F3; Mon, 26 Oct 2020 17:25:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 12501.32570; Mon, 26 Oct 2020 17:25:59 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kX6Fr-0004Vh-BI; Mon, 26 Oct 2020 17:25:59 +0000 Received: by outflank-mailman (input) for mailman id 12501; Mon, 26 Oct 2020 17:25:57 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kX6Fp-0004UI-R8 for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 17:25:57 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ba839629-3739-46e5-9838-5a6827041efd; Mon, 26 Oct 2020 17:25:56 +0000 (UTC) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kX6Fp-0004UI-R8 for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 17:25:57 +0000 X-Inumbo-ID: ba839629-3739-46e5-9838-5a6827041efd Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ba839629-3739-46e5-9838-5a6827041efd; Mon, 26 Oct 2020 17:25:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1603733156; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nO7Qr7V6r7ZHR8K0sMdn1GJ/DwtEeYhxjW4WWT4T3NU=; b=heZv7/3TLNmlMc2Pveatv6cAyO7ECJrenlRTBs0UuXo00kNAnQ6HJebA 8iGaitDKMBCehtrJ10xvcTaRDsxXpLtbJCvH8OMo3xPr9r0bB5/+sLJyd FpY/0+zD23gKyQV9dKRUFg1HVJTRn0ewRkOgHwTIDtK02NSgdkRlOx0m0 U=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: lGVp5LQRwa7XhBUO7HSZMpI7+PjUyiPEgfU6FBq5AXzG3dTwVyujYJUgr0FBZTd/dBKNFBeJ2b NSe4YHuqS6BvwKY4aoXBiBuSaSNQtccJ/EAEHMpg9OQdxS1XYF6Pa3/PIoS/cuF2IiV7ugkLLU jkdVev3TaAlU6sPZpfGVXXZ8SsFiq35j3srlovjqsbJfPOuDA2KaiyZEPuf6XdiHSbOVykd3SZ yePPIoxUAr8I6m+Mu2u/YfuLZ/Q3Gj5J8DVbxpLJfkWkhhFa4eSH/imZ32/GnyQMGvA11aUSmb JSg= X-SBRS: None X-MesageID: 30138966 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.77,420,1596513600"; d="scan'208";a="30138966" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Juergen Gross , Igor Druzhinin Subject: [PATCH 3/3] x86/ucode: Introduce ucode=allow-same for testing purposes Date: Mon, 26 Oct 2020 17:25:19 +0000 Message-ID: <20201026172519.17881-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201026172519.17881-1-andrew.cooper3@citrix.com> References: <20201026172519.17881-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Many CPUs will actually reload microcode when offered the same version as currently loaded. This allows for easy testing of the late microcode loading path. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monné CC: Wei Liu CC: Juergen Gross CC: Igor Druzhinin I was hoping to make this a runtime parameter, but I honestly can't figure out the new HYPFS-only infrastructure is supposed to work. --- docs/misc/xen-command-line.pandoc | 7 ++++++- xen/arch/x86/cpu/microcode/amd.c | 3 +++ xen/arch/x86/cpu/microcode/core.c | 4 ++++ xen/arch/x86/cpu/microcode/intel.c | 3 +++ xen/arch/x86/cpu/microcode/private.h | 2 ++ 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line.pandoc index 4ae9391fcd..97b1cc67a4 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -2216,7 +2216,7 @@ logic applies: active by default. ### ucode -> `= List of [ | scan=, nmi= ]` +> `= List of [ | scan=, nmi=, allow-same= ]` Applicability: x86 Default: `nmi` @@ -2248,6 +2248,11 @@ precedence over `scan`. stop_machine context. In NMI handler, even NMIs are blocked, which is considered safer. The default value is `true`. +'allow-same' alters the default acceptance policy for new microcode to permit +trying to reload the same version. Many CPUs will actually reload microcode +of the same version, and this allows for easily testing of the late microcode +loading path. + ### unrestricted_guest (Intel) > `= ` diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/amd.c index 7d2f57c4cb..5255028af7 100644 --- a/xen/arch/x86/cpu/microcode/amd.c +++ b/xen/arch/x86/cpu/microcode/amd.c @@ -174,6 +174,9 @@ static enum microcode_match_result compare_revisions( if ( new_rev > old_rev ) return NEW_UCODE; + if ( opt_ucode_allow_same && new_rev == old_rev ) + return NEW_UCODE; + return OLD_UCODE; } diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode/core.c index 18ebc07b13..ac3ceb567c 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -95,6 +95,8 @@ static bool_t __initdata ucode_scan; /* By default, ucode loading is done in NMI handler */ static bool ucode_in_nmi = true; +bool __read_mostly opt_ucode_allow_same; + /* Protected by microcode_mutex */ static struct microcode_patch *microcode_cache; @@ -121,6 +123,8 @@ static int __init parse_ucode(const char *s) if ( (val = parse_boolean("nmi", s, ss)) >= 0 ) ucode_in_nmi = val; + else if ( (val = parse_boolean("allow-same", s, ss)) >= 0 ) + opt_ucode_allow_same = val; else if ( !ucode_mod_forced ) /* Not forced by EFI */ { if ( (val = parse_boolean("scan", s, ss)) >= 0 ) diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcode/intel.c index 5fa2821cdb..f6d01490e0 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -232,6 +232,9 @@ static enum microcode_match_result compare_revisions( if ( new_rev > old_rev ) return NEW_UCODE; + if ( opt_ucode_allow_same && new_rev == old_rev ) + return NEW_UCODE; + /* * Treat pre-production as always applicable - anyone using pre-production * microcode knows what they are doing, and can keep any resulting pieces. diff --git a/xen/arch/x86/cpu/microcode/private.h b/xen/arch/x86/cpu/microcode/private.h index 9a15cdc879..c085a10268 100644 --- a/xen/arch/x86/cpu/microcode/private.h +++ b/xen/arch/x86/cpu/microcode/private.h @@ -3,6 +3,8 @@ #include +extern bool opt_ucode_allow_same; + enum microcode_match_result { OLD_UCODE, /* signature matched, but revision id is older or equal */ NEW_UCODE, /* signature matched, but revision id is newer */