Skip to content

Commit 00a5c58

Browse files
aikmpe
authored andcommitted
KVM: PPC: Make iommu_table::it_userspace big endian
We are going to reuse multilevel TCE code for the userspace copy of the TCE table and since it is big endian, let's make the copy big endian too. Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> Acked-by: Paul Mackerras <paulus@ozlabs.org> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 191c228 commit 00a5c58

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

arch/powerpc/include/asm/iommu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ struct iommu_table {
117117
unsigned long *it_map; /* A simple allocation bitmap for now */
118118
unsigned long it_page_shift;/* table iommu page size */
119119
struct list_head it_group_list;/* List of iommu_table_group_link */
120-
unsigned long *it_userspace; /* userspace view of the table */
120+
__be64 *it_userspace; /* userspace view of the table */
121121
struct iommu_table_ops *it_ops;
122122
struct kref it_kref;
123123
};

arch/powerpc/kvm/book3s_64_vio.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,19 +378,19 @@ static long kvmppc_tce_iommu_mapped_dec(struct kvm *kvm,
378378
{
379379
struct mm_iommu_table_group_mem_t *mem = NULL;
380380
const unsigned long pgsize = 1ULL << tbl->it_page_shift;
381-
unsigned long *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl, entry);
381+
__be64 *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl, entry);
382382

383383
if (!pua)
384384
/* it_userspace allocation might be delayed */
385385
return H_TOO_HARD;
386386

387-
mem = mm_iommu_lookup(kvm->mm, *pua, pgsize);
387+
mem = mm_iommu_lookup(kvm->mm, be64_to_cpu(*pua), pgsize);
388388
if (!mem)
389389
return H_TOO_HARD;
390390

391391
mm_iommu_mapped_dec(mem);
392392

393-
*pua = 0;
393+
*pua = cpu_to_be64(0);
394394

395395
return H_SUCCESS;
396396
}
@@ -437,7 +437,8 @@ long kvmppc_tce_iommu_do_map(struct kvm *kvm, struct iommu_table *tbl,
437437
enum dma_data_direction dir)
438438
{
439439
long ret;
440-
unsigned long hpa, *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl, entry);
440+
unsigned long hpa;
441+
__be64 *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl, entry);
441442
struct mm_iommu_table_group_mem_t *mem;
442443

443444
if (!pua)
@@ -464,7 +465,7 @@ long kvmppc_tce_iommu_do_map(struct kvm *kvm, struct iommu_table *tbl,
464465
if (dir != DMA_NONE)
465466
kvmppc_tce_iommu_mapped_dec(kvm, tbl, entry);
466467

467-
*pua = ua;
468+
*pua = cpu_to_be64(ua);
468469

469470
return 0;
470471
}

arch/powerpc/kvm/book3s_64_vio_hv.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static long kvmppc_rm_tce_iommu_mapped_dec(struct kvm *kvm,
200200
{
201201
struct mm_iommu_table_group_mem_t *mem = NULL;
202202
const unsigned long pgsize = 1ULL << tbl->it_page_shift;
203-
unsigned long *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl, entry);
203+
__be64 *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl, entry);
204204

205205
if (!pua)
206206
/* it_userspace allocation might be delayed */
@@ -210,13 +210,13 @@ static long kvmppc_rm_tce_iommu_mapped_dec(struct kvm *kvm,
210210
if (WARN_ON_ONCE_RM(!pua))
211211
return H_HARDWARE;
212212

213-
mem = mm_iommu_lookup_rm(kvm->mm, *pua, pgsize);
213+
mem = mm_iommu_lookup_rm(kvm->mm, be64_to_cpu(*pua), pgsize);
214214
if (!mem)
215215
return H_TOO_HARD;
216216

217217
mm_iommu_mapped_dec(mem);
218218

219-
*pua = 0;
219+
*pua = cpu_to_be64(0);
220220

221221
return H_SUCCESS;
222222
}
@@ -268,7 +268,7 @@ static long kvmppc_rm_tce_iommu_do_map(struct kvm *kvm, struct iommu_table *tbl,
268268
{
269269
long ret;
270270
unsigned long hpa = 0;
271-
unsigned long *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl, entry);
271+
__be64 *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl, entry);
272272
struct mm_iommu_table_group_mem_t *mem;
273273

274274
if (!pua)
@@ -302,7 +302,7 @@ static long kvmppc_rm_tce_iommu_do_map(struct kvm *kvm, struct iommu_table *tbl,
302302
if (dir != DMA_NONE)
303303
kvmppc_rm_tce_iommu_mapped_dec(kvm, tbl, entry);
304304

305-
*pua = ua;
305+
*pua = cpu_to_be64(ua);
306306

307307
return 0;
308308
}

drivers/vfio/vfio_iommu_spapr_tce.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static long tce_iommu_userspace_view_alloc(struct iommu_table *tbl,
230230
decrement_locked_vm(mm, cb >> PAGE_SHIFT);
231231
return -ENOMEM;
232232
}
233-
tbl->it_userspace = uas;
233+
tbl->it_userspace = (__be64 *) uas;
234234

235235
return 0;
236236
}
@@ -482,20 +482,20 @@ static void tce_iommu_unuse_page_v2(struct tce_container *container,
482482
struct mm_iommu_table_group_mem_t *mem = NULL;
483483
int ret;
484484
unsigned long hpa = 0;
485-
unsigned long *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl, entry);
485+
__be64 *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl, entry);
486486

487487
if (!pua)
488488
return;
489489

490-
ret = tce_iommu_prereg_ua_to_hpa(container, *pua, IOMMU_PAGE_SIZE(tbl),
491-
&hpa, &mem);
490+
ret = tce_iommu_prereg_ua_to_hpa(container, be64_to_cpu(*pua),
491+
IOMMU_PAGE_SIZE(tbl), &hpa, &mem);
492492
if (ret)
493-
pr_debug("%s: tce %lx at #%lx was not cached, ret=%d\n",
494-
__func__, *pua, entry, ret);
493+
pr_debug("%s: tce %llx at #%lx was not cached, ret=%d\n",
494+
__func__, be64_to_cpu(*pua), entry, ret);
495495
if (mem)
496496
mm_iommu_mapped_dec(mem);
497497

498-
*pua = 0;
498+
*pua = cpu_to_be64(0);
499499
}
500500

501501
static int tce_iommu_clear(struct tce_container *container,
@@ -607,8 +607,7 @@ static long tce_iommu_build_v2(struct tce_container *container,
607607

608608
for (i = 0; i < pages; ++i) {
609609
struct mm_iommu_table_group_mem_t *mem = NULL;
610-
unsigned long *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl,
611-
entry + i);
610+
__be64 *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl, entry + i);
612611

613612
ret = tce_iommu_prereg_ua_to_hpa(container,
614613
tce, IOMMU_PAGE_SIZE(tbl), &hpa, &mem);
@@ -642,7 +641,7 @@ static long tce_iommu_build_v2(struct tce_container *container,
642641
if (dirtmp != DMA_NONE)
643642
tce_iommu_unuse_page_v2(container, tbl, entry + i);
644643

645-
*pua = tce;
644+
*pua = cpu_to_be64(tce);
646645

647646
tce += IOMMU_PAGE_SIZE(tbl);
648647
}

0 commit comments

Comments
 (0)