1
0
Fork 0
alistair23-linux/arch/riscv/include/asm
Arnd Bergmann 1bef5f25a6 arch: pgtable: define MAX_POSSIBLE_PHYSMEM_BITS where needed
[ Upstream commit cef3970381 ]

Stefan Agner reported a bug when using zsram on 32-bit Arm machines
with RAM above the 4GB address boundary:

  Unable to handle kernel NULL pointer dereference at virtual address 00000000
  pgd = a27bd01c
  [00000000] *pgd=236a0003, *pmd=1ffa64003
  Internal error: Oops: 207 [#1] SMP ARM
  Modules linked in: mdio_bcm_unimac(+) brcmfmac cfg80211 brcmutil raspberrypi_hwmon hci_uart crc32_arm_ce bcm2711_thermal phy_generic genet
  CPU: 0 PID: 123 Comm: mkfs.ext4 Not tainted 5.9.6 #1
  Hardware name: BCM2711
  PC is at zs_map_object+0x94/0x338
  LR is at zram_bvec_rw.constprop.0+0x330/0xa64
  pc : [<c0602b38>]    lr : [<c0bda6a0>]    psr: 60000013
  sp : e376bbe0  ip : 00000000  fp : c1e2921c
  r10: 00000002  r9 : c1dda730  r8 : 00000000
  r7 : e8ff7a00  r6 : 00000000  r5 : 02f9ffa0  r4 : e3710000
  r3 : 000fdffe  r2 : c1e0ce80  r1 : ebf979a0  r0 : 00000000
  Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
  Control: 30c5383d  Table: 235c2a80  DAC: fffffffd
  Process mkfs.ext4 (pid: 123, stack limit = 0x495a22e6)
  Stack: (0xe376bbe0 to 0xe376c000)

As it turns out, zsram needs to know the maximum memory size, which
is defined in MAX_PHYSMEM_BITS when CONFIG_SPARSEMEM is set, or in
MAX_POSSIBLE_PHYSMEM_BITS on the x86 architecture.

The same problem will be hit on all 32-bit architectures that have a
physical address space larger than 4GB and happen to not enable sparsemem
and include asm/sparsemem.h from asm/pgtable.h.

After the initial discussion, I suggested just always defining
MAX_POSSIBLE_PHYSMEM_BITS whenever CONFIG_PHYS_ADDR_T_64BIT is
set, or provoking a build error otherwise. This addresses all
configurations that can currently have this runtime bug, but
leaves all other configurations unchanged.

I looked up the possible number of bits in source code and
datasheets, here is what I found:

 - on ARC, CONFIG_ARC_HAS_PAE40 controls whether 32 or 40 bits are used
 - on ARM, CONFIG_LPAE enables 40 bit addressing, without it we never
   support more than 32 bits, even though supersections in theory allow
   up to 40 bits as well.
 - on MIPS, some MIPS32r1 or later chips support 36 bits, and MIPS32r5
   XPA supports up to 60 bits in theory, but 40 bits are more than
   anyone will ever ship
 - On PowerPC, there are three different implementations of 36 bit
   addressing, but 32-bit is used without CONFIG_PTE_64BIT
 - On RISC-V, the normal page table format can support 34 bit
   addressing. There is no highmem support on RISC-V, so anything
   above 2GB is unused, but it might be useful to eventually support
   CONFIG_ZRAM for high pages.

Fixes: 61989a80fb ("staging: zsmalloc: zsmalloc memory allocation library")
Fixes: 02390b87a9 ("mm/zsmalloc: Prepare to variable MAX_PHYSMEM_BITS")
Acked-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Reviewed-by: Stefan Agner <stefan@agner.ch>
Tested-by: Stefan Agner <stefan@agner.ch>
Acked-by: Mike Rapoport <rppt@linux.ibm.com>
Link: https://lore.kernel.org/linux-mm/bdfa44bf1c570b05d6c70898e2bbb0acf234ecdf.1604762181.git.stefan@agner.ch/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-12-02 08:49:50 +01:00
..
Kbuild riscv: include generic support for MSI irqdomains 2019-07-22 13:06:07 -07:00
asm-offsets.h
asm-prototypes.h RISC-V: include linux/ftrace.h in asm-prototypes.h 2018-09-24 13:12:27 -07:00
asm.h RISC-V: Clear load reservations while restoring hart contexts 2019-10-01 13:16:40 -07:00
atomic.h locking/atomic, riscv: Use s64 for atomic64 2019-06-03 12:32:56 +02:00
barrier.h RISC-V: Upgrade smp_mb__after_spinlock() to iorw,iorw 2020-07-29 10:18:40 +02:00
bitops.h RISC-V patches for v5.2-rc6 2019-06-17 10:34:03 -07:00
bug.h riscv: cleanup <asm/bug.h> 2019-10-23 14:53:46 -07:00
cache.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
cacheflush.h riscv: fix build break after macro-to-function conversion in generic cacheflush.h 2019-07-18 08:16:56 -07:00
cmpxchg.h riscv/atomic: Fix sign extension for RV64I 2020-06-30 15:37:03 -04:00
csr.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
current.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
delay.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
elf.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
fence.h riscv/spinlock: Strengthen implementations with fences 2018-04-02 19:59:43 -07:00
fixmap.h RISC-V: Fix FIXMAP area corruption on RV32 systems 2019-08-28 15:30:12 -07:00
ftrace.h RISC-V: Take text_mutex in ftrace_init_nop() 2020-10-01 13:18:14 +02:00
futex.h riscv: remove CONFIG_RISCV_ISA_A 2019-04-25 14:51:10 -07:00
hugetlb.h riscv: Introduce huge page support for 32/64bit kernel 2019-07-03 15:23:38 -07:00
hwcap.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 234 2019-06-19 17:09:07 +02:00
image.h riscv: modify the Image header to improve compatibility with the ARM64 header 2019-09-13 19:03:52 -07:00
io.h RISC-V: Add PCIe I/O BAR memory mapping 2019-10-28 10:43:32 -07:00
irq.h riscv: add missing header file includes 2019-10-28 00:46:01 -07:00
irqflags.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
kprobes.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 174 2019-05-30 11:26:41 -07:00
linkage.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
mmiowb.h riscv/mmiowb: Hook up mmwiob() implementation to asm-generic code 2019-04-08 12:00:40 +01:00
mmu.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
mmu_context.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
module.h RISC-V: Support MODULE_SECTIONS mechanism on RV32 2019-01-07 08:19:20 -08:00
page.h RISC-V: Implement sparsemem 2019-08-30 11:10:37 -07:00
pci.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
perf_event.h RISC-V: Fix !CONFIG_SMP compilation error 2018-08-13 08:31:32 -07:00
pgalloc.h mm: treewide: clarify pgtable_page_{ctor,dtor}() naming 2019-09-26 10:10:44 -07:00
pgtable-32.h arch: pgtable: define MAX_POSSIBLE_PHYSMEM_BITS where needed 2020-12-02 08:49:50 +01:00
pgtable-64.h RISC-V: Setup initial page tables in two stages 2019-07-09 09:08:04 -07:00
pgtable-bits.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
pgtable.h RISC-V: Add PCIe I/O BAR memory mapping 2019-10-28 10:43:32 -07:00
processor.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
ptrace.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
sbi.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
sifive_l2_cache.h RISC-V: sifive_l2_cache: Add L2 cache controller driver for SiFive SoCs 2019-05-16 20:42:13 -07:00
smp.h riscv: cleanup riscv_cpuid_to_hartid_mask 2019-09-05 01:51:57 -07:00
sparsemem.h RISC-V: Implement sparsemem 2019-08-30 11:10:37 -07:00
spinlock.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
spinlock_types.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
string.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
switch_to.h riscv: add missing header file includes 2019-10-28 00:46:01 -07:00
syscall.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
thread_info.h riscv: use 16KB kernel stack on 64-bit 2020-07-22 09:33:14 +02:00
timex.h riscv: don't use the rdtime(h) pseudo-instructions 2019-09-05 01:52:46 -07:00
tlb.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
tlbflush.h riscv: tlbflush: remove confusing comment on local_flush_tlb_all() 2019-10-14 12:35:36 -07:00
uaccess.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
unistd.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00
vdso.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 234 2019-06-19 17:09:07 +02:00
word-at-a-time.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286 2019-06-05 17:36:37 +02:00