From: Cosmin Tanislav <demonsingur@gmail.com>
Cc: Romain Gantois <romain.gantois@bootlin.com>,
Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
Luca Ceresoli <luca.ceresoli@bootlin.com>,
Wolfram Sang <wsa+renesas@sang-engineering.com>,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>
Subject: [PATCH v2 1/9] i2c: atr: Fix lockdep for nested ATRs
Date: Tue, 25 Feb 2025 13:39:29 +0200 [thread overview]
Message-ID: <20250225113939.49811-2-demonsingur@gmail.com> (raw)
In-Reply-To: <20250225113939.49811-1-demonsingur@gmail.com>
From: Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>
When we have an ATR, and another ATR as a subdevice of the first ATR,
we get lockdep warnings for the i2c_atr.lock and
i2c_atr_chan.orig_addrs_lock. This is because lockdep uses a static key
for the locks, and doesn't see the locks of the separate ATR instances
as separate.
Fix this by generating a dynamic lock key per lock instance.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>
---
drivers/i2c/i2c-atr.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c
index 1a6ff47b4200..39b3b95c6842 100644
--- a/drivers/i2c/i2c-atr.c
+++ b/drivers/i2c/i2c-atr.c
@@ -68,11 +68,13 @@ struct i2c_atr_alias_pool {
* @atr: The parent I2C ATR
* @chan_id: The ID of this channel
* @alias_pairs_lock: Mutex protecting @alias_pairs
+ * @alias_pairs_lock_key: Lock key for @alias_pairs_lock
* @alias_pairs: List of @struct i2c_atr_alias_pair containing the
* assigned aliases
* @alias_pool: Pool of available client aliases
*
* @orig_addrs_lock: Mutex protecting @orig_addrs
+ * @orig_addrs_lock_key: Lock key for @orig_addrs_lock
* @orig_addrs: Buffer used to store the original addresses during transmit
* @orig_addrs_size: Size of @orig_addrs
*/
@@ -83,11 +85,13 @@ struct i2c_atr_chan {
/* Lock alias_pairs during attach/detach */
struct mutex alias_pairs_lock;
+ struct lock_class_key alias_pairs_lock_key;
struct list_head alias_pairs;
struct i2c_atr_alias_pool *alias_pool;
/* Lock orig_addrs during xfer */
struct mutex orig_addrs_lock;
+ struct lock_class_key orig_addrs_lock_key;
u16 *orig_addrs;
unsigned int orig_addrs_size;
};
@@ -100,6 +104,7 @@ struct i2c_atr_chan {
* @priv: Private driver data, set with i2c_atr_set_driver_data()
* @algo: The &struct i2c_algorithm for adapters
* @lock: Lock for the I2C bus segment (see &struct i2c_lock_operations)
+ * @lock_key: Lock key for @lock
* @max_adapters: Maximum number of adapters this I2C ATR can have
* @alias_pool: Optional common pool of available client aliases
* @i2c_nb: Notifier for remote client add & del events
@@ -115,6 +120,7 @@ struct i2c_atr {
struct i2c_algorithm algo;
/* lock for the I2C bus segment (see struct i2c_lock_operations) */
struct mutex lock;
+ struct lock_class_key lock_key;
int max_adapters;
struct i2c_atr_alias_pool *alias_pool;
@@ -679,7 +685,8 @@ struct i2c_atr *i2c_atr_new(struct i2c_adapter *parent, struct device *dev,
if (!atr)
return ERR_PTR(-ENOMEM);
- mutex_init(&atr->lock);
+ lockdep_register_key(&atr->lock_key);
+ mutex_init_with_key(&atr->lock, &atr->lock_key);
atr->parent = parent;
atr->dev = dev;
@@ -707,6 +714,7 @@ struct i2c_atr *i2c_atr_new(struct i2c_adapter *parent, struct device *dev,
i2c_atr_free_alias_pool(atr->alias_pool);
err_destroy_mutex:
mutex_destroy(&atr->lock);
+ lockdep_unregister_key(&atr->lock_key);
kfree(atr);
return ERR_PTR(ret);
@@ -723,6 +731,7 @@ void i2c_atr_delete(struct i2c_atr *atr)
bus_unregister_notifier(&i2c_bus_type, &atr->i2c_nb);
i2c_atr_free_alias_pool(atr->alias_pool);
mutex_destroy(&atr->lock);
+ lockdep_unregister_key(&atr->lock_key);
kfree(atr);
}
EXPORT_SYMBOL_NS_GPL(i2c_atr_delete, "I2C_ATR");
@@ -757,8 +766,10 @@ int i2c_atr_add_adapter(struct i2c_atr *atr, struct i2c_atr_adap_desc *desc)
chan->atr = atr;
chan->chan_id = chan_id;
INIT_LIST_HEAD(&chan->alias_pairs);
- mutex_init(&chan->alias_pairs_lock);
- mutex_init(&chan->orig_addrs_lock);
+ lockdep_register_key(&chan->alias_pairs_lock_key);
+ lockdep_register_key(&chan->orig_addrs_lock_key);
+ mutex_init_with_key(&chan->alias_pairs_lock, &chan->alias_pairs_lock_key);
+ mutex_init_with_key(&chan->orig_addrs_lock, &chan->orig_addrs_lock_key);
snprintf(chan->adap.name, sizeof(chan->adap.name), "i2c-%d-atr-%d",
i2c_adapter_id(parent), chan_id);
@@ -835,6 +846,8 @@ int i2c_atr_add_adapter(struct i2c_atr *atr, struct i2c_atr_adap_desc *desc)
fwnode_handle_put(dev_fwnode(&chan->adap.dev));
mutex_destroy(&chan->orig_addrs_lock);
mutex_destroy(&chan->alias_pairs_lock);
+ lockdep_unregister_key(&chan->orig_addrs_lock_key);
+ lockdep_unregister_key(&chan->alias_pairs_lock_key);
kfree(chan);
return ret;
}
@@ -872,6 +885,8 @@ void i2c_atr_del_adapter(struct i2c_atr *atr, u32 chan_id)
fwnode_handle_put(fwnode);
mutex_destroy(&chan->orig_addrs_lock);
mutex_destroy(&chan->alias_pairs_lock);
+ lockdep_unregister_key(&chan->orig_addrs_lock_key);
+ lockdep_unregister_key(&chan->alias_pairs_lock_key);
kfree(chan->orig_addrs);
kfree(chan);
}
--
2.48.1
next prev parent reply other threads:[~2025-02-25 11:39 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-25 11:39 [PATCH v2 0/9] i2c: atr: allow usage of nested ATRs Cosmin Tanislav
2025-02-25 11:39 ` Cosmin Tanislav [this message]
2025-02-25 11:39 ` [PATCH v2 2/9] i2c: atr: unlock mutex after c2a access Cosmin Tanislav
2025-02-27 10:43 ` Romain Gantois
2025-02-25 11:39 ` [PATCH v2 3/9] i2c: atr: find_mapping() -> get_mapping() Cosmin Tanislav
2025-02-27 13:25 ` Romain Gantois
2025-02-25 11:39 ` [PATCH v2 4/9] i2c: atr: split up i2c_atr_get_mapping_by_addr() Cosmin Tanislav
2025-02-27 13:29 ` Romain Gantois
2025-02-27 13:43 ` Romain Gantois
2025-02-25 11:39 ` [PATCH v2 5/9] i2c: atr: do not create mapping in detach_addr() Cosmin Tanislav
2025-02-27 13:33 ` Romain Gantois
2025-02-25 11:39 ` [PATCH v2 6/9] i2c: atr: deduplicate logic in attach_addr() Cosmin Tanislav
2025-02-27 13:36 ` Romain Gantois
2025-02-28 12:22 ` Cosmin Tanislav
2025-02-25 11:39 ` [PATCH v2 7/9] i2c: atr: allow replacing mappings " Cosmin Tanislav
2025-02-25 11:39 ` [PATCH v2 8/9] i2c: atr: add static flag Cosmin Tanislav
2025-02-27 13:58 ` Romain Gantois
2025-02-25 11:39 ` [PATCH v2 9/9] i2c: atr: add passthrough flag Cosmin Tanislav
2025-02-27 14:03 ` Romain Gantois
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250225113939.49811-2-demonsingur@gmail.com \
--to=demonsingur@gmail.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=romain.gantois@bootlin.com \
--cc=tomi.valkeinen+renesas@ideasonboard.com \
--cc=tomi.valkeinen@ideasonboard.com \
--cc=wsa+renesas@sang-engineering.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.