@@ -1288,7 +1288,8 @@ static void blkif_free_ring(struct blkfront_ring_info *rinfo)
1288
1288
rinfo -> ring_ref [i ] = GRANT_INVALID_REF ;
1289
1289
}
1290
1290
}
1291
- free_pages ((unsigned long )rinfo -> ring .sring , get_order (info -> nr_ring_pages * XEN_PAGE_SIZE ));
1291
+ free_pages_exact (rinfo -> ring .sring ,
1292
+ info -> nr_ring_pages * XEN_PAGE_SIZE );
1292
1293
rinfo -> ring .sring = NULL ;
1293
1294
1294
1295
if (rinfo -> irq )
@@ -1372,9 +1373,15 @@ static int blkif_get_final_status(enum blk_req_status s1,
1372
1373
return BLKIF_RSP_OKAY ;
1373
1374
}
1374
1375
1375
- static bool blkif_completion (unsigned long * id ,
1376
- struct blkfront_ring_info * rinfo ,
1377
- struct blkif_response * bret )
1376
+ /*
1377
+ * Return values:
1378
+ * 1 response processed.
1379
+ * 0 missing further responses.
1380
+ * -1 error while processing.
1381
+ */
1382
+ static int blkif_completion (unsigned long * id ,
1383
+ struct blkfront_ring_info * rinfo ,
1384
+ struct blkif_response * bret )
1378
1385
{
1379
1386
int i = 0 ;
1380
1387
struct scatterlist * sg ;
@@ -1397,7 +1404,7 @@ static bool blkif_completion(unsigned long *id,
1397
1404
1398
1405
/* Wait the second response if not yet here. */
1399
1406
if (s2 -> status < REQ_DONE )
1400
- return false ;
1407
+ return 0 ;
1401
1408
1402
1409
bret -> status = blkif_get_final_status (s -> status ,
1403
1410
s2 -> status );
@@ -1448,42 +1455,43 @@ static bool blkif_completion(unsigned long *id,
1448
1455
}
1449
1456
/* Add the persistent grant into the list of free grants */
1450
1457
for (i = 0 ; i < num_grant ; i ++ ) {
1451
- if (gnttab_query_foreign_access (s -> grants_used [i ]-> gref )) {
1458
+ if (! gnttab_try_end_foreign_access (s -> grants_used [i ]-> gref )) {
1452
1459
/*
1453
1460
* If the grant is still mapped by the backend (the
1454
1461
* backend has chosen to make this grant persistent)
1455
1462
* we add it at the head of the list, so it will be
1456
1463
* reused first.
1457
1464
*/
1458
- if (!info -> feature_persistent )
1459
- pr_alert_ratelimited ("backed has not unmapped grant: %u\n" ,
1460
- s -> grants_used [i ]-> gref );
1465
+ if (!info -> feature_persistent ) {
1466
+ pr_alert ("backed has not unmapped grant: %u\n" ,
1467
+ s -> grants_used [i ]-> gref );
1468
+ return -1 ;
1469
+ }
1461
1470
list_add (& s -> grants_used [i ]-> node , & rinfo -> grants );
1462
1471
rinfo -> persistent_gnts_c ++ ;
1463
1472
} else {
1464
1473
/*
1465
- * If the grant is not mapped by the backend we end the
1466
- * foreign access and add it to the tail of the list,
1467
- * so it will not be picked again unless we run out of
1468
- * persistent grants.
1474
+ * If the grant is not mapped by the backend we add it
1475
+ * to the tail of the list, so it will not be picked
1476
+ * again unless we run out of persistent grants.
1469
1477
*/
1470
- gnttab_end_foreign_access (s -> grants_used [i ]-> gref , 0 , 0UL );
1471
1478
s -> grants_used [i ]-> gref = GRANT_INVALID_REF ;
1472
1479
list_add_tail (& s -> grants_used [i ]-> node , & rinfo -> grants );
1473
1480
}
1474
1481
}
1475
1482
if (s -> req .operation == BLKIF_OP_INDIRECT ) {
1476
1483
for (i = 0 ; i < INDIRECT_GREFS (num_grant ); i ++ ) {
1477
- if (gnttab_query_foreign_access (s -> indirect_grants [i ]-> gref )) {
1478
- if (!info -> feature_persistent )
1479
- pr_alert_ratelimited ("backed has not unmapped grant: %u\n" ,
1480
- s -> indirect_grants [i ]-> gref );
1484
+ if (!gnttab_try_end_foreign_access (s -> indirect_grants [i ]-> gref )) {
1485
+ if (!info -> feature_persistent ) {
1486
+ pr_alert ("backed has not unmapped grant: %u\n" ,
1487
+ s -> indirect_grants [i ]-> gref );
1488
+ return -1 ;
1489
+ }
1481
1490
list_add (& s -> indirect_grants [i ]-> node , & rinfo -> grants );
1482
1491
rinfo -> persistent_gnts_c ++ ;
1483
1492
} else {
1484
1493
struct page * indirect_page ;
1485
1494
1486
- gnttab_end_foreign_access (s -> indirect_grants [i ]-> gref , 0 , 0UL );
1487
1495
/*
1488
1496
* Add the used indirect page back to the list of
1489
1497
* available pages for indirect grefs.
@@ -1498,7 +1506,7 @@ static bool blkif_completion(unsigned long *id,
1498
1506
}
1499
1507
}
1500
1508
1501
- return true ;
1509
+ return 1 ;
1502
1510
}
1503
1511
1504
1512
static irqreturn_t blkif_interrupt (int irq , void * dev_id )
@@ -1564,12 +1572,17 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
1564
1572
}
1565
1573
1566
1574
if (bret .operation != BLKIF_OP_DISCARD ) {
1575
+ int ret ;
1576
+
1567
1577
/*
1568
1578
* We may need to wait for an extra response if the
1569
1579
* I/O request is split in 2
1570
1580
*/
1571
- if (!blkif_completion (& id , rinfo , & bret ))
1581
+ ret = blkif_completion (& id , rinfo , & bret );
1582
+ if (!ret )
1572
1583
continue ;
1584
+ if (unlikely (ret < 0 ))
1585
+ goto err ;
1573
1586
}
1574
1587
1575
1588
if (add_id_to_freelist (rinfo , id )) {
@@ -1676,8 +1689,7 @@ static int setup_blkring(struct xenbus_device *dev,
1676
1689
for (i = 0 ; i < info -> nr_ring_pages ; i ++ )
1677
1690
rinfo -> ring_ref [i ] = GRANT_INVALID_REF ;
1678
1691
1679
- sring = (struct blkif_sring * )__get_free_pages (GFP_NOIO | __GFP_HIGH ,
1680
- get_order (ring_size ));
1692
+ sring = alloc_pages_exact (ring_size , GFP_NOIO );
1681
1693
if (!sring ) {
1682
1694
xenbus_dev_fatal (dev , - ENOMEM , "allocating shared ring" );
1683
1695
return - ENOMEM ;
@@ -1687,7 +1699,7 @@ static int setup_blkring(struct xenbus_device *dev,
1687
1699
1688
1700
err = xenbus_grant_ring (dev , rinfo -> ring .sring , info -> nr_ring_pages , gref );
1689
1701
if (err < 0 ) {
1690
- free_pages (( unsigned long ) sring , get_order ( ring_size ) );
1702
+ free_pages_exact ( sring , ring_size );
1691
1703
rinfo -> ring .sring = NULL ;
1692
1704
goto fail ;
1693
1705
}
@@ -2532,11 +2544,10 @@ static void purge_persistent_grants(struct blkfront_info *info)
2532
2544
list_for_each_entry_safe (gnt_list_entry , tmp , & rinfo -> grants ,
2533
2545
node ) {
2534
2546
if (gnt_list_entry -> gref == GRANT_INVALID_REF ||
2535
- gnttab_query_foreign_access (gnt_list_entry -> gref ))
2547
+ ! gnttab_try_end_foreign_access (gnt_list_entry -> gref ))
2536
2548
continue ;
2537
2549
2538
2550
list_del (& gnt_list_entry -> node );
2539
- gnttab_end_foreign_access (gnt_list_entry -> gref , 0 , 0UL );
2540
2551
rinfo -> persistent_gnts_c -- ;
2541
2552
gnt_list_entry -> gref = GRANT_INVALID_REF ;
2542
2553
list_add_tail (& gnt_list_entry -> node , & rinfo -> grants );
0 commit comments