Re: [Qemu-block] [Qemu-devel] [PATCH v6 12/29] libqos: Track QTestState with QPCIBus
On 09/07/2017 12:35 AM, Thomas Huth wrote: > On 06.09.2017 23:00, Eric Blake wrote: >> On 09/05/2017 04:36 AM, Thomas Huth wrote: >>> On 01.09.2017 20:03, Eric Blake wrote: When initializing a QPCIBus, track which QTestState the bus is associated with (so that a later patch can then explicitly use that test state for all communication on the bus, rather than blindly relying on global_qtest). Update the initialization functions to take another parameter, and update all callers to pass in state (for now, most callers get away with passing the current global_qtest as the current state, although this required fixing the order of initialization to ensure qtest_start() is called before qpci_init*() in rtl8139-test, and provided an opportunity to pass in the allocator in e1000e-test). >>> >>> Why did you remove the check for qs->alloc? >>> +qs->pcibus = ops->qpci_init(qs->qts, qs->alloc); >> >> Because we want to ensure qpci_init() is called to set qs->qts >> (presumably, whether or not qs->alloc is set). Furthermore, only two >> files declare a 'static QOSOps' structure in the first place >> (libqos-pc.c and libqos-spapr.c); where both files set both the >> .init_allocator and .qpci_init callbacks; a little bit of auditing shows >> that the .init_allocator() never returns NULL (although that requires >> browsing yet more files for malloc-{pc,spapr}.c). > > OK, thanks for the explanation! ... but maybe we should > g_assert(gs->alloc) somewhere instead? ... just an idea, I'm also fine > if you leave it away. Users of QOSOps always supply qs->alloc, but there are tests that successfully use NULL for qs->alloc (because they did not go through QOSOps). At any rate, I can certainly update the commit message. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org signature.asc Description: OpenPGP digital signature
Re: [Qemu-block] [Qemu-devel] [PATCH v6 12/29] libqos: Track QTestState with QPCIBus
On 06.09.2017 23:00, Eric Blake wrote: > On 09/05/2017 04:36 AM, Thomas Huth wrote: >> On 01.09.2017 20:03, Eric Blake wrote: >>> When initializing a QPCIBus, track which QTestState the bus is >>> associated with (so that a later patch can then explicitly use >>> that test state for all communication on the bus, rather than >>> blindly relying on global_qtest). Update the initialization >>> functions to take another parameter, and update all callers to >>> pass in state (for now, most callers get away with passing the >>> current global_qtest as the current state, although this required >>> fixing the order of initialization to ensure qtest_start() is >>> called before qpci_init*() in rtl8139-test, and provided an >>> opportunity to pass in the allocator in e1000e-test). >>> >>> Signed-off-by: Eric Blake>>> --- >> [...] >>> diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c >>> index 6226546c28..c95428e1cb 100644 >>> --- a/tests/libqos/libqos.c >>> +++ b/tests/libqos/libqos.c >>> @@ -26,8 +26,8 @@ QOSState *qtest_vboot(QOSOps *ops, const char >>> *cmdline_fmt, va_list ap) >>> if (ops->init_allocator) { >>> qs->alloc = ops->init_allocator(ALLOC_NO_FLAGS); >>> } >>> -if (ops->qpci_init && qs->alloc) { >>> -qs->pcibus = ops->qpci_init(qs->alloc); >>> +if (ops->qpci_init) { >> >> Why did you remove the check for qs->alloc? >> >>> +qs->pcibus = ops->qpci_init(qs->qts, qs->alloc); > > Because we want to ensure qpci_init() is called to set qs->qts > (presumably, whether or not qs->alloc is set). Furthermore, only two > files declare a 'static QOSOps' structure in the first place > (libqos-pc.c and libqos-spapr.c); where both files set both the > .init_allocator and .qpci_init callbacks; a little bit of auditing shows > that the .init_allocator() never returns NULL (although that requires > browsing yet more files for malloc-{pc,spapr}.c). OK, thanks for the explanation! ... but maybe we should g_assert(gs->alloc) somewhere instead? ... just an idea, I'm also fine if you leave it away. Thomas signature.asc Description: OpenPGP digital signature
Re: [Qemu-block] [Qemu-devel] [PATCH v6 12/29] libqos: Track QTestState with QPCIBus
On 09/05/2017 04:36 AM, Thomas Huth wrote: > On 01.09.2017 20:03, Eric Blake wrote: >> When initializing a QPCIBus, track which QTestState the bus is >> associated with (so that a later patch can then explicitly use >> that test state for all communication on the bus, rather than >> blindly relying on global_qtest). Update the initialization >> functions to take another parameter, and update all callers to >> pass in state (for now, most callers get away with passing the >> current global_qtest as the current state, although this required >> fixing the order of initialization to ensure qtest_start() is >> called before qpci_init*() in rtl8139-test, and provided an >> opportunity to pass in the allocator in e1000e-test). >> >> Signed-off-by: Eric Blake>> --- > [...] >> diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c >> index 6226546c28..c95428e1cb 100644 >> --- a/tests/libqos/libqos.c >> +++ b/tests/libqos/libqos.c >> @@ -26,8 +26,8 @@ QOSState *qtest_vboot(QOSOps *ops, const char >> *cmdline_fmt, va_list ap) >> if (ops->init_allocator) { >> qs->alloc = ops->init_allocator(ALLOC_NO_FLAGS); >> } >> -if (ops->qpci_init && qs->alloc) { >> -qs->pcibus = ops->qpci_init(qs->alloc); >> +if (ops->qpci_init) { > > Why did you remove the check for qs->alloc? > >> +qs->pcibus = ops->qpci_init(qs->qts, qs->alloc); Because we want to ensure qpci_init() is called to set qs->qts (presumably, whether or not qs->alloc is set). Furthermore, only two files declare a 'static QOSOps' structure in the first place (libqos-pc.c and libqos-spapr.c); where both files set both the .init_allocator and .qpci_init callbacks; a little bit of auditing shows that the .init_allocator() never returns NULL (although that requires browsing yet more files for malloc-{pc,spapr}.c). -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org signature.asc Description: OpenPGP digital signature
Re: [Qemu-block] [Qemu-devel] [PATCH v6 12/29] libqos: Track QTestState with QPCIBus
On 09/01/2017 02:20 PM, Philippe Mathieu-Daudé wrote: > Hi Eric, > > On 09/01/2017 03:03 PM, Eric Blake wrote: >> When initializing a QPCIBus, track which QTestState the bus is >> associated with (so that a later patch can then explicitly use >> that test state for all communication on the bus, rather than >> blindly relying on global_qtest). Update the initialization >> functions to take another parameter, and update all callers to >> pass in state (for now, most callers get away with passing the >> current global_qtest as the current state, although this required >> fixing the order of initialization to ensure qtest_start() is >> called before qpci_init*() in rtl8139-test, and provided an >> opportunity to pass in the allocator in e1000e-test). >> >> +++ b/tests/libqos/pci-pc.c >> @@ -115,11 +115,14 @@ static void qpci_pc_config_writel(QPCIBus *bus, >> int devfn, uint8_t offset, uint3 >> outl(0xcfc, value); >> } >> >> -QPCIBus *qpci_init_pc(QGuestAllocator *alloc) >> +QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc) >> { >> QPCIBusPC *ret; >> >> + assert(qts); >> + >> ret = g_malloc(sizeof(*ret)); > > I'd rather use g_malloc0() here (safer!) Pre-existing, but yes, I can touch it while in the area. > >> + ret->bus.qts = qts; >> >> ret->bus.pio_readb = qpci_pc_pio_readb; >> ret->bus.pio_readw = qpci_pc_pio_readw; > > or init qts field in same order than struct: Okay. > > Either ways: > Reviewed-by: Philippe Mathieu-Daudé> -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org signature.asc Description: OpenPGP digital signature
Re: [Qemu-block] [Qemu-devel] [PATCH v6 12/29] libqos: Track QTestState with QPCIBus
On 01.09.2017 20:03, Eric Blake wrote: > When initializing a QPCIBus, track which QTestState the bus is > associated with (so that a later patch can then explicitly use > that test state for all communication on the bus, rather than > blindly relying on global_qtest). Update the initialization > functions to take another parameter, and update all callers to > pass in state (for now, most callers get away with passing the > current global_qtest as the current state, although this required > fixing the order of initialization to ensure qtest_start() is > called before qpci_init*() in rtl8139-test, and provided an > opportunity to pass in the allocator in e1000e-test). > > Signed-off-by: Eric Blake> --- [...] > diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c > index 6226546c28..c95428e1cb 100644 > --- a/tests/libqos/libqos.c > +++ b/tests/libqos/libqos.c > @@ -26,8 +26,8 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, > va_list ap) > if (ops->init_allocator) { > qs->alloc = ops->init_allocator(ALLOC_NO_FLAGS); > } > -if (ops->qpci_init && qs->alloc) { > -qs->pcibus = ops->qpci_init(qs->alloc); > +if (ops->qpci_init) { Why did you remove the check for qs->alloc? > +qs->pcibus = ops->qpci_init(qs->qts, qs->alloc); > } > } > > diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c > index 02ce49927a..85b34c6d13 100644 > --- a/tests/libqos/pci-pc.c > +++ b/tests/libqos/pci-pc.c > @@ -115,11 +115,14 @@ static void qpci_pc_config_writel(QPCIBus *bus, int > devfn, uint8_t offset, uint3 > outl(0xcfc, value); > } > > -QPCIBus *qpci_init_pc(QGuestAllocator *alloc) > +QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc) > { > QPCIBusPC *ret; > > +assert(qts); > + > ret = g_malloc(sizeof(*ret)); > +ret->bus.qts = qts; > > ret->bus.pio_readb = qpci_pc_pio_readb; > ret->bus.pio_readw = qpci_pc_pio_readw; > diff --git a/tests/libqos/pci-spapr.c b/tests/libqos/pci-spapr.c > index 2043f1e123..cd9b8f52d2 100644 > --- a/tests/libqos/pci-spapr.c > +++ b/tests/libqos/pci-spapr.c > @@ -154,11 +154,14 @@ static void qpci_spapr_config_writel(QPCIBus *bus, int > devfn, uint8_t offset, > #define SPAPR_PCI_MMIO32_WIN_SIZE0x8000 /* 2 GiB */ > #define SPAPR_PCI_IO_WIN_SIZE0x1 > > -QPCIBus *qpci_init_spapr(QGuestAllocator *alloc) > +QPCIBus *qpci_init_spapr(QTestState *qts, QGuestAllocator *alloc) > { > QPCIBusSPAPR *ret; > > +assert(qts); > + > ret = g_malloc(sizeof(*ret)); +1 for using g_malloc0 here instead. > +ret->bus.qts = qts; > > ret->alloc = alloc; > > @@ -201,6 +204,7 @@ QPCIBus *qpci_init_spapr(QGuestAllocator *alloc) > ret->bus.mmio_alloc_ptr = ret->mmio32.pci_base; > ret->bus.mmio_limit = ret->mmio32.pci_base + ret->mmio32.size; > > + Superfluous white space change. > return >bus; > } Thomas
Re: [Qemu-block] [Qemu-devel] [PATCH v6 12/29] libqos: Track QTestState with QPCIBus
On 09/01/2017 02:03 PM, Eric Blake wrote: > When initializing a QPCIBus, track which QTestState the bus is > associated with (so that a later patch can then explicitly use > that test state for all communication on the bus, rather than > blindly relying on global_qtest). Update the initialization > functions to take another parameter, and update all callers to > pass in state (for now, most callers get away with passing the > current global_qtest as the current state, although this required > fixing the order of initialization to ensure qtest_start() is > called before qpci_init*() in rtl8139-test, and provided an > opportunity to pass in the allocator in e1000e-test). > > Signed-off-by: Eric BlakeReviewed-by: John Snow
Re: [Qemu-block] [Qemu-devel] [PATCH v6 12/29] libqos: Track QTestState with QPCIBus
Hi Eric, On 09/01/2017 03:03 PM, Eric Blake wrote: When initializing a QPCIBus, track which QTestState the bus is associated with (so that a later patch can then explicitly use that test state for all communication on the bus, rather than blindly relying on global_qtest). Update the initialization functions to take another parameter, and update all callers to pass in state (for now, most callers get away with passing the current global_qtest as the current state, although this required fixing the order of initialization to ensure qtest_start() is called before qpci_init*() in rtl8139-test, and provided an opportunity to pass in the allocator in e1000e-test). Signed-off-by: Eric Blake--- tests/libqos/ahci.h | 2 +- tests/libqos/libqos.h | 2 +- tests/libqos/pci-pc.h | 2 +- tests/libqos/pci-spapr.h | 2 +- tests/libqos/pci.h| 1 + tests/ahci-test.c | 2 +- tests/e1000e-test.c | 6 +++--- tests/i440fx-test.c | 2 +- tests/ide-test.c | 2 +- tests/libqos/ahci.c | 4 ++-- tests/libqos/libqos.c | 4 ++-- tests/libqos/pci-pc.c | 5 - tests/libqos/pci-spapr.c | 6 +- tests/q35-test.c | 4 ++-- tests/rtl8139-test.c | 5 +++-- tests/tco-test.c | 2 +- tests/usb-hcd-ehci-test.c | 2 +- tests/vhost-user-test.c | 4 ++-- 18 files changed, 33 insertions(+), 24 deletions(-) diff --git a/tests/libqos/ahci.h b/tests/libqos/ahci.h index 5f9627bb0f..715ca1e226 100644 --- a/tests/libqos/ahci.h +++ b/tests/libqos/ahci.h @@ -571,7 +571,7 @@ void ahci_free(AHCIQState *ahci, uint64_t addr); void ahci_clean_mem(AHCIQState *ahci); /* Device management */ -QPCIDevice *get_ahci_device(uint32_t *fingerprint); +QPCIDevice *get_ahci_device(QTestState *qts, uint32_t *fingerprint); void free_ahci_device(QPCIDevice *dev); void ahci_pci_enable(AHCIQState *ahci); void start_ahci_device(AHCIQState *ahci); diff --git a/tests/libqos/libqos.h b/tests/libqos/libqos.h index 231969766f..78e5c044a0 100644 --- a/tests/libqos/libqos.h +++ b/tests/libqos/libqos.h @@ -10,7 +10,7 @@ typedef struct QOSState QOSState; typedef struct QOSOps { QGuestAllocator *(*init_allocator)(QAllocOpts); void (*uninit_allocator)(QGuestAllocator *); -QPCIBus *(*qpci_init)(QGuestAllocator *alloc); +QPCIBus *(*qpci_init)(QTestState *qts, QGuestAllocator *alloc); void (*qpci_free)(QPCIBus *bus); void (*shutdown)(QOSState *); } QOSOps; diff --git a/tests/libqos/pci-pc.h b/tests/libqos/pci-pc.h index 9479b51642..491eeac756 100644 --- a/tests/libqos/pci-pc.h +++ b/tests/libqos/pci-pc.h @@ -16,7 +16,7 @@ #include "libqos/pci.h" #include "libqos/malloc.h" -QPCIBus *qpci_init_pc(QGuestAllocator *alloc); +QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc); void qpci_free_pc(QPCIBus *bus); #endif diff --git a/tests/libqos/pci-spapr.h b/tests/libqos/pci-spapr.h index 4192126d86..387686dfc8 100644 --- a/tests/libqos/pci-spapr.h +++ b/tests/libqos/pci-spapr.h @@ -11,7 +11,7 @@ #include "libqos/malloc.h" #include "libqos/pci.h" -QPCIBus *qpci_init_spapr(QGuestAllocator *alloc); +QPCIBus *qpci_init_spapr(QTestState *qts, QGuestAllocator *alloc); void qpci_free_spapr(QPCIBus *bus); #endif diff --git a/tests/libqos/pci.h b/tests/libqos/pci.h index ed480614ff..429c382282 100644 --- a/tests/libqos/pci.h +++ b/tests/libqos/pci.h @@ -48,6 +48,7 @@ struct QPCIBus { void (*config_writel)(QPCIBus *bus, int devfn, uint8_t offset, uint32_t value); +QTestState *qts; uint16_t pio_alloc_ptr; uint64_t mmio_alloc_ptr, mmio_limit; }; diff --git a/tests/ahci-test.c b/tests/ahci-test.c index 999121bb7c..c94d1bd712 100644 --- a/tests/ahci-test.c +++ b/tests/ahci-test.c @@ -160,7 +160,7 @@ static AHCIQState *ahci_vboot(const char *cli, va_list ap) alloc_set_flags(s->parent->alloc, ALLOC_LEAK_ASSERT); /* Verify that we have an AHCI device present. */ -s->dev = get_ahci_device(>fingerprint); +s->dev = get_ahci_device(s->parent->qts, >fingerprint); return s; } diff --git a/tests/e1000e-test.c b/tests/e1000e-test.c index c612dc64ec..d8085d944e 100644 --- a/tests/e1000e-test.c +++ b/tests/e1000e-test.c @@ -392,12 +392,12 @@ static void data_test_init(e1000e_device *d) qtest_start(cmdline); g_free(cmdline); -test_bus = qpci_init_pc(NULL); -g_assert_nonnull(test_bus); - test_alloc = pc_alloc_init(); g_assert_nonnull(test_alloc); +test_bus = qpci_init_pc(global_qtest, test_alloc); +g_assert_nonnull(test_bus); + e1000e_device_init(test_bus, d); } diff --git a/tests/i440fx-test.c b/tests/i440fx-test.c index e9d05c87d1..4390e5591e 100644 --- a/tests/i440fx-test.c +++ b/tests/i440fx-test.c @@ -38,7 +38,7 @@ static QPCIBus *test_start_get_bus(const TestData *s) cmdline = g_strdup_printf("-smp %d", s->num_cpus); qtest_start(cmdline);