From patchwork Wed Sep 22 16:00:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 12511135 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8CCCC433F5 for ; Wed, 22 Sep 2021 17:30:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9A0E661131 for ; Wed, 22 Sep 2021 17:30:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236891AbhIVRcL (ORCPT ); Wed, 22 Sep 2021 13:32:11 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:46565 "EHLO lizzy.crudebyte.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236837AbhIVRcK (ORCPT ); Wed, 22 Sep 2021 13:32:10 -0400 X-Greylist: delayed 2685 seconds by postgrey-1.27 at vger.kernel.org; Wed, 22 Sep 2021 13:32:09 EDT DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=Cqx/q/n6hrY5Ps1ipX2QJFZ34qH2P2+3lxddoYfsBeQ=; b=mS6zR z5uI18mxP9aneaQmW2ScNP5w9aJrE0brLyb0fF88Ano26r4RFmTqHe+OVNDntbY37Dxf3WGyIrfOj jCFfvJn117/nbx41ncBrYYL6ASfnQ7LRRVHcz0dJd5DFjDJieB8AfyT69VoZD8crr+pclNXNuLsok DV23p6ewKwIiw8oi0Xm8wUWP8IDJsxGNi+o6Mq+WVGcoiMNYPz2lo6GzA9C+b5bKKooDG8BxdZfcM UwkMk9dKbIq2iqBuyHBfC8YG5gWl2ySeDOuzpW9X42EPz1n52xyk7q724xhzbysqOvQM76m3rG0+Z eiIuC6INFp8Vkpnpz8N9bdqw9XJ1g==; Message-Id: <925da76c58d67372307e5f516989600c96831c3a.1632327421.git.linux_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Wed, 22 Sep 2021 18:00:21 +0200 Subject: [PATCH v3 1/7] net/9p: show error message if user 'msize' cannot be satisfied To: v9fs-developer@lists.sourceforge.net Cc: netdev@vger.kernel.org, Dominique Martinet , Eric Van Hensbergen , Latchesar Ionkov , Greg Kurz , Vivek Goyal Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org If user supplied a large value with the 'msize' option, then client would silently limit that 'msize' value to the maximum value supported by transport. That's a bit confusing for users of not having any indication why the preferred 'msize' value could not be satisfied. Reported-by: Vivek Goyal Signed-off-by: Christian Schoenebeck --- net/9p/client.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/9p/client.c b/net/9p/client.c index 213f12ed76cd..4f4fd2098a30 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -1044,8 +1044,13 @@ struct p9_client *p9_client_create(const char *dev_name, char *options) if (err) goto put_trans; - if (clnt->msize > clnt->trans_mod->maxsize) + if (clnt->msize > clnt->trans_mod->maxsize) { clnt->msize = clnt->trans_mod->maxsize; + pr_info("Limiting 'msize' to %d as this is the maximum " + "supported by transport %s\n", + clnt->msize, clnt->trans_mod->name + ); + } if (clnt->msize < 4096) { p9_debug(P9_DEBUG_ERROR, From patchwork Wed Sep 22 16:00:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 12511137 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7184CC433EF for ; Wed, 22 Sep 2021 17:30:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 595F060F6E for ; Wed, 22 Sep 2021 17:30:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236895AbhIVRcY (ORCPT ); Wed, 22 Sep 2021 13:32:24 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:33551 "EHLO lizzy.crudebyte.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236851AbhIVRcW (ORCPT ); Wed, 22 Sep 2021 13:32:22 -0400 X-Greylist: delayed 2687 seconds by postgrey-1.27 at vger.kernel.org; Wed, 22 Sep 2021 13:32:21 EDT DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=Dg1gjIRekS8zgEvTByPnswl6ttfsf5eNF+Ja+K6B/K4=; b=B70xc uz9FsxzNWTVlK0LqahSpPkrSpaIVnDtzCLAqdxK11Yay5C42weL1/WPTVnEeseH45GHOpjBPm5XUm UHLlX2GoMGIbSTchqd++dnpyaFByccQt8bYIs+tmqFWKPfIh0zeJoLSM9GZAR2YoP/Xf2tHOATPK+ znZwDGcgwBo4BWxyCwEyrZUXdfJ3LRfCAt2ICWDIigoNtb+UyRLVKzDpcTEHnDP+kgDM8I9jezhxq Gx4JzCxMR2rgWMXkBqTGOsYE/65RIsjSCUWVqMnfF4e8Z0a3RDH1dNAFZL5yOO5Y8sE9ih2IB8ofY s10h6YlbIn2z3P1QbOj/2CrNrhiAA==; Message-Id: <36abf4c1ed348b1ef8ed38655f875942e0103d7f.1632327421.git.linux_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Wed, 22 Sep 2021 18:00:24 +0200 Subject: [PATCH v3 2/7] 9p/trans_virtio: separate allocation of scatter gather list To: v9fs-developer@lists.sourceforge.net Cc: netdev@vger.kernel.org, Dominique Martinet , Eric Van Hensbergen , Latchesar Ionkov , Greg Kurz , Vivek Goyal Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The scatter gather list in struct virtio_chan currently resides as compile-time constant size array directly within the contiguous struct virtio_chan's memory space. Separate memory space and allocation of the scatter gather list from memory space and allocation of struct virtio_chan. Signed-off-by: Christian Schoenebeck --- net/9p/trans_virtio.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c index 490a4c900339..1dbe2e921bb8 100644 --- a/net/9p/trans_virtio.c +++ b/net/9p/trans_virtio.c @@ -77,7 +77,7 @@ struct virtio_chan { */ unsigned long p9_max_pages; /* Scatterlist: can be too big for stack. */ - struct scatterlist sg[VIRTQUEUE_NUM]; + struct scatterlist *sg; /** * @tag: name to identify a mount null terminated */ @@ -574,6 +574,14 @@ static int p9_virtio_probe(struct virtio_device *vdev) goto fail; } + chan->sg = kmalloc_array(VIRTQUEUE_NUM, + sizeof(struct scatterlist), GFP_KERNEL); + if (!chan->sg) { + pr_err("Failed to allocate virtio 9P channel\n"); + err = -ENOMEM; + goto out_free_chan_shallow; + } + chan->vdev = vdev; /* We expect one virtqueue, for requests. */ @@ -635,6 +643,8 @@ static int p9_virtio_probe(struct virtio_device *vdev) out_free_vq: vdev->config->del_vqs(vdev); out_free_chan: + kfree(chan->sg); +out_free_chan_shallow: kfree(chan); fail: return err; @@ -728,6 +738,7 @@ static void p9_virtio_remove(struct virtio_device *vdev) kobject_uevent(&(vdev->dev.kobj), KOBJ_CHANGE); kfree(chan->tag); kfree(chan->vc_wq); + kfree(chan->sg); kfree(chan); } From patchwork Wed Sep 22 16:00:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 12511141 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60796C4332F for ; Wed, 22 Sep 2021 17:31:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B1F9611C9 for ; Wed, 22 Sep 2021 17:31:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236854AbhIVRc3 (ORCPT ); Wed, 22 Sep 2021 13:32:29 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:35917 "EHLO lizzy.crudebyte.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236904AbhIVRc1 (ORCPT ); Wed, 22 Sep 2021 13:32:27 -0400 X-Greylist: delayed 2688 seconds by postgrey-1.27 at vger.kernel.org; Wed, 22 Sep 2021 13:32:26 EDT DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=c43qkPKZ3owcWwHt3qMx8G3o1c4XciboiEemqoGFbCI=; b=AjxBR 7ffE8IiDCOe+kqeCNnk5ipXxz0AV5Z3vhf6McQquZPPh6WGSOheX434sCEng/3U2v/+PbpkCrshPp Nq/Zulm0XBWqWmJnSPdhnpdgHR86Ad01qFyxAZ3WWJuR3XVNtUelc0oTr12XM0OVFVpxshuRuK0OJ cm24hQDCf4X3MzU+w5a8BinPsMXmk3sN4IHzgetm8pmzB9dRod4SaCqZcC6GYveCXJyae/m8kt8hr NaPUu6GS3ancMGRTUquGh5az1UqroBiKoBOs8PnpKl+GcdryyIJec4seKyKyb+uD9JSF21QfarC7m BY07FPN91cAcG+BVRaZgRjD7tZDQg==; Message-Id: <61d32571f72d56de68c317c5be998c9e641c8acf.1632327421.git.linux_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Wed, 22 Sep 2021 18:00:26 +0200 Subject: [PATCH v3 3/7] 9p/trans_virtio: turn amount of sg lists into runtime info To: v9fs-developer@lists.sourceforge.net Cc: netdev@vger.kernel.org, Dominique Martinet , Eric Van Hensbergen , Latchesar Ionkov , Greg Kurz , Vivek Goyal Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The size of scatter/gather lists used by the virtio transport is currently hard coded. Refactor this to using a runtime variable. Signed-off-by: Christian Schoenebeck --- net/9p/trans_virtio.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c index 1dbe2e921bb8..3347d35a5e6e 100644 --- a/net/9p/trans_virtio.c +++ b/net/9p/trans_virtio.c @@ -36,7 +36,7 @@ #include #include "trans_common.h" -#define VIRTQUEUE_NUM 128 +#define VIRTQUEUE_DEFAULT_NUM 128 /* a single mutex to manage channel initialization and attachment */ static DEFINE_MUTEX(virtio_9p_lock); @@ -54,6 +54,7 @@ static atomic_t vp_pinned = ATOMIC_INIT(0); * @vc_wq: wait queue for waiting for thing to be added to ring buf * @p9_max_pages: maximum number of pinned pages * @sg: scatter gather list which is used to pack a request (protected?) + * @sg_n: amount of elements in sg array * @chan_list: linked list of channels * * We keep all per-channel information in a structure. @@ -78,6 +79,7 @@ struct virtio_chan { unsigned long p9_max_pages; /* Scatterlist: can be too big for stack. */ struct scatterlist *sg; + size_t sg_n; /** * @tag: name to identify a mount null terminated */ @@ -270,12 +272,12 @@ p9_virtio_request(struct p9_client *client, struct p9_req_t *req) out_sgs = in_sgs = 0; /* Handle out VirtIO ring buffers */ out = pack_sg_list(chan->sg, 0, - VIRTQUEUE_NUM, req->tc.sdata, req->tc.size); + chan->sg_n, req->tc.sdata, req->tc.size); if (out) sgs[out_sgs++] = chan->sg; in = pack_sg_list(chan->sg, out, - VIRTQUEUE_NUM, req->rc.sdata, req->rc.capacity); + chan->sg_n, req->rc.sdata, req->rc.capacity); if (in) sgs[out_sgs + in_sgs++] = chan->sg + out; @@ -447,14 +449,14 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req, /* out data */ out = pack_sg_list(chan->sg, 0, - VIRTQUEUE_NUM, req->tc.sdata, req->tc.size); + chan->sg_n, req->tc.sdata, req->tc.size); if (out) sgs[out_sgs++] = chan->sg; if (out_pages) { sgs[out_sgs++] = chan->sg + out; - out += pack_sg_list_p(chan->sg, out, VIRTQUEUE_NUM, + out += pack_sg_list_p(chan->sg, out, chan->sg_n, out_pages, out_nr_pages, offs, outlen); } @@ -466,13 +468,13 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req, * allocated memory and payload onto the user buffer. */ in = pack_sg_list(chan->sg, out, - VIRTQUEUE_NUM, req->rc.sdata, in_hdr_len); + chan->sg_n, req->rc.sdata, in_hdr_len); if (in) sgs[out_sgs + in_sgs++] = chan->sg + out; if (in_pages) { sgs[out_sgs + in_sgs++] = chan->sg + out + in; - in += pack_sg_list_p(chan->sg, out + in, VIRTQUEUE_NUM, + in += pack_sg_list_p(chan->sg, out + in, chan->sg_n, in_pages, in_nr_pages, offs, inlen); } @@ -574,13 +576,14 @@ static int p9_virtio_probe(struct virtio_device *vdev) goto fail; } - chan->sg = kmalloc_array(VIRTQUEUE_NUM, + chan->sg = kmalloc_array(VIRTQUEUE_DEFAULT_NUM, sizeof(struct scatterlist), GFP_KERNEL); if (!chan->sg) { pr_err("Failed to allocate virtio 9P channel\n"); err = -ENOMEM; goto out_free_chan_shallow; } + chan->sg_n = VIRTQUEUE_DEFAULT_NUM; chan->vdev = vdev; @@ -593,7 +596,7 @@ static int p9_virtio_probe(struct virtio_device *vdev) chan->vq->vdev->priv = chan; spin_lock_init(&chan->lock); - sg_init_table(chan->sg, VIRTQUEUE_NUM); + sg_init_table(chan->sg, chan->sg_n); chan->inuse = false; if (virtio_has_feature(vdev, VIRTIO_9P_MOUNT_TAG)) { @@ -777,7 +780,7 @@ static struct p9_trans_module p9_virtio_trans = { * that are not at page boundary, that can result in an extra * page in zero copy. */ - .maxsize = PAGE_SIZE * (VIRTQUEUE_NUM - 3), + .maxsize = PAGE_SIZE * (VIRTQUEUE_DEFAULT_NUM - 3), .def = 1, .owner = THIS_MODULE, }; From patchwork Wed Sep 22 16:00:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 12511139 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED868C433F5 for ; Wed, 22 Sep 2021 17:30:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D6CF0611C9 for ; Wed, 22 Sep 2021 17:30:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236858AbhIVRc0 (ORCPT ); Wed, 22 Sep 2021 13:32:26 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:55901 "EHLO lizzy.crudebyte.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236905AbhIVRcY (ORCPT ); Wed, 22 Sep 2021 13:32:24 -0400 X-Greylist: delayed 2678 seconds by postgrey-1.27 at vger.kernel.org; Wed, 22 Sep 2021 13:32:24 EDT DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=4QmQTn9LRMDnOoJpjNkEpQtqrqBlcOOjz4bgQbwvBSY=; b=SInZL Vf//qLeLTlBCTOCeOl9s7cQt949xbe0+HHxqLl/JWojqmYh4qonI3CvIJVSWnH8nMNAP8dppNqeHV y4oJkEziCPuyS5LUBQ3XfkWzNPbx4ijI2HBNbsuco6vSQSMK68kPlHfh2tBYmYKx2sQlHnP0Vbhjl TL6viYy7NOnIjDYmV786hIvnp6BKTyhCsSdvZ+eBA7zw0w2lp+467b/t5l697eYeQNUwffjIvlu7i oa+QI04HHKt/09/Bf0kM9Z3LBIzP7v/3kwAAVNi1sPYihmWvfjaR2nDoPL3KGV0Jp4ge6cHVx1k9h yv0wJnLMjcwr6A03yaCp4azeHPk8g==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Wed, 22 Sep 2021 18:00:29 +0200 Subject: [PATCH v3 4/7] 9p/trans_virtio: introduce struct virtqueue_sg To: v9fs-developer@lists.sourceforge.net Cc: netdev@vger.kernel.org, Dominique Martinet , Eric Van Hensbergen , Latchesar Ionkov , Greg Kurz , Vivek Goyal Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The amount of elements in a scatter/gather list is limited to approximately 128 elements. To allow going beyond that limit with subsequent patches, pave the way by turning the one- dimensional sg list array into a two-dimensional array, i.e: sg[128] becomes sgl[nsgl][SG_MAX_SINGLE_ALLOC] As the value of 'nsgl' is exactly (still) 1 in this commit and the compile-time (compiler and architecture dependent) value of 'SG_MAX_SINGLE_ALLOC' equals approximately the previous hard coded 128 elements, this commit is therefore more of a preparatory refactoring then actual behaviour change. A custom struct virtqueue_sg is defined instead of using shared API struct sg_table, because the latter would not allow to resize the table after allocation. sg_append_table API OTOH would not fit either, because it requires a list of pages beforehand upon allocation. And both APIs only support all-or-nothing allocation. Signed-off-by: Christian Schoenebeck --- net/9p/trans_virtio.c | 193 ++++++++++++++++++++++++++++++++---------- 1 file changed, 147 insertions(+), 46 deletions(-) diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c index 3347d35a5e6e..e478a34326f1 100644 --- a/net/9p/trans_virtio.c +++ b/net/9p/trans_virtio.c @@ -36,7 +36,31 @@ #include #include "trans_common.h" -#define VIRTQUEUE_DEFAULT_NUM 128 +/** + * struct virtqueue_sg - (chained) scatter gather lists for virtqueue data + * transmission + * @nsgl: amount of elements (in first dimension) of array field @sgl + * @sgl: two-dimensional array, i.e. sgl[nsgl][SG_MAX_SINGLE_ALLOC] + */ +struct virtqueue_sg { + unsigned int nsgl; + struct scatterlist *sgl[]; +}; + +/* + * Default value for field nsgl in struct virtqueue_sg, which defines the + * initial virtio data transmission capacity when this virtio transport is + * probed. + */ +#define VIRTQUEUE_SG_NSGL_DEFAULT 1 + +/* maximum value for field nsgl in struct virtqueue_sg */ +#define VIRTQUEUE_SG_NSGL_MAX \ + ((PAGE_SIZE - sizeof(struct virtqueue_sg)) / \ + sizeof(struct scatterlist *)) \ + +/* last entry per sg list is used for chaining (pointer to next list) */ +#define SG_USER_PAGES_PER_LIST (SG_MAX_SINGLE_ALLOC - 1) /* a single mutex to manage channel initialization and attachment */ static DEFINE_MUTEX(virtio_9p_lock); @@ -53,8 +77,7 @@ static atomic_t vp_pinned = ATOMIC_INIT(0); * @ring_bufs_avail: flag to indicate there is some available in the ring buf * @vc_wq: wait queue for waiting for thing to be added to ring buf * @p9_max_pages: maximum number of pinned pages - * @sg: scatter gather list which is used to pack a request (protected?) - * @sg_n: amount of elements in sg array + * @vq_sg: table of scatter gather lists, which are used to pack a request * @chan_list: linked list of channels * * We keep all per-channel information in a structure. @@ -77,9 +100,7 @@ struct virtio_chan { * will be placing it in each channel. */ unsigned long p9_max_pages; - /* Scatterlist: can be too big for stack. */ - struct scatterlist *sg; - size_t sg_n; + struct virtqueue_sg *vq_sg; /** * @tag: name to identify a mount null terminated */ @@ -96,6 +117,92 @@ static unsigned int rest_of_page(void *data) return PAGE_SIZE - offset_in_page(data); } +/** + * vq_sg_page - returns user page for given page index + * @vq_sg: scatter gather lists used by this transport + * @page: user page index across all scatter gather lists + */ +static struct scatterlist *vq_sg_page(struct virtqueue_sg *vq_sg, size_t page) +{ + unsigned int node = page / SG_USER_PAGES_PER_LIST; + unsigned int leaf = page % SG_USER_PAGES_PER_LIST; + BUG_ON(node >= VIRTQUEUE_SG_NSGL_MAX); + return &vq_sg->sgl[node][leaf]; +} + +/** + * vq_sg_npages - returns total number of individual user pages in passed + * scatter gather lists + * @vq_sg: scatter gather lists to be counted + */ +static size_t vq_sg_npages(struct virtqueue_sg *vq_sg) +{ + return vq_sg->nsgl * SG_USER_PAGES_PER_LIST; +} + +/** + * vq_sg_free - free all memory previously allocated for @vq_sg + * @vq_sg: scatter gather lists to be freed + */ +static void vq_sg_free(struct virtqueue_sg *vq_sg) +{ + unsigned int i; + + if (!vq_sg) + return; + + for (i = 0; i < vq_sg->nsgl; ++i) { + kfree(vq_sg->sgl[i]); + } + kfree(vq_sg); +} + +/** + * vq_sg_alloc - allocates and returns @nsgl scatter gather lists + * @nsgl: amount of scatter gather lists to be allocated + * If @nsgl is larger than one then chained lists are used if supported by + * architecture. + */ +static struct virtqueue_sg *vq_sg_alloc(unsigned int nsgl) +{ + struct virtqueue_sg *vq_sg; + unsigned int i; + + BUG_ON(!nsgl || nsgl > VIRTQUEUE_SG_NSGL_MAX); +#ifdef CONFIG_ARCH_NO_SG_CHAIN + if (WARN_ON_ONCE(nsgl > 1)) + return NULL; +#endif + + vq_sg = kzalloc(sizeof(struct virtqueue_sg) + + nsgl * sizeof(struct scatterlist *), + GFP_KERNEL); + + if (!vq_sg) + return NULL; + + vq_sg->nsgl = nsgl; + + for (i = 0; i < nsgl; ++i) { + vq_sg->sgl[i] = kmalloc_array( + SG_MAX_SINGLE_ALLOC, sizeof(struct scatterlist), + GFP_KERNEL + ); + if (!vq_sg->sgl[i]) { + vq_sg_free(vq_sg); + return NULL; + } + sg_init_table(vq_sg->sgl[i], SG_MAX_SINGLE_ALLOC); + if (i) { + /* chain the lists */ + sg_chain(vq_sg->sgl[i - 1], SG_MAX_SINGLE_ALLOC, + vq_sg->sgl[i]); + } + } + sg_mark_end(&vq_sg->sgl[nsgl - 1][SG_MAX_SINGLE_ALLOC - 1]); + return vq_sg; +} + /** * p9_virtio_close - reclaim resources of a channel * @client: client instance @@ -158,9 +265,8 @@ static void req_done(struct virtqueue *vq) /** * pack_sg_list - pack a scatter gather list from a linear buffer - * @sg: scatter/gather list to pack into + * @vq_sg: scatter/gather lists to pack into * @start: which segment of the sg_list to start at - * @limit: maximum segment to pack data to * @data: data to pack into scatter/gather list * @count: amount of data to pack into the scatter/gather list * @@ -170,11 +276,12 @@ static void req_done(struct virtqueue *vq) * */ -static int pack_sg_list(struct scatterlist *sg, int start, - int limit, char *data, int count) +static int pack_sg_list(struct virtqueue_sg *vq_sg, int start, + char *data, int count) { int s; int index = start; + size_t limit = vq_sg_npages(vq_sg); while (count) { s = rest_of_page(data); @@ -182,13 +289,13 @@ static int pack_sg_list(struct scatterlist *sg, int start, s = count; BUG_ON(index >= limit); /* Make sure we don't terminate early. */ - sg_unmark_end(&sg[index]); - sg_set_buf(&sg[index++], data, s); + sg_unmark_end(vq_sg_page(vq_sg, index)); + sg_set_buf(vq_sg_page(vq_sg, index++), data, s); count -= s; data += s; } if (index-start) - sg_mark_end(&sg[index - 1]); + sg_mark_end(vq_sg_page(vq_sg, index - 1)); return index-start; } @@ -208,21 +315,21 @@ static int p9_virtio_cancelled(struct p9_client *client, struct p9_req_t *req) /** * pack_sg_list_p - Just like pack_sg_list. Instead of taking a buffer, * this takes a list of pages. - * @sg: scatter/gather list to pack into + * @vq_sg: scatter/gather lists to pack into * @start: which segment of the sg_list to start at - * @limit: maximum number of pages in sg list. * @pdata: a list of pages to add into sg. * @nr_pages: number of pages to pack into the scatter/gather list * @offs: amount of data in the beginning of first page _not_ to pack * @count: amount of data to pack into the scatter/gather list */ static int -pack_sg_list_p(struct scatterlist *sg, int start, int limit, +pack_sg_list_p(struct virtqueue_sg *vq_sg, int start, struct page **pdata, int nr_pages, size_t offs, int count) { int i = 0, s; int data_off = offs; int index = start; + size_t limit = vq_sg_npages(vq_sg); BUG_ON(nr_pages > (limit - start)); /* @@ -235,15 +342,16 @@ pack_sg_list_p(struct scatterlist *sg, int start, int limit, s = count; BUG_ON(index >= limit); /* Make sure we don't terminate early. */ - sg_unmark_end(&sg[index]); - sg_set_page(&sg[index++], pdata[i++], s, data_off); + sg_unmark_end(vq_sg_page(vq_sg, index)); + sg_set_page(vq_sg_page(vq_sg, index++), pdata[i++], s, + data_off); data_off = 0; count -= s; nr_pages--; } if (index-start) - sg_mark_end(&sg[index - 1]); + sg_mark_end(vq_sg_page(vq_sg, index - 1)); return index - start; } @@ -271,15 +379,13 @@ p9_virtio_request(struct p9_client *client, struct p9_req_t *req) out_sgs = in_sgs = 0; /* Handle out VirtIO ring buffers */ - out = pack_sg_list(chan->sg, 0, - chan->sg_n, req->tc.sdata, req->tc.size); + out = pack_sg_list(chan->vq_sg, 0, req->tc.sdata, req->tc.size); if (out) - sgs[out_sgs++] = chan->sg; + sgs[out_sgs++] = vq_sg_page(chan->vq_sg, 0); - in = pack_sg_list(chan->sg, out, - chan->sg_n, req->rc.sdata, req->rc.capacity); + in = pack_sg_list(chan->vq_sg, out, req->rc.sdata, req->rc.capacity); if (in) - sgs[out_sgs + in_sgs++] = chan->sg + out; + sgs[out_sgs + in_sgs++] = vq_sg_page(chan->vq_sg, out); err = virtqueue_add_sgs(chan->vq, sgs, out_sgs, in_sgs, req, GFP_ATOMIC); @@ -448,16 +554,15 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req, out_sgs = in_sgs = 0; /* out data */ - out = pack_sg_list(chan->sg, 0, - chan->sg_n, req->tc.sdata, req->tc.size); + out = pack_sg_list(chan->vq_sg, 0, req->tc.sdata, req->tc.size); if (out) - sgs[out_sgs++] = chan->sg; + sgs[out_sgs++] = vq_sg_page(chan->vq_sg, 0); if (out_pages) { - sgs[out_sgs++] = chan->sg + out; - out += pack_sg_list_p(chan->sg, out, chan->sg_n, - out_pages, out_nr_pages, offs, outlen); + sgs[out_sgs++] = vq_sg_page(chan->vq_sg, out); + out += pack_sg_list_p(chan->vq_sg, out, out_pages, + out_nr_pages, offs, outlen); } /* @@ -467,15 +572,14 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req, * Arrange in such a way that server places header in the * allocated memory and payload onto the user buffer. */ - in = pack_sg_list(chan->sg, out, - chan->sg_n, req->rc.sdata, in_hdr_len); + in = pack_sg_list(chan->vq_sg, out, req->rc.sdata, in_hdr_len); if (in) - sgs[out_sgs + in_sgs++] = chan->sg + out; + sgs[out_sgs + in_sgs++] = vq_sg_page(chan->vq_sg, out); if (in_pages) { - sgs[out_sgs + in_sgs++] = chan->sg + out + in; - in += pack_sg_list_p(chan->sg, out + in, chan->sg_n, - in_pages, in_nr_pages, offs, inlen); + sgs[out_sgs + in_sgs++] = vq_sg_page(chan->vq_sg, out + in); + in += pack_sg_list_p(chan->vq_sg, out + in, in_pages, + in_nr_pages, offs, inlen); } BUG_ON(out_sgs + in_sgs > ARRAY_SIZE(sgs)); @@ -576,14 +680,12 @@ static int p9_virtio_probe(struct virtio_device *vdev) goto fail; } - chan->sg = kmalloc_array(VIRTQUEUE_DEFAULT_NUM, - sizeof(struct scatterlist), GFP_KERNEL); - if (!chan->sg) { + chan->vq_sg = vq_sg_alloc(VIRTQUEUE_SG_NSGL_DEFAULT); + if (!chan->vq_sg) { pr_err("Failed to allocate virtio 9P channel\n"); err = -ENOMEM; goto out_free_chan_shallow; } - chan->sg_n = VIRTQUEUE_DEFAULT_NUM; chan->vdev = vdev; @@ -596,8 +698,6 @@ static int p9_virtio_probe(struct virtio_device *vdev) chan->vq->vdev->priv = chan; spin_lock_init(&chan->lock); - sg_init_table(chan->sg, chan->sg_n); - chan->inuse = false; if (virtio_has_feature(vdev, VIRTIO_9P_MOUNT_TAG)) { virtio_cread(vdev, struct virtio_9p_config, tag_len, &tag_len); @@ -646,7 +746,7 @@ static int p9_virtio_probe(struct virtio_device *vdev) out_free_vq: vdev->config->del_vqs(vdev); out_free_chan: - kfree(chan->sg); + vq_sg_free(chan->vq_sg); out_free_chan_shallow: kfree(chan); fail: @@ -741,7 +841,7 @@ static void p9_virtio_remove(struct virtio_device *vdev) kobject_uevent(&(vdev->dev.kobj), KOBJ_CHANGE); kfree(chan->tag); kfree(chan->vc_wq); - kfree(chan->sg); + vq_sg_free(chan->vq_sg); kfree(chan); } @@ -780,7 +880,8 @@ static struct p9_trans_module p9_virtio_trans = { * that are not at page boundary, that can result in an extra * page in zero copy. */ - .maxsize = PAGE_SIZE * (VIRTQUEUE_DEFAULT_NUM - 3), + .maxsize = PAGE_SIZE * + ((VIRTQUEUE_SG_NSGL_DEFAULT * SG_USER_PAGES_PER_LIST) - 3), .def = 1, .owner = THIS_MODULE, }; From patchwork Wed Sep 22 16:00:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 12511129 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D7A9C433EF for ; Wed, 22 Sep 2021 17:30:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C4C660F6E for ; Wed, 22 Sep 2021 17:30:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236824AbhIVRb4 (ORCPT ); Wed, 22 Sep 2021 13:31:56 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:47947 "EHLO lizzy.crudebyte.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236701AbhIVRbz (ORCPT ); Wed, 22 Sep 2021 13:31:55 -0400 X-Greylist: delayed 2644 seconds by postgrey-1.27 at vger.kernel.org; Wed, 22 Sep 2021 13:31:55 EDT DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=xGiunjavhziw/hR6JJjI0G+puRHTGyjYNaa0pMUw2PY=; b=jtdbs x7QQFGAdE0SADUlwm4us5be0+7CKPOGD7p0cAOwT3f7dL8uIGr5x1DEtZ9LL8SQY6yCt7DMSFtpZn 0V2AP2+y0vcmUbfT2R2Y8Q2GU8AsoOX3qshAxlH20GT9RxlHa4y8IIKFt7xIP5nYwrdS5tMKFXrwd Uw0mMylYlrCQrQ6YuZgMiS8KEkULleY18eyUhhj4/Z1fgIKcbLE/XeK6pqWbUSqil9EEhVcmojYXM reWc1r3aQ6eTbpmdL7dz8ylXW5nQ/MkA7nzceyC/ooiYvk+KfCXSquM2ntwmgwX0gWS0VVnyGqF1p MKCWa271n/9R/JgILA36FVmPbhpNw==; Message-Id: <39113683f53916d6c9e5b24ffbd9e28b38df3800.1632327421.git.linux_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Wed, 22 Sep 2021 18:00:31 +0200 Subject: [PATCH v3 5/7] net/9p: add trans_maxsize to struct p9_client To: v9fs-developer@lists.sourceforge.net Cc: netdev@vger.kernel.org, Dominique Martinet , Eric Van Hensbergen , Latchesar Ionkov , Greg Kurz , Vivek Goyal Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This new field 'trans_maxsize' optionally allows transport to update it to reflect the actual maximum msize supported by allocated transport channel. Signed-off-by: Christian Schoenebeck --- include/net/9p/client.h | 2 ++ net/9p/client.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/net/9p/client.h b/include/net/9p/client.h index e1c308d8d288..e48c4cdf9be0 100644 --- a/include/net/9p/client.h +++ b/include/net/9p/client.h @@ -89,6 +89,7 @@ struct p9_req_t { * struct p9_client - per client instance state * @lock: protect @fids and @reqs * @msize: maximum data size negotiated by protocol + * @trans_maxsize: actual maximum msize supported by transport channel * @proto_version: 9P protocol version to use * @trans_mod: module API instantiated with this client * @status: connection state @@ -103,6 +104,7 @@ struct p9_req_t { struct p9_client { spinlock_t lock; unsigned int msize; + unsigned int trans_maxsize; unsigned char proto_version; struct p9_trans_module *trans_mod; enum p9_trans_status status; diff --git a/net/9p/client.c b/net/9p/client.c index 4f4fd2098a30..a75034fa249b 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -1037,6 +1037,14 @@ struct p9_client *p9_client_create(const char *dev_name, char *options) goto free_client; } + /* + * transport will get a chance to increase trans_maxsize (if + * necessary) and it may update trans_maxsize in create() function + * below accordingly to reflect the actual maximum size supported by + * the allocated transport channel + */ + clnt->trans_maxsize = clnt->trans_mod->maxsize; + p9_debug(P9_DEBUG_MUX, "clnt %p trans %p msize %d protocol %d\n", clnt, clnt->trans_mod, clnt->msize, clnt->proto_version); @@ -1044,8 +1052,8 @@ struct p9_client *p9_client_create(const char *dev_name, char *options) if (err) goto put_trans; - if (clnt->msize > clnt->trans_mod->maxsize) { - clnt->msize = clnt->trans_mod->maxsize; + if (clnt->msize > clnt->trans_maxsize) { + clnt->msize = clnt->trans_maxsize; pr_info("Limiting 'msize' to %d as this is the maximum " "supported by transport %s\n", clnt->msize, clnt->trans_mod->name From patchwork Wed Sep 22 16:00:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 12511177 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82B8DC433F5 for ; Wed, 22 Sep 2021 18:00:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5572C6115A for ; Wed, 22 Sep 2021 18:00:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236991AbhIVSB5 (ORCPT ); Wed, 22 Sep 2021 14:01:57 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:60163 "EHLO lizzy.crudebyte.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236837AbhIVSBz (ORCPT ); Wed, 22 Sep 2021 14:01:55 -0400 X-Greylist: delayed 1797 seconds by postgrey-1.27 at vger.kernel.org; Wed, 22 Sep 2021 14:01:55 EDT DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=TjeszQPirpXnTpbD9rI0NjLFV5R8Nppc65UV5+bdDM0=; b=i7w6s K3v7ehw97Anw0r9TxKmh1cAxbqpqcKVEo9K7wsWWrdKlVN+iqq5AkXZWIJZamuPRyhxRjnSq0S2fd jiNABkt6+8m0umc+QgOq1sP331EfNDhYx3vO2cfR0Adn7auUpY0VWPm/u2T96KYYOI5EJdVDUzA+v zUcl0feOEb002tjNlCBO5xTCm54klpKMm7peehmTH17lrKtjm8AkU6+7z8RNojUliNzs+ttw+BEk/ t+lSb0KZrd0X4BMA0UUeNM2ylW8LuzHnYvBhJr83KZLQWyCLQq5ZSxBWEuStq4cwMRTbbTAhTl/B4 2PJH4yKHcLDwIZa+eZss/OF3x5dXA==; Message-Id: <8119d4d93a39758075bb83730dcb571f5d071af6.1632327421.git.linux_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Wed, 22 Sep 2021 18:00:33 +0200 Subject: [PATCH v3 6/7] 9p/trans_virtio: support larger msize values To: v9fs-developer@lists.sourceforge.net Cc: netdev@vger.kernel.org, Dominique Martinet , Eric Van Hensbergen , Latchesar Ionkov , Greg Kurz , Vivek Goyal Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The virtio transport supports by default a 9p 'msize' of up to approximately 500 kB. This patch adds support for larger 'msize' values by resizing the amount of scatter/gather lists if required. Signed-off-by: Christian Schoenebeck --- net/9p/trans_virtio.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c index e478a34326f1..147ebf647a95 100644 --- a/net/9p/trans_virtio.c +++ b/net/9p/trans_virtio.c @@ -203,6 +203,31 @@ static struct virtqueue_sg *vq_sg_alloc(unsigned int nsgl) return vq_sg; } +/** + * vq_sg_resize - resize passed virtqueue scatter/gather lists to the passed + * amount of lists + * @_vq_sg: scatter/gather lists to be resized + * @nsgl: new amount of scatter/gather lists + */ +static int vq_sg_resize(struct virtqueue_sg **_vq_sg, unsigned int nsgl) +{ + struct virtqueue_sg *vq_sg; + + BUG_ON(!_vq_sg || !nsgl); + vq_sg = *_vq_sg; + if (vq_sg->nsgl == nsgl) + return 0; + + /* lazy resize implementation for now */ + vq_sg = vq_sg_alloc(nsgl); + if (!vq_sg) + return -ENOMEM; + + kfree(*_vq_sg); + *_vq_sg = vq_sg; + return 0; +} + /** * p9_virtio_close - reclaim resources of a channel * @client: client instance @@ -774,6 +799,10 @@ p9_virtio_create(struct p9_client *client, const char *devname, char *args) struct virtio_chan *chan; int ret = -ENOENT; int found = 0; +#if !defined(CONFIG_ARCH_NO_SG_CHAIN) + size_t npages; + size_t nsgl; +#endif if (devname == NULL) return -EINVAL; @@ -796,6 +825,38 @@ p9_virtio_create(struct p9_client *client, const char *devname, char *args) return ret; } + /* + * if user supplied an 'msize' option that's larger than what this + * transport supports by default, then try to allocate more sg lists + */ + if (client->msize > client->trans_maxsize) { +#ifdef CONFIG_ARCH_NO_SG_CHAIN + pr_info("limiting 'msize' to %d because architecture does not " + "support chained scatter gather lists\n", + client->trans_maxsize); +#else + npages = DIV_ROUND_UP(client->msize, PAGE_SIZE); + if (npages > chan->p9_max_pages) { + npages = chan->p9_max_pages; + pr_info("limiting 'msize' as it would exceed the max. " + "of %lu pages allowed on this system\n", + chan->p9_max_pages); + } + nsgl = DIV_ROUND_UP(npages, SG_USER_PAGES_PER_LIST); + if (nsgl > chan->vq_sg->nsgl) { + /* + * if resize fails, no big deal, then just + * continue with default msize instead + */ + if (!vq_sg_resize(&chan->vq_sg, nsgl)) { + client->trans_maxsize = + PAGE_SIZE * + ((nsgl * SG_USER_PAGES_PER_LIST) - 3); + } + } +#endif /* CONFIG_ARCH_NO_SG_CHAIN */ + } + client->trans = (void *)chan; client->status = Connected; chan->client = client; From patchwork Wed Sep 22 16:00:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 12511133 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1875C433F5 for ; Wed, 22 Sep 2021 17:30:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C5C7F61153 for ; Wed, 22 Sep 2021 17:30:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236858AbhIVRb7 (ORCPT ); Wed, 22 Sep 2021 13:31:59 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:47947 "EHLO lizzy.crudebyte.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236837AbhIVRb5 (ORCPT ); Wed, 22 Sep 2021 13:31:57 -0400 X-Greylist: delayed 2675 seconds by postgrey-1.27 at vger.kernel.org; Wed, 22 Sep 2021 13:31:56 EDT DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=uAkW4TzWUK16Ru7P7NVmzaRv5wNfHu4c5UQ/NgBgNCA=; b=FqXMK 8A3sVyxb17CYv7bIfljrujhdCLCGIyXrCG/VlclgMOBUx/ENyoXTilIDxsW1I42SCqACmqocetTIO 0zULow7k+Eofe8gPQujhXZhfKMHrj3KerfJP4uAPFCUJt/jra5A8LczIuUWKlBVfpiM+pR4aN7CIY Lq5VmDxmGHIOGXntY0+u/jraYaTygoiNG2k1XGenRF3pcBUQm7bsMPJ8FXanDjNE3NnJ86FJFdXtS Zr4X+S9udp45Rh6gHtRr4FzjrTQA9VY1RCaAhkgrxCUiZwQvKHz1vpzLBW/qsi+rd6KK6SvUPQxex k25rxt6iODgZrsOPofOZJ2n3ED/Xw==; Message-Id: <3a0d9c26581f237976c5903e332d49c9727b3fa7.1632327421.git.linux_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Wed, 22 Sep 2021 18:00:35 +0200 Subject: [PATCH v3 7/7] 9p/trans_virtio: resize sg lists to whatever is possible To: v9fs-developer@lists.sourceforge.net Cc: netdev@vger.kernel.org, Dominique Martinet , Eric Van Hensbergen , Latchesar Ionkov , Greg Kurz , Vivek Goyal Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Right now vq_sg_resize() used a lazy implementation following the all-or-nothing princible. So it either resized exactly to the requested new amount of sg lists, or it did not resize at all. The problem with this is if a user supplies a very large msize value, resize would simply fail and the user would stick to the default maximum msize supported by the virtio transport. To resolve this potential issue, change vq_sg_resize() to resize the passed sg list to whatever is possible on the machine. Signed-off-by: Christian Schoenebeck --- net/9p/trans_virtio.c | 68 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c index 147ebf647a95..4c61b4857bea 100644 --- a/net/9p/trans_virtio.c +++ b/net/9p/trans_virtio.c @@ -208,24 +208,67 @@ static struct virtqueue_sg *vq_sg_alloc(unsigned int nsgl) * amount of lists * @_vq_sg: scatter/gather lists to be resized * @nsgl: new amount of scatter/gather lists + * + * Old scatter/gather lists are retained. Only growing the size is supported. + * If the requested amount cannot be satisfied, then lists are increased to + * whatever is possible. */ static int vq_sg_resize(struct virtqueue_sg **_vq_sg, unsigned int nsgl) { struct virtqueue_sg *vq_sg; + unsigned int i; + size_t sz; + int ret = 0; BUG_ON(!_vq_sg || !nsgl); vq_sg = *_vq_sg; + if (nsgl > VIRTQUEUE_SG_NSGL_MAX) + nsgl = VIRTQUEUE_SG_NSGL_MAX; if (vq_sg->nsgl == nsgl) return 0; + if (vq_sg->nsgl > nsgl) + return -ENOTSUPP; + + vq_sg = kzalloc(sizeof(struct virtqueue_sg) + + nsgl * sizeof(struct scatterlist *), + GFP_KERNEL); - /* lazy resize implementation for now */ - vq_sg = vq_sg_alloc(nsgl); if (!vq_sg) return -ENOMEM; + /* copy over old scatter gather lists */ + sz = sizeof(struct virtqueue_sg) + + (*_vq_sg)->nsgl * sizeof(struct scatterlist *); + memcpy(vq_sg, *_vq_sg, sz); + + vq_sg->nsgl = nsgl; + + for (i = (*_vq_sg)->nsgl; i < nsgl; ++i) { + vq_sg->sgl[i] = kmalloc_array( + SG_MAX_SINGLE_ALLOC, sizeof(struct scatterlist), + GFP_KERNEL + ); + /* + * handle failed allocation as soft error, we take whatever + * we get + */ + if (!vq_sg->sgl[i]) { + ret = -ENOMEM; + vq_sg->nsgl = nsgl = i; + break; + } + sg_init_table(vq_sg->sgl[i], SG_MAX_SINGLE_ALLOC); + if (i) { + /* chain the lists */ + sg_chain(vq_sg->sgl[i - 1], SG_MAX_SINGLE_ALLOC, + vq_sg->sgl[i]); + } + } + sg_mark_end(&vq_sg->sgl[nsgl - 1][SG_MAX_SINGLE_ALLOC - 1]); + kfree(*_vq_sg); *_vq_sg = vq_sg; - return 0; + return ret; } /** @@ -846,12 +889,21 @@ p9_virtio_create(struct p9_client *client, const char *devname, char *args) if (nsgl > chan->vq_sg->nsgl) { /* * if resize fails, no big deal, then just - * continue with default msize instead + * continue with whatever we got + */ + vq_sg_resize(&chan->vq_sg, nsgl); + /* + * actual allocation size might be less than + * requested, so use vq_sg->nsgl instead of nsgl */ - if (!vq_sg_resize(&chan->vq_sg, nsgl)) { - client->trans_maxsize = - PAGE_SIZE * - ((nsgl * SG_USER_PAGES_PER_LIST) - 3); + client->trans_maxsize = + PAGE_SIZE * ((chan->vq_sg->nsgl * + SG_USER_PAGES_PER_LIST) - 3); + if (nsgl > chan->vq_sg->nsgl) { + pr_info("limiting 'msize' to %d as only %d " + "of %zu SG lists could be allocated", + client->trans_maxsize, + chan->vq_sg->nsgl, nsgl); } } #endif /* CONFIG_ARCH_NO_SG_CHAIN */