From patchwork Tue May 28 15:29:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fouad Hilly X-Patchwork-Id: 13676992 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 AA068C25B78 for ; Tue, 28 May 2024 15:30:32 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.731195.1136566 (Exim 4.92) (envelope-from ) id 1sBymC-0001Fo-8i; Tue, 28 May 2024 15:30:12 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 731195.1136566; Tue, 28 May 2024 15:30:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sBymC-0001FH-1d; Tue, 28 May 2024 15:30:12 +0000 Received: by outflank-mailman (input) for mailman id 731195; Tue, 28 May 2024 15:30:11 +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 1sBymB-00018F-6L for xen-devel@lists.xenproject.org; Tue, 28 May 2024 15:30:11 +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 2accabe2-1d07-11ef-90a1-e314d9c70b13; Tue, 28 May 2024 17:30:09 +0200 (CEST) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a6341cf2c99so98851466b.0 for ; Tue, 28 May 2024 08:30:09 -0700 (PDT) Received: from fhilly.citrite.net ([160.101.139.1]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a626c937444sm621673366b.61.2024.05.28.08.30.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 08:30:08 -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: 2accabe2-1d07-11ef-90a1-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1716910208; x=1717515008; 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=bJX73ZmntNKRAs0BEZRhybEqHcJwu5VuVHE4B8+pY60=; b=jsH+tYRG95sELT8cWmsfGHEKCkPHYDNU3TW66Xhd9e98bau26M3lUVmgGOsC5GKd5m iLneUP35aqUVOdJkUOawonZiMCtloe9/+7D1B/kwKdD+flGQ50Ft56fS61TkqKFajSOA 7vSqM+qFtDmfgQMqZ3KwmBHMP5KWaoDy4cNQ4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716910208; x=1717515008; 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=bJX73ZmntNKRAs0BEZRhybEqHcJwu5VuVHE4B8+pY60=; b=Eh4PuwG0b4G7cGw3bmb766wb1N6DFYSygO5MnYEVKbB/BXNIrWGIPYo2PnK6PPTMV0 ZfILHwDUmZR8MGxlAqvYPIPoJUBIawN2xwlM56ffgGUV7tFr1SkpD38KXAl8FVrvpEXk 5sdY3XPhuQnXU+S0IYZyJvDSjg7aFBl47QQJNmJLOgJ3uc82MCwc2BTyd+DmZhUvyaWB T5ZV1wb51zOfngWOSVX5Dyw48yQC+MQ78KzNkuhCWd7hLmaNWj0OGO6tDs9+D9FptV6M OOLcKBzlOjpHlRx6frUUoW5KDN2wAzyOYYt4gN9cMVaHBczBI8Js1IzOJVmvlUNOKDYa QkgA== X-Gm-Message-State: AOJu0Yx87t1DNWHPTAp4KSCxodswAWOx/5HE0Q4V+SsmTbJ4m55P9sSx 9yl7pH/UcdORY25+lupDdXO5nIVd2RGFjNk32ofg9QyP7g9wxE9OrV+CM6w4yWxJc7YoIYSyElX 9U48= X-Google-Smtp-Source: AGHT+IHzLvVpGVHVUdhsRJaFBLhxIExE5P2Hb13QIBulTEa2VIkMdvPfsb8s3kG1g7MR5q0a2ZRzUg== X-Received: by 2002:a17:906:3741:b0:a5a:1f4f:cb4c with SMTP id a640c23a62f3a-a62641b4532mr886848066b.7.1716910208404; Tue, 28 May 2024 08:30:08 -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 v4 1/4] x86/ucode: Introduce PF_microcode_update2 with flags parameter Date: Tue, 28 May 2024 16:29:40 +0100 Message-ID: <20240528152943.3915760-2-fouad.hilly@cloud.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240528152943.3915760-1-fouad.hilly@cloud.com> References: <20240528152943.3915760-1-fouad.hilly@cloud.com> MIME-Version: 1.0 Refactor microcode_update() by adding flags field. struct xenpf_microcode_update2 added with uint32_t flags field. Introduce XENPF_microcode_update2 hypercall with flags field. Signed-off-by: Fouad Hilly Reviewed-by: Andrew Cooper --- [v4] 1- Commit message and description updated. 2- Changing the order of the patches. [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 | 11 ++++++++--- xen/arch/x86/include/asm/microcode.h | 3 ++- xen/arch/x86/platform_hypercall.c | 13 ++++++++++++- xen/include/public/platform.h | 14 ++++++++++++++ 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode/core.c index e90055772acf..8a9e744489b9 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[]; }; @@ -708,13 +711,14 @@ 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 ( len != (uint32_t)len ) - return -E2BIG; + if ( flags & ~XENPF_UCODE_FORCE ) + return -EINVAL; if ( !ucode_ops.apply_microcode ) return -EINVAL; @@ -730,6 +734,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..7e3278109300 100644 --- a/xen/arch/x86/platform_hypercall.c +++ b/xen/arch/x86/platform_hypercall.c @@ -311,7 +311,18 @@ 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..2725b8d1044f 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 */ +#define XENPF_UCODE_FORCE 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 May 28 15:29:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fouad Hilly X-Patchwork-Id: 13676991 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 8B37EC41513 for ; Tue, 28 May 2024 15:30:29 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.731194.1136559 (Exim 4.92) (envelope-from ) id 1sBymC-0001BX-0n; Tue, 28 May 2024 15:30:12 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 731194.1136559; Tue, 28 May 2024 15:30:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sBymB-0001AM-Qy; Tue, 28 May 2024 15:30:11 +0000 Received: by outflank-mailman (input) for mailman id 731194; Tue, 28 May 2024 15:30:10 +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 1sBymA-00018F-P2 for xen-devel@lists.xenproject.org; Tue, 28 May 2024 15:30:10 +0000 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [2a00:1450:4864:20::634]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2af7124b-1d07-11ef-90a1-e314d9c70b13; Tue, 28 May 2024 17:30:09 +0200 (CEST) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a62ef52e837so116111266b.3 for ; Tue, 28 May 2024 08:30:09 -0700 (PDT) Received: from fhilly.citrite.net ([160.101.139.1]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a626c937444sm621673366b.61.2024.05.28.08.30.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 08:30:08 -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: 2af7124b-1d07-11ef-90a1-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1716910209; x=1717515009; 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=eiZixxDd1y7HmvULwDCnAUl2gq5YDTcVfKI5Yqc7A6o=; b=Sh7lNcJHSd6q+jXD65e0hzkl69rRH8HrJdzb2lAtbzI+AM3jMi7xoX0ZuAge387TF3 S1c7tYqb3wCirwJNNuZnd001THXFe0dy40jCgaDen+HnqnJiIvcAW47jyyOb8rkFKuge mjKEdd0JF92934BaXrT7B5jkk9pXM0zBTntZc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716910209; x=1717515009; 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=eiZixxDd1y7HmvULwDCnAUl2gq5YDTcVfKI5Yqc7A6o=; b=G0L3j1cAHsoGMQAakdms81MHhTuT7k8vlvf/grpJzX6dVveUw72r+8Nu+LTPK8Mh+b +1tDCBPII6jfu6RzICf8HiCsTv1TnyDjStwK/uwNop9McHazdA1iSpYHBvSu4oJDzl/c pACPABuu+9BNSPSMgdQoIH78Zq1Dq8Vl8H1jDY8SbxWNoNcGUnLM4J/J0QuquGNDlwCQ 9ZXJOIONcd+PTZadx5xn2m2a87yzc1lzvQF7iv+2cXRa5o+aalfLV/FP4pq56wgVO0mt 5p4yD7RU5URxyxkS4n2Nvh1FTpaVfvCCUluhpUU+VNYaFzOv22e3YmNHV7hsvs/yiyjA V/ng== X-Gm-Message-State: AOJu0YwpQRQI1+FO5LU72mqYOn63gA82/WP3xf7bZUYFXnmpLPzxFqz/ gEpwh2YM2vPxPqziUt8hRtsbTRqOpXnI84L/JBhTPv3KRLyjG6uwyNctsmxt72VKIXgtwkYWSur +zP8= X-Google-Smtp-Source: AGHT+IGrPVCUH8m9ucxJfQ8Bfo55q54C/wA4hv+O7jryDjihHoTJ4VxJksixq/14le3M65dEFfPECg== X-Received: by 2002:a17:906:1945:b0:a59:b807:330a with SMTP id a640c23a62f3a-a62641cf941mr896251366b.32.1716910208980; Tue, 28 May 2024 08:30:08 -0700 (PDT) From: Fouad Hilly To: Xen-devel Cc: Fouad Hilly , Anthony PERARD Subject: [PATCH v4 2/4] x86/ucode: refactor xen-ucode to utilize getopt Date: Tue, 28 May 2024 16:29:41 +0100 Message-ID: <20240528152943.3915760-3-fouad.hilly@cloud.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240528152943.3915760-1-fouad.hilly@cloud.com> References: <20240528152943.3915760-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. xc_microcode_update() refactored to accept flags and utilize xenpf_microcode_update2 Introducing usage() to handle usage\help messages in a common block. show_curr_cpu is printed to stdout only. Signed-off-by: Fouad Hilly --- [v4] 1- Merge three patches into one. 2- usage() to print messages to the correct stream. 3- Update commit message and description. --- tools/misc/xen-ucode.c | 51 ++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/tools/misc/xen-ucode.c b/tools/misc/xen-ucode.c index 390969db3d1c..6f9dd2a7e431 100644 --- a/tools/misc/xen-ucode.c +++ b/tools/misc/xen-ucode.c @@ -11,12 +11,23 @@ #include #include #include +#include static xc_interface *xch; static const char intel_id[] = "GenuineIntel"; static const char amd_id[] = "AuthenticAMD"; +static void usage(FILE *stream, const char *name) +{ + fprintf(stream, "%s: Xen microcode updating tool\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", + name, name); +} + static void show_curr_cpu(FILE *f) { int ret; @@ -77,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 ) @@ -86,22 +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, - "xen-ucode: Xen microcode updating tool\n" - "Usage: %s [ | show-cpu-info]\n", argv[0]); - show_curr_cpu(stderr); - exit(2); + switch (opt) + { + case 'h': + usage(stdout, 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 ) { @@ -146,4 +167,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(stderr, argv[0]); + exit(EXIT_FAILURE); } From patchwork Tue May 28 15:29:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fouad Hilly X-Patchwork-Id: 13676990 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 81F34C25B7C for ; Tue, 28 May 2024 15:30:29 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.731197.1136589 (Exim 4.92) (envelope-from ) id 1sBymD-0001sk-Pm; Tue, 28 May 2024 15:30:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 731197.1136589; Tue, 28 May 2024 15:30:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sBymD-0001s8-Jp; Tue, 28 May 2024 15:30:13 +0000 Received: by outflank-mailman (input) for mailman id 731197; Tue, 28 May 2024 15:30:12 +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 1sBymC-00018E-AS for xen-devel@lists.xenproject.org; Tue, 28 May 2024 15:30:12 +0000 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [2a00:1450:4864:20::432]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2b9df50d-1d07-11ef-b4bb-af5377834399; Tue, 28 May 2024 17:30:10 +0200 (CEST) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-354faf5f1b4so779629f8f.1 for ; Tue, 28 May 2024 08:30:10 -0700 (PDT) Received: from fhilly.citrite.net ([160.101.139.1]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a626c937444sm621673366b.61.2024.05.28.08.30.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 08:30:09 -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: 2b9df50d-1d07-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1716910210; x=1717515010; 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=29kKGaSNhLed8Jk9dwMB1HDWbyK77p3VZnpuSymtJak=; b=ishgnpllRC/svCCzlkPPL7nnUgrCjrP1JeLR6CvohTRc/AnaYHsPUJ1/JnXjxJMvtb 48stk6/tUkjyr8RwLuO3mXGIbNhkcRXf+IhENdzwrukS/Og/m6C7Ev9UmUpqaGIibYiI dV5aOYRRt9cb4OKd3rxdHRBwLVKDWTOrZ7BmY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716910210; x=1717515010; 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=29kKGaSNhLed8Jk9dwMB1HDWbyK77p3VZnpuSymtJak=; b=PLzoKtte6ONCmDChBq39npOQAra0eIcUuzyiHKer9A3l4MlVdZHUB/ZlAF1z1osgZF 5oOXO34DBkc5edfxHanu+k7ZNR+2ZldOUN71ASj4l9NuEDB2Rc9zis9nfw+EWzWiVq+N AMcHA0yRVN9Mgstp9zxsZATwco90kIFXz8MyirNo1MwxZWLro0EvWSzoRujLAixCT55o KhEnW+AC3ntiNzLUyotmdNJ/HVpQ69uVVVzPVSJMcksgMIdGf4OpEQRSelexml+vKNGV 2hxwnStGu6XJo4EkiMrOzFB6Tk4zYodcaUvO6YnfKaZ6mEETRzWoBEuR4TwJcpCdyzSP xkNg== X-Gm-Message-State: AOJu0YybK6Jr4tSM22vIzh7pgksLsY9daxQUluflw7X0OOFmEBnDadXZ xBuB1VHvZyeYDs8qWsVr2CDA7Yyw6A73rUPNi3turjzBDQPF45n5vy8Qzy75poBYxW17wk8iG8C oY48= X-Google-Smtp-Source: AGHT+IHJ5pIptnLo5qJAv1DVP0wUcqG2/5riYCtRVCTsvS+oNS+wekQ6nvMZBPq3NglWopzcliQulQ== X-Received: by 2002:adf:e681:0:b0:34c:b80a:233c with SMTP id ffacd0b85a97d-3552f4fd1b5mr10569229f8f.15.1716910209647; Tue, 28 May 2024 08:30:09 -0700 (PDT) From: Fouad Hilly To: Xen-devel Cc: Fouad Hilly , Anthony PERARD , Juergen Gross Subject: [PATCH v4 3/4] x86/ucode: Introduce --force option to xen-ucode to force skipping microcode version check Date: Tue, 28 May 2024 16:29:42 +0100 Message-ID: <20240528152943.3915760-4-fouad.hilly@cloud.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240528152943.3915760-1-fouad.hilly@cloud.com> References: <20240528152943.3915760-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 or downgrade. xc_microcode_update() refactored to accept flags and utilize xenpf_microcode_update2. Signed-off-by: Fouad Hilly Reviewed-by: Andrew Cooper --- [4] 1- Add --force to xen-ucode options. 2- Update xc_microcode_update() to accept and handle flags. --- tools/include/xenctrl.h | 3 ++- tools/libs/ctrl/xc_misc.c | 12 +++++++----- tools/misc/xen-ucode.c | 14 +++++++++++--- 3 files changed, 20 insertions(+), 9 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 6f9dd2a7e431..b878edf2399a 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"; @@ -24,7 +26,8 @@ static void usage(FILE *stream, const char *name) "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 microcode 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_flags = 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_flags = XENPF_UCODE_FORCE; + break; default: goto ext_err; } @@ -147,7 +155,7 @@ int main(int argc, char *argv[]) } errno = 0; - ret = xc_microcode_update(xch, buf, len); + ret = xc_microcode_update(xch, buf, len, ucode_flags); if ( ret == -1 && errno == EEXIST ) printf("Microcode already up to date\n"); else if ( ret ) From patchwork Tue May 28 15:29:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fouad Hilly X-Patchwork-Id: 13676989 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 F02D0C25B7E for ; Tue, 28 May 2024 15:30:28 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.731196.1136584 (Exim 4.92) (envelope-from ) id 1sBymD-0001pR-G0; Tue, 28 May 2024 15:30:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 731196.1136584; Tue, 28 May 2024 15:30:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sBymD-0001pK-C2; Tue, 28 May 2024 15:30:13 +0000 Received: by outflank-mailman (input) for mailman id 731196; Tue, 28 May 2024 15:30:12 +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 1sBymC-00018F-6c for xen-devel@lists.xenproject.org; Tue, 28 May 2024 15:30:12 +0000 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [2a00:1450:4864:20::635]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2c014c96-1d07-11ef-90a1-e314d9c70b13; Tue, 28 May 2024 17:30:11 +0200 (CEST) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-a63359aaaa6so126666066b.2 for ; Tue, 28 May 2024 08:30:11 -0700 (PDT) Received: from fhilly.citrite.net ([160.101.139.1]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a626c937444sm621673366b.61.2024.05.28.08.30.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 08:30:10 -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: 2c014c96-1d07-11ef-90a1-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1716910210; x=1717515010; 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=z7mcoezWV0j0H2zzn7JIYS8Z2/p6a2i2l5f1Q/llZE0=; b=CWQ9MkMxFzYjqVq8JEzhTJ2ctT11Uq0m1Aib1E4zLZMy6d2llX6MxmHmRyOXsxM4yF lY2w+uV/D2G8l7SkEej/y8Dl6HdQqozFCI2M/I9dy+CPPZ6i9lVc/RcUyZ9f73ues3rJ QJDnisQS1Cik7CiHF8f3X3WC43NUjndyejmsc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716910210; x=1717515010; 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=z7mcoezWV0j0H2zzn7JIYS8Z2/p6a2i2l5f1Q/llZE0=; b=N0raUnfeVDjtZtrpUEpJQ6EZv54SGUiVi+jUQqgzCEtAPdhV4ikeHea+K/4uYIWish 7mFKkfqUzpDxcyk1/TtcMEtarX3hB8TtF2mfY187U0ULZ2Hkpg0aJ7hZA5Q2429YzMiQ KZdKNIY5IiYxPwGBKFOFA7gu08r2iiikPPaAdu+R7P/diJZCF7eUWe99AwmJ/QdhxA6H Xlo37LyLyIULJThoC93cbgThHR1hhPNSGfvZciRwtgqx3KHlGYqhKXa2yZL38VYAfHKl Y6mlfQ6+Z15qJ+TY2ANi/ZYJjXxVkd8+i46ua5jC+edAc21tdIqdB77BTa22IXi19URe yN9Q== X-Gm-Message-State: AOJu0Yzn6/U2LcSvXk4aAir6uS5rgocu5QNViWEQJowp5WEPbwUfsfLk JMlCD31X5/ksYk2/aIH12u4Bf0aTlwimVWN9Z9Ml38JYqcfOjB10pXUKL+r8N81v1qvQIOrAAgI S2U0= X-Google-Smtp-Source: AGHT+IG4ytefBo9qwZrlmg2vHgWyH70OIDv7RtLE8pO6Uf1I0FZqM0xsPwXkUBHRuVwjEpLdxigKzQ== X-Received: by 2002:a17:906:a287:b0:a59:cb29:3fb3 with SMTP id a640c23a62f3a-a6265148babmr864229366b.53.1716910210477; Tue, 28 May 2024 08:30:10 -0700 (PDT) From: Fouad Hilly To: Xen-devel Cc: Fouad Hilly , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v4 4/4] x86/ucode: Utilize ucode_force and remove opt_ucode_allow_same Date: Tue, 28 May 2024 16:29:43 +0100 Message-ID: <20240528152943.3915760-5-fouad.hilly@cloud.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240528152943.3915760-1-fouad.hilly@cloud.com> References: <20240528152943.3915760-1-fouad.hilly@cloud.com> MIME-Version: 1.0 Pass ucode_force to common micorocde checks and utilize it to allow for microcode downgrade or reapply the same version of the microcode. Update low level Intel and AMD to check for valid signature only. Any version checks is done at core.c. While adding ucode_force, opt_ucode_allow_same was removed. Remove opt_ucode_allow_same from documentation. Signed-off-by: Fouad Hilly --- [4] 1- As opt_ucode_allow_same is not required anymore, it has been removed while introducing ucode_force. 2- Apply the changes for both AMD and Intel. 3- Remove the mention of opt_ucode_allow_same from documentation. --- docs/misc/xen-command-line.pandoc | 7 +------ xen/arch/x86/cpu/microcode/amd.c | 7 ------- xen/arch/x86/cpu/microcode/core.c | 9 +++------ xen/arch/x86/cpu/microcode/intel.c | 4 ---- xen/arch/x86/cpu/microcode/private.h | 2 -- 5 files changed, 4 insertions(+), 25 deletions(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line.pandoc index 1dea7431fab6..a42ce1039fed 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -2648,7 +2648,7 @@ performance. Alternatively, selecting `tsx=1` will re-enable TSX at the users own risk. ### ucode -> `= List of [ | scan=, nmi=, allow-same= ]` +> `= List of [ | scan=, nmi= ]` Applicability: x86 Default: `nmi` @@ -2680,11 +2680,6 @@ 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 easy 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 f76a563c8b84..4bcc79f1ab2d 100644 --- a/xen/arch/x86/cpu/microcode/amd.c +++ b/xen/arch/x86/cpu/microcode/amd.c @@ -225,13 +225,6 @@ static int cf_check apply_microcode(const struct microcode_patch *patch) if ( result == MIS_UCODE ) return -EINVAL; - /* - * Allow application of the same revision to pick up SMT-specific changes - * even if the revision of the other SMT thread is already up-to-date. - */ - if ( result == OLD_UCODE ) - return -EEXIST; - if ( check_final_patch_levels(sig) ) { printk(XENLOG_ERR diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode/core.c index 8a9e744489b9..fc8ad8cfdd76 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -100,8 +100,6 @@ static bool __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; @@ -128,8 +126,6 @@ static int __init cf_check 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 ) @@ -583,6 +579,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 = buffer->flags == XENPF_UCODE_FORCE; /* cpu_online_map must not change during update */ if ( !get_cpu_maps() ) @@ -636,12 +633,12 @@ static long cf_check microcode_update_helper(void *data) microcode_cache); if ( result != NEW_UCODE && - !(opt_ucode_allow_same && result == SAME_UCODE) ) + (!ucode_force || (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)" : ""); + ucode_force? " (or a valid)" : ""); microcode_free_patch(patch); ret = -EEXIST; diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcode/intel.c index f505aa1b7888..5e1b528ffe05 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -297,10 +297,6 @@ static int cf_check apply_microcode(const struct microcode_patch *patch) if ( result == MIS_UCODE ) return -EINVAL; - if ( result == OLD_UCODE || - (result == SAME_UCODE && !opt_ucode_allow_same) ) - return -EEXIST; - wbinvd(); wrmsrl(MSR_IA32_UCODE_WRITE, (unsigned long)patch->data); diff --git a/xen/arch/x86/cpu/microcode/private.h b/xen/arch/x86/cpu/microcode/private.h index da556fe5060a..aea51678a662 100644 --- a/xen/arch/x86/cpu/microcode/private.h +++ b/xen/arch/x86/cpu/microcode/private.h @@ -3,8 +3,6 @@ #include -extern bool opt_ucode_allow_same; - enum microcode_match_result { OLD_UCODE, /* signature matched, but revision id is older */ SAME_UCODE, /* signature matched, but revision id is the same */