LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH v5 0/6] implement KASLR for powerpc/fsl_booke/64
From: Daniel Axtens @ 2020-04-27 13:34 UTC (permalink / raw)
  To: Jason Yan, mpe, linuxppc-dev, diana.craciun, christophe.leroy,
	benh, paulus, npiggin, keescook, kernel-hardening, oss
  Cc: linux-kernel, zhaohongjiang
In-Reply-To: <7362ac94-8f3a-1eed-4445-10772eebea38@huawei.com>

[-- Attachment #1: Type: text/plain, Size: 157 bytes --]

Hi Jason,

> Thanks for the test. Can you send me the full log which may contain the 
> system info such as the following:

It's attached.

Regards,
Daniel


[-- Attachment #2: fail-log --]
[-- Type: application/octet-stream, Size: 40438 bytes --]

[    0.000000] KASLR: No safe seed for randomizing the kernel base.
[    0.000000] MMU: Supported page sizes
[    0.000000]          4 KB as direct
[    0.000000]       2048 KB as direct & indirect
[    0.000000]       4096 KB as direct
[    0.000000]      16384 KB as direct
[    0.000000]      65536 KB as direct
[    0.000000]     262144 KB as direct
[    0.000000]    1048576 KB as direct
[    0.000000] MMU: Book3E HW tablewalk enabled
[    0.000000] Linux version 5.7.0-rc2-00865-gf55c3370c485 (dja@dja-thinkpad) (gcc version 9.2.1 20191008 (Ubuntu 9.2.1-9ubuntu1), GNU ld (GNU Binutils for Ubuntu) 2.33) #326 SMP Mon Apr 27 23:26:22 AEST 2020
[    0.000000] Argh, can't find dcache properties !
[    0.000000] Argh, can't find icache properties !
[    0.000000] Using CoreNet Generic machine description
[    0.000000] Found legacy serial port 0 for /soc@ffe000000/serial@11c500
[    0.000000]   mem=ffe11c500, taddr=ffe11c500, irq=0, clk=366666663, speed=0
[    0.000000] Found legacy serial port 1 for /soc@ffe000000/serial@11c600
[    0.000000]   mem=ffe11c600, taddr=ffe11c600, irq=0, clk=366666663, speed=0
[    0.000000] Found legacy serial port 2 for /soc@ffe000000/serial@11d500
[    0.000000]   mem=ffe11d500, taddr=ffe11d500, irq=0, clk=366666663, speed=0
[    0.000000] Found legacy serial port 3 for /soc@ffe000000/serial@11d600
[    0.000000]   mem=ffe11d600, taddr=ffe11d600, irq=0, clk=366666663, speed=0
[    0.000000] ioremap() called early from .find_legacy_serial_ports+0x6d0/0x7c0. Use early_ioremap() instead
[    0.000000] printk: bootconsole [udbg0] enabled
[    0.000000] CPU maps initialized for 2 threads per core
[    0.000000]  (thread shift is 1)
[    0.000000] Allocated 1984 bytes for 24 pacas
[    0.000000] -----------------------------------------------------
[    0.000000] phys_mem_size     = 0x180000000
[    0.000000] dcache_bsize      = 0x40
[    0.000000] icache_bsize      = 0x40
[    0.000000] cpu_features      = 0x00000003009003b6
[    0.000000]   possible        = 0x00000003009003b6
[    0.000000]   always          = 0x00000003008003b4
[    0.000000] cpu_user_features = 0xdc008000 0x08000000
[    0.000000] mmu_features      = 0x000a0010
[    0.000000] firmware_features = 0x0000000000000000
[    0.000000] physical_start    = 0x10080000
[    0.000000] -----------------------------------------------------
[    0.000000] CoreNet Generic board
[    0.000000] barrier-nospec: using isync; sync as speculation barrier
[    0.000000] barrier-nospec: patched 395 locations
[    0.000000] Top of RAM: 0x180000000, Total RAM: 0x180000000
[    0.000000] Memory hole size: 0MB
[    0.000000] Zone ranges:
[    0.000000]   DMA      [mem 0x0000000000000000-0x000000007fffffff]
[    0.000000]   Normal   [mem 0x0000000080000000-0x000000017fffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x000000017fffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x000000017fffffff]
[    0.000000] On node 0 totalpages: 1572864
[    0.000000]   DMA zone: 8192 pages used for memmap
[    0.000000]   DMA zone: 0 pages reserved
[    0.000000]   DMA zone: 524288 pages, LIFO batch:63
[    0.000000]   Normal zone: 16384 pages used for memmap
[    0.000000]   Normal zone: 1048576 pages, LIFO batch:63
[    0.000000] MMU: Allocated 2112 bytes of context maps for 255 contexts
[    0.000000] percpu: Embedded 32 pages/cpu s91736 r0 d39336 u131072
[    0.000000] pcpu-alloc: s91736 r0 d39336 u131072 alloc=1*1048576
[    0.000000] pcpu-alloc: [0] 00 01 02 03 04 05 06 07 [0] 08 09 10 11 12 13 14 15 
[    0.000000] pcpu-alloc: [0] 16 17 18 19 20 21 22 23 
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 1548288
[    0.000000] Kernel command line: root=/dev/nfs rw nfsroot=10.1.2.1:/srv/sid-ppc64 ip=10.1.2.2:10.1.2.1:10.1.1.1:255.255.0.0:t4240rdb:eth0:off console=ttyS0,115200
[    0.000000] printk: log_buf_len individual max cpu contribution: 16384 bytes
[    0.000000] printk: log_buf_len total cpu_extra contributions: 376832 bytes
[    0.000000] printk: log_buf_len min size: 131072 bytes
[    0.000000] printk: log_buf_len: 524288 bytes
[    0.000000] printk: early log buf free: 126824(96%)
[    0.000000] Dentry cache hash table entries: 1048576 (order: 11, 8388608 bytes, linear)
[    0.000000] Inode-cache hash table entries: 524288 (order: 10, 4194304 bytes, linear)
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] Memory: 6004108K/6291456K available (10468K kernel code, 1988K rwdata, 3396K rodata, 4112K init, 355K bss, 287348K reserved, 0K cma-reserved)
[    0.000000] rcu: Hierarchical RCU implementation.
[    0.000000] rcu: 	RCU event tracing is enabled.
[    0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
[    0.000000] NR_IRQS: 512, nr_irqs: 512, preallocated irqs: 16
[    0.000000] mpic: Setting up MPIC " OpenPIC  " version 1.2 at ffe040000, max 24 CPUs
[    0.000000] mpic: ISU size: 512, shift: 9, mask: 1ff
[    0.000000] mpic: Initializing for 512 sources
[    0.000000] random: get_random_u64 called from .start_kernel+0x734/0x964 with crng_init=0
[    0.000000] time_init: decrementer frequency = 45.833333 MHz
[    0.000000] time_init: processor frequency   = 1666.666650 MHz
[    0.000003] clocksource: timebase: mask: 0xffffffffffffffff max_cycles: 0xa9210e89c, max_idle_ns: 440795203878 ns
[    0.008944] clocksource: timebase mult[15d17460] shift[24] registered
[    0.014079] clockevent: decrementer mult[bbbbbba] shift[32] cpu[0]
[    0.018750] Console: colour dummy device 80x25
[    0.021832] pid_max: default: 32768 minimum: 301
[    0.025363] Mount-cache hash table entries: 16384 (order: 5, 131072 bytes, linear)
[    0.031553] Mountpoint-cache hash table entries: 16384 (order: 5, 131072 bytes, linear)
[    0.039224] e6500 family performance monitor hardware support registered
[    0.044587] rcu: Hierarchical SRCU implementation.
[    0.048540] smp: Bringing up secondary CPUs ...
[    4.961490] Processor 2 is stuck.
[    9.872983] Processor 3 is stuck.
[   14.784302] Processor 4 is stuck.
[   19.695729] Processor 5 is stuck.
[   24.607059] Processor 6 is stuck.
[   29.518496] Processor 7 is stuck.
[   34.429831] Processor 8 is stuck.
[   39.341233] Processor 9 is stuck.
[   44.252586] Processor 10 is stuck.
[   49.164063] Processor 11 is stuck.
[   54.075512] Processor 12 is stuck.
[   58.986907] Processor 13 is stuck.
[   63.898321] Processor 14 is stuck.
[   68.809721] Processor 15 is stuck.
[   73.721128] Processor 16 is stuck.
[   78.632517] Processor 17 is stuck.
[   83.543916] Processor 18 is stuck.
[   88.455324] Processor 19 is stuck.
[   93.366712] Processor 20 is stuck.
[   98.278111] Processor 21 is stuck.
[  103.189490] Processor 22 is stuck.
[  108.100890] Processor 23 is stuck.
[  108.102924] smp: Brought up 1 node, 2 CPUs
[  108.105671] Using standard scheduler topology
[  108.109270] devtmpfs: initialized
[  108.118401] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[  108.126769] futex hash table entries: 8192 (order: 7, 524288 bytes, linear)
[  108.132956] NET: Registered protocol family 16
[  108.136218] audit: initializing netlink subsys (disabled)
[  108.140280] audit: type=2000 audit(108.036:1): state=initialized audit_enabled=0 res=1
[  108.166744] Machine: fsl,T4240RDB
[  108.168666] SoC family: QorIQ T4240
[  108.170832] SoC ID: svr:0x82480020, Revision: 2.0
[  108.177249] OF: Can't handle multiple dma-ranges with different offsets on node(/pcie@ffe240000)
[  108.184647] OF: Can't handle multiple dma-ranges with different offsets on node(/pcie@ffe240000)
[  108.192110] fsl-pci ffe240000.pcie: Invalid size 0xfffff9 for dma-range
[  108.197445] Found FSL PCI host bridge at 0x0000000ffe240000. Firmware bus number: 0->1
[  108.204005] PCI host bridge /pcie@ffe240000  ranges:
[  108.207652]  MEM 0x0000000c00000000..0x0000000c1fffffff -> 0x00000000e0000000 
[  108.213558]   IO 0x0000000ff8000000..0x0000000ff800ffff -> 0x0000000000000000
[  108.219436] /pcie@ffe240000: PCICSRBAR @ 0xdf000007
[  108.222930] setup_pci_atmu: end of DRAM 180000000
[  108.226328] /pcie@ffe240000: Setup 64-bit PCI DMA window
[  108.230313] /pcie@ffe240000: DMA window size is 0xdf000007
[  108.234723] OF: Can't handle multiple dma-ranges with different offsets on node(/pcie@ffe260000)
[  108.242117] OF: Can't handle multiple dma-ranges with different offsets on node(/pcie@ffe260000)
[  108.249582] fsl-pci ffe260000.pcie: Invalid size 0xfffff9 for dma-range
[  108.254908] Found FSL PCI host bridge at 0x0000000ffe260000. Firmware bus number: 0->0
[  108.261479] PCI host bridge /pcie@ffe260000  ranges:
[  108.265126]  MEM 0x0000000c40000000..0x0000000c5fffffff -> 0x00000000e0000000 
[  108.271031]   IO 0x0000000ff8020000..0x0000000ff802ffff -> 0x0000000000000000
[  108.276867] /pcie@ffe260000: PCICSRBAR @ 0xdf000007
[  108.280404] setup_pci_atmu: end of DRAM 180000000
[  108.283804] /pcie@ffe260000: Setup 64-bit PCI DMA window
[  108.287786] /pcie@ffe260000: DMA window size is 0xdf000007
[  108.292195] OF: Can't handle multiple dma-ranges with different offsets on node(/pcie@ffe270000)
[  108.299589] OF: Can't handle multiple dma-ranges with different offsets on node(/pcie@ffe270000)
[  108.307053] fsl-pci ffe270000.pcie: Invalid size 0xfffff9 for dma-range
[  108.312381] Found FSL PCI host bridge at 0x0000000ffe270000. Firmware bus number: 0->0
[  108.318950] PCI host bridge /pcie@ffe270000  ranges:
[  108.322597]  MEM 0x0000000c60000000..0x0000000c7fffffff -> 0x00000000e0000000 
[  108.328503]   IO 0x0000000ff8030000..0x0000000ff803ffff -> 0x0000000000000000
[  108.334339] /pcie@ffe270000: PCICSRBAR @ 0xdf000007
[  108.337875] setup_pci_atmu: end of DRAM 180000000
[  108.341273] /pcie@ffe270000: Setup 64-bit PCI DMA window
[  108.345258] /pcie@ffe270000: DMA window size is 0xdf000007
[  108.351988] platform ff6000000.qman-portal: Adding to iommu group 0
[  108.356886] platform ff6004000.qman-portal: Adding to iommu group 1
[  108.361828] platform ff6008000.qman-portal: Adding to iommu group 2
[  108.366779] platform ff600c000.qman-portal: Adding to iommu group 3
[  108.371727] platform ff6010000.qman-portal: Adding to iommu group 4
[  108.376675] platform ff6014000.qman-portal: Adding to iommu group 5
[  108.381624] platform ff6018000.qman-portal: Adding to iommu group 6
[  108.386577] platform ff601c000.qman-portal: Adding to iommu group 7
[  108.391527] platform ff6020000.qman-portal: Adding to iommu group 8
[  108.396474] platform ff6024000.qman-portal: Adding to iommu group 9
[  108.401424] platform ff6028000.qman-portal: Adding to iommu group 10
[  108.406460] platform ff602c000.qman-portal: Adding to iommu group 11
[  108.411499] platform ff6030000.qman-portal: Adding to iommu group 12
[  108.416537] platform ff6034000.qman-portal: Adding to iommu group 13
[  108.421570] platform ff6038000.qman-portal: Adding to iommu group 14
[  108.426606] platform ff603c000.qman-portal: Adding to iommu group 15
[  108.431645] platform ff6040000.qman-portal: Adding to iommu group 16
[  108.436681] platform ff6044000.qman-portal: Adding to iommu group 17
[  108.441715] platform ff6048000.qman-portal: Adding to iommu group 18
[  108.446752] platform ff604c000.qman-portal: Adding to iommu group 19
[  108.451791] platform ff6050000.qman-portal: Adding to iommu group 20
[  108.456826] platform ff6054000.qman-portal: Adding to iommu group 21
[  108.461861] platform ff6058000.qman-portal: Adding to iommu group 22
[  108.466899] platform ff605c000.qman-portal: Adding to iommu group 23
[  108.471939] platform ff6060000.qman-portal: Adding to iommu group 24
[  108.476971] platform ff6064000.qman-portal: Adding to iommu group 25
[  108.482008] platform ff6068000.qman-portal: Adding to iommu group 26
[  108.487046] platform ff606c000.qman-portal: Adding to iommu group 27
[  108.492083] platform ff6070000.qman-portal: Adding to iommu group 28
[  108.497118] platform ff6074000.qman-portal: Adding to iommu group 29
[  108.502156] platform ff6078000.qman-portal: Adding to iommu group 30
[  108.507191] platform ff607c000.qman-portal: Adding to iommu group 31
[  108.512229] platform ff6080000.qman-portal: Adding to iommu group 32
[  108.517265] platform ff6084000.qman-portal: Adding to iommu group 33
[  108.522301] platform ff6088000.qman-portal: Adding to iommu group 34
[  108.527337] platform ff608c000.qman-portal: Adding to iommu group 35
[  108.532375] platform ff6090000.qman-portal: Adding to iommu group 36
[  108.537410] platform ff6094000.qman-portal: Adding to iommu group 37
[  108.542446] platform ff6098000.qman-portal: Adding to iommu group 38
[  108.547483] platform ff609c000.qman-portal: Adding to iommu group 39
[  108.552521] platform ff60a0000.qman-portal: Adding to iommu group 40
[  108.557555] platform ff60a4000.qman-portal: Adding to iommu group 41
[  108.562592] platform ff60a8000.qman-portal: Adding to iommu group 42
[  108.567629] platform ff60ac000.qman-portal: Adding to iommu group 43
[  108.572669] platform ff60b0000.qman-portal: Adding to iommu group 44
[  108.577702] platform ff60b4000.qman-portal: Adding to iommu group 45
[  108.582738] platform ff60b8000.qman-portal: Adding to iommu group 46
[  108.587777] platform ff60bc000.qman-portal: Adding to iommu group 47
[  108.592813] platform ff60c0000.qman-portal: Adding to iommu group 48
[  108.597849] platform ff60c4000.qman-portal: Adding to iommu group 49
[  108.602920] platform ffe488000.port: Adding to iommu group 50
[  108.607318] platform ffe489000.port: Adding to iommu group 51
[  108.611746] platform ffe48a000.port: Adding to iommu group 52
[  108.616173] platform ffe48b000.port: Adding to iommu group 53
[  108.620602] platform ffe48c000.port: Adding to iommu group 54
[  108.625030] platform ffe48d000.port: Adding to iommu group 55
[  108.629460] platform ffe490000.port: Adding to iommu group 56
[  108.633887] platform ffe491000.port: Adding to iommu group 57
[  108.638343] platform ffe588000.port: Adding to iommu group 58
[  108.642745] platform ffe589000.port: Adding to iommu group 59
[  108.647174] platform ffe58a000.port: Adding to iommu group 60
[  108.651602] platform ffe58b000.port: Adding to iommu group 61
[  108.656032] platform ffe58c000.port: Adding to iommu group 62
[  108.660459] platform ffe58d000.port: Adding to iommu group 63
[  108.664890] platform ffe590000.port: Adding to iommu group 64
[  108.669319] platform ffe591000.port: Adding to iommu group 65
[  108.673744] platform ffe114000.sdhc: Adding to iommu group 66
[  108.678191] platform ffe100300.dma: Adding to iommu group 67
[  108.682515] platform ffe101300.dma: Adding to iommu group 68
[  108.686868] platform ffe210000.usb: Adding to iommu group 69
[  108.691199] platform ffe211000.usb: Adding to iommu group 70
[  108.695538] platform ffe220000.sata: Adding to iommu group 71
[  108.699968] platform ffe221000.sata: Adding to iommu group 72
[  108.704400] platform ffe316000.pme: Adding to iommu group 73
[  108.708737] platform ffe318000.qman: Adding to iommu group 74
[  108.713167] platform ffe31a000.bman: Adding to iommu group 75
[  108.717600] fsl-pci ffe240000.pcie: Adding to iommu group 76
[  108.721938] fsl-pci ffe260000.pcie: Adding to iommu group 77
[  108.726279] fsl-pci ffe270000.pcie: Adding to iommu group 78
[  108.764910] software IO TLB: mapped [mem 0x1145a000-0x1545a000] (64MB)
[  108.770049] PCI: Probing PCI hardware
[  108.772447] fsl-pci ffe240000.pcie: PCI host bridge to bus 0000:00
[  108.777256] pci_bus 0000:00: root bus resource [io  0x8000080000010000-0x800008000001ffff] (bus address [0x0000-0xffff])
[  108.786806] pci_bus 0000:00: root bus resource [mem 0xc00000000-0xc1fffffff] (bus address [0xe0000000-0xffffffff])
[  108.795836] pci_bus 0000:00: root bus resource [bus 00-01]
[  108.800004] pci_bus 0000:00: busn_res: [bus 00-01] end is updated to ff
[  108.805319] pci 0000:00:00.0: [1957:0440] type 01 class 0x0b2000
[  108.810014] pci 0000:00:00.0: reg 0x10: [io  0xdf000004-0xdf000007]
[  108.814948] pci 0000:00:00.0: reg 0x38: [mem 0xc00000000-0xc00ffffff pref]
[  108.820560] pci 0000:00:00.0: supports D1 D2
[  108.823445] pci 0000:00:00.0: PME# supported from D0 D1 D2 D3hot
[  108.828237] fsl-pci ffe240000.pcie: Removing from iommu group 76
[  108.832868] pci 0000:00:00.0: Adding to iommu group 79
[  108.841338] pci 0000:01:00.0: [8086:10d3] type 00 class 0x020000
[  108.845992] pci 0000:01:00.0: reg 0x10: [mem 0xc01000000-0xc0101ffff]
[  108.851086] pci 0000:01:00.0: reg 0x14: [mem 0xc01080000-0xc010fffff]
[  108.856209] pci 0000:01:00.0: reg 0x18: [io  0x8000080000011000-0x800008000001101f]
[  108.862548] pci 0000:01:00.0: reg 0x1c: [mem 0xc01100000-0xc01103fff]
[  108.867704] pci 0000:01:00.0: reg 0x30: [mem 0xc01140000-0xc0117ffff pref]
[  108.873343] pci 0000:01:00.0: PME# supported from D0 D3hot D3cold
[  108.878165] pci 0000:01:00.0: Adding to iommu group 79
[  108.898576] pci 0000:00:00.0: PCI bridge to [bus 01-ff]
[  108.902408] pci 0000:00:00.0:   bridge window [io  0x8000080000011000-0x8000080000011fff]
[  108.909268] pci 0000:00:00.0:   bridge window [mem 0xc00000000-0xc011fffff]
[  108.914919] pci_bus 0000:01: busn_res: [bus 01-ff] end is updated to 01
[  108.920209] pci_bus 0000:00: busn_res: [bus 00-ff] end is updated to 01
[  108.925555] fsl-pci ffe260000.pcie: PCI host bridge to bus 0001:00
[  108.930369] pci_bus 0001:00: root bus resource [io  0x8000080000021000-0x8000080000030fff] (bus address [0x0000-0xffff])
[  108.939924] pci_bus 0001:00: root bus resource [mem 0xc40000000-0xc5fffffff] (bus address [0xe0000000-0xffffffff])
[  108.948951] pci_bus 0001:00: root bus resource [bus 00]
[  108.952855] pci_bus 0001:00: busn_res: [bus 00] end is updated to ff
[  108.957910] pci 0001:00:00.0: [1957:0440] type 01 class 0x0b2000
[  108.962599] pci 0001:00:00.0: reg 0x10: [io  0xdf000004-0xdf000007]
[  108.967542] pci 0001:00:00.0: reg 0x38: [mem 0x00000000-0x00ffffff pref]
[  108.972964] pci 0001:00:00.0: supports D1 D2
[  108.975866] pci 0001:00:00.0: PME# supported from D0 D1 D2 D3hot
[  108.980635] fsl-pci ffe260000.pcie: Removing from iommu group 77
[  108.985263] pci 0001:00:00.0: Adding to iommu group 76
[  108.993609] pci 0001:00:00.0: bridge configuration invalid ([bus 00-00]), reconfiguring
[  109.004762] pci 0001:00:00.0: PCI bridge to [bus 01-ff]
[  109.008596] pci 0001:00:00.0:   bridge window [io  0x8000080000021000-0x8000080000021fff]
[  109.015454] pci 0001:00:00.0:   bridge window [mem 0x00000000-0x000fffff]
[  109.020926] pci 0001:00:00.0:   bridge window [mem 0x00000000-0x000fffff 64bit pref]
[  109.027357] pci_bus 0001:01: busn_res: [bus 01-ff] end is updated to 01
[  109.032647] pci_bus 0001:00: busn_res: [bus 00-ff] end is updated to 01
[  109.037991] fsl-pci ffe270000.pcie: PCI host bridge to bus 0002:00
[  109.042807] pci_bus 0002:00: root bus resource [io  0x8000080000032000-0x8000080000041fff] (bus address [0x0000-0xffff])
[  109.052359] pci_bus 0002:00: root bus resource [mem 0xc60000000-0xc7fffffff] (bus address [0xe0000000-0xffffffff])
[  109.061388] pci_bus 0002:00: root bus resource [bus 00]
[  109.065293] pci_bus 0002:00: busn_res: [bus 00] end is updated to ff
[  109.070345] pci 0002:00:00.0: [1957:0440] type 01 class 0x0b2000
[  109.075037] pci 0002:00:00.0: reg 0x10: [io  0xdf000004-0xdf000007]
[  109.079980] pci 0002:00:00.0: reg 0x38: [mem 0x00000000-0x00ffffff pref]
[  109.085402] pci 0002:00:00.0: supports D1 D2
[  109.088304] pci 0002:00:00.0: PME# supported from D0 D1 D2 D3hot
[  109.093075] fsl-pci ffe270000.pcie: Removing from iommu group 78
[  109.097702] pci 0002:00:00.0: Adding to iommu group 77
[  109.106035] pci 0002:00:00.0: bridge configuration invalid ([bus 00-00]), reconfiguring
[  109.117184] pci 0002:00:00.0: PCI bridge to [bus 01-ff]
[  109.121017] pci 0002:00:00.0:   bridge window [io  0x8000080000032000-0x8000080000032fff]
[  109.127876] pci 0002:00:00.0:   bridge window [mem 0x00000000-0x000fffff]
[  109.133348] pci 0002:00:00.0:   bridge window [mem 0x00000000-0x000fffff 64bit pref]
[  109.139779] pci_bus 0002:01: busn_res: [bus 01-ff] end is updated to 01
[  109.145069] pci_bus 0002:00: busn_res: [bus 00-ff] end is updated to 01
[  109.150369] PCI: Cannot allocate resource region 0 of device 0000:00:00.0, will remap
[  109.156876] PCI: Cannot allocate resource region 6 of device 0000:00:00.0, will remap
[  109.163397] PCI: Cannot allocate resource region 0 of device 0001:00:00.0, will remap
[  109.169904] PCI: Cannot allocate resource region 0 of device 0002:00:00.0, will remap
[  109.176424] PCI 0000:00 Cannot reserve Legacy IO [io  0x8000080000010000-0x10fff]
[  109.176427] PCI 0001:00 Cannot reserve Legacy IO [io  0x8000080000021000-0x21fff]
[  109.176429] PCI 0002:00 Cannot reserve Legacy IO [io  0x8000080000032000-0x32fff]
[  109.176440] pci 0000:00:00.0: BAR 6: no space for [mem size 0x01000000 pref]
[  109.182147] pci 0000:00:00.0: BAR 6: failed to assign [mem size 0x01000000 pref]
[  109.188226] pci 0000:00:00.0: BAR 0: no space for [io  size 0x0004]
[  109.193176] pci 0000:00:00.0: BAR 0: failed to assign [io  size 0x0004]
[  109.198473] pci 0000:00:00.0: PCI bridge to [bus 01]
[  109.202117] pci 0000:00:00.0:   bridge window [io  0x8000080000010000-0x800008000001ffff]
[  109.208981] pci 0000:00:00.0:   bridge window [mem 0xc00000000-0xc1fffffff]
[  109.214625] pci_bus 0000:00: Some PCI device resources are unassigned, try booting with pci=realloc
[  109.222352] pci_bus 0000:00: resource 4 [io  0x8000080000010000-0x800008000001ffff]
[  109.228691] pci_bus 0000:00: resource 5 [mem 0xc00000000-0xc1fffffff]
[  109.233814] pci_bus 0000:01: resource 0 [io  0x8000080000010000-0x800008000001ffff]
[  109.240153] pci_bus 0000:01: resource 1 [mem 0xc00000000-0xc1fffffff]
[  109.245279] pci 0001:00:00.0: BAR 6: no space for [mem size 0x01000000 pref]
[  109.251008] pci 0001:00:00.0: BAR 6: failed to assign [mem size 0x01000000 pref]
[  109.257087] pci 0001:00:00.0: BAR 0: no space for [io  size 0x0004]
[  109.262036] pci 0001:00:00.0: BAR 0: failed to assign [io  size 0x0004]
[  109.267333] pci 0001:00:00.0: PCI bridge to [bus 01]
[  109.270978] pci 0001:00:00.0:   bridge window [io  0x8000080000021000-0x8000080000030fff]
[  109.277842] pci 0001:00:00.0:   bridge window [mem 0xc40000000-0xc5fffffff]
[  109.283486] pci_bus 0001:00: Some PCI device resources are unassigned, try booting with pci=realloc
[  109.291214] pci_bus 0001:00: resource 4 [io  0x8000080000021000-0x8000080000030fff]
[  109.297554] pci_bus 0001:00: resource 5 [mem 0xc40000000-0xc5fffffff]
[  109.302676] pci_bus 0001:01: resource 0 [io  0x8000080000021000-0x8000080000030fff]
[  109.309015] pci_bus 0001:01: resource 1 [mem 0xc40000000-0xc5fffffff]
[  109.314140] pci 0002:00:00.0: BAR 6: no space for [mem size 0x01000000 pref]
[  109.319869] pci 0002:00:00.0: BAR 6: failed to assign [mem size 0x01000000 pref]
[  109.325948] pci 0002:00:00.0: BAR 0: no space for [io  size 0x0004]
[  109.330897] pci 0002:00:00.0: BAR 0: failed to assign [io  size 0x0004]
[  109.336195] pci 0002:00:00.0: PCI bridge to [bus 01]
[  109.339838] pci 0002:00:00.0:   bridge window [io  0x8000080000032000-0x8000080000041fff]
[  109.346703] pci 0002:00:00.0:   bridge window [mem 0xc60000000-0xc7fffffff]
[  109.352348] pci_bus 0002:00: Some PCI device resources are unassigned, try booting with pci=realloc
[  109.360074] pci_bus 0002:00: resource 4 [io  0x8000080000032000-0x8000080000041fff]
[  109.366413] pci_bus 0002:00: resource 5 [mem 0xc60000000-0xc7fffffff]
[  109.371537] pci_bus 0002:01: resource 0 [io  0x8000080000032000-0x8000080000041fff]
[  109.377876] pci_bus 0002:01: resource 1 [mem 0xc60000000-0xc7fffffff]
[  109.383056] PCI: Probing PCI hardware done
[  109.383569] Setting up Freescale MSI support
[  109.383936] Setting up Freescale MSI support
[  109.384295] Setting up Freescale MSI support
[  109.384660] Setting up Freescale MSI support
[  109.393666] HugeTLB registered 4.00 MiB page size, pre-allocated 0 pages
[  109.398983] HugeTLB registered 16.0 MiB page size, pre-allocated 0 pages
[  109.404365] HugeTLB registered 64.0 MiB page size, pre-allocated 0 pages
[  109.409742] HugeTLB registered 256 MiB page size, pre-allocated 0 pages
[  109.415039] HugeTLB registered 1.00 GiB page size, pre-allocated 0 pages
[  109.424164] iommu: Default domain type: Translated 
[  109.427708] vgaarb: loaded
[  109.429148] SCSI subsystem initialized
[  109.431659] libata version 3.00 loaded.
[  109.431785] usbcore: registered new interface driver usbfs
[  109.435898] usbcore: registered new interface driver hub
[  109.439955] usbcore: registered new device driver usb
[  109.443658] pps_core: LinuxPPS API ver. 1 registered
[  109.447258] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[  109.455082] PTP clock support registered
[  109.457851] EDAC MC: Ver: 3.0.0
[  109.460700] clocksource: Switched to clocksource timebase
[  109.710567] NET: Registered protocol family 2
[  109.713985] tcp_listen_portaddr_hash hash table entries: 4096 (order: 4, 65536 bytes, linear)
[  109.721183] TCP established hash table entries: 65536 (order: 7, 524288 bytes, linear)
[  109.727979] TCP bind hash table entries: 65536 (order: 8, 1048576 bytes, linear)
[  109.734380] TCP: Hash tables configured (established 65536 bind 65536)
[  109.739615] UDP hash table entries: 4096 (order: 5, 131072 bytes, linear)
[  109.745090] UDP-Lite hash table entries: 4096 (order: 5, 131072 bytes, linear)
[  109.751134] NET: Registered protocol family 1
[  109.754303] RPC: Registered named UNIX socket transport module.
[  109.758831] RPC: Registered udp transport module.
[  109.762214] RPC: Registered tcp transport module.
[  109.765602] RPC: Registered tcp NFSv4.1 backchannel transport module.
[  109.770760] pci 0000:01:00.0: CLS mismatch (32 != 64), using 64 bytes
[  109.777400] workingset: timestamp_bits=46 max_order=21 bucket_order=0
[  109.783109] NFS: Registering the id_resolver key type
[  109.786778] Key type id_resolver registered
[  109.789630] Key type id_legacy registered
[  109.792332] ntfs: driver 2.1.32 [Flags: R/O].
[  109.795394] jffs2: version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
[  109.815523] io scheduler mq-deadline registered
[  109.818662] io scheduler kyber registered
[  109.821456] OF: Can't handle multiple dma-ranges with different offsets on node(/pcie@ffe240000)
[  109.828855] OF: Can't handle multiple dma-ranges with different offsets on node(/pcie@ffe240000)
[  109.836319] pcieport 0000:00:00.0: Invalid size 0xfffff9 for dma-range
[  109.841688] pcieport 0000:00:00.0: AER: enabled with IRQ 20
[  109.845986] OF: Can't handle multiple dma-ranges with different offsets on node(/pcie@ffe260000)
[  109.853382] OF: Can't handle multiple dma-ranges with different offsets on node(/pcie@ffe260000)
[  109.860845] pcieport 0001:00:00.0: Invalid size 0xfffff9 for dma-range
[  109.866203] pcieport 0001:00:00.0: AER: enabled with IRQ 22
[  109.870485] OF: Can't handle multiple dma-ranges with different offsets on node(/pcie@ffe270000)
[  109.877880] OF: Can't handle multiple dma-ranges with different offsets on node(/pcie@ffe270000)
[  109.885343] pcieport 0002:00:00.0: Invalid size 0xfffff9 for dma-range
[  109.890696] pcieport 0002:00:00.0: AER: enabled with IRQ 23
[  109.895997] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[  109.901344] printk: console [ttyS0] disabled
[  109.904233] serial8250.0: ttyS0 at MMIO 0xffe11c500 (irq = 36, base_baud = 22916666) is a 16550A
[  109.911704] printk: console [ttyS0] enabled
[  109.917421] printk: bootconsole [udbg0] disabled
[  109.924167] serial8250.0: ttyS1 at MMIO 0xffe11c600 (irq = 36, base_baud = 22916666) is a 16550A
[  109.931796] serial8250.0: ttyS2 at MMIO 0xffe11d500 (irq = 37, base_baud = 22916666) is a 16550A
[  109.939427] serial8250.0: ttyS3 at MMIO 0xffe11d600 (irq = 37, base_baud = 22916666) is a 16550A
[  109.947077] ePAPR hypervisor byte channel driver
[  109.954200] brd: module loaded
[  109.962388] loop: module loaded
[  109.964250] st: Version 20160209, fixed bufsize 32768, s/g segs 256
[  109.969931] fsl-sata ffe220000.sata: Sata FSL Platform/CSB Driver init
[  109.975448] scsi host0: sata_fsl
[  109.977470] ata1: SATA max UDMA/133 irq 68
[  109.980307] fsl-sata ffe221000.sata: Sata FSL Platform/CSB Driver init
[  109.985759] scsi host1: sata_fsl
[  109.987745] ata2: SATA max UDMA/133 irq 69
[  109.991308] fsl_espi ffe110000.spi: cs=0, init_csmode=0x100008
[  109.996085] spi-nor spi0.0: unrecognized JEDEC id bytes: ff ff ff ff ff ff
[  110.001666] fsl_espi ffe110000.spi: at 0x(____ptrval____) (irq = 53)
[  110.007869] libphy: Fixed MDIO Bus: probed
[  110.011211] libphy: Freescale XGMAC MDIO Bus: probed
[  110.015080] libphy: Freescale XGMAC MDIO Bus: probed
[  110.018943] libphy: Freescale XGMAC MDIO Bus: probed
[  110.022812] libphy: Freescale XGMAC MDIO Bus: probed
[  110.026678] libphy: Freescale XGMAC MDIO Bus: probed
[  110.030548] libphy: Freescale XGMAC MDIO Bus: probed
[  110.034415] libphy: Freescale XGMAC MDIO Bus: probed
[  110.038272] libphy: Freescale XGMAC MDIO Bus: probed
[  110.042130] libphy: Freescale XGMAC MDIO Bus: probed
[  110.048770] libphy: Freescale XGMAC MDIO Bus: probed
[  110.058922] libphy: Freescale XGMAC MDIO Bus: probed
[  110.062781] libphy: Freescale XGMAC MDIO Bus: probed
[  110.066639] libphy: Freescale XGMAC MDIO Bus: probed
[  110.070499] libphy: Freescale XGMAC MDIO Bus: probed
[  110.074355] libphy: Freescale XGMAC MDIO Bus: probed
[  110.078212] libphy: Freescale XGMAC MDIO Bus: probed
[  110.082073] libphy: Freescale XGMAC MDIO Bus: probed
[  110.085943] libphy: Freescale XGMAC MDIO Bus: probed
[  110.089719] e1000e: Intel(R) PRO/1000 Network Driver - 3.2.6-k
[  110.094244] e1000e: Copyright(c) 1999 - 2015 Intel Corporation.
[  110.098881] OF: Can't handle multiple dma-ranges with different offsets on node(/pcie@ffe240000)
[  110.106364] OF: Can't handle multiple dma-ranges with different offsets on node(/pcie@ffe240000)
[  110.113844] e1000e 0000:01:00.0: Invalid size 0xfffff9 for dma-range
[  110.119049] e1000e 0000:01:00.0: Interrupt Throttling Rate (ints/sec) set to dynamic conservative mode
[  110.173151] e1000e 0000:01:00.0 0000:01:00.0 (uninitialized): registered PHC clock
[  110.230696] e1000e 0000:01:00.0 eth0: (PCI Express:2.5GT/s:Width x1) 68:05:ca:2e:24:a8
[  110.237311] e1000e 0000:01:00.0 eth0: Intel(R) PRO/1000 Network Connection
[  110.242892] e1000e 0000:01:00.0 eth0: MAC: 3, PHY: 8, PBA No: E46981-008
[  110.248350] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[  110.253892] ehci-pci: EHCI PCI platform driver
[  110.257475] ehci-fsl: Freescale EHCI Host controller driver
[  110.261834] fsl-ehci fsl-ehci.0: Freescale On-Chip EHCI Host Controller
[  110.267153] fsl-ehci fsl-ehci.0: new USB bus registered, assigned bus number 1
[  110.282931] fsl-ehci fsl-ehci.0: irq 44, io mem 0xffe210000
[  110.300705] fsl-ehci fsl-ehci.0: USB 2.0 started, EHCI 1.00
[  110.305249] hub 1-0:1.0: USB hub found
[  110.307702] hub 1-0:1.0: 1 port detected
[  110.310464] fsl-ehci fsl-ehci.1: Freescale On-Chip EHCI Host Controller
[  110.315783] fsl-ehci fsl-ehci.1: new USB bus registered, assigned bus number 2
[  110.331547] fsl-ehci fsl-ehci.1: irq 45, io mem 0xffe211000
[  110.348699] fsl-ehci fsl-ehci.1: USB 2.0 started, EHCI 1.00
[  110.353215] hub 2-0:1.0: USB hub found
[  110.355667] hub 2-0:1.0: 1 port detected
[  110.358489] usbcore: registered new interface driver usb-storage
[  110.364395] i2c /dev entries driver
[  110.366998] mpc-i2c ffe118000.i2c: timeout 1000000 us
[  110.375814] rtc-ds1374 0-0068: registered as rtc0
[  110.379883] rtc-ds1374 0-0068: setting system clock to 1970-01-01T00:04:57 UTC (297)
[  110.386680] mpc-i2c ffe118100.i2c: timeout 1000000 us
[  110.390570] mpc-i2c ffe119000.i2c: timeout 1000000 us
[  110.394452] mpc-i2c ffe119100.i2c: timeout 1000000 us
[  110.402034] hwmon_vid: Unknown VRM version of your CPU
[  110.406051] w83793 0-002f: hwmon_device_register() is deprecated. Please convert the driver to use hwmon_device_register_with_info().
[  110.418175] w83793 0-002f: Registered watchdog chardev major 10, minor: 130
[  110.423944] Freescale(R) MPC85xx EDAC driver, (C) 2006 Montavista Software
[  110.430923] EDAC MC0: Giving out device to module fsl_ddr_edac controller fsl_mc_err: DEV fsl_mc_err (INTERRUPT)
[  110.439809] fsl_ddr_edac acquired irq 490 for MC
[  110.443117] fsl_ddr_edac MC err registered
[  110.446008] EDAC MC1: Giving out device to module fsl_ddr_edac controller fsl_mc_err: DEV fsl_mc_err (INTERRUPT)
[  110.454893] fsl_ddr_edac acquired irq 489 for MC
[  110.458201] fsl_ddr_edac MC err registered
[  110.461091] EDAC MC2: Giving out device to module fsl_ddr_edac controller fsl_mc_err: DEV fsl_mc_err (INTERRUPT)
[  110.469976] fsl_ddr_edac acquired irq 488 for MC
[  110.473286] fsl_ddr_edac MC err registered
[  110.477997] EDAC PCI0: Giving out device to module MPC85xx_edac controller mpc85xx_pci_err: DEV mpc85xx-pci-edac.0.auto (INTERRUPT)
[  110.480814] ata1: No Device OR PHYRDY change,Hstatus = 0xa0000000
[  110.488525] MPC85xx_edac acquired irq 20 for PCI Err
[  110.493309] ata1: SATA link down (SStatus 10 SControl 300)
[  110.496955] MPC85xx_edac PCI err registered
[  110.501150] ata2: No Device OR PHYRDY change,Hstatus = 0xa0000000
[  110.504041] EDAC PCI1: Giving out device to module MPC85xx_edac controller mpc85xx_pci_err: DEV mpc85xx-pci-edac.1.auto (INTERRUPT)
[  110.508791] ata2: SATA link down (SStatus 10 SControl 300)
[  110.519308] MPC85xx_edac acquired irq 22 for PCI Err
[  110.527127] MPC85xx_edac PCI err registered
[  110.530046] EDAC PCI2: Giving out device to module MPC85xx_edac controller mpc85xx_pci_err: DEV mpc85xx-pci-edac.2.auto (INTERRUPT)
[  110.540574] MPC85xx_edac acquired irq 23 for PCI Err
[  110.544230] MPC85xx_edac PCI err registered
[  110.547545] sdhci: Secure Digital Host Controller Interface driver
[  110.552417] sdhci: Copyright(c) Pierre Ossman
[  110.555464] sdhci-pltfm: SDHCI platform and OF driver helper
[  110.585880] mmc0: SDHCI controller on ffe114000.sdhc [ffe114000.sdhc] using ADMA
[  110.592744] caam ffe300000.crypto: RNG4 SH0 was previously instantiated without prediction resistance. Tearing it down
[  110.602143] caam ffe300000.crypto: Deinstantiated RNG4 SH0
[  110.606326] caam ffe300000.crypto: Instantiated RNG4 SH0
[  110.628202] caam ffe300000.crypto: Instantiated RNG4 SH1
[  110.632209] caam ffe300000.crypto: device ID = 0x0a1c020000000000 (Era 6)
[  110.637690] caam ffe300000.crypto: job rings = 4, qi = 1
[  110.641822] platform ffe301000.jr: Adding to iommu group 78
[  110.646261] platform ffe302000.jr: Adding to iommu group 80
[  110.650681] platform ffe303000.jr: Adding to iommu group 81
[  110.655102] platform ffe304000.jr: Adding to iommu group 82
[  110.670179] caam algorithms registered in /proc/crypto
[  110.675861] caam ffe300000.crypto: caam pkc algorithms registered in /proc/crypto
[  110.682046] caam ffe300000.crypto: registering rng-caam
[  110.686575] usbcore: registered new interface driver usbhid
[  110.690851] usbhid: USB HID core driver
[  110.693378] Freescale hypervisor management driver
[  110.696865] fsl-hv: no hypervisor found
[  110.699548] ipip: IPv4 and MPLS over IPv4 tunneling driver
[  110.703975] Initializing XFRM netlink socket
[  110.707032] NET: Registered protocol family 10
[  110.710655] Segment Routing with IPv6
[  110.713521] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[  110.718383] NET: Registered protocol family 17
[  110.721525] NET: Registered protocol family 15
[  110.724675] 8021q: 802.1Q VLAN Support v1.8
[  110.727566] Key type dns_resolver registered
[  110.730593] drmem: No dynamic reconfiguration memory found
[  110.773502] random: fast init done
[  110.802913] 8021q: adding VLAN 0 to HW filter on device eth0
[  110.817272] random: crng init done
[  113.993688] e1000e 0000:01:00.0 eth0: NIC Link is Up 1000 Mbps Full Duplex, Flow Control: Rx/Tx
[  114.008711] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[  114.028706] IP-Config: Complete:
[  114.030624]      device=eth0, hwaddr=68:05:ca:2e:24:a8, ipaddr=10.1.2.2, mask=255.255.0.0, gw=10.1.1.1
[  114.038628]      host=t4240rdb, domain=, nis-domain=(none)
[  114.042805]      bootserver=10.1.2.1, rootserver=10.1.2.1, rootpath=
[  114.048141] md: Skipping autodetection of RAID arrays. (raid=autodetect will force)
[  114.060967] VFS: Mounted root (nfs filesystem) on device 0:18.
[  114.065743] devtmpfs: mounted
[  114.068395] Freeing unused kernel memory: 4112K
[  114.071661] This architecture does not have kernel memory protection.
[  114.076794] Run /sbin/init as init process
[  114.079577]   with arguments:
[  114.079578]     /sbin/init
[  114.079579]   with environment:
[  114.079580]     HOME=/
[  114.079581]     TERM=linux
[  115.315377] systemd[1]: System time before build time, advancing clock.
[  115.350215] systemd[1]: Failed to lookup module alias 'autofs4': Function not implemented
[  115.380593] systemd[1]: systemd 240 running in system mode. (+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN -PCRE2 default-hierarchy=hybrid)
[  115.401073] systemd[1]: Detected architecture ppc64.
[  115.429616] systemd[1]: Set hostname to <t4240rdb>.
[  115.455850] systemd[1]: Failed to bump fs.file-max, ignoring: Invalid argument
[  115.861866] systemd[1]: File /lib/systemd/system/systemd-journald.service:12 configures an IP firewall (IPAddressDeny=any), but the local system does not support BPF/cgroup based firewalling.
[  115.877607] systemd[1]: Proceeding WITHOUT firewalling in effect! (This warning is only shown for the first loaded unit using IP firewalling.)
[  116.029117] systemd[1]: /lib/systemd/system/fancontrol.service:9: PIDFile= references path below legacy directory /var/run/, updating /var/run/fancontrol.pid → /run/fancontrol.pid; please update the unit file accordingly.
[  116.080232] systemd[1]: Created slice system-serial\x2dgetty.slice.
[  116.100793] systemd[1]: Reached target Remote File Systems.
[  116.120751] systemd[1]: Reached target Swap.
[  116.774505] systemd-journald[1440]: Received request to flush runtime journal from PID 1
[  117.323688] pcieport 0000:00:00.0: AER: Corrected error received: 0000:01:00.0
[  117.329694] e1000e 0000:01:00.0: AER: PCIe Bus Error: severity=Corrected, type=Data Link Layer, (Transmitter ID)
[  117.338582] e1000e 0000:01:00.0: AER:   device [8086:10d3] error status/mask=00001000/00002000
[  117.345919] e1000e 0000:01:00.0: AER:    [12] Timeout               
[  119.035056] pcieport 0000:00:00.0: AER: Corrected error received: 0000:01:00.0
[  119.042196] e1000e 0000:01:00.0: AER: PCIe Bus Error: severity=Corrected, type=Data Link Layer, (Transmitter ID)
[  119.052409] e1000e 0000:01:00.0: AER:   device [8086:10d3] error status/mask=00001000/00002000
[  119.061092] e1000e 0000:01:00.0: AER:    [12] Timeout               
[  119.066684] pcieport 0000:00:00.0: AER: Corrected error received: 0000:01:00.0
[  119.262731] pcieport 0000:00:00.0: AER: Corrected error received: 0000:01:00.0
[  119.268724] e1000e 0000:01:00.0: AER: PCIe Bus Error: severity=Corrected, type=Data Link Layer, (Transmitter ID)
[  119.277619] e1000e 0000:01:00.0: AER:   device [8086:10d3] error status/mask=00001000/00002000
[  119.284953] e1000e 0000:01:00.0: AER:    [12] Timeout               
[  119.486153] pcieport 0000:00:00.0: AER: Corrected error received: 0000:01:00.0
[  119.492124] e1000e 0000:01:00.0: AER: PCIe Bus Error: severity=Corrected, type=Data Link Layer, (Transmitter ID)
[  119.501054] e1000e 0000:01:00.0: AER:   device [8086:10d3] error status/mask=00001000/00002000
[  119.508399] e1000e 0000:01:00.0: AER:    [12] Timeout               
[  142.345527] pcieport 0000:00:00.0: AER: Corrected error received: 0000:01:00.0
[  142.351469] e1000e 0000:01:00.0: AER: PCIe Bus Error: severity=Corrected, type=Data Link Layer, (Transmitter ID)
[  142.360359] e1000e 0000:01:00.0: AER:   device [8086:10d3] error status/mask=00001000/00002000
[  142.367684] e1000e 0000:01:00.0: AER:    [12] Timeout               

[-- Attachment #3: Type: text/plain, Size: 8062 bytes --]



>
> -----------------------------------------------------
> phys_mem_size     = 0x200000000
> dcache_bsize      = 0x20
> icache_bsize      = 0x20
> cpu_features      = 0x00000003008003b6
>    possible        = 0x00000003009003b6
>    always          = 0x00000003008003b4
> cpu_user_features = 0xdc008000 0x08000000
> mmu_features      = 0x000a0010
> firmware_features = 0x0000000000000000
> physical_start    = 0x20000000
> -----------------------------------------------------
> barrier-nospec: using isync; sync as speculation barrier
> Zone ranges:
>    DMA      [mem 0x0000000000000000-0x000000007fffffff]
>    Normal   [mem 0x0000000080000000-0x00000001ffffffff]
> Movable zone start for each node
> Early memory node ranges
>    node   0: [mem 0x0000000000000000-0x00000001ffffffff]
> Initmem setup node 0 [mem 0x0000000000000000-0x00000001ffffffff]
> MMU: Allocated 2112 bytes of context maps for 255 contexts
> percpu: Embedded 32 pages/cpu s91736 r0 d39336 u131072
> Built 1 zonelists, mobility grouping on.  Total pages: 2064384
> Kernel command line: console=ttyS0 root=/dev/ram0
> printk: log_buf_len individual max cpu contribution: 16384 bytes
> printk: log_buf_len total cpu_extra contributions: 376832 bytes
> printk: log_buf_len min size: 131072 bytes
> printk: log_buf_len: 524288 bytes
> printk: early log buf free: 127460(97%)
> Dentry cache hash table entries: 1048576 (order: 11, 8388608 bytes, linear)
> Inode-cache hash table entries: 524288 (order: 10, 4194304 bytes, linear)
> mem auto-init: stack:off, heap alloc:off, heap free:off
> Memory: 8135632K/8388608K available (10572K kernel code, 2000K rwdata, 
> 3396K rodata, 4124K init, 358K bss, 252976K reserved, 0K cma-reserved)
> rcu: Hierarchical RCU implementation.
> rcu:    RCU event tracing is enabled.
> rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
> NR_IRQS: 512, nr_irqs: 512, preallocated irqs: 16
> mpic: Setting up MPIC " OpenPIC  " version 1.2 at fe0040000, max 24 CPUs
> mpic: ISU size: 256, shift: 8, mask: ff
> mpic: Initializing for 256 sources
> random: get_random_u64 called from .start_kernel+0x724/0x954 with 
> crng_init=0
> clocksource: timebase: mask: 0xffffffffffffffff max_cycles: 
> 0x5c4093a7d1, max_idle_ns: 440795210635 ns
> clocksource: timebase mult[2800000] shift[24] registered
> Console: colour dummy device 80x25
> pid_max: default: 32768 minimum: 301
> Mount-cache hash table entries: 16384 (order: 5, 131072 bytes, linear)
> Mountpoint-cache hash table entries: 16384 (order: 5, 131072 bytes, linear)
> e6500 family performance monitor hardware support registered
> rcu: Hierarchical SRCU implementation.
> smp: Bringing up secondary CPUs ...
> smp: Brought up 1 node, 24 CPUs
>
>
>
> 在 2020/4/25 1:17, Daniel Axtens 写道:
>> Hi Jason,
>> 
>> Apologies for the delay in testing.
>> 
>> I'm seeing this problem when I try to boot on a t4240rdb:
>> 
>> random: get_random_u64 called from .start_kernel+0x734/0x964 with crng_init=0                               [8/973]
>> clocksource: timebase: mask: 0xffffffffffffffff max_cycles: 0xa9210e89c, max_idle_ns: 440795203878 ns
>> clocksource: timebase mult[15d17460] shift[24] registered
>> Console: colour dummy device 80x25
>> pid_max: default: 32768 minimum: 301
>> Mount-cache hash table entries: 16384 (order: 5, 131072 bytes, linear)
>> Mountpoint-cache hash table entries: 16384 (order: 5, 131072 bytes, linear)
>> e6500 family performance monitor hardware support registered
>> rcu: Hierarchical SRCU implementation.
>> smp: Bringing up secondary CPUs ...
>> Processor 2 is stuck.
>> Processor 3 is stuck.
>> Processor 4 is stuck.
>> Processor 5 is stuck.
>> Processor 6 is stuck.
>> Processor 7 is stuck.
>> Processor 8 is stuck.
>> Processor 9 is stuck.
>> Processor 10 is stuck.
>> Processor 11 is stuck.
>> Processor 12 is stuck.
>> Processor 13 is stuck.
>> Processor 14 is stuck.
>> ...
>> Processor 22 is stuck.
>> Processor 23 is stuck.
>> smp: Brought up 1 node, 2 CPUs
>> Using standard scheduler topology
>> devtmpfs: initialized
>> clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
>> futex hash table entries: 8192 (order: 7, 524288 bytes, linear)
>> NET: Registered protocol family 16
>> audit: initializing netlink subsys (disabled)
>> audit: type=2000 audit(108.032:1): state=initialized audit_enabled=0 res=1
>> Machine: fsl,T4240RDB
>> SoC family: QorIQ T4240
>> SoC ID: svr:0x82480020, Revision: 2.0
>> ... boot continues ...
>> 
>> 
>> If I boot with nokaslr, all the CPUs come up with no issue.
>> 
>> This is on top of powerpc/merge at
>> 8299da600ad05b8aa0f15ec0f5f03bd40e37d6f0. If you'd like me to test any
>> debug patches I can do that.
>> 
>> I've attached my .config.
>> 
>> Regards,
>> Daniel
>> 
>> 
>> 
>>> This is a try to implement KASLR for Freescale BookE64 which is based on
>>> my earlier implementation for Freescale BookE32:
>>> https://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=131718&state=*
>>>
>>> The implementation for Freescale BookE64 is similar as BookE32. One
>>> difference is that Freescale BookE64 set up a TLB mapping of 1G during
>>> booting. Another difference is that ppc64 needs the kernel to be
>>> 64K-aligned. So we can randomize the kernel in this 1G mapping and make
>>> it 64K-aligned. This can save some code to creat another TLB map at
>>> early boot. The disadvantage is that we only have about 1G/64K = 16384
>>> slots to put the kernel in.
>>>
>>>      KERNELBASE
>>>
>>>            64K                     |--> kernel <--|
>>>             |                      |              |
>>>          +--+--+--+    +--+--+--+--+--+--+--+--+--+    +--+--+
>>>          |  |  |  |....|  |  |  |  |  |  |  |  |  |....|  |  |
>>>          +--+--+--+    +--+--+--+--+--+--+--+--+--+    +--+--+
>>>          |                         |                        1G
>>>          |----->   offset    <-----|
>>>
>>>                                kernstart_virt_addr
>>>
>>> I'm not sure if the slot numbers is enough or the design has any
>>> defects. If you have some better ideas, I would be happy to hear that.
>>>
>>> Thank you all.
>>>
>>> v4->v5:
>>>    Fix "-Werror=maybe-uninitialized" compile error.
>>>    Fix typo "similar as" -> "similar to".
>>> v3->v4:
>>>    Do not define __kaslr_offset as a fixed symbol. Reference __run_at_load and
>>>      __kaslr_offset by symbol instead of magic offsets.
>>>    Use IS_ENABLED(CONFIG_PPC32) instead of #ifdef CONFIG_PPC32.
>>>    Change kaslr-booke32 to kaslr-booke in index.rst
>>>    Switch some instructions to 64-bit.
>>> v2->v3:
>>>    Fix build error when KASLR is disabled.
>>> v1->v2:
>>>    Add __kaslr_offset for the secondary cpu boot up.
>>>
>>> Jason Yan (6):
>>>    powerpc/fsl_booke/kaslr: refactor kaslr_legal_offset() and
>>>      kaslr_early_init()
>>>    powerpc/fsl_booke/64: introduce reloc_kernel_entry() helper
>>>    powerpc/fsl_booke/64: implement KASLR for fsl_booke64
>>>    powerpc/fsl_booke/64: do not clear the BSS for the second pass
>>>    powerpc/fsl_booke/64: clear the original kernel if randomized
>>>    powerpc/fsl_booke/kaslr: rename kaslr-booke32.rst to kaslr-booke.rst
>>>      and add 64bit part
>>>
>>>   Documentation/powerpc/index.rst               |  2 +-
>>>   .../{kaslr-booke32.rst => kaslr-booke.rst}    | 35 ++++++-
>>>   arch/powerpc/Kconfig                          |  2 +-
>>>   arch/powerpc/kernel/exceptions-64e.S          | 23 +++++
>>>   arch/powerpc/kernel/head_64.S                 | 13 +++
>>>   arch/powerpc/kernel/setup_64.c                |  3 +
>>>   arch/powerpc/mm/mmu_decl.h                    | 23 +++--
>>>   arch/powerpc/mm/nohash/kaslr_booke.c          | 91 +++++++++++++------
>>>   8 files changed, 147 insertions(+), 45 deletions(-)
>>>   rename Documentation/powerpc/{kaslr-booke32.rst => kaslr-booke.rst} (59%)
>>>
>>> -- 
>>> 2.17.2

^ permalink raw reply

* Re: New powerpc vdso calling convention
From: Adhemerval Zanella @ 2020-04-27 13:09 UTC (permalink / raw)
  To: Nicholas Piggin, Rich Felker
  Cc: libc-alpha, musl, binutils, Andy Lutomirski, libc-dev,
	Thomas Gleixner, Vincenzo Frascino, linuxppc-dev
In-Reply-To: <1587872025.rtx2ygrmn0.astroid@bobo.none>



On 26/04/2020 00:41, Nicholas Piggin wrote:
> Excerpts from Rich Felker's message of April 26, 2020 9:11 am:
>> On Sun, Apr 26, 2020 at 08:58:19AM +1000, Nicholas Piggin wrote:
>>> Excerpts from Christophe Leroy's message of April 25, 2020 10:20 pm:
>>>>
>>>>
>>>> Le 25/04/2020 à 12:56, Nicholas Piggin a écrit :
>>>>> Excerpts from Christophe Leroy's message of April 25, 2020 5:47 pm:
>>>>>>
>>>>>>
>>>>>> Le 25/04/2020 à 07:22, Nicholas Piggin a écrit :
>>>>>>> As noted in the 'scv' thread, powerpc's vdso calling convention does not
>>>>>>> match the C ELF ABI calling convention (or the proposed scv convention).
>>>>>>> I think we could implement a new ABI by basically duplicating function
>>>>>>> entry points with different names.
>>>>>>
>>>>>> I think doing this is a real good idea.
>>>>>>
>>>>>> I've been working at porting powerpc VDSO to the GENERIC C VDSO, and the
>>>>>> main pitfall has been that our vdso calling convention is not compatible
>>>>>> with C calling convention, so we have go through an ASM entry/exit.
>>>>>>
>>>>>> See https://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=171469
>>>>>>
>>>>>> We should kill this error flag return through CR[SO] and get it the
>>>>>> "modern" way like other architectectures implementing the C VDSO: return
>>>>>> 0 when successfull, return -err when failed.
>>>>>
>>>>> Agreed.
>>>>>
>>>>>>> The ELF v2 ABI convention would suit it well, because the caller already
>>>>>>> requires the function address for ctr, so having it in r12 will
>>>>>>> eliminate the need for address calculation, which suits the vdso data
>>>>>>> page access.
>>>>>>>
>>>>>>> Is there a need for ELF v1 specific calls as well, or could those just be
>>>>>>> deprecated and remain on existing functions or required to use the ELF
>>>>>>> v2 calls using asm wrappers?
>>>>>>
>>>>>> What's ELF v1 and ELF v2 ? Is ELF v1 what PPC32 uses ? If so, I'd say
>>>>>> yes, it would be good to have it to avoid going through ASM in the middle.
>>>>>
>>>>> I'm not sure about PPC32. On PPC64, ELFv2 functions must be called with
>>>>> their address in r12 if called at their global entry point. ELFv1 have a
>>>>> function descriptor with call address and TOC in it, caller has to load
>>>>> the TOC if it's global.
>>>>>
>>>>> The vdso doesn't have TOC, it has one global address (the vdso data
>>>>> page) which it loads by calculating its own address.
>>>>>
>>>>> The kernel doesn't change the vdso based on whether it's called by a v1
>>>>> or v2 userspace (it doesn't really know itself and would have to export
>>>>> different functions). glibc has a hack to create something:
>>>>>
>>>>> # define VDSO_IFUNC_RET(value)                           \
>>>>>    ({                                                     \
>>>>>      static Elf64_FuncDesc vdso_opd = { .fd_toc = ~0x0 }; \
>>>>>      vdso_opd.fd_func = (Elf64_Addr)value;                \
>>>>>      &vdso_opd;                                           \
>>>>>    })
>>>>>
>>>>> If we could make something which links more like any other dso with
>>>>> ELFv1, that would be good. Otherwise I think v2 is preferable so it
>>>>> doesn't have to calculate its own address.
>>>>
>>>> I see the following in glibc. So looks like PPC32 is like PPC64 elfv1. 
>>>> By the way, they are talking about something not completely finished in 
>>>> the kernel. Can we finish it ?
>>>
>>> Possibly can. It seems like a good idea to fix all loose ends if we are 
>>> going to add new versions. Will have to check with the toolchain people 
>>> to make sure we're doing the right thing.
>>
>> "ELFv1" and "ELFv2" are PPC64-specific names for the old and new
>> version of the ELF psABI for PPC64. They have nothing at all to do
>> with PPC32 which is a completely different ABI from either.
> 
> Right, I'm just talking about those comments -- it seems like the kernel 
> vdso should contain an .opd section with function descriptors in it for
> elfv1 calls, rather than the hack it has now of creating one in the 
> caller's .data section.
> 
> But all that function descriptor code is gated by
> 
> #if (defined(__PPC64__) || defined(__powerpc64__)) && _CALL_ELF != 2
> 
> So it seems PPC32 does not use function descriptors but a direct pointer 
> to the entry point like PPC64 with ELFv2.

Yes, this hack is only for ELFv1.  The missing ODP has not been an issue 
or glibc because it has been using the inline assembly to emulate the 
functions call since initial vDSO support (INTERNAL_VSYSCALL_CALL_TYPE).
It just has become an issue when I added a ifunc optimization to 
gettimeofday so it can bypass the libc.so and make plt branch to vDSO 
directly.

Recently on some y2038 refactoring it was suggested to get rid of this 
and make gettimeofday call clock_gettime regardless.  But some felt that 
the performance degradation was not worth for a symbol that is still used
extensibility, so we stuck with the hack.

And I think having this synthetic opd entry is not an issue, since for 
full relro the program's will be used and correctly set as read-only.
The issue is more for glibc itself, and I wouldn't mind to just remove the
gettimeofday and time optimizations and use the default vDSO support
(which might increase in function latency though).

As Rich has put, it would be simpler to just have powerpc vDSO symbols
to have a default function call semantic so we could issue a function
call directly.  But for powerpc64, we glibc will need to continue to 
support this non-standard call on older kernels and I am not sure if
adding new symbols with a different semantic will help much.

GLibc already hides this powerpc semantic on INTERNAL_VSYSCALL_CALL_TYPE,
so internally all syscalls are assumed to have the new semantic (-errno
on error, 0 on success). Adding another ELFv1 would require to add
more logic to handle multiple symbol version for vDSO setup
(sysdeps/unix/sysv/linux/dl-vdso-setup.h), which would mostly likely to
require an arch-specific implementation to handle it.

^ permalink raw reply

* Re: [PATCH v2] ASoC: fsl_easrc: Check for null pointer before dereferencing "ctx" in fsl_easrc_hw_free()
From: Mark Brown @ 2020-04-27 13:09 UTC (permalink / raw)
  To: perex, timur, alsa-devel, tiwai, festevam, Shengjiu Wang,
	Xiubo.Lee, nicoleotsuka, lgirdwood
  Cc: linuxppc-dev, linux-kernel
In-Reply-To: <d23c939f1c9eeb3fce34b6c34d44e2d6156f663a.1587799355.git.shengjiu.wang@nxp.com>

On Sat, 25 Apr 2020 15:19:29 +0800, Shengjiu Wang wrote:
> The patch 955ac624058f: "ASoC: fsl_easrc: Add EASRC ASoC CPU DAI
> drivers" from Apr 16, 2020, leads to the following Smatch complaint:
> 
> sound/soc/fsl/fsl_easrc.c:1529 fsl_easrc_hw_free()
> warn: variable dereferenced before check 'ctx' (see line 1527)
> 
> sound/soc/fsl/fsl_easrc.c
>   1526          struct fsl_asrc_pair *ctx = runtime->private_data;
>   1527          struct fsl_easrc_ctx_priv *ctx_priv = ctx->private;
>                                                       ^^^^^
> Dereference
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.8

Thanks!

[1/1] ASoC: fsl_easrc: Check for null pointer before dereferencing "ctx" in fsl_easrc_hw_free()
      commit: f3fc1ea011f09156886e8f4beb240ea814f2197a

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply

* Re: [PATCH v2] ASoC: fsl_esai: Disable exception interrupt before scheduling tasklet
From: Mark Brown @ 2020-04-27 12:06 UTC (permalink / raw)
  To: festevam, Xiubo.Lee, nicoleotsuka, timur, Shengjiu Wang,
	alsa-devel, tiwai, perex
  Cc: linuxppc-dev, linux-kernel
In-Reply-To: <a8f2ad955aac9e52587beedc1133b3efbe746895.1587968824.git.shengjiu.wang@nxp.com>

On Mon, 27 Apr 2020 14:23:21 +0800, Shengjiu Wang wrote:
> Disable exception interrupt before scheduling tasklet, otherwise if
> the tasklet isn't handled immediately, there will be endless xrun
> interrupt.
> 
> Fixes: 7ccafa2b3879 ("ASoC: fsl_esai: recover the channel swap after xrun")
> Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
> Acked-by: Nicolin Chen <nicoleotsuka@gmail.com>
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.7

Thanks!

[1/1] ASoC: fsl_esai: Disable exception interrupt before scheduling tasklet
      commit: 1fecbb71fe0e46b886f84e3b6decca6643c3af6d

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply

* Re: [RFC 1/3] powernv/cpuidle : Support for pre-entry and post exit of stop state in firmware
From: Gautham R Shenoy @ 2020-04-27 10:26 UTC (permalink / raw)
  To: Abhishek Goel
  Cc: ego, mikey, linux-kernel, npiggin, linuxppc-dev, oohall, psampat
In-Reply-To: <20200427021027.114582-1-huntbag@linux.vnet.ibm.com>

Hi Abhishek,

On Sun, Apr 26, 2020 at 09:10:25PM -0500, Abhishek Goel wrote:
> This patch provides kernel framework fro opal support of save restore
> of sprs in idle stop loop. Opal support for stop states is needed to
> selectively enable stop states or to introduce a quirk quickly in case
> a buggy stop state is present.
> 
> We make a opal call from kernel if firmware-stop-support for stop
> states is present and enabled. All the quirks for pre-entry of stop
> state is handled inside opal. A call from opal is made into kernel
> where we execute stop afer saving of NVGPRs.
> After waking up from 0x100 vector in kernel, we enter back into opal.
> All the quirks in post exit path, if any, are then handled in opal,
> from where we return successfully back to kernel.
> For deep stop states in which additional SPRs are lost, saving and
> restoration will be done in OPAL.
> 
> This idea was first proposed by Nick here:
> https://patchwork.ozlabs.org/patch/1208159/
> 
> The corresponding skiboot patch for this kernel patch is here:
> https://patchwork.ozlabs.org/project/skiboot/list/?series=172831
> 
> When we callback from OPAL into kernel, r13 is clobbered. So, to
> access PACA we need to restore it from HSPRGO. In future we can
> handle this into OPAL as in here:
> https://patchwork.ozlabs.org/patch/1245275/
> 
> Signed-off-by: Abhishek Goel <huntbag@linux.vnet.ibm.com>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
> 
>  v1->v2 : No change in this patch.
> 
>  arch/powerpc/include/asm/opal-api.h        |  8 ++++-
>  arch/powerpc/include/asm/opal.h            |  3 ++
>  arch/powerpc/kernel/idle_book3s.S          |  5 +++
>  arch/powerpc/platforms/powernv/idle.c      | 37 ++++++++++++++++++++++
>  arch/powerpc/platforms/powernv/opal-call.c |  2 ++
>  5 files changed, 54 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/include/asm/opal-api.h b/arch/powerpc/include/asm/opal-api.h
> index c1f25a760eb1..a2c782c99c9e 100644
> --- a/arch/powerpc/include/asm/opal-api.h
> +++ b/arch/powerpc/include/asm/opal-api.h
> @@ -214,7 +214,9 @@
>  #define OPAL_SECVAR_GET				176
>  #define OPAL_SECVAR_GET_NEXT			177
>  #define OPAL_SECVAR_ENQUEUE_UPDATE		178
> -#define OPAL_LAST				178
> +#define OPAL_REGISTER_OS_OPS			181
> +#define OPAL_CPU_IDLE				182
> +#define OPAL_LAST				182
> 
>  #define QUIESCE_HOLD			1 /* Spin all calls at entry */
>  #define QUIESCE_REJECT			2 /* Fail all calls with OPAL_BUSY */
> @@ -1181,6 +1183,10 @@ struct opal_mpipl_fadump {
>  	struct	opal_mpipl_region region[];
>  } __packed;
> 
> +struct opal_os_ops {
> +	__be64 os_idle_stop;
> +};
> +
>  #endif /* __ASSEMBLY__ */
> 
>  #endif /* __OPAL_API_H */
> diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
> index 9986ac34b8e2..3c340bc4df8e 100644
> --- a/arch/powerpc/include/asm/opal.h
> +++ b/arch/powerpc/include/asm/opal.h
> @@ -400,6 +400,9 @@ void opal_powercap_init(void);
>  void opal_psr_init(void);
>  void opal_sensor_groups_init(void);
> 
> +extern int64_t opal_register_os_ops(struct opal_os_ops *os_ops);
> +extern int64_t opal_cpu_idle(__be64 srr1_addr, uint64_t psscr);
> +
>  #endif /* __ASSEMBLY__ */
> 
>  #endif /* _ASM_POWERPC_OPAL_H */
> diff --git a/arch/powerpc/kernel/idle_book3s.S b/arch/powerpc/kernel/idle_book3s.S
> index 22f249b6f58d..8d287d1d06c0 100644
> --- a/arch/powerpc/kernel/idle_book3s.S
> +++ b/arch/powerpc/kernel/idle_book3s.S
> @@ -49,6 +49,8 @@ _GLOBAL(isa300_idle_stop_noloss)
>   */
>  _GLOBAL(isa300_idle_stop_mayloss)
>  	mtspr 	SPRN_PSSCR,r3
> +	mr	r6, r13
> +	mfspr	r13, SPRN_HSPRG0
>  	std	r1,PACAR1(r13)
>  	mflr	r4
>  	mfcr	r5
> @@ -74,6 +76,7 @@ _GLOBAL(isa300_idle_stop_mayloss)
>  	std	r31,-8*18(r1)
>  	std	r4,-8*19(r1)
>  	std	r5,-8*20(r1)
> +	std	r6,-8*21(r1)
>  	/* 168 bytes */
>  	PPC_STOP
>  	b	.	/* catch bugs */
> @@ -91,8 +94,10 @@ _GLOBAL(idle_return_gpr_loss)
>  	ld	r1,PACAR1(r13)
>  	ld	r4,-8*19(r1)
>  	ld	r5,-8*20(r1)
> +	ld	r6,-8*21(r1)
>  	mtlr	r4
>  	mtcr	r5
> +	mr	r13,r6
>  	/*
>  	 * KVM nap requires r2 to be saved, rather than just restoring it
>  	 * from PACATOC. This could be avoided for that less common case
> diff --git a/arch/powerpc/platforms/powernv/idle.c b/arch/powerpc/platforms/powernv/idle.c
> index 78599bca66c2..1841027b25c5 100644
> --- a/arch/powerpc/platforms/powernv/idle.c
> +++ b/arch/powerpc/platforms/powernv/idle.c
> @@ -35,6 +35,7 @@
>  static u32 supported_cpuidle_states;
>  struct pnv_idle_states_t *pnv_idle_states;
>  int nr_pnv_idle_states;
> +static bool firmware_stop_supported;
> 
>  /*
>   * The default stop state that will be used by ppc_md.power_save
> @@ -602,6 +603,25 @@ struct p9_sprs {
>  	u64 uamor;
>  };
> 
> +/*
> + * This function is called from OPAL if firmware support for stop
> + * states is present and enabled. It provides a fallback for idle
> + * stop states via OPAL.
> + */
> +static uint64_t os_idle_stop(uint64_t psscr, bool save_gprs)
> +{
> +	/*
> +	 * For lite state which does not lose even GPRS we call
> +	 * idle_stop_noloss while for all other states we call
> +	 * idle_stop_mayloss. Saving and restoration of other additional
> +	 * SPRs if required is handled in OPAL. All the quirks are also
> +	 * handled in OPAL.
> +	 */
> +	if (!save_gprs)
> +		return isa300_idle_stop_noloss(psscr);

I think PSSCR[ESL|EC] = 0 case is an overkill to go into OPAL and come
back via a callback. That can be handled in the kernel itself.



> +	return isa300_idle_stop_mayloss(psscr);
> +}
> +
>  static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
>  {
>  	int cpu = raw_smp_processor_id();
> @@ -613,6 +633,16 @@ static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
>  	unsigned long mmcr0 = 0;
>  	struct p9_sprs sprs = {}; /* avoid false used-uninitialised */
>  	bool sprs_saved = false;
> +	int rc = 0;
> +
> +	/*
> +	 * Kernel takes decision whether to make OPAL call or not. This logic
> +	 * will be combined with the logic for BE opal to take decision.
> +	 */
> +	if (firmware_stop_supported) {
> +		rc = opal_cpu_idle(cpu_to_be64(__pa(&srr1)), (uint64_t) psscr);

Couple of comments here. 

   1) If PSSCR[ESL|EC] = 0, the current code expects mmu_on=true. When
      we make an OPAL call and come back into the kernel via the
      callback today, we will be in real-mode, with mmu turned off.

   2) You seem to be choosing the opal cpuidle support as the default
      case, and not as a fallback. Thus, with this patch you will miss
      out on the deep stop-state support.


> +		goto out;
> +	}
> 
>  	if (!(psscr & (PSSCR_EC|PSSCR_ESL))) {
>  		/* EC=ESL=0 case */
> @@ -1232,6 +1262,10 @@ static int pnv_parse_cpuidle_dt(void)
>  		pr_warn("opal: PowerMgmt Node not found\n");
>  		return -ENODEV;
>  	}
> +
> +	if (of_device_is_compatible(np, "firmware-stop-supported"))
> +		firmware_stop_supported = true;

IMO, at least for POWER9 generation, you need to do this only when
"idle-stop" device-tree cpu-feature is unavailable.


> +
>  	nr_idle_states = of_property_count_u32_elems(np,
>  						"ibm,cpu-idle-state-flags");
> 
> @@ -1326,6 +1360,7 @@ static int pnv_parse_cpuidle_dt(void)
> 
>  static int __init pnv_init_idle_states(void)
>  {
> +	struct opal_os_ops os_ops;
>  	int cpu;
>  	int rc = 0;
> 
> @@ -1349,6 +1384,8 @@ static int __init pnv_init_idle_states(void)
>  		}
>  	}
> 
> +	os_ops.os_idle_stop = be64_to_cpu(os_idle_stop);
> +	rc = opal_register_os_ops((struct opal_os_ops *)(&os_ops));
>  	/* In case we error out nr_pnv_idle_states will be zero */
>  	nr_pnv_idle_states = 0;
>  	supported_cpuidle_states = 0;
> diff --git a/arch/powerpc/platforms/powernv/opal-call.c b/arch/powerpc/platforms/powernv/opal-call.c
> index 5cd0f52d258f..c885e607ba62 100644
> --- a/arch/powerpc/platforms/powernv/opal-call.c
> +++ b/arch/powerpc/platforms/powernv/opal-call.c
> @@ -293,3 +293,5 @@ OPAL_CALL(opal_mpipl_query_tag,			OPAL_MPIPL_QUERY_TAG);
>  OPAL_CALL(opal_secvar_get,			OPAL_SECVAR_GET);
>  OPAL_CALL(opal_secvar_get_next,			OPAL_SECVAR_GET_NEXT);
>  OPAL_CALL(opal_secvar_enqueue_update,		OPAL_SECVAR_ENQUEUE_UPDATE);
> +OPAL_CALL(opal_register_os_ops,			OPAL_REGISTER_OS_OPS);
> +OPAL_CALL(opal_cpu_idle,			OPAL_CPU_IDLE);
> -- 
> 2.17.1
> 

^ permalink raw reply

* [RFC PATCH 19/25] powerpc/book3s64/kuap: Restrict access to userspace based on userspace AMR
From: Aneesh Kumar K.V @ 2020-04-27  8:05 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

If an application has configured address protection such that read/write is
denied using pkey even the kernel should receive a FAULT on accessing the same.

This patch use user AMR value stored in pt_regs.kuap to achieve the same.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/include/asm/book3s/64/kup.h | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/kup.h b/arch/powerpc/include/asm/book3s/64/kup.h
index 6a706e6fef59..590c1d9455d1 100644
--- a/arch/powerpc/include/asm/book3s/64/kup.h
+++ b/arch/powerpc/include/asm/book3s/64/kup.h
@@ -242,14 +242,20 @@ static inline void set_kuap(unsigned long value)
 static __always_inline void allow_user_access(void __user *to, const void __user *from,
 					      unsigned long size, unsigned long dir)
 {
+	unsigned long thread_amr = 0;
+
 	// This is written so we can resolve to a single case at build time
 	BUILD_BUG_ON(!__builtin_constant_p(dir));
+
+	if (mmu_has_feature(MMU_FTR_PKEY))
+		thread_amr = current_thread_amr();
+
 	if (dir == KUAP_READ)
-		set_kuap(AMR_KUAP_BLOCK_WRITE);
+		set_kuap(thread_amr | AMR_KUAP_BLOCK_WRITE);
 	else if (dir == KUAP_WRITE)
-		set_kuap(AMR_KUAP_BLOCK_READ);
+		set_kuap(thread_amr | AMR_KUAP_BLOCK_READ);
 	else if (dir == KUAP_READ_WRITE)
-		set_kuap(0);
+		set_kuap(thread_amr);
 	else
 		BUILD_BUG();
 }
-- 
2.25.3


^ permalink raw reply related

* [RFC PATCH 24/25] powerpc/book3s64/hash/kuep: Enable KUEP on hash
From: Aneesh Kumar K.V @ 2020-04-27  8:05 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/mm/book3s64/pkeys.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/mm/book3s64/pkeys.c b/arch/powerpc/mm/book3s64/pkeys.c
index 40b6240ecc89..a1952ee6668e 100644
--- a/arch/powerpc/mm/book3s64/pkeys.c
+++ b/arch/powerpc/mm/book3s64/pkeys.c
@@ -219,7 +219,12 @@ void __init pkey_early_init_devtree(void)
 #ifdef CONFIG_PPC_KUEP
 void setup_kuep(bool disabled)
 {
-	if (disabled || !early_radix_enabled())
+	if (disabled)
+		return;
+	/*
+	 * On hash if PKEY feature is not enabled, disable KUAP too.
+	 */
+	if (!early_radix_enabled() && !early_mmu_has_feature(MMU_FTR_PKEY))
 		return;
 
 	if (smp_processor_id() == boot_cpuid) {
-- 
2.25.3


^ permalink raw reply related

* [RFC PATCH 22/25] powerpc/book3s64/kuep: Use Key 3 to implement KUEP with hash translation.
From: Aneesh Kumar K.V @ 2020-04-27  8:05 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

Radix use IAMR Key 0 and hash translation use IAMR key 3.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/include/asm/book3s/64/kup.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/book3s/64/kup.h b/arch/powerpc/include/asm/book3s/64/kup.h
index 7ccbe2653273..ae03b6341f88 100644
--- a/arch/powerpc/include/asm/book3s/64/kup.h
+++ b/arch/powerpc/include/asm/book3s/64/kup.h
@@ -7,7 +7,7 @@
 
 #define AMR_KUAP_BLOCK_READ	UL(0x5455555555555555)
 #define AMR_KUAP_BLOCK_WRITE	UL(0xa8aaaaaaaaaaaaaa)
-#define AMR_KUEP_BLOCKED	(1UL << 62)
+#define AMR_KUEP_BLOCKED	UL(0x5455555555555555)
 #define AMR_KUAP_BLOCKED	(AMR_KUAP_BLOCK_READ | AMR_KUAP_BLOCK_WRITE)
 
 #ifdef __ASSEMBLY__
-- 
2.25.3


^ permalink raw reply related

* [RFC PATCH 25/25] powerpc/book3s64/keys: Print information during boot.
From: Aneesh Kumar K.V @ 2020-04-27  8:05 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/mm/book3s64/pkeys.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/mm/book3s64/pkeys.c b/arch/powerpc/mm/book3s64/pkeys.c
index a1952ee6668e..660e0691db07 100644
--- a/arch/powerpc/mm/book3s64/pkeys.c
+++ b/arch/powerpc/mm/book3s64/pkeys.c
@@ -207,6 +207,7 @@ void __init pkey_early_init_devtree(void)
 	 */
 	initial_allocation_mask |= reserved_allocation_mask;
 
+	pr_info("Enabling Memory keys with max key count %d", max_pkey);
 err_out:
 	/*
 	 * Setup uamor on boot cpu
-- 
2.25.3


^ permalink raw reply related

* [RFC PATCH 21/25] powerpc/book3s64/kuap: Use Key 3 to implement KUAP with hash translation.
From: Aneesh Kumar K.V @ 2020-04-27  8:05 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

Radix use AMR Key 0 and hash translation use AMR key 3.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/include/asm/book3s/64/kup.h | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/kup.h b/arch/powerpc/include/asm/book3s/64/kup.h
index f564d909e195..7ccbe2653273 100644
--- a/arch/powerpc/include/asm/book3s/64/kup.h
+++ b/arch/powerpc/include/asm/book3s/64/kup.h
@@ -5,11 +5,10 @@
 #include <linux/const.h>
 #include <asm/reg.h>
 
-#define AMR_KUAP_BLOCK_READ	UL(0x4000000000000000)
-#define AMR_KUAP_BLOCK_WRITE	UL(0x8000000000000000)
+#define AMR_KUAP_BLOCK_READ	UL(0x5455555555555555)
+#define AMR_KUAP_BLOCK_WRITE	UL(0xa8aaaaaaaaaaaaaa)
 #define AMR_KUEP_BLOCKED	(1UL << 62)
 #define AMR_KUAP_BLOCKED	(AMR_KUAP_BLOCK_READ | AMR_KUAP_BLOCK_WRITE)
-#define AMR_KUAP_SHIFT		62
 
 #ifdef __ASSEMBLY__
 
@@ -63,8 +62,8 @@
 #ifdef CONFIG_PPC_KUAP_DEBUG
 	BEGIN_MMU_FTR_SECTION_NESTED(67)
 	mfspr	\gpr1, SPRN_AMR
-	li	\gpr2, (AMR_KUAP_BLOCKED >> AMR_KUAP_SHIFT)
-	sldi	\gpr2, \gpr2, AMR_KUAP_SHIFT
+	/* Prevent access to userspace using any key values */
+	LOAD_REG_IMMEDIATE(\gpr2, AMR_KUAP_BLOCKED)
 999:	tdne	\gpr1, \gpr2
 	EMIT_BUG_ENTRY 999b, __FILE__, __LINE__, (BUGFLAG_WARNING | BUGFLAG_ONCE)
 	END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_KUAP, 67)
-- 
2.25.3


^ permalink raw reply related

* [RFC PATCH 20/25] powerpc/book3s64/kuap: Improve error reporting with KUAP
From: Aneesh Kumar K.V @ 2020-04-27  8:05 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

With hash translation use DSISR_KEYFAULT to identify a wrong access.
With Radix we look at the AMR value and type of fault.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/include/asm/book3s/64/kup.h |  7 ------
 arch/powerpc/mm/fault.c                  | 27 +++++++++++++++++++++++-
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/kup.h b/arch/powerpc/include/asm/book3s/64/kup.h
index 590c1d9455d1..f564d909e195 100644
--- a/arch/powerpc/include/asm/book3s/64/kup.h
+++ b/arch/powerpc/include/asm/book3s/64/kup.h
@@ -280,13 +280,6 @@ static inline void restore_user_access(unsigned long flags)
 	set_kuap(flags);
 }
 
-static inline bool
-bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
-{
-	return WARN(mmu_has_feature(MMU_FTR_KUAP) &&
-		    (regs->kuap & (is_write ? AMR_KUAP_BLOCK_WRITE : AMR_KUAP_BLOCK_READ)),
-		    "Bug: %s fault blocked by AMR!", is_write ? "Write" : "Read");
-}
 #else /* CONFIG_PPC_KUAP */
 static inline void kuap_restore_amr(struct pt_regs *regs)
 {
diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index 84af6c8eecf7..4f866b11512c 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -198,6 +198,31 @@ static int mm_fault_error(struct pt_regs *regs, unsigned long addr,
 	return 0;
 }
 
+#define RADIX_KUAP_BLOCK_READ	UL(0x4000000000000000)
+#define RADIX_KUAP_BLOCK_WRITE	UL(0x8000000000000000)
+
+static bool bad_kuap_fault(struct pt_regs *regs, unsigned long address,
+			   bool is_write, unsigned long error_code)
+{
+	if (!mmu_has_feature(MMU_FTR_KUAP))
+		return false;
+
+	if (radix_enabled()) {
+		/*
+		 * Will be a storage protection fault.
+		 * Only check the details of AMR[0]
+		 */
+		return WARN((regs->kuap & (is_write ? RADIX_KUAP_BLOCK_WRITE : RADIX_KUAP_BLOCK_READ)),
+			    "Bug: %s fault blocked by AMR!", is_write ? "Write" : "Read");
+	}
+	/*
+	 * We don't want to WARN here because userspace can setup
+	 * keys such that a kernel access to user address can cause
+	 * fault
+	 */
+	return !!(error_code & DSISR_KEYFAULT);
+}
+
 /* Is this a bad kernel fault ? */
 static bool bad_kernel_fault(struct pt_regs *regs, unsigned long error_code,
 			     unsigned long address, bool is_write)
@@ -233,7 +258,7 @@ static bool bad_kernel_fault(struct pt_regs *regs, unsigned long error_code,
 
 	// Read/write fault in a valid region (the exception table search passed
 	// above), but blocked by KUAP is bad, it can never succeed.
-	if (bad_kuap_fault(regs, address, is_write))
+	if (bad_kuap_fault(regs, address, is_write, error_code))
 		return true;
 
 	// What's left? Kernel fault on user in well defined regions (extable
-- 
2.25.3


^ permalink raw reply related

* [RFC PATCH 23/25] powerpc/book3s64/hash/kuap: Enable kuap on hash
From: Aneesh Kumar K.V @ 2020-04-27  8:05 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/mm/book3s64/pkeys.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/mm/book3s64/pkeys.c b/arch/powerpc/mm/book3s64/pkeys.c
index 2484d8502499..40b6240ecc89 100644
--- a/arch/powerpc/mm/book3s64/pkeys.c
+++ b/arch/powerpc/mm/book3s64/pkeys.c
@@ -240,7 +240,12 @@ void setup_kuep(bool disabled)
 #ifdef CONFIG_PPC_KUAP
 void setup_kuap(bool disabled)
 {
-	if (disabled || !early_radix_enabled())
+	if (disabled)
+		return;
+	/*
+	 * On hash if PKEY feature is not enabled, disable KUAP too.
+	 */
+	if (!early_radix_enabled() && !early_mmu_has_feature(MMU_FTR_PKEY))
 		return;
 
 	if (smp_processor_id() == boot_cpuid) {
-- 
2.25.3


^ permalink raw reply related

* [RFC PATCH 18/25] powerpc/book3s64/pkeys: Don't update SPRN_AMR when in kernel mode.
From: Aneesh Kumar K.V @ 2020-04-27  8:04 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

Now that kernel correctly store/restore userspace AMR/IAMR values, avoid
manipulating AMR and IAMR from the kernel on behalf of userspace.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/include/asm/book3s/64/kup.h | 27 +++++++++
 arch/powerpc/include/asm/pkeys.h         |  2 -
 arch/powerpc/include/asm/processor.h     |  5 --
 arch/powerpc/kernel/process.c            |  4 --
 arch/powerpc/kernel/traps.c              |  6 --
 arch/powerpc/mm/book3s64/pkeys.c         | 73 ++++--------------------
 6 files changed, 39 insertions(+), 78 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/kup.h b/arch/powerpc/include/asm/book3s/64/kup.h
index 717c2c4d3681..6a706e6fef59 100644
--- a/arch/powerpc/include/asm/book3s/64/kup.h
+++ b/arch/powerpc/include/asm/book3s/64/kup.h
@@ -158,6 +158,33 @@
 #include <asm/mmu.h>
 #include <asm/ptrace.h>
 
+extern u64 default_uamor;
+extern u64 default_amr;
+extern u64 default_iamr;
+
+/*
+ * For kernel thread that doesn't have thread.regs return
+ * default AMR/IAMR values.
+ */
+static inline u64 current_thread_amr(void)
+{
+	if (current->thread.regs)
+		return current->thread.regs->kuap;
+	return AMR_KUAP_BLOCKED;
+}
+
+static inline u64 current_thread_iamr(void)
+{
+	if (current->thread.regs)
+		return current->thread.regs->kuep;
+	return AMR_KUEP_BLOCKED;
+}
+
+static inline u64 read_uamor(void)
+{
+	return default_uamor;
+}
+
 static inline void kuap_restore_amr(struct pt_regs *regs, bool to_user)
 {
 	if (!mmu_has_feature(MMU_FTR_PKEY) && to_user)
diff --git a/arch/powerpc/include/asm/pkeys.h b/arch/powerpc/include/asm/pkeys.h
index cd1a03044814..b1d448c53209 100644
--- a/arch/powerpc/include/asm/pkeys.h
+++ b/arch/powerpc/include/asm/pkeys.h
@@ -12,8 +12,6 @@
 #include <asm/firmware.h>
 
 extern int max_pkey;
-extern u64 default_uamor;
-extern u64 default_amr;
 extern u32 reserved_allocation_mask; /* bits set for reserved keys */
 
 #define ARCH_VM_PKEY_FLAGS (VM_PKEY_BIT0 | VM_PKEY_BIT1 | VM_PKEY_BIT2 | \
diff --git a/arch/powerpc/include/asm/processor.h b/arch/powerpc/include/asm/processor.h
index eedcbfb9a6ff..3cef707b27c7 100644
--- a/arch/powerpc/include/asm/processor.h
+++ b/arch/powerpc/include/asm/processor.h
@@ -234,11 +234,6 @@ struct thread_struct {
 	struct thread_vr_state ckvr_state; /* Checkpointed VR state */
 	unsigned long	ckvrsave; /* Checkpointed VRSAVE */
 #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
-#ifdef CONFIG_PPC_MEM_KEYS
-	unsigned long	amr;
-	unsigned long	iamr;
-	unsigned long	uamor;
-#endif
 #ifdef CONFIG_KVM_BOOK3S_32_HANDLER
 	void*		kvm_shadow_vcpu; /* KVM internal data */
 #endif /* CONFIG_KVM_BOOK3S_32_HANDLER */
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 9660bab1d99d..17f65a2738bc 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -585,7 +585,6 @@ static void save_all(struct task_struct *tsk)
 		__giveup_spe(tsk);
 
 	msr_check_and_clear(msr_all_available);
-	thread_pkey_regs_save(&tsk->thread);
 }
 
 void flush_all_to_thread(struct task_struct *tsk)
@@ -1097,8 +1096,6 @@ static inline void save_sprs(struct thread_struct *t)
 		t->tar = mfspr(SPRN_TAR);
 	}
 #endif
-
-	thread_pkey_regs_save(t);
 }
 
 static inline void restore_sprs(struct thread_struct *old_thread,
@@ -1139,7 +1136,6 @@ static inline void restore_sprs(struct thread_struct *old_thread,
 		mtspr(SPRN_TIDR, new_thread->tidr);
 #endif
 
-	thread_pkey_regs_restore(new_thread, old_thread);
 }
 
 struct task_struct *__switch_to(struct task_struct *prev,
diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 3fca22276bb1..a47fb49b7af8 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -348,12 +348,6 @@ static bool exception_common(int signr, struct pt_regs *regs, int code,
 
 	current->thread.trap_nr = code;
 
-	/*
-	 * Save all the pkey registers AMR/IAMR/UAMOR. Eg: Core dumps need
-	 * to capture the content, if the task gets killed.
-	 */
-	thread_pkey_regs_save(&current->thread);
-
 	return true;
 }
 
diff --git a/arch/powerpc/mm/book3s64/pkeys.c b/arch/powerpc/mm/book3s64/pkeys.c
index 42ca7aa09d5b..2484d8502499 100644
--- a/arch/powerpc/mm/book3s64/pkeys.c
+++ b/arch/powerpc/mm/book3s64/pkeys.c
@@ -21,7 +21,7 @@ int  max_pkey;			/* Maximum key value supported */
 u32  reserved_allocation_mask;
 static u32  initial_allocation_mask;   /* Bits set for the initially allocated keys */
 u64 default_amr;
-static u64 default_iamr;
+u64 default_iamr;
 /* Allow all keys to be modified by default */
 u64 default_uamor = ~0x0UL;
 /*
@@ -264,40 +264,17 @@ void pkey_mm_init(struct mm_struct *mm)
 	mm->context.execute_only_pkey = execute_only_key;
 }
 
-static inline u64 read_amr(void)
+static inline void update_current_thread_amr(u64 value)
 {
-	return mfspr(SPRN_AMR);
+	current->thread.regs->kuap = value;
 }
 
-static inline void write_amr(u64 value)
-{
-	mtspr(SPRN_AMR, value);
-}
-
-static inline u64 read_iamr(void)
-{
-	if (static_branch_unlikely(&execute_pkey_disabled))
-		return 0x0UL;
-
-	return mfspr(SPRN_IAMR);
-}
-
-static inline void write_iamr(u64 value)
+static inline void update_current_thread_iamr(u64 value)
 {
 	if (static_branch_unlikely(&execute_pkey_disabled))
 		return;
 
-	mtspr(SPRN_IAMR, value);
-}
-
-static inline u64 read_uamor(void)
-{
-	return mfspr(SPRN_UAMOR);
-}
-
-static inline void write_uamor(u64 value)
-{
-	mtspr(SPRN_UAMOR, value);
+	current->thread.regs->kuep = value;
 }
 
 static bool is_pkey_enabled(int pkey)
@@ -314,20 +291,21 @@ static bool is_pkey_enabled(int pkey)
 	return !!(uamor_pkey_bits);
 }
 
+/*  FIXME!! what happens to other threads AMR value? */
 static inline void init_amr(int pkey, u8 init_bits)
 {
 	u64 new_amr_bits = (((u64)init_bits & 0x3UL) << pkeyshift(pkey));
-	u64 old_amr = read_amr() & ~((u64)(0x3ul) << pkeyshift(pkey));
+	u64 old_amr = current_thread_amr() & ~((u64)(0x3ul) << pkeyshift(pkey));
 
-	write_amr(old_amr | new_amr_bits);
+	update_current_thread_amr(old_amr | new_amr_bits);
 }
 
 static inline void init_iamr(int pkey, u8 init_bits)
 {
 	u64 new_iamr_bits = (((u64)init_bits & 0x1UL) << pkeyshift(pkey));
-	u64 old_iamr = read_iamr() & ~((u64)(0x1ul) << pkeyshift(pkey));
+	u64 old_iamr = current_thread_iamr() & ~((u64)(0x1ul) << pkeyshift(pkey));
 
-	write_iamr(old_iamr | new_iamr_bits);
+	update_current_thread_iamr(old_iamr | new_iamr_bits);
 }
 
 /*
@@ -360,33 +338,6 @@ int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
 	return 0;
 }
 
-void thread_pkey_regs_save(struct thread_struct *thread)
-{
-	if (!mmu_has_feature(MMU_FTR_PKEY))
-		return;
-
-	/*
-	 * TODO: Skip saving registers if @thread hasn't used any keys yet.
-	 */
-	thread->amr = read_amr();
-	thread->iamr = read_iamr();
-	thread->uamor = read_uamor();
-}
-
-void thread_pkey_regs_restore(struct thread_struct *new_thread,
-			      struct thread_struct *old_thread)
-{
-	if (!mmu_has_feature(MMU_FTR_PKEY))
-		return;
-
-	if (old_thread->amr != new_thread->amr)
-		write_amr(new_thread->amr);
-	if (old_thread->iamr != new_thread->iamr)
-		write_iamr(new_thread->iamr);
-	if (old_thread->uamor != new_thread->uamor)
-		write_uamor(new_thread->uamor);
-}
-
 int execute_only_pkey(struct mm_struct *mm)
 {
 	if (static_branch_likely(&execute_pkey_disabled))
@@ -440,10 +391,10 @@ static bool pkey_access_permitted(int pkey, bool write, bool execute)
 		return true;
 
 	pkey_shift = pkeyshift(pkey);
-	if (execute && !(read_iamr() & (IAMR_EX_BIT << pkey_shift)))
+	if (execute && !(current_thread_iamr() & (IAMR_EX_BIT << pkey_shift)))
 		return true;
 
-	amr = read_amr(); /* Delay reading amr until absolutely needed */
+	amr = current_thread_amr();
 	return ((!write && !(amr & (AMR_RD_BIT << pkey_shift))) ||
 		(write &&  !(amr & (AMR_WR_BIT << pkey_shift))));
 }
-- 
2.25.3


^ permalink raw reply related

* [RFC PATCH 17/25] powerpc/ptrace-view: Use pt_regs values instead of thread_struct based one.
From: Aneesh Kumar K.V @ 2020-04-27  8:04 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

We will remove thread.amr/iamr/uamor in a later patch

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/kernel/ptrace/ptrace-view.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kernel/ptrace/ptrace-view.c b/arch/powerpc/kernel/ptrace/ptrace-view.c
index 15e3b79b6395..5b7bea41c699 100644
--- a/arch/powerpc/kernel/ptrace/ptrace-view.c
+++ b/arch/powerpc/kernel/ptrace/ptrace-view.c
@@ -488,14 +488,25 @@ static int pkey_active(struct task_struct *target, const struct user_regset *reg
 static int pkey_get(struct task_struct *target, const struct user_regset *regset,
 		    unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf)
 {
-	BUILD_BUG_ON(TSO(amr) + sizeof(unsigned long) != TSO(iamr));
-	BUILD_BUG_ON(TSO(iamr) + sizeof(unsigned long) != TSO(uamor));
+	int ret;
 
 	if (!arch_pkeys_enabled())
 		return -ENODEV;
 
-	return user_regset_copyout(&pos, &count, &kbuf, &ubuf, &target->thread.amr,
-				   0, ELF_NPKEY * sizeof(unsigned long));
+	ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &target->thread.regs->kuap,
+				  0, 1 * sizeof(unsigned long));
+	if (ret)
+		goto err_out;
+
+	ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &target->thread.regs->kuep,
+				  1 * sizeof(unsigned long), 2 * sizeof(unsigned long));
+	if (ret)
+		goto err_out;
+
+	ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &default_uamor,
+				  2 * sizeof(unsigned long), 3 * sizeof(unsigned long));
+err_out:
+	return ret;
 }
 
 static int pkey_set(struct task_struct *target, const struct user_regset *regset,
@@ -518,8 +529,8 @@ static int pkey_set(struct task_struct *target, const struct user_regset *regset
 		return ret;
 
 	/* UAMOR determines which bits of the AMR can be set from userspace. */
-	target->thread.amr = (new_amr & target->thread.uamor) |
-			     (target->thread.amr & ~target->thread.uamor);
+	target->thread.regs->kuap = (new_amr & default_uamor) |
+		(target->thread.regs->kuap & ~default_uamor);
 
 	return 0;
 }
-- 
2.25.3


^ permalink raw reply related

* [RFC PATCH 16/25] powerpc/book3s64/pkeys: Reset userspace AMR correctly on exec
From: Aneesh Kumar K.V @ 2020-04-27  8:04 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

On fork, we inherit from the parent and on exec, we should switch to default_amr values.

Also, avoid changing the AMR register value within the kernel. The kernel now runs with
different AMR values.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/include/asm/pkeys.h |  1 +
 arch/powerpc/kernel/process.c    |  3 ++-
 arch/powerpc/mm/book3s64/pkeys.c | 16 +---------------
 3 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/include/asm/pkeys.h b/arch/powerpc/include/asm/pkeys.h
index 6e8157f78b52..cd1a03044814 100644
--- a/arch/powerpc/include/asm/pkeys.h
+++ b/arch/powerpc/include/asm/pkeys.h
@@ -13,6 +13,7 @@
 
 extern int max_pkey;
 extern u64 default_uamor;
+extern u64 default_amr;
 extern u32 reserved_allocation_mask; /* bits set for reserved keys */
 
 #define ARCH_VM_PKEY_FLAGS (VM_PKEY_BIT0 | VM_PKEY_BIT1 | VM_PKEY_BIT2 | \
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index fc4cc32d4726..9660bab1d99d 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1473,6 +1473,8 @@ void arch_setup_new_exec(void)
 		current->thread.regs = regs - 1;
 	}
 
+	current->thread.regs->kuap  = default_amr;
+	current->thread.regs->kuep  = default_iamr;
 }
 #endif
 
@@ -1827,7 +1829,6 @@ void start_thread(struct pt_regs *regs, unsigned long start, unsigned long sp)
 	current->thread.load_tm = 0;
 #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
 
-	thread_pkey_regs_init(&current->thread);
 }
 EXPORT_SYMBOL(start_thread);
 
diff --git a/arch/powerpc/mm/book3s64/pkeys.c b/arch/powerpc/mm/book3s64/pkeys.c
index d0d781876c20..42ca7aa09d5b 100644
--- a/arch/powerpc/mm/book3s64/pkeys.c
+++ b/arch/powerpc/mm/book3s64/pkeys.c
@@ -20,7 +20,7 @@ int  max_pkey;			/* Maximum key value supported */
  */
 u32  reserved_allocation_mask;
 static u32  initial_allocation_mask;   /* Bits set for the initially allocated keys */
-static u64 default_amr;
+u64 default_amr;
 static u64 default_iamr;
 /* Allow all keys to be modified by default */
 u64 default_uamor = ~0x0UL;
@@ -387,20 +387,6 @@ void thread_pkey_regs_restore(struct thread_struct *new_thread,
 		write_uamor(new_thread->uamor);
 }
 
-void thread_pkey_regs_init(struct thread_struct *thread)
-{
-	if (!mmu_has_feature(MMU_FTR_PKEY))
-		return;
-
-	thread->amr   = default_amr;
-	thread->iamr  = default_iamr;
-	thread->uamor = default_uamor;
-
-	write_amr(default_amr);
-	write_iamr(default_iamr);
-	write_uamor(default_uamor);
-}
-
 int execute_only_pkey(struct mm_struct *mm)
 {
 	if (static_branch_likely(&execute_pkey_disabled))
-- 
2.25.3


^ permalink raw reply related

* [RFC PATCH 15/25] powerpc/book3s64/pkeys: Inherit correctly on fork.
From: Aneesh Kumar K.V @ 2020-04-27  8:04 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

Child thread.kuap value is inherited from the parent in copy_thread_tls. We still
need to make sure when the child returns from a fork in the kernel we start with the kernel
default AMR value.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/kernel/process.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 78eedf0b5c30..fc4cc32d4726 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1698,6 +1698,11 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
 
 	p->thread.tidr = 0;
 #endif
+	/*
+	 * Run with the current AMR value of the kernel
+	 */
+	kregs->kuap = AMR_KUAP_BLOCKED;
+	kregs->kuep = AMR_KUEP_BLOCKED;
 	kregs->nip = ppc_function_entry(f);
 	return 0;
 }
-- 
2.25.3


^ permalink raw reply related

* [RFC PATCH 14/25] powerpc/book3s64/kuep: Store/restore userspace IAMR correctly on entry and exit from kernel
From: Aneesh Kumar K.V @ 2020-04-27  8:04 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

This prepare kernel to operate with a different value than userspace IAMR.
For this, IAMR needs to be saved and restored on entry and return from the
kernel.

If MMU_FTR_KEY is enabled we always use the key mechanism to implement KUEP
feature. If MMU_FTR_KEY is not supported and if we support MMU_FTR_KUEP
(radix translation on POWER9), we can skip restoring IAMR on return
to userspace. Userspace won't be using IAMR in that specific config.

We don't need to save/restore IAMR on reentry into the kernel due to interrupt
because the kernel doesn't modify IAMR internally.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/include/asm/book3s/64/kup.h | 51 +++++++++++++++++++++++-
 arch/powerpc/include/asm/ptrace.h        |  6 ++-
 arch/powerpc/kernel/asm-offsets.c        |  4 ++
 arch/powerpc/kernel/syscall_64.c         |  5 ++-
 4 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/kup.h b/arch/powerpc/include/asm/book3s/64/kup.h
index 85645d1b7102..717c2c4d3681 100644
--- a/arch/powerpc/include/asm/book3s/64/kup.h
+++ b/arch/powerpc/include/asm/book3s/64/kup.h
@@ -25,6 +25,13 @@
 	b	100f  // skip_restore_amr
 	ALT_MMU_FTR_SECTION_END_NESTED_IFSET(MMU_FTR_KUAP, 68)
 
+	/*
+	 * We don't check KUEP feature here, because if FTR_PKEY
+	 * is not enabled we don't need to restore IAMR on
+	 * return to usespace. That is handled by either
+	 * handle_kuap_restore_amr or skip_restore_amr
+	 */
+
 99:  // handle_kuap_restore_amr
 	/*
 	 * No key support, don't bother to restore AMR
@@ -37,7 +44,17 @@
 	ld	\gpr, STACK_REGS_KUAP(r1)
 	isync
 	mtspr	SPRN_AMR, \gpr
-	/*  No isync here because we will return to a different context  */
+
+	/*
+	 * Restore IAMR only when returning to userspace
+	 */
+	.ifnb \to_user
+	ld	\gpr, STACK_REGS_KUEP(r1)
+	mtspr	SPRN_IAMR, \gpr
+	.endif
+	/*
+	 * No isync here because we will return to a different context
+	 */
 100:  // skip_restore_amr
 #endif
 .endm
@@ -75,6 +92,12 @@
 	b	100f  // skip_save_amr
 	ALT_MMU_FTR_SECTION_END_NESTED_IFSET(MMU_FTR_KUAP, 68)
 
+	/*
+	 * We don't check KUEP feature here, because if FTR_PKEY
+	 * is not enabled we don't need to save IAMR on
+	 * entry from usespace. That is handled by either
+	 * handle_kuap_save_amr or skip_save_amr
+	 */
 
 99: // handle_kuap_save_amr
 	.ifnb \msr_pr_cr
@@ -103,7 +126,26 @@
 	mtspr	SPRN_AMR, \gpr2
 	isync
 102:
-        END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_KUAP, 69)
+	END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_KUAP, 69)
+
+	.ifnb \msr_pr_cr
+	beq	\msr_pr_cr, 103f // from kernel space
+	mfspr	\gpr1, SPRN_IAMR
+	std	\gpr1, STACK_REGS_KUEP(r1)
+
+	/*
+	 * update kernel IAMR with AMR_KUEP_BLOCKED only
+	 * if KUAP feature is enabled
+	 */
+	BEGIN_MMU_FTR_SECTION_NESTED(70)
+	LOAD_REG_IMMEDIATE(\gpr2, AMR_KUEP_BLOCKED)
+	cmpd	\use_cr, \gpr1, \gpr2
+	beq	\use_cr, 103f
+	mtspr	SPRN_IAMR, \gpr2
+	isync
+103:
+        END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_KUEP, 70)
+	.endif
 
 100: // skip_save_amr
 #endif
@@ -129,6 +171,11 @@ static inline void kuap_restore_amr(struct pt_regs *regs, bool to_user)
 		 * returning to a different context using rfid
 		 */
 	}
+	/*
+	 * We do support FTR_PKEY, restore IAMR when returning to user
+	 */
+	if (to_user)
+		mtspr(SPRN_IAMR, regs->kuep);
 }
 
 static inline void kuap_check_amr(void)
diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/ptrace.h
index e0195e6b892b..2bfd2b6a72ab 100644
--- a/arch/powerpc/include/asm/ptrace.h
+++ b/arch/powerpc/include/asm/ptrace.h
@@ -56,8 +56,12 @@ struct pt_regs
 #ifdef CONFIG_PPC_KUAP
 			unsigned long kuap;
 #endif
+#ifdef CONFIG_PPC_KUEP
+			unsigned long kuep;
+#endif
+
 		};
-		unsigned long __pad[2];	/* Maintain 16 byte interrupt stack alignment */
+		unsigned long __pad[4];	/* Maintain 16 byte interrupt stack alignment */
 	};
 };
 #endif
diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c
index fcf24a365fc0..6c7326fc73b9 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -353,6 +353,10 @@ int main(void)
 #ifdef CONFIG_PPC_KUAP
 	STACK_PT_REGS_OFFSET(STACK_REGS_KUAP, kuap);
 #endif
+#ifdef CONFIG_PPC_KUEP
+	STACK_PT_REGS_OFFSET(STACK_REGS_KUEP, kuep);
+#endif
+
 
 #if defined(CONFIG_PPC32)
 #if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
diff --git a/arch/powerpc/kernel/syscall_64.c b/arch/powerpc/kernel/syscall_64.c
index f69b4774f3b3..458f2bb80c6d 100644
--- a/arch/powerpc/kernel/syscall_64.c
+++ b/arch/powerpc/kernel/syscall_64.c
@@ -36,11 +36,14 @@ notrace long system_call_exception(long r3, long r4, long r5,
 	BUG_ON(regs->softe != IRQS_ENABLED);
 
 	if (mmu_has_feature(MMU_FTR_PKEY)) {
-		unsigned long amr;
+		unsigned long amr, iamr;
 
 		amr = mfspr(SPRN_AMR);
+		iamr = mfspr(SPRN_IAMR);
 		regs->kuap = amr;
+		regs->kuep = iamr;
 		mtspr(SPRN_AMR, AMR_KUAP_BLOCKED);
+		mtspr(SPRN_IAMR, AMR_KUEP_BLOCKED);
 		isync();
 	} else
 		kuap_check_amr();
-- 
2.25.3


^ permalink raw reply related

* [RFC PATCH 13/25] powerpc/book3s64/pkeys: Store/restore userspace AMR correctly on entry and exit from kernel
From: Aneesh Kumar K.V @ 2020-04-27  8:04 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

This prepare kernel to operate with a different value than userspace AMR.
For this, AMR needs to be saved and restored on entry and return from the
kernel.

With KUAP we modify kernel AMR when accessing user address from the kernel
via copy_to/from_user interfaces.

If MMU_FTR_KEY is enabled we always use the key mechanism to implement KUAP
feature. If MMU_FTR_KEY is not supported and if we support MMU_FTR_KUAP
(radix translation on POWER9), we can skip restoring AMR on return
to userspace. Userspace won't be using AMR in that specific config.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/include/asm/book3s/64/kup.h | 86 ++++++++++++++++++++----
 arch/powerpc/kernel/entry_64.S           |  4 +-
 arch/powerpc/kernel/syscall_64.c         | 19 +++++-
 3 files changed, 92 insertions(+), 17 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/kup.h b/arch/powerpc/include/asm/book3s/64/kup.h
index c56894b9b3a1..85645d1b7102 100644
--- a/arch/powerpc/include/asm/book3s/64/kup.h
+++ b/arch/powerpc/include/asm/book3s/64/kup.h
@@ -13,13 +13,32 @@
 
 #ifdef __ASSEMBLY__
 
-.macro kuap_restore_amr	gpr
-#ifdef CONFIG_PPC_KUAP
+.macro kuap_restore_amr	gpr to_user
+#if defined(CONFIG_PPC_MEM_KEYS) || defined (CONFIG_PPC_KUAP)
 	BEGIN_MMU_FTR_SECTION_NESTED(67)
+	b	101f  // handle_pkey_restore_amr
+	END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_PKEY , 67)
+
+	BEGIN_MMU_FTR_SECTION_NESTED(68)
+	b	99f  // handle_kuap_restore_amr
+	MMU_FTR_SECTION_ELSE_NESTED(68)
+	b	100f  // skip_restore_amr
+	ALT_MMU_FTR_SECTION_END_NESTED_IFSET(MMU_FTR_KUAP, 68)
+
+99:  // handle_kuap_restore_amr
+	/*
+	 * No key support, don't bother to restore AMR
+	 * when returning to userspace.
+	 */
+	.ifnb \to_user
+	b	100f
+	.endif
+101:   // handle_pkey_restore_amr
 	ld	\gpr, STACK_REGS_KUAP(r1)
 	isync
 	mtspr	SPRN_AMR, \gpr
-	END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_KUAP, 67)
+	/*  No isync here because we will return to a different context  */
+100:  // skip_restore_amr
 #endif
 .endm
 
@@ -35,23 +54,58 @@
 #endif
 .endm
 
+/*
+ * MMU_FTR_PKEY and MMU_FTR_KUAP can both be enabled on a platform. We prefer
+ * PKEY over KUAP if both can be enabled on the platform.
+ *
+ * With KUAP only enabled on exception if we are coming from userspace we don't
+ * save the AMR at all, because the expectation is that userspace can't change
+ * the AMR if KUAP feature is enabled.
+ */
 .macro kuap_save_amr_and_lock gpr1, gpr2, use_cr, msr_pr_cr
-#ifdef CONFIG_PPC_KUAP
+#if defined(CONFIG_PPC_MEM_KEYS) || defined (CONFIG_PPC_KUAP)
+
 	BEGIN_MMU_FTR_SECTION_NESTED(67)
+	b	101f   // handle_pkey_save_amr
+        END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_PKEY , 67)
+
+	BEGIN_MMU_FTR_SECTION_NESTED(68)
+	b	99f  // handle_kuap_save_amr
+	MMU_FTR_SECTION_ELSE_NESTED(68)
+	b	100f  // skip_save_amr
+	ALT_MMU_FTR_SECTION_END_NESTED_IFSET(MMU_FTR_KUAP, 68)
+
+
+99: // handle_kuap_save_amr
 	.ifnb \msr_pr_cr
-	bne	\msr_pr_cr, 99f
+	/*
+	 * We avoid changing AMR outside the kernel
+	 * hence skip this completely.
+	 */
+	bne	\msr_pr_cr, 100f  // from userspace
 	.endif
+
+101:   // handle_pkey_save_amr
 	mfspr	\gpr1, SPRN_AMR
 	std	\gpr1, STACK_REGS_KUAP(r1)
-	li	\gpr2, (AMR_KUAP_BLOCKED >> AMR_KUAP_SHIFT)
-	sldi	\gpr2, \gpr2, AMR_KUAP_SHIFT
+
+	/*
+	 * update kernel AMR with AMR_KUAP_BLOCKED only
+	 * if KUAP feature is enabled
+	 */
+	BEGIN_MMU_FTR_SECTION_NESTED(69)
+	LOAD_REG_IMMEDIATE(\gpr2, AMR_KUAP_BLOCKED)
 	cmpd	\use_cr, \gpr1, \gpr2
-	beq	\use_cr, 99f
-	// We don't isync here because we very recently entered via rfid
+	beq	\use_cr, 102f
+	/*
+	 * We don't isync here because we very recently entered via an interrupt
+	 */
 	mtspr	SPRN_AMR, \gpr2
 	isync
-99:
-	END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_KUAP, 67)
+102:
+        END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_KUAP, 69)
+
+100: // skip_save_amr
 #endif
 .endm
 
@@ -62,9 +116,12 @@
 #include <asm/mmu.h>
 #include <asm/ptrace.h>
 
-static inline void kuap_restore_amr(struct pt_regs *regs)
+static inline void kuap_restore_amr(struct pt_regs *regs, bool to_user)
 {
-	if (mmu_has_feature(MMU_FTR_KUAP)) {
+	if (!mmu_has_feature(MMU_FTR_PKEY) && to_user)
+		return;
+
+	if (mmu_has_feature(MMU_FTR_KUAP) || mmu_has_feature(MMU_FTR_PKEY)) {
 		isync();
 		mtspr(SPRN_AMR, regs->kuap);
 		/*
@@ -76,7 +133,8 @@ static inline void kuap_restore_amr(struct pt_regs *regs)
 
 static inline void kuap_check_amr(void)
 {
-	if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG) && mmu_has_feature(MMU_FTR_KUAP))
+	if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG) &&
+	    (mmu_has_feature(MMU_FTR_KUAP) || mmu_has_feature(MMU_FTR_PKEY)))
 		WARN_ON_ONCE(mfspr(SPRN_AMR) != AMR_KUAP_BLOCKED);
 }
 
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index b3c9f15089b6..c2f783dda56d 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -481,7 +481,7 @@ _ASM_NOKPROBE_SYMBOL(fast_interrupt_return)
 	kuap_check_amr r3, r4
 	ld	r4,_MSR(r1)
 	andi.	r0,r4,MSR_PR
-	bne	.Lfast_user_interrupt_return
+	bne	.Lfast_user_interrupt_return_amr
 	kuap_restore_amr r3
 	andi.	r0,r4,MSR_RI
 	li	r3,0 /* 0 return value, no EMULATE_STACK_STORE */
@@ -502,6 +502,8 @@ _ASM_NOKPROBE_SYMBOL(interrupt_return)
 	cmpdi	r3,0
 	bne-	.Lrestore_nvgprs
 
+.Lfast_user_interrupt_return_amr:
+	kuap_restore_amr r3, 1
 .Lfast_user_interrupt_return:
 	ld	r11,_NIP(r1)
 	ld	r12,_MSR(r1)
diff --git a/arch/powerpc/kernel/syscall_64.c b/arch/powerpc/kernel/syscall_64.c
index c0fdb02a13d5..f69b4774f3b3 100644
--- a/arch/powerpc/kernel/syscall_64.c
+++ b/arch/powerpc/kernel/syscall_64.c
@@ -35,7 +35,15 @@ notrace long system_call_exception(long r3, long r4, long r5,
 	BUG_ON(!FULL_REGS(regs));
 	BUG_ON(regs->softe != IRQS_ENABLED);
 
-	kuap_check_amr();
+	if (mmu_has_feature(MMU_FTR_PKEY)) {
+		unsigned long amr;
+
+		amr = mfspr(SPRN_AMR);
+		regs->kuap = amr;
+		mtspr(SPRN_AMR, AMR_KUAP_BLOCKED);
+		isync();
+	} else
+		kuap_check_amr();
 
 	account_cpu_user_entry();
 
@@ -208,6 +216,10 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3,
 
 	account_cpu_user_exit();
 
+	/*
+	 * We do this at the end so that we do context switch with KERNEL AMR
+	 */
+	kuap_restore_amr(regs, true);
 	return ret;
 }
 
@@ -293,9 +305,12 @@ notrace unsigned long interrupt_exit_user_prepare(struct pt_regs *regs, unsigned
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
 	local_paca->tm_scratch = regs->msr;
 #endif
-
 	account_cpu_user_exit();
 
+	/*
+	 * We do this at the end so that we do context switch with KERNEL AMR
+	 */
+	kuap_restore_amr(regs, true);
 	return ret;
 }
 
-- 
2.25.3


^ permalink raw reply related

* [RFC PATCH 12/25] powerpc/exec: Set thread.regs early during exec
From: Aneesh Kumar K.V @ 2020-04-27  8:04 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

In later patches during exec, we would like to access default regs.kuap to
control access to the user mapping. Having thread.regs set early makes the
code changes simpler.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/kernel/process.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 9c21288f8645..78eedf0b5c30 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1461,9 +1461,18 @@ void flush_thread(void)
 #ifdef CONFIG_PPC_BOOK3S_64
 void arch_setup_new_exec(void)
 {
-	if (radix_enabled())
-		return;
-	hash__setup_new_exec();
+	if (!radix_enabled())
+		hash__setup_new_exec();
+
+	/*
+	 * If we exec out of a kernel thread then thread.regs will not be
+	 * set.  Do it now.
+	 */
+	if (!current->thread.regs) {
+		struct pt_regs *regs = task_stack_page(current) + THREAD_SIZE;
+		current->thread.regs = regs - 1;
+	}
+
 }
 #endif
 
@@ -1709,15 +1718,6 @@ void start_thread(struct pt_regs *regs, unsigned long start, unsigned long sp)
 #endif
 #endif
 
-	/*
-	 * If we exec out of a kernel thread then thread.regs will not be
-	 * set.  Do it now.
-	 */
-	if (!current->thread.regs) {
-		struct pt_regs *regs = task_stack_page(current) + THREAD_SIZE;
-		current->thread.regs = regs - 1;
-	}
-
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
 	/*
 	 * Clear any transactional state, we're exec()ing. The cause is
-- 
2.25.3


^ permalink raw reply related

* [RFC PATCH 11/25] powerpc/book3s64/kuap: Use Key 3 for kernel mapping with hash translation
From: Aneesh Kumar K.V @ 2020-04-27  8:04 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

This patch updates kernel hash page table entries to use storage key 3
for its mapping. This implies all kernel access will now use key 3 to
control READ/WRITE. The patch also prevents the allocation of key 3 from
userspace and UAMOR value is updated such that userspace cannot modify key 3.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 .../powerpc/include/asm/book3s/64/hash-pkey.h | 24 ++++++++++++++-----
 arch/powerpc/include/asm/book3s/64/hash.h     |  3 ++-
 arch/powerpc/include/asm/book3s/64/mmu-hash.h |  1 +
 arch/powerpc/mm/book3s64/hash_4k.c            |  2 +-
 arch/powerpc/mm/book3s64/hash_64k.c           |  4 ++--
 arch/powerpc/mm/book3s64/hash_hugepage.c      |  2 +-
 arch/powerpc/mm/book3s64/hash_hugetlbpage.c   |  2 +-
 arch/powerpc/mm/book3s64/hash_pgtable.c       |  2 +-
 arch/powerpc/mm/book3s64/hash_utils.c         | 10 ++++----
 arch/powerpc/mm/book3s64/pkeys.c              |  4 ++++
 10 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/hash-pkey.h b/arch/powerpc/include/asm/book3s/64/hash-pkey.h
index 795010897e5d..fc75b815c9ca 100644
--- a/arch/powerpc/include/asm/book3s/64/hash-pkey.h
+++ b/arch/powerpc/include/asm/book3s/64/hash-pkey.h
@@ -2,6 +2,9 @@
 #ifndef _ASM_POWERPC_BOOK3S_64_HASH_PKEY_H
 #define _ASM_POWERPC_BOOK3S_64_HASH_PKEY_H
 
+/*  We use key 3 for KERNEL */
+#define HASH_DEFAULT_KERNEL_KEY (HPTE_R_KEY_BIT0 | HPTE_R_KEY_BIT1)
+
 static inline u64 hash__vmflag_to_pte_pkey_bits(u64 vm_flags)
 {
 	return (((vm_flags & VM_PKEY_BIT0) ? H_PTE_PKEY_BIT0 : 0x0UL) |
@@ -11,13 +14,22 @@ static inline u64 hash__vmflag_to_pte_pkey_bits(u64 vm_flags)
 		((vm_flags & VM_PKEY_BIT4) ? H_PTE_PKEY_BIT4 : 0x0UL));
 }
 
-static inline u64 pte_to_hpte_pkey_bits(u64 pteflags)
+static inline u64 pte_to_hpte_pkey_bits(u64 pteflags, unsigned long flags)
 {
-	return (((pteflags & H_PTE_PKEY_BIT4) ? HPTE_R_KEY_BIT4 : 0x0UL) |
-		((pteflags & H_PTE_PKEY_BIT3) ? HPTE_R_KEY_BIT3 : 0x0UL) |
-		((pteflags & H_PTE_PKEY_BIT2) ? HPTE_R_KEY_BIT2 : 0x0UL) |
-		((pteflags & H_PTE_PKEY_BIT1) ? HPTE_R_KEY_BIT1 : 0x0UL) |
-		((pteflags & H_PTE_PKEY_BIT0) ? HPTE_R_KEY_BIT0 : 0x0UL));
+	unsigned long pte_pkey;
+
+	pte_pkey = (((pteflags & H_PTE_PKEY_BIT4) ? HPTE_R_KEY_BIT4 : 0x0UL) |
+		    ((pteflags & H_PTE_PKEY_BIT3) ? HPTE_R_KEY_BIT3 : 0x0UL) |
+		    ((pteflags & H_PTE_PKEY_BIT2) ? HPTE_R_KEY_BIT2 : 0x0UL) |
+		    ((pteflags & H_PTE_PKEY_BIT1) ? HPTE_R_KEY_BIT1 : 0x0UL) |
+		    ((pteflags & H_PTE_PKEY_BIT0) ? HPTE_R_KEY_BIT0 : 0x0UL));
+
+	if (mmu_has_feature(MMU_FTR_KUAP)) {
+		if ((pte_pkey == 0) && (flags & HPTE_USE_KERNEL_KEY))
+			return HASH_DEFAULT_KERNEL_KEY;
+	}
+
+	return pte_pkey;
 }
 
 static inline u16 hash__pte_to_pkey_bits(u64 pteflags)
diff --git a/arch/powerpc/include/asm/book3s/64/hash.h b/arch/powerpc/include/asm/book3s/64/hash.h
index 6fc4520092c7..12b65d3d79aa 100644
--- a/arch/powerpc/include/asm/book3s/64/hash.h
+++ b/arch/powerpc/include/asm/book3s/64/hash.h
@@ -145,7 +145,8 @@ extern void hash__mark_initmem_nx(void);
 
 extern void hpte_need_flush(struct mm_struct *mm, unsigned long addr,
 			    pte_t *ptep, unsigned long pte, int huge);
-extern unsigned long htab_convert_pte_flags(unsigned long pteflags);
+extern unsigned long htab_convert_pte_flags(unsigned long pteflags,
+					    unsigned long flags);
 /* Atomic PTE updates */
 static inline unsigned long hash__pte_update(struct mm_struct *mm,
 					 unsigned long addr,
diff --git a/arch/powerpc/include/asm/book3s/64/mmu-hash.h b/arch/powerpc/include/asm/book3s/64/mmu-hash.h
index 58fcc959f9d5..eb9950043b78 100644
--- a/arch/powerpc/include/asm/book3s/64/mmu-hash.h
+++ b/arch/powerpc/include/asm/book3s/64/mmu-hash.h
@@ -452,6 +452,7 @@ static inline unsigned long hpt_hash(unsigned long vpn,
 
 #define HPTE_LOCAL_UPDATE	0x1
 #define HPTE_NOHPTE_UPDATE	0x2
+#define HPTE_USE_KERNEL_KEY	0x4
 
 extern int __hash_page_4K(unsigned long ea, unsigned long access,
 			  unsigned long vsid, pte_t *ptep, unsigned long trap,
diff --git a/arch/powerpc/mm/book3s64/hash_4k.c b/arch/powerpc/mm/book3s64/hash_4k.c
index 22e787123cdf..7de1a8a0c62a 100644
--- a/arch/powerpc/mm/book3s64/hash_4k.c
+++ b/arch/powerpc/mm/book3s64/hash_4k.c
@@ -54,7 +54,7 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
 	 * PP bits. _PAGE_USER is already PP bit 0x2, so we only
 	 * need to add in 0x1 if it's a read-only user page
 	 */
-	rflags = htab_convert_pte_flags(new_pte);
+	rflags = htab_convert_pte_flags(new_pte, flags);
 	rpte = __real_pte(__pte(old_pte), ptep, PTRS_PER_PTE);
 
 	if (cpu_has_feature(CPU_FTR_NOEXECUTE) &&
diff --git a/arch/powerpc/mm/book3s64/hash_64k.c b/arch/powerpc/mm/book3s64/hash_64k.c
index 7084ce2951e6..998c6817ed47 100644
--- a/arch/powerpc/mm/book3s64/hash_64k.c
+++ b/arch/powerpc/mm/book3s64/hash_64k.c
@@ -72,7 +72,7 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
 	 * Handle the subpage protection bits
 	 */
 	subpg_pte = new_pte & ~subpg_prot;
-	rflags = htab_convert_pte_flags(subpg_pte);
+	rflags = htab_convert_pte_flags(subpg_pte, flags);
 
 	if (cpu_has_feature(CPU_FTR_NOEXECUTE) &&
 	    !cpu_has_feature(CPU_FTR_COHERENT_ICACHE)) {
@@ -260,7 +260,7 @@ int __hash_page_64K(unsigned long ea, unsigned long access,
 			new_pte |= _PAGE_DIRTY;
 	} while (!pte_xchg(ptep, __pte(old_pte), __pte(new_pte)));
 
-	rflags = htab_convert_pte_flags(new_pte);
+	rflags = htab_convert_pte_flags(new_pte, flags);
 	rpte = __real_pte(__pte(old_pte), ptep, PTRS_PER_PTE);
 
 	if (cpu_has_feature(CPU_FTR_NOEXECUTE) &&
diff --git a/arch/powerpc/mm/book3s64/hash_hugepage.c b/arch/powerpc/mm/book3s64/hash_hugepage.c
index 440823797de7..c0fabe6c5a12 100644
--- a/arch/powerpc/mm/book3s64/hash_hugepage.c
+++ b/arch/powerpc/mm/book3s64/hash_hugepage.c
@@ -57,7 +57,7 @@ int __hash_page_thp(unsigned long ea, unsigned long access, unsigned long vsid,
 	if (!(old_pmd & (H_PAGE_THP_HUGE | _PAGE_DEVMAP)))
 		return 0;
 
-	rflags = htab_convert_pte_flags(new_pmd);
+	rflags = htab_convert_pte_flags(new_pmd, flags);
 
 #if 0
 	if (!cpu_has_feature(CPU_FTR_COHERENT_ICACHE)) {
diff --git a/arch/powerpc/mm/book3s64/hash_hugetlbpage.c b/arch/powerpc/mm/book3s64/hash_hugetlbpage.c
index eefa89c6117b..8ce8fc327af4 100644
--- a/arch/powerpc/mm/book3s64/hash_hugetlbpage.c
+++ b/arch/powerpc/mm/book3s64/hash_hugetlbpage.c
@@ -72,7 +72,7 @@ int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid,
 	if (old_pte & (H_PAGE_THP_HUGE | _PAGE_DEVMAP))
 		return 0;
 
-	rflags = htab_convert_pte_flags(new_pte);
+	rflags = htab_convert_pte_flags(new_pte, flags);
 	if (unlikely(mmu_psize == MMU_PAGE_16G))
 		offset = PTRS_PER_PUD;
 	else
diff --git a/arch/powerpc/mm/book3s64/hash_pgtable.c b/arch/powerpc/mm/book3s64/hash_pgtable.c
index 64733b9cb20a..6c43aaf1c713 100644
--- a/arch/powerpc/mm/book3s64/hash_pgtable.c
+++ b/arch/powerpc/mm/book3s64/hash_pgtable.c
@@ -454,7 +454,7 @@ void hash__mark_initmem_nx(void)
 	start = (unsigned long)__init_begin;
 	end = (unsigned long)__init_end;
 
-	pp = htab_convert_pte_flags(pgprot_val(PAGE_KERNEL));
+	pp = htab_convert_pte_flags(pgprot_val(PAGE_KERNEL), HPTE_USE_KERNEL_KEY);
 
 	WARN_ON(!hash__change_memory_range(start, end, pp));
 }
diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c
index 8ed2411c3f39..bdd4f1792c76 100644
--- a/arch/powerpc/mm/book3s64/hash_utils.c
+++ b/arch/powerpc/mm/book3s64/hash_utils.c
@@ -183,7 +183,7 @@ static struct mmu_psize_def mmu_psize_defaults_gp[] = {
  *    - We make sure R is always set and never lost
  *    - C is _PAGE_DIRTY, and *should* always be set for a writeable mapping
  */
-unsigned long htab_convert_pte_flags(unsigned long pteflags)
+unsigned long htab_convert_pte_flags(unsigned long pteflags, unsigned long flags)
 {
 	unsigned long rflags = 0;
 
@@ -237,7 +237,7 @@ unsigned long htab_convert_pte_flags(unsigned long pteflags)
 		 */
 		rflags |= HPTE_R_M;
 
-	rflags |= pte_to_hpte_pkey_bits(pteflags);
+	rflags |= pte_to_hpte_pkey_bits(pteflags, flags);
 	return rflags;
 }
 
@@ -252,7 +252,7 @@ int htab_bolt_mapping(unsigned long vstart, unsigned long vend,
 	shift = mmu_psize_defs[psize].shift;
 	step = 1 << shift;
 
-	prot = htab_convert_pte_flags(prot);
+	prot = htab_convert_pte_flags(prot, HPTE_USE_KERNEL_KEY);
 
 	DBG("htab_bolt_mapping(%lx..%lx -> %lx (%lx,%d,%d)\n",
 	    vstart, vend, pstart, prot, psize, ssize);
@@ -1295,12 +1295,14 @@ int hash_page_mm(struct mm_struct *mm, unsigned long ea,
 		vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
 		psize = mmu_vmalloc_psize;
 		ssize = mmu_kernel_ssize;
+		flags |= HPTE_USE_KERNEL_KEY;
 		break;
 
 	case IO_REGION_ID:
 		vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
 		psize = mmu_io_psize;
 		ssize = mmu_kernel_ssize;
+		flags |= HPTE_USE_KERNEL_KEY;
 		break;
 	default:
 		/*
@@ -1894,7 +1896,7 @@ static void kernel_map_linear_page(unsigned long vaddr, unsigned long lmi)
 	unsigned long hash;
 	unsigned long vsid = get_kernel_vsid(vaddr, mmu_kernel_ssize);
 	unsigned long vpn = hpt_vpn(vaddr, vsid, mmu_kernel_ssize);
-	unsigned long mode = htab_convert_pte_flags(pgprot_val(PAGE_KERNEL));
+	unsigned long mode = htab_convert_pte_flags(pgprot_val(PAGE_KERNEL), HPTE_USE_KERNEL_KEY);
 	long ret;
 
 	hash = hpt_hash(vpn, PAGE_SHIFT, mmu_kernel_ssize);
diff --git a/arch/powerpc/mm/book3s64/pkeys.c b/arch/powerpc/mm/book3s64/pkeys.c
index a0406ea32487..d0d781876c20 100644
--- a/arch/powerpc/mm/book3s64/pkeys.c
+++ b/arch/powerpc/mm/book3s64/pkeys.c
@@ -189,6 +189,10 @@ void __init pkey_early_init_devtree(void)
 	 */
 	reserved_allocation_mask |= (0x1 << 1);
 
+	/*  handle key 3 which is used by kernel for KAUP */
+	reserved_allocation_mask |= (0x1 << 3);
+	default_uamor &= ~(0x3ul << pkeyshift(3));
+
 	/*
 	 * Prevent the usage of OS reserved keys. Update UAMOR
 	 * for those keys. Also mark the rest of the bits in the
-- 
2.25.3


^ permalink raw reply related

* [RFC PATCH 10/25] powerpc/book3s64/kuap: Move UAMOR setup to key init function
From: Aneesh Kumar K.V @ 2020-04-27  8:04 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

With hash translation, the kernel will use key 3 for implementing
KUAP feature. Hence the default UAMOR value depends on what other
keys are marked reserved. Move the UAMOR initialization to pkeys init.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/include/asm/pkeys.h |  1 +
 arch/powerpc/kernel/smp.c        |  3 +++
 arch/powerpc/mm/book3s64/pkeys.c | 25 ++++++++++++++++++++-----
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/include/asm/pkeys.h b/arch/powerpc/include/asm/pkeys.h
index b1d448c53209..6e8157f78b52 100644
--- a/arch/powerpc/include/asm/pkeys.h
+++ b/arch/powerpc/include/asm/pkeys.h
@@ -12,6 +12,7 @@
 #include <asm/firmware.h>
 
 extern int max_pkey;
+extern u64 default_uamor;
 extern u32 reserved_allocation_mask; /* bits set for reserved keys */
 
 #define ARCH_VM_PKEY_FLAGS (VM_PKEY_BIT0 | VM_PKEY_BIT1 | VM_PKEY_BIT2 | \
diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 6d2a3a3666f0..5d1e5489bcd2 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -59,6 +59,7 @@
 #include <asm/asm-prototypes.h>
 #include <asm/cpu_has_feature.h>
 #include <asm/ftrace.h>
+#include <asm/pkeys.h>
 
 #ifdef DEBUG
 #include <asm/udbg.h>
@@ -1256,6 +1257,8 @@ void start_secondary(void *unused)
 	mmgrab(&init_mm);
 	current->active_mm = &init_mm;
 
+	mtspr(SPRN_UAMOR, default_uamor);
+
 	smp_store_cpu_info(cpu);
 	set_dec(tb_ticks_per_jiffy);
 	preempt_disable();
diff --git a/arch/powerpc/mm/book3s64/pkeys.c b/arch/powerpc/mm/book3s64/pkeys.c
index 727284607fa8..a0406ea32487 100644
--- a/arch/powerpc/mm/book3s64/pkeys.c
+++ b/arch/powerpc/mm/book3s64/pkeys.c
@@ -23,7 +23,7 @@ static u32  initial_allocation_mask;   /* Bits set for the initially allocated k
 static u64 default_amr;
 static u64 default_iamr;
 /* Allow all keys to be modified by default */
-static u64 default_uamor = ~0x0UL;
+u64 default_uamor = ~0x0UL;
 /*
  * Key used to implement PROT_EXEC mmap. Denies READ/WRITE
  * We pick key 2 because 0 is special key and 1 is reserved as per ISA.
@@ -112,8 +112,16 @@ void __init pkey_early_init_devtree(void)
 	/* scan the device tree for pkey feature */
 	pkeys_total = scan_pkey_feature();
 	if (!pkeys_total) {
-		/* No support for pkey. Mark it disabled */
-		return;
+		/*
+		 * No key support but on radix we can use key 0
+		 * to implement kuap.
+		 */
+		if (early_radix_enabled())
+			/*
+			 * Make sure userspace can't change the AMR
+			 */
+			default_uamor = 0;
+		goto err_out;
 	}
 
 	cur_cpu_spec->mmu_features |= MMU_FTR_PKEY;
@@ -195,6 +203,12 @@ void __init pkey_early_init_devtree(void)
 	 */
 	initial_allocation_mask |= reserved_allocation_mask;
 
+err_out:
+	/*
+	 * Setup uamor on boot cpu
+	 */
+	mtspr(SPRN_UAMOR, default_uamor);
+
 	return;
 }
 
@@ -230,8 +244,9 @@ void setup_kuap(bool disabled)
 		cur_cpu_spec->mmu_features |= MMU_FTR_KUAP;
 	}
 
-	/* Make sure userspace can't change the AMR */
-	mtspr(SPRN_UAMOR, 0);
+	/*
+	 * Set the default kernel AMR values on all cpus.
+	 */
 	mtspr(SPRN_AMR, AMR_KUAP_BLOCKED);
 	isync();
 }
-- 
2.25.3


^ permalink raw reply related

* [RFC PATCH 08/25] powerpc/book3s64/kuap: Rename MMU_FTR_RADIX_KUAP to MMU_FTR_KUAP
From: Aneesh Kumar K.V @ 2020-04-27  8:04 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

The next set of patches adds support for kuap with hash translation.
In preparation for that rename/move kuap related functions to
non radix names.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/include/asm/book3s/64/kup.h | 16 ++++++++--------
 arch/powerpc/include/asm/mmu.h           |  6 +++---
 arch/powerpc/kernel/syscall_64.c         |  4 ++--
 arch/powerpc/mm/book3s64/pkeys.c         |  2 +-
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/kup.h b/arch/powerpc/include/asm/book3s/64/kup.h
index 047f4298c053..c56894b9b3a1 100644
--- a/arch/powerpc/include/asm/book3s/64/kup.h
+++ b/arch/powerpc/include/asm/book3s/64/kup.h
@@ -19,7 +19,7 @@
 	ld	\gpr, STACK_REGS_KUAP(r1)
 	isync
 	mtspr	SPRN_AMR, \gpr
-	END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_RADIX_KUAP, 67)
+	END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_KUAP, 67)
 #endif
 .endm
 
@@ -31,7 +31,7 @@
 	sldi	\gpr2, \gpr2, AMR_KUAP_SHIFT
 999:	tdne	\gpr1, \gpr2
 	EMIT_BUG_ENTRY 999b, __FILE__, __LINE__, (BUGFLAG_WARNING | BUGFLAG_ONCE)
-	END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_RADIX_KUAP, 67)
+	END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_KUAP, 67)
 #endif
 .endm
 
@@ -51,7 +51,7 @@
 	mtspr	SPRN_AMR, \gpr2
 	isync
 99:
-	END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_RADIX_KUAP, 67)
+	END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_KUAP, 67)
 #endif
 .endm
 
@@ -64,7 +64,7 @@
 
 static inline void kuap_restore_amr(struct pt_regs *regs)
 {
-	if (mmu_has_feature(MMU_FTR_RADIX_KUAP)) {
+	if (mmu_has_feature(MMU_FTR_KUAP)) {
 		isync();
 		mtspr(SPRN_AMR, regs->kuap);
 		/*
@@ -76,7 +76,7 @@ static inline void kuap_restore_amr(struct pt_regs *regs)
 
 static inline void kuap_check_amr(void)
 {
-	if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG) && mmu_has_feature(MMU_FTR_RADIX_KUAP))
+	if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG) && mmu_has_feature(MMU_FTR_KUAP))
 		WARN_ON_ONCE(mfspr(SPRN_AMR) != AMR_KUAP_BLOCKED);
 }
 
@@ -87,7 +87,7 @@ static inline void kuap_check_amr(void)
 
 static inline unsigned long get_kuap(void)
 {
-	if (!early_mmu_has_feature(MMU_FTR_RADIX_KUAP))
+	if (!early_mmu_has_feature(MMU_FTR_KUAP))
 		return 0;
 
 	return mfspr(SPRN_AMR);
@@ -95,7 +95,7 @@ static inline unsigned long get_kuap(void)
 
 static inline void set_kuap(unsigned long value)
 {
-	if (!early_mmu_has_feature(MMU_FTR_RADIX_KUAP))
+	if (!early_mmu_has_feature(MMU_FTR_KUAP))
 		return;
 
 	/*
@@ -145,7 +145,7 @@ static inline void restore_user_access(unsigned long flags)
 static inline bool
 bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
 {
-	return WARN(mmu_has_feature(MMU_FTR_RADIX_KUAP) &&
+	return WARN(mmu_has_feature(MMU_FTR_KUAP) &&
 		    (regs->kuap & (is_write ? AMR_KUAP_BLOCK_WRITE : AMR_KUAP_BLOCK_READ)),
 		    "Bug: %s fault blocked by AMR!", is_write ? "Write" : "Read");
 }
diff --git a/arch/powerpc/include/asm/mmu.h b/arch/powerpc/include/asm/mmu.h
index f6fcc9daf6ac..55b746d6b844 100644
--- a/arch/powerpc/include/asm/mmu.h
+++ b/arch/powerpc/include/asm/mmu.h
@@ -112,7 +112,7 @@
 /*
  * Supports KUAP (key 0 controlling userspace addresses) on radix
  */
-#define MMU_FTR_RADIX_KUAP		ASM_CONST(0x80000000)
+#define MMU_FTR_KUAP			ASM_CONST(0x80000000)
 
 /* MMU feature bit sets for various CPUs */
 #define MMU_FTRS_DEFAULT_HPTE_ARCH_V2	\
@@ -174,10 +174,10 @@ enum {
 #endif
 #ifdef CONFIG_PPC_RADIX_MMU
 		MMU_FTR_TYPE_RADIX |
+#endif /* CONFIG_PPC_RADIX_MMU */
 #ifdef CONFIG_PPC_KUAP
-		MMU_FTR_RADIX_KUAP |
+	MMU_FTR_KUAP |
 #endif /* CONFIG_PPC_KUAP */
-#endif /* CONFIG_PPC_RADIX_MMU */
 #ifdef CONFIG_PPC_MEM_KEYS
 	MMU_FTR_PKEY |
 #endif
diff --git a/arch/powerpc/kernel/syscall_64.c b/arch/powerpc/kernel/syscall_64.c
index 09695e042363..c0fdb02a13d5 100644
--- a/arch/powerpc/kernel/syscall_64.c
+++ b/arch/powerpc/kernel/syscall_64.c
@@ -314,7 +314,7 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs, unsign
 	BUG_ON(regs->msr & MSR_PR);
 	BUG_ON(!FULL_REGS(regs));
 
-	if (mmu_has_feature(MMU_FTR_RADIX_KUAP)) {
+	if (mmu_has_feature(MMU_FTR_KUAP)) {
 		amr = mfspr(SPRN_AMR);
 		if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG)) /* kuap_check_amr() */
 			WARN_ON_ONCE(amr != AMR_KUAP_BLOCKED);
@@ -377,7 +377,7 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs, unsign
 	 * We don't need to restore AMR on the way back to userspace for KUAP.
 	 * The value of AMR only matters while we're in the kernel.
 	 */
-	if (mmu_has_feature(MMU_FTR_RADIX_KUAP) && (regs->kuap != amr)) {
+	if (mmu_has_feature(MMU_FTR_KUAP) && (regs->kuap != amr)) {
 		isync();
 		mtspr(SPRN_AMR, regs->kuap);
 	}
diff --git a/arch/powerpc/mm/book3s64/pkeys.c b/arch/powerpc/mm/book3s64/pkeys.c
index dc6b56c6e004..727284607fa8 100644
--- a/arch/powerpc/mm/book3s64/pkeys.c
+++ b/arch/powerpc/mm/book3s64/pkeys.c
@@ -227,7 +227,7 @@ void setup_kuap(bool disabled)
 
 	if (smp_processor_id() == boot_cpuid) {
 		pr_info("Activating Kernel Userspace Access Prevention\n");
-		cur_cpu_spec->mmu_features |= MMU_FTR_RADIX_KUAP;
+		cur_cpu_spec->mmu_features |= MMU_FTR_KUAP;
 	}
 
 	/* Make sure userspace can't change the AMR */
-- 
2.25.3


^ permalink raw reply related

* [RFC PATCH 09/25] powerpc/book3s64/kuap/kuep: Make KUAP and KUEP a subfeature of PPC_MEM_KEYS
From: Aneesh Kumar K.V @ 2020-04-27  8:04 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

The next set of patches adds support for kuap with hash translation.
Hence make KUAP a BOOK3S_64 feature. Also make it a subfeature of
PPC_MEM_KEYS. Hash translation is going to use pkeys to support
KUAP/KUEP. Adding this dependency reduces the code complexity and
enables us to move some of the initialization code to pkeys.c

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/platforms/Kconfig.cputype | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype
index 0c3c1902135c..8100d5c0812d 100644
--- a/arch/powerpc/platforms/Kconfig.cputype
+++ b/arch/powerpc/platforms/Kconfig.cputype
@@ -99,6 +99,8 @@ config PPC_BOOK3S_64
 	select ARCH_SUPPORTS_NUMA_BALANCING
 	select IRQ_WORK
 	select PPC_MM_SLICES
+	select PPC_HAVE_KUAP if PPC_MEM_KEYS
+	select PPC_HAVE_KUEP if PPC_MEM_KEYS
 
 config PPC_BOOK3E_64
 	bool "Embedded processors"
@@ -350,8 +352,6 @@ config PPC_RADIX_MMU
 	bool "Radix MMU Support"
 	depends on PPC_BOOK3S_64
 	select ARCH_HAS_GIGANTIC_PAGE
-	select PPC_HAVE_KUEP
-	select PPC_HAVE_KUAP
 	default y
 	help
 	  Enable support for the Power ISA 3.0 Radix style MMU. Currently this
-- 
2.25.3


^ permalink raw reply related

* [RFC PATCH 07/25] powerpc/book3s64/kuep: Move KUEP related function outside radix
From: Aneesh Kumar K.V @ 2020-04-27  8:04 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

The next set of patches adds support for kuep with hash translation.
In preparation for that rename/move kuap related functions to
non radix names.

Also set MMU_FTR_KUEP and add the missing isync().

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/include/asm/book3s/64/kup.h |  1 +
 arch/powerpc/mm/book3s64/pkeys.c         | 21 +++++++++++++++++++++
 arch/powerpc/mm/book3s64/radix_pgtable.c | 18 ------------------
 3 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/kup.h b/arch/powerpc/include/asm/book3s/64/kup.h
index 8d76044a971f..047f4298c053 100644
--- a/arch/powerpc/include/asm/book3s/64/kup.h
+++ b/arch/powerpc/include/asm/book3s/64/kup.h
@@ -7,6 +7,7 @@
 
 #define AMR_KUAP_BLOCK_READ	UL(0x4000000000000000)
 #define AMR_KUAP_BLOCK_WRITE	UL(0x8000000000000000)
+#define AMR_KUEP_BLOCKED	(1UL << 62)
 #define AMR_KUAP_BLOCKED	(AMR_KUAP_BLOCK_READ | AMR_KUAP_BLOCK_WRITE)
 #define AMR_KUAP_SHIFT		62
 
diff --git a/arch/powerpc/mm/book3s64/pkeys.c b/arch/powerpc/mm/book3s64/pkeys.c
index efb65629d05b..dc6b56c6e004 100644
--- a/arch/powerpc/mm/book3s64/pkeys.c
+++ b/arch/powerpc/mm/book3s64/pkeys.c
@@ -198,6 +198,27 @@ void __init pkey_early_init_devtree(void)
 	return;
 }
 
+#ifdef CONFIG_PPC_KUEP
+void setup_kuep(bool disabled)
+{
+	if (disabled || !early_radix_enabled())
+		return;
+
+	if (smp_processor_id() == boot_cpuid) {
+		pr_info("Activating Kernel Userspace Execution Prevention\n");
+		cur_cpu_spec->mmu_features |= MMU_FTR_KUEP;
+	}
+
+	/*
+	 * Radix always uses key0 of the IAMR to determine if an access is
+	 * allowed. We set bit 0 (IBM bit 1) of key0, to prevent instruction
+	 * fetch.
+	 */
+	mtspr(SPRN_IAMR, AMR_KUEP_BLOCKED);
+	isync();
+}
+#endif
+
 #ifdef CONFIG_PPC_KUAP
 void setup_kuap(bool disabled)
 {
diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c
index 74558ce6b5cb..3fb088eecece 100644
--- a/arch/powerpc/mm/book3s64/radix_pgtable.c
+++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
@@ -508,24 +508,6 @@ static void radix_init_amor(void)
 	mtspr(SPRN_AMOR, (3ul << 62));
 }
 
-#ifdef CONFIG_PPC_KUEP
-void setup_kuep(bool disabled)
-{
-	if (disabled || !early_radix_enabled())
-		return;
-
-	if (smp_processor_id() == boot_cpuid)
-		pr_info("Activating Kernel Userspace Execution Prevention\n");
-
-	/*
-	 * Radix always uses key0 of the IAMR to determine if an access is
-	 * allowed. We set bit 0 (IBM bit 1) of key0, to prevent instruction
-	 * fetch.
-	 */
-	mtspr(SPRN_IAMR, (1ul << 62));
-}
-#endif
-
 void __init radix__early_init_mmu(void)
 {
 	unsigned long lpcr;
-- 
2.25.3


^ permalink raw reply related

* [RFC PATCH 06/25] powerpc/book3s64/kuap: Move KUAP related function outside radix
From: Aneesh Kumar K.V @ 2020-04-27  8:04 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V, linuxram, npiggin
In-Reply-To: <20200427080507.1626327-1-aneesh.kumar@linux.ibm.com>

The next set of patches adds support for kuap with hash translation.
In preparation for that rename/move kuap related functions to
non radix names.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 .../asm/book3s/64/{kup-radix.h => kup.h}       |  6 +++---
 arch/powerpc/include/asm/kup.h                 |  2 +-
 arch/powerpc/kernel/syscall_64.c               |  2 +-
 arch/powerpc/mm/book3s64/pkeys.c               | 18 ++++++++++++++++++
 arch/powerpc/mm/book3s64/radix_pgtable.c       | 18 ------------------
 5 files changed, 23 insertions(+), 23 deletions(-)
 rename arch/powerpc/include/asm/book3s/64/{kup-radix.h => kup.h} (96%)

diff --git a/arch/powerpc/include/asm/book3s/64/kup-radix.h b/arch/powerpc/include/asm/book3s/64/kup.h
similarity index 96%
rename from arch/powerpc/include/asm/book3s/64/kup-radix.h
rename to arch/powerpc/include/asm/book3s/64/kup.h
index 224658efe2fd..8d76044a971f 100644
--- a/arch/powerpc/include/asm/book3s/64/kup-radix.h
+++ b/arch/powerpc/include/asm/book3s/64/kup.h
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_POWERPC_BOOK3S_64_KUP_RADIX_H
-#define _ASM_POWERPC_BOOK3S_64_KUP_RADIX_H
+#ifndef _ASM_POWERPC_BOOK3S_64_KUP_H
+#define _ASM_POWERPC_BOOK3S_64_KUP_H
 
 #include <linux/const.h>
 #include <asm/reg.h>
@@ -160,4 +160,4 @@ static inline void kuap_check_amr(void)
 
 #endif /* __ASSEMBLY__ */
 
-#endif /* _ASM_POWERPC_BOOK3S_64_KUP_RADIX_H */
+#endif /* _ASM_POWERPC_BOOK3S_64_KUP_H */
diff --git a/arch/powerpc/include/asm/kup.h b/arch/powerpc/include/asm/kup.h
index 92bcd1a26d73..248438dff74a 100644
--- a/arch/powerpc/include/asm/kup.h
+++ b/arch/powerpc/include/asm/kup.h
@@ -13,7 +13,7 @@
 #define KUAP_CURRENT	4
 
 #ifdef CONFIG_PPC64
-#include <asm/book3s/64/kup-radix.h>
+#include <asm/book3s/64/kup.h>
 #endif
 #ifdef CONFIG_PPC_8xx
 #include <asm/nohash/32/kup-8xx.h>
diff --git a/arch/powerpc/kernel/syscall_64.c b/arch/powerpc/kernel/syscall_64.c
index 0625c251548b..09695e042363 100644
--- a/arch/powerpc/kernel/syscall_64.c
+++ b/arch/powerpc/kernel/syscall_64.c
@@ -2,7 +2,7 @@
 
 #include <linux/err.h>
 #include <asm/asm-prototypes.h>
-#include <asm/book3s/64/kup-radix.h>
+#include <asm/book3s/64/kup.h>
 #include <asm/cputime.h>
 #include <asm/hw_irq.h>
 #include <asm/kprobes.h>
diff --git a/arch/powerpc/mm/book3s64/pkeys.c b/arch/powerpc/mm/book3s64/pkeys.c
index 8a589509d6fc..efb65629d05b 100644
--- a/arch/powerpc/mm/book3s64/pkeys.c
+++ b/arch/powerpc/mm/book3s64/pkeys.c
@@ -198,6 +198,24 @@ void __init pkey_early_init_devtree(void)
 	return;
 }
 
+#ifdef CONFIG_PPC_KUAP
+void setup_kuap(bool disabled)
+{
+	if (disabled || !early_radix_enabled())
+		return;
+
+	if (smp_processor_id() == boot_cpuid) {
+		pr_info("Activating Kernel Userspace Access Prevention\n");
+		cur_cpu_spec->mmu_features |= MMU_FTR_RADIX_KUAP;
+	}
+
+	/* Make sure userspace can't change the AMR */
+	mtspr(SPRN_UAMOR, 0);
+	mtspr(SPRN_AMR, AMR_KUAP_BLOCKED);
+	isync();
+}
+#endif
+
 void pkey_mm_init(struct mm_struct *mm)
 {
 	if (!mmu_has_feature(MMU_FTR_PKEY))
diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c
index 8f9edf07063a..74558ce6b5cb 100644
--- a/arch/powerpc/mm/book3s64/radix_pgtable.c
+++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
@@ -526,24 +526,6 @@ void setup_kuep(bool disabled)
 }
 #endif
 
-#ifdef CONFIG_PPC_KUAP
-void setup_kuap(bool disabled)
-{
-	if (disabled || !early_radix_enabled())
-		return;
-
-	if (smp_processor_id() == boot_cpuid) {
-		pr_info("Activating Kernel Userspace Access Prevention\n");
-		cur_cpu_spec->mmu_features |= MMU_FTR_RADIX_KUAP;
-	}
-
-	/* Make sure userspace can't change the AMR */
-	mtspr(SPRN_UAMOR, 0);
-	mtspr(SPRN_AMR, AMR_KUAP_BLOCKED);
-	isync();
-}
-#endif
-
 void __init radix__early_init_mmu(void)
 {
 	unsigned long lpcr;
-- 
2.25.3


^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox