From patchwork Thu Jan 25 14:19:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 192091 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6359:bb0:b0:176:abc2:f11e with SMTP id gf48csp264865rwb; Thu, 25 Jan 2024 06:19:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IEctjlwRc5CooJRiEsRFniVHKl/SRdHC3DvJi8qY16yBb/LrW33tVQL/chxt/BprhQxxD61 X-Received: by 2002:a05:622a:345:b0:42a:4391:b13b with SMTP id r5-20020a05622a034500b0042a4391b13bmr2134484qtw.11.1706192368188; Thu, 25 Jan 2024 06:19:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706192368; cv=pass; d=google.com; s=arc-20160816; b=pg3aIc6JO49pIjOUusFq8zdA/94Yw20D9D0NeNugSKpq5eFmEezognJDlAAI7ZDR29 Cd966Yv1Dsc3rGax9YHwNOSA2cgI3eKxSQv4UWLCrGRVULofFovHPnsQ2fV+w+fN8p0/ S7pV+Q72wRYxS0BPqV99eEXxFZBEE6ECIAcTdMDV6B1obSIUhlsyPljlThSdJSPGeiVl 55Pibx2ENbAQNAsmr3DYgvq+Yo5hmXW3H4WegpGSVgobHD+KKSCXDHtWjFeVnNvc8XbS YMMsZA+ydVFk1l327WqkqD0gb39uhT+pMYmRNd24B5P3cvyJqoyNc2fK+tx4qBhEHrJ6 7usg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date :dkim-signature; bh=c/2WeWW2Fn5yg1GPwUuNDTXsVqVeRnV+qWCrViUMXrM=; fh=XzIZHT/rMHxVb77YyyJHO/dIYBweNPivQdR5caLx10w=; b=khExVcRHgQ9FG53KEtAkh5L/zDDd7B51Fa7i7VccdOr9oP0vtPud1uc/uVhH8zGp2f YDxaKfVrXXP2nfNXrtp3Qs+Bbywb/XlVHfuiq/sccOWKdSNYyMSj3TYitLZaa3BiGIT5 oWr1I0yM73G0lM+njA3OP/GXy7YSDNokV2wKNyggckqaFqoCIZZGT7i7/mlYId7pJpgK yicc3iChn9KMLrQ5eUF4WfVwcs3pStZiJ65ONb7qmvtdboigS8R8l4SQYhvzLWtNUHwr /uZidpTsWqPAB4WnWgNNK5ukhWwAU9zOwf8Nl9BhBssqEyf/IstziBFIo24pJLCbZQQv q7kQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JAWUBONj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-38713-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38713-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id w21-20020ac87e95000000b0042a51526bd6si5967418qtj.153.2024.01.25.06.19.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 06:19:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38713-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JAWUBONj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-38713-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38713-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id EE8081C23EFD for ; Thu, 25 Jan 2024 14:19:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 63F72634E9; Thu, 25 Jan 2024 14:19:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JAWUBONj" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5BEAB633F4 for ; Thu, 25 Jan 2024 14:19:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706192351; cv=none; b=bMEE1OwKGeCQvTReoQnoKynqeg3ztRFqBZyshF5z01jjJQob6+LfvgFzbLETH5tROYA5vZLVCzeSqV6MQEtXv8h7Rg/1hY74LZw7g6wIPeKdhqwXNMifHzrUI6eKZ/x5g+tptW0dTg6PmOrf270Mv/D3mRnf1T5fMVzebrsYxn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706192351; c=relaxed/simple; bh=1bLUIWpLx127mVujO9y94HqM7q9CrpLnMA+IDBr6PB4=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=V8tClv4XQfjgq+KSRDhQ4VgKUwoLFXDoK4jAql+fVxELRE/X45Wzl947gnMl7utGL0lZmwhe5anAzL4uBuTjEdtxeJBPGkileYzTmCRb7x03CBedOicoQQtfiGE6yY9arFh3XkbMjbj0gfE2FM1iHsCA0wqYWFO4toOK6NRDD54= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JAWUBONj; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EA52C433F1; Thu, 25 Jan 2024 14:19:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706192350; bh=1bLUIWpLx127mVujO9y94HqM7q9CrpLnMA+IDBr6PB4=; h=Date:From:To:Cc:Subject:From; b=JAWUBONjkjLchI5bTMkiSMuT3gdFgIHAczdIa1jWRvnuqlMfVLsFz7NfdN9sVrZ9b +nBL1LN2mIHfPODXJa4KhQ/z/dYmuoipXUkvhKmmUYUHilfqxvKLxCP8nMjgjCkfXi DqToFe2Ec914wQGoMAzT8qVctPVzmpIaFsNFaXNiHkBzvc9jUO9/ueiJx8TbBftYND tSA5Y+zGt82IfiZUEqOHCfhUpwubOnsP6F4lOkIEGWh5XGU4eQf4y+HMajUJNfcIxU 3q5TNMlK4s7gr6BqfMNWkg9hu4vqDA8nD4NRT39KVnzr9sywJGZVCq9ycFnRWxy8yq AZdXMrhyZMbLA== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id DC10C405B2; Thu, 25 Jan 2024 11:19:07 -0300 (-03) Date: Thu, 25 Jan 2024 11:19:07 -0300 From: Arnaldo Carvalho de Melo To: linux-kernel@vger.kernel.org Cc: Adrian Hunter , Dave Hansen , Ian Rogers , Jiri Olsa , Kai Huang , Namhyung Kim Subject: [PATCH 1/1 FYI] tools arch x86: Sync the msr-index.h copy with the kernel sources to pick IA32_MKTME_KEYID_PARTITIONING Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789072369018552820 X-GMAIL-MSGID: 1789072369018552820 tldr; Just FYI, I'm carrying this on the perf tools tree. - Arnaldo Full explanation: There used to be no copies, with tools/ code using kernel headers directly. From time to time tools/perf/ broke due to legitimate kernel hacking. At some point Linus complained about such direct usage. Then we adopted the current model. The way these headers are used in perf are not restricted to just including them to compile something. There are sometimes used in scripts that convert defines into string tables, etc, so some change may break one of these scripts, or new MSRs may use some different #define pattern, etc. E.g.: $ ls -1 tools/perf/trace/beauty/*.sh | head -5 tools/perf/trace/beauty/arch_errno_names.sh tools/perf/trace/beauty/drm_ioctl.sh tools/perf/trace/beauty/fadvise.sh tools/perf/trace/beauty/fsconfig.sh tools/perf/trace/beauty/fsmount.sh $ $ tools/perf/trace/beauty/fadvise.sh static const char *fadvise_advices[] = { [0] = "NORMAL", [1] = "RANDOM", [2] = "SEQUENTIAL", [3] = "WILLNEED", [4] = "DONTNEED", [5] = "NOREUSE", }; $ The tools/perf/check-headers.sh script, part of the tools/ build process, points out changes in the original files. So its important not to touch the copies in tools/ when doing changes in the original kernel headers, that will be done later, when check-headers.sh inform about the change to the perf tools hackers. --- To pick up the changes in: 765a0542fdc7aad7 ("x86/virt/tdx: Detect TDX during kernel boot") Addressing this tools/perf build warning: Warning: Kernel ABI header differences: diff -u tools/arch/x86/include/asm/msr-index.h arch/x86/include/asm/msr-index.h That makes the beautification scripts to pick some new entries: $ tools/perf/trace/beauty/tracepoints/x86_msr.sh > before $ cp arch/x86/include/asm/msr-index.h tools/arch/x86/include/asm/msr-index.h $ tools/perf/trace/beauty/tracepoints/x86_msr.sh > after $ diff -u before after --- before 2024-01-25 11:08:12.363223880 -0300 +++ after 2024-01-25 11:08:24.839307699 -0300 @@ -21,6 +21,7 @@ [0x0000004f] = "PPIN", [0x00000060] = "LBR_CORE_TO", [0x00000079] = "IA32_UCODE_WRITE", + [0x00000087] = "IA32_MKTME_KEYID_PARTITIONING", [0x0000008b] = "AMD64_PATCH_LEVEL", [0x0000008C] = "IA32_SGXLEPUBKEYHASH0", [0x0000008D] = "IA32_SGXLEPUBKEYHASH1", $ Now one can trace systemwide asking to see backtraces to where that MSR is being read/written, see this example with a previous update: # perf trace -e msr:*_msr/max-stack=32/ --filter="msr==IA32_MKTME_KEYID_PARTITIONING" ^C# If we use -v (verbose mode) we can see what it does behind the scenes: # perf trace -v -e msr:*_msr/max-stack=32/ --filter="msr==IA32_MKTME_KEYID_PARTITIONING" Using CPUID GenuineIntel-6-8E-A 0x87 New filter for msr:read_msr: (msr==0x87) && (common_pid != 58627 && common_pid != 3792) 0x87 New filter for msr:write_msr: (msr==0x87) && (common_pid != 58627 && common_pid != 3792) mmap size 528384B ^C# Example with a frequent msr: # perf trace -v -e msr:*_msr/max-stack=32/ --filter="msr==IA32_SPEC_CTRL" --max-events 2 Using CPUID AuthenticAMD-25-21-0 0x48 New filter for msr:read_msr: (msr==0x48) && (common_pid != 2612129 && common_pid != 3841) 0x48 New filter for msr:write_msr: (msr==0x48) && (common_pid != 2612129 && common_pid != 3841) mmap size 528384B Looking at the vmlinux_path (8 entries long) symsrc__init: build id mismatch for vmlinux. Using /proc/kcore for kernel data Using /proc/kallsyms for symbols 0.000 Timer/2525383 msr:write_msr(msr: IA32_SPEC_CTRL, val: 6) do_trace_write_msr ([kernel.kallsyms]) do_trace_write_msr ([kernel.kallsyms]) __switch_to_xtra ([kernel.kallsyms]) __switch_to ([kernel.kallsyms]) __schedule ([kernel.kallsyms]) schedule ([kernel.kallsyms]) futex_wait_queue_me ([kernel.kallsyms]) futex_wait ([kernel.kallsyms]) do_futex ([kernel.kallsyms]) __x64_sys_futex ([kernel.kallsyms]) do_syscall_64 ([kernel.kallsyms]) entry_SYSCALL_64_after_hwframe ([kernel.kallsyms]) __futex_abstimed_wait_common64 (/usr/lib64/libpthread-2.33.so) 0.030 :0/0 msr:write_msr(msr: IA32_SPEC_CTRL, val: 2) do_trace_write_msr ([kernel.kallsyms]) do_trace_write_msr ([kernel.kallsyms]) __switch_to_xtra ([kernel.kallsyms]) __switch_to ([kernel.kallsyms]) __schedule ([kernel.kallsyms]) schedule_idle ([kernel.kallsyms]) do_idle ([kernel.kallsyms]) cpu_startup_entry ([kernel.kallsyms]) secondary_startup_64_no_verify ([kernel.kallsyms]) # Cc: Adrian Hunter Cc: Dave Hansen Cc: Ian Rogers Cc: Jiri Olsa Cc: Kai Huang Cc: Namhyung Kim Link: https://lore.kernel.org/lkml/ Signed-off-by: Arnaldo Carvalho de Melo --- tools/arch/x86/include/asm/msr-index.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/arch/x86/include/asm/msr-index.h b/tools/arch/x86/include/asm/msr-index.h index 1d51e1850ed03d46..f1bd7b91b3c63735 100644 --- a/tools/arch/x86/include/asm/msr-index.h +++ b/tools/arch/x86/include/asm/msr-index.h @@ -237,6 +237,11 @@ #define LBR_INFO_CYCLES 0xffff #define LBR_INFO_BR_TYPE_OFFSET 56 #define LBR_INFO_BR_TYPE (0xfull << LBR_INFO_BR_TYPE_OFFSET) +#define LBR_INFO_BR_CNTR_OFFSET 32 +#define LBR_INFO_BR_CNTR_NUM 4 +#define LBR_INFO_BR_CNTR_BITS 2 +#define LBR_INFO_BR_CNTR_MASK GENMASK_ULL(LBR_INFO_BR_CNTR_BITS - 1, 0) +#define LBR_INFO_BR_CNTR_FULL_MASK GENMASK_ULL(LBR_INFO_BR_CNTR_NUM * LBR_INFO_BR_CNTR_BITS - 1, 0) #define MSR_ARCH_LBR_CTL 0x000014ce #define ARCH_LBR_CTL_LBREN BIT(0) @@ -536,6 +541,9 @@ #define MSR_RELOAD_PMC0 0x000014c1 #define MSR_RELOAD_FIXED_CTR0 0x00001309 +/* KeyID partitioning between MKTME and TDX */ +#define MSR_IA32_MKTME_KEYID_PARTITIONING 0x00000087 + /* * AMD64 MSRs. Not complete. See the architecture manual for a more * complete list.