Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp331667lqp; Mon, 10 Jun 2024 05:46:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUGCZQUjHyVsYhKuluGuXFoh9NjMlENek3E2LzqoOqSA6j9EJUYKqrEJN/9b+5HbklWbrB1xet0UpYRcGn6gJ1rDdaXZz/k7KXAR55wjw== X-Google-Smtp-Source: AGHT+IEA/n1jKmfRWGOg9QdGAFkC7UV63DUji3GLGr/GhD9uq1GhdL7cRfaqsH8zVPsYk5oRvxpQ X-Received: by 2002:a50:c2da:0:b0:57c:7c44:74df with SMTP id 4fb4d7f45d1cf-57c7c447531mr2738638a12.29.1718023616951; Mon, 10 Jun 2024 05:46:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718023616; cv=pass; d=google.com; s=arc-20160816; b=zm1GquQ+PcF1+pczhAWtSkiI1tXrnbE5GePJ7hM2EGZ470jwdUhLqAfUB4+ilbj6D3 yiI4GUwY1Xo0x4kmbX8c9ZG6rt6vpwR5LGf0LJi6sNc/FtXg+qHZp5sT32+XnosbVrx9 9/eMfYrltlD+ivx5Tr05S5zry1z6ub79OzoFtFM8xz8c/gWuqV1TAuvJHx/ZGPJ9HkxZ XPf2VndO5ARq8neswGcNUjeyCtOq4fdlIAUSwbe/nlEyT6wvNxxp5Plk/vCwN2t3LL24 +ZvIfW026aI3Nx0WvTTSJSgjonVsCgCX8FDKAww1kivrjWGWw8DMdIp+dvdHRVFfEGfj xYsw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:subject:cc:to:from:dkim-signature :dkim-signature:message-id; bh=1aKSWv3sviyM2cko0BTe9cpwsTAoHAr5O414DpYJPMk=; fh=SJ221ozUQKE1gMXz18gHJLS2vw73dxI/wEW1L5tRolE=; b=aKElMKi0YmmUdWVc3JpOh9A/Rg+6VhBPRI0CyNZyFsMrhQ95POGSlTPx/6y9eoNFzz qQnRZ5BwjPL2gNFm0HoB3RoPr7krbXs+dKJxMCLkpeuv3lvk0Ww70Cenk07WOiFtqXGD 2yb3MSe9gFhcuspOaSLWvD/PZtWmZ3mo/hrZRsBX+RDQiKY5kY1h88R31Dq8eyVDpxJJ RWfl6IGV3PZS0A3CWs7RyfhLQsBvaL/Agr1TvPjGS0XsXq4nn6MXoK8W/BEAxSJ1/JLN Zo0by5JijUvPpjpPKxqcisUCQ+t9W/mU/EOo2nMxe8kSnwm0SJOSBJ6hK2hmYvutVlxZ Coog==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yT490YFF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-208172-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208172-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57c821b1bc6si959916a12.70.2024.06.10.05.46.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 05:46:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208172-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yT490YFF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-208172-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208172-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 am.mirrors.kernel.org (Postfix) with ESMTPS id AC4B21F21CA1 for ; Mon, 10 Jun 2024 12:46:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 96D4B80C1C; Mon, 10 Jun 2024 12:46:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yT490YFF"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="I1gphHWH" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 62A2D7FBDF for ; Mon, 10 Jun 2024 12:46:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718023598; cv=none; b=dWkr91ahKzGp82vB230MeboXuPJCPCo8069HuUA2wiyWNupvU155RIXzL2ggzgIbVg+eW199LY5ZohgYSacriWdonE1VxEO1BqBxQbJMc11VRPIRdpgw0ZlMcHByIfw57yDkynZJVcYPf0naKA5ArbsnJU9OEiQEu+seM6X/W+s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718023598; c=relaxed/simple; bh=oCEqJwcxMYboMVgrrm6y7VEn7VWx+xeGRNPCQEOcPxs=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=riXsu6dU+7InbC/Ymip1W9IRri2kRcSm9gRYqzYrxrKIKRLapSgAx/zoTxvDWIn+QeO4ntLW+8kO93P3+YloCFQrQ2AffttHN/Dja5clBmbfewGsDOl1bExavN10i6HwUcrib2HcBUC4enFbIsxZiYcXzgb/IGhkKv9yRQFj4jw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=yT490YFF; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=I1gphHWH; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Message-ID: <20240610124406.359476013@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1718023595; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=1aKSWv3sviyM2cko0BTe9cpwsTAoHAr5O414DpYJPMk=; b=yT490YFF6PPEGMHbNULktS2FmI18dVp7vUQgcqkZk9Ihkl31ng3C5NwZ75+shwEYv1cbyG 0FcCeKnUzR5UQWA9BgMs3OZDjskAulz3rZGmXDKU3jIKz0hZnmsdHBN4n7eV/SZCQVIHUy 8X5V+jgX3A/cWUsB+jUdCXZFlB7DnqII4yn6ehgGnuqC2r1tH22YYzPOl9ZTWa5m/ZJKg2 cP/o6WQ4Dxm/tiIbTpa3N0cQDH0pYplra7xYB5Asmw/ZiE5WlLvy/23SWJFWgRmLcIZs6p Cuq909lmxmAogdb7PaSYZhfDB5T8pQ1AUshvoAv17tHBHioCHEjbfjMRrxORKw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1718023595; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=1aKSWv3sviyM2cko0BTe9cpwsTAoHAr5O414DpYJPMk=; b=I1gphHWH0KTjYMrhYZnT9EZzhHiGS8b2a78TEoXv0YGJu2WmY7btuax/AD0tza2xFY1EOP j4KCEZePe3SqtkCQ== From: Thomas Gleixner To: LKML Cc: Steven Rostedt , Sam Sun , x86@kernel.org, syzkaller-bugs@googlegroups.com, xrivendell7@gmail.com Subject: [patch 1/4] perf/x86: Serialize set_attr_rdpmc() References: <87bk49xf15.ffs@tglx> <20240610124258.109097511@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Mon, 10 Jun 2024 14:46:35 +0200 (CEST) Yue and Xingwei reported a jump label failure. It's caused by the lack of serialization in set_attr_rdpmc(): CPU0 CPU1 Assume: x86_pmu.attr_rdpmc == 0 if (val != x86_pmu.attr_rdpmc) { if (val == 0) ... else if (x86_pmu.attr_rdpmc == 0) static_branch_dec(&rdpmc_never_available_key); if (val != x86_pmu.attr_rdpmc) { if (val == 0) ... else if (x86_pmu.attr_rdpmc == 0) FAIL, due to imbalance ---> static_branch_dec(&rdpmc_never_available_key); The reported BUG() is a consequence of the above and of another bug in the jump label core code. The core code needs a separate fix, but that cannot prevent the imbalance problem caused by set_attr_rdpmc(). Prevent this by serializing set_attr_rdpmc() locally. Fixes: a66734297f78 ("perf/x86: Add /sys/devices/cpu/rdpmc=2 to allow rdpmc for all tasks") Reported-by: Yue Sun Reported-by: Xingwei Lee Signed-off-by: Thomas Gleixner Closes: https://lore.kernel.org/r/CAEkJfYNzfW1vG=ZTMdz_Weoo=RXY1NDunbxnDaLyj8R4kEoE_w@mail.gmail.com --- arch/x86/events/core.c | 3 +++ 1 file changed, 3 insertions(+) --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2547,6 +2547,7 @@ static ssize_t set_attr_rdpmc(struct dev struct device_attribute *attr, const char *buf, size_t count) { + static DEFINE_MUTEX(rdpmc_mutex); unsigned long val; ssize_t ret; @@ -2560,6 +2561,8 @@ static ssize_t set_attr_rdpmc(struct dev if (x86_pmu.attr_rdpmc_broken) return -ENOTSUPP; + guard(mutex)(&rdpmc_mutex); + if (val != x86_pmu.attr_rdpmc) { /* * Changing into or out of never available or always available,