From: Peter Maydell <peter.maydell@linaro.org>
To: Isaku Yamahata <isaku.yamahata@intel.com>
Cc: "Peter Maydell" <Peter.maydel@linaro.org>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"QEMU Developers" <qemu-devel@nongnu.org>,
"Igor Mammedov" <imammedo@redhat.com>,
isaku.yamahata@gmail.com
Subject: Re: [PATCH v2 2/3] pci: sprinkle assert in PCI pin number
Date: Tue, 23 Mar 2021 17:50:26 +0000 [thread overview]
Message-ID: <CAFEAcA83AgZ0QoyawPUgmeocGhnvRVYAU9KzWuDNDvWhTodidA@mail.gmail.com> (raw)
In-Reply-To: <dc9c8d2aa7bfcd82ba812f1ff5630a4cc0ffbbe7.1616519655.git.isaku.yamahata@intel.com>
On Tue, 23 Mar 2021 at 17:26, Isaku Yamahata <isaku.yamahata@intel.com> wrote:
>
> If a device model
> (a) doesn't set the value to a correct interrupt number and then
> (b) triggers an interrupt for itself,
> it's device model bug. Add assert on interrupt pin number to catch
> this kind of bug more obviously.
>
> Suggested-by: Peter Maydell <Peter.maydel@linaro.org>
> Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
> ---
> hw/pci/pci.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index ac9a24889c..cb6bab999b 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -1450,6 +1450,8 @@ static void pci_irq_handler(void *opaque, int irq_num, int level)
> PCIDevice *pci_dev = opaque;
> int change;
>
> + assert(0 <= irq_num && irq_num < PCI_NUM_PINS);
> + assert(level == 0 || level == 1);
If you have these...
> change = level - pci_irq_state(pci_dev, irq_num);
> if (!change)
> return;
> @@ -1463,7 +1465,13 @@ static void pci_irq_handler(void *opaque, int irq_num, int level)
>
> static inline int pci_intx(PCIDevice *pci_dev)
> {
> - return pci_get_byte(pci_dev->config + PCI_INTERRUPT_PIN) - 1;
> + int intx = pci_get_byte(pci_dev->config + PCI_INTERRUPT_PIN) - 1;
> + /*
> + * This function is used to setup/trigger irq.
> + * So PIN = 0 (interrupt isn't used) doesn't make sense.
> + */
> + assert(0 <= intx && intx < PCI_NUM_PINS);
...you don't need this, because the assert in pci_irq_handler()
covers all the uses of pci_intx().
See also
https://patchew.org/QEMU/20210323164601.27200-1-peter.maydell@linaro.org/
thanks
-- PMM
next prev parent reply other threads:[~2021-03-23 18:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-23 17:24 [PATCH v2 0/3] reinitialize ACPI PM device on reset Isaku Yamahata
2021-03-23 17:24 ` [PATCH v2 1/3] vt82c686.c: don't raise SCI when PCI_INTERRUPT_PIN isn't setup Isaku Yamahata
2021-03-23 18:43 ` Philippe Mathieu-Daudé
2021-03-23 22:33 ` BALATON Zoltan
2021-03-23 17:24 ` [PATCH v2 2/3] pci: sprinkle assert in PCI pin number Isaku Yamahata
2021-03-23 17:50 ` Peter Maydell [this message]
2021-03-24 16:37 ` Michael S. Tsirkin
2021-03-23 17:24 ` [PATCH v2 3/3] acpi:piix4, vt82c686: reinitialize acpi PM device on reset Isaku Yamahata
2021-03-23 19:36 ` Michael S. Tsirkin
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=CAFEAcA83AgZ0QoyawPUgmeocGhnvRVYAU9KzWuDNDvWhTodidA@mail.gmail.com \
--to=peter.maydell@linaro.org \
--cc=Peter.maydel@linaro.org \
--cc=f4bug@amsat.org \
--cc=imammedo@redhat.com \
--cc=isaku.yamahata@gmail.com \
--cc=isaku.yamahata@intel.com \
--cc=mst@redhat.com \
--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).