]> git.karo-electronics.de Git - karo-tx-linux.git/log
karo-tx-linux.git
8 years agopowerpc/powernv: Rename PE# fields in struct pnv_phb
Gavin Shan [Tue, 3 May 2016 05:41:24 +0000 (15:41 +1000)]
powerpc/powernv: Rename PE# fields in struct pnv_phb

This renames the fields related to PE number in "struct pnv_phb"
for better reflecting of their usages as Alexey suggested. No
logical changes introduced.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/powernv: Reorder fields in struct pnv_phb
Gavin Shan [Tue, 3 May 2016 05:41:23 +0000 (15:41 +1000)]
powerpc/powernv: Reorder fields in struct pnv_phb

This moves those fields in struct pnv_phb that are related to PE
allocation around. No logical change.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/powernv: Drop phb->bdfn_to_pe()
Gavin Shan [Tue, 3 May 2016 05:41:22 +0000 (15:41 +1000)]
powerpc/powernv: Drop phb->bdfn_to_pe()

The last usage of pnv_phb::bdfn_to_pe() was removed in
ff57b454ddb9 ("powerpc/eeh: Do probe on pci_dn"), so drop it.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/powernv: Cleanup on pci_controller_ops instances
Gavin Shan [Tue, 3 May 2016 05:41:21 +0000 (15:41 +1000)]
powerpc/powernv: Cleanup on pci_controller_ops instances

This cleans up on below data struct instances to use tab instead of
space indent of statement to avoid complains from scripts/checkpatch.pl.
No logical changes introduced.

  @pnv_pci_ioda_controller_ops
  @pnv_npu_ioda_controller_ops

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Reviewed-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Acked-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/pci: Cleanup on struct pci_controller_ops
Gavin Shan [Tue, 3 May 2016 05:41:20 +0000 (15:41 +1000)]
powerpc/pci: Cleanup on struct pci_controller_ops

Each PHB has one instance of "struct pci_controller_ops" that includes
various callbacks called by PCI subsystem. In the definition of this
struct, some callbacks have explicit names for its arguments, but the
left don't have.

This adds all explicit names of the arguments to the callbacks in
"struct pci_controller_ops" so that the code looks consistent. Also,
argument name @dev is replaced by @pdev as the later one is the
preferred name for PCI device.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Reviewed-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agoselftests/powerpc: Add test to check if TM SPRs are corrupted
Rashmica Gupta [Wed, 23 Dec 2015 05:49:54 +0000 (16:49 +1100)]
selftests/powerpc: Add test to check if TM SPRs are corrupted

Testing that the TM SPRs are behaving the way they should. Uses more
threads than cpus to see if the following register values persist with
context switching:
- the FS (failure summary) flag in TEXASR
- TFIAR and TFHAR

Signed-off-by: Rashmica Gupta <rashmicy@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agoselftests/powerpc: Add TM test to check if TAR is corrupted
Rashmica Gupta [Wed, 23 Dec 2015 05:49:53 +0000 (16:49 +1100)]
selftests/powerpc: Add TM test to check if TAR is corrupted

If the transaction is aborted, the TAR should be rolled back to the
checkpointed value before the transaction began. The value written to the
TAR when the transaction is suspended should only remain there if the
transaction completes successfully.

Signed-off-by: Rashmica Gupta <rashmicy@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agoselftests/powerpc: Add test for forking inside transaction
Rashmica Gupta [Wed, 23 Dec 2015 05:49:52 +0000 (16:49 +1100)]
selftests/powerpc: Add test for forking inside transaction

This test does a fork syscall inside a transaction. Basic sniff test to see
if we can enter the kernel during a transaction.

Signed-off-by: Rashmica Gupta <rashmicy@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agoselftests/powerpc: Standardise TM calls
Rashmica Gupta [Wed, 23 Dec 2015 05:49:51 +0000 (16:49 +1100)]
selftests/powerpc: Standardise TM calls

Currently tbegin, tend etc are written as opcodes or asm instructions. So
standardise these to asm instructions.

Signed-off-by: Rashmica Gupta <rashmicy@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agoselftests/powerpc: Make reg.h common to all powerpc selftests
Rashmica Gupta [Wed, 23 Dec 2015 05:49:50 +0000 (16:49 +1100)]
selftests/powerpc: Make reg.h common to all powerpc selftests

Currently there is a reg.h in pmu/ebb that has defines that are useful
in other powerpc selftests so move this up into selftests/powerpc
folder. Also include in utils.h - as this is often used in self tests.
Add in some other useful register defines.

Signed-off-by: Rashmica Gupta <rashmicy@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/powernv: Rename machine_check_pSeries_early() to powernv
Mahesh Salgaonkar [Tue, 1 Mar 2016 05:47:46 +0000 (11:17 +0530)]
powerpc/powernv: Rename machine_check_pSeries_early() to powernv

The routine machine_check_pSeries_early() is only used on powernv, not
pseries. Hence rename machine_check_pSeries_early() to
machine_check_powernv_early().

Reported-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agocxl: Check periodically the coherent platform function's state
Christophe Lombard [Fri, 22 Apr 2016 13:39:22 +0000 (15:39 +0200)]
cxl: Check periodically the coherent platform function's state

In the PowerVM environment, the PHYP CoherentAccel component manages
the state of the Coherent Accelerator Processor Interface adapter and
virtualizes CAPI resources, handles CAPP, PSL, PSL Slice errors - and
interrupts - and provides a new set of hcalls for the OS APIs to utilize
Accelerator Function Unit (AFU).

During the course of operation, a coherent platform function can
encounter errors. Some possible reason for errors are:
• Hardware recoverable and unrecoverable errors
• Transient and over-threshold correctable errors

PHYP implements its own state model for the coherent platform function.
The state of the AFU is available through a hcall.

The current implementation of the cxl driver, for the PowerVM
environment, checks this state of the AFU only when an action is
requested - open a device, ioctl command, memory map, attach/detach a
process - from an external driver - cxlflash, libcxl. If an error is
detected the cxl driver handles the error according the content of the
Power Architecture Platform Requirements document.

But in case of low-level troubles (or error injection), the PHYP
component may reset the card and change the AFU state. The PHYP
interface doesn't provide any way to be notified when that happens thus
implies that the cxl driver:
• cannot handle immediatly the state change of the AFU.
• cannot notify other drivers (cxlflash, ...)

The purpose of this patch is to wake up the cpu periodically to check
the current state of each AFU and to see if we need to enter an error
recovery path.

Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
Acked-by: Ian Munsie <imunsie@au1.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agocxl: Add kernel API to allow a context to operate with relocate disabled
Ian Munsie [Fri, 6 May 2016 07:46:36 +0000 (17:46 +1000)]
cxl: Add kernel API to allow a context to operate with relocate disabled

cxl devices typically access memory using an MMU in much the same way as
the CPU, and each context includes a state register much like the MSR in
the CPU. Like the CPU, the state register includes a bit to enable
relocation, which we currently always enable.

In some cases, it may be desirable to allow a device to access memory
using real addresses instead of effective addresses, so this adds a new
API, cxl_set_translation_mode, that can be used to disable relocation
on a given kernel context. This can allow for the creation of a special
privileged context that the device can use if it needs relocation
disabled, and can use regular contexts at times when it needs relocation
enabled.

This interface is only available to users of the kernel API for obvious
reasons, and will never be supported in a virtualised environment.

This will be used by the upcoming cxl support in the mlx5 driver.

Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agocxl: Ensure PSL interrupt is configured for contexts with no AFU IRQs
Ian Munsie [Wed, 4 May 2016 04:52:58 +0000 (14:52 +1000)]
cxl: Ensure PSL interrupt is configured for contexts with no AFU IRQs

In the cxl kernel API, it is possible to create a context and start it
without allocating any interrupts. Since we assign or allocate the PSL
interrupt when allocating AFU interrupts this will lead to a situation
where we start the context with no means to take any faults.

The user API is not affected as it always goes through the cxl interrupt
allocation code paths and will have the PSL interrupt allocated or
assigned, even if no AFU interrupts were requested.

This checks that at least one interrupt is configured at the time of
attach, and if not it will assign the multiplexed PSL interrupt for
powernv, or allocate a single interrupt for PowerVM.

Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
Reviewed-by: Frederic Barrat <fbarrat@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agocxl: Remove duplicate #defines
Ian Munsie [Wed, 4 May 2016 04:48:32 +0000 (14:48 +1000)]
cxl: Remove duplicate #defines

These defines are not used, but other equivalent definitions
(CXL_SPA_SW_CMD_*) are used. Remove the unused defines.

Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agocxl: Handle num_of_processes larger than can fit in the SPA
Ian Munsie [Wed, 4 May 2016 04:46:30 +0000 (14:46 +1000)]
cxl: Handle num_of_processes larger than can fit in the SPA

num_of_process is a 16 bit field, theoretically allowing an AFU to
support 16K processes, however the scheduled process area currently has
a maximum size of 1MB, which limits the maximum number of processes to
7704.

Some AFUs may not necessarily care what the limit is and just want to be
able to use the maximum by setting the field to 16K. To allow these to
work, detect this situation and use the maximum size for the SPA.

Downgrade the WARN_ON to a dev_warn.

Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Improve readability of update_mmu_cache()
Gavin Shan [Fri, 26 Feb 2016 00:26:26 +0000 (11:26 +1100)]
powerpc/mm: Improve readability of update_mmu_cache()

The function is used to update the MMU with software PTE. It can
be called by data access exception handler (0x300) or instruction
access exception handler (0x400). If the function is called by
0x400 handler, the local variable @access is set to _PAGE_EXEC
to indicate the software PTE should have that flag set. When the
function is called by 0x300 handler, @access is set to zero.

This improves the readability of the function by replacing if
statements with switch. No logical changes introduced.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: define TOP_ZONE as a constant
Oliver O'Halloran [Thu, 5 May 2016 07:54:08 +0000 (17:54 +1000)]
powerpc/mm: define TOP_ZONE as a constant

The zone that contains the top of memory will be either ZONE_NORMAL
or ZONE_HIGHMEM depending on the kernel config. There are two functions
that require this information and both of them use an #ifdef to set
a local variable (top_zone). This is a little silly so lets just make it
a constant.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
Cc: linux-mm@kvack.org
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/sstep: Fix emulation fall-through
Oliver O'Halloran [Tue, 16 Feb 2016 06:31:53 +0000 (17:31 +1100)]
powerpc/sstep: Fix emulation fall-through

There is a switch fallthough in instr_analyze() which can cause an
invalid instruction to be emulated as a different, valid, instruction.
The rld* (opcode 30) case extracts a sub-opcode from bits 3:1 of the
instruction word. However, the only valid values of this field are 001
and 000. These cases are correctly handled, but the others are not which
causes execution to fall through into case 31.

Breaking out of the switch causes the instruction to be marked as
unknown and allows the caller to deal with the invalid instruction in a
manner consistent with other invalid instructions.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/sstep: Fix sstep.c compile on powerpcspe
Lennart Sorensen [Thu, 5 May 2016 20:44:44 +0000 (16:44 -0400)]
powerpc/sstep: Fix sstep.c compile on powerpcspe

Commit be96f63375a1 ("powerpc: Split out instruction analysis part of
emulate_step()") introduced ldarx and stdcx into the instructions in
sstep.c, which are not accepted by the assembler on powerpcspe, but does
seem to be accepted by the normal powerpc assembler even in 32 bit mode.

Wrap these two instructions in a __powerpc64__ check like it is
everywhere else in the file.

Fixes: be96f63375a1 ("powerpc: Split out instruction analysis part of emulate_step()")
Signed-off-by: Len Sorensen <lsorense@csclub.uwaterloo.ca>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/xmon: Fix SPR read/write commands and add command to dump SPRs
Paul Mackerras [Wed, 13 Apr 2016 11:31:24 +0000 (21:31 +1000)]
powerpc/xmon: Fix SPR read/write commands and add command to dump SPRs

xmon has commands for reading and writing SPRs, but they don't work
currently for several reasons. They attempt to synthesize a small
function containing an mfspr or mtspr instruction and call it. However,
the instructions are on the stack, which is usually not executable.
Also, for 64-bit we set up a procedure descriptor, which is fine for the
big-endian ABIv1, but not correct for ABIv2. Finally, the code uses the
infrastructure for catching memory errors, but that only catches data
storage interrupts and machine check interrupts, but a failed
mfspr/mtspr can generate a program interrupt or a hypervisor emulation
assist interrupt, or be a no-op.

Instead of trying to synthesize a function on the fly, this adds two new
functions, xmon_mfspr() and xmon_mtspr(), which take an SPR number as an
argument and read or write the SPR. Because there is no Power ISA
instruction which takes an SPR number in a register, we have to generate
one of each possible mfspr and mtspr instruction, for all 1024 possible
SPRs. Thus we get just over 8k bytes of code for each of xmon_mfspr()
and xmon_mtspr(). However, this 16kB of code pales in comparison to the
> 130kB of PPC opcode tables used by the xmon disassembler.

To catch interrupts caused by the mfspr/mtspr instructions, we add a new
'catch_spr_faults' flag. If an interrupt occurs while it is set, we come
back into xmon() via program_check_interrupt(), _exception() and die(),
see that catch_spr_faults is set and do a longjmp to bus_error_jmp, back
into read_spr() or write_spr().

This adds a couple of other nice features: first, a "Sa" command that
attempts to read and print out the value of all 1024 SPRs. If any mfspr
instruction acts as a no-op, then the SPR is not implemented and not
printed.

Secondly, the Sr and Sw commands detect when an SPR is not
implemented (i.e. mfspr is a no-op) and print a message to that effect
rather than printing a bogus value.

Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agoperf tools: Fix perf regs mask generation
Naveen N. Rao [Thu, 28 Apr 2016 09:31:10 +0000 (15:01 +0530)]
perf tools: Fix perf regs mask generation

On some architectures (powerpc in particular), the number of registers
exceeds what can be represented in an integer bitmask. Ensure we
generate the proper bitmask on such platforms.

Fixes: 71ad0f5e4 ("perf tools: Support for DWARF CFI unwinding on post processing")
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agoperf/powerpc: Add support for unwinding perf-stackdump
Chandan Kumar [Thu, 28 Apr 2016 09:31:09 +0000 (15:01 +0530)]
perf/powerpc: Add support for unwinding perf-stackdump

Adds support for unwinding user stack dump by linking with libunwind.

Signed-off-by: Chandan Kumar <chandan.kumar@linux.vnet.ibm.com>
Reviewed-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Tested-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc: Add HAVE_PERF_USER_STACK_DUMP support
Chandan Kumar [Thu, 28 Apr 2016 09:31:08 +0000 (15:01 +0530)]
powerpc: Add HAVE_PERF_USER_STACK_DUMP support

With perf regs support enabled for powerpc, in commit ed4a4ef85cf5
("powerpc/perf: Add support for sampling interrupt register state"),
the support for obtaining perf user stack dump is already enabled. This
patch declares the support for same and also updates documentation to
mark the support for perf-regs and perf-stackdump.

Signed-off-by: Chandan Kumar <chandan.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/hash64: Fix subpage protection with 4K HPTE config
Michael Ellerman [Fri, 6 May 2016 06:47:12 +0000 (16:47 +1000)]
powerpc/mm/hash64: Fix subpage protection with 4K HPTE config

With Linux page size of 64K and hardware only supporting 4K HPTE, if we
use subpage protection, we always fail for the subpage 0 as shown
below (using the selftest subpage_prot test):

  520175565:  (4520111850): Failed at 0x3fffad4b0000 (p=13,sp=0,w=0), want=fault, got=pass !
  4520890210: (4520826495): Failed at 0x3fffad5b0000 (p=29,sp=0,w=0), want=fault, got=pass !
  4521574251: (4521510536): Failed at 0x3fffad6b0000 (p=45,sp=0,w=0), want=fault, got=pass !
  4522258324: (4522194609): Failed at 0x3fffad7b0000 (p=61,sp=0,w=0), want=fault, got=pass !

This is because hash preload wrongly inserts the HPTE entry for subpage
0 without looking at the subpage protection information.

Fix it by teaching should_hash_preload() not to preload if we have
subpage protection configured for that range.

It appears this has been broken since it was introduced in 2008.

Fixes: fa28237cfcc5 ("[POWERPC] Provide a way to protect 4k subpages when using 64k pages")
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
[mpe: Rework into should_hash_preload() to avoid build fails w/SLICES=n]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/hash64: Factor out hash preload psize check
Michael Ellerman [Fri, 6 May 2016 06:46:00 +0000 (16:46 +1000)]
powerpc/mm/hash64: Factor out hash preload psize check

Currently we have a check in hash_preload() against the psize, which is
only included when CONFIG_PPC_MM_SLICES is enabled. We want to expand
this check in a subsequent patch, so factor it out to allow that. As a
bonus it removes the #ifdef in the C code.

Unfortunately we can't put this in the existing CONFIG_PPC_MM_SLICES
block because it would require a forward declaration.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc: Update of_remove_property() call sites to remove null checking
Suraj Jitindar Singh [Thu, 28 Apr 2016 05:34:55 +0000 (15:34 +1000)]
powerpc: Update of_remove_property() call sites to remove null checking

After obtaining a property from of_find_property() and before calling
of_remove_property() most code checks to ensure that the property
returned from of_find_property() is not null. The previous patch moved
this check to the start of the function of_remove_property() in order to
avoid the case where this check isn't done and a null value is passed.
This ensures the check is always conducted before taking locks and
attempting to remove the property. Thus it is no longer necessary to
perform a check for null values before invoking of_remove_property().

Update of_remove_property() call sites in order to remove redundant
checking for null property value as check is now performed within the
of_remove_property function().

Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
[mpe: Unbreak some lines which are just >80 chars for readability]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agodrivers/of: Add check for null property in of_remove_property()
Suraj Jitindar Singh [Thu, 28 Apr 2016 05:34:54 +0000 (15:34 +1000)]
drivers/of: Add check for null property in of_remove_property()

The validity of the property input argument to of_remove_property() is
never checked within the function and thus it is possible to pass a null
value. It happens that this will be picked up in __of_remove_property()
as no matching property of the device node will be found and thus an
error will be returned, however once again there is no explicit check
for a null value. By the time this is detected 2 locks have already been
acquired which is completely unnecessary if the property to remove is
null.

Add an explicit check in the function of_remove_property() for a null
property value and return -ENODEV in this case, this is consistent with
what the previous return value would have been when the null value was
not detected and passed to __of_remove_property().

By moving an explicit check for the property paramenter into the
of_remove_property() function, this will remove the need to perform this
check in calling code before invocation of the of_remove_property()
function.

Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/pseries: Add null property check to pseries_discover_pic()
Suraj Jitindar Singh [Thu, 28 Apr 2016 05:53:45 +0000 (15:53 +1000)]
powerpc/pseries: Add null property check to pseries_discover_pic()

The return value of of_get_property() isn't checked before it is passed
to the strstr() function, if it happens that the return value is null
then this will result in a null pointer being dereferenced.

Add a check to see if the return value of of_get_property() is null and
if it is continue straight on to the next node.

Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
Reviewed-by: Chris Smart <chris@distroguy.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/powernv/pci: Fix cfg_dbg() & replace with pr_devel()
Alexey Kardashevskiy [Mon, 2 May 2016 07:06:12 +0000 (17:06 +1000)]
powerpc/powernv/pci: Fix cfg_dbg() & replace with pr_devel()

When cfg_dbg() is enabled (i.e. mapped to printk()), gcc produces
errors as the __func__ parameter is missing (pnv_pci_cfg_read() has one);
this adds the missing parameter.

cfg_dbg() is just an inferior version of pr_devel() so use the latter
instead.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agoselftests/powerpc: Fix subpage_prot test to return !0 on failure
Michael Ellerman [Mon, 2 May 2016 04:54:29 +0000 (14:54 +1000)]
selftests/powerpc: Fix subpage_prot test to return !0 on failure

It's helpful for automated testing if the test returns error codes back
to the calling program.

While we're here fix all the usages of %p to remove the double 0x, ie.
%p already includes 0x.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
8 years agoselftests/powerpc: Test cp_abort during context switch
Chris Smart [Mon, 2 May 2016 03:51:38 +0000 (13:51 +1000)]
selftests/powerpc: Test cp_abort during context switch

Test that performing a copy paste sequence in userspace on P9 does not
result in a leak of the copy into the paste of another process.

This is based on Anton Blanchard's context_switch benchmarking code. It
sets up two processes tied to the same CPU, one which copies and one
which pastes.

The paste should never succeed and the test fails if it does.

This is a test for commit, "8a64904 powerpc: Add support for userspace
P9 copy paste."

Patch created with much assistance from Michael Neuling
<mikey@neuling.org>

Signed-off-by: Chris Smart <chris@distroguy.com>
Reviewed-by: Cyril Bur <cyrilbur@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc: Remove unnecessary CONFIG_SMP #ifdefs
Chris Smart [Mon, 2 May 2016 06:00:58 +0000 (16:00 +1000)]
powerpc: Remove unnecessary CONFIG_SMP #ifdefs

The code in machine_restart/power_off/halt() includes #ifdefs around
calls to smp_send_stop(), however these are not required as
include/linux/smp.h includes an empty version of this function for
CONFIG_SMP=n builds.

Signed-off-by: Chris Smart <chris@distroguy.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc: Remove unused remnants from A2 cpu
Rashmica Gupta [Tue, 12 Apr 2016 05:33:58 +0000 (15:33 +1000)]
powerpc: Remove unused remnants from A2 cpu

Support for the A2 cpu was removed in commit fb5a515704d7 ("powerpc:
Remove platforms/wsp and associated pieces"), and the externs:
__setup_cpu_a2 and __restore_cpu_a2 are still around and unused, so
remove them.

Signed-off-by: Rashmica Gupta <rashmicy@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/slice: Remove slice_mm_new_context()
Aneesh Kumar K.V [Mon, 2 May 2016 12:56:07 +0000 (18:26 +0530)]
powerpc/mm/slice: Remove slice_mm_new_context()

The usage in mm mmu_context_nohash.c is bogus, because we set the
context.id value to MMU_NO_CONTEXT 4 lines previously in the same
function, meaning slice_mm_new_context() will always be true.

The book3s 64 usage was removed in the previous commit. So remove it as
unused.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/subpage: Initialise user psize correctly
Aneesh Kumar K.V [Mon, 2 May 2016 10:51:50 +0000 (16:21 +0530)]
powerpc/mm/subpage: Initialise user psize correctly

As part of the radix support we switched Book3s64 to use a value of ~0
for MMU_NO_CONTEXT. That is because id 0 is special on radix.

However that broke the logic in init_new_context(). The code there needs
to differentiate between a newly allocated context and one inherited via
fork. Previously it worked because a newly allocated context has an id
of zero (because it was just memset() to zero), which used to match
MMU_NO_CONTEXT, and therefore slice_mm_new_context() did the right
thing.

Instead check against a context.id value of zero instead of using
slice_mm_new_context().

Without this patch we never call slice_set_user_psize(), and end up with
a slice psize value of zero and we always end up using 4K HPTE.

Fixes: 1a472c9dba6b ("powerpc/mm/radix: Add tlbflush routines")
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Fix CONFIG_PPC_MMU_STD_64 typo
Valentin Rothberg [Tue, 3 May 2016 06:59:27 +0000 (08:59 +0200)]
powerpc/mm/radix: Fix CONFIG_PPC_MMU_STD_64 typo

It's CONFIG_PPC_STD_MMU_64 not ...
     CONFIG_PPC_MMU_STD_64.

Fixes: 11ffc1cfa4c2 ("powerpc/mm/radix: Use STD_MMU_64 to properly isolate hash related code")
Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Document software bits for radix
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:33 +0000 (23:26 +1000)]
powerpc/mm/radix: Document software bits for radix

Add #defines for Power ISA 3.0 software defined bits.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Use firmware feature to enable Radix MMU
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:32 +0000 (23:26 +1000)]
powerpc/mm/radix: Use firmware feature to enable Radix MMU

We use the existing "ibm,pa-features" device-tree property to enable
Radix MMU mode. This means we default to hash mode unless firmware tells
us it's OK to start using Radix mode.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Add THP support for 4K linux page size
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:31 +0000 (23:26 +1000)]
powerpc/mm/radix: Add THP support for 4K linux page size

This adds THP support for 4K Linux page size config with radix. We still
don't do THP with 4K Linux page size and hash page table. Hash page
table needs a 16MB hugepage and we can't do THP with 16MM hugepage and
4K Linux page size.

We add missing functions to 4K hash config to get it to build and
hash__has_transparent_hugepage() makes sure we don't enable THP for 4K
hash config. To catch wrong usage of THP related with 4K config, we add
BUG() in those dummy functions we added to get it compile.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Add radix THP callbacks
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:30 +0000 (23:26 +1000)]
powerpc/mm/radix: Add radix THP callbacks

The deposited pgtable_t is a pte fragment hence we cannot use page->lru
for linking then together. We use the first two 64 bits for pte fragment
as list_head type to link all deposited fragments together. On withdraw
we properly zero then out.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/thp: Abstraction for THP functions
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:29 +0000 (23:26 +1000)]
powerpc/mm/thp: Abstraction for THP functions

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: THP is only available on hash64 as of now
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:28 +0000 (23:26 +1000)]
powerpc/mm: THP is only available on hash64 as of now

Only code movement in this patch. No functionality change.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Add hugetlb support 4K page size
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:27 +0000 (23:26 +1000)]
powerpc/mm/radix: Add hugetlb support 4K page size

We have hugepage at the pmd level with 4K radix config. Hence we don't
need to use hugepd format with radix.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Make sure swapper pgdir is properly aligned
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:26 +0000 (23:26 +1000)]
powerpc/mm/radix: Make sure swapper pgdir is properly aligned

With 4K page size radix config our level 1 page table size is 64K and it
should be naturally aligned.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Add radix support for hugetlb
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:25 +0000 (23:26 +1000)]
powerpc/mm: Add radix support for hugetlb

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Fix vma_mmu_pagesize() for radix
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:24 +0000 (23:26 +1000)]
powerpc/mm: Fix vma_mmu_pagesize() for radix

Radix doesn't use the slice framework to find the page size. Hence use
vma to find the page size.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: pte_frag abstraction
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:23 +0000 (23:26 +1000)]
powerpc/mm: pte_frag abstraction

In this patch we make the number of pte fragments per level 4 page table
page a variable. Radix level 4 table size is 256 bytes and hence we can
have 256 fragments per level 4 page. We don't update the fragment count
in this patch. We need to do performance measurements to find the right
value for fragment count.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/radix: Update MMU cache
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:22 +0000 (23:26 +1000)]
powerpc/radix: Update MMU cache

With radix there is no MMU cache. Hence we don't need to do anything in
update_mmu_cache().

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Acked-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: vmalloc abstraction in preparation for radix
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:21 +0000 (23:26 +1000)]
powerpc/mm: vmalloc abstraction in preparation for radix

The vmalloc range differs between hash and radix config. Hence make
VMALLOC_START and related constants a variable which will be runtime
initialized depending on whether hash or radix mode is active.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
[mpe: Fix missing init of ioremap_bot in pgtable_64.c for ppc64e]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Update pte filter for radix
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:20 +0000 (23:26 +1000)]
powerpc/mm: Update pte filter for radix

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Acked-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Add radix pgalloc details
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:19 +0000 (23:26 +1000)]
powerpc/mm: Add radix pgalloc details

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Make 4K and 64K use pte_t for pgtable_t
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:18 +0000 (23:26 +1000)]
powerpc/mm: Make 4K and 64K use pte_t for pgtable_t

This patch switches 4K Linux page size config to use pte_t * type
instead of struct page * for pgtable_t. This simplifies the code a lot
and helps in consolidating both 64K and 4K page allocator routines. The
changes should not have any impact, because we already store physical
address in the upper level page table tree and that implies we already
do struct page * to physical address conversion.

One change to note here is we move the pgtable_page_dtor() call for
nohash to pte_fragment_free_mm(). The nohash related change is due to
the related changes in pgtable_64.c.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Rename function to indicate we are allocating fragments
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:17 +0000 (23:26 +1000)]
powerpc/mm: Rename function to indicate we are allocating fragments

Only code cleanup. No functionality change.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Simplify the code dropping 4-level table #ifdef
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:16 +0000 (23:26 +1000)]
powerpc/mm: Simplify the code dropping 4-level table #ifdef

Simplify the code by dropping 4-level page table #ifdef. We are always
4-level now.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Revert changes made to nohash pgalloc-64.h
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:15 +0000 (23:26 +1000)]
powerpc/mm: Revert changes made to nohash pgalloc-64.h

This reverts pgalloc related changes WRT implementing 4-level page
table for 64K Linux page size and storing of physical address in higher
level page tables since they are only applicable to book3s64 variant
and we now have a separate copy for book3s64. This helps to keep these
headers simpler.

Cc: Scott Wood <scottwood@freescale.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Copy pgalloc (part 2)
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:14 +0000 (23:26 +1000)]
powerpc/mm: Copy pgalloc (part 2)

This moves the nohash variant of pgalloc headers to nohash/ directory

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Make a copy of pgalloc.h for 32 and 64 book3s
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:13 +0000 (23:26 +1000)]
powerpc/mm: Make a copy of pgalloc.h for 32 and 64 book3s

This patch start to make a book3s variant for pgalloc headers. We have
multiple book3s specific changes such as:
  * 4 level page table
  * store physical address in higher level table
  * use pte_t * for pgtable_t

Having a book3s64 specific variant helps to keep code simpler and remove
lots of #ifdef around code.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Update PTCR on secondary CPUs
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:12 +0000 (23:26 +1000)]
powerpc/mm/radix: Update PTCR on secondary CPUs

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Pick the address layout for radix config
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:11 +0000 (23:26 +1000)]
powerpc/mm/radix: Pick the address layout for radix config

Hash needs special get_unmapped_area() handling because of limitations
around base page size, so we have to set HAVE_ARCH_UNMAPPED_AREA.

With radix we don't have such restrictions, so we could use the generic
code. But because we've set HAVE_ARCH_UNMAPPED_AREA (for hash), we have
to re-implement the same logic as the generic code.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Limit paca allocation in radix
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:10 +0000 (23:26 +1000)]
powerpc/mm/radix: Limit paca allocation in radix

On return from RTAS we access the paca variables and we have 64 bit
disabled. This requires us to limit paca in 32 bit range.

Fix this by setting ppc64_rma_size to first_memblock_size/1G range.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Add checks in slice code to catch radix usage
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:09 +0000 (23:26 +1000)]
powerpc/mm/radix: Add checks in slice code to catch radix usage

Radix doesn't need slice support. Catch incorrect usage of slice code
when radix is enabled.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Isolate hash table function from pseries guest code
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:08 +0000 (23:26 +1000)]
powerpc/mm/radix: Isolate hash table function from pseries guest code

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Use STD_MMU_64 to properly isolate hash related code
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:07 +0000 (23:26 +1000)]
powerpc/mm/radix: Use STD_MMU_64 to properly isolate hash related code

We also use MMU_FTR_RADIX to branch out from code path specific to
hash.

No functionality change.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Add MMU_FTR_RADIX
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:06 +0000 (23:26 +1000)]
powerpc/mm/radix: Add MMU_FTR_RADIX

We are going to add asm changes in the follow up patches. Add the
feature bit now so that we can get it all build.

mpe: When CONFIG_PPC_RADIX_MMU=n we omit MMU_FTR_RADIX from the
MMU_FTRS_POSSIBLE mask. This allows the compiler to work out that those
checks will always be false and so the code can be elided completely.

Note we do *not* define MMU_FTR_RADIX to 0 in the RADIX_MMU=n case,
because that doesn't work with the ASM_FTR patching. In particular an
IF_SET section will result in a mask and value of zero, which is always
true, meaning the section *won't* be patched, which is the opposite of
what we want.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Acked-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Add mask of possible MMU features
Michael Ellerman [Wed, 11 May 2016 05:30:47 +0000 (15:30 +1000)]
powerpc/mm: Add mask of possible MMU features

Follow the example of the cpu feature code, and add a mask of possible
MMU features, MMU_FTRS_POSSIBLE.

This is used in mmu_has_feature(), which allows the possible mask to act
as a shortcut for any features that are not possible, but still allows
the feature bit itself to be defined.

We will use this in the next commit to allow MMU_FTR_RADIX checks to be
elided when MMU_FTR_RADIX is not possible.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Add tlbflush routines
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:05 +0000 (23:26 +1000)]
powerpc/mm/radix: Add tlbflush routines

Core kernel doesn't track the page size of the VA range that we are
invalidating. Hence we end up flushing TLB for the entire mm here. Later
patches will improve this.

We also don't flush page walk cache separetly instead use RIC=2 when
flushing TLB, because we do a MMU gather flush after freeing page table.

MMU_NO_CONTEXT is updated for hash.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Hash abstraction for tlbflush routines
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:04 +0000 (23:26 +1000)]
powerpc/mm: Hash abstraction for tlbflush routines

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Rename mmu_context_hash64.c to mmu_context_book3s64.c
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:03 +0000 (23:26 +1000)]
powerpc/mm: Rename mmu_context_hash64.c to mmu_context_book3s64.c

This file now contains both hash and radix specific code. Rename it to
indicate this better.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Add mmu context handling callback for radix
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:02 +0000 (23:26 +1000)]
powerpc/mm/radix: Add mmu context handling callback for radix

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Abstraction for switch_mmu_context()
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:01 +0000 (23:26 +1000)]
powerpc/mm: Abstraction for switch_mmu_context()

How we switch MMU context differs between hash and radix. For hash we
need to switch the SLB details and for radix we need to switch the PID
SPR.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Add radix callbacks for vmemmap and map_kernel page()
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:26:00 +0000 (23:26 +1000)]
powerpc/mm/radix: Add radix callbacks for vmemmap and map_kernel page()

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Abstraction for vmemmap and map_kernel_page()
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:59 +0000 (23:25 +1000)]
powerpc/mm: Abstraction for vmemmap and map_kernel_page()

For hash we create vmemmap mapping using bolted hash page table entries.
For radix we fill the radix page table. The next patch will add the
radix details for creating vmemmap mappings.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Add radix callbacks for early init routines
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:58 +0000 (23:25 +1000)]
powerpc/mm/radix: Add radix callbacks for early init routines

This adds routines for early setup for radix. We use device tree
property "ibm,processor-radix-AP-encodings" to find supported page
sizes. If we don't find the above we consider 64K and 4K as supported
page sizes.

We do map vmemap using 2M page size if we can. The linear mapping is
done such that we use required page size for that range. For example
memory of 3.5G is mapped such that we use 1G mapping till 3G range and
use 2M mapping for the rest.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Abstract early MMU init in preparation for radix
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:57 +0000 (23:25 +1000)]
powerpc/mm: Abstract early MMU init in preparation for radix

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Add radix callback for pmd accessors
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:56 +0000 (23:25 +1000)]
powerpc/mm/radix: Add radix callback for pmd accessors

This only does 64K Linux page support for now. 64K hash Linux config
THP needs to differentiate it from hugetlb huge page because with THP we
need to track hash pte slot information with respect to each subpage.
This is not needed with hugetlb hugepage, because we don't do MPSS with
hugetlb.

Radix doesn't have any such restrictions.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Move hugetlb and THP related pmd accessors to pgtable.h
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:55 +0000 (23:25 +1000)]
powerpc/mm: Move hugetlb and THP related pmd accessors to pgtable.h

Here we create pgtable-64/4k.h and move pmd accessors that are common
between hash and radix there. We can't do much sharing with 4K Linux
page size because 4K Linux page size with hash config doesn't support
THP. So for now it is empty. In later patches we will add functions that
does conditional hash/radix accessors there.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Add radix callbacks to pte accessors
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:54 +0000 (23:25 +1000)]
powerpc/mm: Add radix callbacks to pte accessors

For those pte accessors, that operate on a different set of pte bits
between hash/radix, we add a generic variant that does a conditional
to hash linux or radix variant.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Add dummy radix_enabled()
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:53 +0000 (23:25 +1000)]
powerpc/mm/radix: Add dummy radix_enabled()

In this patch we add the radix Kconfig and conditional check.
radix_enabled() is written to always return 0 here. Once we have all
needed radix changes added, we will update this to an mmu_feature check.

We need to add this early so that we can get it all build in the early
stage.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Add radix pte #defines
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:52 +0000 (23:25 +1000)]
powerpc/mm/radix: Add radix pte #defines

This adds Power ISA 3.0 specific pte defines. We share most of the
details with hash Linux page table format. This patch indicates only
things where we differ.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Move pte related functions together
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:51 +0000 (23:25 +1000)]
powerpc/mm: Move pte related functions together

Only code movement. No functionality change.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Acked-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Move page table index and and vaddr to pgtable.h
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:50 +0000 (23:25 +1000)]
powerpc/mm: Move page table index and and vaddr to pgtable.h

Now that the page table size is a variable, we can move these to
generic pgtable.h.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Make page table size a variable
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:49 +0000 (23:25 +1000)]
powerpc/mm: Make page table size a variable

Radix and hash MMU models support different page table sizes. Make
the #defines a variable so that existing code can work with variable
sizes.

Slice related code is only used by hash, so use hash constants there. We
will replicate some of the boundary conditions with resepct to TASK_SIZE
using radix values too. Right now we do boundary condition check using
hash constants.

Swapper pgdir size is initialized in asm code. We select the max pgd
size to keep it simple. For now we select hash pgdir. When adding radix
we will switch that to radix pgdir which is 64K.

BUILD_BUG_ON check which is removed is already done in hugepage_init()
using MAYBE_BUILD_BUG_ON().

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Move pte accessors that operate on common pte bits to pgtable.h
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:48 +0000 (23:25 +1000)]
powerpc/mm: Move pte accessors that operate on common pte bits to pgtable.h

These pte functions will remain the same between radix and hash. Move
them to pgtable.h.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Move common pte bits and accessors to book3s/64/pgtable.h
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:47 +0000 (23:25 +1000)]
powerpc/mm: Move common pte bits and accessors to book3s/64/pgtable.h

Now that we have moved book3s hash64 Linux pte bits to match Power ISA
3.0 radix pte bit positions, we move the matching pte bits to a common
header.

Only code movement in this patch. No functionality change.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Handle _PTE_NONE_MASK
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:46 +0000 (23:25 +1000)]
powerpc/mm: Handle _PTE_NONE_MASK

I am splitting this as a separate patch to get better review. If ok
we should merge this with previous patch.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/book3s: Rename hash specific PTE bits to carry H_ prefix
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:45 +0000 (23:25 +1000)]
powerpc/mm/book3s: Rename hash specific PTE bits to carry H_ prefix

This helps to make following hash only pte bits easier.

We have kept _PAGE_CHG_MASK, _HPAGE_CHG_MASK and _PAGE_PROT_BITS as it
is in this patch eventhough they use hash specific bits. Using them in
radix as it is should be ok, because with radix we expect those bit
positions to be zero.

Only renames in this patch, no change in functionality.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Move hash and no hash code to separate files
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:44 +0000 (23:25 +1000)]
powerpc/mm: Move hash and no hash code to separate files

This patch reduces the number of #ifdefs in C code and will also help in
adding radix changes later. Only code movement in this patch.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
[mpe: Propagate copyrights and update GPL text]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/hash: Add support for Power9 Hash
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:43 +0000 (23:25 +1000)]
powerpc/mm/hash: Add support for Power9 Hash

PowerISA 3.0 adds a parition table indexed by LPID. Parition table
allows us to specify the MMU model that will be used for guest and host
translation.

This patch adds support with SLB based hash model (UPRT = 0). What is
required with this model is to support the new hash page table entry
format and also setup partition table such that we use hash table for
address translation.

We don't have segment table support yet.

In order to make sure we don't load KVM module on Power9 (since we don't
have kvm support yet) this patch also disables KVM on Power9.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm/radix: Add partition table format & callback
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:42 +0000 (23:25 +1000)]
powerpc/mm/radix: Add partition table format & callback

Add structs and #defines related to the radix MMU partition table
format. We also add a ppc_md callback for updating a partition table
entry.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Move radix/hash common data structures to book3s64 headers
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:41 +0000 (23:25 +1000)]
powerpc/mm: Move radix/hash common data structures to book3s64 headers

Start moving code that is generic between radix and hash to book3s64
specific headers from the book3s64 hash specific one.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Use generic version of ptep_clear_flush_young()
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:40 +0000 (23:25 +1000)]
powerpc/mm: Use generic version of ptep_clear_flush_young()

The radix variant is going to require a flush_tlb_range(). With
flush_tlb_range() added, ptep_clear_flush_young() is the same as the
generic version. So drop the powerpc specific variant.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Use generic version of pmdp_clear_flush_young()
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:39 +0000 (23:25 +1000)]
powerpc/mm: Use generic version of pmdp_clear_flush_young()

The radix variant is going to require a flush_pmd_tlb_range(). With
flush_pmd_tlb_range() added, pmdp_clear_flush_young() is the same as the
generic version. So drop the powerpc specific variant.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Drop WIMG in favour of new constants
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:38 +0000 (23:25 +1000)]
powerpc/mm: Drop WIMG in favour of new constants

PowerISA 3.0 introduces two pte bits with the below meaning for radix:
  00 -> Normal Memory
  01 -> Strong Access Order (SAO)
  10 -> Non idempotent I/O (Cache inhibited and guarded)
  11 -> Tolerant I/O (Cache inhibited)

We drop the existing WIMG bits in the Linux page table in favour of the
above constants. We loose _PAGE_WRITETHRU with this conversion. We only
use writethru via pgprot_cached_wthru() which is used by
fbdev/controlfb.c which is Apple control display and also PPC32.

With respect to _PAGE_COHERENCE, we have been marking hpte always
coherent for some time now. htab_convert_pte_flags() always added
HPTE_R_M.

NOTE: KVM changes need closer review.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Use a helper for finding pte bits mapping I/O area
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:37 +0000 (23:25 +1000)]
powerpc/mm: Use a helper for finding pte bits mapping I/O area

Use a helper instead of open coding with constants. A later patch will
drop the WIMG bits and use PowerISA 3.0 defines.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Update _PAGE_KERNEL_RO
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:36 +0000 (23:25 +1000)]
powerpc/mm: Update _PAGE_KERNEL_RO

PS3 had used a PPP bit hack to implement a read only mapping in the
kernel area. Since we are bolting the ioremap area, it used the pte
flags _PAGE_PRESENT | _PAGE_USER to get a PPP value of 0x3 there by
resulting in a read only mapping. This means the area can be accessed by
user space, but kernel will never return such an address to user space.

But we can do better by implementing a read only kernel mapping using
PPP bits 0b110.

This also allows us to do read only kernel mapping for radix in later
patches.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Remove RPN_SHIFT and RPN_SIZE
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:35 +0000 (23:25 +1000)]
powerpc/mm: Remove RPN_SHIFT and RPN_SIZE

PTE_RPN_SHIFT is actually page size dependent. Even though PowerISA 3.0
expects only the lower 12 bits to be zero, we will always find the pages
to be PAGE_SHIFT aligned. In case of hash config, this also allows us to
use the additional 3 bits to track pte specific information. We need
to make sure we use these bits only for hash specific pte flags.

For both 4K and 64K config, pte now can hold 57 bits address.

Inorder to keep things simpler, drop PTE_RPN_SHIFT and PTE_RPN_SIZE and
specify the 57 bit detail explicitly.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Replace _PAGE_USER with _PAGE_PRIVILEGED
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:34 +0000 (23:25 +1000)]
powerpc/mm: Replace _PAGE_USER with _PAGE_PRIVILEGED

_PAGE_PRIVILEGED means the page can be accessed only by the kernel. This
is done to keep pte bits similar to PowerISA 3.0 Radix PTE format. User
pages are now marked by clearing _PAGE_PRIVILEGED bit.

Previously we allowed the kernel to have a privileged page in the lower
address range (USER_REGION). With this patch such access is denied.

We also prevent a kernel access to a non-privileged page in higher
address range (ie, REGION_ID != 0).

Both the above access scenarios should never happen.

Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Jeremy Kerr <jk@ozlabs.org>
Cc: Frederic Barrat <fbarrat@linux.vnet.ibm.com>
Acked-by: Ian Munsie <imunsie@au1.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Use pte_user() instead of open coding
Aneesh Kumar K.V [Fri, 29 Apr 2016 13:25:33 +0000 (23:25 +1000)]
powerpc/mm: Use pte_user() instead of open coding

We have a common declaration in pte-common.h Add a book3s specific one
and switch to pte_user() in callchain.c. In a subsequent patch we will
switch _PAGE_USER to _PAGE_PRIVILEGED in the book3s version only.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
8 years agopowerpc/mm: Convert pte_user() to static inline
Michael Ellerman [Fri, 29 Apr 2016 13:25:32 +0000 (23:25 +1000)]
powerpc/mm: Convert pte_user() to static inline

In a subsequent patch we want to add a second definition of pte_user().
Before we do that, make the signature clear, ie. it takes a pte_t and
returns bool.

We move it up inside the existing #ifndef __ASSEMBLY__ block, but
otherwise it's a straight conversion.

Convert the call in settlbcam(), which passes an unsigned long, to pass
a pte_t.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>