Skip to content

Commit 810d237

Browse files
bauermanngregkh
authored andcommitted
powerpc/pseries/svm: Allocate SWIOTLB buffer anywhere in memory
[ Upstream commit eae9eec ] POWER secure guests (i.e., guests which use the Protected Execution Facility) need to use SWIOTLB to be able to do I/O with the hypervisor, but they don't need the SWIOTLB memory to be in low addresses since the hypervisor doesn't have any addressing limitation. This solves a SWIOTLB initialization problem we are seeing in secure guests with 128 GB of RAM: they are configured with 4 GB of crashkernel reserved memory, which leaves no space for SWIOTLB in low addresses. To do this, we use mostly the same code as swiotlb_init(), but allocate the buffer using memblock_alloc() instead of memblock_alloc_low(). Fixes: 2efbc58 ("powerpc/pseries/svm: Force SWIOTLB for secure guests") Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20200818221126.391073-1-bauerman@linux.ibm.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent d9fbd90 commit 810d237

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

arch/powerpc/include/asm/svm.h

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

18+
void __init svm_swiotlb_init(void);
19+
1820
void dtl_cache_ctor(void *addr);
1921
#define get_dtl_cache_ctor() (is_secure_guest() ? dtl_cache_ctor : NULL)
2022

@@ -25,6 +27,8 @@ static inline bool is_secure_guest(void)
2527
return false;
2628
}
2729

30+
static inline void svm_swiotlb_init(void) {}
31+
2832
#define get_dtl_cache_ctor() NULL
2933

3034
#endif /* CONFIG_PPC_SVM */

arch/powerpc/mm/mem.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <asm/swiotlb.h>
5050
#include <asm/rtas.h>
5151
#include <asm/kasan.h>
52+
#include <asm/svm.h>
5253

5354
#include <mm/mmu_decl.h>
5455

@@ -282,7 +283,10 @@ void __init mem_init(void)
282283
* back to to-down.
283284
*/
284285
memblock_set_bottom_up(true);
285-
swiotlb_init(0);
286+
if (is_secure_guest())
287+
svm_swiotlb_init();
288+
else
289+
swiotlb_init(0);
286290
#endif
287291

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

arch/powerpc/platforms/pseries/svm.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include <linux/mm.h>
10+
#include <linux/memblock.h>
1011
#include <asm/machdep.h>
1112
#include <asm/svm.h>
1213
#include <asm/swiotlb.h>
@@ -35,6 +36,31 @@ static int __init init_svm(void)
3536
}
3637
machine_early_initcall(pseries, init_svm);
3738

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

0 commit comments

Comments
 (0)