From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60863) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YC30J-0004gx-3h for qemu-devel@nongnu.org; Fri, 16 Jan 2015 04:15:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YC307-0003eX-R0 for qemu-devel@nongnu.org; Fri, 16 Jan 2015 04:15:43 -0500 Received: from mail-bl2on0118.outbound.protection.outlook.com ([65.55.169.118]:32577 helo=na01-bl2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YC307-0003eL-Bv for qemu-devel@nongnu.org; Fri, 16 Jan 2015 04:15:31 -0500 Message-ID: <54B8D6A1.8030800@freescale.com> Date: Fri, 16 Jan 2015 11:15:13 +0200 From: Vasile Catalin-B50542 MIME-Version: 1.0 References: <54B65A8B.3000801@freescale.com> <20150115014131.GA8720@ad.nay.redhat.com> In-Reply-To: <20150115014131.GA8720@ad.nay.redhat.com> Content-Type: multipart/alternative; boundary="------------000109090108030200000504" Subject: Re: [Qemu-devel] [virtio] virtqueue allocation and thread-safety List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: qemu-devel@nongnu.org --------------000109090108030200000504 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Does the guest memory allocation include the descriptor tables allocation? Which part of the structures is the descriptor tables? On 15.01.2015 03:41, Fam Zheng wrote: > On Wed, 01/14 14:01, Vasile Catalin-B50542 wrote: >> Hi, >> >> I'm trying to make a new virtio device. >> I got it running (I made a functional dummy device & guest driver). >> Now I'm trying to build some communication between the device and guest >> driver. >> I can't seem to find where the actual allocation of virtqueues are made. >> I've looked inside virtio_init(), but it just allocates the vq structures >> and I don't see >> any pointers inside that structure that might give and idea of something >> dynamically >> allocated. There is a member of that structure named "vector", but it's type >> is uint16_t. >> I've also looked inside the virtio_add_queue(), and it just makes some >> constant assignments. >> Where are the vqs buffer space actually allocated? > The guest memory is prepared by guest. See the virtio spec "Virtual I/O Device > (VIRTIO) Version 1.0" section "3.2.1 Supplying Buffers to The Device": > > > > The driver offers buffers to one of the device’s virtqueues as follows: > > 1. The driver places the buffer into free descriptor(s) in the descriptor > table, chaining as necessary (see 2.4.5 The Virtqueue Descriptor Table). > > 2. The driver places the index of the head of the descriptor chain into the > next ring entry of the available ring. > > 3. Steps 1 and 2 MAY be performed repeatedly if batching is possible. > > 4. The driver performs suitable a memory barrier to ensure the device sees the > updated descriptor table and available ring before the next step. > > 5. The available idx is increased by the number of descriptor chain heads added > to the available ring. > > 6. The driver performs a suitable memory barrier to ensure that it updates the > idx field before checking for notification suppression. > > 7. If notifications are not suppressed, the driver notifies the device of the > new available buffers. > > > > Fam > >> One more thing. Are the virtqueue functions thread safe, from both point of >> views >> (qemu and guest driver API's view)? >> Also I don't see any dynamic allocations/freeing when pushing and popping, >> either. >> >> Cătă >> -- CatalinVasile Intern, DN-Software FreescaleSemiconductor, Inc. www.freescale.com phone: 073-021-1938 e-mail: catalin.vasile@freescale.com *Freescale_Logo-nosemi_Lh_4c*** This e-mail, and any associated attachments have been classified as: [ ] Public [ ] Freescale Semiconductor Internal Use Only [ ] Freescale Semiconductor Confidential Proprietary --------------000109090108030200000504 Content-Type: multipart/related; boundary="------------040506040603080206010206" --------------040506040603080206010206 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: 8bit Does the guest memory allocation include the descriptor tables allocation?
Which part of the structures is the descriptor tables?

On 15.01.2015 03:41, Fam Zheng wrote:
On Wed, 01/14 14:01, Vasile Catalin-B50542 wrote:
Hi,

I'm trying to make a new virtio device.
I got it running (I made a functional dummy device & guest driver).
Now I'm trying to build some communication between the device and guest
driver.
I can't seem to find where the actual allocation of virtqueues are made.
I've looked inside virtio_init(), but it just allocates the vq structures
and I don't see
any pointers inside that structure that might give and idea of something
dynamically
allocated. There is a member of that structure named "vector", but it's type
is uint16_t.
I've also looked inside the virtio_add_queue(), and it just makes some
constant assignments.
Where are the vqs buffer space actually allocated?
The guest memory is prepared by guest. See the virtio spec "Virtual I/O Device
(VIRTIO) Version 1.0" section "3.2.1 Supplying Buffers to The Device":

<quote>

The driver offers buffers to one of the device’s virtqueues as follows:

1. The driver places the buffer into free descriptor(s) in the descriptor
table, chaining as necessary (see 2.4.5 The Virtqueue Descriptor Table).

2. The driver places the index of the head of the descriptor chain into the
next ring entry of the available ring.

3. Steps 1 and 2 MAY be performed repeatedly if batching is possible.

4. The driver performs suitable a memory barrier to ensure the device sees the
updated descriptor table and available ring before the next step.

5. The available idx is increased by the number of descriptor chain heads added
to the available ring.

6. The driver performs a suitable memory barrier to ensure that it updates the
idx field before checking for notification suppression.

7. If notifications are not suppressed, the driver notifies the device of the
new available buffers.

</unquote>

Fam

One more thing. Are the virtqueue functions thread safe, from both point of
views
(qemu and guest driver API's view)?
Also I don't see any dynamic allocations/freeing when pushing and popping,
either.

Cătă


--

Catalin Vasile

Intern, DN-Software

Freescale Semiconductor, Inc.

www.freescale.com

phone: 073-021-1938

e-mail: catalin.vasile@freescale.com

Freescale_Logo-nosemi_Lh_4c

This e-mail, and any associated attachments have been classified as:

[ ] Public

[ ] Freescale Semiconductor Internal Use Only

[ ] Freescale Semiconductor Confidential Proprietary

--------------040506040603080206010206 Content-Type: image/gif; name="image002.gif" Content-Transfer-Encoding: base64 Content-ID: Content-Disposition: inline; filename="image002.gif" R0lGODlhwwBJAHcAMSH+GlNvZnR3YXJlOiBNaWNyb3NvZnQgT2ZmaWNlACH5BAEAAAAALBkA EACeACgAhwAAAAAAAAAAMwAAZgAAmQAAzAAA/wAzAAAzMwAzZgAzmQAzzAAz/wBmAABmMwBm ZgBmmQBmzABm/wCZAACZMwCZZgCZmQCZzACZ/wDMAADMMwDMZgDMmQDMzADM/wD/AAD/MwD/ ZgD/mQD/zAD//zMAADMAMzMAZjMAmTMAzDMA/zMzADMzMzMzZjMzmTMzzDMz/zN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ti/0 Mc5NWgtM6gbkrwORzE33QpPPeoQkrEhVriDK8A9GBOgSF+brZGbjHBTvl7nJRU5aaCrW4tC0 w8zByGYOjNfSFvY57onEYkurYUFq17wibQ1xlUrZGIektX+x73WwEhMdM1a6BHYLjyCy3nVa oaS0MaSQnuqfkAjpKWIpEn6FLGEkOxK7Rj4SSZikSEAAADs= --------------040506040603080206010206-- --------------000109090108030200000504--