diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index abdc814162d53d88e5afb4dd8de3b283f1159c84..283aa4602eb1838393ad024db8db5d665b97abd7 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2529,6 +2529,7 @@ static ssize_t set_attr_rdpmc(struct device *cdev, struct device_attribute *attr, const char *buf, size_t count) { + static DEFINE_MUTEX(rdpmc_mutex); unsigned long val; ssize_t ret; @@ -2542,6 +2543,8 @@ static ssize_t set_attr_rdpmc(struct device *cdev, if (x86_pmu.attr_rdpmc_broken) return -ENOTSUPP; + mutex_lock(&rdpmc_mutex); + if (val != x86_pmu.attr_rdpmc) { /* * Changing into or out of never available or always available, @@ -2562,6 +2565,8 @@ static ssize_t set_attr_rdpmc(struct device *cdev, x86_pmu.attr_rdpmc = val; } + mutex_unlock(&rdpmc_mutex); + return count; }