Skip to content

Commit 06b4b71

Browse files
jasowangBrian Maly
authored andcommitted
virtio: allow driver to disable the configure change notification
Sometime, it would be useful to disable the configure change notification from the driver. So this patch allows this by introducing a variable config_change_driver_disabled and only allow the configure change notification callback to be triggered when it is allowed by both the virtio core and the driver. It is set to false by default to hold the current semantic so we don't need to change any drivers. The first user for this would be virtio-net. Cc: Venkat Venkatsubra <[email protected]> Cc: Gia-Khanh Nguyen <[email protected]> Acked-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Jason Wang <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> (cherry picked from commit 224de6f) Orabug: 36637822 Reviewed-by: Dongli Zhang <[email protected]> Signed-off-by: Venkat Venkatsubra <[email protected]> Signed-off-by: Brian Maly <[email protected]>
1 parent 0be0cca commit 06b4b71

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

drivers/virtio/virtio.c

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@ static void __virtio_config_changed(struct virtio_device *dev)
126126
{
127127
struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
128128

129-
if (!dev->config_core_enabled)
129+
if (!dev->config_core_enabled || dev->config_driver_disabled)
130130
dev->config_change_pending = true;
131-
else if (drv && drv->config_changed)
131+
else if (drv && drv->config_changed) {
132132
drv->config_changed(dev);
133+
dev->config_change_pending = false;
134+
}
133135
}
134136

135137
void virtio_config_changed(struct virtio_device *dev)
@@ -142,6 +144,38 @@ void virtio_config_changed(struct virtio_device *dev)
142144
}
143145
EXPORT_SYMBOL_GPL(virtio_config_changed);
144146

147+
/**
148+
* virtio_config_driver_disable - disable config change reporting by drivers
149+
* @dev: the device to reset
150+
*
151+
* This is only allowed to be called by a driver and disabling can't
152+
* be nested.
153+
*/
154+
void virtio_config_driver_disable(struct virtio_device *dev)
155+
{
156+
spin_lock_irq(&dev->config_lock);
157+
dev->config_driver_disabled = true;
158+
spin_unlock_irq(&dev->config_lock);
159+
}
160+
EXPORT_SYMBOL_GPL(virtio_config_driver_disable);
161+
162+
/**
163+
* virtio_config_driver_enable - enable config change reporting by drivers
164+
* @dev: the device to reset
165+
*
166+
* This is only allowed to be called by a driver and enabling can't
167+
* be nested.
168+
*/
169+
void virtio_config_driver_enable(struct virtio_device *dev)
170+
{
171+
spin_lock_irq(&dev->config_lock);
172+
dev->config_driver_disabled = false;
173+
if (dev->config_change_pending)
174+
__virtio_config_changed(dev);
175+
spin_unlock_irq(&dev->config_lock);
176+
}
177+
EXPORT_SYMBOL_GPL(virtio_config_driver_enable);
178+
145179
static void virtio_config_core_disable(struct virtio_device *dev)
146180
{
147181
spin_lock_irq(&dev->config_lock);
@@ -155,7 +189,6 @@ static void virtio_config_core_enable(struct virtio_device *dev)
155189
dev->config_core_enabled = true;
156190
if (dev->config_change_pending)
157191
__virtio_config_changed(dev);
158-
dev->config_change_pending = false;
159192
spin_unlock_irq(&dev->config_lock);
160193
}
161194

include/linux/virtio.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ dma_addr_t virtqueue_get_used_addr(struct virtqueue *vq);
9696
* @index: unique position on the virtio bus
9797
* @failed: saved value for VIRTIO_CONFIG_S_FAILED bit (for restore)
9898
* @config_core_enabled: configuration change reporting enabled by core
99+
* @config_driver_disabled: configuration change reporting disabled by
100+
* a driver
99101
* @config_change_pending: configuration change reported while disabled
100102
* @config_lock: protects configuration change reporting
101103
* @dev: underlying device.
@@ -110,6 +112,7 @@ struct virtio_device {
110112
int index;
111113
bool failed;
112114
bool config_core_enabled;
115+
bool config_driver_disabled;
113116
bool config_change_pending;
114117
spinlock_t config_lock;
115118
spinlock_t vqs_list_lock; /* Protects VQs list access */
@@ -135,6 +138,10 @@ bool is_virtio_device(struct device *dev);
135138
void virtio_break_device(struct virtio_device *dev);
136139

137140
void virtio_config_changed(struct virtio_device *dev);
141+
142+
void virtio_config_driver_disable(struct virtio_device *dev);
143+
void virtio_config_driver_enable(struct virtio_device *dev);
144+
138145
#ifdef CONFIG_PM_SLEEP
139146
int virtio_device_freeze(struct virtio_device *dev);
140147
int virtio_device_restore(struct virtio_device *dev);

0 commit comments

Comments
 (0)