From patchwork Tue Mar 7 22:41:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 65940 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp8577wrd; Tue, 7 Mar 2023 15:00:51 -0800 (PST) X-Google-Smtp-Source: AK7set8x3nyiQjKFtVHs5SGSWWUcN8K4Blmu9G6JmeW3EJrTe8mZhgs+kMCCsSl02N4oSeZdKTW/ X-Received: by 2002:a17:90a:53:b0:234:d1c:f112 with SMTP id 19-20020a17090a005300b002340d1cf112mr17153820pjb.0.1678230051032; Tue, 07 Mar 2023 15:00:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678230051; cv=none; d=google.com; s=arc-20160816; b=NSWgpd/JZB7sgwsBd4E2u4CqEsjR61xh8JW8mW11v7ZcocSzRzpnPSiNEfNDhJ+BK9 dWEjD6B6s1MPLvC5ZfaLaK50dgVZ4m5m5LfZDBNwPYcgJOeBNlDetDCOXkloW4wxtSYf eCA6wdubTNmvIoundpzZyArEXWg6CCxSe7kfqBMNLHYB9F/G2APBCR6UDjrvMCMHnmc2 IJipIVizNFa4tcjcxGXFWO7gqt2JjLykD8x3vdnTNXzzMOzZfA2SiWXHv7QreEIVvzeQ F6bXSFdstOfSj2NNtqNMx0rhkdip7Y555cEr7K9d8LOtLhkrWdcSJsQExGFfz1LIQWBe 08Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=fNE135kfip+/55i0Uctu9VE1eiRjfeodH4xQSM4wxck=; b=fzVI+qsJlma/9vLcehzjgihN7FQnDsIB3IIww5s+JMvG4zBzBjn1hKHCecWMgI4BFF ExDsXDzc/N2qPEu7TEltdqKKb/j2Fcoa0TImh8GEZh9P6L/snFlvjuNXX5bSJfj1IbKo XXoJURT+NirZBhQIkdBqJiev+OEPTf1rFrDglFOgetHphP8n+qbiM14PSahZfaFxfDmc g13RHAqtG/dtC0p8vWHXgE4neHKKPtUrxxplx7+6yZl/TUtdrYK8Q2ydI17NIdmBiKW2 Kjg53FJnfJSVyt57avZcbA6bpZoNW/5/jc9Y5EDupFxYHdGVEoZ42rz+n8Ye0E3Y9bxI 9/HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=AP0qFDjq; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ms2-20020a17090b234200b00234ba949302si15537768pjb.91.2023.03.07.15.00.27; Tue, 07 Mar 2023 15:00:51 -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=@linutronix.de header.s=2020 header.b=AP0qFDjq; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231694AbjCGWnC (ORCPT + 99 others); Tue, 7 Mar 2023 17:43:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231232AbjCGWmg (ORCPT ); Tue, 7 Mar 2023 17:42:36 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26F2559407; Tue, 7 Mar 2023 14:41:56 -0800 (PST) Date: Tue, 07 Mar 2023 22:41:30 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1678228890; h=from:from:sender:sender:reply-to: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: in-reply-to:in-reply-to:references:references; bh=fNE135kfip+/55i0Uctu9VE1eiRjfeodH4xQSM4wxck=; b=AP0qFDjqhVNIt/H65GJ8kqa3v+coTqM73tPhB++rb9PWWh0CCL0IWpZ+sYZ+ylw648E8jN bm4FUkbUeggQMn2lNhpBgh7HG3rgzEvTP05KrHnXRyeKkpiJnp4/eKPiAbK8NdqPxUNlE8 PCYMiakXn3IEh2bEnLntVfr/Mnkny1nxDLKg1VV95BjstOHzqLFLqGJYwRKO/TLvGyBD2Y RLNyl++UjQ5Wg2KzeA0c1ZhMPDO+eWnFrkreey2zY86XO95y9TVvDXsR9Q/Gw8F8bSRPFt D+bQrdXQlGNKQDf+/nrDf0WPhbjWC5t/+p+LNej6I00ACFQRbSf25QngwR/zYg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1678228890; h=from:from:sender:sender:reply-to: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: in-reply-to:in-reply-to:references:references; bh=fNE135kfip+/55i0Uctu9VE1eiRjfeodH4xQSM4wxck=; b=I/3uVJJD/bfgPvbsvQNtMLWYFu4V4sBMMWXJnnbOuJCNuLnxlalNAZEdllijS6zFXo35vb IFN8A+4eonmo+4Cg== From: "tip-bot2 for Borislav Petkov (AMD)" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/misc] tools/x86/kcpuid: Dump the CPUID function in detailed view Cc: "Borislav Petkov (AMD)" , Terry Bowman , Feng Tang , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230206141832.4162264-4-terry.bowman@amd.com> References: <20230206141832.4162264-4-terry.bowman@amd.com> MIME-Version: 1.0 Message-ID: <167822889002.5837.2464794663329420874.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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?1757092605429360719?= X-GMAIL-MSGID: =?utf-8?q?1759751754206423201?= The following commit has been merged into the x86/misc branch of tip: Commit-ID: cd3ad6619517cda3a055d864a85cebbd434dba9a Gitweb: https://git.kernel.org/tip/cd3ad6619517cda3a055d864a85cebbd434dba9a Author: Borislav Petkov (AMD) AuthorDate: Mon, 06 Feb 2023 08:18:32 -06:00 Committer: Borislav Petkov (AMD) CommitterDate: Tue, 07 Mar 2023 23:35:44 +01:00 tools/x86/kcpuid: Dump the CPUID function in detailed view Sometimes it is useful to know which CPUID leaf contains the fields so add it to -d output so that it looks like this: CPUID_0x8000001e_ECX[0x0]: extended_apic_id : 0x8 - Extended APIC ID core_id : 0x4 - Identifies the logical core ID threads_per_core : 0x1 - The number of threads per core is threads_per_core + 1 node_id : 0x0 - Node ID nodes_per_processor : 0x0 - Nodes per processor { 0: 1 node, else reserved } CPUID_0x8000001f_ECX[0x0]: sme - Secure Memory Encryption ... Signed-off-by: Borislav Petkov (AMD) Signed-off-by: Terry Bowman Reviewed-by: Feng Tang Link: https://lore.kernel.org/r/20230206141832.4162264-4-terry.bowman@amd.com --- tools/arch/x86/kcpuid/kcpuid.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/tools/arch/x86/kcpuid/kcpuid.c b/tools/arch/x86/kcpuid/kcpuid.c index dae7551..416f5b3 100644 --- a/tools/arch/x86/kcpuid/kcpuid.c +++ b/tools/arch/x86/kcpuid/kcpuid.c @@ -33,7 +33,7 @@ struct reg_desc { struct bits_desc descs[32]; }; -enum { +enum cpuid_reg { R_EAX = 0, R_EBX, R_ECX, @@ -41,6 +41,10 @@ enum { NR_REGS }; +static const char * const reg_names[] = { + "EAX", "EBX", "ECX", "EDX", +}; + struct subleaf { u32 index; u32 sub; @@ -428,12 +432,18 @@ static void parse_text(void) /* Decode every eax/ebx/ecx/edx */ -static void decode_bits(u32 value, struct reg_desc *rdesc) +static void decode_bits(u32 value, struct reg_desc *rdesc, enum cpuid_reg reg) { struct bits_desc *bdesc; int start, end, i; u32 mask; + if (!rdesc->nr) { + if (show_details) + printf("\t %s: 0x%08x\n", reg_names[reg], value); + return; + } + for (i = 0; i < rdesc->nr; i++) { bdesc = &rdesc->descs[i]; @@ -468,13 +478,21 @@ static void show_leaf(struct subleaf *leaf) if (!leaf) return; - if (show_raw) + if (show_raw) { leaf_print_raw(leaf); + } else { + if (show_details) + printf("CPUID_0x%x_ECX[0x%x]:\n", + leaf->index, leaf->sub); + } + + decode_bits(leaf->eax, &leaf->info[R_EAX], R_EAX); + decode_bits(leaf->ebx, &leaf->info[R_EBX], R_EBX); + decode_bits(leaf->ecx, &leaf->info[R_ECX], R_ECX); + decode_bits(leaf->edx, &leaf->info[R_EDX], R_EDX); - decode_bits(leaf->eax, &leaf->info[R_EAX]); - decode_bits(leaf->ebx, &leaf->info[R_EBX]); - decode_bits(leaf->ecx, &leaf->info[R_ECX]); - decode_bits(leaf->edx, &leaf->info[R_EDX]); + if (!show_raw && show_details) + printf("\n"); } static void show_func(struct cpuid_func *func)