Virtio support for toolstack on Arm (Was "IOREQ feature (+ virtio-mmio) on Arm")
v7 cover Virtio support for toolstack on Arm (Was "IOREQ feature (+ virtio-mmio) on Arm")
From: Oleksandr Tyshchenko <[email protected]>
Hello all.
The purpose of this patch series is to add missing virtio-mmio bits to Xen toolstack on Arm. The Virtio support for toolstack [1] was postponed as the main target was to upstream IOREQ/DM support on Arm in the first place. Now, we already have IOREQ support in, so we can resume Virtio enabling work. You can find previous discussions at [2].
Patch series [3] is based on recent "staging" branch (9120b5737f517fe9d2a3936c38d3a2211630323b livepatch: avoid relocations referencing ignored section symbols) and tested on Renesas Salvator-X board + H3 ES3.0 SoC (Arm64) with virtio-mmio based virtio-disk backend [4] running in Dom0 (or Driver domain) and unmodified Linux Guest running on existing virtio-blk driver (frontend). No issues were observed. Guest domain 'reboot/destroy' use-cases work properly.
Any feedback/help would be highly appreciated.
[1]
https://lore.kernel.org/xen-devel/[email protected]/
https://lore.kernel.org/xen-devel/[email protected]/
[2]
https://lists.xenproject.org/archives/html/xen-devel/2021-01/msg02403.html
https://lists.xenproject.org/archives/html/xen-devel/2021-01/msg02536.html
https://lore.kernel.org/xen-devel/[email protected]/
https://lore.kernel.org/xen-devel/[email protected]/
[3] https://github.com/otyshchenko1/xen/commits/libxl_virtio2
[4] https://github.com/otyshchenko1/virtio-disk/commits/virtio_grant
Julien Grall (1):
libxl: Introduce basic virtio-mmio support on Arm
Oleksandr Tyshchenko (1):
libxl: Add support for Virtio disk configuration
docs/man/xl-disk-configuration.5.pod.in | 37 +- tools/golang/xenlight/helpers.gen.go | 6 + tools/golang/xenlight/types.gen.go | 11 + tools/include/libxl.h | 6 + tools/libs/light/libxl_arm.c | 131 +++- tools/libs/light/libxl_device.c | 57 +- tools/libs/light/libxl_disk.c | 111 +++- tools/libs/light/libxl_internal.h | 1 + tools/libs/light/libxl_types.idl | 10 + tools/libs/light/libxl_types_internal.idl | 1 + tools/libs/light/libxl_utils.c | 2 + tools/libs/util/libxlu_disk_l.c | 952 +++++++++++++++--------------- tools/libs/util/libxlu_disk_l.h | 2 +- tools/libs/util/libxlu_disk_l.l | 9 + tools/xl/xl_block.c | 11 + xen/include/public/arch-arm.h | 7 + 16 files changed, 872 insertions(+), 482 deletions(-)
Signature · 1 line
2.7.4
PATCH v7 2/2 libxl: Introduce basic virtio-mmio support on Arm
From: Julien Grall <[email protected]>
This patch introduces helpers to allocate Virtio MMIO params (IRQ and memory region) and create specific device node in the Guest device-tree with allocated params. In order to deal with multiple Virtio devices, reserve corresponding ranges. For now, we reserve 1MB for memory regions and 10 SPIs.
As these helpers should be used for every Virtio device attached to the Guest, call them for Virtio disk(s).
Please note, with statically allocated Virtio IRQs there is a risk of a clash with a physical IRQs of passthrough devices. For the first version, it's fine, but we should consider allocating the Virtio IRQs automatically. Thankfully, we know in advance which IRQs will be used for passthrough to be able to choose non-clashed ones.
---
@Jiamei, @Henry I decided to leave your T-b and R-b tags with the minor change I made, are you still happy with that?
s/if (disk->virtio)/if (disk->protocol == LIBXL_DISK_PROTOCOL_VIRTIO_MMIO)
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"
Changes RFC -> V1:
- was squashed with:
"[RFC PATCH V1 09/12] libxl: Handle virtio-mmio irq in more correct way" "[RFC PATCH V1 11/12] libxl: Insert "dma-coherent" property into virtio-mmio device node" "[RFC PATCH V1 12/12] libxl: Fix duplicate memory node in DT"
- move VirtIO MMIO #define-s to xen/include/public/arch-arm.h
Changes V1 -> V2:
- update the author of a patch
Changes V2 -> V3:
- no changes
Changes V3 -> V4:
- no changes
Changes V4 -> V5:
- split the changes, change the order of the patches
- drop an extra "virtio" configuration option
- update patch description
- use CONTAINER_OF instead of own implementation
- reserve ranges for Virtio MMIO params and put them in correct location
- create helpers to allocate Virtio MMIO params, add corresponding sanity-сhecks
- add comment why MMIO size 0x200 is chosen
- update debug print
- drop Wei's T-b
Changes V5 -> V6:
- rebase on current staging
Changes V6 -> V7:
- rebase on current staging
- add T-b and R-b tags
- update according to the recent changes to "libxl: Add support for Virtio disk configuration"
--- tools/libs/light/libxl_arm.c | 131 +++++++++++++++++++++++++++++++++++++++++- xen/include/public/arch-arm.h | 7 +++ 2 files changed, 136 insertions(+), 2 deletions(-)
tools/libs/light/libxl_arm.c +129 -2
@@ -8,6 +8,56 @@#include <assert.h> #include <xen/device_tree_defs.h> +/* +* There is no clear requirements for the total size of Virtio MMIO region. +* The size of control registers is 0x100 and device-specific configuration +* registers starts at the offset 0x100, however it's size depends on the device +* and the driver. Pick the biggest known size at the moment to cover most +* of the devices (also consider allowing the user to configure the size via +* config file for the one not conforming with the proposed value). +*/ +#define VIRTIO_MMIO_DEV_SIZE xen_mk_ullong(0x200) + +static uint64_t virtio_mmio_base; +static uint32_t virtio_mmio_irq; + +static void init_virtio_mmio_params (void ) +{ + virtio_mmio_base =GUEST_VIRTIO_MMIO_BASE ; + virtio_mmio_irq =GUEST_VIRTIO_MMIO_SPI_FIRST ; +} + +static uint64_t alloc_virtio_mmio_base (libxl__gc *gc) +{ +uint64_t base = virtio_mmio_base; + +/* Make sure we have enough reserved resources */ +if ((virtio_mmio_base +VIRTIO_MMIO_DEV_SIZE > +GUEST_VIRTIO_MMIO_BASE +GUEST_VIRTIO_MMIO_SIZE )) { +LOG (ERROR ,"Ran out of reserved range for Virtio MMIO BASE 0x%" PRIx64"\n" , + virtio_mmio_base); +return 0 ; + } + virtio_mmio_base +=VIRTIO_MMIO_DEV_SIZE ; + +return base; +} + +static uint32_t alloc_virtio_mmio_irq (libxl__gc *gc) +{ +uint32_t irq = virtio_mmio_irq; + +/* Make sure we have enough reserved resources */ +if (virtio_mmio_irq >GUEST_VIRTIO_MMIO_SPI_LAST ) { +LOG (ERROR ,"Ran out of reserved range for Virtio MMIO IRQ %u\n" , + virtio_mmio_irq); +return 0 ; + } + virtio_mmio_irq++; + +return irq; +} +static const char *gicv_to_string (libxl_gic_version gic_version) {switch (gic_version) {
@@ -26,8 +76,8 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, {uint32_t nr_spis =0 ;unsigned int i; -uint32_t vuart_irq; -bool vuart_enabled = false; +uint32_t vuart_irq, virtio_irq =0 ; +bool vuart_enabled = false, virtio_enabled = false;/* * If pl011 vuart is enabled then increment the nr_spis to allow allocation
@@ -39,6 +89,35 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, vuart_enabled = true; } +/* +* Virtio MMIO params are non-unique across the whole system and must be +* initialized for every new guest. +*/ +init_virtio_mmio_params (); +for (i =0 ; i < d_config->num_disks; i++) { +libxl_device_disk *disk = &d_config->disks[i]; + +if (disk->protocol ==LIBXL_DISK_PROTOCOL_VIRTIO_MMIO ) { + disk->base =alloc_virtio_mmio_base (gc); +if (!disk->base) +return ERROR_FAIL ; + + disk->irq =alloc_virtio_mmio_irq (gc); +if (!disk->irq) +return ERROR_FAIL ; + +if (virtio_irq < disk->irq) + virtio_irq = disk->irq; + virtio_enabled = true; + +LOG (DEBUG ,"Allocate Virtio MMIO params for Vdev %s: IRQ %u BASE 0x%" PRIx64, + disk->vdev, disk->irq, disk->base); + } + } + +if (virtio_enabled) + nr_spis += (virtio_irq -32 ) +1 ; +for (i =0 ; i < d_config->b_info.num_irqs; i++) {uint32_t irq = d_config->b_info.irqs[i];uint32_t spi;
@@ -58,6 +137,13 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,return ERROR_FAIL ; } +/* The same check as for vpl011 */ +if (virtio_enabled && + (irq >=GUEST_VIRTIO_MMIO_SPI_FIRST && irq <= virtio_irq)) { +LOG (ERROR ,"Physical IRQ %u conflicting with Virtio MMIO IRQ range\n" , irq); +return ERROR_FAIL ; + } +if (irq <32 )continue ;
@@ -787,6 +873,39 @@ static int make_vpci_node(libxl__gc *gc, void *fdt,return 0 ; } + +static int make_virtio_mmio_node (libxl__gc *gc,void *fdt, +uint64_t base,uint32_t irq) +{ +int res; +gic_interrupt intr; +/* Placeholder for virtio@ + a 64-bit number + \0 */ +char buf[24 ]; + +snprintf (buf,sizeof (buf),"virtio@%" PRIx64, base); + res =fdt_begin_node (fdt, buf); +if (res)return res; + + res =fdt_property_compat (gc, fdt,1 ,"virtio,mmio" ); +if (res)return res; + + res =fdt_property_regs (gc, fdt,GUEST_ROOT_ADDRESS_CELLS ,GUEST_ROOT_SIZE_CELLS , +1 , base,VIRTIO_MMIO_DEV_SIZE ); +if (res)return res; + +set_interrupt (intr, irq,0xf ,DT_IRQ_TYPE_EDGE_RISING ); + res =fdt_property_interrupts (gc, fdt, &intr,1 ); +if (res)return res; + + res =fdt_property (fdt,"dma-coherent" ,NULL ,0 ); +if (res)return res; + + res =fdt_end_node (fdt); +if (res)return res; + +return 0 ; +} +static const struct arch_info *get_arch_info (libxl__gc *gc,const struct xc_dom_image *dom) {
@@ -988,6 +1107,7 @@ static int libxl__prepare_dtb(libxl__gc *gc, libxl_domain_config *d_config,size_t fdt_size =0 ;int pfdt_size =0 ;libxl_domain_build_info *const info = &d_config->b_info; +unsigned int i;const libxl_version_info *vers;const struct arch_info *ainfo;
@@ -1094,6 +1214,13 @@ next_resize:if (d_config->num_pcidevs)FDT (make_vpci_node (gc, fdt, ainfo, dom) ); +for (i =0 ; i < d_config->num_disks; i++) { +libxl_device_disk *disk = &d_config->disks[i]; + +if (disk->protocol ==LIBXL_DISK_PROTOCOL_VIRTIO_MMIO ) +FDT (make_virtio_mmio_node (gc, fdt, disk->base, disk->irq) ); + } +if (pfdt)FDT (copy_partial_fdt (gc, fdt, pfdt) );
xen/include/public/arch-arm.h +7 -0
@@ -407,6 +407,10 @@ typedef uint64_t xen_callback_t;/* Physical Address Space */ +/* Virtio MMIO mappings */ +#define GUEST_VIRTIO_MMIO_BASE xen_mk_ullong(0x02000000) +#define GUEST_VIRTIO_MMIO_SIZE xen_mk_ullong(0x00100000) +/* * vGIC mappings: Only one set of mapping is used by the guest. * Therefore they can overlap.
@@ -493,6 +497,9 @@ typedef uint64_t xen_callback_t;#define GUEST_VPL011_SPI 32 +#define GUEST_VIRTIO_MMIO_SPI_FIRST 33 +#define GUEST_VIRTIO_MMIO_SPI_LAST 43 +/* PSCI functions */ #define PSCI_cpu_suspend 0#define PSCI_cpu_off 1
Signature · 1 line
2.7.4
PATCH v7 1/2 libxl: Add support for Virtio disk configuration
In reply to Oleksandr TyshchenkoFrom: Oleksandr Tyshchenko <[email protected]>
This patch adds basic support for configuring and assisting virtio-mmio based virtio-disk backend (emualator) which is intended to run out of Qemu and could be run in any domain.
Although the Virtio block device is quite different from traditional Xen PV block device (vbd) from the toolstack's point of view:
- as the frontend is virtio-blk which is not a Xenbus driver, nothing written to Xenstore are fetched by the frontend (the vdev is not passed to the frontend)
- the ring-ref/event-channel are not used for the backend<->frontend communication, the proposed IPC for Virtio is IOREQ/DM
it is still a "block device" and ought to be integrated in existing "disk" handling. So, re-use (and adapt) "disk" parsing/configuration logic to deal with Virtio devices as well.
For the immediate purpose and an ability to extend that support for other use-cases in future (Qemu, virtio-pci, etc) perform the following actions:
- Add new disk backend type (LIBXL_DISK_BACKEND_OTHER) and reflect that in the configuration
- Introduce new disk protocol field to libxl_device_disk struct (with LIBXL_DISK_PROTOCOL_XEN and LIBXL_DISK_PROTOCOL_VIRTIO_MMIO types) and reflect that in the configuration (new "protocol" option with "xen" protocol being default value)
- Add new device kind (LIBXL__DEVICE_KIND_VIRTIO_DISK) as current one (LIBXL__DEVICE_KIND_VBD) doesn't fit into Virtio disk model
An example of domain configuration for Virtio disk:
disk = [ 'phy:/dev/mmcblk0p3, xvda1, backendtype=other, protocol=virtio-mmio']
Nothing has changed for default Xen disk configuration.
Please note, this patch is not enough for virtio-disk to work on Xen (Arm), as for every Virtio device (including disk) we need to allocate Virtio MMIO params (IRQ and memory region) and pass them to the backend, also update Guest device-tree. The subsequent patch will add these missing bits. For the current patch, the default "irq" and "base" are just written to the Xenstore. This is not an ideal splitting, but this way we avoid breaking the bisectability.
---
Changes RFC -> V1:
- no changes
Changes V1 -> V2:
- rebase according to the new location of libxl_virtio_disk.c
Changes V2 -> V3:
- no changes
Changes V3 -> V4:
- rebase according to the new argument for DEFINE_DEVICE_TYPE_STRUCT
Changes V4 -> V5:
- split the changes, change the order of the patches
- update patch description
- don't introduce new "vdisk" configuration option with own parsing logic, re-use Xen PV block "disk" parsing/configuration logic for the virtio-disk
- introduce "virtio" flag and document it's usage
- add LIBXL_HAVE_DEVICE_DISK_VIRTIO
- update libxlu_disk_l.[ch]
- drop num_disks variable/MAX_VIRTIO_DISKS
- drop Wei's T-b
Changes V5 -> V6:
- rebase on current staging
- use "%"PRIu64 instead of %lu for disk->base in device_disk_add()
- update *.gen.go files
Changes V6 -> V7:
- rebase on current staging
- update *.gen.go files and libxlu_disk_l.[ch] files
- update patch description
- rework significantly to support more flexible configuration and have more generic basic implementation for being able to extend that for other use-cases (virtio-pci, qemu, etc).
--- docs/man/xl-disk-configuration.5.pod.in | 37 +- tools/golang/xenlight/helpers.gen.go | 6 + tools/golang/xenlight/types.gen.go | 11 + tools/include/libxl.h | 6 + tools/libs/light/libxl_device.c | 57 +- tools/libs/light/libxl_disk.c | 111 +++- tools/libs/light/libxl_internal.h | 1 + tools/libs/light/libxl_types.idl | 10 + tools/libs/light/libxl_types_internal.idl | 1 + tools/libs/light/libxl_utils.c | 2 + tools/libs/util/libxlu_disk_l.c | 952 +++++++++++++++--------------- tools/libs/util/libxlu_disk_l.h | 2 +- tools/libs/util/libxlu_disk_l.l | 9 + tools/xl/xl_block.c | 11 + 14 files changed, 736 insertions(+), 480 deletions(-)
docs/man/xl-disk-configuration.5.pod.in +33 -4
@@ -232,7 +232,7 @@ Specifies the backend implementation to use =item Supported values -phy, qdisk +phy, qdisk, other =item Mandatory
@@ -244,11 +244,13 @@ Automatically determine which backend to use. =back -This does not affect the guest's view of the device. It controls -which software implementation of the Xen backend driver is used. +It controls which software implementation of the backend driver is used. +Depending on the "protocol" option this may affect the guest's view +of the device. Not all backend drivers support all combinations of other options. -For example, "phy" does not support formats other than "raw". +For example, "phy" and "other" do not support formats other than "raw" and +"other" does not support protocols other than "virtio-mmio". Normally this option should not be specified, in which case libxl will automatically determine the most suitable backend.
@@ -344,8 +346,35 @@ can be used to disable "hole punching" for file based backends which were intentionally created non-sparse to avoid fragmentation of the file. +=item B<protocol>=I<PROTOCOL> + +=over 4 + +=item Description + +Specifies the communication protocol to use for the chosen "backendtype" option + +=item Supported values + +xen, virtio-mmio + +=item Mandatory + +No + +=item Default value + +xen + =back +Besides forcing toolstack to use specific backend implementation, this also +affects the guest's view of the device. For example, "virtio-mmio" requires +Virtio frontend driver (virtio-blk) to be used. Please note, the virtual +device (vdev) is not passed to the guest in that case, but it still must be +specified for the internal purposes. + +=back =head1 COLO Parameters
tools/golang/xenlight/helpers.gen.go +6 -0
@@ -1751,6 +1751,9 @@ x.DirectIoSafe = bool(xc.direct_io_safe) if err := x.DiscardEnable.fromC(&xc.discard_enable);err != nil { return fmt.Errorf("converting field DiscardEnable: %v", err) } +x.Protocol = DiskProtocol(xc.protocol) +x.Irq = uint32(xc.irq) +x.Base = uint64(xc.base) if err := x.ColoEnable.fromC(&xc.colo_enable);err != nil { return fmt.Errorf("converting field ColoEnable: %v", err) }
@@ -1788,6 +1791,9 @@ xc.direct_io_safe = C.bool(x.DirectIoSafe) if err := x.DiscardEnable.toC(&xc.discard_enable); err != nil { return fmt.Errorf("converting field DiscardEnable: %v", err) } +xc.protocol = C.libxl_disk_protocol(x.Protocol) +xc.irq = C.uint32_t(x.Irq) +xc.base = C.uint64_t(x.Base) if err := x.ColoEnable.toC(&xc.colo_enable); err != nil { return fmt.Errorf("converting field ColoEnable: %v", err) }
tools/golang/xenlight/types.gen.go +11 -0
@@ -99,6 +99,14 @@ DiskBackendUnknown DiskBackend = 0 DiskBackendPhy DiskBackend = 1 DiskBackendTap DiskBackend = 2 DiskBackendQdisk DiskBackend = 3 +DiskBackendOther DiskBackend = 4 +) + +type DiskProtocol int +const( +DiskProtocolUnknown DiskProtocol = 0 +DiskProtocolXen DiskProtocol = 1 +DiskProtocolVirtioMmio DiskProtocol = 2 ) type NicType int
@@ -643,6 +651,9 @@ Readwrite int IsCdrom int DirectIoSafe bool DiscardEnable Defbool +Protocol DiskProtocol +Irq uint32 +Base uint64 ColoEnable Defbool ColoRestoreEnable Defbool ColoHost string
tools/include/libxl.h +6 -0
@@ -528,6 +528,12 @@#define LIBXL_HAVE_MAX_GRANT_VERSION 1/* +* LIBXL_HAVE_DEVICE_DISK_PROTOCOL indicates that a 'protocol' field +* (of libxl_disk_protocol type) is present in libxl_device_disk. +*/ +#define LIBXL_HAVE_DEVICE_DISK_PROTOCOL 1 + +/* * libxl ABI compatibility * * The only guarantee which libxl makes regarding ABI compatibility
tools/libs/light/libxl_device.c +53 -4
102 lines not on this page · raw message
tools/libs/light/libxl_disk.c +104 -7
186 lines not on this page · raw message
tools/libs/light/libxl_internal.h +1 -0
@@ -1493,6 +1493,7 @@ _hidden char * libxl__domain_pvcontrol_read(libxl__gc *gc,/* from xl_device */ _hidden char *libxl__device_disk_string_of_backend(libxl_disk_backend backend); +_hidden char *libxl__device_disk_string_of_protocol(libxl_disk_protocol protocol); _hidden char *libxl__device_disk_string_of_format(libxl_disk_format format); _hidden const char *libxl__qemu_disk_format_string(libxl_disk_format format); _hidden int libxl__device_disk_set_backend(libxl__gc*, libxl_device_disk*);
tools/libs/light/libxl_types.idl +10 -0
@@ -130,6 +130,13 @@ libxl_disk_backend = Enumeration("disk_backend", [ (1, "PHY"), (2, "TAP"), (3, "QDISK"), + (4, "OTHER"), + ]) + +libxl_disk_protocol = Enumeration("disk_protocol", [ + (0, "UNKNOWN"), + (1, "XEN"), + (2, "VIRTIO_MMIO"), ]) libxl_nic_type = Enumeration("nic_type", [
@@ -704,6 +711,9 @@ libxl_device_disk = Struct("device_disk", [ ("is_cdrom", integer), ("direct_io_safe", bool), ("discard_enable", libxl_defbool), + ("protocol", libxl_disk_protocol), + ("irq", uint32), + ("base", uint64), # Note that the COLO configuration settings should be considered unstable. # They may change incompatibly in future versions of Xen. ("colo_enable", libxl_defbool),
tools/libs/light/libxl_types_internal.idl +1 -0
@@ -32,6 +32,7 @@ libxl__device_kind = Enumeration("device_kind", [ (14, "PVCALLS"), (15, "VSND"), (16, "VINPUT"), + (17, "VIRTIO_DISK"), ]) libxl__console_backend = Enumeration("console_backend", [
tools/libs/light/libxl_utils.c +2 -0
@@ -303,6 +303,8 @@ int libxl_string_to_backend(libxl_ctx *ctx, char *s, libxl_disk_backend *backend *backend =LIBXL_DISK_BACKEND_TAP ; }else if (!strcmp (s,"qdisk" )) { *backend =LIBXL_DISK_BACKEND_QDISK ; + }else if (!strcmp (s,"other" )) { + *backend =LIBXL_DISK_BACKEND_OTHER ; }else if (!strcmp (s,"tap" )) { p =strchr (s,':' );if (!p) {
tools/libs/util/libxlu_disk_l.c +488 -464
1,237 lines not on this page · raw message
tools/libs/util/libxlu_disk_l.h +1 -1
@@ -694,7 +694,7 @@ extern int yylex (yyscan_t yyscanner);#undef yyTABLES_NAME#endif -#line 291 "libxlu_disk_l.l" +#line 300 "libxlu_disk_l.l"#line 699 "libxlu_disk_l.h"#undef xlu__disk_yyIN_HEADER
tools/libs/util/libxlu_disk_l.l +9 -0
@@ -122,9 +122,17 @@ static void setbackendtype(DiskParseContext *dpc, const char *str) { if ( !strcmp(str,"phy")) DSET(dpc,backend,BACKEND,str,PHY); else if (!strcmp(str,"tap")) DSET(dpc,backend,BACKEND,str,TAP); else if (!strcmp(str,"qdisk")) DSET(dpc,backend,BACKEND,str,QDISK); + else if (!strcmp(str,"other")) DSET(dpc,backend,BACKEND,str,OTHER); else xlu__disk_err(dpc,str,"unknown value for backendtype"); } +/* Sets ->protocol from the string. IDL should provide something for this. */ +static void setprotocol(DiskParseContext *dpc, const char *str) { + if (!strcmp(str,"xen")) DSET(dpc,protocol,PROTOCOL,str,XEN); + else if (!strcmp(str,"virtio-mmio")) DSET(dpc,protocol,PROTOCOL,str,VIRTIO_MMIO); + else xlu__disk_err(dpc,str,"unknown value for protocol"); +} + /* Sets ->colo-port from the string. COLO need this. */ static void setcoloport(DiskParseContext *dpc, const char *str) { int port = atoi(str);
@@ -192,6 +200,7 @@ devtype=[^,]*,? { xlu__disk_err(DPC,yytext,"unknown value for type"); } access=[^,]*,? { STRIP(','); setaccess(DPC, FROMEQUALS); } backend=[^,]*,? { STRIP(','); SAVESTRING("backend", backend_domname, FROMEQUALS); } backendtype=[^,]*,? { STRIP(','); setbackendtype(DPC,FROMEQUALS); } +protocol=[^,]*,? { STRIP(','); setprotocol(DPC,FROMEQUALS); } vdev=[^,]*,? { STRIP(','); SAVESTRING("vdev", vdev, FROMEQUALS); } script=[^,]*,? { STRIP(','); SAVESTRING("script", script, FROMEQUALS); }
tools/xl/xl_block.c +11 -0
@@ -50,6 +50,11 @@ int main_blockattach(int argc, char **argv)return 0 ; } +if (disk.protocol !=LIBXL_DISK_PROTOCOL_XEN ) { +fprintf (stderr,"block-attach is only supported for protocol xen\n" ); +return 1 ; + } +if (libxl_device_disk_add (ctx, fe_domid, &disk,0 )) {fprintf (stderr,"libxl_device_disk_add failed.\n" );return 1 ;
@@ -119,6 +124,12 @@ int main_blockdetach(int argc, char **argv)fprintf (stderr,"Error: Device %s not connected.\n" , argv[optind+1 ]);return 1 ; } + +if (disk.protocol !=LIBXL_DISK_PROTOCOL_XEN ) { +fprintf (stderr,"block-detach is only supported for protocol xen\n" ); +return 1 ; + } + rc = !force ?libxl_device_disk_safe_remove (ctx, domid, &disk,0 ) :libxl_device_disk_destroy (ctx, domid, &disk,0 );if (rc) {
Signature · 1 line
2.7.4
Re: [PATCH V7 1/2] libxl: Add support for Virtio disk configuration
Quoted 4 lines
From: Oleksandr Tyshchenko <[email protected]>
This patch adds basic support for configuring and assisting virtio-mmio based virtio-disk backend (emualator) which is intended to run out of
^ emulator
Re: [PATCH V7 2/2] libxl: Introduce basic virtio-mmio support on Arm
In reply to Oleksandr TyshchenkoQuoted 18 lines · Oleksandr Tyshchenko
From: Julien Grall <[email protected]>
This patch introduces helpers to allocate Virtio MMIO params (IRQ and memory region) and create specific device node in the Guest device-tree with allocated params. In order to deal with multiple Virtio devices, reserve corresponding ranges. For now, we reserve 1MB for memory regions and 10 SPIs.
As these helpers should be used for every Virtio device attached to the Guest, call them for Virtio disk(s).
Please note, with statically allocated Virtio IRQs there is a risk of a clash with a physical IRQs of passthrough devices. For the first version, it's fine, but we should consider allocating the Virtio IRQs automatically. Thankfully, we know in advance which IRQs will be used for passthrough to be able to choose non-clashed ones.
Quoted 4 lines
Signed-off-by Julien Grall <[email protected]>Signed-off-by Oleksandr Tyshchenko <[email protected]>Tested-by Jiamei Xie <[email protected]>Reviewed-by Henry Wang <[email protected]>
I realize that we are at v7 and I haven't reviewed this before, so I'll limit my comments. I'll clarify the ones that I think are more important from the one that are less important.
Quoted 58 lines
---
@Jiamei, @Henry I decided to leave your T-b and R-b tags with the minor change I made, are you still happy with that?s/if (disk->virtio)/if (
disk->protocol==LIBXL_DISK_PROTOCOL_VIRTIO_MMIO)Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"Changes RFC -> V1:
- was squashed with:
"[RFC PATCH V1 09/12] libxl: Handle virtio-mmio irq in more correct way" "[RFC PATCH V1 11/12] libxl: Insert "dma-coherent" property into virtio-mmio device node" "[RFC PATCH V1 12/12] libxl: Fix duplicate memory node in DT"
- move VirtIO MMIO #define-s toxen/include/public/arch-arm.hChanges V1 -> V2:
- update the author of a patchChanges V2 -> V3:
- no changesChanges V3 -> V4:
- no changesChanges V4 -> V5:
- split the changes, change the order of the patches
- drop an extra "virtio" configuration option
- update patch description
- useCONTAINER_OFinstead of own implementation
- reserve ranges for Virtio MMIO params and put them in correct location
- create helpers to allocate Virtio MMIO params, add corresponding sanity-сhecks
- add comment why MMIO size0x200is chosen
- update debug print
- drop Wei's T-bChanges V5 -> V6:
- rebase on current stagingChanges V6 -> V7:
- rebase on current staging
- add T-b and R-b tags
- update according to the recent changes to "libxl: Add support for Virtio disk configuration"--- tools/libs/light/libxl_arm.c | 131 +++++++++++++++++++++++++++++++++++++++++- xen/include/public/arch-arm.h | 7 +++ 2 files changed, 136 insertions(+), 2 deletions(-)tools/libs/light/libxl_arm.c +0
-0@@ -8,6 +8,56 @@#include <assert.h> #include <xen/device_tree_defs.h>
tools/libs/light/libxl_arm.c line 19
Quoted 10 lines
tools/libs/light/libxl_arm.c +9
-0+/* +* There is no clear requirements for the total size of Virtio MMIO region. +* The size of control registers is 0x100 and device-specific configuration +* registers starts at the offset 0x100, however it's size depends on the device +* and the driver. Pick the biggest known size at the moment to cover most +* of the devices (also consider allowing the user to configure the size via +* config file for the one not conforming with the proposed value). +*/ +#define VIRTIO_MMIO_DEV_SIZE xen_mk_ullong(0x200)
Actually, I don't think we need to make this generic. We only support virtio-disk now and I think it is fine if this was called VIRTIO_DISK_MMIO_DEV_SIZE and the size was exactly the size needed by virtio-disk. When/if we support another virtio protocol we can add set the appropriate size of that one as well.
At the moment as you can see below:
*/
for (i = 0; i < d_config->num_disks; i++) {
libxl_device_disk *disk = &d_config->disks[i];
if (disk->protocol == LIBXL_DISK_PROTOCOL_VIRTIO_MMIO) {it is all very virtio-disk specific, so we might as well exploit it for the better :-)
Given that we are at v7 of this series, I don't think this is very important, so I think it is OK if we keep the code as is.
tools/libs/light/libxl_arm.c line 22
Quoted 2 lines
tools/libs/light/libxl_arm.c +2
-0+static uint64_t virtio_mmio_base; +static uint32_t virtio_mmio_irq;
No need for these two variables to be global in this file, they could be local variables in libxl__arch_domain_prepare_config.
I think that this is a change we should make if possible before committing these patches.
tools/libs/light/libxl_arm.c line 32
Quoted 9 lines
tools/libs/light/libxl_arm.c +9
-0+static void init_virtio_mmio_params (void ) +{ + virtio_mmio_base =GUEST_VIRTIO_MMIO_BASE ; + virtio_mmio_irq =GUEST_VIRTIO_MMIO_SPI_FIRST ; +} + +static uint64_t alloc_virtio_mmio_base (libxl__gc *gc) +{ +uint64_t base = virtio_mmio_base;
If virtio_mmio_base is local in libxl__arch_domain_prepare_config, then it could be passed here as parameter (as pointer).
If we make the dev MMIO size (GUEST_VIRTIO_MMIO_SIZE) specific to virtio-disk, then we could pass it also as argument to this function:
static uint64_t alloc_virtio_mmio_base(libxl__gc *gc,
uint64 *virtio_mmio_base,
uint64_t dev_mmio_size)Quoted 42 lines
tools/libs/light/libxl_arm.c +29
-2+/* Make sure we have enough reserved resources */ +if ((virtio_mmio_base +VIRTIO_MMIO_DEV_SIZE > +GUEST_VIRTIO_MMIO_BASE +GUEST_VIRTIO_MMIO_SIZE )) { +LOG (ERROR ,"Ran out of reserved range for Virtio MMIO BASE 0x%" PRIx64"\n" , + virtio_mmio_base); +return 0 ; + } + virtio_mmio_base +=VIRTIO_MMIO_DEV_SIZE ; + +return base; +} + +static uint32_t alloc_virtio_mmio_irq (libxl__gc *gc) +{ +uint32_t irq = virtio_mmio_irq; + +/* Make sure we have enough reserved resources */ +if (virtio_mmio_irq >GUEST_VIRTIO_MMIO_SPI_LAST ) { +LOG (ERROR ,"Ran out of reserved range for Virtio MMIO IRQ %u\n" , + virtio_mmio_irq); +return 0 ; + } + virtio_mmio_irq++; + +return irq; +} +static const char *gicv_to_string (libxl_gic_version gic_version) {switch (gic_version) {@@ -26,8 +76,8 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, {uint32_t nr_spis =0 ;unsigned int i; -uint32_t vuart_irq; -bool vuart_enabled = false; +uint32_t vuart_irq, virtio_irq =0 ; +bool vuart_enabled = false, virtio_enabled = false;/* * If pl011 vuart is enabled then increment the nr_spis to allow allocation
tools/libs/light/libxl_arm.c int libxl__arch_domain_prepare_config(libxl__gc *gc, · line 96
Quoted 8 lines
tools/libs/light/libxl_arm.c +5
-0@@ -39,6 +89,35 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, vuart_enabled = true; } +/* +* Virtio MMIO params are non-unique across the whole system and must be +* initialized for every new guest. +*/ +init_virtio_mmio_params ();
No need to initialize them in init_virtio_mmio_params, you could just do:
uint64_t virtio_mmio_base = GUEST_VIRTIO_MMIO_BASE; uint32_t virtio_mmio_irq = GUEST_VIRTIO_MMIO_SPI_FIRST;
at the top of libxl__arch_domain_prepare_config
Quoted 28 lines
tools/libs/light/libxl_arm.c +24
-0+for (i =0 ; i < d_config->num_disks; i++) { +libxl_device_disk *disk = &d_config->disks[i]; + +if (disk->protocol ==LIBXL_DISK_PROTOCOL_VIRTIO_MMIO ) { + disk->base =alloc_virtio_mmio_base (gc); +if (!disk->base) +return ERROR_FAIL ; + + disk->irq =alloc_virtio_mmio_irq (gc); +if (!disk->irq) +return ERROR_FAIL ; + +if (virtio_irq < disk->irq) + virtio_irq = disk->irq; + virtio_enabled = true; + +LOG (DEBUG ,"Allocate Virtio MMIO params for Vdev %s: IRQ %u BASE 0x%" PRIx64, + disk->vdev, disk->irq, disk->base); + } + } + +if (virtio_enabled) + nr_spis += (virtio_irq -32 ) +1 ; +for (i =0 ; i < d_config->b_info.num_irqs; i++) {uint32_t irq = d_config->b_info.irqs[i];uint32_t spi;
tools/libs/light/libxl_arm.c int libxl__arch_domain_prepare_config(libxl__gc *gc, · line 142
Quoted 6 lines
tools/libs/light/libxl_arm.c +3
-0@@ -58,6 +137,13 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,return ERROR_FAIL ; } +/* The same check as for vpl011 */ +if (virtio_enabled && + (irq >=GUEST_VIRTIO_MMIO_SPI_FIRST && irq <= virtio_irq)) {
NIT: alignment:
if (virtio_enabled &&
(irq >= GUEST_VIRTIO_MMIO_SPI_FIRST && irq <= virtio_irq)) {Quoted 97 lines
tools/libs/light/libxl_arm.c +45
-0+LOG (ERROR ,"Physical IRQ %u conflicting with Virtio MMIO IRQ range\n" , irq); +return ERROR_FAIL ; + } +if (irq <32 )continue ;@@ -787,6 +873,39 @@ static int make_vpci_node(libxl__gc *gc, void *fdt,return 0 ; } + +static int make_virtio_mmio_node (libxl__gc *gc,void *fdt, +uint64_t base,uint32_t irq) +{ +int res; +gic_interrupt intr; +/* Placeholder for virtio@ + a 64-bit number + \0 */ +char buf[24 ]; + +snprintf (buf,sizeof (buf),"virtio@%" PRIx64, base); + res =fdt_begin_node (fdt, buf); +if (res)return res; + + res =fdt_property_compat (gc, fdt,1 ,"virtio,mmio" ); +if (res)return res; + + res =fdt_property_regs (gc, fdt,GUEST_ROOT_ADDRESS_CELLS ,GUEST_ROOT_SIZE_CELLS , +1 , base,VIRTIO_MMIO_DEV_SIZE ); +if (res)return res; + +set_interrupt (intr, irq,0xf ,DT_IRQ_TYPE_EDGE_RISING ); + res =fdt_property_interrupts (gc, fdt, &intr,1 ); +if (res)return res; + + res =fdt_property (fdt,"dma-coherent" ,NULL ,0 ); +if (res)return res; + + res =fdt_end_node (fdt); +if (res)return res; + +return 0 ; +} +static const struct arch_info *get_arch_info (libxl__gc *gc,const struct xc_dom_image *dom) {@@ -988,6 +1107,7 @@ static int libxl__prepare_dtb(libxl__gc *gc, libxl_domain_config *d_config,size_t fdt_size =0 ;int pfdt_size =0 ;libxl_domain_build_info *const info = &d_config->b_info; +unsigned int i;const libxl_version_info *vers;const struct arch_info *ainfo;@@ -1094,6 +1214,13 @@ next_resize:if (d_config->num_pcidevs)FDT (make_vpci_node (gc, fdt, ainfo, dom) ); +for (i =0 ; i < d_config->num_disks; i++) { +libxl_device_disk *disk = &d_config->disks[i]; + +if (disk->protocol ==LIBXL_DISK_PROTOCOL_VIRTIO_MMIO ) +FDT (make_virtio_mmio_node (gc, fdt, disk->base, disk->irq) ); + } +if (pfdt)FDT (copy_partial_fdt (gc, fdt, pfdt) );xen/include/public/arch-arm.h +7
-0@@ -407,6 +407,10 @@ typedef uint64_t xen_callback_t;/* Physical Address Space */ +/* Virtio MMIO mappings */ +#define GUEST_VIRTIO_MMIO_BASE xen_mk_ullong(0x02000000) +#define GUEST_VIRTIO_MMIO_SIZE xen_mk_ullong(0x00100000) +/* * vGIC mappings: Only one set of mapping is used by the guest. * Therefore they can overlap. @@ -493,6 +497,9 @@ typedef uint64_t xen_callback_t;#define GUEST_VPL011_SPI 32 +#define GUEST_VIRTIO_MMIO_SPI_FIRST 33 +#define GUEST_VIRTIO_MMIO_SPI_LAST 43 +/* PSCI functions */ #define PSCI_cpu_suspend 0#define PSCI_cpu_off 1Signature · 1 line
2.7.4
Re: [PATCH V7 2/2] libxl: Introduce basic virtio-mmio support on Arm
Hi,
Sorry for the formatting issues.
Quoted 5 lines · On Mon, 18 Apr 2022, 21:41 Stefano Stabellini, <[email protected]> wrote:
tools/libs/light/libxl_arm.c line 22
Quoted 2 lines
tools/libs/light/libxl_arm.c +2
-0+static uint64_t virtio_mmio_base; +static uint32_t virtio_mmio_irq;No need for these two variables to be global in this file, they could be local variables in
libxl__arch_domain_prepare_config.
It is more than "no need". Libxl can be used by a daemon to handle multiple domains. So we can't use static variable to keep track of local information.
Cheers,
Re: [PATCH V7 2/2] libxl: Introduce basic virtio-mmio support on Arm
In reply to Stefano StabelliniOn 19.04.22 00:41, Stefano Stabellini wrote:
Hello Stefano
Quoted 19 lines · Oleksandr Tyshchenko
Quoted 18 lines
From: Julien Grall <[email protected]>
This patch introduces helpers to allocate Virtio MMIO params (IRQ and memory region) and create specific device node in the Guest device-tree with allocated params. In order to deal with multiple Virtio devices, reserve corresponding ranges. For now, we reserve 1MB for memory regions and 10 SPIs.
As these helpers should be used for every Virtio device attached to the Guest, call them for Virtio disk(s).
Please note, with statically allocated Virtio IRQs there is a risk of a clash with a physical IRQs of passthrough devices. For the first version, it's fine, but we should consider allocating the Virtio IRQs automatically. Thankfully, we know in advance which IRQs will be used for passthrough to be able to choose non-clashed ones.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Julien Grall <[email protected]>Signed-off-by Oleksandr Tyshchenko <[email protected]>Tested-by Jiamei Xie <[email protected]>Reviewed-by Henry Wang <[email protected]>I realize that we are at v7 and I haven't reviewed this before, so I'll limit my comments. I'll clarify the ones that I think are more important from the one that are less important.
thank you
Quoted 61 lines
Quoted 61 lines
---
@Jiamei, @Henry I decided to leave your T-b and R-b tags with the minor change I made, are you still happy with that?s/if (disk->virtio)/if (
disk->protocol==LIBXL_DISK_PROTOCOL_VIRTIO_MMIO)Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"Changes RFC -> V1:
- was squashed with:
"[RFC PATCH V1 09/12] libxl: Handle virtio-mmio irq in more correct way" "[RFC PATCH V1 11/12] libxl: Insert "dma-coherent" property into virtio-mmio device node" "[RFC PATCH V1 12/12] libxl: Fix duplicate memory node in DT"
- move VirtIO MMIO #define-s toxen/include/public/arch-arm.hChanges V1 -> V2:
- update the author of a patchChanges V2 -> V3:
- no changesChanges V3 -> V4:
- no changesChanges V4 -> V5:
- split the changes, change the order of the patches
- drop an extra "virtio" configuration option
- update patch description
- useCONTAINER_OFinstead of own implementation
- reserve ranges for Virtio MMIO params and put them in correct location
- create helpers to allocate Virtio MMIO params, add corresponding sanity-сhecks
- add comment why MMIO size0x200is chosen
- update debug print
- drop Wei's T-bChanges V5 -> V6:
- rebase on current stagingChanges V6 -> V7:
- rebase on current staging
- add T-b and R-b tags
- update according to the recent changes to "libxl: Add support for Virtio disk configuration"--- tools/libs/light/libxl_arm.c | 131 +++++++++++++++++++++++++++++++++++++++++- xen/include/public/arch-arm.h | 7 +++ 2 files changed, 136 insertions(+), 2 deletions(-)tools/libs/light/libxl_arm.c +0
-0@@ -8,6 +8,56 @@#include <assert.h> #include <xen/device_tree_defs.h>
Quoted 14 lines
tools/libs/light/libxl_arm.c line 19
Quoted 9 lines
tools/libs/light/libxl_arm.c +9
-0+/* +* There is no clear requirements for the total size of Virtio MMIO region. +* The size of control registers is 0x100 and device-specific configuration +* registers starts at the offset 0x100, however it's size depends on the device +* and the driver. Pick the biggest known size at the moment to cover most +* of the devices (also consider allowing the user to configure the size via +* config file for the one not conforming with the proposed value). +*/ +#define VIRTIO_MMIO_DEV_SIZE xen_mk_ullong(0x200)Actually, I don't think we need to make this generic. We only support virtio-disk now and I think it is fine if this was called
VIRTIO_DISK_MMIO_DEV_SIZEand the size was exactly the size needed by virtio-disk. When/if we support another virtio protocol we can add set the appropriate size of that one as well.
I would prefer if we keep this generic, although we are going to support virtio-blk as the first virtio-mmio device, there is nothing disk specific in that value. The same value (0x200) is used by SW which also generates virtio-mmio device tree nodes like we do in Xen libxl, I am speaking about kvmtool, Qemu here.
Quoted 9 lines
At the moment as you can see below:
*/ for (i = 0; i < d_config->num_disks; i++) { libxl_device_disk *disk = &d_config->disks[i]; if (disk->protocol == LIBXL_DISK_PROTOCOL_VIRTIO_MMIO) {
Quoted 5 lines
it is all very virtio-disk specific, so we might as well exploit it for the better :-)
Given that we are at v7 of this series, I don't think this is very important, so I think it is OK if we keep the code as is.
ok
Quoted 9 lines
tools/libs/light/libxl_arm.c line 22
Quoted 4 lines
tools/libs/light/libxl_arm.c +2
-0+static uint64_t virtio_mmio_base; +static uint32_t virtio_mmio_irq;No need for these two variables to be global in this file, they could be local variables in
libxl__arch_domain_prepare_config.I think that this is a change we should make if possible before committing these patches.
I agree with that, will do
Quoted 14 lines
tools/libs/light/libxl_arm.c line 32
Quoted 12 lines
tools/libs/light/libxl_arm.c +9
-0+static void init_virtio_mmio_params (void ) +{ + virtio_mmio_base =GUEST_VIRTIO_MMIO_BASE ; + virtio_mmio_irq =GUEST_VIRTIO_MMIO_SPI_FIRST ; +} + +static uint64_t alloc_virtio_mmio_base (libxl__gc *gc) +{ +uint64_t base = virtio_mmio_base;If
virtio_mmio_baseis local inlibxl__arch_domain_prepare_config, then it could be passed here as parameter (as pointer).
yes, good point, will do
Quoted 7 lines
If we make the dev MMIO size (
GUEST_VIRTIO_MMIO_SIZE) specific to virtio-disk, then we could pass it also as argument to this function:static
uint64_talloc_virtio_mmio_base(libxl__gc *gc,uint64 *virtio_mmio_base, uint64_t dev_mmio_size)
Please see my comment regarding VIRTIO_MMIO_DEV_SIZE above
Quoted 55 lines
Quoted 44 lines
tools/libs/light/libxl_arm.c +29
-2+/* Make sure we have enough reserved resources */ +if ((virtio_mmio_base +VIRTIO_MMIO_DEV_SIZE > +GUEST_VIRTIO_MMIO_BASE +GUEST_VIRTIO_MMIO_SIZE )) { +LOG (ERROR ,"Ran out of reserved range for Virtio MMIO BASE 0x%" PRIx64"\n" , + virtio_mmio_base); +return 0 ; + } + virtio_mmio_base +=VIRTIO_MMIO_DEV_SIZE ; + +return base; +} + +static uint32_t alloc_virtio_mmio_irq (libxl__gc *gc) +{ +uint32_t irq = virtio_mmio_irq; + +/* Make sure we have enough reserved resources */ +if (virtio_mmio_irq >GUEST_VIRTIO_MMIO_SPI_LAST ) { +LOG (ERROR ,"Ran out of reserved range for Virtio MMIO IRQ %u\n" , + virtio_mmio_irq); +return 0 ; + } + virtio_mmio_irq++; + +return irq; +} +static const char *gicv_to_string (libxl_gic_version gic_version) {switch (gic_version) {@@ -26,8 +76,8 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, {uint32_t nr_spis =0 ;unsigned int i; -uint32_t vuart_irq; -bool vuart_enabled = false; +uint32_t vuart_irq, virtio_irq =0 ; +bool vuart_enabled = false, virtio_enabled = false;/* * If pl011 vuart is enabled then increment the nr_spis to allow allocation tools/libs/light/libxl_arm.c int libxl__arch_domain_prepare_config(libxl__gc *gc, · line 96
Quoted 8 lines
tools/libs/light/libxl_arm.c +5
-0@@ -39,6 +89,35 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, vuart_enabled = true; } +/* +* Virtio MMIO params are non-unique across the whole system and must be +* initialized for every new guest. +*/ +init_virtio_mmio_params ();No need to initialize them in
init_virtio_mmio_params, you could just do:
Quoted 4 lines
uint64_t virtio_mmio_base = GUEST_VIRTIO_MMIO_BASE; uint32_t virtio_mmio_irq = GUEST_VIRTIO_MMIO_SPI_FIRST;at the top of
libxl__arch_domain_prepare_config
yes, will do
Quoted 33 lines
Quoted 33 lines
tools/libs/light/libxl_arm.c +24
-0+for (i =0 ; i < d_config->num_disks; i++) { +libxl_device_disk *disk = &d_config->disks[i]; + +if (disk->protocol ==LIBXL_DISK_PROTOCOL_VIRTIO_MMIO ) { + disk->base =alloc_virtio_mmio_base (gc); +if (!disk->base) +return ERROR_FAIL ; + + disk->irq =alloc_virtio_mmio_irq (gc); +if (!disk->irq) +return ERROR_FAIL ; + +if (virtio_irq < disk->irq) + virtio_irq = disk->irq; + virtio_enabled = true; + +LOG (DEBUG ,"Allocate Virtio MMIO params for Vdev %s: IRQ %u BASE 0x%" PRIx64, + disk->vdev, disk->irq, disk->base); + } + } + +if (virtio_enabled) + nr_spis += (virtio_irq -32 ) +1 ; +for (i =0 ; i < d_config->b_info.num_irqs; i++) {uint32_t irq = d_config->b_info.irqs[i];uint32_t spi;@@ -58,6 +137,13 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,return ERROR_FAIL ; }
Quoted 7 lines
tools/libs/light/libxl_arm.c int libxl__arch_domain_prepare_config(libxl__gc *gc, · line 142
Quoted 3 lines
tools/libs/light/libxl_arm.c +3
-0+/* The same check as for vpl011 */ +if (virtio_enabled && + (irq >=GUEST_VIRTIO_MMIO_SPI_FIRST && irq <= virtio_irq)) {NIT: alignment:
if (virtio_enabled && (irq >= GUEST_VIRTIO_MMIO_SPI_FIRST && irq <= virtio_irq)) {
ok
Quoted 99 lines
Quoted 99 lines
tools/libs/light/libxl_arm.c +45
-0+LOG (ERROR ,"Physical IRQ %u conflicting with Virtio MMIO IRQ range\n" , irq); +return ERROR_FAIL ; + } +if (irq <32 )continue ;@@ -787,6 +873,39 @@ static int make_vpci_node(libxl__gc *gc, void *fdt,return 0 ; } + +static int make_virtio_mmio_node (libxl__gc *gc,void *fdt, +uint64_t base,uint32_t irq) +{ +int res; +gic_interrupt intr; +/* Placeholder for virtio@ + a 64-bit number + \0 */ +char buf[24 ]; + +snprintf (buf,sizeof (buf),"virtio@%" PRIx64, base); + res =fdt_begin_node (fdt, buf); +if (res)return res; + + res =fdt_property_compat (gc, fdt,1 ,"virtio,mmio" ); +if (res)return res; + + res =fdt_property_regs (gc, fdt,GUEST_ROOT_ADDRESS_CELLS ,GUEST_ROOT_SIZE_CELLS , +1 , base,VIRTIO_MMIO_DEV_SIZE ); +if (res)return res; + +set_interrupt (intr, irq,0xf ,DT_IRQ_TYPE_EDGE_RISING ); + res =fdt_property_interrupts (gc, fdt, &intr,1 ); +if (res)return res; + + res =fdt_property (fdt,"dma-coherent" ,NULL ,0 ); +if (res)return res; + + res =fdt_end_node (fdt); +if (res)return res; + +return 0 ; +} +static const struct arch_info *get_arch_info (libxl__gc *gc,const struct xc_dom_image *dom) {@@ -988,6 +1107,7 @@ static int libxl__prepare_dtb(libxl__gc *gc, libxl_domain_config *d_config,size_t fdt_size =0 ;int pfdt_size =0 ;libxl_domain_build_info *const info = &d_config->b_info; +unsigned int i;const libxl_version_info *vers;const struct arch_info *ainfo;@@ -1094,6 +1214,13 @@ next_resize:if (d_config->num_pcidevs)FDT (make_vpci_node (gc, fdt, ainfo, dom) ); +for (i =0 ; i < d_config->num_disks; i++) { +libxl_device_disk *disk = &d_config->disks[i]; + +if (disk->protocol ==LIBXL_DISK_PROTOCOL_VIRTIO_MMIO ) +FDT (make_virtio_mmio_node (gc, fdt, disk->base, disk->irq) ); + } +if (pfdt)FDT (copy_partial_fdt (gc, fdt, pfdt) );xen/include/public/arch-arm.h +7
-0@@ -407,6 +407,10 @@ typedef uint64_t xen_callback_t;/* Physical Address Space */ +/* Virtio MMIO mappings */ +#define GUEST_VIRTIO_MMIO_BASE xen_mk_ullong(0x02000000) +#define GUEST_VIRTIO_MMIO_SIZE xen_mk_ullong(0x00100000) +/* * vGIC mappings: Only one set of mapping is used by the guest. * Therefore they can overlap. @@ -493,6 +497,9 @@ typedef uint64_t xen_callback_t;#define GUEST_VPL011_SPI 32 +#define GUEST_VIRTIO_MMIO_SPI_FIRST 33 +#define GUEST_VIRTIO_MMIO_SPI_LAST 43 +/* PSCI functions */ #define PSCI_cpu_suspend 0#define PSCI_cpu_off 1Signature · 1 line
2.7.4
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V7 1/2] libxl: Add support for Virtio disk configuration
In reply to Stefano StabelliniOn 19.04.22 00:38, Stefano Stabellini wrote:
Hello Stefano
Quoted 5 lines
Quoted 4 lines
From: Oleksandr Tyshchenko <[email protected]>
This patch adds basic support for configuring and assisting virtio-mmio based virtio-disk backend (emualator) which is intended to run out of
^ emulator
ok)
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V7 2/2] libxl: Introduce basic virtio-mmio support on Arm
In reply to OleksandrQuoted 116 lines · Oleksandr
On 19.04.22 00:41, Stefano Stabellini wrote:
Hello StefanoQuoted 19 lines · Oleksandr Tyshchenko
Quoted 18 lines
From: Julien Grall <[email protected]>
This patch introduces helpers to allocate Virtio MMIO params (IRQ and memory region) and create specific device node in the Guest device-tree with allocated params. In order to deal with multiple Virtio devices, reserve corresponding ranges. For now, we reserve 1MB for memory regions and 10 SPIs.
As these helpers should be used for every Virtio device attached to the Guest, call them for Virtio disk(s).
Please note, with statically allocated Virtio IRQs there is a risk of a clash with a physical IRQs of passthrough devices. For the first version, it's fine, but we should consider allocating the Virtio IRQs automatically. Thankfully, we know in advance which IRQs will be used for passthrough to be able to choose non-clashed ones.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Julien Grall <[email protected]>Signed-off-by Oleksandr Tyshchenko <[email protected]>Tested-by Jiamei Xie <[email protected]>Reviewed-by Henry Wang <[email protected]>I realize that we are at v7 and I haven't reviewed this before, so I'll limit my comments. I'll clarify the ones that I think are more important from the one that are less important.
thank you
Quoted 74 lines
Quoted 74 lines
---
@Jiamei, @Henry I decided to leave your T-b and R-b tags with the minor change I made, are you still happy with that?s/if (disk->virtio)/if (
disk->protocol==LIBXL_DISK_PROTOCOL_VIRTIO_MMIO)Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"Changes RFC -> V1:
- was squashed with:
"[RFC PATCH V1 09/12] libxl: Handle virtio-mmio irq in more correct
way"
"[RFC PATCH V1 11/12] libxl: Insert "dma-coherent" property into
virtio-mmio device node"
"[RFC PATCH V1 12/12] libxl: Fix duplicate memory node in DT"
- move VirtIO MMIO #define-s toxen/include/public/arch-arm.hChanges V1 -> V2:
- update the author of a patchChanges V2 -> V3:
- no changesChanges V3 -> V4:
- no changesChanges V4 -> V5:
- split the changes, change the order of the patches
- drop an extra "virtio" configuration option
- update patch description
- useCONTAINER_OFinstead of own implementation
- reserve ranges for Virtio MMIO params and put them in correct location
- create helpers to allocate Virtio MMIO params, add corresponding sanity-сhecks
- add comment why MMIO size0x200is chosen
- update debug print
- drop Wei's T-bChanges V5 -> V6:
- rebase on current stagingChanges V6 -> V7:
- rebase on current staging
- add T-b and R-b tags
- update according to the recent changes to "libxl: Add support for Virtio disk configuration"--- tools/libs/light/libxl_arm.c | 131 +++++++++++++++++++++++++++++++++++++++++- xen/include/public/arch-arm.h | 7 +++ 2 files changed, 136 insertions(+), 2 deletions(-)tools/libs/light/libxl_arm.c +1
-0@@ -8,6 +8,56 @@#include <assert.h> #include <xen/device_tree_defs.h> +/* +* There is no clear requirements for the total size of Virtio MMIO region.
+ * The size of control registers is0x100and device-specific configuration
+ * registers starts at the offset0x100, however it's size depends on the device
+ * and the driver. Pick the biggest known size at the moment to cover most
+ * of the devices (also consider allowing the user to configure the size viaQuoted 8 lines
Quoted 3 lines
+ * config file for the one not conforming with the proposed value).
+ */
+#defineVIRTIO_MMIO_DEV_SIZExen_mk_ullong(0x200)Actually, I don't think we need to make this generic. We only support virtio-disk now and I think it is fine if this was called
VIRTIO_DISK_MMIO_DEV_SIZEand the size was exactly the size needed by virtio-disk. When/if we support another virtio protocol we can add set the appropriate size of that one as well.
Quoted 5 lines
I would prefer if we keep this generic, although we are going to support virtio-blk as the first virtio-mmio device, there is nothing disk specific in that value. The same value (
0x200) is used
by SW which also generates virtio-mmio device tree nodes like we do in Xen libxl, I am speaking about kvmtool, Qemu here.
OK
RE: [PATCH V7 2/2] libxl: Introduce basic virtio-mmio support on Arm
In reply to Oleksandr TyshchenkoHi Oleksandr,
Quoted 22 lines
-----Original Message-----
From: Oleksandr Tyshchenko <[email protected]>
Subject: [PATCH V7 2/2] libxl: Introduce basic virtio-mmio support on ArmFrom: Julien Grall <[email protected]>
This patch introduces helpers to allocate Virtio MMIO params (IRQ and memory region) and create specific device node in the Guest device-tree with allocated params. In order to deal with multiple Virtio devices, reserve corresponding ranges. For now, we reserve 1MB for memory regions and 10 SPIs.
As these helpers should be used for every Virtio device attached to the Guest, call them for Virtio disk(s).
Please note, with statically allocated Virtio IRQs there is a risk of a clash with a physical IRQs of passthrough devices. For the first version, it's fine, but we should consider allocating the Virtio IRQs automatically. Thankfully, we know in advance which IRQs will be used for passthrough to be able to choose non-clashed ones.
Quoted 7 lines
Signed-off-by Julien Grall <[email protected]>Signed-off-by Oleksandr Tyshchenko <[email protected]>Tested-by Jiamei Xie <[email protected]>Reviewed-by Henry Wang <[email protected]>---
@Jiamei, @Henry I decided to leave your T-b and R-b tags with the minor change I made, are you still happy with that?
Sorry for the late response, just checked the code and yes I am happy with keeping my Reviewed-by. Thanks for your effort in rebasing the patch!
Kind regards,
Henry
Re: [PATCH V7 2/2] libxl: Introduce basic virtio-mmio support on Arm
Quoted 1 line · Henry Wang
Hi Oleksandr,
Hi Henry
Quoted 30 lines
Quoted 23 lines
-----Original Message-----
From: Oleksandr Tyshchenko <[email protected]>
Subject: [PATCH V7 2/2] libxl: Introduce basic virtio-mmio support on ArmFrom: Julien Grall <[email protected]>
This patch introduces helpers to allocate Virtio MMIO params (IRQ and memory region) and create specific device node in the Guest device-tree with allocated params. In order to deal with multiple Virtio devices, reserve corresponding ranges. For now, we reserve 1MB for memory regions and 10 SPIs.
As these helpers should be used for every Virtio device attached to the Guest, call them for Virtio disk(s).
Please note, with statically allocated Virtio IRQs there is a risk of a clash with a physical IRQs of passthrough devices. For the first version, it's fine, but we should consider allocating the Virtio IRQs automatically. Thankfully, we know in advance which IRQs will be used for passthrough to be able to choose non-clashed ones.
Quoted 7 lines
Signed-off-by Julien Grall <[email protected]>Signed-off-by Oleksandr Tyshchenko <[email protected]>Tested-by Jiamei Xie <[email protected]>Reviewed-by Henry Wang <[email protected]>---
@Jiamei, @Henry I decided to leave your T-b and R-b tags with the minor change I made, are you still happy with that?
Quoted 2 lines
Sorry for the late response, just checked the code and yes I am happy with keeping my Reviewed-by. Thanks for your effort in rebasing the patch!
Thank you for confirming! Note that I will have to drop tags for the next version due to non-minor changes I am currently making to address review comments.
Quoted 3 lines
Kind regards,
Henry
Signature · 3 lines
Regards, Oleksandr Tyshchenko
RE: [PATCH V7 2/2] libxl: Introduce basic virtio-mmio support on Arm
In reply to Oleksandr TyshchenkoHi Oleksandr,
I am happy to keep my T-b tag. I have tested this latest patch series and it works.
Regards,
Jiamei Xie
Quoted 308 lines
-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Oleksandr Tyshchenko
Sent: 2022年4月9日 2:21
To: [email protected]
Cc: Julien Grall <[email protected]>; Wei Liu <[email protected]>; Anthony PERARD <[email protected]>; Juergen Gross <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>; Bertrand Marquis <[email protected]>; Volodymyr Babchuk <[email protected]>; Jiamei Xie <[email protected]>; Henry Wang <[email protected]>; Oleksandr Tyshchenko <[email protected]>
Subject: [PATCH V7 2/2] libxl: Introduce basic virtio-mmio support on ArmFrom: Julien Grall <[email protected]>
This patch introduces helpers to allocate Virtio MMIO params (IRQ and memory region) and create specific device node in the Guest device-tree with allocated params. In order to deal with multiple Virtio devices, reserve corresponding ranges. For now, we reserve 1MB for memory regions and 10 SPIs.
As these helpers should be used for every Virtio device attached to the Guest, call them for Virtio disk(s).
Please note, with statically allocated Virtio IRQs there is a risk of a clash with a physical IRQs of passthrough devices. For the first version, it's fine, but we should consider allocating the Virtio IRQs automatically. Thankfully, we know in advance which IRQs will be used for passthrough to be able to choose non-clashed ones.
Signed-off-by Julien Grall <[email protected]>Signed-off-by Oleksandr Tyshchenko <[email protected]>Tested-by Jiamei Xie <[email protected]>Reviewed-by Henry Wang <[email protected]>---
@Jiamei, @Henry I decided to leave your T-b and R-b tags with the minor change I made, are you still happy with that?s/if (disk->virtio)/if (
disk->protocol==LIBXL_DISK_PROTOCOL_VIRTIO_MMIO)Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"Changes RFC -> V1:
- was squashed with:
"[RFC PATCH V1 09/12] libxl: Handle virtio-mmio irq in more correct way" "[RFC PATCH V1 11/12] libxl: Insert "dma-coherent" property into virtio-
mmio device node"
"[RFC PATCH V1 12/12] libxl: Fix duplicate memory node in DT"
- move VirtIO MMIO #define-s toxen/include/public/arch-arm.hChanges V1 -> V2:
- update the author of a patchChanges V2 -> V3:
- no changesChanges V3 -> V4:
- no changesChanges V4 -> V5:
- split the changes, change the order of the patches
- drop an extra "virtio" configuration option
- update patch description
- useCONTAINER_OFinstead of own implementation
- reserve ranges for Virtio MMIO params and put them in correct location
- create helpers to allocate Virtio MMIO params, add corresponding sanity-сhecks
- add comment why MMIO size0x200is chosen
- update debug print
- drop Wei's T-bChanges V5 -> V6:
- rebase on current stagingChanges V6 -> V7:
- rebase on current staging
- add T-b and R-b tags
- update according to the recent changes to "libxl: Add support for Virtio disk configuration"--- tools/libs/light/libxl_arm.c | 131 +++++++++++++++++++++++++++++++++++++++++- xen/include/public/arch-arm.h | 7 +++ 2 files changed, 136 insertions(+), 2 deletions(-)tools/libs/light/libxl_arm.c +4
-0@@ -8,6 +8,56 @@#include <assert.h> #include <xen/device_tree_defs.h> +/* +* There is no clear requirements for the total size of Virtio MMIO region. +* The size of control registers is 0x100 and device-specific configuration +* registers starts at the offset 0x100, however it's size depends on the device
+ * and the driver. Pick the biggest known size at the moment to cover most
+ * of the devices (also consider allowing the user to configure the size via
+ * config file for the one not conforming with the proposed value).
+ */tools/libs/light/libxl_arm.c +19
-0+#define VIRTIO_MMIO_DEV_SIZE xen_mk_ullong(0x200) + +static uint64_t virtio_mmio_base; +static uint32_t virtio_mmio_irq; + +static void init_virtio_mmio_params (void ) +{ + virtio_mmio_base =GUEST_VIRTIO_MMIO_BASE ; + virtio_mmio_irq =GUEST_VIRTIO_MMIO_SPI_FIRST ; +} + +static uint64_t alloc_virtio_mmio_base (libxl__gc *gc) +{ +uint64_t base = virtio_mmio_base; + +/* Make sure we have enough reserved resources */ +if ((virtio_mmio_base +VIRTIO_MMIO_DEV_SIZE > +GUEST_VIRTIO_MMIO_BASE +GUEST_VIRTIO_MMIO_SIZE )) { + LOG(ERROR, "Ran out of reserved range for Virtio MMIO BASE0x%"PRIx64"\n",
tools/libs/light/libxl_arm.c +27
-2+ virtio_mmio_base); +return 0 ; + } + virtio_mmio_base +=VIRTIO_MMIO_DEV_SIZE ; + +return base; +} + +static uint32_t alloc_virtio_mmio_irq (libxl__gc *gc) +{ +uint32_t irq = virtio_mmio_irq; + +/* Make sure we have enough reserved resources */ +if (virtio_mmio_irq >GUEST_VIRTIO_MMIO_SPI_LAST ) { +LOG (ERROR ,"Ran out of reserved range for Virtio MMIO IRQ %u\n" , + virtio_mmio_irq); +return 0 ; + } + virtio_mmio_irq++; + +return irq; +} +static const char *gicv_to_string (libxl_gic_version gic_version) {switch (gic_version) {@@ -26,8 +76,8 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, {uint32_t nr_spis =0 ;unsigned int i; -uint32_t vuart_irq; -bool vuart_enabled = false; +uint32_t vuart_irq, virtio_irq =0 ; +bool vuart_enabled = false, virtio_enabled = false;/* * If pl011 vuart is enabled then increment the nr_spis to allow allocation @@ -39,6 +89,35 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, vuart_enabled = true; } +/* +* Virtio MMIO params are non-unique across the whole system and must be
tools/libs/light/libxl_arm.c +20
-0+* initialized for every new guest. +*/ +init_virtio_mmio_params (); +for (i =0 ; i < d_config->num_disks; i++) { +libxl_device_disk *disk = &d_config->disks[i]; + +if (disk->protocol ==LIBXL_DISK_PROTOCOL_VIRTIO_MMIO ) { + disk->base =alloc_virtio_mmio_base (gc); +if (!disk->base) +return ERROR_FAIL ; + + disk->irq =alloc_virtio_mmio_irq (gc); +if (!disk->irq) +return ERROR_FAIL ; + +if (virtio_irq < disk->irq) + virtio_irq = disk->irq; + virtio_enabled = true; + + LOG(DEBUG, "Allocate Virtio MMIO params for Vdev %s: IRQ %uBASE 0x%"PRIx64,
tools/libs/light/libxl_arm.c +47
-0+ disk->vdev, disk->irq, disk->base); + } + } + +if (virtio_enabled) + nr_spis += (virtio_irq -32 ) +1 ; +for (i =0 ; i < d_config->b_info.num_irqs; i++) {uint32_t irq = d_config->b_info.irqs[i];uint32_t spi;@@ -58,6 +137,13 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,return ERROR_FAIL ; } +/* The same check as for vpl011 */ +if (virtio_enabled && + (irq >=GUEST_VIRTIO_MMIO_SPI_FIRST && irq <= virtio_irq)) { +LOG (ERROR ,"Physical IRQ %u conflicting with Virtio MMIO IRQ range\n", irq); +return ERROR_FAIL ; + } +if (irq <32 )continue ;@@ -787,6 +873,39 @@ static int make_vpci_node(libxl__gc *gc, void *fdt,return 0 ; } + +static int make_virtio_mmio_node (libxl__gc *gc,void *fdt, +uint64_t base,uint32_t irq) +{ +int res; +gic_interrupt intr; +/* Placeholder for virtio@ + a 64-bit number + \0 */ +char buf[24 ]; + +snprintf (buf,sizeof (buf),"virtio@%" PRIx64, base); + res =fdt_begin_node (fdt, buf); +if (res)return res; + + res =fdt_property_compat (gc, fdt,1 ,"virtio,mmio" ); +if (res)return res; + + res =fdt_property_regs (gc, fdt,GUEST_ROOT_ADDRESS_CELLS ,GUEST_ROOT_SIZE_CELLS , +1 , base,VIRTIO_MMIO_DEV_SIZE ); +if (res)return res; + +set_interrupt (intr, irq,0xf ,DT_IRQ_TYPE_EDGE_RISING ); + res =fdt_property_interrupts (gc, fdt, &intr,1 ); +if (res)return res; + + res =fdt_property (fdt,"dma-coherent" ,NULL ,0 ); +if (res)return res; + + res =fdt_end_node (fdt); +if (res)return res; + +return 0 ; +} +static const struct arch_info *get_arch_info (libxl__gc *gc,const struct xc_dom_image *dom){
tools/libs/light/libxl_arm.c +1
-0@@ -988,6 +1107,7 @@ static int libxl__prepare_dtb(libxl__gc *gc,libxl_domain_config *d_config, size_t fdt_size = 0;int pfdt_size =0 ;libxl_domain_build_info *const info = &d_config->b_info; +unsigned int i;const libxl_version_info *vers;const struct arch_info *ainfo;tools/libs/light/libxl_arm.c +7
-0@@ -1094,6 +1214,13 @@ next_resize:if (d_config->num_pcidevs)FDT (make_vpci_node (gc, fdt, ainfo, dom) ); +for (i =0 ; i < d_config->num_disks; i++) { +libxl_device_disk *disk = &d_config->disks[i]; + +if (disk->protocol ==LIBXL_DISK_PROTOCOL_VIRTIO_MMIO ) +FDT (make_virtio_mmio_node (gc, fdt, disk->base, disk->irq) ); + } +if (pfdt)FDT (copy_partial_fdt (gc, fdt, pfdt) );xen/include/public/arch-arm.h +7
-1@@ -407,6 +407,10 @@ typedef uint64_t xen_callback_t;/* Physical Address Space */ +/* Virtio MMIO mappings */ +#define GUEST_VIRTIO_MMIO_BASE xen_mk_ullong(0x02000000) +#define GUEST_VIRTIO_MMIO_SIZE xen_mk_ullong(0x00100000) +/* * vGIC mappings: Only one set of mapping is used by the guest. * Therefore they can overlap. @@ -493,6 +497,9 @@ typedef uint64_t xen_callback_t;#define GUEST_VPL011_SPI 32 +#define GUEST_VIRTIO_MMIO_SPI_FIRST 33 +#define GUEST_VIRTIO_MMIO_SPI_LAST 43 +/* PSCI functions */ #define PSCI_cpu_suspend 0#define PSCI_cpu_off 1 --2.7.4
Re: [PATCH V7 1/2] libxl: Add support for Virtio disk configuration
In reply to Oleksandr TyshchenkoQuoted 131 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
This patch adds basic support for configuring and assisting virtio-mmio based virtio-disk backend (emualator) which is intended to run out of Qemu and could be run in any domain.
Although the Virtio block device is quite different from traditional Xen PV block device (vbd) from the toolstack's point of view:
- as the frontend is virtio-blk which is not a Xenbus driver, nothing written to Xenstore are fetched by the frontend (the vdev is not passed to the frontend)
- the ring-ref/event-channel are not used for the backend<->frontend communication, the proposed IPC for Virtio is IOREQ/DM
it is still a "block device" and ought to be integrated in existing "disk" handling. So, re-use (and adapt) "disk" parsing/configuration logic to deal with Virtio devices as well.For the immediate purpose and an ability to extend that support for other use-cases in future (Qemu, virtio-pci, etc) perform the following actions:
- Add new disk backend type (LIBXL_DISK_BACKEND_OTHER) and reflect that in the configuration
- Introduce new disk protocol field tolibxl_device_diskstruct (withLIBXL_DISK_PROTOCOL_XENandLIBXL_DISK_PROTOCOL_VIRTIO_MMIOtypes) and reflect that in the configuration (new "protocol" option with "xen" protocol being default value)
- Add new device kind (LIBXL__DEVICE_KIND_VIRTIO_DISK) as current one (LIBXL__DEVICE_KIND_VBD) doesn't fit into Virtio disk modelAn example of domain configuration for Virtio disk:
disk = [ 'phy:/dev/mmcblk0p3, xvda1, backendtype=other, protocol=virtio-mmio']Nothing has changed for default Xen disk configuration.
Please note, this patch is not enough for virtio-disk to work on Xen (Arm), as for every Virtio device (including disk) we need to allocate Virtio MMIO params (IRQ and memory region) and pass them to the backend, also update Guest device-tree. The subsequent patch will add these missing bits. For the current patch, the default "irq" and "base" are just written to the Xenstore. This is not an ideal splitting, but this way we avoid breaking the bisectability.
Signed-off-by Oleksandr Tyshchenko <[email protected]>---
Changes RFC -> V1:
- no changesChanges V1 -> V2:
- rebase according to the new location oflibxl_virtio_disk.cChanges V2 -> V3:
- no changesChanges V3 -> V4:
- rebase according to the new argument forDEFINE_DEVICE_TYPE_STRUCTChanges V4 -> V5:
- split the changes, change the order of the patches
- update patch description
- don't introduce new "vdisk" configuration option with own parsing logic, re-use Xen PV block "disk" parsing/configuration logic for the virtio-disk
- introduce "virtio" flag and document it's usage
- addLIBXL_HAVE_DEVICE_DISK_VIRTIO
- update libxlu_disk_l.[ch]
- dropnum_disksvariable/MAX_VIRTIO_DISKS
- drop Wei's T-bChanges V5 -> V6:
- rebase on current staging
- use "%"PRIu64 instead of %lu fordisk->baseindevice_disk_add()
- update *.gen.go filesChanges V6 -> V7:
- rebase on current staging
- update *.gen.go files and libxlu_disk_l.[ch] files
- update patch description
- rework significantly to support more flexible configuration and have more generic basic implementation for being able to extend that for other use-cases (virtio-pci, qemu, etc).--- docs/man/xl-disk-configuration.5.pod.in | 37 +- tools/golang/xenlight/helpers.gen.go | 6 + tools/golang/xenlight/types.gen.go | 11 + tools/include/libxl.h | 6 + tools/libs/light/libxl_device.c | 57 +- tools/libs/light/libxl_disk.c | 111 +++- tools/libs/light/libxl_internal.h | 1 + tools/libs/light/libxl_types.idl | 10 + tools/libs/light/libxl_types_internal.idl | 1 + tools/libs/light/libxl_utils.c | 2 + tools/libs/util/libxlu_disk_l.c | 952 +++++++++++++++--------------- tools/libs/util/libxlu_disk_l.h | 2 +- tools/libs/util/libxlu_disk_l.l | 9 + tools/xl/xl_block.c | 11 + 14 files changed, 736 insertions(+), 480 deletions(-)docs/man/xl-disk-configuration.5.pod.in +7
-4@@ -232,7 +232,7 @@ Specifies the backend implementation to use =item Supported values -phy, qdisk +phy, qdisk, other =item Mandatory@@ -244,11 +244,13 @@ Automatically determine which backend to use. =back -This does not affect the guest's view of the device. It controls -which software implementation of the Xen backend driver is used. +It controls which software implementation of the backend driver is used. +Depending on the "protocol" option this may affect the guest's view +of the device. Not all backend drivers support all combinations of other options. -For example, "phy" does not support formats other than "raw". +For example, "phy" and "other" do not support formats other than "raw" and +"other" does not support protocols other than "virtio-mmio". Normally this option should not be specified, in which case libxl will automatically determine the most suitable backend.@@ -344,8 +346,35 @@ can be used to disable "hole punching" for file based backends which were intentionally created non-sparse to avoid fragmentation of the file. +=item B<protocol>=I<PROTOCOL>
docs/man/xl-disk-configuration.5.pod.in can be used to disable "hole punching" for file based backends which · line 359
Quoted 10 lines
docs/man/xl-disk-configuration.5.pod.in +10
-0+ +=over 4 + +=item Description + +Specifies the communication protocol to use for the chosen "backendtype" option + +=item Supported values + +xen, virtio-mmio
From a user PoV, I think it would be better to just select xen or virtio here, but not the underlying configuration mechanism used to expose the devices to the guest.
We would likely need to add a different option to select mmio or pci then, but that should be set by default based on architecture/guest type. For example on x86 it should default to pci, while on Arm I guess it will depend on whether the guest has PCI or not?
In any case, I think we should offer an option that's selecting between xen or virtio protocol, and the way to expose the configuration of the device shouldn't need to be explicitly selected by the user.
Thanks, Roger.
Re: [PATCH V7 2/2] libxl: Introduce basic virtio-mmio support on Arm
In reply to Jiamei XieQuoted 2 lines · Jiamei Xie
Hi Oleksandr,
Hi Jiamei
[Sorry for the possible format issues]
Quoted 3 lines
I am happy to keep my T-b tag. I have tested this latest patch series
and it works.
Thank you for the testing and confirmation!
Quoted 328 lines
Regards,
Jiamei XieQuoted 8 lines
-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Oleksandr Tyshchenko
Sent: 2022年4月9日 2:21
To: [email protected]
Cc: Julien Grall <[email protected]>; Wei Liu <[email protected]>; Anthony PERARD <[email protected]>; Juergen Gross <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <Quoted 28 lines
Bertrand Marquis <[email protected]>; Volodymyr Babchuk <[email protected]>; Jiamei Xie <[email protected]>; Henry Wang <[email protected]>; Oleksandr Tyshchenko <[email protected]>
Subject: [PATCH V7 2/2] libxl: Introduce basic virtio-mmio support on ArmFrom: Julien Grall <[email protected]>
This patch introduces helpers to allocate Virtio MMIO params (IRQ and memory region) and create specific device node in the Guest device-tree with allocated params. In order to deal with multiple Virtio devices, reserve corresponding ranges. For now, we reserve 1MB for memory regions and 10 SPIs.
As these helpers should be used for every Virtio device attached to the Guest, call them for Virtio disk(s).
Please note, with statically allocated Virtio IRQs there is a risk of a clash with a physical IRQs of passthrough devices. For the first version, it's fine, but we should consider allocating the Virtio IRQs automatically. Thankfully, we know in advance which IRQs will be used for passthrough to be able to choose non-clashed ones.
Signed-off-by Julien Grall <[email protected]>Signed-off-by Oleksandr Tyshchenko <[email protected]>Tested-by Jiamei Xie <[email protected]>Reviewed-by Henry Wang <[email protected]>Quoted 5 lines
---
@Jiamei, @Henry I decided to leave your T-b and R-b tags with the minor change I made, are you still happy with that?s/if (disk->virtio)/if (
disk->protocol==
LIBXL_DISK_PROTOCOL_VIRTIO_MMIO)Quoted 7 lines
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"Changes RFC -> V1:
- was squashed with:
"[RFC PATCH V1 09/12] libxl: Handle virtio-mmio irq in more correctway"
Quoted 1 line
"[RFC PATCH V1 11/12] libxl: Insert "dma-coherent" property into
virtio-
Quoted 45 lines
mmio device node"
"[RFC PATCH V1 12/12] libxl: Fix duplicate memory node in DT"
- move VirtIO MMIO #define-s toxen/include/public/arch-arm.hChanges V1 -> V2:
- update the author of a patchChanges V2 -> V3:
- no changesChanges V3 -> V4:
- no changesChanges V4 -> V5:
- split the changes, change the order of the patches
- drop an extra "virtio" configuration option
- update patch description
- useCONTAINER_OFinstead of own implementation
- reserve ranges for Virtio MMIO params and put them in correct location
- create helpers to allocate Virtio MMIO params, add corresponding sanity-сhecks
- add comment why MMIO size0x200is chosen
- update debug print
- drop Wei's T-bChanges V5 -> V6:
- rebase on current stagingChanges V6 -> V7:
- rebase on current staging
- add T-b and R-b tags
- update according to the recent changes to "libxl: Add support for Virtio disk configuration"--- tools/libs/light/libxl_arm.c | 131 +++++++++++++++++++++++++++++++++++++++++- xen/include/public/arch-arm.h | 7 +++ 2 files changed, 136 insertions(+), 2 deletions(-)tools/libs/light/libxl_arm.c +0
-0tools/libs/light/libxl_arm.c line 12
Quoted 5 lines
tools/libs/light/libxl_arm.c +2
-0@@ -8,6 +8,56 @@#include <assert.h> #include <xen/device_tree_defs.h> +/* +* There is no clear requirements for the total size of Virtio MMIO region.
tools/libs/light/libxl_arm.c line 13
Quoted 1 line
tools/libs/light/libxl_arm.c +1
-0+* The size of control registers is 0x100 and device-specific configuration
tools/libs/light/libxl_arm.c line 14
Quoted 1 line
tools/libs/light/libxl_arm.c +1
-0+* registers starts at the offset 0x100, however it's size depends on the
Quoted 2 lines
device
+ * and the driver. Pick the biggest known size at the moment to covermost
Quoted 1 line
+ * of the devices (also consider allowing the user to configure the
size via
Quoted 49 lines
+ * config file for the one not conforming with the proposed value).
+ */tools/libs/light/libxl_arm.c +19
-0+#define VIRTIO_MMIO_DEV_SIZE xen_mk_ullong(0x200) + +static uint64_t virtio_mmio_base; +static uint32_t virtio_mmio_irq; + +static void init_virtio_mmio_params (void ) +{ + virtio_mmio_base =GUEST_VIRTIO_MMIO_BASE ; + virtio_mmio_irq =GUEST_VIRTIO_MMIO_SPI_FIRST ; +} + +static uint64_t alloc_virtio_mmio_base (libxl__gc *gc) +{ +uint64_t base = virtio_mmio_base; + +/* Make sure we have enough reserved resources */ +if ((virtio_mmio_base +VIRTIO_MMIO_DEV_SIZE > +GUEST_VIRTIO_MMIO_BASE +GUEST_VIRTIO_MMIO_SIZE )) { + LOG(ERROR, "Ran out of reserved range for Virtio MMIO BASE0x%"PRIx64"\n",
tools/libs/light/libxl_arm.c +23
-0+ virtio_mmio_base); +return 0 ; + } + virtio_mmio_base +=VIRTIO_MMIO_DEV_SIZE ; + +return base; +} + +static uint32_t alloc_virtio_mmio_irq (libxl__gc *gc) +{ +uint32_t irq = virtio_mmio_irq; + +/* Make sure we have enough reserved resources */ +if (virtio_mmio_irq >GUEST_VIRTIO_MMIO_SPI_LAST ) { +LOG (ERROR ,"Ran out of reserved range for Virtio MMIO IRQ %u\n" , + virtio_mmio_irq); +return 0 ; + } + virtio_mmio_irq++; + +return irq; +} +static const char *gicv_to_string (libxl_gic_version gic_version) {switch (gic_version) {tools/libs/light/libxl_arm.c int libxl__arch_domain_prepare_config(libxl__gc *gc, · line 83
Quoted 10 lines
tools/libs/light/libxl_arm.c +2
-2@@ -26,8 +76,8 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, {uint32_t nr_spis =0 ;unsigned int i; -uint32_t vuart_irq; -bool vuart_enabled = false; +uint32_t vuart_irq, virtio_irq =0 ; +bool vuart_enabled = false, virtio_enabled = false;/* * If pl011 vuart is enabled then increment the nr_spis to allow allocation
Quoted 83 lines
tools/libs/light/libxl_arm.c +2
-0@@ -39,6 +89,35 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, vuart_enabled = true; } +/* +* Virtio MMIO params are non-unique across the whole system and must be
tools/libs/light/libxl_arm.c +20
-0+* initialized for every new guest. +*/ +init_virtio_mmio_params (); +for (i =0 ; i < d_config->num_disks; i++) { +libxl_device_disk *disk = &d_config->disks[i]; + +if (disk->protocol ==LIBXL_DISK_PROTOCOL_VIRTIO_MMIO ) { + disk->base =alloc_virtio_mmio_base (gc); +if (!disk->base) +return ERROR_FAIL ; + + disk->irq =alloc_virtio_mmio_irq (gc); +if (!disk->irq) +return ERROR_FAIL ; + +if (virtio_irq < disk->irq) + virtio_irq = disk->irq; + virtio_enabled = true; + + LOG(DEBUG, "Allocate Virtio MMIO params for Vdev %s: IRQ %uBASE 0x%"PRIx64,
tools/libs/light/libxl_arm.c +39
-0+ disk->vdev, disk->irq, disk->base); + } + } + +if (virtio_enabled) + nr_spis += (virtio_irq -32 ) +1 ; +for (i =0 ; i < d_config->b_info.num_irqs; i++) {uint32_t irq = d_config->b_info.irqs[i];uint32_t spi;@@ -58,6 +137,13 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,return ERROR_FAIL ; } +/* The same check as for vpl011 */ +if (virtio_enabled && + (irq >=GUEST_VIRTIO_MMIO_SPI_FIRST && irq <= virtio_irq)) { +LOG (ERROR ,"Physical IRQ %u conflicting with Virtio MMIO IRQ range\n", irq); +return ERROR_FAIL ; + } +if (irq <32 )continue ;@@ -787,6 +873,39 @@ static int make_vpci_node(libxl__gc *gc, void *fdt,return 0 ; } + +static int make_virtio_mmio_node (libxl__gc *gc,void *fdt, +uint64_t base,uint32_t irq) +{ +int res; +gic_interrupt intr; +/* Placeholder for virtio@ + a 64-bit number + \0 */ +char buf[24 ]; + +snprintf (buf,sizeof (buf),"virtio@%" PRIx64, base); + res =fdt_begin_node (fdt, buf); +if (res)return res; + + res =fdt_property_compat (gc, fdt,1 ,"virtio,mmio" ); +if (res)return res; + + res =fdt_property_regs (gc, fdt,GUEST_ROOT_ADDRESS_CELLS ,GUEST_ROOT_SIZE_CELLS , +1 , base,VIRTIO_MMIO_DEV_SIZE ); +if (res)return res; + +set_interrupt (intr, irq,0xf ,DT_IRQ_TYPE_EDGE_RISING ); + res =fdt_property_interrupts (gc, fdt, &intr,1 ); +if (res)return res; + + res =fdt_property (fdt,"dma-coherent" ,NULL ,0 );tools/libs/light/libxl_arm.c static int make_vpci_node(libxl__gc *gc, void *fdt, · line 911
Quoted 10 lines
tools/libs/light/libxl_arm.c +8
-0+if (res)return res; + + res =fdt_end_node (fdt); +if (res)return res; + +return 0 ; +} +static const struct arch_info *get_arch_info (libxl__gc *gc, const struct xc_dom_image*dom)
Quoted 11 lines
{
tools/libs/light/libxl_arm.c +1
-0@@ -988,6 +1107,7 @@ static int libxl__prepare_dtb(libxl__gc *gc,libxl_domain_config *d_config, size_t fdt_size = 0;int pfdt_size =0 ;libxl_domain_build_info *const info = &d_config->b_info; +unsigned int i;const libxl_version_info *vers;const struct arch_info *ainfo;tools/libs/light/libxl_arm.c next_resize: · line 1221
Quoted 8 lines
tools/libs/light/libxl_arm.c +5
-0@@ -1094,6 +1214,13 @@ next_resize:if (d_config->num_pcidevs)FDT (make_vpci_node (gc, fdt, ainfo, dom) ); +for (i =0 ; i < d_config->num_disks; i++) { +libxl_device_disk *disk = &d_config->disks[i]; + +if (disk->protocol ==LIBXL_DISK_PROTOCOL_VIRTIO_MMIO ) + FDT( make_virtio_mmio_node(gc, fdt, disk->base,
disk->irq) );Review
Quoted 6 lines
tools/libs/light/libxl_arm.c +2
-0+ } +if (pfdt)FDT (copy_partial_fdt (gc, fdt, pfdt) );(quoted diff) +0
-0
b/xen/include/public/arch-arm.hQuoted 27 lines
index ab05fe1..c8b6058 100644
xen/include/public/arch-arm.h +7
-1@@ -407,6 +407,10 @@ typedef uint64_t xen_callback_t;/* Physical Address Space */ +/* Virtio MMIO mappings */ +#define GUEST_VIRTIO_MMIO_BASE xen_mk_ullong(0x02000000) +#define GUEST_VIRTIO_MMIO_SIZE xen_mk_ullong(0x00100000) +/* * vGIC mappings: Only one set of mapping is used by the guest. * Therefore they can overlap. @@ -493,6 +497,9 @@ typedef uint64_t xen_callback_t;#define GUEST_VPL011_SPI 32 +#define GUEST_VIRTIO_MMIO_SPI_FIRST 33 +#define GUEST_VIRTIO_MMIO_SPI_LAST 43 +/* PSCI functions */ #define PSCI_cpu_suspend 0#define PSCI_cpu_off 1 --2.7.4
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V7 1/2] libxl: Add support for Virtio disk configuration
In reply to Roger Pau MonnéOn 22.04.22 12:41, Roger Pau Monné wrote:
Hello Roger
Quoted 131 lines · Oleksandr Tyshchenko
Quoted 130 lines
From: Oleksandr Tyshchenko <[email protected]>
This patch adds basic support for configuring and assisting virtio-mmio based virtio-disk backend (emualator) which is intended to run out of Qemu and could be run in any domain.
Although the Virtio block device is quite different from traditional Xen PV block device (vbd) from the toolstack's point of view:
- as the frontend is virtio-blk which is not a Xenbus driver, nothing written to Xenstore are fetched by the frontend (the vdev is not passed to the frontend)
- the ring-ref/event-channel are not used for the backend<->frontend communication, the proposed IPC for Virtio is IOREQ/DM
it is still a "block device" and ought to be integrated in existing "disk" handling. So, re-use (and adapt) "disk" parsing/configuration logic to deal with Virtio devices as well.For the immediate purpose and an ability to extend that support for other use-cases in future (Qemu, virtio-pci, etc) perform the following actions:
- Add new disk backend type (LIBXL_DISK_BACKEND_OTHER) and reflect that in the configuration
- Introduce new disk protocol field tolibxl_device_diskstruct (withLIBXL_DISK_PROTOCOL_XENandLIBXL_DISK_PROTOCOL_VIRTIO_MMIOtypes) and reflect that in the configuration (new "protocol" option with "xen" protocol being default value)
- Add new device kind (LIBXL__DEVICE_KIND_VIRTIO_DISK) as current one (LIBXL__DEVICE_KIND_VBD) doesn't fit into Virtio disk modelAn example of domain configuration for Virtio disk:
disk = [ 'phy:/dev/mmcblk0p3, xvda1, backendtype=other, protocol=virtio-mmio']Nothing has changed for default Xen disk configuration.
Please note, this patch is not enough for virtio-disk to work on Xen (Arm), as for every Virtio device (including disk) we need to allocate Virtio MMIO params (IRQ and memory region) and pass them to the backend, also update Guest device-tree. The subsequent patch will add these missing bits. For the current patch, the default "irq" and "base" are just written to the Xenstore. This is not an ideal splitting, but this way we avoid breaking the bisectability.
Signed-off-by Oleksandr Tyshchenko <[email protected]>---
Changes RFC -> V1:
- no changesChanges V1 -> V2:
- rebase according to the new location oflibxl_virtio_disk.cChanges V2 -> V3:
- no changesChanges V3 -> V4:
- rebase according to the new argument forDEFINE_DEVICE_TYPE_STRUCTChanges V4 -> V5:
- split the changes, change the order of the patches
- update patch description
- don't introduce new "vdisk" configuration option with own parsing logic, re-use Xen PV block "disk" parsing/configuration logic for the virtio-disk
- introduce "virtio" flag and document it's usage
- addLIBXL_HAVE_DEVICE_DISK_VIRTIO
- update libxlu_disk_l.[ch]
- dropnum_disksvariable/MAX_VIRTIO_DISKS
- drop Wei's T-bChanges V5 -> V6:
- rebase on current staging
- use "%"PRIu64 instead of %lu fordisk->baseindevice_disk_add()
- update *.gen.go filesChanges V6 -> V7:
- rebase on current staging
- update *.gen.go files and libxlu_disk_l.[ch] files
- update patch description
- rework significantly to support more flexible configuration and have more generic basic implementation for being able to extend that for other use-cases (virtio-pci, qemu, etc).--- docs/man/xl-disk-configuration.5.pod.in | 37 +- tools/golang/xenlight/helpers.gen.go | 6 + tools/golang/xenlight/types.gen.go | 11 + tools/include/libxl.h | 6 + tools/libs/light/libxl_device.c | 57 +- tools/libs/light/libxl_disk.c | 111 +++- tools/libs/light/libxl_internal.h | 1 + tools/libs/light/libxl_types.idl | 10 + tools/libs/light/libxl_types_internal.idl | 1 + tools/libs/light/libxl_utils.c | 2 + tools/libs/util/libxlu_disk_l.c | 952 +++++++++++++++--------------- tools/libs/util/libxlu_disk_l.h | 2 +- tools/libs/util/libxlu_disk_l.l | 9 + tools/xl/xl_block.c | 11 + 14 files changed, 736 insertions(+), 480 deletions(-)docs/man/xl-disk-configuration.5.pod.in +6
-4@@ -232,7 +232,7 @@ Specifies the backend implementation to use =item Supported values -phy, qdisk +phy, qdisk, other =item Mandatory@@ -244,11 +244,13 @@ Automatically determine which backend to use. =back -This does not affect the guest's view of the device. It controls -which software implementation of the Xen backend driver is used. +It controls which software implementation of the backend driver is used. +Depending on the "protocol" option this may affect the guest's view +of the device. Not all backend drivers support all combinations of other options. -For example, "phy" does not support formats other than "raw". +For example, "phy" and "other" do not support formats other than "raw" and +"other" does not support protocols other than "virtio-mmio". Normally this option should not be specified, in which case libxl will automatically determine the most suitable backend.@@ -344,8 +346,35 @@ can be used to disable "hole punching" for file based backends which were intentionally created non-sparse to avoid fragmentation of the file.
Quoted 14 lines
docs/man/xl-disk-configuration.5.pod.in can be used to disable "hole punching" for file based backends which · line 359
Quoted 11 lines
docs/man/xl-disk-configuration.5.pod.in +11
-0+=item B<protocol>=I<PROTOCOL> + +=over 4 + +=item Description + +Specifies the communication protocol to use for the chosen "backendtype" option + +=item Supported values + +xen, virtio-mmioFrom a user PoV, I think it would be better to just select xen or
virtio here, but not the underlying configuration mechanism used to expose the devices to the guest.
I got your point.
Quoted 10 lines
We would likely need to add a different option to select mmio or pci then, but that should be set by default based on architecture/guest type. For example on x86 it should default to pci, while on Arm I guess it will depend on whether the guest has PCI or not?
In any case, I think we should offer an option that's selecting between xen or virtio protocol, and the way to expose the configuration of the device shouldn't need to be explicitly selected by the user.
ok, for now I will use "xen and virtio" values for the "protocol" option, then internally toolstack will assume that "virtio" really means "virtio-mmio".
When there is a need to expand that support to "virtio-pci", we will see how to deal with it from the configuration PoV, probably like you suggested above by adding another option (e.g. "transport") with default values based on the architecture/guest type.
Quoted 2 lines
Thanks, Roger.
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V7 1/2] libxl: Add support for Virtio disk configuration
In reply to Oleksandr TyshchenkoQuoted 10 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
This patch adds basic support for configuring and assisting virtio-mmio based virtio-disk backend (emualator) which is intended to run out of Qemu and could be run in any domain.
Although the Virtio block device is quite different from traditional Xen PV block device (vbd) from the toolstack's point of view:
- as the frontend is virtio-blk which is not a Xenbus driver, nothing written to Xenstore are fetched by the frontend (the vdev is not passed to the frontend)
I thought about the future support on x86.
There we don't have a device tree (and I don't want to introduce it), so the only ways to specify the backend domain id would be to:
- add some information to ACPI tables
- use boot parameters
- use Xenstore
Thinking further of hotplugging virtio devices, Xenstore seems to be the only real suitable alternative. Using virtio mechanisms doesn't seem appropriate, as such information should be retrieved in "platform specific" ways (see e.g. specifying an "endpoint" in the virtio IOMMU device [1], [2]). I think the Xenstore information for that purpose could be rather minimal and it should be device-type agnostic. Having just a directory with endpoints and associated backend domids would probably be enough (not needed in this series, of course).
This doesn't preclude the device tree variant you are using, as this would be required for dom0less systems anyway.
OTOH I'd like you to modify the commit message to make it more clear that in future frontend data might be written to Xenstore in order to support other use cases.
Quoted 6 lines
- the ring-ref/event-channel are not used for the backend<->frontend communication, the proposed IPC for Virtio is IOREQ/DM
it is still a "block device" and ought to be integrated in existing "disk" handling. So, re-use (and adapt) "disk" parsing/configuration logic to deal with Virtio devices as well.
Quoted 9 lines
For the immediate purpose and an ability to extend that support for other use-cases in future (Qemu, virtio-pci, etc) perform the following actions:
- Add new disk backend type (LIBXL_DISK_BACKEND_OTHER) and reflect that in the configuration
- Introduce new disk protocol field tolibxl_device_diskstruct (withLIBXL_DISK_PROTOCOL_XENandLIBXL_DISK_PROTOCOL_VIRTIO_MMIOtypes) and reflect that in the configuration (new "protocol" option with "xen" protocol being default value)
And with the hotplug option in mind I start to feel unueasy with naming the new Xenstore node "protocol", as the frontend disk nodes for "normal" disks already have a "protocol" entry specifying 64- or 32-bit protocol.
Maybe we should really name it "transport" instead?
Quoted 5 lines
- Add new device kind (
LIBXL__DEVICE_KIND_VIRTIO_DISK) as current one (LIBXL__DEVICE_KIND_VBD) doesn't fit into Virtio disk modelAn example of domain configuration for Virtio disk:
disk = [ 'phy:/dev/mmcblk0p3, xvda1, backendtype=other, protocol=virtio-mmio']
With Roger's feedback this would then be "transport=virtio", the "mmio" part should then be something like "adapter=mmio" (in contrast to "adapter=pci"), and "adapter" only needed in case of a device tree and PCI being available.
Quoted 12 lines
Nothing has changed for default Xen disk configuration.
Please note, this patch is not enough for virtio-disk to work on Xen (Arm), as for every Virtio device (including disk) we need to allocate Virtio MMIO params (IRQ and memory region) and pass them to the backend, also update Guest device-tree. The subsequent patch will add these missing bits. For the current patch, the default "irq" and "base" are just written to the Xenstore. This is not an ideal splitting, but this way we avoid breaking the bisectability.
Quoted 1 line
Signed-off-by Oleksandr Tyshchenko <[email protected]>
I'm fine with the overall approach and couldn't spot any real issues in the code.
Juergen
[1]: https://github.com/oasis-tcs/virtio-spec/blob/master/virtio-iommu.tex
[2]: https://medium.com/@michael2012zhao_67085/virtio-iommu-789369049443
Re: [PATCH V7 1/2] libxl: Add support for Virtio disk configuration
On 25.04.22 10:43, Juergen Gross wrote:
Hello Juergen
Thank you for the feedback.
Quoted 12 lines · Oleksandr Tyshchenko
Quoted 10 lines
From: Oleksandr Tyshchenko <[email protected]>
This patch adds basic support for configuring and assisting virtio-mmio based virtio-disk backend (emualator) which is intended to run out of Qemu and could be run in any domain.
Although the Virtio block device is quite different from traditional Xen PV block device (vbd) from the toolstack's point of view:
- as the frontend is virtio-blk which is not a Xenbus driver, nothing written to Xenstore are fetched by the frontend (the vdev is not passed to the frontend)
Quoted 8 lines
I thought about the future support on x86.
There we don't have a device tree (and I don't want to introduce it), so the only ways to specify the backend domain id would be to:
- add some information to ACPI tables
- use boot parameters
- use Xenstore
I understand that, and agree
Quoted 8 lines
Thinking further of hotplugging virtio devices, Xenstore seems to be the only real suitable alternative. Using virtio mechanisms doesn't seem appropriate, as such information should be retrieved in "platform specific" ways (see e.g. specifying an "endpoint" in the virtio IOMMU device [1], [2]). I think the Xenstore information for that purpose could be rather minimal and it should be device-type agnostic. Having just a directory with endpoints and associated backend domids would probably be enough (not needed in this series, of course).
Just to make it clear, we are speaking about the possible ways to communicate backend domid for another series [1], so about the x86's alternative of device-tree bindings "xen,dev-domid" [2]. I was thinking we could avoid using Xenstore at the guest side for that purpose, but I didn't think about hotplug...
I assume, all Xenstore bits wouldn't go the outside Xen grant DMA-mapping layer (grant-dma-ops.c)?
Quoted 3 lines
This doesn't preclude the device tree variant you are using, as this would be required for dom0less systems anyway.
good
Quoted 4 lines
OTOH I'd like you to modify the commit message to make it more clear that in future frontend data might be written to Xenstore in order to support other use cases.
ok, will do
Quoted 17 lines
Quoted 7 lines
- the ring-ref/event-channel are not used for the backend<->frontend communication, the proposed IPC for Virtio is IOREQ/DM it is still a "block device" and ought to be integrated in existing "disk" handling. So, re-use (and adapt) "disk" parsing/configuration logic to deal with Virtio devices as well.
Quoted 9 lines
For the immediate purpose and an ability to extend that support for other use-cases in future (Qemu, virtio-pci, etc) perform the following actions:
- Add new disk backend type (LIBXL_DISK_BACKEND_OTHER) and reflect that in the configuration
- Introduce new disk protocol field tolibxl_device_diskstruct (withLIBXL_DISK_PROTOCOL_XENandLIBXL_DISK_PROTOCOL_VIRTIO_MMIOtypes) and reflect that in the configuration (new "protocol" option with "xen" protocol being default value)
Quoted 3 lines
And with the hotplug option in mind I start to feel unueasy with naming the new Xenstore node "protocol", as the frontend disk nodes for "normal" disks already have a "protocol" entry specifying 64- or 32-bit protocol.
I noticed the "protocol" node at the frontend side for traditional Xen PV block device which handles yet another purpose, but I didn't think much about it since the new "protocol" node in only for the backend's use. If we start thinking of frontend's Xenstore nodes, then yes, will clash...
Quoted 3 lines
Maybe we should really name it "transport" instead?
... For me the "transport" name is associated with virtio transports: mmio, pci, ccw. But, I would be ok with that name. Another possible name could be "specification".
Quoted 5 lines
Quoted 5 lines
- Add new device kind (
LIBXL__DEVICE_KIND_VIRTIO_DISK) as current one (LIBXL__DEVICE_KIND_VBD) doesn't fit into Virtio disk model
Quoted 7 lines
Quoted 2 lines
An example of domain configuration for Virtio disk:
disk = [ 'phy:/dev/mmcblk0p3, xvda1, backendtype=other, protocol=virtio-mmio']With Roger's feedback this would then be "transport=virtio", the "mmio" part should then be something like "adapter=mmio" (in contrast to "adapter=pci"), and "adapter" only needed in case of a device tree and PCI being available.
ok, will rename. Can we add "adapter" (or whenever the name would be) option later, when there is a real need? For now, I mean within the current series which adds only virtio-mmio bits on Arm, we can assume that "transport=virtio" implies using virtio-mmio.
BTW, if we named the main option "specification", the secondary option "transport" would good fit from my PoV. For example:
disk = [ 'phy:/dev/mmcblk0p3, xvda1, backendtype=other, specification=virtio, transport=mmio']
But, I am perfectly fine with "transport/adapter".
Quoted 13 lines
Quoted 13 lines
Nothing has changed for default Xen disk configuration.
Please note, this patch is not enough for virtio-disk to work on Xen (Arm), as for every Virtio device (including disk) we need to allocate Virtio MMIO params (IRQ and memory region) and pass them to the backend, also update Guest device-tree. The subsequent patch will add these missing bits. For the current patch, the default "irq" and "base" are just written to the Xenstore. This is not an ideal splitting, but this way we avoid breaking the bisectability.
Quoted 4 lines
Quoted 1 line
Signed-off-by Oleksandr Tyshchenko <[email protected]>I'm fine with the overall approach and couldn't spot any real issues in the code.
Thank you.
[1] https://lore.kernel.org/xen-devel/[email protected]/
[2] https://lore.kernel.org/xen-devel/[email protected]/
https://lore.kernel.org/xen-devel/[email protected]/
Quoted 7 lines
Juergen
[1]: https://github.com/oasis-tcs/virtio-spec/blob/master/virtio-iommu.tex
[2]: https://medium.com/@michael2012zhao_67085/virtio-iommu-789369049443
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V7 1/2] libxl: Add support for Virtio disk configuration
Quoted 42 lines · Oleksandr
On 25.04.22 10:43, Juergen Gross wrote:
Hello Juergen
Thank you for the feedback.
Quoted 12 lines · Oleksandr Tyshchenko
Quoted 10 lines
From: Oleksandr Tyshchenko <[email protected]>
This patch adds basic support for configuring and assisting virtio-mmio based virtio-disk backend (emualator) which is intended to run out of Qemu and could be run in any domain.
Although the Virtio block device is quite different from traditional Xen PV block device (vbd) from the toolstack's point of view:
- as the frontend is virtio-blk which is not a Xenbus driver, nothing written to Xenstore are fetched by the frontend (the vdev is not passed to the frontend)Quoted 8 lines
I thought about the future support on x86.
There we don't have a device tree (and I don't want to introduce it), so the only ways to specify the backend domain id would be to:
- add some information to ACPI tables
- use boot parameters
- use XenstoreI understand that, and agree
Quoted 8 lines
Thinking further of hotplugging virtio devices, Xenstore seems to be the only real suitable alternative. Using virtio mechanisms doesn't seem appropriate, as such information should be retrieved in "platform specific" ways (see e.g. specifying an "endpoint" in the virtio IOMMU device [1], [2]). I think the Xenstore information for that purpose could be rather minimal and it should be device-type agnostic. Having just a directory with endpoints and associated backend domids would probably be enough (not needed in this series, of course).
Quoted 3 lines
Just to make it clear, we are speaking about the possible ways to communicate backend domid for another series [1], so about the x86's alternative of device-tree bindings "xen,dev-domid" [2]. I was thinking we could avoid using Xenstore at the guest side for that purpose, but I didn't think about hotplug...
I assume, all Xenstore bits wouldn't go the outside Xen grant DMA-mapping layer (grant-dma-ops.c)?
I think it would be another driver under drivers/xen/ without the need to touch any other frontend related file or Xen-related architecture specific code.
Quoted 5 lines
Quoted 3 lines
And with the hotplug option in mind I start to feel unueasy with naming the new Xenstore node "protocol", as the frontend disk nodes for "normal" disks already have a "protocol" entry specifying 64- or 32-bit protocol.
Quoted 8 lines
I noticed the "protocol" node at the frontend side for traditional Xen PV block device which handles yet another purpose, but I didn't think much about it since the new "protocol" node in only for the backend's use. If we start thinking of frontend's Xenstore nodes, then yes, will clash...
Quoted 3 lines
Maybe we should really name it "transport" instead?
... For me the "transport" name is associated with virtio transports: mmio, pci, ccw. But, I would be ok with that name. Another possible name could be "specification".
Yeah, looking at the virtio spec this makes sense.
So I would be fine with "specification".
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
- Add new device kind (
LIBXL__DEVICE_KIND_VIRTIO_DISK) as current one (LIBXL__DEVICE_KIND_VBD) doesn't fit into Virtio disk modelAn example of domain configuration for Virtio disk:
disk = [ 'phy:/dev/mmcblk0p3, xvda1, backendtype=other, protocol=virtio-mmio']
Quoted 6 lines
Quoted 4 lines
With Roger's feedback this would then be "transport=virtio", the "mmio" part should then be something like "adapter=mmio" (in contrast to "adapter=pci"), and "adapter" only needed in case of a device tree and PCI being available.
ok, will rename. Can we add "adapter" (or whenever the name would be) option later, when there is a real need? For now, I mean within the current series which adds only virtio-mmio bits on Arm, we can assume that "transport=virtio" implies using virtio-mmio.
Yes, we should add it only when needed.
Quoted 4 lines
BTW, if we named the main option "specification", the secondary option "transport" would good fit from my PoV. For example:
disk = [ 'phy:/dev/mmcblk0p3, xvda1, backendtype=other, specification=virtio, transport=mmio']
Fine with me.
Juergen
Re: [PATCH V7 1/2] libxl: Add support for Virtio disk configuration
On 25.04.22 15:09, Juergen Gross wrote:
Hello Juergen
Quoted 43 lines · Oleksandr
Quoted 42 lines · Juergen Gross
Hello Juergen
Thank you for the feedback.
Quoted 12 lines · Oleksandr Tyshchenko
Quoted 10 lines
From: Oleksandr Tyshchenko <[email protected]>
This patch adds basic support for configuring and assisting virtio-mmio based virtio-disk backend (emualator) which is intended to run out of Qemu and could be run in any domain.
Although the Virtio block device is quite different from traditional Xen PV block device (vbd) from the toolstack's point of view:
- as the frontend is virtio-blk which is not a Xenbus driver, nothing written to Xenstore are fetched by the frontend (the vdev is not passed to the frontend)Quoted 8 lines
I thought about the future support on x86.
There we don't have a device tree (and I don't want to introduce it), so the only ways to specify the backend domain id would be to:
- add some information to ACPI tables
- use boot parameters
- use XenstoreI understand that, and agree
Quoted 8 lines
Thinking further of hotplugging virtio devices, Xenstore seems to be the only real suitable alternative. Using virtio mechanisms doesn't seem appropriate, as such information should be retrieved in "platform specific" ways (see e.g. specifying an "endpoint" in the virtio IOMMU device [1], [2]). I think the Xenstore information for that purpose could be rather minimal and it should be device-type agnostic. Having just a directory with endpoints and associated backend domids would probably be enough (not needed in this series, of course).
Quoted 7 lines
Quoted 3 lines
Just to make it clear, we are speaking about the possible ways to communicate backend domid for another series [1], so about the x86's alternative of device-tree bindings "xen,dev-domid" [2]. I was thinking we could avoid using Xenstore at the guest side for that purpose, but I didn't think about hotplug...
I assume, all Xenstore bits wouldn't go the outside Xen grant DMA-mapping layer (grant-dma-ops.c)?I think it would be another driver under
drivers/xen/without the need to touch any other frontend related file or Xen-related architecture specific code.
ok
Quoted 12 lines
Quoted 12 lines
Quoted 5 lines
And with the hotplug option in mind I start to feel unueasy with naming the new Xenstore node "protocol", as the frontend disk nodes for "normal" disks already have a "protocol" entry specifying 64- or 32-bit protocol.
I noticed the "protocol" node at the frontend side for traditional Xen PV block device which handles yet another purpose, but I didn't think much about it since the new "protocol" node in only for the backend's use. If we start thinking of frontend's Xenstore nodes, then yes, will clash...
Quoted 2 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Maybe we should really name it "transport" instead?
... For me the "transport" name is associated with virtio transports: mmio, pci, ccw. But, I would be ok with that name. Another possible name could be "specification".
Yeah, looking at the virtio spec this makes sense.
So I would be fine with "specification".
ok, thank you for the confirmation.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
- Add new device kind (
LIBXL__DEVICE_KIND_VIRTIO_DISK) as current one (LIBXL__DEVICE_KIND_VBD) doesn't fit into Virtio disk modelAn example of domain configuration for Virtio disk:
disk = [ 'phy:/dev/mmcblk0p3, xvda1, backendtype=other, protocol=virtio-mmio']
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
With Roger's feedback this would then be "transport=virtio", the "mmio" part should then be something like "adapter=mmio" (in contrast to "adapter=pci"), and "adapter" only needed in case of a device tree and PCI being available.
ok, will rename. Can we add "adapter" (or whenever the name would be) option later, when there is a real need? For now, I mean within the current series which adds only virtio-mmio bits on Arm, we can assume that "transport=virtio" implies using virtio-mmio.
Yes, we should add it only when needed.
ok, good
Quoted 7 lines
Quoted 5 lines
BTW, if we named the main option "specification", the secondary option "transport" would good fit from my PoV. For example:
disk = [ 'phy:/dev/mmcblk0p3, xvda1, backendtype=other, specification=virtio, transport=mmio']Fine with me.
perfect
Quoted 3 lines
Juergen
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V7 1/2] libxl: Add support for Virtio disk configuration
In reply to OleksandrQuoted 159 lines · Oleksandr
On 22.04.22 12:41, Roger Pau Monné wrote:
Hello Roger
Quoted 128 lines · Oleksandr Tyshchenko
Quoted 127 lines
From: Oleksandr Tyshchenko <[email protected]>
This patch adds basic support for configuring and assisting virtio-mmio based virtio-disk backend (emualator) which is intended to run out of Qemu and could be run in any domain.
Although the Virtio block device is quite different from traditional Xen PV block device (vbd) from the toolstack's point of view:
- as the frontend is virtio-blk which is not a Xenbus driver, nothing written to Xenstore are fetched by the frontend (the vdev is not passed to the frontend)
- the ring-ref/event-channel are not used for the backend<->frontend communication, the proposed IPC for Virtio is IOREQ/DM
it is still a "block device" and ought to be integrated in existing "disk" handling. So, re-use (and adapt) "disk" parsing/configuration logic to deal with Virtio devices as well.For the immediate purpose and an ability to extend that support for other use-cases in future (Qemu, virtio-pci, etc) perform the following actions:
- Add new disk backend type (LIBXL_DISK_BACKEND_OTHER) and reflect that in the configuration
- Introduce new disk protocol field tolibxl_device_diskstruct (withLIBXL_DISK_PROTOCOL_XENandLIBXL_DISK_PROTOCOL_VIRTIO_MMIOtypes) and reflect that in the configuration (new "protocol" option with "xen" protocol being default value)
- Add new device kind (LIBXL__DEVICE_KIND_VIRTIO_DISK) as current one (LIBXL__DEVICE_KIND_VBD) doesn't fit into Virtio disk modelAn example of domain configuration for Virtio disk:
disk = [ 'phy:/dev/mmcblk0p3, xvda1, backendtype=other, protocol=virtio-mmio']Nothing has changed for default Xen disk configuration.
Please note, this patch is not enough for virtio-disk to work on Xen (Arm), as for every Virtio device (including disk) we need to allocate Virtio MMIO params (IRQ and memory region) and pass them to the backend, also update Guest device-tree. The subsequent patch will add these missing bits. For the current patch, the default "irq" and "base" are just written to the Xenstore. This is not an ideal splitting, but this way we avoid breaking the bisectability.
Signed-off-by Oleksandr Tyshchenko <[email protected]>---
Changes RFC -> V1:
- no changesChanges V1 -> V2:
- rebase according to the new location oflibxl_virtio_disk.cChanges V2 -> V3:
- no changesChanges V3 -> V4:
- rebase according to the new argument forDEFINE_DEVICE_TYPE_STRUCTChanges V4 -> V5:
- split the changes, change the order of the patches
- update patch description
- don't introduce new "vdisk" configuration option with own parsing logic, re-use Xen PV block "disk" parsing/configuration logic for the virtio-disk
- introduce "virtio" flag and document it's usage
- addLIBXL_HAVE_DEVICE_DISK_VIRTIO
- update libxlu_disk_l.[ch]
- dropnum_disksvariable/MAX_VIRTIO_DISKS
- drop Wei's T-bChanges V5 -> V6:
- rebase on current staging
- use "%"PRIu64 instead of %lu fordisk->baseindevice_disk_add()
- update *.gen.go filesChanges V6 -> V7:
- rebase on current staging
- update *.gen.go files and libxlu_disk_l.[ch] files
- update patch description
- rework significantly to support more flexible configuration and have more generic basic implementation for being able to extend that for other use-cases (virtio-pci, qemu, etc).--- docs/man/xl-disk-configuration.5.pod.in | 37 +- tools/golang/xenlight/helpers.gen.go | 6 + tools/golang/xenlight/types.gen.go | 11 + tools/include/libxl.h | 6 + tools/libs/light/libxl_device.c | 57 +- tools/libs/light/libxl_disk.c | 111 +++- tools/libs/light/libxl_internal.h | 1 + tools/libs/light/libxl_types.idl | 10 + tools/libs/light/libxl_types_internal.idl | 1 + tools/libs/light/libxl_utils.c | 2 + tools/libs/util/libxlu_disk_l.c | 952 +++++++++++++++--------------- tools/libs/util/libxlu_disk_l.h | 2 +- tools/libs/util/libxlu_disk_l.l | 9 + tools/xl/xl_block.c | 11 + 14 files changed, 736 insertions(+), 480 deletions(-)docs/man/xl-disk-configuration.5.pod.in +12
-4@@ -232,7 +232,7 @@ Specifies the backend implementation to use =item Supported values -phy, qdisk +phy, qdisk, other =item Mandatory@@ -244,11 +244,13 @@ Automatically determine which backend to use. =back -This does not affect the guest's view of the device. It controls -which software implementation of the Xen backend driver is used. +It controls which software implementation of the backend driver is used. +Depending on the "protocol" option this may affect the guest's view +of the device. Not all backend drivers support all combinations of other options. -For example, "phy" does not support formats other than "raw". +For example, "phy" and "other" do not support formats other than "raw" and +"other" does not support protocols other than "virtio-mmio". Normally this option should not be specified, in which case libxl will automatically determine the most suitable backend.@@ -344,8 +346,35 @@ can be used to disable "hole punching" for file based backends which were intentionally created non-sparse to avoid fragmentation of the file. +=item B<protocol>=I<PROTOCOL> + +=over 4 + +=item Description +Quoted 8 lines
docs/man/xl-disk-configuration.5.pod.in can be used to disable "hole punching" for file based backends which · line 359
Quoted 5 lines
docs/man/xl-disk-configuration.5.pod.in +5
-0+Specifies the communication protocol to use for the chosen "backendtype" option + +=item Supported values + +xen, virtio-mmioFrom a user PoV, I think it would be better to just select xen or
virtio here, but not the underlying configuration mechanism used to expose the devices to the guest.I got your point.
Quoted 10 lines
We would likely need to add a different option to select mmio or pci then, but that should be set by default based on architecture/guest type. For example on x86 it should default to pci, while on Arm I guess it will depend on whether the guest has PCI or not?
In any case, I think we should offer an option that's selecting between xen or virtio protocol, and the way to expose the configuration of the device shouldn't need to be explicitly selected by the user.
Quoted 8 lines
ok, for now I will use "xen and virtio" values for the "protocol" option, then internally toolstack will assume that "virtio" really means "virtio-mmio".
When there is a need to expand that support to "virtio-pci", we will see how to deal with it from the configuration PoV, probably like you suggested above by adding another option (e.g. "transport") with default values based on the architecture/guest type.
I think this likely also wants to be a separate field in libxl_device_disk, which could be left empty and libxl will attempt to set a default. For example have the following in libxl_types.idl:
libxl_device_protocol = Enumeration("device_protocol", [
(0, "UNKNOWN"),
(1, "XEN"),
(2, "VIRTIO"),
])libxl_device_configuration = Enumeration("device_configuration", [
(0, "UNKNOWN"),
(1, "XENBUS"),
(2, "MMIO"),
])libxl_device_disk = Struct("device_disk", [
("protocol", libxl_device_protocol),
("configuration", libxl_device_configuration),
])I don't like libxl_device_configuration much, I think is too generic, but I can't think of anything better. Maybe others can provide better names.
Thanks, Roger.
Re: [PATCH V7 1/2] libxl: Add support for Virtio disk configuration
On 25.04.22 16:12, Roger Pau Monné wrote:
Hello Roger
Quoted 180 lines · Oleksandr
Quoted 155 lines · Roger Pau Monné
Hello Roger
Quoted 128 lines · Oleksandr Tyshchenko
Quoted 127 lines
From: Oleksandr Tyshchenko <[email protected]>
This patch adds basic support for configuring and assisting virtio-mmio based virtio-disk backend (emualator) which is intended to run out of Qemu and could be run in any domain.
Although the Virtio block device is quite different from traditional Xen PV block device (vbd) from the toolstack's point of view:
- as the frontend is virtio-blk which is not a Xenbus driver, nothing written to Xenstore are fetched by the frontend (the vdev is not passed to the frontend)
- the ring-ref/event-channel are not used for the backend<->frontend communication, the proposed IPC for Virtio is IOREQ/DM
it is still a "block device" and ought to be integrated in existing "disk" handling. So, re-use (and adapt) "disk" parsing/configuration logic to deal with Virtio devices as well.For the immediate purpose and an ability to extend that support for other use-cases in future (Qemu, virtio-pci, etc) perform the following actions:
- Add new disk backend type (LIBXL_DISK_BACKEND_OTHER) and reflect that in the configuration
- Introduce new disk protocol field tolibxl_device_diskstruct (withLIBXL_DISK_PROTOCOL_XENandLIBXL_DISK_PROTOCOL_VIRTIO_MMIOtypes) and reflect that in the configuration (new "protocol" option with "xen" protocol being default value)
- Add new device kind (LIBXL__DEVICE_KIND_VIRTIO_DISK) as current one (LIBXL__DEVICE_KIND_VBD) doesn't fit into Virtio disk modelAn example of domain configuration for Virtio disk:
disk = [ 'phy:/dev/mmcblk0p3, xvda1, backendtype=other, protocol=virtio-mmio']Nothing has changed for default Xen disk configuration.
Please note, this patch is not enough for virtio-disk to work on Xen (Arm), as for every Virtio device (including disk) we need to allocate Virtio MMIO params (IRQ and memory region) and pass them to the backend, also update Guest device-tree. The subsequent patch will add these missing bits. For the current patch, the default "irq" and "base" are just written to the Xenstore. This is not an ideal splitting, but this way we avoid breaking the bisectability.
Signed-off-by Oleksandr Tyshchenko <[email protected]>---
Changes RFC -> V1:
- no changesChanges V1 -> V2:
- rebase according to the new location oflibxl_virtio_disk.cChanges V2 -> V3:
- no changesChanges V3 -> V4:
- rebase according to the new argument forDEFINE_DEVICE_TYPE_STRUCTChanges V4 -> V5:
- split the changes, change the order of the patches
- update patch description
- don't introduce new "vdisk" configuration option with own parsing logic, re-use Xen PV block "disk" parsing/configuration logic for the virtio-disk
- introduce "virtio" flag and document it's usage
- addLIBXL_HAVE_DEVICE_DISK_VIRTIO
- update libxlu_disk_l.[ch]
- dropnum_disksvariable/MAX_VIRTIO_DISKS
- drop Wei's T-bChanges V5 -> V6:
- rebase on current staging
- use "%"PRIu64 instead of %lu fordisk->baseindevice_disk_add()
- update *.gen.go filesChanges V6 -> V7:
- rebase on current staging
- update *.gen.go files and libxlu_disk_l.[ch] files
- update patch description
- rework significantly to support more flexible configuration and have more generic basic implementation for being able to extend that for other use-cases (virtio-pci, qemu, etc).--- docs/man/xl-disk-configuration.5.pod.in | 37 +- tools/golang/xenlight/helpers.gen.go | 6 + tools/golang/xenlight/types.gen.go | 11 + tools/include/libxl.h | 6 + tools/libs/light/libxl_device.c | 57 +- tools/libs/light/libxl_disk.c | 111 +++- tools/libs/light/libxl_internal.h | 1 + tools/libs/light/libxl_types.idl | 10 + tools/libs/light/libxl_types_internal.idl | 1 + tools/libs/light/libxl_utils.c | 2 + tools/libs/util/libxlu_disk_l.c | 952 +++++++++++++++--------------- tools/libs/util/libxlu_disk_l.h | 2 +- tools/libs/util/libxlu_disk_l.l | 9 + tools/xl/xl_block.c | 11 + 14 files changed, 736 insertions(+), 480 deletions(-)docs/man/xl-disk-configuration.5.pod.in +12
-4@@ -232,7 +232,7 @@ Specifies the backend implementation to use =item Supported values -phy, qdisk +phy, qdisk, other =item Mandatory@@ -244,11 +244,13 @@ Automatically determine which backend to use. =back -This does not affect the guest's view of the device. It controls -which software implementation of the Xen backend driver is used. +It controls which software implementation of the backend driver is used. +Depending on the "protocol" option this may affect the guest's view +of the device. Not all backend drivers support all combinations of other options. -For example, "phy" does not support formats other than "raw". +For example, "phy" and "other" do not support formats other than "raw" and +"other" does not support protocols other than "virtio-mmio". Normally this option should not be specified, in which case libxl will automatically determine the most suitable backend.@@ -344,8 +346,35 @@ can be used to disable "hole punching" for file based backends which were intentionally created non-sparse to avoid fragmentation of the file. +=item B<protocol>=I<PROTOCOL> + +=over 4 + +=item Description +Quoted 8 lines
docs/man/xl-disk-configuration.5.pod.in can be used to disable "hole punching" for file based backends which · line 359
Quoted 5 lines
docs/man/xl-disk-configuration.5.pod.in +5
-0+Specifies the communication protocol to use for the chosen "backendtype" option + +=item Supported values + +xen, virtio-mmioFrom a user PoV, I think it would be better to just select xen or
virtio here, but not the underlying configuration mechanism used to expose the devices to the guest.I got your point.
Quoted 9 lines
We would likely need to add a different option to select mmio or pci then, but that should be set by default based on architecture/guest type. For example on x86 it should default to pci, while on Arm I guess it will depend on whether the guest has PCI or not?
In any case, I think we should offer an option that's selecting between xen or virtio protocol, and the way to expose the configuration of the device shouldn't need to be explicitly selected by the user.
Quoted 8 lines
ok, for now I will use "xen and virtio" values for the "protocol" option, then internally toolstack will assume that "virtio" really means "virtio-mmio".
When there is a need to expand that support to "virtio-pci", we will see how to deal with it from the configuration PoV, probably like you suggested above by adding another option (e.g. "transport") with default values based on the architecture/guest type.
I think this likely also wants to be a separate field in
libxl_device_disk, which could be left empty and libxl will attempt to set a default. For example have the following in libxl_types.idl:
libxl_device_protocol= Enumeration("device_protocol", [(0, "UNKNOWN"), (1, "XEN"), (2, "VIRTIO"), ])
libxl_device_configuration= Enumeration("device_configuration", [(0, "UNKNOWN"), (1, "XENBUS"), (2, "MMIO"), ])
Quoted 8 lines
libxl_device_disk= Struct("device_disk", [("protocol", libxl_device_protocol), ("configuration", libxl_device_configuration), ])I don't like
libxl_device_configurationmuch, I think is too generic, but I can't think of anything better. Maybe others can provide better names.
Here [1] we had a discussion regarding user configuration options. "protocol" cannot be used as it will lead to the confusion (at least with Xen PV block device which already has "protocol" frontend's entry in Xenstore).
Preliminary, we had agreed on the following names:
1. specification: xen or virtio
2. transport: mmio or pci
Please tell me, are you OK with them?
[1] https://lore.kernel.org/xen-devel/[email protected]/
Quoted 2 lines
Thanks, Roger.
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V7 1/2] libxl: Add support for Virtio disk configuration
Quoted 105 lines · Oleksandr
On 25.04.22 16:12, Roger Pau Monné wrote:
Hello Roger
Quoted 83 lines · Oleksandr
Quoted 58 lines · Roger Pau Monné
Hello Roger
Quoted 31 lines · Oleksandr Tyshchenko
Quoted 30 lines
From: Oleksandr Tyshchenko <[email protected]>
docs/man/xl-disk-configuration.5.pod.in +12
-4@@ -232,7 +232,7 @@ Specifies the backend implementation to use =item Supported values -phy, qdisk +phy, qdisk, other =item Mandatory@@ -244,11 +244,13 @@ Automatically determine which backend to use. =back -This does not affect the guest's view of the device. It controls -which software implementation of the Xen backend driver is used. +It controls which software implementation of the backend driver is used. +Depending on the "protocol" option this may affect the guest's view +of the device. Not all backend drivers support all combinations of other options. -For example, "phy" does not support formats other than "raw". +For example, "phy" and "other" do not support formats other than "raw" and +"other" does not support protocols other than "virtio-mmio". Normally this option should not be specified, in which case libxl will automatically determine the most suitable backend.@@ -344,8 +346,35 @@ can be used to disable "hole punching" for file based backends which were intentionally created non-sparse to avoid fragmentation of the file. +=item B<protocol>=I<PROTOCOL> + +=over 4 + +=item Description +Quoted 8 lines
docs/man/xl-disk-configuration.5.pod.in can be used to disable "hole punching" for file based backends which · line 359
Quoted 5 lines
docs/man/xl-disk-configuration.5.pod.in +5
-0+Specifies the communication protocol to use for the chosen "backendtype" option + +=item Supported values + +xen, virtio-mmioFrom a user PoV, I think it would be better to just select xen or
virtio here, but not the underlying configuration mechanism used to expose the devices to the guest.I got your point.
Quoted 9 lines
We would likely need to add a different option to select mmio or pci then, but that should be set by default based on architecture/guest type. For example on x86 it should default to pci, while on Arm I guess it will depend on whether the guest has PCI or not?
In any case, I think we should offer an option that's selecting between xen or virtio protocol, and the way to expose the configuration of the device shouldn't need to be explicitly selected by the user.
Quoted 8 lines
ok, for now I will use "xen and virtio" values for the "protocol" option, then internally toolstack will assume that "virtio" really means "virtio-mmio".
When there is a need to expand that support to "virtio-pci", we will see how to deal with it from the configuration PoV, probably like you suggested above by adding another option (e.g. "transport") with default values based on the architecture/guest type.
I think this likely also wants to be a separate field in
libxl_device_disk, which could be left empty and libxl will attempt to set a default. For example have the following in libxl_types.idl:
libxl_device_protocol= Enumeration("device_protocol", [(0, "UNKNOWN"), (1, "XEN"), (2, "VIRTIO"), ])
libxl_device_configuration= Enumeration("device_configuration", [(0, "UNKNOWN"), (1, "XENBUS"), (2, "MMIO"), ])Quoted 8 lines
libxl_device_disk= Struct("device_disk", [("protocol", libxl_device_protocol), ("configuration", libxl_device_configuration), ])I don't like
libxl_device_configurationmuch, I think is too generic, but I can't think of anything better. Maybe others can provide better names.Here [1] we had a discussion regarding user configuration options. "protocol" cannot be used as it will lead to the confusion (at least with Xen PV block device which already has "protocol" frontend's entry in Xenstore).
Quoted 5 lines
Preliminary, we had agreed on the following names:
1. specification: xen or virtio
2. transport: mmio or pciPlease tell me, are you OK with them?
Yes, that's fine. My main point is that libxl_device_disk should contain both fields, so a 3rd party toolstack can set 'specification = virtio' and let Xen decide the transport to use.
I'm dubious whether we want to have a xenbus transport for xen specification to use, but I guess it's fine to say that for specification == xen transport is ignored.
Thanks, Roger.
Re: [PATCH V7 1/2] libxl: Add support for Virtio disk configuration
Quoted 112 lines · Roger Pau Monné
Quoted 105 lines · Oleksandr
On 25.04.22 16:12, Roger Pau Monné wrote:
Hello Roger
Quoted 83 lines · Oleksandr
Quoted 58 lines · Roger Pau Monné
Hello Roger
Quoted 31 lines · Oleksandr Tyshchenko
Quoted 30 lines
From: Oleksandr Tyshchenko <[email protected]>
docs/man/xl-disk-configuration.5.pod.in +12
-4@@ -232,7 +232,7 @@ Specifies the backend implementation to use =item Supported values -phy, qdisk +phy, qdisk, other =item Mandatory@@ -244,11 +244,13 @@ Automatically determine which backend to use. =back -This does not affect the guest's view of the device. It controls -which software implementation of the Xen backend driver is used. +It controls which software implementation of the backend driver is used. +Depending on the "protocol" option this may affect the guest's view +of the device. Not all backend drivers support all combinations of other options. -For example, "phy" does not support formats other than "raw". +For example, "phy" and "other" do not support formats other than "raw" and +"other" does not support protocols other than "virtio-mmio". Normally this option should not be specified, in which case libxl will automatically determine the most suitable backend.@@ -344,8 +346,35 @@ can be used to disable "hole punching" for file based backends which were intentionally created non-sparse to avoid fragmentation of the file. +=item B<protocol>=I<PROTOCOL> + +=over 4 + +=item Description +Quoted 8 lines
docs/man/xl-disk-configuration.5.pod.in can be used to disable "hole punching" for file based backends which · line 359
Quoted 5 lines
docs/man/xl-disk-configuration.5.pod.in +5
-0+Specifies the communication protocol to use for the chosen "backendtype" option + +=item Supported values + +xen, virtio-mmioFrom a user PoV, I think it would be better to just select xen or
virtio here, but not the underlying configuration mechanism used to expose the devices to the guest.I got your point.
Quoted 9 lines
We would likely need to add a different option to select mmio or pci then, but that should be set by default based on architecture/guest type. For example on x86 it should default to pci, while on Arm I guess it will depend on whether the guest has PCI or not?
In any case, I think we should offer an option that's selecting between xen or virtio protocol, and the way to expose the configuration of the device shouldn't need to be explicitly selected by the user.
Quoted 8 lines
ok, for now I will use "xen and virtio" values for the "protocol" option, then internally toolstack will assume that "virtio" really means "virtio-mmio".
When there is a need to expand that support to "virtio-pci", we will see how to deal with it from the configuration PoV, probably like you suggested above by adding another option (e.g. "transport") with default values based on the architecture/guest type.
I think this likely also wants to be a separate field in
libxl_device_disk, which could be left empty and libxl will attempt to set a default. For example have the following in libxl_types.idl:
libxl_device_protocol= Enumeration("device_protocol", [(0, "UNKNOWN"), (1, "XEN"), (2, "VIRTIO"), ])
libxl_device_configuration= Enumeration("device_configuration", [(0, "UNKNOWN"), (1, "XENBUS"), (2, "MMIO"), ])Quoted 8 lines
libxl_device_disk= Struct("device_disk", [("protocol", libxl_device_protocol), ("configuration", libxl_device_configuration), ])I don't like
libxl_device_configurationmuch, I think is too generic, but I can't think of anything better. Maybe others can provide better names.Here [1] we had a discussion regarding user configuration options. "protocol" cannot be used as it will lead to the confusion (at least with Xen PV block device which already has "protocol" frontend's entry in Xenstore).
Quoted 5 lines
Preliminary, we had agreed on the following names:
1. specification: xen or virtio
2. transport: mmio or pciPlease tell me, are you OK with them?
Quoted 7 lines
Yes, that's fine. My main point is that
libxl_device_diskshould contain both fields, so a 3rd party toolstack can set 'specification = virtio' and let Xen decide the transport to use.I'm dubious whether we want to have a xenbus transport for xen specification to use, but I guess it's fine to say that for specification == xen transport is ignored.
At least for now, I guess. It might be a thing in case someone decides to add argo support.
Juergen