Skip to content

Commit 6136768

Browse files
committed
xen/virtio: enable grant based virtio on x86
Use an x86-specific virtio_check_mem_acc_cb() for Xen in order to setup the correct DMA ops. Signed-off-by: Juergen Gross <[email protected]> Reviewed-by: Oleksandr Tyshchenko <[email protected]> # common code Reviewed-by: Boris Ostrovsky <[email protected]> Signed-off-by: Juergen Gross <[email protected]>
1 parent 7228113 commit 6136768

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

arch/x86/xen/enlighten_hvm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static void __init xen_hvm_guest_init(void)
212212
return;
213213

214214
if (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT))
215-
virtio_set_mem_acc_cb(virtio_require_restricted_mem_acc);
215+
virtio_set_mem_acc_cb(xen_virtio_restricted_mem_acc);
216216

217217
init_hvm_pv_info();
218218

arch/x86/xen/enlighten_pv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static void __init xen_pv_init_platform(void)
112112
{
113113
/* PV guests can't operate virtio devices without grants. */
114114
if (IS_ENABLED(CONFIG_XEN_VIRTIO))
115-
virtio_set_mem_acc_cb(virtio_require_restricted_mem_acc);
115+
virtio_set_mem_acc_cb(xen_virtio_restricted_mem_acc);
116116

117117
populate_extra_pte(fix_to_virt(FIX_PARAVIRT_BOOTMAP));
118118

drivers/xen/grant-dma-ops.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ bool xen_is_grant_dma_device(struct device *dev)
313313

314314
bool xen_virtio_mem_acc(struct virtio_device *dev)
315315
{
316-
if (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT))
316+
if (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT) || xen_pv_domain())
317317
return true;
318318

319319
return xen_is_grant_dma_device(dev->dev.parent);
@@ -387,6 +387,16 @@ void xen_grant_setup_dma_ops(struct device *dev)
387387
dev_err(dev, "Cannot set up Xen grant DMA ops, retain platform DMA ops\n");
388388
}
389389

390+
bool xen_virtio_restricted_mem_acc(struct virtio_device *dev)
391+
{
392+
bool ret = xen_virtio_mem_acc(dev);
393+
394+
if (ret)
395+
xen_grant_setup_dma_ops(dev->dev.parent);
396+
397+
return ret;
398+
}
399+
390400
MODULE_DESCRIPTION("Xen grant DMA-mapping layer");
391401
MODULE_AUTHOR("Juergen Gross <[email protected]>");
392402
MODULE_LICENSE("GPL");

include/xen/xen-ops.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ static inline void xen_preemptible_hcall_end(void) { }
219219
void xen_grant_setup_dma_ops(struct device *dev);
220220
bool xen_is_grant_dma_device(struct device *dev);
221221
bool xen_virtio_mem_acc(struct virtio_device *dev);
222+
bool xen_virtio_restricted_mem_acc(struct virtio_device *dev);
222223
#else
223224
static inline void xen_grant_setup_dma_ops(struct device *dev)
224225
{
@@ -234,6 +235,11 @@ static inline bool xen_virtio_mem_acc(struct virtio_device *dev)
234235
{
235236
return false;
236237
}
238+
239+
static inline bool xen_virtio_restricted_mem_acc(struct virtio_device *dev)
240+
{
241+
return false;
242+
}
237243
#endif /* CONFIG_XEN_GRANT_DMA_OPS */
238244

239245
#endif /* INCLUDE_XEN_OPS_H */

0 commit comments

Comments
 (0)