mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-08 18:23:57 -06:00
ivshmem: Fixes, cleanups, device model split
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAABAgAGBQJW8FqyAAoJEDhwtADrkYZTjYcP/R1m2LcFnLTxzDjSK38nxWcw 5t/Do7nBNgXL2ZdRHfJsy7bx/9RR55k16rvzkFgW8LpUa5Ro64onRh2PfMz2p0e8 QvZRBhXTh5/y4TD61y5Y8d9xawA6Hr1oEUtwsfovI9EiXzVaLl3sLI/nleed68Rk eAD2h8+ZcBeJ+lRK3UHEzAvqh0u+IScRMJifCxHyJuoZiylHIHVVq7x40ywg0Ejq 8wHEj/nDJZHUxbuH4sm215Lv4dK6CmIP8UzuhfY6MxAS6Jo7Zdk1zv2SjJO2DzwT rWU4hD0+khwTz3hBR341oWxb84C5MujPwkeP7mibR46HLHCn5imQMz0W+6tj7umb dxnwPpXzON00+56B7e4i21aXTO0IaY3AcL9QuETSAaoy3SD5BdDkt3R9XWM+jqqZ armE5nNAv8WEN8qUYL/YpBxFDYSZ3CFgNv1enoP2pSp4DqeF/H3aP4RWu+dYqLDm MyVhcXUkjHfTCY6NVPPBkNwSvz2vq4ft/b6t7tLN+0ZmIRsEegKxxRrI2vB6O8Ga Gh2iKcJfMp90jwwvywfGO+DNQ8npHvhxMkioyzMHflo0QyS2ZDhlf4ubp7cXlYZ6 tj7iGXJKJQpQyJWA58k8EXR9wc2W+fgRYD/H61QTTyTUgxEo6w10KjBDTsbFwvIY R0poHCfRR0DQ7y3GerZO =XEMm -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/armbru/tags/pull-ivshmem-2016-03-18' into staging ivshmem: Fixes, cleanups, device model split # gpg: Signature made Mon 21 Mar 2016 20:33:54 GMT using RSA key ID EB918653 # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" * remotes/armbru/tags/pull-ivshmem-2016-03-18: (40 commits) contrib/ivshmem-server: Print "not for production" warning ivshmem: Require master to have ID zero ivshmem: Drop ivshmem property x-memdev ivshmem: Clean up after the previous commit ivshmem: Split ivshmem-plain, ivshmem-doorbell off ivshmem ivshmem: Replace int role_val by OnOffAuto master qdev: New DEFINE_PROP_ON_OFF_AUTO ivshmem: Inline check_shm_size() into its only caller ivshmem: Simplify memory regions for BAR 2 (shared memory) ivshmem: Implement shm=... with a memory backend ivshmem: Tighten check of property "size" ivshmem: Simplify how we cope with short reads from server ivshmem: Drop the hackish test for UNIX domain chardev ivshmem: Rely on server sending the ID right after the version ivshmem: Propagate errors through ivshmem_recv_setup() ivshmem: Receive shared memory synchronously in realize() ivshmem: Plug leaks on unplug, fix peer disconnect ivshmem: Disentangle ivshmem_read() ivshmem: Simplify rejection of invalid peer ID from server ivshmem: Assert interrupts are set up once ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
2538039f2c
15 changed files with 1053 additions and 851 deletions
|
@ -166,7 +166,7 @@ gcov-files-pci-y += hw/display/virtio-gpu-pci.c
|
|||
gcov-files-pci-$(CONFIG_VIRTIO_VGA) += hw/display/virtio-vga.c
|
||||
check-qtest-pci-y += tests/intel-hda-test$(EXESUF)
|
||||
gcov-files-pci-y += hw/audio/intel-hda.c hw/audio/hda-codec.c
|
||||
check-qtest-pci-$(CONFIG_POSIX) += tests/ivshmem-test$(EXESUF)
|
||||
check-qtest-pci-$(CONFIG_EVENTFD) += tests/ivshmem-test$(EXESUF)
|
||||
gcov-files-pci-y += hw/misc/ivshmem.c
|
||||
|
||||
check-qtest-i386-y = tests/endianness-test$(EXESUF)
|
||||
|
|
|
@ -110,25 +110,26 @@ static void setup_vm_cmd(IVState *s, const char *cmd, bool msix)
|
|||
s->pcibus = qpci_init_pc();
|
||||
s->dev = get_device(s->pcibus);
|
||||
|
||||
/* FIXME: other bar order fails, mappings changes */
|
||||
s->mem_base = qpci_iomap(s->dev, 2, &barsize);
|
||||
g_assert_nonnull(s->mem_base);
|
||||
g_assert_cmpuint(barsize, ==, TMPSHMSIZE);
|
||||
s->reg_base = qpci_iomap(s->dev, 0, &barsize);
|
||||
g_assert_nonnull(s->reg_base);
|
||||
g_assert_cmpuint(barsize, ==, 256);
|
||||
|
||||
if (msix) {
|
||||
qpci_msix_enable(s->dev);
|
||||
}
|
||||
|
||||
s->reg_base = qpci_iomap(s->dev, 0, &barsize);
|
||||
g_assert_nonnull(s->reg_base);
|
||||
g_assert_cmpuint(barsize, ==, 256);
|
||||
s->mem_base = qpci_iomap(s->dev, 2, &barsize);
|
||||
g_assert_nonnull(s->mem_base);
|
||||
g_assert_cmpuint(barsize, ==, TMPSHMSIZE);
|
||||
|
||||
qpci_device_enable(s->dev);
|
||||
}
|
||||
|
||||
static void setup_vm(IVState *s)
|
||||
{
|
||||
char *cmd = g_strdup_printf("-device ivshmem,shm=%s,size=1M", tmpshm);
|
||||
char *cmd = g_strdup_printf("-object memory-backend-file"
|
||||
",id=mb1,size=1M,share,mem-path=/dev/shm%s"
|
||||
" -device ivshmem-plain,memdev=mb1", tmpshm);
|
||||
|
||||
setup_vm_cmd(s, cmd, false);
|
||||
|
||||
|
@ -144,32 +145,41 @@ static void test_ivshmem_single(void)
|
|||
setup_vm(&state);
|
||||
s = &state;
|
||||
|
||||
/* valid io */
|
||||
out_reg(s, INTRMASK, 0);
|
||||
in_reg(s, INTRSTATUS);
|
||||
in_reg(s, IVPOSITION);
|
||||
/* initial state of readable registers */
|
||||
g_assert_cmpuint(in_reg(s, INTRMASK), ==, 0);
|
||||
g_assert_cmpuint(in_reg(s, INTRSTATUS), ==, 0);
|
||||
g_assert_cmpuint(in_reg(s, IVPOSITION), ==, 0);
|
||||
|
||||
/* trigger interrupt via registers */
|
||||
out_reg(s, INTRMASK, 0xffffffff);
|
||||
g_assert_cmpuint(in_reg(s, INTRMASK), ==, 0xffffffff);
|
||||
out_reg(s, INTRSTATUS, 1);
|
||||
/* XXX: intercept IRQ, not seen in resp */
|
||||
/* check interrupt status */
|
||||
g_assert_cmpuint(in_reg(s, INTRSTATUS), ==, 1);
|
||||
/* reading clears */
|
||||
g_assert_cmpuint(in_reg(s, INTRSTATUS), ==, 0);
|
||||
/* TODO intercept actual interrupt (needs qtest work) */
|
||||
|
||||
/* invalid io */
|
||||
/* invalid register access */
|
||||
out_reg(s, IVPOSITION, 1);
|
||||
in_reg(s, DOORBELL);
|
||||
|
||||
/* ring the (non-functional) doorbell */
|
||||
out_reg(s, DOORBELL, 8 << 16);
|
||||
|
||||
/* write shared memory */
|
||||
for (i = 0; i < G_N_ELEMENTS(data); i++) {
|
||||
data[i] = i;
|
||||
}
|
||||
qtest_memwrite(s->qtest, (uintptr_t)s->mem_base, data, sizeof(data));
|
||||
|
||||
/* verify write */
|
||||
for (i = 0; i < G_N_ELEMENTS(data); i++) {
|
||||
g_assert_cmpuint(((uint32_t *)tmpshmem)[i], ==, i);
|
||||
}
|
||||
|
||||
/* read it back and verify read */
|
||||
memset(data, 0, sizeof(data));
|
||||
|
||||
qtest_memread(s->qtest, (uintptr_t)s->mem_base, data, sizeof(data));
|
||||
for (i = 0; i < G_N_ELEMENTS(data); i++) {
|
||||
g_assert_cmpuint(data[i], ==, i);
|
||||
|
@ -276,8 +286,10 @@ static void *server_thread(void *data)
|
|||
static void setup_vm_with_server(IVState *s, int nvectors, bool msi)
|
||||
{
|
||||
char *cmd = g_strdup_printf("-chardev socket,id=chr0,path=%s,nowait "
|
||||
"-device ivshmem,size=1M,chardev=chr0,vectors=%d,msi=%s",
|
||||
tmpserver, nvectors, msi ? "true" : "false");
|
||||
"-device ivshmem%s,chardev=chr0,vectors=%d",
|
||||
tmpserver,
|
||||
msi ? "-doorbell" : ",size=1M,msi=off",
|
||||
nvectors);
|
||||
|
||||
setup_vm_cmd(s, cmd, msi);
|
||||
|
||||
|
@ -293,8 +305,7 @@ static void test_ivshmem_server(bool msi)
|
|||
int nvectors = 2;
|
||||
guint64 end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;
|
||||
|
||||
memset(tmpshmem, 0x42, TMPSHMSIZE);
|
||||
ret = ivshmem_server_init(&server, tmpserver, tmpshm,
|
||||
ret = ivshmem_server_init(&server, tmpserver, tmpshm, true,
|
||||
TMPSHMSIZE, nvectors,
|
||||
g_test_verbose());
|
||||
g_assert_cmpint(ret, ==, 0);
|
||||
|
@ -302,49 +313,39 @@ static void test_ivshmem_server(bool msi)
|
|||
ret = ivshmem_server_start(&server);
|
||||
g_assert_cmpint(ret, ==, 0);
|
||||
|
||||
setup_vm_with_server(&state1, nvectors, msi);
|
||||
s1 = &state1;
|
||||
setup_vm_with_server(&state2, nvectors, msi);
|
||||
s2 = &state2;
|
||||
|
||||
g_assert_cmpuint(in_reg(s1, IVPOSITION), ==, 0xffffffff);
|
||||
g_assert_cmpuint(in_reg(s2, IVPOSITION), ==, 0xffffffff);
|
||||
|
||||
g_assert_cmpuint(qtest_readb(s1->qtest, (uintptr_t)s1->mem_base), ==, 0x00);
|
||||
|
||||
thread.server = &server;
|
||||
ret = pipe(thread.pipe);
|
||||
g_assert_cmpint(ret, ==, 0);
|
||||
thread.thread = g_thread_new("ivshmem-server", server_thread, &thread);
|
||||
g_assert(thread.thread != NULL);
|
||||
|
||||
/* waiting until mapping is done */
|
||||
while (g_get_monotonic_time() < end_time) {
|
||||
g_usleep(1000);
|
||||
|
||||
if (qtest_readb(s1->qtest, (uintptr_t)s1->mem_base) == 0x42 &&
|
||||
qtest_readb(s2->qtest, (uintptr_t)s2->mem_base) == 0x42) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
setup_vm_with_server(&state1, nvectors, msi);
|
||||
s1 = &state1;
|
||||
setup_vm_with_server(&state2, nvectors, msi);
|
||||
s2 = &state2;
|
||||
|
||||
/* check got different VM ids */
|
||||
vm1 = in_reg(s1, IVPOSITION);
|
||||
vm2 = in_reg(s2, IVPOSITION);
|
||||
g_assert_cmpuint(vm1, !=, vm2);
|
||||
g_assert_cmpint(vm1, >=, 0);
|
||||
g_assert_cmpint(vm2, >=, 0);
|
||||
g_assert_cmpint(vm1, !=, vm2);
|
||||
|
||||
/* check number of MSI-X vectors */
|
||||
global_qtest = s1->qtest;
|
||||
if (msi) {
|
||||
ret = qpci_msix_table_size(s1->dev);
|
||||
g_assert_cmpuint(ret, ==, nvectors);
|
||||
}
|
||||
|
||||
/* ping vm2 -> vm1 */
|
||||
/* TODO test behavior before MSI-X is enabled */
|
||||
|
||||
/* ping vm2 -> vm1 on vector 0 */
|
||||
if (msi) {
|
||||
ret = qpci_msix_pending(s1->dev, 0);
|
||||
g_assert_cmpuint(ret, ==, 0);
|
||||
} else {
|
||||
out_reg(s1, INTRSTATUS, 0);
|
||||
g_assert_cmpuint(in_reg(s1, INTRSTATUS), ==, 0);
|
||||
}
|
||||
out_reg(s2, DOORBELL, vm1 << 16);
|
||||
do {
|
||||
|
@ -353,18 +354,18 @@ static void test_ivshmem_server(bool msi)
|
|||
} while (ret == 0 && g_get_monotonic_time() < end_time);
|
||||
g_assert_cmpuint(ret, !=, 0);
|
||||
|
||||
/* ping vm1 -> vm2 */
|
||||
/* ping vm1 -> vm2 on vector 1 */
|
||||
global_qtest = s2->qtest;
|
||||
if (msi) {
|
||||
ret = qpci_msix_pending(s2->dev, 0);
|
||||
ret = qpci_msix_pending(s2->dev, 1);
|
||||
g_assert_cmpuint(ret, ==, 0);
|
||||
} else {
|
||||
out_reg(s2, INTRSTATUS, 0);
|
||||
g_assert_cmpuint(in_reg(s2, INTRSTATUS), ==, 0);
|
||||
}
|
||||
out_reg(s1, DOORBELL, vm2 << 16);
|
||||
out_reg(s1, DOORBELL, vm2 << 16 | 1);
|
||||
do {
|
||||
g_usleep(10000);
|
||||
ret = msi ? qpci_msix_pending(s2->dev, 0) : in_reg(s2, INTRSTATUS);
|
||||
ret = msi ? qpci_msix_pending(s2->dev, 1) : in_reg(s2, INTRSTATUS);
|
||||
} while (ret == 0 && g_get_monotonic_time() < end_time);
|
||||
g_assert_cmpuint(ret, !=, 0);
|
||||
|
||||
|
@ -415,7 +416,7 @@ static void test_ivshmem_memdev(void)
|
|||
|
||||
/* just for the sake of checking memory-backend property */
|
||||
setup_vm_cmd(&state, "-object memory-backend-ram,size=1M,id=mb1"
|
||||
" -device ivshmem,x-memdev=mb1", false);
|
||||
" -device ivshmem-plain,memdev=mb1", false);
|
||||
|
||||
cleanup_vm(&state);
|
||||
}
|
||||
|
|
|
@ -184,7 +184,9 @@ static void *qpci_pc_iomap(QPCIBus *bus, QPCIDevice *dev, int barno, uint64_t *s
|
|||
if (io_type == PCI_BASE_ADDRESS_SPACE_IO) {
|
||||
uint16_t loc;
|
||||
|
||||
g_assert((s->pci_iohole_alloc + size) <= s->pci_iohole_size);
|
||||
g_assert(QEMU_ALIGN_UP(s->pci_iohole_alloc, size) + size
|
||||
<= s->pci_iohole_size);
|
||||
s->pci_iohole_alloc = QEMU_ALIGN_UP(s->pci_iohole_alloc, size);
|
||||
loc = s->pci_iohole_start + s->pci_iohole_alloc;
|
||||
s->pci_iohole_alloc += size;
|
||||
|
||||
|
@ -194,7 +196,9 @@ static void *qpci_pc_iomap(QPCIBus *bus, QPCIDevice *dev, int barno, uint64_t *s
|
|||
} else {
|
||||
uint64_t loc;
|
||||
|
||||
g_assert((s->pci_hole_alloc + size) <= s->pci_hole_size);
|
||||
g_assert(QEMU_ALIGN_UP(s->pci_hole_alloc, size) + size
|
||||
<= s->pci_hole_size);
|
||||
s->pci_hole_alloc = QEMU_ALIGN_UP(s->pci_hole_alloc, size);
|
||||
loc = s->pci_hole_start + s->pci_hole_alloc;
|
||||
s->pci_hole_alloc += size;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue