[Devel] [PATCH RHEL7 COMMIT] ploop: sysfs: ignore discard_granularity lockdep false positive

Konstantin Khorenko khorenko at virtuozzo.com
Fri May 19 19:34:06 MSK 2023


The commit is pushed to "branch-rh7-3.10.0-1160.88.1.vz7.195.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1160.88.1.vz7.195.3
------>
commit cdae454cdf895bc6e3bead1cb5f1c4bde32dd8e5
Author: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
Date:   Tue May 9 13:11:23 2023 +0300

    ploop: sysfs: ignore discard_granularity lockdep false positive
    
    Lockdep reported a possible deadlock here:
    
         CPU0                    CPU1
         ----                    ----
    A lock(sb_writers#9);
                                 D lock(&plo->ctl_mutex);
                                 A lock(sb_writers#9);
    B lock(&p->lock);
    
    A - sendfile(src=any, of=ploopdelta) -> takes sb_writers
    B - seq_read takes m->lock /aka p->lock in lockdep/ in struct seq_file
    C - of->mutex struct kernfs_open_file *of
    D - plo->ctl_mutex
    
    kernfs_fop_write takes C and store_discard_granularity takes D
    &p->lock -> &plo>ctl_mutex --> sb_writers
    B->D->A
    
    There is a dependancy but it never goes to sb_writers except when
    opening top delta but then the seq_file lock is not held.
    
    It looks like a common issue when using sysfs, so at some point
    ignore_lockdep was added to struct attribute /used by sysfs files/
    to silence such false positive reports.
    
    Create  _A2_NO_LOCKDEP macro that sets ignore_lockdep to true
    and use it to declare discard_granularity sysfs file.
    
    https://jira.vzint.dev/browse/PSBM-146987
    Signed-off-by: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
---
 drivers/block/ploop/sysfs.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/block/ploop/sysfs.c b/drivers/block/ploop/sysfs.c
index e27860810e27..c3cc707ec323 100644
--- a/drivers/block/ploop/sysfs.c
+++ b/drivers/block/ploop/sysfs.c
@@ -644,6 +644,13 @@ struct pattr_sysfs_entry {
 #define _A2(_name) \
 &((struct pattr_sysfs_entry){ .attr = { .name = __stringify(_name), .mode = S_IRUGO|S_IWUSR }, .show = show_##_name, .store = store_##_name, }).attr
 
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+#define _A2_NO_LOCKDEP(_name) \
+&((struct pattr_sysfs_entry){ .attr = { .name = __stringify(_name), .mode = S_IRUGO|S_IWUSR, .ignore_lockdep = true }, .show = show_##_name, .store = store_##_name, }).attr
+#else
+#define _A2_NO_LOCKDEP _A2
+#endif
+
 #define _A3(_name)							\
 &((struct pattr_sysfs_entry){ .attr = { .name = __stringify(_name), .mode = S_IRUGO }, .print = print_##_name, }).attr
 
@@ -696,7 +703,7 @@ static struct attribute *tune_attributes[] = {
 	_A2(congestion_low_watermark),
 	_A2(max_active_requests),
 	_A2(push_backup_timeout),
-	_A2(discard_granularity),
+	_A2_NO_LOCKDEP(discard_granularity),
 	_A(discard_alignment),
 	_A2(discard_zeroes_data),
 	_A2(trusted),


More information about the Devel mailing list