From: Hanjun Guo <guohanjun@huawei.com>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
<linux-arm-kernel@lists.infradead.org>
Cc: Kees Cook <keescook@chromium.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Jan Glauber <jglauber@marvell.com>,
Will Deacon <will.deacon@arm.com>,
Jayachandran Chandrasekharan Nair <jnair@marvell.com>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH v5] arm64: kernel: implement fast refcount checking
Date: Mon, 24 Jun 2019 14:37:15 +0800 [thread overview]
Message-ID: <abc0e649-ed32-ac76-434e-632dee53980c@huawei.com> (raw)
In-Reply-To: <20190619105431.2630-1-ard.biesheuvel@linaro.org>
On 2019/6/19 18:54, Ard Biesheuvel wrote:
> This adds support to arm64 for fast refcount checking, as contributed
> by Kees for x86 based on the implementation by grsecurity/PaX.
>
> The general approach is identical: the existing atomic_t helpers are
> cloned for refcount_t, with the arithmetic instruction modified to set
> the PSTATE flags, and one or two branch instructions added that jump to
> an out of line handler if overflow, decrement to zero or increment from
> zero are detected.
>
> One complication that we have to deal with on arm64 is the fact that
> it has two atomics implementations: the original LL/SC implementation
> using load/store exclusive loops, and the newer LSE one that does mostly
> the same in a single instruction. So we need to clone some parts of
> both for the refcount handlers, but we also need to deal with the way
> LSE builds fall back to LL/SC at runtime if the hardware does not
> support it.
>
> As is the case with the x86 version, the performance gain is substantial
> (ThunderX2 @ 2.2 GHz, using LSE), even though the arm64 implementation
> incorporates an add-from-zero check as well:
>
> perf stat -B -- echo ATOMIC_TIMING >/sys/kernel/debug/provoke-crash/DIRECT
>
> 116252672661 cycles # 2.207 GHz
>
> 52.689793525 seconds time elapsed
>
> perf stat -B -- echo REFCOUNT_TIMING >/sys/kernel/debug/provoke-crash/DIRECT
>
> 127060259162 cycles # 2.207 GHz
>
> 57.243690077 seconds time elapsed
>
> For comparison, the numbers below were captured using CONFIG_REFCOUNT_FULL,
> which uses the validation routines implemented in C using cmpxchg():
>
> perf stat -B -- echo REFCOUNT_TIMING >/sys/kernel/debug/provoke-crash/DIRECT
>
> Performance counter stats for 'cat /dev/fd/63':
>
> 191057942484 cycles # 2.207 GHz
>
> 86.568269904 seconds time elapsed
>
> As a bonus, this code has been found to perform significantly better on
> systems with many CPUs, due to the fact that it no longer relies on the
> load/compare-and-swap combo performed in a tight loop, which is what we
> emit for cmpxchg() on arm64.
It helps my 96 cores ARM64 server as well,
Tested-by: Hanjun Guo <guohanjun@huawei.com>
Thanks
Hanjun
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-06-24 6:38 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-19 10:54 [PATCH v5] arm64: kernel: implement fast refcount checking Ard Biesheuvel
2019-06-19 10:56 ` Ard Biesheuvel
2019-06-20 11:03 ` Jan Glauber
2019-06-20 18:10 ` Kees Cook
2019-06-24 6:37 ` Hanjun Guo [this message]
2019-07-03 13:40 ` Will Deacon
2019-07-03 18:12 ` Ard Biesheuvel
2019-07-10 12:21 ` Will Deacon
2019-07-15 12:44 ` Jan Glauber
2019-07-17 12:53 ` Hanjun Guo
2019-07-17 13:23 ` Hanjun Guo
2019-07-22 16:43 ` Kees Cook
2019-07-22 17:11 ` Will Deacon
2019-07-22 17:27 ` Kees Cook
2019-07-29 17:24 ` Will Deacon
2019-07-29 21:38 ` Kees Cook
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=abc0e649-ed32-ac76-434e-632dee53980c@huawei.com \
--to=guohanjun@huawei.com \
--cc=ard.biesheuvel@linaro.org \
--cc=catalin.marinas@arm.com \
--cc=jglauber@marvell.com \
--cc=jnair@marvell.com \
--cc=keescook@chromium.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=torvalds@linux-foundation.org \
--cc=will.deacon@arm.com \
/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).