From nobody Sat Mar 18 15:40:27 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Pf4vb57h0z3yjBP; Sat, 18 Mar 2023 15:40:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Pf4vb4V1gz4QLv; Sat, 18 Mar 2023 15:40:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679154027; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mtdarEQTuNyXaLDp5XRxpePzE7HyAE4mzuEAy2WzP3U=; b=Wy9rf69Ed2va3exbp/i8nRv4XWVXDiu6/nbn3dR+3xhFSW7xrM9mSyodtjTRtsGYOKfoFq lAh7QEmQlIpZCzk6ygt4rSrv47ZOdJUCtMme3MCpTVLFkdlRYRfEPD7PtLSAtN50SPqTwq CIasWaV3tHIlTntmppd8U3tBSuJugnlcMUwEswK1Jxc26SygTt1lwYyKoaLnrmwSZaE63i KOPZSPCOBvID1uBpQUhVC9ibp7jEjlZQ6SSeMiOCabyLe3isnrL4kEJNweEVSw0czyCji4 HvMEHg0gqzZlJeZA9xUABAeSla6qSQ1RJ8UBQD+E1307n+CMU30Oy1wgPN27lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679154027; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mtdarEQTuNyXaLDp5XRxpePzE7HyAE4mzuEAy2WzP3U=; b=Wb4nWZ4kBzSBGwROzpglHz/CgiqMZAc1XjdjUJ046Dkhld2MHgEBpm0uU6XEO8YjX7Su7s 2HwM+2j4NHlkyFby+42PD9s4z8QUKdRrRDttEDAU+J7ZIdeb82V9SCV1CwTkJxkXsOcE3L J0FR1FduZ0Bc2krwpHgHuuMqAWRVblwbterpdsBMgkOvCQikWNt99Sz/ckrXM04lThE7IP 8/E9Wc29/TGsnPkhtKDFfRQKT3Xpbioy5l2n3RL87l+vVEO4n9AHIvXU7FjpagxyN2GgSs CNjIaqjnWpRVfYcGWYtI5xh10GtQKW5fk5nYY+GO+TdclWfl7LPEPJ78uxXi0g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679154027; a=rsa-sha256; cv=none; b=aH4p56g7j9EduvpaWBc3T1A39FvdxMJE0kvJ1q88FD3qw5V+VExSZGB4P57JYbP3LsGpOv 5DGgD93+aO9mXFnI8sqBE6r/O659N6C1rBPIYcJcaFInWPfRWqEUiah88SEbIhp+8z5oan T3caoaIl9R8zU/VwhWcZiA2bUhJQXdXCgC6bv1x0rjvV6SFMOaLUs5FxhqL5msxpc7IQyY oS8FXJmE3ECUjdz1I1qEAamReuptkw5DsOlHRkIHReDvmmhjjaC+w/klFhIMadLNu5ZWVw gi4SXwIWMuCycMijaHn12Gc6M1KztHcb3C6T8xbaoBnIyBFW/hCD7IdG72eZ3w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Pf4vb3Wzkz1CL1; Sat, 18 Mar 2023 15:40:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32IFeRMj052612; Sat, 18 Mar 2023 15:40:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32IFeR0r052611; Sat, 18 Mar 2023 15:40:27 GMT (envelope-from git) Date: Sat, 18 Mar 2023 15:40:27 GMT Message-Id: <202303181540.32IFeR0r052611@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 02904a06c76b - main - amd64: properly recalculate mitigations knobs after resume List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 02904a06c76be857307b78184863654b9e7b88ab Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=02904a06c76be857307b78184863654b9e7b88ab commit 02904a06c76be857307b78184863654b9e7b88ab Author: Konstantin Belousov AuthorDate: 2023-03-17 13:02:03 +0000 Commit: Konstantin Belousov CommitDate: 2023-03-18 15:40:05 +0000 amd64: properly recalculate mitigations knobs after resume Revision r333125 AKA 986c4ca38772f72 forced clear cpu_stdext_feature3 on suspend, since at that time microcode update was not reloaded early on resume. Then, revision 050f5a8405c63 started re-reading cpu_stdext_feature3 again. Since modern CPUs do not require mitigations from the Skylake era, this went unnoticed for some time. Keep zeroing cpu_stdext_feature3 on suspend, but re-read it in more controlled way on resume after microcode is reloaded, and recalculate active workarounds based on actual microcode capabilities. Reported and tested by: romain Reviewed by: emaste, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D39146 --- sys/amd64/acpica/acpi_wakeup.c | 14 ++++++++++++++ sys/amd64/amd64/initcpu.c | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/sys/amd64/acpica/acpi_wakeup.c b/sys/amd64/acpica/acpi_wakeup.c index 9601a88e11a4..1afbdc3a3bec 100644 --- a/sys/amd64/acpica/acpi_wakeup.c +++ b/sys/amd64/acpica/acpi_wakeup.c @@ -288,6 +288,20 @@ acpi_wakeup_machdep(struct acpi_softc *sc, int state, int sleep_result, if (!CPU_EMPTY(&suspcpus)) resume_cpus(suspcpus); #endif + + /* + * Re-read cpu_stdext_feature3, which was zeroed-out + * in acpi_sleep_machdep, after the microcode was + * reloaded. Then recalculate the active mitigations + * knobs that depend on the microcode and + * cpu_stdext_feature3. + */ + identify_cpu_ext_features(); + hw_ibrs_recalculate(true); + hw_ssb_recalculate(true); + amd64_syscall_ret_flush_l1d_recalc(); + x86_rngds_mitg_recalculate(true); + mca_resume(); if (vmm_resume_p != NULL) vmm_resume_p(); diff --git a/sys/amd64/amd64/initcpu.c b/sys/amd64/amd64/initcpu.c index 16780a9e069b..8d4c9d9cbe64 100644 --- a/sys/amd64/amd64/initcpu.c +++ b/sys/amd64/amd64/initcpu.c @@ -313,7 +313,7 @@ initializecpu(void) } load_cr4(cr4); /* Reload cpu ext features to reflect cr4 changes */ - if (IS_BSP()) + if (IS_BSP() && cold) identify_cpu_ext_features(); if (IS_BSP() && (amd_feature & AMDID_NX) != 0) { msr = rdmsr(MSR_EFER) | EFER_NXE;