android_kernel_motorola_sm6225/arch/arm
Arnd Bergmann d4fe42d646 arch: pgtable: define MAX_POSSIBLE_PHYSMEM_BITS where needed
commit cef397038167ac15d085914493d6c86385773709 upstream.

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>
[florian: patch arch/powerpc/include/asm/pte-common.h for 4.19.y]
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-11-06 13:58:45 +01:00
..
boot ARM: 8819/1: Remove '-p' from LDFLAGS 2021-11-02 18:26:43 +01:00
common ARM: 8847/1: pm: fix HYP/SVC mode mismatch when MCPM is used 2020-01-27 14:50:28 +01:00
configs scsi: sr: remove references to BLK_DEV_SR_VENDOR, leave it enabled 2020-07-22 09:32:04 +02:00
crypto crypto: arm/crc32 - avoid warning when compiling with Clang 2019-11-20 18:47:11 +01:00
firmware ARM: 32-bit SoC platform updates 2018-08-23 13:44:43 -07:00
include arch: pgtable: define MAX_POSSIBLE_PHYSMEM_BITS where needed 2021-11-06 13:58:45 +01:00
kernel ARM: 9141/1: only warn about XIP address when not compile testing 2021-11-02 18:26:43 +01:00
kvm KVM: arm: Don't write junk to CP15 registers on reset 2019-08-29 08:28:48 +02:00
lib ARM: 8843/1: use unified assembler in headers 2020-06-03 08:19:34 +02:00
mach-actions
mach-alpine
mach-artpec
mach-asm9260
mach-aspeed
mach-at91 ARM: at91: pm: add missing put_device() call in at91_pm_sram_init() 2020-08-19 08:14:49 +02:00
mach-axxia
mach-bcm
mach-berlin
mach-clps711x
mach-cns3xxx ARM: cns3xxx: Fix writing to wrong PCI config registers after alignment 2019-02-06 17:30:11 +01:00
mach-davinci ARM: davinci: dm365: Fix McBSP dma_slave_map entry 2019-11-10 11:27:26 +01:00
mach-digicolor
mach-dove
mach-ebsa110
mach-efm32
mach-ep93xx
mach-exynos ARM: exynos: Fix undefined instruction during Exynos5422 resume 2019-06-15 11:54:10 +02:00
mach-footbridge ARM: footbridge: fix PCI interrupt mapping 2021-04-28 13:16:51 +02:00
mach-gemini
mach-highbank
mach-hisi ARM: hisi: handle of_iomap and fix missing of_node_put 2018-07-16 17:36:50 +01:00
mach-imx ARM: imx6: disable the GIC CPU interface before calling stby-poweroff sequence 2021-10-13 10:10:51 +02:00
mach-integrator ARM: integrator: Add some Kconfig selections 2020-06-25 15:32:48 +02:00
mach-iop13xx ARM: iop: don't use using 64-bit DMA masks 2019-05-08 07:21:51 +02:00
mach-iop32x ARM: iop32x/n2100: fix PCI IRQ mapping 2019-02-15 08:10:12 +01:00
mach-iop33x
mach-ixp4xx
mach-keystone ARM: keystone: fix integer overflow warning 2021-04-28 13:16:49 +02:00
mach-ks8695 ARM: ks8695: fix section mismatch warning 2019-12-05 09:20:02 +01:00
mach-lpc18xx
mach-lpc32xx
mach-mediatek
mach-meson
mach-mmp ARM: mmp/mmp2: fix cpu_is_mmp2() on mmp2-dt 2018-12-19 19:19:51 +01:00
mach-moxart
mach-mv78xx0
mach-mvebu
mach-mxs
mach-netx
mach-nomadik
mach-npcm ARM: npcm: Bring back GPIOLIB support 2020-02-19 19:51:56 +01:00
mach-nspire
mach-omap1 ARM: OMAP: replace setup_irq() by request_irq() 2021-07-11 12:49:31 +02:00
mach-omap2 clocksource/drivers/timer-ti-dm: Handle dra7 timer wrap errata i940 2021-07-11 12:49:32 +02:00
mach-orion5x
mach-oxnas
mach-picoxcell
mach-prima2
mach-pxa ARM: pxa: avoid section mismatch warning 2019-02-12 19:47:09 +01:00
mach-qcom
mach-realview
mach-rockchip ARM: rockchip: Force CONFIG_PM on Rockchip systems 2018-08-24 08:50:23 -07:00
mach-rpc ARM: riscpc: fix lack of keyboard interrupts after irq conversion 2020-01-27 14:50:47 +01:00
mach-s3c24xx ARM: s3c24xx: Fix boolean expressions in osiris_dvs_notify 2019-03-23 20:10:08 +01:00
mach-s3c64xx
mach-s5pv210
mach-sa1100
mach-shmobile soc: renesas: rmobile-sysc: Fix some leaks in rmobile_init_pm_domains() 2020-12-30 11:25:49 +01:00
mach-socfpga ARM: socfpga: PM: add missing put_device() call in socfpga_setup_ocram_self_refresh() 2020-08-19 08:14:50 +02:00
mach-spear
mach-sti
mach-stm32 ARM: stm32: use "depends on" instead of "if" after prompt 2020-01-27 14:51:01 +01:00
mach-sunxi ARM: sunxi: Add machine match for the Allwinner V3 SoC 2020-12-30 11:26:06 +01:00
mach-tango ARM: tango: Improve ARCH_MULTIPLATFORM compatibility 2019-02-15 08:10:12 +01:00
mach-tegra ARM: tegra: Correct PL310 Auxiliary Control Register initialization 2020-06-22 09:05:28 +02:00
mach-u300
mach-uniphier ARM: uniphier: select RESET_CONTROLLER 2018-07-31 19:04:41 -07:00
mach-ux500
mach-versatile
mach-vexpress ARM: vexpress: Set-up shared OPP table instead of individual for each CPU 2020-01-12 12:17:08 +01:00
mach-vt8500
mach-w90x900
mach-zx
mach-zynq ARM: zynq: Use memcpy_toio instead of memcpy on smp bring-up 2019-10-05 13:10:07 +02:00
mm ARM: 9133/1: mm: proc-macros: ensure *_tlb_fns are 4B aligned 2021-11-02 18:26:43 +01:00
net bpf, arm: Fix register clobbering in div/mod implementation 2021-10-13 10:10:51 +02:00
nwfpe
oprofile
plat-iop ARM: iop: don't use using 64-bit DMA masks 2019-05-08 07:21:51 +02:00
plat-omap ARM/time: Remove read_boot_clock64() 2018-07-20 00:02:41 +02:00
plat-orion ARM: orion: don't use using 64-bit DMA masks 2019-05-08 07:21:51 +02:00
plat-pxa ARM: pxa: ssp: Fix "WARNING: invalid free of devm_ allocated data" 2020-01-27 14:50:38 +01:00
plat-samsung ARM: samsung: fix PM debug build with DEBUG_LL but !MMU 2020-11-05 11:08:55 +01:00
plat-versatile
probes ARM: 9139/1: kprobes: fix arch_init_kprobes() prototype 2021-11-02 18:26:43 +01:00
tools ARM: 8787/1: wire up io_pgetevents syscall 2018-09-19 10:44:11 +01:00
vdso ARM: 8867/1: vdso: pass --be8 to linker if necessary 2020-10-17 10:12:56 +02:00
vfp ARM: 8810/1: vfp: Fix wrong assignement to ufp_exc 2019-02-20 10:25:37 +01:00
xen Xen/gnttab: handle p2m update errors on a per-slot basis 2021-03-07 12:19:01 +01:00
Kconfig ARM: 9122/1: select HAVE_FUTEX_CMPXCHG 2021-10-27 09:53:15 +02:00
Kconfig-nommu
Kconfig.debug ARM: debug: enable UART1 for socfpga Cyclone5 2019-12-13 08:52:08 +01:00
Makefile ARM: 8819/1: Remove '-p' from LDFLAGS 2021-11-02 18:26:43 +01:00