Received: by 2002:ac0:8c8e:0:0:0:0:0 with SMTP id r14csp573372ima; Wed, 6 Feb 2019 05:04:36 -0800 (PST) X-Google-Smtp-Source: AHgI3IbL8IyR61NREWlnN4M9PmKwJTkclmGdJucmA90RNIB0gKiwNj1KyZDH+LAzlJwv4NesOgcH X-Received: by 2002:a62:ab0d:: with SMTP id p13mr10427181pff.211.1549458276781; Wed, 06 Feb 2019 05:04:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549458276; cv=none; d=google.com; s=arc-20160816; b=TbWxyUvG5GV2WdCTPXgxAhSZHOVzALvjrVtOIHQwgOAuzybXdOIgdEFCZSLCX8Dk3w o19o0ltYa9YgQSje615uLo2HBD1P6E1610gyT/OORMrpmm5iAFzRdP+vCsew5fP6ylkq uYpI+t92XiMQmx9fKpBQmk/uAv65BRnQTl10eAptbCZpyqoCMMNwHiUP73ETRLn9f7R0 mT4kLW1I9aBMGV5fkKs/torIq6gFaz2PeHlVUkr9+qcvMpsWSkkG2aEMy1JCw8HENJyv atXFS+X0mj/WFlGV4kTac6iemxnXRgvffJK495se+v8qI4/FNgWj75D5P5ufZ7MsPEeb jW9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:mime-version:user-agent:date :message-id:organization:autocrypt:openpgp:from:references:cc:to :subject; bh=usPpdY84UwzooG5xQbwATVdd03skMKjjrutqPd077O0=; b=E1U9qe0C7HE7no1/m45NCuX7P/E+yARMIONQxWNGwenVkOIHaoqnktJklyhk0e6WRI oHnNiIfA5nA8wORyFooiko7QIjlWJUzwJi0PMr9OkHY+jeeJP8+LWuxah1qZikw6Msm+ ibAA53x60jdeK1N7rB32kW3l9KI4p5kenNao+3Kkkkpl/Mex8iGU/yC25l12+t7fMipB YWIFkU4YQzQcNbFHa5OwO83c/T9xCAVpXqR6iUuXhDuEjhAgPjE/sz/lHYmJbiaVw2/Q nJcz2+HETctWJ37MNeDF1a7toPljeL03ElDF6ivE9ckG5rR1nTQd25Oghw5mjuBZsHX+ m33g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ay4si6010022plb.235.2019.02.06.05.04.20; Wed, 06 Feb 2019 05:04:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730477AbfBFM4q (ORCPT + 99 others); Wed, 6 Feb 2019 07:56:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46880 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727585AbfBFM4p (ORCPT ); Wed, 6 Feb 2019 07:56:45 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A58A8A787A; Wed, 6 Feb 2019 12:56:44 +0000 (UTC) Received: from [10.18.17.32] (dhcp-17-32.bos.redhat.com [10.18.17.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E5DA68D27; Wed, 6 Feb 2019 12:56:38 +0000 (UTC) Subject: Re: [RFC][Patch v8 5/7] virtio: Enables to add a single descriptor to the host To: "Michael S. Tsirkin" Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com, lcapitulino@redhat.com, pagupta@redhat.com, wei.w.wang@intel.com, yang.zhang.wz@gmail.com, riel@surriel.com, david@redhat.com, dodgen@google.com, konrad.wilk@oracle.com, dhildenb@redhat.com, aarcange@redhat.com References: <20190204201854.2328-1-nitesh@redhat.com> <20190204201854.2328-6-nitesh@redhat.com> <20190205154545-mutt-send-email-mst@kernel.org> From: Nitesh Narayan Lal Openpgp: preference=signencrypt Autocrypt: addr=nitesh@redhat.com; prefer-encrypt=mutual; keydata= mQINBFl4pQoBEADT/nXR2JOfsCjDgYmE2qonSGjkM1g8S6p9UWD+bf7YEAYYYzZsLtbilFTe z4nL4AV6VJmC7dBIlTi3Mj2eymD/2dkKP6UXlliWkq67feVg1KG+4UIp89lFW7v5Y8Muw3Fm uQbFvxyhN8n3tmhRe+ScWsndSBDxYOZgkbCSIfNPdZrHcnOLfA7xMJZeRCjqUpwhIjxQdFA7 n0s0KZ2cHIsemtBM8b2WXSQG9CjqAJHVkDhrBWKThDRF7k80oiJdEQlTEiVhaEDURXq+2XmG jpCnvRQDb28EJSsQlNEAzwzHMeplddfB0vCg9fRk/kOBMDBtGsTvNT9OYUZD+7jaf0gvBvBB lbKmmMMX7uJB+ejY7bnw6ePNrVPErWyfHzR5WYrIFUtgoR3LigKnw5apzc7UIV9G8uiIcZEn C+QJCK43jgnkPcSmwVPztcrkbC84g1K5v2Dxh9amXKLBA1/i+CAY8JWMTepsFohIFMXNLj+B RJoOcR4HGYXZ6CAJa3Glu3mCmYqHTOKwezJTAvmsCLd3W7WxOGF8BbBjVaPjcZfavOvkin0u DaFvhAmrzN6lL0msY17JCZo046z8oAqkyvEflFbC0S1R/POzehKrzQ1RFRD3/YzzlhmIowkM BpTqNBeHEzQAlIhQuyu1ugmQtfsYYq6FPmWMRfFPes/4JUU/PQARAQABtCVOaXRlc2ggTmFy YXlhbiBMYWwgPG5pbGFsQHJlZGhhdC5jb20+iQI9BBMBCAAn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NK9ZhT0+qkiN7npFLtNtbzwqaqceq3XhafmCiw8xrtzCnlB/C4SiBr/93Ip4kihXJ0EuHSLn VujM7c/b4pps Organization: Red Hat Inc, Message-ID: <26a36489-2289-f970-3362-60547b268a76@redhat.com> Date: Wed, 6 Feb 2019 07:56:37 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190205154545-mutt-send-email-mst@kernel.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ha4exRGTtw5KbdsWt5m4y9umJmPCcpij8" X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 06 Feb 2019 12:56:44 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --ha4exRGTtw5KbdsWt5m4y9umJmPCcpij8 Content-Type: multipart/mixed; boundary="tdA7p9mxdzwJbQvr5PBwjo22dgtaMZoyO"; protected-headers="v1" From: Nitesh Narayan Lal To: "Michael S. Tsirkin" Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com, lcapitulino@redhat.com, pagupta@redhat.com, wei.w.wang@intel.com, yang.zhang.wz@gmail.com, riel@surriel.com, david@redhat.com, dodgen@google.com, konrad.wilk@oracle.com, dhildenb@redhat.com, aarcange@redhat.com Message-ID: <26a36489-2289-f970-3362-60547b268a76@redhat.com> Subject: Re: [RFC][Patch v8 5/7] virtio: Enables to add a single descriptor to the host References: <20190204201854.2328-1-nitesh@redhat.com> <20190204201854.2328-6-nitesh@redhat.com> <20190205154545-mutt-send-email-mst@kernel.org> In-Reply-To: <20190205154545-mutt-send-email-mst@kernel.org> --tdA7p9mxdzwJbQvr5PBwjo22dgtaMZoyO Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Language: en-US On 2/5/19 3:49 PM, Michael S. Tsirkin wrote: > On Mon, Feb 04, 2019 at 03:18:52PM -0500, Nitesh Narayan Lal wrote: >> This patch enables the caller to expose a single buffers to the >> other end using vring descriptor. It also allows the caller to >> perform this action in synchornous manner by using virtqueue_kick_sync= =2E >> >> Signed-off-by: Nitesh Narayan Lal > I am not sure why do we need this API. Polling in guest > until host runs isn't great either since these > might be running on the same host CPU. True. However, my understanding is that the existing API such as virtqueue_add_outbuf() requires an allocation which will be problematic for my implementation. Although I am not blocking the allocation path during normal Linux kernel usage as even if one of the zone is locked the other zone could be used to get free pages. But during the initial boot time (device initialization), in certain situations the allocation can only come from a single zone, acquiring a lock on it may result in a deadlock situation. > > > >> --- >> drivers/virtio/virtio_ring.c | 72 +++++++++++++++++++++++++++++++++++= + >> include/linux/virtio.h | 4 ++ >> 2 files changed, 76 insertions(+) >> >> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring= =2Ec >> index cd7e755484e3..93c161ac6a28 100644 >> --- a/drivers/virtio/virtio_ring.c >> +++ b/drivers/virtio/virtio_ring.c >> @@ -1695,6 +1695,52 @@ static inline int virtqueue_add(struct virtqueu= e *_vq, >> out_sgs, in_sgs, data, ctx, gfp); >> } >> =20 >> +/** >> + * virtqueue_add_desc - add a buffer to a chain using a vring desc >> + * @vq: the struct virtqueue we're talking about. >> + * @addr: address of the buffer to add. >> + * @len: length of the buffer. >> + * @in: set if the buffer is for the device to write. >> + * >> + * Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO). >> + */ >> +int virtqueue_add_desc(struct virtqueue *_vq, u64 addr, u32 len, int = in) >> +{ >> + struct vring_virtqueue *vq =3D to_vvq(_vq); >> + struct vring_desc *desc =3D vq->split.vring.desc; >> + u16 flags =3D in ? VRING_DESC_F_WRITE : 0; >> + unsigned int i; >> + void *data =3D (void *)addr; >> + int avail_idx; >> + >> + /* Sanity check */ >> + if (!_vq) >> + return -EINVAL; >> + >> + START_USE(vq); >> + if (unlikely(vq->broken)) { >> + END_USE(vq); >> + return -EIO; >> + } >> + >> + i =3D vq->free_head; >> + flags &=3D ~VRING_DESC_F_NEXT; >> + desc[i].flags =3D cpu_to_virtio16(_vq->vdev, flags); >> + desc[i].addr =3D cpu_to_virtio64(_vq->vdev, addr); >> + desc[i].len =3D cpu_to_virtio32(_vq->vdev, len); >> + >> + vq->vq.num_free--; >> + vq->free_head =3D virtio16_to_cpu(_vq->vdev, desc[i].next); >> + vq->split.desc_state[i].data =3D data; >> + vq->split.avail_idx_shadow =3D 1; >> + avail_idx =3D vq->split.avail_idx_shadow; >> + vq->split.vring.avail->idx =3D cpu_to_virtio16(_vq->vdev, avail_idx)= ; >> + vq->num_added =3D 1; >> + END_USE(vq); >> + return 0; >> +} >> +EXPORT_SYMBOL_GPL(virtqueue_add_desc); >> + >> /** >> * virtqueue_add_sgs - expose buffers to other end >> * @vq: the struct virtqueue we're talking about. >> @@ -1842,6 +1888,32 @@ bool virtqueue_notify(struct virtqueue *_vq) >> } >> EXPORT_SYMBOL_GPL(virtqueue_notify); >> =20 >> +/** >> + * virtqueue_kick_sync - update after add_buf and busy wait till upda= te is done >> + * @vq: the struct virtqueue >> + * >> + * After one or more virtqueue_add_* calls, invoke this to kick >> + * the other side. Busy wait till the other side is done with the upd= ate. >> + * >> + * Caller must ensure we don't call this with other virtqueue >> + * operations at the same time (except where noted). >> + * >> + * Returns false if kick failed, otherwise true. >> + */ >> +bool virtqueue_kick_sync(struct virtqueue *vq) >> +{ >> + u32 len; >> + >> + if (likely(virtqueue_kick(vq))) { >> + while (!virtqueue_get_buf(vq, &len) && >> + !virtqueue_is_broken(vq)) >> + cpu_relax(); >> + return true; >> + } >> + return false; >> +} >> +EXPORT_SYMBOL_GPL(virtqueue_kick_sync); >> + >> /** >> * virtqueue_kick - update after add_buf >> * @vq: the struct virtqueue >> diff --git a/include/linux/virtio.h b/include/linux/virtio.h >> index fa1b5da2804e..58943a3a0e8d 100644 >> --- a/include/linux/virtio.h >> +++ b/include/linux/virtio.h >> @@ -57,6 +57,10 @@ int virtqueue_add_sgs(struct virtqueue *vq, >> unsigned int in_sgs, >> void *data, >> gfp_t gfp); >> +/* A desc with this init id is treated as an invalid desc */ >> +int virtqueue_add_desc(struct virtqueue *_vq, u64 addr, u32 len, int = in); >> + >> +bool virtqueue_kick_sync(struct virtqueue *vq); >> =20 >> bool virtqueue_kick(struct virtqueue *vq); >> =20 >> --=20 >> 2.17.2 --=20 Regards Nitesh --tdA7p9mxdzwJbQvr5PBwjo22dgtaMZoyO-- --ha4exRGTtw5KbdsWt5m4y9umJmPCcpij8 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEkXcoRVGaqvbHPuAGo4ZA3AYyozkFAlxa2YUACgkQo4ZA3AYy ozm3YhAArLA7JLniz1fqgzuOgoKdVdhkoaS1sxtMPh31s/UzOtaArza9oi65DlcI qCwYTo48bsoo4+VAQfBWkYI3F8mdCnPZNRUzCrIgKMA+DSUF27PjUOEvpxZeADMP TgaXwONd/cPYOlXRomZlSfUwzq0fKDh/X6CPXAqPaaEf2L5yDvET3B69INGgxTzz yMPWeCUtw5R4Q0KGPOnGhiJ8PbhgO5hP9yZZOlXJVMJo2ADb1BugC6AmTR6CM880 BI2/pSAuYKvtSEV4hRV7nHsqBHaPvVGaaPfbW1rmWrkNLquk91hm8vrPH8aw0wCS neu/GDQ9LMgRWrR05Pr359Tg+SyPEiNrBrHHjNJ8ttISSlcW6XWOXkGwx9yydjkC aTUP9+lDNsv/7A9RvqG12/OnM0/Juy8eDQMoJdHnqSeGbBjjYBxxI2EtrGXh8nZx OErN/nebZUnS9AdZXIrEgwmK0/Wc9U66sXgkowu8WHMReJPwrFoHoctmJCjOoMAH ViT3DC2c5qw6Xp0+laEItIw5M/wjn0VMhj21RYbp2sjEJ4QTM1jSVAm1NsYHmdrt pyoxCMg55C/sp41JkrZHN6DedF2qFT0NA1NK5i6gKR9az2Jfju4eLsqAJh3nPx/2 qcXjgvO21PDf9kMFbb2p79oCmGtAUBxoqMAd8vYWZXh0UMn+s6E= =J5tb -----END PGP SIGNATURE----- --ha4exRGTtw5KbdsWt5m4y9umJmPCcpij8--