From patchwork Thu Sep 5 20:47:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13792984 Received: from 009.lax.mailroute.net (009.lax.mailroute.net [199.89.1.12]) (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 0F1E78821 for ; Thu, 5 Sep 2024 20:47:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725569257; cv=none; b=qccebqCFcg1YVUPr7Y5q3iF3+2aJ8c7fybs/2C93YTUtguiMlkthB/gwdIgWeq+otd1KkZxOFXYchfawEG4SscckQYp7tAbY97ab+pxYzAGC3MY6wbqyxro7asOnFn9ulv5UppryfmtrsfBGwjhCpLcLE1tyix06ghr/ZM69mq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725569257; c=relaxed/simple; bh=g7eFIs8rWIiv6LyZA5yY4gfg+YZ9lUeHCDfTzDScKSQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pOpHjA1Vxcrz6tKZAnLTSKagfGcpFzIvMvzJZ+CkqOV6Hh/1CNmgZ5MD1qHVNyEp0jQKDHCvPWxBy+CHFwsdM48TDMExdj0sGqS3PWJyWOgy8RBj0gYGmQgSttdaqqTGUqwCqKWvG/VcmIwNTsvpjpQI7kZnDEgTil9Ib3KzO3g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=IhusZUuj; arc=none smtp.client-ip=199.89.1.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="IhusZUuj" Received: from localhost (localhost [127.0.0.1]) by 009.lax.mailroute.net (Postfix) with ESMTP id 4X0BJ73PW5zlgVnF; Thu, 5 Sep 2024 20:47:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1725569252; x=1728161253; bh=ij9YH tVJF77NPK/0c7KFSqL6vPi/fCqG3KtMptK68dg=; b=IhusZUujtFwEwgCDWseJx bCzsXZH/xUM6HsBmr2/6W8ZFNitpyalTyikS/RfZ4D7YkWFMmlMEvCcIH1smWNj+ V38OBdRfIVIOjnQdtJLPyAYPgQC+xZCg8chE/pVrDAwzGnDNKECDrx24pBDTBKBw RJPusbn+XMzf62xXeJNHoJ26zgrd1acHQCq4jMzQyzzKW49ej2GEwt0ngdHZsCRU zzEmJag53Habvw44Uv7pp/IfF95KbJH6VtVcr/M3ZZc9miuLAqHCisQocEZr4oSx VKnaUiHQllS04CyAZt7T3RpkDg0KikCfc7LkZICWFvKjo+BcjWKPpKF/hrSxN5Jy A== X-Virus-Scanned: by MailRoute Received: from 009.lax.mailroute.net ([127.0.0.1]) by localhost (009.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id 3jFaJtMxtoyw; Thu, 5 Sep 2024 20:47:32 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 009.lax.mailroute.net (Postfix) with ESMTPSA id 4X0BJ34X1MzlgMVL; Thu, 5 Sep 2024 20:47:31 +0000 (UTC) From: Bart Van Assche To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, Thomas Gleixner , Peter Zijlstra , Ingo Molnar , Andy Shevchenko , Amit Sunil Dhamne , Bart Van Assche Subject: [PATCH v2 1/3] locking/mutex: Define mutex_init() once Date: Thu, 5 Sep 2024 13:47:07 -0700 Message-ID: <20240905204709.556577-2-bvanassche@acm.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240905204709.556577-1-bvanassche@acm.org> References: <20240905204709.556577-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With CONFIG_PREEMPT_RT disabled __mutex_init() is a function. With CONFIG_PREEMPT_RT enabled, __mutex_init() is a macro. I assume this is why mutex_init() is defined twice as exactly the same macro. Prepare for introducing a new macro for mutex initialization by combining the two identical mutex_init() definitions into a single definition. This patch does not change any functionality because the C preprocessor expands macros when it encounters the macro name and not when a macro definition is encountered. See also commit bb630f9f7a7d ("locking/rtmutex: Add mutex variant for RT"). Cc: Thomas Gleixner Cc: Peter Zijlstra (Intel) Cc: Ingo Molnar Signed-off-by: Bart Van Assche --- include/linux/mutex.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/include/linux/mutex.h b/include/linux/mutex.h index a561c629d89f..ef617089db19 100644 --- a/include/linux/mutex.h +++ b/include/linux/mutex.h @@ -49,7 +49,6 @@ static inline void mutex_destroy(struct mutex *lock) {} #endif -#ifndef CONFIG_PREEMPT_RT /** * mutex_init - initialize the mutex * @mutex: the mutex to be initialized @@ -65,6 +64,7 @@ do { \ __mutex_init((mutex), #mutex, &__key); \ } while (0) +#ifndef CONFIG_PREEMPT_RT #define __MUTEX_INITIALIZER(lockname) \ { .owner = ATOMIC_LONG_INIT(0) \ , .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(lockname.wait_lock) \ @@ -111,12 +111,6 @@ do { \ __mutex_rt_init((mutex), name, key); \ } while (0) -#define mutex_init(mutex) \ -do { \ - static struct lock_class_key __key; \ - \ - __mutex_init((mutex), #mutex, &__key); \ -} while (0) #endif /* CONFIG_PREEMPT_RT */ #ifdef CONFIG_DEBUG_MUTEXES From patchwork Thu Sep 5 20:47:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13792985 Received: from 009.lax.mailroute.net (009.lax.mailroute.net [199.89.1.12]) (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 49DDF3D6D for ; Thu, 5 Sep 2024 20:47:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725569258; cv=none; b=WCXzeIJ/BAhIq2RomKJTc/7aUCGRalOP7fgRH5VmONOXaW+356QaJ299WzorcaO9tET7OUZFio+82ATpvJWHCv3SISBhVcOrusPHEZgKLwuokyUQK4NOs5KZOKwDt2aV+retbvchH3IGzt5OZA1oPlnCTe0mFfiBRaeEZ5Kaib8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725569258; c=relaxed/simple; bh=xL2Cb4/VSZof31xlNvAm7jxrEdCtUmtRtLCGqLxXBP8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YE4gB0dDn91A5dZn0fzJAAPjVvQ1R7UJKkA0Co2hjZhCnVJvmZhIrJD0HM0aS6RMrJ/p1JHbYdPMPsGuIC0kQSpIJDLXC47amObmJcUbYqJMNtjuTRSOL5zx03QCpcU2xXOgp11lJxCUhAU0diBvgCxco8HP1IQQFMYeeAlqZG8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=bW9XmCS7; arc=none smtp.client-ip=199.89.1.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="bW9XmCS7" Received: from localhost (localhost [127.0.0.1]) by 009.lax.mailroute.net (Postfix) with ESMTP id 4X0BJ85ZkGzlgMVL; Thu, 5 Sep 2024 20:47:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1725569253; x=1728161254; bh=VE75y 2PZNpv97rcFuBflEUaHs5bByovg34YBSk0oV+g=; b=bW9XmCS7fPnzsejdUbYSj wXBjKglpjCUedOLLGDDkWj9cPgB8HIGJgydDS0YsTrLNOpvjGr0UMR9SxL1vQe1i PYk4bLxAdyH/TMATqEecq3AxkzIkTYnzZIobNjBDRjQ89wT00PWGZfUoT2fWBOtz kYDjtySIYwoiKr1BRWyhusDZydMjnAn4HdQfvF0A0cVcOIXe7G75fkmKruXvpYJQ 9gY5ioKCsGeyG+SKet39VskVZ+Nd6zg/JrduQnqF94HmG8akj55FBfwXJbS86oD9 Ms6ZLUAq4rP7+mMueFuNjElIDkMMcD/mXPIr2fT0/XgkUMbXn2qrFY7IkbtX9vnx A== X-Virus-Scanned: by MailRoute Received: from 009.lax.mailroute.net ([127.0.0.1]) by localhost (009.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id a1YZHCr6QzqL; Thu, 5 Sep 2024 20:47:33 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 009.lax.mailroute.net (Postfix) with ESMTPSA id 4X0BJ43tjrzlgMVN; Thu, 5 Sep 2024 20:47:32 +0000 (UTC) From: Bart Van Assche To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, Thomas Gleixner , Peter Zijlstra , Ingo Molnar , Andy Shevchenko , Amit Sunil Dhamne , Bart Van Assche Subject: [PATCH v2 2/3] locking/mutex: Introduce mutex_init_with_key() Date: Thu, 5 Sep 2024 13:47:08 -0700 Message-ID: <20240905204709.556577-3-bvanassche@acm.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240905204709.556577-1-bvanassche@acm.org> References: <20240905204709.556577-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The following pattern occurs 5 times in kernel drivers: lockdep_register_key(key); __mutex_init(mutex, name, key); In several cases the 'name' argument matches #mutex. Hence, introduce the mutex_init_with_key() macro. This macro derives the 'name' argument from the 'mutex' argument. Cc: Thomas Gleixner Cc: Peter Zijlstra (Intel) Cc: Ingo Molnar Suggested-by: Andy Shevchenko Signed-off-by: Bart Van Assche Reviewed-by: Andy Shevchenko --- include/linux/mutex.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/linux/mutex.h b/include/linux/mutex.h index ef617089db19..2bf91b57591b 100644 --- a/include/linux/mutex.h +++ b/include/linux/mutex.h @@ -64,6 +64,17 @@ do { \ __mutex_init((mutex), #mutex, &__key); \ } while (0) +/** + * mutex_init_with_key - initialize a mutex with a given lockdep key + * @mutex: the mutex to be initialized + * @key: the lockdep key to be associated with the mutex + * + * Initialize the mutex to the unlocked state. + * + * It is not allowed to initialize an already locked mutex. + */ +#define mutex_init_with_key(mutex, key) __mutex_init((mutex), #mutex, (key)) + #ifndef CONFIG_PREEMPT_RT #define __MUTEX_INITIALIZER(lockname) \ { .owner = ATOMIC_LONG_INIT(0) \ From patchwork Thu Sep 5 20:47:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13792986 Received: from 009.lax.mailroute.net (009.lax.mailroute.net [199.89.1.12]) (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 8CB2F1A76AF; Thu, 5 Sep 2024 20:47:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725569261; cv=none; b=MV+wrSGCGr2WUW/6yQYFfZPhupQZg51Hvwv7TszViUAWQnOrI30G2Xa6Kn3/8KmUJ16xsaN7Cnp8MlrP6R9IFdCrRO75ygh1hIIvKopwp1znhPNdn/cq64NDsY/6NBYSuUkTw+5QJk+5C65/23+hMrAWJcfo94hFgmOVdOLHFoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725569261; c=relaxed/simple; bh=qsJw1HcUe7Gj/mQM1O3YLvKuT9ECBKUAznlArU8F344=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PhqMWOCJy6xq85pEypcHZy1t2m2n9URX4HlsKwTUGDXJPbP1WjUsrjwBNhDMhuvflNVV9nYIuppM5NufyS6SuP5xyGnG10oukp38q94FkPe77Nl3bHTSZyl3wRTu2fgjvbuCLyOX39Rh7HnQRJVGROotIWJfogqs5wsn5CUKQro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=NoR3MkiV; arc=none smtp.client-ip=199.89.1.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="NoR3MkiV" Received: from localhost (localhost [127.0.0.1]) by 009.lax.mailroute.net (Postfix) with ESMTP id 4X0BJC2GHgzlgMVN; Thu, 5 Sep 2024 20:47:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1725569254; x=1728161255; bh=DQspN xAEnqiT6HWVkGfG0pG8H7Ac6GOoJnrw0mezREg=; b=NoR3MkiVPNYIIYRr3Sdyv IABUNEiuaVoLBj8rJuIsEToPFWCAOndvXZ/kLiqb4eRoUFn+H+zhYgxVZSRfXI15 c3HknjPW0k/hccUIWZqGTpwOFCegyzbai8SDjzCuu6vAkFpwlAw5nKQ4zPUqrgLT 2ugpEYshUlb86F/ibUxswhtNzSuZzwUpMgy6yrX3dIfN0wqGcmC5D7/z5ZqRQXJr rNOewFuH0WEwWr87hyKfncCBkGujTMo7+20U39d/Do1DlYRQP/i741xTuO7MoZy0 zptETRiOAMSKBk6bDpqbyTk2vnjb6R4lOs6rJG/6JHW7jkgu3jfUKKLtTLP3x7rt Q== X-Virus-Scanned: by MailRoute Received: from 009.lax.mailroute.net ([127.0.0.1]) by localhost (009.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id 75uldK_sVijw; Thu, 5 Sep 2024 20:47:34 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 009.lax.mailroute.net (Postfix) with ESMTPSA id 4X0BJ53FM1zlgMVP; Thu, 5 Sep 2024 20:47:33 +0000 (UTC) From: Bart Van Assche To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, Thomas Gleixner , Peter Zijlstra , Ingo Molnar , Andy Shevchenko , Amit Sunil Dhamne , Bart Van Assche , Hans de Goede , Heikki Krogerus , Badhri Jagan Sridharan , stable@vger.kernel.org Subject: [PATCH v2 3/3] usb: roles: Fix a false positive recursive locking complaint Date: Thu, 5 Sep 2024 13:47:09 -0700 Message-ID: <20240905204709.556577-4-bvanassche@acm.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240905204709.556577-1-bvanassche@acm.org> References: <20240905204709.556577-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Suppress the following lockdep complaint by giving each sw->lock a unique lockdep key instead of using the same lockdep key for all sw->lock instances: INFO: trying to register non-static key. The code is fine but needs lockdep annotation, or maybe you didn't initialize this object before use? turning off the locking correctness validator. Cc: Hans de Goede Cc: Andy Shevchenko Cc: Heikki Krogerus Cc: Greg Kroah-Hartman Cc: Badhri Jagan Sridharan Cc: stable@vger.kernel.org Fixes: fde0aa6c175a ("usb: common: Small class for USB role switches") Signed-off-by: Amit Sunil Dhamne Signed-off-by: Bart Van Assche --- drivers/usb/roles/class.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c index 7aca1ef7f44c..37556aa0eeee 100644 --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c @@ -22,6 +22,7 @@ static const struct class role_class = { struct usb_role_switch { struct device dev; + struct lock_class_key key; struct mutex lock; /* device lock*/ struct module *module; /* the module this device depends on */ enum usb_role role; @@ -329,6 +330,8 @@ static void usb_role_switch_release(struct device *dev) { struct usb_role_switch *sw = to_role_switch(dev); + mutex_destroy(&sw->lock); + lockdep_unregister_key(&sw->key); kfree(sw); } @@ -367,7 +370,8 @@ usb_role_switch_register(struct device *parent, if (!sw) return ERR_PTR(-ENOMEM); - mutex_init(&sw->lock); + lockdep_register_key(&sw->key); + mutex_init_with_key(&sw->lock, &sw->key); sw->allow_userspace_control = desc->allow_userspace_control; sw->usb2_port = desc->usb2_port;