47
47
48
48
#define DM_MSG_PREFIX "crypt"
49
49
50
+ static DEFINE_IDA (workqueue_ida );
51
+
50
52
/*
51
53
* context holding the current state of a multi-part conversion
52
54
*/
@@ -137,9 +139,9 @@ struct iv_elephant_private {
137
139
* and encrypts / decrypts at the same time.
138
140
*/
139
141
enum flags { DM_CRYPT_SUSPENDED , DM_CRYPT_KEY_VALID ,
140
- DM_CRYPT_SAME_CPU , DM_CRYPT_NO_OFFLOAD ,
141
- DM_CRYPT_NO_READ_WORKQUEUE , DM_CRYPT_NO_WRITE_WORKQUEUE ,
142
- DM_CRYPT_WRITE_INLINE };
142
+ DM_CRYPT_SAME_CPU , DM_CRYPT_HIGH_PRIORITY ,
143
+ DM_CRYPT_NO_OFFLOAD , DM_CRYPT_NO_READ_WORKQUEUE ,
144
+ DM_CRYPT_NO_WRITE_WORKQUEUE , DM_CRYPT_WRITE_INLINE };
143
145
144
146
enum cipher_flags {
145
147
CRYPT_MODE_INTEGRITY_AEAD , /* Use authenticated mode for cipher */
@@ -184,6 +186,7 @@ struct crypt_config {
184
186
struct crypto_aead * * tfms_aead ;
185
187
} cipher_tfm ;
186
188
unsigned int tfms_count ;
189
+ int workqueue_id ;
187
190
unsigned long cipher_flags ;
188
191
189
192
/*
@@ -1653,8 +1656,8 @@ static void crypt_free_buffer_pages(struct crypt_config *cc, struct bio *clone);
1653
1656
1654
1657
/*
1655
1658
* Generate a new unfragmented bio with the given size
1656
- * This should never violate the device limitations (but only because
1657
- * max_segment_size is being constrained to PAGE_SIZE ).
1659
+ * This should never violate the device limitations (but if it did then block
1660
+ * core should split the bio as needed ).
1658
1661
*
1659
1662
* This function may be called concurrently. If we allocate from the mempool
1660
1663
* concurrently, there is a possibility of deadlock. For example, if we have
@@ -2771,6 +2774,9 @@ static void crypt_dtr(struct dm_target *ti)
2771
2774
if (cc -> crypt_queue )
2772
2775
destroy_workqueue (cc -> crypt_queue );
2773
2776
2777
+ if (cc -> workqueue_id )
2778
+ ida_free (& workqueue_ida , cc -> workqueue_id );
2779
+
2774
2780
crypt_free_tfms (cc );
2775
2781
2776
2782
bioset_exit (& cc -> bs );
@@ -3134,7 +3140,7 @@ static int crypt_ctr_optional(struct dm_target *ti, unsigned int argc, char **ar
3134
3140
struct crypt_config * cc = ti -> private ;
3135
3141
struct dm_arg_set as ;
3136
3142
static const struct dm_arg _args [] = {
3137
- {0 , 8 , "Invalid number of feature args" },
3143
+ {0 , 9 , "Invalid number of feature args" },
3138
3144
};
3139
3145
unsigned int opt_params , val ;
3140
3146
const char * opt_string , * sval ;
@@ -3161,6 +3167,8 @@ static int crypt_ctr_optional(struct dm_target *ti, unsigned int argc, char **ar
3161
3167
3162
3168
else if (!strcasecmp (opt_string , "same_cpu_crypt" ))
3163
3169
set_bit (DM_CRYPT_SAME_CPU , & cc -> flags );
3170
+ else if (!strcasecmp (opt_string , "high_priority" ))
3171
+ set_bit (DM_CRYPT_HIGH_PRIORITY , & cc -> flags );
3164
3172
3165
3173
else if (!strcasecmp (opt_string , "submit_from_crypt_cpus" ))
3166
3174
set_bit (DM_CRYPT_NO_OFFLOAD , & cc -> flags );
@@ -3230,8 +3238,9 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
3230
3238
{
3231
3239
struct crypt_config * cc ;
3232
3240
const char * devname = dm_table_device_name (ti -> table );
3233
- int key_size ;
3241
+ int key_size , wq_id ;
3234
3242
unsigned int align_mask ;
3243
+ unsigned int common_wq_flags ;
3235
3244
unsigned long long tmpll ;
3236
3245
int ret ;
3237
3246
size_t iv_size_padding , additional_req_size ;
@@ -3398,20 +3407,38 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
3398
3407
cc -> tag_pool_max_sectors <<= cc -> sector_shift ;
3399
3408
}
3400
3409
3410
+ wq_id = ida_alloc_min (& workqueue_ida , 1 , GFP_KERNEL );
3411
+ if (wq_id < 0 ) {
3412
+ ti -> error = "Couldn't get workqueue id" ;
3413
+ ret = wq_id ;
3414
+ goto bad ;
3415
+ }
3416
+ cc -> workqueue_id = wq_id ;
3417
+
3401
3418
ret = - ENOMEM ;
3402
- cc -> io_queue = alloc_workqueue ("kcryptd_io/%s" , WQ_MEM_RECLAIM , 1 , devname );
3419
+ common_wq_flags = WQ_MEM_RECLAIM | WQ_SYSFS ;
3420
+ if (test_bit (DM_CRYPT_HIGH_PRIORITY , & cc -> flags ))
3421
+ common_wq_flags |= WQ_HIGHPRI ;
3422
+
3423
+ cc -> io_queue = alloc_workqueue ("kcryptd_io-%s-%d" , common_wq_flags , 1 , devname , wq_id );
3403
3424
if (!cc -> io_queue ) {
3404
3425
ti -> error = "Couldn't create kcryptd io queue" ;
3405
3426
goto bad ;
3406
3427
}
3407
3428
3408
- if (test_bit (DM_CRYPT_SAME_CPU , & cc -> flags ))
3409
- cc -> crypt_queue = alloc_workqueue ("kcryptd/%s" , WQ_CPU_INTENSIVE | WQ_MEM_RECLAIM ,
3410
- 1 , devname );
3411
- else
3412
- cc -> crypt_queue = alloc_workqueue ("kcryptd/%s" ,
3413
- WQ_CPU_INTENSIVE | WQ_MEM_RECLAIM | WQ_UNBOUND ,
3414
- num_online_cpus (), devname );
3429
+ if (test_bit (DM_CRYPT_SAME_CPU , & cc -> flags )) {
3430
+ cc -> crypt_queue = alloc_workqueue ("kcryptd-%s-%d" ,
3431
+ common_wq_flags | WQ_CPU_INTENSIVE ,
3432
+ 1 , devname , wq_id );
3433
+ } else {
3434
+ /*
3435
+ * While crypt_queue is certainly CPU intensive, the use of
3436
+ * WQ_CPU_INTENSIVE is meaningless with WQ_UNBOUND.
3437
+ */
3438
+ cc -> crypt_queue = alloc_workqueue ("kcryptd-%s-%d" ,
3439
+ common_wq_flags | WQ_UNBOUND ,
3440
+ num_online_cpus (), devname , wq_id );
3441
+ }
3415
3442
if (!cc -> crypt_queue ) {
3416
3443
ti -> error = "Couldn't create kcryptd queue" ;
3417
3444
goto bad ;
@@ -3427,6 +3454,8 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
3427
3454
ti -> error = "Couldn't spawn write thread" ;
3428
3455
goto bad ;
3429
3456
}
3457
+ if (test_bit (DM_CRYPT_HIGH_PRIORITY , & cc -> flags ))
3458
+ set_user_nice (cc -> write_thread , MIN_NICE );
3430
3459
3431
3460
ti -> num_flush_bios = 1 ;
3432
3461
ti -> limit_swap_bios = true;
@@ -3547,6 +3576,7 @@ static void crypt_status(struct dm_target *ti, status_type_t type,
3547
3576
3548
3577
num_feature_args += !!ti -> num_discard_bios ;
3549
3578
num_feature_args += test_bit (DM_CRYPT_SAME_CPU , & cc -> flags );
3579
+ num_feature_args += test_bit (DM_CRYPT_HIGH_PRIORITY , & cc -> flags );
3550
3580
num_feature_args += test_bit (DM_CRYPT_NO_OFFLOAD , & cc -> flags );
3551
3581
num_feature_args += test_bit (DM_CRYPT_NO_READ_WORKQUEUE , & cc -> flags );
3552
3582
num_feature_args += test_bit (DM_CRYPT_NO_WRITE_WORKQUEUE , & cc -> flags );
@@ -3560,6 +3590,8 @@ static void crypt_status(struct dm_target *ti, status_type_t type,
3560
3590
DMEMIT (" allow_discards" );
3561
3591
if (test_bit (DM_CRYPT_SAME_CPU , & cc -> flags ))
3562
3592
DMEMIT (" same_cpu_crypt" );
3593
+ if (test_bit (DM_CRYPT_HIGH_PRIORITY , & cc -> flags ))
3594
+ DMEMIT (" high_priority" );
3563
3595
if (test_bit (DM_CRYPT_NO_OFFLOAD , & cc -> flags ))
3564
3596
DMEMIT (" submit_from_crypt_cpus" );
3565
3597
if (test_bit (DM_CRYPT_NO_READ_WORKQUEUE , & cc -> flags ))
@@ -3579,6 +3611,7 @@ static void crypt_status(struct dm_target *ti, status_type_t type,
3579
3611
DMEMIT_TARGET_NAME_VERSION (ti -> type );
3580
3612
DMEMIT (",allow_discards=%c" , ti -> num_discard_bios ? 'y' : 'n' );
3581
3613
DMEMIT (",same_cpu_crypt=%c" , test_bit (DM_CRYPT_SAME_CPU , & cc -> flags ) ? 'y' : 'n' );
3614
+ DMEMIT (",high_priority=%c" , test_bit (DM_CRYPT_HIGH_PRIORITY , & cc -> flags ) ? 'y' : 'n' );
3582
3615
DMEMIT (",submit_from_crypt_cpus=%c" , test_bit (DM_CRYPT_NO_OFFLOAD , & cc -> flags ) ?
3583
3616
'y' : 'n' );
3584
3617
DMEMIT (",no_read_workqueue=%c" , test_bit (DM_CRYPT_NO_READ_WORKQUEUE , & cc -> flags ) ?
@@ -3688,14 +3721,6 @@ static void crypt_io_hints(struct dm_target *ti, struct queue_limits *limits)
3688
3721
{
3689
3722
struct crypt_config * cc = ti -> private ;
3690
3723
3691
- /*
3692
- * Unfortunate constraint that is required to avoid the potential
3693
- * for exceeding underlying device's max_segments limits -- due to
3694
- * crypt_alloc_buffer() possibly allocating pages for the encryption
3695
- * bio that are not as physically contiguous as the original bio.
3696
- */
3697
- limits -> max_segment_size = PAGE_SIZE ;
3698
-
3699
3724
limits -> logical_block_size =
3700
3725
max_t (unsigned int , limits -> logical_block_size , cc -> sector_size );
3701
3726
limits -> physical_block_size =
@@ -3706,7 +3731,7 @@ static void crypt_io_hints(struct dm_target *ti, struct queue_limits *limits)
3706
3731
3707
3732
static struct target_type crypt_target = {
3708
3733
.name = "crypt" ,
3709
- .version = {1 , 25 , 0 },
3734
+ .version = {1 , 26 , 0 },
3710
3735
.module = THIS_MODULE ,
3711
3736
.ctr = crypt_ctr ,
3712
3737
.dtr = crypt_dtr ,
0 commit comments