Skip to content

Commit bd912ef

Browse files
Dongli Zhangkonradwilk
authored andcommitted
xen/blkfront: always allocate grants first from per-queue persistent grants
This patch partially reverts 3df0e50 ("xen/blkfront: pseudo support for multi hardware queues/rings"). The xen-blkfront queue/ring might hang due to grants allocation failure in the situation when gnttab_free_head is almost empty while many persistent grants are reserved for this queue/ring. As persistent grants management was per-queue since 73716df ("xen/blkfront: make persistent grants pool per-queue"), we should always allocate from persistent grants first. Acked-by: Roger Pau Monné <[email protected]> Signed-off-by: Dongli Zhang <[email protected]> Signed-off-by: Konrad Rzeszutek Wilk <[email protected]>
1 parent 4b422cb commit bd912ef

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

drivers/block/xen-blkfront.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
708708
* existing persistent grants, or if we have to get new grants,
709709
* as there are not sufficiently many free.
710710
*/
711+
bool new_persistent_gnts = false;
711712
struct scatterlist *sg;
712713
int num_sg, max_grefs, num_grant;
713714

@@ -719,19 +720,21 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
719720
*/
720721
max_grefs += INDIRECT_GREFS(max_grefs);
721722

722-
/*
723-
* We have to reserve 'max_grefs' grants because persistent
724-
* grants are shared by all rings.
725-
*/
726-
if (max_grefs > 0)
727-
if (gnttab_alloc_grant_references(max_grefs, &setup.gref_head) < 0) {
723+
/* Check if we have enough persistent grants to allocate a requests */
724+
if (rinfo->persistent_gnts_c < max_grefs) {
725+
new_persistent_gnts = true;
726+
727+
if (gnttab_alloc_grant_references(
728+
max_grefs - rinfo->persistent_gnts_c,
729+
&setup.gref_head) < 0) {
728730
gnttab_request_free_callback(
729731
&rinfo->callback,
730732
blkif_restart_queue_callback,
731733
rinfo,
732-
max_grefs);
734+
max_grefs - rinfo->persistent_gnts_c);
733735
return 1;
734736
}
737+
}
735738

736739
/* Fill out a communications ring structure. */
737740
id = blkif_ring_get_request(rinfo, req, &ring_req);
@@ -832,7 +835,7 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
832835
if (unlikely(require_extra_req))
833836
rinfo->shadow[extra_id].req = *extra_ring_req;
834837

835-
if (max_grefs > 0)
838+
if (new_persistent_gnts)
836839
gnttab_free_grant_references(setup.gref_head);
837840

838841
return 0;

0 commit comments

Comments
 (0)