[PATCH v1 01/11] perf/amd/ibs: Fix race condition in IBS

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Consider the following scenario,

While scheduling out an IBS event from perf's core scheduling path,
event_sched_out() disables the IBS event by clearing the IBS enable
bit in perf_ibs_disable_event(). However, if a delayed IBS NMI is
delivered after the IBS enable bit is cleared, the IBS NMI handler
may still observe the valid bit set and incorrectly treat the sample
as valid. As a result, it re-enables IBS by setting the enable bit,
even though the event has already been scheduled out.

This leads to a situation where IBS is re-enabled after being
explicitly disabled, which is incorrect. Although this race does not
have visible side effects, it violates the expected behavior of the
perf subsystem.

The race is particularly noticeable when userspace repeatedly disables
and re-enables IBS using PERF_EVENT_IOC_DISABLE and
PERF_EVENT_IOC_ENABLE ioctls in a loop.

Fix this by checking the IBS_STOPPED bit in the IBS NMI handler before
re-enabling the IBS event. If the IBS_STOPPED bit is set, it indicates
that the event is either disabled or in the process of being disabled,
and the NMI handler should not re-enable it.

Signed-off-by: Manali Shukla <manali.shukla@xxxxxxx>
---
 arch/x86/events/amd/ibs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c
index 0252b7ea8bca..c998f68eeddc 100644
--- a/arch/x86/events/amd/ibs.c
+++ b/arch/x86/events/amd/ibs.c
@@ -1386,7 +1386,8 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)
 		}
 		new_config |= period >> 4;
 
-		perf_ibs_enable_event(perf_ibs, hwc, new_config);
+		if (!test_bit(IBS_STOPPING, pcpu->state))
+			perf_ibs_enable_event(perf_ibs, hwc, new_config);
 	}
 
 	perf_event_update_userpage(event);

base-commit: 61374cc145f4a56377eaf87c7409a97ec7a34041
prerequisite-patch-id: 0094bc7b958de1caba7b779c1c2dc96b3e1bcac1
prerequisite-patch-id: 58a6a462207dd7ec06998d6ff6a418f373f25d43
prerequisite-patch-id: 42d94622dfc4ccc786ce9bd6be186dbc5d32ed5b
prerequisite-patch-id: d93658ba28ece72eb6b9e2bb2a2a6188c4654216
prerequisite-patch-id: 669a4b410b39f4f34b9bcc4748a277ad2ac3b24c
prerequisite-patch-id: 89161a3395ead9159840634b594b973eee4728e0
prerequisite-patch-id: 58860afef836e3429817055807502201dd914602
prerequisite-patch-id: 9de4d874201da2dcec388e8fe4b3750ba3afc563
prerequisite-patch-id: b1d44b6a3ed8124ce9bd71474e367c8143baad41
prerequisite-patch-id: b7d50d21fe0f1c6d3b63d31d8cf573ad4bd06d33
prerequisite-patch-id: 526f07d6a60996b4839a170bacead2eeacf953bf
prerequisite-patch-id: 602259a8d1ac84dd95ad56463ebabc55e612400b
prerequisite-patch-id: ae0e84487c58d976362fbef7eaec565b14162d3e
prerequisite-patch-id: 78ba19a866d65e36352ec8f5bbd039bc2108e54c
prerequisite-patch-id: 973787b7d310a4cbe45836921402c6708bf3f67a
prerequisite-patch-id: cb2f413bf916cb895c26a27bd6415396c56b3e63
prerequisite-patch-id: 7546a92ef58aa9e40b1389650f5c7ffc28de40e5
prerequisite-patch-id: 0750ebfe9b7d25e9b6bdf838a179190c958aff97
prerequisite-patch-id: bd71d326c645eff74bf3f203ebde1739ad2eaa64
prerequisite-patch-id: 1937d5112d9a975009d3b75cebd16fabd7e595e0
prerequisite-patch-id: c3e3bac41574713b413d6ef13e373953080d26c9
prerequisite-patch-id: ebf87b381105b90d89670f3f0e123de8bc4e2086
prerequisite-patch-id: d450df9a0e717374c4a73355ef438e8b012e2ab7
prerequisite-patch-id: 91d5d4adfd44253424016b3132de587328f4d1f6
prerequisite-patch-id: 5743f22d48a3e410ab28ce6d81d6213e9854128d
prerequisite-patch-id: 0f8c5fff2d0ae8eb84446439bbb1792e078acac8
prerequisite-patch-id: 9ead85c0f9cd7a0a5448e2aff7e2d94fab9fa106
prerequisite-patch-id: 4ea3a56935fd4a23c2c1101738002bb3c89c8723
prerequisite-patch-id: 303869f48baa0d36f8a894bea87ba9283314efa1
prerequisite-patch-id: d774d5ff6a124c32c86a6db6bd5d97285591294c
prerequisite-patch-id: 9708b3ac43c53623fe553e88cf42d06940af1d43
prerequisite-patch-id: 5d890648afbf86e18eff47520a10a8f6eefb5f6c
prerequisite-patch-id: ddba6b9f04901285c77f3af1ea5ab50fe063b015
prerequisite-patch-id: 2fafac2db57921b28591ff0bf1e38f911870ef05
prerequisite-patch-id: 16cd8c4d184fd1e4217835aa43c38d2986bb30f3
prerequisite-patch-id: 1536075a6bd45c6c2484e9045e6f0173dfb4fbc2
prerequisite-patch-id: 3dcc0186dd0c08353bb3ba50c384085fc6ded721
prerequisite-patch-id: 6c2e2cd3416fba38621f75286283b452765ee3bc
prerequisite-patch-id: 4cdd5b8e215224a7dd8224914cf1dfacc4f52a96
prerequisite-patch-id: bce24d584bfaf81b23ba88aea97187387791e8fc
prerequisite-patch-id: 3981227aa4d106f583a9ac07ca08e416b60ea52e
prerequisite-patch-id: 9b56c12722196db1ed0ab3a5aaf3d5c5b26e8814
prerequisite-patch-id: 9f3c7f29d4142a13b919356c458059aac4732082
prerequisite-patch-id: 218445b88281283066b23a1844f51098fe670f49
prerequisite-patch-id: 5d92b7d25437e3d3e5e3a5a08e779bb23b10d5ad
prerequisite-patch-id: 1d1a5aee655b9adc11daa0b24e5a6a44dd2b55eb
prerequisite-patch-id: 94adf0a619adcc857014fd1b5b52d2bc6a920aca
prerequisite-patch-id: 5317018cfb51d5aa27bab2ca259fa6a36aad6303
prerequisite-patch-id: 083070d1b008b9396f64ff3ea1998e624db058ca
prerequisite-patch-id: d69b8afdc062ad10cc8dc2aad1759dbe70fc666c
prerequisite-patch-id: 1f1045ecce2d127cbfc0a382adba9c4bb711dd30
prerequisite-patch-id: a7a8a308c1b0eca850bc140019066a52a9aaf64a
prerequisite-patch-id: 1891c0fec1d1f2ba2dd26e79a8207b0e13a0f8bf
prerequisite-patch-id: f4027ba53a2e69f12fd22697dbf1f97951323d6a
prerequisite-patch-id: 8ca87584eaaa9fda7ffe7bfac4684af9e82988f5
prerequisite-patch-id: 0000000000000000000000000000000000000000
prerequisite-patch-id: 4537a12ab34d9c9a40d5602b51e8ddc968d6ff83
prerequisite-patch-id: bc8ece4d02f8b541d5fcf731059c35861be5eefe
prerequisite-patch-id: 1759acbd0b0f8e8b974e22c0627ea81a0b1cb431
prerequisite-patch-id: 2876c944ff6ef5ad1e146cf04674cafd08023369
prerequisite-patch-id: d7245aeede10610be8545ae9344ae0a4ce5c4227
prerequisite-patch-id: efad6c0b30a629d976fce1ca63005b064029354c
prerequisite-patch-id: 68e90423c6d9ddecf4262234c0791b807885f7cd
prerequisite-patch-id: b8015065a77b10b3d27cc0277ccc4d8cbb476008
prerequisite-patch-id: 76180001a4e5e51fcb68e08403a82edca008e8af
prerequisite-patch-id: 647937e4716b773c813aa2de6cf689c518db8459
prerequisite-patch-id: 61e0acf355c7cbbe888f03ae3ebe5fa3df83176e
prerequisite-patch-id: 32eb0a230627e45739d15b1ffbad9e897144fcca
prerequisite-patch-id: a0f10d6af86558cb3752f32111ebee4e6ad0887b
prerequisite-patch-id: 219266326bb1c41c441d92a82d5e38c9ca8a066f
-- 
2.43.0





[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux