linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Boqun Feng <boqun.feng-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Mathieu Desnoyers
	<mathieu.desnoyers-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
Cc: Dave Watson <davejwatson-b10kYP2dOMg@public.gmane.org>,
	Andrew Morton
	<akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>,
	Russell King <linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org>,
	Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>,
	Ingo Molnar <mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	"H. Peter Anvin" <hpa-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org>,
	linux-kernel
	<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	linux-api <linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Paul Turner <pjt-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	Andrew Hunter <ahh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	Peter Zijlstra <peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
	Andy Lutomirski <luto-kltTT9wpgjJwATOyAt5JVQ@public.gmane.org>,
	Andi Kleen <andi-Vw/NltI1exuRpAAqCnN02g@public.gmane.org>,
	Chris Lameter <cl-vYTEC60ixJUAvxtiuMwx3w@public.gmane.org>,
	Ben Maurer <bmaurer-b10kYP2dOMg@public.gmane.org>,
	rostedt <rostedt-nx8X9YLhiw1AfugRpC6u6w@public.gmane.org>,
	"Paul E. McKenney"
	<paulmck-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>,
	Josh Triplett <josh-iaAMLnmF4UmaiuxdJuQwMA@public.gmane.org>,
	Linus Torvalds
	<torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>,
	Catalin Marinas <catalin.marinas-5wv7dgnIgG8@public.gmane.org>,
	Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>,
	Michael Kerrisk
	<mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: Re: [RFC PATCH v7 7/7] Restartable sequences: self-tests
Date: Sat, 13 Aug 2016 09:28:42 +0800	[thread overview]
Message-ID: <20160813012834.GC18611@tardis.cn.ibm.com> (raw)
In-Reply-To: <434180831.9286.1471025505641.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 4762 bytes --]

On Fri, Aug 12, 2016 at 06:11:45PM +0000, Mathieu Desnoyers wrote:
> ----- On Aug 12, 2016, at 12:35 PM, Boqun Feng boqun.feng-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:
> 
> > On Fri, Aug 12, 2016 at 01:30:15PM +0800, Boqun Feng wrote:
> > [snip]
> >> > > Besides, do we allow userspace programs do read-only access to the
> >> > > memory objects modified by do_rseq(). If so, we have a problem when
> >> > > there are two writes in a do_rseq()(either in the rseq critical section
> >> > > or in the asm block), because in current implemetation, these two writes
> >> > > are unordered, which makes the readers outside a do_rseq() could observe
> >> > > the ordering of writes differently.
> >> > > 
> >> > > For rseq_finish2(), a simple solution would be making the "final" write
> >> > > a RELEASE.
> >> > 
> >> > Indeed, we would need a release semantic for the final store here if this
> >> > is the common use. Or we could duplicate the "flavors" of rseq_finish2 and
> >> > add a rseq_finish2_release. We should find a way to eliminate code duplication
> >> 
> >> I'm in favor of a separate rseq_finish2_release().
> >> 
> >> > there. I suspect we'll end up doing macros.
> >> > 
> >> 
> >> Me too. Lemme have a try ;-)
> >> 
> > 
> > How about this? Although a little messy, I separated the asm block into
> > several parts and implemented each part in a arch-diagnose way.
> 
> I find it rather hard to follow the per-arch assembly with this approach.
> It might prove to be troublesome if we want to do arch-specific optimizations
> in the future.
> 

It might be, but I was just trying to kill as much duplicate code as
possible, because the more duplicate we have, the more maintain effort
we need.

For example, PPC32 and PPC64 may have the same asm code to check the
event counter, but different code to do the final store.  Having the
same RSEQ_CHECK_COUNTER() for PPC32 and PPC64 actually makes it easy if
we come up a way to optimize the counter check code on PPC.

And if some arch wants to have some very specifical optimizations,
it could always write the whole asm block again rather than use the
helpers macros.

> I've come up with the following macro approach instead, feedback welcome!
> 
> 
> commit 4d27431d6aefaee617540ef04518962b0e4d14f4
> Author: Mathieu Desnoyers <mathieu.desnoyers-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
> Date:   Thu Aug 11 19:11:27 2016 -0400
> 
>     rseq_finish2, rseq_finish2_release (WIP)
> 
[...]
> +#elif defined(__ARMEL__)
> +
> +#define RSEQ_FINISH_ASM(_target_final, _to_write_final, _start_value, \
> +		_failure, extra_store, extra_input) \
> +	__asm__ __volatile__ goto ( \
> +		".pushsection __rseq_table, \"aw\"\n\t" \
> +		".balign 32\n\t" \
> +		".word 1f, 0x0, 2f, 0x0, %l[failure], 0x0, 0x0, 0x0\n\t" \
> +		".popsection\n\t" \
> +		"1:\n\t" \
> +		RSEQ_INJECT_ASM(1) \
> +		"adr r0, 3f\n\t" \
> +		"str r0, [%[rseq_cs]]\n\t" \
> +		RSEQ_INJECT_ASM(2) \
> +		"ldr r0, %[current_event_counter]\n\t" \
> +		"mov r1, #0\n\t" \
> +		"cmp %[start_event_counter], r0\n\t" \
> +		"bne %l[failure]\n\t" \
> +		RSEQ_INJECT_ASM(3) \
> +		extra_store \
> +		"str %[to_write_final], [%[target_final]]\n\t" \
> +		"2:\n\t" \
> +		RSEQ_INJECT_ASM(5) \
> +		"str r1, [%[rseq_cs]]\n\t" \

I find this is a little weird here, that is having an extra register for
zeroing the rseq_cs. Could we

		"mov r0, #0\n\t"
		"str r0, [%[rseq_cs]]\n\t"

here? Which not only saves a register, but also an instruction "mov r1,
#0" in the fast path. Am I missing something subtle?

> +		"b 4f\n\t" \
> +		".balign 32\n\t" \
> +		"3:\n\t" \
> +		".word 1b, 0x0, 2b, 0x0, l[failure], 0x0, 0x0, 0x0\n\t" \
> +		"4:\n\t" \
> +		: /* no outputs */ \
> +		: [start_event_counter]"r"((_start_value).event_counter), \
> +		  [current_event_counter]"m"((_start_value).rseqp->u.e.event_counter), \
> +		  [to_write_final]"r"(_to_write_final), \
> +		  [target_final]"r"(_target_final), \
> +		  [rseq_cs]"r"(&(_start_value).rseqp->rseq_cs) \
> +		  extra_input \
> +		  RSEQ_INJECT_INPUT \
> +		: "r0", "r1", "memory", "cc" \
> +		  RSEQ_INJECT_CLOBBER \
> +		: _failure \
>  	);

[...]

> +
> +#define RSEQ_FINISH2_RELEASE_SPECULATIVE_STORE_ASM() \
> +		RSEQ_FINISH2_SPECULATIVE_STORE_ASM() \
> +		"dmb\n\t"
> +

Having a RELEASE barrier here may be OK for all current archs we
support, but there are archs which rather than have a lightweight
RELEASE barrier but use a special instruction for RELEASE operations,
for example, AArch64. Do we need to take that into consideration and
define a RSEQ_FINISH_ASM_RELEASE() rather than a
RSEQ_FINISH2_SPECULATIVE_STORE_INPUT_ASM()?

[...]

Regards
Boqun

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

  parent reply	other threads:[~2016-08-13  1:28 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-21 21:14 [RFC PATCH v7 0/7] Restartable sequences system call Mathieu Desnoyers
2016-07-21 21:14 ` [RFC PATCH v7 2/7] tracing: instrument restartable sequences Mathieu Desnoyers
2016-07-21 21:14 ` [RFC PATCH v7 3/7] Restartable sequences: ARM 32 architecture support Mathieu Desnoyers
     [not found] ` <1469135662-31512-1-git-send-email-mathieu.desnoyers-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2016-07-21 21:14   ` [RFC PATCH v7 1/7] Restartable sequences system call Mathieu Desnoyers
     [not found]     ` <1469135662-31512-2-git-send-email-mathieu.desnoyers-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2016-07-25 23:02       ` Andy Lutomirski
     [not found]         ` <CALCETrVq3hgLbADcx_4g6gGgp7Hf-WnnWA8gg68tPZTv2wfbDg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-07-26  3:02           ` Mathieu Desnoyers
     [not found]             ` <1806206514.82247.1469502139408.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2016-08-03 12:27               ` Peter Zijlstra
2016-08-03 16:37                 ` Andy Lutomirski
2016-08-03 18:31                   ` Christoph Lameter
     [not found]                     ` <alpine.DEB.2.20.1608031330000.14875-wcBtFHqTun5QOdAKl3ChDw@public.gmane.org>
2016-08-04  5:01                       ` Andy Lutomirski
     [not found]                   ` <CALCETrWw0M9YLWTR7_ruxY8cW9_5XRONdw1QN+_pBp0Y63L8pA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-08-04  4:27                     ` Boqun Feng
2016-08-04  5:03                       ` Andy Lutomirski
     [not found]                         ` <CALCETrW7t89BWXW5JbWyLVciKS1HJMXe7feopM31wkqL4AtoFA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-08-09 16:13                           ` Boqun Feng
2016-08-10  8:01                             ` Andy Lutomirski
2016-08-10 17:40                               ` Mathieu Desnoyers
2016-08-10 17:33                             ` Mathieu Desnoyers
     [not found]                               ` <1918884375.7403.1470850424697.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2016-08-11  4:54                                 ` Boqun Feng
2016-08-10  8:13                           ` Andy Lutomirski
2016-08-03 18:29               ` Christoph Lameter
     [not found]                 ` <alpine.DEB.2.20.1608031325040.14875-wcBtFHqTun5QOdAKl3ChDw@public.gmane.org>
2016-08-10 16:47                   ` Mathieu Desnoyers
2016-08-10 16:59                     ` Christoph Lameter
2016-07-27 15:03       ` Boqun Feng
     [not found]         ` <20160727150352.GA32142-jkllrLZ6VuqyUtPGxGje5AC/G2K4zDHf@public.gmane.org>
2016-07-27 15:05           ` [RFC 1/4] rseq/param_test: Convert test_data_entry::count to intptr_t Boqun Feng
2016-07-27 15:05             ` [RFC 2/4] Restartable sequences: powerpc architecture support Boqun Feng
2016-07-28  3:13               ` Mathieu Desnoyers
2016-07-27 15:05             ` [RFC 3/4] Restartable sequences: Wire up powerpc system call Boqun Feng
     [not found]               ` <20160727150517.26983-3-boqun.feng-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-07-28  3:13                 ` Mathieu Desnoyers
2016-07-27 15:05             ` [RFC 4/4] Restartable sequences: Add self-tests for PPC Boqun Feng
2016-07-28  2:59               ` Mathieu Desnoyers
     [not found]                 ` <389340521.403.1469674785661.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2016-07-28  4:43                   ` Boqun Feng
2016-07-28  7:37                     ` [RFC v2] " Boqun Feng
     [not found]                       ` <20160728073723.3884-1-boqun.feng-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-07-28 14:04                         ` Mathieu Desnoyers
     [not found]                     ` <20160728044304.GC24740-jkllrLZ6VuqyUtPGxGje5AC/G2K4zDHf@public.gmane.org>
2016-07-28 13:42                       ` [RFC 4/4] " Mathieu Desnoyers
     [not found]             ` <20160727150517.26983-1-boqun.feng-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-07-28  3:07               ` [RFC 1/4] rseq/param_test: Convert test_data_entry::count to intptr_t Mathieu Desnoyers
2016-07-28  3:10           ` [RFC PATCH v7 1/7] Restartable sequences system call Mathieu Desnoyers
2016-08-03 13:19       ` Peter Zijlstra
2016-08-03 14:53         ` Paul E. McKenney
     [not found]         ` <20160803131940.GM6862-ndre7Fmf5hadTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org>
2016-08-03 15:45           ` Boqun Feng
2016-08-07 15:36             ` Mathieu Desnoyers
     [not found]               ` <468742193.3955.1470584184630.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2016-08-07 23:35                 ` Boqun Feng
     [not found]                   ` <20160807233543.GB13232-jkllrLZ6VuqyUtPGxGje5AC/G2K4zDHf@public.gmane.org>
2016-08-09 13:22                     ` Mathieu Desnoyers
2016-08-09 20:06           ` Mathieu Desnoyers
     [not found]             ` <656745027.6624.1470773200334.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2016-08-09 21:33               ` Peter Zijlstra
     [not found]                 ` <20160809213314.GK30192-ndre7Fmf5hadTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org>
2016-08-09 22:41                   ` Mathieu Desnoyers
2016-08-10  7:50                     ` Peter Zijlstra
2016-08-10 13:26                       ` Mathieu Desnoyers
2016-08-10 13:33                         ` Peter Zijlstra
2016-08-10 14:04                           ` Mathieu Desnoyers
2016-08-10  8:43               ` Peter Zijlstra
2016-08-10 13:57                 ` Mathieu Desnoyers
2016-08-10 14:28                   ` Peter Zijlstra
2016-08-10 14:44                     ` Mathieu Desnoyers
2016-08-10  8:10             ` Andy Lutomirski
     [not found]               ` <CALCETrUTpq6qX5SS170y_VtwiPc-SeR03bt-1Q98n+YMZMqopA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-08-10 19:04                 ` Mathieu Desnoyers
2016-08-10 19:16                   ` Andy Lutomirski
2016-08-10 20:06                     ` Mathieu Desnoyers
     [not found]                       ` <1224101037.7764.1470859581723.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2016-08-10 20:09                         ` Andy Lutomirski
2016-08-10 21:01                           ` Mathieu Desnoyers
     [not found]                             ` <1327322278.7807.1470862882633.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2016-08-11  7:23                               ` Andy Lutomirski
2016-08-10 13:29             ` Peter Zijlstra
2016-07-21 21:14   ` [RFC PATCH v7 4/7] Restartable sequences: wire up ARM 32 " Mathieu Desnoyers
2016-07-21 21:14   ` [RFC PATCH v7 5/7] Restartable sequences: x86 32/64 architecture support Mathieu Desnoyers
2016-07-21 21:14 ` [RFC PATCH v7 6/7] Restartable sequences: wire up x86 32/64 system call Mathieu Desnoyers
2016-07-21 21:14 ` [RFC PATCH v7 7/7] Restartable sequences: self-tests Mathieu Desnoyers
     [not found]   ` <CO1PR15MB09822FC140F84DCEEF2004CDDD0B0@CO1PR15MB0982.namprd15.prod.outlook.com>
     [not found]     ` <CO1PR15MB09822FC140F84DCEEF2004CDDD0B0-K8OqZrtvGWNkuEq+M2l22od3EbNNOtPMvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2016-07-24  3:09       ` Mathieu Desnoyers
     [not found]         ` <1590181502.79032.1469329777708.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2016-07-24 18:01           ` Dave Watson
     [not found]             ` <CO1PR15MB09825505EBF36E0C56AA037ADD0C0-K8OqZrtvGWNkuEq+M2l22od3EbNNOtPMvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2016-07-25 16:43               ` Mathieu Desnoyers
2016-08-11 23:26             ` Mathieu Desnoyers
     [not found]               ` <374861479.8581.1470957990793.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2016-08-12  1:28                 ` Boqun Feng
2016-08-12  3:10                   ` Mathieu Desnoyers
     [not found]                     ` <365498072.8664.1470971438957.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2016-08-12  3:13                       ` Mathieu Desnoyers
2016-08-12  5:30                       ` Boqun Feng
     [not found]                         ` <20160812053008.GA18611-jkllrLZ6VuqyUtPGxGje5AC/G2K4zDHf@public.gmane.org>
2016-08-12 16:35                           ` Boqun Feng
     [not found]                             ` <20160812163542.GB18611-jkllrLZ6VuqyUtPGxGje5AC/G2K4zDHf@public.gmane.org>
2016-08-12 18:11                               ` Mathieu Desnoyers
     [not found]                                 ` <434180831.9286.1471025505641.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2016-08-13  1:28                                   ` Boqun Feng [this message]
     [not found]                                     ` <20160813012834.GC18611-jkllrLZ6VuqyUtPGxGje5AC/G2K4zDHf@public.gmane.org>
2016-08-14 15:02                                       ` Mathieu Desnoyers
     [not found]                                         ` <832944127.9855.1471186940516.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2016-08-15  0:56                                           ` Boqun Feng
     [not found]                                             ` <20160815005607.GD18611-jkllrLZ6VuqyUtPGxGje5AC/G2K4zDHf@public.gmane.org>
2016-08-15 18:06                                               ` Mathieu Desnoyers
2016-08-12 19:36                 ` Mathieu Desnoyers
     [not found]                   ` <753387169.9345.1471030573282.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2016-08-12 20:05                     ` Dave Watson
     [not found]                       ` <CO1PR15MB0982484D57E73C83E6E6DB75DD1F0-K8OqZrtvGWNkuEq+M2l22od3EbNNOtPMvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2016-08-14 17:09                         ` Mathieu Desnoyers
2016-07-25 18:12     ` Mathieu Desnoyers

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=20160813012834.GC18611@tardis.cn.ibm.com \
    --to=boqun.feng-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=ahh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
    --cc=andi-Vw/NltI1exuRpAAqCnN02g@public.gmane.org \
    --cc=bmaurer-b10kYP2dOMg@public.gmane.org \
    --cc=catalin.marinas-5wv7dgnIgG8@public.gmane.org \
    --cc=cl-vYTEC60ixJUAvxtiuMwx3w@public.gmane.org \
    --cc=davejwatson-b10kYP2dOMg@public.gmane.org \
    --cc=hpa-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org \
    --cc=josh-iaAMLnmF4UmaiuxdJuQwMA@public.gmane.org \
    --cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org \
    --cc=luto-kltTT9wpgjJwATOyAt5JVQ@public.gmane.org \
    --cc=mathieu.desnoyers-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org \
    --cc=mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=paulmck-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org \
    --cc=peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=pjt-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=rostedt-nx8X9YLhiw1AfugRpC6u6w@public.gmane.org \
    --cc=tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org \
    --cc=torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
    --cc=will.deacon-5wv7dgnIgG8@public.gmane.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).