Skip to contentSkip to conversation

dm vdo: fix sparse warnings

PATCH New Matthew Sakai 1 participant 8 messages Feb 6, 2024

Subsystems (2)
lore
Share & tools
lore

Matthew Sakai

author maintainer
#0 lore raw

cover dm vdo: fix sparse warnings

Fix warnings from sparse.

Mike Snitzer (6):
dm vdo: fix sparse warnings about missing statics
dm vdo: fix sparse 'warning: Using plain integer as NULL pointer' dm vdo: fix various blk_opf_t sparse warnings
dm vdo data-vio: silence sparse warnings about locking context
imbalances
dm vdo dedupe: silence sparse warnings about locking context
imbalances
dm vdo recovery-journal: fix sparse 'mixed bitwiseness' warning

Susan LeGendre-McGhee (1):
dm vdo: move encoding constants to encodings.h

 drivers/md/dm-vdo/Makefile           |  1 -
 drivers/md/dm-vdo/block-map.c        |  4 +--
 drivers/md/dm-vdo/constants.c        | 15 -----------
 drivers/md/dm-vdo/constants.h        | 12 +++------
 drivers/md/dm-vdo/data-vio.c         | 39 ++++++++++++++++------------
 drivers/md/dm-vdo/dedupe.c           |  2 ++
 drivers/md/dm-vdo/encodings.c        |  2 +-
 drivers/md/dm-vdo/encodings.h        |  6 +++++
 drivers/md/dm-vdo/index.c            |  8 +++---
 drivers/md/dm-vdo/io-submitter.c     |  2 +-
 drivers/md/dm-vdo/io-submitter.h     |  4 +--
 drivers/md/dm-vdo/recovery-journal.c |  4 +--
 drivers/md/dm-vdo/vdo.c              |  3 ++-
 drivers/md/dm-vdo/vio.c              |  4 +--
 drivers/md/dm-vdo/vio.h              |  4 +--
 15 files changed, 52 insertions(+), 58 deletions(-)
 delete mode 100644 drivers/md/dm-vdo/constants.c
Signature · 1 line
2.42.0
author maintainer
#1 lore raw

PATCH 1/7 dm vdo: fix sparse warnings about missing statics

From: Mike Snitzer <[email protected]>

Addresses various sparse warnings like:
warning: symbol 'SYMBOL' was not declared. Should it be static?

---
 drivers/md/dm-vdo/Makefile    |  1 -
 drivers/md/dm-vdo/block-map.c |  2 +-
 drivers/md/dm-vdo/constants.c | 15 ---------------
 drivers/md/dm-vdo/constants.h |  6 +++---
 drivers/md/dm-vdo/encodings.c |  2 +-
 5 files changed, 5 insertions(+), 21 deletions(-)
 delete mode 100644 drivers/md/dm-vdo/constants.c
drivers/md/dm-vdo/Makefile +0 -1
index 8f8d161a6dbe..8c06c3b969e3 100644
@@ -9,7 +9,6 @@ dm-vdo-objs := \
 	chapter-index.o \
 	completion.o \
 	config.o \
-	constants.o \
 	data-vio.o \
 	dedupe.o \
 	delta-index.o \
drivers/md/dm-vdo/block-map.c +1 -1
index 54ad6939cab7..1278a5791160 100644
@@ -67,7 +67,7 @@ struct block_map_tree_segment {
 
 struct block_map_tree {
 	struct block_map_tree_segment *segments;
-} block_map_tree;
+};
 
 struct forest {
 	struct block_map *map;
drivers/md/dm-vdo/constants.c deleted +0 -15
deleted file mode 100644
index 14ac047101f8..000000000000
@@ -1,15 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * Copyright 2023 Red Hat
- */
-
-#include "types.h"
-
-/* The maximum logical space is 4 petabytes, which is 1 terablock. */
-const block_count_t MAXIMUM_VDO_LOGICAL_BLOCKS = 1024ULL * 1024 * 1024 * 1024;
-
-/* The maximum physical space is 256 terabytes, which is 64 gigablocks. */
-const block_count_t MAXIMUM_VDO_PHYSICAL_BLOCKS = 1024ULL * 1024 * 1024 * 64;
-
-/* unit test minimum */
-const block_count_t MINIMUM_VDO_SLAB_JOURNAL_BLOCKS = 2;
drivers/md/dm-vdo/constants.h +3 -3
index 9ae3917d00de..3a997dd7d0b1 100644
@@ -91,12 +91,12 @@ enum {
 };
 
 /** The maximum logical space is 4 petabytes, which is 1 terablock. */
-extern const block_count_t MAXIMUM_VDO_LOGICAL_BLOCKS;
+static const block_count_t MAXIMUM_VDO_LOGICAL_BLOCKS = 1024ULL * 1024 * 1024 * 1024;
 
 /** The maximum physical space is 256 terabytes, which is 64 gigablocks. */
-extern const block_count_t MAXIMUM_VDO_PHYSICAL_BLOCKS;
+static const block_count_t MAXIMUM_VDO_PHYSICAL_BLOCKS = 1024ULL * 1024 * 1024 * 64;
 
 /** unit test minimum */
-extern const block_count_t MINIMUM_VDO_SLAB_JOURNAL_BLOCKS;
+static const block_count_t MINIMUM_VDO_SLAB_JOURNAL_BLOCKS = 2;
 
 #endif /* VDO_CONSTANTS_H */
drivers/md/dm-vdo/encodings.c +1 -1
index 2d9d8645f66b..6b3e9a5b3a91 100644
@@ -85,7 +85,7 @@ const struct header VDO_SLAB_DEPOT_HEADER_2_0 = {
 	.size = sizeof(struct slab_depot_state_2_0),
 };
 
-const struct header VDO_LAYOUT_HEADER_3_0 = {
+static const struct header VDO_LAYOUT_HEADER_3_0 = {
 	.id = VDO_LAYOUT,
 	.version = {
 		.major_version = 3,
Signature · 1 line
2.42.0
author maintainer
#2 lore raw

PATCH 2/7 dm vdo: fix sparse 'warning: Using plain integer as NULL pointer'

In reply to Matthew Sakai

From: Mike Snitzer <[email protected]>

---
 drivers/md/dm-vdo/index.c | 8 ++++----
 drivers/md/dm-vdo/vdo.c   | 3 ++-
 2 files changed, 6 insertions(+), 5 deletions(-)
drivers/md/dm-vdo/index.c +4 -4
index e343a973881d..1596f6ba43a5 100644
@@ -732,18 +732,18 @@ static void close_chapters(void *arg)
 
 static void stop_chapter_writer(struct chapter_writer *writer)
 {
-	struct thread *writer_thread = 0;
+	struct thread *writer_thread = NULL;
 
 	uds_lock_mutex(&writer->mutex);
-	if (writer->thread != 0) {
+	if (writer->thread != NULL) {
 		writer_thread = writer->thread;
-		writer->thread = 0;
+		writer->thread = NULL;
 		writer->stop = true;
 		uds_broadcast_cond(&writer->cond);
 	}
 	uds_unlock_mutex(&writer->mutex);
 
-	if (writer_thread != 0)
+	if (writer_thread != NULL)
 		uds_join_threads(writer_thread);
 }
 
drivers/md/dm-vdo/vdo.c +2 -1
index 1ead769f0150..e0eddd4007b8 100644
@@ -889,7 +889,8 @@ int vdo_synchronous_flush(struct vdo *vdo)
 	int result;
 	struct bio bio;
 
-	bio_init(&bio, vdo_get_backing_device(vdo), 0, 0, REQ_OP_WRITE | REQ_PREFLUSH);
+	bio_init(&bio, vdo_get_backing_device(vdo), NULL, 0,
+		 REQ_OP_WRITE | REQ_PREFLUSH);
 	submit_bio_wait(&bio);
 	result = blk_status_to_errno(bio.bi_status);
 
Signature · 1 line
2.42.0
author maintainer
#3 lore raw

PATCH 3/7 dm vdo: fix various blk_opf_t sparse warnings

In reply to Matthew Sakai

From: Mike Snitzer <[email protected]>

Use proper blk_opf_t type rather than unsigned int.

---
 drivers/md/dm-vdo/block-map.c    | 2 +-
 drivers/md/dm-vdo/data-vio.c     | 4 ++--
 drivers/md/dm-vdo/io-submitter.c | 2 +-
 drivers/md/dm-vdo/io-submitter.h | 4 ++--
 drivers/md/dm-vdo/vio.c          | 4 ++--
 drivers/md/dm-vdo/vio.h          | 4 ++--
 6 files changed, 10 insertions(+), 10 deletions(-)
drivers/md/dm-vdo/block-map.c +1 -1
index 1278a5791160..cc87e1ac72b6 100644
@@ -1620,7 +1620,7 @@ static void write_initialized_page(struct vdo_completion *completion)
 	struct block_map_zone *zone = pooled->context;
 	struct tree_page *tree_page = completion->parent;
 	struct block_map_page *page = (struct block_map_page *) vio->data;
-	unsigned int operation = REQ_OP_WRITE | REQ_PRIO;
+	blk_opf_t operation = REQ_OP_WRITE | REQ_PRIO;
 
 	/*
 	 * Now that we know the page has been written at least once, mark the copy we are writing
drivers/md/dm-vdo/data-vio.c +2 -2
index 328b645dee16..e0f1574ae112 100644
@@ -69,7 +69,7 @@
  *   ASAP to service heavy load, which is the only place where REQ_BACKGROUND might aid in load
  *   prioritization.
  */
-static unsigned int PASSTHROUGH_FLAGS = (REQ_PRIO | REQ_META | REQ_SYNC | REQ_RAHEAD);
+static blk_opf_t PASSTHROUGH_FLAGS = (REQ_PRIO | REQ_META | REQ_SYNC | REQ_RAHEAD);
 
 /**
  * DOC:
@@ -1570,7 +1570,7 @@ static void read_block(struct vdo_completion *completion)
 		result = vio_reset_bio(vio, (char *) data_vio->compression.block,
 				       read_endio, REQ_OP_READ, data_vio->mapped.pbn);
 	} else {
-		int opf = ((data_vio->user_bio->bi_opf & PASSTHROUGH_FLAGS) | REQ_OP_READ);
+		blk_opf_t opf = ((data_vio->user_bio->bi_opf & PASSTHROUGH_FLAGS) | REQ_OP_READ);
 
 		if (data_vio->is_partial) {
 			result = vio_reset_bio(vio, vio->data, read_endio, opf,
drivers/md/dm-vdo/io-submitter.c +1 -1
index 74f33a3ddce5..6c050f2b3b44 100644
@@ -338,7 +338,7 @@ void vdo_submit_data_vio(struct data_vio *data_vio)
  */
 void __submit_metadata_vio(struct vio *vio, physical_block_number_t physical,
 			   bio_end_io_t callback, vdo_action_fn error_handler,
-			   unsigned int operation, char *data)
+			   blk_opf_t operation, char *data)
 {
 	int result;
 	struct vdo_completion *completion = &vio->completion;
drivers/md/dm-vdo/io-submitter.h +2 -2
index ddd5f4b391b6..80748699496f 100644
@@ -26,11 +26,11 @@ void vdo_submit_data_vio(struct data_vio *data_vio);
 
 void __submit_metadata_vio(struct vio *vio, physical_block_number_t physical,
 			   bio_end_io_t callback, vdo_action_fn error_handler,
-			   unsigned int operation, char *data);
+			   blk_opf_t operation, char *data);
 
 static inline void vdo_submit_metadata_vio(struct vio *vio, physical_block_number_t physical,
 					   bio_end_io_t callback, vdo_action_fn error_handler,
-					   unsigned int operation)
+					   blk_opf_t operation)
 {
 	__submit_metadata_vio(vio, physical, callback, error_handler,
 			      operation, vio->data);
drivers/md/dm-vdo/vio.c +2 -2
index 6acaba149c75..f9c54ec56176 100644
@@ -172,7 +172,7 @@ void free_vio(struct vio *vio)
 
 /* Set bio properties for a VDO read or write. */
 void vdo_set_bio_properties(struct bio *bio, struct vio *vio, bio_end_io_t callback,
-			    unsigned int bi_opf, physical_block_number_t pbn)
+			    blk_opf_t bi_opf, physical_block_number_t pbn)
 {
 	struct vdo *vdo = vio->completion.vdo;
 	struct device_config *config = vdo->device_config;
@@ -193,7 +193,7 @@ void vdo_set_bio_properties(struct bio *bio, struct vio *vio, bio_end_io_t callb
  * vio associated with the bio.
  */
 int vio_reset_bio(struct vio *vio, char *data, bio_end_io_t callback,
-		  unsigned int bi_opf, physical_block_number_t pbn)
+		  blk_opf_t bi_opf, physical_block_number_t pbn)
 {
 	int bvec_count, offset, len, i;
 	struct bio *bio = vio->bio;
drivers/md/dm-vdo/vio.h +2 -2
index 71585424f85b..fbfee5e3415d 100644
@@ -119,10 +119,10 @@ static inline void initialize_vio(struct vio *vio, struct bio *bio,
 }
 
 void vdo_set_bio_properties(struct bio *bio, struct vio *vio, bio_end_io_t callback,
-			    unsigned int bi_opf, physical_block_number_t pbn);
+			    blk_opf_t bi_opf, physical_block_number_t pbn);
 
 int vio_reset_bio(struct vio *vio, char *data, bio_end_io_t callback,
-		  unsigned int bi_opf, physical_block_number_t pbn);
+		  blk_opf_t bi_opf, physical_block_number_t pbn);
 
 void update_vio_error_stats(struct vio *vio, const char *format, ...)
 	__printf(2, 3);
Signature · 1 line
2.42.0
author maintainer
#4 lore raw

PATCH 4/7 dm vdo data-vio: silence sparse warnings about locking context imbalances

In reply to Matthew Sakai

From: Mike Snitzer <[email protected]>

Factor wait_permit() out from acquire_permit() so that the latter always holds the spinlock and the former always releases it.

Otherwise sparse complains about locking context imbalances due to conditional spin_unlock in acquire_permit:
warning: context imbalance in 'acquire_permit' - different lock contexts for basic block
warning: context imbalance in 'vdo_launch_bio' - unexpected unlock

---
 drivers/md/dm-vdo/data-vio.c | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)
drivers/md/dm-vdo/data-vio.c +21 -14
index e0f1574ae112..d77adeb5006e 100644
@@ -929,27 +929,30 @@ void free_data_vio_pool(struct data_vio_pool *pool)
 	uds_free(pool);
 }
 
-static bool acquire_permit(struct limiter *limiter, struct bio *bio)
+static bool acquire_permit(struct limiter *limiter)
 {
-	if (limiter->busy >= limiter->limit) {
-		DEFINE_WAIT(wait);
-
-		bio_list_add(&limiter->new_waiters, bio);
-		prepare_to_wait_exclusive(&limiter->blocked_threads, &wait,
-					  TASK_UNINTERRUPTIBLE);
-		spin_unlock(&limiter->pool->lock);
-		io_schedule();
-		finish_wait(&limiter->blocked_threads, &wait);
+	if (limiter->busy >= limiter->limit)
 		return false;
-	}
 
 	WRITE_ONCE(limiter->busy, limiter->busy + 1);
 	if (limiter->max_busy < limiter->busy)
 		WRITE_ONCE(limiter->max_busy, limiter->busy);
-
 	return true;
 }
 
+static void wait_permit(struct limiter *limiter, struct bio *bio)
+	__releases(&limiter->pool->lock)
+{
+	DEFINE_WAIT(wait);
+
+	bio_list_add(&limiter->new_waiters, bio);
+	prepare_to_wait_exclusive(&limiter->blocked_threads, &wait,
+				  TASK_UNINTERRUPTIBLE);
+	spin_unlock(&limiter->pool->lock);
+	io_schedule();
+	finish_wait(&limiter->blocked_threads, &wait);
+}
+
 /**
  * vdo_launch_bio() - Acquire a data_vio from the pool, assign the bio to it, and launch it.
  *
@@ -965,11 +968,15 @@ void vdo_launch_bio(struct data_vio_pool *pool, struct bio *bio)
 	bio->bi_private = (void *) jiffies;
 	spin_lock(&pool->lock);
 	if ((bio_op(bio) == REQ_OP_DISCARD) &&
-	    !acquire_permit(&pool->discard_limiter, bio))
+	    !acquire_permit(&pool->discard_limiter)) {
+		wait_permit(&pool->discard_limiter, bio);
 		return;
+	}
 
-	if (!acquire_permit(&pool->limiter, bio))
+	if (!acquire_permit(&pool->limiter)) {
+		wait_permit(&pool->limiter, bio);
 		return;
+	}
 
 	data_vio = get_available_data_vio(pool);
 	spin_unlock(&pool->lock);
Signature · 1 line
2.42.0
author maintainer
#5 lore raw

PATCH 5/7 dm vdo dedupe: silence sparse warnings about locking context imbalances

In reply to Matthew Sakai

From: Mike Snitzer <[email protected]>

Annotate both open_index() and close_index() with __must_hold(&zones->lock) to silence these sparse warnings:
warning: context imbalance in 'close_index' - unexpected unlock
warning: context imbalance in 'open_index' - unexpected unlock

---
 drivers/md/dm-vdo/dedupe.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/md/dm-vdo/dedupe.c +2 -0
index 8533f1669a01..4b00135511dd 100644
@@ -2092,6 +2092,7 @@ static void finish_uds_queue(void *ptr __always_unused)
 }
 
 static void close_index(struct hash_zones *zones)
+	__must_hold(&zones->lock)
 {
 	int result;
 
@@ -2113,6 +2114,7 @@ static void close_index(struct hash_zones *zones)
 }
 
 static void open_index(struct hash_zones *zones)
+	__must_hold(&zones->lock)
 {
 	/* ASSERTION: We enter in IS_CLOSED state. */
 	int result;
Signature · 1 line
2.42.0
author maintainer
#6 lore raw

PATCH 6/7 dm vdo recovery-journal: fix sparse 'mixed bitwiseness' warning

In reply to Matthew Sakai

From: Mike Snitzer <[email protected]>

Only one user of WRITE_FLAGS so no need to factor it out in an enum (which causes sparse's 'mixed bitwiseness' warning). Just use the flags in the only consumer.

---
 drivers/md/dm-vdo/recovery-journal.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/dm-vdo/recovery-journal.c +2 -2
index a6981e5dd017..1e15bfe42cfc 100644
@@ -34,7 +34,6 @@ enum {
 	 */
 	RECOVERY_JOURNAL_RESERVED_BLOCKS =
 		(MAXIMUM_VDO_USER_VIOS / RECOVERY_JOURNAL_ENTRIES_PER_BLOCK) + 2,
-	WRITE_FLAGS = REQ_OP_WRITE | REQ_PRIO | REQ_PREFLUSH | REQ_SYNC | REQ_FUA,
 };
 
 /**
@@ -1398,7 +1397,8 @@ static void write_block(struct vdo_waiter *waiter, void *context __always_unused
 	 * block itself is stable before allowing overwrites of the lbn's previous data.
 	 */
 	vdo_submit_metadata_vio(&block->vio, journal->origin + block->block_number,
-				complete_write_endio, handle_write_error, WRITE_FLAGS);
+				complete_write_endio, handle_write_error,
+				REQ_OP_WRITE | REQ_PRIO | REQ_PREFLUSH | REQ_SYNC | REQ_FUA);
 }
 
 
Signature · 1 line
2.42.0
author maintainer
#7 lore raw

PATCH 7/7 dm vdo: move encoding constants to encodings.h

In reply to Matthew Sakai

From: Susan LeGendre-McGhee <[email protected]>

---
 drivers/md/dm-vdo/constants.h | 12 +++---------
 drivers/md/dm-vdo/encodings.h |  6 ++++++
 2 files changed, 9 insertions(+), 9 deletions(-)
drivers/md/dm-vdo/constants.h +3 -9
index 3a997dd7d0b1..24237bc29f87 100644
@@ -44,6 +44,9 @@ enum {
 	/** The default size of each slab journal, in blocks */
 	DEFAULT_VDO_SLAB_JOURNAL_SIZE = 224,
 
+	/** Unit test minimum */
+	MINIMUM_VDO_SLAB_JOURNAL_BLOCKS = 2,
+
 	/*
 	 * The initial size of lbn_operations and pbn_operations, which is based upon the expected
 	 * maximum number of outstanding VIOs. This value was chosen to make it highly unlikely
@@ -90,13 +93,4 @@ enum {
 	VDO_ZERO_BLOCK = 0,
 };
 
-/** The maximum logical space is 4 petabytes, which is 1 terablock. */
-static const block_count_t MAXIMUM_VDO_LOGICAL_BLOCKS = 1024ULL * 1024 * 1024 * 1024;
-
-/** The maximum physical space is 256 terabytes, which is 64 gigablocks. */
-static const block_count_t MAXIMUM_VDO_PHYSICAL_BLOCKS = 1024ULL * 1024 * 1024 * 64;
-
-/** unit test minimum */
-static const block_count_t MINIMUM_VDO_SLAB_JOURNAL_BLOCKS = 2;
-
 #endif /* VDO_CONSTANTS_H */
drivers/md/dm-vdo/encodings.h +6 -0
index 260822a3958a..bfc397a72f9f 100644
@@ -609,6 +609,12 @@ struct vdo_config {
 	block_count_t slab_journal_blocks; /* number of slab journal blocks */
 };
 
+/** The maximum logical space is 4 petabytes, which is 1 terablock. */
+static const block_count_t MAXIMUM_VDO_LOGICAL_BLOCKS = 1024ULL * 1024 * 1024 * 1024;
+
+/** The maximum physical space is 256 terabytes, which is 64 gigablocks. */
+static const block_count_t MAXIMUM_VDO_PHYSICAL_BLOCKS = 1024ULL * 1024 * 1024 * 64;
+
 /* This is the structure that captures the vdo fields saved as a super block component. */
 struct vdo_component {
 	enum vdo_state state;
Signature · 1 line
2.42.0