libqos: use standard virtio headers
v2 cover libqos: use standard virtio headers
v2:
* Fix missing s/X/(1u << X)/ conversion in Patch 3 [Marc]
This patch series eliminates code duplication in libqos virtio. include/standard-headers/ contains the Linux virtio header files so we don't need to define our own version of the structs and constants.
Eric Blake (1):
qapi: Don't pass NULL to printf in string input visitor
Gerd Hoffmann (2):
usb/uhci: move pid check
Revert "acpi: mark PMTIMER as unlocked"
Igor Mammedov (1):
acpi: fix bios linker loadder COMMAND_ALLOCATE on bigendian host
James Hogan (1):
target-mips: Fix RDHWR exception host PC
Jan Vesely (1):
configure: Check if struct fsxattr is available from linux header
Kevin Wolf (2):
vvfat: Fix volume name assertion
vvfat: Fix default volume label
Markus Armbruster (3):
QemuOpts: Fix qemu_opts_foreach() dangling location regression
replay: Fix dangling location bug in replay_configure()
qom: -object error messages lost location, restore it
Michael Roth (1):
spapr_drc: fix aborts during DRC-count based hotplug
Peter Maydell (1):
Update version for v2.6.0-rc4 release
Samuel Thibault (1):
slirp: fix guest network access with darwin host
Stefan Hajnoczi (8):
libqos: use virtio_ids.h for device ID definitions
libqos: drop duplicated PCI vendor ID definition
libqos: drop duplicated virtio_config.h definitions
libqos: drop duplicated virtio_ring.h bit definitions
libqos: drop duplicated virtio_vring.h structs
libqos: drop duplicated virtio_blk.h definitions
libqos: drop duplicated virtio_scsi.h definitions
libqos: drop duplicated virtio_pci.h definitions
Thomas Huth (1):
hw/ppc/spapr: Fix crash when specifying bad parameters to
spapr-pci-host-bridge
PATCH v2 1/23 hw/ppc/spapr: Fix crash when specifying bad parameters to spapr-pci-host-bridge
From: Thomas Huth <[email protected]>
QEMU currently crashes when using bad parameters for the spapr-pci-host-bridge device:
$ qemu-system-ppc64 -device spapr-pci-host-bridge,buid=0x123,liobn=0x321,mem_win_addr=0x1,io_win_addr=0x10 Segmentation fault
The problem is that spapr_tce_find_by_liobn() might return NULL, but the code in spapr_populate_pci_dt() does not check for this condition and then tries to dereference this NULL pointer.
Apart from that, the return value of spapr_populate_pci_dt() also has to be checked for all PCI buses, not only for the last one, to make sure we catch all errors.
--- hw/ppc/spapr.c | 9 ++++----- hw/ppc/spapr_pci.c | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-)
hw/ppc/spapr.c +4 -5
@@ -940,11 +940,10 @@ static void spapr_finalize_fdt(sPAPRMachineState *spapr, QLIST_FOREACH(phb, &spapr->phbs, list) { ret =spapr_populate_pci_dt (phb,PHANDLE_XICP , fdt); - } - -if (ret <0 ) { -fprintf (stderr,"couldn't setup PCI devices in fdt\n" ); -exit (1 ); +if (ret <0 ) { +error_report ("couldn't setup PCI devices in fdt" ); +exit (1 ); + } }/* RTAS */
hw/ppc/spapr_pci.c +3 -0
@@ -1816,6 +1816,9 @@ int spapr_populate_pci_dt(sPAPRPHBState *phb, sizeof(interrupt_map))); tcet =spapr_tce_find_by_liobn (SPAPR_PCI_LIOBN (phb->index,0 )); +if (!tcet) { +return -1 ; + }spapr_dma_dt (fdt, bus_off,"ibm,dma-window" , tcet->liobn, tcet->bus_offset, tcet->nb_table << tcet->page_shift);
Signature · 1 line
2.5.5
PATCH v2 2/23 usb/uhci: move pid check
In reply to Stefan HajnocziFrom: Gerd Hoffmann <[email protected]>
commit "5f77e06 usb: add pid check at the first of uhci_handle_td()" moved the pid verification to the start of the uhci_handle_td function, to simplify the error handling (we don't have to free stuff which we didn't allocate in the first place ...).
Problem is now the check fires too often, it raises error IRQs even for TDs which we are not going to process because they are not set active.
So, lets move down the check a bit, so it is done only for active TDs, but still before we are going to allocate stuff to process the requested transfer.
Message-id: [email protected]
--- hw/usb/hcd-uhci.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
hw/usb/hcd-uhci.c +13 -13
@@ -776,19 +776,6 @@ static int uhci_handle_td(UHCIState *s, UHCIQueue *q, uint32_t qh_addr,uint8_t pid = td->token &0xff ;UHCIAsync *async; -switch (pid) { -case USB_TOKEN_OUT : -case USB_TOKEN_SETUP : -case USB_TOKEN_IN : -break ; -default : -/* invalid pid : frame interrupted */ - s->status |=UHCI_STS_HCPERR ; - s->cmd &= ~UHCI_CMD_RS ; -uhci_update_irq (s); -return TD_RESULT_STOP_FRAME ; - } - async =uhci_async_find_td (s, td_addr);if (async) {if (uhci_queue_verify (async->queue, qh_addr, td, td_addr, queuing)) {
@@ -828,6 +815,19 @@ static int uhci_handle_td(UHCIState *s, UHCIQueue *q, uint32_t qh_addr,return TD_RESULT_NEXT_QH ; } +switch (pid) { +case USB_TOKEN_OUT : +case USB_TOKEN_SETUP : +case USB_TOKEN_IN : +break ; +default : +/* invalid pid : frame interrupted */ + s->status |=UHCI_STS_HCPERR ; + s->cmd &= ~UHCI_CMD_RS ; +uhci_update_irq (s); +return TD_RESULT_STOP_FRAME ; + } +if (async) {if (queuing) {/* we are busy filling the queue, we are not prepared
Signature · 1 line
2.5.5
PATCH v2 3/23 spapr_drc: fix aborts during DRC-count based hotplug
In reply to Stefan HajnocziFrom: Michael Roth <[email protected]>
CPU/memory resources can be signalled en-masse via spapr_hotplug_req_add_by_count(), and when doing so, actually change the meaning of the 'drc' parameter passed to spapr_hotplug_req_event() to be a count rather than an index.
f40eb92 added a hook in spapr_hotplug_req_event() to record when a device had been 'signalled' to the guest, but that code assumes that drc is always an index. In cases where it's a count, such as memory hotplug, the DRC lookup will fail, leading to an assert.
Fix this by only explicitly setting the signalled state for cases where we are doing PCI hotplug.
For other resources types, since we cannot selectively track whether a resource has been signalled in cases where we signal attach as a count, set the 'signalled' state to true immediately upon making the resource available via drck->attach().
--- hw/ppc/spapr_drc.c | 12 +++++++++++- hw/ppc/spapr_events.c | 7 +++---- 2 files changed, 14 insertions(+), 5 deletions(-)
hw/ppc/spapr_drc.c +11 -1
@@ -364,7 +364,17 @@ static void attach(sPAPRDRConnector *drc, DeviceState *d, void *fdt, drc->fdt = fdt; drc->fdt_start_offset = fdt_start_offset; drc->configured = coldplug; - drc->signalled = coldplug; +/* 'logical' DR resources such as memory/cpus are in some cases treated +* as a pool of resources from which the guest is free to choose from +* based on only a count. for resources that can be assigned in this +* fashion, we must assume the resource is signalled immediately +* since a single hotplug request might make an arbitrary number of +* such attached resources available to the guest, as opposed to +* 'physical' DR resources such as PCI where each device/resource is +* signalled individually. +*/ + drc->signalled = (drc->type !=SPAPR_DR_CONNECTOR_TYPE_PCI ) + ? true : coldplug; object_property_add_link(OBJECT(drc), "device", object_get_typename(OBJECT(drc->dev)),
hw/ppc/spapr_events.c +3 -4
@@ -442,6 +442,9 @@ static void spapr_hotplug_req_event(uint8_t hp_id, uint8_t hp_action,switch (drc_type) {case SPAPR_DR_CONNECTOR_TYPE_PCI : hp->hotplug_type =RTAS_LOG_V6_HP_TYPE_PCI ; +if (hp->hotplug_action ==RTAS_LOG_V6_HP_ACTION_ADD ) { +spapr_hotplug_set_signalled (drc); + }break ;case SPAPR_DR_CONNECTOR_TYPE_LMB : hp->hotplug_type =RTAS_LOG_V6_HP_TYPE_MEMORY ;
@@ -462,10 +465,6 @@ static void spapr_hotplug_req_event(uint8_t hp_id, uint8_t hp_action,rtas_event_log_queue (RTAS_LOG_TYPE_HOTPLUG , new_hp, true); -if (hp->hotplug_action ==RTAS_LOG_V6_HP_ACTION_ADD ) { -spapr_hotplug_set_signalled (drc); - } -qemu_irq_pulse (xics_get_qirq (spapr->icp, spapr->check_exception_irq)); }
Signature · 1 line
2.5.5
PATCH v2 4/23 QemuOpts: Fix qemu_opts_foreach() dangling location regression
In reply to Stefan HajnocziFrom: Markus Armbruster <[email protected]>
qemu_opts_foreach() pushes and pops a Location with automatic storage duration. Except it fails to pop when @func() returns non-zero. cur_loc then points to unused stack space, and will most likely get clobbered in short order.
Clobbered cur_loc can make loc_pop() and error_print_loc() crash or report bogus locations.
Affects several qemu command line options as well as qemu-img, qemu-io, qemu-nbd -object, and blkdebug's configuration file.
Broken in commit a4c7367, v2.4.0.
Reproducer:
$ qemu-system-x86_64 -nodefaults -display none -object secret,id=foo,foo=bar
main() reports "Property '.foo' not found" like this:
if (qemu_opts_foreach(qemu_find_opts("object"),
user_creatable_add_opts_foreach,
object_create_delayed, &err)) {
error_report_err(err);
exit(1);
}cur_loc then points to where qemu_opts_foreach()'s Location used to be, i.e. unused stack space. With optimization, this Location doesn't get clobbered for me, and also happens to be the correct location. Without optimization, it does get clobbered in a way that makes error_report_err() report no location.
Message-Id: <[email protected]>
--- util/qemu-option.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
util/qemu-option.c +3 -3
@@ -1108,19 +1108,19 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, {Location loc;QemuOpts *opts; -int rc; +int rc =0 ;loc_push_none (&loc); QTAILQ_FOREACH(opts, &list->head, next) {loc_restore (&opts->loc); rc =func (opaque, opts, errp);if (rc) { -return rc; +break ; }assert (!errp || !*errp); }loc_pop (&loc); -return 0 ; +return rc; }static size_t count_opts_list (QemuOptsList *list)
Signature · 1 line
2.5.5
PATCH v2 5/23 replay: Fix dangling location bug in replay_configure()
In reply to Stefan HajnocziFrom: Markus Armbruster <[email protected]>
replay_configure() pushes and pops a Location with automatic storage duration. Except it fails to pop when -icount parameter "rr" isn't given. cur_loc then points to unused stack space, and will most likely get clobbered in short order.
Clobbered cur_loc can make loc_pop() and error_print_loc() crash or report bogus locations.
Broken in commit 890ad55.
I didn't take the time to find a reproducer.
Message-Id: <[email protected]>
--- replay/replay.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
replay/replay.c +2 -1
@@ -275,7 +275,7 @@ void replay_configure(QemuOpts *opts) rr =qemu_opt_get (opts,"rr" );if (!rr) {/* Just enabling icount */ -return ; + goto out; }else if (!strcmp (rr,"record" )) { mode =REPLAY_MODE_RECORD ; }else if (!strcmp (rr,"replay" )) {
@@ -293,6 +293,7 @@ void replay_configure(QemuOpts *opts)replay_enable (fname, mode); +out:loc_pop (&loc); }
Signature · 1 line
2.5.5
PATCH v2 6/23 qom: -object error messages lost location, restore it
In reply to Stefan HajnocziFrom: Markus Armbruster <[email protected]>
qemu_opts_foreach() runs its callback with the error location set to the option's location. Any errors the callback reports use the option's location automatically.
Commit 90998d5 moved the actual error reporting from "inside" qemu_opts_foreach() to after it. Here's a typical hunk:
if (qemu_opts_foreach(qemu_find_opts("object"),
- object_create,
- object_create_initial, NULL)) {
+ user_creatable_add_opts_foreach,
+ object_create_initial, &err)) {
+ error_report_err(err);
exit(1);
}
Before, object_create() reports from within qemu_opts_foreach(), using the option's location. Afterwards, we do it after qemu_opts_foreach(), using whatever location happens to be current there. Commonly a "none" location.
This is because Error objects don't have location information. Problematic.
Reproducer:
$ qemu-system-x86_64 -nodefaults -display none -object secret,id=foo,foo=bar
qemu-system-x86_64: Property '.foo' not foundNote no location. This commit restores it:
qemu-system-x86_64: -object secret,id=foo,foo=bar: Property '.foo' not found
Note that the qemu_opts_foreach() bug just fixed could mask the bug
here: if the location it leaves dangling hasn't been clobbered, yet, it's the correct one.
Message-Id: <[email protected]>
--- include/qom/object_interfaces.h | 5 +++-- qemu-img.c | 39 +++++++++++---------------------------- qemu-io.c | 3 +-- qemu-nbd.c | 3 +-- qom/object_interfaces.c | 4 +++- vl.c | 6 ++---- 6 files changed, 21 insertions(+), 39 deletions(-)
include/qom/object_interfaces.h +3 -2
@@ -140,7 +140,7 @@ typedef bool (*user_creatable_add_opts_predicate)(const char *type);* user_creatable_add_opts_foreach: * @opaque: a user_creatable_add_opts_predicate callback or NULL * @opts: options to create -* @errp: if an error occurs, a pointer to an area to store the error +* @errp: unused * * An iterator callback to be used in conjunction with * the qemu_opts_foreach() method for creating a list of
@@ -148,8 +148,9 @@ typedef bool (*user_creatable_add_opts_predicate)(const char *type);* * The @opaque parameter can be passed a user_creatable_add_opts_predicate * callback to filter which types of object are created during iteration. +* When it fails, report the error. * -* Returns: 0 on success, -1 on error +* Returns: 0 on success, -1 when an error was reported. */ int user_creatable_add_opts_foreach (void *opaque,QemuOpts *opts,Error **errp);
qemu-img.c +11 -28
@@ -435,8 +435,7 @@ static int img_create(int argc, char **argv)if (qemu_opts_foreach (&qemu_object_opts, user_creatable_add_opts_foreach, -NULL , &local_err)) { -error_report_err (local_err); +NULL ,NULL )) { goto fail; }
@@ -598,7 +597,6 @@ static int img_check(int argc, char **argv)bool writethrough;ImageCheck *check;bool quiet = false; -Error *local_err =NULL ;bool image_opts = false; fmt =NULL ;
@@ -679,8 +677,7 @@ static int img_check(int argc, char **argv)if (qemu_opts_foreach (&qemu_object_opts, user_creatable_add_opts_foreach, -NULL , &local_err)) { -error_report_err (local_err); +NULL ,NULL )) {return 1 ; }
@@ -871,8 +868,7 @@ static int img_commit(int argc, char **argv)if (qemu_opts_foreach (&qemu_object_opts, user_creatable_add_opts_foreach, -NULL , &local_err)) { -error_report_err (local_err); +NULL ,NULL )) {return 1 ; }
@@ -1133,7 +1129,6 @@ static int img_compare(int argc, char **argv)int64_t nb_sectors;int c, pnum;uint64_t progress_base; -Error *local_err =NULL ;bool image_opts = false; cache =BDRV_DEFAULT_CACHE ;
@@ -1201,8 +1196,7 @@ static int img_compare(int argc, char **argv)if (qemu_opts_foreach (&qemu_object_opts, user_creatable_add_opts_foreach, -NULL , &local_err)) { -error_report_err (local_err); +NULL ,NULL )) { ret =2 ; goto out4; }
@@ -1864,8 +1858,7 @@ static int img_convert(int argc, char **argv)if (qemu_opts_foreach (&qemu_object_opts, user_creatable_add_opts_foreach, -NULL , &local_err)) { -error_report_err (local_err); +NULL ,NULL )) { goto fail_getopt; }
@@ -2299,7 +2292,6 @@ static int img_info(int argc, char **argv)bool chain = false;const char *filename, *fmt, *output;ImageInfoList *list; -Error *local_err =NULL ;bool image_opts = false; fmt =NULL ;
@@ -2363,8 +2355,7 @@ static int img_info(int argc, char **argv)if (qemu_opts_foreach (&qemu_object_opts, user_creatable_add_opts_foreach, -NULL , &local_err)) { -error_report_err (local_err); +NULL ,NULL )) {return 1 ; }
@@ -2513,7 +2504,6 @@ static int img_map(int argc, char **argv)int64_t length;MapEntry curr = { .length =0 }, next;int ret =0 ; -Error *local_err =NULL ;bool image_opts = false; fmt =NULL ;
@@ -2573,8 +2563,7 @@ static int img_map(int argc, char **argv)if (qemu_opts_foreach (&qemu_object_opts, user_creatable_add_opts_foreach, -NULL , &local_err)) { -error_report_err (local_err); +NULL ,NULL )) {return 1 ; }
@@ -2717,8 +2706,7 @@ static int img_snapshot(int argc, char **argv)if (qemu_opts_foreach (&qemu_object_opts, user_creatable_add_opts_foreach, -NULL , &err)) { -error_report_err (err); +NULL ,NULL )) {return 1 ; }
@@ -2867,8 +2855,7 @@ static int img_rebase(int argc, char **argv)if (qemu_opts_foreach (&qemu_object_opts, user_creatable_add_opts_foreach, -NULL , &local_err)) { -error_report_err (local_err); +NULL ,NULL )) {return 1 ; }
@@ -3133,7 +3120,6 @@ static int img_resize(int argc, char **argv)bool quiet = false;BlockBackend *blk =NULL ;QemuOpts *param; -Error *local_err =NULL ;static QemuOptsList resize_options = { .name ="resize_options" ,
@@ -3204,8 +3190,7 @@ static int img_resize(int argc, char **argv)if (qemu_opts_foreach (&qemu_object_opts, user_creatable_add_opts_foreach, -NULL , &local_err)) { -error_report_err (local_err); +NULL ,NULL )) {return 1 ; }
@@ -3297,7 +3282,6 @@ static int img_amend(int argc, char **argv)bool quiet = false, progress = false;BlockBackend *blk =NULL ;BlockDriverState *bs =NULL ; -Error *local_err =NULL ;bool image_opts = false; cache =BDRV_DEFAULT_CACHE ;
@@ -3365,8 +3349,7 @@ static int img_amend(int argc, char **argv)if (qemu_opts_foreach (&qemu_object_opts, user_creatable_add_opts_foreach, -NULL , &local_err)) { -error_report_err (local_err); +NULL ,NULL )) { ret =-1 ; goto out_no_progress; }
qemu-io.c +1 -2
@@ -534,8 +534,7 @@ int main(int argc, char **argv)if (qemu_opts_foreach (&qemu_object_opts, user_creatable_add_opts_foreach, -NULL , &local_error)) { -error_report_err (local_error); +NULL ,NULL )) {exit (1 ); }
qemu-nbd.c +1 -2
@@ -711,8 +711,7 @@ int main(int argc, char **argv)if (qemu_opts_foreach (&qemu_object_opts, user_creatable_add_opts_foreach, -NULL , &local_err)) { -error_report_err (local_err); +NULL ,NULL )) {exit (EXIT_FAILURE ); }
qom/object_interfaces.c +3 -1
@@ -170,6 +170,7 @@ int user_creatable_add_opts_foreach(void *opaque, QemuOpts *opts, Error **errp) {bool (*type_predicate)(const char *) = opaque;Object *obj =NULL ; +Error *err =NULL ;const char *type; type =qemu_opt_get (opts,"qom-type" );
@@ -178,8 +179,9 @@ int user_creatable_add_opts_foreach(void *opaque, QemuOpts *opts, Error **errp)return 0 ; } - obj =user_creatable_add_opts (opts, errp); + obj =user_creatable_add_opts (opts, &err);if (!obj) { +error_report_err (err);return -1 ; }object_unref (obj);
vl.c +2 -4
@@ -4291,8 +4291,7 @@ int main(int argc, char **argv, char **envp)if (qemu_opts_foreach (qemu_find_opts ("object" ), user_creatable_add_opts_foreach, - object_create_initial, &err)) { -error_report_err (err); + object_create_initial,NULL )) {exit (1 ); }
@@ -4410,8 +4409,7 @@ int main(int argc, char **argv, char **envp)if (qemu_opts_foreach (qemu_find_opts ("object" ), user_creatable_add_opts_foreach, - object_create_delayed, &err)) { -error_report_err (err); + object_create_delayed,NULL )) {exit (1 ); }
Signature · 1 line
2.5.5
PATCH v2 7/23 target-mips: Fix RDHWR exception host PC
In reply to Stefan HajnocziFrom: James Hogan <[email protected]>
Commit b00c72180c36 ("target-mips: add PC, XNP reg numbers to RDHWR") changed the rdhwr helpers to use check_hwrena() to check the register being accessed is enabled in CP0_HWREna when used from user mode. If that check fails an EXCP_RI exception is raised at the host PC calculated with GETPC().
However check_hwrena() may not be fully inlined as the do_raise_exception() part of it is common regardless of the arguments. This causes GETPC() to calculate the address in the call in the helper instead of the generated code calling the helper. No TB will be found and the EPC reported with the resulting guest RI exception points to the beginning of the TB instead of the RDHWR instruction.
We can't reliably force check_hwrena() to be inlined, and converting it to a macro would be ugly, so instead pass the host PC in as an argument, with each rdhwr helper passing GETPC(). This should avoid any dependence on compiler behaviour, and in practice seems to ensure the full inlining of check_hwrena() on x86_64.
This issue causes failures when running a MIPS KVM (trap & emulate) guest in a MIPS QEMU TCG guest, as the inner guest kernel will do a RDHWR of counter, which is disabled in the outer guest's CP0_HWREna by KVM so it can emulate the inner guest's counter. The emulation fails and the RI exception is passed to the inner guest.
--- target-mips/op_helper.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
target-mips/op_helper.c +8 -8
@@ -2294,29 +2294,29 @@ void helper_deret(CPUMIPSState *env) }#endif /* !CONFIG_USER_ONLY */ -static inline void check_hwrena (CPUMIPSState *env,int reg) +static inline void check_hwrena (CPUMIPSState *env,int reg,uintptr_t pc) {if ((env->hflags &MIPS_HFLAG_CP0 ) || (env->CP0_HWREna & (1 << reg))) {return ; } -do_raise_exception (env,EXCP_RI ,GETPC ()); +do_raise_exception (env,EXCP_RI , pc); }target_ulong helper_rdhwr_cpunum (CPUMIPSState *env) { -check_hwrena (env,0 ); +check_hwrena (env,0 ,GETPC ());return env->CP0_EBase &0x3ff ; }target_ulong helper_rdhwr_synci_step (CPUMIPSState *env) { -check_hwrena (env,1 ); +check_hwrena (env,1 ,GETPC ());return env->SYNCI_Step; }target_ulong helper_rdhwr_cc (CPUMIPSState *env) { -check_hwrena (env,2 ); +check_hwrena (env,2 ,GETPC ());#ifdef CONFIG_USER_ONLY return env->CP0_Count;#else
@@ -2326,19 +2326,19 @@ target_ulong helper_rdhwr_cc(CPUMIPSState *env)target_ulong helper_rdhwr_ccres (CPUMIPSState *env) { -check_hwrena (env,3 ); +check_hwrena (env,3 ,GETPC ());return env->CCRes; }target_ulong helper_rdhwr_performance (CPUMIPSState *env) { -check_hwrena (env,4 ); +check_hwrena (env,4 ,GETPC ());return env->CP0_Performance0; }target_ulong helper_rdhwr_xnp (CPUMIPSState *env) { -check_hwrena (env,5 ); +check_hwrena (env,5 ,GETPC ());return (env->CP0_Config5 >>CP0C5_XNP ) &1 ; }
Signature · 1 line
2.5.5
PATCH v2 8/23 slirp: fix guest network access with darwin host
In reply to Stefan HajnocziFrom: Samuel Thibault <[email protected]>
On Darwin, connect, sendto and friends want the exact size of the sockaddr, not more (and in particular, not sizeof(struct sockaddr_storaget))
This commit adds the sockaddr_size helper to be used when passing a sockaddr size to such function, and makes use of it int sendto and connect calls.
--- slirp/ip_icmp.c | 2 +- slirp/socket.c | 2 +- slirp/socket.h | 12 ++++++++++++ slirp/tcp_subr.c | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-)
slirp/ip_icmp.c +1 -1
@@ -186,7 +186,7 @@ icmp_input(struct mbuf *m, int hlen)sotranslate_out (so, &addr);if (sendto (so->s, icmp_ping_msg,strlen (icmp_ping_msg),0 , - (struct sockaddr *)&addr,sizeof (addr)) ==-1 ) { + (struct sockaddr *)&addr,sockaddr_size (&addr)) ==-1 ) {DEBUG_MISC ((dfd,"icmp_input udp sendto tx errno = %d-%s\n" , errno,strerror (errno)));icmp_send_error (m,ICMP_UNREACH ,ICMP_UNREACH_NET ,0 ,strerror (errno));
slirp/socket.c +1 -1
@@ -627,7 +627,7 @@ sosendto(struct socket *so, struct mbuf *m)/* Don't care what port we get */ ret =sendto (so->s, m->m_data, m->m_len,0 , - (struct sockaddr *)&addr,sizeof (addr)); + (struct sockaddr *)&addr,sockaddr_size (&addr));if (ret <0 )return -1 ;
slirp/socket.h +12 -0
@@ -122,6 +122,18 @@ static inline int sockaddr_equal(struct sockaddr_storage *a,return 0 ; } +static inline socklen_t sockaddr_size (struct sockaddr_storage *a) +{ +switch (a->ss_family) { +case AF_INET : +return sizeof (struct sockaddr_in ); +case AF_INET6 : +return sizeof (struct sockaddr_in6 ); +default : +g_assert_not_reached (); + } +} +struct socket *solookup (struct socket **,struct socket *,struct sockaddr_storage *,struct sockaddr_storage *);struct socket *socreate (Slirp *);
slirp/tcp_subr.c +1 -1
@@ -413,7 +413,7 @@ int tcp_fconnect(struct socket *so, unsigned short af)sotranslate_out (so, &addr);/* We don't care what port we get */ - ret =connect (s,(struct sockaddr *)&addr,sizeof (addr)); + ret =connect (s, (struct sockaddr *)&addr,sockaddr_size (&addr));/* * If it's not in progress, it failed, so we just return 0,
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH v2 08/23] slirp: fix guest network access with darwin host
Hello,
Quoted 7 lines · Stefan Hajnoczi, on Mon 09 May 2016 13:07:52 +0100, wrote:
From: Samuel Thibault <[email protected]>
On Darwin, connect, sendto and friends want the exact size of the sockaddr, not more (and in particular, not
sizeof(struct sockaddr_storaget))This commit adds the
sockaddr_sizehelper to be used when passing a sockaddr size to such function, and makes use of it int sendto and connect calls.
This was already committed, before rc4.
Quoted 75 lines
Signed-off-by Samuel Thibault <[email protected]>Reviewed-by John Arbuckle <[email protected]>Signed-off-by Peter Maydell <[email protected]>--- slirp/ip_icmp.c | 2 +- slirp/socket.c | 2 +- slirp/socket.h | 12 ++++++++++++ slirp/tcp_subr.c | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-)slirp/ip_icmp.c +1
-1@@ -186,7 +186,7 @@ icmp_input(struct mbuf *m, int hlen)sotranslate_out (so, &addr);if (sendto (so->s, icmp_ping_msg,strlen (icmp_ping_msg),0 , - (struct sockaddr *)&addr,sizeof (addr)) ==-1 ) { + (struct sockaddr *)&addr,sockaddr_size (&addr)) ==-1 ) {DEBUG_MISC ((dfd,"icmp_input udp sendto tx errno = %d-%s\n" , errno,strerror (errno)));icmp_send_error (m,ICMP_UNREACH ,ICMP_UNREACH_NET ,0 ,strerror (errno));slirp/socket.c +1
-1@@ -627,7 +627,7 @@ sosendto(struct socket *so, struct mbuf *m)/* Don't care what port we get */ ret =sendto (so->s, m->m_data, m->m_len,0 , - (struct sockaddr *)&addr,sizeof (addr)); + (struct sockaddr *)&addr,sockaddr_size (&addr));if (ret <0 )return -1 ;slirp/socket.h +12
-0@@ -122,6 +122,18 @@ static inline int sockaddr_equal(struct sockaddr_storage *a,return 0 ; } +static inline socklen_t sockaddr_size (struct sockaddr_storage *a) +{ +switch (a->ss_family) { +case AF_INET : +return sizeof (struct sockaddr_in ); +case AF_INET6 : +return sizeof (struct sockaddr_in6 ); +default : +g_assert_not_reached (); + } +} +struct socket *solookup (struct socket **,struct socket *,struct sockaddr_storage *,struct sockaddr_storage *);struct socket *socreate (Slirp *);slirp/tcp_subr.c +1
-1@@ -413,7 +413,7 @@ int tcp_fconnect(struct socket *so, unsigned short af)sotranslate_out (so, &addr);/* We don't care what port we get */ - ret =connect (s,(struct sockaddr *)&addr,sizeof (addr)); + ret =connect (s, (struct sockaddr *)&addr,sockaddr_size (&addr));/* * If it's not in progress, it failed, so we just return 0, Signature · 1 line
2.5.5
Signature · 4 lines
Samuel "How should I know if it works? That's what beta testers are for. I only coded it." (Attributed to Linus Torvalds, somewhere in a posting)
PATCH v2 9/23 qapi: Don't pass NULL to printf in string input visitor
In reply to Stefan HajnocziFrom: Eric Blake <[email protected]>
Make sure the error message for visit_type_uint64() gracefully handles a NULL 'name' when called from the top level or a list context, as not all the world behaves like glibc in allowing NULL through a printf-family %s.
Message-Id: <[email protected]>
--- qapi/string-input-visitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qapi/string-input-visitor.c +1 -1
@@ -222,7 +222,7 @@ static void parse_type_int64(Visitor *v, const char *name, int64_t *obj,return ; error: -error_setg (errp,QERR_INVALID_PARAMETER_VALUE , name, +error_setg (errp,QERR_INVALID_PARAMETER_VALUE , name ? name :"null" ,"an int64 value or range" ); }
Signature · 1 line
2.5.5
PATCH v2 10/23 vvfat: Fix volume name assertion
In reply to Stefan HajnocziFrom: Kevin Wolf <[email protected]>
Commit d5941dd made the volume name configurable, but it didn't consider that the rw code compares the volume name string to assert that the first directory entry is the volume name. This made vvfat crash in rw mode.
This fixes the assertion to compare with the configured volume name instead of a literal string.
--- block/vvfat.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
block/vvfat.c +6 -1
@@ -2283,12 +2283,17 @@ DLOG(fprintf(stderr, "commit_direntries for %s, parent_mapping_index %d\n", mapp factor * (old_cluster_count - new_cluster_count));for (c = first_cluster; !fat_eof (s, c); c =modified_fat_get (s, c)) { +direntry_t *first_direntry;void * direntry =array_get (&(s->directory), current_dir_index);int ret =vvfat_read (s->bs,cluster2sector (s, c), direntry, s->sectors_per_cluster);if (ret)return ret; -assert (!strncmp (s->directory.pointer,"QEMU" ,4 )); + +/* The first directory entry on the filesystem is the volume name */ + first_direntry = (direntry_t *) s->directory.pointer; +assert (!memcmp (first_direntry->name, s->volume_label,11 )); + current_dir_index += factor; }
Signature · 1 line
2.5.5
PATCH v2 11/23 vvfat: Fix default volume label
In reply to Stefan HajnocziFrom: Kevin Wolf <[email protected]>
Commit d5941dd documented that it leaves the default volume name as it was ("QEMU VVFAT"), but it doesn't actually implement this. You get an empty name (eleven space characters) instead.
This fixes the implementation to apply the advertised default.
--- block/vvfat.c | 2 ++ 1 file changed, 2 insertions(+)
block/vvfat.c +2 -0
@@ -1109,6 +1109,8 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, goto fail; }memcpy (s->volume_label, label, label_length); + }else { +memcpy (s->volume_label,"QEMU VVFAT" ,10 ); }if (floppy) {
Signature · 1 line
2.5.5
PATCH v2 12/23 acpi: fix bios linker loadder COMMAND_ALLOCATE on bigendian host
In reply to Stefan HajnocziFrom: Igor Mammedov <[email protected]>
'make check' fails with:
ERROR:tests/bios-tables-test.c:493:load_expected_aml:
assertion failed: (g_file_test(aml_file, G_FILE_TEST_EXISTS))
since commit:caf50c7166a6ed96c462ab5db4b495e1234e4cc6
tests: pc: acpi: drop not needed 'expected SSDT' blobs
Assert happens because qemu-system-x86_64 generates SSDT table and test looks for a corresponding expected table to compare with.
However there is no expected SSDT blob anymore, since QEMU souldn't generate one. As it happens BIOS is not able to read ACPI tables from QEMU and fallbacks to embeded legacy ACPI codepath, which generates SSDT. That happens due to wrongly sized endiannes conversion which makes
uint8_t BiosLinkerLoaderEntry.alloc.zone
end up with 0 due to truncation of 32 bit integer which on host is 1 or 2.
Fix it by dropping invalid cpu_to_le32() as uint8_t doesn't require any conversion.
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1330174
--- hw/acpi/bios-linker-loader.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
hw/acpi/bios-linker-loader.c +2 -3
@@ -135,9 +135,8 @@ void bios_linker_loader_alloc(GArray *linker,strncpy (entry.alloc.file, file,sizeof entry.alloc.file -1 ); entry.command =cpu_to_le32 (BIOS_LINKER_LOADER_COMMAND_ALLOCATE ); entry.alloc.align =cpu_to_le32 (alloc_align); - entry.alloc.zone =cpu_to_le32 (alloc_fseg ? -BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG : -BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH ); + entry.alloc.zone = alloc_fseg ?BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG : +BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH ;/* Alloc entries must come first, so prepend them */ g_array_prepend_vals (linker, &entry,sizeof entry);
Signature · 1 line
2.5.5
PATCH v2 13/23 configure: Check if struct fsxattr is available from linux header
In reply to Stefan HajnocziFrom: Jan Vesely <[email protected]>
Fixes build failure with --enable-xfsctl and new linux headers (>=4.5) and older xfsprogs(<4.5):
In file included from /usr/include/xfs/xfs.h:38:0,
from /var/tmp/portage/app-emulation/qemu-2.5.0-r1/work/qemu-2.5.0/block/raw-posix.c:97:
/usr/include/xfs/xfs_fs.h:42:8: error: redefinition of ‘struct fsxattr’
struct fsxattr {
^In file included from /var/tmp/portage/app-emulation/qemu-2.5.0-r1/work/qemu-2.5.0/block/raw-posix.c:60:0:/usr/include/linux/fs.h:155:8: note: originally defined here
struct fsxattr {
This is really a bug in the system headers, but we can work around it by defining HAVE_FSXATTR in the QEMU headers if linux/fs.h provides the struct, so that xfs_fs.h doesn't try to define it as well.
--- configure | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
configure +23 -0
@@ -4494,6 +4494,21 @@ if test "$fortify_source" != "no"; then fi ########################################## +# check if struct fsxattr is available via linux/fs.h + +have_fsxattr=no +cat > $TMPC << EOF +#include <linux/fs.h> +struct fsxattr foo; +int main(void) { + return 0; +} +EOF +if compile_prog "" "" ; then + have_fsxattr=yes +fi + +########################################## # End of CC checks # After here, no more $cc or $ld runs
@@ -5160,6 +5175,14 @@ fi if test "$have_ifaddrs_h" = "yes" ; then echo "HAVE_IFADDRS_H=y" >> $config_host_mak fi + +# Work around a system header bug with some kernel/XFS header +# versions where they both try to define 'struct fsxattr': +# xfs headers will not try to redefine structs from linux headers +# if this macro is set. +if test "$have_fsxattr" = "yes" ; then + echo "HAVE_FSXATTR=y" >> $config_host_mak +fi if test "$vte" = "yes" ; then echo "CONFIG_VTE=y" >> $config_host_mak echo "VTE_CFLAGS=$vte_cflags" >> $config_host_mak
Signature · 1 line
2.5.5
PATCH v2 14/23 Revert "acpi: mark PMTIMER as unlocked"
In reply to Stefan HajnocziFrom: Gerd Hoffmann <[email protected]>
This reverts commit 7070e085d490c396f9237c8f10bf8b6e69cd0066.
Commit message claims locking is not needed, but that appears to not be true, seabios ehci driver runs into timekeeping problems with this, see
https://bugzilla.redhat.com/show_bug.cgi?id=1322713
Message-id: [email protected]
--- hw/acpi/core.c | 1 - 1 file changed, 1 deletion(-)
hw/acpi/core.c +0 -1
@@ -536,7 +536,6 @@ void acpi_pm_tmr_init(ACPIREGS *ar, acpi_update_sci_fn update_sci, ar->tmr.timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , acpi_pm_tmr_timer, ar);memory_region_init_io (&ar->tmr.io,memory_region_owner (parent), &acpi_pm_tmr_ops, ar,"acpi-tmr" ,4 ); -memory_region_clear_global_locking (&ar->tmr.io);memory_region_add_subregion (parent,8 , &ar->tmr.io); }
Signature · 1 line
2.5.5
PATCH v2 15/23 Update version for v2.6.0-rc4 release
In reply to Stefan HajnocziFrom: Peter Maydell <[email protected]>
--- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
VERSION +1 -1
@@ -1 +1 @@ -2.5.93 +2.5.94
Signature · 1 line
2.5.5
PATCH v2 16/23 libqos: use virtio_ids.h for device ID definitions
In reply to Stefan HajnocziAvoid redefining device IDs. Use the standard Linux headers that are already in the source tree.
--- tests/libqos/virtio.h | 9 --------- tests/virtio-blk-test.c | 7 ++++--- tests/virtio-net-test.c | 5 +++-- tests/virtio-scsi-test.c | 5 +++-- 4 files changed, 10 insertions(+), 16 deletions(-)
tests/libqos/virtio.h +0 -9
@@ -19,15 +19,6 @@#define QVIRTIO_DRIVER 0x2#define QVIRTIO_DRIVER_OK 0x4 -#define QVIRTIO_NET_DEVICE_ID 0x1 -#define QVIRTIO_BLK_DEVICE_ID 0x2 -#define QVIRTIO_CONSOLE_DEVICE_ID 0x3 -#define QVIRTIO_RNG_DEVICE_ID 0x4 -#define QVIRTIO_BALLOON_DEVICE_ID 0x5 -#define QVIRTIO_RPMSG_DEVICE_ID 0x7 -#define QVIRTIO_SCSI_DEVICE_ID 0x8 -#define QVIRTIO_9P_DEVICE_ID 0x9 -#define QVIRTIO_F_NOTIFY_ON_EMPTY 0x01000000#define QVIRTIO_F_ANY_LAYOUT 0x08000000#define QVIRTIO_F_RING_INDIRECT_DESC 0x10000000
tests/virtio-blk-test.c +4 -3
@@ -19,6 +19,7 @@#include "libqos/malloc-pc.h" #include "libqos/malloc-generic.h" #include "qemu/bswap.h" +#include "standard-headers/linux/virtio_ids.h" #define QVIRTIO_BLK_F_BARRIER 0x00000001#define QVIRTIO_BLK_F_SIZE_MAX 0x00000002
@@ -119,9 +120,9 @@ static QVirtioPCIDevice *virtio_blk_pci_init(QPCIBus *bus, int slot) {QVirtioPCIDevice *dev; - dev =qvirtio_pci_device_find (bus,QVIRTIO_BLK_DEVICE_ID ); + dev =qvirtio_pci_device_find (bus,VIRTIO_ID_BLOCK );g_assert (dev !=NULL ); - g_assert_cmphex(dev->vdev.device_type, ==, QVIRTIO_BLK_DEVICE_ID); + g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_BLOCK); g_assert_cmphex(dev->pdev->devfn, ==, ((slot << 3) | PCI_FN));qvirtio_pci_device_enable (dev);
@@ -733,7 +734,7 @@ static void mmio_basic(void) dev =qvirtio_mmio_init_device (MMIO_DEV_BASE_ADDR ,MMIO_PAGE_SIZE );g_assert (dev !=NULL ); - g_assert_cmphex(dev->vdev.device_type, ==, QVIRTIO_BLK_DEVICE_ID); + g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_BLOCK);qvirtio_reset (&qvirtio_mmio, &dev->vdev);qvirtio_set_acknowledge (&qvirtio_mmio, &dev->vdev);
tests/virtio-net-test.c +3 -2
@@ -21,6 +21,7 @@#include "libqos/malloc-generic.h" #include "qemu/bswap.h" #include "hw/virtio/virtio-net.h" +#include "standard-headers/linux/virtio_ids.h" #define PCI_SLOT_HP 0x06#define PCI_SLOT 0x04
@@ -40,9 +41,9 @@ static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, int slot) {QVirtioPCIDevice *dev; - dev =qvirtio_pci_device_find (bus,QVIRTIO_NET_DEVICE_ID ); + dev =qvirtio_pci_device_find (bus,VIRTIO_ID_NET );g_assert (dev !=NULL ); - g_assert_cmphex(dev->vdev.device_type, ==, QVIRTIO_NET_DEVICE_ID); + g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_NET);qvirtio_pci_device_enable (dev);qvirtio_reset (&qvirtio_pci, &dev->vdev);
tests/virtio-scsi-test.c +3 -2
@@ -18,6 +18,7 @@#include "libqos/malloc.h" #include "libqos/malloc-pc.h" #include "libqos/malloc-generic.h" +#include "standard-headers/linux/virtio_ids.h" #define PCI_SLOT 0x02#define PCI_FN 0x00
@@ -164,10 +165,10 @@ static QVirtIOSCSI *qvirtio_scsi_pci_init(int slot) vs->alloc =pc_alloc_init (); vs->bus =qpci_init_pc (); - dev =qvirtio_pci_device_find (vs->bus,QVIRTIO_SCSI_DEVICE_ID ); + dev =qvirtio_pci_device_find (vs->bus,VIRTIO_ID_SCSI ); vs->dev = (QVirtioDevice *)dev;g_assert (dev !=NULL ); - g_assert_cmphex(vs->dev->device_type, ==, QVIRTIO_SCSI_DEVICE_ID); + g_assert_cmphex(vs->dev->device_type, ==, VIRTIO_ID_SCSI);qvirtio_pci_device_enable (dev);qvirtio_reset (&qvirtio_pci, vs->dev);
Signature · 1 line
2.5.5
PATCH v2 17/23 libqos: drop duplicated PCI vendor ID definition
In reply to Stefan Hajnoczi--- tests/libqos/virtio-pci.c | 3 ++- tests/libqos/virtio.h | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-)
tests/libqos/virtio-pci.c +2 -1
@@ -17,6 +17,7 @@#include "libqos/malloc.h" #include "libqos/malloc-pc.h" +#include "hw/pci/pci.h" #include "hw/pci/pci_regs.h" typedef struct QVirtioPCIForeachData {
@@ -264,7 +265,7 @@ void qvirtio_pci_foreach(QPCIBus *bus, uint16_t device_type, .device_type = device_type, .user_data = data }; -qpci_device_foreach (bus,QVIRTIO_VENDOR_ID ,-1 , +qpci_device_foreach (bus,PCI_VENDOR_ID_REDHAT_QUMRANET ,-1 , qvirtio_pci_foreach_callback, &d); }
tests/libqos/virtio.h +0 -2
@@ -12,8 +12,6 @@#include "libqos/malloc.h" -#define QVIRTIO_VENDOR_ID 0x1AF4 -#define QVIRTIO_RESET 0x0#define QVIRTIO_ACKNOWLEDGE 0x1#define QVIRTIO_DRIVER 0x2
Signature · 1 line
2.5.5
PATCH v2 18/23 libqos: drop duplicated virtio_config.h definitions
In reply to Stefan HajnocziNote that VIRTIO_F_ANY_LAYOUT and VIRTIO_F_NOTIFY_ON_EMPTY are bit numbers in virtio_config.h but bit masks in qtest virtio.h. Therefore it's necessary to change users from X to (1u << X).
--- tests/libqos/virtio.c | 19 ++++++++++--------- tests/libqos/virtio.h | 9 --------- tests/virtio-blk-test.c | 6 ++++-- 3 files changed, 14 insertions(+), 20 deletions(-)
tests/libqos/virtio.c +10 -9
@@ -11,6 +11,7 @@#include <glib.h> #include "libqtest.h" #include "libqos/virtio.h" +#include "standard-headers/linux/virtio_config.h" uint8_t qvirtio_config_readb (const QVirtioBus *bus,QVirtioDevice *d,uint64_t addr)
@@ -55,28 +56,28 @@ QVirtQueue *qvirtqueue_setup(const QVirtioBus *bus, QVirtioDevice *d,void qvirtio_reset (const QVirtioBus *bus,QVirtioDevice *d) { - bus->set_status (d,QVIRTIO_RESET ); - g_assert_cmphex(bus->get_status(d), ==, QVIRTIO_RESET); + bus->set_status (d,0 ); + g_assert_cmphex(bus->get_status(d), ==, 0); }void qvirtio_set_acknowledge (const QVirtioBus *bus,QVirtioDevice *d) { - bus->set_status (d, bus->get_status (d) |QVIRTIO_ACKNOWLEDGE ); - g_assert_cmphex(bus->get_status(d), ==, QVIRTIO_ACKNOWLEDGE); + bus->set_status (d, bus->get_status (d) |VIRTIO_CONFIG_S_ACKNOWLEDGE ); + g_assert_cmphex(bus->get_status(d), ==, VIRTIO_CONFIG_S_ACKNOWLEDGE); }void qvirtio_set_driver (const QVirtioBus *bus,QVirtioDevice *d) { - bus->set_status (d, bus->get_status (d) |QVIRTIO_DRIVER ); + bus->set_status (d, bus->get_status (d) |VIRTIO_CONFIG_S_DRIVER ); g_assert_cmphex(bus->get_status(d), ==, -QVIRTIO_DRIVER |QVIRTIO_ACKNOWLEDGE ); +VIRTIO_CONFIG_S_DRIVER |VIRTIO_CONFIG_S_ACKNOWLEDGE ); }void qvirtio_set_driver_ok (const QVirtioBus *bus,QVirtioDevice *d) { - bus->set_status (d, bus->get_status (d) |QVIRTIO_DRIVER_OK ); - g_assert_cmphex(bus->get_status(d), ==, -QVIRTIO_DRIVER_OK |QVIRTIO_DRIVER |QVIRTIO_ACKNOWLEDGE ); + bus->set_status (d, bus->get_status (d) |VIRTIO_CONFIG_S_DRIVER_OK ); + g_assert_cmphex(bus->get_status(d), ==, VIRTIO_CONFIG_S_DRIVER_OK | +VIRTIO_CONFIG_S_DRIVER |VIRTIO_CONFIG_S_ACKNOWLEDGE ); } void qvirtio_wait_queue_isr(const QVirtioBus *bus, QVirtioDevice *d,
tests/libqos/virtio.h +0 -9
@@ -12,13 +12,6 @@#include "libqos/malloc.h" -#define QVIRTIO_RESET 0x0 -#define QVIRTIO_ACKNOWLEDGE 0x1 -#define QVIRTIO_DRIVER 0x2 -#define QVIRTIO_DRIVER_OK 0x4 - -#define QVIRTIO_F_NOTIFY_ON_EMPTY 0x01000000 -#define QVIRTIO_F_ANY_LAYOUT 0x08000000#define QVIRTIO_F_RING_INDIRECT_DESC 0x10000000#define QVIRTIO_F_RING_EVENT_IDX 0x20000000#define QVIRTIO_F_BAD_FEATURE 0x40000000
@@ -27,8 +20,6 @@#define QVRING_DESC_F_WRITE 0x2#define QVRING_DESC_F_INDIRECT 0x4 -#define QVIRTIO_F_NOTIFY_ON_EMPTY 0x01000000 -#define QVIRTIO_F_ANY_LAYOUT 0x08000000#define QVIRTIO_F_RING_INDIRECT_DESC 0x10000000#define QVIRTIO_F_RING_EVENT_IDX 0x20000000#define QVIRTIO_F_BAD_FEATURE 0x40000000
tests/virtio-blk-test.c +4 -2
@@ -20,6 +20,7 @@#include "libqos/malloc-generic.h" #include "qemu/bswap.h" #include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/virtio_config.h" #define QVIRTIO_BLK_F_BARRIER 0x00000001#define QVIRTIO_BLK_F_SIZE_MAX 0x00000002
@@ -240,7 +241,7 @@ static void test_basic(const QVirtioBus *bus, QVirtioDevice *dev,guest_free (alloc, req_addr); -if (features &QVIRTIO_F_ANY_LAYOUT ) { +if (features & (1u <<VIRTIO_F_ANY_LAYOUT )) {/* Write and read with 2 descriptor layout */ /* Write request */ req.type =QVIRTIO_BLK_T_OUT ;
@@ -607,7 +608,8 @@ static void pci_idx(void) features =qvirtio_get_features (&qvirtio_pci, &dev->vdev); features = features & ~(QVIRTIO_F_BAD_FEATURE |QVIRTIO_F_RING_INDIRECT_DESC | -QVIRTIO_F_NOTIFY_ON_EMPTY |QVIRTIO_BLK_F_SCSI ); + (1u <<VIRTIO_F_NOTIFY_ON_EMPTY ) | +QVIRTIO_BLK_F_SCSI );qvirtio_set_features (&qvirtio_pci, &dev->vdev, features); vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&qvirtio_pci, &dev->vdev,
Signature · 1 line
2.5.5
PATCH v2 19/23 libqos: drop duplicated virtio_ring.h bit definitions
In reply to Stefan HajnocziNote that virtio_ring.h defines feature bits using their bit number:
#define VIRTIO_RING_F_INDIRECT_DESC 28
On the other hand libqos virtio.h uses the bit mask:
#define QVIRTIO_F_RING_INDIRECT_DESC 0x10000000
The patch makes the necessary adjustments.
I have used "1u << BITMASK" instead of "1ULL << BITMASK" because the 64-bit feature fields are not implemented in libqos virtio.
--- tests/libqos/virtio-mmio.c | 5 +++-- tests/libqos/virtio-pci.c | 5 +++-- tests/libqos/virtio.c | 13 +++++++------ tests/libqos/virtio.h | 14 -------------- tests/virtio-blk-test.c | 18 +++++++++++------- tests/virtio-net-test.c | 5 +++-- 6 files changed, 27 insertions(+), 33 deletions(-)
tests/libqos/virtio-mmio.c +3 -2
@@ -14,6 +14,7 @@#include "libqos/virtio-mmio.h" #include "libqos/malloc.h" #include "libqos/malloc-generic.h" +#include "standard-headers/linux/virtio_ring.h" static uint8_t qvirtio_mmio_config_readb (QVirtioDevice *d,uint64_t addr) {
@@ -136,8 +137,8 @@ static QVirtQueue *qvirtio_mmio_virtqueue_setup(QVirtioDevice *d, vq->free_head =0 ; vq->num_free = vq->size; vq->align = dev->page_size; - vq->indirect = (dev->features &QVIRTIO_F_RING_INDIRECT_DESC ) !=0 ; - vq->event = (dev->features &QVIRTIO_F_RING_EVENT_IDX ) !=0 ; + vq->indirect = (dev->features & (1u <<VIRTIO_RING_F_INDIRECT_DESC )) !=0 ; + vq->event = (dev->features & (1u <<VIRTIO_RING_F_EVENT_IDX )) !=0 ;writel (dev->addr +QVIRTIO_MMIO_QUEUE_NUM , vq->size);
tests/libqos/virtio-pci.c +3 -2
@@ -16,6 +16,7 @@#include "libqos/pci-pc.h" #include "libqos/malloc.h" #include "libqos/malloc-pc.h" +#include "standard-headers/linux/virtio_ring.h" #include "hw/pci/pci.h" #include "hw/pci/pci_regs.h"
@@ -213,8 +214,8 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d, vqpci->vq.free_head =0 ; vqpci->vq.num_free = vqpci->vq.size; vqpci->vq.align =QVIRTIO_PCI_ALIGN ; - vqpci->vq.indirect = (feat &QVIRTIO_F_RING_INDIRECT_DESC ) !=0 ; - vqpci->vq.event = (feat &QVIRTIO_F_RING_EVENT_IDX ) !=0 ; + vqpci->vq.indirect = (feat & (1u <<VIRTIO_RING_F_INDIRECT_DESC )) !=0 ; + vqpci->vq.event = (feat & (1u <<VIRTIO_RING_F_EVENT_IDX )) !=0 ; vqpci->msix_entry =-1 ; vqpci->msix_addr =0 ;
tests/libqos/virtio.c +7 -6
@@ -12,6 +12,7 @@#include "libqtest.h" #include "libqos/virtio.h" #include "standard-headers/linux/virtio_config.h" +#include "standard-headers/linux/virtio_ring.h" uint8_t qvirtio_config_readb (const QVirtioBus *bus,QVirtioDevice *d,uint64_t addr)
@@ -173,7 +174,7 @@ QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,/* indirect->desc[i].addr */ writeq (indirect->desc + (16 * i),0 );/* indirect->desc[i].flags */ -writew (indirect->desc + (16 * i) +12 ,QVRING_DESC_F_NEXT ); +writew (indirect->desc + (16 * i) +12 ,VRING_DESC_F_NEXT );/* indirect->desc[i].next */ writew (indirect->desc + (16 * i) +14 , i +1 ); }
@@ -191,7 +192,7 @@ void qvring_indirect_desc_add(QVRingIndirectDesc *indirect, uint64_t data, flags =readw (indirect->desc + (16 * indirect->index) +12 );if (write) { - flags |=QVRING_DESC_F_WRITE ; + flags |=VRING_DESC_F_WRITE ; }/* indirect->desc[indirect->index].addr */
@@ -211,11 +212,11 @@ uint32_t qvirtqueue_add(QVirtQueue *vq, uint64_t data, uint32_t len, bool write, vq->num_free--;if (write) { - flags |=QVRING_DESC_F_WRITE ; + flags |=VRING_DESC_F_WRITE ; }if (next) { - flags |=QVRING_DESC_F_NEXT ; + flags |=VRING_DESC_F_NEXT ; }/* vq->desc[vq->free_head].addr */
@@ -242,7 +243,7 @@ uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect)writel (vq->desc + (16 * vq->free_head) +8 ,sizeof (QVRingDesc) * indirect->elem);/* vq->desc[vq->free_head].flags */ -writew (vq->desc + (16 * vq->free_head) +12 ,QVRING_DESC_F_INDIRECT ); +writew (vq->desc + (16 * vq->free_head) +12 ,VRING_DESC_F_INDIRECT );return vq->free_head++;/* Return and increase, in this order */ }
@@ -268,7 +269,7 @@ void qvirtqueue_kick(const QVirtioBus *bus, QVirtioDevice *d, QVirtQueue *vq, (sizeof(struct QVRingUsedElem) * vq->size));/* < 1 because we add elements to avail queue one by one */ -if ((flags &QVRING_USED_F_NO_NOTIFY ) ==0 && +if ((flags &VRING_USED_F_NO_NOTIFY ) ==0 && (!vq->event || (uint16_t )(idx-avail_event) <1 )) { bus->virtqueue_kick (d, vq); }
tests/libqos/virtio.h +0 -14
@@ -12,22 +12,8 @@#include "libqos/malloc.h" -#define QVIRTIO_F_RING_INDIRECT_DESC 0x10000000 -#define QVIRTIO_F_RING_EVENT_IDX 0x20000000#define QVIRTIO_F_BAD_FEATURE 0x40000000 -#define QVRING_DESC_F_NEXT 0x1 -#define QVRING_DESC_F_WRITE 0x2 -#define QVRING_DESC_F_INDIRECT 0x4 - -#define QVIRTIO_F_RING_INDIRECT_DESC 0x10000000 -#define QVIRTIO_F_RING_EVENT_IDX 0x20000000 -#define QVIRTIO_F_BAD_FEATURE 0x40000000 - -#define QVRING_AVAIL_F_NO_INTERRUPT 1 - -#define QVRING_USED_F_NO_NOTIFY 1 - typedef struct QVirtioDevice { /* Device type */ uint16_t device_type;
tests/virtio-blk-test.c +11 -7
@@ -21,6 +21,7 @@#include "qemu/bswap.h" #include "standard-headers/linux/virtio_ids.h" #include "standard-headers/linux/virtio_config.h" +#include "standard-headers/linux/virtio_ring.h" #define QVIRTIO_BLK_F_BARRIER 0x00000001#define QVIRTIO_BLK_F_SIZE_MAX 0x00000002
@@ -184,7 +185,8 @@ static void test_basic(const QVirtioBus *bus, QVirtioDevice *dev, features =qvirtio_get_features (bus, dev); features = features & ~(QVIRTIO_F_BAD_FEATURE | -QVIRTIO_F_RING_INDIRECT_DESC |QVIRTIO_F_RING_EVENT_IDX | + (1u <<VIRTIO_RING_F_INDIRECT_DESC ) | + (1u <<VIRTIO_RING_F_EVENT_IDX ) |QVIRTIO_BLK_F_SCSI );qvirtio_set_features (bus, dev, features);
@@ -350,9 +352,10 @@ static void pci_indirect(void) g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); features =qvirtio_get_features (&qvirtio_pci, &dev->vdev); - g_assert_cmphex(features & QVIRTIO_F_RING_INDIRECT_DESC, !=, 0); - features = features & ~(QVIRTIO_F_BAD_FEATURE |QVIRTIO_F_RING_EVENT_IDX | -QVIRTIO_BLK_F_SCSI ); + g_assert_cmphex(features & (1u << VIRTIO_RING_F_INDIRECT_DESC), !=, 0); + features = features & ~(QVIRTIO_F_BAD_FEATURE | + (1u <<VIRTIO_RING_F_EVENT_IDX ) | +QVIRTIO_BLK_F_SCSI );qvirtio_set_features (&qvirtio_pci, &dev->vdev, features); alloc =pc_alloc_init ();
@@ -492,8 +495,9 @@ static void pci_msix(void) features =qvirtio_get_features (&qvirtio_pci, &dev->vdev); features = features & ~(QVIRTIO_F_BAD_FEATURE | -QVIRTIO_F_RING_INDIRECT_DESC | -QVIRTIO_F_RING_EVENT_IDX |QVIRTIO_BLK_F_SCSI ); + (1u <<VIRTIO_RING_F_INDIRECT_DESC ) | + (1u <<VIRTIO_RING_F_EVENT_IDX ) | +QVIRTIO_BLK_F_SCSI );qvirtio_set_features (&qvirtio_pci, &dev->vdev, features); vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&qvirtio_pci, &dev->vdev,
@@ -607,7 +611,7 @@ static void pci_idx(void) features =qvirtio_get_features (&qvirtio_pci, &dev->vdev); features = features & ~(QVIRTIO_F_BAD_FEATURE | -QVIRTIO_F_RING_INDIRECT_DESC | + (1u <<VIRTIO_RING_F_INDIRECT_DESC ) | (1u <<VIRTIO_F_NOTIFY_ON_EMPTY ) |QVIRTIO_BLK_F_SCSI );qvirtio_set_features (&qvirtio_pci, &dev->vdev, features);
tests/virtio-net-test.c +3 -2
@@ -22,6 +22,7 @@#include "qemu/bswap.h" #include "hw/virtio/virtio-net.h" #include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/virtio_ring.h" #define PCI_SLOT_HP 0x06#define PCI_SLOT 0x04
@@ -71,8 +72,8 @@ static void driver_init(const QVirtioBus *bus, QVirtioDevice *dev) features =qvirtio_get_features (bus, dev); features = features & ~(QVIRTIO_F_BAD_FEATURE | -QVIRTIO_F_RING_INDIRECT_DESC | -QVIRTIO_F_RING_EVENT_IDX ); + (1u <<VIRTIO_RING_F_INDIRECT_DESC ) | + (1u <<VIRTIO_RING_F_EVENT_IDX ));qvirtio_set_features (bus, dev, features);qvirtio_set_driver_ok (bus, dev);
Signature · 1 line
2.5.5
PATCH v2 20/23 libqos: drop duplicated virtio_vring.h structs
In reply to Stefan HajnocziThe descriptor element, used, and avail vring structs are defined in virtio_ring.h. There is no need to duplicate them in libqos virtio.
--- tests/libqos/virtio.c | 10 +++++----- tests/libqos/virtio.h | 39 +++++++-------------------------------- 2 files changed, 12 insertions(+), 37 deletions(-)
tests/libqos/virtio.c +5 -5
@@ -136,7 +136,7 @@ void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr)int i; vq->desc = addr; - vq->avail = vq->desc + vq->size*sizeof (QVRingDesc); + vq->avail = vq->desc + vq->size *sizeof (struct vring_desc ); vq->used = (uint64_t )((vq->avail +sizeof (uint16_t ) * (3 + vq->size) + vq->align -1 ) & ~(vq->align -1 ));
@@ -157,7 +157,7 @@ void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr)/* vq->used->flags */ writew (vq->used,0 );/* vq->used->avail_event */ -writew (vq->used+2 +(sizeof (struct QVRingUsedElem )*vq->size),0 ); +writew (vq->used +2 +sizeof (struct vring_used_elem ) * vq->size,0 ); } QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,
@@ -168,7 +168,7 @@ QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d, indirect->index =0 ; indirect->elem = elem; - indirect->desc =guest_alloc (alloc,sizeof (QVRingDesc)*elem); + indirect->desc =guest_alloc (alloc,sizeof (struct vring_desc ) * elem);for (i =0 ; i < elem -1 ; ++i) {/* indirect->desc[i].addr */
@@ -241,7 +241,7 @@ uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect)writeq (vq->desc + (16 * vq->free_head), indirect->desc);/* vq->desc[vq->free_head].len */ writel (vq->desc + (16 * vq->free_head) +8 , -sizeof (QVRingDesc) * indirect->elem); +sizeof (struct vring_desc ) * indirect->elem);/* vq->desc[vq->free_head].flags */ writew (vq->desc + (16 * vq->free_head) +12 ,VRING_DESC_F_INDIRECT );
@@ -266,7 +266,7 @@ void qvirtqueue_kick(const QVirtioBus *bus, QVirtioDevice *d, QVirtQueue *vq,/* Must read after idx is updated */ flags =readw (vq->avail); avail_event =readw (vq->used +4 + - (sizeof (struct QVRingUsedElem ) * vq->size)); +sizeof (struct vring_used_elem ) * vq->size);/* < 1 because we add elements to avail queue one by one */ if ((flags & VRING_USED_F_NO_NOTIFY) == 0 &&
tests/libqos/virtio.h +7 -32
@@ -11,6 +11,7 @@#define LIBQOS_VIRTIO_H #include "libqos/malloc.h" +#include "standard-headers/linux/virtio_ring.h" #define QVIRTIO_F_BAD_FEATURE 0x40000000
@@ -19,36 +20,10 @@ typedef struct QVirtioDevice {uint16_t device_type; } QVirtioDevice; -typedef struct QVRingDesc { -uint64_t addr; -uint32_t len; -uint16_t flags; -uint16_t next; -}QVRingDesc ; - -typedef struct QVRingAvail { -uint16_t flags; -uint16_t idx; -uint16_t ring[0 ];/* This is an array of uint16_t */ -uint16_t used_event; -}QVRingAvail ; - -typedef struct QVRingUsedElem { -uint32_t id; -uint32_t len; -}QVRingUsedElem ; - -typedef struct QVRingUsed { -uint16_t flags; -uint16_t idx; -QVRingUsedElem ring[0 ];/* This is an array of QVRingUsedElem structs */ -uint16_t avail_event; -}QVRingUsed ; - typedef struct QVirtQueue { - uint64_t desc; /* This points to an array of QVRingDesc */ - uint64_t avail; /* This points to a QVRingAvail */ - uint64_t used; /* This points to a QVRingDesc */ + uint64_t desc; /* This points to an array of struct vring_desc */ + uint64_t avail; /* This points to a struct vring_avail */ + uint64_t used; /* This points to a struct vring_desc */ uint16_t index; uint32_t size; uint32_t free_head;
@@ -59,7 +34,7 @@ typedef struct QVirtQueue { } QVirtQueue;typedef struct QVRingIndirectDesc { -uint64_t desc;/* This points to an array fo QVRingDesc */ +uint64_t desc;/* This points to an array fo struct vring_desc */ uint16_t index;uint16_t elem; }QVRingIndirectDesc ;
@@ -110,9 +85,9 @@ typedef struct QVirtioBus {static inline uint32_t qvring_size (uint32_t num,uint32_t align) { -return ((sizeof (struct QVRingDesc ) * num +sizeof (uint16_t ) * (3 + num) +return ((sizeof (struct vring_desc ) * num +sizeof (uint16_t ) * (3 + num) + align -1 ) & ~(align -1 )) - +sizeof (uint16_t ) *3 +sizeof (struct QVRingUsedElem ) * num; + +sizeof (uint16_t ) *3 +sizeof (struct vring_used_elem ) * num; } uint8_t qvirtio_config_readb(const QVirtioBus *bus, QVirtioDevice *d,
Signature · 1 line
2.5.5
PATCH v2 21/23 libqos: drop duplicated virtio_blk.h definitions
In reply to Stefan Hajnoczi--- tests/virtio-blk-test.c | 50 ++++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 34 deletions(-)
tests/virtio-blk-test.c +16 -34
@@ -22,25 +22,7 @@#include "standard-headers/linux/virtio_ids.h" #include "standard-headers/linux/virtio_config.h" #include "standard-headers/linux/virtio_ring.h" - -#define QVIRTIO_BLK_F_BARRIER 0x00000001 -#define QVIRTIO_BLK_F_SIZE_MAX 0x00000002 -#define QVIRTIO_BLK_F_SEG_MAX 0x00000004 -#define QVIRTIO_BLK_F_GEOMETRY 0x00000010 -#define QVIRTIO_BLK_F_RO 0x00000020 -#define QVIRTIO_BLK_F_BLK_SIZE 0x00000040 -#define QVIRTIO_BLK_F_SCSI 0x00000080 -#define QVIRTIO_BLK_F_WCE 0x00000200 -#define QVIRTIO_BLK_F_TOPOLOGY 0x00000400 -#define QVIRTIO_BLK_F_CONFIG_WCE 0x00000800 - -#define QVIRTIO_BLK_T_IN 0 -#define QVIRTIO_BLK_T_OUT 1 -#define QVIRTIO_BLK_T_SCSI_CMD 2 -#define QVIRTIO_BLK_T_SCSI_CMD_OUT 3 -#define QVIRTIO_BLK_T_FLUSH 4 -#define QVIRTIO_BLK_T_FLUSH_OUT 5 -#define QVIRTIO_BLK_T_GET_ID 8 +#include "standard-headers/linux/virtio_blk.h" #define TEST_IMAGE_SIZE (64 * 1024 * 1024)#define QVIRTIO_BLK_TIMEOUT_US (30 * 1000 * 1000)
@@ -187,14 +169,14 @@ static void test_basic(const QVirtioBus *bus, QVirtioDevice *dev, features = features & ~(QVIRTIO_F_BAD_FEATURE | (1u <<VIRTIO_RING_F_INDIRECT_DESC ) | (1u <<VIRTIO_RING_F_EVENT_IDX ) | -QVIRTIO_BLK_F_SCSI ); + (1u <<VIRTIO_BLK_F_SCSI ));qvirtio_set_features (bus, dev, features);qvirtio_set_driver_ok (bus, dev);/* Write and read with 3 descriptor layout */ /* Write request */ - req.type =QVIRTIO_BLK_T_OUT ; + req.type =VIRTIO_BLK_T_OUT ; req.ioprio =1 ; req.sector =0 ; req.data =g_malloc0 (512 );
@@ -217,7 +199,7 @@ static void test_basic(const QVirtioBus *bus, QVirtioDevice *dev,guest_free (alloc, req_addr);/* Read request */ - req.type =QVIRTIO_BLK_T_IN ; + req.type =VIRTIO_BLK_T_IN ; req.ioprio =1 ; req.sector =0 ; req.data =g_malloc0 (512 );
@@ -246,7 +228,7 @@ static void test_basic(const QVirtioBus *bus, QVirtioDevice *dev,if (features & (1u <<VIRTIO_F_ANY_LAYOUT )) {/* Write and read with 2 descriptor layout */ /* Write request */ - req.type =QVIRTIO_BLK_T_OUT ; + req.type =VIRTIO_BLK_T_OUT ; req.ioprio =1 ; req.sector =1 ; req.data =g_malloc0 (512 );
@@ -267,7 +249,7 @@ static void test_basic(const QVirtioBus *bus, QVirtioDevice *dev,guest_free (alloc, req_addr);/* Read request */ - req.type =QVIRTIO_BLK_T_IN ; + req.type =VIRTIO_BLK_T_IN ; req.ioprio =1 ; req.sector =1 ; req.data =g_malloc0 (512 );
@@ -355,7 +337,7 @@ static void pci_indirect(void) g_assert_cmphex(features & (1u << VIRTIO_RING_F_INDIRECT_DESC), !=, 0); features = features & ~(QVIRTIO_F_BAD_FEATURE | (1u <<VIRTIO_RING_F_EVENT_IDX ) | -QVIRTIO_BLK_F_SCSI ); + (1u <<VIRTIO_BLK_F_SCSI ));qvirtio_set_features (&qvirtio_pci, &dev->vdev, features); alloc =pc_alloc_init ();
@@ -364,7 +346,7 @@ static void pci_indirect(void)qvirtio_set_driver_ok (&qvirtio_pci, &dev->vdev);/* Write request */ - req.type =QVIRTIO_BLK_T_OUT ; + req.type =VIRTIO_BLK_T_OUT ; req.ioprio =1 ; req.sector =0 ; req.data =g_malloc0 (512 );
@@ -389,7 +371,7 @@ static void pci_indirect(void)guest_free (alloc, req_addr);/* Read request */ - req.type =QVIRTIO_BLK_T_IN ; + req.type =VIRTIO_BLK_T_IN ; req.ioprio =1 ; req.sector =0 ; req.data =g_malloc0 (512 );
@@ -497,7 +479,7 @@ static void pci_msix(void) features = features & ~(QVIRTIO_F_BAD_FEATURE | (1u <<VIRTIO_RING_F_INDIRECT_DESC ) | (1u <<VIRTIO_RING_F_EVENT_IDX ) | -QVIRTIO_BLK_F_SCSI ); + (1u <<VIRTIO_BLK_F_SCSI ));qvirtio_set_features (&qvirtio_pci, &dev->vdev, features); vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&qvirtio_pci, &dev->vdev,
@@ -516,7 +498,7 @@ static void pci_msix(void) g_assert_cmpint(capacity, ==, n_size / 512);/* Write request */ - req.type =QVIRTIO_BLK_T_OUT ; + req.type =VIRTIO_BLK_T_OUT ; req.ioprio =1 ; req.sector =0 ; req.data =g_malloc0 (512 );
@@ -540,7 +522,7 @@ static void pci_msix(void)guest_free (alloc, req_addr);/* Read request */ - req.type =QVIRTIO_BLK_T_IN ; + req.type =VIRTIO_BLK_T_IN ; req.ioprio =1 ; req.sector =0 ; req.data =g_malloc0 (512 );
@@ -613,7 +595,7 @@ static void pci_idx(void) features = features & ~(QVIRTIO_F_BAD_FEATURE | (1u <<VIRTIO_RING_F_INDIRECT_DESC ) | (1u <<VIRTIO_F_NOTIFY_ON_EMPTY ) | -QVIRTIO_BLK_F_SCSI ); + (1u <<VIRTIO_BLK_F_SCSI ));qvirtio_set_features (&qvirtio_pci, &dev->vdev, features); vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&qvirtio_pci, &dev->vdev,
@@ -623,7 +605,7 @@ static void pci_idx(void)qvirtio_set_driver_ok (&qvirtio_pci, &dev->vdev);/* Write request */ - req.type =QVIRTIO_BLK_T_OUT ; + req.type =VIRTIO_BLK_T_OUT ; req.ioprio =1 ; req.sector =0 ; req.data =g_malloc0 (512 );
@@ -642,7 +624,7 @@ static void pci_idx(void) QVIRTIO_BLK_TIMEOUT_US);/* Write request */ - req.type =QVIRTIO_BLK_T_OUT ; + req.type =VIRTIO_BLK_T_OUT ; req.ioprio =1 ; req.sector =1 ; req.data =g_malloc0 (512 );
@@ -668,7 +650,7 @@ static void pci_idx(void)guest_free (alloc, req_addr);/* Read request */ - req.type =QVIRTIO_BLK_T_IN ; + req.type =VIRTIO_BLK_T_IN ; req.ioprio =1 ; req.sector =1 ; req.data =g_malloc0 (512 );
Signature · 1 line
2.5.5
PATCH v2 22/23 libqos: drop duplicated virtio_scsi.h definitions
In reply to Stefan Hajnoczi--- tests/virtio-scsi-test.c | 45 +++++++++++++++------------------------------ 1 file changed, 15 insertions(+), 30 deletions(-)
tests/virtio-scsi-test.c +15 -30
@@ -19,11 +19,11 @@#include "libqos/malloc-pc.h" #include "libqos/malloc-generic.h" #include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/virtio_scsi.h" #define PCI_SLOT 0x02#define PCI_FN 0x00#define QVIRTIO_SCSI_TIMEOUT_US (1 * 1000 * 1000) -#define CDB_SIZE 32#define MAX_NUM_QUEUES 64
@@ -35,24 +35,6 @@ typedef struct {QVirtQueue *vq[MAX_NUM_QUEUES +2 ]; } QVirtIOSCSI; -typedef struct { -uint8_t lun[8 ]; -int64_t tag; -uint8_t task_attr; -uint8_t prio; -uint8_t crn; -uint8_t cdb[CDB_SIZE ]; -} QEMU_PACKED QVirtIOSCSICmdReq; - -typedef struct { -uint32_t sense_len; -uint32_t resid; -uint16_t status_qualifier; -uint8_t status; -uint8_t response; -uint8_t sense[96 ]; -} QEMU_PACKED QVirtIOSCSICmdResp; -static void qvirtio_scsi_start (const char *extra_opts) {char *cmdline;
@@ -101,11 +83,11 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb,const uint8_t *data_in, size_t data_in_len, uint8_t *data_out, size_t data_out_len, - QVirtIOSCSICmdResp *resp_out) + struct virtio_scsi_cmd_resp *resp_out) { QVirtQueue *vq; -QVirtIOSCSICmdReq req = { {0 } }; -QVirtIOSCSICmdResp resp = { .response =0xff , .status =0xff }; +struct virtio_scsi_cmd_req req = { {0 } }; +struct virtio_scsi_cmd_resp resp = { .response =0xff , .status =0xff };uint64_t req_addr, resp_addr, data_in_addr =0 , data_out_addr =0 ;uint8_t response;uint32_t free_head;
@@ -114,7 +96,7 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb, req.lun[0 ] =1 ;/* Select LUN */ req.lun[1 ] =1 ;/* Select target 1 */ -memcpy (req.cdb, cdb,CDB_SIZE ); +memcpy (req.cdb, cdb,VIRTIO_SCSI_CDB_SIZE );/* XXX: Fix endian if any multi-byte field in req/resp is used */
@@ -139,7 +121,8 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb,qvirtqueue_kick (&qvirtio_pci, vs->dev, vq, free_head);qvirtio_wait_queue_isr (&qvirtio_pci, vs->dev, vq,QVIRTIO_SCSI_TIMEOUT_US ); - response =readb (resp_addr + offsetof(QVirtIOSCSICmdResp , response)); + response =readb (resp_addr + + offsetof(struct virtio_scsi_cmd_resp , response));if (resp_out) {memread (resp_addr, resp_out,sizeof (*resp_out));
@@ -154,10 +137,10 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb,static QVirtIOSCSI *qvirtio_scsi_pci_init (int slot) { -const uint8_t test_unit_ready_cdb[CDB_SIZE ] = {}; +const uint8_t test_unit_ready_cdb[VIRTIO_SCSI_CDB_SIZE ] = {};QVirtIOSCSI *vs;QVirtioPCIDevice *dev; -QVirtIOSCSICmdResp resp; +struct virtio_scsi_cmd_resp resp;void *addr;int i;
@@ -240,10 +223,12 @@ static void test_unaligned_write_same(void)QVirtIOSCSI *vs;uint8_t buf1[512 ] = {0 };uint8_t buf2[512 ] = {1 }; -const uint8_t write_same_cdb_1[CDB_SIZE ] = {0x41 ,0x00 ,0x00 ,0x00 ,0x00 , -0x01 ,0x00 ,0x00 ,0x02 ,0x00 }; -const uint8_t write_same_cdb_2[CDB_SIZE ] = {0x41 ,0x00 ,0x00 ,0x00 ,0x00 , -0x01 ,0x00 ,0x33 ,0x00 ,0x00 }; +const uint8_t write_same_cdb_1[VIRTIO_SCSI_CDB_SIZE ] = { +0x41 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x00 ,0x00 ,0x02 ,0x00 + }; +const uint8_t write_same_cdb_2[VIRTIO_SCSI_CDB_SIZE ] = { +0x41 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x00 ,0x33 ,0x00 ,0x00 + };qvirtio_scsi_start ("-drive file=blkdebug::null-co://,if=none,id=dr1" ",format=raw,file.align=4k "
Signature · 1 line
2.5.5
Stefan Hajnoczi
NAKQuoted 2 lines · Stefan Hajnoczi
v2:
* Fix missing s/X/(1u << X)/ conversion in Patch 3 [Marc]
NACK
A bunch of extra commits were included due to an error invoking my patch submission script. Sorry for the noise, I'll resend a clean series.
Stefan
PATCH v2 23/23 libqos: drop duplicated virtio_pci.h definitions
In reply to Stefan Hajnoczi--- tests/libqos/virtio-pci.c | 42 ++++++++++++++++++++++-------------------- tests/libqos/virtio-pci.h | 17 ----------------- tests/virtio-blk-test.c | 11 ++++++----- tests/virtio-scsi-test.c | 3 ++- 4 files changed, 30 insertions(+), 43 deletions(-)
tests/libqos/virtio-pci.c +22 -20
@@ -17,6 +17,7 @@#include "libqos/malloc.h" #include "libqos/malloc-pc.h" #include "standard-headers/linux/virtio_ring.h" +#include "standard-headers/linux/virtio_pci.h" #include "hw/pci/pci.h" #include "hw/pci/pci_regs.h"
@@ -104,31 +105,31 @@ static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, uint64_t addr)static uint32_t qvirtio_pci_get_features (QVirtioDevice *d) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -return qpci_io_readl (dev->pdev, dev->addr +QVIRTIO_PCI_DEVICE_FEATURES ); +return qpci_io_readl (dev->pdev, dev->addr +VIRTIO_PCI_HOST_FEATURES ); }static void qvirtio_pci_set_features (QVirtioDevice *d,uint32_t features) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -qpci_io_writel (dev->pdev, dev->addr +QVIRTIO_PCI_GUEST_FEATURES , features); +qpci_io_writel (dev->pdev, dev->addr +VIRTIO_PCI_GUEST_FEATURES , features); }static uint32_t qvirtio_pci_get_guest_features (QVirtioDevice *d) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -return qpci_io_readl (dev->pdev, dev->addr +QVIRTIO_PCI_GUEST_FEATURES ); +return qpci_io_readl (dev->pdev, dev->addr +VIRTIO_PCI_GUEST_FEATURES ); }static uint8_t qvirtio_pci_get_status (QVirtioDevice *d) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -return qpci_io_readb (dev->pdev, dev->addr +QVIRTIO_PCI_DEVICE_STATUS ); +return qpci_io_readb (dev->pdev, dev->addr +VIRTIO_PCI_STATUS ); }static void qvirtio_pci_set_status (QVirtioDevice *d,uint8_t status) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -qpci_io_writeb (dev->pdev, dev->addr +QVIRTIO_PCI_DEVICE_STATUS , status); +qpci_io_writeb (dev->pdev, dev->addr +VIRTIO_PCI_STATUS , status); }static bool qvirtio_pci_get_queue_isr_status (QVirtioDevice *d,QVirtQueue *vq)
@@ -152,7 +153,7 @@ static bool qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq) } } }else { -return qpci_io_readb (dev->pdev, dev->addr +QVIRTIO_PCI_ISR_STATUS ) &1 ; +return qpci_io_readb (dev->pdev, dev->addr +VIRTIO_PCI_ISR ) &1 ; } }
@@ -176,26 +177,26 @@ static bool qvirtio_pci_get_config_isr_status(QVirtioDevice *d) } } }else { -return qpci_io_readb (dev->pdev, dev->addr +QVIRTIO_PCI_ISR_STATUS ) &2 ; +return qpci_io_readb (dev->pdev, dev->addr +VIRTIO_PCI_ISR ) &2 ; } }static void qvirtio_pci_queue_select (QVirtioDevice *d,uint16_t index) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -qpci_io_writeb (dev->pdev, dev->addr +QVIRTIO_PCI_QUEUE_SELECT , index); +qpci_io_writeb (dev->pdev, dev->addr +VIRTIO_PCI_QUEUE_SEL , index); }static uint16_t qvirtio_pci_get_queue_size (QVirtioDevice *d) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -return qpci_io_readw (dev->pdev, dev->addr +QVIRTIO_PCI_QUEUE_SIZE ); +return qpci_io_readw (dev->pdev, dev->addr +VIRTIO_PCI_QUEUE_NUM ); }static void qvirtio_pci_set_queue_address (QVirtioDevice *d,uint32_t pfn) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -qpci_io_writel (dev->pdev, dev->addr +QVIRTIO_PCI_QUEUE_ADDRESS , pfn); +qpci_io_writel (dev->pdev, dev->addr +VIRTIO_PCI_QUEUE_PFN , pfn); } static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d,
@@ -213,7 +214,7 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d, vqpci->vq.size =qvirtio_pci_get_queue_size (d); vqpci->vq.free_head =0 ; vqpci->vq.num_free = vqpci->vq.size; - vqpci->vq.align =QVIRTIO_PCI_ALIGN ; + vqpci->vq.align =VIRTIO_PCI_VRING_ALIGN ; vqpci->vq.indirect = (feat & (1u <<VIRTIO_RING_F_INDIRECT_DESC )) !=0 ; vqpci->vq.event = (feat & (1u <<VIRTIO_RING_F_EVENT_IDX )) !=0 ;
@@ -227,9 +228,10 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d,/* Check power of 2 */ g_assert_cmpint(vqpci->vq.size & (vqpci->vq.size - 1), ==, 0); - addr =guest_alloc (alloc,qvring_size (vqpci->vq.size,QVIRTIO_PCI_ALIGN )); + addr =guest_alloc (alloc,qvring_size (vqpci->vq.size, +VIRTIO_PCI_VRING_ALIGN ));qvring_init (alloc, &vqpci->vq, addr); -qvirtio_pci_set_queue_address (d, vqpci->vq.desc /QVIRTIO_PCI_ALIGN ); +qvirtio_pci_set_queue_address (d, vqpci->vq.desc /VIRTIO_PCI_VRING_ALIGN );return &vqpci->vq; }
@@ -237,7 +239,7 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d,static void qvirtio_pci_virtqueue_kick (QVirtioDevice *d,QVirtQueue *vq) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -qpci_io_writew (dev->pdev, dev->addr +QVIRTIO_PCI_QUEUE_NOTIFY , vq->index); +qpci_io_writew (dev->pdev, dev->addr +VIRTIO_PCI_QUEUE_NOTIFY , vq->index); }const QVirtioBus qvirtio_pci = {
@@ -317,9 +319,9 @@ void qvirtqueue_pci_msix_setup(QVirtioPCIDevice *d, QVirtQueuePCI *vqpci, control & ~PCI_MSIX_ENTRY_CTRL_MASKBIT);qvirtio_pci_queue_select (&d->vdev, vqpci->vq.index); -qpci_io_writew (d->pdev, d->addr +QVIRTIO_PCI_MSIX_QUEUE_VECTOR , entry); - vector =qpci_io_readw (d->pdev, d->addr +QVIRTIO_PCI_MSIX_QUEUE_VECTOR ); - g_assert_cmphex(vector, !=, QVIRTIO_MSI_NO_VECTOR); +qpci_io_writew (d->pdev, d->addr +VIRTIO_MSI_QUEUE_VECTOR , entry); + vector =qpci_io_readw (d->pdev, d->addr +VIRTIO_MSI_QUEUE_VECTOR ); + g_assert_cmphex(vector, !=, VIRTIO_MSI_NO_VECTOR); } void qvirtio_pci_set_msix_configuration_vector(QVirtioPCIDevice *d,
@@ -349,7 +351,7 @@ void qvirtio_pci_set_msix_configuration_vector(QVirtioPCIDevice *d,qpci_io_writel (d->pdev, addr +PCI_MSIX_ENTRY_VECTOR_CTRL , control & ~PCI_MSIX_ENTRY_CTRL_MASKBIT ); -qpci_io_writew (d->pdev, d->addr +QVIRTIO_PCI_MSIX_CONF_VECTOR , entry); - vector =qpci_io_readw (d->pdev, d->addr +QVIRTIO_PCI_MSIX_CONF_VECTOR ); - g_assert_cmphex(vector, !=, QVIRTIO_MSI_NO_VECTOR); +qpci_io_writew (d->pdev, d->addr +VIRTIO_MSI_CONFIG_VECTOR , entry); + vector =qpci_io_readw (d->pdev, d->addr +VIRTIO_MSI_CONFIG_VECTOR ); + g_assert_cmphex(vector, !=, VIRTIO_MSI_NO_VECTOR); }
tests/libqos/virtio-pci.h +0 -17
@@ -13,23 +13,6 @@#include "libqos/virtio.h" #include "libqos/pci.h" -#define QVIRTIO_PCI_DEVICE_FEATURES 0x00 -#define QVIRTIO_PCI_GUEST_FEATURES 0x04 -#define QVIRTIO_PCI_QUEUE_ADDRESS 0x08 -#define QVIRTIO_PCI_QUEUE_SIZE 0x0C -#define QVIRTIO_PCI_QUEUE_SELECT 0x0E -#define QVIRTIO_PCI_QUEUE_NOTIFY 0x10 -#define QVIRTIO_PCI_DEVICE_STATUS 0x12 -#define QVIRTIO_PCI_ISR_STATUS 0x13 -#define QVIRTIO_PCI_MSIX_CONF_VECTOR 0x14 -#define QVIRTIO_PCI_MSIX_QUEUE_VECTOR 0x16 -#define QVIRTIO_PCI_DEVICE_SPECIFIC_MSIX 0x18 -#define QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX 0x14 - -#define QVIRTIO_PCI_ALIGN 4096 - -#define QVIRTIO_MSI_NO_VECTOR 0xFFFF - typedef struct QVirtioPCIDevice { QVirtioDevice vdev; QPCIDevice *pdev;
tests/virtio-blk-test.c +6 -5
@@ -23,6 +23,7 @@#include "standard-headers/linux/virtio_config.h" #include "standard-headers/linux/virtio_ring.h" #include "standard-headers/linux/virtio_blk.h" +#include "standard-headers/linux/virtio_pci.h" #define TEST_IMAGE_SIZE (64 * 1024 * 1024)#define QVIRTIO_BLK_TIMEOUT_US (30 * 1000 * 1000)
@@ -292,7 +293,7 @@ static void pci_basic(void) alloc, 0);/* MSI-X is not enabled */ - addr = dev->addr +QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX ; + addr = dev->addr +VIRTIO_PCI_CONFIG_OFF (false);test_basic (&qvirtio_pci, &dev->vdev, alloc, &vqpci->vq, (uint64_t )(uintptr_t )addr);
@@ -327,7 +328,7 @@ static void pci_indirect(void) dev =virtio_blk_pci_init (bus,PCI_SLOT );/* MSI-X is not enabled */ - addr = dev->addr +QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX ; + addr = dev->addr +VIRTIO_PCI_CONFIG_OFF (false); capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, (uint64_t )(uintptr_t )addr);
@@ -422,7 +423,7 @@ static void pci_config(void) dev =virtio_blk_pci_init (bus,PCI_SLOT );/* MSI-X is not enabled */ - addr = dev->addr +QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX ; + addr = dev->addr +VIRTIO_PCI_CONFIG_OFF (false); capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, (uint64_t )(uintptr_t )addr);
@@ -469,7 +470,7 @@ static void pci_msix(void)qvirtio_pci_set_msix_configuration_vector (dev, alloc,0 );/* MSI-X is enabled */ - addr = dev->addr +QVIRTIO_PCI_DEVICE_SPECIFIC_MSIX ; + addr = dev->addr +VIRTIO_PCI_CONFIG_OFF (true); capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, (uint64_t )(uintptr_t )addr);
@@ -585,7 +586,7 @@ static void pci_idx(void)qvirtio_pci_set_msix_configuration_vector (dev, alloc,0 );/* MSI-X is enabled */ - addr = dev->addr +QVIRTIO_PCI_DEVICE_SPECIFIC_MSIX ; + addr = dev->addr +VIRTIO_PCI_CONFIG_OFF (true); capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, (uint64_t )(uintptr_t )addr);
tests/virtio-scsi-test.c +2 -1
@@ -19,6 +19,7 @@#include "libqos/malloc-pc.h" #include "libqos/malloc-generic.h" #include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/virtio_pci.h" #include "standard-headers/linux/virtio_scsi.h" #define PCI_SLOT 0x02
@@ -158,7 +159,7 @@ static QVirtIOSCSI *qvirtio_scsi_pci_init(int slot)qvirtio_set_acknowledge (&qvirtio_pci, vs->dev);qvirtio_set_driver (&qvirtio_pci, vs->dev); - addr = dev->addr +QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX ; + addr = dev->addr +VIRTIO_PCI_CONFIG_OFF (false); vs->num_queues =qvirtio_config_readl (&qvirtio_pci, vs->dev, (uint64_t )(uintptr_t )addr);
Signature · 1 line
2.5.5