From patchwork Mon Nov 7 21:15:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Borislav Petkov X-Patchwork-Id: 16726 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2304782wru; Mon, 7 Nov 2022 13:26:24 -0800 (PST) X-Google-Smtp-Source: AMsMyM6+u9g3QXD+tiqEv7sYB93dfjuJe+zMoI161ZbNVOXM0sEtn6MIwu7mJjxvq08WPYTLCIAy X-Received: by 2002:a05:6402:274c:b0:461:9921:60cf with SMTP id z12-20020a056402274c00b00461992160cfmr53118073edd.353.1667856384786; Mon, 07 Nov 2022 13:26:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667856384; cv=none; d=google.com; s=arc-20160816; b=rl/5Ahffcx0+xpwDbxjKumirn9Jkiocy6WHAIABhMm+wz+AwsTgXZo1YPHQP6C5qEl ELggAdG6OEZIkYn901AFQyUBvVX6/lCpR/7TOIsOZVF7s3iSowEYR7DlVH8vdP5pQR4E FwOvZ1otKZrVhfy36rcDeS038Hydtw5e0/wS5aJYYxewJUhLC9ThrHa8cm7l/43O4Pv3 4bisnNuYlIBjvvX4F0gTcxWOp9AnO71iRyy8eoR3xCQ722Z0Mid33THHH2HT/WOLkrn0 1l7U5wxcqO+QNo+M+7lvkmF/YUgdsJ5tKDrCgeDaZcBLnIkVVjZIZjw1gKi/e2opOsZT q84A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=rbOTxD9ZKYlilVo5kI9gEidbFcfzuiyGtj4TcpECXu8=; b=HIdmrOYTLdzlg+KUetgwwyZ4iOSux1zYonE1rlL2cQL3OgfVkXMKFEYeImy2CdrT+Z YZVh7SvXCIYtlgTdm7OlJ3bmdRYNpN5z6o6mCYBdP52cpTNvzer1H3jindGVZyUCGsu5 U76k8E4uHG33tJAMvZ659o0im6tS45r1xPMYmPRyHEPRsNJnpeh6V6CbzrsYAnvuNBU7 dFcYmMcadRhZ5pz9RJaZo9XBcX/5IITzAQIH6m3N4u8z/FAZoejAAkWWYMhaBIpAsJv0 AvKOSKig4o7iZNBa2QRKrkpfNtiKhdIBPbl06QU6S63HbFfs7lqecimr+8rg5XMMEJU0 GtGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=DDfYNpFe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp20-20020a1709073e1400b0073da4a0f01csi10477253ejc.743.2022.11.07.13.26.00; Mon, 07 Nov 2022 13:26:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=DDfYNpFe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232851AbiKGVS5 (ORCPT + 99 others); Mon, 7 Nov 2022 16:18:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233619AbiKGVSP (ORCPT ); Mon, 7 Nov 2022 16:18:15 -0500 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2909326C7 for ; Mon, 7 Nov 2022 13:15:18 -0800 (PST) Received: from zn.tnic (p200300ea9733e764329c23fffea6a903.dip0.t-ipconnect.de [IPv6:2003:ea:9733:e764:329c:23ff:fea6:a903]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 509E71EC059D; Mon, 7 Nov 2022 22:15:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1667855717; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=rbOTxD9ZKYlilVo5kI9gEidbFcfzuiyGtj4TcpECXu8=; b=DDfYNpFeTRMchdM0zB46lZpL48UYZdZzPzivVPw4P3pVwGaS3U8nPQgcgud1I4aocQ9CVV bAh2I6THf6v173aVuwdcmsXeaMGL5e5d9Qum20MRkjY+D0ba2ogrT9DGkSZm+gork34ZpF iszaL1Q3Tbr4CPSeLcOVoXoi3tkL1KU= From: Borislav Petkov To: X86 ML Cc: LKML Subject: [PATCH] x86/cpu: Start documenting what the X86_FEATURE_ flag testing macros do Date: Mon, 7 Nov 2022 22:15:05 +0100 Message-Id: <20221107211505.8572-1-bp@alien8.de> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748874176541303177?= X-GMAIL-MSGID: =?utf-8?q?1748874176541303177?= From: Borislav Petkov ... and how and when they should be used. This keeps popping up everytime people start poking at the CPU features testing machinery - which has admittedly grown some warts and would need cleaning up - or when they are wondering what function/macro to use. Start documenting it first. Proper cleanup will follow once all the functionality has been agreed upon. No functional changes. Signed-off-by: Borislav Petkov Link: https://lore.kernel.org/r/20220718141123.136106-3-mlevitsk@redhat.com --- arch/x86/include/asm/cpufeature.h | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h index 1a85e1fb0922..47ff025e7387 100644 --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h @@ -131,12 +131,13 @@ extern const char * const x86_bug_flags[NBUGINTS*32]; (unsigned long __percpu *)&cpu_info.x86_capability)) /* - * This macro is for detection of features which need kernel - * infrastructure to be used. It may *not* directly test the CPU - * itself. Use the cpu_has() family if you want true runtime - * testing of CPU features, like in hypervisor code where you are - * supporting a possible guest feature where host support for it - * is not relevant. + * This is the preferred macro to use when testing X86_FEATURE_ bits + * support without the need to test on a particular CPU but rather + * system-wide. It takes into account build-time disabled feature + * support too. All those macros mirror the kernel's idea of enabled + * CPU features and not necessarily what real, hardware CPUID bits are + * set or clear. For that use tools/arch/x86/kcpuid/ and/or potentially + * extend if it's feature list is lacking. */ #define cpu_feature_enabled(bit) \ (__builtin_constant_p(bit) && DISABLED_MASK_BIT_SET(bit) ? 0 : static_cpu_has(bit)) @@ -145,9 +146,15 @@ extern const char * const x86_bug_flags[NBUGINTS*32]; #define set_cpu_cap(c, bit) set_bit(bit, (unsigned long *)((c)->x86_capability)) -extern void setup_clear_cpu_cap(unsigned int bit); extern void clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit); +/* + * The setup_* prefixed variants enable/disable feature bits on all + * CPUs in the system and are used to replicate those settings before + * apply_forced_caps() has synthesized enabled and disabled bits across + * every CPU. + */ +extern void setup_clear_cpu_cap(unsigned int bit); #define setup_force_cpu_cap(bit) do { \ set_cpu_cap(&boot_cpu_data, bit); \ set_bit(bit, (unsigned long *)cpu_caps_set); \