From nobody Sat Feb 7 17:42:23 2026 Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazon11010002.outbound.protection.outlook.com [52.101.193.2]) (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 41E8E299AB1 for ; Thu, 29 Jan 2026 14:44:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.193.2 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769697886; cv=fail; b=ND0uxT/fzuQze57w7buDuzJmuzhxcehNgpRWLvSfsFALUPzvn1hgigNA6mDRmC4CNeF6FFzMslpkqgvb+LPf5jUdxiYKEpuZjdrzgjTjBEuk5fn8TYnExNT78yXP9UIduRXOifmNAU8uFJv1tg9OJe9NfNxwT5XspGhXSj0Knxw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769697886; c=relaxed/simple; bh=wW/01NZFHhF5WxTmL0OFyGxMgheZrWIxz5JxBSWj4ZU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=D4nVFgYyl/rL121v/WWkI6APXpu+XKuHM6qrn/QR/R9HM8eVB0RrutzdtDZclCqSBod7lF6pDVRPdAw81gNhm/DwjLFrrRix3Gm7Aldg80vGvZkIJfm2aSUeAlkHPfa44HXdxrzy9PlXFlgZUnvvlwnC7/6HmfOLWmRBUB7cjsw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=07Kvx/dz; arc=fail smtp.client-ip=52.101.193.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="07Kvx/dz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IWNZcQxJoVIRE50jAhDJCW2YA529dGC4J1kTBuwNO0iFkeAHWUXSXIp647VBVQtledjVddI4/3sBAjcybuNE3uJ123aInut3aLonv+Ufve8MMrDbKpak3xZ2pX5i41n0IAaxdTXtcLwvsQl+P5s9hBj6moFMTVCA+vcePCMtWDN4bGuU97AEKJlLSd1X8to64y6Nz9BFe8yWrFkrW83qpZYx+/b4o6vT7ClM1dHeKQf6mVHzNPrZs5syxQYWN7uzNlmesksIUDJdRw74FMwPEK8OYHCPhva6VQ6+Sm770Flw2RV9J0jzeFHrdjyLFJNB8aYpSQe75b9NygQSWtpViA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=u2OkrMC7qdJVfZLoWONgXxDemyug/hm/5RsPwgSfGz0=; b=whRzcZ9cqX38VhbvicEbtCzhRWhYVbnh+857BssNdmpACO8/rU7vP9603izV2Bi0WF6oDMooHZjX8QksbxHa3TQf9fKTpdbYMxTIehT5hFTBIqQY5sg955fdY45VDgoKtW16ITPMHR/PjZQCpahtOXNyowB3kNHyuwvNHKMVRIZDDOrSkfw3A6mBuQCNsFRMDcyZuhKWaYXP0dTFkgFR8EYn5GFtl0S5/FTZjenkOGfK7m0urcTDRK6SA0ooqkHY/0ibZlZQI+42Ok8ivXeoCFXm7N4SqTOHAGp1iSlWlemgPfIGK4LeDAG1dkKZaRZpUrB5VCPPGqWa/Feeg46ASg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=u2OkrMC7qdJVfZLoWONgXxDemyug/hm/5RsPwgSfGz0=; b=07Kvx/dz90m+bYsYGDsLK2E0v+SSXnDaBKsy7a/tCdfeu69IbZ/s9a1G6X7DgNrGYTAzn1965jSE+A4icWKh0ec/4prxAs9f+gFxbEtTTaL5w2fm/VBm/Yvorpyk2RWzQlSUNdpDB4n/qrOlvAT0v6FwZZEx0OPY1cZnYsJcLY4= Received: from BL1PR13CA0367.namprd13.prod.outlook.com (2603:10b6:208:2c0::12) by CY3PR12MB9556.namprd12.prod.outlook.com (2603:10b6:930:10a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.10; Thu, 29 Jan 2026 14:44:35 +0000 Received: from BN2PEPF000055DC.namprd21.prod.outlook.com (2603:10b6:208:2c0:cafe::8d) by BL1PR13CA0367.outlook.office365.com (2603:10b6:208:2c0::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9587.2 via Frontend Transport; Thu, 29 Jan 2026 14:44:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BN2PEPF000055DC.mail.protection.outlook.com (10.167.245.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9587.0 via Frontend Transport; Thu, 29 Jan 2026 14:44:35 +0000 Received: from BLR-L-BHARARAO.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 29 Jan 2026 08:44:27 -0600 From: Bharata B Rao To: , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Bharata B Rao Subject: [RFC PATCH v5 07/10] x86: ibs: Enable IBS profiling for memory accesses Date: Thu, 29 Jan 2026 20:10:40 +0530 Message-ID: <20260129144043.231636-8-bharata@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260129144043.231636-1-bharata@amd.com> References: <20260129144043.231636-1-bharata@amd.com> 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 X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000055DC:EE_|CY3PR12MB9556:EE_ X-MS-Office365-Filtering-Correlation-Id: 3ede1100-8178-45d7-a409-08de5f44ec02 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|7416014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?/ytA+7EjjwUGJxmAfncte2N8PLj2VpJ/O8x8Nb2aeuE++8Vjecnx0+VPg2vV?= =?us-ascii?Q?d9EePBdiHk1Zs5F5ua67rNV0qEdLzI4DjOzBW/2h1Hvq11hEWT4EuNvt8M/G?= =?us-ascii?Q?Aw6NANIr/7XA/POa8OtQPR3XW9eWCSi7WC6Tg/vfAiZ6gQ2at4HF1UdO0WJ1?= =?us-ascii?Q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sPzvtABWS?= =?us-ascii?Q?uyyJ48uZPSSHYOXLUdweXBIEBMF9PJ6B37CAhyi3df7hCJHoF+WfxaAijUrr?= =?us-ascii?Q?iEqdek9dvDv8s3xYkkfZjmbWUCv7i3Deea+tfw4sY+lGzQM7EoQvmtpZ/+T+?= =?us-ascii?Q?3qgkcDC4crrV99x/tX4uVwZfnbaPFzYsPukJHvRDRB1XpG98R0Iho1pdGxXT?= =?us-ascii?Q?x89vjWEjRwV9VuR7Ii12/V1k3zIWHUdSGNmXzKv5UNlJJg8JwOAvqs3obHsx?= =?us-ascii?Q?BDzlJosqv7n7DW9Abpab3je3/YUBLvhQ6gJEZA8ZQzV1Hk+OTfoEhTHYYPUt?= =?us-ascii?Q?1CctduQCgUN2ZY6g/pPkWLI22cbhvluY+nXB835bkm9KUFg0Qje09Xbo2EUg?= =?us-ascii?Q?Glacfz5LBp1Fa1lwTL/LV8aLA6PwNHuGj6F++/WULKQMbUQUgysGKBHWvWjo?= =?us-ascii?Q?YIdj7c/yLAWXiMljhW1lg6V2WKlXqdYgSDJv5dfpxp7GyzBA4GbAxaeTnBpw?= =?us-ascii?Q?Q/aavlAdzLNDQ+YT31giYI/pFqmGev/coXBi33W1YOhE86jOPCnxhU0vJ0I9?= =?us-ascii?Q?CRlHTKYB3AMtIdioSWmH1THLnGnbaDeRTz7+r/yC1HlmoSnHgyUgVgkMqe1i?= =?us-ascii?Q?gc3vjA=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(376014)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jan 2026 14:44:35.4772 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3ede1100-8178-45d7-a409-08de5f44ec02 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF000055DC.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY3PR12MB9556 Content-Type: text/plain; charset="utf-8" Enable IBS memory access data collection for user memory accesses by programming the required MSRs. The profiling is turned ON only for user mode execution and turned OFF for kernel mode execution. Profiling is explicitly disabled for NMI handler too. TODOs: - IBS sampling rate is kept fixed for now. - Arch/vendor separation/isolation of the code needs relook. Signed-off-by: Bharata B Rao --- arch/x86/include/asm/entry-common.h | 3 +++ arch/x86/include/asm/hardirq.h | 2 ++ arch/x86/mm/ibs.c | 32 +++++++++++++++++++++++++++++ include/linux/pghot.h | 4 ++++ 4 files changed, 41 insertions(+) diff --git a/arch/x86/include/asm/entry-common.h b/arch/x86/include/asm/ent= ry-common.h index ce3eb6d5fdf9..0f381a63669e 100644 --- a/arch/x86/include/asm/entry-common.h +++ b/arch/x86/include/asm/entry-common.h @@ -4,6 +4,7 @@ =20 #include #include +#include =20 #include #include @@ -13,6 +14,7 @@ /* Check that the stack and regs on entry from user mode are sane. */ static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs) { + hwmem_access_profiling_stop(); if (IS_ENABLED(CONFIG_DEBUG_ENTRY)) { /* * Make sure that the entry code gave us a sensible EFLAGS @@ -106,6 +108,7 @@ static inline void arch_exit_to_user_mode_prepare(struc= t pt_regs *regs, static __always_inline void arch_exit_to_user_mode(void) { amd_clear_divider(); + hwmem_access_profiling_start(); } #define arch_exit_to_user_mode arch_exit_to_user_mode =20 diff --git a/arch/x86/include/asm/hardirq.h b/arch/x86/include/asm/hardirq.h index 6b6d472baa0b..e80c305c17d1 100644 --- a/arch/x86/include/asm/hardirq.h +++ b/arch/x86/include/asm/hardirq.h @@ -91,4 +91,6 @@ static __always_inline bool kvm_get_cpu_l1tf_flush_l1d(vo= id) static __always_inline void kvm_set_cpu_l1tf_flush_l1d(void) { } #endif /* IS_ENABLED(CONFIG_KVM_INTEL) */ =20 +#define arch_nmi_enter() hwmem_access_profiling_stop() +#define arch_nmi_exit() hwmem_access_profiling_start() #endif /* _ASM_X86_HARDIRQ_H */ diff --git a/arch/x86/mm/ibs.c b/arch/x86/mm/ibs.c index 752f688375f9..d0d93f09432d 100644 --- a/arch/x86/mm/ibs.c +++ b/arch/x86/mm/ibs.c @@ -16,6 +16,7 @@ static u64 ibs_config __read_mostly; static u32 ibs_caps; =20 #define IBS_NR_SAMPLES 150 +#define IBS_SAMPLE_PERIOD 10000 =20 /* * Basic access info captured for each memory access. @@ -43,6 +44,36 @@ struct ibs_sample_pcpu __percpu *ibs_s; static struct work_struct ibs_work; static struct irq_work ibs_irq_work; =20 +void hwmem_access_profiling_stop(void) +{ + u64 ops_ctl; + + if (!hwmem_access_profiling) + return; + + rdmsrl(MSR_AMD64_IBSOPCTL, ops_ctl); + wrmsrl(MSR_AMD64_IBSOPCTL, ops_ctl & ~IBS_OP_ENABLE); +} + +void hwmem_access_profiling_start(void) +{ + u64 config =3D 0; + unsigned int period =3D IBS_SAMPLE_PERIOD; + + if (!hwmem_access_profiling) + return; + + /* Disable IBS for kernel thread */ + if (!current->mm) + goto out; + + config =3D (period >> 4) & IBS_OP_MAX_CNT; + config |=3D (period & IBS_OP_MAX_CNT_EXT_MASK); + config |=3D ibs_config; +out: + wrmsrl(MSR_AMD64_IBSOPCTL, config); +} + bool hwmem_access_profiler_inuse(void) { return hwmem_access_profiling; @@ -310,6 +341,7 @@ static int __init ibs_access_profiling_init(void) x86_amd_ibs_access_profile_startup, x86_amd_ibs_access_profile_teardown); =20 + hwmem_access_profiling =3D true; pr_info("IBS setup for memory access profiling\n"); return 0; } diff --git a/include/linux/pghot.h b/include/linux/pghot.h index 20ea9767dbdd..603791183102 100644 --- a/include/linux/pghot.h +++ b/include/linux/pghot.h @@ -6,8 +6,12 @@ =20 #ifdef CONFIG_HWMEM_PROFILER bool hwmem_access_profiler_inuse(void); +void hwmem_access_profiling_start(void); +void hwmem_access_profiling_stop(void); #else static inline bool hwmem_access_profiler_inuse(void) { return false; } +static inline void hwmem_access_profiling_start(void) {} +static inline void hwmem_access_profiling_stop(void) {} #endif =20 /* Page hotness temperature sources */ --=20 2.34.1