From patchwork Mon Oct 28 09:18:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13853189 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 131D6D13599 for ; Mon, 28 Oct 2024 09:19:26 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 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 --- CC: Jan Beulich CC: Roger Pau Monné 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; } -int __init microcode_init_cache(struct boot_info *bi) +static int __init cf_check microcode_init_cache(void) { + struct boot_info *bi = &xen_boot_info; int rc = 0; if ( !ucode_ops.apply_microcode ) @@ -838,6 +839,7 @@ int __init microcode_init_cache(struct boot_info *bi) return rc; } +presmp_initcall(microcode_init_cache); /* 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/asm/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); struct boot_info; int early_microcode_init(struct boot_info *bi); -int microcode_init_cache(struct boot_info *bi); #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) timer_init(); - microcode_init_cache(bi); /* Needs xmalloc() */ - tsx_init(); /* Needs microcode. May change HLE/RTM feature bits. */ calculate_raw_cpu_policy(); /* Needs microcode. No other dependenices. */ From patchwork Mon Oct 28 09:18:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13853188 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 12FAED13570 for ; Mon, 28 Oct 2024 09:19:26 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 The comment highlights just how bogus this really is. Being an initcall, the 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 validity of the mappings "being freed". Indeed, they both constitute use-after-frees. 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 these 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 --- CC: Jan Beulich CC: Roger Pau Monné 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); } -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 = 0; - ucode_blob.data = NULL; - } - else if ( ucode_mod.mod_end ) - { - bootstrap_unmap(); - ucode_mod.mod_end = 0; - } - - return 0; -} -__initcall(microcode_init); - /* Load a cached update to current cpu */ int microcode_update_one(void) { From patchwork Mon Oct 28 09:18:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13853191 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B9B49D1359A for ; Mon, 28 Oct 2024 09:19:26 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 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 functions out of early_microcode_init(). No functional change. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monné 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); } +/* + * 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 = &boot_cpu_data; @@ -897,10 +913,7 @@ int __init early_microcode_init(struct boot_info *bi) return -ENODEV; } - microcode_grab_module(bi); - - if ( ucode_mod.mod_end || ucode_blob.size ) - rc = early_microcode_update_cpu(); + rc = early_microcode_load(bi); /* * Some CPUID leaves and MSRs are only present after microcode updates From patchwork Mon Oct 28 09:18:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13853193 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 06FBFD1359D for ; Mon, 28 Oct 2024 09:19:28 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 Diff-wise, as early_microcode_update_cpu() is the larger function, this more closely resembles "merge early_microcode_load() into it's single callee", but 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 --- CC: Jan Beulich CC: Roger Pau Monné 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); -/* 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 = NULL; - size_t len; + size_t size; struct microcode_patch *patch; + microcode_grab_module(bi); + + if ( !ucode_mod.mod_end && !ucode_blob.size ) + return 0; + if ( ucode_blob.size ) { - len = ucode_blob.size; + size = ucode_blob.size; data = ucode_blob.data; } else if ( ucode_mod.mod_end ) { - len = ucode_mod.mod_end; + size = ucode_mod.mod_end; data = bootstrap_map(&ucode_mod); } if ( !data ) return -ENOMEM; - patch = ucode_ops.cpu_request_microcode(data, len, false); + patch = 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); } -/* - * 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 = &boot_cpu_data; From patchwork Mon Oct 28 09:18:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13853186 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5CFD0D13588 for ; Mon, 28 Oct 2024 09:19:25 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 No functional change. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monné 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_info *bi) } } -static void __init microcode_grab_module(struct boot_info *bi) -{ - if ( ucode_mod_idx < 0 ) - ucode_mod_idx += bi->nr_modules; - if ( ucode_mod_idx <= 0 || ucode_mod_idx >= bi->nr_modules || - !__test_and_clear_bit(ucode_mod_idx, bi->module_map) ) - goto scan; - ucode_mod = *bi->mods[ucode_mod_idx].mod; -scan: - if ( ucode_scan ) - microcode_scan_module(bi); -} - static struct microcode_ops __ro_after_init ucode_ops; static DEFINE_SPINLOCK(microcode_mutex); @@ -831,7 +818,15 @@ static int __init early_microcode_load(struct boot_info *bi) size_t size; struct microcode_patch *patch; - microcode_grab_module(bi); + if ( ucode_mod_idx < 0 ) + ucode_mod_idx += bi->nr_modules; + if ( ucode_mod_idx <= 0 || ucode_mod_idx >= bi->nr_modules || + !__test_and_clear_bit(ucode_mod_idx, bi->module_map) ) + goto scan; + ucode_mod = *bi->mods[ucode_mod_idx].mod; + scan: + if ( ucode_scan ) + microcode_scan_module(bi); if ( !ucode_mod.mod_end && !ucode_blob.size ) return 0; From patchwork Mon Oct 28 09:18:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13853196 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 41F06D1359C for ; Mon, 28 Oct 2024 09:19:28 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 The work to add the `ucode=nmi` 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 opposite 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 ucode") Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monné 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 static module_t __initdata ucode_mod; -static signed int __initdata ucode_mod_idx; static bool __initdata ucode_mod_forced; static unsigned int nr_cores; @@ -97,11 +96,6 @@ struct patch_with_flags { }; 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; /* By default, ucode loading is done in NMI handler */ static bool ucode_in_nmi = true; @@ -109,13 +103,28 @@ static bool ucode_in_nmi = true; /* Protected by microcode_mutex */ static const struct microcode_patch *microcode_cache; +/* + * opt_mod_idx and opt_scan have subtle semantics. + * + * The cmdline can either identify a module by number (inc -ve back-reference) + * containing a raw microcode container, or select scan which instructs Xen to + * search all modules for an uncompressed CPIO archive containing a file with + * a vendor-dependent name. + * + * These options do not make sense when combined, so for the benefit of module + * 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=|scan on the regular command line. */ void __init microcode_set_module(unsigned int idx) { - ucode_mod_idx = idx; + opt_mod_idx = idx; + opt_scan = false; ucode_mod_forced = 1; } @@ -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 = parse_boolean("scan", s, ss)) >= 0 ) - ucode_scan = val; + { + opt_scan = val; + opt_mod_idx = 0; + } else { const char *q; - ucode_mod_idx = simple_strtol(s, &q, 0); + opt_scan = false; + opt_mod_idx = simple_strtol(s, &q, 0); if ( q != ss ) rc = -EINVAL; } @@ -166,7 +179,7 @@ static void __init microcode_scan_module(struct boot_info *bi) int i; ucode_blob.size = 0; - if ( !ucode_scan ) + if ( !opt_scan ) return; if ( boot_cpu_data.x86_vendor == X86_VENDOR_AMD ) @@ -792,7 +805,7 @@ static int __init cf_check microcode_init_cache(void) if ( !ucode_ops.apply_microcode ) return -ENODEV; - if ( ucode_scan ) + if ( opt_scan ) /* Need to rescan the modules because they might have been relocated */ microcode_scan_module(bi); @@ -817,17 +830,42 @@ static int __init early_microcode_load(struct boot_info *bi) const void *data = NULL; size_t size; struct microcode_patch *patch; + int idx = 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 == 0 || !opt_scan); - if ( ucode_mod_idx < 0 ) - ucode_mod_idx += bi->nr_modules; - if ( ucode_mod_idx <= 0 || ucode_mod_idx >= bi->nr_modules || - !__test_and_clear_bit(ucode_mod_idx, bi->module_map) ) - goto scan; - ucode_mod = *bi->mods[ucode_mod_idx].mod; - scan: - if ( ucode_scan ) + if ( opt_scan ) /* Scan for a CPIO archive */ microcode_scan_module(bi); + if ( idx ) /* Specific module nominated */ + { + /* + * Negative indicies can be used to reference from the end of the + * modules. e.g. ucode=-1 refers to the last module. + */ + if ( idx < 0 ) + idx += bi->nr_modules; + + if ( idx <= 0 || idx >= bi->nr_modules ) + { + printk(XENLOG_WARNING "Microcode: Chosen module %d out of range [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 used\n", idx); + return -ENODEV; + } + + ucode_mod = *bi->mods[idx].mod; + } + if ( !ucode_mod.mod_end && !ucode_blob.size ) return 0; From patchwork Mon Oct 28 09:18:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13853192 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 00A15D13597 for ; Mon, 28 Oct 2024 09:19:25 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 We've got a perfectly good vendor abstraction already for microcode. No need 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 them into __initconst. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monné 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_microcode( return patch; } +static const char __initconst amd_cpio_path[] = + "kernel/x86/microcode/AuthenticAMD.bin"; + static const struct microcode_ops __initconst_cf_clobber amd_ucode_ops = { .cpu_request_microcode = cpu_request_microcode, .collect_cpu_info = collect_cpu_info, .apply_microcode = apply_microcode, .compare_patch = compare_patch, + .cpio_path = amd_cpio_path, }; 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); +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 = NULL; int i; ucode_blob.size = 0; if ( !opt_scan ) return; - if ( boot_cpu_data.x86_vendor == X86_VENDOR_AMD ) - p = "kernel/x86/microcode/AuthenticAMD.bin"; - else if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL ) - p = "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_info *bi) } cd.data = NULL; cd.size = 0; - cd = find_cpio_data(p, _blob_start, _blob_size); + cd = find_cpio_data(ucode_ops.cpio_path, _blob_start, _blob_size); if ( cd.data ) { ucode_blob.size = cd.size; @@ -218,8 +212,6 @@ static void __init microcode_scan_module(struct boot_info *bi) } } -static struct microcode_ops __ro_after_init ucode_ops; - static DEFINE_SPINLOCK(microcode_mutex); DEFINE_PER_CPU(struct cpu_signature, cpu_sig); diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcode/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); } +static const char __initconst intel_cpio_path[] = + "kernel/x86/microcode/GenuineIntel.bin"; + static const struct microcode_ops __initconst_cf_clobber intel_ucode_ops = { .cpu_request_microcode = cpu_request_microcode, .collect_cpu_info = collect_cpu_info, .apply_microcode = apply_microcode, .compare_patch = compare_patch, + .cpio_path = intel_cpio_path, }; void __init ucode_probe_intel(struct microcode_ops *ops) diff --git a/xen/arch/x86/cpu/microcode/private.h b/xen/arch/x86/cpu/microcode/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 *old); + + /* + * For Linux inird microcode compatibliity. + * + * The path where this vendor's microcode can be found in CPIO. + */ + const char *cpio_path; }; /* From patchwork Mon Oct 28 09:18:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13853187 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E7025D13593 for ; Mon, 28 Oct 2024 09:19:25 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 If bootstrap_map() has provided a mapping, we must free it when done. Failing 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,mod} 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, but 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 --- CC: Jan Beulich CC: Roger Pau Monné 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 = opt_mod_idx; + int rc = 0; /* * 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_info *bi) patch = 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 = PTR_ERR(patch); + printk(XENLOG_WARNING "Microcode: Parse error %d\n", rc); + goto unmap; } if ( !patch ) - return -ENOENT; + { + printk(XENLOG_DEBUG "Microcode: No suitable patch found\n"); + rc = -ENOENT; + goto unmap; + } + + rc = microcode_update_cpu(patch, 0); - return microcode_update_cpu(patch, 0); + unmap: + bootstrap_unmap(); + + return rc; } int __init early_microcode_init(struct boot_info *bi) From patchwork Mon Oct 28 09:18:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13853195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8EBEED1359B for ; Mon, 28 Oct 2024 09:19:27 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 Both are used to pass information from early_microcode_load() to microcode_init_cache(), and both constitute use-after-free's in certain cases. * ucode_mod is a copy of the module_t identified by `ucode=$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 invalid 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 CPIO 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 operates 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 --- CC: Jan Beulich CC: Roger Pau Monné 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 -static module_t __initdata ucode_mod; static bool __initdata ucode_mod_forced; static unsigned int nr_cores; @@ -79,24 +77,11 @@ static enum { LOADING_EXIT, } loading_state; -/* - * 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; }; -static struct ucode_mod_blob __initdata ucode_blob; - /* By default, ucode loading is done in NMI handler */ static bool ucode_in_nmi = true; @@ -172,46 +157,6 @@ custom_param("ucode", parse_ucode); 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; - int i; - - ucode_blob.size = 0; - if ( !opt_scan ) - return; - - /* - * Try all modules and see whichever could be the microcode blob. - */ - for ( i = 1 /* Ignore dom0 kernel */; i < bi->nr_modules; i++ ) - { - if ( !test_bit(i, bi->module_map) ) - continue; - - _blob_start = bootstrap_map(bi->mods[i].mod); - _blob_size = 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 = NULL; - cd.size = 0; - cd = find_cpio_data(ucode_ops.cpio_path, _blob_start, _blob_size); - if ( cd.data ) - { - ucode_blob.size = cd.size; - ucode_blob.data = cd.data; - break; - } - bootstrap_unmap(); - } -} - static DEFINE_SPINLOCK(microcode_mutex); 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; } +/* + * 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 = -1; + static int __init cf_check microcode_init_cache(void) { struct boot_info *bi = &xen_boot_info; + void *data; + size_t size; int rc = 0; - 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 = bi->mods[early_mod_idx].mod->mod_end; + data = __mfn_to_virt(bi->mods[early_mod_idx].mod->mod_start); + /* + * 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 relocated */ - microcode_scan_module(bi); + { + struct cpio_data cd = find_cpio_data(ucode_ops.cpio_path, data, size); - if ( ucode_mod.mod_end ) - rc = early_update_cache(bootstrap_map(&ucode_mod), - ucode_mod.mod_end); - else if ( ucode_blob.size ) - rc = 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 = cd.data; + size = cd.size; + } + + rc = early_update_cache(data, size); return rc; } @@ -819,7 +788,7 @@ presmp_initcall(microcode_init_cache); */ static int __init early_microcode_load(struct boot_info *bi) { - const void *data = NULL; + void *data = NULL; size_t size; struct microcode_patch *patch; int idx = opt_mod_idx; @@ -832,7 +801,40 @@ static int __init early_microcode_load(struct boot_info *bi) ASSERT(idx == 0 || !opt_scan); if ( opt_scan ) /* Scan for a CPIO archive */ - microcode_scan_module(bi); + { + for ( idx = 1; idx < bi->nr_modules; ++idx ) + { + struct cpio_data cd; + + if ( !test_bit(idx, bi->module_map) ) + continue; + + size = bi->mods[idx].mod->mod_end; + data = bootstrap_map_bm(&bi->mods[idx]); + if ( !data ) + { + printk(XENLOG_WARNING "Microcode: Could not map module %d, size %zu\n", + idx, size); + continue; + } + + cd = 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 = cd.data; + size = cd.size; + goto found; + } + + printk(XENLOG_WARNING "Microcode: %s not found during CPIO scan\n", + strrchr(ucode_ops.cpio_path, '/') + 1); + return -ENODEV; + } if ( idx ) /* Specific module nominated */ { @@ -856,26 +858,21 @@ static int __init early_microcode_load(struct boot_info *bi) return -ENODEV; } - ucode_mod = *bi->mods[idx].mod; - } - - if ( !ucode_mod.mod_end && !ucode_blob.size ) - return 0; - - if ( ucode_blob.size ) - { - size = ucode_blob.size; - data = ucode_blob.data; - } - else if ( ucode_mod.mod_end ) - { - size = ucode_mod.mod_end; - data = bootstrap_map(&ucode_mod); + size = bi->mods[idx].mod->mod_end; + data = bootstrap_map_bm(&bi->mods[idx]); + if ( !data ) + { + printk(XENLOG_WARNING "Microcode: Could not map module %d, size %zu\n", + idx, size); + return -ENODEV; + } + goto found; } - if ( !data ) - return -ENOMEM; + /* No method of finding microcode specified. Nothing to do. */ + return 0; + found: patch = ucode_ops.cpu_request_microcode(data, size, false); if ( IS_ERR(patch) ) { @@ -891,6 +888,15 @@ static int __init early_microcode_load(struct boot_info *bi) goto unmap; } + /* + * 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 platforms + * are known to update the BSP but leave the APs on older ucode. + */ + early_mod_idx = idx; + rc = microcode_update_cpu(patch, 0); unmap: From patchwork Mon Oct 28 09:18:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13853194 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5D638D1359E for ; Mon, 28 Oct 2024 09:19:28 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 The data pointer is known good, so the -ENOMEM path is unnecessary. However, 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 populate it. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monné 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); } -static int __init early_update_cache(const void *data, size_t len) -{ - int rc = 0; - struct microcode_patch *patch; - - if ( !data ) - return -ENOMEM; - - patch = 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 = 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 = -1; static int __init cf_check microcode_init_cache(void) { struct boot_info *bi = &xen_boot_info; + struct microcode_patch *patch; void *data; size_t size; int rc = 0; @@ -774,7 +748,24 @@ static int __init cf_check microcode_init_cache(void) size = cd.size; } - rc = early_update_cache(data, size); + patch = parse_blob(data, size); + if ( IS_ERR(patch) ) + { + rc = 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 == NULL); + microcode_cache = patch; + spin_unlock(µcode_mutex); return rc; }