All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/1] xen/blkfront: always allocate grants first from per-queue persistent grants
@ 2017-06-28 12:57 Dongli Zhang
  2017-06-28 15:34 ` Roger Pau Monné
  2017-06-28 15:34 ` Roger Pau Monné
  0 siblings, 2 replies; 6+ messages in thread
From: Dongli Zhang @ 2017-06-28 12:57 UTC (permalink / raw)
  To: xen-devel, linux-kernel; +Cc: konrad.wilk, roger.pau, boris.ostrovsky, jgross

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.

Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>

---
Changed since v1:
  * use "max_grefs - rinfo->persistent_gnts_c" as callback argument

---
 drivers/block/xen-blkfront.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 3945963..4544a1c 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -713,6 +713,7 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
 	 * existing persistent grants, or if we have to get new grants,
 	 * as there are not sufficiently many free.
 	 */
+	bool new_persistent_gnts = false;
 	struct scatterlist *sg;
 	int num_sg, max_grefs, num_grant;
 
@@ -724,19 +725,21 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
 		 */
 		max_grefs += INDIRECT_GREFS(max_grefs);
 
-	/*
-	 * We have to reserve 'max_grefs' grants because persistent
-	 * grants are shared by all rings.
-	 */
-	if (max_grefs > 0)
-		if (gnttab_alloc_grant_references(max_grefs, &setup.gref_head) < 0) {
+	/* Check if we have enough persistent grants to allocate a requests */
+	if (rinfo->persistent_gnts_c < max_grefs) {
+		new_persistent_gnts = true;
+
+		if (gnttab_alloc_grant_references(
+		    max_grefs - rinfo->persistent_gnts_c,
+		    &setup.gref_head) < 0) {
 			gnttab_request_free_callback(
 				&rinfo->callback,
 				blkif_restart_queue_callback,
 				rinfo,
-				max_grefs);
+				max_grefs - rinfo->persistent_gnts_c);
 			return 1;
 		}
+	}
 
 	/* Fill out a communications ring structure. */
 	id = blkif_ring_get_request(rinfo, req, &ring_req);
@@ -837,7 +840,7 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
 	if (unlikely(require_extra_req))
 		rinfo->shadow[extra_id].req = *extra_ring_req;
 
-	if (max_grefs > 0)
+	if (new_persistent_gnts)
 		gnttab_free_grant_references(setup.gref_head);
 
 	return 0;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/1] xen/blkfront: always allocate grants first from per-queue persistent grants
  2017-06-28 12:57 [PATCH v2 1/1] xen/blkfront: always allocate grants first from per-queue persistent grants Dongli Zhang
  2017-06-28 15:34 ` Roger Pau Monné
@ 2017-06-28 15:34 ` Roger Pau Monné
  2017-07-19  7:49   ` Dongli Zhang
  2017-07-19  7:49   ` Dongli Zhang
  1 sibling, 2 replies; 6+ messages in thread
From: Roger Pau Monné @ 2017-06-28 15:34 UTC (permalink / raw)
  To: Dongli Zhang
  Cc: xen-devel, linux-kernel, konrad.wilk, boris.ostrovsky, jgross

On Wed, Jun 28, 2017 at 08:57:28PM +0800, Dongli Zhang wrote:
> 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.
> 
> Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>

Acked-by: Roger Pau Monné <roger.pau@citrix.com>

Thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/1] xen/blkfront: always allocate grants first from per-queue persistent grants
  2017-06-28 12:57 [PATCH v2 1/1] xen/blkfront: always allocate grants first from per-queue persistent grants Dongli Zhang
@ 2017-06-28 15:34 ` Roger Pau Monné
  2017-06-28 15:34 ` Roger Pau Monné
  1 sibling, 0 replies; 6+ messages in thread
From: Roger Pau Monné @ 2017-06-28 15:34 UTC (permalink / raw)
  To: Dongli Zhang; +Cc: jgross, xen-devel, boris.ostrovsky, linux-kernel

On Wed, Jun 28, 2017 at 08:57:28PM +0800, Dongli Zhang wrote:
> 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.
> 
> Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>

Acked-by: Roger Pau Monné <roger.pau@citrix.com>

Thanks.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/1] xen/blkfront: always allocate grants first from per-queue persistent grants
  2017-06-28 15:34 ` Roger Pau Monné
  2017-07-19  7:49   ` Dongli Zhang
@ 2017-07-19  7:49   ` Dongli Zhang
  1 sibling, 0 replies; 6+ messages in thread
From: Dongli Zhang @ 2017-07-19  7:49 UTC (permalink / raw)
  To: Roger Pau Monné, konrad.wilk
  Cc: xen-devel, linux-kernel, boris.ostrovsky, jgross

Hi Konrad,

In addition to Junxiao's patch on xen-blkfront, would you please help merge this
to mainline as well?

Thank you very much!

Dongli Zhang

On 06/28/2017 11:34 PM, Roger Pau Monné wrote:
> On Wed, Jun 28, 2017 at 08:57:28PM +0800, Dongli Zhang wrote:
>> 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.
>>
>> Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
> 
> Acked-by: Roger Pau Monné <roger.pau@citrix.com>
> 
> Thanks.
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/1] xen/blkfront: always allocate grants first from per-queue persistent grants
  2017-06-28 15:34 ` Roger Pau Monné
@ 2017-07-19  7:49   ` Dongli Zhang
  2017-07-19  7:49   ` Dongli Zhang
  1 sibling, 0 replies; 6+ messages in thread
From: Dongli Zhang @ 2017-07-19  7:49 UTC (permalink / raw)
  To: Roger Pau Monné, konrad.wilk
  Cc: jgross, xen-devel, boris.ostrovsky, linux-kernel

Hi Konrad,

In addition to Junxiao's patch on xen-blkfront, would you please help merge this
to mainline as well?

Thank you very much!

Dongli Zhang

On 06/28/2017 11:34 PM, Roger Pau Monné wrote:
> On Wed, Jun 28, 2017 at 08:57:28PM +0800, Dongli Zhang wrote:
>> 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.
>>
>> Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
> 
> Acked-by: Roger Pau Monné <roger.pau@citrix.com>
> 
> Thanks.
> 

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/1] xen/blkfront: always allocate grants first from per-queue persistent grants
@ 2017-06-28 12:57 Dongli Zhang
  0 siblings, 0 replies; 6+ messages in thread
From: Dongli Zhang @ 2017-06-28 12:57 UTC (permalink / raw)
  To: xen-devel, linux-kernel; +Cc: jgross, boris.ostrovsky, roger.pau

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.

Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>

---
Changed since v1:
  * use "max_grefs - rinfo->persistent_gnts_c" as callback argument

---
 drivers/block/xen-blkfront.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 3945963..4544a1c 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -713,6 +713,7 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
 	 * existing persistent grants, or if we have to get new grants,
 	 * as there are not sufficiently many free.
 	 */
+	bool new_persistent_gnts = false;
 	struct scatterlist *sg;
 	int num_sg, max_grefs, num_grant;
 
@@ -724,19 +725,21 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
 		 */
 		max_grefs += INDIRECT_GREFS(max_grefs);
 
-	/*
-	 * We have to reserve 'max_grefs' grants because persistent
-	 * grants are shared by all rings.
-	 */
-	if (max_grefs > 0)
-		if (gnttab_alloc_grant_references(max_grefs, &setup.gref_head) < 0) {
+	/* Check if we have enough persistent grants to allocate a requests */
+	if (rinfo->persistent_gnts_c < max_grefs) {
+		new_persistent_gnts = true;
+
+		if (gnttab_alloc_grant_references(
+		    max_grefs - rinfo->persistent_gnts_c,
+		    &setup.gref_head) < 0) {
 			gnttab_request_free_callback(
 				&rinfo->callback,
 				blkif_restart_queue_callback,
 				rinfo,
-				max_grefs);
+				max_grefs - rinfo->persistent_gnts_c);
 			return 1;
 		}
+	}
 
 	/* Fill out a communications ring structure. */
 	id = blkif_ring_get_request(rinfo, req, &ring_req);
@@ -837,7 +840,7 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
 	if (unlikely(require_extra_req))
 		rinfo->shadow[extra_id].req = *extra_ring_req;
 
-	if (max_grefs > 0)
+	if (new_persistent_gnts)
 		gnttab_free_grant_references(setup.gref_head);
 
 	return 0;
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-07-19  7:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-28 12:57 [PATCH v2 1/1] xen/blkfront: always allocate grants first from per-queue persistent grants Dongli Zhang
2017-06-28 15:34 ` Roger Pau Monné
2017-06-28 15:34 ` Roger Pau Monné
2017-07-19  7:49   ` Dongli Zhang
2017-07-19  7:49   ` Dongli Zhang
  -- strict thread matches above, loose matches on Subject: below --
2017-06-28 12:57 Dongli Zhang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.