From nobody Thu Nov 21 20:23:04 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1730107180; cv=none; d=zohomail.com; s=zohoarc; b=Vjffk6aFawR5NyYHhJ3PuXRspjYtCeaJqlwEIJ9rmHkXaZqQGK06SGaHlUzb23cXCh3DK1g5OrLJOoEyGJYpC21KAMiFmc46XtsVuncS0YpWYJTLhg7V05HHGGdXk34z9rIViHG4QpJDkXcdFdmz9x1L+SSl965X2TlFKLC+/Ik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730107180; h=Content-Type: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=uNoXSVIzcbAquQH53qcOLIpudAiENFsvnljoElW6cME=; b=lNxpQB6fEMjUQTkeh50RRbBHMtFddKk14mye/hjPdxugdIQSvkp4w2gwEfpdM+VWNgzKgb8nizvdHF94A5Q5y9UeqQ6Jwh/GAkt7O+hJeM4RTv34bi3PryiFrcq8k/QN+/toCnRBbhp30VvSe8sab/h+7nwvF4DE4NJu7O3aL+A= 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 1730107180722589.7851697502964; Mon, 28 Oct 2024 02:19:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.826294.1240492 (Exim 4.92) (envelope-from ) id 1t5Ltz-0005QH-KD; Mon, 28 Oct 2024 09:19:07 +0000 Received: by outflank-mailman (output) from mailman id 826294.1240492; Mon, 28 Oct 2024 09:19: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 1t5Ltz-0005Pq-DW; Mon, 28 Oct 2024 09:19:07 +0000 Received: by outflank-mailman (input) for mailman id 826294; Mon, 28 Oct 2024 09:19:05 +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 1t5Ltx-0005MP-Ug for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 09:19:05 +0000 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [2a00:1450:4864:20::536]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id acfaf3cf-950d-11ef-a0c2-8be0dac302b0; Mon, 28 Oct 2024 10:19:04 +0100 (CET) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-5cb74434bc5so5277093a12.0 for ; Mon, 28 Oct 2024 02:19:04 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f05deb6sm355961566b.88.2024.10.28.02.19.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 02:19:02 -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: acfaf3cf-950d-11ef-a0c2-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1730107143; x=1730711943; 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=uNoXSVIzcbAquQH53qcOLIpudAiENFsvnljoElW6cME=; b=Ps+3zxOmsahkjibcjo7VWSd44EXXMC7M0x3s7qJM0shro+17nD0R/2brVocurhe7o8 KrmbrHBKRR0wbjwtegl7+jB758D4rWIjG9ZoEx42cDaxEoaWGn6f7fbwoftM2/oiLF8c QgjCWjeYgTpfDmeXV3iWcOTKVRi5ZO04wdTI4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730107143; x=1730711943; 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=uNoXSVIzcbAquQH53qcOLIpudAiENFsvnljoElW6cME=; b=AmTENU3JS7FL1HJzq63Y+C5Hr4ItNYyaW305qH44A9el2qfq77FImBHkYboCuSjshW oRWK75mHR/A4NVg2Tm3+SSfw6Ci6eorDEKnZwZU6GRpj7XaHlH+VuyP4xfjvRavzD04d xNI5qOD3GyO688zQ+VLmEVSy+6pZcGln+LMk2VcfIo+K12e9ri2C2LukIrU1gil7C7u4 Z+B85BMacwBH4vWqli2sycWMo2rac7FReN83xn/cdCgpJ7Q+S9HXoggf24BQcx9+kiIZ Y0fpm0WvCG+Te6xfmFZ5deoxwMCvZCs9hxb98fGKW8ccpzFoRNbREoPurrzpVdj5wGmR 7qMA== X-Gm-Message-State: AOJu0YzpijumNCkiCi0UcjFTTT9SHMMa9GDetPaeGRM+MIlALqDNPG8V FYT8o7jhfegDDuxTn/NWkRGk8wh5UU3VjiH4eomjDzQ22pMcIf3gEFxyOXWRofuNxfkPUV5fjY2 9 X-Google-Smtp-Source: AGHT+IEzCQkQNqwke7Zikn3jgL4+v0prf1RFWQGjUMZAes/8amX7zz05t3Zw99Z0317ykL3aPf5Ewg== X-Received: by 2002:a17:907:7e8e:b0:a9a:4aa3:728b with SMTP id a640c23a62f3a-a9de61eaa03mr611502666b.53.1730107143103; Mon, 28 Oct 2024 02:19:03 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , "Daniel P . Smith" Subject: [PATCH 01/10] x86/ucode: Turn microcode_init_cache() into a presmp_initcall Date: Mon, 28 Oct 2024 09:18:47 +0000 Message-Id: <20241028091856.2151603-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241028091856.2151603-1-andrew.cooper3@citrix.com> References: <20241028091856.2151603-1-andrew.cooper3@citrix.com> 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: 1730107181298116600 There's no need for microcode_init_cache() to be called exactly where it is= in __start_xen(). All that matters is it must be after xmalloc() is available and before APs start up. As a consequence, microcode_init_cache() runs a little later on boot now. No functional change. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich Reviewed-by: Daniel P. Smith --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Daniel P. Smith --- xen/arch/x86/cpu/microcode/core.c | 4 +++- xen/arch/x86/include/asm/microcode.h | 1 - xen/arch/x86/setup.c | 2 -- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index 8d916d891e6e..9a2cc631d2aa 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -819,8 +819,9 @@ static int __init early_update_cache(const void *data, = size_t len) return rc; } =20 -int __init microcode_init_cache(struct boot_info *bi) +static int __init cf_check microcode_init_cache(void) { + struct boot_info *bi =3D &xen_boot_info; int rc =3D 0; =20 if ( !ucode_ops.apply_microcode ) @@ -838,6 +839,7 @@ int __init microcode_init_cache(struct boot_info *bi) =20 return rc; } +presmp_initcall(microcode_init_cache); =20 /* BSP calls this function to parse ucode blob and then apply an update. */ static int __init early_microcode_update_cpu(void) diff --git a/xen/arch/x86/include/asm/microcode.h b/xen/arch/x86/include/as= m/microcode.h index a278773f8b5d..c62c131fd047 100644 --- a/xen/arch/x86/include/asm/microcode.h +++ b/xen/arch/x86/include/asm/microcode.h @@ -28,6 +28,5 @@ int microcode_update_one(void); =20 struct boot_info; int early_microcode_init(struct boot_info *bi); -int microcode_init_cache(struct boot_info *bi); =20 #endif /* ASM_X86__MICROCODE_H */ diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 177f4024abca..5db57e1b1af2 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1952,8 +1952,6 @@ void asmlinkage __init noreturn __start_xen(void) =20 timer_init(); =20 - microcode_init_cache(bi); /* Needs xmalloc() */ - tsx_init(); /* Needs microcode. May change HLE/RTM feature bits. */ =20 calculate_raw_cpu_policy(); /* Needs microcode. No other dependenices= . */ --=20 2.39.5 From nobody Thu Nov 21 20:23:04 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1730107181; cv=none; d=zohomail.com; s=zohoarc; b=ZKlwjYQGe6DuiV0dStCdf8f4hS2Eo5MPSdOvVFaXqmLARDQ/tigqMaZhwxoP54SJdLYGyaSiijmHCCf3WVnL8qtCwph9pFmwx069v68j2o8LHjdfjvNA5L41x/a8VHTHb2Z36jtJWTxR2+9wEXtFBp1J1ElLPUYSeYzOQht1hQI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730107181; h=Content-Type: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=HdgomcGm+tyb6osYP5OAYq6042ngUQkHmwMCkva53Ic=; b=UkJaQV87cd7JSCq0V2KgIuHeJ8F5vtkZDR41cVIICxtPPYtaDN1CW/PIwWFNjQxtmI5zMdSvbcmvtLbk1/dkRarNYv/h+1mSZ6jOGpxBpeF5JayLZIR28T5vTI3PcEqedrweQKMrervc2/AvLk7ixI+bwSybQgC/RamDVVUbNs0= 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 173010718171156.611379061965295; Mon, 28 Oct 2024 02:19:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.826297.1240520 (Exim 4.92) (envelope-from ) id 1t5Lu3-00067K-AX; Mon, 28 Oct 2024 09:19:11 +0000 Received: by outflank-mailman (output) from mailman id 826297.1240520; Mon, 28 Oct 2024 09:19: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 1t5Lu3-00065x-2j; Mon, 28 Oct 2024 09:19:11 +0000 Received: by outflank-mailman (input) for mailman id 826297; Mon, 28 Oct 2024 09:19: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 1t5Lu2-0005yk-Av for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 09:19:10 +0000 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [2a00:1450:4864:20::62f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id af10cdb9-950d-11ef-99a3-01e77a169b0f; Mon, 28 Oct 2024 10:19:07 +0100 (CET) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a998a5ca499so548901766b.0 for ; Mon, 28 Oct 2024 02:19:07 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f05deb6sm355961566b.88.2024.10.28.02.19.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 02:19: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: af10cdb9-950d-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1730107146; x=1730711946; 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=HdgomcGm+tyb6osYP5OAYq6042ngUQkHmwMCkva53Ic=; b=uM0UKGSicrKqUQteRrshehA9iIykD30CUQDZD71/o5bCmMpacEwDhlDIoYAoMk3QGc 0lo/JSJywQawBVFtlWr7BnZ9BVVAI7NGtvJyzeCZuOwq/jZPHvbU60TkQ483qi9+q71V xDJvrdu2Rs3zcJH8u6n/R6RQslxYAkg9jbl0E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730107146; x=1730711946; 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=HdgomcGm+tyb6osYP5OAYq6042ngUQkHmwMCkva53Ic=; b=TE2Sh5cnySsCfKXNONxHSduClWC/phm5Dwwsbf+MkauYtSxkBnG/ur1s4mAUO3nCsY IvY52G+7GC7HZ4JCZcR7JuOcpPNxKLOsHjEye6eCFQtarsBDrdkuq5sq/7TBbsa0vtjX VqgsVFSuDzbxrqs+HEIB2yowGi9dSHa5LtO9tBIXntvTVIWTUf+mGt+hZGBpjoPRYUFm rwTu8w0wj+JmVbsZpfLoUc+0LBHS0DzownFgQK+VQW07DfPiWIFkVVTyZVmrlKn6kFgy laOPmntuBnKQz0R9NugKywFGaC0oxRhz7pjI/i2lOvftwmgk1b0JZYCo4PBTw7Ko6C/1 ylPw== X-Gm-Message-State: AOJu0Yx1iVBE7pGkq4mv4y+c758q9JqgRQTmQv95bto8FApSb82PlyiD 97z5FCo3Pc/ClcPO3/gB3Z73ERiXwIBq3cNzQdcmpKWGzaoYJL6uyx0QjR5I4JZmLCoAOyl2xx2 C X-Google-Smtp-Source: AGHT+IHWATzgfaBR+v7s6x26PjQ/1kwTDosqOTlvX4xnR0qEOkNvvuLiP6BdqUAHfeuQZcsSkG6MLA== X-Received: by 2002:a17:907:94c1:b0:a99:4ca4:4ff4 with SMTP id a640c23a62f3a-a9de5d98002mr545033266b.23.1730107144591; Mon, 28 Oct 2024 02:19:04 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , "Daniel P . Smith" Subject: [PATCH 02/10] x86/ucode: Delete the microcode_init() initcall Date: Mon, 28 Oct 2024 09:18:48 +0000 Message-Id: <20241028091856.2151603-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241028091856.2151603-1-andrew.cooper3@citrix.com> References: <20241028091856.2151603-1-andrew.cooper3@citrix.com> 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: 1730107183341116600 The comment highlights just how bogus this really is. Being an initcall, t= he boot allocator is long gone, and bootstrap_unmap() is a no-op. The fact there is nothing to do should be a giant red flag about the validi= ty of the mappings "being freed". Indeed, they both constitute use-after-free= s. We could move the size/data/end clobbering into microcode_init_cache() which is the final consumer of the information, but we're intending to delete the= se static variables entirely, and it's less churn to just leave them dangling = for a few patches. No functional change. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich Reviewed-by: Daniel P. Smith --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Daniel P. Smith After the $N'th rearranging, this could actually be merged into "x86/ucode: Drop ucode_mod and ucode_blob" with no effect on the intermediate patches. --- xen/arch/x86/cpu/microcode/core.c | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index 9a2cc631d2aa..3e815f1880af 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -758,28 +758,6 @@ int microcode_update(XEN_GUEST_HANDLE(const_void) buf, return continue_hypercall_on_cpu(0, microcode_update_helper, buffer); } =20 -static int __init cf_check microcode_init(void) -{ - /* - * At this point, all CPUs should have updated their microcode - * via the early_microcode_* paths so free the microcode blob. - */ - if ( ucode_blob.size ) - { - bootstrap_unmap(); - ucode_blob.size =3D 0; - ucode_blob.data =3D NULL; - } - else if ( ucode_mod.mod_end ) - { - bootstrap_unmap(); - ucode_mod.mod_end =3D 0; - } - - return 0; -} -__initcall(microcode_init); - /* Load a cached update to current cpu */ int microcode_update_one(void) { --=20 2.39.5 From nobody Thu Nov 21 20:23:04 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1730107173; cv=none; d=zohomail.com; s=zohoarc; b=ld5EzKJ70YXYTVleYPUSeQ0a5g95thSPY5YCpX4afjBxqZfysmiMSrLoMTJEFVZ3I8+yE31xaMuHB9Voz0HAM9BFnJEP1q3EMB/eOHeLChfUGnNi2izPb+8S1y9U+rDfmXKMBQtOrLtQAGvVUv7/T80TBa1bkK1m8FhNEH4eZvM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730107173; h=Content-Type: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=4MqNUkwecighwf5ZEZecpwf+J1DakAlBwf9uooe4i8Q=; b=Rnl66iiP7pySErpaw18Ley6AUpBXCPolzQ2ZJfvhtncsM8aUmHgcBQpzQROjL1+Eil30MTQIJI20xRpoJALKjzo6SPICAoXhespSg9onXtGSYTfBrXjVuzA+RZiaLM+NOm5XnM3b909wXuFYRY5HWEt+KuSByIIbxPf43Xc2Jpg= 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 1730107173934443.4778170598154; Mon, 28 Oct 2024 02:19:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.826295.1240505 (Exim 4.92) (envelope-from ) id 1t5Lu0-0005pB-NQ; Mon, 28 Oct 2024 09:19:08 +0000 Received: by outflank-mailman (output) from mailman id 826295.1240505; Mon, 28 Oct 2024 09:19: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 1t5Lu0-0005p4-Kh; Mon, 28 Oct 2024 09:19:08 +0000 Received: by outflank-mailman (input) for mailman id 826295; Mon, 28 Oct 2024 09:19: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 1t5Ltz-0005MP-9c for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 09:19:07 +0000 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [2a00:1450:4864:20::534]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ae750aa8-950d-11ef-a0c2-8be0dac302b0; Mon, 28 Oct 2024 10:19:06 +0100 (CET) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-5c95a962c2bso5078113a12.2 for ; Mon, 28 Oct 2024 02:19:06 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f05deb6sm355961566b.88.2024.10.28.02.19.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 02:19:04 -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: ae750aa8-950d-11ef-a0c2-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1730107145; x=1730711945; 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=4MqNUkwecighwf5ZEZecpwf+J1DakAlBwf9uooe4i8Q=; b=R+0EG1Iz2Bv+mCOOj/zP225x2HUDJb5XSfacmOG70pXO56IT6FV/cLqucT1oHqMrmc +edG3SknidfsK5xi0DQB6K5y/btBgXFqUtjIMXzfssadWruNLyZKqfQEw/Kv5WOWLxs0 9KEW9moedmof1C0vwJS6HZMxdZF3VyPNXliuA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730107145; x=1730711945; 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=4MqNUkwecighwf5ZEZecpwf+J1DakAlBwf9uooe4i8Q=; b=VyFK/oJ0mGnTDy7BKryy3WOFyvUMIYWcz6LfL5VPp0M5tWHysSSonhLlsFuchXEZ7M 0Pq1fC5kvFtWzqyb1j/+Kl9GBkEgJqSoIkf5pJx9RWFNBeC1rPqInSbpJ5B7gFmNiaY4 rVS2AdTMhfuVtPhPBULTMOqZHv68z4FVI2NRCJgBl5KScrxnBIDrth0sWdwPOZkqVV9/ I5FfRosTYsWg569wvPlU/pIVYIDOC0NJ3PYmIQ5dR+1BkMKG3YI6XZ72zj4gBjPLYmn3 SupSJM69CKz6EZOkiED2/m31F1WOci7UW9Xo8HmbaZfL1xSAEU/2jTlSuEwkCUd2Ljjw OMig== X-Gm-Message-State: AOJu0YzkCz8EEkkpuLHArwJbKK8QKrQpORitkJWmCghLQs4v4ljpcqmP F0aqFH6kEoHuBnQC1auKdBba0OGEoFqX3NpFRAPbR1tp6DaWtd1GFWAmzsZgiJ5UbpimNhLTb6h M X-Google-Smtp-Source: AGHT+IH5tcFhm3dopPSqg6B3iTWtDz1h4rBWC3w9u+K5IL4SIE7v2kpqaJ0KZfV49ENmGsyWmEA79Q== X-Received: by 2002:a17:907:e87:b0:a99:5cd5:5b9c with SMTP id a640c23a62f3a-a9de5ee1155mr665254766b.36.1730107145339; Mon, 28 Oct 2024 02:19:05 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , "Daniel P . Smith" Subject: [PATCH 03/10] x86/ucode: Break early_microcode_load() out of early_microcode_init() Date: Mon, 28 Oct 2024 09:18:49 +0000 Message-Id: <20241028091856.2151603-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241028091856.2151603-1-andrew.cooper3@citrix.com> References: <20241028091856.2151603-1-andrew.cooper3@citrix.com> 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: 1730107175564116600 microcode_grab_module() and early_microcode_update_cpu() are logically one task that passes state via static variables. We intend to delete said static variables, so start by moving these functio= ns out of early_microcode_init(). No functional change. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich Reviewed-by: Daniel P. Smith --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Daniel P. Smith --- xen/arch/x86/cpu/microcode/core.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index 3e815f1880af..d13f8338e4e6 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -854,6 +854,22 @@ static int __init early_microcode_update_cpu(void) return microcode_update_cpu(patch, 0); } =20 +/* + * There are several tasks: + * - Locate the ucode blob in the boot modules. + * - Parse and attempt in-place load. + * - Inform microcode_init_cache() of how to find the blob again. + */ +static int __init early_microcode_load(struct boot_info *bi) +{ + microcode_grab_module(bi); + + if ( !ucode_mod.mod_end && !ucode_blob.size ) + return 0; + + return early_microcode_update_cpu(); +} + int __init early_microcode_init(struct boot_info *bi) { const struct cpuinfo_x86 *c =3D &boot_cpu_data; @@ -897,10 +913,7 @@ int __init early_microcode_init(struct boot_info *bi) return -ENODEV; } =20 - microcode_grab_module(bi); - - if ( ucode_mod.mod_end || ucode_blob.size ) - rc =3D early_microcode_update_cpu(); + rc =3D early_microcode_load(bi); =20 /* * Some CPUID leaves and MSRs are only present after microcode updates --=20 2.39.5 From nobody Thu Nov 21 20:23:04 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1730107180; cv=none; d=zohomail.com; s=zohoarc; b=SJk7Hd+426FMW4lcnKsCK/UftqDFaZMyK+bc9jAVTBWdyOZulpnC62F1MSZK4Wg9K9sYAvGq8TcKljZcjAuLv0k3vzzUfHb9JY/0fZBJXEG9C4iQdjuMsTQSfoxCG6ImG4eEg0Kw74NJ41crlVVsZyAv3XlyeGlWIwgBkcKy89A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730107180; h=Content-Type: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=r1bM8SCLj6R5IbsmBphTqHMm0oBQSGTeHlM7ro4wldk=; b=M8ZMsdYA+CVrp3sfWUVY5tJLtbSsccnFjLkgqMoreOGLkyFp+sNoL25hz0IpSxpN0PpGRu6zapFP00Tr1kTwHDCGccd/JmYGVZlfXTSRmnwGR2DJBYSVGk2nwUKrCLTbOyiahlHLl0YpKFzzPxXscptzsUZfxQ0bB4iq7yNudkg= 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 1730107180712104.3371658762228; Mon, 28 Oct 2024 02:19:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.826296.1240515 (Exim 4.92) (envelope-from ) id 1t5Lu2-00064k-W5; Mon, 28 Oct 2024 09:19:10 +0000 Received: by outflank-mailman (output) from mailman id 826296.1240515; Mon, 28 Oct 2024 09:19: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 1t5Lu2-00064a-SM; Mon, 28 Oct 2024 09:19:10 +0000 Received: by outflank-mailman (input) for mailman id 826296; Mon, 28 Oct 2024 09:19: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 1t5Lu2-0005yk-42 for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 09:19:10 +0000 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [2a00:1450:4864:20::62f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id aec66eb1-950d-11ef-99a3-01e77a169b0f; Mon, 28 Oct 2024 10:19:07 +0100 (CET) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a9a2cdc6f0cso551005066b.2 for ; Mon, 28 Oct 2024 02:19:07 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f05deb6sm355961566b.88.2024.10.28.02.19.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 02:19: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: aec66eb1-950d-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1730107146; x=1730711946; 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=r1bM8SCLj6R5IbsmBphTqHMm0oBQSGTeHlM7ro4wldk=; b=tGPDIzdtk9cV/uYse4W/2FzJp6OoFGsTV/e3+F4pwX1mfo8ky9WSoMp7C64U8nGkgJ oRGYlQCskAASLUsCfFysWBeGvI7g2E3IIKmgU+LFF5MR2IcrYHFWp7gyrOXTPOJjX/Dz p1VqQmxnIcTL6gljCWOBp0f8h51QmMVFBYsXU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730107146; x=1730711946; 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=r1bM8SCLj6R5IbsmBphTqHMm0oBQSGTeHlM7ro4wldk=; b=gY5EdRzZsLsNybpBmYVYcTJ+KkqhGO5OQNpd+M278u6dmGm2ZS7/UEIz21m1ibu+NQ VwGWaTwoboqMMsg9Zghz9/HmwUqO8B1260CoKHkdrks4KINGJ+WFI2gMp53JsK1NpdTo lk9oqyYOdjUP2Jy0qSdYt824REIMeLYln5+AGhxDzsaf9xhvbkOUexnsWhYUGRcK5cJ9 0Qjixl+VPve1iYMpyF8c98Bd9dagQCFKkWEPekJqqV/T52aJ4siT4c3kc2rpqAhrj9dr fxRqubU5+B8NgaFLMNbQVjIZbEr4qaBbkmEHMQl+pQU4VJuOjI4zdhC8qANVZIZek8J4 PpXg== X-Gm-Message-State: AOJu0YzAMFzNDoZcPJanZfjhoWvlrPrXcKqx1LK8eIp+a9chD+mY+aNU mmZffjuMLlHWzi+4icAin45Nf9sVqSwpKM3XRbadAmOchmzXDty5NBsvZryI8uZ3z0Fg0aT0Nm8 Y X-Google-Smtp-Source: AGHT+IEP9KlEgbT5966fOb8YxiB5q7SRSyRaOvW6vHnzGKGD9sG85PdUM8qsnLLjc6FJETP54fbglw== X-Received: by 2002:a17:907:1c24:b0:a9a:7f84:940b with SMTP id a640c23a62f3a-a9de5c91b71mr577280266b.10.1730107146079; Mon, 28 Oct 2024 02:19:06 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , "Daniel P . Smith" Subject: [PATCH 04/10] x86/ucode: Fold early_microcode_update_cpu() into it's single caller Date: Mon, 28 Oct 2024 09:18:50 +0000 Message-Id: <20241028091856.2151603-5-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241028091856.2151603-1-andrew.cooper3@citrix.com> References: <20241028091856.2151603-1-andrew.cooper3@citrix.com> 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: 1730107181340116600 Diff-wise, as early_microcode_update_cpu() is the larger function, this more closely resembles "merge early_microcode_load() into it's single callee", b= ut the end result is the same. At the same time, rename the len variable to size. This is for better consistency with existing logic, and to reduce churn later. No functional change. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich Reviewed-by: Daniel P. Smith --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Daniel P. Smith --- xen/arch/x86/cpu/microcode/core.c | 38 +++++++++++++------------------ 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index d13f8338e4e6..0b00e70f3b07 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -819,28 +819,38 @@ static int __init cf_check microcode_init_cache(void) } presmp_initcall(microcode_init_cache); =20 -/* BSP calls this function to parse ucode blob and then apply an update. */ -static int __init early_microcode_update_cpu(void) +/* + * There are several tasks: + * - Locate the ucode blob in the boot modules. + * - Parse and attempt in-place load. + * - Inform microcode_init_cache() of how to find the blob again. + */ +static int __init early_microcode_load(struct boot_info *bi) { const void *data =3D NULL; - size_t len; + size_t size; struct microcode_patch *patch; =20 + microcode_grab_module(bi); + + if ( !ucode_mod.mod_end && !ucode_blob.size ) + return 0; + if ( ucode_blob.size ) { - len =3D ucode_blob.size; + size =3D ucode_blob.size; data =3D ucode_blob.data; } else if ( ucode_mod.mod_end ) { - len =3D ucode_mod.mod_end; + size =3D ucode_mod.mod_end; data =3D bootstrap_map(&ucode_mod); } =20 if ( !data ) return -ENOMEM; =20 - patch =3D ucode_ops.cpu_request_microcode(data, len, false); + patch =3D ucode_ops.cpu_request_microcode(data, size, false); if ( IS_ERR(patch) ) { printk(XENLOG_WARNING "Parsing microcode blob error %ld\n", @@ -854,22 +864,6 @@ static int __init early_microcode_update_cpu(void) return microcode_update_cpu(patch, 0); } =20 -/* - * There are several tasks: - * - Locate the ucode blob in the boot modules. - * - Parse and attempt in-place load. - * - Inform microcode_init_cache() of how to find the blob again. - */ -static int __init early_microcode_load(struct boot_info *bi) -{ - microcode_grab_module(bi); - - if ( !ucode_mod.mod_end && !ucode_blob.size ) - return 0; - - return early_microcode_update_cpu(); -} - int __init early_microcode_init(struct boot_info *bi) { const struct cpuinfo_x86 *c =3D &boot_cpu_data; --=20 2.39.5 From nobody Thu Nov 21 20:23:04 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1730107173; cv=none; d=zohomail.com; s=zohoarc; b=ebCN6od5MSkeOIqziYgE1oLMJ1vpx8PnxLNLXxLoXpIlGhF72DloL7UQCfn2EzMOPMNhTgANBj9oASZBO3bDFPT9+6Ov8CK8RUbMh9hlBhZd87+lglyDJf+TVwLOTfxXZtRfjtMJR8kDvS/VlgKIdq1eR7y3EQRfROFgmweUCLw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730107173; h=Content-Type: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=oICYqe4yhMzxG8joOnpcuB9tYuO3zHV62gOFfMxJa7M=; b=fs9udR2IC6UoYIvxfWTQPAIWXREt+qojAcnU54EoOortm7entSbeCT5cFoUIroWZnKvOA76IjQucGG5tmGQLQSCS6fhvKZA1D08IAw7g39BEWgfsDz75UOXEYBdSFpFUXCsy24uHQzIBCXjKzBEvrs1cTBxXd1IO9rsKOAw7Smo= 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 1730107173053280.17051829698175; Mon, 28 Oct 2024 02:19:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.826298.1240534 (Exim 4.92) (envelope-from ) id 1t5Lu4-0006XR-GK; Mon, 28 Oct 2024 09:19:12 +0000 Received: by outflank-mailman (output) from mailman id 826298.1240534; Mon, 28 Oct 2024 09:19:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5Lu4-0006Wc-DB; Mon, 28 Oct 2024 09:19:12 +0000 Received: by outflank-mailman (input) for mailman id 826298; Mon, 28 Oct 2024 09:19:11 +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 1t5Lu3-0005yk-94 for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 09:19:11 +0000 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [2a00:1450:4864:20::62d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id afe37ec1-950d-11ef-99a3-01e77a169b0f; Mon, 28 Oct 2024 10:19:09 +0100 (CET) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-a9a850270e2so677426566b.0 for ; Mon, 28 Oct 2024 02:19:09 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f05deb6sm355961566b.88.2024.10.28.02.19.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 02:19:06 -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: afe37ec1-950d-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1730107148; x=1730711948; 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=oICYqe4yhMzxG8joOnpcuB9tYuO3zHV62gOFfMxJa7M=; b=W3KafJDx2IkapzBEPdM/Kv/m6YdPTmMCwrJJrd5jp/65m5rtoyCK5qXgstTZdj+2Es FhGUJCFvzFHC5zPb13U5VfM8x5yn0wXQ5d4xSzhNZeTlGNlc+c0sitTidZ2jEUfqptuZ GTEowN+QGdF0w5nnQITXk7yv12ymuPV6bAabc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730107148; x=1730711948; 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=oICYqe4yhMzxG8joOnpcuB9tYuO3zHV62gOFfMxJa7M=; b=cJnp22mqe0X/ECd6QCx5/caPAkC1npv7PSNMSUULbD9kqI+nmLZBvm7KNFEcehDO7Q NQ7iuJ02H61DD5qq6JiIb0Y0/Eyej3cfGbCPnpKDoRNJhMZZie9g/GVSxe1/Dxcijfdk ElSqoMRHlW5707HT8IxPb7KEFzWIuecIsFq7tUL772asuLKORN3kB9LLe95pF1TMzmEB W0hOz+U5tH0yoGBFoJ3OJeN11yua0ex9jKpX8IH8QMYsBsMzPczL5PEuJ8+lVy1GfEgf dAVIh0K8OmFsrefEBaDZF8IKm8M+L9hUk3ZrCO8yHrLmoxT26VAy8lLZK0OUv8mLkB22 V1DQ== X-Gm-Message-State: AOJu0YyfQG6yZMIoQMtJ4uS0oxxkizbsPqaoM/Kpk6338MH5vSJkU4OA aNCfaml6JFGY95TI8FMkQBua/kUskBF4NSvrIUYlur9AFjozwpXM+itPr4G+8yStpY12OiDfRk6 h X-Google-Smtp-Source: AGHT+IFPmRBctsKkbYZfwJ/wA3cEUyI1GBO58kJ5TMNvnj+8riKv+CKvmi65G6mLHSuZnD3+BsL2RA== X-Received: by 2002:a17:907:a07:b0:a99:4ebc:82d4 with SMTP id a640c23a62f3a-a9de6192c15mr813457466b.55.1730107148172; Mon, 28 Oct 2024 02:19:08 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , "Daniel P . Smith" Subject: [PATCH 05/10] x86/ucode: Fold microcode_grab_module() into its single caller Date: Mon, 28 Oct 2024 09:18:51 +0000 Message-Id: <20241028091856.2151603-6-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241028091856.2151603-1-andrew.cooper3@citrix.com> References: <20241028091856.2151603-1-andrew.cooper3@citrix.com> 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: 1730107175351116600 No functional change. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich Reviewed-by: Daniel P. Smith --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Daniel P. Smith --- xen/arch/x86/cpu/microcode/core.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index 0b00e70f3b07..4c4003bf9687 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -205,19 +205,6 @@ static void __init microcode_scan_module(struct boot_i= nfo *bi) } } =20 -static void __init microcode_grab_module(struct boot_info *bi) -{ - if ( ucode_mod_idx < 0 ) - ucode_mod_idx +=3D bi->nr_modules; - if ( ucode_mod_idx <=3D 0 || ucode_mod_idx >=3D bi->nr_modules || - !__test_and_clear_bit(ucode_mod_idx, bi->module_map) ) - goto scan; - ucode_mod =3D *bi->mods[ucode_mod_idx].mod; -scan: - if ( ucode_scan ) - microcode_scan_module(bi); -} - static struct microcode_ops __ro_after_init ucode_ops; =20 static DEFINE_SPINLOCK(microcode_mutex); @@ -831,7 +818,15 @@ static int __init early_microcode_load(struct boot_inf= o *bi) size_t size; struct microcode_patch *patch; =20 - microcode_grab_module(bi); + if ( ucode_mod_idx < 0 ) + ucode_mod_idx +=3D bi->nr_modules; + if ( ucode_mod_idx <=3D 0 || ucode_mod_idx >=3D bi->nr_modules || + !__test_and_clear_bit(ucode_mod_idx, bi->module_map) ) + goto scan; + ucode_mod =3D *bi->mods[ucode_mod_idx].mod; + scan: + if ( ucode_scan ) + microcode_scan_module(bi); =20 if ( !ucode_mod.mod_end && !ucode_blob.size ) return 0; --=20 2.39.5 From nobody Thu Nov 21 20:23:04 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1730107176; cv=none; d=zohomail.com; s=zohoarc; b=eoPujis94hXGbiblC5HlwYjBOiN20ee5otFkBvYytGAc07/L/yUwJm6/EHyJmFysNSFuufatLrqfwQ/4/zx7M4sCzHobzT6Z63BiSAG6HUDaTkr7dkYWyuEYG/E8m8OukuuaRJwdCApO76yXsYi4f36XShTH3lDA9fHN7jrZ7uU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730107176; h=Content-Type: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=2tHJ9KvrKOuMjaRdKbRkR2CwfZwErwPkHq08Lc76WTw=; b=YtSxcLF2T3GOODLyhhw7aIo5PdnSDE04c9P0e8mRMB/sN2Vzub1pbvgjQyi3Bd59NdA1RVRd/hc6rzW1bHT6tDpiSgWgvIOYsYJj4ldAc8xOq4NTlDHBkfj0INxgZQVrs+sgjrI5T6/rhWL6B0Vuw0usXguQZzy9Kq2fGHoWyfQ= 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 1730107176278225.90371266170484; Mon, 28 Oct 2024 02:19:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.826299.1240541 (Exim 4.92) (envelope-from ) id 1t5Lu5-0006gx-3V; Mon, 28 Oct 2024 09:19:13 +0000 Received: by outflank-mailman (output) from mailman id 826299.1240541; Mon, 28 Oct 2024 09:19:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5Lu4-0006fH-TX; Mon, 28 Oct 2024 09:19:12 +0000 Received: by outflank-mailman (input) for mailman id 826299; Mon, 28 Oct 2024 09:19:11 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5Lu3-0005MP-DJ for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 09:19:11 +0000 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [2a00:1450:4864:20::634]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b0d03caf-950d-11ef-a0c2-8be0dac302b0; Mon, 28 Oct 2024 10:19:10 +0100 (CET) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a9a6b4ca29bso503388266b.3 for ; Mon, 28 Oct 2024 02:19:10 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f05deb6sm355961566b.88.2024.10.28.02.19.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 02:19:08 -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: b0d03caf-950d-11ef-a0c2-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1730107150; x=1730711950; 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=2tHJ9KvrKOuMjaRdKbRkR2CwfZwErwPkHq08Lc76WTw=; b=kahqWksxgzonAQz1hLCbU2S8FFI6DVKIeBrsa/xBMnrbV6FIhTxLUjFO4yymZr934T Fwp22CxvtECXf/VLMk8ogr5zoBKk5DmtUg2ZodOU/978FSgLVwSPT6Heg7y6iPJhmp29 jFIgRRJfO2m9NepiFzsdXGbrGZHP+zQIPS0+E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730107150; x=1730711950; 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=2tHJ9KvrKOuMjaRdKbRkR2CwfZwErwPkHq08Lc76WTw=; b=Gt6d52xzOfaHgt9I9Itrm4BN+Ka8bSBhSbPtaPLAeOKxmIl9FQO3b0PzDVUJdOjQSa YPPelV3ASAAm8UpWyIQ2Ydxio9rA/WNF6sW9xGDK2Apmow7nRIkHBpIavkdTnR1FMctc 2aCxwWnmdg2YZZcFigOLDWxM45mW09V47gjI7ypBEzM2nC17vhp3C/4dbL/kTaqgoAP3 uGyQqbPzqUw4OXal5O9W/l5HJirpt2cKyg3HggiWt8TLX8tkfg/th5eMLVwbpn8f9Jo2 buGOPl+H/KMPpvGlHRhxT/vBCyXw+38OlhFKM9PAxUE8fe0D6funn3dV2ZwrYILE+BPx 2ULQ== X-Gm-Message-State: AOJu0YxDKyiUAKffccbHTWHC40TxlqyYM06ZyqCO5WgIWuwxnmBYZOWj Jo6johjfjQ/Y9SCm/pu6GlUuZ3/b+4R5/pljLh3G4gBvPASHBqmjyFTkLh5IgI+2maydO7sWaxv L X-Google-Smtp-Source: AGHT+IFnmPuo6iIDZ2uIcOkFOtwk+936hL3j8xHD3pymnaePQ9S+o2bupb6g8N/5ycChEVRj6IpzKg== X-Received: by 2002:a17:907:3f20:b0:a9a:375e:c167 with SMTP id a640c23a62f3a-a9de5c91a19mr711781366b.1.1730107149626; Mon, 28 Oct 2024 02:19:09 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , "Daniel P . Smith" Subject: [PATCH 06/10] x86/ucode: Enforce invariant about module selection Date: Mon, 28 Oct 2024 09:18:52 +0000 Message-Id: <20241028091856.2151603-7-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241028091856.2151603-1-andrew.cooper3@citrix.com> References: <20241028091856.2151603-1-andrew.cooper3@citrix.com> 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: 1730107177374116600 The work to add the `ucode=3Dnmi` cmdline option left a subtle corner case. Both scan and an explicit index could be selected, and we could really find= a CPIO archive and explicit microcode file. Worse, because the if/else chains for processing ucode_{blob,mod} are oppos= ite ways around in early_microcode_load() and microcode_init_cache(), we can genuinely perform early microcode loading from the CPIO archive, then cache from the explicit file. Therefore, enforce that only one selection method can be active. Rename ucode_{scan,mod_idx} to have an opt_ prefix. This is both for consistency with the rest of Xen, and to guarantee that we've got all instances of the variables covered in this change. Explain how they're use. During cmdline/config parsing, always update both variables in pairs. In early_microcode_load(), ASSERT() the invariant just in case. Use a local variable for idx rather than operating on the static; we're the only consume of the value. Expand the index selection logic with comments and warnings to the user when something went wrong. Fixes: 5ed12565aa32 ("microcode: rendezvous CPUs in NMI handler and load uc= ode") Signed-off-by: Andrew Cooper Reviewed-by: Daniel P. Smith --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Daniel P. Smith Despite the fixes tag, this can't be backported (at least not in this form). --- xen/arch/x86/cpu/microcode/core.c | 76 +++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 19 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index 4c4003bf9687..fc31ab35c3c8 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -60,7 +60,6 @@ #define MICROCODE_UPDATE_TIMEOUT_US 1000000 =20 static module_t __initdata ucode_mod; -static signed int __initdata ucode_mod_idx; static bool __initdata ucode_mod_forced; static unsigned int nr_cores; =20 @@ -97,11 +96,6 @@ struct patch_with_flags { }; =20 static struct ucode_mod_blob __initdata ucode_blob; -/* - * By default we will NOT parse the multiboot modules to see if there is - * cpio image with the microcode images. - */ -static bool __initdata ucode_scan; =20 /* By default, ucode loading is done in NMI handler */ static bool ucode_in_nmi =3D true; @@ -109,13 +103,28 @@ static bool ucode_in_nmi =3D true; /* Protected by microcode_mutex */ static const struct microcode_patch *microcode_cache; =20 +/* + * opt_mod_idx and opt_scan have subtle semantics. + * + * The cmdline can either identify a module by number (inc -ve back-refere= nce) + * containing a raw microcode container, or select scan which instructs Xe= n to + * search all modules for an uncompressed CPIO archive containing a file w= ith + * a vendor-dependent name. + * + * These options do not make sense when combined, so for the benefit of mo= dule + * location we require that they are not both active together. + */ +static int __initdata opt_mod_idx; +static bool __initdata opt_scan; + /* * Used by the EFI path only, when xen.cfg identifies an explicit microcode * file. Overrides ucode=3D|scan on the regular command line. */ void __init microcode_set_module(unsigned int idx) { - ucode_mod_idx =3D idx; + opt_mod_idx =3D idx; + opt_scan =3D false; ucode_mod_forced =3D 1; } =20 @@ -139,12 +148,16 @@ static int __init cf_check parse_ucode(const char *s) else if ( !ucode_mod_forced ) /* Not forced by EFI */ { if ( (val =3D parse_boolean("scan", s, ss)) >=3D 0 ) - ucode_scan =3D val; + { + opt_scan =3D val; + opt_mod_idx =3D 0; + } else { const char *q; =20 - ucode_mod_idx =3D simple_strtol(s, &q, 0); + opt_scan =3D false; + opt_mod_idx =3D simple_strtol(s, &q, 0); if ( q !=3D ss ) rc =3D -EINVAL; } @@ -166,7 +179,7 @@ static void __init microcode_scan_module(struct boot_in= fo *bi) int i; =20 ucode_blob.size =3D 0; - if ( !ucode_scan ) + if ( !opt_scan ) return; =20 if ( boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD ) @@ -792,7 +805,7 @@ static int __init cf_check microcode_init_cache(void) if ( !ucode_ops.apply_microcode ) return -ENODEV; =20 - if ( ucode_scan ) + if ( opt_scan ) /* Need to rescan the modules because they might have been relocat= ed */ microcode_scan_module(bi); =20 @@ -817,17 +830,42 @@ static int __init early_microcode_load(struct boot_in= fo *bi) const void *data =3D NULL; size_t size; struct microcode_patch *patch; + int idx =3D opt_mod_idx; + + /* + * Cmdline parsing ensures this invariant holds, so that we don't end = up + * trying to mix multiple ways of finding the microcode. + */ + ASSERT(idx =3D=3D 0 || !opt_scan); =20 - if ( ucode_mod_idx < 0 ) - ucode_mod_idx +=3D bi->nr_modules; - if ( ucode_mod_idx <=3D 0 || ucode_mod_idx >=3D bi->nr_modules || - !__test_and_clear_bit(ucode_mod_idx, bi->module_map) ) - goto scan; - ucode_mod =3D *bi->mods[ucode_mod_idx].mod; - scan: - if ( ucode_scan ) + if ( opt_scan ) /* Scan for a CPIO archive */ microcode_scan_module(bi); =20 + if ( idx ) /* Specific module nominated */ + { + /* + * Negative indicies can be used to reference from the end of the + * modules. e.g. ucode=3D-1 refers to the last module. + */ + if ( idx < 0 ) + idx +=3D bi->nr_modules; + + if ( idx <=3D 0 || idx >=3D bi->nr_modules ) + { + printk(XENLOG_WARNING "Microcode: Chosen module %d out of rang= e [1, %u)\n", + idx, bi->nr_modules); + return -ENODEV; + } + + if ( !__test_and_clear_bit(idx, bi->module_map) ) + { + printk(XENLOG_WARNING "Microcode: Chosen module %d already use= d\n", idx); + return -ENODEV; + } + + ucode_mod =3D *bi->mods[idx].mod; + } + if ( !ucode_mod.mod_end && !ucode_blob.size ) return 0; =20 --=20 2.39.5 From nobody Thu Nov 21 20:23:04 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1730107180; cv=none; d=zohomail.com; s=zohoarc; b=GpKtmvy/bZ3L7vV5dEpTLDnEe0+Hi85xqtr5PuPN0krdBp2IR+u+I1PWadlwmZ26crINp+4yk6TnsWUAC4lddxR+o+2FLY0qlGpgzPvqd9jXrFsfZDLT7jYSH0VLOmqIX7FAN66uRt11qAaC01Di+G9vVEHprt0FwpFF9cT6jpU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730107180; h=Content-Type: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=KXO3yd4l+MzrsSxRFtcdMeGmvEoN34yTRv1ZIvRcIRg=; b=nmXPUrfgZ7gp1ggRclph1aDJXVEpwIANeCDKXH1glkG5x5ihwnKwdJ+M6qzhc3WuVfTn/t9mG0ql96+2bAB1ikn2R1rReJnUNG9irfGIoqzhrUUpazNLA/9Fje0VENonKOY2sUHe7JACXqq4Mi8MocMLrGvH54tlgvvNn1JfSQQ= 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 1730107180371749.1467195967145; Mon, 28 Oct 2024 02:19:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.826300.1240555 (Exim 4.92) (envelope-from ) id 1t5Lu7-00077h-9x; Mon, 28 Oct 2024 09:19:15 +0000 Received: by outflank-mailman (output) from mailman id 826300.1240555; Mon, 28 Oct 2024 09:19:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5Lu7-00077Y-6Z; Mon, 28 Oct 2024 09:19:15 +0000 Received: by outflank-mailman (input) for mailman id 826300; Mon, 28 Oct 2024 09:19:14 +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 1t5Lu6-0005yk-7L for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 09:19:14 +0000 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [2a00:1450:4864:20::632]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b1f0041f-950d-11ef-99a3-01e77a169b0f; Mon, 28 Oct 2024 10:19:12 +0100 (CET) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a9acafdb745so734092566b.0 for ; Mon, 28 Oct 2024 02:19:12 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f05deb6sm355961566b.88.2024.10.28.02.19.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 02:19:09 -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: b1f0041f-950d-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1730107151; x=1730711951; 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=KXO3yd4l+MzrsSxRFtcdMeGmvEoN34yTRv1ZIvRcIRg=; b=U8NLVyaVQdgCYJb3+Sc10tKEyF54w3ZI/1GWXeanY111PEUGiw49TbHQYSjvi/cYey abefuos7tbmyK7qoDjo/YlTHg0pc/NYoPqdmVApezuumDp1fwWT5bM50L4MA7pqw2A/d jIAUkvjRxv48FA8MOpy+9BGQfejRM8f2p80wc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730107151; x=1730711951; 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=KXO3yd4l+MzrsSxRFtcdMeGmvEoN34yTRv1ZIvRcIRg=; b=aNp00izfjS1mZLUfbliK5Q1JoIHfvd7S3/Yk7D0quVvd60trG7N0PM1HZp4syiclt9 eqliiaMLbvXdeHohhnKcRwdv6Xa5YvNc+pbbdaAQ0k58Az6U2f3xy4P79aLuoAhJdVnF 2A/vD7p1M62BWT0wEQrabGlUim6QYOdgMv3jvCgvqP19vtrjZfXkuCGDDFHaNfqhsoC+ bEHnNkqn2z7eczF0f8We+/PAl3eY99OvXv4dxMJae0Ina19dBYjuBTmn7Jw3q0IqdlTF caEv0/BLwkrBM8aG3VXhZk2NVRa152rvWgtXB0+vSjGgA+OIXWvqL/qeZ8agvEwwbfzQ GBJw== X-Gm-Message-State: AOJu0Yzxs7sqOxILPMYL5ryAt37uavck35B1AslG2GAkfZRi8VUrZO+9 6gxWPxuK9oJC8Q+4C/AuBzsz+JEtRtNBYxUnbxSTXwWvYGcLUBNZYxTgJ0oGypf/+jvnrQ5ns7+ 1 X-Google-Smtp-Source: AGHT+IE2HztMoWz9TM71tWKVWeJZNK3i6ZU7DJ/Y8LB9GICUVzN4pEV2+DfZvHLbl6G/6ls1BIFlFw== X-Received: by 2002:a17:907:2d22:b0:a99:fbb6:4972 with SMTP id a640c23a62f3a-a9de38e2fbbmr570966966b.25.1730107151115; Mon, 28 Oct 2024 02:19:11 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , "Daniel P . Smith" Subject: [PATCH 07/10] x86/ucode: Move the CPIO path string into microcode_ops Date: Mon, 28 Oct 2024 09:18:53 +0000 Message-Id: <20241028091856.2151603-8-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241028091856.2151603-1-andrew.cooper3@citrix.com> References: <20241028091856.2151603-1-andrew.cooper3@citrix.com> 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: 1730107181368116600 We've got a perfectly good vendor abstraction already for microcode. No ne= ed for a second ad-hoc one in microcode_scan_module(). This is in preparation to use ucode_ops.cpio_path in multiple places. These paths are only used during __init, so take the opportunity to move th= em into __initconst. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich Reviewed-by: Daniel P. Smith --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Daniel P. Smith --- xen/arch/x86/cpu/microcode/amd.c | 4 ++++ xen/arch/x86/cpu/microcode/core.c | 14 +++----------- xen/arch/x86/cpu/microcode/intel.c | 4 ++++ xen/arch/x86/cpu/microcode/private.h | 7 +++++++ 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/= amd.c index 0fe869eff119..c7a779c1d885 100644 --- a/xen/arch/x86/cpu/microcode/amd.c +++ b/xen/arch/x86/cpu/microcode/amd.c @@ -443,11 +443,15 @@ static struct microcode_patch *cf_check cpu_request_m= icrocode( return patch; } =20 +static const char __initconst amd_cpio_path[] =3D + "kernel/x86/microcode/AuthenticAMD.bin"; + static const struct microcode_ops __initconst_cf_clobber amd_ucode_ops =3D= { .cpu_request_microcode =3D cpu_request_microcode, .collect_cpu_info =3D collect_cpu_info, .apply_microcode =3D apply_microcode, .compare_patch =3D compare_patch, + .cpio_path =3D amd_cpio_path, }; =20 void __init ucode_probe_amd(struct microcode_ops *ops) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index fc31ab35c3c8..6a87390ab770 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -170,25 +170,19 @@ static int __init cf_check parse_ucode(const char *s) } custom_param("ucode", parse_ucode); =20 +static struct microcode_ops __ro_after_init ucode_ops; + static void __init microcode_scan_module(struct boot_info *bi) { uint64_t *_blob_start; unsigned long _blob_size; struct cpio_data cd; - const char *p =3D NULL; int i; =20 ucode_blob.size =3D 0; if ( !opt_scan ) return; =20 - if ( boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD ) - p =3D "kernel/x86/microcode/AuthenticAMD.bin"; - else if ( boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_INTEL ) - p =3D "kernel/x86/microcode/GenuineIntel.bin"; - else - return; - /* * Try all modules and see whichever could be the microcode blob. */ @@ -207,7 +201,7 @@ static void __init microcode_scan_module(struct boot_in= fo *bi) } cd.data =3D NULL; cd.size =3D 0; - cd =3D find_cpio_data(p, _blob_start, _blob_size); + cd =3D find_cpio_data(ucode_ops.cpio_path, _blob_start, _blob_size= ); if ( cd.data ) { ucode_blob.size =3D cd.size; @@ -218,8 +212,6 @@ static void __init microcode_scan_module(struct boot_in= fo *bi) } } =20 -static struct microcode_ops __ro_after_init ucode_ops; - static DEFINE_SPINLOCK(microcode_mutex); =20 DEFINE_PER_CPU(struct cpu_signature, cpu_sig); diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcod= e/intel.c index bad51f64724a..aad6a693e800 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -405,11 +405,15 @@ static bool __init can_load_microcode(void) return !(mcu_ctrl & MCU_CONTROL_DIS_MCU_LOAD); } =20 +static const char __initconst intel_cpio_path[] =3D + "kernel/x86/microcode/GenuineIntel.bin"; + static const struct microcode_ops __initconst_cf_clobber intel_ucode_ops = =3D { .cpu_request_microcode =3D cpu_request_microcode, .collect_cpu_info =3D collect_cpu_info, .apply_microcode =3D apply_microcode, .compare_patch =3D compare_patch, + .cpio_path =3D intel_cpio_path, }; =20 void __init ucode_probe_intel(struct microcode_ops *ops) diff --git a/xen/arch/x86/cpu/microcode/private.h b/xen/arch/x86/cpu/microc= ode/private.h index c72f060ac394..c9dd8ba066f9 100644 --- a/xen/arch/x86/cpu/microcode/private.h +++ b/xen/arch/x86/cpu/microcode/private.h @@ -59,6 +59,13 @@ struct microcode_ops { */ enum microcode_match_result (*compare_patch)( const struct microcode_patch *new, const struct microcode_patch *o= ld); + + /* + * For Linux inird microcode compatibliity. + * + * The path where this vendor's microcode can be found in CPIO. + */ + const char *cpio_path; }; =20 /* --=20 2.39.5 From nobody Thu Nov 21 20:23:04 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1730107181; cv=none; d=zohomail.com; s=zohoarc; b=YdtAT2TyMM6Za2mTQH9vJPU6d08vBUHiXFmb+GayWTipi4bSBVZ1g53cCQVZfVLg0OqjenEvmdH40iP3hs4zkEs4OJ9F8nNeZN1DHBEwQzlppAhcQaH8QKIbI4hVw3FElq2nYaSSvZQ6jaGCqB1Fha5a43/SjmM2ubqpstM/n6w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730107181; h=Content-Type: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=s0bQWwaJpgsfZHiC3o/SG7G/jAI+5h9RvIivMx1nt38=; b=KZpk7TEIG+l0pIlzwhY4XtyYxjJo2MJlp7Gi5SQv+AgdadptgeV2oNtmDrw7JVIkq8QiQZkxMImFZcV+ovd3EqE70/zlqH4CHhvZe6bbt7cc1meOlK2V79QtGnol62MDcEmtruFfA6mfUzR/usetJ5p/5oIxIaIUqnM+lVSOf1s= 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 1730107181050849.5511626831674; Mon, 28 Oct 2024 02:19:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.826301.1240560 (Exim 4.92) (envelope-from ) id 1t5Lu7-0007BU-NN; Mon, 28 Oct 2024 09:19:15 +0000 Received: by outflank-mailman (output) from mailman id 826301.1240560; Mon, 28 Oct 2024 09:19:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5Lu7-0007Au-H3; Mon, 28 Oct 2024 09:19:15 +0000 Received: by outflank-mailman (input) for mailman id 826301; Mon, 28 Oct 2024 09:19:14 +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 1t5Lu6-0005yk-JW for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 09:19:14 +0000 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [2a00:1450:4864:20::62e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b239fedf-950d-11ef-99a3-01e77a169b0f; Mon, 28 Oct 2024 10:19:13 +0100 (CET) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a9a0ec0a94fso572799566b.1 for ; Mon, 28 Oct 2024 02:19:13 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f05deb6sm355961566b.88.2024.10.28.02.19.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 02:19:11 -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: b239fedf-950d-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1730107152; x=1730711952; 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=s0bQWwaJpgsfZHiC3o/SG7G/jAI+5h9RvIivMx1nt38=; b=Az2RTmn5ff2Ct6zz41gAjJZB9XfpGMD9+o0qlhKVrw/1Cl7EAbJ2POE30l4BTXmsS0 /nf56CIcfRsC7xGptB/dbR/MkShPTEIY4lRiLz0l4c0avCLNVj1HNh5dmix+HBhOgFuP drfSrqMLm5pln0F8TPAgv3uWgWuU1yRDLoWTo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730107152; x=1730711952; 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=s0bQWwaJpgsfZHiC3o/SG7G/jAI+5h9RvIivMx1nt38=; b=aroNsNC1vxSkDGCqvdZ6nGa/+HHkdLs85Q4e6Q7PkCXQ27G9qKv74JCIyF5W9cNGMt m+I8eY57H78HjIzHbH9qYw05qmMTecfFVcVWl7DJP3b+p+Cbbj9exVaQGHh1+Cp3rk/X nR7wuJfs+4jJieBWtP6UN+zwylnmyO+uJZsP5xIi0qR36FOCgboK1w2hXxr8WbYhyXXx NcCXbLTsWkkLcZLt5SpGvS3pA2Z696G4mtxcs1kljMX3NLfErYqG010mtEQQx2vqekyc H10iB0HsRjdSZVh0EwbJ6g+pI0UytF9YLcP1UbcHkqTwx/GNjbJeG8hLNAePKfq48xyg Kwaw== X-Gm-Message-State: AOJu0YyqzzmctjgmPzrRmQ4HDdILNIvbmFrOBQXLhwUpihBZYww3b7XT OkvmfIARTopcQHAtG6RrF+n3HFObS/UEE1x8qCEkhMSUboANffKmQ+Phn9WKp1tpZ/EOQsmtBmQ C X-Google-Smtp-Source: AGHT+IHUScjwHs+SIRSiBfF67ypzxxtUffXbIKI8gWWL9LwAwdGM1fnb3VoqaEvFjPGPmyn4qCNscQ== X-Received: by 2002:a17:906:f59b:b0:a99:f975:2e6 with SMTP id a640c23a62f3a-a9de5f6ddcbmr788105366b.35.1730107151905; Mon, 28 Oct 2024 02:19:11 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , "Daniel P . Smith" Subject: [PATCH 08/10] x86/ucode: Use bootstrap_unmap() in early_microcode_load() Date: Mon, 28 Oct 2024 09:18:54 +0000 Message-Id: <20241028091856.2151603-9-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241028091856.2151603-1-andrew.cooper3@citrix.com> References: <20241028091856.2151603-1-andrew.cooper3@citrix.com> 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: 1730107181329116600 If bootstrap_map() has provided a mapping, we must free it when done. Fail= ing to do so may cause a spurious failure for unrelated logic later. Inserting a bootstrap_unmap() here does not break the use of ucode_{blob,mo= d} any more than they already are. Add a printk noting when we didn't find a microcode patch. It's at debug level, because this is the expected case on AMD Client systems, and SDPs, b= ut for people trying to figure out why microcode loading isn't work, it might = be helpful. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich Reviewed-by: Daniel P. Smith --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Daniel P. Smith --- xen/arch/x86/cpu/microcode/core.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index 6a87390ab770..28cfeab75a81 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -823,6 +823,7 @@ static int __init early_microcode_load(struct boot_info= *bi) size_t size; struct microcode_patch *patch; int idx =3D opt_mod_idx; + int rc =3D 0; =20 /* * Cmdline parsing ensures this invariant holds, so that we don't end = up @@ -878,15 +879,24 @@ static int __init early_microcode_load(struct boot_in= fo *bi) patch =3D ucode_ops.cpu_request_microcode(data, size, false); if ( IS_ERR(patch) ) { - printk(XENLOG_WARNING "Parsing microcode blob error %ld\n", - PTR_ERR(patch)); - return PTR_ERR(patch); + rc =3D PTR_ERR(patch); + printk(XENLOG_WARNING "Microcode: Parse error %d\n", rc); + goto unmap; } =20 if ( !patch ) - return -ENOENT; + { + printk(XENLOG_DEBUG "Microcode: No suitable patch found\n"); + rc =3D -ENOENT; + goto unmap; + } + + rc =3D microcode_update_cpu(patch, 0); =20 - return microcode_update_cpu(patch, 0); + unmap: + bootstrap_unmap(); + + return rc; } =20 int __init early_microcode_init(struct boot_info *bi) --=20 2.39.5 From nobody Thu Nov 21 20:23:04 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1730107181; cv=none; d=zohomail.com; s=zohoarc; b=IFj4Jmncb8XTh122QhUvUTzMqynqoZGNbRaEKgavJuPkOrZPOrkMAlqrc3fLEOsRkdgCXUdUVb29ZVUUMYKeLZ+2NoYfkXLnJjcVuuE8y/BvCf7dduvHjr0rj9tKSFKIx6KceG/gkpnAbsUs9bRqIKPJZIWeUd/4Co7gnlu8dqg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730107181; h=Content-Type: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=tOxfpCoQr1fVtkc55vOO7DIo2+McEVShrt/nmgVD2Nc=; b=aAVOOn6U6v816EG8J0FbvoWvgWg+MIcDCK2iBGHeYvrMhFEmUAHQbmF1KANNt0JtV1LZsF92leP7oVWyBG5ObCg3Q1k+IeozifuqJg5DxRGnZN845FmYI7rTlTYPxwEdJt7ac7nTUStzQ54Z8WEfD/K1v6w4WlBTgRybX+qwYYw= 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 1730107181626593.2519000432601; Mon, 28 Oct 2024 02:19:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.826302.1240574 (Exim 4.92) (envelope-from ) id 1t5LuB-0007mQ-18; Mon, 28 Oct 2024 09:19:19 +0000 Received: by outflank-mailman (output) from mailman id 826302.1240574; Mon, 28 Oct 2024 09:19:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5LuA-0007mC-U6; Mon, 28 Oct 2024 09:19:18 +0000 Received: by outflank-mailman (input) for mailman id 826302; Mon, 28 Oct 2024 09:19:17 +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 1t5Lu9-0005yk-Bo for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 09:19:17 +0000 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [2a00:1450:4864:20::634]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b3b74dd4-950d-11ef-99a3-01e77a169b0f; Mon, 28 Oct 2024 10:19:15 +0100 (CET) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a9a6b4ca29bso503396966b.3 for ; Mon, 28 Oct 2024 02:19:15 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f05deb6sm355961566b.88.2024.10.28.02.19.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 02:19:12 -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: b3b74dd4-950d-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1730107154; x=1730711954; 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=tOxfpCoQr1fVtkc55vOO7DIo2+McEVShrt/nmgVD2Nc=; b=ZeSyhCJ9M5/oLw/pxpLB2C93bnM91u4GJabTWZWu3xA5S02ZmmtuL6BL1xVgm7YDmP yp+UX+9tWCW1nFii1JXN0u/W/BZdJSvfkWauYgCAWmN1WeX4YZtoxtCyZhtxWmDLDl1m v+/QxC+LGWEEW1CBK56Vy6dWUOocdPWiMAzHA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730107154; x=1730711954; 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=tOxfpCoQr1fVtkc55vOO7DIo2+McEVShrt/nmgVD2Nc=; b=Ly5hP/OE8X765z3apa+BQVnLJS9/K1Yh4aPi73poLGsZ0cfDz++ecAvIFZROjCLxPs lP14kip70zBc5rM+38KgIlWlcYOE/9VcFQOvynzOHkMdJHMYZDypRXqALjoy7AuDu4lW fzBegri8tHP/ALCbwVEEjL7/ARUXSrBuiZYgRTJmTBpqfJeq64K9kKDG0GGGwXp34stz Wj/RXoJEc/SGw6dVV0JkeL9oyB2UIXyuV0NsrkqeTuB11rjGmJ985XrFpIH6XBmEyUho zAPpw+/ROASBXHCxWCIy9xjpVgbbXUawGIIVPr9HUegsUZHeeueNj8JzE/AjIrdvz05x fdmg== X-Gm-Message-State: AOJu0Yw/nINDAVsfKGyNjmDuQ/UN3gpgGMzuBd/aAL+8HA07wE9cPcwv H7krMlo5nNX/j6nv+V66Y1AS/8WlCzboEar5TOnGdI63scc9HXSQaJONTfEQCZD47kD3oIg4hS5 A X-Google-Smtp-Source: AGHT+IF5Zj0+DmUz/iiGI9arwyEOISVm/s8FlkCO7Eh2n/FJlgucYcavycgcmFQ19nPK9n9r6tR4sQ== X-Received: by 2002:a17:907:1b81:b0:a99:6036:90a with SMTP id a640c23a62f3a-a9de5ce2501mr517120566b.14.1730107153579; Mon, 28 Oct 2024 02:19:13 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , "Daniel P . Smith" Subject: [PATCH 09/10] x86/ucode: Drop ucode_mod and ucode_blob Date: Mon, 28 Oct 2024 09:18:55 +0000 Message-Id: <20241028091856.2151603-10-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241028091856.2151603-1-andrew.cooper3@citrix.com> References: <20241028091856.2151603-1-andrew.cooper3@citrix.com> 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: 1730107183419116600 Both are used to pass information from early_microcode_load() to microcode_init_cache(), and both constitute use-after-free's in certain cas= es. * ucode_mod is a copy of the module_t identified by `ucode=3D$n`. Except = it's a copy from prior to Xen relocating the modules. microcode_init_cache() might happen to find the data still intact in it's old location, but it might be an arbitrary part of some other module. * ucode_blob is a stashed pointer to a bootstrap_map() which becomes inval= id the moment control returns to __start_xen(), where other logic is free to to make temporary mappings. This was even noticed and microcode_init_cache() adjusted to "fix" the stashed pointers. The information which should be passed between these two functions is which module to look in. Introduce early_mod_idx for this purpose. opt_scan can= be reused to distinguish between CPIO archives and raw containers. Notably this means microcode_init_cache() doesn't need to scan all modules = any more; we know exactly which one to look in. However, we do re-parse the CP= IO header for simplicity. Furthermore, microcode_init_cache(), being a presmp_initcall does not need = to use bootstrap_map() to access modules; it can use mfn_to_virt() directly, which avoids needing to funnel exit paths through bootstrap_unmap(). Fold microcode_scan_module() into what is now it's single caller. It opera= tes on the function-wide idx/data/size state which allows for a unified "found" path irrespective of module selection method. This resolves all issues to do with holding pointers (physical or virtual) across returning to __start_xen(). Signed-off-by: Andrew Cooper Acked-by: Jan Beulich Reviewed-by: Daniel P. Smith --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Daniel P. Smith --- xen/arch/x86/cpu/microcode/core.c | 172 ++++++++++++++++-------------- 1 file changed, 89 insertions(+), 83 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index 28cfeab75a81..591c13ad91fb 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -59,7 +58,6 @@ */ #define MICROCODE_UPDATE_TIMEOUT_US 1000000 =20 -static module_t __initdata ucode_mod; static bool __initdata ucode_mod_forced; static unsigned int nr_cores; =20 @@ -79,24 +77,11 @@ static enum { LOADING_EXIT, } loading_state; =20 -/* - * If we scan the initramfs.cpio for the early microcode code - * and find it, then 'ucode_blob' will contain the pointer - * and the size of said blob. It is allocated from Xen's heap - * memory. - */ -struct ucode_mod_blob { - const void *data; - size_t size; -}; - struct patch_with_flags { unsigned int flags; const struct microcode_patch *patch; }; =20 -static struct ucode_mod_blob __initdata ucode_blob; - /* By default, ucode loading is done in NMI handler */ static bool ucode_in_nmi =3D true; =20 @@ -172,46 +157,6 @@ custom_param("ucode", parse_ucode); =20 static struct microcode_ops __ro_after_init ucode_ops; =20 -static void __init microcode_scan_module(struct boot_info *bi) -{ - uint64_t *_blob_start; - unsigned long _blob_size; - struct cpio_data cd; - int i; - - ucode_blob.size =3D 0; - if ( !opt_scan ) - return; - - /* - * Try all modules and see whichever could be the microcode blob. - */ - for ( i =3D 1 /* Ignore dom0 kernel */; i < bi->nr_modules; i++ ) - { - if ( !test_bit(i, bi->module_map) ) - continue; - - _blob_start =3D bootstrap_map(bi->mods[i].mod); - _blob_size =3D bi->mods[i].mod->mod_end; - if ( !_blob_start ) - { - printk("Could not map multiboot module #%d (size: %ld)\n", - i, _blob_size); - continue; - } - cd.data =3D NULL; - cd.size =3D 0; - cd =3D find_cpio_data(ucode_ops.cpio_path, _blob_start, _blob_size= ); - if ( cd.data ) - { - ucode_blob.size =3D cd.size; - ucode_blob.data =3D cd.data; - break; - } - bootstrap_unmap(); - } -} - static DEFINE_SPINLOCK(microcode_mutex); =20 DEFINE_PER_CPU(struct cpu_signature, cpu_sig); @@ -789,23 +734,47 @@ static int __init early_update_cache(const void *data= , size_t len) return rc; } =20 +/* + * Set by early_microcode_load() to indicate where it found microcode, so + * microcode_init_cache() can find it again and initalise the cache. opt_= scan + * tells us whether we're looking for a raw container or CPIO archive. + */ +static int __initdata early_mod_idx =3D -1; + static int __init cf_check microcode_init_cache(void) { struct boot_info *bi =3D &xen_boot_info; + void *data; + size_t size; int rc =3D 0; =20 - if ( !ucode_ops.apply_microcode ) - return -ENODEV; + if ( early_mod_idx < 0 ) + /* early_microcode_load() didn't leave us any work to do. */ + return 0; + + size =3D bi->mods[early_mod_idx].mod->mod_end; + data =3D __mfn_to_virt(bi->mods[early_mod_idx].mod->mod_start); =20 + /* + * If opt_scan is set, we're looking for a CPIO archive rather than a = raw + * microcode container. Look within it. + */ if ( opt_scan ) - /* Need to rescan the modules because they might have been relocat= ed */ - microcode_scan_module(bi); + { + struct cpio_data cd =3D find_cpio_data(ucode_ops.cpio_path, data, = size); =20 - if ( ucode_mod.mod_end ) - rc =3D early_update_cache(bootstrap_map(&ucode_mod), - ucode_mod.mod_end); - else if ( ucode_blob.size ) - rc =3D early_update_cache(ucode_blob.data, ucode_blob.size); + if ( !cd.data ) + { + printk(XENLOG_WARNING "Microcode: %s not found in CPIO archive= \n", + strrchr(ucode_ops.cpio_path, '/') + 1); + return -ENOENT; + } + + data =3D cd.data; + size =3D cd.size; + } + + rc =3D early_update_cache(data, size); =20 return rc; } @@ -819,7 +788,7 @@ presmp_initcall(microcode_init_cache); */ static int __init early_microcode_load(struct boot_info *bi) { - const void *data =3D NULL; + void *data =3D NULL; size_t size; struct microcode_patch *patch; int idx =3D opt_mod_idx; @@ -832,7 +801,40 @@ static int __init early_microcode_load(struct boot_inf= o *bi) ASSERT(idx =3D=3D 0 || !opt_scan); =20 if ( opt_scan ) /* Scan for a CPIO archive */ - microcode_scan_module(bi); + { + for ( idx =3D 1; idx < bi->nr_modules; ++idx ) + { + struct cpio_data cd; + + if ( !test_bit(idx, bi->module_map) ) + continue; + + size =3D bi->mods[idx].mod->mod_end; + data =3D bootstrap_map_bm(&bi->mods[idx]); + if ( !data ) + { + printk(XENLOG_WARNING "Microcode: Could not map module %d,= size %zu\n", + idx, size); + continue; + } + + cd =3D find_cpio_data(ucode_ops.cpio_path, data, size); + if ( !cd.data ) + { + /* CPIO archive, but no cpio_path. Try the next module */ + bootstrap_unmap(); + continue; + } + + data =3D cd.data; + size =3D cd.size; + goto found; + } + + printk(XENLOG_WARNING "Microcode: %s not found during CPIO scan\n", + strrchr(ucode_ops.cpio_path, '/') + 1); + return -ENODEV; + } =20 if ( idx ) /* Specific module nominated */ { @@ -856,26 +858,21 @@ static int __init early_microcode_load(struct boot_in= fo *bi) return -ENODEV; } =20 - ucode_mod =3D *bi->mods[idx].mod; - } - - if ( !ucode_mod.mod_end && !ucode_blob.size ) - return 0; - - if ( ucode_blob.size ) - { - size =3D ucode_blob.size; - data =3D ucode_blob.data; - } - else if ( ucode_mod.mod_end ) - { - size =3D ucode_mod.mod_end; - data =3D bootstrap_map(&ucode_mod); + size =3D bi->mods[idx].mod->mod_end; + data =3D bootstrap_map_bm(&bi->mods[idx]); + if ( !data ) + { + printk(XENLOG_WARNING "Microcode: Could not map module %d, siz= e %zu\n", + idx, size); + return -ENODEV; + } + goto found; } =20 - if ( !data ) - return -ENOMEM; + /* No method of finding microcode specified. Nothing to do. */ + return 0; =20 + found: patch =3D ucode_ops.cpu_request_microcode(data, size, false); if ( IS_ERR(patch) ) { @@ -891,6 +888,15 @@ static int __init early_microcode_load(struct boot_inf= o *bi) goto unmap; } =20 + /* + * We've found a microcode patch suitable for this CPU. + * + * Tell microcode_init_cache() which module we found it in. We cache = it + * irrespective of whether the BSP successfully loads it; Some platfor= ms + * are known to update the BSP but leave the APs on older ucode. + */ + early_mod_idx =3D idx; + rc =3D microcode_update_cpu(patch, 0); =20 unmap: --=20 2.39.5 From nobody Thu Nov 21 20:23:04 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1730107180; cv=none; d=zohomail.com; s=zohoarc; b=OogWs9AiKU7YmF/mNwUoQE/9efIzUQpRw0WPuppJ3qsTh3+PTd6VwzCypQz6+qDAs9IaJ1UJjbIdfhhAnDlZS9ldctx1Bi8FsQTQQUDoJ4b1CwuLj47XZY+BoDOkQFnWb30YUQeKZOb9T5WUU1jIIDaQZkUmZC4SGInLpkaJdiM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730107180; h=Content-Type: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=N3hciQ8Ka+dHVzkGgN9t9G2Trm/MbifcubSrtXUCw+M=; b=gRcBYFMVxviCATB1AGoFRfOBF0NwuaGcP8AMmPAabIRLOTSnBr9c1p/iSh4Y+StSJVoaig51QtmHaAJrEaQnR0MI77zEzoe7G5rtyHWGmprkfz4klepEW05yLP1Us+r23+h5hvXKLgmjzmcaxfMRKSrMpHcfbERwvYWHStO+f1k= 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 1730107180382364.79176038389176; Mon, 28 Oct 2024 02:19:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.826303.1240581 (Exim 4.92) (envelope-from ) id 1t5LuB-0007uO-RD; Mon, 28 Oct 2024 09:19:19 +0000 Received: by outflank-mailman (output) from mailman id 826303.1240581; Mon, 28 Oct 2024 09:19:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5LuB-0007tF-Ko; Mon, 28 Oct 2024 09:19:19 +0000 Received: by outflank-mailman (input) for mailman id 826303; Mon, 28 Oct 2024 09:19:18 +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 1t5LuA-0005yk-C6 for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 09:19:18 +0000 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [2a00:1450:4864:20::633]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b3ffc1e0-950d-11ef-99a3-01e77a169b0f; Mon, 28 Oct 2024 10:19:16 +0100 (CET) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a9a16b310f5so631781666b.0 for ; Mon, 28 Oct 2024 02:19:16 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1f05deb6sm355961566b.88.2024.10.28.02.19.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 02:19:13 -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: b3ffc1e0-950d-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1730107154; x=1730711954; 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=N3hciQ8Ka+dHVzkGgN9t9G2Trm/MbifcubSrtXUCw+M=; b=IXwUuC1xzv8NPdzys5H0aWul5/OF4Xv76JNr0xYLz/ufgtv8SREikhHlS6ztVUWaZc n9P+0WoGgN8Y6+fLzsbOZsj0VGKkSrfgbaq4udZUwIAAm/HKMCFWuUyUeT73cEEaFHIK LxMhfHYDjNPp1+6iai6n+VBFf/fp7u9vsiw5s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730107154; x=1730711954; 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=N3hciQ8Ka+dHVzkGgN9t9G2Trm/MbifcubSrtXUCw+M=; b=gJDgzEDKgaOAEzc6kqNAe0z+VG4CpaXNYRaq+WMwtgh9PshtDJ/9CzhqIE6e6yQTiG WcwqpK+lSlwjUgod+4R23UUypRzXW0/yqGTZ+3gOBF/dK8UOrJaT0OZELgmheYp5HY/m FYwBBSxbWkztc3WIZmxy/CKXQuxspc6yxmVzaTUPYxSSPPSP6/DuAGAyPqNN0gAuvsLU RHlw0QUEWsKZHkuskdgqb3AlDY3Dxn1GovvprD03hg8o9rb3wMdiMd8sv4RdEEK+Dbo4 1qy5TrLAtR7dgy2w/F2/7qsm/Gfd5IUzoLroCfG2Q4ZLsrzy2m7eBPff5FQNwZbecKyJ +HuA== X-Gm-Message-State: AOJu0YxXvluYhcvfdjYydUZvqD+nJ8HsEXbSiAPcX37lJTTquGqNljpZ xn/5vsOjcz2dhBOSe1fLmG3RAAFyhUieN/7kfj/CtWtjjGhJ1nULyfoHh4n729Abtm4VkjaTviT Y X-Google-Smtp-Source: AGHT+IHDTU7KYy6C7gkSIvfD0SXzraoTh+peLzg0SM8iNtvWnEKHnonHgd6RuBE5i3u2p+RDyGorCQ== X-Received: by 2002:a17:907:7284:b0:a9a:6ab:c93b with SMTP id a640c23a62f3a-a9de62ec47fmr687812466b.62.1730107154586; Mon, 28 Oct 2024 02:19:14 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , "Daniel P . Smith" Subject: [PATCH 10/10] x86/ucode: Fold early_update_cache() into its single caller Date: Mon, 28 Oct 2024 09:18:56 +0000 Message-Id: <20241028091856.2151603-11-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241028091856.2151603-1-andrew.cooper3@citrix.com> References: <20241028091856.2151603-1-andrew.cooper3@citrix.com> 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: 1730107181343116600 The data pointer is known good, so the -ENOMEM path is unnecessary. Howeve= r, if we find no patch, something's wrong seeing as early_microcode_init() indicated it was happy. We are the entity initialising the cache, so we don't need the complexity of using microcode_update_cache(). Just assert the cache is empty, and popula= te it. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich Reviewed-by: Daniel P. Smith --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Daniel P. Smith --- xen/arch/x86/cpu/microcode/core.c | 47 +++++++++++++------------------ 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index 591c13ad91fb..90a6f2bd87ae 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -707,33 +707,6 @@ int microcode_update_one(void) return microcode_update_cpu(NULL, 0); } =20 -static int __init early_update_cache(const void *data, size_t len) -{ - int rc =3D 0; - struct microcode_patch *patch; - - if ( !data ) - return -ENOMEM; - - patch =3D parse_blob(data, len); - if ( IS_ERR(patch) ) - { - printk(XENLOG_WARNING "Parsing microcode blob error %ld\n", - PTR_ERR(patch)); - return PTR_ERR(patch); - } - - if ( !patch ) - return -ENOENT; - - spin_lock(µcode_mutex); - rc =3D microcode_update_cache(patch); - spin_unlock(µcode_mutex); - ASSERT(rc); - - return rc; -} - /* * Set by early_microcode_load() to indicate where it found microcode, so * microcode_init_cache() can find it again and initalise the cache. opt_= scan @@ -744,6 +717,7 @@ static int __initdata early_mod_idx =3D -1; static int __init cf_check microcode_init_cache(void) { struct boot_info *bi =3D &xen_boot_info; + struct microcode_patch *patch; void *data; size_t size; int rc =3D 0; @@ -774,7 +748,24 @@ static int __init cf_check microcode_init_cache(void) size =3D cd.size; } =20 - rc =3D early_update_cache(data, size); + patch =3D parse_blob(data, size); + if ( IS_ERR(patch) ) + { + rc =3D PTR_ERR(patch); + printk(XENLOG_WARNING "Microcode: Parse error %d\n", rc); + return rc; + } + + if ( !patch ) + { + printk(XENLOG_WARNING "Microcode: No suitable patch found\n"); + return -ENOENT; + } + + spin_lock(µcode_mutex); + ASSERT(microcode_cache =3D=3D NULL); + microcode_cache =3D patch; + spin_unlock(µcode_mutex); =20 return rc; } --=20 2.39.5