Received: by 2002:ab2:6991:0:b0:1f2:fff1:ace7 with SMTP id v17csp132884lqo; Wed, 27 Mar 2024 08:46:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX/sCHhOo6NqjSCYs0VK1YtgbqjC5mTIcnr7nz/ACCVvc53R6Tl0CECggjD90CTL2vkMxV26XQOqzmKm5iNzWWLfVpszdu/5uAV2UIUOA== X-Google-Smtp-Source: AGHT+IFFoiZalb0o7+DUvfeUQZQ+1ZqNX8LYeh9WE/3oVhqKokoBspXQ5q7GYza/h9zKd3kV3Yeo X-Received: by 2002:a17:906:f2cb:b0:a46:954a:aa14 with SMTP id gz11-20020a170906f2cb00b00a46954aaa14mr1327624ejb.67.1711554400085; Wed, 27 Mar 2024 08:46:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711554400; cv=pass; d=google.com; s=arc-20160816; b=hfwv4G61kSUOtGTDD2Hxa4pmhcZIsbZuotAAxIhvj7+TkK6KyJpnYDSuRVTLoQYMwI 6K276wGJtjzIbOt7/D6z/WQ32/lm2ef7cTQIL2qtKG91fU7XFzg9T+2/BUm+q5HV8xVN 4iRTmlYbYZ2HJcu1xNRBUfEIhGWw6z7859wZeoiZlOcBl0M9qgClykmVNIAgzqCWoN9x nifc0evJVagtsR8TxbZBfxg0wgfnhJB+V367lq6UixQ5WojojY7UK6G7ZeiI6T0gRSGa GC73DXncbspSwYXnEPUpianl7M0awkRn7jM/Eowm1SCQ4OtJb6CgQ+GQhtOYFFbn0Hsz hqig== ARC-Message-Signature: i=2; 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=cJi2ud/jDKqDCI8Q37OL9HLgpw81JXUyLlOPmVp4jb4=; fh=NOzzcwpGCCVd3KhMilQXeBbCRmtNVEnUdr1sER8Xt9E=; b=ElssnQCUQLrHRutPnDQVrXwKe+R8phAgfvvmtBLPuH/dTn6QarCM3eBvS6gN1PR0Ws ZkD9w44lDD2GbeaDk8hHQSY6bEe+wt3NgBDKkvGphdmcpQ3Ov2j2fW/KMecr/8Y97Foj /OmDWq8uGO3mhiM2/HTXALddffd5NuJhLXiw6wqrhAVidcvelvdcESgYSsGVnRekXDrY Lw8SNRfbcy+PExT6Ja5PEdBwZEjX+w44fDbNxERAdpeS9/dOsLljYBvc+l2i5bQhQZB/ BSeNLKCnSwaTGRpRiymI2kRequ/rTSQFkYrBOzoyH3B4ue3DaNVoiP5ZyoUYClRFjpV+ fzqA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=neutral (body hash did not verify) header.i=@alien8.de header.s=alien8 header.b="NW/3Jlhd"; arc=pass (i=1 spf=pass spfdomain=alien8.de dmarc=pass fromdomain=alien8.de); spf=pass (google.com: domain of linux-kernel+bounces-121556-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121556-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id d25-20020a170906175900b00a4694009900si4535061eje.341.2024.03.27.08.46.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 08:46:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-121556-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=neutral (body hash did not verify) header.i=@alien8.de header.s=alien8 header.b="NW/3Jlhd"; arc=pass (i=1 spf=pass spfdomain=alien8.de dmarc=pass fromdomain=alien8.de); spf=pass (google.com: domain of linux-kernel+bounces-121556-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121556-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alien8.de 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 924341F32EE0 for ; Wed, 27 Mar 2024 15:46:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EDB7E131724; Wed, 27 Mar 2024 15:44:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (4096-bit key) header.d=alien8.de header.i=@alien8.de header.b="NW/3Jlhd" Received: from mail.alien8.de (mail.alien8.de [65.109.113.108]) (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 E1DD913118D; Wed, 27 Mar 2024 15:43:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=65.109.113.108 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711554240; cv=none; b=gyUSWLWQefh49LsO62RZ4aTLWBHV0uLIdkNDc7bHYcuCcLFpJN9LnSwUBZwwxWSqeX47va+SHabPrSoG4ZQuu0DeTGxtpBb8KBBLowSC3RHw6kB67a/a9F9uRLDmFh42JZegp4542D0hYoYY8i6ge3KRWkBA+2TN5PHnoiqY7fI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711554240; c=relaxed/simple; bh=TBvqd4ujGjrA+OEG0n+syO68Cgjq1l9a/go8qjYx8ks=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uUvXglZ1OpqdgtoX+gp5Qej+UUImQn0IiDJtuymjuxCHWhZsI0Nc0rNpY3onnctv0ZRojmXaKEY0gWCdrlv47GRJotoVyAS/m9iURodE3Q8+SKR5K+Cz3hdj+WHwKI1ri4RDQth479yzfBK2qPYgoszo4r4Ev/kahA4BHp3XMic= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=alien8.de; spf=pass smtp.mailfrom=alien8.de; dkim=fail (4096-bit key) header.d=alien8.de header.i=@alien8.de header.b=NW/3Jlhd reason="signature verification failed"; arc=none smtp.client-ip=65.109.113.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=alien8.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=alien8.de Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTP id DA3DB40E02A8; Wed, 27 Mar 2024 15:43:55 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at mail.alien8.de Received: from mail.alien8.de ([127.0.0.1]) by localhost (mail.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id EGYJW5CSriZ3; Wed, 27 Mar 2024 15:43:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=alien8; t=1711554231; bh=bYojYaz3Qt0yOaxbHdC8/dOtftdqSFONlreqd9GBVqE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NW/3JlhdOPRTaKedcmBt9i6WTUS1ebSXGGgQOxu7MNK0FuJ7mujCBXPO/Sr3mhaHJ dBucxNkc5Xz7x/Qys/A4C4n2HSUEnhM/P0niLZDzyGq2/DcSlxe2XH0V+qoTs6trgh nxw+WEOOiR99SnMYXAyu2xfpinVuNaN3A4UPUYqnoKo2cmU1NI+y2Ck/ycL8QHDxnp TkEzsANFpxzclstlURZOV7Itn6ACnvKROY4kXdHJgWercHldVLmiE2FJNytrrULj87 a04Z/tGOqW55PwihKqDIq8dKSwOObD6/ilABk61PRIhEmQ0q256dvOTus4Yyyf5wA1 95bXmLW/393EwMJZOeT+uncG7W28mn+lEx6OvNQU7NnVIyB1WAwhjETAC+W1uzQypK 7Ensy5qVEH7Ui6vKG72O4h4lUIWmXSu7Vvl6VPiCdrotc+AlG7cgr1EWfqCb+ybzZg Li7GxDEY8upYKCABAphGi7ncNVrU5dPrbiZgeSnNaW3iSl4Ih8LUPZP2J2P9tDbFDY F6flNCDFxBtOgpDoe17dXJOl/6WtNWwJKulRRvm1TYyltdrwhYj1FffgE9u7j+TKME Fun30Wl3JTe08Bl+PzOqwdChj9G8APGu26fo4EtGGwFubIDPMNghqBhExHcLIt0Zhk unWwzKhm3wT0+EXw2bHaj2FI= Received: from zn.tnic (p5de8ecf7.dip0.t-ipconnect.de [93.232.236.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id DFE5540E02A5; Wed, 27 Mar 2024 15:43:43 +0000 (UTC) From: Borislav Petkov To: X86 ML Cc: LKML , KVM , Ashish Kalra , Joerg Roedel , Michael Roth , Tom Lendacky Subject: [PATCH 2/5] x86/alternatives: Catch late X86_FEATURE modifiers Date: Wed, 27 Mar 2024 16:43:14 +0100 Message-ID: <20240327154317.29909-3-bp@alien8.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240327154317.29909-1-bp@alien8.de> References: <20240327154317.29909-1-bp@alien8.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: "Borislav Petkov (AMD)" After alternatives have been patched, changes to the X86_FEATURE flags won't take effect and could potentially even be wrong. Warn about it. This is something which has been long overdue. Signed-off-by: Borislav Petkov (AMD) --- arch/x86/include/asm/cpufeature.h | 8 ++++++-- arch/x86/kernel/cpu/cpuid-deps.c | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpu= feature.h index 1ef620d508f4..d0b9c411144b 100644 --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h @@ -146,8 +146,12 @@ extern const char * const x86_bug_flags[NBUGINTS*32]= ; extern void setup_clear_cpu_cap(unsigned int bit); extern void clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit); =20 -#define setup_force_cpu_cap(bit) do { \ - set_cpu_cap(&boot_cpu_data, bit); \ +#define setup_force_cpu_cap(bit) do { \ + \ + if (!boot_cpu_has(bit)) \ + WARN_ON(alternatives_patched); \ + \ + set_cpu_cap(&boot_cpu_data, bit); \ set_bit(bit, (unsigned long *)cpu_caps_set); \ } while (0) =20 diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid= -deps.c index b7174209d855..5dd427c6feb2 100644 --- a/arch/x86/kernel/cpu/cpuid-deps.c +++ b/arch/x86/kernel/cpu/cpuid-deps.c @@ -114,6 +114,9 @@ static void do_clear_cpu_cap(struct cpuinfo_x86 *c, u= nsigned int feature) if (WARN_ON(feature >=3D MAX_FEATURE_BITS)) return; =20 + if (boot_cpu_has(feature)) + WARN_ON(alternatives_patched); + clear_feature(c, feature); =20 /* Collect all features to disable, handling dependencies */ --=20 2.43.0