From nobody Mon Sep 16 18:51:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1721896090; cv=none; d=zohomail.com; s=zohoarc; b=ZF2PYB5gv6xxkvbyYeki3gKl3ykeF2s06f7EGolAfoGN0Yy0vtZqU9MPTKUD03QRJq6hpqjewkcXeEsox61vIupRd4URJQJcUj5BKfLqGvGLT42lTB8/jOwr8pe6f2yrM1ythQiKTPLXtrKfQaKce7sErCDq3IoeRKl7tOIh+T0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1721896090; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DlS1KhWcLxjYccvIIzbFt8aClNyV66/s1GUBwIQYHsI=; b=YyXSwPWcTW5JZveN1phmZ9IsDb0zwl3e9cYlRXYLsRELGu+ocIiiHuWlNOiRatD1DZolUAOuqd9A5geX7mpiJdlAw6zgEtKRFdGyZx0QhSDHZQX+hFq0bHz8ipce9VIoBX2AoGYKhU5UUScKD8eueuf4mB1PRIdVpK2x3+Bv3CM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1721896090805866.4222037096401; Thu, 25 Jul 2024 01:28:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.764816.1175370 (Exim 4.92) (envelope-from ) id 1sWtpJ-0006j4-Tt; Thu, 25 Jul 2024 08:27:53 +0000 Received: by outflank-mailman (output) from mailman id 764816.1175370; Thu, 25 Jul 2024 08:27:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sWtpJ-0006i0-NE; Thu, 25 Jul 2024 08:27:53 +0000 Received: by outflank-mailman (input) for mailman id 764816; Thu, 25 Jul 2024 08:27:53 +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 1sWtpJ-0006fy-19 for xen-devel@lists.xenproject.org; Thu, 25 Jul 2024 08:27:53 +0000 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [2a00:1450:4864:20::52c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c888f67d-4a5f-11ef-bbff-fd08da9f4363; Thu, 25 Jul 2024 10:27:52 +0200 (CEST) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5a3458bf858so775042a12.1 for ; Thu, 25 Jul 2024 01:27:51 -0700 (PDT) Received: from fhilly.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5ac63590e7esm558590a12.36.2024.07.25.01.27.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 01:27:50 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: c888f67d-4a5f-11ef-bbff-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1721896071; x=1722500871; 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=DlS1KhWcLxjYccvIIzbFt8aClNyV66/s1GUBwIQYHsI=; b=c7LMZXVi2We6MGyqpij+TBdQJk7Ssfl1yF05x8UM2JnRQbB10vWTA5y9DfvNhAYhw3 4A7wjqzb1p10mGnjxIRQUqKQ1w7G129OjlM31Mz+97okFehlCzvbiLhff00o80rUCJzy BWQ4XQbt1lDQs7HaIgo9qW4cA+ipTq+Eayl+E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721896071; x=1722500871; 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=DlS1KhWcLxjYccvIIzbFt8aClNyV66/s1GUBwIQYHsI=; b=U3+maFW335quJAVRpwXKdLop4fXmTj4v0KnoABD6WiYdd/V06UNoTpyMkw3JGHSN26 tFBzNQNJn05lWh9w/KsowyK0jlbIgkh2I/OJKDKvZdvsSePC7rq6LAyOB3hS2eeJi2ab BMEvoOJeVSyWGL9WhdNzD5vVOyWqvIFFOPOt2QkuESN+XcvzqVKGhi6Vbn85ohAln0NQ LhCXjVUp3NcS4BisHaQ0T/uAOgIPpM1cOqGbqvcFnmcitUw8mvZbuJNBSg0Fxif9H0bR IargPItFeb2KbDNgOrKGHYYnvw6GDD1jMRXr7+biKrrVWg/Yf+XQBHQW5omXju8qSz84 gcRA== X-Gm-Message-State: AOJu0Yw3nymmaEkiige79tvhhL4O8WB6klI61Vu6aIW7riWr2zhqFEjx j+PUfms8hz3oPFLOzbq/KA7dP17ibVaL7lj0PyJVrSoRQNF2hxxo03hH2HO/9sjF+pZGh6N2CV/ L X-Google-Smtp-Source: AGHT+IGTV8Q1xjQCN4TbbuLHy7aECY3v2sqai8ntavveWfSOYmY+ZgnOp4IJHYABt/xKMKw2wpr6qg== X-Received: by 2002:a50:d79b:0:b0:5a2:d411:89fa with SMTP id 4fb4d7f45d1cf-5ac6412964amr874373a12.36.1721896070978; Thu, 25 Jul 2024 01:27:50 -0700 (PDT) From: Fouad Hilly To: xen-devel@lists.xenproject.org Cc: Fouad Hilly , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Julien Grall , Stefano Stabellini Subject: [PATCH v6 1/4] x86/ucode: Introduce XENPF_microcode_update2 with flags parameter Date: Thu, 25 Jul 2024 09:27:22 +0100 Message-ID: <20240725082725.2685481-2-fouad.hilly@cloud.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240725082725.2685481-1-fouad.hilly@cloud.com> References: <20240725082725.2685481-1-fouad.hilly@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1721896091188116600 Content-Type: text/plain; charset="utf-8" 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 Suggested-by: Andrew Cooper --- [v6] No change [v5] 1- Update commit message to include the full name of XENPF_microcode_update2 [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 determ= ine 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 =20 +#include + #include "private.h" =20 /* @@ -570,6 +572,7 @@ static int cf_check do_microcode_update(void *patch) } =20 struct ucode_buf { + unsigned int flags; unsigned int len; char buffer[]; }; @@ -708,13 +711,14 @@ static long cf_check microcode_update_helper(void *da= ta) return ret; } =20 -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; =20 - if ( len !=3D (uint32_t)len ) - return -E2BIG; + if ( flags & ~XENPF_UCODE_FORCE ) + return -EINVAL; =20 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 =3D len; + buffer->flags =3D flags; =20 /* * 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/as= m/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); =20 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_hype= rcall.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( =20 guest_from_compat_handle(data, op->u.microcode.data); =20 - ret =3D microcode_update(data, op->u.microcode.length); + ret =3D 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 =3D microcode_update(data, op->u.microcode2.length, + op->u.microcode2.flags); break; } =20 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); =20 +/* 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; }; --=20 2.42.0 From nobody Mon Sep 16 18:51:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1721896093; cv=none; d=zohomail.com; s=zohoarc; b=iaEBUV+vBhaSXkUgcZ10ukiiRWGrCUFt9vkhfS2VJKkq4gVe8At0P8mZ89aHxc6l09J1JpajgehejZFFg4zDljUC4RI5ZBX1NeZJQsprczgZvroLywcvU16C8kJoTc8DqoMtJ6dT915C+J3aX5Vw33Q9BBarEbzw7PWvV/pqu9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1721896093; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OBaRyDnAGRnUAzYqwQI4QueAjcDEPAmUfs0Um5xu1Fw=; b=JyA+ZqzhCUPg278pLBsa9zTzG845MB96iowdb6ivihH7Dl5JInuoUtC00xG7CF2ys6g3pGUIRzlVzUNDBbrq8keL2R20ktnwnecNO47ThTR8ZPlAIu5W4MEu8Y4CRPIyuHlmZCZgu8q/RuNc6IO7pXkJKvcUPmym04Oa5Qlsdn8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 17218960939171012.5495628000259; Thu, 25 Jul 2024 01:28:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.764818.1175393 (Exim 4.92) (envelope-from ) id 1sWtpM-0007OJ-Cy; Thu, 25 Jul 2024 08:27:56 +0000 Received: by outflank-mailman (output) from mailman id 764818.1175393; Thu, 25 Jul 2024 08:27:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sWtpM-0007O8-A6; Thu, 25 Jul 2024 08:27:56 +0000 Received: by outflank-mailman (input) for mailman id 764818; Thu, 25 Jul 2024 08:27:54 +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 1sWtpK-00070a-Pg for xen-devel@lists.xenproject.org; Thu, 25 Jul 2024 08:27:54 +0000 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [2a00:1450:4864:20::52f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c8da7fd4-4a5f-11ef-8776-851b0ebba9a2; Thu, 25 Jul 2024 10:27:52 +0200 (CEST) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-5a1c49632deso784624a12.2 for ; Thu, 25 Jul 2024 01:27:52 -0700 (PDT) Received: from fhilly.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5ac63590e7esm558590a12.36.2024.07.25.01.27.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 01:27:51 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: c8da7fd4-4a5f-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1721896072; x=1722500872; 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=OBaRyDnAGRnUAzYqwQI4QueAjcDEPAmUfs0Um5xu1Fw=; b=VA/+1NZG2Ye8x+cMODrXVvy6Unbm++2iWufSv0SZOqAQC96FnaR+YLSwub7qLFFS7k x/8cQtKO4uVEUAlyWEhVskccGzKSTRpRSD9zeSjfUT04EmJLqGhs3mxLzwSbjhZHXy7t a6ElbEJksFbsktC0YVVeRestsirLlLGsot6xA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721896072; x=1722500872; 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=OBaRyDnAGRnUAzYqwQI4QueAjcDEPAmUfs0Um5xu1Fw=; b=BI1RACxYHeaoM3vE6CmJFkDA+MWZOezYp+lW9Q0ffqUfW18g6wqOBALVRxyh1AHfDW LGxX+lmtE+7oIcMDfz5zMzMGq8bHnwYZuAthkrjQGXwdebTq5P3gHYZ/4Ndhs4ba+3a4 yujxffFIQFEUr5Rs1tLm+T1aU5OxuLL5phRVZMdsbyYSP7ZuEplZOh08G/Q3VThLqyr4 43vFDXbTywJfL/tQ23HwxWF7eTlVyTBDTaOMGV3gWdan4UMaXJCBj+6ubGyXcKnqB6pE 5hoh3fQi6fXRipcQIbSjQTbMm6tZtFl7fPgEmp31UXgl+txvlWHF0SqEvVllY+eOAPMg 2rBQ== X-Gm-Message-State: AOJu0YzoFQ6EZcA0dzjrCHx/GoTzA1WTzgW3nO8VEtwVe6X2uwLssLoo kJFvYAuQZtA79cDOJW9KbEA4DGwRJzHS4VP09mMQoTpDggT0EMEKiBnogG7V8aAJFcHxBQ5wAlG N X-Google-Smtp-Source: AGHT+IH7u/9vSqUG18/Wai/gBMKMoz1kLZADxXkS2EPtQ2jADup/zKwH3xjvDtCWFr24WntaeJTVng== X-Received: by 2002:a05:6402:2681:b0:586:e6e3:ea18 with SMTP id 4fb4d7f45d1cf-5acaad3c2b4mr672296a12.23.1721896071456; Thu, 25 Jul 2024 01:27:51 -0700 (PDT) From: Fouad Hilly To: xen-devel@lists.xenproject.org Cc: Fouad Hilly , Anthony PERARD Subject: [PATCH v6 2/4] x86/ucode: refactor xen-ucode to utilize getopt Date: Thu, 25 Jul 2024 09:27:23 +0100 Message-ID: <20240725082725.2685481-3-fouad.hilly@cloud.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240725082725.2685481-1-fouad.hilly@cloud.com> References: <20240725082725.2685481-1-fouad.hilly@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1721896095208116600 Content-Type: text/plain; charset="utf-8" Use getopt_long() to handle command line arguments. Introduce ext_err for common exit with errors. Introducing usage() to handle usage\help messages in a common block. show_curr_cpu is printed to stdout only. Signed-off-by: Fouad Hilly Suggested-by: Andrew Cooper --- [v6] 1- Update usage() printed message format: [microcode file] [options] -> [mi= crocode file | options] 2- Add missing blanks in switch ( opt ) [v5] 1- Update message description. 2- re-arrange static and automatic variables. 3- Fix indentations. 4- reverted the deletion of show-cpu-info for backwards compatibility. [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 | 52 +++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/tools/misc/xen-ucode.c b/tools/misc/xen-ucode.c index 390969db3d1c..2c9f337b86cb 100644 --- a/tools/misc/xen-ucode.c +++ b/tools/misc/xen-ucode.c @@ -11,6 +11,7 @@ #include #include #include +#include =20 static xc_interface *xch; =20 @@ -71,12 +72,29 @@ static void show_curr_cpu(FILE *f) } } =20 +static void usage(FILE *stream, const char *name) +{ + fprintf(stream, + "%s: Xen microcode updating tool\n" + "options:\n" + " -h, --help display this help\n" + " -s, --show-cpu-info show CPU information\n" + "Usage: %s [microcode file | options]\n", name, name); + show_curr_cpu(stream); +} + int main(int argc, char *argv[]) { + static const struct option options[] =3D { + {"help", no_argument, NULL, 'h'}, + {"show-cpu-info", no_argument, NULL, 's'}, + {NULL, no_argument, NULL, 0} + }; int fd, ret; char *filename, *buf; size_t len; struct stat st; + int opt; =20 xch =3D xc_interface_open(NULL, NULL, 0); if ( xch =3D=3D NULL ) @@ -86,22 +104,34 @@ int main(int argc, char *argv[]) exit(1); } =20 - if ( argc < 2 ) + while ( (opt =3D getopt_long(argc, argv, "hs", options, NULL)) !=3D -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; + } } =20 - if ( !strcmp(argv[1], "show-cpu-info") ) + if ( optind =3D=3D argc ) + goto ext_err; + + /* For backwards compatibility to the pre-getopt() cmdline handling */ + if ( !strcmp(argv[optind], "show-cpu-info") ) { show_curr_cpu(stdout); return 0; } =20 - filename =3D argv[1]; + filename =3D argv[optind]; fd =3D open(filename, O_RDONLY); if ( fd < 0 ) { @@ -146,4 +176,10 @@ int main(int argc, char *argv[]) close(fd); =20 return 0; + + ext_err: + fprintf(stderr, + "%s: unable to process command line arguments\n", argv[0]); + usage(stderr, argv[0]); + exit(EXIT_FAILURE); } --=20 2.42.0 From nobody Mon Sep 16 18:51:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1721896092; cv=none; d=zohomail.com; s=zohoarc; b=ZN9yw1UTHNK44BZzGGdRhZudHbfjIwGzOFrYtyBe/9T3kJmHP1iVV5EsfbUQ4roU5/ktZDMZBLC4hMAEeNdRMa8r1ZloddzRPOPsY9M03EEjJN3FA0BE0waVeXqcdDwc2cDfCMNkr9qE+NVsCSd2yWA8n8tZtTd+UCFfNJIicwA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1721896092; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BMAwTFy1Rlxptzf1ewiWhywNFS6V1PSKUkf1KHF6qIo=; b=RpQ9Pq1fab13ztQTyo8SmgNxfafQTL0FmYQlVmcPbbd+z9enNmVsu1MDCcWZqBQyrn6az4UdpKwb2Z/8RyEvushuAU0se+2hPAc1QXpTvw3DOolcvEC+7Iq1NFw2IYTslb+W2Ea3GC4GCwyo/9A01C/2gKhEeqpgAR5lRNHs8x4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1721896092157339.2883776669489; Thu, 25 Jul 2024 01:28:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.764817.1175383 (Exim 4.92) (envelope-from ) id 1sWtpL-000797-6E; Thu, 25 Jul 2024 08:27:55 +0000 Received: by outflank-mailman (output) from mailman id 764817.1175383; Thu, 25 Jul 2024 08:27:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sWtpL-000790-1u; Thu, 25 Jul 2024 08:27:55 +0000 Received: by outflank-mailman (input) for mailman id 764817; Thu, 25 Jul 2024 08:27:54 +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 1sWtpK-0006fy-1S for xen-devel@lists.xenproject.org; Thu, 25 Jul 2024 08:27:54 +0000 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [2a00:1450:4864:20::52b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c91f2d10-4a5f-11ef-bbff-fd08da9f4363; Thu, 25 Jul 2024 10:27:52 +0200 (CEST) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-58f9874aeb4so705754a12.0 for ; Thu, 25 Jul 2024 01:27:52 -0700 (PDT) Received: from fhilly.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5ac63590e7esm558590a12.36.2024.07.25.01.27.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 01:27:51 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: c91f2d10-4a5f-11ef-bbff-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1721896072; x=1722500872; 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=BMAwTFy1Rlxptzf1ewiWhywNFS6V1PSKUkf1KHF6qIo=; b=Is5JZWrhnOBXK54KYo9gKIe9Zx3/9zcObnIgEsbKKAfI8VCcTjCubpc6uL3Tmf1RWG eBCjUxIvMrohf7dw+L5giWkVtgKXXGLAWYBLMYB7ItEwR3WXMqRGWxukryfNV9X2XK0c Kh9PUghh9Na5Oxcn157FMXvB7E/iuU8SdgW50= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721896072; x=1722500872; 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=BMAwTFy1Rlxptzf1ewiWhywNFS6V1PSKUkf1KHF6qIo=; b=wWL7BaWv1eLLFu6WfPlCok1B28YdA05V7s7SGLxNU0h3Vvpqa1g5ARBIXw3H5vPxYc LVw4GTYPGfR6ZmH9pPuW7xRABwq94PxLWxYtXOFlf4cvGEM91rCfXG2qneQUtRsJb8po iHREIlNmLfsAQ48OmI5Xj3PQabPfsM8m7s9c0R07pCvHREdAm4HGoXn98LuXleNCxcNJ sY4D2ie4dtGyMYwpG1OeyVcWL+OtgsYMLlV7gJpaZA8nSydlgfP2EgI3qx8Ey+wuDoga t2bPQUvlJzNYlkmmrJwpmfiDWCUitmfjVNUN8qDDlKNsGr26Zo5kQ3mJZQWPSx+yQHeO doEg== X-Gm-Message-State: AOJu0YyeBdoCU3Qcziv5AQvw85Wn26tg2QbPYq8cLxcLheYDm1Lt1KBz NBC0vOrXhNBqksw8SbsI56Y46y+E35aK4SuEWyljKwvr7KbW/yi23tf1M/xcViz2mQmf6L108o8 w X-Google-Smtp-Source: AGHT+IEz/+qJhdhxjZMktp80vLu3Z7zdYAu8mcS1B1o0Mx+HJTsGQGdTSZqLNFRA01NszMnXySo2Kw== X-Received: by 2002:a50:9f6a:0:b0:5a1:b0b2:798d with SMTP id 4fb4d7f45d1cf-5ac64cc7549mr999063a12.25.1721896071983; Thu, 25 Jul 2024 01:27:51 -0700 (PDT) From: Fouad Hilly To: xen-devel@lists.xenproject.org Cc: Fouad Hilly , Anthony PERARD , Juergen Gross , Andrew Cooper Subject: [PATCH v6 3/4] x86/ucode: Introduce --force option to xen-ucode Date: Thu, 25 Jul 2024 09:27:24 +0100 Message-ID: <20240725082725.2685481-4-fouad.hilly@cloud.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240725082725.2685481-1-fouad.hilly@cloud.com> References: <20240725082725.2685481-1-fouad.hilly@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1721896093187116600 Content-Type: text/plain; charset="utf-8" Introduce --force option to xen-ucode to force skipping microcode version c= heck, 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_microcod= e_update2. Signed-off-by: Fouad Hilly Reviewed-by: Andrew Cooper Suggested-by: Andrew Cooper --- [v6] 1- Fix usage() output for -f option to be explicitly wrapped for 80 charact= er width [v5] 1- Update commit message. 2- Re-phrase --force option description. [v4] 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 | 15 ++++++++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 9ceca0cffc2f..2c4608c09ab0 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_v= er); 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; } =20 -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 =3D {}; - DECLARE_HYPERCALL_BUFFER(struct xenpf_microcode_update, uc); + DECLARE_HYPERCALL_BUFFER(struct xenpf_microcode_update2, uc); =20 uc =3D xc_hypercall_buffer_alloc(xch, uc, len); if ( uc =3D=3D NULL ) @@ -215,9 +216,10 @@ int xc_microcode_update(xc_interface *xch, const void = *buf, size_t len) =20 memcpy(uc, buf, len); =20 - platform_op.cmd =3D XENPF_microcode_update; - platform_op.u.microcode.length =3D len; - set_xen_guest_handle(platform_op.u.microcode.data, uc); + platform_op.cmd =3D XENPF_microcode_update2; + platform_op.u.microcode2.length =3D len; + platform_op.u.microcode2.flags =3D flags; + set_xen_guest_handle(platform_op.u.microcode2.data, uc); =20 ret =3D do_platform_op(xch, &platform_op); =20 diff --git a/tools/misc/xen-ucode.c b/tools/misc/xen-ucode.c index 2c9f337b86cb..688e540943b1 100644 --- a/tools/misc/xen-ucode.c +++ b/tools/misc/xen-ucode.c @@ -13,6 +13,8 @@ #include #include =20 +#include + static xc_interface *xch; =20 static const char intel_id[] =3D "GenuineIntel"; @@ -79,7 +81,9 @@ static void usage(FILE *stream, const char *name) "options:\n" " -h, --help display this help\n" " -s, --show-cpu-info show CPU information\n" - "Usage: %s [microcode file | options]\n", name, name); + " -f, --force skip certain checks; do not use unles= s\n" + "you know exactly what you are doing\n" + "Usage: %s [microcode file [-f,--force] | options]\n", name, n= ame); show_curr_cpu(stream); } =20 @@ -88,6 +92,7 @@ int main(int argc, char *argv[]) static const struct option options[] =3D { {"help", no_argument, NULL, 'h'}, {"show-cpu-info", no_argument, NULL, 's'}, + {"force", no_argument, NULL, 'f'}, {NULL, no_argument, NULL, 0} }; int fd, ret; @@ -95,6 +100,7 @@ int main(int argc, char *argv[]) size_t len; struct stat st; int opt; + uint32_t ucode_flags =3D 0; =20 xch =3D xc_interface_open(NULL, NULL, 0); if ( xch =3D=3D NULL ) @@ -104,7 +110,7 @@ int main(int argc, char *argv[]) exit(1); } =20 - while ( (opt =3D getopt_long(argc, argv, "hs", options, NULL)) !=3D -1= ) + while ( (opt =3D getopt_long(argc, argv, "hsf", options, NULL)) !=3D -= 1 ) { switch ( opt ) { @@ -116,6 +122,9 @@ int main(int argc, char *argv[]) show_curr_cpu(stdout); exit(EXIT_SUCCESS); =20 + case 'f': + ucode_flags =3D XENPF_UCODE_FORCE; + break; default: goto ext_err; } @@ -156,7 +165,7 @@ int main(int argc, char *argv[]) } =20 errno =3D 0; - ret =3D xc_microcode_update(xch, buf, len); + ret =3D xc_microcode_update(xch, buf, len, ucode_flags); if ( ret =3D=3D -1 && errno =3D=3D EEXIST ) printf("Microcode already up to date\n"); else if ( ret ) --=20 2.42.0 From nobody Mon Sep 16 18:51:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1721896098; cv=none; d=zohomail.com; s=zohoarc; b=FmHqH/opFsIBr0DtvA9tqFWW12R5VzUJ5f5OmBXQ3HU37iIAuBWoeVO1AXEex1bE145uV9rrRkSXaR8ZS6Ffq1EAioF2TB0K/g/aQPgTdIxVwu4kwW2rcQAWpERb4knqRbBY+G9cJUKhqHBBFRY94wwov6sDN+1Vr6ZYx9Nk2Ik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1721896098; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VVOe/t8VUEI4RbQ7J8nQRfJ3cqYvw3XGeBz8W3XqdYQ=; b=F5uz5PQLNN4FXW3EpwCsNW6dvYDgwqQp6zPhDYK30oZMZP2JKi6eM1+bKqHQBmUTsQqIzLCXypbq5ls62FGbd1sYyiNmQB9u2NSJVH7Yhg+mL8C70RoFTghGweCEbo4PRSMD0E5ECA6k+Jf/KfcESQcM71RvH23cPpHNbmVnXRU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1721896097924264.00300889887797; Thu, 25 Jul 2024 01:28:17 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.764819.1175397 (Exim 4.92) (envelope-from ) id 1sWtpM-0007Sq-P6; Thu, 25 Jul 2024 08:27:56 +0000 Received: by outflank-mailman (output) from mailman id 764819.1175397; Thu, 25 Jul 2024 08:27:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sWtpM-0007Q0-Jo; Thu, 25 Jul 2024 08:27:56 +0000 Received: by outflank-mailman (input) for mailman id 764819; Thu, 25 Jul 2024 08:27:55 +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 1sWtpL-0006fy-1U for xen-devel@lists.xenproject.org; Thu, 25 Jul 2024 08:27:55 +0000 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [2a00:1450:4864:20::52e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c98fceed-4a5f-11ef-bbff-fd08da9f4363; Thu, 25 Jul 2024 10:27:53 +0200 (CEST) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-5a3458bf858so775061a12.1 for ; Thu, 25 Jul 2024 01:27:53 -0700 (PDT) Received: from fhilly.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5ac63590e7esm558590a12.36.2024.07.25.01.27.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 01:27:52 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: c98fceed-4a5f-11ef-bbff-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1721896073; x=1722500873; 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=VVOe/t8VUEI4RbQ7J8nQRfJ3cqYvw3XGeBz8W3XqdYQ=; b=bc9NLOZqY8akKdVl6epvNFAIRbhXk37XuqogVZYvHCD0CfcZLQcXrWX1RyuO6QR8fm 6jTsaw3Wb2m9Cbt+GwD8RKQkbIIw4L8fGTlZ1yBqPFu/tAUwRMyfHka1VMfunAWkKWTL qeYJcHFQgvi/n5+Yio6780R1x8OI2yQWZbDpc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721896073; x=1722500873; 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=VVOe/t8VUEI4RbQ7J8nQRfJ3cqYvw3XGeBz8W3XqdYQ=; b=m8tPmJP5acrqNOFpLaVCWEM/EGXH9GVviiVVARrMArM28FuCr9FWY6WhUFZTWqdP0a ujnRyAlKcdinkAFwzNT50FFi+zFDQncxf4tNn6eGzz2raUsmAqUUJF8pcCnnhgoAjJts CIiGxLtpqf4qI6iXAfzwO2DrbBX9KouZOzYm9U4MIUBl9ztW45h9zxW6kUHKNpmqByc4 31mJJFbkoXOHMi9M0vRCTnry7vvjUdgeSfBKkiVUjGxseDBOIfYauB1PZH8HUdNida/b 3nzzM+jks2oiJ257zF3tN2poKkaP3DAP9TZNX8SVsa1ItC0eiCCGbHHoAfQvdgoaz7+q g1qQ== X-Gm-Message-State: AOJu0YyBD7wSEF8wksHNYRBuunZ5YyUm+xO5cf6Xz14xvFMYsABaop9A +AnIJ/yegB9a/zn9SOYHny6vvgvDNWS4HAMyTkl4ZdbW6oFEuLkXys2EinBdyUAwOmWVCIErLQs z X-Google-Smtp-Source: AGHT+IHqduZ9jVdHIHCAMWvCZqNZx+lg5p4II0Cave3jH/z3mA1k0t7L04M1v0i9O+J7YkYuM9Katw== X-Received: by 2002:a50:870b:0:b0:58b:9561:650b with SMTP id 4fb4d7f45d1cf-5ac63c50f88mr962304a12.25.1721896072638; Thu, 25 Jul 2024 01:27:52 -0700 (PDT) From: Fouad Hilly To: xen-devel@lists.xenproject.org Cc: Fouad Hilly , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v6 4/4] x86/ucode: Utilize ucode_force and remove opt_ucode_allow_same Date: Thu, 25 Jul 2024 09:27:25 +0100 Message-ID: <20240725082725.2685481-5-fouad.hilly@cloud.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240725082725.2685481-1-fouad.hilly@cloud.com> References: <20240725082725.2685481-1-fouad.hilly@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1721896099163116600 Content-Type: text/plain; charset="utf-8" Pass xen-ucode flags to do low level checks on micorocde version and utilize it to allow for microcode downgrade or reapply the same version of = the microcode. ucode_force is required to be passed to a low level Intel and AMD for versi= on checks to be done. While adding ucode_force, opt_ucode_allow_same was removed. Remove opt_ucode_allow_same from documentation. Signed-off-by: Fouad Hilly Suggested-by: Andrew Cooper --- [v6] 1- Removed struct microcode_nmi_patch_with_flags. 2- removed const from control_thread_fn() and primary_thread_fn(). 3- Fixed "flags" checks. [v5] 1- Update commit message. 2- Introduce structs microcode_patch_with_flags and microcode_nmi_patch_wit= h_flags. 3- pass flags to Intel and AMD low level through apply_microcode(). [4] 1- As opt_ucode_allow_same is not required anymore, it has been removed whi= le 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 | 8 ++- xen/arch/x86/cpu/microcode/core.c | 88 +++++++++++++++++----------- xen/arch/x86/cpu/microcode/intel.c | 9 ++- xen/arch/x86/cpu/microcode/private.h | 5 +- 5 files changed, 68 insertions(+), 49 deletions(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index 98a45211556b..2a8d47bbc664 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -2650,7 +2650,7 @@ performance. Alternatively, selecting `tsx=3D1` will re-enable TSX at the users own = risk. =20 ### ucode -> `=3D List of [ | scan=3D, nmi=3D, allow-same=3D ]` +> `=3D List of [ | scan=3D, nmi=3D ]` =20 Applicability: x86 Default: `nmi` @@ -2682,11 +2682,6 @@ precedence over `scan`. stop_machine context. In NMI handler, even NMIs are blocked, which is considered safer. The default value is `true`. =20 -'allow-same' alters the default acceptance policy for new microcode to per= mit -trying to reload the same version. Many CPUs will actually reload microco= de -of the same version, and this allows for easy testing of the late microcode -loading path. - ### unrestricted_guest (Intel) > `=3D ` =20 diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/= amd.c index f76a563c8b84..80ff6335d64a 100644 --- a/xen/arch/x86/cpu/microcode/amd.c +++ b/xen/arch/x86/cpu/microcode/amd.c @@ -22,6 +22,8 @@ =20 #include "private.h" =20 +#include "public/platform.h" + #define pr_debug(x...) ((void)0) =20 struct equiv_cpu_entry { @@ -214,13 +216,15 @@ static enum microcode_match_result cf_check compare_p= atch( return compare_header(new, old); } =20 -static int cf_check apply_microcode(const struct microcode_patch *patch) +static int cf_check apply_microcode(const struct microcode_patch *patch, + unsigned int flags) { int hw_err; unsigned int cpu =3D smp_processor_id(); struct cpu_signature *sig =3D &per_cpu(cpu_sig, cpu); uint32_t rev, old_rev =3D sig->rev; enum microcode_match_result result =3D microcode_fits(patch); + bool ucode_force =3D flags & XENPF_UCODE_FORCE; =20 if ( result =3D=3D MIS_UCODE ) return -EINVAL; @@ -229,7 +233,7 @@ static int cf_check apply_microcode(const struct microc= ode_patch *patch) * Allow application of the same revision to pick up SMT-specific chan= ges * even if the revision of the other SMT thread is already up-to-date. */ - if ( result =3D=3D OLD_UCODE ) + if ( !ucode_force && (result =3D=3D SAME_UCODE || result =3D=3D OLD_UC= ODE) ) return -EEXIST; =20 if ( check_final_patch_levels(sig) ) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index 8a9e744489b9..a0106a987e33 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -90,6 +90,11 @@ struct ucode_mod_blob { size_t size; }; =20 +struct patch_with_flags { + unsigned int flags; + struct microcode_patch *patch; +}; + static struct ucode_mod_blob __initdata ucode_blob; /* * By default we will NOT parse the multiboot modules to see if there is @@ -100,8 +105,6 @@ static bool __initdata ucode_scan; /* By default, ucode loading is done in NMI handler */ static bool ucode_in_nmi =3D true; =20 -bool __read_mostly opt_ucode_allow_same; - /* Protected by microcode_mutex */ static struct microcode_patch *microcode_cache; =20 @@ -128,8 +131,6 @@ static int __init cf_check parse_ucode(const char *s) =20 if ( (val =3D parse_boolean("nmi", s, ss)) >=3D 0 ) ucode_in_nmi =3D val; - else if ( (val =3D parse_boolean("allow-same", s, ss)) >=3D 0 ) - opt_ucode_allow_same =3D val; else if ( !ucode_mod_forced ) /* Not forced by EFI */ { if ( (val =3D parse_boolean("scan", s, ss)) >=3D 0 ) @@ -237,7 +238,11 @@ static DEFINE_PER_CPU(int, loading_err); */ static cpumask_t cpu_callin_map; static atomic_t cpu_out, cpu_updated; -static const struct microcode_patch *nmi_patch =3D ZERO_BLOCK_PTR; +static struct patch_with_flags nmi_patch_with_flags =3D +{ + .flags =3D 0, + .patch =3D ZERO_BLOCK_PTR, +}; =20 /* * Return a patch that covers current CPU. If there are multiple patches, @@ -327,7 +332,8 @@ static bool cf_check wait_cpu_callout(unsigned int nr) * If no patch is provided, the cached patch will be loaded. Microcode upd= ate * during APs bringup and CPU resuming falls into this case. */ -static int microcode_update_cpu(const struct microcode_patch *patch) +static int microcode_update_cpu(const struct microcode_patch *patch, + unsigned int flags) { int err; =20 @@ -335,10 +341,11 @@ static int microcode_update_cpu(const struct microcod= e_patch *patch) =20 spin_lock(µcode_mutex); if ( patch ) - err =3D alternative_call(ucode_ops.apply_microcode, patch); + err =3D alternative_call(ucode_ops.apply_microcode, patch, flags); else if ( microcode_cache ) { - err =3D alternative_call(ucode_ops.apply_microcode, microcode_cach= e); + err =3D alternative_call(ucode_ops.apply_microcode, microcode_cach= e, + flags); if ( err =3D=3D -EIO ) { microcode_free_patch(microcode_cache); @@ -379,7 +386,8 @@ static int secondary_nmi_work(void) return wait_for_state(LOADING_EXIT) ? 0 : -EBUSY; } =20 -static int primary_thread_work(const struct microcode_patch *patch) +static int primary_thread_work(struct microcode_patch *patch, + unsigned int flags) { int ret; =20 @@ -388,7 +396,7 @@ static int primary_thread_work(const struct microcode_p= atch *patch) if ( !wait_for_state(LOADING_ENTER) ) return -EBUSY; =20 - ret =3D alternative_call(ucode_ops.apply_microcode, patch); + ret =3D alternative_call(ucode_ops.apply_microcode, patch, flags); if ( !ret ) atomic_inc(&cpu_updated); atomic_inc(&cpu_out); @@ -416,7 +424,8 @@ static int cf_check microcode_nmi_callback( return 0; =20 if ( primary_cpu ) - ret =3D primary_thread_work(nmi_patch); + ret =3D primary_thread_work(nmi_patch_with_flags.patch, + nmi_patch_with_flags.flags); else ret =3D secondary_nmi_work(); this_cpu(loading_err) =3D ret; @@ -446,7 +455,8 @@ static int secondary_thread_fn(void) return this_cpu(loading_err); } =20 -static int primary_thread_fn(const struct microcode_patch *patch) +static int primary_thread_fn(struct microcode_patch *patch, + unsigned int flags) { if ( !wait_for_state(LOADING_CALLIN) ) return -EBUSY; @@ -466,10 +476,11 @@ static int primary_thread_fn(const struct microcode_p= atch *patch) return this_cpu(loading_err); } =20 - return primary_thread_work(patch); + return primary_thread_work(patch, flags); } =20 -static int control_thread_fn(const struct microcode_patch *patch) +static int control_thread_fn(struct microcode_patch *patch, + unsigned int flags) { unsigned int cpu =3D smp_processor_id(), done; unsigned long tick; @@ -482,7 +493,8 @@ static int control_thread_fn(const struct microcode_pat= ch *patch) */ watchdog_disable(); =20 - nmi_patch =3D patch; + nmi_patch_with_flags.patch =3D patch; + nmi_patch_with_flags.flags =3D flags; smp_wmb(); saved_nmi_callback =3D set_nmi_callback(microcode_nmi_callback); =20 @@ -498,7 +510,7 @@ static int control_thread_fn(const struct microcode_pat= ch *patch) goto out; =20 /* Control thread loads ucode first while others are in NMI handler. */ - ret =3D alternative_call(ucode_ops.apply_microcode, patch); + ret =3D alternative_call(ucode_ops.apply_microcode, patch, flags); if ( !ret ) atomic_inc(&cpu_updated); atomic_inc(&cpu_out); @@ -544,17 +556,19 @@ static int control_thread_fn(const struct microcode_p= atch *patch) =20 set_nmi_callback(saved_nmi_callback); smp_wmb(); - nmi_patch =3D ZERO_BLOCK_PTR; + nmi_patch_with_flags.patch =3D ZERO_BLOCK_PTR; + nmi_patch_with_flags.flags =3D 0; =20 watchdog_enable(); =20 return ret; } =20 -static int cf_check do_microcode_update(void *patch) +static int cf_check do_microcode_update(void *_patch_with_flags) { unsigned int cpu =3D smp_processor_id(); int ret; + struct patch_with_flags *patch_with_flags =3D _patch_with_flags; =20 /* * The control thread set state to coordinate ucode loading. Primary @@ -562,9 +576,11 @@ static int cf_check do_microcode_update(void *patch) * the completion of the ucode loading process. */ if ( cpu =3D=3D cpumask_first(&cpu_online_map) ) - ret =3D control_thread_fn(patch); + ret =3D control_thread_fn(patch_with_flags->patch, + patch_with_flags->flags); else if ( is_cpu_primary(cpu) ) - ret =3D primary_thread_fn(patch); + ret =3D primary_thread_fn(patch_with_flags->patch, + patch_with_flags->flags); else ret =3D secondary_thread_fn(); =20 @@ -582,7 +598,8 @@ static long cf_check microcode_update_helper(void *data) int ret; struct ucode_buf *buffer =3D data; unsigned int cpu, updated; - struct microcode_patch *patch; + struct patch_with_flags patch_with_flags; + bool ucode_force =3D buffer->flags & XENPF_UCODE_FORCE; =20 /* cpu_online_map must not change during update */ if ( !get_cpu_maps() ) @@ -606,16 +623,17 @@ static long cf_check microcode_update_helper(void *da= ta) goto put; } =20 - patch =3D parse_blob(buffer->buffer, buffer->len); + patch_with_flags.patch =3D parse_blob(buffer->buffer, buffer->len); + patch_with_flags.flags =3D buffer->flags; xfree(buffer); - if ( IS_ERR(patch) ) + if ( IS_ERR(patch_with_flags.patch) ) { - ret =3D PTR_ERR(patch); + ret =3D PTR_ERR(patch_with_flags.patch); printk(XENLOG_WARNING "Parsing microcode blob error %d\n", ret); goto put; } =20 - if ( !patch ) + if ( !patch_with_flags.patch ) { printk(XENLOG_WARNING "microcode: couldn't find any matching ucode= in " "the provided blob!\n"); @@ -632,17 +650,17 @@ static long cf_check microcode_update_helper(void *da= ta) { enum microcode_match_result result; =20 - result =3D alternative_call(ucode_ops.compare_patch, patch, - microcode_cache); + result =3D alternative_call(ucode_ops.compare_patch, + patch_with_flags.patch, microcode_cache); =20 if ( result !=3D NEW_UCODE && - !(opt_ucode_allow_same && result =3D=3D SAME_UCODE) ) + !(ucode_force && (result =3D=3D OLD_UCODE || result =3D=3D SA= ME_UCODE)) ) { spin_unlock(µcode_mutex); printk(XENLOG_WARNING "microcode: couldn't find any newer%s revision in the p= rovided blob!\n", - opt_ucode_allow_same ? " (or the same)" : ""); - microcode_free_patch(patch); + ucode_force? " (or a valid)" : ""); + microcode_free_patch(patch_with_flags.patch); ret =3D -EEXIST; =20 goto put; @@ -674,13 +692,13 @@ static long cf_check microcode_update_helper(void *da= ta) * this requirement can be relaxed in the future. Right now, this is * conservative and good. */ - ret =3D stop_machine_run(do_microcode_update, patch, NR_CPUS); + ret =3D stop_machine_run(do_microcode_update, &patch_with_flags, NR_CP= US); =20 updated =3D atomic_read(&cpu_updated); if ( updated > 0 ) { spin_lock(µcode_mutex); - microcode_update_cache(patch); + microcode_update_cache(patch_with_flags.patch); spin_unlock(µcode_mutex); =20 /* @@ -697,7 +715,7 @@ static long cf_check microcode_update_helper(void *data) alternative_vcall(ctxt_switch_masking, current); } else - microcode_free_patch(patch); + microcode_free_patch(patch_with_flags.patch); =20 if ( updated && updated !=3D nr_cores ) printk(XENLOG_ERR "ERROR: Updating microcode succeeded on %u cores= and failed\n" @@ -775,7 +793,7 @@ int microcode_update_one(void) if ( !ucode_ops.apply_microcode ) return -EOPNOTSUPP; =20 - return microcode_update_cpu(NULL); + return microcode_update_cpu(NULL, 0); } =20 static int __init early_update_cache(const void *data, size_t len) @@ -858,7 +876,7 @@ static int __init early_microcode_update_cpu(void) if ( !patch ) return -ENOENT; =20 - return microcode_update_cpu(patch); + return microcode_update_cpu(patch, 0); } =20 int __init early_microcode_init(unsigned long *module_map, diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcod= e/intel.c index f505aa1b7888..fc80f17d2376 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -29,6 +29,8 @@ =20 #include "private.h" =20 +#include "public/platform.h" + #define pr_debug(x...) ((void)0) =20 struct microcode_patch { @@ -284,21 +286,22 @@ static enum microcode_match_result cf_check compare_p= atch( return compare_revisions(old->rev, new->rev); } =20 -static int cf_check apply_microcode(const struct microcode_patch *patch) +static int cf_check apply_microcode(const struct microcode_patch *patch, + unsigned int flags) { uint64_t msr_content; unsigned int cpu =3D smp_processor_id(); struct cpu_signature *sig =3D &this_cpu(cpu_sig); uint32_t rev, old_rev =3D sig->rev; enum microcode_match_result result; + bool ucode_force =3D flags & XENPF_UCODE_FORCE; =20 result =3D microcode_update_match(patch); =20 if ( result =3D=3D MIS_UCODE ) return -EINVAL; =20 - if ( result =3D=3D OLD_UCODE || - (result =3D=3D SAME_UCODE && !opt_ucode_allow_same) ) + if ( !ucode_force && (result =3D=3D SAME_UCODE || result =3D=3D OLD_UC= ODE) ) return -EEXIST; =20 wbinvd(); diff --git a/xen/arch/x86/cpu/microcode/private.h b/xen/arch/x86/cpu/microc= ode/private.h index da556fe5060a..017889e1b58d 100644 --- a/xen/arch/x86/cpu/microcode/private.h +++ b/xen/arch/x86/cpu/microcode/private.h @@ -3,8 +3,6 @@ =20 #include =20 -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 */ @@ -50,7 +48,8 @@ struct microcode_ops { * Attempt to load the provided patch into the CPU. Returns an error = if * anything didn't go as expected. */ - int (*apply_microcode)(const struct microcode_patch *patch); + int (*apply_microcode)(const struct microcode_patch *patch, + unsigned int flags); =20 /* * Given two patches, are they both applicable to the current CPU, and= is --=20 2.42.0