From: Ralf Baechle <ralf@linux-mips.org>
To: "Maciej W. Rozycki" <macro@linux-mips.org>
Cc: linux-mips@linux-mips.org
Subject: Re: [PATCH] MIPS: strnlen_user.S: Fix a CPU_DADDI_WORKAROUNDS regression
Date: Thu, 28 May 2015 20:36:40 +0200 [thread overview]
Message-ID: <20150528183640.GE7012@linux-mips.org> (raw)
In-Reply-To: <alpine.LFD.2.11.1505281829400.21603@eddie.linux-mips.org>
On Thu, May 28, 2015 at 06:51:27PM +0100, Maciej W. Rozycki wrote:
> On Thu, 28 May 2015, Ralf Baechle wrote:
>
> > > The jump to the delay slot combined with the unusual register usage
> > > convention taken here made it trickier than it would normally be to make a
> > > fix that does not regress -- in terms of code size -- unaffected microMIPS
> > > systems. I tried several versions and eventually I came up with this one
> > > that I believe produces the best code in all cases, at the cost of these
> > > #ifdefs. I hope they are acceptable.
> >
> > I think it's all a hint to rewrite the thing in a language that
> > transparently handles the DADDIU issue. Such as C. Which would also
> > make using a better algorithm easier.
>
> Probably. One concern that bothers me is the ability of GCC to make
> alternative entry points into frameless leaf functions.
>
> Here we have `__strnlen_kernel_asm' that falls through to
> `__strnlen_kernel_nocheck_asm'. That's a nice optimisation (we could
> probably schedule that `move $v0, $a0' into its preceding delay slot too,
> even though one might consider it hilarious to have a function's entry
> point in a delay slot).
>
> It would likely be lost in a conversion to C. But perhaps GCC can get
> better, or maybe it already has? I haven't been tracking what's been
> happening recently on that front.
>
> What I have in mind is that given:
>
> bar() { blah; }
>
> foo() { blah_blah; bar(); }
>
> in a single compilation unit, rather than making `foo' tail-jump to `bar'
> GCC would inline `bar' into `foo' entirely and merely export an additional
> `bar' entry point in the middle of `foo', where the original body of `bar'
> begins.
In this particular case we might move the access_ok() in to the
strnlen_user function, something like:
static inline long strnlen_user(const char __user *s, long n)
{
long res;
might_fault();
if (!access_ok(VERIFY_READ, s, 0))
return 0;
if (segment_eq(get_fs(), get_ds())) {
__asm__ __volatile__(
"move\t$4, %1\n\t"
"move\t$5, %2\n\t"
__MODULE_JAL(__strnlen_kernel_nocheck_asm)
"move\t%0, $2"
: "=r" (res)
: "r" (s), "r" (n)
: "$2", "$4", "$5", __UA_t0, "$31");
} else {
__asm__ __volatile__(
"move\t$4, %1\n\t"
"move\t$5, %2\n\t"
__MODULE_JAL(__strnlen_kernel_nocheck_asm)
"move\t%0, $2"
: "=r" (res)
: "r" (s), "r" (n)
: "$2", "$4", "$5", __UA_t0, "$31");
}
return res;
}
I'd not be surprised if GCC can optimize that better than the existing
code.
Ralf
next prev parent reply other threads:[~2015-05-28 18:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-28 16:46 [PATCH] MIPS: strnlen_user.S: Fix a CPU_DADDI_WORKAROUNDS regression Maciej W. Rozycki
2015-05-28 17:18 ` Ralf Baechle
2015-05-28 17:51 ` Maciej W. Rozycki
2015-05-28 18:36 ` Ralf Baechle [this message]
2015-06-05 8:44 ` Ralf Baechle
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=20150528183640.GE7012@linux-mips.org \
--to=ralf@linux-mips.org \
--cc=linux-mips@linux-mips.org \
--cc=macro@linux-mips.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