From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40001) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c6fH7-0000U3-5A for qemu-devel@nongnu.org; Tue, 15 Nov 2016 10:03:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c6fH3-0003wV-67 for qemu-devel@nongnu.org; Tue, 15 Nov 2016 10:03:53 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:41104 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c6fH3-0003v7-0z for qemu-devel@nongnu.org; Tue, 15 Nov 2016 10:03:49 -0500 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uAFEwhh1030875 for ; Tue, 15 Nov 2016 10:03:45 -0500 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0b-001b2d01.pphosted.com with ESMTP id 26r2cgfb6x-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 15 Nov 2016 10:03:45 -0500 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 15 Nov 2016 15:03:43 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 4162617D8042 for ; Tue, 15 Nov 2016 15:06:05 +0000 (GMT) Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id uAFF3fm533554460 for ; Tue, 15 Nov 2016 15:03:41 GMT Received: from d06av01.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id uAFF3f57011312 for ; Tue, 15 Nov 2016 08:03:41 -0700 References: <20161115134629.23161-1-pbonzini@redhat.com> <20161115134629.23161-3-pbonzini@redhat.com> From: Christian Borntraeger Date: Tue, 15 Nov 2016 16:03:40 +0100 MIME-Version: 1.0 In-Reply-To: <20161115134629.23161-3-pbonzini@redhat.com> Content-Type: text/plain; charset=UTF-8 Message-Id: <09b1a5ef-81ed-9af2-a48f-ee4882c87939@de.ibm.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 2/3] virtio: access ISR atomically List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org Cc: mst@redhat.com, alex.williamson@redhat.com, felipe@nutanix.com On 11/15/2016 02:46 PM, Paolo Bonzini wrote: > This will be needed once dataplane will be able to set it outside > the big QEMU lock. >=20 > Signed-off-by: Paolo Bonzini This is fixed by the followup patch, but this patch alone gives me /home/cborntra/REPOS/qemu/hw/virtio/virtio.c: In function =E2=80=98virtio= _notify_config=E2=80=99: /home/cborntra/REPOS/qemu/hw/virtio/virtio.c:1375:20: error: =E2=80=98vq=E2= =80=99 undeclared (first use in this function) virtio_set_isr(vq->vdev, 0x3); ^ /home/cborntra/REPOS/qemu/hw/virtio/virtio.c:1375:20: note: each undeclar= ed identifier is reported only once for each function it appears in /home/cborntra/REPOS/qemu/rules.mak:60: recipe for target 'hw/virtio/virt= io.o' failed make[1]: *** [hw/virtio/virtio.o] Error 1 make[1]: *** Waiting for unfinished jobs.... > --- > hw/virtio/virtio-mmio.c | 6 +++--- > hw/virtio/virtio-pci.c | 9 +++------ > hw/virtio/virtio.c | 18 +++++++++++++----- > 3 files changed, 19 insertions(+), 14 deletions(-) >=20 > diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c > index a30270f..17412cb 100644 > --- a/hw/virtio/virtio-mmio.c > +++ b/hw/virtio/virtio-mmio.c > @@ -191,7 +191,7 @@ static uint64_t virtio_mmio_read(void *opaque, hwad= dr offset, unsigned size) > return virtio_queue_get_addr(vdev, vdev->queue_sel) > >> proxy->guest_page_shift; > case VIRTIO_MMIO_INTERRUPTSTATUS: > - return vdev->isr; > + return atomic_read(&vdev->isr); > case VIRTIO_MMIO_STATUS: > return vdev->status; > case VIRTIO_MMIO_HOSTFEATURESSEL: > @@ -299,7 +299,7 @@ static void virtio_mmio_write(void *opaque, hwaddr = offset, uint64_t value, > } > break; > case VIRTIO_MMIO_INTERRUPTACK: > - vdev->isr &=3D ~value; > + atomic_and(&vdev->isr, ~value); > virtio_update_irq(vdev); > break; > case VIRTIO_MMIO_STATUS: > @@ -347,7 +347,7 @@ static void virtio_mmio_update_irq(DeviceState *opa= que, uint16_t vector) > if (!vdev) { > return; > } > - level =3D (vdev->isr !=3D 0); > + level =3D (atomic_read(&vdev->isr) !=3D 0); > DPRINTF("virtio_mmio setting IRQ %d\n", level); > qemu_set_irq(proxy->irq, level); > } > diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c > index 62001b4..d5e99b0 100644 > --- a/hw/virtio/virtio-pci.c > +++ b/hw/virtio/virtio-pci.c > @@ -73,7 +73,7 @@ static void virtio_pci_notify(DeviceState *d, uint16_= t vector) > msix_notify(&proxy->pci_dev, vector); > else { > VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); > - pci_set_irq(&proxy->pci_dev, vdev->isr & 1); > + pci_set_irq(&proxy->pci_dev, atomic_read(&vdev->isr) & 1); > } > } >=20 > @@ -449,8 +449,7 @@ static uint32_t virtio_ioport_read(VirtIOPCIProxy *= proxy, uint32_t addr) > break; > case VIRTIO_PCI_ISR: > /* reading from the ISR also clears it. */ > - ret =3D vdev->isr; > - vdev->isr =3D 0; > + ret =3D atomic_xchg(&vdev->isr, 0); > pci_irq_deassert(&proxy->pci_dev); > break; > case VIRTIO_MSI_CONFIG_VECTOR: > @@ -1377,9 +1376,7 @@ static uint64_t virtio_pci_isr_read(void *opaque,= hwaddr addr, > { > VirtIOPCIProxy *proxy =3D opaque; > VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); > - uint64_t val =3D vdev->isr; > - > - vdev->isr =3D 0; > + uint64_t val =3D atomic_xchg(&vdev->isr, 0); > pci_irq_deassert(&proxy->pci_dev); >=20 > return val; > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c > index 89b0b80..35255ad 100644 > --- a/hw/virtio/virtio.c > +++ b/hw/virtio/virtio.c > @@ -945,7 +945,7 @@ void virtio_reset(void *opaque) > vdev->guest_features =3D 0; > vdev->queue_sel =3D 0; > vdev->status =3D 0; > - vdev->isr =3D 0; > + atomic_set(&vdev->isr, 0); > vdev->config_vector =3D VIRTIO_NO_VECTOR; > virtio_notify_vector(vdev, vdev->config_vector); >=20 > @@ -1318,10 +1318,18 @@ void virtio_del_queue(VirtIODevice *vdev, int n= ) > vdev->vq[n].vring.num_default =3D 0; > } >=20 > +static void virtio_set_isr(VirtIODevice *vdev, int value) > +{ > + uint8_t old =3D atomic_read(&vdev->isr); > + if ((old & value) !=3D value) { > + atomic_or(&vdev->isr, value); > + } > +} > + > void virtio_irq(VirtQueue *vq) > { > trace_virtio_irq(vq); > - vq->vdev->isr |=3D 0x01; > + virtio_set_isr(vq->vdev, 0x1); > virtio_notify_vector(vq->vdev, vq->vector); > } >=20 > @@ -1355,7 +1363,7 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue = *vq) > } >=20 > trace_virtio_notify(vdev, vq); > - vdev->isr |=3D 0x01; > + virtio_set_isr(vq->vdev, 0x1); > virtio_notify_vector(vdev, vq->vector); > } >=20 > @@ -1364,7 +1372,7 @@ void virtio_notify_config(VirtIODevice *vdev) > if (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) > return; >=20 > - vdev->isr |=3D 0x03; > + virtio_set_isr(vq->vdev, 0x3); > vdev->generation++; > virtio_notify_vector(vdev, vdev->config_vector); > } > @@ -1895,7 +1903,7 @@ void virtio_init(VirtIODevice *vdev, const char *= name, >=20 > vdev->device_id =3D device_id; > vdev->status =3D 0; > - vdev->isr =3D 0; > + atomic_set(&vdev->isr, 0); > vdev->queue_sel =3D 0; > vdev->config_vector =3D VIRTIO_NO_VECTOR; > vdev->vq =3D g_malloc0(sizeof(VirtQueue) * VIRTIO_QUEUE_MAX); >=20