Skip to content

Commit a540aa5

Browse files
aikmpe
authored andcommitted
powerpc/powernv/iommu: Add real mode version of iommu_table_ops::exchange()
In real mode, TCE tables are invalidated using special cache-inhibited store instructions which are not available in virtual mode This defines and implements exchange_rm() callback. This does not define set_rm/clear_rm/flush_rm callbacks as there is no user for those - exchange/exchange_rm are only to be used by KVM for VFIO. The exchange_rm callback is defined for IODA1/IODA2 powernv platforms. This replaces list_for_each_entry_rcu with its lockless version as from now on pnv_pci_ioda2_tce_invalidate() can be called in the real mode too. Signed-off-by: Alexey Kardashevskiy <[email protected]> Reviewed-by: David Gibson <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 6b5c19c commit a540aa5

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

arch/powerpc/include/asm/iommu.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ struct iommu_table_ops {
6464
long index,
6565
unsigned long *hpa,
6666
enum dma_data_direction *direction);
67+
/* Real mode */
68+
int (*exchange_rm)(struct iommu_table *tbl,
69+
long index,
70+
unsigned long *hpa,
71+
enum dma_data_direction *direction);
6772
#endif
6873
void (*clear)(struct iommu_table *tbl,
6974
long index, long npages);
@@ -208,6 +213,8 @@ extern void iommu_del_device(struct device *dev);
208213
extern int __init tce_iommu_bus_notifier_init(void);
209214
extern long iommu_tce_xchg(struct iommu_table *tbl, unsigned long entry,
210215
unsigned long *hpa, enum dma_data_direction *direction);
216+
extern long iommu_tce_xchg_rm(struct iommu_table *tbl, unsigned long entry,
217+
unsigned long *hpa, enum dma_data_direction *direction);
211218
#else
212219
static inline void iommu_register_group(struct iommu_table_group *table_group,
213220
int pci_domain_number,

arch/powerpc/kernel/iommu.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,31 @@ long iommu_tce_xchg(struct iommu_table *tbl, unsigned long entry,
10041004
}
10051005
EXPORT_SYMBOL_GPL(iommu_tce_xchg);
10061006

1007+
#ifdef CONFIG_PPC_BOOK3S_64
1008+
long iommu_tce_xchg_rm(struct iommu_table *tbl, unsigned long entry,
1009+
unsigned long *hpa, enum dma_data_direction *direction)
1010+
{
1011+
long ret;
1012+
1013+
ret = tbl->it_ops->exchange_rm(tbl, entry, hpa, direction);
1014+
1015+
if (!ret && ((*direction == DMA_FROM_DEVICE) ||
1016+
(*direction == DMA_BIDIRECTIONAL))) {
1017+
struct page *pg = realmode_pfn_to_page(*hpa >> PAGE_SHIFT);
1018+
1019+
if (likely(pg)) {
1020+
SetPageDirty(pg);
1021+
} else {
1022+
tbl->it_ops->exchange_rm(tbl, entry, hpa, direction);
1023+
ret = -EFAULT;
1024+
}
1025+
}
1026+
1027+
return ret;
1028+
}
1029+
EXPORT_SYMBOL_GPL(iommu_tce_xchg_rm);
1030+
#endif
1031+
10071032
int iommu_take_ownership(struct iommu_table *tbl)
10081033
{
10091034
unsigned long flags, i, sz = (tbl->it_size + 7) >> 3;

arch/powerpc/platforms/powernv/pci-ioda.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,17 @@ static int pnv_ioda1_tce_xchg(struct iommu_table *tbl, long index,
18601860

18611861
return ret;
18621862
}
1863+
1864+
static int pnv_ioda1_tce_xchg_rm(struct iommu_table *tbl, long index,
1865+
unsigned long *hpa, enum dma_data_direction *direction)
1866+
{
1867+
long ret = pnv_tce_xchg(tbl, index, hpa, direction);
1868+
1869+
if (!ret)
1870+
pnv_pci_p7ioc_tce_invalidate(tbl, index, 1, true);
1871+
1872+
return ret;
1873+
}
18631874
#endif
18641875

18651876
static void pnv_ioda1_tce_free(struct iommu_table *tbl, long index,
@@ -1874,6 +1885,7 @@ static struct iommu_table_ops pnv_ioda1_iommu_ops = {
18741885
.set = pnv_ioda1_tce_build,
18751886
#ifdef CONFIG_IOMMU_API
18761887
.exchange = pnv_ioda1_tce_xchg,
1888+
.exchange_rm = pnv_ioda1_tce_xchg_rm,
18771889
#endif
18781890
.clear = pnv_ioda1_tce_free,
18791891
.get = pnv_tce_get,
@@ -1948,7 +1960,7 @@ static void pnv_pci_ioda2_tce_invalidate(struct iommu_table *tbl,
19481960
{
19491961
struct iommu_table_group_link *tgl;
19501962

1951-
list_for_each_entry_rcu(tgl, &tbl->it_group_list, next) {
1963+
list_for_each_entry_lockless(tgl, &tbl->it_group_list, next) {
19521964
struct pnv_ioda_pe *pe = container_of(tgl->table_group,
19531965
struct pnv_ioda_pe, table_group);
19541966
struct pnv_phb *phb = pe->phb;
@@ -2004,6 +2016,17 @@ static int pnv_ioda2_tce_xchg(struct iommu_table *tbl, long index,
20042016

20052017
return ret;
20062018
}
2019+
2020+
static int pnv_ioda2_tce_xchg_rm(struct iommu_table *tbl, long index,
2021+
unsigned long *hpa, enum dma_data_direction *direction)
2022+
{
2023+
long ret = pnv_tce_xchg(tbl, index, hpa, direction);
2024+
2025+
if (!ret)
2026+
pnv_pci_ioda2_tce_invalidate(tbl, index, 1, true);
2027+
2028+
return ret;
2029+
}
20072030
#endif
20082031

20092032
static void pnv_ioda2_tce_free(struct iommu_table *tbl, long index,
@@ -2024,6 +2047,7 @@ static struct iommu_table_ops pnv_ioda2_iommu_ops = {
20242047
.set = pnv_ioda2_tce_build,
20252048
#ifdef CONFIG_IOMMU_API
20262049
.exchange = pnv_ioda2_tce_xchg,
2050+
.exchange_rm = pnv_ioda2_tce_xchg_rm,
20272051
#endif
20282052
.clear = pnv_ioda2_tce_free,
20292053
.get = pnv_tce_get,

0 commit comments

Comments
 (0)