md/raid5-ppl: Annotate with rcu_dereference_protected()
authorLogan Gunthorpe <logang@deltatee.com>
Thu, 7 Apr 2022 16:57:12 +0000 (10:57 -0600)
committerSong Liu <song@kernel.org>
Mon, 25 Apr 2022 21:00:37 +0000 (14:00 -0700)
To suppress the last remaining sparse warnings about accessing
rdev, add rcu_dereference_protected calls to a couple places
in raid5-ppl. All of these places are called under raid5_run and
therefore are occurring before the array has started and is thus
safe.

There's no sensible check to do for the second argument of
rcu_dereference_protected() so a comment is added instead.

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Song Liu <song@kernel.org>
drivers/md/raid5-ppl.c

index d3962d9..55d065a 100644 (file)
@@ -883,7 +883,9 @@ static int ppl_recover_entry(struct ppl_log *log, struct ppl_header_entry *e,
                                 (unsigned long long)r_sector, dd_idx,
                                 (unsigned long long)sector);
 
-                       rdev = conf->disks[dd_idx].rdev;
+                       /* Array has not started so rcu dereference is safe */
+                       rdev = rcu_dereference_protected(
+                                       conf->disks[dd_idx].rdev, 1);
                        if (!rdev || (!test_bit(In_sync, &rdev->flags) &&
                                      sector >= rdev->recovery_offset)) {
                                pr_debug("%s:%*s data member disk %d missing\n",
@@ -934,7 +936,10 @@ static int ppl_recover_entry(struct ppl_log *log, struct ppl_header_entry *e,
                parity_sector = raid5_compute_sector(conf, r_sector_first + i,
                                0, &disk, &sh);
                BUG_ON(sh.pd_idx != le32_to_cpu(e->parity_disk));
-               parity_rdev = conf->disks[sh.pd_idx].rdev;
+
+               /* Array has not started so rcu dereference is safe */
+               parity_rdev = rcu_dereference_protected(
+                                       conf->disks[sh.pd_idx].rdev, 1);
 
                BUG_ON(parity_rdev->bdev->bd_dev != log->rdev->bdev->bd_dev);
                pr_debug("%s:%*s write parity at sector %llu, disk %s\n",
@@ -1404,7 +1409,9 @@ int ppl_init_log(struct r5conf *conf)
 
        for (i = 0; i < ppl_conf->count; i++) {
                struct ppl_log *log = &ppl_conf->child_logs[i];
-               struct md_rdev *rdev = conf->disks[i].rdev;
+               /* Array has not started so rcu dereference is safe */
+               struct md_rdev *rdev =
+                       rcu_dereference_protected(conf->disks[i].rdev, 1);
 
                mutex_init(&log->io_mutex);
                spin_lock_init(&log->io_list_lock);