From nobody Sat Nov 23 04:18:59 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