@@ -1454,13 +1454,16 @@ static int crypt_convert_block_skcipher(struct crypt_config *cc,
1454
1454
static void kcryptd_async_done (struct crypto_async_request * async_req ,
1455
1455
int error );
1456
1456
1457
- static void crypt_alloc_req_skcipher (struct crypt_config * cc ,
1457
+ static int crypt_alloc_req_skcipher (struct crypt_config * cc ,
1458
1458
struct convert_context * ctx )
1459
1459
{
1460
1460
unsigned key_index = ctx -> cc_sector & (cc -> tfms_count - 1 );
1461
1461
1462
- if (!ctx -> r .req )
1463
- ctx -> r .req = mempool_alloc (& cc -> req_pool , GFP_NOIO );
1462
+ if (!ctx -> r .req ) {
1463
+ ctx -> r .req = mempool_alloc (& cc -> req_pool , in_interrupt () ? GFP_ATOMIC : GFP_NOIO );
1464
+ if (!ctx -> r .req )
1465
+ return - ENOMEM ;
1466
+ }
1464
1467
1465
1468
skcipher_request_set_tfm (ctx -> r .req , cc -> cipher_tfm .tfms [key_index ]);
1466
1469
@@ -1471,13 +1474,18 @@ static void crypt_alloc_req_skcipher(struct crypt_config *cc,
1471
1474
skcipher_request_set_callback (ctx -> r .req ,
1472
1475
CRYPTO_TFM_REQ_MAY_BACKLOG ,
1473
1476
kcryptd_async_done , dmreq_of_req (cc , ctx -> r .req ));
1477
+
1478
+ return 0 ;
1474
1479
}
1475
1480
1476
- static void crypt_alloc_req_aead (struct crypt_config * cc ,
1481
+ static int crypt_alloc_req_aead (struct crypt_config * cc ,
1477
1482
struct convert_context * ctx )
1478
1483
{
1479
- if (!ctx -> r .req_aead )
1480
- ctx -> r .req_aead = mempool_alloc (& cc -> req_pool , GFP_NOIO );
1484
+ if (!ctx -> r .req ) {
1485
+ ctx -> r .req = mempool_alloc (& cc -> req_pool , in_interrupt () ? GFP_ATOMIC : GFP_NOIO );
1486
+ if (!ctx -> r .req )
1487
+ return - ENOMEM ;
1488
+ }
1481
1489
1482
1490
aead_request_set_tfm (ctx -> r .req_aead , cc -> cipher_tfm .tfms_aead [0 ]);
1483
1491
@@ -1488,15 +1496,17 @@ static void crypt_alloc_req_aead(struct crypt_config *cc,
1488
1496
aead_request_set_callback (ctx -> r .req_aead ,
1489
1497
CRYPTO_TFM_REQ_MAY_BACKLOG ,
1490
1498
kcryptd_async_done , dmreq_of_req (cc , ctx -> r .req_aead ));
1499
+
1500
+ return 0 ;
1491
1501
}
1492
1502
1493
- static void crypt_alloc_req (struct crypt_config * cc ,
1503
+ static int crypt_alloc_req (struct crypt_config * cc ,
1494
1504
struct convert_context * ctx )
1495
1505
{
1496
1506
if (crypt_integrity_aead (cc ))
1497
- crypt_alloc_req_aead (cc , ctx );
1507
+ return crypt_alloc_req_aead (cc , ctx );
1498
1508
else
1499
- crypt_alloc_req_skcipher (cc , ctx );
1509
+ return crypt_alloc_req_skcipher (cc , ctx );
1500
1510
}
1501
1511
1502
1512
static void crypt_free_req_skcipher (struct crypt_config * cc ,
@@ -1539,7 +1549,12 @@ static blk_status_t crypt_convert(struct crypt_config *cc,
1539
1549
1540
1550
while (ctx -> iter_in .bi_size && ctx -> iter_out .bi_size ) {
1541
1551
1542
- crypt_alloc_req (cc , ctx );
1552
+ r = crypt_alloc_req (cc , ctx );
1553
+ if (r ) {
1554
+ complete (& ctx -> restart );
1555
+ return BLK_STS_DEV_RESOURCE ;
1556
+ }
1557
+
1543
1558
atomic_inc (& ctx -> cc_pending );
1544
1559
1545
1560
if (crypt_integrity_aead (cc ))
0 commit comments