From nobody Mon Nov 3 18:39:06 2025 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1726231218; cv=none; d=zohomail.com; s=zohoarc; b=OAEik5e4KRF2/LWH/quOU1hV2RRprtK1ixZDVHFg3e1kzaPcZBse7RQNbWGN4EGZEYIZEO0LZmN0ZtTVGjdBsapYMHRd0OUz4w1QuehULSLOIQk2vAtSP4OuWb8tzsG8l5INshrK99bfwoie+Sx71x4FmPOxWSfrcWZEpe27COo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726231218; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3/ueT8uW8b4tBIRnCuXFQV/WnWZs2GVaHe/kpWB77Io=; b=gMIw385BGKbHo1jViC7GJbXEl0FvDVSiCXJtIf9QVW2+Liuavl+/+igQhMhqgE7UMRCiTFlUvKbNUIhPZ3MQMosRRMG2HqRjxPAgS7uss7k1Drf7PE3HnxEdEFhXynyO8wR97AgltqRs1HBC3vQJL9DkKofXHj8+DaaUbSeNBYo= 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 1726231217879477.8383629848056; Fri, 13 Sep 2024 05:40:17 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.798167.1208283 (Exim 4.92) (envelope-from ) id 1sp5aj-0008UP-Ge; Fri, 13 Sep 2024 12:40:01 +0000 Received: by outflank-mailman (output) from mailman id 798167.1208283; Fri, 13 Sep 2024 12:40:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sp5aj-0008UI-E8; Fri, 13 Sep 2024 12:40:01 +0000 Received: by outflank-mailman (input) for mailman id 798167; Fri, 13 Sep 2024 12:40:00 +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 1sp5ai-0008U8-5N for xen-devel@lists.xenproject.org; Fri, 13 Sep 2024 12:40:00 +0000 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [2a00:1450:4864:20::62b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 49b6cddd-71cd-11ef-a0b5-8be0dac302b0; Fri, 13 Sep 2024 14:39:59 +0200 (CEST) Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-a9018103214so286595166b.3 for ; Fri, 13 Sep 2024 05:39:59 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25953275sm867616966b.70.2024.09.13.05.39.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 05:39:57 -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: 49b6cddd-71cd-11ef-a0b5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1726231198; x=1726835998; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3/ueT8uW8b4tBIRnCuXFQV/WnWZs2GVaHe/kpWB77Io=; b=Okuf2beITFpaawzyaqwaHAhCD3uck2JGwsxdvnOHzAotCtuvdlqWXPg6ZIxo0HR9/p UVT7PEfEUiO2qdeWczvbygiLsf45VuupGDziQhDddWGfM33epylAOZ179oMjL4dp0Z9j btK36wIIpmxdru1VkOx+QVqoEmFpb/iA7iPHA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726231198; x=1726835998; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3/ueT8uW8b4tBIRnCuXFQV/WnWZs2GVaHe/kpWB77Io=; b=WjuQjrg7cDeRoK+FFHgmRw+vAm7gOe4UwXW3luNwWucegA6JsAvdsJ4QZ8ZEDefK+9 K3j3GoaFc8S/noflYUf2nwIF+6ZO0V+au8fyaJe/TIL5hVtWlseqND9eS36ehQ8r484J +1yZA8IzcuAPdKancWsV0JDXJopUyIn3E/MEb/EiKWdLenPzqtnl8ZxVZCnhokmO4uLS nnMYo/mK+X/7bKSQ6U7wT7jFRBUxEwIdn4v7AOjj4VfYNotoTwP7grQT3qj0hr2ikZEE b8ffXVnCvPOMYWrl54BKgnPdevcB8TEMBKioY7xae3zXuETgPHUYANBqD3ZGanNGE0tk Sxjw== X-Gm-Message-State: AOJu0Yxnx5QIAUb6Rl+W45K+ouMpxSsDSSbCHNLN3fVSGOk+v7VNMJaN yRp2d5j3IdIz1uCFSlIszhzaX6ohAVKY322uzzF8MV8N+HqiNhGARBazwdq09rJw8vxmVkEGLfN q X-Google-Smtp-Source: AGHT+IG7itZmeivfoVyIcenFYmFvTw3w4sL/abmRb1dmPISH9XJgUQeU7wjukim5YCNg9KxqfzPISQ== X-Received: by 2002:a17:907:f752:b0:a86:a481:248c with SMTP id a640c23a62f3a-a90294465abmr529481366b.19.1726231197603; Fri, 13 Sep 2024 05:39:57 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH] xen/ucode: Improve commentary for parsing AMD containers Date: Fri, 13 Sep 2024 13:39:54 +0100 Message-Id: <20240913123954.1907305-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1726231219173116600 Despite writing this code, it's not the easiest logic to follow. Shorten the UCODE_EQUIV_TYPE name, and provide more of an explanation of what's going on. No functional change. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 --- xen/arch/x86/cpu/microcode/amd.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/= amd.c index 32490c8b7d2a..35bcec643c04 100644 --- a/xen/arch/x86/cpu/microcode/amd.c +++ b/xen/arch/x86/cpu/microcode/amd.c @@ -52,11 +52,11 @@ struct microcode_patch { }; =20 #define UCODE_MAGIC 0x00414d44 -#define UCODE_EQUIV_CPU_TABLE_TYPE 0x00000000 +#define UCODE_EQUIV_TYPE 0x00000000 #define UCODE_UCODE_TYPE 0x00000001 =20 struct container_equiv_table { - uint32_t type; /* UCODE_EQUIV_CPU_TABLE_TYPE */ + uint32_t type; /* UCODE_EQUIV_TYPE */ uint32_t len; struct equiv_cpu_entry eq[]; }; @@ -335,10 +335,10 @@ static struct microcode_patch *cf_check cpu_request_m= icrocode( buf +=3D 4; size -=3D 4; =20 - if ( size < sizeof(*et) || - (et =3D buf)->type !=3D UCODE_EQUIV_CPU_TABLE_TYPE || - size - sizeof(*et) < et->len || - et->len % sizeof(et->eq[0]) ) + if ( size < sizeof(*et) || /* Insufficient space= for header? */ + (et =3D buf)->type !=3D UCODE_EQUIV_TYPE || /* Not an Equival= ence Table? */ + size - sizeof(*et) < et->len || /* Insufficient space= for table? */ + et->len % sizeof(et->eq[0]) ) /* Not a multiple of = equiv_cpu_entry? */ { printk(XENLOG_ERR "microcode: Bad equivalent cpu table\n"); error =3D -EINVAL; @@ -351,7 +351,12 @@ static struct microcode_patch *cf_check cpu_request_mi= crocode( =20 error =3D scan_equiv_cpu_table(et); =20 - /* -ESRCH means no applicable microcode in this container. */ + /* + * -ESRCH means no applicable microcode in this container. But, t= here + * might be subsequent containers in the blob. Skipping to the en= d of + * this container still requires us to follow the UCODE_UCODE_TYPE= /len + * metadata because there's no overall container length given. + */ if ( error && error !=3D -ESRCH ) break; skip_ucode =3D error; @@ -361,10 +366,10 @@ static struct microcode_patch *cf_check cpu_request_m= icrocode( { const struct container_microcode *mc; =20 - if ( size < sizeof(*mc) || - (mc =3D buf)->type !=3D UCODE_UCODE_TYPE || - size - sizeof(*mc) < mc->len || - mc->len < sizeof(struct microcode_patch) ) + if ( size < sizeof(*mc) || /* Insufficien= t space for container header? */ + (mc =3D buf)->type !=3D UCODE_UCODE_TYPE || /* Not an = ucode blob? */ + size - sizeof(*mc) < mc->len || /* Insufficien= t space for blob? */ + mc->len < sizeof(struct microcode_patch) ) /* Insufficien= t space for patch header? */ { printk(XENLOG_ERR "microcode: Bad microcode data\n"); error =3D -EINVAL; --=20 2.39.2