From patchwork Wed Apr 26 09:41:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Borislav Petkov X-Patchwork-Id: 87780 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp122963vqo; Wed, 26 Apr 2023 02:58:42 -0700 (PDT) X-Google-Smtp-Source: AKy350bonBShnymGMVowZXnn2wT0XnS+S1Pu+guzBKvXOJSpg8Q3M/msOpZW77o7OfY+QyWoyLgR X-Received: by 2002:a17:902:e94c:b0:19e:6e00:4676 with SMTP id b12-20020a170902e94c00b0019e6e004676mr25050828pll.61.1682503122436; Wed, 26 Apr 2023 02:58:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682503122; cv=none; d=google.com; s=arc-20160816; b=FmuKOdqB7oZ6qYl6DVngr0nhPmSIGp+jcGqMDuGsW7ZzzYt6D9DeDT4RONpESuL2bo Cu8mDyxRUaAeVl6vkglJpTxoF3S/3+8PmT/NBikPJe7Qo4N/256w8ij3BPihgM/KOGN5 pOCD8aFB2yxDmR9LYTvcYPDrHqije5ecpru4tL+sOzH1q2wFLVRKYLXGyGEa2pXmxFf7 T4jjKQRGBFuVNKHtcTZVhAu3Ua88QWtXempV+mv+KywHlCrrGp3HGG57Lv07c4HkKriS TSue2qu6RVDGzvyNDvEoQWLUzTiE3xmDJbmf11NXfQPbz/jFZW8x1yh0ZOOMrYJUqyq7 5NxQ== 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=uziZ0nC95pE1bmYPqhWD9tTWtuuxLYKpfD3KPfIloxo=; b=zfVio6MUyfOPnqtFnlyQljXH6+5I9LW0C4/WVX/GYcIdC0H4DxG68d+Ai+HRCx7NXx BdgNU6k6nipbx57sYPmrrMZbYbZArXnRzWwtMDm/OX55q8vYJ4YDJc9tsE/wK243ZTfq lb1+WT3cWnuMxK/55yIDPyQvJXoz2rX3lCKm1g+u3fQpr1sZP9AN+mYj+WPOQ5OvK35f h1gQUXn7jh0/C2ppOXL0XrSSeiySgezPVNGZEa5JyQkKj9bCQgLXLvm/8RwhUCcJVpKr fPnn7uURE2AtbWVCuY/i4W6vywTgop+SfHqgudFXU16JA4VAs9yT+kXgF90sWVDD5G3p NHTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=nPihICyT; 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 p8-20020a170902e74800b001a966042af8si9932320plf.341.2023.04.26.02.58.27; Wed, 26 Apr 2023 02:58:42 -0700 (PDT) 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=nPihICyT; 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 S240267AbjDZJl3 (ORCPT + 99 others); Wed, 26 Apr 2023 05:41:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240310AbjDZJlW (ORCPT ); Wed, 26 Apr 2023 05:41:22 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C08E630EB for ; Wed, 26 Apr 2023 02:41:18 -0700 (PDT) Received: from zn.tnic (p5de8e8ea.dip0.t-ipconnect.de [93.232.232.234]) (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 3670F1EC0441; Wed, 26 Apr 2023 11:41:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1682502077; 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=uziZ0nC95pE1bmYPqhWD9tTWtuuxLYKpfD3KPfIloxo=; b=nPihICyT4GyugLPX3j1YerlXclryfdX7mVnvh3a0Q4EtCgy9KlM7SJ4WRobaSX7ZUbLsND gMkHstXqXs0co0xOr3pJFH48x7g6ZSYnL6QueQPlRsekFa+XxAdZBgGM53Ughca1sCVUmM 3CZp1awn9g4jn/s/P+B/Onphs4jTIcI= From: Borislav Petkov To: X86 ML Cc: LKML Subject: [PATCH] tools/x86/kcpuid: Dump the correct CPUID function in error Date: Wed, 26 Apr 2023 11:41:07 +0200 Message-Id: <20230426094107.27348-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, T_SCC_BODY_TEXT_LINE,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?1764232394008301476?= X-GMAIL-MSGID: =?utf-8?q?1764232394008301476?= From: "Borislav Petkov (AMD)" The tool uses the 16 least significant bits of the CPUID leaf as an index into its array of CPUID function field descriptions. However, when that index is non-existent, it uses the same, truncated index to report it, which is wrong: $ kcpuid -l 0x80000034 ERR: invalid input index (0x34) Use the original index number in the error message. Signed-off-by: Borislav Petkov (AMD) --- tools/arch/x86/kcpuid/kcpuid.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/arch/x86/kcpuid/kcpuid.c b/tools/arch/x86/kcpuid/kcpuid.c index 416f5b35dd8f..24b7d017ec2c 100644 --- a/tools/arch/x86/kcpuid/kcpuid.c +++ b/tools/arch/x86/kcpuid/kcpuid.c @@ -517,15 +517,16 @@ static void show_range(struct cpuid_range *range) static inline struct cpuid_func *index_to_func(u32 index) { struct cpuid_range *range; + u32 func_idx; range = (index & 0x80000000) ? leafs_ext : leafs_basic; - index &= 0x7FFFFFFF; + func_idx = index & 0xffff; - if (((index & 0xFFFF) + 1) > (u32)range->nr) { + if ((func_idx + 1) > (u32)range->nr) { printf("ERR: invalid input index (0x%x)\n", index); return NULL; } - return &range->funcs[index]; + return &range->funcs[func_idx]; } static void show_info(void)