From nobody Fri May 3 18:54:39 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1583402704; cv=none; d=zohomail.com; s=zohoarc; b=Y/C7QGDIN1DfeeLSX641GFCiDEgqvTy4uXKtOc96hxq5JgOjLGVTIO7lDir7j/Ece0wkaJz3gzm5ccQm0AJYfTWQ2MuC3CjsUUEpvtzGCFI6M3yjK16X6T7vBbF+aKVHwF9eaMkjFbtseYrPoqmQVK16DvvqDe34p6G3uJ00Rqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583402704; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=o4DD3mjagnAwE2tFxXznfsXL4HK+tK0Q8ImPCeWVT6U=; b=JAt126iE5h4y1B1pe8H0w3t/3bGon6jneT4Xo+wGkPFa22/vOUUsrBnQqPXuXRlevQ68W8sABxY4gd/3FGj7lXku7WECSjLyEfvVifE+mNRYbHzSOizylFLLyjM0irD/B9NLl2ElioVJhd6pWljMj5M9nLOk8KmwzRiSr3mvcrw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1583402704671393.6221644681284; Thu, 5 Mar 2020 02:05:04 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j9nLs-000110-ST; Thu, 05 Mar 2020 10:03:36 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j9nLr-00010p-Dk for xen-devel@lists.xenproject.org; Thu, 05 Mar 2020 10:03:35 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 92c94dca-5ec8-11ea-90c4-bc764e2007e4; Thu, 05 Mar 2020 10:03:34 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1FA98B2DE; Thu, 5 Mar 2020 10:03:33 +0000 (UTC) X-Inumbo-ID: 92c94dca-5ec8-11ea-90c4-bc764e2007e4 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 5 Mar 2020 11:03:31 +0100 Message-Id: <20200305100331.16790-1-jgross@suse.com> X-Mailer: git-send-email 2.16.4 Subject: [Xen-devel] [PATCH] xen/blkfront: fix ring info addressing X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Jens Axboe , Stefano Stabellini , Konrad Rzeszutek Wilk , Boris Ostrovsky , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Commit 0265d6e8ddb890 ("xen/blkfront: limit allocated memory size to actual use case") made struct blkfront_ring_info size dynamic. This is fine when running with only one queue, but with multiple queues the addressing of the single queues has to be adapted as the structs are allocated in an array. Fixes: 0265d6e8ddb890 ("xen/blkfront: limit allocated memory size to actual= use case") Signed-off-by: Juergen Gross --- drivers/block/xen-blkfront.c | 82 ++++++++++++++++++++++++----------------= ---- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index e2ad6bba2281..a8d4a3838e5d 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -213,6 +213,7 @@ struct blkfront_info struct blk_mq_tag_set tag_set; struct blkfront_ring_info *rinfo; unsigned int nr_rings; + unsigned int rinfo_size; /* Save uncomplete reqs and bios for migration. */ struct list_head requests; struct bio_list bio_list; @@ -259,6 +260,21 @@ static int blkfront_setup_indirect(struct blkfront_rin= g_info *rinfo); static void blkfront_gather_backend_features(struct blkfront_info *info); static int negotiate_mq(struct blkfront_info *info); =20 +#define rinfo_ptr(rinfo, off) \ + (struct blkfront_ring_info *)((unsigned long)(rinfo) + (off)) + +#define for_each_rinfo(info, rinfo, idx) \ + for (rinfo =3D info->rinfo, idx =3D 0; \ + idx < info->nr_rings; \ + idx++, rinfo =3D rinfo_ptr(rinfo, info->rinfo_size)) + +static struct blkfront_ring_info *get_rinfo(struct blkfront_info *info, + unsigned int i) +{ + BUG_ON(i >=3D info->nr_rings); + return rinfo_ptr(info->rinfo, i * info->rinfo_size); +} + static int get_id_from_freelist(struct blkfront_ring_info *rinfo) { unsigned long free =3D rinfo->shadow_free; @@ -883,8 +899,7 @@ static blk_status_t blkif_queue_rq(struct blk_mq_hw_ctx= *hctx, struct blkfront_info *info =3D hctx->queue->queuedata; struct blkfront_ring_info *rinfo =3D NULL; =20 - BUG_ON(info->nr_rings <=3D qid); - rinfo =3D &info->rinfo[qid]; + rinfo =3D get_rinfo(info, qid); blk_mq_start_request(qd->rq); spin_lock_irqsave(&rinfo->ring_lock, flags); if (RING_FULL(&rinfo->ring)) @@ -1181,6 +1196,7 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacit= y, static void xlvbd_release_gendisk(struct blkfront_info *info) { unsigned int minor, nr_minors, i; + struct blkfront_ring_info *rinfo; =20 if (info->rq =3D=3D NULL) return; @@ -1188,8 +1204,7 @@ static void xlvbd_release_gendisk(struct blkfront_inf= o *info) /* No more blkif_request(). */ blk_mq_stop_hw_queues(info->rq); =20 - for (i =3D 0; i < info->nr_rings; i++) { - struct blkfront_ring_info *rinfo =3D &info->rinfo[i]; + for_each_rinfo(info, rinfo, i) { =20 /* No more gnttab callback work. */ gnttab_cancel_free_callback(&rinfo->callback); @@ -1339,6 +1354,7 @@ static void blkif_free_ring(struct blkfront_ring_info= *rinfo) static void blkif_free(struct blkfront_info *info, int suspend) { unsigned int i; + struct blkfront_ring_info *rinfo; =20 /* Prevent new requests being issued until we fix things up. */ info->connected =3D suspend ? @@ -1347,8 +1363,8 @@ static void blkif_free(struct blkfront_info *info, in= t suspend) if (info->rq) blk_mq_stop_hw_queues(info->rq); =20 - for (i =3D 0; i < info->nr_rings; i++) - blkif_free_ring(&info->rinfo[i]); + for_each_rinfo(info, rinfo, i) + blkif_free_ring(rinfo); =20 kvfree(info->rinfo); info->rinfo =3D NULL; @@ -1775,6 +1791,7 @@ static int talk_to_blkback(struct xenbus_device *dev, int err; unsigned int i, max_page_order; unsigned int ring_page_order; + struct blkfront_ring_info *rinfo; =20 if (!info) return -ENODEV; @@ -1788,9 +1805,7 @@ static int talk_to_blkback(struct xenbus_device *dev, if (err) goto destroy_blkring; =20 - for (i =3D 0; i < info->nr_rings; i++) { - struct blkfront_ring_info *rinfo =3D &info->rinfo[i]; - + for_each_rinfo(info, rinfo, i) { /* Create shared ring, alloc event channel. */ err =3D setup_blkring(dev, rinfo); if (err) @@ -1815,7 +1830,7 @@ static int talk_to_blkback(struct xenbus_device *dev, =20 /* We already got the number of queues/rings in _probe */ if (info->nr_rings =3D=3D 1) { - err =3D write_per_ring_nodes(xbt, &info->rinfo[0], dev->nodename); + err =3D write_per_ring_nodes(xbt, info->rinfo, dev->nodename); if (err) goto destroy_blkring; } else { @@ -1837,10 +1852,10 @@ static int talk_to_blkback(struct xenbus_device *de= v, goto abort_transaction; } =20 - for (i =3D 0; i < info->nr_rings; i++) { + for_each_rinfo(info, rinfo, i) { memset(path, 0, pathsize); snprintf(path, pathsize, "%s/queue-%u", dev->nodename, i); - err =3D write_per_ring_nodes(xbt, &info->rinfo[i], path); + err =3D write_per_ring_nodes(xbt, rinfo, path); if (err) { kfree(path); goto destroy_blkring; @@ -1868,9 +1883,8 @@ static int talk_to_blkback(struct xenbus_device *dev, goto destroy_blkring; } =20 - for (i =3D 0; i < info->nr_rings; i++) { + for_each_rinfo(info, rinfo, i) { unsigned int j; - struct blkfront_ring_info *rinfo =3D &info->rinfo[i]; =20 for (j =3D 0; j < BLK_RING_SIZE(info); j++) rinfo->shadow[j].req.u.rw.id =3D j + 1; @@ -1900,6 +1914,7 @@ static int negotiate_mq(struct blkfront_info *info) { unsigned int backend_max_queues; unsigned int i; + struct blkfront_ring_info *rinfo; =20 BUG_ON(info->nr_rings); =20 @@ -1911,20 +1926,16 @@ static int negotiate_mq(struct blkfront_info *info) if (!info->nr_rings) info->nr_rings =3D 1; =20 - info->rinfo =3D kvcalloc(info->nr_rings, - struct_size(info->rinfo, shadow, - BLK_RING_SIZE(info)), - GFP_KERNEL); + info->rinfo_size =3D struct_size(info->rinfo, shadow, + BLK_RING_SIZE(info)); + info->rinfo =3D kvcalloc(info->nr_rings, info->rinfo_size, GFP_KERNEL); if (!info->rinfo) { xenbus_dev_fatal(info->xbdev, -ENOMEM, "allocating ring_info structure"); info->nr_rings =3D 0; return -ENOMEM; } =20 - for (i =3D 0; i < info->nr_rings; i++) { - struct blkfront_ring_info *rinfo; - - rinfo =3D &info->rinfo[i]; + for_each_rinfo(info, rinfo, i) { INIT_LIST_HEAD(&rinfo->indirect_pages); INIT_LIST_HEAD(&rinfo->grants); rinfo->dev_info =3D info; @@ -2017,6 +2028,7 @@ static int blkif_recover(struct blkfront_info *info) int rc; struct bio *bio; unsigned int segs; + struct blkfront_ring_info *rinfo; =20 blkfront_gather_backend_features(info); /* Reset limits changed by blk_mq_update_nr_hw_queues(). */ @@ -2024,9 +2036,7 @@ static int blkif_recover(struct blkfront_info *info) segs =3D info->max_indirect_segments ? : BLKIF_MAX_SEGMENTS_PER_REQUEST; blk_queue_max_segments(info->rq, segs / GRANTS_PER_PSEG); =20 - for (r_index =3D 0; r_index < info->nr_rings; r_index++) { - struct blkfront_ring_info *rinfo =3D &info->rinfo[r_index]; - + for_each_rinfo(info, rinfo, r_index) { rc =3D blkfront_setup_indirect(rinfo); if (rc) return rc; @@ -2036,10 +2046,7 @@ static int blkif_recover(struct blkfront_info *info) /* Now safe for us to use the shared ring */ info->connected =3D BLKIF_STATE_CONNECTED; =20 - for (r_index =3D 0; r_index < info->nr_rings; r_index++) { - struct blkfront_ring_info *rinfo; - - rinfo =3D &info->rinfo[r_index]; + for_each_rinfo(info, rinfo, r_index) { /* Kick any other new requests queued since we resumed */ kick_pending_request_queues(rinfo); } @@ -2072,13 +2079,13 @@ static int blkfront_resume(struct xenbus_device *de= v) struct blkfront_info *info =3D dev_get_drvdata(&dev->dev); int err =3D 0; unsigned int i, j; + struct blkfront_ring_info *rinfo; =20 dev_dbg(&dev->dev, "blkfront_resume: %s\n", dev->nodename); =20 bio_list_init(&info->bio_list); INIT_LIST_HEAD(&info->requests); - for (i =3D 0; i < info->nr_rings; i++) { - struct blkfront_ring_info *rinfo =3D &info->rinfo[i]; + for_each_rinfo(info, rinfo, i) { struct bio_list merge_bio; struct blk_shadow *shadow =3D rinfo->shadow; =20 @@ -2337,6 +2344,7 @@ static void blkfront_connect(struct blkfront_info *in= fo) unsigned int binfo; char *envp[] =3D { "RESIZE=3D1", NULL }; int err, i; + struct blkfront_ring_info *rinfo; =20 switch (info->connected) { case BLKIF_STATE_CONNECTED: @@ -2394,8 +2402,8 @@ static void blkfront_connect(struct blkfront_info *in= fo) "physical-sector-size", sector_size); blkfront_gather_backend_features(info); - for (i =3D 0; i < info->nr_rings; i++) { - err =3D blkfront_setup_indirect(&info->rinfo[i]); + for_each_rinfo(info, rinfo, i) { + err =3D blkfront_setup_indirect(rinfo); if (err) { xenbus_dev_fatal(info->xbdev, err, "setup_indirect at %s", info->xbdev->otherend); @@ -2416,8 +2424,8 @@ static void blkfront_connect(struct blkfront_info *in= fo) =20 /* Kick pending requests. */ info->connected =3D BLKIF_STATE_CONNECTED; - for (i =3D 0; i < info->nr_rings; i++) - kick_pending_request_queues(&info->rinfo[i]); + for_each_rinfo(info, rinfo, i) + kick_pending_request_queues(rinfo); =20 device_add_disk(&info->xbdev->dev, info->gd, NULL); =20 @@ -2652,9 +2660,9 @@ static void purge_persistent_grants(struct blkfront_i= nfo *info) { unsigned int i; unsigned long flags; + struct blkfront_ring_info *rinfo; =20 - for (i =3D 0; i < info->nr_rings; i++) { - struct blkfront_ring_info *rinfo =3D &info->rinfo[i]; + for_each_rinfo(info, rinfo, i) { struct grant *gnt_list_entry, *tmp; =20 spin_lock_irqsave(&rinfo->ring_lock, flags); --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel