Skip to content

Commit 8ba2ed1

Browse files
author
Christoph Hellwig
committed
swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction
Power SVM wants to allocate a swiotlb buffer that is not restricted to low memory for the trusted hypervisor scheme. Consolidate the support for this into the swiotlb_init interface by adding a new flag. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Konrad Rzeszutek Wilk <[email protected]> Tested-by: Boris Ostrovsky <[email protected]>
1 parent c6af2aa commit 8ba2ed1

File tree

7 files changed

+14
-35
lines changed

7 files changed

+14
-35
lines changed

arch/powerpc/include/asm/svm.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ static inline bool is_secure_guest(void)
1515
return mfmsr() & MSR_S;
1616
}
1717

18-
void __init svm_swiotlb_init(void);
19-
2018
void dtl_cache_ctor(void *addr);
2119
#define get_dtl_cache_ctor() (is_secure_guest() ? dtl_cache_ctor : NULL)
2220

@@ -27,8 +25,6 @@ static inline bool is_secure_guest(void)
2725
return false;
2826
}
2927

30-
static inline void svm_swiotlb_init(void) {}
31-
3228
#define get_dtl_cache_ctor() NULL
3329

3430
#endif /* CONFIG_PPC_SVM */

arch/powerpc/include/asm/swiotlb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/swiotlb.h>
1010

1111
extern unsigned int ppc_swiotlb_enable;
12+
extern unsigned int ppc_swiotlb_flags;
1213

1314
#ifdef CONFIG_SWIOTLB
1415
void swiotlb_detect_4g(void);

arch/powerpc/kernel/dma-swiotlb.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <asm/swiotlb.h>
1111

1212
unsigned int ppc_swiotlb_enable;
13+
unsigned int ppc_swiotlb_flags;
1314

1415
void __init swiotlb_detect_4g(void)
1516
{

arch/powerpc/mm/mem.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,7 @@ void __init mem_init(void)
249249
* back to to-down.
250250
*/
251251
memblock_set_bottom_up(true);
252-
if (is_secure_guest())
253-
svm_swiotlb_init();
254-
else
255-
swiotlb_init(ppc_swiotlb_enable, 0);
252+
swiotlb_init(ppc_swiotlb_enable, ppc_swiotlb_flags);
256253
#endif
257254

258255
high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);

arch/powerpc/platforms/pseries/svm.c

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static int __init init_svm(void)
2828
* need to use the SWIOTLB buffer for DMA even if dma_capable() says
2929
* otherwise.
3030
*/
31-
swiotlb_force = SWIOTLB_FORCE;
31+
ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;
3232

3333
/* Share the SWIOTLB buffer with the host. */
3434
swiotlb_update_mem_attributes();
@@ -37,30 +37,6 @@ static int __init init_svm(void)
3737
}
3838
machine_early_initcall(pseries, init_svm);
3939

40-
/*
41-
* Initialize SWIOTLB. Essentially the same as swiotlb_init(), except that it
42-
* can allocate the buffer anywhere in memory. Since the hypervisor doesn't have
43-
* any addressing limitation, we don't need to allocate it in low addresses.
44-
*/
45-
void __init svm_swiotlb_init(void)
46-
{
47-
unsigned char *vstart;
48-
unsigned long bytes, io_tlb_nslabs;
49-
50-
io_tlb_nslabs = (swiotlb_size_or_default() >> IO_TLB_SHIFT);
51-
io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
52-
53-
bytes = io_tlb_nslabs << IO_TLB_SHIFT;
54-
55-
vstart = memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE);
56-
if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, false))
57-
return;
58-
59-
60-
memblock_free(vstart, PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT));
61-
panic("SVM: Cannot allocate SWIOTLB buffer");
62-
}
63-
6440
int set_memory_encrypted(unsigned long addr, int numpages)
6541
{
6642
if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT))

include/linux/swiotlb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct scatterlist;
1515

1616
#define SWIOTLB_VERBOSE (1 << 0) /* verbose initialization */
1717
#define SWIOTLB_FORCE (1 << 1) /* force bounce buffering */
18+
#define SWIOTLB_ANY (1 << 2) /* allow any memory for the buffer */
1819

1920
/*
2021
* Maximum allowable number of contiguous slabs to map,

kernel/dma/swiotlb.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,15 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
266266
if (swiotlb_force_disable)
267267
return;
268268

269-
/* Get IO TLB memory from the low pages */
270-
tlb = memblock_alloc_low(bytes, PAGE_SIZE);
269+
/*
270+
* By default allocate the bounce buffer memory from low memory, but
271+
* allow to pick a location everywhere for hypervisors with guest
272+
* memory encryption.
273+
*/
274+
if (flags & SWIOTLB_ANY)
275+
tlb = memblock_alloc(bytes, PAGE_SIZE);
276+
else
277+
tlb = memblock_alloc_low(bytes, PAGE_SIZE);
271278
if (!tlb)
272279
goto fail;
273280
if (swiotlb_init_with_tbl(tlb, default_nslabs, flags))

0 commit comments

Comments
 (0)