qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-devel@nongnu.org,
	Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
	Jason Wang <jasowang@redhat.com>
Subject: Re: [PATCH 4/4] hw/pci: Ensure pci_add_capability() is called before device is realized
Date: Tue, 21 Mar 2023 22:18:47 -0400	[thread overview]
Message-ID: <20230321221821-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20230314111435.89796-5-philmd@linaro.org>

On Tue, Mar 14, 2023 at 12:14:35PM +0100, Philippe Mathieu-Daudé wrote:
> PCI capabilities can't appear magically at runtime.
> Guests aren't expecting that. Assert all capabilities
> are added _before_ a device instance is realized.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  hw/pci/pci.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index ac41fcbf6a..ed60b352e4 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -2397,7 +2397,7 @@ static void pci_del_option_rom(PCIDevice *pdev)
>   * On success, pci_add_capability() returns a positive value
>   * that the offset of the pci capability.
>   * On failure, it sets an error and returns a negative error
> - * code.
> + * code. @pdev must be unrealized.
>   */
>  int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
>                         uint8_t offset, uint8_t size,
> @@ -2406,6 +2406,8 @@ int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
>      uint8_t *config;
>      int i, overlapping_cap;
>  
> +    assert(!DEVICE(pdev)->realized);
> +
>      if (!offset) {
>          offset = pci_find_space(pdev, size);
>          /* out of PCI config space is programming error */

Fails in CI:

https://gitlab.com/mstredhat/qemu/-/jobs/3976974199

qemu-system-i386: ../hw/pci/pci.c:2409: pci_add_capability: Assertion `!DEVICE(pdev)->realized' failed.
Broken pipe
../tests/qtest/libqtest.c:193: kill_qemu() detected QEMU death from signal 6 (Aborted) (core dumped)
TAP parsing error: Too few tests run (expected 49, got 40)
(test program exited with status code -6)



> -- 
> 2.38.1



  reply	other threads:[~2023-03-22  2:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-14 11:14 [PATCH 0/4] hw/pci: Ensure capabilities are added before calling pci_qdev_realize() Philippe Mathieu-Daudé
2023-03-14 11:14 ` [PATCH 1/4] hw/pci/msi: Fix debug format string Philippe Mathieu-Daudé
2023-03-14 11:14 ` [PATCH 2/4] hw/pci/msi: Ensure msi_init() is called before device is realized Philippe Mathieu-Daudé
2023-03-14 11:14 ` [PATCH 3/4] hw/pci: Add sanity check in pci_find_space() Philippe Mathieu-Daudé
2023-03-14 11:14 ` [PATCH 4/4] hw/pci: Ensure pci_add_capability() is called before device is realized Philippe Mathieu-Daudé
2023-03-22  2:18   ` Michael S. Tsirkin [this message]
2023-03-22  8:52     ` Philippe Mathieu-Daudé
2023-03-22 22:01       ` Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230321221821-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).