From patchwork Tue Apr 30 12:47:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fouad Hilly X-Patchwork-Id: 13648934 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 61BC6C4345F for ; Tue, 30 Apr 2024 12:47:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.714807.1116133 (Exim 4.92) (envelope-from ) id 1s1mtO-0005Ga-Si; Tue, 30 Apr 2024 12:47:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 714807.1116133; Tue, 30 Apr 2024 12:47:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1mtO-0005Es-Nw; Tue, 30 Apr 2024 12:47:30 +0000 Received: by outflank-mailman (input) for mailman id 714807; Tue, 30 Apr 2024 12:47:29 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1mtN-0005Ay-IT for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 12:47:29 +0000 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [2a00:1450:4864:20::634]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ccd0812e-06ef-11ef-b4bb-af5377834399; Tue, 30 Apr 2024 14:47:27 +0200 (CEST) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a58a36008ceso662040466b.0 for ; Tue, 30 Apr 2024 05:47:27 -0700 (PDT) Received: from fhilly.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id e14-20020a170906504e00b00a558014ab2csm14165324ejk.145.2024.04.30.05.47.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 05:47:26 -0700 (PDT) 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" X-Inumbo-ID: ccd0812e-06ef-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1714481247; x=1715086047; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bxvxpeo53t3s7EbhOvzZRsMHHwhI5TdimldfKLtVGMc=; b=fMdFeSM77EzxJp2l/OGOd8Lh5enogyE7Z5gqUov6cc1h/XPMrdnlXsGhmFJ42aPMOj Yc7SBBVtGd+QuQWgdffsAvQ1/wPeCaykd3ue1fZbuEPtJBloiF5i8YYqZ6T4Fr+nQdDN UwcZDD3CrgOr33lRLHNeskfo7cGyhmRehqaHQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714481247; x=1715086047; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bxvxpeo53t3s7EbhOvzZRsMHHwhI5TdimldfKLtVGMc=; b=E/MXkPvfXZ+OBvsAr0voYSJPR8cyBrTXSHnpRnJbkdwqii6gBcbmxWxEXtkbUsqeEs bVVgSk/UNTYg+ePLXVU3dA0yp53PYzT3+FFScyhzTSEhHCGUYnLYrjWt+q+0UWJWyD69 O8oURqRxmOlhRq7/TojKsUtjsqEkXA2EUPPwfd0vZXVMSkfN9jkk0n9waL0Txpsl8vSO +lEszZiMh5+2Ej6FJsICBBoUP+OlwwPHJaD4Rl4BHeeRGdOWhGW125EAkjjtT8hVCCFh jLr/BGh0wCZ9wZpG6Zcduo+IxFRs5o4KIfKE5ThyZj9CzOwjr83S8JwJUVUUWt0OKt36 hrAg== X-Gm-Message-State: AOJu0Yy0Wyni/BIflDxW5siG5huPWJ+iZEjrPIQ8aO0Qxch2rv5L/EGF bB309XC+pjFq8J2+JUDuDpj+CgcVvtyjHzxzUTT0p0UEDGLcOkKPWEptc0TIBMbzFJZWdr9AclJ X X-Google-Smtp-Source: AGHT+IEYkZIzhUEArnmSrlxLG95tEEeoD8rk4qvgtIN3V+ZO4wpE/Zw2bddMmewo+3ca9v7SmEH5/g== X-Received: by 2002:a17:906:5fd3:b0:a58:e8c7:c0ae with SMTP id k19-20020a1709065fd300b00a58e8c7c0aemr6933947ejv.16.1714481246781; Tue, 30 Apr 2024 05:47:26 -0700 (PDT) From: Fouad Hilly To: Xen-devel Cc: Fouad Hilly , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v3 1/5] x86: Update x86 low level version check of microcode Date: Tue, 30 Apr 2024 13:47:05 +0100 Message-ID: <20240430124709.865183-2-fouad.hilly@cloud.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240430124709.865183-1-fouad.hilly@cloud.com> References: <20240430124709.865183-1-fouad.hilly@cloud.com> MIME-Version: 1.0 Update microcode version check at Intel and AMD Level by: Preventing the low level code from sending errors if the microcode version is not a newer version. this is required to allow developers to do ucode loading testing, including the introduction of Intel "min rev" field, which requires an override mechanism for newer version checks. Even though the check for newer is removed at this level, it still exists at higher common level, where by default only newer version will be processed. The option to override version check, will be added as part of this patch series. Other errors will be handled as required at this level. Keep all the required code at low level that checks for signature and CPU compatibility Signed-off-by: Fouad Hilly --- [v3] 1- Update intel code to return errors in case of invalid microcode only. 2- Update code comments. 3- Update commit message and its description [v2] Update message description to better describe the changes xen/arch/x86/cpu/microcode/amd.c | 7 +++---- xen/arch/x86/cpu/microcode/intel.c | 10 ++++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/amd.c index 17e68697d5bf..316469ec06e4 100644 --- a/xen/arch/x86/cpu/microcode/amd.c +++ b/xen/arch/x86/cpu/microcode/amd.c @@ -384,11 +384,10 @@ static struct microcode_patch *cf_check cpu_request_microcode( } /* - * If the new ucode covers current CPU, compare ucodes and store the - * one with higher revision. + * If the microcode covers current CPU, then store its + * revision. */ - if ( (microcode_fits(mc->patch) != MIS_UCODE) && - (!saved || (compare_header(mc->patch, saved) == NEW_UCODE)) ) + if ( (microcode_fits(mc->patch) != MIS_UCODE) && !saved ) { saved = mc->patch; saved_size = mc->len; diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcode/intel.c index 96f34b336b21..de9115974d08 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -294,8 +294,7 @@ static int cf_check apply_microcode(const struct microcode_patch *patch) result = microcode_update_match(patch); - if ( result != NEW_UCODE && - !(opt_ucode_allow_same && result == SAME_UCODE) ) + if ( result == MIS_UCODE ) return -EINVAL; wbinvd(); @@ -355,11 +354,10 @@ static struct microcode_patch *cf_check cpu_request_microcode( break; /* - * If the new update covers current CPU, compare updates and store the - * one with higher revision. + * If the microcode covers current CPU, then store its + * revision. */ - if ( (microcode_update_match(mc) != MIS_UCODE) && - (!saved || compare_revisions(saved->rev, mc->rev) == NEW_UCODE) ) + if ( (microcode_update_match(mc) != MIS_UCODE) && !saved ) saved = mc; buf += blob_size; From patchwork Tue Apr 30 12:47:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fouad Hilly X-Patchwork-Id: 13648937 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 3AF46C25B4F for ; Tue, 30 Apr 2024 12:47:40 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.714808.1116137 (Exim 4.92) (envelope-from ) id 1s1mtP-0005KK-4T; Tue, 30 Apr 2024 12:47:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 714808.1116137; Tue, 30 Apr 2024 12:47:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1mtO-0005Id-W9; Tue, 30 Apr 2024 12:47:30 +0000 Received: by outflank-mailman (input) for mailman id 714808; Tue, 30 Apr 2024 12:47:29 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1mtN-0005B4-Qw for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 12:47:29 +0000 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [2a00:1450:4864:20::629]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cd38ed5c-06ef-11ef-909b-e314d9c70b13; Tue, 30 Apr 2024 14:47:28 +0200 (CEST) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a587831809eso676291566b.1 for ; Tue, 30 Apr 2024 05:47:28 -0700 (PDT) Received: from fhilly.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id e14-20020a170906504e00b00a558014ab2csm14165324ejk.145.2024.04.30.05.47.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 05:47:27 -0700 (PDT) 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" X-Inumbo-ID: cd38ed5c-06ef-11ef-909b-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1714481247; x=1715086047; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9wz3B6+A8lhOeY7j5+k4dVHqDybst4sg6UIDJkawnmo=; b=IbnB0jASRMYRdb9IRHzJaIpgfteLF8PAoWBZcLNnGdqizogHUESjHJEisQ7mqusvlp toNJ31SXZwPpMX4hDRds0DAvQcLKDoznoGk6QLmCKGFBNK51zRpbZgXjBTW1aQ9AcaU8 YrYAcP/KBEWgze2JOd1aS91Js6QfHkEHmpm9Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714481247; x=1715086047; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9wz3B6+A8lhOeY7j5+k4dVHqDybst4sg6UIDJkawnmo=; b=GITH2oHyGGnLqIwk+jiZsaOD6ORC1IBL1uG7VZffdAyWknQmlVGrbpRTx/TdaJuIVM k4OpFpmmPPL2ZqKj03fwRBYmw51E9DUgReS2mVkkselv3Se5jJSwYlb1HZk6/qjV9as/ Axv8oTlQ3nepU50e4JSppgzmx8wPVOssR51GvNNNHTmB+G5SQlDEs2OS1WLCizQQ9sms iYwvMeY1h4UNN2BCSRQOtci3eLMIf9bGyQFORuq3k5DV//5B5GuiEvC/b2KLlAruOQGf J52mLkIFVrp1BEmpweTacv+PD2lJeSpYaucrm5yhGMp4bgwtRCt0b+m8aViLGAAq8qf6 yarA== X-Gm-Message-State: AOJu0YxWbpJ01csmS/wFEjCee5RkxRqnkB9qium3cluULBdzzxKqd4LE uI/WVy2aFFouhs9+U7yXwil4WXuKZ74HciSKBV5lwaZABppgdSMizx4yLJmwnTpyHzRGP6P8FLn N X-Google-Smtp-Source: AGHT+IFT7PZwNx8GQNYXEBmUxl3prPSWZyeNF8iQMPJam7XqVplZbEjnynY9LtbJ7JXqxK+WUnqmhg== X-Received: by 2002:a17:906:f20e:b0:a58:fabc:4a02 with SMTP id gt14-20020a170906f20e00b00a58fabc4a02mr5124437ejb.39.1714481247604; Tue, 30 Apr 2024 05:47:27 -0700 (PDT) From: Fouad Hilly To: Xen-devel Cc: Fouad Hilly , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , George Dunlap , Julien Grall , Stefano Stabellini Subject: [PATCH v3 2/5] x86: Refactor microcode_update() hypercall with flags Date: Tue, 30 Apr 2024 13:47:06 +0100 Message-ID: <20240430124709.865183-3-fouad.hilly@cloud.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240430124709.865183-1-fouad.hilly@cloud.com> References: <20240430124709.865183-1-fouad.hilly@cloud.com> MIME-Version: 1.0 Refactor microcode_update() by adding a flags field. struct xenpf_microcode_update2 added with uint32_t flags field. Introduce XENPF_microcode_update2 hypercall to handle flags field. Introduce ucode_force_flag to microcode_update_helper. Signed-off-by: Fouad Hilly --- [v3] 1- Updated Commit message description. 2- Revereted changes to a stable ABI and introduced a new struct. 3- ucode_force_flag updated from static to a local variable. 4- microcode_update() updated to reject unsupported flags yet. [v2] 1- Update message description to highlight interface change. 2- Removed extra empty lines. 3- removed unnecessary define. 4- Corrected long lines. 5- Removed ternary operator. 6- Introduced static ucode_update_flags, which will be used later to determine local ucode_force_flag. xen/arch/x86/cpu/microcode/core.c | 15 ++++++++++++--- xen/arch/x86/include/asm/microcode.h | 3 ++- xen/arch/x86/platform_hypercall.c | 12 +++++++++++- xen/include/public/platform.h | 14 ++++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode/core.c index e738a88f5cd1..4a18ddd2683b 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -40,6 +40,8 @@ #include #include +#include + #include "private.h" /* @@ -570,6 +572,7 @@ static int cf_check do_microcode_update(void *patch) } struct ucode_buf { + unsigned int flags; unsigned int len; char buffer[]; }; @@ -580,6 +583,7 @@ static long cf_check microcode_update_helper(void *data) struct ucode_buf *buffer = data; unsigned int cpu, updated; struct microcode_patch *patch; + bool ucode_force_flag = buffer->flags == XENPF_UCODE_FLAG_FORCE_SET; /* cpu_online_map must not change during update */ if ( !get_cpu_maps() ) @@ -633,12 +637,12 @@ static long cf_check microcode_update_helper(void *data) microcode_cache); if ( result != NEW_UCODE && - !(opt_ucode_allow_same && result == SAME_UCODE) ) + !((opt_ucode_allow_same || ucode_force_flag) && result == SAME_UCODE) ) { spin_unlock(µcode_mutex); printk(XENLOG_WARNING "microcode: couldn't find any newer%s revision in the provided blob!\n", - opt_ucode_allow_same ? " (or the same)" : ""); + (opt_ucode_allow_same || ucode_force_flag) ? " (or the same)" : ""); microcode_free_patch(patch); ret = -ENOENT; @@ -708,11 +712,15 @@ static long cf_check microcode_update_helper(void *data) return ret; } -int microcode_update(XEN_GUEST_HANDLE(const_void) buf, unsigned long len) +int microcode_update(XEN_GUEST_HANDLE(const_void) buf, + unsigned long len, unsigned int flags) { int ret; struct ucode_buf *buffer; + if ( flags > 1 ) + return -EINVAL; + if ( len != (uint32_t)len ) return -E2BIG; @@ -730,6 +738,7 @@ int microcode_update(XEN_GUEST_HANDLE(const_void) buf, unsigned long len) return -EFAULT; } buffer->len = len; + buffer->flags = flags; /* * Always queue microcode_update_helper() on CPU0. Most of the logic diff --git a/xen/arch/x86/include/asm/microcode.h b/xen/arch/x86/include/asm/microcode.h index 8f59b20b0289..57c08205d475 100644 --- a/xen/arch/x86/include/asm/microcode.h +++ b/xen/arch/x86/include/asm/microcode.h @@ -22,7 +22,8 @@ struct cpu_signature { DECLARE_PER_CPU(struct cpu_signature, cpu_sig); void microcode_set_module(unsigned int idx); -int microcode_update(XEN_GUEST_HANDLE(const_void) buf, unsigned long len); +int microcode_update(XEN_GUEST_HANDLE(const_void) buf, + unsigned long len, unsigned int flags); int early_microcode_init(unsigned long *module_map, const struct multiboot_info *mbi); int microcode_init_cache(unsigned long *module_map, diff --git a/xen/arch/x86/platform_hypercall.c b/xen/arch/x86/platform_hypercall.c index 95467b88ab64..a22f2929896e 100644 --- a/xen/arch/x86/platform_hypercall.c +++ b/xen/arch/x86/platform_hypercall.c @@ -311,7 +311,17 @@ ret_t do_platform_op( guest_from_compat_handle(data, op->u.microcode.data); - ret = microcode_update(data, op->u.microcode.length); + ret = microcode_update(data, op->u.microcode.length, 0); + break; + } + + case XENPF_microcode_update2: + { + XEN_GUEST_HANDLE(const_void) data; + + guest_from_compat_handle(data, op->u.microcode2.data); + + ret = microcode_update(data, op->u.microcode2.length, op->u.microcode2.flags); break; } diff --git a/xen/include/public/platform.h b/xen/include/public/platform.h index 15777b541690..a30de7153779 100644 --- a/xen/include/public/platform.h +++ b/xen/include/public/platform.h @@ -624,6 +624,19 @@ struct xenpf_ucode_revision { typedef struct xenpf_ucode_revision xenpf_ucode_revision_t; DEFINE_XEN_GUEST_HANDLE(xenpf_ucode_revision_t); +/* Hypercall to microcode_update with flags */ +#define XENPF_microcode_update2 66 +struct xenpf_microcode_update2 { + /* IN variables. */ + uint32_t flags; /* Flags to be passed with ucode. */ +/* Force to skip microcode version check when set */ +#define XENPF_UCODE_FLAG_FORCE_SET 1 + uint32_t length; /* Length of microcode data. */ + XEN_GUEST_HANDLE(const_void) data;/* Pointer to microcode data */ +}; +typedef struct xenpf_microcode_update2 xenpf_microcode_update2_t; +DEFINE_XEN_GUEST_HANDLE(xenpf_microcode_update2_t); + /* * ` enum neg_errnoval * ` HYPERVISOR_platform_op(const struct xen_platform_op*); @@ -656,6 +669,7 @@ struct xen_platform_op { xenpf_symdata_t symdata; xenpf_dom0_console_t dom0_console; xenpf_ucode_revision_t ucode_revision; + xenpf_microcode_update2_t microcode2; uint8_t pad[128]; } u; }; From patchwork Tue Apr 30 12:47:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fouad Hilly X-Patchwork-Id: 13648938 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 3163EC25B5F for ; Tue, 30 Apr 2024 12:47:41 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.714810.1116164 (Exim 4.92) (envelope-from ) id 1s1mtQ-0005yS-QW; Tue, 30 Apr 2024 12:47:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 714810.1116164; Tue, 30 Apr 2024 12:47:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1mtQ-0005wM-Hc; Tue, 30 Apr 2024 12:47:32 +0000 Received: by outflank-mailman (input) for mailman id 714810; Tue, 30 Apr 2024 12:47:30 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1mtO-0005Ay-N9 for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 12:47:30 +0000 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [2a00:1450:4864:20::130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cdd7ce2c-06ef-11ef-b4bb-af5377834399; Tue, 30 Apr 2024 14:47:29 +0200 (CEST) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-518a56cdbcfso8997161e87.2 for ; Tue, 30 Apr 2024 05:47:29 -0700 (PDT) Received: from fhilly.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id e14-20020a170906504e00b00a558014ab2csm14165324ejk.145.2024.04.30.05.47.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 05:47:27 -0700 (PDT) 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" X-Inumbo-ID: cdd7ce2c-06ef-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1714481248; x=1715086048; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jMReDGOEMqkK5y2P+7Ej6yo+s3bsc3gfBuc2Q1pLAao=; b=glHZUERr4k4RGeJoGKRdMLcuJBVoOQiDaLvwf27snXrzz3LRdtadckUA8M6Q38rRIU mbo36gX0r+jXUi5edDTwEV1PYik4z9QfYPNxdvL++l3jqLm33aH6df6Q1z6H2mt/+yID 4tasSTcITdZJv0pSfyu81qc7KGtn4qMk78yK4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714481248; x=1715086048; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jMReDGOEMqkK5y2P+7Ej6yo+s3bsc3gfBuc2Q1pLAao=; b=NzrC+pPV+DW2z/eCmKAJIqZYvIG++DzTCLZObH8ABvsCSKlKuehDW1lNWrqGGrt9cZ xumfVkUx+8xDrYES3HqTj7gVo327icjuKXVI6L2D3YCe8ZiE6NWvSsD9VNeDcTAQ6QDW yRrq6Zd1pTI0VyoUbGRDa62CqtjESpQtqX/KcdPQp5ncDr/3KWRkIQ98YLEg+fWHMIFw No9Pbmt7LwNKasuvBrPMV7ol8u/mWsKP7nYYZ0982f6OQJ4tkaXlQq+r3Io2j+p8t0Rb XeS2Nrvuza4rUM/kmM09RpdmvkpYIGYuB9BssITGsNdHWhotA1/CSLwEPeQ17ZEQG+SA AgUQ== X-Gm-Message-State: AOJu0YwPlmEmze6fut/fb0XcyS/tE5iLE+tEX1irrmZwnFpDS7UZ5ucy eLwWUMV2TegVZREfBFozzOXy0YblBj5SuWJ9YXO10XyifWf+8X7pdkvvaMPyfE9ZcV9Faq8YGVO G X-Google-Smtp-Source: AGHT+IHUwWP4GYjp6G7GfRPpu9qFMwfVdEn0Y2viDmq5lbzPCwk6pgFIaP4qGODGMHtj+4BgPfs15w== X-Received: by 2002:a05:6512:33c1:b0:51d:aeae:27f6 with SMTP id d1-20020a05651233c100b0051daeae27f6mr6610139lfg.16.1714481248344; Tue, 30 Apr 2024 05:47:28 -0700 (PDT) From: Fouad Hilly To: Xen-devel Cc: Fouad Hilly , Anthony PERARD Subject: [PATCH v3 3/5] x86: Add usage() to print out usage message Date: Tue, 30 Apr 2024 13:47:07 +0100 Message-ID: <20240430124709.865183-4-fouad.hilly@cloud.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240430124709.865183-1-fouad.hilly@cloud.com> References: <20240430124709.865183-1-fouad.hilly@cloud.com> MIME-Version: 1.0 Refactor xen-ucode tool by adding usage() to handle usage\help messages. As we add more command options this will keep help\usage messages in a common block. Only generic error message is printed to stderr. usage and show_curr_cpu are printed to stdout. Signed-off-by: Fouad Hilly --- [v3] 1- Reverted usage message. 2- Utilized usage(). [v2] 1- Improved message description. 2- Fixed formatting and indentation. 3- Error message to print to stderr. tools/misc/xen-ucode.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/misc/xen-ucode.c b/tools/misc/xen-ucode.c index c6ae6498d659..005bf85b6551 100644 --- a/tools/misc/xen-ucode.c +++ b/tools/misc/xen-ucode.c @@ -17,6 +17,13 @@ static xc_interface *xch; static const char intel_id[] = "GenuineIntel"; static const char amd_id[] = "AuthenticAMD"; +static void usage(const char *name) +{ + printf("%s: Xen microcode updating tool\n" + "Usage: %s [ | show-cpu-info]\n", + name, name); +} + static void show_curr_cpu(FILE *f) { int ret; @@ -89,9 +96,8 @@ int main(int argc, char *argv[]) if ( argc < 2 ) { fprintf(stderr, - "xen-ucode: Xen microcode updating tool\n" - "Usage: %s [ | show-cpu-info]\n", argv[0]); - show_curr_cpu(stderr); + "%s: unable to process command line arguments\n", argv[0]); + usage(argv[0]); exit(2); } From patchwork Tue Apr 30 12:47:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fouad Hilly X-Patchwork-Id: 13648935 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 4F383C19F53 for ; Tue, 30 Apr 2024 12:47:39 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.714809.1116144 (Exim 4.92) (envelope-from ) id 1s1mtP-0005R0-Gk; Tue, 30 Apr 2024 12:47:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 714809.1116144; Tue, 30 Apr 2024 12:47:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1mtP-0005PA-93; Tue, 30 Apr 2024 12:47:31 +0000 Received: by outflank-mailman (input) for mailman id 714809; Tue, 30 Apr 2024 12:47:30 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1mtO-0005B4-8h for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 12:47:30 +0000 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [2a00:1450:4864:20::633]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cdfffa86-06ef-11ef-909b-e314d9c70b13; Tue, 30 Apr 2024 14:47:29 +0200 (CEST) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a55bf737cecso668767266b.0 for ; Tue, 30 Apr 2024 05:47:29 -0700 (PDT) Received: from fhilly.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id e14-20020a170906504e00b00a558014ab2csm14165324ejk.145.2024.04.30.05.47.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 05:47:28 -0700 (PDT) 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" X-Inumbo-ID: cdfffa86-06ef-11ef-909b-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1714481249; x=1715086049; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xetGCzyng7oSVdEu+g4DSoDeJEZCA8694EpUidgaMa8=; b=gdpPgm6+e3ajxiUMY3jXIiXPq8OTWW3wmlCviUCMp2XYArpzW6kJ6qUutIxeLy9SHA HZSmMXvUodJ7t1fMHWXwFCsugYGkVFigyb8T4RINqeaJi9OfTLchH9MhlRr6HAdBnqi8 JYy0MaCvdZud0Jnjv4BVkXpf98+/CdAIUau9w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714481249; x=1715086049; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xetGCzyng7oSVdEu+g4DSoDeJEZCA8694EpUidgaMa8=; b=bIFdImaSu8mRR8GvGHqoZr0BW+iBSi99UXMQdVbNg94K8Yo8bNS1gnz/Pm9+ZkG35l Ax0eJfaARBvktCQCy6Iuzbi2wSf/wBAlTq5BhRFhDTn4071HilNa11mf3AQUwMQlYH+J Z1kvlohzYh/POrTRLLBxoJ7bCTWDwIHDUbvbdh8UhKtF08JQIqfIwA9J5Xjap839iY3W 4yOC3GSjFvQvQSexY/WyWTRz4JEXq6iaa/nhLyjFiyKh7CerBWXPeK4rrYtPfzugbjYy L6f9jFcQ18Rzb+B23P3K9GFDgyieErcqzXVlJkxwnSzdEzlZJybiHBSKTtEPhVCI/Mua i/Gw== X-Gm-Message-State: AOJu0YzVV09/he7n0Ivrmvxt+JkrYezkWazgWRRSEEGdiYSp7XRONqUn J75wvHzE8j+xl74yBJQs5jKfd+pWmNKoMBqdmyRw2kYPa0XCO13zBMBZyQ3kCzD015hkppleIdj j X-Google-Smtp-Source: AGHT+IEgypZzUkmtEkoARhyE6vL2FcIm90aW/XVJnTNlJjgUCAOSBS4YAT210l6216z9vbqk/+S3bw== X-Received: by 2002:a17:906:698e:b0:a52:58a7:11d1 with SMTP id i14-20020a170906698e00b00a5258a711d1mr8632442ejr.38.1714481248942; Tue, 30 Apr 2024 05:47:28 -0700 (PDT) From: Fouad Hilly To: Xen-devel Cc: Fouad Hilly , Anthony PERARD Subject: [PATCH v3 4/5] x86: Use getopt to handle command line args Date: Tue, 30 Apr 2024 13:47:08 +0100 Message-ID: <20240430124709.865183-5-fouad.hilly@cloud.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240430124709.865183-1-fouad.hilly@cloud.com> References: <20240430124709.865183-1-fouad.hilly@cloud.com> MIME-Version: 1.0 Use getopt_long() to handle command line arguments. Introduce ext_err for common exit with errors. Signed-off-by: Fouad Hilly --- [v3] 1- Exit with error prints erros only to stderr. 2- Remove argc checks. 3- Utilize optind. [v2] 1- Removed unnecessary NULL initialization. 2- Used static at the beginning of type struct declaration. 3- Corrected switch\case indentations. 4- Removed redundant checks. 5- Corrected label indentation. tools/misc/xen-ucode.c | 45 +++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/tools/misc/xen-ucode.c b/tools/misc/xen-ucode.c index 005bf85b6551..d95f967f021b 100644 --- a/tools/misc/xen-ucode.c +++ b/tools/misc/xen-ucode.c @@ -11,6 +11,7 @@ #include #include #include +#include static xc_interface *xch; @@ -20,7 +21,10 @@ static const char amd_id[] = "AuthenticAMD"; static void usage(const char *name) { printf("%s: Xen microcode updating tool\n" - "Usage: %s [ | show-cpu-info]\n", + "Usage: %s [ | Options]\n" + "options:\n" + " -h, --help display this help and exit\n" + " -s, --show-cpu-info show CPU information and exit\n", name, name); } @@ -84,6 +88,13 @@ int main(int argc, char *argv[]) char *filename, *buf; size_t len; struct stat st; + int opt; + + static const struct option options[] = { + {"help", no_argument, NULL, 'h'}, + {"show-cpu-info", no_argument, NULL, 's'}, + {NULL, no_argument, NULL, 0} + }; xch = xc_interface_open(NULL, NULL, 0); if ( xch == NULL ) @@ -93,21 +104,25 @@ int main(int argc, char *argv[]) exit(1); } - if ( argc < 2 ) + while ( (opt = getopt_long(argc, argv, "hs", options, NULL)) != -1 ) { - fprintf(stderr, - "%s: unable to process command line arguments\n", argv[0]); - usage(argv[0]); - exit(2); + switch (opt) + { + case 'h': + usage(argv[0]); + exit(EXIT_SUCCESS); + case 's': + show_curr_cpu(stdout); + exit(EXIT_SUCCESS); + default: + goto ext_err; + } } - if ( !strcmp(argv[1], "show-cpu-info") ) - { - show_curr_cpu(stdout); - return 0; - } + if ( optind == argc ) + goto ext_err; - filename = argv[1]; + filename = argv[optind]; fd = open(filename, O_RDONLY); if ( fd < 0 ) { @@ -149,4 +164,10 @@ int main(int argc, char *argv[]) close(fd); return 0; + + ext_err: + fprintf(stderr, + "%s: unable to process command line arguments\n", argv[0]); + usage(argv[0]); + exit(EXIT_FAILURE); } From patchwork Tue Apr 30 12:47:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fouad Hilly X-Patchwork-Id: 13648939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 1D8CAC4345F for ; Tue, 30 Apr 2024 12:47:41 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.714811.1116176 (Exim 4.92) (envelope-from ) id 1s1mtS-0006NL-2X; Tue, 30 Apr 2024 12:47:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 714811.1116176; Tue, 30 Apr 2024 12:47:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1mtR-0006Mv-S6; Tue, 30 Apr 2024 12:47:33 +0000 Received: by outflank-mailman (input) for mailman id 714811; Tue, 30 Apr 2024 12:47:31 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1mtP-0005Ay-PC for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 12:47:31 +0000 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [2a00:1450:4864:20::62e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ce6a27ca-06ef-11ef-b4bb-af5377834399; Tue, 30 Apr 2024 14:47:30 +0200 (CEST) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a58fbbcd77aso288956466b.2 for ; Tue, 30 Apr 2024 05:47:30 -0700 (PDT) Received: from fhilly.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id e14-20020a170906504e00b00a558014ab2csm14165324ejk.145.2024.04.30.05.47.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 05:47:29 -0700 (PDT) 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" X-Inumbo-ID: ce6a27ca-06ef-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1714481249; x=1715086049; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wMnmkNjA1BInUsP0IVDeKNq5vnJN5ZIs/BtVpY7OG3w=; b=jFK1RWmnT/FqkJSImpJEaqk9iZdHGtwfxqVT0nJhizHmJVhTkT9+/My/84Vud0Bv3y fhq4h59UGjWuE48/l74N7q/1R/0nhZx3BRRIqq8pYw4aJEFqzIz2KEjIWLFmogAPrFmg tRxgtnT60fL+CjBd/61tawyRtPTOJg5G+my7E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714481249; x=1715086049; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wMnmkNjA1BInUsP0IVDeKNq5vnJN5ZIs/BtVpY7OG3w=; b=SJe8PSxvRnnEuhZ2qnW4LPnRBgapMrGA78VrL3dAT3KDlKBSVMtDJJapjr/9K2wJIe ua2ASjtCdSM2INp+gfjfu80LrVv5ZV9pc71LS0lvaUYy92Nw1ulo0mp4vR5rNCMoty/N xE+ciiLilGjcVorA9jDVKzmZcGVmOkyxa1qJXhEICO+QVaHYFoJoGS11TbYBljdk16CN RQc071An9n4f0aO0polpkKxF+tAM+LSjBh9vXX9DYU8rrUqyxrZ4bS2YWQxLLalsgjGV /QzekEYvyTH9bJlo9IT2b2TNKZmljLRQhT9KaL+nj2VL6u+YAQ1hmjYW6As0IcZ4vdBp w8eA== X-Gm-Message-State: AOJu0YyftWj2FAMPTZmIXhneo/gUT8GWFqRoUcEKHmuL+fblCgQREWDr ZcEs/gO8XQM5/lGPUC48MUu2fWrgqwAU1gCAr3Y6LQ2Lq/UZbM7pKJpeIQN1bVKncc8+dxADw/f K X-Google-Smtp-Source: AGHT+IHuGgBj+b4p0staZvEOfZNUXXfaKd46jbkmS+YqCxuThRZx9jRiLWsVPANiQ/3NFRIdUbauyQ== X-Received: by 2002:a17:906:80da:b0:a55:b021:c0b1 with SMTP id a26-20020a17090680da00b00a55b021c0b1mr6742377ejx.9.1714481249645; Tue, 30 Apr 2024 05:47:29 -0700 (PDT) From: Fouad Hilly To: Xen-devel Cc: Fouad Hilly , Anthony PERARD , Juergen Gross , Andrew Cooper Subject: [PATCH v3 5/5] Add --force option to xen-ucode to override microcode version check Date: Tue, 30 Apr 2024 13:47:09 +0100 Message-ID: <20240430124709.865183-6-fouad.hilly@cloud.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240430124709.865183-1-fouad.hilly@cloud.com> References: <20240430124709.865183-1-fouad.hilly@cloud.com> MIME-Version: 1.0 Introduce --force option to xen-ucode to force skipping microcode version check, which allows the user to update x86 microcode even if both versions are the same. xc_microcode_update() refactored to accept flags and utilize xenpf_microcode_update2 Signed-off-by: Fouad Hilly Suggested-by: Andrew Cooper --- [v3] 1- Message description updated. 2- xc_microcode_update() uses xenpf_microcode_update2 to pass flags. [v2] 1- Changed data type from uint32_t to unsigned int. 2- Corrected line length. 3- Removed XENPF_UCODE_FLAG_FORCE_NOT_SET. 4- Corrected indentations. 5- Changed command line options to have the file name as first argument when applicable. 6- --force option doesn't require an argument anymore. 7- Used optint to access filename in argv. tools/include/xenctrl.h | 3 ++- tools/libs/ctrl/xc_misc.c | 12 +++++++----- tools/misc/xen-ucode.c | 16 ++++++++++++---- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 499685594427..7fb409bc6dc4 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1171,7 +1171,8 @@ typedef uint32_t xc_node_to_node_dist_t; int xc_physinfo(xc_interface *xch, xc_physinfo_t *info); int xc_cputopoinfo(xc_interface *xch, unsigned *max_cpus, xc_cputopo_t *cputopo); -int xc_microcode_update(xc_interface *xch, const void *buf, size_t len); +int xc_microcode_update(xc_interface *xch, const void *buf, + size_t len, unsigned int flags); int xc_get_cpu_version(xc_interface *xch, struct xenpf_pcpu_version *cpu_ver); int xc_get_ucode_revision(xc_interface *xch, struct xenpf_ucode_revision *ucode_rev); diff --git a/tools/libs/ctrl/xc_misc.c b/tools/libs/ctrl/xc_misc.c index 50282fd60dcc..6a60216bda03 100644 --- a/tools/libs/ctrl/xc_misc.c +++ b/tools/libs/ctrl/xc_misc.c @@ -203,11 +203,12 @@ int xc_physinfo(xc_interface *xch, return 0; } -int xc_microcode_update(xc_interface *xch, const void *buf, size_t len) +int xc_microcode_update(xc_interface *xch, const void *buf, + size_t len, unsigned int flags) { int ret; struct xen_platform_op platform_op = {}; - DECLARE_HYPERCALL_BUFFER(struct xenpf_microcode_update, uc); + DECLARE_HYPERCALL_BUFFER(struct xenpf_microcode_update2, uc); uc = xc_hypercall_buffer_alloc(xch, uc, len); if ( uc == NULL ) @@ -215,9 +216,10 @@ int xc_microcode_update(xc_interface *xch, const void *buf, size_t len) memcpy(uc, buf, len); - platform_op.cmd = XENPF_microcode_update; - platform_op.u.microcode.length = len; - set_xen_guest_handle(platform_op.u.microcode.data, uc); + platform_op.cmd = XENPF_microcode_update2; + platform_op.u.microcode2.length = len; + platform_op.u.microcode2.flags = flags; + set_xen_guest_handle(platform_op.u.microcode2.data, uc); ret = do_platform_op(xch, &platform_op); diff --git a/tools/misc/xen-ucode.c b/tools/misc/xen-ucode.c index d95f967f021b..b3c9a2bfe5c8 100644 --- a/tools/misc/xen-ucode.c +++ b/tools/misc/xen-ucode.c @@ -13,6 +13,8 @@ #include #include +#include + static xc_interface *xch; static const char intel_id[] = "GenuineIntel"; @@ -21,10 +23,11 @@ static const char amd_id[] = "AuthenticAMD"; static void usage(const char *name) { printf("%s: Xen microcode updating tool\n" - "Usage: %s [ | Options]\n" + "Usage: %s [microcode file] [options]\n" "options:\n" " -h, --help display this help and exit\n" - " -s, --show-cpu-info show CPU information and exit\n", + " -s, --show-cpu-info show CPU information and exit\n" + " -f, --force force to skip micorocde version check\n", name, name); } @@ -89,10 +92,12 @@ int main(int argc, char *argv[]) size_t len; struct stat st; int opt; + uint32_t ucode_flag = 0; static const struct option options[] = { {"help", no_argument, NULL, 'h'}, {"show-cpu-info", no_argument, NULL, 's'}, + {"force", no_argument, NULL, 'f'}, {NULL, no_argument, NULL, 0} }; @@ -104,7 +109,7 @@ int main(int argc, char *argv[]) exit(1); } - while ( (opt = getopt_long(argc, argv, "hs", options, NULL)) != -1 ) + while ( (opt = getopt_long(argc, argv, "hsf", options, NULL)) != -1 ) { switch (opt) { @@ -114,6 +119,9 @@ int main(int argc, char *argv[]) case 's': show_curr_cpu(stdout); exit(EXIT_SUCCESS); + case 'f': + ucode_flag = XENPF_UCODE_FLAG_FORCE_SET; + break; default: goto ext_err; } @@ -146,7 +154,7 @@ int main(int argc, char *argv[]) exit(1); } - ret = xc_microcode_update(xch, buf, len); + ret = xc_microcode_update(xch, buf, len, ucode_flag); if ( ret ) { fprintf(stderr, "Failed to update microcode. (err: %s)\n",