Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp444145rdb; Mon, 15 Jan 2024 02:22:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IFXvISXLvSyc7lidnyV5D98cHdYSCK28klwwk9taBd3QtTGN7UZB47QiF90DQXrJUKLWRU9 X-Received: by 2002:a17:907:c719:b0:a2c:2cef:2542 with SMTP id ty25-20020a170907c71900b00a2c2cef2542mr5949643ejc.16.1705314137976; Mon, 15 Jan 2024 02:22:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705314137; cv=none; d=google.com; s=arc-20160816; b=UWD5MqeoklguQ+6xgSeL5nwZhuPJJgL74PCpBc/xs3lTQl1G71dIAhd4xbmt/AXSCw m2Q/W3Zg13Ng8txHzs3yoq87gbt/2QQ/lU7hLr7RbkzXLzUtevVQ0jeD7MHXlIh8/gCO KPwU/D5IBEj/8K0dBu3c607rodLAcd+R68xCIR0Kfze/skkDprMpnkRUu+izg5HyiGMu XwEwNGstw1sIoo/ypSfKCLaTQ7T4W6dFTalaZBEgGeCrSOxNvds8cIvClJip8IjJAK+1 hO7fFOZFHPVd+E7wPdaFktGYakSXj03vReXOW0IxkgflnMjpQcYcf+rRO9YISgcj/67j roig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=K4+D1x6d473u1B/OH3x1vFCMppzL+VsC3/Prb9EM8Ro=; fh=o76LsYmeQyX9msE3QKWY7Q9y4QCUKzUrW+xDoJ1Vj0k=; b=gKdAj19xQ3LWsnizUiTfQ2ZnoKl4wYqJB6NNV7aKy5ZkCiuDeBn/yGIxKCPd40tl16 SSpn75v+dOh2xXmJIJ/1JjXkZu6dQD7nfugQBKleILG4Y3XlMRzmgfqZyGvdZnTzKbdk AxTRD6/4o/LgFd7utDW1SduopxE4qCXabVtktSmz84u/BoKndKLEKTIEYGxOeVoERft8 Q9eyZJqjTHcjC6DHJ3wa5VVUNOQPjiqY3kjAM5zx2TDdQalS6mGDU6x96hl3/TbJ+7uT Zk/UIwfeVOrm+USO7uirbRe6IKZz8dbUfEgL/JRalUSE3bQ+g0nKUUvSvXjkHAXrBxxK Wq5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=biefZFFw; spf=pass (google.com: domain of linux-kernel+bounces-25877-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25877-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id n11-20020a170906b30b00b00a28de829801si3537700ejz.819.2024.01.15.02.22.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 02:22:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25877-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=biefZFFw; spf=pass (google.com: domain of linux-kernel+bounces-25877-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25877-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B82EA1F220A0 for ; Mon, 15 Jan 2024 10:22:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7BE1C101CA; Mon, 15 Jan 2024 10:22:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="biefZFFw" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12E83F9F5 for ; Mon, 15 Jan 2024 10:22:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705314127; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=K4+D1x6d473u1B/OH3x1vFCMppzL+VsC3/Prb9EM8Ro=; b=biefZFFwM2sHHUaUwSnyeR7ExGOe358glOSFtWJr84wEgkTbme+s77gvgd0ZreAXXwanVg UUCcaogtnpaTIm+uKBFMh8YeNn96V2DpxkxvflxhVSuyh6ifagiBnWIR2hotJfLDtIpQrr oTvsJJKMySdcSXiAMQg5TUBgkqiptzQ= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-639-4FkQHVEHNc-PznCFBskzPA-1; Mon, 15 Jan 2024 05:22:06 -0500 X-MC-Unique: 4FkQHVEHNc-PznCFBskzPA-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a2c20945b80so586532166b.0 for ; Mon, 15 Jan 2024 02:22:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705314124; x=1705918924; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=K4+D1x6d473u1B/OH3x1vFCMppzL+VsC3/Prb9EM8Ro=; b=pMyp/od68/Dpnf8Ynyeq+Io+4dYfi+/7DlTKWoFyC3uZKdzH4UDXZ5j1YwllkE/5SA pzkHuNd7h7eeSueUN6P0MI6Q+D5583bO82dVI3vkjRFWAmMMjwT5vTCaIFcVnE3wB/Bm ezF57YAHPJuYHWb23sHDPmyOTiRwV4oekJYUqLIVHg6Nq7Whc0qUane6wyj2S9OQ7XUK 1OTQGPXBwRJ9S8SeRm7oWJ54+lTRWAPY86dKmGVzaw2nEKIKiNV4nsFTw1xuibWtrr1H /Skyw2gO4wwgGRqru3JKbQoDArFzPCRW4tmnpBDc4A648DiuHGgYvv9AkKGvipYREryR 3CaA== X-Gm-Message-State: AOJu0YyMkFkZCrwt04vVCppQuHoL5MjiofPFTn0YyAkQXlg56NLEXPi5 fPOfWme90XfoCEMx4c64IKpOiBUvJ+3yGD04iOKFnTsurRitF6C9HfpTsuL0Blv2HAKLnCKtCTf QeLzdE9zIcDUlRERWflqUI9RebeHRYajJ4w4RM/8DB5pGkW+aWF5elqxKvkS6T5kLNLydMgQ91j 5uoCWzk4vGow7gzZ/P X-Received: by 2002:a17:906:2304:b0:a29:905d:1815 with SMTP id l4-20020a170906230400b00a29905d1815mr5191195eja.60.1705314124095; Mon, 15 Jan 2024 02:22:04 -0800 (PST) X-Received: by 2002:a17:906:2304:b0:a29:905d:1815 with SMTP id l4-20020a170906230400b00a29905d1815mr5191179eja.60.1705314123650; Mon, 15 Jan 2024 02:22:03 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id f11-20020a170906084b00b00a2c32b6053dsm5110933ejd.166.2024.01.15.02.22.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 02:22:02 -0800 (PST) From: Paolo Bonzini To: linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org, x86@kernel.org, Borislav Petkov , Dave Hansen Subject: [PATCH stable] x86/microcode: do not cache microcode if it will not be used Date: Mon, 15 Jan 2024 11:22:02 +0100 Message-ID: <20240115102202.1321115-1-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [ Upstream commit a7939f01672034a58ad3fdbce69bb6c665ce0024 ] Builtin/initrd microcode will not be used the ucode loader is disabled. But currently, save_microcode_in_initrd is always performed and it accesses MSR_IA32_UCODE_REV even if dis_ucode_ldr is true, and in particular even if X86_FEATURE_HYPERVISOR is set; the TDX module does not implement the MSR and the result is a call trace at boot for TDX guests. Mainline Linux fixed this as part of a more complex rework of microcode caching that went into 6.7 (see in particular commits dd5e3e3ca6, "x86/microcode/intel: Simplify early loading"; and a7939f0167203, "x86/microcode/amd: Cache builtin/initrd microcode early"). Do the bare minimum in stable kernels, setting initrd_gone just like mainline Linux does in mark_initrd_gone(). Note that save_microcode_in_initrd() is not in the microcode application path, which runs with paging disabled on 32-bit systems, so it can (and has to) use dis_ucode_ldr instead of check_loader_disabled_ap(). Cc: stable@vger.kernel.org # v6.6+ Cc: x86@kernel.org # v6.6+ Cc: Borislav Petkov Cc: Dave Hansen Signed-off-by: Paolo Bonzini --- arch/x86/kernel/cpu/microcode/core.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c index 35d39a13dc90..503b5da56685 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -214,6 +214,11 @@ static int __init save_microcode_in_initrd(void) struct cpuinfo_x86 *c = &boot_cpu_data; int ret = -EINVAL; + if (dis_ucode_ldr) { + ret = 0; + goto out; + } + switch (c->x86_vendor) { case X86_VENDOR_INTEL: if (c->x86 >= 6) @@ -227,6 +230,7 @@ static int __init save_microcode_in_initrd(void) break; } +out: initrd_gone = true; return ret; -- 2.43.0