Skip to content

Commit 5f58bde

Browse files
committed
s390/mm: provide simple ARCH_HAS_DEBUG_VIRTUAL support
Provide a very simple ARCH_HAS_DEBUG_VIRTUAL implementation. For now errors are only reported for the following cases: - Trying to translate a vmalloc or module address to a physical address - Translating a supposed to be ZONE_DMA virtual address into a physical address, and the resulting physical address is larger than two GiB Reviewed-by: Alexander Gordeev <[email protected]> Signed-off-by: Heiko Carstens <[email protected]>
1 parent bd36cfb commit 5f58bde

File tree

7 files changed

+48
-3
lines changed

7 files changed

+48
-3
lines changed

arch/s390/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ config S390
6363
select ARCH_ENABLE_MEMORY_HOTREMOVE
6464
select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2
6565
select ARCH_HAS_CURRENT_STACK_POINTER
66+
select ARCH_HAS_DEBUG_VIRTUAL
6667
select ARCH_HAS_DEBUG_VM_PGTABLE
6768
select ARCH_HAS_DEBUG_WX
6869
select ARCH_HAS_DEVMEM_IS_ALLOWED

arch/s390/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ KBUILD_AFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO),$(aflags_dwarf))
2929
endif
3030
KBUILD_CFLAGS_DECOMPRESSOR := $(CLANG_FLAGS) -m64 -O2 -mpacked-stack
3131
KBUILD_CFLAGS_DECOMPRESSOR += -DDISABLE_BRANCH_PROFILING -D__NO_FORTIFY
32+
KBUILD_CFLAGS_DECOMPRESSOR += -D__DECOMPRESSOR
3233
KBUILD_CFLAGS_DECOMPRESSOR += -fno-delete-null-pointer-checks -msoft-float -mbackchain
3334
KBUILD_CFLAGS_DECOMPRESSOR += -fno-asynchronous-unwind-tables
3435
KBUILD_CFLAGS_DECOMPRESSOR += -ffreestanding

arch/s390/configs/debug_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ CONFIG_DEBUG_OBJECTS_PERCPU_COUNTER=y
810810
CONFIG_DEBUG_STACK_USAGE=y
811811
CONFIG_DEBUG_VM=y
812812
CONFIG_DEBUG_VM_PGFLAGS=y
813+
CONFIG_DEBUG_VIRTUAL=y
813814
CONFIG_DEBUG_MEMORY_INIT=y
814815
CONFIG_MEMORY_NOTIFIER_ERROR_INJECT=m
815816
CONFIG_DEBUG_PER_CPU_MAPS=y

arch/s390/include/asm/dma-types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ typedef u64 __bitwise dma64_t;
3737
*/
3838
static inline dma32_t virt_to_dma32(void *ptr)
3939
{
40-
return (__force dma32_t)__pa(ptr);
40+
return (__force dma32_t)__pa32(ptr);
4141
}
4242

4343
static inline void *dma32_to_virt(dma32_t addr)

arch/s390/include/asm/page.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,35 @@ int arch_make_page_accessible(struct page *page);
181181
#define __PAGE_OFFSET 0x0UL
182182
#define PAGE_OFFSET 0x0UL
183183

184-
#define __pa(x) ((unsigned long)(x))
184+
#define __pa_nodebug(x) ((unsigned long)(x))
185+
186+
#ifdef __DECOMPRESSOR
187+
188+
#define __pa(x) __pa_nodebug(x)
189+
#define __pa32(x) __pa(x)
185190
#define __va(x) ((void *)(unsigned long)(x))
186191

192+
#else /* __DECOMPRESSOR */
193+
194+
#ifdef CONFIG_DEBUG_VIRTUAL
195+
196+
unsigned long __phys_addr(unsigned long x, bool is_31bit);
197+
198+
#else /* CONFIG_DEBUG_VIRTUAL */
199+
200+
static inline unsigned long __phys_addr(unsigned long x, bool is_31bit)
201+
{
202+
return __pa_nodebug(x);
203+
}
204+
205+
#endif /* CONFIG_DEBUG_VIRTUAL */
206+
207+
#define __pa(x) __phys_addr((unsigned long)(x), false)
208+
#define __pa32(x) __phys_addr((unsigned long)(x), true)
209+
#define __va(x) ((void *)(unsigned long)(x))
210+
211+
#endif /* __DECOMPRESSOR */
212+
187213
#define phys_to_pfn(phys) ((phys) >> PAGE_SHIFT)
188214
#define pfn_to_phys(pfn) ((pfn) << PAGE_SHIFT)
189215

@@ -205,7 +231,7 @@ static inline unsigned long virt_to_pfn(const void *kaddr)
205231
#define virt_to_page(kaddr) pfn_to_page(virt_to_pfn(kaddr))
206232
#define page_to_virt(page) pfn_to_virt(page_to_pfn(page))
207233

208-
#define virt_addr_valid(kaddr) pfn_valid(virt_to_pfn(kaddr))
234+
#define virt_addr_valid(kaddr) pfn_valid(phys_to_pfn(__pa_nodebug(kaddr)))
209235

210236
#define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_NON_EXEC
211237

arch/s390/mm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ obj-y := init.o fault.o extmem.o mmap.o vmem.o maccess.o
77
obj-y += page-states.o pageattr.o pgtable.o pgalloc.o extable.o
88

99
obj-$(CONFIG_CMM) += cmm.o
10+
obj-$(CONFIG_DEBUG_VIRTUAL) += physaddr.o
1011
obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
1112
obj-$(CONFIG_PTDUMP_CORE) += dump_pagetables.o
1213
obj-$(CONFIG_PGSTE) += gmap.o

arch/s390/mm/physaddr.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include <linux/mmdebug.h>
3+
#include <linux/export.h>
4+
#include <linux/mm.h>
5+
#include <asm/page.h>
6+
7+
unsigned long __phys_addr(unsigned long x, bool is_31bit)
8+
{
9+
VIRTUAL_BUG_ON(is_vmalloc_or_module_addr((void *)(x)));
10+
x = __pa_nodebug(x);
11+
if (is_31bit)
12+
VIRTUAL_BUG_ON(x >> 31);
13+
return x;
14+
}
15+
EXPORT_SYMBOL(__phys_addr);

0 commit comments

Comments
 (0)