Re: [Qemu-devel] [PATCH v4 5/5] Add param Error ** for msi_init()

2016-04-29 Thread Markus Armbruster
Cao jin  writes:

> Hi Markus,
> sorry for replying so late, I am stucked by other tasks for a while.
>
> On 04/12/2016 07:50 PM, Markus Armbruster wrote:
>>
>> Examine how it uses msi_init().  That's how we give a PCI device
>> capability MSI.  If the device model treats msi_init() failure as fatal,
>> it doesn't have a non-MSI variant.
>>
>> Some device models let the user ask for MSI with a property, and make
>> the msi_init() call depend on the property.  The property is commonly
>> called "msi" or "use_msi", with values "on" and "off".
>>
>> msi=off then works as expected: you get the variant without MSI.
>>
>> The meaning of msi=on depends on how msi_init() failure is handled.  If
>> it's fatal, then msi=on works as expected: you get the variant with MSI.
>> But if it's not fatal, then you may or may not get it, which I consider
>> a grossly misleading user interface.
>>
>> To clean this up, we could add msi=auto, and move the non-fatal behavior
>> from msi=on to msi=auto.
>>
>> Same for MSI-X with msix_init() and property "msix".
>>
> Let me try to understand your meaning, correct me pls if I am wrong:
>
> replace the msi property type from bit/int to enum OnOffAuto(it seems
> need a tiny surgery for device structure), and default to auto. Then
> process going to look like this:
>
> (msi property = auto) means enable msi by default. If msi_init fail,
> we switch to the non-MSI variant; If msi_init success, we got msi
> variant.

You got it.

> Another condition I want to mention, ahci, pvscsi & vmxnet3 don`t have
> msi property, and when msi_init fail, they all will use intx. One
> thing need to be confirmed: whether they need a msi property or not?

While I don't particularly like additional configuration knobs, I like
the "try to use MSI, fall back to INTx silently" behavior even less.
I'd welcome such a property.  Can guarantee the respective maintainers
will agree with me, of course.



Re: [Qemu-devel] [PATCH v4 5/5] Add param Error ** for msi_init()

2016-04-29 Thread Cao jin

Hi Markus,
sorry for replying so late, I am stucked by other tasks for a while.

On 04/12/2016 07:50 PM, Markus Armbruster wrote:


Examine how it uses msi_init().  That's how we give a PCI device
capability MSI.  If the device model treats msi_init() failure as fatal,
it doesn't have a non-MSI variant.

Some device models let the user ask for MSI with a property, and make
the msi_init() call depend on the property.  The property is commonly
called "msi" or "use_msi", with values "on" and "off".

msi=off then works as expected: you get the variant without MSI.

The meaning of msi=on depends on how msi_init() failure is handled.  If
it's fatal, then msi=on works as expected: you get the variant with MSI.
But if it's not fatal, then you may or may not get it, which I consider
a grossly misleading user interface.

To clean this up, we could add msi=auto, and move the non-fatal behavior
from msi=on to msi=auto.

Same for MSI-X with msix_init() and property "msix".


Let me try to understand your meaning, correct me pls if I am wrong:

replace the msi property type from bit/int to enum OnOffAuto(it seems 
need a tiny surgery for device structure), and default to auto. Then 
process going to look like this:


(msi property = auto) means enable msi by default. If msi_init fail, we 
switch to the non-MSI variant; If msi_init success, we got msi variant.


Another condition I want to mention, ahci, pvscsi & vmxnet3 don`t have 
msi property, and when msi_init fail, they all will use intx. One thing 
need to be confirmed: whether they need a msi property or not?


--
Yours Sincerely,

Cao jin





Re: [Qemu-devel] [PATCH v4 5/5] Add param Error ** for msi_init()

2016-04-12 Thread Markus Armbruster
Marcel Apfelbaum  writes:

> On 04/10/2016 12:38 PM, Cao jin wrote:
>>
>>
>> On 04/10/2016 04:20 PM, Marcel Apfelbaum wrote:
>>
>>>
>>> Hi,
>>> I'll let Markus to continue the review, it brings very valuable
>>> information,
>>> I will only try to answer the questions below.
>>>
 Several questions on this topic:
 1. How to confirm whether a device model has non-MSI variant? AFAICT,
 it is these who have msi property.

Examine how it uses msi_init().  That's how we give a PCI device
capability MSI.  If the device model treats msi_init() failure as fatal,
it doesn't have a non-MSI variant.

Some device models let the user ask for MSI with a property, and make
the msi_init() call depend on the property.  The property is commonly
called "msi" or "use_msi", with values "on" and "off".

msi=off then works as expected: you get the variant without MSI.

The meaning of msi=on depends on how msi_init() failure is handled.  If
it's fatal, then msi=on works as expected: you get the variant with MSI.
But if it's not fatal, then you may or may not get it, which I consider
a grossly misleading user interface.

To clean this up, we could add msi=auto, and move the non-fatal behavior
from msi=on to msi=auto.

Same for MSI-X with msix_init() and property "msix".

>>> MSI is required for PCI Express devices, optional for PCI devices.
>>> Even if a PCI device supports MSI, it is strongly advised to support
>>> legacy INTx for backward compatibility.

Devices commonly do, but the standards certainly permit devices that
only do MSI or MSI-X.

PCI Local Bus Specification Revision 3.0 (2004) section 6.8: "It is
recommended that devices implement interrupt pins to provide
compatibility in systems that do not support MSI (devices default to
interrupt pins).  However, it is expected that the need for interrupt
pins will diminish over time.  Devices that do not support interrupt
pins due to pin constraints (rely on polling for device service) may
implement messages to increase performance without adding additional
pins.  Therefore, system configuration software must not assume that a
message capable device has an interrupt pin."

PCIe emulates INTx for software compatibility with PCI.  PCI Express
Base Specification Revision 3.0 (2010) section 6.1.2: "The legacy INTx
emulation mechanism may be deprecated in a future version of this
specification."

>>> Bottom line, as far as I know, almost all PCI devices support legacy
>>> interrupts.
>>> (an exception is the ivshmem device that requires MSI)

Virtual devices modelled after a physical device should follow the
physical device's example as closely as practical.

For reasons discussed recently, we don't actually do that when it comes
to MSI and MSI-X.  Instead, we tend to provide up to four variants of a
virtual device: with/without MSI/MSI-X capability.  Typically they all
support legacy INTx.

ivshmem doesn't have a physical model, so we can do whatever we want.

The deprecated "ivshmem" device comes in four variants: with/without
interrupts, with/without MSI-X capability.  The variant without
interrupts but with MSI-X capability is of course silly.  The variant
with interrupts and with MSI-X capability can't do legacy INTx.  It
could, but it's not worth changing now.

The modern "ivshmem-plain" and "ivshmem-doorbell" device don't come in
variants.  The former doesn't have interrupts (guest-compatible to
"ivshmem" without interrupts and without MSI-X), and the latter only
supports MSI-X interrupts (guest-compatible to "ivshmem" with interrupts
and with MSI-X).

 2. For those have non-MSI variant devices(have msi property), as I see
 in the code, they all have it on by default, So we won`t know it is
 user order, or user don`t set it at all.

Correct.

Note that if we add value "auto" and make it the default, then value
"on" is known to be the user's order.

>>> I didn't quite understand the sentence, but some devices have a
>>> "use_msi" property that can be set by the user. If no such property exists,
>>> we can assume the user "prefers" the msi version.
>>>
>> Hi,
>> Sorry for my bad description. let me explain myself again.
>> I think(guess), if a device model has msi property, it means this device 
>> model has non-msi variant. For those devices who has msi property, I see 
>> most of them will have it on by default. So when these
>> devices initialize msi, qemu won`t know whether it is user order or not.
>>
>> If I understand Markus right:
>> 1). If user orders msi on, when msi_init returns -ENOTSUP, It is error. Then 
>> I suggest to inform user "set msi=off and try again"
>
> If the user *specifically* asked for msi=on (setting a property) is OK to 
> fail the device init process.

Yes, failing is the only sane behavior when the user asked for msi=on
but we can't provide it.

However, in the device model code, we can't know whether the asked for
msi=on, or whether the property defaults to on.  That's why I'd like us
to add msi=auto 

Re: [Qemu-devel] [PATCH v4 5/5] Add param Error ** for msi_init()

2016-04-12 Thread Markus Armbruster
Cao jin  writes:

> Hi
>
> On 04/08/2016 04:44 PM, Markus Armbruster wrote:
>
>>> diff --git a/hw/ide/ich.c b/hw/ide/ich.c
>>> index 0a13334..db4fdb5 100644
>>> --- a/hw/ide/ich.c
>>> +++ b/hw/ide/ich.c
>>> @@ -146,7 +146,7 @@ static void pci_ich9_ahci_realize(PCIDevice *dev, Error 
>>> **errp)
>>>   /* Although the AHCI 1.3 specification states that the first 
>>> capability
>>>* should be PMCAP, the Intel ICH9 data sheet specifies that the ICH9
>>>* AHCI device puts the MSI capability first, pointing to 0x80. */
>>> -msi_init(dev, ICH9_MSI_CAP_OFFSET, 1, true, false);
>>> +msi_init(dev, ICH9_MSI_CAP_OFFSET, 1, true, false, errp);
>>
>> Sure there's nothing to undo on error?  Instead of undoing, you may want
>> to move msi_init() before the stuff that needs undoing.
>>
>
> ich9-ahci is a on-board device of Q35, like cover-letter says: when it
> fail, qemu will exit. So, is it necessary to undo on error?

Yes, it's a Q35 onboard device, but it's not only that: QEMU happily
accepts -device ich9-ahci.

A realize() method should fail cleanly unless its device has
cannot_instantiate_with_device_add_yet set.

> maybe you saw, I did move msi_init() for some other devices.

Yes.  Appreciated!

[...]



Re: [Qemu-devel] [PATCH v4 5/5] Add param Error ** for msi_init()

2016-04-11 Thread Cao jin



On 04/11/2016 06:00 PM, Marcel Apfelbaum wrote:



2). If user doesn`t order msi on(so device have msi on by default),
when msi_init returns -ENOTSUP, I am ok with Markus`s suggestion:
*caller should silently switch to the non-MSI variant*

But now the condition is, qemu can`t distinguish whether user ordered
msi or not, so for the condition 2) above, my suggestion is the same
as 1)



If we can't distinguish between the cases, 2 would not be user-friendly.
Once it would be possible to differentiate we could go for 2.



Hi,

How to differentiate? Do you mean: let these msi(msix) property default 
to 'off'? It seem most device have it on, a few have it off.




Thanks,
Marcel



--
Yours Sincerely,

Cao jin





Re: [Qemu-devel] [PATCH v4 5/5] Add param Error ** for msi_init()

2016-04-11 Thread Marcel Apfelbaum

On 04/10/2016 12:38 PM, Cao jin wrote:



On 04/10/2016 04:20 PM, Marcel Apfelbaum wrote:



Hi,
I'll let Markus to continue the review, it brings very valuable
information,
I will only try to answer the questions below.


Several questions on this topic:
1. How to confirm whether a device model has non-MSI variant? AFAICT,
it is these who have msi property.



MSI is required for PCI Express devices, optional for PCI devices.
Even if a PCI device supports MSI, it is strongly advised to support
legacy INTx for backward compatibility.
Bottom line, as far as I know, almost all PCI devices support legacy
interrupts.
(an exception is the ivshmem device that requires MSI)


2. For those have non-MSI variant devices(have msi property), as I see
in the code, they all have it on by default, So we won`t know it is
user order, or user don`t set it at all.



I didn't quite understand the sentence, but some devices have a
"use_msi" property that can be set by the user. If no such property exists,
we can assume the user "prefers" the msi version.


Hi,
Sorry for my bad description. let me explain myself again.
I think(guess), if a device model has msi property, it means this device model 
has non-msi variant. For those devices who has msi property, I see most of them 
will have it on by default. So when these
devices initialize msi, qemu won`t know whether it is user order or not.

If I understand Markus right:
1). If user orders msi on, when msi_init returns -ENOTSUP, It is error. Then I suggest to 
inform user "set msi=off and try again"


If the user *specifically* asked for msi=on (setting a property) is OK to fail 
the device init process.


2). If user doesn`t order msi on(so device have msi on by default), when 
msi_init returns -ENOTSUP, I am ok with Markus`s suggestion: *caller should 
silently switch to the non-MSI variant*

But now the condition is, qemu can`t distinguish whether user ordered msi or 
not, so for the condition 2) above, my suggestion is the same as 1)



If we can't distinguish between the cases, 2 would not be user-friendly. Once 
it would be possible to differentiate we could go for 2.


Thanks,
Marcel




If user don`t know msi and don`t set it on, I think it is acceptable
to create the non-msi variant for user silently. But if it is user
order, like you said, it is an error.



I am not sure about this. At least a warning should be given IMHO.


So, how about: inform user to swich msi off and try again when
encounter -ENOTSUP, no matter it is user order, or user doesn`t set it
at all?



Not all devices have an "msi" switch. If the board has msi broken and
the devices supports legacy interrupts, its OK to continue without MSI.


Actually in this v4, I do checked whether device has a msi property,
like cover-letter said:

   3. most devices have msi/msix(except vmxnet3 & pvscsi) property as
a   switch, if it has and is switched on, then msi_init() failure
should   results in return directly. So in this version, mptsas
is updated



I don't see a "msi" properties on PCIDevice class or VirtioPCIClass, are
you sure we have an msi switch for most of the PCI devices?



My bad, I didn`t limit the range. I mean the devices who will call msi_init, 
they mostly have msi(or msix, or both) property








Re: [Qemu-devel] [PATCH v4 5/5] Add param Error ** for msi_init()

2016-04-10 Thread Cao jin



On 04/10/2016 04:20 PM, Marcel Apfelbaum wrote:



Hi,
I'll let Markus to continue the review, it brings very valuable
information,
I will only try to answer the questions below.


Several questions on this topic:
1. How to confirm whether a device model has non-MSI variant? AFAICT,
it is these who have msi property.



MSI is required for PCI Express devices, optional for PCI devices.
Even if a PCI device supports MSI, it is strongly advised to support
legacy INTx for backward compatibility.
Bottom line, as far as I know, almost all PCI devices support legacy
interrupts.
(an exception is the ivshmem device that requires MSI)


2. For those have non-MSI variant devices(have msi property), as I see
in the code, they all have it on by default, So we won`t know it is
user order, or user don`t set it at all.



I didn't quite understand the sentence, but some devices have a
"use_msi" property that can be set by the user. If no such property exists,
we can assume the user "prefers" the msi version.


Hi,
Sorry for my bad description. let me explain myself again.
I think(guess), if a device model has msi property, it means this device 
model has non-msi variant. For those devices who has msi property, I see 
most of them will have it on by default. So when these devices 
initialize msi, qemu won`t know whether it is user order or not.


If I understand Markus right:
1). If user orders msi on, when msi_init returns -ENOTSUP, It is error. 
Then I suggest to inform user "set msi=off and try again"
2). If user doesn`t order msi on(so device have msi on by default), when 
msi_init returns -ENOTSUP, I am ok with Markus`s suggestion: *caller 
should silently switch to the non-MSI variant*


But now the condition is, qemu can`t distinguish whether user ordered 
msi or not, so for the condition 2) above, my suggestion is the same as 1)





If user don`t know msi and don`t set it on, I think it is acceptable
to create the non-msi variant for user silently. But if it is user
order, like you said, it is an error.



I am not sure about this. At least a warning should be given IMHO.


So, how about: inform user to swich msi off and try again when
encounter -ENOTSUP, no matter it is user order, or user doesn`t set it
at all?



Not all devices have an "msi" switch. If the board has msi broken and
the devices supports legacy interrupts, its OK to continue without MSI.


Actually in this v4, I do checked whether device has a msi property,
like cover-letter said:

   3. most devices have msi/msix(except vmxnet3 & pvscsi) property as
a   switch, if it has and is switched on, then msi_init() failure
should   results in return directly. So in this version, mptsas
is updated



I don't see a "msi" properties on PCIDevice class or VirtioPCIClass, are
you sure we have an msi switch for most of the PCI devices?



My bad, I didn`t limit the range. I mean the devices who will call 
msi_init, they mostly have msi(or msix, or both) property




--
Yours Sincerely,

Cao jin





Re: [Qemu-devel] [PATCH v4 5/5] Add param Error ** for msi_init()

2016-04-10 Thread Marcel Apfelbaum

On 04/09/2016 03:19 PM, Cao jin wrote:

Hi

On 04/08/2016 04:44 PM, Markus Armbruster wrote:


diff --git a/hw/ide/ich.c b/hw/ide/ich.c
index 0a13334..db4fdb5 100644
--- a/hw/ide/ich.c
+++ b/hw/ide/ich.c
@@ -146,7 +146,7 @@ static void pci_ich9_ahci_realize(PCIDevice *dev, Error 
**errp)
  /* Although the AHCI 1.3 specification states that the first capability
   * should be PMCAP, the Intel ICH9 data sheet specifies that the ICH9
   * AHCI device puts the MSI capability first, pointing to 0x80. */
-msi_init(dev, ICH9_MSI_CAP_OFFSET, 1, true, false);
+msi_init(dev, ICH9_MSI_CAP_OFFSET, 1, true, false, errp);


Sure there's nothing to undo on error?  Instead of undoing, you may want
to move msi_init() before the stuff that needs undoing.



ich9-ahci is a on-board device of Q35, like cover-letter says: when it fail, 
qemu will exit. So, is it necessary to undo on error?

maybe you saw, I did move msi_init() for some other devices.


diff --git a/hw/pci/msi.c b/hw/pci/msi.c


msi_init() has three failure modes:

* -ENOTSUP

   Board's MSI emulation is not known to work: !msi_nonbroken.

   This is not necessarily an error.

   It is when the device model requires MSI.

   It isnt' when a non-MSI variant of the device model exists.  Then
   caller should silently switch to the non-MSI variant[*].





Hi,
I'll let Markus to continue the review, it brings very valuable information,
I will only try to answer the questions below.


Several questions on this topic:
1. How to confirm whether a device model has non-MSI variant? AFAICT, it is 
these who have msi property.



MSI is required for PCI Express devices, optional for PCI devices.
Even if a PCI device supports MSI, it is strongly advised to support
legacy INTx for backward compatibility.
Bottom line, as far as I know, almost all PCI devices support legacy interrupts.
(an exception is the ivshmem device that requires MSI)


2. For those have non-MSI variant devices(have msi property), as I see in the 
code, they all have it on by default, So we won`t know it is user order, or 
user don`t set it at all.



I didn't quite understand the sentence, but some devices have a "use_msi" 
property that can be set by the user. If no such property exists,
we can assume the user "prefers" the msi version.



If user don`t know msi and don`t set it on, I think it is acceptable to create 
the non-msi variant for user silently. But if it is user order, like you said, 
it is an error.



I am not sure about this. At least a warning should be given IMHO.


So, how about: inform user to swich msi off and try again when encounter 
-ENOTSUP, no matter it is user order, or user doesn`t set it at all?



Not all devices have an "msi" switch. If the board has msi broken and the 
devices supports legacy interrupts, its OK to continue without MSI.


Actually in this v4, I do checked whether device has a msi property, like 
cover-letter said:

   3. most devices have msi/msix(except vmxnet3 & pvscsi) property as a   
switch, if it has and is switched on, then msi_init() failure should   results in 
return directly. So in this version, mptsas
is updated



I don't see a "msi" properties on PCIDevice class or VirtioPCIClass, are you 
sure we have an msi switch for most of the PCI devices?

Thanks for looking into this,
Marcel



Re: [Qemu-devel] [PATCH v4 5/5] Add param Error ** for msi_init()

2016-04-09 Thread Cao jin



On 04/09/2016 08:19 PM, Cao jin wrote:

Hi







Several questions on this topic:
1. How to confirm whether a device model has non-MSI variant? AFAICT, it
is these who have msi property.

2. For those have non-MSI variant devices(have msi property), as I see
in the code, they all have it on by default, So we won`t know it is user


Sorry, not accurate, not 'all', should be 'most'(megasas have it off by 
default)


--
Yours Sincerely,

Cao jin





Re: [Qemu-devel] [PATCH v4 5/5] Add param Error ** for msi_init()

2016-04-09 Thread Cao jin

Hi

On 04/08/2016 04:44 PM, Markus Armbruster wrote:


diff --git a/hw/ide/ich.c b/hw/ide/ich.c
index 0a13334..db4fdb5 100644
--- a/hw/ide/ich.c
+++ b/hw/ide/ich.c
@@ -146,7 +146,7 @@ static void pci_ich9_ahci_realize(PCIDevice *dev, Error 
**errp)
  /* Although the AHCI 1.3 specification states that the first capability
   * should be PMCAP, the Intel ICH9 data sheet specifies that the ICH9
   * AHCI device puts the MSI capability first, pointing to 0x80. */
-msi_init(dev, ICH9_MSI_CAP_OFFSET, 1, true, false);
+msi_init(dev, ICH9_MSI_CAP_OFFSET, 1, true, false, errp);


Sure there's nothing to undo on error?  Instead of undoing, you may want
to move msi_init() before the stuff that needs undoing.



ich9-ahci is a on-board device of Q35, like cover-letter says: when it 
fail, qemu will exit. So, is it necessary to undo on error?


maybe you saw, I did move msi_init() for some other devices.


diff --git a/hw/pci/msi.c b/hw/pci/msi.c


msi_init() has three failure modes:

* -ENOTSUP

   Board's MSI emulation is not known to work: !msi_nonbroken.

   This is not necessarily an error.

   It is when the device model requires MSI.

   It isnt' when a non-MSI variant of the device model exists.  Then
   caller should silently switch to the non-MSI variant[*].



Several questions on this topic:
1. How to confirm whether a device model has non-MSI variant? AFAICT, it 
is these who have msi property.


2. For those have non-MSI variant devices(have msi property), as I see 
in the code, they all have it on by default, So we won`t know it is user 
order, or user don`t set it at all.


If user don`t know msi and don`t set it on, I think it is acceptable to 
create the non-msi variant for user silently. But if it is user order, 
like you said, it is an error.


So, how about: inform user to swich msi off and try again when encounter 
-ENOTSUP, no matter it is user order, or user doesn`t set it at all?


Actually in this v4, I do checked whether device has a msi property, 
like cover-letter said:


  3. most devices have msi/msix(except vmxnet3 & pvscsi) property as a 
  switch, if it has and is switched on, then msi_init() failure should 
  results in return directly. So in this version, mptsas is updated


--
Yours Sincerely,

Cao jin





Re: [Qemu-devel] [PATCH v4 5/5] Add param Error ** for msi_init()

2016-04-08 Thread Markus Armbruster
Cao jin  writes:

> Add param Error **errp, and change pci_add_capability() to
> pci_add_capability2(), because pci_add_capability() report error, and
> msi_init() is widely used in realize(), so it is not suitable for realize()

Suggest:

pci: Convert msi_init() to Error and fix callers to check it

msi_init() reports errors with error_report(), which is wrong when
it's used in realize().

Fix by converting it to Error.

But see the discussion of the msi_init() failure modes below; commit
message may need further work for that.

Same issue in msix_init().  Please fix that as well, if it's not too
much trouble.

> Also fix all the callers who should deal with the msi_init() failure
> but actually not.

Grammar: "but actually don't" (you need a verb).

You neglect to explain the bug's impact.  Something like

Fix its callers to handle failure instead of ignoring it.
[Description on what goes wrong because of that goes here]

>
> Signed-off-by: Cao jin 
> ---
>  hw/audio/intel-hda.c   | 11 +++---
>  hw/ide/ich.c   |  2 +-
>  hw/net/vmxnet3.c   | 41 
> +++---
>  hw/pci-bridge/ioh3420.c|  4 +++-
>  hw/pci-bridge/pci_bridge_dev.c |  4 +++-
>  hw/pci-bridge/xio3130_downstream.c |  4 +++-
>  hw/pci-bridge/xio3130_upstream.c   |  4 +++-
>  hw/pci/msi.c   |  9 +++--
>  hw/scsi/megasas.c  | 12 +++
>  hw/scsi/mptsas.c   | 15 +-
>  hw/scsi/vmw_pvscsi.c   |  6 +-
>  hw/usb/hcd-xhci.c  | 10 +++---
>  hw/vfio/pci.c  |  6 --
>  include/hw/pci/msi.h   |  3 ++-
>  14 files changed, 80 insertions(+), 51 deletions(-)
>
> diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c
> index d372d4a..c3856cc 100644
> --- a/hw/audio/intel-hda.c
> +++ b/hw/audio/intel-hda.c
> @@ -1139,12 +1139,17 @@ static void intel_hda_realize(PCIDevice *pci, Error 
> **errp)
>  /* HDCTL off 0x40 bit 0 selects signaling mode (1-HDA, 0 - Ac97) 18.1.19 
> */
>  conf[0x40] = 0x01;
>  
> +if (d->msi) {
> +msi_init(>pci, d->old_msi_addr ? 0x50 : 0x60, 1,
> +true, false, errp);
> +if (*errp) {

Crash bug if errp is null.  I guess it's never null here right now, but
let's not rely on that for robustness, and to avoid setting a bad
example.  Bad examples multiply like rabbits.

The big comment in error.h explains how to receive an error correctly:

 * Receive an error and pass it on to the caller:
 * Error *err = NULL;
 * foo(arg, );
 * if (err) {
 * handle the error...
 * error_propagate(errp, err);
 * }
 * where Error **errp is a parameter, by convention the last one.

This is what you should do here.

 *
 * Do *not* "optimize" this to
 * foo(arg, errp);
 * if (*errp) { // WRONG!
 * handle the error...
 * }
 * because errp may be NULL!

This is what your patch does.

 *
 * But when all you do with the error is pass it on, please use
 * foo(arg, errp);
 * for readability.
 *

> +return;
> +}
> +}
> +
>  memory_region_init_io(>mmio, OBJECT(d), _hda_mmio_ops, d,
>"intel-hda", 0x4000);
>  pci_register_bar(>pci, 0, 0, >mmio);
> -if (d->msi) {
> -msi_init(>pci, d->old_msi_addr ? 0x50 : 0x60, 1, true, false);
> -}
>  
>  hda_codec_bus_init(DEVICE(pci), >codecs, sizeof(d->codecs),
> intel_hda_response, intel_hda_xfer);
> diff --git a/hw/ide/ich.c b/hw/ide/ich.c
> index 0a13334..db4fdb5 100644
> --- a/hw/ide/ich.c
> +++ b/hw/ide/ich.c
> @@ -146,7 +146,7 @@ static void pci_ich9_ahci_realize(PCIDevice *dev, Error 
> **errp)
>  /* Although the AHCI 1.3 specification states that the first capability
>   * should be PMCAP, the Intel ICH9 data sheet specifies that the ICH9
>   * AHCI device puts the MSI capability first, pointing to 0x80. */
> -msi_init(dev, ICH9_MSI_CAP_OFFSET, 1, true, false);
> +msi_init(dev, ICH9_MSI_CAP_OFFSET, 1, true, false, errp);

Sure there's nothing to undo on error?  Instead of undoing, you may want
to move msi_init() before the stuff that needs undoing.

>  }
>  
>  static void pci_ich9_uninit(PCIDevice *dev)
> diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c
> index 7a38e47..d8dbb0b 100644
> --- a/hw/net/vmxnet3.c
> +++ b/hw/net/vmxnet3.c
> @@ -2189,27 +2189,6 @@ vmxnet3_cleanup_msix(VMXNET3State *s)
>  }
>  }
>  
> -#define VMXNET3_USE_64BIT (true)
> -#define VMXNET3_PER_VECTOR_MASK   (false)
> -
> -static bool
> -vmxnet3_init_msi(VMXNET3State *s)
> -{
> -PCIDevice *d = PCI_DEVICE(s);
> -int res;
> -
> -res = msi_init(d, VMXNET3_MSI_OFFSET(s), VMXNET3_MAX_NMSIX_INTRS,
> -   VMXNET3_USE_64BIT, VMXNET3_PER_VECTOR_MASK);
> -if (0 > res) {
> -