linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Nicholas Piggin <npiggin@gmail.com>
To: Christophe Leroy <christophe.leroy@c-s.fr>,
	linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH v2 0/4] powerpc/64: syscalls in C
Date: Thu, 29 Aug 2019 19:38:01 +1000	[thread overview]
Message-ID: <1567070800.hlilai6sy6.astroid@bobo.none> (raw)
In-Reply-To: <4d0359d8-0958-583f-7727-10a51bd3c7c6@c-s.fr>

Christophe Leroy's on August 28, 2019 7:55 pm:
> 
> 
> Le 28/08/2019 à 11:49, Nicholas Piggin a écrit :
>> Christophe Leroy's on August 28, 2019 7:06 pm:
>>>
>>>
>>> Le 27/08/2019 à 15:55, Nicholas Piggin a écrit :
>>>> Accounted for some feedback.
>>>>
>>>> Nicholas Piggin (4):
>>>>     powerpc: convert to copy_thread_tls
>>>>     powerpc/64: remove support for kernel-mode syscalls
>>>>     powerpc/64: system call remove non-volatile GPR save optimisation
>>>>     powerpc/64: system call implement the bulk of the logic in C
>>>
>>> Would it be possible to split in the following parts:
>>>
>>> 1/ Implement in C whatever can be implemented without removing
>>> non-volatile GPR save optimisation
>>> 2/ Remove non-volatile GPR save optimisation
>>> 3/ Implement in C everything else
>> 
>> Hmm. I'll have a look but I would rather not go back and add the
>> intermediate state I was hoping to avoid. I'll think about it and
>> if it's not too difficult I will try to add something. I have an
>> idea.
>> 
>> With your nvregs performance test on ppc32, are you doing the
>> nvgpr restore? The fast path should be able to avoid that.
> 
> I only added the SAVE_NVGPRS call in the syscall entry macro just after 
> the saving of volatile regs, and changed the trap from \trapno+1 to \trapno

So... this actually seems to work. Haven't booted it, but the compiler
seems to do what we want.

This may be the way to go for ppc32 I think. I had a look at various 
ways you could save nvgprs with some early tests and returning early 
from the C call if it hits trouble without all registers saved. Most of 
it becomes quite ugly.

Thanks,
Nick

diff --git a/arch/powerpc/kernel/syscall_64.c b/arch/powerpc/kernel/syscall_64.c
index d42519b86ddd..b11346447882 100644
--- a/arch/powerpc/kernel/syscall_64.c
+++ b/arch/powerpc/kernel/syscall_64.c
@@ -14,6 +14,52 @@ extern void __noreturn tabort_syscall(void);
 
 typedef long (*syscall_fn)(long, long, long, long, long, long);
 
+register unsigned long r31 asm("r31");
+register unsigned long r30 asm("r30");
+register unsigned long r29 asm("r29");
+register unsigned long r28 asm("r28");
+register unsigned long r27 asm("r27");
+register unsigned long r26 asm("r26");
+register unsigned long r25 asm("r25");
+register unsigned long r24 asm("r24");
+register unsigned long r23 asm("r23");
+register unsigned long r22 asm("r22");
+register unsigned long r21 asm("r21");
+register unsigned long r20 asm("r20");
+register unsigned long r19 asm("r19");
+register unsigned long r18 asm("r18");
+register unsigned long r17 asm("r17");
+register unsigned long r16 asm("r16");
+register unsigned long r15 asm("r15");
+register unsigned long r14 asm("r14");
+
+static inline void save_nvgprs(struct pt_regs *regs)
+{
+	if (!(regs->trap & 1))
+		return;
+
+	regs->gpr[14] = r14;
+	regs->gpr[15] = r15;
+	regs->gpr[16] = r16;
+	regs->gpr[17] = r17;
+	regs->gpr[18] = r18;
+	regs->gpr[19] = r19;
+	regs->gpr[20] = r20;
+	regs->gpr[21] = r21;
+	regs->gpr[22] = r22;
+	regs->gpr[23] = r23;
+	regs->gpr[24] = r24;
+	regs->gpr[25] = r25;
+	regs->gpr[26] = r26;
+	regs->gpr[27] = r27;
+	regs->gpr[28] = r28;
+	regs->gpr[29] = r29;
+	regs->gpr[30] = r30;
+	regs->gpr[31] = r31;
+
+	regs->trap &= 0x1;
+}
+
 long system_call_exception(long r3, long r4, long r5, long r6, long r7, long r8, unsigned long r0, struct pt_regs *regs)
 {
 	unsigned long ti_flags;
@@ -66,6 +112,7 @@ long system_call_exception(long r3, long r4, long r5, long r6, long r7, long r8,
 		 * do_syscall_trace_enter() returns an invalid syscall number
 		 * and the test below against NR_syscalls will fail.
 		 */
+		save_nvgprs(regs);
 		r0 = do_syscall_trace_enter(regs);
 	}
 
@@ -132,6 +179,7 @@ unsigned long syscall_exit_prepare(unsigned long r3, struct pt_regs *regs)
 		if (ti_flags & _TIF_NEED_RESCHED) {
 			schedule();
 		} else {
+			save_nvgprs(regs);
 			/*
 			 * SIGPENDING must restore signal handler function
 			 * argument GPRs, and some non-volatiles (e.g., r1).

  reply	other threads:[~2019-08-29  9:42 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-27 13:55 [PATCH v2 0/4] powerpc/64: syscalls in C Nicholas Piggin
2019-08-27 13:55 ` [PATCH v2 1/4] powerpc: convert to copy_thread_tls Nicholas Piggin
2019-08-27 13:55 ` [PATCH v2 2/4] powerpc/64: remove support for kernel-mode syscalls Nicholas Piggin
2019-08-27 13:55 ` [PATCH v2 3/4] powerpc/64: system call remove non-volatile GPR save optimisation Nicholas Piggin
2019-08-28  9:02   ` Christophe Leroy
2019-08-28  9:32     ` Nicholas Piggin
2019-08-27 13:55 ` [PATCH v2 4/4] powerpc/64: system call implement the bulk of the logic in C Nicholas Piggin
2019-08-28  6:51   ` Christophe Leroy
2019-08-28  9:41     ` Nicholas Piggin
2019-08-28 15:30   ` Michal Suchánek
2019-08-28 22:19     ` Nicholas Piggin
2019-08-30 18:48   ` kbuild test robot
2019-08-30 20:04     ` Michal Suchánek
2019-09-02 10:20       ` Michael Ellerman
2019-08-28  9:06 ` [PATCH v2 0/4] powerpc/64: syscalls " Christophe Leroy
2019-08-28  9:49   ` Nicholas Piggin
2019-08-28  9:55     ` Christophe Leroy
2019-08-29  9:38       ` Nicholas Piggin [this message]
2019-08-29 10:45         ` Nicholas Piggin
2019-08-29 11:51         ` Segher Boessenkool
2019-08-29 15:49           ` Nicholas Piggin
2019-08-29 22:56             ` Nicholas Piggin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1567070800.hlilai6sy6.astroid@bobo.none \
    --to=npiggin@gmail.com \
    --cc=christophe.leroy@c-s.fr \
    --cc=linuxppc-dev@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).