* [Qemu-devel] [PATCH qemu] pci: Only unmap bus_master_enabled_region if was added previously
@ 2017-03-31 4:47 Alexey Kardashevskiy
2017-03-31 10:33 ` Max Reitz
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Alexey Kardashevskiy @ 2017-03-31 4:47 UTC (permalink / raw)
To: qemu-devel
Cc: Alexey Kardashevskiy, Michael S. Tsirkin, Marcel Apfelbaum,
John Snow, Max Reitz, Paolo Bonzini
Normally pci_init_bus_master() would be called either via
bus->machine_done.notify or directly from do_pci_register_device().
However if a device's realize() failed, pci_init_bus_master() is not
called, and do_pci_unregister_device() fails on
memory_region_del_subregion() as it was not mapped.
This adds a check that subregion was mapped before unmapping it.
Fixes: c53598ed18e4 ("pci: Add missing drop of bus master AS reference")
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
This is to pass iotest 051 which does run QEMU like this:
ppc64-softmmu/qemu-system-ppc64 -nodefaults -machine accel=qtest -nographic -monitor stdio -serial none -drive if=virtio
which normally fails with:
qemu-system-ppc64: -drive if=virtio: Device needs media, but drive is empty
or asserts (without this patch):
qemu-system-ppc64: /home/aik/p/qemu-kvm/memory.c:2118: memory_region_del_subregion: Assertion `subregion->container == mr' failed.
---
hw/pci/pci.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index bd8043c460..259483b1c0 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -869,8 +869,10 @@ static void do_pci_unregister_device(PCIDevice *pci_dev)
pci_dev->bus->devices[pci_dev->devfn] = NULL;
pci_config_free(pci_dev);
- memory_region_del_subregion(&pci_dev->bus_master_container_region,
- &pci_dev->bus_master_enable_region);
+ if (memory_region_is_mapped(&pci_dev->bus_master_enable_region)) {
+ memory_region_del_subregion(&pci_dev->bus_master_container_region,
+ &pci_dev->bus_master_enable_region);
+ }
address_space_destroy(&pci_dev->bus_master_as);
}
--
2.11.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH qemu] pci: Only unmap bus_master_enabled_region if was added previously
2017-03-31 4:47 [Qemu-devel] [PATCH qemu] pci: Only unmap bus_master_enabled_region if was added previously Alexey Kardashevskiy
@ 2017-03-31 10:33 ` Max Reitz
2017-03-31 11:56 ` Alexey Kardashevskiy
2017-03-31 12:08 ` Marcel Apfelbaum
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Max Reitz @ 2017-03-31 10:33 UTC (permalink / raw)
To: Alexey Kardashevskiy, qemu-devel
Cc: Michael S. Tsirkin, Marcel Apfelbaum, John Snow, Paolo Bonzini
[-- Attachment #1: Type: text/plain, Size: 2241 bytes --]
On 31.03.2017 06:47, Alexey Kardashevskiy wrote:
> Normally pci_init_bus_master() would be called either via
> bus->machine_done.notify or directly from do_pci_register_device().
>
> However if a device's realize() failed, pci_init_bus_master() is not
> called, and do_pci_unregister_device() fails on
> memory_region_del_subregion() as it was not mapped.
>
> This adds a check that subregion was mapped before unmapping it.
>
> Fixes: c53598ed18e4 ("pci: Add missing drop of bus master AS reference")
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> ---
> This is to pass iotest 051 which does run QEMU like this:
>
> ppc64-softmmu/qemu-system-ppc64 -nodefaults -machine accel=qtest -nographic -monitor stdio -serial none -drive if=virtio
>
> which normally fails with:
>
> qemu-system-ppc64: -drive if=virtio: Device needs media, but drive is empty
>
> or asserts (without this patch):
>
> qemu-system-ppc64: /home/aik/p/qemu-kvm/memory.c:2118: memory_region_del_subregion: Assertion `subregion->container == mr' failed.
> ---
> hw/pci/pci.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index bd8043c460..259483b1c0 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -869,8 +869,10 @@ static void do_pci_unregister_device(PCIDevice *pci_dev)
> pci_dev->bus->devices[pci_dev->devfn] = NULL;
> pci_config_free(pci_dev);
>
> - memory_region_del_subregion(&pci_dev->bus_master_container_region,
> - &pci_dev->bus_master_enable_region);
> + if (memory_region_is_mapped(&pci_dev->bus_master_enable_region)) {
> + memory_region_del_subregion(&pci_dev->bus_master_container_region,
> + &pci_dev->bus_master_enable_region);
> + }
> address_space_destroy(&pci_dev->bus_master_as);
> }
I'm not sure whether it's generally assumed to be safe to call
memory_region_is_mapped() on "uninitialized" memory regions
(bus_master_enable_region is just completely zeroed out before
pci_init_bus_master(), as far as I can see and guess), but it certainly
works in practice, so:
Reviewed-by: Max Reitz <mreitz@redhat.com>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 512 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH qemu] pci: Only unmap bus_master_enabled_region if was added previously
2017-03-31 10:33 ` Max Reitz
@ 2017-03-31 11:56 ` Alexey Kardashevskiy
0 siblings, 0 replies; 7+ messages in thread
From: Alexey Kardashevskiy @ 2017-03-31 11:56 UTC (permalink / raw)
To: Max Reitz, qemu-devel
Cc: Michael S. Tsirkin, Marcel Apfelbaum, John Snow, Paolo Bonzini
[-- Attachment #1: Type: text/plain, Size: 2459 bytes --]
On 31/03/17 21:33, Max Reitz wrote:
> On 31.03.2017 06:47, Alexey Kardashevskiy wrote:
>> Normally pci_init_bus_master() would be called either via
>> bus->machine_done.notify or directly from do_pci_register_device().
>>
>> However if a device's realize() failed, pci_init_bus_master() is not
>> called, and do_pci_unregister_device() fails on
>> memory_region_del_subregion() as it was not mapped.
>>
>> This adds a check that subregion was mapped before unmapping it.
>>
>> Fixes: c53598ed18e4 ("pci: Add missing drop of bus master AS reference")
>> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
>> ---
>> This is to pass iotest 051 which does run QEMU like this:
>>
>> ppc64-softmmu/qemu-system-ppc64 -nodefaults -machine accel=qtest -nographic -monitor stdio -serial none -drive if=virtio
>>
>> which normally fails with:
>>
>> qemu-system-ppc64: -drive if=virtio: Device needs media, but drive is empty
>>
>> or asserts (without this patch):
>>
>> qemu-system-ppc64: /home/aik/p/qemu-kvm/memory.c:2118: memory_region_del_subregion: Assertion `subregion->container == mr' failed.
>> ---
>> hw/pci/pci.c | 6 ++++--
>> 1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
>> index bd8043c460..259483b1c0 100644
>> --- a/hw/pci/pci.c
>> +++ b/hw/pci/pci.c
>> @@ -869,8 +869,10 @@ static void do_pci_unregister_device(PCIDevice *pci_dev)
>> pci_dev->bus->devices[pci_dev->devfn] = NULL;
>> pci_config_free(pci_dev);
>>
>> - memory_region_del_subregion(&pci_dev->bus_master_container_region,
>> - &pci_dev->bus_master_enable_region);
>> + if (memory_region_is_mapped(&pci_dev->bus_master_enable_region)) {
>> + memory_region_del_subregion(&pci_dev->bus_master_container_region,
>> + &pci_dev->bus_master_enable_region);
>> + }
>> address_space_destroy(&pci_dev->bus_master_as);
>> }
>
> I'm not sure whether it's generally assumed to be safe to call
> memory_region_is_mapped() on "uninitialized" memory regions
> (bus_master_enable_region is just completely zeroed out before
> pci_init_bus_master(), as far as I can see and guess), but it certainly
> works in practice, so:
>
> Reviewed-by: Max Reitz <mreitz@redhat.com>
PCI device is also initialized via object_initialize() which does memset(0)
so I assume it is quite safe.
--
Alexey
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 839 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH qemu] pci: Only unmap bus_master_enabled_region if was added previously
2017-03-31 4:47 [Qemu-devel] [PATCH qemu] pci: Only unmap bus_master_enabled_region if was added previously Alexey Kardashevskiy
2017-03-31 10:33 ` Max Reitz
@ 2017-03-31 12:08 ` Marcel Apfelbaum
2017-03-31 17:44 ` John Snow
2017-03-31 21:40 ` Michael S. Tsirkin
3 siblings, 0 replies; 7+ messages in thread
From: Marcel Apfelbaum @ 2017-03-31 12:08 UTC (permalink / raw)
To: Alexey Kardashevskiy, qemu-devel
Cc: Michael S. Tsirkin, John Snow, Max Reitz, Paolo Bonzini
On 03/31/2017 07:47 AM, Alexey Kardashevskiy wrote:
> Normally pci_init_bus_master() would be called either via
> bus->machine_done.notify or directly from do_pci_register_device().
>
> However if a device's realize() failed, pci_init_bus_master() is not
> called, and do_pci_unregister_device() fails on
> memory_region_del_subregion() as it was not mapped.
>
> This adds a check that subregion was mapped before unmapping it.
>
> Fixes: c53598ed18e4 ("pci: Add missing drop of bus master AS reference")
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> ---
> This is to pass iotest 051 which does run QEMU like this:
>
> ppc64-softmmu/qemu-system-ppc64 -nodefaults -machine accel=qtest -nographic -monitor stdio -serial none -drive if=virtio
>
> which normally fails with:
>
> qemu-system-ppc64: -drive if=virtio: Device needs media, but drive is empty
>
> or asserts (without this patch):
>
> qemu-system-ppc64: /home/aik/p/qemu-kvm/memory.c:2118: memory_region_del_subregion: Assertion `subregion->container == mr' failed.
> ---
> hw/pci/pci.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index bd8043c460..259483b1c0 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -869,8 +869,10 @@ static void do_pci_unregister_device(PCIDevice *pci_dev)
> pci_dev->bus->devices[pci_dev->devfn] = NULL;
> pci_config_free(pci_dev);
>
> - memory_region_del_subregion(&pci_dev->bus_master_container_region,
> - &pci_dev->bus_master_enable_region);
> + if (memory_region_is_mapped(&pci_dev->bus_master_enable_region)) {
> + memory_region_del_subregion(&pci_dev->bus_master_container_region,
> + &pci_dev->bus_master_enable_region);
> + }
> address_space_destroy(&pci_dev->bus_master_as);
> }
>
>
Hi,
Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
Thanks,
Marcel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH qemu] pci: Only unmap bus_master_enabled_region if was added previously
2017-03-31 4:47 [Qemu-devel] [PATCH qemu] pci: Only unmap bus_master_enabled_region if was added previously Alexey Kardashevskiy
2017-03-31 10:33 ` Max Reitz
2017-03-31 12:08 ` Marcel Apfelbaum
@ 2017-03-31 17:44 ` John Snow
2017-03-31 19:49 ` Paolo Bonzini
2017-03-31 21:40 ` Michael S. Tsirkin
3 siblings, 1 reply; 7+ messages in thread
From: John Snow @ 2017-03-31 17:44 UTC (permalink / raw)
To: Alexey Kardashevskiy, qemu-devel
Cc: Michael S. Tsirkin, Marcel Apfelbaum, Max Reitz, Paolo Bonzini
On 03/31/2017 12:47 AM, Alexey Kardashevskiy wrote:
> Normally pci_init_bus_master() would be called either via
> bus->machine_done.notify or directly from do_pci_register_device().
>
> However if a device's realize() failed, pci_init_bus_master() is not
> called, and do_pci_unregister_device() fails on
> memory_region_del_subregion() as it was not mapped.
>
> This adds a check that subregion was mapped before unmapping it.
>
> Fixes: c53598ed18e4 ("pci: Add missing drop of bus master AS reference")
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> ---
> This is to pass iotest 051 which does run QEMU like this:
>
> ppc64-softmmu/qemu-system-ppc64 -nodefaults -machine accel=qtest -nographic -monitor stdio -serial none -drive if=virtio
>
> which normally fails with:
>
> qemu-system-ppc64: -drive if=virtio: Device needs media, but drive is empty
>
> or asserts (without this patch):
>
> qemu-system-ppc64: /home/aik/p/qemu-kvm/memory.c:2118: memory_region_del_subregion: Assertion `subregion->container == mr' failed.
> ---
> hw/pci/pci.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index bd8043c460..259483b1c0 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -869,8 +869,10 @@ static void do_pci_unregister_device(PCIDevice *pci_dev)
> pci_dev->bus->devices[pci_dev->devfn] = NULL;
> pci_config_free(pci_dev);
>
> - memory_region_del_subregion(&pci_dev->bus_master_container_region,
> - &pci_dev->bus_master_enable_region);
> + if (memory_region_is_mapped(&pci_dev->bus_master_enable_region)) {
> + memory_region_del_subregion(&pci_dev->bus_master_container_region,
> + &pci_dev->bus_master_enable_region);
> + }
> address_space_destroy(&pci_dev->bus_master_as);
> }
>
>
Thanks for the quick turnaround!
Tested-by: John Snow <jsnow@redhat.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH qemu] pci: Only unmap bus_master_enabled_region if was added previously
2017-03-31 17:44 ` John Snow
@ 2017-03-31 19:49 ` Paolo Bonzini
0 siblings, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2017-03-31 19:49 UTC (permalink / raw)
To: John Snow
Cc: Alexey Kardashevskiy, qemu-devel, Marcel Apfelbaum, Max Reitz,
Michael S. Tsirkin
> On 03/31/2017 12:47 AM, Alexey Kardashevskiy wrote:
> > Normally pci_init_bus_master() would be called either via
> > bus->machine_done.notify or directly from do_pci_register_device().
> >
> > However if a device's realize() failed, pci_init_bus_master() is not
> > called, and do_pci_unregister_device() fails on
> > memory_region_del_subregion() as it was not mapped.
> >
> > This adds a check that subregion was mapped before unmapping it.
> >
> > Fixes: c53598ed18e4 ("pci: Add missing drop of bus master AS reference")
> > Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> > ---
> > This is to pass iotest 051 which does run QEMU like this:
> >
> > ppc64-softmmu/qemu-system-ppc64 -nodefaults -machine accel=qtest -nographic
> > -monitor stdio -serial none -drive if=virtio
> >
> > which normally fails with:
> >
> > qemu-system-ppc64: -drive if=virtio: Device needs media, but drive is empty
> >
> > or asserts (without this patch):
> >
> > qemu-system-ppc64: /home/aik/p/qemu-kvm/memory.c:2118:
> > memory_region_del_subregion: Assertion `subregion->container == mr'
> > failed.
> > ---
> > hw/pci/pci.c | 6 ++++--
> > 1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> > index bd8043c460..259483b1c0 100644
> > --- a/hw/pci/pci.c
> > +++ b/hw/pci/pci.c
> > @@ -869,8 +869,10 @@ static void do_pci_unregister_device(PCIDevice
> > *pci_dev)
> > pci_dev->bus->devices[pci_dev->devfn] = NULL;
> > pci_config_free(pci_dev);
> >
> > - memory_region_del_subregion(&pci_dev->bus_master_container_region,
> > - &pci_dev->bus_master_enable_region);
> > + if (memory_region_is_mapped(&pci_dev->bus_master_enable_region)) {
> > + memory_region_del_subregion(&pci_dev->bus_master_container_region,
> > + &pci_dev->bus_master_enable_region);
> > + }
> > address_space_destroy(&pci_dev->bus_master_as);
> > }
> >
> >
>
> Thanks for the quick turnaround!
>
> Tested-by: John Snow <jsnow@redhat.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH qemu] pci: Only unmap bus_master_enabled_region if was added previously
2017-03-31 4:47 [Qemu-devel] [PATCH qemu] pci: Only unmap bus_master_enabled_region if was added previously Alexey Kardashevskiy
` (2 preceding siblings ...)
2017-03-31 17:44 ` John Snow
@ 2017-03-31 21:40 ` Michael S. Tsirkin
3 siblings, 0 replies; 7+ messages in thread
From: Michael S. Tsirkin @ 2017-03-31 21:40 UTC (permalink / raw)
To: Alexey Kardashevskiy
Cc: qemu-devel, Marcel Apfelbaum, John Snow, Max Reitz, Paolo Bonzini
On Fri, Mar 31, 2017 at 03:47:11PM +1100, Alexey Kardashevskiy wrote:
> Normally pci_init_bus_master() would be called either via
> bus->machine_done.notify or directly from do_pci_register_device().
>
> However if a device's realize() failed, pci_init_bus_master() is not
> called, and do_pci_unregister_device() fails on
> memory_region_del_subregion() as it was not mapped.
>
> This adds a check that subregion was mapped before unmapping it.
>
> Fixes: c53598ed18e4 ("pci: Add missing drop of bus master AS reference")
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Applied, thanks everyone.
> ---
> This is to pass iotest 051 which does run QEMU like this:
>
> ppc64-softmmu/qemu-system-ppc64 -nodefaults -machine accel=qtest -nographic -monitor stdio -serial none -drive if=virtio
>
> which normally fails with:
>
> qemu-system-ppc64: -drive if=virtio: Device needs media, but drive is empty
>
> or asserts (without this patch):
>
> qemu-system-ppc64: /home/aik/p/qemu-kvm/memory.c:2118: memory_region_del_subregion: Assertion `subregion->container == mr' failed.
> ---
> hw/pci/pci.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index bd8043c460..259483b1c0 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -869,8 +869,10 @@ static void do_pci_unregister_device(PCIDevice *pci_dev)
> pci_dev->bus->devices[pci_dev->devfn] = NULL;
> pci_config_free(pci_dev);
>
> - memory_region_del_subregion(&pci_dev->bus_master_container_region,
> - &pci_dev->bus_master_enable_region);
> + if (memory_region_is_mapped(&pci_dev->bus_master_enable_region)) {
> + memory_region_del_subregion(&pci_dev->bus_master_container_region,
> + &pci_dev->bus_master_enable_region);
> + }
> address_space_destroy(&pci_dev->bus_master_as);
> }
>
> --
> 2.11.0
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-03-31 21:40 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-31 4:47 [Qemu-devel] [PATCH qemu] pci: Only unmap bus_master_enabled_region if was added previously Alexey Kardashevskiy
2017-03-31 10:33 ` Max Reitz
2017-03-31 11:56 ` Alexey Kardashevskiy
2017-03-31 12:08 ` Marcel Apfelbaum
2017-03-31 17:44 ` John Snow
2017-03-31 19:49 ` Paolo Bonzini
2017-03-31 21:40 ` Michael S. Tsirkin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.