* Re: [PATCH v2 0/8] powernv/memtrace: don't abuse memory hot(un)plug infrastructure for memory allocations
From: Michael Ellerman @ 2020-11-25 11:57 UTC (permalink / raw)
To: linux-kernel, David Hildenbrand
Cc: Michal Hocko, Wei Yang, Nicholas Piggin, Michal Hocko, linux-mm,
Paul Mackerras, Aneesh Kumar K.V, Rashmica Gupta, linuxppc-dev,
Andrew Morton, Mike Rapoport, Oscar Salvador
In-Reply-To: <20201111145322.15793-1-david@redhat.com>
On Wed, 11 Nov 2020 15:53:14 +0100, David Hildenbrand wrote:
> Based on latest linux/master
>
> powernv/memtrace is the only in-kernel user that rips out random memory
> it never added (doesn't own) in order to allocate memory without a
> linear mapping. Let's stop abusing memory hot(un)plug infrastructure for
> that - use alloc_contig_pages() for allocating memory and remove the
> linear mapping manually.
>
> [...]
Applied to powerpc/next.
[1/8] powerpc/powernv/memtrace: Don't leak kernel memory to user space
https://git.kernel.org/powerpc/c/c74cf7a3d59a21b290fe0468f5b470d0b8ee37df
[2/8] powerpc/powernv/memtrace: Fix crashing the kernel when enabling concurrently
https://git.kernel.org/powerpc/c/d6718941a2767fb383e105d257d2105fe4f15f0e
[3/8] powerpc/mm: factor out creating/removing linear mapping
https://git.kernel.org/powerpc/c/4abb1e5b63ac3281275315fc6b0cde0b9c2e2e42
[4/8] powerpc/mm: protect linear mapping modifications by a mutex
https://git.kernel.org/powerpc/c/e5b2af044f31bf18defa557a8cd11c23caefa34c
[5/8] powerpc/mm: print warning in arch_remove_linear_mapping()
https://git.kernel.org/powerpc/c/1f73ad3e8d755dbec52fcec98618a7ce4de12af2
[6/8] powerpc/book3s64/hash: Drop WARN_ON in hash__remove_section_mapping()
https://git.kernel.org/powerpc/c/d8bd9a121c2f2bc8b36da930dc91b69fd2a705e2
[7/8] powerpc/mm: remove linear mapping if __add_pages() fails in arch_add_memory()
https://git.kernel.org/powerpc/c/ca2c36cae9d48b180ea51259e35ab3d95d327df2
[8/8] powernv/memtrace: don't abuse memory hot(un)plug infrastructure for memory allocations
https://git.kernel.org/powerpc/c/0bd4b96d99108b7ea9bac0573957483be7781d70
cheers
^ permalink raw reply
* Re: [PATCH] powerpc/64s/perf: perf interrupt does not have to get_user_pages to access user memory
From: Michael Ellerman @ 2020-11-25 11:57 UTC (permalink / raw)
To: Nicholas Piggin, linuxppc-dev
In-Reply-To: <20201111120151.3150658-1-npiggin@gmail.com>
On Wed, 11 Nov 2020 22:01:51 +1000, Nicholas Piggin wrote:
> read_user_stack_slow that walks user address translation by hand is
> only required on hash, because a hash fault can not be serviced from
> "NMI" context (to avoid re-entering the hash code) so the user stack
> can be mapped into Linux page tables but not accessible by the CPU.
>
> Radix MMU mode does not have this restriction. A page fault failure
> would indicate the page is not accessible via get_user_pages either,
> so avoid this on radix.
Applied to powerpc/next.
[1/1] powerpc/64s/perf: perf interrupt does not have to get_user_pages to access user memory
https://git.kernel.org/powerpc/c/987c426320cce72d1b28f55c8603b239e4f7187c
cheers
^ permalink raw reply
* Re: [PATCH] powerpc: sysdev: add missing iounmap() on error in mpic_msgr_probe()
From: Michael Ellerman @ 2020-11-25 11:57 UTC (permalink / raw)
To: Qinglang Miao, Michael Ellerman, Benjamin Herrenschmidt,
Paul Mackerras
Cc: linuxppc-dev, linux-kernel
In-Reply-To: <20201028091551.136400-1-miaoqinglang@huawei.com>
On Wed, 28 Oct 2020 17:15:51 +0800, Qinglang Miao wrote:
> I noticed that iounmap() of msgr_block_addr before return from
> mpic_msgr_probe() in the error handling case is missing. So use
> devm_ioremap() instead of just ioremap() when remapping the message
> register block, so the mapping will be automatically released on
> probe failure.
Applied to powerpc/next.
[1/1] powerpc: sysdev: add missing iounmap() on error in mpic_msgr_probe()
https://git.kernel.org/powerpc/c/ffa1797040c5da391859a9556be7b735acbe1242
cheers
^ permalink raw reply
* Re: [PATCH] powerpc/85xx: Fix declaration made after definition
From: Michael Ellerman @ 2020-11-25 11:57 UTC (permalink / raw)
To: Michael Ellerman, linuxppc-dev
In-Reply-To: <20201023020838.3274226-1-mpe@ellerman.id.au>
On Fri, 23 Oct 2020 13:08:38 +1100, Michael Ellerman wrote:
> Currently the clang build of corenet64_smp_defconfig fails with:
>
> arch/powerpc/platforms/85xx/corenet_generic.c:210:1: error:
> attribute declaration must precede definition
> machine_arch_initcall(corenet_generic, corenet_gen_publish_devices);
>
> Fix it by moving the initcall definition prior to the machine
> definition, and directly below the function it calls, which is the
> usual style anyway.
Applied to powerpc/next.
[1/1] powerpc/85xx: Fix declaration made after definition
https://git.kernel.org/powerpc/c/ef78f2dd2398ce8ed9eeaab9c9f8af2e15f5d870
cheers
^ permalink raw reply
* Re: [PATCH] powerpc/ps3: Drop unused DBG macro
From: Michael Ellerman @ 2020-11-25 11:57 UTC (permalink / raw)
To: Michael Ellerman, linuxppc-dev
In-Reply-To: <20201023031305.3284819-1-mpe@ellerman.id.au>
On Fri, 23 Oct 2020 14:13:05 +1100, Michael Ellerman wrote:
> This DBG macro is unused, and has been unused since the file was
> originally merged into mainline. Just drop it.
Applied to powerpc/next.
[1/1] powerpc/ps3: Drop unused DBG macro
https://git.kernel.org/powerpc/c/cb5d4c465f31bc44b8bbd4934678c2b140a2ad29
cheers
^ permalink raw reply
* Re: [PATCHv2] selftests/powerpc/eeh: disable kselftest timeout setting for eeh-basic
From: Michael Ellerman @ 2020-11-25 11:57 UTC (permalink / raw)
To: Po-Hsu Lin, mpe, linux-kselftest, linux-kernel, linuxppc-dev
Cc: mathieu.desnoyers, shuah, joe.lawrence, mbenes
In-Reply-To: <20201023024539.9512-1-po-hsu.lin@canonical.com>
On Fri, 23 Oct 2020 10:45:39 +0800, Po-Hsu Lin wrote:
> The eeh-basic test got its own 60 seconds timeout (defined in commit
> 414f50434aa2 "selftests/eeh: Bump EEH wait time to 60s") per breakable
> device.
>
> And we have discovered that the number of breakable devices varies
> on different hardware. The device recovery time ranges from 0 to 35
> seconds. In our test pool it will take about 30 seconds to run on a
> Power8 system that with 5 breakable devices, 60 seconds to run on a
> Power9 system that with 4 breakable devices.
>
> [...]
Applied to powerpc/next.
[1/1] selftests/powerpc/eeh: disable kselftest timeout setting for eeh-basic
https://git.kernel.org/powerpc/c/f5eca0b279117f25020112a2f65ec9c3ea25f3ac
cheers
^ permalink raw reply
* Re: [PATCH] powerpc/mm: Fix comparing pointer to 0 warning
From: Michael Ellerman @ 2020-11-25 11:57 UTC (permalink / raw)
To: paulus, xiakaixu1987@gmail.com, mpe, benh
Cc: linuxppc-dev, Kaixu Xia, linux-kernel
In-Reply-To: <1604976961-20441-1-git-send-email-kaixuxia@tencent.com>
On Tue, 10 Nov 2020 10:56:01 +0800, xiakaixu1987@gmail.com wrote:
> Fixes coccicheck warning:
>
> ./arch/powerpc/mm/pgtable_32.c:87:11-12: WARNING comparing pointer to 0
>
> Avoid pointer type value compared to 0.
Applied to powerpc/next.
[1/1] powerpc/mm: Fix comparing pointer to 0 warning
https://git.kernel.org/powerpc/c/b84bf098fcc49ed6bf4b0a8bed52e9df0e8f1de7
cheers
^ permalink raw reply
* Re: [PATCH] powerpc/powernv/sriov: fix unsigned int win compared to less than zero
From: Michael Ellerman @ 2020-11-25 11:58 UTC (permalink / raw)
To: ajd, paulus, fbarrat, mpe, xiakaixu1987@gmail.com, benh
Cc: linuxppc-dev, Kaixu Xia, linux-kernel
In-Reply-To: <1605007170-22171-1-git-send-email-kaixuxia@tencent.com>
On Tue, 10 Nov 2020 19:19:30 +0800, xiakaixu1987@gmail.com wrote:
> Fix coccicheck warning:
>
> ./arch/powerpc/platforms/powernv/pci-sriov.c:443:7-10: WARNING: Unsigned expression compared with zero: win < 0
> ./arch/powerpc/platforms/powernv/pci-sriov.c:462:7-10: WARNING: Unsigned expression compared with zero: win < 0
Applied to powerpc/next.
[1/1] powerpc/powernv/sriov: fix unsigned int win compared to less than zero
https://git.kernel.org/powerpc/c/027717a45ca251a7ba67a63db359994836962cd2
cheers
^ permalink raw reply
* Re: [PATCH] Revert "powerpc/pseries/hotplug-cpu: Remove double free in error path"
From: Michael Ellerman @ 2020-11-25 11:58 UTC (permalink / raw)
To: Zhang Xiaoxu, paulus, groug, tyreld, mpe, benh, linuxppc-dev
In-Reply-To: <20201111020752.1686139-1-zhangxiaoxu5@huawei.com>
On Tue, 10 Nov 2020 21:07:52 -0500, Zhang Xiaoxu wrote:
> This reverts commit a0ff72f9f5a780341e7ff5e9ba50a0dad5fa1980.
>
> Since the commit b015f6bc9547 ("powerpc/pseries: Add cpu DLPAR
> support for drc-info property"), the 'cpu_drcs' wouldn't be double
> freed when the 'cpus' node not found.
>
> So we needn't apply this patch, otherwise, the memory will be leak.
Applied to powerpc/next.
[1/1] Revert "powerpc/pseries/hotplug-cpu: Remove double free in error path"
https://git.kernel.org/powerpc/c/a40fdaf1420d6e6bda0dd2df1e6806013e58dbe1
cheers
^ permalink raw reply
* Re: [PATCH] powerpc: Use the common INIT_DATA_SECTION macro in vmlinux.lds.S
From: Michael Ellerman @ 2020-11-25 11:57 UTC (permalink / raw)
To: Youling Tang, Michael Ellerman, Benjamin Herrenschmidt,
Paul Mackerras
Cc: linuxppc-dev, linux-kernel
In-Reply-To: <1604487550-20040-1-git-send-email-tangyouling@loongson.cn>
On Wed, 4 Nov 2020 18:59:10 +0800, Youling Tang wrote:
> Use the common INIT_DATA_SECTION rule for the linker script in an effort
> to regularize the linker script.
Applied to powerpc/next.
[1/1] powerpc: Use the common INIT_DATA_SECTION macro in vmlinux.lds.S
https://git.kernel.org/powerpc/c/fdcfeaba38e5b183045f5b079af94f97658eabe6
cheers
^ permalink raw reply
* Re: C vdso
From: Michael Ellerman @ 2020-11-25 12:22 UTC (permalink / raw)
To: Christophe Leroy; +Cc: linuxppc-dev
In-Reply-To: <20201125102134.Horde.0HRWPh9SlZQBfjT7da-o2A1@messagerie.c-s.fr>
Christophe Leroy <christophe.leroy@csgroup.eu> writes:
> Quoting Michael Ellerman <mpe@ellerman.id.au>:
>
>> Christophe Leroy <christophe.leroy@csgroup.eu> writes:
>>> Le 03/11/2020 à 19:13, Christophe Leroy a écrit :
>>>> Le 23/10/2020 à 15:24, Michael Ellerman a écrit :
>>>>> Christophe Leroy <christophe.leroy@csgroup.eu> writes:
>>>>>> Le 24/09/2020 à 15:17, Christophe Leroy a écrit :
>>>>>>> Le 17/09/2020 à 14:33, Michael Ellerman a écrit :
>>>>>>>> Christophe Leroy <christophe.leroy@csgroup.eu> writes:
>>>>>>>>>
>>>>>>>>> What is the status with the generic C vdso merge ?
>>>>>>>>> In some mail, you mentionned having difficulties getting it working on
>>>>>>>>> ppc64, any progress ? What's the problem ? Can I help ?
>>>>>>>>
>>>>>>>> Yeah sorry I was hoping to get time to work on it but haven't been able
>>>>>>>> to.
>>>>>>>>
>>>>>>>> It's causing crashes on ppc64 ie. big endian.
>>>>> ...
>>>>>>>
>>>>>>> Can you tell what defconfig you are using ? I have been able to
>>>>>>> setup a full glibc PPC64 cross
>>>>>>> compilation chain and been able to test it under QEMU with
>>>>>>> success, using Nathan's vdsotest tool.
>>>>>>
>>>>>> What config are you using ?
>>>>>
>>>>> ppc64_defconfig + guest.config
>>>>>
>>>>> Or pseries_defconfig.
>>>>>
>>>>> I'm using Ubuntu GCC 9.3.0 mostly, but it happens with other
>>>>> toolchains too.
>>>>>
>>>>> At a minimum we're seeing relocations in the output, which is a problem:
>>>>>
>>>>> $ readelf -r build\~/arch/powerpc/kernel/vdso64/vdso64.so
>>>>> Relocation section '.rela.dyn' at offset 0x12a8 contains 8 entries:
>>>>> Offset Info Type Sym. Value
>>>>> Sym. Name + Addend
>>>>> 000000001368 000000000016 R_PPC64_RELATIVE 7c0
>>>>> 000000001370 000000000016 R_PPC64_RELATIVE 9300
>>>>> 000000001380 000000000016 R_PPC64_RELATIVE 970
>>>>> 000000001388 000000000016 R_PPC64_RELATIVE 9300
>>>>> 000000001398 000000000016 R_PPC64_RELATIVE a90
>>>>> 0000000013a0 000000000016 R_PPC64_RELATIVE 9300
>>>>> 0000000013b0 000000000016 R_PPC64_RELATIVE b20
>>>>> 0000000013b8 000000000016 R_PPC64_RELATIVE 9300
>>>>
>>>> Looks like it's due to the OPD and relation between the function()
>>>> and .function()
>>>>
>>>> By using DOTSYM() in the 'bl' call, that's directly the dot
>>>> function which is called and the OPD is
>>>> not used anymore, it can get dropped.
>>>>
>>>> Now I get .rela.dyn full of 0, don't know if we should drop it explicitely.
>>>
>>> What is the status now with latest version of CVDSO ? I saw you had
>>> it in next-test for some time,
>>> it is not there anymore today.
>>
>> Still having some trouble with the compat VDSO.
>>
>> eg:
>>
>> $ ./vdsotest clock-gettime-monotonic verify
>> timestamp obtained from kernel predates timestamp
>> previously obtained from libc/vDSO:
>> [1346, 821441653] (vDSO)
>> [570, 769440040] (kernel)
>>
>>
>> And similar for all clocks except the coarse ones.
>>
>
> Ok, I managed to get the same with QEMU. Looking at the binary, I only
> see an mftb instead of the mftbu/mftb/mftbu triplet.
>
> Fix below. Can you carry it, or do you prefer a full patch from me ?
> The easiest would be either to squash it into [v13,4/8]
> ("powerpc/time: Move timebase functions into new asm/timebase.h"), or
> to add it between patch 4 and 5 ?
I can squash it in.
cheers
^ permalink raw reply
* Re: [PATCH v2 2/2] powerpc/pseries: pass MSI affinity to irq_create_mapping()
From: Greg Kurz @ 2020-11-25 12:51 UTC (permalink / raw)
To: Laurent Vivier
Cc: Michael S . Tsirkin, linux-pci, linux-kernel, linux-block,
Paul Mackerras, Marc Zyngier, Thomas Gleixner, linuxppc-dev,
Christoph Hellwig
In-Reply-To: <20201125111657.1141295-3-lvivier@redhat.com>
On Wed, 25 Nov 2020 12:16:57 +0100
Laurent Vivier <lvivier@redhat.com> wrote:
> With virtio multiqueue, normally each queue IRQ is mapped to a CPU.
>
> But since commit 0d9f0a52c8b9f ("virtio_scsi: use virtio IRQ affinity")
> this is broken on pseries.
>
> The affinity is correctly computed in msi_desc but this is not applied
> to the system IRQs.
>
> It appears the affinity is correctly passed to rtas_setup_msi_irqs() but
> lost at this point and never passed to irq_domain_alloc_descs()
> (see commit 06ee6d571f0e ("genirq: Add affinity hint to irq allocation"))
> because irq_create_mapping() doesn't take an affinity parameter.
>
> As the previous patch has added the affinity parameter to
> irq_create_mapping() we can forward the affinity from rtas_setup_msi_irqs()
> to irq_domain_alloc_descs().
>
> With this change, the virtqueues are correctly dispatched between the CPUs
> on pseries.
>
Since it is public, maybe add:
BugId: https://bugzilla.redhat.com/show_bug.cgi?id=1702939
?
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> ---
Anyway,
Reviewed-by: Greg Kurz <groug@kaod.org>
> arch/powerpc/platforms/pseries/msi.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/platforms/pseries/msi.c b/arch/powerpc/platforms/pseries/msi.c
> index 133f6adcb39c..b3ac2455faad 100644
> --- a/arch/powerpc/platforms/pseries/msi.c
> +++ b/arch/powerpc/platforms/pseries/msi.c
> @@ -458,7 +458,8 @@ static int rtas_setup_msi_irqs(struct pci_dev *pdev, int nvec_in, int type)
> return hwirq;
> }
>
> - virq = irq_create_mapping(NULL, hwirq);
> + virq = irq_create_mapping_affinity(NULL, hwirq,
> + entry->affinity);
>
> if (!virq) {
> pr_debug("rtas_msi: Failed mapping hwirq %d\n", hwirq);
^ permalink raw reply
* Re: [PATCH v2 1/2] genirq: add an irq_create_mapping_affinity() function
From: Thomas Gleixner @ 2020-11-25 13:20 UTC (permalink / raw)
To: Laurent Vivier, linux-kernel
Cc: Laurent Vivier, Marc Zyngier, Michael S . Tsirkin, linux-pci,
Greg Kurz, linux-block, Paul Mackerras, linuxppc-dev,
Christoph Hellwig
In-Reply-To: <20201125111657.1141295-2-lvivier@redhat.com>
Laurent,
On Wed, Nov 25 2020 at 12:16, Laurent Vivier wrote:
The proper subsystem prefix is: 'genirq/irqdomain:' and the first letter
after the colon wants to be uppercase.
> This function adds an affinity parameter to irq_create_mapping().
> This parameter is needed to pass it to irq_domain_alloc_descs().
A changelog has to explain the WHY. 'The parameter is needed' is not
really useful information.
Thanks,
tglx
^ permalink raw reply
* Re: [PATCH v6 03/22] powerpc/book3s64/kuap/kuep: Make KUAP and KUEP a subfeature of PPC_MEM_KEYS
From: Christophe Leroy @ 2020-11-25 13:30 UTC (permalink / raw)
To: Aneesh Kumar K.V, linuxppc-dev, mpe
In-Reply-To: <20201125051634.509286-4-aneesh.kumar@linux.ibm.com>
Le 25/11/2020 à 06:16, Aneesh Kumar K.V a écrit :
> 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>
> ---
> .../powerpc/include/asm/book3s/64/kup-radix.h | 4 ++--
> arch/powerpc/include/asm/book3s/64/mmu.h | 2 +-
> arch/powerpc/include/asm/ptrace.h | 7 +++++-
> arch/powerpc/kernel/asm-offsets.c | 3 +++
> arch/powerpc/mm/book3s64/Makefile | 2 +-
> arch/powerpc/mm/book3s64/pkeys.c | 24 ++++++++++++-------
> arch/powerpc/platforms/Kconfig.cputype | 5 ++++
> 7 files changed, 33 insertions(+), 14 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/book3s/64/kup-radix.h b/arch/powerpc/include/asm/book3s/64/kup-radix.h
> index 28716e2f13e3..68eaa2fac3ab 100644
> --- a/arch/powerpc/include/asm/book3s/64/kup-radix.h
> +++ b/arch/powerpc/include/asm/book3s/64/kup-radix.h
> @@ -16,7 +16,7 @@
> #ifdef CONFIG_PPC_KUAP
> BEGIN_MMU_FTR_SECTION_NESTED(67)
> mfspr \gpr1, SPRN_AMR
> - ld \gpr2, STACK_REGS_KUAP(r1)
> + ld \gpr2, STACK_REGS_AMR(r1)
> cmpd \gpr1, \gpr2
> beq 998f
> isync
> @@ -48,7 +48,7 @@
> bne \msr_pr_cr, 99f
> .endif
> mfspr \gpr1, SPRN_AMR
> - std \gpr1, STACK_REGS_KUAP(r1)
> + std \gpr1, STACK_REGS_AMR(r1)
> li \gpr2, (AMR_KUAP_BLOCKED >> AMR_KUAP_SHIFT)
> sldi \gpr2, \gpr2, AMR_KUAP_SHIFT
> cmpd \use_cr, \gpr1, \gpr2
> diff --git a/arch/powerpc/include/asm/book3s/64/mmu.h b/arch/powerpc/include/asm/book3s/64/mmu.h
> index e0b52940e43c..a2a015066bae 100644
> --- a/arch/powerpc/include/asm/book3s/64/mmu.h
> +++ b/arch/powerpc/include/asm/book3s/64/mmu.h
> @@ -199,7 +199,7 @@ extern int mmu_io_psize;
> void mmu_early_init_devtree(void);
> void hash__early_init_devtree(void);
> void radix__early_init_devtree(void);
> -#ifdef CONFIG_PPC_MEM_KEYS
> +#ifdef CONFIG_PPC_PKEY
> void pkey_early_init_devtree(void);
> #else
> static inline void pkey_early_init_devtree(void) {}
> diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/ptrace.h
> index e2c778c176a3..e7f1caa007a4 100644
> --- a/arch/powerpc/include/asm/ptrace.h
> +++ b/arch/powerpc/include/asm/ptrace.h
> @@ -53,9 +53,14 @@ struct pt_regs
> #ifdef CONFIG_PPC64
> unsigned long ppr;
> #endif
> + union {
> #ifdef CONFIG_PPC_KUAP
> - unsigned long kuap;
> + unsigned long kuap;
> #endif
> +#ifdef CONFIG_PPC_PKEY
> + unsigned long amr;
> +#endif
> + };
> };
> unsigned long __pad[2]; /* Maintain 16 byte interrupt stack alignment */
> };
> diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c
> index c2722ff36e98..418a0b314a33 100644
> --- a/arch/powerpc/kernel/asm-offsets.c
> +++ b/arch/powerpc/kernel/asm-offsets.c
> @@ -354,6 +354,9 @@ int main(void)
> STACK_PT_REGS_OFFSET(_PPR, ppr);
> #endif /* CONFIG_PPC64 */
>
> +#ifdef CONFIG_PPC_PKEY
> + STACK_PT_REGS_OFFSET(STACK_REGS_AMR, amr);
> +#endif
> #ifdef CONFIG_PPC_KUAP
> STACK_PT_REGS_OFFSET(STACK_REGS_KUAP, kuap);
> #endif
> diff --git a/arch/powerpc/mm/book3s64/Makefile b/arch/powerpc/mm/book3s64/Makefile
> index fd393b8be14f..1b56d3af47d4 100644
> --- a/arch/powerpc/mm/book3s64/Makefile
> +++ b/arch/powerpc/mm/book3s64/Makefile
> @@ -17,7 +17,7 @@ endif
> obj-$(CONFIG_TRANSPARENT_HUGEPAGE) += hash_hugepage.o
> obj-$(CONFIG_PPC_SUBPAGE_PROT) += subpage_prot.o
> obj-$(CONFIG_SPAPR_TCE_IOMMU) += iommu_api.o
> -obj-$(CONFIG_PPC_MEM_KEYS) += pkeys.o
> +obj-$(CONFIG_PPC_PKEY) += pkeys.o
>
> # Instrumenting the SLB fault path can lead to duplicate SLB entries
> KCOV_INSTRUMENT_slb.o := n
> diff --git a/arch/powerpc/mm/book3s64/pkeys.c b/arch/powerpc/mm/book3s64/pkeys.c
> index b1d091a97611..7dc71f85683d 100644
> --- a/arch/powerpc/mm/book3s64/pkeys.c
> +++ b/arch/powerpc/mm/book3s64/pkeys.c
> @@ -89,12 +89,14 @@ static int scan_pkey_feature(void)
> }
> }
>
> +#ifdef CONFIG_PPC_MEM_KEYS
> /*
> * Adjust the upper limit, based on the number of bits supported by
> * arch-neutral code.
> */
> pkeys_total = min_t(int, pkeys_total,
> ((ARCH_VM_PKEY_FLAGS >> VM_PKEY_SHIFT) + 1));
I don't think we need an #ifdef here. I thing an 'if (IS_ENABLED(CONFIG_PPC_MEM_KEYS))' should make it.
> +#endif
> return pkeys_total;
> }
>
> @@ -102,6 +104,7 @@ void __init pkey_early_init_devtree(void)
> {
> int pkeys_total, i;
>
> +#ifdef CONFIG_PPC_MEM_KEYS
> /*
> * We define PKEY_DISABLE_EXECUTE in addition to the arch-neutral
> * generic defines for PKEY_DISABLE_ACCESS and PKEY_DISABLE_WRITE.
> @@ -117,7 +120,7 @@ void __init pkey_early_init_devtree(void)
> BUILD_BUG_ON(__builtin_clzl(ARCH_VM_PKEY_FLAGS >> VM_PKEY_SHIFT) +
> __builtin_popcountl(ARCH_VM_PKEY_FLAGS >> VM_PKEY_SHIFT)
> != (sizeof(u64) * BITS_PER_BYTE));
> -
> +#endif
> /*
> * Only P7 and above supports SPRN_AMR update with MSR[PR] = 1
> */
> @@ -223,14 +226,6 @@ void __init pkey_early_init_devtree(void)
> return;
> }
>
> -void pkey_mm_init(struct mm_struct *mm)
> -{
> - if (!mmu_has_feature(MMU_FTR_PKEY))
> - return;
> - mm_pkey_allocation_map(mm) = initial_allocation_mask;
> - mm->context.execute_only_pkey = execute_only_key;
> -}
> -
> static inline u64 read_amr(void)
> {
> return mfspr(SPRN_AMR);
> @@ -257,6 +252,15 @@ static inline void write_iamr(u64 value)
> mtspr(SPRN_IAMR, value);
> }
>
> +#ifdef CONFIG_PPC_MEM_KEYS
> +void pkey_mm_init(struct mm_struct *mm)
> +{
> + if (!mmu_has_feature(MMU_FTR_PKEY))
> + return;
> + mm_pkey_allocation_map(mm) = initial_allocation_mask;
> + mm->context.execute_only_pkey = execute_only_key;
> +}
> +
> static inline void init_amr(int pkey, u8 init_bits)
> {
> u64 new_amr_bits = (((u64)init_bits & 0x3UL) << pkeyshift(pkey));
> @@ -445,3 +449,5 @@ void arch_dup_pkeys(struct mm_struct *oldmm, struct mm_struct *mm)
> mm_pkey_allocation_map(mm) = mm_pkey_allocation_map(oldmm);
> mm->context.execute_only_pkey = oldmm->context.execute_only_pkey;
> }
> +
> +#endif /* CONFIG_PPC_MEM_KEYS */
> diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype
> index c194c4ae8bc7..f255e8f32155 100644
> --- a/arch/powerpc/platforms/Kconfig.cputype
> +++ b/arch/powerpc/platforms/Kconfig.cputype
> @@ -395,6 +395,11 @@ config PPC_KUAP_DEBUG
> Add extra debugging for Kernel Userspace Access Protection (KUAP)
> If you're unsure, say N.
>
> +config PPC_PKEY
> + def_bool y
> + depends on PPC_BOOK3S_64
> + depends on PPC_MEM_KEYS || PPC_KUAP || PPC_KUEP
> +
> config ARCH_ENABLE_HUGEPAGE_MIGRATION
> def_bool y
> depends on PPC_BOOK3S_64 && HUGETLB_PAGE && MIGRATION
>
^ permalink raw reply
* Re: [PATCH v6 04/22] powerpc/book3s64/kuap/kuep: Move uamor setup to pkey init
From: Christophe Leroy @ 2020-11-25 13:32 UTC (permalink / raw)
To: Aneesh Kumar K.V, linuxppc-dev, mpe
In-Reply-To: <20201125051634.509286-5-aneesh.kumar@linux.ibm.com>
Le 25/11/2020 à 06:16, Aneesh Kumar K.V a écrit :
> This patch consolidates UAMOR update across pkey, kuap and kuep features.
> The boot cpu initialize UAMOR via pkey init and both radix/hash do the
> secondary cpu UAMOR init in early_init_mmu_secondary.
>
> We don't check for mmu_feature in radix secondary init because UAMOR
> is a supported SPRN with all CPUs supporting radix translation.
> The old code was not updating UAMOR if we had smap disabled and smep enabled.
> This change handles that case.
>
> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
> ---
> arch/powerpc/mm/book3s64/radix_pgtable.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c
> index 3adcf730f478..bfe441af916a 100644
> --- a/arch/powerpc/mm/book3s64/radix_pgtable.c
> +++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
> @@ -620,9 +620,6 @@ void setup_kuap(bool disabled)
> cur_cpu_spec->mmu_features |= MMU_FTR_RADIX_KUAP;
> }
>
> - /* Make sure userspace can't change the AMR */
> - mtspr(SPRN_UAMOR, 0);
> -
> /*
> * Set the default kernel AMR values on all cpus.
> */
> @@ -721,6 +718,11 @@ void radix__early_init_mmu_secondary(void)
>
> radix__switch_mmu_context(NULL, &init_mm);
> tlbiel_all();
> +
> +#ifdef CONFIG_PPC_PKEY
It should be possible to use an 'if' with IS_ENABLED(CONFIG_PPC_PKEY) instead of this #ifdef
> + /* Make sure userspace can't change the AMR */
> + mtspr(SPRN_UAMOR, 0);
> +#endif
> }
>
> void radix__mmu_cleanup_all(void)
>
^ permalink raw reply
* Re: [PATCH v6 07/22] powerpc/book3s64/kuap: Rename MMU_FTR_RADIX_KUAP to MMU_FTR_KUAP
From: Christophe Leroy @ 2020-11-25 13:43 UTC (permalink / raw)
To: Aneesh Kumar K.V, linuxppc-dev, mpe
In-Reply-To: <20201125051634.509286-8-aneesh.kumar@linux.ibm.com>
Le 25/11/2020 à 06:16, Aneesh Kumar K.V a écrit :
> This is in preparate to adding support for kuap with hash translation.
> In preparation for that rename/move kuap related functions to
> non radix names. Also move the feature bit closer to MMU_FTR_KUEP.
It was obvious with MMU_FTR_RADIX_KUAP that it was only for Radix PPC64.
Now, do we expect it to be applies on PPC32 as well or is it still for PPC64 only ?
>
> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
> ---
> arch/powerpc/include/asm/book3s/64/kup.h | 18 +++++++++---------
> arch/powerpc/include/asm/mmu.h | 14 +++++++-------
> arch/powerpc/mm/book3s64/pkeys.c | 2 +-
> 3 files changed, 17 insertions(+), 17 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/book3s/64/kup.h b/arch/powerpc/include/asm/book3s/64/kup.h
> index 39d2e3a0d64d..1d38eab83d48 100644
> --- a/arch/powerpc/include/asm/book3s/64/kup.h
> +++ b/arch/powerpc/include/asm/book3s/64/kup.h
> @@ -24,7 +24,7 @@
> mtspr SPRN_AMR, \gpr2
> /* No isync required, see kuap_restore_amr() */
> 998:
> - END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_RADIX_KUAP, 67)
> + END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_KUAP, 67)
> #endif
> .endm
>
> @@ -37,7 +37,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
> #endif
> @@ -58,7 +58,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
>
> @@ -73,7 +73,7 @@ DECLARE_STATIC_KEY_FALSE(uaccess_flush_key);
>
> static inline void kuap_restore_amr(struct pt_regs *regs, unsigned long amr)
> {
> - if (mmu_has_feature(MMU_FTR_RADIX_KUAP) && unlikely(regs->kuap != amr)) {
> + if (mmu_has_feature(MMU_FTR_KUAP) && unlikely(regs->kuap != amr)) {
> isync();
> mtspr(SPRN_AMR, regs->kuap);
> /*
> @@ -86,7 +86,7 @@ static inline void kuap_restore_amr(struct pt_regs *regs, unsigned long amr)
>
> static inline unsigned long kuap_get_and_check_amr(void)
> {
> - if (mmu_has_feature(MMU_FTR_RADIX_KUAP)) {
> + if (mmu_has_feature(MMU_FTR_KUAP)) {
> unsigned long amr = mfspr(SPRN_AMR);
> if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG)) /* kuap_check_amr() */
> WARN_ON_ONCE(amr != AMR_KUAP_BLOCKED);
> @@ -97,7 +97,7 @@ static inline unsigned long kuap_get_and_check_amr(void)
>
> 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);
> }
>
> @@ -116,7 +116,7 @@ static inline unsigned long get_kuap(void)
> * This has no effect in terms of actually blocking things on hash,
> * so it doesn't break anything.
> */
> - if (!early_mmu_has_feature(MMU_FTR_RADIX_KUAP))
> + if (!early_mmu_has_feature(MMU_FTR_KUAP))
> return AMR_KUAP_BLOCKED;
>
> return mfspr(SPRN_AMR);
> @@ -124,7 +124,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;
>
> /*
> @@ -139,7 +139,7 @@ static inline void set_kuap(unsigned long value)
> 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 255a1837e9f7..f5c7a17c198a 100644
> --- a/arch/powerpc/include/asm/mmu.h
> +++ b/arch/powerpc/include/asm/mmu.h
> @@ -28,6 +28,11 @@
> * Individual features below.
> */
>
> +/*
> + * Supports KUAP (key 0 controlling userspace addresses) on radix
> + */
> +#define MMU_FTR_KUAP ASM_CONST(0x00000200)
> +
> /*
> * Support for KUEP feature.
> */
> @@ -120,11 +125,6 @@
> */
> #define MMU_FTR_1T_SEGMENT ASM_CONST(0x40000000)
>
> -/*
> - * Supports KUAP (key 0 controlling userspace addresses) on radix
> - */
> -#define MMU_FTR_RADIX_KUAP ASM_CONST(0x80000000)
> -
> /* MMU feature bit sets for various CPUs */
> #define MMU_FTRS_DEFAULT_HPTE_ARCH_V2 \
> MMU_FTR_HPTE_TABLE | MMU_FTR_PPCAS_ARCH_V2
> @@ -187,10 +187,10 @@ enum {
> #ifdef CONFIG_PPC_RADIX_MMU
> MMU_FTR_TYPE_RADIX |
> MMU_FTR_GTSE |
> +#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/mm/book3s64/pkeys.c b/arch/powerpc/mm/book3s64/pkeys.c
> index 82c722fbce52..bfc27f1f0ab0 100644
> --- a/arch/powerpc/mm/book3s64/pkeys.c
> +++ b/arch/powerpc/mm/book3s64/pkeys.c
> @@ -258,7 +258,7 @@ void __init 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;
> }
>
> /*
>
^ permalink raw reply
* Re: [PATCH V3 1/5] ocxl: Assign a register set to a Logical Partition
From: Frederic Barrat @ 2020-11-25 13:47 UTC (permalink / raw)
To: Christophe Lombard, linuxppc-dev, fbarrat, ajd
In-Reply-To: <20201124095838.18665-2-clombard@linux.vnet.ibm.com>
On 24/11/2020 10:58, Christophe Lombard wrote:
> Platform specific function to assign a register set to a Logical Partition.
> The "ibm,mmio-atsd" property, provided by the firmware, contains the 16
> base ATSD physical addresses (ATSD0 through ATSD15) of the set of MMIO
> registers (XTS MMIO ATSDx LPARID/AVA/launch/status register).
>
> For the time being, the ATSD0 set of registers is used by default.
>
> Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
> ---
Looks good, thanks for the updates!
Acked-by: Frederic Barrat <fbarrat@linux.ibm.com>
> arch/powerpc/include/asm/pnv-ocxl.h | 3 ++
> arch/powerpc/platforms/powernv/ocxl.c | 45 +++++++++++++++++++++++++++
> 2 files changed, 48 insertions(+)
>
> diff --git a/arch/powerpc/include/asm/pnv-ocxl.h b/arch/powerpc/include/asm/pnv-ocxl.h
> index d37ededca3ee..60c3c74427d9 100644
> --- a/arch/powerpc/include/asm/pnv-ocxl.h
> +++ b/arch/powerpc/include/asm/pnv-ocxl.h
> @@ -28,4 +28,7 @@ int pnv_ocxl_spa_setup(struct pci_dev *dev, void *spa_mem, int PE_mask, void **p
> void pnv_ocxl_spa_release(void *platform_data);
> int pnv_ocxl_spa_remove_pe_from_cache(void *platform_data, int pe_handle);
>
> +int pnv_ocxl_map_lpar(struct pci_dev *dev, uint64_t lparid,
> + uint64_t lpcr, void __iomem **arva);
> +void pnv_ocxl_unmap_lpar(void __iomem *arva);
> #endif /* _ASM_PNV_OCXL_H */
> diff --git a/arch/powerpc/platforms/powernv/ocxl.c b/arch/powerpc/platforms/powernv/ocxl.c
> index ecdad219d704..57fc1062677b 100644
> --- a/arch/powerpc/platforms/powernv/ocxl.c
> +++ b/arch/powerpc/platforms/powernv/ocxl.c
> @@ -483,3 +483,48 @@ int pnv_ocxl_spa_remove_pe_from_cache(void *platform_data, int pe_handle)
> return rc;
> }
> EXPORT_SYMBOL_GPL(pnv_ocxl_spa_remove_pe_from_cache);
> +
> +int pnv_ocxl_map_lpar(struct pci_dev *dev, uint64_t lparid,
> + uint64_t lpcr, void __iomem **arva)
> +{
> + struct pci_controller *hose = pci_bus_to_host(dev->bus);
> + struct pnv_phb *phb = hose->private_data;
> + u64 mmio_atsd;
> + int rc;
> +
> + /* ATSD physical address.
> + * ATSD LAUNCH register: write access initiates a shoot down to
> + * initiate the TLB Invalidate command.
> + */
> + rc = of_property_read_u64_index(hose->dn, "ibm,mmio-atsd",
> + 0, &mmio_atsd);
> + if (rc) {
> + dev_info(&dev->dev, "No available ATSD found\n");
> + return rc;
> + }
> +
> + /* Assign a register set to a Logical Partition and MMIO ATSD
> + * LPARID register to the required value.
> + */
> + rc = opal_npu_map_lpar(phb->opal_id, pci_dev_id(dev),
> + lparid, lpcr);
> + if (rc) {
> + dev_err(&dev->dev, "Error mapping device to LPAR: %d\n", rc);
> + return rc;
> + }
> +
> + *arva = ioremap(mmio_atsd, 24);
> + if (!(*arva)) {
> + dev_warn(&dev->dev, "ioremap failed - mmio_atsd: %#llx\n", mmio_atsd);
> + rc = -ENOMEM;
> + }
> +
> + return rc;
> +}
> +EXPORT_SYMBOL_GPL(pnv_ocxl_map_lpar);
> +
> +void pnv_ocxl_unmap_lpar(void __iomem *arva)
> +{
> + iounmap(arva);
> +}
> +EXPORT_SYMBOL_GPL(pnv_ocxl_unmap_lpar);
>
^ permalink raw reply
* Re: [PATCH v6 09/22] powerpc/exec: Set thread.regs early during exec
From: Christophe Leroy @ 2020-11-25 13:47 UTC (permalink / raw)
To: Aneesh Kumar K.V, linuxppc-dev, mpe
In-Reply-To: <20201125051634.509286-10-aneesh.kumar@linux.ibm.com>
Le 25/11/2020 à 06:16, Aneesh Kumar K.V a écrit :
> In later patches during exec, we would like to access default regs.amr 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/include/asm/thread_info.h | 2 --
> arch/powerpc/kernel/process.c | 37 +++++++++++++++++---------
> 2 files changed, 25 insertions(+), 14 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
> index 46a210b03d2b..de4c911d9ced 100644
> --- a/arch/powerpc/include/asm/thread_info.h
> +++ b/arch/powerpc/include/asm/thread_info.h
> @@ -77,10 +77,8 @@ struct thread_info {
> /* how to get the thread information struct from C */
> extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
>
> -#ifdef CONFIG_PPC_BOOK3S_64
> void arch_setup_new_exec(void);
> #define arch_setup_new_exec arch_setup_new_exec
> -#endif
>
> #endif /* __ASSEMBLY__ */
>
> diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
> index d421a2c7f822..b6b8a845e454 100644
> --- a/arch/powerpc/kernel/process.c
> +++ b/arch/powerpc/kernel/process.c
> @@ -1530,10 +1530,32 @@ 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;
> + }
> +
> +}
> +#else
> +void arch_setup_new_exec(void)
> +{
> + /*
> + * 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
No need to duplicate arch_setup_new_exec() I think. radix_enabled() is defined at all time so the
first function should be valid at all time.
>
> #ifdef CONFIG_PPC64
> @@ -1765,15 +1787,6 @@ void start_thread(struct pt_regs *regs, unsigned long start, unsigned long sp)
> preload_new_slb_context(start, sp);
> #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
>
^ permalink raw reply
* Re: [PATCH v6 10/22] powerpc/book3s64/pkeys: Store/restore userspace AMR/IAMR correctly on entry and exit from kernel
From: Christophe Leroy @ 2020-11-25 13:52 UTC (permalink / raw)
To: Aneesh Kumar K.V, linuxppc-dev, mpe; +Cc: Sandipan Das
In-Reply-To: <20201125051634.509286-11-aneesh.kumar@linux.ibm.com>
Le 25/11/2020 à 06:16, Aneesh Kumar K.V a écrit :
> This prepare kernel to operate with a different value than userspace AMR/IAMR.
> For this, AMR/IAMR need 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. We don't need to modify IAMR value in
> similar fashion.
>
> If MMU_FTR_PKEY is enabled we need to save AMR/IAMR in pt_regs on entering
> kernel from userspace. If not we can assume that AMR/IAMR is not modified
> from userspace.
>
> We need to save AMR if we have MMU_FTR_KUAP feature enabled and we are
> interrupted within kernel. This is required so that if we get interrupted
> within copy_to/from_user we continue with the right AMR value.
>
> If we hae MMU_FTR_KUEP enabled we need to restore IAMR on return to userspace
> beause kernel will be running with a different IAMR value.
>
> Reviewed-by: Sandipan Das <sandipan@linux.ibm.com>
> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
> ---
> arch/powerpc/include/asm/book3s/64/kup.h | 222 +++++++++++++++++++----
> arch/powerpc/include/asm/ptrace.h | 5 +-
> arch/powerpc/kernel/asm-offsets.c | 2 +
> arch/powerpc/kernel/entry_64.S | 6 +-
> arch/powerpc/kernel/exceptions-64s.S | 4 +-
> arch/powerpc/kernel/syscall_64.c | 32 +++-
> 6 files changed, 225 insertions(+), 46 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/book3s/64/kup.h b/arch/powerpc/include/asm/book3s/64/kup.h
> index 1d38eab83d48..4dbb2d53fd8f 100644
> --- a/arch/powerpc/include/asm/book3s/64/kup.h
> +++ b/arch/powerpc/include/asm/book3s/64/kup.h
> @@ -13,17 +13,46 @@
>
> #ifdef __ASSEMBLY__
>
> -.macro kuap_restore_amr gpr1, gpr2
> -#ifdef CONFIG_PPC_KUAP
> +.macro kuap_restore_user_amr gpr1
> +#if defined(CONFIG_PPC_PKEY)
> BEGIN_MMU_FTR_SECTION_NESTED(67)
> - mfspr \gpr1, SPRN_AMR
> + /*
> + * AMR and IAMR are going to be different when
> + * returning to userspace.
> + */
> + ld \gpr1, STACK_REGS_AMR(r1)
> + isync
> + mtspr SPRN_AMR, \gpr1
> + /*
> + * Restore IAMR only when returning to userspace
> + */
> + ld \gpr1, STACK_REGS_IAMR(r1)
> + mtspr SPRN_IAMR, \gpr1
> +
> + /* No isync required, see kuap_restore_user_amr() */
> + END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_PKEY, 67)
> +#endif
> +.endm
> +
> +.macro kuap_restore_kernel_amr gpr1, gpr2
> +#if defined(CONFIG_PPC_PKEY)
> +
> + BEGIN_MMU_FTR_SECTION_NESTED(67)
> + /*
> + * AMR is going to be mostly the same since we are
> + * returning to the kernel. Compare and do a mtspr.
> + */
> ld \gpr2, STACK_REGS_AMR(r1)
> + mfspr \gpr1, SPRN_AMR
> cmpd \gpr1, \gpr2
> - beq 998f
> + beq 100f
> isync
> mtspr SPRN_AMR, \gpr2
> - /* No isync required, see kuap_restore_amr() */
> -998:
> + /*
> + * No isync required, see kuap_restore_amr()
> + * No need to restore IAMR when returning to kernel space.
> + */
> +100:
> END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_KUAP, 67)
> #endif
> .endm
> @@ -42,23 +71,98 @@
> .endm
> #endif
>
> +/*
> + * if (pkey) {
> + *
> + * save AMR -> stack;
> + * if (kuap) {
> + * if (AMR != BLOCKED)
> + * KUAP_BLOCKED -> AMR;
> + * }
> + * if (from_user) {
> + * save IAMR -> stack;
> + * if (kuep) {
> + * KUEP_BLOCKED ->IAMR
> + * }
> + * }
> + * return;
> + * }
> + *
> + * if (kuap) {
> + * if (from_kernel) {
> + * save AMR -> stack;
> + * if (AMR != BLOCKED)
> + * KUAP_BLOCKED -> AMR;
> + * }
> + *
> + * }
> + */
> .macro kuap_save_amr_and_lock gpr1, gpr2, use_cr, msr_pr_cr
> -#ifdef CONFIG_PPC_KUAP
> +#if defined(CONFIG_PPC_PKEY)
> +
> + /*
> + * if both pkey and kuap is disabled, nothing to do
> + */
> + BEGIN_MMU_FTR_SECTION_NESTED(68)
> + b 100f // skip_save_amr
> + END_MMU_FTR_SECTION_NESTED_IFCLR(MMU_FTR_PKEY | MMU_FTR_KUAP, 68)
> +
> + /*
> + * if pkey is disabled and we are entering from userspace
> + * don't do anything.
> + */
> BEGIN_MMU_FTR_SECTION_NESTED(67)
> .ifnb \msr_pr_cr
> - bne \msr_pr_cr, 99f
> + /*
> + * Without pkey we are not changing AMR outside the kernel
> + * hence skip this completely.
> + */
> + bne \msr_pr_cr, 100f // from userspace
> .endif
> + END_MMU_FTR_SECTION_NESTED_IFCLR(MMU_FTR_PKEY, 67)
> +
> + /*
> + * pkey is enabled or pkey is disabled but entering from kernel
> + */
> mfspr \gpr1, SPRN_AMR
> std \gpr1, STACK_REGS_AMR(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)
> +
> + /*
> + * if entering from kernel we don't need save IAMR
> + */
> + .ifnb \msr_pr_cr
> + beq \msr_pr_cr, 100f // from kernel space
> + mfspr \gpr1, SPRN_IAMR
> + std \gpr1, STACK_REGS_IAMR(r1)
> +
> + /*
> + * update kernel IAMR with AMR_KUEP_BLOCKED only
> + * if KUEP feature is enabled
> + */
> + BEGIN_MMU_FTR_SECTION_NESTED(70)
> + LOAD_REG_IMMEDIATE(\gpr2, AMR_KUEP_BLOCKED)
> + mtspr SPRN_IAMR, \gpr2
> + isync
> + END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_KUEP, 70)
> + .endif
> +
> +100: // skip_save_amr
> #endif
> .endm
>
> @@ -66,22 +170,42 @@
>
> DECLARE_STATIC_KEY_FALSE(uaccess_flush_key);
>
> -#ifdef CONFIG_PPC_KUAP
> +#ifdef CONFIG_PPC_PKEY
>
> #include <asm/mmu.h>
> #include <asm/ptrace.h>
>
> -static inline void kuap_restore_amr(struct pt_regs *regs, unsigned long amr)
> +static inline void kuap_restore_user_amr(struct pt_regs *regs)
While we are at changing the function's names, could we remove the _amr from the names in order to
make it more generic and allow to re-use that name when we migrate PPC32 to C interrupt/syscall
entries/exits ? (see
https://patchwork.ozlabs.org/project/linuxppc-dev/patch/302a0e88e15ce4569d9619631b36248041d5ed27.1586196948.git.christophe.leroy@c-s.fr/)
> +{
> + if (!mmu_has_feature(MMU_FTR_PKEY))
> + return;
> +
> + isync();
> + mtspr(SPRN_AMR, regs->amr);
> + mtspr(SPRN_IAMR, regs->iamr);
> + /*
> + * No isync required here because we are about to rfi
> + * back to previous context before any user accesses
> + * would be made, which is a CSI.
> + */
> +}
> +static inline void kuap_restore_kernel_amr(struct pt_regs *regs,
> + unsigned long amr)
> {
> - if (mmu_has_feature(MMU_FTR_KUAP) && unlikely(regs->kuap != amr)) {
> - isync();
> - mtspr(SPRN_AMR, regs->kuap);
> - /*
> - * No isync required here because we are about to RFI back to
> - * previous context before any user accesses would be made,
> - * which is a CSI.
> - */
> + if (mmu_has_feature(MMU_FTR_KUAP)) {
> + if (unlikely(regs->amr != amr)) {
> + isync();
> + mtspr(SPRN_AMR, regs->amr);
> + /*
> + * No isync required here because we are about to rfi
> + * back to previous context before any user accesses
> + * would be made, which is a CSI.
> + */
> + }
> }
> + /*
> + * No need to restore IAMR when returning to kernel space.
> + */
> }
>
> static inline unsigned long kuap_get_and_check_amr(void)
> @@ -95,6 +219,26 @@ static inline unsigned long kuap_get_and_check_amr(void)
> return 0;
> }
>
> +#else /* CONFIG_PPC_PKEY */
> +
> +static inline void kuap_restore_user_amr(struct pt_regs *regs)
> +{
> +}
> +
> +static inline void kuap_restore_kernel_amr(struct pt_regs *regs, unsigned long amr)
> +{
> +}
> +
> +static inline unsigned long kuap_get_and_check_amr(void)
> +{
> + return 0;
> +}
> +
> +#endif /* CONFIG_PPC_PKEY */
> +
> +
> +#ifdef CONFIG_PPC_KUAP
> +
> static inline void kuap_check_amr(void)
> {
> if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG) && mmu_has_feature(MMU_FTR_KUAP))
> @@ -143,21 +287,6 @@ bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
> (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, unsigned long amr) { }
> -
> -static inline unsigned long kuap_get_and_check_amr(void)
> -{
> - return 0UL;
> -}
> -
> -static inline unsigned long get_kuap(void)
> -{
> - return AMR_KUAP_BLOCKED;
> -}
> -
> -static inline void set_kuap(unsigned long value) { }
> -#endif /* !CONFIG_PPC_KUAP */
>
> static __always_inline void allow_user_access(void __user *to, const void __user *from,
> unsigned long size, unsigned long dir)
> @@ -174,6 +303,21 @@ static __always_inline void allow_user_access(void __user *to, const void __user
> BUILD_BUG();
> }
>
> +#else /* CONFIG_PPC_KUAP */
> +
> +static inline unsigned long get_kuap(void)
> +{
> + return AMR_KUAP_BLOCKED;
> +}
> +
> +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)
> +{ }
> +
> +#endif /* !CONFIG_PPC_KUAP */
> +
> static inline void prevent_user_access(void __user *to, const void __user *from,
> unsigned long size, unsigned long dir)
> {
> diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/ptrace.h
> index e7f1caa007a4..f240f0cdcec2 100644
> --- a/arch/powerpc/include/asm/ptrace.h
> +++ b/arch/powerpc/include/asm/ptrace.h
> @@ -61,8 +61,11 @@ struct pt_regs
> unsigned long amr;
> #endif
> };
> +#ifdef CONFIG_PPC_PKEY
> + unsigned long iamr;
> +#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 418a0b314a33..76545cdc7f8a 100644
> --- a/arch/powerpc/kernel/asm-offsets.c
> +++ b/arch/powerpc/kernel/asm-offsets.c
> @@ -356,11 +356,13 @@ int main(void)
>
> #ifdef CONFIG_PPC_PKEY
> STACK_PT_REGS_OFFSET(STACK_REGS_AMR, amr);
> + STACK_PT_REGS_OFFSET(STACK_REGS_IAMR, iamr);
> #endif
> #ifdef CONFIG_PPC_KUAP
> STACK_PT_REGS_OFFSET(STACK_REGS_KUAP, kuap);
> #endif
>
> +
> #if defined(CONFIG_PPC32)
> #if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
> DEFINE(EXC_LVL_SIZE, STACK_EXC_LVL_FRAME_SIZE);
> diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
> index 2f3846192ec7..e49291594c68 100644
> --- a/arch/powerpc/kernel/entry_64.S
> +++ b/arch/powerpc/kernel/entry_64.S
> @@ -653,8 +653,8 @@ _ASM_NOKPROBE_SYMBOL(fast_interrupt_return)
> kuap_check_amr r3, r4
> ld r5,_MSR(r1)
> andi. r0,r5,MSR_PR
> - bne .Lfast_user_interrupt_return
> - kuap_restore_amr r3, r4
> + bne .Lfast_user_interrupt_return_amr
> + kuap_restore_kernel_amr r3, r4
> andi. r0,r5,MSR_RI
> li r3,0 /* 0 return value, no EMULATE_STACK_STORE */
> bne+ .Lfast_kernel_interrupt_return
> @@ -674,6 +674,8 @@ _ASM_NOKPROBE_SYMBOL(interrupt_return)
> cmpdi r3,0
> bne- .Lrestore_nvgprs
>
> +.Lfast_user_interrupt_return_amr:
> + kuap_restore_user_amr r3
> .Lfast_user_interrupt_return:
> ld r11,_NIP(r1)
> ld r12,_MSR(r1)
> diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
> index 4d01f09ecf80..84cc23529cdb 100644
> --- a/arch/powerpc/kernel/exceptions-64s.S
> +++ b/arch/powerpc/kernel/exceptions-64s.S
> @@ -1059,7 +1059,7 @@ EXC_COMMON_BEGIN(system_reset_common)
> ld r10,SOFTE(r1)
> stb r10,PACAIRQSOFTMASK(r13)
>
> - kuap_restore_amr r9, r10
> + kuap_restore_kernel_amr r9, r10
> EXCEPTION_RESTORE_REGS
> RFI_TO_USER_OR_KERNEL
>
> @@ -2875,7 +2875,7 @@ EXC_COMMON_BEGIN(soft_nmi_common)
> ld r10,SOFTE(r1)
> stb r10,PACAIRQSOFTMASK(r13)
>
> - kuap_restore_amr r9, r10
> + kuap_restore_kernel_amr r9, r10
> EXCEPTION_RESTORE_REGS hsrr=0
> RFI_TO_KERNEL
>
> diff --git a/arch/powerpc/kernel/syscall_64.c b/arch/powerpc/kernel/syscall_64.c
> index 310bcd768cd5..60c57609d316 100644
> --- a/arch/powerpc/kernel/syscall_64.c
> +++ b/arch/powerpc/kernel/syscall_64.c
> @@ -35,7 +35,25 @@ 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();
> +#ifdef CONFIG_PPC_PKEY
> + if (mmu_has_feature(MMU_FTR_PKEY)) {
> + unsigned long amr, iamr;
> + /*
> + * When entering from userspace we mostly have the AMR/IAMR
> + * different from kernel default values. Hence don't compare.
> + */
> + amr = mfspr(SPRN_AMR);
> + iamr = mfspr(SPRN_IAMR);
> + regs->amr = amr;
> + regs->iamr = iamr;
> + if (mmu_has_feature(MMU_FTR_KUAP))
> + mtspr(SPRN_AMR, AMR_KUAP_BLOCKED);
> + if (mmu_has_feature(MMU_FTR_KUEP))
> + mtspr(SPRN_IAMR, AMR_KUEP_BLOCKED);
> + isync();
> + } else
> +#endif
> + kuap_check_amr();
>
> account_cpu_user_entry();
>
> @@ -245,6 +263,12 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3,
>
> account_cpu_user_exit();
>
> +#ifdef CONFIG_PPC_BOOK3S /* BOOK3E not yet using this */
> + /*
> + * We do this at the end so that we do context switch with KERNEL AMR
> + */
> + kuap_restore_user_amr(regs);
> +#endif
> return ret;
> }
>
> @@ -330,6 +354,10 @@ notrace unsigned long interrupt_exit_user_prepare(struct pt_regs *regs, unsigned
>
> account_cpu_user_exit();
>
> + /*
> + * We do this at the end so that we do context switch with KERNEL AMR
> + */
> + kuap_restore_user_amr(regs);
> return ret;
> }
>
> @@ -400,7 +428,7 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs, unsign
> * which would cause Read-After-Write stalls. Hence, we take the AMR
> * value from the check above.
> */
> - kuap_restore_amr(regs, amr);
> + kuap_restore_kernel_amr(regs, amr);
>
> return ret;
> }
>
^ permalink raw reply
* Re: [PATCH v6 07/22] powerpc/book3s64/kuap: Rename MMU_FTR_RADIX_KUAP to MMU_FTR_KUAP
From: Aneesh Kumar K.V @ 2020-11-25 13:52 UTC (permalink / raw)
To: Christophe Leroy, linuxppc-dev, mpe
In-Reply-To: <49af7fc3-c9f0-ff2c-507e-595c3be8c8f6@csgroup.eu>
On 11/25/20 7:13 PM, Christophe Leroy wrote:
>
>
> Le 25/11/2020 à 06:16, Aneesh Kumar K.V a écrit :
>> This is in preparate to adding support for kuap with hash translation.
>> In preparation for that rename/move kuap related functions to
>> non radix names. Also move the feature bit closer to MMU_FTR_KUEP.
>
> It was obvious with MMU_FTR_RADIX_KUAP that it was only for Radix PPC64.
> Now, do we expect it to be applies on PPC32 as well or is it still for
> PPC64 only ?
Right now this is PPC64 only. I added
+config PPC_PKEY
+ def_bool y
+ depends on PPC_BOOK3S_64
+ depends on PPC_MEM_KEYS || PPC_KUAP || PPC_KUEP
to select the base bits needed for both KUAP and MEM_KEYS. I haven't
looked at PPC32 to see if we can implement it there also.
>
>>
>> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
>> ---
>> arch/powerpc/include/asm/book3s/64/kup.h | 18 +++++++++---------
>> arch/powerpc/include/asm/mmu.h | 14 +++++++-------
>> arch/powerpc/mm/book3s64/pkeys.c | 2 +-
>> 3 files changed, 17 insertions(+), 17 deletions(-)
>>
>> diff --git a/arch/powerpc/include/asm/book3s/64/kup.h
>> b/arch/powerpc/include/asm/book3s/64/kup.h
>> index 39d2e3a0d64d..1d38eab83d48 100644
>> --- a/arch/powerpc/include/asm/book3s/64/kup.h
>> +++ b/arch/powerpc/include/asm/book3s/64/kup.h
>> @@ -24,7 +24,7 @@
>> mtspr SPRN_AMR, \gpr2
>> /* No isync required, see kuap_restore_amr() */
>> 998:
>> - END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_RADIX_KUAP, 67)
>> + END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_KUAP, 67)
>> #endif
>> .endm
>> @@ -37,7 +37,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
>> #endif
>> @@ -58,7 +58,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
>> @@ -73,7 +73,7 @@ DECLARE_STATIC_KEY_FALSE(uaccess_flush_key);
>> static inline void kuap_restore_amr(struct pt_regs *regs, unsigned
>> long amr)
>> {
>> - if (mmu_has_feature(MMU_FTR_RADIX_KUAP) && unlikely(regs->kuap !=
>> amr)) {
>> + if (mmu_has_feature(MMU_FTR_KUAP) && unlikely(regs->kuap != amr)) {
>> isync();
>> mtspr(SPRN_AMR, regs->kuap);
>> /*
>> @@ -86,7 +86,7 @@ static inline void kuap_restore_amr(struct pt_regs
>> *regs, unsigned long amr)
>> static inline unsigned long kuap_get_and_check_amr(void)
>> {
>> - if (mmu_has_feature(MMU_FTR_RADIX_KUAP)) {
>> + if (mmu_has_feature(MMU_FTR_KUAP)) {
>> unsigned long amr = mfspr(SPRN_AMR);
>> if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG)) /* kuap_check_amr() */
>> WARN_ON_ONCE(amr != AMR_KUAP_BLOCKED);
>> @@ -97,7 +97,7 @@ static inline unsigned long
>> kuap_get_and_check_amr(void)
>> 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);
>> }
>> @@ -116,7 +116,7 @@ static inline unsigned long get_kuap(void)
>> * This has no effect in terms of actually blocking things on hash,
>> * so it doesn't break anything.
>> */
>> - if (!early_mmu_has_feature(MMU_FTR_RADIX_KUAP))
>> + if (!early_mmu_has_feature(MMU_FTR_KUAP))
>> return AMR_KUAP_BLOCKED;
>> return mfspr(SPRN_AMR);
>> @@ -124,7 +124,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;
>> /*
>> @@ -139,7 +139,7 @@ static inline void set_kuap(unsigned long value)
>> 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 255a1837e9f7..f5c7a17c198a 100644
>> --- a/arch/powerpc/include/asm/mmu.h
>> +++ b/arch/powerpc/include/asm/mmu.h
>> @@ -28,6 +28,11 @@
>> * Individual features below.
>> */
>> +/*
>> + * Supports KUAP (key 0 controlling userspace addresses) on radix
>> + */
>> +#define MMU_FTR_KUAP ASM_CONST(0x00000200)
>> +
>> /*
>> * Support for KUEP feature.
>> */
>> @@ -120,11 +125,6 @@
>> */
>> #define MMU_FTR_1T_SEGMENT ASM_CONST(0x40000000)
>> -/*
>> - * Supports KUAP (key 0 controlling userspace addresses) on radix
>> - */
>> -#define MMU_FTR_RADIX_KUAP ASM_CONST(0x80000000)
>> -
>> /* MMU feature bit sets for various CPUs */
>> #define MMU_FTRS_DEFAULT_HPTE_ARCH_V2 \
>> MMU_FTR_HPTE_TABLE | MMU_FTR_PPCAS_ARCH_V2
>> @@ -187,10 +187,10 @@ enum {
>> #ifdef CONFIG_PPC_RADIX_MMU
>> MMU_FTR_TYPE_RADIX |
>> MMU_FTR_GTSE |
>> +#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/mm/book3s64/pkeys.c
>> b/arch/powerpc/mm/book3s64/pkeys.c
>> index 82c722fbce52..bfc27f1f0ab0 100644
>> --- a/arch/powerpc/mm/book3s64/pkeys.c
>> +++ b/arch/powerpc/mm/book3s64/pkeys.c
>> @@ -258,7 +258,7 @@ void __init 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;
>> }
>> /*
>>
^ permalink raw reply
* Re: [PATCH v6 11/22] powerpc/book3s64/pkeys: Inherit correctly on fork.
From: Christophe Leroy @ 2020-11-25 13:54 UTC (permalink / raw)
To: Aneesh Kumar K.V, linuxppc-dev, mpe; +Cc: Sandipan Das
In-Reply-To: <20201125051634.509286-12-aneesh.kumar@linux.ibm.com>
Le 25/11/2020 à 06:16, Aneesh Kumar K.V a écrit :
> 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.
>
> Reviewed-by: Sandipan Das <sandipan@linux.ibm.com>
> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
> ---
> arch/powerpc/kernel/process.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
> index b6b8a845e454..733680de0ba4 100644
> --- a/arch/powerpc/kernel/process.c
> +++ b/arch/powerpc/kernel/process.c
> @@ -1768,6 +1768,17 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
> childregs->ppr = DEFAULT_PPR;
>
> p->thread.tidr = 0;
> +#endif
> + /*
> + * Run with the current AMR value of the kernel
> + */
> +#ifdef CONFIG_PPC_KUAP
> + if (mmu_has_feature(MMU_FTR_KUAP))
> + kregs->kuap = AMR_KUAP_BLOCKED;
> +#endif
Do we need that ifdef at all ?
Shouldn't mmu_has_feature(MMU_FTR_KUAP) be always false and get optimised out when CONFIG_PPC_KUAP
is not defined ?
> +#ifdef CONFIG_PPC_KUEP
> + if (mmu_has_feature(MMU_FTR_KUEP))
> + kregs->iamr = AMR_KUEP_BLOCKED;
Same ?
> #endif
> kregs->nip = ppc_function_entry(f);
> return 0;
>
^ permalink raw reply
* Re: [PATCH v6 10/22] powerpc/book3s64/pkeys: Store/restore userspace AMR/IAMR correctly on entry and exit from kernel
From: Aneesh Kumar K.V @ 2020-11-25 13:55 UTC (permalink / raw)
To: Christophe Leroy, linuxppc-dev, mpe; +Cc: Sandipan Das
In-Reply-To: <5f7a467a-c4c7-76b1-5837-34db0f4db51e@csgroup.eu>
On 11/25/20 7:22 PM, Christophe Leroy wrote:
>
>
> Le 25/11/2020 à 06:16, Aneesh Kumar K.V a écrit :
>> This prepare kernel to operate with a different value than userspace
>> AMR/IAMR.
>> For this, AMR/IAMR need 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. We don't need to modify IAMR value in
>> similar fashion.
>>
>> If MMU_FTR_PKEY is enabled we need to save AMR/IAMR in pt_regs on
>> entering
>> kernel from userspace. If not we can assume that AMR/IAMR is not modified
>> from userspace.
>>
>> We need to save AMR if we have MMU_FTR_KUAP feature enabled and we are
>> interrupted within kernel. This is required so that if we get interrupted
>> within copy_to/from_user we continue with the right AMR value.
>>
>> If we hae MMU_FTR_KUEP enabled we need to restore IAMR on return to
>> userspace
>> beause kernel will be running with a different IAMR value.
>>
>> Reviewed-by: Sandipan Das <sandipan@linux.ibm.com>
>> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
>> ---
>> arch/powerpc/include/asm/book3s/64/kup.h | 222 +++++++++++++++++++----
>> arch/powerpc/include/asm/ptrace.h | 5 +-
>> arch/powerpc/kernel/asm-offsets.c | 2 +
>> arch/powerpc/kernel/entry_64.S | 6 +-
>> arch/powerpc/kernel/exceptions-64s.S | 4 +-
>> arch/powerpc/kernel/syscall_64.c | 32 +++-
>> 6 files changed, 225 insertions(+), 46 deletions(-)
>>
>> diff --git a/arch/powerpc/include/asm/book3s/64/kup.h
>> b/arch/powerpc/include/asm/book3s/64/kup.h
>> index 1d38eab83d48..4dbb2d53fd8f 100644
>> --- a/arch/powerpc/include/asm/book3s/64/kup.h
>> +++ b/arch/powerpc/include/asm/book3s/64/kup.h
>> @@ -13,17 +13,46 @@
>> #ifdef __ASSEMBLY__
>> -.macro kuap_restore_amr gpr1, gpr2
>> -#ifdef CONFIG_PPC_KUAP
>> +.macro kuap_restore_user_amr gpr1
>> +#if defined(CONFIG_PPC_PKEY)
>> BEGIN_MMU_FTR_SECTION_NESTED(67)
>> - mfspr \gpr1, SPRN_AMR
>> + /*
>> + * AMR and IAMR are going to be different when
>> + * returning to userspace.
>> + */
>> + ld \gpr1, STACK_REGS_AMR(r1)
>> + isync
>> + mtspr SPRN_AMR, \gpr1
>> + /*
>> + * Restore IAMR only when returning to userspace
>> + */
>> + ld \gpr1, STACK_REGS_IAMR(r1)
>> + mtspr SPRN_IAMR, \gpr1
>> +
>> + /* No isync required, see kuap_restore_user_amr() */
>> + END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_PKEY, 67)
>> +#endif
>> +.endm
>> +
>> +.macro kuap_restore_kernel_amr gpr1, gpr2
>> +#if defined(CONFIG_PPC_PKEY)
>> +
>> + BEGIN_MMU_FTR_SECTION_NESTED(67)
>> + /*
>> + * AMR is going to be mostly the same since we are
>> + * returning to the kernel. Compare and do a mtspr.
>> + */
>> ld \gpr2, STACK_REGS_AMR(r1)
>> + mfspr \gpr1, SPRN_AMR
>> cmpd \gpr1, \gpr2
>> - beq 998f
>> + beq 100f
>> isync
>> mtspr SPRN_AMR, \gpr2
>> - /* No isync required, see kuap_restore_amr() */
>> -998:
>> + /*
>> + * No isync required, see kuap_restore_amr()
>> + * No need to restore IAMR when returning to kernel space.
>> + */
>> +100:
>> END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_KUAP, 67)
>> #endif
>> .endm
>> @@ -42,23 +71,98 @@
>> .endm
>> #endif
>> +/*
>> + * if (pkey) {
>> + *
>> + * save AMR -> stack;
>> + * if (kuap) {
>> + * if (AMR != BLOCKED)
>> + * KUAP_BLOCKED -> AMR;
>> + * }
>> + * if (from_user) {
>> + * save IAMR -> stack;
>> + * if (kuep) {
>> + * KUEP_BLOCKED ->IAMR
>> + * }
>> + * }
>> + * return;
>> + * }
>> + *
>> + * if (kuap) {
>> + * if (from_kernel) {
>> + * save AMR -> stack;
>> + * if (AMR != BLOCKED)
>> + * KUAP_BLOCKED -> AMR;
>> + * }
>> + *
>> + * }
>> + */
>> .macro kuap_save_amr_and_lock gpr1, gpr2, use_cr, msr_pr_cr
>> -#ifdef CONFIG_PPC_KUAP
>> +#if defined(CONFIG_PPC_PKEY)
>> +
>> + /*
>> + * if both pkey and kuap is disabled, nothing to do
>> + */
>> + BEGIN_MMU_FTR_SECTION_NESTED(68)
>> + b 100f // skip_save_amr
>> + END_MMU_FTR_SECTION_NESTED_IFCLR(MMU_FTR_PKEY | MMU_FTR_KUAP, 68)
>> +
>> + /*
>> + * if pkey is disabled and we are entering from userspace
>> + * don't do anything.
>> + */
>> BEGIN_MMU_FTR_SECTION_NESTED(67)
>> .ifnb \msr_pr_cr
>> - bne \msr_pr_cr, 99f
>> + /*
>> + * Without pkey we are not changing AMR outside the kernel
>> + * hence skip this completely.
>> + */
>> + bne \msr_pr_cr, 100f // from userspace
>> .endif
>> + END_MMU_FTR_SECTION_NESTED_IFCLR(MMU_FTR_PKEY, 67)
>> +
>> + /*
>> + * pkey is enabled or pkey is disabled but entering from kernel
>> + */
>> mfspr \gpr1, SPRN_AMR
>> std \gpr1, STACK_REGS_AMR(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)
>> +
>> + /*
>> + * if entering from kernel we don't need save IAMR
>> + */
>> + .ifnb \msr_pr_cr
>> + beq \msr_pr_cr, 100f // from kernel space
>> + mfspr \gpr1, SPRN_IAMR
>> + std \gpr1, STACK_REGS_IAMR(r1)
>> +
>> + /*
>> + * update kernel IAMR with AMR_KUEP_BLOCKED only
>> + * if KUEP feature is enabled
>> + */
>> + BEGIN_MMU_FTR_SECTION_NESTED(70)
>> + LOAD_REG_IMMEDIATE(\gpr2, AMR_KUEP_BLOCKED)
>> + mtspr SPRN_IAMR, \gpr2
>> + isync
>> + END_MMU_FTR_SECTION_NESTED_IFSET(MMU_FTR_KUEP, 70)
>> + .endif
>> +
>> +100: // skip_save_amr
>> #endif
>> .endm
>> @@ -66,22 +170,42 @@
>> DECLARE_STATIC_KEY_FALSE(uaccess_flush_key);
>> -#ifdef CONFIG_PPC_KUAP
>> +#ifdef CONFIG_PPC_PKEY
>> #include <asm/mmu.h>
>> #include <asm/ptrace.h>
>> -static inline void kuap_restore_amr(struct pt_regs *regs, unsigned
>> long amr)
>> +static inline void kuap_restore_user_amr(struct pt_regs *regs)
>
> While we are at changing the function's names, could we remove the _amr
> from the names in order to make it more generic and allow to re-use that
> name when we migrate PPC32 to C interrupt/syscall entries/exits ? (see
> https://patchwork.ozlabs.org/project/linuxppc-dev/patch/302a0e88e15ce4569d9619631b36248041d5ed27.1586196948.git.christophe.leroy@c-s.fr/)
>
How do you suggest we rename it? kuap_restore_user is a bit ambiguous right?
-aneesh
^ permalink raw reply
* Re: [PATCH v6 11/22] powerpc/book3s64/pkeys: Inherit correctly on fork.
From: Aneesh Kumar K.V @ 2020-11-25 13:56 UTC (permalink / raw)
To: Christophe Leroy, linuxppc-dev, mpe; +Cc: Sandipan Das
In-Reply-To: <38a05d5e-5009-9a00-c1fb-5dd60bba1802@csgroup.eu>
On 11/25/20 7:24 PM, Christophe Leroy wrote:
>
>
> Le 25/11/2020 à 06:16, Aneesh Kumar K.V a écrit :
>> 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.
>>
>> Reviewed-by: Sandipan Das <sandipan@linux.ibm.com>
>> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
>> ---
>> arch/powerpc/kernel/process.c | 11 +++++++++++
>> 1 file changed, 11 insertions(+)
>>
>> diff --git a/arch/powerpc/kernel/process.c
>> b/arch/powerpc/kernel/process.c
>> index b6b8a845e454..733680de0ba4 100644
>> --- a/arch/powerpc/kernel/process.c
>> +++ b/arch/powerpc/kernel/process.c
>> @@ -1768,6 +1768,17 @@ int copy_thread(unsigned long clone_flags,
>> unsigned long usp,
>> childregs->ppr = DEFAULT_PPR;
>> p->thread.tidr = 0;
>> +#endif
>> + /*
>> + * Run with the current AMR value of the kernel
>> + */
>> +#ifdef CONFIG_PPC_KUAP
>> + if (mmu_has_feature(MMU_FTR_KUAP))
>> + kregs->kuap = AMR_KUAP_BLOCKED;
>> +#endif
>
> Do we need that ifdef at all ?
>
> Shouldn't mmu_has_feature(MMU_FTR_KUAP) be always false and get
> optimised out when CONFIG_PPC_KUAP is not defined ?
>
>> +#ifdef CONFIG_PPC_KUEP
>> + if (mmu_has_feature(MMU_FTR_KUEP))
>> + kregs->iamr = AMR_KUEP_BLOCKED;
>
> Same ?
>
>> #endif
>> kregs->nip = ppc_function_entry(f);
>> return 0;
>>
Not really. I did hit a compile error with this patch on
mpc885_ads_defconfig and that required me to do
modified arch/powerpc/kernel/process.c
@@ -1772,11 +1772,10 @@ int copy_thread(unsigned long clone_flags,
unsigned long usp,
/*
* Run with the current AMR value of the kernel
*/
-#ifdef CONFIG_PPC_KUAP
+#ifdef CONFIG_PPC_PKEY
if (mmu_has_feature(MMU_FTR_KUAP))
- kregs->kuap = AMR_KUAP_BLOCKED;
-#endif
-#ifdef CONFIG_PPC_KUEP
+ kregs->amr = AMR_KUAP_BLOCKED;
+
if (mmu_has_feature(MMU_FTR_KUEP))
kregs->iamr = AMR_KUEP_BLOCKED;
#endif
^ permalink raw reply
* Re: [PATCH] ASoC: fsl_xcvr: fix potential resource leak
From: Mark Brown @ 2020-11-25 13:58 UTC (permalink / raw)
To: linuxppc-dev, Fabio Estevam, alsa-devel, Liam Girdwood,
Takashi Iwai, Timur Tabi, Jaroslav Kysela, linux-kernel,
Nicolin Chen, Xiubo Li, Viorel Suman (OSS), Shengjiu Wang
Cc: Viorel Suman
In-Reply-To: <20201124141957.20481-1-viorel.suman@oss.nxp.com>
On Tue, 24 Nov 2020 16:19:57 +0200, Viorel Suman (OSS) wrote:
> "fw" variable must be relased before return.
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/1] ASoC: fsl_xcvr: fix potential resource leak
commit: 373c2cebf42772434c8dd0deffc3b3886ea8f1eb
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 v6 16/22] powerpc/book3s64/kuap: Improve error reporting with KUAP
From: Christophe Leroy @ 2020-11-25 14:04 UTC (permalink / raw)
To: Aneesh Kumar K.V, linuxppc-dev, mpe
In-Reply-To: <20201125051634.509286-17-aneesh.kumar@linux.ibm.com>
Le 25/11/2020 à 06:16, Aneesh Kumar K.V a écrit :
> 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/32/kup.h | 4 +--
> arch/powerpc/include/asm/book3s/64/kup.h | 27 ++++++++++++++++----
> arch/powerpc/include/asm/kup.h | 4 +--
> arch/powerpc/include/asm/nohash/32/kup-8xx.h | 4 +--
> arch/powerpc/mm/fault.c | 2 +-
> 5 files changed, 29 insertions(+), 12 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/book3s/32/kup.h b/arch/powerpc/include/asm/book3s/32/kup.h
> index 32fd4452e960..b18cd931e325 100644
> --- a/arch/powerpc/include/asm/book3s/32/kup.h
> +++ b/arch/powerpc/include/asm/book3s/32/kup.h
> @@ -177,8 +177,8 @@ static inline void restore_user_access(unsigned long flags)
> allow_user_access(to, to, end - addr, KUAP_READ_WRITE);
> }
>
> -static inline bool
> -bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
> +static inline bool bad_kuap_fault(struct pt_regs *regs, unsigned long address,
> + bool is_write, unsigned long error_code)
> {
> unsigned long begin = regs->kuap & 0xf0000000;
> unsigned long end = regs->kuap << 28;
> diff --git a/arch/powerpc/include/asm/book3s/64/kup.h b/arch/powerpc/include/asm/book3s/64/kup.h
> index 4a3d0d601745..2922c442a218 100644
> --- a/arch/powerpc/include/asm/book3s/64/kup.h
> +++ b/arch/powerpc/include/asm/book3s/64/kup.h
> @@ -301,12 +301,29 @@ static inline void set_kuap(unsigned long value)
> isync();
> }
>
> -static inline bool
> -bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
> +#define RADIX_KUAP_BLOCK_READ UL(0x4000000000000000)
> +#define RADIX_KUAP_BLOCK_WRITE UL(0x8000000000000000)
> +
> +static inline bool bad_kuap_fault(struct pt_regs *regs, unsigned long address,
> + bool is_write, unsigned long error_code)
> {
> - 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");
> + 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");
I think it is pointless to keep the WARN() here.
I have a series aiming at removing them. See
https://patchwork.ozlabs.org/project/linuxppc-dev/patch/cc9129bdda1dbc2f0a09cf45fece7d0b0e690784.1605541983.git.christophe.leroy@csgroup.eu/
> + }
> + /*
> + * 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);
> }
>
> static __always_inline void allow_user_access(void __user *to, const void __user *from,
> diff --git a/arch/powerpc/include/asm/kup.h b/arch/powerpc/include/asm/kup.h
> index a06e50b68d40..952be0414f43 100644
> --- a/arch/powerpc/include/asm/kup.h
> +++ b/arch/powerpc/include/asm/kup.h
> @@ -59,8 +59,8 @@ void setup_kuap(bool disabled);
> #else
> static inline void setup_kuap(bool disabled) { }
>
> -static inline bool
> -bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
> +static inline bool bad_kuap_fault(struct pt_regs *regs, unsigned long address,
> + bool is_write, unsigned long error_code)
> {
> return false;
> }
> diff --git a/arch/powerpc/include/asm/nohash/32/kup-8xx.h b/arch/powerpc/include/asm/nohash/32/kup-8xx.h
> index 567cdc557402..7bdd9e5b63ed 100644
> --- a/arch/powerpc/include/asm/nohash/32/kup-8xx.h
> +++ b/arch/powerpc/include/asm/nohash/32/kup-8xx.h
> @@ -60,8 +60,8 @@ static inline void restore_user_access(unsigned long flags)
> mtspr(SPRN_MD_AP, flags);
> }
>
> -static inline bool
> -bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
> +static inline bool bad_kuap_fault(struct pt_regs *regs, unsigned long address,
> + bool is_write, unsigned long error_code)
> {
> return WARN(!((regs->kuap ^ MD_APG_KUAP) & 0xff000000),
> "Bug: fault blocked by AP register !");
> diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
> index 0add963a849b..c91621df0c61 100644
> --- a/arch/powerpc/mm/fault.c
> +++ b/arch/powerpc/mm/fault.c
> @@ -227,7 +227,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
>
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox