Skip to content

Commit 97729b6

Browse files
Stefano Stabellinijgross1
authored andcommitted
xen/swiotlb: check if the swiotlb has already been initialized
xen_swiotlb_init calls swiotlb_late_init_with_tbl, which fails with -ENOMEM if the swiotlb has already been initialized. Add an explicit check io_tlb_default_mem != NULL at the beginning of xen_swiotlb_init. If the swiotlb is already initialized print a warning and return -EEXIST. On x86, the error propagates. On ARM, we don't actually need a special swiotlb buffer (yet), any buffer would do. So ignore the error and continue. CC: boris.ostrovsky@oracle.com CC: jgross@suse.com Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com> Reviewed-by: Boris Ostrovsky <boris.ostrvsky@oracle.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20210512201823.1963-3-sstabellini@kernel.org Signed-off-by: Juergen Gross <jgross@suse.com>
1 parent 687842e commit 97729b6

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

arch/arm/xen/mm.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,15 @@ void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order)
138138
static int __init xen_mm_init(void)
139139
{
140140
struct gnttab_cache_flush cflush;
141+
int rc;
142+
141143
if (!xen_swiotlb_detect())
142144
return 0;
143-
xen_swiotlb_init();
145+
146+
rc = xen_swiotlb_init();
147+
/* we can work with the default swiotlb */
148+
if (rc < 0 && rc != -EEXIST)
149+
return rc;
144150

145151
cflush.op = 0;
146152
cflush.a.dev_bus_addr = 0;

drivers/xen/swiotlb-xen.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ int __ref xen_swiotlb_init(void)
164164
int rc = -ENOMEM;
165165
char *start;
166166

167+
if (io_tlb_default_mem != NULL) {
168+
pr_warn("swiotlb buffer already initialized\n");
169+
return -EEXIST;
170+
}
171+
167172
retry:
168173
m_ret = XEN_SWIOTLB_ENOMEM;
169174
order = get_order(bytes);

0 commit comments

Comments
 (0)