Skip to contentSkip to conversation

xen-140507

GIT PULL Stefano Stabellini 3 participants 15 messages May 7, 2014 Kbuild

lore
Share & tools
lore
#0 lore raw

The following changes since commit 951916d02c59cd0eddd57c3d66f87f921931e394:

Merge remote-tracking branch 'remotes/kraxel/tags/pull-usb-6' into staging (2014-05-06 13:06:32 +0100)

are available in the git repository at:

git://xenbits.xen.org/people/sstabellini/qemu-dm.git xen-140507

for you to fetch changes up to 6a16be0810eccd3aede1ef592c3c1b64430b3280:

xen_disk: add discard support (2014-05-07 14:56:54 +0000)

----------------------------------------------------------------
Alexey Kardashevskiy (1):
exec: Limit translation limiting in address_space_translate to xen

Olaf Hering (1):
xen_disk: add discard support

Stefano Stabellini (1):
pass an inclusive address range to xc_domain_pin_memory_cacheattr

Wei Liu (3):
xen: move Xen PV machine files to hw/xenpv
xen: move Xen HVM files under hw/i386/xen
xen: factor out common functions

Zhenzhong Duan (1):
qemu-xen: free all the pirqs for msi/msix when driver unload

 Makefile.target                      |    6 +-
 exec.c                               |    2 +-
 hw/block/xen_blkif.h                 |   12 ++++
 hw/block/xen_disk.c                  |   33 +++++++++
 hw/i386/Makefile.objs                |    2 +-
 hw/i386/xen/Makefile.objs            |    1 +
 hw/{ => i386}/xen/xen_apic.c         |    0
 hw/{ => i386}/xen/xen_platform.c     |    0
 hw/{ => i386}/xen/xen_pvdevice.c     |    0
 hw/xen/Makefile.objs                 |    1 -
 hw/xen/xen_pt_config_init.c          |    6 +-
 hw/xen/xen_pt_msi.c                  |    6 +-
 hw/xenpv/Makefile.objs               |    2 +
 hw/{i386 => xenpv}/xen_domainbuild.c |    0
 hw/{i386 => xenpv}/xen_domainbuild.h |    0
 hw/{i386 => xenpv}/xen_machine_pv.c  |    0
 include/hw/xen/xen_common.h          |    7 ++
 xen-common-stub.c                    |   19 ++++++
 xen-common.c                         |  123 ++++++++++++++++++++++++++++++++++
 xen-stub.c => xen-hvm-stub.c         |   17 ++---
 xen-all.c => xen-hvm.c               |  123 ++++------------------------------
 21 files changed, 227 insertions(+), 133 deletions(-)
 create mode 100644 hw/i386/xen/Makefile.objs
 rename hw/{ => i386}/xen/xen_apic.c (100%)
 rename hw/{ => i386}/xen/xen_platform.c (100%)
 rename hw/{ => i386}/xen/xen_pvdevice.c (100%)
 create mode 100644 hw/xenpv/Makefile.objs
 rename hw/{i386 => xenpv}/xen_domainbuild.c (100%)
 rename hw/{i386 => xenpv}/xen_domainbuild.h (100%)
 rename hw/{i386 => xenpv}/xen_machine_pv.c (100%)
 create mode 100644 xen-common-stub.c
 create mode 100644 xen-common.c
 rename xen-stub.c => xen-hvm-stub.c (89%)
 rename xen-all.c => xen-hvm.c (92%)
#1 lore raw

[Qemu-devel] [PULL 1/7] exec: Limit translation limiting in address_space_translate to xen

From: Alexey Kardashevskiy <[email protected]>

The address_space_translate() function cuts the returned plen (page size) to hardcoded TARGET_PAGE_SIZE. This function can be used on pages bigger than that so this limiting should not be used on such pages.

Since originally the limiting was introduced for XEN, we can safely limit this piece of code to XEN. So does the patch.

---
 exec.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
exec.c +1 -1
index 91513c6..cf12049 100644
@@ -380,7 +380,7 @@ MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr,
         as = iotlb.target_as;
     }
 
-    if (memory_access_is_direct(mr, is_write)) {
+    if (xen_enabled() && memory_access_is_direct(mr, is_write)) {
         hwaddr page = ((addr & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE) - addr;
         len = MIN(page, len);
     }
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [Qemu-devel] [PULL 1/7] exec: Limit translation limiting in address_space_translate to xen

Quoted 21 lines · Stefano Stabellini

From: Alexey Kardashevskiy <[email protected]>

The address_space_translate() function cuts the returned plen (page size) to hardcoded TARGET_PAGE_SIZE. This function can be used on pages bigger than that so this limiting should not be used on such pages.

Since originally the limiting was introduced for XEN, we can safely limit this piece of code to XEN. So does the patch.

---
 exec.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
exec.c +0 -0
index 91513c6..cf12049 100644

exec.c MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr, · line 386

Quoted 8 lines
exec.c +1 -1
@@ -380,7 +380,7 @@ MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr,
         as = iotlb.target_as;
     }
 
-    if (memory_access_is_direct(mr, is_write)) {
+    if (xen_enabled() && memory_access_is_direct(mr, is_write)) {
         hwaddr page = ((addr & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE) - addr;
         len = MIN(page, len);
     }

We should put this patch in (both as an efficiency thing and an expedient fix) but we really need to either track down which callers of this API are relying on the returned plen not being truncated, or we need to fix Xen to not truncate either. This is just a bandaid IMHO.

thanks
-- PMM

#3 lore raw

Re: [Qemu-devel] [PULL 1/7] exec: Limit translation limiting in address_space_translate to xen

Il 07/05/2014 17:12, Peter Maydell ha scritto:

Quoted 10 lines
Quoted 5 lines

exec.c MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr, · line 386

Quoted 5 lines
exec.c +1 -1
-    if (memory_access_is_direct(mr, is_write)) {
+    if (xen_enabled() && memory_access_is_direct(mr, is_write)) {
         hwaddr page = ((addr & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE) - addr;
         len = MIN(page, len);
     }

We should put this patch in (both as an efficiency thing and an expedient fix) but we really need to either track down which callers of this API are relying on the returned plen not being truncated, or we need to fix Xen to not truncate either. This is just a bandaid IMHO.

Fixing Xen to not truncate is not possible because of the Xen mapcache, unless of course QEMU is changed to avoid the mapcache completely on 64-bit hosts. I'm not sure if that makes sense from the Xen point of view.

Regarding fixing callers, a known one is virtio-scsi which is a bug and on my todo list. But another is VFIO, which cannot accept truncation if the IOMMU page size is greater than TARGET_PAGE_SIZE.

Paolo

#4 lore raw

Re: [Qemu-devel] [PULL 1/7] exec: Limit translation limiting in address_space_translate to xen

Quoted 13 lines · Paolo Bonzini

Il 07/05/2014 17:12, Peter Maydell ha scritto:

Quoted 11 lines
Quoted 6 lines

exec.c MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr,

Quoted 3 lines
exec.c +1 -1
-    if (memory_access_is_direct(mr, is_write)) {
+    if (xen_enabled() && memory_access_is_direct(mr, is_write)) {
         hwaddr page = ((addr & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE) -

addr;

Quoted 2 lines
         len = MIN(page, len);
     }

We should put this patch in (both as an efficiency thing and an expedient fix) but we really need to either track down which callers of this API are relying on the returned plen not being truncated, or we need to fix Xen to not truncate either. This is just a bandaid IMHO.

Quoted 3 lines

Fixing Xen to not truncate is not possible because of the Xen mapcache, unless of course QEMU is changed to avoid the mapcache completely on 64-bit hosts. I'm not sure if that makes sense from the Xen point of view.

Right, it makes sense, however we would still need to keep the 32-bit mapcache code path working.

Quoted 3 lines

Regarding fixing callers, a known one is virtio-scsi which is a bug and on my todo list. But another is VFIO, which cannot accept truncation if the IOMMU page size is greater than TARGET_PAGE_SIZE.

#5 lore raw

Re: [Qemu-devel] [PULL 1/7] exec: Limit translation limiting in address_space_translate to xen

In reply to Paolo Bonzini
Quoted 7 lines · Paolo Bonzini

Fixing Xen to not truncate is not possible because of the Xen mapcache, unless of course QEMU is changed to avoid the mapcache completely on 64-bit hosts. I'm not sure if that makes sense from the Xen point of view.

Regarding fixing callers, a known one is virtio-scsi which is a bug and on my todo list. But another is VFIO, which cannot accept truncation if the IOMMU page size is greater than TARGET_PAGE_SIZE.

The API can't simultaneously allow the implementation to truncate and guarantee to the caller that we don't truncate, so one of these has to change, surely?

Otherwise we would need to provide some sort of flag for truncation-unacceptable so that incompatible combinations fail nicely rather than silently doing weird stuff, I guess.

thanks
-- PMM

#6 lore raw

Re: [Qemu-devel] [PULL 1/7] exec: Limit translation limiting in address_space_translate to xen

Il 07/05/2014 17:32, Peter Maydell ha scritto:

Quoted 7 lines
Quoted 3 lines

Regarding fixing callers, a known one is virtio-scsi which is a bug and on my todo list. But another is VFIO, which cannot accept truncation if the IOMMU page size is greater than TARGET_PAGE_SIZE.

The API can't simultaneously allow the implementation to truncate and guarantee to the caller that we don't truncate, so one of these has to change, surely?

We can provide a function to return the truncation granularity, and add to VFIO a check that will prevent using VFIO together with Xen.

Paolo

#7 lore raw

[Qemu-devel] [PULL 2/7] qemu-xen: free all the pirqs for msi/msix when driver unload

In reply to Stefano Stabellini

From: Zhenzhong Duan <[email protected]>

Pirqs are not freed when driver unload, then new pirqs are allocated when driver reload. This could exhaust pirqs if do it in a loop.

This patch fixes the bug by freeing pirqs when ENABLE bit is cleared in msi/msix control reg.

There is also other way of fixing it such as reuse pirqs between driver reload, but this way is better.
Xen-devel: http://marc.info/?l=xen-devel&m=136800120304275&w=2

---
 hw/xen/xen_pt_config_init.c |    6 ++++--
 hw/xen/xen_pt_msi.c         |    6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)
hw/xen/xen_pt_config_init.c +4 -2
index 8ccc2e4..de9a20f 100644
@@ -1123,8 +1123,8 @@ static int xen_pt_msgctrl_reg_write(XenPCIPassthroughState *s,
             msi->mapped = true;
         }
         msi->flags |= PCI_MSI_FLAGS_ENABLE;
-    } else {
-        msi->flags &= ~PCI_MSI_FLAGS_ENABLE;
+    } else if (msi->mapped) {
+        xen_pt_msi_disable(s);
     }
 
     /* pass through MSI_ENABLE bit */
@@ -1397,6 +1397,8 @@ static int xen_pt_msixctrl_reg_write(XenPCIPassthroughState *s,
     if ((*val & PCI_MSIX_FLAGS_ENABLE)
         && !(*val & PCI_MSIX_FLAGS_MASKALL)) {
         xen_pt_msix_update(s);
+    } else if (!(*val & PCI_MSIX_FLAGS_ENABLE) && s->msix->enabled) {
+        xen_pt_msix_disable(s);
     }
 
     debug_msix_enabled_old = s->msix->enabled;
hw/xen/xen_pt_msi.c +4 -2
index 6fbe0cc..12b4c45 100644
@@ -282,7 +282,8 @@ void xen_pt_msi_disable(XenPCIPassthroughState *s)
                      msi->initialized);
 
     /* clear msi info */
-    msi->flags = 0;
+    msi->flags &= ~PCI_MSI_FLAGS_ENABLE;
+    msi->initialized = false;
     msi->mapped = false;
     msi->pirq = XEN_PT_UNASSIGNED_PIRQ;
 }
@@ -446,7 +447,8 @@ static void pci_msix_write(void *opaque, hwaddr addr,
     if (offset != PCI_MSIX_ENTRY_VECTOR_CTRL) {
         const volatile uint32_t *vec_ctrl;
 
-        if (get_entry_value(entry, offset) == val) {
+        if (get_entry_value(entry, offset) == val
+            && entry->pirq != XEN_PT_UNASSIGNED_PIRQ) {
             return;
         }
 
Signature · 1 line
1.7.10.4
#8 lore raw

[Qemu-devel] [PULL 3/7] xen: move Xen PV machine files to hw/xenpv

In reply to Stefano Stabellini

From: Wei Liu <[email protected]>

---
 hw/i386/Makefile.objs      |    2 +-
 hw/i386/xen_domainbuild.c  |  299 --------------------------------------------
 hw/i386/xen_domainbuild.h  |   13 --
 hw/i386/xen_machine_pv.c   |  109 ----------------
 hw/xenpv/Makefile.objs     |    2 +
 hw/xenpv/xen_domainbuild.c |  299 ++++++++++++++++++++++++++++++++++++++++++++
 hw/xenpv/xen_domainbuild.h |   13 ++
 hw/xenpv/xen_machine_pv.c  |  109 ++++++++++++++++
 8 files changed, 424 insertions(+), 422 deletions(-)
 delete mode 100644 hw/i386/xen_domainbuild.c
 delete mode 100644 hw/i386/xen_domainbuild.h
 delete mode 100644 hw/i386/xen_machine_pv.c
 create mode 100644 hw/xenpv/Makefile.objs
 create mode 100644 hw/xenpv/xen_domainbuild.c
 create mode 100644 hw/xenpv/xen_domainbuild.h
 create mode 100644 hw/xenpv/xen_machine_pv.c
hw/i386/Makefile.objs +1 -1
index 3df1612..f9899a3 100644
@@ -2,7 +2,7 @@ obj-$(CONFIG_KVM) += kvm/
 obj-y += multiboot.o smbios.o
 obj-y += pc.o pc_piix.o pc_q35.o
 obj-y += pc_sysfw.o
-obj-$(CONFIG_XEN) += xen_domainbuild.o xen_machine_pv.o
+obj-$(CONFIG_XEN) += ../xenpv/
 
 obj-y += kvmvapic.o
 obj-y += acpi-build.o
hw/i386/xen_domainbuild.c deleted +0 -299

299 lines not on this page · raw message

hw/i386/xen_domainbuild.h deleted +0 -13
deleted file mode 100644
index 29a91ea..0000000
@@ -1,13 +0,0 @@
-#ifndef QEMU_HW_XEN_DOMAINBUILD_H
-#define QEMU_HW_XEN_DOMAINBUILD_H 1
-
-#include "hw/xen/xen_common.h"
-
-int xenstore_domain_init1(const char *kernel, const char *ramdisk,
-                          const char *cmdline);
-int xenstore_domain_init2(int xenstore_port, int xenstore_mfn,
-                          int console_port, int console_mfn);
-int xen_domain_build_pv(const char *kernel, const char *ramdisk,
-                        const char *cmdline);
-
-#endif /* QEMU_HW_XEN_DOMAINBUILD_H */
hw/i386/xen_machine_pv.c deleted +0 -109

109 lines not on this page · raw message

hw/xenpv/Makefile.objs new file +2 -0
new file mode 100644
index 0000000..49f6e9e
@@ -0,0 +1,2 @@
+# Xen PV machine support
+obj-$(CONFIG_XEN) += xen_domainbuild.o xen_machine_pv.o
hw/xenpv/xen_domainbuild.c new file +299 -0

299 lines not on this page · raw message

hw/xenpv/xen_domainbuild.h new file +13 -0
new file mode 100644
index 0000000..29a91ea
@@ -0,0 +1,13 @@
+#ifndef QEMU_HW_XEN_DOMAINBUILD_H
+#define QEMU_HW_XEN_DOMAINBUILD_H 1
+
+#include "hw/xen/xen_common.h"
+
+int xenstore_domain_init1(const char *kernel, const char *ramdisk,
+                          const char *cmdline);
+int xenstore_domain_init2(int xenstore_port, int xenstore_mfn,
+                          int console_port, int console_mfn);
+int xen_domain_build_pv(const char *kernel, const char *ramdisk,
+                        const char *cmdline);
+
+#endif /* QEMU_HW_XEN_DOMAINBUILD_H */
hw/xenpv/xen_machine_pv.c new file +109 -0

109 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#9 lore raw

[Qemu-devel] [PULL 4/7] xen: move Xen HVM files under hw/i386/xen

In reply to Stefano Stabellini

From: Wei Liu <[email protected]>

---
 hw/i386/Makefile.objs      |    2 +-
 hw/i386/xen/Makefile.objs  |    1 +
 hw/i386/xen/xen_apic.c     |   97 ++++++++++
 hw/i386/xen/xen_platform.c |  450 ++++++++++++++++++++++++++++++++++++++++++++
 hw/i386/xen/xen_pvdevice.c |  135 +++++++++++++
 hw/xen/Makefile.objs       |    1 -
 hw/xen/xen_apic.c          |   97 ----------
 hw/xen/xen_platform.c      |  450 --------------------------------------------
 hw/xen/xen_pvdevice.c      |  135 -------------
 9 files changed, 684 insertions(+), 684 deletions(-)
 create mode 100644 hw/i386/xen/Makefile.objs
 create mode 100644 hw/i386/xen/xen_apic.c
 create mode 100644 hw/i386/xen/xen_platform.c
 create mode 100644 hw/i386/xen/xen_pvdevice.c
 delete mode 100644 hw/xen/xen_apic.c
 delete mode 100644 hw/xen/xen_platform.c
 delete mode 100644 hw/xen/xen_pvdevice.c
hw/i386/Makefile.objs +1 -1
index f9899a3..f66c349 100644
@@ -2,7 +2,7 @@ obj-$(CONFIG_KVM) += kvm/
 obj-y += multiboot.o smbios.o
 obj-y += pc.o pc_piix.o pc_q35.o
 obj-y += pc_sysfw.o
-obj-$(CONFIG_XEN) += ../xenpv/
+obj-$(CONFIG_XEN) += ../xenpv/ xen/
 
 obj-y += kvmvapic.o
 obj-y += acpi-build.o
hw/i386/xen/Makefile.objs new file +1 -0
new file mode 100644
index 0000000..801a68d
@@ -0,0 +1 @@
+obj-y += xen_platform.o xen_apic.o xen_pvdevice.o
hw/i386/xen/xen_apic.c new file +97 -0

97 lines not on this page · raw message

hw/i386/xen/xen_platform.c new file +450 -0

450 lines not on this page · raw message

hw/i386/xen/xen_pvdevice.c new file +135 -0

135 lines not on this page · raw message

hw/xen/Makefile.objs +0 -1
index ce640c6..a0ca0aa 100644
@@ -1,6 +1,5 @@
 # xen backend driver support
 common-obj-$(CONFIG_XEN_BACKEND) += xen_backend.o xen_devconfig.o
 
-obj-$(CONFIG_XEN_I386) += xen_platform.o xen_apic.o xen_pvdevice.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_msi.o
hw/xen/xen_apic.c deleted +0 -97

97 lines not on this page · raw message

hw/xen/xen_platform.c deleted +0 -450

450 lines not on this page · raw message

hw/xen/xen_pvdevice.c deleted +0 -135

135 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#10 lore raw

[Qemu-devel] [PULL 5/7] xen: factor out common functions

In reply to Stefano Stabellini

From: Wei Liu <[email protected]>

So common functions used by both HVM and PV are factored out from xen-all.c to xen-common.c.

Finally rename xen-all.c to xen-hvm.c, as those functions are only useful to HVM guest.

Create *-stub files and modify Makefile.target to reflect the changes.

---
 Makefile.target   |    6 +-
 xen-all.c         | 1228 -----------------------------------------------------
 xen-common-stub.c |   19 +
 xen-common.c      |  123 ++++++
 xen-hvm-stub.c    |   61 +++
 xen-hvm.c         | 1129 ++++++++++++++++++++++++++++++++++++++++++++++++
 xen-stub.c        |   70 ---
 7 files changed, 1336 insertions(+), 1300 deletions(-)
 delete mode 100644 xen-all.c
 create mode 100644 xen-common-stub.c
 create mode 100644 xen-common.c
 create mode 100644 xen-hvm-stub.c
 create mode 100644 xen-hvm.c
 delete mode 100644 xen-stub.c
Makefile.target +4 -2
index ba12340..6d8fde8 100644
@@ -120,8 +120,10 @@ obj-y += dump.o
 LIBS+=$(libs_softmmu)
 
 # xen support
-obj-$(CONFIG_XEN) += xen-all.o xen-mapcache.o
-obj-$(call lnot,$(CONFIG_XEN)) += xen-stub.o
+obj-$(CONFIG_XEN) += xen-common.o
+obj-$(CONFIG_XEN_I386) += xen-hvm.o xen-mapcache.o
+obj-$(call lnot,$(CONFIG_XEN)) += xen-common-stub.o
+obj-$(call lnot,$(CONFIG_XEN_I386)) += xen-hvm-stub.o
 
 # Hardware support
 ifeq ($(TARGET_NAME), sparc64)
xen-all.c deleted +0 -1228

1,228 lines not on this page · raw message

xen-common-stub.c new file +19 -0
new file mode 100644
index 0000000..0bba290
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2014       Citrix Systems UK Ltd.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu-common.h"
+#include "hw/xen/xen.h"
+
+void xenstore_store_pv_console_info(int i, CharDriverState *chr)
+{
+}
+
+int xen_init(QEMUMachine *machine)
+{
+    return -ENOSYS;
+}
+
xen-common.c new file +123 -0

123 lines not on this page · raw message

xen-hvm-stub.c new file +61 -0

61 lines not on this page · raw message

xen-hvm.c new file +1129 -0

1,129 lines not on this page · raw message

xen-stub.c deleted +0 -70

70 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#11 lore raw

[Qemu-devel] [PULL 6/7] pass an inclusive address range to xc_domain_pin_memory_cacheattr

In reply to Stefano Stabellini

xc_domain_pin_memory_cacheattr expects an inclusive address range:
adjust the parameters.

---
 xen-hvm.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen-hvm.c +1 -1
index 0a49055..a64486c 100644
@@ -323,7 +323,7 @@ go_physmap:
 
     xc_domain_pin_memory_cacheattr(xen_xc, xen_domid,
                                    start_addr >> TARGET_PAGE_BITS,
-                                   (start_addr + size) >> TARGET_PAGE_BITS,
+                                   (start_addr + size - 1) >> TARGET_PAGE_BITS,
                                    XEN_DOMCTL_MEM_CACHEATTR_WB);
 
     snprintf(path, sizeof(path),
Signature · 1 line
1.7.10.4
#12 lore raw

[Qemu-devel] [PULL 7/7] xen_disk: add discard support

In reply to Stefano Stabellini

From: Olaf Hering <[email protected]>

Implement discard support for xen_disk. It makes use of the existing discard code in qemu.

The discard support is enabled unconditionally. The tool stack may provide a property "discard-enable" in the backend node to optionally disable discard support. This is helpful in case the backing file was intentionally created non-sparse to avoid fragmentation.

---
 hw/block/xen_blkif.h        |   12 ++++++++++++
 hw/block/xen_disk.c         |   33 +++++++++++++++++++++++++++++++++
 include/hw/xen/xen_common.h |    7 +++++++
 3 files changed, 52 insertions(+)
hw/block/xen_blkif.h +12 -0
index c0f4136..711b692 100644
@@ -79,6 +79,12 @@ static inline void blkif_get_x86_32_req(blkif_request_t *dst, blkif_x86_32_reque
 	dst->handle = src->handle;
 	dst->id = src->id;
 	dst->sector_number = src->sector_number;
+	if (src->operation == BLKIF_OP_DISCARD) {
+		struct blkif_request_discard *s = (void *)src;
+		struct blkif_request_discard *d = (void *)dst;
+		d->nr_sectors = s->nr_sectors;
+		return;
+	}
 	if (n > src->nr_segments)
 		n = src->nr_segments;
 	for (i = 0; i < n; i++)
@@ -94,6 +100,12 @@ static inline void blkif_get_x86_64_req(blkif_request_t *dst, blkif_x86_64_reque
 	dst->handle = src->handle;
 	dst->id = src->id;
 	dst->sector_number = src->sector_number;
+	if (src->operation == BLKIF_OP_DISCARD) {
+		struct blkif_request_discard *s = (void *)src;
+		struct blkif_request_discard *d = (void *)dst;
+		d->nr_sectors = s->nr_sectors;
+		return;
+	}
 	if (n > src->nr_segments)
 		n = src->nr_segments;
 	for (i = 0; i < n; i++)
hw/block/xen_disk.c +33 -0
index a8fea72..aed5b5b 100644
@@ -114,6 +114,7 @@ struct XenBlkDev {
     int                 requests_finished;
 
     /* Persistent grants extension */
+    gboolean            feature_discard;
     gboolean            feature_persistent;
     GTree               *persistent_gnts;
     unsigned int        persistent_gnt_count;
@@ -253,6 +254,8 @@ static int ioreq_parse(struct ioreq *ioreq)
     case BLKIF_OP_WRITE:
         ioreq->prot = PROT_READ; /* from memory */
         break;
+    case BLKIF_OP_DISCARD:
+        return 0;
     default:
         xen_be_printf(&blkdev->xendev, 0, "error: unknown operation (%d)\n",
                       ioreq->req.operation);
@@ -492,6 +495,7 @@ static void qemu_aio_complete(void *opaque, int ret)
     case BLKIF_OP_READ:
         bdrv_acct_done(ioreq->blkdev->bs, &ioreq->acct);
         break;
+    case BLKIF_OP_DISCARD:
     default:
         break;
     }
@@ -532,6 +536,15 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq)
                         &ioreq->v, ioreq->v.size / BLOCK_SIZE,
                         qemu_aio_complete, ioreq);
         break;
+    case BLKIF_OP_DISCARD:
+    {
+        struct blkif_request_discard *discard_req = (void *)&ioreq->req;
+        ioreq->aio_inflight++;
+        bdrv_aio_discard(blkdev->bs,
+                        discard_req->sector_number, discard_req->nr_sectors,
+                        qemu_aio_complete, ioreq);
+        break;
+    }
     default:
         /* unknown operation (shouldn't happen -- parse catches this) */
         goto err;
@@ -710,6 +723,21 @@ static void blk_alloc(struct XenDevice *xendev)
     }
 }
 
+static void blk_parse_discard(struct XenBlkDev *blkdev)
+{
+    int enable;
+
+    blkdev->feature_discard = true;
+
+    if (xenstore_read_be_int(&blkdev->xendev, "discard-enable", &enable) == 0) {
+        blkdev->feature_discard = !!enable;
+    }
+
+    if (blkdev->feature_discard) {
+        xenstore_write_be_int(&blkdev->xendev, "feature-discard", 1);
+    }
+}
+
 static int blk_init(struct XenDevice *xendev)
 {
     struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
@@ -777,6 +805,8 @@ static int blk_init(struct XenDevice *xendev)
     xenstore_write_be_int(&blkdev->xendev, "feature-persistent", 1);
     xenstore_write_be_int(&blkdev->xendev, "info", info);
 
+    blk_parse_discard(blkdev);
+
     g_free(directiosafe);
     return 0;
 
@@ -812,6 +842,9 @@ static int blk_connect(struct XenDevice *xendev)
         qflags |= BDRV_O_RDWR;
         readonly = false;
     }
+    if (blkdev->feature_discard) {
+        qflags |= BDRV_O_UNMAP;
+    }
 
     /* init qemu block driver */
     index = (blkdev->xendev.dev - 202 * 256) / 16;
include/hw/xen/xen_common.h +7 -0
index 2d5a25b..07731b9 100644
@@ -144,6 +144,13 @@ static inline int xen_xc_hvm_inject_msi(XenXC xen_xc, domid_t dom,
 {
     return -ENOSYS;
 }
+/* The followings are only to compile op_discard related code on older
+ * Xen releases. */
+#define BLKIF_OP_DISCARD 5
+struct blkif_request_discard {
+    uint64_t nr_sectors;
+    uint64_t sector_number;
+};
 #else
 static inline int xen_xc_hvm_inject_msi(XenXC xen_xc, domid_t dom,
         uint64_t addr, uint32_t data)
Signature · 1 line
1.7.10.4
#13 lore raw
In reply to Stefano Stabellini
Quoted 4 lines · Stefano Stabellini

The following changes since commit 951916d02c59cd0eddd57c3d66f87f921931e394:

Merge remote-tracking branch 'remotes/kraxel/tags/pull-usb-6' into staging (2014-05-06 13:06:32 +0100)

Quoted 8 lines

are available in the git repository at:

git://xenbits.xen.org/people/sstabellini/qemu-dm.git xen-140507

for you to fetch changes up to 6a16be0810eccd3aede1ef592c3c1b64430b3280:

xen_disk: add discard support (2014-05-07 14:56:54 +0000)

Hi; I'm afraid I get merge conflicts when I pull this:

Quoted 1 line

From git://xenbits.xen.org/people/sstabellini/qemu-dm

* [new branch] xen-140507 -> sstabellini/xen-140507
merging...
Auto-merging xen-hvm.c
CONFLICT (content): Merge conflict in xen-hvm.c Auto-merging xen-hvm-stub.c
CONFLICT (content): Merge conflict in xen-hvm-stub.c Automatic merge failed; fix conflicts and then commit the result.

It looks like they're pretty trivial, but since this pull involves file renames and I have no way to test Xen, I'd appreciate it if you could reroll the pull request.

thanks
-- PMM

#14 lore raw
Quoted 25 lines · Peter Maydell
Quoted 4 lines · Stefano Stabellini

The following changes since commit 951916d02c59cd0eddd57c3d66f87f921931e394:

Merge remote-tracking branch 'remotes/kraxel/tags/pull-usb-6' into staging (2014-05-06 13:06:32 +0100)

Quoted 8 lines

are available in the git repository at:

git://xenbits.xen.org/people/sstabellini/qemu-dm.git xen-140507

for you to fetch changes up to 6a16be0810eccd3aede1ef592c3c1b64430b3280:

xen_disk: add discard support (2014-05-07 14:56:54 +0000)

Hi; I'm afraid I get merge conflicts when I pull this:

Quoted 1 line

From git://xenbits.xen.org/people/sstabellini/qemu-dm

* [new branch] xen-140507 -> sstabellini/xen-140507
merging...
Auto-merging xen-hvm.c
CONFLICT (content): Merge conflict in xen-hvm.c Auto-merging xen-hvm-stub.c
CONFLICT (content): Merge conflict in xen-hvm-stub.c Automatic merge failed; fix conflicts and then commit the result.

Quoted 3 lines

It looks like they're pretty trivial, but since this pull involves file renames and I have no way to test Xen, I'd appreciate it if you could reroll the pull request.

Sure