1
0
Fork 0
alistair23-linux/arch/mips
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
..
alchemy MIPS: Alchemy: Fix memleak in alchemy_clk_setup_cpu 2020-11-24 13:29:07 +01:00
ar7 The main MIPS changes for a pretty light v5.3 cycle, including: 2019-07-17 09:42:03 -07:00
ath25 PCI: consolidate PCI config entry in drivers/pci 2018-11-23 11:45:34 +09:00
ath79 The main MIPS changes for a pretty light v5.3 cycle, including: 2019-07-17 09:42:03 -07:00
bcm47xx MIPS: BCM47XX: Add support for Netgear R6200 V1 2019-07-25 22:10:05 -07:00
bcm63xx MIPS: bmips: mark exception vectors as char arrays 2019-10-23 21:07:28 -07:00
bmips docs: arm: convert docs to ReST and rename to *.rst 2019-07-15 09:20:24 -03:00
boot MIPS: qi_lb60: Fix routing to audio amplifier 2020-08-21 13:05:26 +02:00
cavium-octeon MIPS: OCTEON: add missing put_device() call in dwc3_octeon_device_init() 2020-08-19 08:16:15 +02:00
cobalt treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 1 2019-05-21 11:28:39 +02:00
configs scsi: sr: remove references to BLK_DEV_SR_VENDOR, leave it enabled 2020-07-22 09:32:57 +02:00
crypto
dec MIPS: DEC: Restore bootmem reservation for firmware working memory area 2020-11-05 11:43:30 +01:00
emma treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
fw MIPS: fw: sni: Fix out of bounds init of o32 stack 2019-10-09 12:47:28 -07:00
generic treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
include arch: pgtable: define MAX_POSSIBLE_PHYSMEM_BITS where needed 2020-12-02 08:49:50 +01:00
jazz dma-mapping: explicitly wire up ->mmap and ->get_sgtable 2019-09-04 11:13:18 +02:00
jz4740 Merge branch 'ingenic-tcu-v5.4' into mips-next 2019-08-08 15:33:16 -07:00
kernel MIPS: add missing MSACSR and upper MSA initialization 2020-09-09 19:12:28 +02:00
kvm KVM: MIPS: Change the definition of kvm type 2020-09-23 12:40:38 +02:00
lantiq MIPS: lantiq: xway: sysctrl: fix the GPHY clock alias names 2020-07-09 09:37:56 +02:00
lasat treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 182 2019-05-30 11:29:20 -07:00
lib treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 504 2019-06-19 17:09:56 +02:00
loongson32 treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
loongson64 MIPS: Loongson: Fix potential NULL dereference in loongson3_platform_init() 2020-02-24 08:36:27 +01:00
math-emu treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 454 2019-06-19 17:09:09 +02:00
mm MIPS: export has_transparent_hugepage() for modules 2020-11-24 13:29:04 +01:00
mti-malta MIPS: malta: Drop prom_free_prom_memory 2019-08-23 14:47:13 +01:00
net bpf, mips: Limit to 33 tail calls 2020-01-12 12:21:24 +01:00
netlogic MIPS: xlp: Drop boot_mem_map 2019-08-23 14:47:21 +01:00
oprofile MIPS: OProfile: Mark expected switch fall-throughs 2019-07-30 09:40:17 -07:00
paravirt
pci MIPS: PCI: Fix MIPS build 2020-11-22 10:14:11 +01:00
pic32 treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 445 2019-06-05 17:37:18 +02:00
pistachio A batch of MIPS fixes: 2019-06-08 13:09:31 -07:00
pmcs-msp71xx MIPS: pmcs-msp71xx: Remove unused addr variable 2019-10-03 15:47:17 -07:00
pnx833x A batch of MIPS fixes: 2019-06-08 13:09:31 -07:00
power treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 305 2019-06-05 17:37:04 +02:00
ralink MIPS: ralink: enable PCI support only if driver for mt7621 SoC is selected 2019-12-31 16:45:29 +01:00
rb532 treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 182 2019-05-30 11:29:20 -07:00
sgi-ip22 MIPS: ip22: Drop addr_is_ram 2019-08-23 14:47:18 +01:00
sgi-ip27 MIPS: SGI-IP27: Fix crash, when CPUs are disabled via nr_cpus parameter 2020-01-17 19:48:55 +01:00
sgi-ip32 Merge branch 'siginfo-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace 2019-07-08 21:48:15 -07:00
sibyte treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
sni MIPS: SNI: Fix spurious interrupts 2020-09-23 12:40:42 +02:00
tools MIPS: tools: Fix resource leak in elf-entry.c 2020-06-22 09:31:08 +02:00
txx9 A batch of MIPS fixes: 2019-06-08 13:09:31 -07:00
vdso mips/vdso: Fix resource leaks in genvdso.c 2020-09-03 11:26:45 +02:00
vr41xx treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
Kbuild treewide: Add SPDX license identifier - Kbuild 2019-05-30 11:32:33 -07:00
Kbuild.platforms treewide: Add SPDX license identifier - Kbuild 2019-05-30 11:32:33 -07:00
Kconfig MIPS: SNI: Fix MIPS_L1_CACHE_SHIFT 2020-09-23 12:40:41 +02:00
Kconfig.debug Kconfig: consolidate the "Kernel hacking" menu 2018-08-02 08:06:48 +09:00
Makefile MIPS: Truncate link address into 32bit for 32bit kernel 2020-06-22 09:31:03 +02:00
Makefile.postlink MIPS: fix indentation of the 'RELOCS' message 2020-02-11 04:35:16 -08:00