All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Cao jin <caoj.fnst@cn.fujitsu.com>
Cc: qemu-devel@nongnu.org, Marcel Apfelbaum <marcel@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 1/5] msix_init: assert programming error
Date: Mon, 12 Sep 2016 15:29:35 +0200	[thread overview]
Message-ID: <87y42xw8jk.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <1471944454-13895-2-git-send-email-caoj.fnst@cn.fujitsu.com> (Cao jin's message of "Tue, 23 Aug 2016 17:27:30 +0800")

Cao jin <caoj.fnst@cn.fujitsu.com> writes:

> The input parameters is used for creating the msix capable device, so
> they must obey the PCI spec, or else, it should be programming error.

True when the the parameters come from a device model attempting to
define a PCI device violating the spec.  But what if the parameters come
from an actual PCI device violating the spec, via device assignment?

For what it's worth, the new behavior seems consistent with msi_init(),
which is good.

> CC: Markus Armbruster <armbru@redhat.com>
> CC: Marcel Apfelbaum <marcel@redhat.com>
> CC: Michael S. Tsirkin <mst@redhat.com>
> Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
> ---
>  hw/pci/msix.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/hw/pci/msix.c b/hw/pci/msix.c
> index 0ec1cb1..384a29d 100644
> --- a/hw/pci/msix.c
> +++ b/hw/pci/msix.c
> @@ -253,9 +253,7 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries,
>          return -ENOTSUP;
>      }
>  
> -    if (nentries < 1 || nentries > PCI_MSIX_FLAGS_QSIZE + 1) {
> -        return -EINVAL;
> -    }
> +    assert(nentries >= 1 && nentries <= PCI_MSIX_FLAGS_QSIZE + 1);
>  
>      table_size = nentries * PCI_MSIX_ENTRY_SIZE;
>      pba_size = QEMU_ALIGN_UP(nentries, 64) / 8;
> @@ -266,7 +264,7 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries,
       /* Sanity test: table & pba don't overlap, fit within BARs, min aligned */
       if ((table_bar_nr == pba_bar_nr &&
            ranges_overlap(table_offset, table_size, pba_offset, pba_size)) ||
>          table_offset + table_size > memory_region_size(table_bar) ||
>          pba_offset + pba_size > memory_region_size(pba_bar) ||
>          (table_offset | pba_offset) & PCI_MSIX_FLAGS_BIRMASK) {
> -        return -EINVAL;
> +        assert(0);
>      }

Instead of

    if (... complicated condition ...) {
        assert(0);
    }

let's write

    assert(... negation of the complicated condition ...);

>  
>      cap = pci_add_capability(dev, PCI_CAP_ID_MSIX, cap_pos, MSIX_CAP_LENGTH);

  reply	other threads:[~2016-09-12 13:29 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-23  9:27 [Qemu-devel] [PATCH v2 0/5] Convert msix_init() to error Cao jin
2016-08-23  9:27 ` [Qemu-devel] [PATCH v2 1/5] msix_init: assert programming error Cao jin
2016-09-12 13:29   ` Markus Armbruster [this message]
2016-09-13  2:51     ` Cao jin
2016-09-13  6:16       ` Markus Armbruster
2016-09-13 14:49         ` Alex Williamson
2016-09-29 13:11           ` Markus Armbruster
2016-09-29 16:10             ` Alex Williamson
2016-09-30 14:06               ` Markus Armbruster
2016-09-30 18:06                 ` Dr. David Alan Gilbert
2016-10-04  9:33                   ` Markus Armbruster
2016-10-04 11:19                     ` Dr. David Alan Gilbert
2016-10-06  7:00                 ` Cao jin
2016-08-23  9:27 ` [Qemu-devel] [PATCH v2 2/5] msix: Follow CODING_STYLE Cao jin
2016-08-23  9:27 ` [Qemu-devel] [PATCH v2 3/5] pci: Convert msix_init() to Error and fix callers to check it Cao jin
2016-09-12 13:47   ` Markus Armbruster
2016-09-13  6:04     ` Cao jin
2016-09-13  8:27       ` Markus Armbruster
2016-08-23  9:27 ` [Qemu-devel] [PATCH v2 4/5] megasas: remove unnecessary megasas_use_msix() Cao jin
2016-08-23  9:27 ` [Qemu-devel] [PATCH v2 5/5] megasas: undo the overwrites of user configuration Cao jin
2016-09-06 12:42 ` [Qemu-devel] [PATCH v2 0/5] Convert msix_init() to error Cao jin

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=87y42xw8jk.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=caoj.fnst@cn.fujitsu.com \
    --cc=marcel@redhat.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 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.