[PATCH] powerpc/32: Select ARCH_SPLIT_ARG64

2022-10-31 Thread Michael Ellerman
On 32-bit kernels, 64-bit syscall arguments are split into two
registers. For that to work with syscall wrappers, the prototype of the
syscall must have the argument split so that the wrapper macro properly
unpacks the arguments from pt_regs.

The fanotify_mark() syscall is one such syscall, which already has a
split prototype, guarded behind ARCH_SPLIT_ARG64.

So select ARCH_SPLIT_ARG64 to get that prototype and fix fanotify_mark()
on 32-bit kernels with syscall wrappers.

Note also that fanotify_mark() is the only usage of ARCH_SPLIT_ARG64.

Fixes: 7e92e01b7245 ("powerpc: Provide syscall wrapper")
Signed-off-by: Michael Ellerman 
---
 arch/powerpc/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 20fb1765238c..2ca5418457ed 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -147,6 +147,7 @@ config PPC
select ARCH_MIGHT_HAVE_PC_SERIO
select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX
select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT
+   select ARCH_SPLIT_ARG64 if PPC32
select ARCH_STACKWALK
select ARCH_SUPPORTS_ATOMIC_RMW
select ARCH_SUPPORTS_DEBUG_PAGEALLOCif PPC_BOOK3S || PPC_8xx || 40x
-- 
2.37.3



Re: [PATCH] Change maintainers for vnic driver

2022-10-31 Thread patchwork-bot+netdevbpf
Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski :

On Fri, 28 Oct 2022 13:35:11 -0700 you wrote:
> Changed maintainers for vnic driver, since Dany has new responsibilities.
> Also added Nick Child as reviewer.
> 
> Signed-off-by: Rick Lindsley 
> 
> ---
>  MAINTAINERS | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)

Here is the summary with links:
  - Change maintainers for vnic driver
https://git.kernel.org/netdev/net/c/e230d36f7d4c

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html




[PATCH] powerpc: Fix some kernel-doc warnings

2022-10-31 Thread Bo Liu
The current code provokes some kernel-doc warnings:
arch/powerpc/kernel/process.c:1606: warning: This comment starts with 
'/**', but isn't a kernel-doc comment. Refer 
Documentation/doc-guide/kernel-doc.rst

Signed-off-by: Bo Liu 
---
 arch/powerpc/kernel/process.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index fcf604370c66..2e78232b1fc9 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1602,7 +1602,7 @@ void arch_setup_new_exec(void)
 }
 
 #ifdef CONFIG_PPC64
-/**
+/*
  * Assign a TIDR (thread ID) for task @t and set it in the thread
  * structure. For now, we only support setting TIDR for 'current' task.
  *
-- 
2.27.0



Re: [PATCH v6 22/25] powerpc/64s: Clear user GPRs in syscall interrupt entry

2022-10-31 Thread Rohan McLure
> On 23 Sep 2022, at 6:02 pm, Nicholas Piggin  wrote:
> 
> On Wed Sep 21, 2022 at 4:56 PM AEST, Rohan McLure wrote:
>> Clear user state in gprs (assign to zero) to reduce the influence of user
>> registers on speculation within kernel syscall handlers. Clears occur
>> at the very beginning of the sc and scv 0 interrupt handlers, with
>> restores occurring following the execution of the syscall handler.
>> 
>> Signed-off-by: Rohan McLure 
>> ---
>> V2: Update summary
>> V3: Remove erroneous summary paragraph on syscall_exit_prepare
>> V4: Use ZEROIZE instead of NULLIFY. Clear r0 also.
>> V5: Move to end of patch series.
>> V6: Include clears which were previously in the syscall wrapper patch.
>> Move comment on r3-r8 register save to when we alter the calling
>> convention for system_call_exception.
> 
> The series looks good to here, I just need to find a bit more time to
> look at the code and do some tests with the next few patches. I don't
> see much problem with them, looks a lot better now with fewer ifdefs
> so that's good. Possibly you could share some of those new sanitize
> macros in a header file but that's a minor nit.
> 
> Coud we have this zeroize also under the same config option as the
> next? I figure if we care about speculative security we want both,
> and if we don't we need neither.

Thanks for this. I’ll resubmit the last four patches with a common
configuration option for register clearing. Just pinging to hear your
thoughts on whether we are willing to wear the small performance
regression in general interrupts, and whether this mitigation should
be a default on pseries.

Rohan

> 
> Thanks,
> Nick
> 
>> ---
>> arch/powerpc/kernel/interrupt_64.S | 17 -
>> 1 file changed, 16 insertions(+), 1 deletion(-)
>> 
>> diff --git a/arch/powerpc/kernel/interrupt_64.S 
>> b/arch/powerpc/kernel/interrupt_64.S
>> index a5dd78bdbe6d..40147558e1a6 100644
>> --- a/arch/powerpc/kernel/interrupt_64.S
>> +++ b/arch/powerpc/kernel/interrupt_64.S
>> @@ -106,6 +106,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
>>  * but this is the best we can do.
>>  */
>> 
>> + /*
>> +  * Zero user registers to prevent influencing speculative execution
>> +  * state of kernel code.
>> +  */
>> + ZEROIZE_GPR(0)
>> + ZEROIZE_GPRS(5, 12)
>> + ZEROIZE_NVGPRS()
>> bl system_call_exception
>> 
>> .Lsyscall_vectored_\name\()_exit:
>> @@ -134,6 +141,7 @@ BEGIN_FTR_SECTION
>> HMT_MEDIUM_LOW
>> END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
>> 
>> + REST_NVGPRS(r1)
>> cmpdi r3,0
>> bne .Lsyscall_vectored_\name\()_restore_regs
>> 
>> @@ -285,6 +293,13 @@ END_BTB_FLUSH_SECTION
>> wrteei 1
>> #endif
>> 
>> + /*
>> +  * Zero user registers to prevent influencing speculative execution
>> +  * state of kernel code.
>> +  */
>> + ZEROIZE_GPR(0)
>> + ZEROIZE_GPRS(5, 12)
>> + ZEROIZE_NVGPRS()
>> bl system_call_exception
>> 
>> .Lsyscall_exit:
>> @@ -325,6 +340,7 @@ BEGIN_FTR_SECTION
>> stdcx. r0,0,r1 /* to clear the reservation */
>> END_FTR_SECTION_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS)
>> 
>> + REST_NVGPRS(r1)
>> cmpdi r3,0
>> bne .Lsyscall_restore_regs
>> /* Zero volatile regs that may contain sensitive kernel data */
>> @@ -352,7 +368,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
>> .Lsyscall_restore_regs:
>> ld r3,_CTR(r1)
>> ld r4,_XER(r1)
>> - REST_NVGPRS(r1)
>> mtctr r3
>> mtspr SPRN_XER,r4
>> REST_GPR(0, r1)
>> -- 
>> 2.34.1




Re: [PATCH net-next v7 08/10] powerpc: dts: t208x: Mark MAC1 and MAC2 as 10G

2022-10-31 Thread Sean Anderson
On 10/31/22 10:12, Camelia Alexandra Groza wrote:
>> -Original Message-
>> From: Sean Anderson 
>> Sent: Friday, October 28, 2022 19:55
>> To: Camelia Alexandra Groza ; Sean Anderson
>> ; David S . Miller ;
>> Jakub Kicinski ; Madalin Bucur
>> ; net...@vger.kernel.org
>> Cc: Eric Dumazet ; linuxppc-dev @ lists . ozlabs .
>> org ; linux-arm-ker...@lists.infradead.org;
>> linux-ker...@vger.kernel.org; Russell King ; Paolo
>> Abeni ; Benjamin Herrenschmidt
>> ; Krzysztof Kozlowski
>> ; Leo Li ; Michael
>> Ellerman ; Paul Mackerras ; Rob
>> Herring ; devicet...@vger.kernel.org
>> Subject: Re: [PATCH net-next v7 08/10] powerpc: dts: t208x: Mark MAC1 and
>> MAC2 as 10G
>> 
>> On 10/28/22 12:30, Camelia Alexandra Groza wrote:
>> >> -Original Message-
>> >> From: Sean Anderson 
>> >> Sent: Monday, October 17, 2022 23:23
>> >> To: David S . Miller ; Jakub Kicinski
>> >> ; Madalin Bucur ; Camelia
>> >> Alexandra Groza ; net...@vger.kernel.org
>> >> Cc: Eric Dumazet ; linuxppc-dev @ lists . ozlabs .
>> >> org ; linux-arm-
>> ker...@lists.infradead.org;
>> >> linux-ker...@vger.kernel.org; Russell King ;
>> Paolo
>> >> Abeni ; Sean Anderson
>> ;
>> >> Benjamin Herrenschmidt ; Krzysztof
>> Kozlowski
>> >> ; Leo Li ;
>> Michael
>> >> Ellerman ; Paul Mackerras ;
>> Rob
>> >> Herring ; devicet...@vger.kernel.org
>> >> Subject: [PATCH net-next v7 08/10] powerpc: dts: t208x: Mark MAC1 and
>> >> MAC2 as 10G
>> >>
>> >> On the T208X SoCs, MAC1 and MAC2 support XGMII. Add some new MAC
>> >> dtsi
>> >> fragments, and mark the QMAN ports as 10G.
>> >>
>> >> Fixes: da414bb923d9 ("powerpc/mpc85xx: Add FSL QorIQ DPAA FMan
>> >> support to the SoC device tree(s)")
>> >> Signed-off-by: Sean Anderson 
>> >> ---
>> >>
>> >> (no changes since v4)
>> >>
>> >> Changes in v4:
>> >> - New
>> >
>> > Hi Sean,
>> >
>> > These changes prevent MAC2 from probing on T2080RDB due to
>> insufficient FMan hardware resources.
>> >
>> > fsl-fman ffe40.fman: set_num_of_tasks: Requested num_of_tasks
>> and extra tasks pool for fm0 exceed total num_of_tasks.
>> > fsl_dpa: dpaa_eth_init_tx_port: fm_port_init failed
>> > fsl_dpa: probe of dpaa-ethernet.5 failed with error -11
>> >
>> > The distribution of resources depends on the port type, and different
>> FMan hardware revisions have different amounts of resources.
>> >
>> > The current distribution of resources can be reconsidered, but this change
>> should be reverted for now.
>> 
>> OK, so this patch does two things:
>> 
>> @@ -37,12 +11,14 @@
>>  cell-index = <0x8>;
>>  compatible = "fsl,fman-v3-port-rx";
>>  reg = <0x88000 0x1000>;
>> +fsl,fman-10g-port;
>>  };
>> 
>>  fman0_tx_0x28: port@a8000 {
>>  cell-index = <0x28>;
>>  compatible = "fsl,fman-v3-port-tx";
>>  reg = <0xa8000 0x1000>;
>> +fsl,fman-10g-port;
>>  };
>> 
>>  ethernet@e {
>> @@ -52,7 +28,7 @@
>>  fsl,fman-ports = <_rx_0x08 _tx_0x28>;
>>  ptp-timer = <_timer0>;
>>  pcsphy-handle = <>, <>;
>> -pcs-handle-names = "sgmii", "qsgmii";
>> +pcs-handle-names = "sgmii", "xfi";
>>  };
>> 
>>  mdio@e1000 {
>> 
>> First, it marks the ports as 10g. I believe this is what's causing the
>> resource problems above.
> 
> That's right.
> 
>> Second, it removes support for QSGMII and adds
>> support for XFI. This is a matter of correctness; these MACs really
>> don't support QSGMII, and do support XFI.
> 
> Correct, these MACs don't support QSGMII on this SoC.
> 
>> As I understand it, you can
>> run a 10g port at 1g speeds, it just won't perform as well. So I think a
>> more minimal revert would be to delete the fsl,fman-10g-port properties
>> in t2081si-post.dtsi.
> 
> Since these two new dtsi files are included by only one SoC, I don't see an
> advantage in adding these properties and then deleting them. No other
> users benefit from adding them in the first place. 

OK, so would you prefer just overriding pcs-handle-names in the SoC dtsi?

--Sean

>> That said, is 10g even being used on these ports? I included this patch
>> in order to avoid breaking any existing users.
> 
> It is used, though less efficiently, with fewer FMan hardware resources.
> 
> Camelia
> 
>> --Sean
>> 
>> > Regards,
>> > Camelia
>> >
>> >
>> >>   .../boot/dts/fsl/qoriq-fman3-0-10g-2.dtsi | 44 +++
>> >>   .../boot/dts/fsl/qoriq-fman3-0-10g-3.dtsi | 44 +++
>> >>   arch/powerpc/boot/dts/fsl/t2081si-post.dtsi   |  4 +-
>> >>   3 files changed, 90 insertions(+), 2 deletions(-)
>> >>   create mode 100644 arch/powerpc/boot/dts/fsl/qoriq-fman3-0-10g-
>> 2.dtsi
>> >>   create mode 100644 arch/powerpc/boot/dts/fsl/qoriq-fman3-0-10g-
>> 3.dtsi
>> >>
>> >> diff --git a/arch/powerpc/boot/dts/fsl/qoriq-fman3-0-10g-2.dtsi
>> >> b/arch/powerpc/boot/dts/fsl/qoriq-fman3-0-10g-2.dtsi
>> >> new file mode 100644
>> >> index ..437dab3fc017
>> >> 

[PATCH v4 2/2] mm, hwpoison: When copy-on-write hits poison, take page offline

2022-10-31 Thread Tony Luck
Cannot call memory_failure() directly from the fault handler because
mmap_lock (and others) are held.

It is important, but not urgent, to mark the source page as h/w poisoned
and unmap it from other tasks.

Use memory_failure_queue() to request a call to memory_failure() for the
page with the error.

Also provide a stub version for CONFIG_MEMORY_FAILURE=n

Reviewed-by: Miaohe Lin 
Tested-by: Shuai Xue 
Signed-off-by: Tony Luck 
Message-Id: <20221021200120.175753-3-tony.l...@intel.com>
Signed-off-by: Tony Luck 
---
 include/linux/mm.h | 5 -
 mm/memory.c| 4 +++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 8bbcccbc5565..03ced659eb58 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3268,7 +3268,6 @@ enum mf_flags {
 int mf_dax_kill_procs(struct address_space *mapping, pgoff_t index,
  unsigned long count, int mf_flags);
 extern int memory_failure(unsigned long pfn, int flags);
-extern void memory_failure_queue(unsigned long pfn, int flags);
 extern void memory_failure_queue_kick(int cpu);
 extern int unpoison_memory(unsigned long pfn);
 extern int sysctl_memory_failure_early_kill;
@@ -3277,8 +3276,12 @@ extern void shake_page(struct page *p);
 extern atomic_long_t num_poisoned_pages __read_mostly;
 extern int soft_offline_page(unsigned long pfn, int flags);
 #ifdef CONFIG_MEMORY_FAILURE
+extern void memory_failure_queue(unsigned long pfn, int flags);
 extern int __get_huge_page_for_hwpoison(unsigned long pfn, int flags);
 #else
+static inline void memory_failure_queue(unsigned long pfn, int flags)
+{
+}
 static inline int __get_huge_page_for_hwpoison(unsigned long pfn, int flags)
 {
return 0;
diff --git a/mm/memory.c b/mm/memory.c
index b6056eef2f72..eae242351726 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2866,8 +2866,10 @@ static inline int __wp_page_copy_user(struct page *dst, 
struct page *src,
unsigned long addr = vmf->address;
 
if (likely(src)) {
-   if (copy_mc_user_highpage(dst, src, addr, vma))
+   if (copy_mc_user_highpage(dst, src, addr, vma)) {
+   memory_failure_queue(page_to_pfn(src), 0);
return -EHWPOISON;
+   }
return 0;
}
 
-- 
2.37.3



[PATCH v4 1/2] mm, hwpoison: Try to recover from copy-on write faults

2022-10-31 Thread Tony Luck
If the kernel is copying a page as the result of a copy-on-write
fault and runs into an uncorrectable error, Linux will crash because
it does not have recovery code for this case where poison is consumed
by the kernel.

It is easy to set up a test case. Just inject an error into a private
page, fork(2), and have the child process write to the page.

I wrapped that neatly into a test at:

  git://git.kernel.org/pub/scm/linux/kernel/git/aegl/ras-tools.git

just enable ACPI error injection and run:

  # ./einj_mem-uc -f copy-on-write

Add a new copy_user_highpage_mc() function that uses copy_mc_to_kernel()
on architectures where that is available (currently x86 and powerpc).
When an error is detected during the page copy, return VM_FAULT_HWPOISON
to caller of wp_page_copy(). This propagates up the call stack. Both x86
and powerpc have code in their fault handler to deal with this code by
sending a SIGBUS to the application.

Note that this patch avoids a system crash and signals the process that
triggered the copy-on-write action. It does not take any action for the
memory error that is still in the shared page. To handle that a call to
memory_failure() is needed. But this cannot be done from wp_page_copy()
because it holds mmap_lock(). Perhaps the architecture fault handlers
can deal with this loose end in a subsequent patch?

On Intel/x86 this loose end will often be handled automatically because
the memory controller provides an additional notification of the h/w
poison in memory, the handler for this will call memory_failure(). This
isn't a 100% solution. If there are multiple errors, not all may be
logged in this way.

Reviewed-by: Dan Williams 
Reviewed-by: Miaohe Lin 
Reviewed-by: Naoya Horiguchi 
Tested-by: Shuai Xue 
Signed-off-by: Tony Luck 
Message-Id: <20221021200120.175753-2-tony.l...@intel.com>
Signed-off-by: Tony Luck 
---
 include/linux/highmem.h | 26 ++
 mm/memory.c | 30 --
 2 files changed, 46 insertions(+), 10 deletions(-)

diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index e9912da5441b..44242268f53b 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -319,6 +319,32 @@ static inline void copy_user_highpage(struct page *to, 
struct page *from,
 
 #endif
 
+#ifdef copy_mc_to_kernel
+static inline int copy_mc_user_highpage(struct page *to, struct page *from,
+   unsigned long vaddr, struct 
vm_area_struct *vma)
+{
+   unsigned long ret;
+   char *vfrom, *vto;
+
+   vfrom = kmap_local_page(from);
+   vto = kmap_local_page(to);
+   ret = copy_mc_to_kernel(vto, vfrom, PAGE_SIZE);
+   if (!ret)
+   kmsan_unpoison_memory(page_address(to), PAGE_SIZE);
+   kunmap_local(vto);
+   kunmap_local(vfrom);
+
+   return ret;
+}
+#else
+static inline int copy_mc_user_highpage(struct page *to, struct page *from,
+   unsigned long vaddr, struct 
vm_area_struct *vma)
+{
+   copy_user_highpage(to, from, vaddr, vma);
+   return 0;
+}
+#endif
+
 #ifndef __HAVE_ARCH_COPY_HIGHPAGE
 
 static inline void copy_highpage(struct page *to, struct page *from)
diff --git a/mm/memory.c b/mm/memory.c
index f88c351aecd4..b6056eef2f72 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2848,10 +2848,16 @@ static inline int pte_unmap_same(struct vm_fault *vmf)
return same;
 }
 
-static inline bool __wp_page_copy_user(struct page *dst, struct page *src,
-  struct vm_fault *vmf)
+/*
+ * Return:
+ * 0:  copied succeeded
+ * -EHWPOISON: copy failed due to hwpoison in source page
+ * -EAGAIN:copied failed (some other reason)
+ */
+static inline int __wp_page_copy_user(struct page *dst, struct page *src,
+ struct vm_fault *vmf)
 {
-   bool ret;
+   int ret;
void *kaddr;
void __user *uaddr;
bool locked = false;
@@ -2860,8 +2866,9 @@ static inline bool __wp_page_copy_user(struct page *dst, 
struct page *src,
unsigned long addr = vmf->address;
 
if (likely(src)) {
-   copy_user_highpage(dst, src, addr, vma);
-   return true;
+   if (copy_mc_user_highpage(dst, src, addr, vma))
+   return -EHWPOISON;
+   return 0;
}
 
/*
@@ -2888,7 +2895,7 @@ static inline bool __wp_page_copy_user(struct page *dst, 
struct page *src,
 * and update local tlb only
 */
update_mmu_tlb(vma, addr, vmf->pte);
-   ret = false;
+   ret = -EAGAIN;
goto pte_unlock;
}
 
@@ -2913,7 +2920,7 @@ static inline bool __wp_page_copy_user(struct page *dst, 
struct page *src,
if (!likely(pte_same(*vmf->pte, vmf->orig_pte))) {
/* 

[PATCH v4 0/2] Copy-on-write poison recovery

2022-10-31 Thread Tony Luck
Recover from poison consumption while copying pages
in the kernel for a copy-on-write fault.

Changes since v3:

1) Miaohe Lin  pointed out that a recent change
by Alexander Potapenko  to copy_user_highpage()
added a call to kmsan_unpoison_memory().  Same is needed in my cloned
copy_mc_user_highpage() ... at least in the successful case where the
page was copied with no machine checks.

2) Picked up some additional Reviewed-by and Tested-by tags.

Tony Luck (2):
  mm, hwpoison: Try to recover from copy-on write faults
  mm, hwpoison: When copy-on-write hits poison, take page offline

 include/linux/highmem.h | 26 ++
 include/linux/mm.h  |  5 -
 mm/memory.c | 32 ++--
 3 files changed, 52 insertions(+), 11 deletions(-)


base-commit: 30a0b95b1335e12efef89dd78518ed3e4a71a763
-- 
2.37.3



Re: [PATCH] powerpc/32: fix syscall wrappers with 64-bit arguments

2022-10-31 Thread Arnd Bergmann
On Mon, Oct 31, 2022, at 15:47, Andreas Schwab wrote:
> With the introducion of syscall wrappers all wrappers for syscalls with
> 64-bit arguments must be handled specially, not only those that have
> unaligned 64-bit arguments.  This left out the fallocate and
> sync_file_range2 syscalls.
>
> Fixes: 7e92e01b7245 ("powerpc: Provide syscall wrapper")
> Fixes: e23750623835 ("powerpc/32: fix syscall wrappers with 64-bit 
> arguments of unaligned register-pairs")
> Signed-off-by: Andreas Schwab 

This looks correct as a minmal bugfix to be backported.
I have cross-checked the syscalls with 64-bit arguments that
have special handlers on powerpc against the list from x86
to make sure there are no other obvious ones that need a
similar fix.

Reviewed-by: Arnd Bergmann 

> +
> +#ifdef CONFIG_PPC32
> +SYSCALL_DEFINE6(ppc_fallocate,
> + int, fd, int, mode,
> + u32, offset1, u32, offset2, u32, len1, u32, len2)
> +{
> + return ksys_fallocate(fd, mode,
> +   merge_64(offset1, offset2),
> +   merge_64(len1, len2));
> +}
> +#endif

This is identical to compat_sys_fallocate() and to
(an andian-corrected) sys_ia32_fallocate(), right?

I still think we should eventually generalize this further and
make all these handlers architecture independent to prevent the
same bug from happening on additional architectures, but that
should probably be done separately.

 Arnd


Re: [PATCH v4 2/2] arm64: support batched/deferred tlb shootdown during page reclamation

2022-10-31 Thread Punit Agrawal
Barry Song <21cn...@gmail.com> writes:

> On Sat, Oct 29, 2022 at 2:11 AM Punit Agrawal
>  wrote:
>>
>> Yicong Yang  writes:
>>
>> > On 2022/10/27 22:19, Punit Agrawal wrote:
>> >>
>> >> [ Apologies for chiming in late in the conversation ]
>> >>
>> >> Anshuman Khandual  writes:
>> >>
>> >>> On 9/28/22 05:53, Barry Song wrote:
>>  On Tue, Sep 27, 2022 at 10:15 PM Yicong Yang  
>>  wrote:
>> >
>> > On 2022/9/27 14:16, Anshuman Khandual wrote:
>> >> [...]
>> >>
>> >> On 9/21/22 14:13, Yicong Yang wrote:
>> >>> +static inline bool arch_tlbbatch_should_defer(struct mm_struct *mm)
>> >>> +{
>> >>> +/* for small systems with small number of CPUs, TLB shootdown 
>> >>> is cheap */
>> >>> +if (num_online_cpus() <= 4)
>> >>
>> >> It would be great to have some more inputs from others, whether 4 
>> >> (which should
>> >> to be codified into a macro e.g ARM64_NR_CPU_DEFERRED_TLB, or 
>> >> something similar)
>> >> is optimal for an wide range of arm64 platforms.
>> >>
>> 
>>  I have tested it on a 4-cpus and 8-cpus machine. but i have no machine
>>  with 5,6,7
>>  cores.
>>  I saw improvement on 8-cpus machines and I found 4-cpus machines don't 
>>  need
>>  this patch.
>> 
>>  so it seems safe to have
>>  if (num_online_cpus()  < 8)
>> 
>> >
>> > Do you prefer this macro to be static or make it configurable through 
>> > kconfig then
>> > different platforms can make choice based on their own situations? It 
>> > maybe hard to
>> > test on all the arm64 platforms.
>> 
>>  Maybe we can have this default enabled on machines with 8 and more cpus 
>>  and
>>  provide a tlbflush_batched = on or off to allow users enable or
>>  disable it according
>>  to their hardware and products. Similar example: rodata=on or off.
>> >>>
>> >>> No, sounds bit excessive. Kernel command line options should not be added
>> >>> for every possible run time switch options.
>> >>>
>> 
>>  Hi Anshuman, Will,  Catalin, Andrew,
>>  what do you think about this approach?
>> 
>>  BTW, haoxin mentioned another important user scenarios for tlb bach on 
>>  arm64:
>>  https://lore.kernel.org/lkml/393d6318-aa38-01ed-6ad8-f9eac89bf...@linux.alibaba.com/
>> 
>>  I do believe we need it based on the expensive cost of tlb shootdown in 
>>  arm64
>>  even by hardware broadcast.
>> >>>
>> >>> Alright, for now could we enable ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH 
>> >>> selectively
>> >>> with CONFIG_EXPERT and for num_online_cpus()  > 8 ?
>> >>
>> >> When running the test program in the commit in a VM, I saw benefits from
>> >> the patches at all sizes from 2, 4, 8, 32 vcpus. On the test machine,
>> >> ptep_clear_flush() went from ~1% in the unpatched version to not showing
>> >> up.
>> >>
>> >
>> > Maybe you're booting VM on a server with more than 32 cores and Barry 
>> > tested
>> > on his 4 CPUs embedded platform. I guess a 4 CPU VM is not fully 
>> > equivalent to
>> > a 4 CPU real machine as the tbli and dsb in the VM may influence the host
>> > as well.
>>
>> Yeah, I also wondered about this.
>>
>> I was able to test on a 6-core RK3399 based system - there the
>> ptep_clear_flush() was only 0.10% of the overall execution time. The
>> hardware seems to do a pretty good job of keeping the TLB flushing
>> overhead low.

I found a problem with my measurements (missing volatile). Correcting
that increased the overhead somewhat - more below.

> RK3399 has Dual-core ARM Cortex-A72 MPCore processor and
> Quad-core ARM Cortex-A53 MPCore processor. you are probably
> going to see different overhead of ptep_clear_flush() when you
> bind the micro-benchmark on different cores.

Indeed - binding the code on the A53 shows half the overhead from
ptep_clear_flush() compared to the A72.

On the A53 -

$ perf report --stdio -i perf.vanilla.a53.data | grep ptep_clear_flush
 0.63%  pageout  [kernel.kallsyms]  [k] ptep_clear_flush

On the A72

$ perf report --stdio -i perf.vanilla.a72.data | grep ptep_clear_flush
 1.34%  pageout  [kernel.kallsyms]  [k] ptep_clear_flush


[...]



Re: [PATCH 1/3] ASoC: dt-bindings: fsl,micfil: Add compatible string for i.MX93 platform

2022-10-31 Thread Rob Herring


On Fri, 28 Oct 2022 16:27:48 +0800, Chancel Liu wrote:
> Add compatible string "fsl,imx93-micfil" for i.MX93 platform
> 
> Signed-off-by: Chancel Liu 
> ---
>  Documentation/devicetree/bindings/sound/fsl,micfil.yaml | 1 +
>  1 file changed, 1 insertion(+)
> 

Acked-by: Rob Herring 


RE: [PATCH v3 5/5] PCI: Remove unnecessary includes

2022-10-31 Thread Roy Zang


> -Original Message-
> From: Bjorn Helgaas 
> Subject: [PATCH v3 5/5] PCI: Remove unnecessary  includes
> 
> From: Bjorn Helgaas 
> 
> Many host controller drivers #include  even though they
> don't need it.  Remove the unnecessary #includes.
> 
> Signed-off-by: Bjorn Helgaas 
> ---
>  drivers/pci/controller/cadence/pci-j721e.c   | 1 -
>  drivers/pci/controller/dwc/pci-layerscape.c  | 1 -
>  drivers/pci/controller/dwc/pcie-armada8k.c   | 1 -
>  drivers/pci/controller/dwc/pcie-tegra194.c   | 1 -
>  drivers/pci/controller/pci-v3-semi.c | 1 -
>  drivers/pci/controller/pci-xgene-msi.c   | 1 -
>  drivers/pci/controller/pci-xgene.c   | 1 -
>  drivers/pci/controller/pcie-altera-msi.c | 1 -
>  drivers/pci/controller/pcie-iproc-platform.c | 1 -
>  drivers/pci/controller/pcie-iproc.c  | 1 -
>  drivers/pci/controller/pcie-microchip-host.c | 1 -  
> drivers/pci/controller/pcie-
> rockchip-host.c  | 1 -
>  drivers/pci/controller/pcie-xilinx-cpm.c | 1 -
>  drivers/pci/controller/pcie-xilinx-nwl.c | 1 -
>  14 files changed, 14 deletions(-)
Acked-by: Roy Zang 

-R


[PATCH v3 5/5] PCI: Remove unnecessary includes

2022-10-31 Thread Bjorn Helgaas
From: Bjorn Helgaas 

Many host controller drivers #include  even though they
don't need it.  Remove the unnecessary #includes.

Signed-off-by: Bjorn Helgaas 
---
 drivers/pci/controller/cadence/pci-j721e.c   | 1 -
 drivers/pci/controller/dwc/pci-layerscape.c  | 1 -
 drivers/pci/controller/dwc/pcie-armada8k.c   | 1 -
 drivers/pci/controller/dwc/pcie-tegra194.c   | 1 -
 drivers/pci/controller/pci-v3-semi.c | 1 -
 drivers/pci/controller/pci-xgene-msi.c   | 1 -
 drivers/pci/controller/pci-xgene.c   | 1 -
 drivers/pci/controller/pcie-altera-msi.c | 1 -
 drivers/pci/controller/pcie-iproc-platform.c | 1 -
 drivers/pci/controller/pcie-iproc.c  | 1 -
 drivers/pci/controller/pcie-microchip-host.c | 1 -
 drivers/pci/controller/pcie-rockchip-host.c  | 1 -
 drivers/pci/controller/pcie-xilinx-cpm.c | 1 -
 drivers/pci/controller/pcie-xilinx-nwl.c | 1 -
 14 files changed, 14 deletions(-)

diff --git a/drivers/pci/controller/cadence/pci-j721e.c 
b/drivers/pci/controller/cadence/pci-j721e.c
index a82f845cc4b5..cc83a8925ce0 100644
--- a/drivers/pci/controller/cadence/pci-j721e.c
+++ b/drivers/pci/controller/cadence/pci-j721e.c
@@ -15,7 +15,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/drivers/pci/controller/dwc/pci-layerscape.c 
b/drivers/pci/controller/dwc/pci-layerscape.c
index 879b8692f96a..ed5fb492fe08 100644
--- a/drivers/pci/controller/dwc/pci-layerscape.c
+++ b/drivers/pci/controller/dwc/pci-layerscape.c
@@ -13,7 +13,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/drivers/pci/controller/dwc/pcie-armada8k.c 
b/drivers/pci/controller/dwc/pcie-armada8k.c
index dc469ef8e99b..5c999e15c357 100644
--- a/drivers/pci/controller/dwc/pcie-armada8k.c
+++ b/drivers/pci/controller/dwc/pcie-armada8k.c
@@ -21,7 +21,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "pcie-designware.h"
 
diff --git a/drivers/pci/controller/dwc/pcie-tegra194.c 
b/drivers/pci/controller/dwc/pcie-tegra194.c
index 1b6b437823d2..02d78a12b6e7 100644
--- a/drivers/pci/controller/dwc/pcie-tegra194.c
+++ b/drivers/pci/controller/dwc/pcie-tegra194.c
@@ -21,7 +21,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/drivers/pci/controller/pci-v3-semi.c 
b/drivers/pci/controller/pci-v3-semi.c
index 154a5398633c..784fcf35599c 100644
--- a/drivers/pci/controller/pci-v3-semi.c
+++ b/drivers/pci/controller/pci-v3-semi.c
@@ -22,7 +22,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/drivers/pci/controller/pci-xgene-msi.c 
b/drivers/pci/controller/pci-xgene-msi.c
index bacb14e558ee..d7987b281f79 100644
--- a/drivers/pci/controller/pci-xgene-msi.c
+++ b/drivers/pci/controller/pci-xgene-msi.c
@@ -11,7 +11,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/drivers/pci/controller/pci-xgene.c 
b/drivers/pci/controller/pci-xgene.c
index 549d3bd6d1c2..887b4941ff32 100644
--- a/drivers/pci/controller/pci-xgene.c
+++ b/drivers/pci/controller/pci-xgene.c
@@ -14,7 +14,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/drivers/pci/controller/pcie-altera-msi.c 
b/drivers/pci/controller/pcie-altera-msi.c
index 4366e042e98b..65e8a20cc442 100644
--- a/drivers/pci/controller/pcie-altera-msi.c
+++ b/drivers/pci/controller/pcie-altera-msi.c
@@ -14,7 +14,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/drivers/pci/controller/pcie-iproc-platform.c 
b/drivers/pci/controller/pcie-iproc-platform.c
index 538115246c79..4142a73e611d 100644
--- a/drivers/pci/controller/pcie-iproc-platform.c
+++ b/drivers/pci/controller/pcie-iproc-platform.c
@@ -12,7 +12,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 
diff --git a/drivers/pci/controller/pcie-iproc.c 
b/drivers/pci/controller/pcie-iproc.c
index 2519201b0e51..83029bdfd884 100644
--- a/drivers/pci/controller/pcie-iproc.c
+++ b/drivers/pci/controller/pcie-iproc.c
@@ -18,7 +18,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 
diff --git a/drivers/pci/controller/pcie-microchip-host.c 
b/drivers/pci/controller/pcie-microchip-host.c
index 57b2a62f52c8..0ebf7015e9af 100644
--- a/drivers/pci/controller/pcie-microchip-host.c
+++ b/drivers/pci/controller/pcie-microchip-host.c
@@ -13,7 +13,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/drivers/pci/controller/pcie-rockchip-host.c 
b/drivers/pci/controller/pcie-rockchip-host.c
index 7352b5ff8d35..c96c0f454570 100644
--- a/drivers/pci/controller/pcie-rockchip-host.c
+++ b/drivers/pci/controller/pcie-rockchip-host.c
@@ -28,7 +28,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/drivers/pci/controller/pcie-xilinx-cpm.c 
b/drivers/pci/controller/pcie-xilinx-cpm.c
index e4ab48041eb6..4a787a941674 100644
--- 

[PATCH v3 4/5] PCI: xgene-msi: Include explicitly

2022-10-31 Thread Bjorn Helgaas
From: Bjorn Helgaas 

pci-xgene-msi.c uses irq_domain_add_linear() and related interfaces, so it
needs  but doesn't include it directly; it relies on the
fact that  includes it.

But pci-xgene-msi.c *doesn't* need  itself.  Include
 directly to remove this implicit dependency so a future
patch can drop .

Signed-off-by: Bjorn Helgaas 
---
 drivers/pci/controller/pci-xgene-msi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pci/controller/pci-xgene-msi.c 
b/drivers/pci/controller/pci-xgene-msi.c
index bfa259781b69..bacb14e558ee 100644
--- a/drivers/pci/controller/pci-xgene-msi.c
+++ b/drivers/pci/controller/pci-xgene-msi.c
@@ -8,6 +8,7 @@
  */
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
-- 
2.25.1



[PATCH v3 3/5] PCI: mvebu: Include explicitly

2022-10-31 Thread Bjorn Helgaas
From: Bjorn Helgaas 

pci-mvebu.c uses irq_domain_add_linear() and related interfaces but relies
on  but doesn't include it directly; it relies on the
fact that  includes it.

Include  directly to remove this implicit dependency.

Signed-off-by: Bjorn Helgaas 
Acked-by: Thomas Petazzoni 
---
 drivers/pci/controller/pci-mvebu.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pci/controller/pci-mvebu.c 
b/drivers/pci/controller/pci-mvebu.c
index 1ced73726a26..73db99035c2b 100644
--- a/drivers/pci/controller/pci-mvebu.c
+++ b/drivers/pci/controller/pci-mvebu.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
-- 
2.25.1



[PATCH v3 2/5] PCI: microchip: Include explicitly

2022-10-31 Thread Bjorn Helgaas
From: Bjorn Helgaas 

pcie-microchip-host.c uses irq_domain_add_linear() and related interfaces,
so it needs  but doesn't include it directly; it relies
on the fact that  includes it.

But pcie-microchip-host.c *doesn't* need  itself.  Include
 directly to remove this implicit dependency so a future
patch can drop .

Signed-off-by: Bjorn Helgaas 
Reviewed-by: Conor Dooley 
---
 drivers/pci/controller/pcie-microchip-host.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pci/controller/pcie-microchip-host.c 
b/drivers/pci/controller/pcie-microchip-host.c
index 7263d175b5ad..57b2a62f52c8 100644
--- a/drivers/pci/controller/pcie-microchip-host.c
+++ b/drivers/pci/controller/pcie-microchip-host.c
@@ -9,6 +9,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
-- 
2.25.1



[PATCH v3 1/5] PCI: altera-msi: Include explicitly

2022-10-31 Thread Bjorn Helgaas
From: Bjorn Helgaas 

pcie-altera-msi.c uses irq_domain_add_linear() and related interfaces, so
it needs  but doesn't include it directly; it relies on
the fact that  includes it.

But pcie-altera-msi.c *doesn't* need  itself.  Include
 directly to remove this implicit dependency so a future
patch can drop .

Signed-off-by: Bjorn Helgaas 
---
 drivers/pci/controller/pcie-altera-msi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pci/controller/pcie-altera-msi.c 
b/drivers/pci/controller/pcie-altera-msi.c
index 7b1d3ebc34ec..4366e042e98b 100644
--- a/drivers/pci/controller/pcie-altera-msi.c
+++ b/drivers/pci/controller/pcie-altera-msi.c
@@ -9,6 +9,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
-- 
2.25.1



[PATCH v3 0/5] PCI: Remove unnecessary includes

2022-10-31 Thread Bjorn Helgaas
From: Bjorn Helgaas 

Many host controller drivers #include  even though they
don't need it.  Remove the unnecessary #includes.

v2: https://lore.kernel.org/r/20221025185147.665365-1-helg...@kernel.org/
v1: https://lore.kernel.org/r/20221019195452.37606-1-helg...@kernel.org/

Changes from v2 to v3:
  - Include  explicitly in xgene-msi, which doesn't need
 itself, but relied on it to include
.  On x86, this was covered up by the fact that
 includes , which includes ,
which includes .  But on parisc,  is
actually asm-generic/msi.h, which does *not* include

  - Pick up tags from Conor Dooley and Thomas Petazzoni

Changes from v1 to v2:
  - Include  explicitly in altera-msi and microchip,
which don't need  itself, but relied on it to include

  - Include  explicitly in mvebu, which needs both it
and 

Bjorn Helgaas (5):
  PCI: altera-msi: Include  explicitly
  PCI: microchip: Include  explicitly
  PCI: mvebu: Include  explicitly
  PCI: xgene-msi: Include  explicitly
  PCI: Remove unnecessary  includes

 drivers/pci/controller/cadence/pci-j721e.c   | 1 -
 drivers/pci/controller/dwc/pci-layerscape.c  | 1 -
 drivers/pci/controller/dwc/pcie-armada8k.c   | 1 -
 drivers/pci/controller/dwc/pcie-tegra194.c   | 1 -
 drivers/pci/controller/pci-mvebu.c   | 1 +
 drivers/pci/controller/pci-v3-semi.c | 1 -
 drivers/pci/controller/pci-xgene-msi.c   | 2 +-
 drivers/pci/controller/pci-xgene.c   | 1 -
 drivers/pci/controller/pcie-altera-msi.c | 2 +-
 drivers/pci/controller/pcie-iproc-platform.c | 1 -
 drivers/pci/controller/pcie-iproc.c  | 1 -
 drivers/pci/controller/pcie-microchip-host.c | 2 +-
 drivers/pci/controller/pcie-rockchip-host.c  | 1 -
 drivers/pci/controller/pcie-xilinx-cpm.c | 1 -
 drivers/pci/controller/pcie-xilinx-nwl.c | 1 -
 15 files changed, 4 insertions(+), 14 deletions(-)

-- 
2.25.1



Re: [PATCH v8 4/9] phy: fsl: Add Lynx 10G SerDes driver

2022-10-31 Thread Sean Anderson
On 10/29/22 05:11, Bagas Sanjaya wrote:
> On Thu, Oct 27, 2022 at 03:11:08PM -0400, Sean Anderson wrote:
>>  .. only::  subproject and html
>> diff --git a/Documentation/driver-api/phy/lynx_10g.rst 
>> b/Documentation/driver-api/phy/lynx_10g.rst
>> new file mode 100644
>> index ..ebbf4dd86726
>> --- /dev/null
>> +++ b/Documentation/driver-api/phy/lynx_10g.rst
>> @@ -0,0 +1,58 @@
>> +.. SPDX-License-Identifier: GPL-2.0
>> +
>> +===
>> +Lynx 10G Phy (QorIQ SerDes)
>> +===
>> +
>> +Using this phy
>> +--
>> +
>> +:c:func:`phy_get` just gets (or creates) a new :c:type:`phy` with the lanes
>> +described in the phandle. :c:func:`phy_init` is what actually reserves the
>> +lanes for use. Unlike some other drivers, when the phy is created, there is 
>> no
>> +default protocol. :c:func:`phy_set_mode ` must be called 
>> in
>> +order to set the protocol.
>> +
>> +Supporting SoCs
>> +---
>> +
>> +Each new SoC needs a :c:type:`struct lynx_conf `, containing the
>> +number of lanes in each device, the endianness of the device, and the helper
>> +functions to use when selecting protocol controllers. For example, the
>> +configuration for the LS1046A is::
> 
> Did you mean struct lynx_cfg as in below snippet?

Yes.

>> +
>> +static const struct lynx_cfg ls1046a_cfg = {
>> +.lanes = 4,
>> +.endian = REGMAP_ENDIAN_BIG,
>> +.mode_conflict = lynx_ls_mode_conflict,
>> +.mode_apply = lynx_ls_mode_apply,
>> +.mode_init = lynx_ls_mode_init,
>> +};
>> +
>> +The ``mode_`` functions will generally be common to all SoCs in a series 
>> (e.g.
>> +all Layerscape SoCs or all T-series SoCs).
>> +
>> +In addition, you will need to add a device node as documented in
>> +``Documentation/devicetree/bindings/phy/fsl,lynx-10g.yaml``. This lets the
>> +driver know which lanes are available to configure.
>> +
>> +Supporting Protocols
>> +
>> +
>> +Each protocol is a combination of values which must be programmed into the 
>> lane
>> +registers. To add a new protocol, first add it to :c:type:`enum 
>> lynx_protocol
>> +`. Add a new entry to `lynx_proto_params`, and populate the
>> +appropriate fields. Modify `lynx_lookup_proto` to map the :c:type:`enum
>> +phy_mode ` to :c:type:`enum lynx_protocol `. Update
>> +the ``mode_conflict``, ``mode_apply``, and ``mode_init`` helpers are 
>> updated to
>> +support your protocol.
>> +
> 
> These lynx_ keywords should be in double backticks to be consistent
> (rendered as inline code).
> 

OK

> Also, don't forget to add conjunctions:
> 
> "... Then modify ``lynx_lookup_proto`` ... Finally, update the ...
> helpers ..."

Personally, I like to be conservative with connectives when describing
sequences. I do agree that a "finally" would help here.

--Sean

>> +You may need to modify :c:func:`lynx_set_mode` in order to support your
>> +protocol. This can happen when you have added members to :c:type:`struct
>> +lynx_proto_params `. It can also happen if you have 
>> specific
>> +clocking requirements, or protocol-specific registers to program.
>> +
>> +Internal API Reference
>> +--
>> +
>> +.. kernel-doc:: drivers/phy/freescale/phy-fsl-lynx-10g.c
> 
> Otherwise LGTM, thanks.
> 


[PATCH] powerpc/32: fix syscall wrappers with 64-bit arguments

2022-10-31 Thread Andreas Schwab
With the introducion of syscall wrappers all wrappers for syscalls with
64-bit arguments must be handled specially, not only those that have
unaligned 64-bit arguments.  This left out the fallocate and
sync_file_range2 syscalls.

Fixes: 7e92e01b7245 ("powerpc: Provide syscall wrapper")
Fixes: e23750623835 ("powerpc/32: fix syscall wrappers with 64-bit arguments of 
unaligned register-pairs")
Signed-off-by: Andreas Schwab 
---
 arch/powerpc/include/asm/syscalls.h  |  7 +++
 arch/powerpc/kernel/sys_ppc32.c  | 13 -
 arch/powerpc/kernel/syscalls/syscall.tbl |  7 +--
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/syscalls.h 
b/arch/powerpc/include/asm/syscalls.h
index a1142496cd58..6d51b007b59e 100644
--- a/arch/powerpc/include/asm/syscalls.h
+++ b/arch/powerpc/include/asm/syscalls.h
@@ -104,6 +104,13 @@ long sys_ppc_ftruncate64(unsigned int fd, u32 reg4,
 unsigned long len1, unsigned long len2);
 long sys_ppc32_fadvise64(int fd, u32 unused, u32 offset1, u32 offset2,
 size_t len, int advice);
+long sys_ppc_sync_file_range2(int fd, unsigned int flags,
+ unsigned int offset1,
+ unsigned int offset2,
+ unsigned int nbytes1,
+ unsigned int nbytes2);
+long sys_ppc_fallocate(int fd, int mode, u32 offset1, u32 offset2,
+  u32 len1, u32 len2);
 #endif
 #ifdef CONFIG_COMPAT
 long compat_sys_mmap2(unsigned long addr, size_t len,
diff --git a/arch/powerpc/kernel/sys_ppc32.c b/arch/powerpc/kernel/sys_ppc32.c
index 1ab4a4d95aba..d451a8229223 100644
--- a/arch/powerpc/kernel/sys_ppc32.c
+++ b/arch/powerpc/kernel/sys_ppc32.c
@@ -112,7 +112,7 @@ PPC32_SYSCALL_DEFINE6(ppc32_fadvise64,
 advice);
 }
 
-COMPAT_SYSCALL_DEFINE6(ppc_sync_file_range2,
+PPC32_SYSCALL_DEFINE6(ppc_sync_file_range2,
   int, fd, unsigned int, flags,
   unsigned int, offset1, unsigned int, offset2,
   unsigned int, nbytes1, unsigned int, nbytes2)
@@ -122,3 +122,14 @@ COMPAT_SYSCALL_DEFINE6(ppc_sync_file_range2,
 
return ksys_sync_file_range(fd, offset, nbytes, flags);
 }
+
+#ifdef CONFIG_PPC32
+SYSCALL_DEFINE6(ppc_fallocate,
+   int, fd, int, mode,
+   u32, offset1, u32, offset2, u32, len1, u32, len2)
+{
+   return ksys_fallocate(fd, mode,
+ merge_64(offset1, offset2),
+ merge_64(len1, len2));
+}
+#endif
diff --git a/arch/powerpc/kernel/syscalls/syscall.tbl 
b/arch/powerpc/kernel/syscalls/syscall.tbl
index e9e0df4f9a61..a0be127475b1 100644
--- a/arch/powerpc/kernel/syscalls/syscall.tbl
+++ b/arch/powerpc/kernel/syscalls/syscall.tbl
@@ -394,8 +394,11 @@
 305common  signalfdsys_signalfd
compat_sys_signalfd
 306common  timerfd_create  sys_timerfd_create
 307common  eventfd sys_eventfd
-308common  sync_file_range2sys_sync_file_range2
compat_sys_ppc_sync_file_range2
-309nospu   fallocate   sys_fallocate   
compat_sys_fallocate
+30832  sync_file_range2sys_ppc_sync_file_range2
compat_sys_ppc_sync_file_range2
+30864  sync_file_range2sys_sync_file_range2
+308spu sync_file_range2sys_sync_file_range2
+30932  fallocate   sys_ppc_fallocate   
compat_sys_fallocate
+30964  fallocate   sys_fallocate
 310nospu   subpage_protsys_subpage_prot
 31132  timerfd_settime sys_timerfd_settime32
 31164  timerfd_settime sys_timerfd_settime
-- 
2.38.1

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."


RE: [PATCH net-next v7 08/10] powerpc: dts: t208x: Mark MAC1 and MAC2 as 10G

2022-10-31 Thread Camelia Alexandra Groza
> -Original Message-
> From: Sean Anderson 
> Sent: Friday, October 28, 2022 19:55
> To: Camelia Alexandra Groza ; Sean Anderson
> ; David S . Miller ;
> Jakub Kicinski ; Madalin Bucur
> ; net...@vger.kernel.org
> Cc: Eric Dumazet ; linuxppc-dev @ lists . ozlabs .
> org ; linux-arm-ker...@lists.infradead.org;
> linux-ker...@vger.kernel.org; Russell King ; Paolo
> Abeni ; Benjamin Herrenschmidt
> ; Krzysztof Kozlowski
> ; Leo Li ; Michael
> Ellerman ; Paul Mackerras ; Rob
> Herring ; devicet...@vger.kernel.org
> Subject: Re: [PATCH net-next v7 08/10] powerpc: dts: t208x: Mark MAC1 and
> MAC2 as 10G
> 
> On 10/28/22 12:30, Camelia Alexandra Groza wrote:
> >> -Original Message-
> >> From: Sean Anderson 
> >> Sent: Monday, October 17, 2022 23:23
> >> To: David S . Miller ; Jakub Kicinski
> >> ; Madalin Bucur ; Camelia
> >> Alexandra Groza ; net...@vger.kernel.org
> >> Cc: Eric Dumazet ; linuxppc-dev @ lists . ozlabs .
> >> org ; linux-arm-
> ker...@lists.infradead.org;
> >> linux-ker...@vger.kernel.org; Russell King ;
> Paolo
> >> Abeni ; Sean Anderson
> ;
> >> Benjamin Herrenschmidt ; Krzysztof
> Kozlowski
> >> ; Leo Li ;
> Michael
> >> Ellerman ; Paul Mackerras ;
> Rob
> >> Herring ; devicet...@vger.kernel.org
> >> Subject: [PATCH net-next v7 08/10] powerpc: dts: t208x: Mark MAC1 and
> >> MAC2 as 10G
> >>
> >> On the T208X SoCs, MAC1 and MAC2 support XGMII. Add some new MAC
> >> dtsi
> >> fragments, and mark the QMAN ports as 10G.
> >>
> >> Fixes: da414bb923d9 ("powerpc/mpc85xx: Add FSL QorIQ DPAA FMan
> >> support to the SoC device tree(s)")
> >> Signed-off-by: Sean Anderson 
> >> ---
> >>
> >> (no changes since v4)
> >>
> >> Changes in v4:
> >> - New
> >
> > Hi Sean,
> >
> > These changes prevent MAC2 from probing on T2080RDB due to
> insufficient FMan hardware resources.
> >
> > fsl-fman ffe40.fman: set_num_of_tasks: Requested num_of_tasks
> and extra tasks pool for fm0 exceed total num_of_tasks.
> > fsl_dpa: dpaa_eth_init_tx_port: fm_port_init failed
> > fsl_dpa: probe of dpaa-ethernet.5 failed with error -11
> >
> > The distribution of resources depends on the port type, and different
> FMan hardware revisions have different amounts of resources.
> >
> > The current distribution of resources can be reconsidered, but this change
> should be reverted for now.
> 
> OK, so this patch does two things:
> 
> @@ -37,12 +11,14 @@
>   cell-index = <0x8>;
>   compatible = "fsl,fman-v3-port-rx";
>   reg = <0x88000 0x1000>;
> + fsl,fman-10g-port;
>   };
> 
>   fman0_tx_0x28: port@a8000 {
>   cell-index = <0x28>;
>   compatible = "fsl,fman-v3-port-tx";
>   reg = <0xa8000 0x1000>;
> + fsl,fman-10g-port;
>   };
> 
>   ethernet@e {
> @@ -52,7 +28,7 @@
>   fsl,fman-ports = <_rx_0x08 _tx_0x28>;
>   ptp-timer = <_timer0>;
>   pcsphy-handle = <>, <>;
> - pcs-handle-names = "sgmii", "qsgmii";
> + pcs-handle-names = "sgmii", "xfi";
>   };
> 
>   mdio@e1000 {
> 
> First, it marks the ports as 10g. I believe this is what's causing the
> resource problems above.

That's right.

> Second, it removes support for QSGMII and adds
> support for XFI. This is a matter of correctness; these MACs really
> don't support QSGMII, and do support XFI.

Correct, these MACs don't support QSGMII on this SoC.

> As I understand it, you can
> run a 10g port at 1g speeds, it just won't perform as well. So I think a
> more minimal revert would be to delete the fsl,fman-10g-port properties
> in t2081si-post.dtsi.

Since these two new dtsi files are included by only one SoC, I don't see an
advantage in adding these properties and then deleting them. No other
users benefit from adding them in the first place. 

> That said, is 10g even being used on these ports? I included this patch
> in order to avoid breaking any existing users.

It is used, though less efficiently, with fewer FMan hardware resources.

Camelia

> --Sean
> 
> > Regards,
> > Camelia
> >
> >
> >>   .../boot/dts/fsl/qoriq-fman3-0-10g-2.dtsi | 44 +++
> >>   .../boot/dts/fsl/qoriq-fman3-0-10g-3.dtsi | 44 +++
> >>   arch/powerpc/boot/dts/fsl/t2081si-post.dtsi   |  4 +-
> >>   3 files changed, 90 insertions(+), 2 deletions(-)
> >>   create mode 100644 arch/powerpc/boot/dts/fsl/qoriq-fman3-0-10g-
> 2.dtsi
> >>   create mode 100644 arch/powerpc/boot/dts/fsl/qoriq-fman3-0-10g-
> 3.dtsi
> >>
> >> diff --git a/arch/powerpc/boot/dts/fsl/qoriq-fman3-0-10g-2.dtsi
> >> b/arch/powerpc/boot/dts/fsl/qoriq-fman3-0-10g-2.dtsi
> >> new file mode 100644
> >> index ..437dab3fc017
> >> --- /dev/null
> >> +++ b/arch/powerpc/boot/dts/fsl/qoriq-fman3-0-10g-2.dtsi
> >> @@ -0,0 +1,44 @@
> >> +// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-or-later
> >> +/*
> >> + * QorIQ FMan v3 10g port #2 device tree stub [ controller @ offset
> >> 0x40 ]
> >> + *
> 

[PATCH] asm-generic: compat: fix compat_arg_u64 and compat_arg_u64_dual

2022-10-31 Thread Andreas Schwab
The macros are defined backwards.

Fixes: 43d5de2b67d7 ("asm-generic: compat: Support BE for long long args in 
32-bit ABIs")
Signed-off-by: Andreas Schwab 
---
 include/asm-generic/compat.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/asm-generic/compat.h b/include/asm-generic/compat.h
index aeb257ad3d1a..8392caea398f 100644
--- a/include/asm-generic/compat.h
+++ b/include/asm-generic/compat.h
@@ -15,7 +15,7 @@
 #endif
 
 #ifndef compat_arg_u64
-#ifdef CONFIG_CPU_BIG_ENDIAN
+#ifndef CONFIG_CPU_BIG_ENDIAN
 #define compat_arg_u64(name)   u32  name##_lo, u32  name##_hi
 #define compat_arg_u64_dual(name)  u32, name##_lo, u32, name##_hi
 #else
-- 
2.38.1



[PATCH v5 2/2] powerpc/64: Add module check for ELF ABI version

2022-10-31 Thread Nicholas Piggin
Override the generic module ELF check to provide a check for the ELF ABI
version. This becomes important if we allow big-endian ELF ABI V2 builds
but it doesn't hurt to check now.

Cc: Jessica Yu 
Signed-off-by: Michael Ellerman 
[np: split patch, added changelog, adjust to Jessica's proposal]
Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/module.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/arch/powerpc/kernel/module.c b/arch/powerpc/kernel/module.c
index f6d6ae0a1692..d46bf9bfda26 100644
--- a/arch/powerpc/kernel/module.c
+++ b/arch/powerpc/kernel/module.c
@@ -19,6 +19,23 @@
 
 static LIST_HEAD(module_bug_list);
 
+#ifdef CONFIG_PPC64
+bool module_elf_check_arch(Elf_Ehdr *hdr)
+{
+   unsigned long abi_level = hdr->e_flags & 0x3;
+
+   if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2)) {
+   if (abi_level != 2)
+   return false;
+   } else {
+   if (abi_level >= 2)
+   return false;
+   }
+
+   return true;
+}
+#endif
+
 static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
const Elf_Shdr *sechdrs,
const char *name)
-- 
2.37.2



[PATCH v5 1/2] module: add module_elf_check_arch for module-specific checks

2022-10-31 Thread Nicholas Piggin
The elf_check_arch() function is also used to test compatibility of
usermode binaries. Kernel modules may have more specific requirements,
for example powerpc would like to test for ABI version compatibility.

Add a weak module_elf_check_arch() that defaults to true, and call it
from elf_validity_check().

Cc: Michael Ellerman 
Signed-off-by: Jessica Yu 
[np: added changelog, adjust name, rebase]
Signed-off-by: Nicholas Piggin 
---
 include/linux/moduleloader.h |  3 +++
 kernel/module/main.c | 10 ++
 2 files changed, 13 insertions(+)

diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
index 9e09d11ffe5b..7b4587a19189 100644
--- a/include/linux/moduleloader.h
+++ b/include/linux/moduleloader.h
@@ -13,6 +13,9 @@
  * must be implemented by each architecture.
  */
 
+/* arch may override to do additional checking of ELF header architecture */
+bool module_elf_check_arch(Elf_Ehdr *hdr);
+
 /* Adjust arch-specific sections.  Return 0 on success.  */
 int module_frob_arch_sections(Elf_Ehdr *hdr,
  Elf_Shdr *sechdrs,
diff --git a/kernel/module/main.c b/kernel/module/main.c
index d02d39c7174e..7b3f6fb0d428 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -1674,6 +1674,11 @@ static int elf_validity_check(struct load_info *info)
   info->hdr->e_machine);
goto no_exec;
}
+   if (!module_elf_check_arch(info->hdr)) {
+   pr_err("Invalid module architecture in ELF header: %u\n",
+  info->hdr->e_machine);
+   goto no_exec;
+   }
if (info->hdr->e_shentsize != sizeof(Elf_Shdr)) {
pr_err("Invalid ELF section header size\n");
goto no_exec;
@@ -2247,6 +2252,11 @@ static void flush_module_icache(const struct module *mod)
   (unsigned long)mod->core_layout.base + 
mod->core_layout.size);
 }
 
+bool __weak module_elf_check_arch(Elf_Ehdr *hdr)
+{
+   return true;
+}
+
 int __weak module_frob_arch_sections(Elf_Ehdr *hdr,
 Elf_Shdr *sechdrs,
 char *secstrings,
-- 
2.37.2



[PATCH v5 0/2] powerpc module arch checks

2022-10-31 Thread Nicholas Piggin
These slipped through the cracks. Picking them up again...

The story so far is that Jessica gave us the new scheme in patch 1,
now slightly rebased. Patch 2 implements the additional check
that powerpc wants which originally came from Michael, and has been
updated to the new approach.

This was previously attached to the ELFv2 build option for big-endian
kernels, but it can go ahead of that option.

Just checking everybody is still okay with the code and their SOBs,
and Luis if you would be okay for patch 1 to be merged via powerpc or
prefer to take it in the module tree (or maybe you object to the
code in the first place).

Thanks,
Nick

Nicholas Piggin (2):
  module: add module_elf_check_arch for module-specific checks
  powerpc/64: Add module check for ELF ABI version

 arch/powerpc/kernel/module.c | 17 +
 include/linux/moduleloader.h |  3 +++
 kernel/module/main.c | 10 ++
 3 files changed, 30 insertions(+)

-- 
2.37.2



Re: [PATCH v3 2/2] x86: Fix /proc/cpuinfo cpumask warning

2022-10-31 Thread Andrew Jones
On Mon, Oct 31, 2022 at 09:58:57AM +0100, Borislav Petkov wrote:
> On Mon, Oct 31, 2022 at 09:06:04AM +0100, Andrew Jones wrote:
> >  The valid cpumask range is [0, nr_cpu_ids) and cpumask_next() always
> >  returns a CPU ID greater than its input, which results in its input
> >  range being [-1, nr_cpu_ids - 1). Ensure showing CPU info avoids
> >  triggering error conditions in cpumask_next() by stopping its loop
> 
> What error conditions?
> 
> What would happen if @n is outside of the valid range?

Currently (after the revert of 78e5a3399421) with DEBUG_PER_CPU_MAPS we'll
get a warning splat when the cpu is outside the range [-1, nr_cpu_ids) and
cpumask_next() will call find_next_bit() with the input plus one anyway.
find_next_bit() doesn't explicity document what happens when an input is
outside the range, but it currently returns the bitmap size without any
side effects, which means cpumask_next() will return nr_cpu_ids.
show_cpuinfo() doesn't try to show anything in that case and stops its
loop, or, IOW, things work fine now with an input of nr_cpu_ids - 1. But,
show_cpuinfo() is just getting away with a violated cpumask_next()
contract, which 78e5a3399421 exposed. How about a new commit message like
this

  seq_read_iter() and cpuinfo's start and next seq operations implement a
  pattern like

n = cpumask_next(n - 1, mask);
show(n);
while (1) {
++n;
n = cpumask_next(n - 1, mask);
if (n >= nr_cpu_ids)
   break;
show(n);
}

  which loops until cpumask_next() identifies its CPU ID input is out of
  its valid range, [-1, nr_cpu_ids - 1). seq_read_iter() assumes the
  result of an invalid input is to return nr_cpu_ids or larger without any
  side effects, however the cpumask API does not document that and it
  reserves the right to change how it responds to invalid inputs. Ensure
  inputs from seq_read_iter() are valid.

Thanks,
drew


Re: [PATCH v3 2/2] x86: Fix /proc/cpuinfo cpumask warning

2022-10-31 Thread Borislav Petkov
On Mon, Oct 31, 2022 at 09:06:04AM +0100, Andrew Jones wrote:
>  The valid cpumask range is [0, nr_cpu_ids) and cpumask_next() always
>  returns a CPU ID greater than its input, which results in its input
>  range being [-1, nr_cpu_ids - 1). Ensure showing CPU info avoids
>  triggering error conditions in cpumask_next() by stopping its loop

What error conditions?

What would happen if @n is outside of the valid range?

-- 
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette


Re: [PATCH v3 2/2] x86: Fix /proc/cpuinfo cpumask warning

2022-10-31 Thread Andrew Jones
On Fri, Oct 28, 2022 at 06:06:41PM +0200, Borislav Petkov wrote:
> On Fri, Oct 28, 2022 at 10:13:28AM -0500, Yury Norov wrote:
> > Because it's related to bitmap API usage and has been revealed after
> > some work in bitmaps.
> 
> So first of all, that "fix" needs to explain what exactly it is fixing.
> Not "it fixes this and that warning" but why the input arg to
> cpumask_next() cannot be nr_cpu_ids because... yadda yadda...

Hi Boris,

I didn't realize you were still looking for improvements to the commit
message for this patch. I could add something like,

 The valid cpumask range is [0, nr_cpu_ids) and cpumask_next() always
 returns a CPU ID greater than its input, which results in its input
 range being [-1, nr_cpu_ids - 1). Ensure showing CPU info avoids
 triggering error conditions in cpumask_next() by stopping its loop
 over CPUs when its input would be invalid.

Thanks,
drew

> 
> > And because nobody else cares.
> 
> Why do you assume that?
> 
> > If you're willing to move it yourself please go ahead.
> 
> If it fixes a real issue, we are taking it. And pls note that x86
> patches go through the tip tree.
> 
> Thx.
> 
> -- 
> Regards/Gruss,
> Boris.
> 
> https://people.kernel.org/tglx/notes-about-netiquette


[PATCH] powerpc/pseries/eeh: Fix some kernel-doc warnings

2022-10-31 Thread Bo Liu
Fixes the following W=1 kernel build warning(s):
  arch/powerpc/platforms/pseries/eeh_pseries.c:163: warning: Function parameter 
or member 'config_addr' not described in 'pseries_eeh_phb_reset'
  arch/powerpc/platforms/pseries/eeh_pseries.c:163: warning: Excess function 
parameter 'config_adddr' description in 'pseries_eeh_phb_reset'
  arch/powerpc/platforms/pseries/eeh_pseries.c:198: warning: Function parameter 
or member 'config_addr' not described in 'pseries_eeh_phb_configure_bridge'
  arch/powerpc/platforms/pseries/eeh_pseries.c:198: warning: Excess function 
parameter 'config_adddr' description in 'pseries_eeh_phb_configure_bridge'

Signed-off-by: Bo Liu 
---
 arch/powerpc/platforms/pseries/eeh_pseries.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/eeh_pseries.c 
b/arch/powerpc/platforms/pseries/eeh_pseries.c
index 8e40ccac0f44..ea890037843c 100644
--- a/arch/powerpc/platforms/pseries/eeh_pseries.c
+++ b/arch/powerpc/platforms/pseries/eeh_pseries.c
@@ -154,7 +154,7 @@ static int pseries_eeh_get_pe_config_addr(struct pci_dn 
*pdn)
 /**
  * pseries_eeh_phb_reset - Reset the specified PHB
  * @phb: PCI controller
- * @config_adddr: the associated config address
+ * @config_addr: the associated config address
  * @option: reset option
  *
  * Reset the specified PHB/PE
@@ -188,7 +188,7 @@ static int pseries_eeh_phb_reset(struct pci_controller 
*phb, int config_addr, in
 /**
  * pseries_eeh_phb_configure_bridge - Configure PCI bridges in the indicated PE
  * @phb: PCI controller
- * @config_adddr: the associated config address
+ * @config_addr: the associated config address
  *
  * The function will be called to reconfigure the bridges included
  * in the specified PE so that the mulfunctional PE would be recovered
-- 
2.27.0



[RFC PATCH 19/19] powerpc/64: ELFv2 use reserved word in the stack frame for the regs marker

2022-10-31 Thread Nicholas Piggin
There are 4 unused bytes in the minimum frame in the ELFv2 ABI. At the
risk of causing a future ABI incompatibility, use this and save 16 bytes
from interrupt and switch frames.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/ptrace.h | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/include/asm/ptrace.h 
b/arch/powerpc/include/asm/ptrace.h
index ab41d47761c9..cc308dce7ace 100644
--- a/arch/powerpc/include/asm/ptrace.h
+++ b/arch/powerpc/include/asm/ptrace.h
@@ -121,11 +121,16 @@ struct pt_regs
 
 #ifdef CONFIG_PPC64_ELF_ABI_V2
 #define STACK_FRAME_MIN_SIZE   32
-#define STACK_USER_INT_FRAME_SIZE  (sizeof(struct pt_regs) + 
STACK_FRAME_MIN_SIZE + 16)
-#define STACK_INT_FRAME_REGS   (STACK_FRAME_MIN_SIZE + 16)
-#define STACK_INT_FRAME_MARKER STACK_FRAME_MIN_SIZE
-#define STACK_SWITCH_FRAME_SIZE (sizeof(struct pt_regs) + STACK_FRAME_MIN_SIZE 
+ 16)
-#define STACK_SWITCH_FRAME_REGS(STACK_FRAME_MIN_SIZE + 16)
+#define STACK_USER_INT_FRAME_SIZE  (sizeof(struct pt_regs) + 
STACK_FRAME_MIN_SIZE)
+#define STACK_INT_FRAME_REGS   STACK_FRAME_MIN_SIZE
+#define STACK_INT_FRAME_MARKER 12  /* Reserved word next to CR save word */
+
+/*
+ * The switch frame has to match the format of the int frames up to pt_regs,
+ * because fields are accessed with the int frame pt_regs offsets.
+ */
+#define STACK_SWITCH_FRAME_SIZE (sizeof(struct pt_regs) + STACK_FRAME_MIN_SIZE)
+#define STACK_SWITCH_FRAME_REGSSTACK_FRAME_MIN_SIZE
 #else
 /*
  * The ELFv1 ABI specifies 48 bytes plus a minimum 64 byte parameter save
-- 
2.37.2



[RFC PATCH 18/19] powerpc: change stack marker memory operations to 32-bit

2022-10-31 Thread Nicholas Piggin
The marker is a 32-bit constant across all platforms now, so use 32-bit
memory accesses.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/ptrace.h| 1 -
 arch/powerpc/kernel/exceptions-64e.S | 2 +-
 arch/powerpc/kernel/exceptions-64s.S | 2 +-
 arch/powerpc/kernel/interrupt_64.S   | 6 +++---
 arch/powerpc/kernel/process.c| 6 +++---
 arch/powerpc/kernel/stacktrace.c | 2 +-
 arch/powerpc/perf/callchain.c| 2 +-
 7 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/include/asm/ptrace.h 
b/arch/powerpc/include/asm/ptrace.h
index a53c580388e2..ab41d47761c9 100644
--- a/arch/powerpc/include/asm/ptrace.h
+++ b/arch/powerpc/include/asm/ptrace.h
@@ -162,7 +162,6 @@ struct pt_regs
 #endif /* __powerpc64__ */
 
 #define STACK_INT_FRAME_SIZE   (KERNEL_REDZONE_SIZE + 
STACK_USER_INT_FRAME_SIZE)
-#define STACK_INT_FRAME_MARKER_LONGS   (STACK_INT_FRAME_MARKER/sizeof(long))
 
 #ifndef __ASSEMBLY__
 #include 
diff --git a/arch/powerpc/kernel/exceptions-64e.S 
b/arch/powerpc/kernel/exceptions-64e.S
index d74c2a53af13..86cf656c6777 100644
--- a/arch/powerpc/kernel/exceptions-64e.S
+++ b/arch/powerpc/kernel/exceptions-64e.S
@@ -391,7 +391,7 @@ exc_##n##_common:   
\
std r10,_CCR(r1);   /* store orig CR in stackframe */   \
std r9,GPR1(r1);/* store stack frame back link */   \
std r11,SOFTE(r1);  /* and save it to stackframe */ \
-   std r12,STACK_INT_FRAME_MARKER(r1); /* mark the frame */\
+   stw r12,STACK_INT_FRAME_MARKER(r1); /* mark the frame */\
std r3,_TRAP(r1);   /* set trap number  */  \
std r0,RESULT(r1);  /* clear regs->result */\
SAVE_NVGPRS(r1);
diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index 39f08ec56126..85bbdfa7e4d3 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -591,7 +591,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
li  r10,0
LOAD_REG_IMMEDIATE(r11, STACK_FRAME_REGS_MARKER)
std r10,RESULT(r1)  /* clear regs->result   */
-   std r11,STACK_INT_FRAME_MARKER(r1) /* mark the frame*/
+   stw r11,STACK_INT_FRAME_MARKER(r1) /* mark the frame*/
 .endm
 
 /*
diff --git a/arch/powerpc/kernel/interrupt_64.S 
b/arch/powerpc/kernel/interrupt_64.S
index 2306b979e71f..ee8cfe17ca37 100644
--- a/arch/powerpc/kernel/interrupt_64.S
+++ b/arch/powerpc/kernel/interrupt_64.S
@@ -78,7 +78,7 @@ _ASM_NOKPROBE_SYMBOL(system_call_vectored_\name)
std r12,_CCR(r1)
std r3,ORIG_GPR3(r1)
LOAD_REG_IMMEDIATE(r11, STACK_FRAME_REGS_MARKER)
-   std r11,STACK_INT_FRAME_MARKER(r1)  /* "regs" marker */
+   stw r11,STACK_INT_FRAME_MARKER(r1)  /* "regs" marker */
/* Calling convention has r3 = regs, r4 = orig r0 */
addir3,r1,STACK_INT_FRAME_REGS
mr  r4,r0
@@ -251,7 +251,7 @@ END_BTB_FLUSH_SECTION
std r12,_CCR(r1)
std r3,ORIG_GPR3(r1)
LOAD_REG_IMMEDIATE(r11, STACK_FRAME_REGS_MARKER)
-   std r11,STACK_INT_FRAME_MARKER(r1)  /* "regs" marker */
+   stw r11,STACK_INT_FRAME_MARKER(r1)  /* "regs" marker */
/* Calling convention has r3 = regs, r4 = orig r0 */
addir3,r1,STACK_INT_FRAME_REGS
mr  r4,r0
@@ -628,7 +628,7 @@ ALT_FTR_SECTION_END_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS)
 * Leaving a stale STACK_FRAME_REGS_MARKER on the stack can confuse
 * the reliable stack unwinder later on. Clear it.
 */
-   std r0,STACK_INT_FRAME_MARKER(r1)
+   stw r0,STACK_INT_FRAME_MARKER(r1)
 
REST_GPRS(2, 5, r1)
 
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 20fdb84759f0..e447bf02f996 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1728,7 +1728,7 @@ int copy_thread(struct task_struct *p, const struct 
kernel_clone_args *args)
 
/* Create initial stack frame. */
sp -= STACK_USER_INT_FRAME_SIZE;
-   *(unsigned long *)(sp + STACK_INT_FRAME_MARKER) = 
STACK_FRAME_REGS_MARKER;
+   *(u32 *)(sp + STACK_INT_FRAME_MARKER) = STACK_FRAME_REGS_MARKER;
 
/* Copy registers */
childregs = (struct pt_regs *)(sp + STACK_INT_FRAME_REGS);
@@ -2246,8 +2246,8 @@ void __no_sanitize_address show_stack(struct task_struct 
*tsk,
 * could hold a pt_regs, if that does not fit then it can't
 * have regs.
 */
-   if (validate_sp_size(sp, tsk, STACK_SWITCH_FRAME_SIZE)
-   && stack[STACK_INT_FRAME_MARKER_LONGS] == 
STACK_FRAME_REGS_MARKER) {
+   if (validate_sp_size(sp, tsk, STACK_SWITCH_FRAME_SIZE) &&
+   *(u32 

[RFC PATCH 17/19] powerpc: remove STACK_FRAME_OVERHEAD

2022-10-31 Thread Nicholas Piggin
This is equal to STACK_FRAME_MIN_SIZE on 32-bit and 64-bit ELFv1, and no
longer used in 64-bit ELFv2, so replace it with that constant.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/ptrace.h | 24 +++-
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/arch/powerpc/include/asm/ptrace.h 
b/arch/powerpc/include/asm/ptrace.h
index a9dfce62a5eb..a53c580388e2 100644
--- a/arch/powerpc/include/asm/ptrace.h
+++ b/arch/powerpc/include/asm/ptrace.h
@@ -117,7 +117,6 @@ struct pt_regs
 #define USER_REDZONE_SIZE  512
 #define KERNEL_REDZONE_SIZE288
 
-#define STACK_FRAME_OVERHEAD   112 /* size of minimum stack frame */
 #define STACK_FRAME_LR_SAVE2   /* Location of LR in stack frame */
 
 #ifdef CONFIG_PPC64_ELF_ABI_V2
@@ -134,11 +133,11 @@ struct pt_regs
  * so the second from last one of those is used for the frame marker.
  */
 #define STACK_FRAME_MIN_SIZE   112
-#define STACK_USER_INT_FRAME_SIZE  (sizeof(struct pt_regs) + 
STACK_FRAME_OVERHEAD)
-#define STACK_INT_FRAME_REGS   STACK_FRAME_OVERHEAD
-#define STACK_INT_FRAME_MARKER (STACK_FRAME_OVERHEAD - 16)
-#define STACK_SWITCH_FRAME_SIZE(sizeof(struct pt_regs) + 
STACK_FRAME_OVERHEAD)
-#define STACK_SWITCH_FRAME_REGSSTACK_FRAME_OVERHEAD
+#define STACK_USER_INT_FRAME_SIZE  (sizeof(struct pt_regs) + 
STACK_FRAME_MIN_SIZE)
+#define STACK_INT_FRAME_REGS   STACK_FRAME_MIN_SIZE
+#define STACK_INT_FRAME_MARKER (STACK_FRAME_MIN_SIZE - 16)
+#define STACK_SWITCH_FRAME_SIZE(sizeof(struct pt_regs) + 
STACK_FRAME_MIN_SIZE)
+#define STACK_SWITCH_FRAME_REGSSTACK_FRAME_MIN_SIZE
 #endif
 
 /* Size of dummy stack frame allocated when calling signal handler. */
@@ -149,14 +148,13 @@ struct pt_regs
 
 #define USER_REDZONE_SIZE  0
 #define KERNEL_REDZONE_SIZE0
-#define STACK_FRAME_OVERHEAD   16  /* size of minimum stack frame */
+#define STACK_FRAME_MIN_SIZE   16
 #define STACK_FRAME_LR_SAVE1   /* Location of LR in stack frame */
-#define STACK_USER_INT_FRAME_SIZE  (sizeof(struct pt_regs) + 
STACK_FRAME_OVERHEAD)
-#define STACK_INT_FRAME_REGS   STACK_FRAME_OVERHEAD
-#define STACK_INT_FRAME_MARKER (STACK_FRAME_OVERHEAD - 8)
-#define STACK_FRAME_MIN_SIZE   STACK_FRAME_OVERHEAD
-#define STACK_SWITCH_FRAME_SIZE(sizeof(struct pt_regs) + 
STACK_FRAME_OVERHEAD)
-#define STACK_SWITCH_FRAME_REGSSTACK_FRAME_OVERHEAD
+#define STACK_USER_INT_FRAME_SIZE  (sizeof(struct pt_regs) + 
STACK_FRAME_MIN_SIZE)
+#define STACK_INT_FRAME_REGS   STACK_FRAME_MIN_SIZE
+#define STACK_INT_FRAME_MARKER (STACK_FRAME_MIN_SIZE - 8)
+#define STACK_SWITCH_FRAME_SIZE(sizeof(struct pt_regs) + 
STACK_FRAME_MIN_SIZE)
+#define STACK_SWITCH_FRAME_REGSSTACK_FRAME_MIN_SIZE
 
 /* Size of stack frame allocated when calling signal handler. */
 #define __SIGNAL_FRAMESIZE 64
-- 
2.37.2



[RFC PATCH 16/19] powerpc/64: ELFv2 use minimal stack frames in int and switch frame sizes

2022-10-31 Thread Nicholas Piggin
This requires an extra 16 bytes beyond the minimum frame size for the
aligned regs marker for the int frame. The switch frame needs to match
that because they share some offset definitions.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/ptrace.h | 21 +++--
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/ptrace.h 
b/arch/powerpc/include/asm/ptrace.h
index 412ef0749775..a9dfce62a5eb 100644
--- a/arch/powerpc/include/asm/ptrace.h
+++ b/arch/powerpc/include/asm/ptrace.h
@@ -96,7 +96,6 @@ struct pt_regs
 };
 #endif
 
-
 // Always displays as "REGS" in memory dumps
 #ifdef CONFIG_CPU_BIG_ENDIAN
 #define STACK_FRAME_REGS_MARKERASM_CONST(0x52454753)
@@ -120,16 +119,26 @@ struct pt_regs
 
 #define STACK_FRAME_OVERHEAD   112 /* size of minimum stack frame */
 #define STACK_FRAME_LR_SAVE2   /* Location of LR in stack frame */
+
+#ifdef CONFIG_PPC64_ELF_ABI_V2
+#define STACK_FRAME_MIN_SIZE   32
+#define STACK_USER_INT_FRAME_SIZE  (sizeof(struct pt_regs) + 
STACK_FRAME_MIN_SIZE + 16)
+#define STACK_INT_FRAME_REGS   (STACK_FRAME_MIN_SIZE + 16)
+#define STACK_INT_FRAME_MARKER STACK_FRAME_MIN_SIZE
+#define STACK_SWITCH_FRAME_SIZE (sizeof(struct pt_regs) + STACK_FRAME_MIN_SIZE 
+ 16)
+#define STACK_SWITCH_FRAME_REGS(STACK_FRAME_MIN_SIZE + 16)
+#else
+/*
+ * The ELFv1 ABI specifies 48 bytes plus a minimum 64 byte parameter save
+ * area. This parameter area is not used by calls to C from interrupt entry,
+ * so the second from last one of those is used for the frame marker.
+ */
+#define STACK_FRAME_MIN_SIZE   112
 #define STACK_USER_INT_FRAME_SIZE  (sizeof(struct pt_regs) + 
STACK_FRAME_OVERHEAD)
 #define STACK_INT_FRAME_REGS   STACK_FRAME_OVERHEAD
 #define STACK_INT_FRAME_MARKER (STACK_FRAME_OVERHEAD - 16)
 #define STACK_SWITCH_FRAME_SIZE(sizeof(struct pt_regs) + 
STACK_FRAME_OVERHEAD)
 #define STACK_SWITCH_FRAME_REGSSTACK_FRAME_OVERHEAD
-
-#ifdef CONFIG_PPC64_ELF_ABI_V2
-#define STACK_FRAME_MIN_SIZE   32
-#else
-#define STACK_FRAME_MIN_SIZE   STACK_FRAME_OVERHEAD
 #endif
 
 /* Size of dummy stack frame allocated when calling signal handler. */
-- 
2.37.2



[RFC PATCH 15/19] powerpc: allow minimum sized kernel stack frames

2022-10-31 Thread Nicholas Piggin
This affects only 64-bit ELFv2 kernels, and reduces the minimum
asm-created stack frame size from 112 to 32 byte on those kernels.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/head_40x.S   | 2 +-
 arch/powerpc/kernel/head_44x.S   | 6 +++---
 arch/powerpc/kernel/head_64.S| 6 +++---
 arch/powerpc/kernel/head_85xx.S  | 4 ++--
 arch/powerpc/kernel/head_8xx.S   | 2 +-
 arch/powerpc/kernel/head_book3s_32.S | 4 ++--
 arch/powerpc/kernel/irq.c| 4 ++--
 arch/powerpc/kernel/misc_32.S| 2 +-
 arch/powerpc/kernel/misc_64.S| 4 ++--
 arch/powerpc/kernel/process.c| 2 +-
 arch/powerpc/kernel/smp.c| 2 +-
 arch/powerpc/kernel/stacktrace.c | 2 +-
 12 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/arch/powerpc/kernel/head_40x.S b/arch/powerpc/kernel/head_40x.S
index 088f500896c7..918547b93b5e 100644
--- a/arch/powerpc/kernel/head_40x.S
+++ b/arch/powerpc/kernel/head_40x.S
@@ -602,7 +602,7 @@ start_here:
lis r1,init_thread_union@ha
addir1,r1,init_thread_union@l
li  r0,0
-   stwur0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
+   stwur0,THREAD_SIZE-STACK_FRAME_MIN_SIZE(r1)
 
bl  early_init  /* We have to do this with MMU on */
 
diff --git a/arch/powerpc/kernel/head_44x.S b/arch/powerpc/kernel/head_44x.S
index f15cb9fdb692..63a85c16fef4 100644
--- a/arch/powerpc/kernel/head_44x.S
+++ b/arch/powerpc/kernel/head_44x.S
@@ -109,7 +109,7 @@ _GLOBAL(_start);
lis r1,init_thread_union@h
ori r1,r1,init_thread_union@l
li  r0,0
-   stwur0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
+   stwur0,THREAD_SIZE-STACK_FRAME_MIN_SIZE(r1)
 
bl  early_init
 
@@ -1012,7 +1012,7 @@ _GLOBAL(start_secondary_47x)
 */
lis r1,temp_boot_stack@h
ori r1,r1,temp_boot_stack@l
-   addir1,r1,1024-STACK_FRAME_OVERHEAD
+   addir1,r1,1024-STACK_FRAME_MIN_SIZE
li  r0,0
stw r0,0(r1)
bl  mmu_init_secondary
@@ -1025,7 +1025,7 @@ _GLOBAL(start_secondary_47x)
lwz r1,TASK_STACK(r2)
 
/* Current stack pointer */
-   addir1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
+   addir1,r1,THREAD_SIZE-STACK_FRAME_MIN_SIZE
li  r0,0
stw r0,0(r1)
 
diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S
index dedcc6fe2263..b513d13bf79e 100644
--- a/arch/powerpc/kernel/head_64.S
+++ b/arch/powerpc/kernel/head_64.S
@@ -424,7 +424,7 @@ generic_secondary_common_init:
 
/* Create a temp kernel stack for use before relocation is on.  */
ld  r1,PACAEMERGSP(r13)
-   subir1,r1,STACK_FRAME_OVERHEAD
+   subir1,r1,STACK_FRAME_MIN_SIZE
 
/* See if we need to call a cpu state restore handler */
LOAD_REG_ADDR(r23, cur_cpu_spec)
@@ -780,7 +780,7 @@ _GLOBAL(pmac_secondary_start)
 
/* Create a temp kernel stack for use before relocation is on.  */
ld  r1,PACAEMERGSP(r13)
-   subir1,r1,STACK_FRAME_OVERHEAD
+   subir1,r1,STACK_FRAME_MIN_SIZE
 
b   __secondary_start
 
@@ -958,7 +958,7 @@ start_here_multiplatform:
LOAD_REG_IMMEDIATE(r1,THREAD_SIZE)
add r1,r3,r1
li  r0,0
-   stdur0,-STACK_FRAME_OVERHEAD(r1)
+   stdur0,-STACK_FRAME_MIN_SIZE(r1)
 
/*
 * Do very early kernel initializations, including initial hash table
diff --git a/arch/powerpc/kernel/head_85xx.S b/arch/powerpc/kernel/head_85xx.S
index 24f39abf81df..d9bd377dec91 100644
--- a/arch/powerpc/kernel/head_85xx.S
+++ b/arch/powerpc/kernel/head_85xx.S
@@ -229,7 +229,7 @@ set_ivor:
lis r1,init_thread_union@h
ori r1,r1,init_thread_union@l
li  r0,0
-   stwur0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
+   stwur0,THREAD_SIZE-STACK_FRAME_MIN_SIZE(r1)
 
 #ifdef CONFIG_SMP
stw r24, TASK_CPU(r2)
@@ -1044,7 +1044,7 @@ __secondary_start:
lwz r1,TASK_STACK(r2)
 
/* stack */
-   addir1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
+   addir1,r1,THREAD_SIZE-STACK_FRAME_MIN_SIZE
li  r0,0
stw r0,0(r1)
 
diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
index 0b05f2be66b9..cf546d0e5c40 100644
--- a/arch/powerpc/kernel/head_8xx.S
+++ b/arch/powerpc/kernel/head_8xx.S
@@ -537,7 +537,7 @@ start_here:
ori r0, r0, STACK_END_MAGIC@l
stw r0, 0(r1)
li  r0,0
-   stwur0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
+   stwur0,THREAD_SIZE-STACK_FRAME_MIN_SIZE(r1)
 
lis r6, swapper_pg_dir@ha
tophys(r6,r6)
diff --git a/arch/powerpc/kernel/head_book3s_32.S 
b/arch/powerpc/kernel/head_book3s_32.S
index 519b60695167..40854d092dd3 100644
--- a/arch/powerpc/kernel/head_book3s_32.S
+++ b/arch/powerpc/kernel/head_book3s_32.S
@@ -840,7 +840,7 @@ __secondary_start:
 

[RFC PATCH 14/19] powerpc: split validate_sp into two functions

2022-10-31 Thread Nicholas Piggin
Most callers just want to validate an arbitrary kernel stack pointer,
some need a particular size. Make the size case the exceptional one
with an extra function.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/processor.h | 15 ---
 arch/powerpc/kernel/process.c| 23 ++-
 arch/powerpc/kernel/stacktrace.c |  2 +-
 arch/powerpc/perf/callchain.c|  6 +++---
 4 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/include/asm/processor.h 
b/arch/powerpc/include/asm/processor.h
index 631802999d59..e96c9b8c2a60 100644
--- a/arch/powerpc/include/asm/processor.h
+++ b/arch/powerpc/include/asm/processor.h
@@ -374,9 +374,18 @@ static inline unsigned long __pack_fe01(unsigned int 
fpmode)
 
 #endif
 
-/* Check that a certain kernel stack pointer is valid in task_struct p */
-int validate_sp(unsigned long sp, struct task_struct *p,
-   unsigned long nbytes);
+/*
+ * Check that a certain kernel stack pointer is a valid (minimum sized)
+ * stack frame in task_struct p.
+ */
+int validate_sp(unsigned long sp, struct task_struct *p);
+
+/*
+ * validate the stack frame of a particular minimum size, used for when we are
+ * looking at a certain object in the stack beyond the minimum.
+ */
+int validate_sp_size(unsigned long sp, struct task_struct *p,
+unsigned long nbytes);
 
 /*
  * Prefetch macros.
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 6cb3982a11ef..b5defea32e75 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -2128,9 +2128,12 @@ static inline int valid_emergency_stack(unsigned long 
sp, struct task_struct *p,
return 0;
 }
 
-
-int validate_sp(unsigned long sp, struct task_struct *p,
-  unsigned long nbytes)
+/*
+ * validate the stack frame of a particular minimum size, used for when we are
+ * looking at a certain object in the stack beyond the minimum.
+ */
+int validate_sp_size(unsigned long sp, struct task_struct *p,
+unsigned long nbytes)
 {
unsigned long stack_page = (unsigned long)task_stack_page(p);
 
@@ -2146,7 +2149,10 @@ int validate_sp(unsigned long sp, struct task_struct *p,
return valid_emergency_stack(sp, p, nbytes);
 }
 
-EXPORT_SYMBOL(validate_sp);
+int validate_sp(unsigned long sp, struct task_struct *p)
+{
+   return validate_sp(sp, p, STACK_FRAME_OVERHEAD);
+}
 
 static unsigned long ___get_wchan(struct task_struct *p)
 {
@@ -2154,13 +2160,12 @@ static unsigned long ___get_wchan(struct task_struct *p)
int count = 0;
 
sp = p->thread.ksp;
-   if (!validate_sp(sp, p, STACK_FRAME_OVERHEAD))
+   if (!validate_sp(sp, p))
return 0;
 
do {
sp = READ_ONCE_NOCHECK(*(unsigned long *)sp);
-   if (!validate_sp(sp, p, STACK_FRAME_OVERHEAD) ||
-   task_is_running(p))
+   if (!validate_sp(sp, p) || task_is_running(p))
return 0;
if (count > 0) {
ip = READ_ONCE_NOCHECK(((unsigned long 
*)sp)[STACK_FRAME_LR_SAVE]);
@@ -2214,7 +2219,7 @@ void __no_sanitize_address show_stack(struct task_struct 
*tsk,
lr = 0;
printk("%sCall Trace:\n", loglvl);
do {
-   if (!validate_sp(sp, tsk, STACK_FRAME_OVERHEAD))
+   if (!validate_sp(sp, tsk))
break;
 
stack = (unsigned long *) sp;
@@ -2241,7 +2246,7 @@ void __no_sanitize_address show_stack(struct task_struct 
*tsk,
 * could hold a pt_regs, if that does not fit then it can't
 * have regs.
 */
-   if (validate_sp(sp, tsk, STACK_SWITCH_FRAME_SIZE)
+   if (validate_sp_size(sp, tsk, STACK_SWITCH_FRAME_SIZE)
&& stack[STACK_INT_FRAME_MARKER_LONGS] == 
STACK_FRAME_REGS_MARKER) {
struct pt_regs *regs = (struct pt_regs *)
(sp + STACK_INT_FRAME_REGS);
diff --git a/arch/powerpc/kernel/stacktrace.c b/arch/powerpc/kernel/stacktrace.c
index 453ac317a6cf..1dbbf30f265e 100644
--- a/arch/powerpc/kernel/stacktrace.c
+++ b/arch/powerpc/kernel/stacktrace.c
@@ -43,7 +43,7 @@ void __no_sanitize_address 
arch_stack_walk(stack_trace_consume_fn consume_entry,
unsigned long *stack = (unsigned long *) sp;
unsigned long newsp, ip;
 
-   if (!validate_sp(sp, task, STACK_FRAME_OVERHEAD))
+   if (!validate_sp(sp, task))
return;
 
newsp = stack[0];
diff --git a/arch/powerpc/perf/callchain.c b/arch/powerpc/perf/callchain.c
index b01497ed5173..6b4434dd0ff3 100644
--- a/arch/powerpc/perf/callchain.c
+++ b/arch/powerpc/perf/callchain.c
@@ -27,7 +27,7 @@ static int valid_next_sp(unsigned long sp, unsigned long 
prev_sp)
 {
if (sp & 0xf)

[RFC PATCH 13/19] powerpc: copy_thread add a back chain to the switch stack frame

2022-10-31 Thread Nicholas Piggin
Stack unwinders need LR and the back chain as a minimum. The switch
stack uses regs->nip for its return pointer rather than lrsave, so
that was not filled in, and neither was the back chain.

With this and the previous change, a stack trace in the switch or
interrupt stack goes from looking like this:

  Oops: Exception in kernel mode, sig: 5 [#1]
  LE PAGE_SIZE=64K MMU=Radix SMP NR_CPUS=2048 NUMA pSeries
  Modules linked in:
  CPU: 3 PID: 90 Comm: systemd Not tainted
  NIP:  c0011060 LR: c0010f68 CTR: 7fff
  [ ... regs ... ]
  NIP [c0011060] _switch+0x160/0x17c
  LR [c0010f68] _switch+0x68/0x17c
  Call Trace:

To this:

  Oops: Exception in kernel mode, sig: 5 [#1]
  LE PAGE_SIZE=64K MMU=Radix SMP NR_CPUS=2048 NUMA pSeries
  CPU: 0 PID: 93 Comm: systemd Not tainted
  NIP:  c0011060 LR: c0010f68 CTR: 7fff
  [ ... regs ... ]
  NIP [c0011060] _switch+0x160/0x17c
  LR [c0010f68] _switch+0x68/0x17c
  Call Trace:
  [c5a93e10] [c000cdbc] ret_from_fork_scv+0x0/0x54
  --- interrupt: 3000 at 0x7fffa72f56d8
  NIP:  7fffa72f56d8 LR:  CTR: 
  [ ... regs ... ]
  NIP [7fffa72f56d8] 0x7fffa72f56d8
  LR [] 0x0
  --- interrupt: 3000

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 27956831fa5d..6cb3982a11ef 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1781,7 +1781,9 @@ int copy_thread(struct task_struct *p, const struct 
kernel_clone_args *args)
 * do some house keeping and then return from the fork or clone
 * system call, using the stack frame created above.
 */
+   ((unsigned long *)sp)[STACK_FRAME_LR_SAVE] = (unsigned long)f;
sp -= STACK_SWITCH_FRAME_SIZE;
+   ((unsigned long *)sp)[0] = sp + STACK_SWITCH_FRAME_SIZE;
kregs = (struct pt_regs *)(sp + STACK_SWITCH_FRAME_REGS);
p->thread.ksp = sp;
 
-- 
2.37.2



[RFC PATCH 12/19] powerpc: copy_thread fill in interrupt frame marker and back chain

2022-10-31 Thread Nicholas Piggin
Backtraces will not recognise the fork system call interrupt without
the regs marker. And at least perf starts unwinding the user stack
from gpr[1] directly, but regular interrupt entry from userspace creates
the back chain to the user stack, so do this too, to be consistent.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/process.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index a097879b0474..27956831fa5d 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1728,12 +1728,13 @@ int copy_thread(struct task_struct *p, const struct 
kernel_clone_args *args)
 
/* Create initial stack frame. */
sp -= STACK_USER_INT_FRAME_SIZE;
-   ((unsigned long *)sp)[0] = 0;
+   *(unsigned long *)(sp + STACK_INT_FRAME_MARKER) = 
STACK_FRAME_REGS_MARKER;
 
/* Copy registers */
childregs = (struct pt_regs *)(sp + STACK_INT_FRAME_REGS);
if (unlikely(args->fn)) {
/* kernel thread */
+   ((unsigned long *)sp)[0] = 0;
memset(childregs, 0, sizeof(struct pt_regs));
childregs->gpr[1] = sp + STACK_USER_INT_FRAME_SIZE;
/* function */
@@ -1753,6 +1754,7 @@ int copy_thread(struct task_struct *p, const struct 
kernel_clone_args *args)
*childregs = *regs;
if (usp)
childregs->gpr[1] = usp;
+   ((unsigned long *)sp)[0] = childregs->gpr[1];
p->thread.regs = childregs;
/* 64s sets this in ret_from_fork */
if (!IS_ENABLED(CONFIG_PPC_BOOK3S_64))
-- 
2.37.2



[RFC PATCH 11/19] powerpc: add a define for the switch frame size and regs offset

2022-10-31 Thread Nicholas Piggin
This is open-coded in process.c, ppc32 uses a different define with the
same value, and the C definition is name differently which makes it an
extra indirection to grep for.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/ptrace.h |  6 --
 arch/powerpc/kernel/asm-offsets.c |  2 +-
 arch/powerpc/kernel/entry_32.S|  6 +++---
 arch/powerpc/kernel/process.c | 12 
 4 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/arch/powerpc/include/asm/ptrace.h 
b/arch/powerpc/include/asm/ptrace.h
index 705ce26ae887..412ef0749775 100644
--- a/arch/powerpc/include/asm/ptrace.h
+++ b/arch/powerpc/include/asm/ptrace.h
@@ -97,8 +97,6 @@ struct pt_regs
 #endif
 
 
-#define STACK_FRAME_WITH_PT_REGS (STACK_FRAME_OVERHEAD + sizeof(struct 
pt_regs))
-
 // Always displays as "REGS" in memory dumps
 #ifdef CONFIG_CPU_BIG_ENDIAN
 #define STACK_FRAME_REGS_MARKERASM_CONST(0x52454753)
@@ -125,6 +123,8 @@ struct pt_regs
 #define STACK_USER_INT_FRAME_SIZE  (sizeof(struct pt_regs) + 
STACK_FRAME_OVERHEAD)
 #define STACK_INT_FRAME_REGS   STACK_FRAME_OVERHEAD
 #define STACK_INT_FRAME_MARKER (STACK_FRAME_OVERHEAD - 16)
+#define STACK_SWITCH_FRAME_SIZE(sizeof(struct pt_regs) + 
STACK_FRAME_OVERHEAD)
+#define STACK_SWITCH_FRAME_REGSSTACK_FRAME_OVERHEAD
 
 #ifdef CONFIG_PPC64_ELF_ABI_V2
 #define STACK_FRAME_MIN_SIZE   32
@@ -146,6 +146,8 @@ struct pt_regs
 #define STACK_INT_FRAME_REGS   STACK_FRAME_OVERHEAD
 #define STACK_INT_FRAME_MARKER (STACK_FRAME_OVERHEAD - 8)
 #define STACK_FRAME_MIN_SIZE   STACK_FRAME_OVERHEAD
+#define STACK_SWITCH_FRAME_SIZE(sizeof(struct pt_regs) + 
STACK_FRAME_OVERHEAD)
+#define STACK_SWITCH_FRAME_REGSSTACK_FRAME_OVERHEAD
 
 /* Size of stack frame allocated when calling signal handler. */
 #define __SIGNAL_FRAMESIZE 64
diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index db5e66c1d031..f7dff906c24b 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -260,7 +260,7 @@ int main(void)
 
/* Interrupt register frame */
DEFINE(INT_FRAME_SIZE, STACK_INT_FRAME_SIZE);
-   DEFINE(SWITCH_FRAME_SIZE, STACK_FRAME_WITH_PT_REGS);
+   DEFINE(SWITCH_FRAME_SIZE, STACK_SWITCH_FRAME_SIZE);
STACK_PT_REGS_OFFSET(GPR0, gpr[0]);
STACK_PT_REGS_OFFSET(GPR1, gpr[1]);
STACK_PT_REGS_OFFSET(GPR2, gpr[2]);
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 2f61b7d3677c..6e99ec10be89 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -215,9 +215,9 @@ ret_from_kernel_thread:
  * in arch/ppc/kernel/process.c
  */
 _GLOBAL(_switch)
-   stwur1,-INT_FRAME_SIZE(r1)
+   stwur1,-SWITCH_FRAME_SIZE(r1)
mflrr0
-   stw r0,INT_FRAME_SIZE+4(r1)
+   stw r0,SWITCH_FRAME_SIZE+4(r1)
/* r3-r12 are caller saved -- Cort */
SAVE_NVGPRS(r1)
stw r0,_NIP(r1) /* Return to switch caller */
@@ -248,7 +248,7 @@ _GLOBAL(_switch)
 
lwz r4,_NIP(r1) /* Return to _switch caller in new task */
mtlrr4
-   addir1,r1,INT_FRAME_SIZE
+   addir1,r1,SWITCH_FRAME_SIZE
blr
 
.globl  fast_exception_return
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index d6daf0d073b3..a097879b0474 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1779,10 +1779,10 @@ int copy_thread(struct task_struct *p, const struct 
kernel_clone_args *args)
 * do some house keeping and then return from the fork or clone
 * system call, using the stack frame created above.
 */
-   sp -= sizeof(struct pt_regs);
-   kregs = (struct pt_regs *) sp;
-   sp -= STACK_FRAME_OVERHEAD;
+   sp -= STACK_SWITCH_FRAME_SIZE;
+   kregs = (struct pt_regs *)(sp + STACK_SWITCH_FRAME_REGS);
p->thread.ksp = sp;
+
 #ifdef CONFIG_HAVE_HW_BREAKPOINT
for (i = 0; i < nr_wp_slots(); i++)
p->thread.ptrace_bps[i] = NULL;
@@ -2232,8 +2232,12 @@ void __no_sanitize_address show_stack(struct task_struct 
*tsk,
/*
 * See if this is an exception frame.
 * We look for the "regs" marker in the current frame.
+*
+* STACK_SWITCH_FRAME_SIZE being the smallest frame that
+* could hold a pt_regs, if that does not fit then it can't
+* have regs.
 */
-   if (validate_sp(sp, tsk, STACK_FRAME_WITH_PT_REGS)
+   if (validate_sp(sp, tsk, STACK_SWITCH_FRAME_SIZE)
&& stack[STACK_INT_FRAME_MARKER_LONGS] == 
STACK_FRAME_REGS_MARKER) {
struct pt_regs *regs = (struct pt_regs *)
(sp + STACK_INT_FRAME_REGS);
-- 
2.37.2



[RFC PATCH 10/19] powerpc: add a define for the user interrupt frame size

2022-10-31 Thread Nicholas Piggin
The user interrupt frame is a different size from the kernel frame, so
give it its own name.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/ptrace.h | 6 +++---
 arch/powerpc/kernel/process.c | 6 +++---
 arch/powerpc/kernel/stacktrace.c  | 4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/include/asm/ptrace.h 
b/arch/powerpc/include/asm/ptrace.h
index fdd50648df56..705ce26ae887 100644
--- a/arch/powerpc/include/asm/ptrace.h
+++ b/arch/powerpc/include/asm/ptrace.h
@@ -122,8 +122,7 @@ struct pt_regs
 
 #define STACK_FRAME_OVERHEAD   112 /* size of minimum stack frame */
 #define STACK_FRAME_LR_SAVE2   /* Location of LR in stack frame */
-#define STACK_INT_FRAME_SIZE   (sizeof(struct pt_regs) + \
-STACK_FRAME_OVERHEAD + KERNEL_REDZONE_SIZE)
+#define STACK_USER_INT_FRAME_SIZE  (sizeof(struct pt_regs) + 
STACK_FRAME_OVERHEAD)
 #define STACK_INT_FRAME_REGS   STACK_FRAME_OVERHEAD
 #define STACK_INT_FRAME_MARKER (STACK_FRAME_OVERHEAD - 16)
 
@@ -143,7 +142,7 @@ struct pt_regs
 #define KERNEL_REDZONE_SIZE0
 #define STACK_FRAME_OVERHEAD   16  /* size of minimum stack frame */
 #define STACK_FRAME_LR_SAVE1   /* Location of LR in stack frame */
-#define STACK_INT_FRAME_SIZE   (sizeof(struct pt_regs) + STACK_FRAME_OVERHEAD)
+#define STACK_USER_INT_FRAME_SIZE  (sizeof(struct pt_regs) + 
STACK_FRAME_OVERHEAD)
 #define STACK_INT_FRAME_REGS   STACK_FRAME_OVERHEAD
 #define STACK_INT_FRAME_MARKER (STACK_FRAME_OVERHEAD - 8)
 #define STACK_FRAME_MIN_SIZE   STACK_FRAME_OVERHEAD
@@ -153,6 +152,7 @@ struct pt_regs
 
 #endif /* __powerpc64__ */
 
+#define STACK_INT_FRAME_SIZE   (KERNEL_REDZONE_SIZE + 
STACK_USER_INT_FRAME_SIZE)
 #define STACK_INT_FRAME_MARKER_LONGS   (STACK_INT_FRAME_MARKER/sizeof(long))
 
 #ifndef __ASSEMBLY__
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index b0a9e5eeec4c..d6daf0d073b3 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1727,15 +1727,15 @@ int copy_thread(struct task_struct *p, const struct 
kernel_clone_args *args)
klp_init_thread_info(p);
 
/* Create initial stack frame. */
-   sp -= (sizeof(struct pt_regs) + STACK_FRAME_OVERHEAD);
+   sp -= STACK_USER_INT_FRAME_SIZE;
((unsigned long *)sp)[0] = 0;
 
/* Copy registers */
-   childregs = (struct pt_regs *)(sp + STACK_FRAME_OVERHEAD);
+   childregs = (struct pt_regs *)(sp + STACK_INT_FRAME_REGS);
if (unlikely(args->fn)) {
/* kernel thread */
memset(childregs, 0, sizeof(struct pt_regs));
-   childregs->gpr[1] = sp + (sizeof(struct pt_regs) + 
STACK_FRAME_OVERHEAD);
+   childregs->gpr[1] = sp + STACK_USER_INT_FRAME_SIZE;
/* function */
if (args->fn)
childregs->gpr[14] = ppc_function_entry((void 
*)args->fn);
diff --git a/arch/powerpc/kernel/stacktrace.c b/arch/powerpc/kernel/stacktrace.c
index 7efa0ec9dd77..453ac317a6cf 100644
--- a/arch/powerpc/kernel/stacktrace.c
+++ b/arch/powerpc/kernel/stacktrace.c
@@ -77,7 +77,7 @@ int __no_sanitize_address 
arch_stack_walk_reliable(stack_trace_consume_fn consum
/*
 * For user tasks, this is the SP value loaded on
 * kernel entry, see "PACAKSAVE(r13)" in _switch() and
-* system_call_common()/EXCEPTION_PROLOG_COMMON().
+* system_call_common().
 *
 * Likewise for non-swapper kernel threads,
 * this also happens to be the top of the stack
@@ -88,7 +88,7 @@ int __no_sanitize_address 
arch_stack_walk_reliable(stack_trace_consume_fn consum
 * an unreliable stack trace until it's been
 * _switch()'ed to for the first time.
 */
-   stack_end -= STACK_FRAME_OVERHEAD + sizeof(struct pt_regs);
+   stack_end -= STACK_USER_INT_FRAME_SIZE;
} else {
/*
 * idle tasks have a custom stack layout,
-- 
2.37.2



[RFC PATCH 09/19] powerpc: Rename STACK_FRAME_MARKER and derive it from frame offset

2022-10-31 Thread Nicholas Piggin
This is a count of longs from the stack pointer to the regs marker.
Rename it to make it more distinct from the other byte offsets. It
can be derived from the byte offset definitions just added.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/ptrace.h | 4 ++--
 arch/powerpc/kernel/process.c | 2 +-
 arch/powerpc/kernel/stacktrace.c  | 2 +-
 arch/powerpc/perf/callchain.c | 2 +-
 arch/powerpc/xmon/xmon.c  | 3 +--
 5 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/include/asm/ptrace.h 
b/arch/powerpc/include/asm/ptrace.h
index 8a9f4cf8c4c5..fdd50648df56 100644
--- a/arch/powerpc/include/asm/ptrace.h
+++ b/arch/powerpc/include/asm/ptrace.h
@@ -126,7 +126,6 @@ struct pt_regs
 STACK_FRAME_OVERHEAD + KERNEL_REDZONE_SIZE)
 #define STACK_INT_FRAME_REGS   STACK_FRAME_OVERHEAD
 #define STACK_INT_FRAME_MARKER (STACK_FRAME_OVERHEAD - 16)
-#define STACK_FRAME_MARKER 12
 
 #ifdef CONFIG_PPC64_ELF_ABI_V2
 #define STACK_FRAME_MIN_SIZE   32
@@ -147,7 +146,6 @@ struct pt_regs
 #define STACK_INT_FRAME_SIZE   (sizeof(struct pt_regs) + STACK_FRAME_OVERHEAD)
 #define STACK_INT_FRAME_REGS   STACK_FRAME_OVERHEAD
 #define STACK_INT_FRAME_MARKER (STACK_FRAME_OVERHEAD - 8)
-#define STACK_FRAME_MARKER 2
 #define STACK_FRAME_MIN_SIZE   STACK_FRAME_OVERHEAD
 
 /* Size of stack frame allocated when calling signal handler. */
@@ -155,6 +153,8 @@ struct pt_regs
 
 #endif /* __powerpc64__ */
 
+#define STACK_INT_FRAME_MARKER_LONGS   (STACK_INT_FRAME_MARKER/sizeof(long))
+
 #ifndef __ASSEMBLY__
 #include 
 
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index e7010f71de24..b0a9e5eeec4c 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -2234,7 +2234,7 @@ void __no_sanitize_address show_stack(struct task_struct 
*tsk,
 * We look for the "regs" marker in the current frame.
 */
if (validate_sp(sp, tsk, STACK_FRAME_WITH_PT_REGS)
-   && stack[STACK_FRAME_MARKER] == STACK_FRAME_REGS_MARKER) {
+   && stack[STACK_INT_FRAME_MARKER_LONGS] == 
STACK_FRAME_REGS_MARKER) {
struct pt_regs *regs = (struct pt_regs *)
(sp + STACK_INT_FRAME_REGS);
 
diff --git a/arch/powerpc/kernel/stacktrace.c b/arch/powerpc/kernel/stacktrace.c
index a2443d61728e..7efa0ec9dd77 100644
--- a/arch/powerpc/kernel/stacktrace.c
+++ b/arch/powerpc/kernel/stacktrace.c
@@ -136,7 +136,7 @@ int __no_sanitize_address 
arch_stack_walk_reliable(stack_trace_consume_fn consum
 
/* Mark stacktraces with exception frames as unreliable. */
if (sp <= stack_end - STACK_INT_FRAME_SIZE &&
-   stack[STACK_FRAME_MARKER] == STACK_FRAME_REGS_MARKER) {
+   stack[STACK_INT_FRAME_MARKER_LONGS] == 
STACK_FRAME_REGS_MARKER) {
return -EINVAL;
}
 
diff --git a/arch/powerpc/perf/callchain.c b/arch/powerpc/perf/callchain.c
index 9e254aed1f61..b01497ed5173 100644
--- a/arch/powerpc/perf/callchain.c
+++ b/arch/powerpc/perf/callchain.c
@@ -62,7 +62,7 @@ perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, 
struct pt_regs *re
 
if (next_sp == sp + STACK_INT_FRAME_SIZE &&
validate_sp(sp, current, STACK_INT_FRAME_SIZE) &&
-   fp[STACK_FRAME_MARKER] == STACK_FRAME_REGS_MARKER) {
+   fp[STACK_INT_FRAME_MARKER_LONGS] == 
STACK_FRAME_REGS_MARKER) {
/*
 * This looks like an interrupt frame for an
 * interrupt that occurred in the kernel
diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index e403f14eb6eb..bbdaa42ba4ba 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -1720,7 +1720,6 @@ static void get_function_bounds(unsigned long pc, 
unsigned long *startp,
 }
 
 #define LRSAVE_OFFSET  (STACK_FRAME_LR_SAVE * sizeof(unsigned long))
-#define MARKER_OFFSET  (STACK_FRAME_MARKER * sizeof(unsigned long))
 
 static void xmon_show_stack(unsigned long sp, unsigned long lr,
unsigned long pc)
@@ -1783,7 +1782,7 @@ static void xmon_show_stack(unsigned long sp, unsigned 
long lr,
 
/* Look for "regs" marker to see if this is
   an exception frame. */
-   if (mread(sp + MARKER_OFFSET, , sizeof(unsigned long))
+   if (mread(sp + STACK_INT_FRAME_MARKER, , sizeof(unsigned 
long))
&& marker == STACK_FRAME_REGS_MARKER) {
if (mread(sp + STACK_INT_FRAME_REGS, , 
sizeof(regs)) != sizeof(regs)) {
printf("Couldn't read registers at %lx\n",
-- 
2.37.2



[RFC PATCH 08/19] powerpc: add a definition for the marker offset within the interrupt frame

2022-10-31 Thread Nicholas Piggin
Define a constant rather than open-code the offset for the
"regs" marker.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/ptrace.h   |  2 ++
 arch/powerpc/kernel/entry_32.S  |  2 +-
 arch/powerpc/kernel/exceptions-64e.S|  2 +-
 arch/powerpc/kernel/exceptions-64s.S|  2 +-
 arch/powerpc/kernel/head_32.h   |  2 +-
 arch/powerpc/kernel/head_booke.h|  2 +-
 arch/powerpc/kernel/interrupt_64.S  | 10 +-
 arch/powerpc/kvm/book3s_hv_rmhandlers.S |  2 +-
 8 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/include/asm/ptrace.h 
b/arch/powerpc/include/asm/ptrace.h
index a4ae67aa9b76..8a9f4cf8c4c5 100644
--- a/arch/powerpc/include/asm/ptrace.h
+++ b/arch/powerpc/include/asm/ptrace.h
@@ -125,6 +125,7 @@ struct pt_regs
 #define STACK_INT_FRAME_SIZE   (sizeof(struct pt_regs) + \
 STACK_FRAME_OVERHEAD + KERNEL_REDZONE_SIZE)
 #define STACK_INT_FRAME_REGS   STACK_FRAME_OVERHEAD
+#define STACK_INT_FRAME_MARKER (STACK_FRAME_OVERHEAD - 16)
 #define STACK_FRAME_MARKER 12
 
 #ifdef CONFIG_PPC64_ELF_ABI_V2
@@ -145,6 +146,7 @@ struct pt_regs
 #define STACK_FRAME_LR_SAVE1   /* Location of LR in stack frame */
 #define STACK_INT_FRAME_SIZE   (sizeof(struct pt_regs) + STACK_FRAME_OVERHEAD)
 #define STACK_INT_FRAME_REGS   STACK_FRAME_OVERHEAD
+#define STACK_INT_FRAME_MARKER (STACK_FRAME_OVERHEAD - 8)
 #define STACK_FRAME_MARKER 2
 #define STACK_FRAME_MIN_SIZE   STACK_FRAME_OVERHEAD
 
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 24c8d84a56c9..2f61b7d3677c 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -114,7 +114,7 @@ transfer_to_syscall:
addir12,r12,STACK_FRAME_REGS_MARKER@l
stw r9,_MSR(r1)
li  r2, INTERRUPT_SYSCALL
-   stw r12,8(r1)
+   stw r12,STACK_INT_FRAME_MARKER(r1)
stw r2,_TRAP(r1)
SAVE_GPR(0, r1)
SAVE_GPRS(3, 8, r1)
diff --git a/arch/powerpc/kernel/exceptions-64e.S 
b/arch/powerpc/kernel/exceptions-64e.S
index f6b36083a8c2..d74c2a53af13 100644
--- a/arch/powerpc/kernel/exceptions-64e.S
+++ b/arch/powerpc/kernel/exceptions-64e.S
@@ -391,7 +391,7 @@ exc_##n##_common:   
\
std r10,_CCR(r1);   /* store orig CR in stackframe */   \
std r9,GPR1(r1);/* store stack frame back link */   \
std r11,SOFTE(r1);  /* and save it to stackframe */ \
-   std r12,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */   \
+   std r12,STACK_INT_FRAME_MARKER(r1); /* mark the frame */\
std r3,_TRAP(r1);   /* set trap number  */  \
std r0,RESULT(r1);  /* clear regs->result */\
SAVE_NVGPRS(r1);
diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index 907054940a07..39f08ec56126 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -591,7 +591,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
li  r10,0
LOAD_REG_IMMEDIATE(r11, STACK_FRAME_REGS_MARKER)
std r10,RESULT(r1)  /* clear regs->result   */
-   std r11,STACK_FRAME_OVERHEAD-16(r1) /* mark the frame   */
+   std r11,STACK_INT_FRAME_MARKER(r1) /* mark the frame*/
 .endm
 
 /*
diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index 117d25330e13..f8e2911478a7 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -112,7 +112,7 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
stw r0,GPR0(r1)
lis r10,STACK_FRAME_REGS_MARKER@ha /* exception frame marker */
addir10,r10,STACK_FRAME_REGS_MARKER@l
-   stw r10,8(r1)
+   stw r10,STACK_INT_FRAME_MARKER(r1)
li  r10, \trapno
stw r10,_TRAP(r1)
SAVE_GPRS(3, 8, r1)
diff --git a/arch/powerpc/kernel/head_booke.h b/arch/powerpc/kernel/head_booke.h
index 3149ac20b18e..37d43c172676 100644
--- a/arch/powerpc/kernel/head_booke.h
+++ b/arch/powerpc/kernel/head_booke.h
@@ -84,7 +84,7 @@ END_BTB_FLUSH_SECTION
stw r0,GPR0(r1)
lis r10, STACK_FRAME_REGS_MARKER@ha /* exception frame marker */
addir10, r10, STACK_FRAME_REGS_MARKER@l
-   stw r10, 8(r1)
+   stw r10, STACK_INT_FRAME_MARKER(r1)
li  r10, \trapno
stw r10,_TRAP(r1)
SAVE_GPRS(3, 8, r1)
diff --git a/arch/powerpc/kernel/interrupt_64.S 
b/arch/powerpc/kernel/interrupt_64.S
index 12807d5298a3..2306b979e71f 100644
--- a/arch/powerpc/kernel/interrupt_64.S
+++ b/arch/powerpc/kernel/interrupt_64.S
@@ -77,11 +77,11 @@ _ASM_NOKPROBE_SYMBOL(system_call_vectored_\name)
std r11,_TRAP(r1)
std r12,_CCR(r1)
std r3,ORIG_GPR3(r1)
+   

[RFC PATCH 07/19] powerpc: add definition for pt_regs offset within an interrupt frame

2022-10-31 Thread Nicholas Piggin
This is a common offset that currently uses the overloaded
STACK_FRAME_OVERHEAD constant. It's easier to read and more
flexible to use a specific regs offset for this.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/ptrace.h |  2 +
 arch/powerpc/kernel/asm-offsets.c |  7 +-
 arch/powerpc/kernel/entry_32.S|  6 +-
 arch/powerpc/kernel/exceptions-64e.S  | 42 +-
 arch/powerpc/kernel/exceptions-64s.S  | 80 +--
 arch/powerpc/kernel/head_32.h |  2 +-
 arch/powerpc/kernel/head_85xx.S   |  4 +-
 arch/powerpc/kernel/head_booke.h  |  2 +-
 arch/powerpc/kernel/interrupt_64.S| 22 ++---
 arch/powerpc/kernel/kgdb.c|  2 +-
 arch/powerpc/kernel/optprobes_head.S  |  4 +-
 arch/powerpc/kernel/ppc_save_regs.S   |  2 +-
 arch/powerpc/kernel/process.c |  4 +-
 arch/powerpc/kernel/tm.S  |  8 +-
 arch/powerpc/kernel/trace/ftrace_mprofile.S   |  2 +-
 .../lib/test_emulate_step_exec_instr.S|  2 +-
 arch/powerpc/perf/callchain.c |  2 +-
 arch/powerpc/xmon/xmon.c  |  7 +-
 18 files changed, 100 insertions(+), 100 deletions(-)

diff --git a/arch/powerpc/include/asm/ptrace.h 
b/arch/powerpc/include/asm/ptrace.h
index 2efec6d87049..a4ae67aa9b76 100644
--- a/arch/powerpc/include/asm/ptrace.h
+++ b/arch/powerpc/include/asm/ptrace.h
@@ -124,6 +124,7 @@ struct pt_regs
 #define STACK_FRAME_LR_SAVE2   /* Location of LR in stack frame */
 #define STACK_INT_FRAME_SIZE   (sizeof(struct pt_regs) + \
 STACK_FRAME_OVERHEAD + KERNEL_REDZONE_SIZE)
+#define STACK_INT_FRAME_REGS   STACK_FRAME_OVERHEAD
 #define STACK_FRAME_MARKER 12
 
 #ifdef CONFIG_PPC64_ELF_ABI_V2
@@ -143,6 +144,7 @@ struct pt_regs
 #define STACK_FRAME_OVERHEAD   16  /* size of minimum stack frame */
 #define STACK_FRAME_LR_SAVE1   /* Location of LR in stack frame */
 #define STACK_INT_FRAME_SIZE   (sizeof(struct pt_regs) + STACK_FRAME_OVERHEAD)
+#define STACK_INT_FRAME_REGS   STACK_FRAME_OVERHEAD
 #define STACK_FRAME_MARKER 2
 #define STACK_FRAME_MIN_SIZE   STACK_FRAME_OVERHEAD
 
diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index 4ce2a4aa3985..db5e66c1d031 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -72,7 +72,7 @@
 #endif
 
 #define STACK_PT_REGS_OFFSET(sym, val) \
-   DEFINE(sym, STACK_FRAME_OVERHEAD + offsetof(struct pt_regs, val))
+   DEFINE(sym, STACK_INT_FRAME_REGS + offsetof(struct pt_regs, val))
 
 int main(void)
 {
@@ -167,9 +167,8 @@ int main(void)
OFFSET(THREAD_CKVRSTATE, thread_struct, ckvr_state.vr);
OFFSET(THREAD_CKVRSAVE, thread_struct, ckvrsave);
OFFSET(THREAD_CKFPSTATE, thread_struct, ckfp_state.fpr);
-   /* Local pt_regs on stack for Transactional Memory funcs. */
-   DEFINE(TM_FRAME_SIZE, STACK_FRAME_OVERHEAD +
-  sizeof(struct pt_regs) + 16);
+   /* Local pt_regs on stack in int frame form, plus 16 bytes for TM */
+   DEFINE(TM_FRAME_SIZE, STACK_INT_FRAME_SIZE + 16);
 #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
 
OFFSET(TI_LOCAL_FLAGS, thread_info, local_flags);
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 3fc7c9886bb7..24c8d84a56c9 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -123,12 +123,12 @@ transfer_to_syscall:
kuep_lock
 
/* Calling convention has r3 = regs, r4 = orig r0 */
-   addir3,r1,STACK_FRAME_OVERHEAD
+   addir3,r1,STACK_INT_FRAME_REGS
mr  r4,r0
bl  system_call_exception
 
 ret_from_syscall:
-   addir4,r1,STACK_FRAME_OVERHEAD
+   addir4,r1,STACK_INT_FRAME_REGS
li  r5,0
bl  syscall_exit_prepare
 #ifdef CONFIG_PPC_47x
@@ -293,7 +293,7 @@ _ASM_NOKPROBE_SYMBOL(fast_exception_return)
.globl interrupt_return
 interrupt_return:
lwz r4,_MSR(r1)
-   addir3,r1,STACK_FRAME_OVERHEAD
+   addir3,r1,STACK_INT_FRAME_REGS
andi.   r0,r4,MSR_PR
beq .Lkernel_interrupt_return
bl  interrupt_exit_user_prepare
diff --git a/arch/powerpc/kernel/exceptions-64e.S 
b/arch/powerpc/kernel/exceptions-64e.S
index 930e36099015..f6b36083a8c2 100644
--- a/arch/powerpc/kernel/exceptions-64e.S
+++ b/arch/powerpc/kernel/exceptions-64e.S
@@ -455,7 +455,7 @@ exc_##n##_bad_stack:
\
EXCEPTION_COMMON(trapnum)   \
ack(r8);\
CHECK_NAPPING();\
-   addir3,r1,STACK_FRAME_OVERHEAD; \
+   addir3,r1,STACK_INT_FRAME_REGS;   

[RFC PATCH 06/19] powerpc: simplify ppc_save_regs

2022-10-31 Thread Nicholas Piggin
Adjust the pt_regs pointer so the interrupt frame offsets can be used
directly to save registers.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/ppc_save_regs.S | 58 +++--
 1 file changed, 14 insertions(+), 44 deletions(-)

diff --git a/arch/powerpc/kernel/ppc_save_regs.S 
b/arch/powerpc/kernel/ppc_save_regs.S
index 2d4d21bb46a9..2908a5c2cd2f 100644
--- a/arch/powerpc/kernel/ppc_save_regs.S
+++ b/arch/powerpc/kernel/ppc_save_regs.S
@@ -21,60 +21,30 @@
  * different ABIs, though).
  */
 _GLOBAL(ppc_save_regs)
-   PPC_STL r0,0*SZL(r3)
-#ifdef CONFIG_PPC32
-   stmwr2, 2*SZL(r3)
-#else
-   PPC_STL r2,2*SZL(r3)
-   PPC_STL r3,3*SZL(r3)
-   PPC_STL r4,4*SZL(r3)
-   PPC_STL r5,5*SZL(r3)
-   PPC_STL r6,6*SZL(r3)
-   PPC_STL r7,7*SZL(r3)
-   PPC_STL r8,8*SZL(r3)
-   PPC_STL r9,9*SZL(r3)
-   PPC_STL r10,10*SZL(r3)
-   PPC_STL r11,11*SZL(r3)
-   PPC_STL r12,12*SZL(r3)
-   PPC_STL r13,13*SZL(r3)
-   PPC_STL r14,14*SZL(r3)
-   PPC_STL r15,15*SZL(r3)
-   PPC_STL r16,16*SZL(r3)
-   PPC_STL r17,17*SZL(r3)
-   PPC_STL r18,18*SZL(r3)
-   PPC_STL r19,19*SZL(r3)
-   PPC_STL r20,20*SZL(r3)
-   PPC_STL r21,21*SZL(r3)
-   PPC_STL r22,22*SZL(r3)
-   PPC_STL r23,23*SZL(r3)
-   PPC_STL r24,24*SZL(r3)
-   PPC_STL r25,25*SZL(r3)
-   PPC_STL r26,26*SZL(r3)
-   PPC_STL r27,27*SZL(r3)
-   PPC_STL r28,28*SZL(r3)
-   PPC_STL r29,29*SZL(r3)
-   PPC_STL r30,30*SZL(r3)
-   PPC_STL r31,31*SZL(r3)
+   /* This allows stack frame accessor macros and offsets to be used */
+   subir3,r3,STACK_FRAME_OVERHEAD
+   SAVE_GPRS(0, 31, r3)
+#ifdef CONFIG_PPC64
lbz r0,PACAIRQSOFTMASK(r13)
-   PPC_STL r0,SOFTE-STACK_FRAME_OVERHEAD(r3)
+   PPC_STL r0,SOFTE(r3)
 #endif
/* go up one stack frame for SP */
PPC_LL  r4,0(r1)
-   PPC_STL r4,1*SZL(r3)
+   PPC_STL r4,GPR1(r3)
/* get caller's LR */
PPC_LL  r0,LRSAVE(r4)
-   PPC_STL r0,_LINK-STACK_FRAME_OVERHEAD(r3)
+   PPC_STL r0,_LINK(r3)
mflrr0
-   PPC_STL r0,_NIP-STACK_FRAME_OVERHEAD(r3)
+   PPC_STL r0,_NIP(r3)
mfmsr   r0
-   PPC_STL r0,_MSR-STACK_FRAME_OVERHEAD(r3)
+   PPC_STL r0,_MSR(r3)
mfctr   r0
-   PPC_STL r0,_CTR-STACK_FRAME_OVERHEAD(r3)
+   PPC_STL r0,_CTR(r3)
mfxer   r0
-   PPC_STL r0,_XER-STACK_FRAME_OVERHEAD(r3)
+   PPC_STL r0,_XER(r3)
mfcrr0
-   PPC_STL r0,_CCR-STACK_FRAME_OVERHEAD(r3)
+   PPC_STL r0,_CCR(r3)
li  r0,0
-   PPC_STL r0,_TRAP-STACK_FRAME_OVERHEAD(r3)
-   PPC_STL r0,ORIG_GPR3-STACK_FRAME_OVERHEAD(r3)
+   PPC_STL r0,_TRAP(r3)
+   PPC_STL r0,ORIG_GPR3(r3)
blr
-- 
2.37.2