f7795e4096
Description copied from Linux kernel commit from Gustavo A. R. Silva
(see [3]):
--v-- description start --v--
The current codebase makes use of the zero-length array language
extension to the C90 standard, but the preferred mechanism to
declare variable-length types such as these ones is a flexible
array member [1], introduced in C99:
struct foo {
int stuff;
struct boo array[];
};
By making use of the mechanism above, we will get a compiler
warning in case the flexible array does not occur last in the
structure, which will help us prevent some kind of undefined
behavior bugs from being unadvertenly introduced [2] to the
Linux codebase from now on.
--^-- description end --^--
Do the similar housekeeping in the QEMU codebase (which uses
C99 since commit 7be41675f7
).
All these instances of code were found with the help of the
following Coccinelle script:
@@
identifier s, m, a;
type t, T;
@@
struct s {
...
t m;
- T a[0];
+ T a[];
};
@@
identifier s, m, a;
type t, T;
@@
struct s {
...
t m;
- T a[0];
+ T a[];
} QEMU_PACKED;
[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=76497732932f
[3] https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git/commit/?id=17642a2fbd2c1
Inspired-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
62 lines
1.7 KiB
C
62 lines
1.7 KiB
C
/*
|
|
* virtio-iommu device
|
|
*
|
|
* Copyright (c) 2020 Red Hat, Inc.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms and conditions of the GNU General Public License,
|
|
* version 2 or later, as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
*/
|
|
|
|
#ifndef QEMU_VIRTIO_IOMMU_H
|
|
#define QEMU_VIRTIO_IOMMU_H
|
|
|
|
#include "standard-headers/linux/virtio_iommu.h"
|
|
#include "hw/virtio/virtio.h"
|
|
#include "hw/pci/pci.h"
|
|
|
|
#define TYPE_VIRTIO_IOMMU "virtio-iommu-device"
|
|
#define TYPE_VIRTIO_IOMMU_PCI "virtio-iommu-device-base"
|
|
#define VIRTIO_IOMMU(obj) \
|
|
OBJECT_CHECK(VirtIOIOMMU, (obj), TYPE_VIRTIO_IOMMU)
|
|
|
|
#define TYPE_VIRTIO_IOMMU_MEMORY_REGION "virtio-iommu-memory-region"
|
|
|
|
typedef struct IOMMUDevice {
|
|
void *viommu;
|
|
PCIBus *bus;
|
|
int devfn;
|
|
IOMMUMemoryRegion iommu_mr;
|
|
AddressSpace as;
|
|
} IOMMUDevice;
|
|
|
|
typedef struct IOMMUPciBus {
|
|
PCIBus *bus;
|
|
IOMMUDevice *pbdev[]; /* Parent array is sparse, so dynamically alloc */
|
|
} IOMMUPciBus;
|
|
|
|
typedef struct VirtIOIOMMU {
|
|
VirtIODevice parent_obj;
|
|
VirtQueue *req_vq;
|
|
VirtQueue *event_vq;
|
|
struct virtio_iommu_config config;
|
|
uint64_t features;
|
|
GHashTable *as_by_busptr;
|
|
IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX];
|
|
PCIBus *primary_bus;
|
|
GTree *domains;
|
|
QemuMutex mutex;
|
|
GTree *endpoints;
|
|
} VirtIOIOMMU;
|
|
|
|
#endif
|