Skip to content

Commit efa916a

Browse files
committed
Merge tag 'for-5.15/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device mapper updates from Mike Snitzer: - Add DM infrastructure for IMA-based remote attestion. These changes are the basis for deploying DM-based storage in a "cloud" that must validate configurations end-users run to maintain trust. These DM changes allow supported DM targets' configurations to be measured via IMA. But the policy and enforcement (of which configurations are valid) is managed by something outside the kernel (e.g. Keylime). - Fix DM crypt scalability regression on systems with many cpus due to percpu_counter spinlock contention in crypt_page_alloc(). - Use in_hardirq() instead of deprecated in_irq() in DM crypt. - Add event counters to DM writecache to allow users to further assess how the writecache is performing. - Various code cleanup in DM writecache's main IO mapping function. * tag 'for-5.15/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm crypt: use in_hardirq() instead of deprecated in_irq() dm ima: update dm documentation for ima measurement support dm ima: update dm target attributes for ima measurements dm ima: add a warning in dm_init if duplicate ima events are not measured dm ima: prefix ima event name related to device mapper with dm_ dm ima: add version info to dm related events in ima log dm ima: prefix dm table hashes in ima log with hash algorithm dm crypt: Avoid percpu_counter spinlock contention in crypt_page_alloc() dm: add documentation for IMA measurement support dm: update target status functions to support IMA measurement dm ima: measure data on device rename dm ima: measure data on table clear dm ima: measure data on device remove dm ima: measure data on device resume dm ima: measure data on table load dm writecache: add event counters dm writecache: report invalid return from writecache_map helpers dm writecache: further writecache_map() cleanup dm writecache: factor out writecache_map_remap_origin() dm writecache: split up writecache_map() to improve code readability
2 parents a998a62 + d3703ef commit efa916a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2235
-197
lines changed

Documentation/admin-guide/device-mapper/dm-ima.rst

Lines changed: 715 additions & 0 deletions
Large diffs are not rendered by default.

Documentation/admin-guide/device-mapper/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Device Mapper
1313
dm-dust
1414
dm-ebs
1515
dm-flakey
16+
dm-ima
1617
dm-init
1718
dm-integrity
1819
dm-io

Documentation/admin-guide/device-mapper/writecache.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,23 @@ Status:
7878
2. the number of blocks
7979
3. the number of free blocks
8080
4. the number of blocks under writeback
81+
5. the number of read requests
82+
6. the number of read requests that hit the cache
83+
7. the number of write requests
84+
8. the number of write requests that hit uncommitted block
85+
9. the number of write requests that hit committed block
86+
10. the number of write requests that bypass the cache
87+
11. the number of write requests that are allocated in the cache
88+
12. the number of write requests that are blocked on the freelist
89+
13. the number of flush requests
90+
14. the number of discard requests
8191

8292
Messages:
8393
flush
84-
flush the cache device. The message returns successfully
94+
Flush the cache device. The message returns successfully
8595
if the cache device was flushed without an error
8696
flush_on_suspend
87-
flush the cache device on next suspend. Use this message
97+
Flush the cache device on next suspend. Use this message
8898
when you are going to remove the cache device. The proper
8999
sequence for removing the cache device is:
90100

@@ -98,3 +108,5 @@ Messages:
98108
6. the cache device is now inactive and it can be deleted
99109
cleaner
100110
See above "cleaner" constructor documentation.
111+
clear_stats
112+
Clear the statistics that are reported on the status line

drivers/md/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ ifeq ($(CONFIG_BLK_DEV_ZONED),y)
9696
dm-mod-objs += dm-zone.o
9797
endif
9898

99+
ifeq ($(CONFIG_IMA),y)
100+
dm-mod-objs += dm-ima.o
101+
endif
102+
99103
ifeq ($(CONFIG_DM_VERITY_FEC),y)
100104
dm-verity-objs += dm-verity-fec.o
101105
endif

drivers/md/dm-cache-target.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3122,6 +3122,30 @@ static void cache_status(struct dm_target *ti, status_type_t type,
31223122
DMEMIT(" %s", cache->ctr_args[i]);
31233123
if (cache->nr_ctr_args)
31243124
DMEMIT(" %s", cache->ctr_args[cache->nr_ctr_args - 1]);
3125+
break;
3126+
3127+
case STATUSTYPE_IMA:
3128+
DMEMIT_TARGET_NAME_VERSION(ti->type);
3129+
if (get_cache_mode(cache) == CM_FAIL)
3130+
DMEMIT(",metadata_mode=fail");
3131+
else if (get_cache_mode(cache) == CM_READ_ONLY)
3132+
DMEMIT(",metadata_mode=ro");
3133+
else
3134+
DMEMIT(",metadata_mode=rw");
3135+
3136+
format_dev_t(buf, cache->metadata_dev->bdev->bd_dev);
3137+
DMEMIT(",cache_metadata_device=%s", buf);
3138+
format_dev_t(buf, cache->cache_dev->bdev->bd_dev);
3139+
DMEMIT(",cache_device=%s", buf);
3140+
format_dev_t(buf, cache->origin_dev->bdev->bd_dev);
3141+
DMEMIT(",cache_origin_device=%s", buf);
3142+
DMEMIT(",writethrough=%c", writethrough_mode(cache) ? 'y' : 'n');
3143+
DMEMIT(",writeback=%c", writeback_mode(cache) ? 'y' : 'n');
3144+
DMEMIT(",passthrough=%c", passthrough_mode(cache) ? 'y' : 'n');
3145+
DMEMIT(",metadata2=%c", cache->features.metadata_version == 2 ? 'y' : 'n');
3146+
DMEMIT(",no_discard_passdown=%c", cache->features.discard_passdown ? 'n' : 'y');
3147+
DMEMIT(";");
3148+
break;
31253149
}
31263150

31273151
return;

drivers/md/dm-clone-target.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,11 @@ static void clone_status(struct dm_target *ti, status_type_t type,
14991499

15001500
for (i = 0; i < clone->nr_ctr_args; i++)
15011501
DMEMIT(" %s", clone->ctr_args[i]);
1502+
break;
1503+
1504+
case STATUSTYPE_IMA:
1505+
*result = '\0';
1506+
break;
15021507
}
15031508

15041509
return;

drivers/md/dm-core.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <trace/events/block.h>
1919

2020
#include "dm.h"
21+
#include "dm-ima.h"
2122

2223
#define DM_RESERVED_MAX_IOS 1024
2324

@@ -119,6 +120,10 @@ struct mapped_device {
119120
unsigned int nr_zones;
120121
unsigned int *zwp_offset;
121122
#endif
123+
124+
#ifdef CONFIG_IMA
125+
struct dm_ima_measurements ima;
126+
#endif
122127
};
123128

124129
/*

drivers/md/dm-crypt.c

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,11 +2223,11 @@ static void kcryptd_queue_crypt(struct dm_crypt_io *io)
22232223
if ((bio_data_dir(io->base_bio) == READ && test_bit(DM_CRYPT_NO_READ_WORKQUEUE, &cc->flags)) ||
22242224
(bio_data_dir(io->base_bio) == WRITE && test_bit(DM_CRYPT_NO_WRITE_WORKQUEUE, &cc->flags))) {
22252225
/*
2226-
* in_irq(): Crypto API's skcipher_walk_first() refuses to work in hard IRQ context.
2226+
* in_hardirq(): Crypto API's skcipher_walk_first() refuses to work in hard IRQ context.
22272227
* irqs_disabled(): the kernel may run some IO completion from the idle thread, but
22282228
* it is being executed with irqs disabled.
22292229
*/
2230-
if (in_irq() || irqs_disabled()) {
2230+
if (in_hardirq() || irqs_disabled()) {
22312231
tasklet_init(&io->tasklet, kcryptd_crypt_tasklet, (unsigned long)&io->work);
22322232
tasklet_schedule(&io->tasklet);
22332233
return;
@@ -2661,7 +2661,12 @@ static void *crypt_page_alloc(gfp_t gfp_mask, void *pool_data)
26612661
struct crypt_config *cc = pool_data;
26622662
struct page *page;
26632663

2664-
if (unlikely(percpu_counter_compare(&cc->n_allocated_pages, dm_crypt_pages_per_client) >= 0) &&
2664+
/*
2665+
* Note, percpu_counter_read_positive() may over (and under) estimate
2666+
* the current usage by at most (batch - 1) * num_online_cpus() pages,
2667+
* but avoids potential spinlock contention of an exact result.
2668+
*/
2669+
if (unlikely(percpu_counter_read_positive(&cc->n_allocated_pages) >= dm_crypt_pages_per_client) &&
26652670
likely(gfp_mask & __GFP_NORETRY))
26662671
return NULL;
26672672

@@ -3485,7 +3490,34 @@ static void crypt_status(struct dm_target *ti, status_type_t type,
34853490
if (test_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags))
34863491
DMEMIT(" iv_large_sectors");
34873492
}
3493+
break;
34883494

3495+
case STATUSTYPE_IMA:
3496+
DMEMIT_TARGET_NAME_VERSION(ti->type);
3497+
DMEMIT(",allow_discards=%c", ti->num_discard_bios ? 'y' : 'n');
3498+
DMEMIT(",same_cpu_crypt=%c", test_bit(DM_CRYPT_SAME_CPU, &cc->flags) ? 'y' : 'n');
3499+
DMEMIT(",submit_from_crypt_cpus=%c", test_bit(DM_CRYPT_NO_OFFLOAD, &cc->flags) ?
3500+
'y' : 'n');
3501+
DMEMIT(",no_read_workqueue=%c", test_bit(DM_CRYPT_NO_READ_WORKQUEUE, &cc->flags) ?
3502+
'y' : 'n');
3503+
DMEMIT(",no_write_workqueue=%c", test_bit(DM_CRYPT_NO_WRITE_WORKQUEUE, &cc->flags) ?
3504+
'y' : 'n');
3505+
DMEMIT(",iv_large_sectors=%c", test_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags) ?
3506+
'y' : 'n');
3507+
3508+
if (cc->on_disk_tag_size)
3509+
DMEMIT(",integrity_tag_size=%u,cipher_auth=%s",
3510+
cc->on_disk_tag_size, cc->cipher_auth);
3511+
if (cc->sector_size != (1 << SECTOR_SHIFT))
3512+
DMEMIT(",sector_size=%d", cc->sector_size);
3513+
if (cc->cipher_string)
3514+
DMEMIT(",cipher_string=%s", cc->cipher_string);
3515+
3516+
DMEMIT(",key_size=%u", cc->key_size);
3517+
DMEMIT(",key_parts=%u", cc->key_parts);
3518+
DMEMIT(",key_extra_size=%u", cc->key_extra_size);
3519+
DMEMIT(",key_mac_size=%u", cc->key_mac_size);
3520+
DMEMIT(";");
34893521
break;
34903522
}
34913523
}

drivers/md/dm-delay.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ static void delay_status(struct dm_target *ti, status_type_t type,
326326
DMEMIT_DELAY_CLASS(&dc->flush);
327327
}
328328
break;
329+
330+
case STATUSTYPE_IMA:
331+
*result = '\0';
332+
break;
329333
}
330334
}
331335

drivers/md/dm-dust.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,10 @@ static void dust_status(struct dm_target *ti, status_type_t type,
527527
DMEMIT("%s %llu %u", dd->dev->name,
528528
(unsigned long long)dd->start, dd->blksz);
529529
break;
530+
531+
case STATUSTYPE_IMA:
532+
*result = '\0';
533+
break;
530534
}
531535
}
532536

0 commit comments

Comments
 (0)