Skip to content

Commit 224de6f

Browse files
jasowangkuba-moo
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]>
1 parent 0cb70ee commit 224de6f

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
@@ -127,10 +127,12 @@ static void __virtio_config_changed(struct virtio_device *dev)
127127
{
128128
struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
129129

130-
if (!dev->config_core_enabled)
130+
if (!dev->config_core_enabled || dev->config_driver_disabled)
131131
dev->config_change_pending = true;
132-
else if (drv && drv->config_changed)
132+
else if (drv && drv->config_changed) {
133133
drv->config_changed(dev);
134+
dev->config_change_pending = false;
135+
}
134136
}
135137

136138
void virtio_config_changed(struct virtio_device *dev)
@@ -143,6 +145,38 @@ void virtio_config_changed(struct virtio_device *dev)
143145
}
144146
EXPORT_SYMBOL_GPL(virtio_config_changed);
145147

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

include/linux/virtio.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ struct virtio_admin_cmd {
119119
* @index: unique position on the virtio bus
120120
* @failed: saved value for VIRTIO_CONFIG_S_FAILED bit (for restore)
121121
* @config_core_enabled: configuration change reporting enabled by core
122+
* @config_driver_disabled: configuration change reporting disabled by
123+
* a driver
122124
* @config_change_pending: configuration change reported while disabled
123125
* @config_lock: protects configuration change reporting
124126
* @vqs_list_lock: protects @vqs.
@@ -136,6 +138,7 @@ struct virtio_device {
136138
int index;
137139
bool failed;
138140
bool config_core_enabled;
141+
bool config_driver_disabled;
139142
bool config_change_pending;
140143
spinlock_t config_lock;
141144
spinlock_t vqs_list_lock;
@@ -166,6 +169,10 @@ void __virtqueue_break(struct virtqueue *_vq);
166169
void __virtqueue_unbreak(struct virtqueue *_vq);
167170

168171
void virtio_config_changed(struct virtio_device *dev);
172+
173+
void virtio_config_driver_disable(struct virtio_device *dev);
174+
void virtio_config_driver_enable(struct virtio_device *dev);
175+
169176
#ifdef CONFIG_PM_SLEEP
170177
int virtio_device_freeze(struct virtio_device *dev);
171178
int virtio_device_restore(struct virtio_device *dev);

0 commit comments

Comments
 (0)