Re: [rt-devel:linux-5.15.y-rt-rebase 85/155] drivers/md/raid5.c:2222:20: sparse: sparse: incorrect type in argument 1 (different address spaces)

From: Sebastian Andrzej Siewior
Date: Mon Oct 11 2021 - 06:43:04 EST


On 2021-10-09 22:20:57 [+0800], kernel test robot wrote:
> sparse warnings: (new ones prefixed by >>)
> >> drivers/md/raid5.c:2222:20: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct spinlock [usertype] *lock @@ got struct spinlock [noderef] __percpu * @@
> drivers/md/raid5.c:2222:20: sparse: expected struct spinlock [usertype] *lock
> drivers/md/raid5.c:2222:20: sparse: got struct spinlock [noderef] __percpu *
> drivers/md/raid5.c:2281:22: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct spinlock [usertype] *lock @@ got struct spinlock [noderef] __percpu * @@
> drivers/md/raid5.c:2281:22: sparse: expected struct spinlock [usertype] *lock
> drivers/md/raid5.c:2281:22: sparse: got struct spinlock [noderef] __percpu *

I think the code itself is correct but sparse got confused by the
definition of the struct. Defining raid5_percpu on its own makes the
warning go away:

diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h
--- a/drivers/md/raid5.h
+++ b/drivers/md/raid5.h
@@ -559,6 +559,17 @@ struct r5pending_data {
struct bio_list bios;
};

+/* per cpu variables */
+struct raid5_percpu {
+ spinlock_t lock; /* Protection for -RT */
+ struct page *spare_page; /* Used when checking P/Q in raid6 */
+ void *scribble; /* space for constructing buffer
+ * lists and performing address
+ * conversions
+ */
+ int scribble_obj_size;
+};
+
struct r5conf {
struct hlist_head *stripe_hashtbl;
/* only protect corresponding hash list and inactive_list */
@@ -634,15 +645,7 @@ struct r5conf {
*/
int recovery_disabled;
/* per cpu variables */
- struct raid5_percpu {
- spinlock_t lock; /* Protection for -RT */
- struct page *spare_page; /* Used when checking P/Q in raid6 */
- void *scribble; /* space for constructing buffer
- * lists and performing address
- * conversions
- */
- int scribble_obj_size;
- } __percpu *percpu;
+ struct raid5_percpu __percpu *percpu;
int scribble_disks;
int scribble_sectors;
struct hlist_node node;

The RCU warnings look valid since there are __rcu annotations.

Sebastian