From: "Michael S. Tsirkin" <mst@redhat.com>
To: arei.gonglei@huawei.com
Cc: weidong.huangwei@huawei.com, pbonzini@redhat.com,
alex.williamson@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/2] pci-assign: Fix memory out of bound when MSI-X table not fit in a single page
Date: Tue, 8 Apr 2014 18:32:12 +0300 [thread overview]
Message-ID: <20140408153212.GA8087@redhat.com> (raw)
In-Reply-To: <1396502304-7456-2-git-send-email-arei.gonglei@huawei.com>
On Thu, Apr 03, 2014 at 01:18:24PM +0800, arei.gonglei@huawei.com wrote:
> From: Gonglei <arei.gonglei@huawei.com>
>
> QEMU only mmap MSIX_PAGE_SIZE memory for all pci devices in
> assigned_dev_register_msix_mmio(), meanwhile the set the one
> page memmory to zero, so the rest memory will be random value
> (maybe etnry.data is not 0). In the assigned_dev_update_msix_mmio()
> maybe occur the issue of entry_nr > 256, and the kmod reports
> the EINVAL error.
>
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Okay so this kind of works because guest does not try
to use so many vectors.
But I think it's better not to give guest more entries
than we can actually support.
How about tweaking MSIX capability exposed to guest to limit table size?
> ---
> hw/i386/kvm/pci-assign.c | 15 ++++++++++++---
> 1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
> index 570333f..d25a19e 100644
> --- a/hw/i386/kvm/pci-assign.c
> +++ b/hw/i386/kvm/pci-assign.c
> @@ -37,6 +37,7 @@
> #include "hw/pci/pci.h"
> #include "hw/pci/msi.h"
> #include "kvm_i386.h"
> +#include "qemu/osdep.h"
>
> #define MSIX_PAGE_SIZE 0x1000
>
> @@ -59,6 +60,9 @@
> #define DEBUG(fmt, ...)
> #endif
>
> +/* the msix-table size readed from pci device config */
> +static int msix_table_size;
> +
> typedef struct PCIRegion {
> int type; /* Memory or port I/O */
> int valid;
> @@ -1604,7 +1608,12 @@ static void assigned_dev_msix_reset(AssignedDevice *dev)
>
> static int assigned_dev_register_msix_mmio(AssignedDevice *dev)
> {
> - dev->msix_table = mmap(NULL, MSIX_PAGE_SIZE, PROT_READ|PROT_WRITE,
> + msix_table_size = ROUND_UP(dev->msix_max * sizeof(struct MSIXTableEntry),
> + MSIX_PAGE_SIZE);
> +
> + DEBUG("msix_table_size: 0x%x\n", msix_table_size);
> +
> + dev->msix_table = mmap(NULL, msix_table_size, PROT_READ|PROT_WRITE,
> MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
> if (dev->msix_table == MAP_FAILED) {
> error_report("fail allocate msix_table! %s", strerror(errno));
> @@ -1615,7 +1624,7 @@ static int assigned_dev_register_msix_mmio(AssignedDevice *dev)
> assigned_dev_msix_reset(dev);
>
> memory_region_init_io(&dev->mmio, OBJECT(dev), &assigned_dev_msix_mmio_ops,
> - dev, "assigned-dev-msix", MSIX_PAGE_SIZE);
> + dev, "assigned-dev-msix", msix_table_size);
> return 0;
> }
>
> @@ -1627,7 +1636,7 @@ static void assigned_dev_unregister_msix_mmio(AssignedDevice *dev)
>
> memory_region_destroy(&dev->mmio);
>
> - if (munmap(dev->msix_table, MSIX_PAGE_SIZE) == -1) {
> + if (munmap(dev->msix_table, msix_table_size) == -1) {
> error_report("error unmapping msix_table! %s", strerror(errno));
> }
> dev->msix_table = NULL;
> --
> 1.7.12.4
>
>
next prev parent reply other threads:[~2014-04-08 15:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-03 5:18 [Qemu-devel] [PATCH 1/2] pci-assign: Fix a bug when map MSI-X table memory failed arei.gonglei
2014-04-03 5:18 ` [Qemu-devel] [PATCH 2/2] pci-assign: Fix memory out of bound when MSI-X table not fit in a single page arei.gonglei
2014-04-08 15:32 ` Michael S. Tsirkin [this message]
2014-04-09 10:56 ` Gonglei (Arei)
2014-04-09 13:52 ` Michael S. Tsirkin
2014-04-10 2:34 ` Gonglei (Arei)
2014-04-09 14:12 ` Laszlo Ersek
2014-04-10 2:05 ` Gonglei (Arei)
2014-04-08 14:02 ` [Qemu-devel] [PATCH 1/2] pci-assign: Fix a bug when map MSI-X table memory failed Gonglei (Arei)
2014-04-08 15:32 ` Michael S. Tsirkin
2014-04-09 14:21 ` 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=20140408153212.GA8087@redhat.com \
--to=mst@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=arei.gonglei@huawei.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=weidong.huangwei@huawei.com \
/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.