Commit 20cf903a authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'for-6.0/dm-changes-2' of...

Merge tag 'for-6.0/dm-changes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm

Pull more device mapper updates from Mike Snitzer:

 - Add flags argument to dm_bufio_client_create and introduce
   DM_BUFIO_CLIENT_NO_SLEEP flag to have dm-bufio use spinlock rather
   than mutex for its locking.

 - Add optional "try_verify_in_tasklet" feature to DM verity target.
   This feature gives users the option to improve IO latency by using a
   tasklet to verify, using hashes in bufio's cache, rather than wait to
   schedule a work item via workqueue. But if there is a bufio cache
   miss, or an error, then the tasklet will fallback to using workqueue.

 - Incremental changes to both dm-bufio and the DM verity target to use
   jump_label to minimize cost of branching associated with the niche
   "try_verify_in_tasklet" feature. DM-bufio in particular is used by
   quite a few other DM targets so it doesn't make sense to incur
   additional bufio cost in those targets purely for the benefit of this
   niche verity feature if the feature isn't ever used.

 - Optimize verity_verify_io, which is used by both workqueue and
   tasklet based verification, if FEC is not configured or tasklet based
   verification isn't used.

 - Remove DM verity target's verify_wq's use of the WQ_CPU_INTENSIVE
   flag since it uses WQ_UNBOUND. Also, use the WQ_HIGHPRI flag if
   "try_verify_in_tasklet" is specified.

* tag 'for-6.0/dm-changes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm:
  dm verity: have verify_wq use WQ_HIGHPRI if "try_verify_in_tasklet"
  dm verity: remove WQ_CPU_INTENSIVE flag since using WQ_UNBOUND
  dm verity: only copy bvec_iter in verity_verify_io if in_tasklet
  dm verity: optimize verity_verify_io if FEC not configured
  dm verity: conditionally enable branching for "try_verify_in_tasklet"
  dm bufio: conditionally enable branching for DM_BUFIO_CLIENT_NO_SLEEP
  dm verity: allow optional args to alter primary args handling
  dm verity: Add optional "try_verify_in_tasklet" feature
  dm bufio: Add DM_BUFIO_CLIENT_NO_SLEEP flag
  dm bufio: Add flags argument to dm_bufio_client_create
parents c993e07b 12907efd
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/rbtree.h> #include <linux/rbtree.h>
#include <linux/stacktrace.h> #include <linux/stacktrace.h>
#include <linux/jump_label.h>
#define DM_MSG_PREFIX "bufio" #define DM_MSG_PREFIX "bufio"
...@@ -81,6 +82,8 @@ ...@@ -81,6 +82,8 @@
*/ */
struct dm_bufio_client { struct dm_bufio_client {
struct mutex lock; struct mutex lock;
spinlock_t spinlock;
unsigned long spinlock_flags;
struct list_head lru[LIST_SIZE]; struct list_head lru[LIST_SIZE];
unsigned long n_buffers[LIST_SIZE]; unsigned long n_buffers[LIST_SIZE];
...@@ -90,6 +93,7 @@ struct dm_bufio_client { ...@@ -90,6 +93,7 @@ struct dm_bufio_client {
s8 sectors_per_block_bits; s8 sectors_per_block_bits;
void (*alloc_callback)(struct dm_buffer *); void (*alloc_callback)(struct dm_buffer *);
void (*write_callback)(struct dm_buffer *); void (*write_callback)(struct dm_buffer *);
bool no_sleep;
struct kmem_cache *slab_buffer; struct kmem_cache *slab_buffer;
struct kmem_cache *slab_cache; struct kmem_cache *slab_cache;
...@@ -161,23 +165,34 @@ struct dm_buffer { ...@@ -161,23 +165,34 @@ struct dm_buffer {
#endif #endif
}; };
static DEFINE_STATIC_KEY_FALSE(no_sleep_enabled);
/*----------------------------------------------------------------*/ /*----------------------------------------------------------------*/
#define dm_bufio_in_request() (!!current->bio_list) #define dm_bufio_in_request() (!!current->bio_list)
static void dm_bufio_lock(struct dm_bufio_client *c) static void dm_bufio_lock(struct dm_bufio_client *c)
{ {
mutex_lock_nested(&c->lock, dm_bufio_in_request()); if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep)
spin_lock_irqsave_nested(&c->spinlock, c->spinlock_flags, dm_bufio_in_request());
else
mutex_lock_nested(&c->lock, dm_bufio_in_request());
} }
static int dm_bufio_trylock(struct dm_bufio_client *c) static int dm_bufio_trylock(struct dm_bufio_client *c)
{ {
return mutex_trylock(&c->lock); if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep)
return spin_trylock_irqsave(&c->spinlock, c->spinlock_flags);
else
return mutex_trylock(&c->lock);
} }
static void dm_bufio_unlock(struct dm_bufio_client *c) static void dm_bufio_unlock(struct dm_bufio_client *c)
{ {
mutex_unlock(&c->lock); if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep)
spin_unlock_irqrestore(&c->spinlock, c->spinlock_flags);
else
mutex_unlock(&c->lock);
} }
/*----------------------------------------------------------------*/ /*----------------------------------------------------------------*/
...@@ -1715,7 +1730,8 @@ static unsigned long dm_bufio_shrink_count(struct shrinker *shrink, struct shrin ...@@ -1715,7 +1730,8 @@ static unsigned long dm_bufio_shrink_count(struct shrinker *shrink, struct shrin
struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsigned block_size, struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsigned block_size,
unsigned reserved_buffers, unsigned aux_size, unsigned reserved_buffers, unsigned aux_size,
void (*alloc_callback)(struct dm_buffer *), void (*alloc_callback)(struct dm_buffer *),
void (*write_callback)(struct dm_buffer *)) void (*write_callback)(struct dm_buffer *),
unsigned int flags)
{ {
int r; int r;
struct dm_bufio_client *c; struct dm_bufio_client *c;
...@@ -1745,12 +1761,18 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign ...@@ -1745,12 +1761,18 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign
c->alloc_callback = alloc_callback; c->alloc_callback = alloc_callback;
c->write_callback = write_callback; c->write_callback = write_callback;
if (flags & DM_BUFIO_CLIENT_NO_SLEEP) {
c->no_sleep = true;
static_branch_inc(&no_sleep_enabled);
}
for (i = 0; i < LIST_SIZE; i++) { for (i = 0; i < LIST_SIZE; i++) {
INIT_LIST_HEAD(&c->lru[i]); INIT_LIST_HEAD(&c->lru[i]);
c->n_buffers[i] = 0; c->n_buffers[i] = 0;
} }
mutex_init(&c->lock); mutex_init(&c->lock);
spin_lock_init(&c->spinlock);
INIT_LIST_HEAD(&c->reserved_buffers); INIT_LIST_HEAD(&c->reserved_buffers);
c->need_reserved_buffers = reserved_buffers; c->need_reserved_buffers = reserved_buffers;
...@@ -1877,6 +1899,8 @@ void dm_bufio_client_destroy(struct dm_bufio_client *c) ...@@ -1877,6 +1899,8 @@ void dm_bufio_client_destroy(struct dm_bufio_client *c)
kmem_cache_destroy(c->slab_buffer); kmem_cache_destroy(c->slab_buffer);
dm_io_client_destroy(c->dm_io); dm_io_client_destroy(c->dm_io);
mutex_destroy(&c->lock); mutex_destroy(&c->lock);
if (c->no_sleep)
static_branch_dec(&no_sleep_enabled);
kfree(c); kfree(c);
} }
EXPORT_SYMBOL_GPL(dm_bufio_client_destroy); EXPORT_SYMBOL_GPL(dm_bufio_client_destroy);
......
...@@ -313,7 +313,8 @@ static int ebs_ctr(struct dm_target *ti, unsigned int argc, char **argv) ...@@ -313,7 +313,8 @@ static int ebs_ctr(struct dm_target *ti, unsigned int argc, char **argv)
goto bad; goto bad;
} }
ec->bufio = dm_bufio_client_create(ec->dev->bdev, to_bytes(ec->u_bs), 1, 0, NULL, NULL); ec->bufio = dm_bufio_client_create(ec->dev->bdev, to_bytes(ec->u_bs), 1,
0, NULL, NULL, 0);
if (IS_ERR(ec->bufio)) { if (IS_ERR(ec->bufio)) {
ti->error = "Cannot create dm bufio client"; ti->error = "Cannot create dm bufio client";
r = PTR_ERR(ec->bufio); r = PTR_ERR(ec->bufio);
......
...@@ -4439,7 +4439,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv) ...@@ -4439,7 +4439,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
} }
ic->bufio = dm_bufio_client_create(ic->meta_dev ? ic->meta_dev->bdev : ic->dev->bdev, ic->bufio = dm_bufio_client_create(ic->meta_dev ? ic->meta_dev->bdev : ic->dev->bdev,
1U << (SECTOR_SHIFT + ic->log2_buffer_sectors), 1, 0, NULL, NULL); 1U << (SECTOR_SHIFT + ic->log2_buffer_sectors), 1, 0, NULL, NULL, 0);
if (IS_ERR(ic->bufio)) { if (IS_ERR(ic->bufio)) {
r = PTR_ERR(ic->bufio); r = PTR_ERR(ic->bufio);
ti->error = "Cannot initialize dm-bufio"; ti->error = "Cannot initialize dm-bufio";
......
...@@ -493,7 +493,7 @@ static int read_exceptions(struct pstore *ps, ...@@ -493,7 +493,7 @@ static int read_exceptions(struct pstore *ps,
client = dm_bufio_client_create(dm_snap_cow(ps->store->snap)->bdev, client = dm_bufio_client_create(dm_snap_cow(ps->store->snap)->bdev,
ps->store->chunk_size << SECTOR_SHIFT, ps->store->chunk_size << SECTOR_SHIFT,
1, 0, NULL, NULL); 1, 0, NULL, NULL, 0);
if (IS_ERR(client)) if (IS_ERR(client))
return PTR_ERR(client); return PTR_ERR(client);
......
...@@ -749,7 +749,7 @@ int verity_fec_ctr(struct dm_verity *v) ...@@ -749,7 +749,7 @@ int verity_fec_ctr(struct dm_verity *v)
f->bufio = dm_bufio_client_create(f->dev->bdev, f->bufio = dm_bufio_client_create(f->dev->bdev,
f->io_size, f->io_size,
1, 0, NULL, NULL); 1, 0, NULL, NULL, 0);
if (IS_ERR(f->bufio)) { if (IS_ERR(f->bufio)) {
ti->error = "Cannot initialize FEC bufio client"; ti->error = "Cannot initialize FEC bufio client";
return PTR_ERR(f->bufio); return PTR_ERR(f->bufio);
...@@ -765,7 +765,7 @@ int verity_fec_ctr(struct dm_verity *v) ...@@ -765,7 +765,7 @@ int verity_fec_ctr(struct dm_verity *v)
f->data_bufio = dm_bufio_client_create(v->data_dev->bdev, f->data_bufio = dm_bufio_client_create(v->data_dev->bdev,
1 << v->data_dev_block_bits, 1 << v->data_dev_block_bits,
1, 0, NULL, NULL); 1, 0, NULL, NULL, 0);
if (IS_ERR(f->data_bufio)) { if (IS_ERR(f->data_bufio)) {
ti->error = "Cannot initialize FEC data bufio client"; ti->error = "Cannot initialize FEC data bufio client";
return PTR_ERR(f->data_bufio); return PTR_ERR(f->data_bufio);
......
This diff is collapsed.
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <linux/dm-bufio.h> #include <linux/dm-bufio.h>
#include <linux/device-mapper.h> #include <linux/device-mapper.h>
#include <linux/interrupt.h>
#include <crypto/hash.h> #include <crypto/hash.h>
#define DM_VERITY_MAX_LEVELS 63 #define DM_VERITY_MAX_LEVELS 63
...@@ -51,9 +52,10 @@ struct dm_verity { ...@@ -51,9 +52,10 @@ struct dm_verity {
unsigned char hash_per_block_bits; /* log2(hashes in hash block) */ unsigned char hash_per_block_bits; /* log2(hashes in hash block) */
unsigned char levels; /* the number of tree levels */ unsigned char levels; /* the number of tree levels */
unsigned char version; unsigned char version;
bool hash_failed:1; /* set if hash of any block failed */
bool use_tasklet:1; /* try to verify in tasklet before work-queue */
unsigned digest_size; /* digest size for the current hash algorithm */ unsigned digest_size; /* digest size for the current hash algorithm */
unsigned int ahash_reqsize;/* the size of temporary space for crypto */ unsigned int ahash_reqsize;/* the size of temporary space for crypto */
int hash_failed; /* set to 1 if hash of any block failed */
enum verity_mode mode; /* mode for handling verification errors */ enum verity_mode mode; /* mode for handling verification errors */
unsigned corrupted_errs;/* Number of errors for corrupted blocks */ unsigned corrupted_errs;/* Number of errors for corrupted blocks */
...@@ -76,10 +78,12 @@ struct dm_verity_io { ...@@ -76,10 +78,12 @@ struct dm_verity_io {
sector_t block; sector_t block;
unsigned n_blocks; unsigned n_blocks;
bool in_tasklet;
struct bvec_iter iter; struct bvec_iter iter;
struct work_struct work; struct work_struct work;
struct tasklet_struct tasklet;
/* /*
* Three variably-size fields follow this struct: * Three variably-size fields follow this struct:
......
...@@ -391,7 +391,8 @@ struct dm_block_manager *dm_block_manager_create(struct block_device *bdev, ...@@ -391,7 +391,8 @@ struct dm_block_manager *dm_block_manager_create(struct block_device *bdev,
bm->bufio = dm_bufio_client_create(bdev, block_size, max_held_per_thread, bm->bufio = dm_bufio_client_create(bdev, block_size, max_held_per_thread,
sizeof(struct buffer_aux), sizeof(struct buffer_aux),
dm_block_manager_alloc_callback, dm_block_manager_alloc_callback,
dm_block_manager_write_callback); dm_block_manager_write_callback,
0);
if (IS_ERR(bm->bufio)) { if (IS_ERR(bm->bufio)) {
r = PTR_ERR(bm->bufio); r = PTR_ERR(bm->bufio);
kfree(bm); kfree(bm);
......
...@@ -17,6 +17,11 @@ ...@@ -17,6 +17,11 @@
struct dm_bufio_client; struct dm_bufio_client;
struct dm_buffer; struct dm_buffer;
/*
* Flags for dm_bufio_client_create
*/
#define DM_BUFIO_CLIENT_NO_SLEEP 0x1
/* /*
* Create a buffered IO cache on a given device * Create a buffered IO cache on a given device
*/ */
...@@ -24,7 +29,8 @@ struct dm_bufio_client * ...@@ -24,7 +29,8 @@ struct dm_bufio_client *
dm_bufio_client_create(struct block_device *bdev, unsigned block_size, dm_bufio_client_create(struct block_device *bdev, unsigned block_size,
unsigned reserved_buffers, unsigned aux_size, unsigned reserved_buffers, unsigned aux_size,
void (*alloc_callback)(struct dm_buffer *), void (*alloc_callback)(struct dm_buffer *),
void (*write_callback)(struct dm_buffer *)); void (*write_callback)(struct dm_buffer *),
unsigned int flags);
/* /*
* Release a buffered IO cache. * Release a buffered IO cache.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment