Received: from eggs.gnu.org ([2001:4830:134:3::10]:58824) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c2c3s-0006k5-Qu for qemu-devel@nongnu.org; Fri, 04 Nov 2016 06:49:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c2c3o-0001BA-GZ for qemu-devel@nongnu.org; Fri, 04 Nov 2016 06:49:28 -0400 Date: Fri, 4 Nov 2016 10:49:21 +0000 From: Stefan Hajnoczi Message-ID: <20161104104921.GD9817@stefanha-x1.localdomain> References: <1476827711-20758-1-git-send-email-logang@deltatee.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="mJm6k4Vb/yFcL9ZU" Content-Disposition: inline In-Reply-To: <1476827711-20758-1-git-send-email-logang@deltatee.com> Subject: Re: [Qemu-devel] [Qemu-block] [PATCH] Added iopmem device emulation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Logan Gunthorpe Cc: Kevin Wolf , Max Reitz , "Michael S. Tsirkin" , Marcel Apfelbaum , qemu-devel@nongnu.org, qemu-block@nongnu.org, Stephen Bates --mJm6k4Vb/yFcL9ZU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Oct 18, 2016 at 03:55:11PM -0600, Logan Gunthorpe wrote: > An iopmem device is one which exposes volatile or non-volatile memory map= ped > directly to a BAR region. One purpose is to provide buffers to do peer > to peer transfers on the bus. As such this device uses QEMU's drive > backing store to simulate non-volatile memory and provides through a > mapped BAR window. >=20 > This patch creates an emulated device which helps to test and debug the > kernel driver for iopmem while hardware availability is poor. A kernel > patch for a driver is being prepared simultaneously. >=20 > Signed-off-by: Logan Gunthorpe > Signed-off-by: Stephen Bates QEMU already has NVDIMM support (https://pmem.io/). It can be used both for passthrough and fake non-volatile memory: qemu-system-x86_64 \ -M pc,nvdimm=3Don \ -m 1024,maxmem=3D$((4096 * 1024 * 1024)),slots=3D2 \ -object memory-backend-file,id=3Dmem0,mem-path=3D/tmp/foo,size=3D$((64 = * 1024 * 1024)) \ -device nvdimm,memdev=3Dmem0 Please explain where iopmem comes from, where the hardware spec is, etc? Perhaps you could use nvdimm instead of adding a new device? > --- > default-configs/pci.mak | 1 + > hw/block/Makefile.objs | 1 + > hw/block/iopmem.c | 141 +++++++++++++++++++++++++++++++++++++++++= ++++++ > include/hw/pci/pci_ids.h | 2 + > 4 files changed, 145 insertions(+) > create mode 100644 hw/block/iopmem.c >=20 > diff --git a/default-configs/pci.mak b/default-configs/pci.mak > index fff7ce3..aef2b35 100644 > --- a/default-configs/pci.mak > +++ b/default-configs/pci.mak > @@ -39,3 +39,4 @@ CONFIG_VGA=3Dy > CONFIG_VGA_PCI=3Dy > CONFIG_IVSHMEM=3D$(CONFIG_EVENTFD) > CONFIG_ROCKER=3Dy > +CONFIG_IOPMEM_PCI=3Dy > diff --git a/hw/block/Makefile.objs b/hw/block/Makefile.objs > index d4c3ab7..1c8044b 100644 > --- a/hw/block/Makefile.objs > +++ b/hw/block/Makefile.objs > @@ -8,6 +8,7 @@ common-obj-$(CONFIG_XEN_BACKEND) +=3D xen_disk.o > common-obj-$(CONFIG_ECC) +=3D ecc.o > common-obj-$(CONFIG_ONENAND) +=3D onenand.o > common-obj-$(CONFIG_NVME_PCI) +=3D nvme.o > +common-obj-$(CONFIG_IOPMEM_PCI) +=3D iopmem.o > =20 > obj-$(CONFIG_SH4) +=3D tc58128.o > =20 > diff --git a/hw/block/iopmem.c b/hw/block/iopmem.c > new file mode 100644 > index 0000000..9c2d716 > --- /dev/null > +++ b/hw/block/iopmem.c > @@ -0,0 +1,141 @@ > +/* > + * QEMU iopmem Controller > + * > + * Copyright (c) 2016, Microsemi Corporation > + * > + * Written by Logan Gunthorpe > + * > + * This code is licensed under the GNU GPL v2 or later. > + */ > + > + > +/** > + * Usage: add options: > + * -drive file=3D,if=3Dnone,id=3D > + * -device iopmem,drive=3D,id=3D > + */ > + > +#include "qemu/osdep.h" > +#include "hw/pci/pci.h" > +#include "sysemu/block-backend.h" > + > +typedef struct IoPmemCtrl { > + PCIDevice parent_obj; > + MemoryRegion iomem; > + BlockBackend *blk; > + uint64_t size; > +} IoPmemCtrl; > + > +#define TYPE_IOPMEM "iopmem" > +#define IOPMEM(obj) \ > + OBJECT_CHECK(IoPmemCtrl, (obj), TYPE_IOPMEM) > + > +static uint64_t iopmem_bar_read(void *opaque, hwaddr addr, unsigned size) > +{ > + IoPmemCtrl *ipm =3D (IoPmemCtrl *)opaque; > + uint64_t val; > + > + blk_pread(ipm->blk, addr, &val, size); > + > + return val; > +} > + > +static void iopmem_bar_write(void *opaque, hwaddr addr, uint64_t data, > + unsigned size) > +{ > + IoPmemCtrl *ipm =3D (IoPmemCtrl *)opaque; > + > + if (addr & 3) { > + return; > + } > + > + blk_pwrite(ipm->blk, addr, &data, size, 0); > +} This has terrible performance because blk_pread()/blk_pwrite() are synchronous operations. The vcpu thread is paused while QEMU is waiting for I/O. --mJm6k4Vb/yFcL9ZU Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAEBAgAGBQJYHGexAAoJEJykq7OBq3PISRAIAMQeTZdymC7NEgeQNoL3BgV2 9toCXtsCRr1mCfl8lh2T7nn+a4qb45sjf1FhcGl6MA4kX612naU3jLV+D2P5y5QG M3JU06BAQpptYaqf7xz7CHe0p3Ba+ksPi4ZBko0YSy+rNjrKIvLD8e5rK1XvtHbF MaPQDo21c7r0D3rwT+INXCMbg5jnP3C/roGKwxyyOJDxUGAQzY6KxOkAzH/iwBYh +B8HdqCkJ+8vynRRKOAsI7aTm1Gg1x4Tu8rT8TcQK+23sRud0+ha9pooZ4Rq0hK8 L+KQUzmxP1rV/6jld3+P4k+a9b+IIvu7TpC+kxr71DM2+DtWOSBls5+0KyUkxiY= =FGwC -----END PGP SIGNATURE----- --mJm6k4Vb/yFcL9ZU--