From nobody Sat Nov 23 00:04:40 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=1713258982; cv=none; d=zohomail.com; s=zohoarc; b=b+PVaqs8oLlbqf51QW95BCmQI1uIjJRzLtyA3dONfB+IewBOXr8L9XFGa9DmLqh5BdLaOVxuoR+9lRD8LvQgrtv70riNonbfDJwjqiHQvFX0XQFo9h6iRUvYlr2M/FV0e8gnI7NE4BXXXU7EuE+nPGXeSp9N4hHp3GwP1Lx0AV8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713258982; 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=VMo9HfH+/6PT62gxIGHAj1EtchV4P4c0BEQDSxaYl8E=; b=FwynEgFwDl3hdsxiu4Wf1BAoQn3CuuQIj/ZsAqi5bZ64J8/kDUupJ9dYZXFalSOrGZ/0khSwT5cufXkaciCbhbGb6G6LAV/3mEl4YT88yef3afRGlVWSALnsLjSOitjU8x4oaI+BzGK3PZCVPs/eab2M3eIZBeeWocwjmNQHcvE= 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 1713258982689699.3499570904221; Tue, 16 Apr 2024 02:16:22 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.706795.1104174 (Exim 4.92) (envelope-from ) id 1rwev9-0000jD-Av; Tue, 16 Apr 2024 09:16:07 +0000 Received: by outflank-mailman (output) from mailman id 706795.1104174; Tue, 16 Apr 2024 09:16:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rwev9-0000j6-8S; Tue, 16 Apr 2024 09:16:07 +0000 Received: by outflank-mailman (input) for mailman id 706795; Tue, 16 Apr 2024 09:16:06 +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 1rwev8-0000j0-Nm for xen-devel@lists.xenproject.org; Tue, 16 Apr 2024 09:16:06 +0000 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [2a00:1450:4864:20::631]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f3f36ab4-fbd1-11ee-b909-491648fe20b8; Tue, 16 Apr 2024 11:16:05 +0200 (CEST) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-a5269c3f9c7so249524866b.2 for ; Tue, 16 Apr 2024 02:16:05 -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 u2-20020a17090657c200b00a524476aac9sm4654723ejr.108.2024.04.16.02.16.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 02:16:03 -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: f3f36ab4-fbd1-11ee-b909-491648fe20b8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1713258965; x=1713863765; 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=VMo9HfH+/6PT62gxIGHAj1EtchV4P4c0BEQDSxaYl8E=; b=VJEok3iEtIuwmTdUJzPtp1ihuKw0D7NcjP8Gb5OBw6Cg9Q2WNz13BveNZpueLRBpzm 5B3eUEwjBxfTgDED4tygut7mHvXw4Pnqs33ekd599tE6tovSANBxNZBGKCRFNaHoCrd4 czA7ZJI/AxEdHPjl6DE+U6W4ZpGgwgEYYtyC8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713258965; x=1713863765; 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=VMo9HfH+/6PT62gxIGHAj1EtchV4P4c0BEQDSxaYl8E=; b=kbM/vrt1FgsQcXvaA0wsXNEK+sCJ8ZdgbAjHhN5Us0521WVnKZOaycgbHk5YJwm06y Yc0C6/xozr6pPp9L9bEVBtXETMwlmF+ZDg7B54+NWEHi+d5ruT386N1NmllMQ6GAtm5d T7V/2rH3pmB6kC87uNgcnx6zIZOsjYumiqD8KCQzLHBLjN/81ghSiDDTUysQvzfLqvgJ 4f4Az0SEVfpR5OVgSj3ubHc3iAc1ug7NRZuPfLv/t3SXrKAWPoNB9uUtHz5Up1Z6nG6H hQWwsoOW+qiF6YMU9Yp9w0cDpEktB0U48vX3ckQvahUmgQiNuMkVjMUYZ07yQ4n8OCcD z0wQ== X-Gm-Message-State: AOJu0Yzbuz9+rdStdh2Q9OTjVNdv9L39mdB6BMa27fWO/ml4bOvmZzsv KvkRZpADfa7LDxm1gmLJO13nzCqNF3cB4i1Jkam7XWB2lxP1MXirtsCOziIQ1mhn/BeAqSgAvq2 5 X-Google-Smtp-Source: AGHT+IGiVFzED4vE2YgqcbK2WERtwlr9k7iUaPSamGBfKHXw9VfXOpLltOmof+L9ChbTrnrinumiKA== X-Received: by 2002:a17:906:2dc5:b0:a52:225a:2ebe with SMTP id h5-20020a1709062dc500b00a52225a2ebemr6719632eji.71.1713258964803; Tue, 16 Apr 2024 02:16:04 -0700 (PDT) From: Fouad Hilly To: Xen-devel Cc: Fouad Hilly , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v2 1/5] x86: Update x86 low level version check of microcode Date: Tue, 16 Apr 2024 10:15:42 +0100 Message-ID: <20240416091546.11622-2-fouad.hilly@cloud.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240416091546.11622-1-fouad.hilly@cloud.com> References: <20240416091546.11622-1-fouad.hilly@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1713258984194100001 Content-Type: text/plain; charset="utf-8" Update microcode version check at Intel and AMD Level by: Preventing the low level code from sending errors if the microcode version provided is not a newer version. Other errors will be sent like bef= ore. When the provided microcode version is the same as the current one, code to point to microcode provided. Microcode version check happens at higher and common level in core.c. Keep all the required code at low level that checks for signature and CPU c= ompatibility [v2] Update message description to better describe the changes Signed-off-by: Fouad Hilly --- xen/arch/x86/cpu/microcode/amd.c | 8 ++------ xen/arch/x86/cpu/microcode/intel.c | 11 +++-------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/= amd.c index 75fc84e445ce..4f805f662701 100644 --- a/xen/arch/x86/cpu/microcode/amd.c +++ b/xen/arch/x86/cpu/microcode/amd.c @@ -383,12 +383,8 @@ static struct microcode_patch *cf_check cpu_request_mi= crocode( goto skip; } =20 - /* - * If the new ucode covers current CPU, compare ucodes and sto= re the - * one with higher revision. - */ - if ( (microcode_fits(mc->patch) !=3D MIS_UCODE) && - (!saved || (compare_header(mc->patch, saved) =3D=3D NEW_U= CODE)) ) + /* If the provided ucode covers current CPU, then store its re= vision. */ + if ( (microcode_fits(mc->patch) !=3D MIS_UCODE) && !saved ) { saved =3D mc->patch; saved_size =3D mc->len; diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcod= e/intel.c index 060c529a6e5d..e65c02a57987 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 microc= ode_patch *patch) =20 result =3D microcode_update_match(patch); =20 - if ( result !=3D NEW_UCODE && - !(opt_ucode_allow_same && result =3D=3D SAME_UCODE) ) + if ( result !=3D NEW_UCODE && result !=3D SAME_UCODE ) return -EINVAL; =20 wbinvd(); @@ -354,12 +353,8 @@ static struct microcode_patch *cf_check cpu_request_mi= crocode( if ( error ) break; =20 - /* - * If the new update covers current CPU, compare updates and store= the - * one with higher revision. - */ - if ( (microcode_update_match(mc) !=3D MIS_UCODE) && - (!saved || compare_revisions(saved->rev, mc->rev) =3D=3D NEW_= UCODE) ) + /* If the provided ucode covers current CPU, then store its revisi= on. */ + if ( (microcode_update_match(mc) !=3D MIS_UCODE) && !saved ) saved =3D mc; =20 buf +=3D blob_size; --=20 2.42.0 From nobody Sat Nov 23 00:04:40 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=1713258988; cv=none; d=zohomail.com; s=zohoarc; b=IXvdnc9acpPMfflZXbspaueG3ZqWogWXbApkyHdTy6dA6+/RY/oQSgFEZ/z9YonkporYPGrmnr5VzYS3yiq+VGNpnBlax8IspIlpC8q7XnAjV5Zlj8SRoav62f3u8JwExi9XFu9fHoCWafTLxbMxo/RtsX2/gcKoxoBC4mhQm0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713258988; 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=5JYgU5u131JTGNDKaVXDUtjVdH+AOMW24dDk4iz+IAQ=; b=OoGUNZCvI9s0u2HYT5fBueznx/wYJj8/ExMfvGSRFHSSVuxmb9PZfA7ZXxf9dbqBZ+MxmOuBJ0/2uq5RmnDAyrF9cNHqx66lEZqPukigs9mVVQ/gVDPETEQRY7tUllsuoQQO1sBHtVDgF022vF4uVZiMvqGOtc0X3ysm/IwvFsA= 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 1713258988864802.0150855535494; Tue, 16 Apr 2024 02:16:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.706796.1104185 (Exim 4.92) (envelope-from ) id 1rwevA-0000xd-KK; Tue, 16 Apr 2024 09:16:08 +0000 Received: by outflank-mailman (output) from mailman id 706796.1104185; Tue, 16 Apr 2024 09:16:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rwevA-0000xW-Fb; Tue, 16 Apr 2024 09:16:08 +0000 Received: by outflank-mailman (input) for mailman id 706796; Tue, 16 Apr 2024 09:16:07 +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 1rwev9-0000j0-DM for xen-devel@lists.xenproject.org; Tue, 16 Apr 2024 09:16:07 +0000 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [2a00:1450:4864:20::62a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f4a4db3f-fbd1-11ee-b909-491648fe20b8; Tue, 16 Apr 2024 11:16:06 +0200 (CEST) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a526a200879so259444566b.1 for ; Tue, 16 Apr 2024 02:16:06 -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 u2-20020a17090657c200b00a524476aac9sm4654723ejr.108.2024.04.16.02.16.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 02:16:05 -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: f4a4db3f-fbd1-11ee-b909-491648fe20b8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1713258965; x=1713863765; 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=5JYgU5u131JTGNDKaVXDUtjVdH+AOMW24dDk4iz+IAQ=; b=BzYa4uWHuv2Zvez4tzfhdDI/KoMiyVC6rj2YpR1zB1V6o7MQaEHqTGeHINqH32Zq1w /9PYScTREX0D+fqhd0bjRAGUzPCCFTF/pKUnueI4i4cSgtSG7r1BDQOGCYBiZNQR/xHR ysZ8aA71P81R79L7RSdNaF4zRJWD9T2NOtMCk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713258965; x=1713863765; 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=5JYgU5u131JTGNDKaVXDUtjVdH+AOMW24dDk4iz+IAQ=; b=f2BX9A74SeYKemXzAmQuC3/t6lWwEab6aIgmQyhExTmESIebEk4SDYKugmEHC1Rvz5 L7Mf8asg+Dksvg6zxmEVptvbA6jzlbS2wvzXHPoh4v948BSGQbvM8ew1vFxBjq/ddy7E AxeXb+nos26IzJh9T4WslNoSzuna/2NvqkH9RY5SVSgP/6+3dgMPzb1V9hLge3Y7e86m zEC0TRQKZ/YSgLsHGESfO73XyRSrGHEKQ+kdQFMQQGJfZsqHRVlXYftoKo1yjE+Lnz+w +BBJv6rpKvDDVL52goRPEyrMpDUEpkbiGNKk0MdhFLacxpU6qO7yWlO5jdYXhzADPlWx bffQ== X-Gm-Message-State: AOJu0YwYDuTrf69LNg7Kt5RsPFUx1G8amvC0hLH9Bm4YOrRUQleriE0J +uOFhznHnligavd+ywBZon22dIvGyEhA3C9JSJjoTZx/I6pDar73XnsBGsgMwJBE+OGkqG8s4QM q X-Google-Smtp-Source: AGHT+IHxM5DeAYgkZJbDRrxtvBfaz5fjtIiGJp51U0h7y+qo192KWoRi01Ube2KEpZZGxGO6bm3fPA== X-Received: by 2002:a17:906:aed4:b0:a52:6a31:a9f2 with SMTP id me20-20020a170906aed400b00a526a31a9f2mr3136041ejb.70.1713258965596; Tue, 16 Apr 2024 02:16:05 -0700 (PDT) From: Fouad Hilly To: Xen-devel Cc: Fouad Hilly , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , George Dunlap , Julien Grall , Stefano Stabellini Subject: [PATCH v2 2/5] x86: Refactor microcode_update() hypercall with flags Date: Tue, 16 Apr 2024 10:15:43 +0100 Message-ID: <20240416091546.11622-3-fouad.hilly@cloud.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240416091546.11622-1-fouad.hilly@cloud.com> References: <20240416091546.11622-1-fouad.hilly@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1713258990166100003 Content-Type: text/plain; charset="utf-8" Refactor microcode_update() hypercall by adding flags field. Introduce XENPF_microcode_update2 hypercall to handle flags field. struct xenpf_microcode_update updated to have uint32_t flags at the end of the sturcture. [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. Signed-off-by: Fouad Hilly --- xen/arch/x86/cpu/microcode/core.c | 14 +++++++++++--- xen/arch/x86/include/asm/microcode.h | 3 ++- xen/arch/x86/platform_hypercall.c | 12 +++++++++++- xen/include/public/platform.h | 6 ++++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index 1c9f66ea8a0f..99b651d8c3a1 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 /* @@ -100,6 +102,8 @@ static bool ucode_in_nmi =3D true; =20 bool __read_mostly opt_ucode_allow_same; =20 +static unsigned int ucode_update_flags =3D 0; + /* Protected by microcode_mutex */ static struct microcode_patch *microcode_cache; =20 @@ -580,6 +584,7 @@ static long cf_check microcode_update_helper(void *data) struct ucode_buf *buffer =3D data; unsigned int cpu, updated; struct microcode_patch *patch; + bool ucode_force_flag =3D ucode_update_flags =3D=3D XENPF_UCODE_FLAG_F= ORCE_SET; =20 /* cpu_online_map must not change during update */ if ( !get_cpu_maps() ) @@ -633,12 +638,12 @@ static long cf_check microcode_update_helper(void *da= ta) microcode_cache); =20 if ( result !=3D NEW_UCODE && - !(opt_ucode_allow_same && result =3D=3D SAME_UCODE) ) + !((opt_ucode_allow_same || ucode_force_flag) && result =3D=3D= SAME_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)" : ""); + (opt_ucode_allow_same || ucode_force_flag) ? " (or the = same)" : ""); microcode_free_patch(patch); ret =3D -ENOENT; =20 @@ -708,7 +713,8 @@ static long cf_check microcode_update_helper(void *data) 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; @@ -731,6 +737,8 @@ int microcode_update(XEN_GUEST_HANDLE(const_void) buf, = unsigned long len) } buffer->len =3D len; =20 + ucode_update_flags =3D flags; + /* * Always queue microcode_update_helper() on CPU0. Most of the logic * won't care, but the update of the Raw CPU policy wants to (re)run on 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..3b29ede8b316 100644 --- a/xen/arch/x86/platform_hypercall.c +++ b/xen/arch/x86/platform_hypercall.c @@ -311,7 +311,17 @@ 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.microcode.data); + + ret =3D microcode_update(data, op->u.microcode.length, op->u.micro= code.flags); break; } =20 diff --git a/xen/include/public/platform.h b/xen/include/public/platform.h index 15777b541690..cc19b2956b46 100644 --- a/xen/include/public/platform.h +++ b/xen/include/public/platform.h @@ -99,6 +99,9 @@ struct xenpf_microcode_update { /* IN variables. */ XEN_GUEST_HANDLE(const_void) data;/* Pointer to microcode data */ uint32_t length; /* Length of microcode data. */ + uint32_t flags; /* Flags to be passed with ucode. */ +/* Force to skip microcode version check when set */ +#define XENPF_UCODE_FLAG_FORCE_SET 1 }; typedef struct xenpf_microcode_update xenpf_microcode_update_t; DEFINE_XEN_GUEST_HANDLE(xenpf_microcode_update_t); @@ -624,6 +627,9 @@ 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 + /* * ` enum neg_errnoval * ` HYPERVISOR_platform_op(const struct xen_platform_op*); --=20 2.42.0 From nobody Sat Nov 23 00:04:40 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=1713258990; cv=none; d=zohomail.com; s=zohoarc; b=DUjedTAYDTa/igW08Ol6tCZF0sxxHra+dDGfkM4wM2/UuKBRSCKpxpXRVMPmaSoBVDwt8SmjVF0lGuXz37VvKDP+O3D62LTQMGBcPVzNhZ/YDc3PDSkMaijy51gEct4X4Q71bWQ2gORJQa7k0zHjseP+sr5VPcEXIxcOAGpTGKg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713258990; 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=8L5gTKzhiipTLmXWv/M3h8GXKJ30XFqq9tUQkMs7y54=; b=grvszNmcRO+rUwYAdgZVjRZTndNiCSdAt9ksDpm/xk3w5gIwcbGQgeUgbzLi15niHeMwNIjtrc+Xrc10nr6EtU6/TQ19dweK9coFompNGsdJIT0KHiaBiPkmp3MEparizh6GmQt0xhRWk25sl77Uj257YspQymc3g6okG9LYEYg= 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 1713258990780496.31941884185426; Tue, 16 Apr 2024 02:16:30 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.706798.1104205 (Exim 4.92) (envelope-from ) id 1rwevC-0001Rz-6N; Tue, 16 Apr 2024 09:16:10 +0000 Received: by outflank-mailman (output) from mailman id 706798.1104205; Tue, 16 Apr 2024 09:16:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rwevC-0001Rr-1r; Tue, 16 Apr 2024 09:16:10 +0000 Received: by outflank-mailman (input) for mailman id 706798; Tue, 16 Apr 2024 09:16:08 +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 1rwevA-0000j0-DQ for xen-devel@lists.xenproject.org; Tue, 16 Apr 2024 09:16:08 +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 f503c26e-fbd1-11ee-b909-491648fe20b8; Tue, 16 Apr 2024 11:16:07 +0200 (CEST) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a5200afe39eso512106966b.1 for ; Tue, 16 Apr 2024 02:16:07 -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 u2-20020a17090657c200b00a524476aac9sm4654723ejr.108.2024.04.16.02.16.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 02:16:05 -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: f503c26e-fbd1-11ee-b909-491648fe20b8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1713258966; x=1713863766; 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=8L5gTKzhiipTLmXWv/M3h8GXKJ30XFqq9tUQkMs7y54=; b=bOkaKFjMhNuUeICsj4Kb/zaUNlqdoUInm5//RCaxOUjHwVX86j7VcuBkFSlJnAy50Y QEr70VoUrQBphwDXecZycAxA8caAV05DE/wGO71czteAjy+y7v3qDoxELqsGF4tyFHQ5 +iH0yJG6HrLJnPZx4J9Uy7U2FwZNpojCH4UfI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713258966; x=1713863766; 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=8L5gTKzhiipTLmXWv/M3h8GXKJ30XFqq9tUQkMs7y54=; b=kOZk74AdXTIjlVIVhiLJT2pC9rJyup35fxRRwYRFgLWgdde7WXzS6+YGQn4couSmFd iCzhzjLWkOUSg2BxJFTiZBabXsah0zkAjYMq2O21Pj6dFLo161opdX181LTwe7h7CS5S /5574pv4dUwZlj9t8EQo2cXSZV9qHzGWGiv75fDDHPp0PZ10D94XjbCK8fjdLQ/k8XVt yiZmTvgXAlTBurUsalLV8Ggx+XypoNX1t938LZYP/9hJzQGNuJV8k8BSp94JDKYD4c8r n+5kIZHE9KKhLht1Gv8KXQ6lO4u5h0YnAI1kLpZGhL01qvXgeQsJUAQzk690i9Q2kZcO AK+g== X-Gm-Message-State: AOJu0Yzb2IbWVRsr1qFgqs6+L6YEekf5Wr9wvkjWGm36dlLwbcF6V9Uy aI2JVqnfqBzgldtZ8RJQB//GZWbC5T84fDFgAdqm96tMLb0znjVuaw2P+U1msSEgzFbv4mpyHBv 9 X-Google-Smtp-Source: AGHT+IFZEmBGqBvnw2Jp/PJNHnVx1tMBkCNCPTVTjpqTQ1tLdZHbYTcE8DSmFB2Nf2q5YLdd+VNC2Q== X-Received: by 2002:a17:906:af14:b0:a52:68db:9fe7 with SMTP id lx20-20020a170906af1400b00a5268db9fe7mr4714628ejb.11.1713258966751; Tue, 16 Apr 2024 02:16:06 -0700 (PDT) From: Fouad Hilly To: Xen-devel Cc: Fouad Hilly , Anthony PERARD Subject: [PATCH v2 3/5] x86: Add usage() to print out usage message Date: Tue, 16 Apr 2024 10:15:44 +0100 Message-ID: <20240416091546.11622-4-fouad.hilly@cloud.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240416091546.11622-1-fouad.hilly@cloud.com> References: <20240416091546.11622-1-fouad.hilly@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1713258992167100005 Content-Type: text/plain; charset="utf-8" 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 common= block [v2] 1- Improved message description. 2- Fixed formatting and indentation. 3- Error message to print to stderr. Signed-off-by: Fouad Hilly --- tools/misc/xen-ucode.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/misc/xen-ucode.c b/tools/misc/xen-ucode.c index c6ae6498d659..0c0b2337b4ea 100644 --- a/tools/misc/xen-ucode.c +++ b/tools/misc/xen-ucode.c @@ -17,6 +17,15 @@ static xc_interface *xch; static const char intel_id[] =3D "GenuineIntel"; static const char amd_id[] =3D "AuthenticAMD"; =20 +static void usage(const char *name) +{ + printf("%s: Xen microcode updating tool\n" + "Usage: %s [microcode file] [options]\n" + "Options:\n" + "show-cou-info show CPU information and exit\n", + name, name); +} + static void show_curr_cpu(FILE *f) { int ret; --=20 2.42.0 From nobody Sat Nov 23 00:04:40 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=1713258991; cv=none; d=zohomail.com; s=zohoarc; b=mvj4JLOdxAhAYTm59QvWsNGV1ByGBa4X8PZlsN60reXCE8ZJPavK9jOwOpWAuMpg2FnRE33Q6OhvgjddlcD2ZjG7Sk2cjcn172E1BhX747teHOtrJ8r5vbZYEhS2QI2gnVMnb+efWiI/QiQBzfDZl2YT1IykgR0zwJwTAJdsLYk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713258991; 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=QqMqjbPKATTcFkSZJE0LrlnS9bwDIdnbbvMhDvcYVI0=; b=RBm2XB8M1GgElldBqS4R1nCbWIHIM0A5TCvEGKArjfcDK8ww2U8MJQwBWkAwMCtud65HFtL1GEVAcjGWn4WnPrxSUbGXmUZtlhlqfS8r2X6/iKRtsFbMgTWZqTsY6/idX1wtZUyBhFDw7khkJuWdbZY4nKpb9atsEYkj5IvTGN8= 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 1713258991223264.46234348100836; Tue, 16 Apr 2024 02:16:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.706799.1104214 (Exim 4.92) (envelope-from ) id 1rwevD-0001hX-Dl; Tue, 16 Apr 2024 09:16:11 +0000 Received: by outflank-mailman (output) from mailman id 706799.1104214; Tue, 16 Apr 2024 09:16: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 1rwevD-0001h0-AZ; Tue, 16 Apr 2024 09:16:11 +0000 Received: by outflank-mailman (input) for mailman id 706799; Tue, 16 Apr 2024 09:16:09 +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 1rwevB-0000mP-HQ for xen-devel@lists.xenproject.org; Tue, 16 Apr 2024 09:16:09 +0000 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [2a00:1450:4864:20::52c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f560a58d-fbd1-11ee-94a3-07e782e9044d; Tue, 16 Apr 2024 11:16:08 +0200 (CEST) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-570097653faso2633925a12.0 for ; Tue, 16 Apr 2024 02:16:08 -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 u2-20020a17090657c200b00a524476aac9sm4654723ejr.108.2024.04.16.02.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 02:16:07 -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: f560a58d-fbd1-11ee-94a3-07e782e9044d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1713258967; x=1713863767; 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=QqMqjbPKATTcFkSZJE0LrlnS9bwDIdnbbvMhDvcYVI0=; b=VD4zMLkKJwilqmWZlfTGn1w949+B5OUX+RIw4cWqBbSjNcY21YbJPv30FhVrPmtXuY 9aH19xWrPj7JC9DCRge8f+iz98s9Dt3GWVLbydEd72H204chs4PzqYb4dxKMSz41K1sK MwgywaYiv9AeYXPDoGFoA1ajGZWIaesCYxk2o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713258967; x=1713863767; 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=QqMqjbPKATTcFkSZJE0LrlnS9bwDIdnbbvMhDvcYVI0=; b=eDu7yhf8ftMqfsmH9tSSN0sS/AeoUVE692+1rZKXDWXv7MJPVjLAk6w/fZvlBGSHtd kXblyNC8ENE0lgVV/Sr2umUTTiVTjjzK64VMoNbWaWq5rzYE6SH4pmJV3tRX2AKpAvc7 59OlDuXp0ia26GvckPh6ZcKfxX3eS3+ee1gxa/3JoArv8Gzhc0o1Qx03SNu/dUpbPw5U 1BvrPGrqbO+4JcT+oHDve8ZpcWu1RUBBuE7P508KVd94KhKFtwuQPqBKVIuIxZyWccrF Z5GqNySqBt3eGxOylspyOg181XJ6qeFeI4TA1B3fPXQ76asbMYJKf4pPThT81GZ1qto7 Ye7A== X-Gm-Message-State: AOJu0Ywyp/crmbzYrJwYorogv+n5nxEaOt7UT2vGx+jKWKw3pSTzmRYw JqJSs0LfZH3Q/EX2jhuP6+RIU3z/oQBlI9QgIqGLyXrZEOPY6/kko2FxdUEcA4wQZEJB+9a288V f X-Google-Smtp-Source: AGHT+IGZFc5vZSLMqmSJtZ9LG3B1/EYB+WqDlokgwcpiJVA1CYkpP42KgKueD+A6VdIm2whqItACUA== X-Received: by 2002:a17:907:9443:b0:a52:3f00:616d with SMTP id dl3-20020a170907944300b00a523f00616dmr10232289ejc.30.1713258967372; Tue, 16 Apr 2024 02:16:07 -0700 (PDT) From: Fouad Hilly To: Xen-devel Cc: Fouad Hilly , Anthony PERARD Subject: [PATCH v2 4/5] x86: Use getopt to handle command line args Date: Tue, 16 Apr 2024 10:15:45 +0100 Message-ID: <20240416091546.11622-5-fouad.hilly@cloud.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240416091546.11622-1-fouad.hilly@cloud.com> References: <20240416091546.11622-1-fouad.hilly@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1713258992170100006 Content-Type: text/plain; charset="utf-8" Use getopt_long() to handle command line arguments. Introduce ext_err for common exit with errors. [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. Signed-off-by: Fouad Hilly --- tools/misc/xen-ucode.c | 43 ++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/tools/misc/xen-ucode.c b/tools/misc/xen-ucode.c index 0c0b2337b4ea..e3c1943e3633 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 @@ -22,7 +23,8 @@ static void usage(const char *name) printf("%s: Xen microcode updating tool\n" "Usage: %s [microcode file] [options]\n" "Options:\n" - "show-cou-info show CPU information and exit\n", + " -h, --help display this help and exit\n" + " -s, --show-cpu-info show CPU information and exit\n", name, name); } =20 @@ -86,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[] =3D { + {"help", no_argument, NULL, 'h'}, + {"show-cpu-info", no_argument, NULL, 's'}, + {NULL, no_argument, NULL, 0} + }; =20 xch =3D xc_interface_open(NULL, NULL, 0); if ( xch =3D=3D NULL ) @@ -95,19 +104,22 @@ int main(int argc, char *argv[]) exit(1); } =20 - if ( argc < 2 ) - { - fprintf(stderr, - "xen-ucode: Xen microcode updating tool\n" - "Usage: %s [ | show-cpu-info]\n", argv[0]); - show_curr_cpu(stderr); - exit(2); - } + if ( argc !=3D 2 ) + goto ext_err; =20 - if ( !strcmp(argv[1], "show-cpu-info") ) + while ( (opt =3D getopt_long(argc, argv, "hs", options, NULL)) !=3D -1= ) { - show_curr_cpu(stdout); - return 0; + switch (opt) + { + case 'h': + usage(argv[0]); + exit(EXIT_SUCCESS); + case 's': + show_curr_cpu(stdout); + exit(EXIT_SUCCESS); + default: + goto ext_err; + } } =20 filename =3D argv[1]; @@ -152,4 +164,11 @@ int main(int argc, char *argv[]) close(fd); =20 return 0; + + ext_err: + fprintf(stderr, + "xen-ucode: Xen microcode updating tool\n" + "Usage: %s [microcode file] [options]\n", argv[0]); + show_curr_cpu(stderr); + exit(STDERR_FILENO); } --=20 2.42.0 From nobody Sat Nov 23 00:04:40 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=1713258996; cv=none; d=zohomail.com; s=zohoarc; b=GEQ1djrFGrWe1IGJBriytkr4wgl13W1RU+NQFkYZbfFIQqafjGMkGC7+brXEKIEiMJWdRpHJCwhcD8RgW7KDEWG4g5Qc1awM2tHPL0gKZHWQo8xAxy6r+dJcfMfByCO/3RUhmnQNI4wNIpH5HSmWl2MwCYM9FJ+4C/TeH4iBZs4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713258996; 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=sEqOdsYIwbuJuEjSHon4MvvMLQajO7Ykh4oIkPsh7vk=; b=SIhMRZQcoe/5LQEqj/ajkcAaPEmkee5E0KUQbaszljZXYiKyGyRq/Spyw0cIW4uYzrbLmxQjWf4aZaT70+uZbx4h6K+tOvVNc1LGy8UGGH1MdW8T07g+hGrK8615IFMcoHpeHXdAXVleFL8w6IvjJh5IyP+0+TQh2WZXo8upNlw= 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 1713258996017465.478711457362; Tue, 16 Apr 2024 02:16:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.706800.1104221 (Exim 4.92) (envelope-from ) id 1rwevD-0001nA-UZ; Tue, 16 Apr 2024 09:16:11 +0000 Received: by outflank-mailman (output) from mailman id 706800.1104221; Tue, 16 Apr 2024 09:16: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 1rwevD-0001lY-Lj; Tue, 16 Apr 2024 09:16:11 +0000 Received: by outflank-mailman (input) for mailman id 706800; Tue, 16 Apr 2024 09:16:10 +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 1rwevC-0000mP-RT for xen-devel@lists.xenproject.org; Tue, 16 Apr 2024 09:16:10 +0000 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [2a00:1450:4864:20::62a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f61d111e-fbd1-11ee-94a3-07e782e9044d; Tue, 16 Apr 2024 11:16:09 +0200 (CEST) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a51a7dc45easo461971566b.2 for ; Tue, 16 Apr 2024 02:16:09 -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 u2-20020a17090657c200b00a524476aac9sm4654723ejr.108.2024.04.16.02.16.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 02:16:07 -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: f61d111e-fbd1-11ee-94a3-07e782e9044d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1713258968; x=1713863768; 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=sEqOdsYIwbuJuEjSHon4MvvMLQajO7Ykh4oIkPsh7vk=; b=EFcGpBQXmYHnfRATV1FQR91RHfwKH8mQB3gp7V4eOrU3x+SiLzbkTGzG7zBkSu0nCt bhCTB79DuUHkGkRh2JmPBrT7V/08J8Rr0B6dSn8PmLHZKoTsugDpEfP6Sm7OPCiF+ugg LaEj4lkQ6jljTPALMmb0NG443Zjn8DHUwdB7Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713258968; x=1713863768; 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=sEqOdsYIwbuJuEjSHon4MvvMLQajO7Ykh4oIkPsh7vk=; b=uJQ1yHCsg+JrhsDrINwBmITEnwxHQBR1MRV4TrB0NKFPIDXq8ajEe0g9TsogTA8fnx sdjV707XpALj+LPXb0Yjn3QXb2/sokS1wLwRlz8scjiTs/NeB3JmnE3U+xTX/otr+X24 klL+wwTHkCveYme25fM2/ol5+MNCIysTLDg5oQIgQuBM8yEzJkh2mtC6qviIHrILa4VL 6ZRRsNowMLtEyyiyTlmGhAuE3fKiIvREvYGuxoMiMgEYymDDdQk9k30TrlaOqHTe7ujZ NvNf+JChUp6aWSePetqAE7hAriOzmDIGpMDxIblLooq3yba8Pgod/D/ufzKyQ6rISEAk LJhg== X-Gm-Message-State: AOJu0YzGOlnA0ZtR1Sxde0vRRGyW0ubzo/eumZtUd9UXwZ5GpP5hRxQk +bWZHHa2KTwGMn6yEcwDk9+Qb6dpOLNY6/1M4iLEkENRz96QaQAtRx2ddwZVW07wEX/vaKwkHZi H X-Google-Smtp-Source: AGHT+IFWpEzwKPPdl1mw7tvXvVp9ZxgCj5ozb/nm/DQDDqkJUfTfQKWsf4eXQoXnBllzoU9TwfBbVQ== X-Received: by 2002:a17:907:6d18:b0:a51:e2a9:97c with SMTP id sa24-20020a1709076d1800b00a51e2a9097cmr12237822ejc.6.1713258968006; Tue, 16 Apr 2024 02:16:08 -0700 (PDT) From: Fouad Hilly To: Xen-devel Cc: Fouad Hilly , Anthony PERARD , Juergen Gross , Andrew Cooper Subject: [PATCH v2 5/5] x86: Add --force option to xen-ucode to override microcode version check Date: Tue, 16 Apr 2024 10:15:46 +0100 Message-ID: <20240416091546.11622-6-fouad.hilly@cloud.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240416091546.11622-1-fouad.hilly@cloud.com> References: <20240416091546.11622-1-fouad.hilly@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1713258996178100001 Content-Type: text/plain; charset="utf-8" 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. [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 whe= n applicable. 6- --force option doesn't require an argument anymore. 7- Used optint to access filename in argv. Signed-off-by: Fouad Hilly Suggested-by: Andrew Cooper --- Suggested-by: Andrew Cooper --- tools/include/xenctrl.h | 3 ++- tools/libs/ctrl/xc_misc.c | 13 +++++++++++-- tools/misc/xen-ucode.c | 18 +++++++++++++----- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 2ef8b4e05422..49d2f19c0d77 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 5ecdfa2c7934..fbc17cefa82e 100644 --- a/tools/libs/ctrl/xc_misc.c +++ b/tools/libs/ctrl/xc_misc.c @@ -203,7 +203,8 @@ 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 {}; @@ -215,7 +216,15 @@ 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; + if ( flags > 0 ) + { + platform_op.cmd =3D XENPF_microcode_update2; + platform_op.u.microcode.flags =3D flags; + } + else + { + platform_op.cmd =3D XENPF_microcode_update; + } platform_op.u.microcode.length =3D len; set_xen_guest_handle(platform_op.u.microcode.data, uc); =20 diff --git a/tools/misc/xen-ucode.c b/tools/misc/xen-ucode.c index e3c1943e3633..4178fd2221ea 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"; @@ -24,7 +26,8 @@ static void usage(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 micorocde version check\= n", name, name); } =20 @@ -89,10 +92,12 @@ int main(int argc, char *argv[]) size_t len; struct stat st; int opt; + uint32_t ucode_flag =3D 0; =20 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} }; =20 @@ -104,10 +109,10 @@ int main(int argc, char *argv[]) exit(1); } =20 - if ( argc !=3D 2 ) + if ( argc < 2 || argc > 3) goto ext_err; =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) { @@ -117,12 +122,15 @@ int main(int argc, char *argv[]) case 's': show_curr_cpu(stdout); exit(EXIT_SUCCESS); + case 'f': + ucode_flag =3D XENPF_UCODE_FLAG_FORCE_SET; + break; default: goto ext_err; } } =20 - filename =3D argv[1]; + filename =3D argv[optind]; fd =3D open(filename, O_RDONLY); if ( fd < 0 ) { @@ -146,7 +154,7 @@ int main(int argc, char *argv[]) exit(1); } =20 - ret =3D xc_microcode_update(xch, buf, len); + ret =3D xc_microcode_update(xch, buf, len, ucode_flag); if ( ret ) { fprintf(stderr, "Failed to update microcode. (err: %s)\n", --=20 2.42.0