Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.

Commit 8236c07

Browse files
author
Yuanyuan Zhao
committed
vos: add BE and FE status synchronization
Add udm synchronization between BE and FE. 1. Add handshake. When the VM which UDM run in shutdown and BE do not have change to notify FE, running FE can know the BE status change by check handshake mask. The handshake mask lays in virtio header in share memory BAR. It is checked every 2 seconds. 2. Add event interrupt. When the backend application exits normally or the VM where the backend resides is shut down normally, BE can trigger a interrupt, and notify FE the event. 3. Create /dev/virtio_shmemX which set auto or manual unresigter virtio device by 'VIRTIO_SHMEM_IOCTL_AUTO_REMOVE'. In this state, APP in user space can unregister the device by 'VIRTIO_SHMEM_IOCTL_UNREGISTER'. Signed-off-by: Yuanyuan Zhao <yuanyuan.zhao@intel.com>
1 parent d1d157b commit 8236c07

4 files changed

Lines changed: 430 additions & 74 deletions

File tree

drivers/virtio/virtio_guest_shm.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,12 @@ static int virtio_ivshmem_probe(struct pci_dev *pci_dev,
130130
vi_dev->notify_peer = virtio_guest_shm_notify_peer;
131131
vi_dev->early_irq_handler = virtio_guest_shm_early_irq_handler;
132132
vi_dev->priv = vi_data;
133+
vi_dev->virtio_registered = false;
133134

134135
ret = virtio_shmem_probe(vi_dev);
135136
if (ret)
136137
goto err_enable;
137138

138-
ret = register_virtio_device(&vi_dev->vdev);
139-
if (ret) {
140-
dev_err(&pci_dev->dev, "failed to register device\n");
141-
put_device(&vi_dev->vdev.dev);
142-
goto err_enable;
143-
}
144-
145139
#ifdef CONFIG_VIRTIO_IVSHMEM_DEBUG
146140
vi_dev->shmem_sz_used = (vi_dev->virtio_header->size
147141
+ (chunk_size - 1)) & ~(chunk_size - 1);
@@ -166,7 +160,7 @@ static void virtio_ivshmem_remove(struct pci_dev *pci_dev)
166160
struct virtio_shmem_device *vi_dev = pci_get_drvdata(pci_dev);
167161
struct device *dev = get_device(&vi_dev->vdev.dev);
168162

169-
unregister_virtio_device(&vi_dev->vdev);
163+
virtio_shmem_remove(vi_dev);
170164
pci_disable_device(pci_dev);
171165
put_device(dev);
172166
kfree(vi_dev);

drivers/virtio/virtio_ivshmem.c

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,6 @@ static void virtio_ivshmem_notify_peer(struct virtio_shmem_device *vi_dev, unsig
3434
writel((vi_dev->peer_id << 16), &vi_data->ivshm_regs->doorbell);
3535
}
3636

37-
static int virito_ivshmem_check_virtio_supports(struct pci_dev *pdev)
38-
{
39-
unsigned long bar_start, bar_len;
40-
void __iomem *bar_addr;
41-
int vendor, err = -1;
42-
43-
bar_start = pci_resource_start(pdev, 2);
44-
bar_len = pci_resource_len(pdev, 2);
45-
if (bar_start && bar_len) {
46-
if (pci_resource_flags(pdev, 2) & IORESOURCE_MEM) {
47-
bar_addr = pci_iomap(pdev, 2, bar_len);
48-
if (!bar_addr) {
49-
dev_err(&pdev->dev, "Could not map memory BAR #%d\n", 2);
50-
return -1;
51-
}
52-
vendor = readw(bar_addr + IVSHMEM_VENDOR_OFFSET);
53-
if (vendor == PCI_VENDOR_ID_REDHAT_QUMRANET)
54-
err = 0;
55-
pci_iounmap(pdev, bar_addr);
56-
}
57-
}
58-
return err;
59-
}
60-
6137
static int virtio_ivshmem_probe(struct pci_dev *pci_dev,
6238
const struct pci_device_id *pci_id)
6339
{
@@ -95,12 +71,6 @@ static int virtio_ivshmem_probe(struct pci_dev *pci_dev,
9571

9672
vi_dev->this_id = readl(&vi_data->ivshm_regs->ivpos);
9773

98-
ret = virito_ivshmem_check_virtio_supports(pci_dev);
99-
if (ret != 0) {
100-
dev_err(&pci_dev->dev, "not a virtio device\n");
101-
goto err_enable;
102-
}
103-
10474
section_sz = pci_resource_len(pci_dev, 2);
10575
if (section_sz == 0) {
10676
dev_err(&pci_dev->dev, "missing shared memory\n");
@@ -118,18 +88,12 @@ static int virtio_ivshmem_probe(struct pci_dev *pci_dev,
11888
vi_dev->shmem_sz = section_sz;
11989
vi_dev->notify_peer = virtio_ivshmem_notify_peer;
12090
vi_dev->priv = vi_data;
91+
vi_dev->virtio_registered = false;
12192

12293
ret = virtio_shmem_probe(vi_dev);
12394
if (ret)
12495
goto err_enable;
12596

126-
ret = register_virtio_device(&vi_dev->vdev);
127-
if (ret) {
128-
dev_err(&pci_dev->dev, "failed to register device\n");
129-
put_device(&vi_dev->vdev.dev);
130-
goto err_enable;
131-
}
132-
13397
#ifdef CONFIG_VIRTIO_IVSHMEM_DEBUG
13498
vi_dev->shmem_sz_used = (vi_dev->virtio_header->size + (chunk_size - 1))
13599
& ~(chunk_size - 1);
@@ -154,7 +118,7 @@ static void virtio_ivshmem_remove(struct pci_dev *pci_dev)
154118
struct virtio_shmem_device *vi_dev = pci_get_drvdata(pci_dev);
155119
struct device *dev = get_device(&vi_dev->vdev.dev);
156120

157-
unregister_virtio_device(&vi_dev->vdev);
121+
virtio_shmem_remove(vi_dev);
158122
pci_disable_device(pci_dev);
159123
put_device(dev);
160124
kfree(vi_dev);

0 commit comments

Comments
 (0)