All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: srikar@linux.vnet.ibm.com, rostedt@goodmis.org,
	mhiramat@kernel.org, peterz@infradead.org, mingo@redhat.com,
	acme@kernel.org, alexander.shishkin@linux.intel.com,
	jolsa@redhat.com, namhyung@kernel.org,
	linux-kernel@vger.kernel.org, corbet@lwn.net,
	linux-doc@vger.kernel.org, ananth@linux.vnet.ibm.com,
	alexis.berlemont@gmail.com, naveen.n.rao@linux.vnet.ibm.com,
	linux-arm-kernel@lists.infradead.org, linux-mips@linux-mips.org,
	linux@armlinux.org.uk, ralf@linux-mips.org, paul.burton@mips.com,
	Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Subject: Re: [PATCH v5 06/10] Uprobes: Support SDT markers having reference count (semaphore)
Date: Mon, 2 Jul 2018 10:46:55 +0530	[thread overview]
Message-ID: <0c543791-f3b7-5a4b-f002-e1c76bb430c0@linux.ibm.com> (raw)
In-Reply-To: <20180701210935.GA14404@redhat.com>

Hi Oleg,

On 07/02/2018 02:39 AM, Oleg Nesterov wrote:
> On 06/28, Ravi Bangoria wrote:
>>
>> @@ -294,6 +462,15 @@ int uprobe_write_opcode(struct uprobe *uprobe, struct mm_struct *mm,
>>  	if (ret <= 0)
>>  		goto put_old;
>>  
>> +	/* Update the ref_ctr if we are going to replace instruction. */
>> +	if (!ref_ctr_updated) {
>> +		ret = update_ref_ctr(uprobe, mm, is_register);
>> +		if (ret)
>> +			goto put_old;
>> +
>> +		ref_ctr_updated = 1;
>> +	}
> 
> Why can't this code live in install_breakpoint() and remove_breakpoint() ?
> this way we do not need to export "struct uprobe" and change set_swbp/set_orig_insn,
> and the logic will be more simple.

IMO, it's more easier with current approach. Updating reference counter
inside uprobe_write_opcode() makes it tightly coupled with instruction
patching. Basically, reference counter gets incremented only when first
consumer gets activated and will get decremented only when last consumer
is going away.

Advantage is, we can get rid of sdt_mm_list patch*, because increment and
decrement are anyway happening in sync. This makes the implementation lot
more simpler. If I do it inside install_breakpoit()/ remove_breakpoint(),
I've to reintroduce sdt_mm_list which makes code more complicated and ugly.

* https://lkml.org/lkml/2018/4/17/28

BTW, is there any harm in exporting struct uprobe outside of uprobe.c?

> 
> And let me ask again... May be you have already explained this, but I can't
> find the previous discussion.
> 
> So why do we need a counter but not a boolean? IIRC, because the counter can
> be shared, in particular 2 different uprobes can have the same >ref_ctr_offset,
> right?

Actually, it's by design. This counter keeps track of current tracers
tracing on a particular SDT marker. So only boolean can't work here.
Also, yes, multiple markers can share the same reference counter.

> 
> But who else can use this counter and how? Say, can userspace update it too?

There are many different ways user can change the reference counter.
Ex, systemtap and bcc both uses uprobe to probe on a marker but reference
counter update logic is different in both of them. Systemtap records all
exec/mmap events and updates the counter when it finds interested process/
vma. bcc directly hooks into process's memory (/proc/pid/mem).

> If yes, why this can't race with __update_ref_ctr() ?

Right. But there is no synchronization mechanism provided by the SDT
infrastructure and this is all userspace so there are chances of race.
At least, this patch still tries to make sure that reference counter
does not go negative. If so, throw a warning and don't update it.

> 
> And btw, why does __update_ref_ctr() use FOLL_FORCE? This vma should be writeable
> or valid_ref_ctr_vma() should nack it?

I don't remember the exact reason but seem its unnecessary. Let me try to
recall the reason, otherwise will remove it in the next version.

> 
> And shouldn't valid_ref_ctr_vma() check VM_SHARED? IIUC we do not want to write
> to this file?

Hmm, I haven't seen reference counter shared across processes. But as this
is a generic infrastructure, I'll add a check there.

Thanks for the review,
Ravi


WARNING: multiple messages have this Message-ID (diff)
From: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: srikar@linux.vnet.ibm.com, rostedt@goodmis.org,
	mhiramat@kernel.org, peterz@infradead.org, mingo@redhat.com,
	acme@kernel.org, alexander.shishkin@linux.intel.com,
	jolsa@redhat.com, namhyung@kernel.org,
	linux-kernel@vger.kernel.org, corbet@lwn.net,
	linux-doc@vger.kernel.org, ananth@linux.vnet.ibm.com,
	alexis.berlemont@gmail.com, naveen.n.rao@linux.vnet.ibm.com,
	linux-arm-kernel@lists.infradead.org, linux-mips@linux-mips.org,
	linux@armlinux.org.uk, ralf@linux-mips.org, paul.burton@mips.com,
	Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Subject: Re: [PATCH v5 06/10] Uprobes: Support SDT markers having reference count (semaphore)
Date: Mon, 2 Jul 2018 10:46:55 +0530	[thread overview]
Message-ID: <0c543791-f3b7-5a4b-f002-e1c76bb430c0@linux.ibm.com> (raw)
In-Reply-To: <20180701210935.GA14404@redhat.com>

Hi Oleg,

On 07/02/2018 02:39 AM, Oleg Nesterov wrote:
> On 06/28, Ravi Bangoria wrote:
>>
>> @@ -294,6 +462,15 @@ int uprobe_write_opcode(struct uprobe *uprobe, struct mm_struct *mm,
>>  	if (ret <= 0)
>>  		goto put_old;
>>  
>> +	/* Update the ref_ctr if we are going to replace instruction. */
>> +	if (!ref_ctr_updated) {
>> +		ret = update_ref_ctr(uprobe, mm, is_register);
>> +		if (ret)
>> +			goto put_old;
>> +
>> +		ref_ctr_updated = 1;
>> +	}
> 
> Why can't this code live in install_breakpoint() and remove_breakpoint() ?
> this way we do not need to export "struct uprobe" and change set_swbp/set_orig_insn,
> and the logic will be more simple.

IMO, it's more easier with current approach. Updating reference counter
inside uprobe_write_opcode() makes it tightly coupled with instruction
patching. Basically, reference counter gets incremented only when first
consumer gets activated and will get decremented only when last consumer
is going away.

Advantage is, we can get rid of sdt_mm_list patch*, because increment and
decrement are anyway happening in sync. This makes the implementation lot
more simpler. If I do it inside install_breakpoit()/ remove_breakpoint(),
I've to reintroduce sdt_mm_list which makes code more complicated and ugly.

* https://lkml.org/lkml/2018/4/17/28

BTW, is there any harm in exporting struct uprobe outside of uprobe.c?

> 
> And let me ask again... May be you have already explained this, but I can't
> find the previous discussion.
> 
> So why do we need a counter but not a boolean? IIRC, because the counter can
> be shared, in particular 2 different uprobes can have the same >ref_ctr_offset,
> right?

Actually, it's by design. This counter keeps track of current tracers
tracing on a particular SDT marker. So only boolean can't work here.
Also, yes, multiple markers can share the same reference counter.

> 
> But who else can use this counter and how? Say, can userspace update it too?

There are many different ways user can change the reference counter.
Ex, systemtap and bcc both uses uprobe to probe on a marker but reference
counter update logic is different in both of them. Systemtap records all
exec/mmap events and updates the counter when it finds interested process/
vma. bcc directly hooks into process's memory (/proc/pid/mem).

> If yes, why this can't race with __update_ref_ctr() ?

Right. But there is no synchronization mechanism provided by the SDT
infrastructure and this is all userspace so there are chances of race.
At least, this patch still tries to make sure that reference counter
does not go negative. If so, throw a warning and don't update it.

> 
> And btw, why does __update_ref_ctr() use FOLL_FORCE? This vma should be writeable
> or valid_ref_ctr_vma() should nack it?

I don't remember the exact reason but seem its unnecessary. Let me try to
recall the reason, otherwise will remove it in the next version.

> 
> And shouldn't valid_ref_ctr_vma() check VM_SHARED? IIUC we do not want to write
> to this file?

Hmm, I haven't seen reference counter shared across processes. But as this
is a generic infrastructure, I'll add a check there.

Thanks for the review,
Ravi

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

WARNING: multiple messages have this Message-ID (diff)
From: ravi.bangoria@linux.ibm.com (Ravi Bangoria)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v5 06/10] Uprobes: Support SDT markers having reference count (semaphore)
Date: Mon, 2 Jul 2018 10:46:55 +0530	[thread overview]
Message-ID: <0c543791-f3b7-5a4b-f002-e1c76bb430c0@linux.ibm.com> (raw)
In-Reply-To: <20180701210935.GA14404@redhat.com>

Hi Oleg,

On 07/02/2018 02:39 AM, Oleg Nesterov wrote:
> On 06/28, Ravi Bangoria wrote:
>>
>> @@ -294,6 +462,15 @@ int uprobe_write_opcode(struct uprobe *uprobe, struct mm_struct *mm,
>>  	if (ret <= 0)
>>  		goto put_old;
>>  
>> +	/* Update the ref_ctr if we are going to replace instruction. */
>> +	if (!ref_ctr_updated) {
>> +		ret = update_ref_ctr(uprobe, mm, is_register);
>> +		if (ret)
>> +			goto put_old;
>> +
>> +		ref_ctr_updated = 1;
>> +	}
> 
> Why can't this code live in install_breakpoint() and remove_breakpoint() ?
> this way we do not need to export "struct uprobe" and change set_swbp/set_orig_insn,
> and the logic will be more simple.

IMO, it's more easier with current approach. Updating reference counter
inside uprobe_write_opcode() makes it tightly coupled with instruction
patching. Basically, reference counter gets incremented only when first
consumer gets activated and will get decremented only when last consumer
is going away.

Advantage is, we can get rid of sdt_mm_list patch*, because increment and
decrement are anyway happening in sync. This makes the implementation lot
more simpler. If I do it inside install_breakpoit()/ remove_breakpoint(),
I've to reintroduce sdt_mm_list which makes code more complicated and ugly.

* https://lkml.org/lkml/2018/4/17/28

BTW, is there any harm in exporting struct uprobe outside of uprobe.c?

> 
> And let me ask again... May be you have already explained this, but I can't
> find the previous discussion.
> 
> So why do we need a counter but not a boolean? IIRC, because the counter can
> be shared, in particular 2 different uprobes can have the same >ref_ctr_offset,
> right?

Actually, it's by design. This counter keeps track of current tracers
tracing on a particular SDT marker. So only boolean can't work here.
Also, yes, multiple markers can share the same reference counter.

> 
> But who else can use this counter and how? Say, can userspace update it too?

There are many different ways user can change the reference counter.
Ex, systemtap and bcc both uses uprobe to probe on a marker but reference
counter update logic is different in both of them. Systemtap records all
exec/mmap events and updates the counter when it finds interested process/
vma. bcc directly hooks into process's memory (/proc/pid/mem).

> If yes, why this can't race with __update_ref_ctr() ?

Right. But there is no synchronization mechanism provided by the SDT
infrastructure and this is all userspace so there are chances of race.
At least, this patch still tries to make sure that reference counter
does not go negative. If so, throw a warning and don't update it.

> 
> And btw, why does __update_ref_ctr() use FOLL_FORCE? This vma should be writeable
> or valid_ref_ctr_vma() should nack it?

I don't remember the exact reason but seem its unnecessary. Let me try to
recall the reason, otherwise will remove it in the next version.

> 
> And shouldn't valid_ref_ctr_vma() check VM_SHARED? IIUC we do not want to write
> to this file?

Hmm, I haven't seen reference counter shared across processes. But as this
is a generic infrastructure, I'll add a check there.

Thanks for the review,
Ravi

  reply	other threads:[~2018-07-02  5:17 UTC|newest]

Thread overview: 152+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-28  5:21 [PATCH v5 00/10] Uprobes: Support SDT markers having reference count (semaphore) Ravi Bangoria
2018-06-28  5:21 ` Ravi Bangoria
2018-06-28  5:21 ` Ravi Bangoria
2018-06-28  5:22 ` [PATCH v5 01/10] Uprobes: Move uprobe structure to uprobe.h Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-06-28  5:22 ` [PATCH v5 02/10] Uprobes: Simplify uprobe_register() body Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-06-28  5:22 ` [PATCH v5 03/10] Uprobe: Change set_swbp definition Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-06-28  5:22 ` [PATCH v5 04/10] Uprobe: Change set_orig_insn definition Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-06-28  5:22 ` [PATCH v5 05/10] Uprobe: Change uprobe_write_opcode definition Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-06-28  5:22 ` [PATCH v5 06/10] Uprobes: Support SDT markers having reference count (semaphore) Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-06-28 19:51   ` Oleg Nesterov
2018-06-28 19:51     ` Oleg Nesterov
2018-06-28 19:51     ` Oleg Nesterov
2018-06-29  3:23     ` Ravi Bangoria
2018-06-29  3:23       ` Ravi Bangoria
2018-06-29  3:23       ` Ravi Bangoria
2018-07-01 21:09   ` Oleg Nesterov
2018-07-01 21:09     ` Oleg Nesterov
2018-07-01 21:09     ` Oleg Nesterov
2018-07-02  5:16     ` Ravi Bangoria [this message]
2018-07-02  5:16       ` Ravi Bangoria
2018-07-02  5:16       ` Ravi Bangoria
2018-07-02 18:01       ` Oleg Nesterov
2018-07-02 18:01         ` Oleg Nesterov
2018-07-02 18:01         ` Oleg Nesterov
2018-07-03  5:30         ` Ravi Bangoria
2018-07-03  5:30           ` Ravi Bangoria
2018-07-03  5:30           ` Ravi Bangoria
2018-07-03  6:16           ` Srikar Dronamraju
2018-07-03  6:16             ` Srikar Dronamraju
2018-07-03  6:16             ` Srikar Dronamraju
2018-07-03  7:43             ` Ravi Bangoria
2018-07-03  7:43               ` Ravi Bangoria
2018-07-03  7:43               ` Ravi Bangoria
2018-07-04  9:16               ` Srikar Dronamraju
2018-07-04  9:16                 ` Srikar Dronamraju
2018-07-04  9:16                 ` Srikar Dronamraju
2018-07-04  9:24                 ` Ravi Bangoria
2018-07-04  9:24                   ` Ravi Bangoria
2018-07-04  9:24                   ` Ravi Bangoria
2018-07-03  8:11           ` Ravi Bangoria
2018-07-03  8:11             ` Ravi Bangoria
2018-07-03  8:11             ` Ravi Bangoria
2018-07-03 16:36           ` Oleg Nesterov
2018-07-03 16:36             ` Oleg Nesterov
2018-07-03 16:36             ` Oleg Nesterov
2018-07-03 17:25             ` Oleg Nesterov
2018-07-03 17:25               ` Oleg Nesterov
2018-07-03 17:25               ` Oleg Nesterov
2018-07-04  4:53               ` Ravi Bangoria
2018-07-04  4:53                 ` Ravi Bangoria
2018-07-04  4:53                 ` Ravi Bangoria
2018-07-10 15:25                 ` Oleg Nesterov
2018-07-10 15:25                   ` Oleg Nesterov
2018-07-10 15:25                   ` Oleg Nesterov
2018-07-11  8:44                   ` Ravi Bangoria
2018-07-11  8:44                     ` Ravi Bangoria
2018-07-11  8:44                     ` Ravi Bangoria
2018-07-11  9:52                     ` Ravi Bangoria
2018-07-11  9:52                       ` Ravi Bangoria
2018-07-11  9:52                       ` Ravi Bangoria
2018-07-12 14:58                     ` Oleg Nesterov
2018-07-12 14:58                       ` Oleg Nesterov
2018-07-12 14:58                       ` Oleg Nesterov
2018-07-12 19:53                       ` Song Liu
2018-07-12 19:53                         ` Song Liu
2018-07-12 19:53                         ` Song Liu
2018-07-12 19:53                         ` Song Liu
2018-07-13  7:55                         ` Ravi Bangoria
2018-07-13  7:55                           ` Ravi Bangoria
2018-07-13  7:55                           ` Ravi Bangoria
2018-07-13 23:50                           ` Song Liu
2018-07-13 23:50                             ` Song Liu
2018-07-13 23:50                             ` Song Liu
2018-07-13 23:50                             ` Song Liu
2018-07-16  8:20                             ` Ravi Bangoria
2018-07-16  8:20                               ` Ravi Bangoria
2018-07-16  8:20                               ` Ravi Bangoria
2018-07-16  8:51                             ` Ravi Bangoria
2018-07-16  8:51                               ` Ravi Bangoria
2018-07-16  8:51                               ` Ravi Bangoria
2018-07-13  5:39                       ` Ravi Bangoria
2018-07-13  5:39                         ` Ravi Bangoria
2018-07-13  5:39                         ` Ravi Bangoria
2018-07-04  4:49             ` Ravi Bangoria
2018-07-04  4:49               ` Ravi Bangoria
2018-07-04  4:49               ` Ravi Bangoria
2018-07-03 17:12           ` Oleg Nesterov
2018-07-03 17:12             ` Oleg Nesterov
2018-07-03 17:12             ` Oleg Nesterov
2018-07-03 18:23             ` Oleg Nesterov
2018-07-03 18:23               ` Oleg Nesterov
2018-07-03 18:23               ` Oleg Nesterov
2018-07-04  5:25               ` Ravi Bangoria
2018-07-04  5:25                 ` Ravi Bangoria
2018-07-04  5:25                 ` Ravi Bangoria
2018-07-02 16:01   ` Srikar Dronamraju
2018-07-02 16:01     ` Srikar Dronamraju
2018-07-02 16:01     ` Srikar Dronamraju
2018-07-02 18:05     ` Oleg Nesterov
2018-07-02 18:05       ` Oleg Nesterov
2018-07-02 18:05       ` Oleg Nesterov
2018-07-03  6:29     ` Ravi Bangoria
2018-07-03  6:29       ` Ravi Bangoria
2018-07-03  6:29       ` Ravi Bangoria
2018-07-03 19:26       ` Oleg Nesterov
2018-07-03 19:26         ` Oleg Nesterov
2018-07-03 19:26         ` Oleg Nesterov
2018-07-04  5:26         ` Ravi Bangoria
2018-07-04  5:26           ` Ravi Bangoria
2018-07-04  5:26           ` Ravi Bangoria
2018-07-04  6:07     ` Ravi Bangoria
2018-07-04  6:07       ` Ravi Bangoria
2018-07-04  6:07       ` Ravi Bangoria
2018-06-28  5:22 ` [PATCH v5 07/10] trace_uprobe/sdt: Prevent multiple reference counter for same uprobe Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-06-28  5:22 ` [PATCH v5 08/10] Uprobes/sdt: " Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-06-28  5:22 ` [PATCH v5 09/10] Uprobes/sdt: Document about reference counter Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-07-02 14:54   ` Srikar Dronamraju
2018-07-02 14:54     ` Srikar Dronamraju
2018-07-02 14:54     ` Srikar Dronamraju
2018-07-03  7:50     ` Ravi Bangoria
2018-07-03  7:50       ` Ravi Bangoria
2018-07-03  7:50       ` Ravi Bangoria
2018-06-28  5:22 ` [PATCH v5 10/10] perf probe: Support SDT markers having reference counter (semaphore) Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-06-28  5:22   ` Ravi Bangoria
2018-07-02 14:45   ` Srikar Dronamraju
2018-07-02 14:45     ` Srikar Dronamraju
2018-07-02 14:45     ` Srikar Dronamraju
2018-07-02 14:57   ` Srikar Dronamraju
2018-07-02 14:57     ` Srikar Dronamraju
2018-07-02 14:57     ` Srikar Dronamraju
2018-07-03  8:00     ` Ravi Bangoria
2018-07-03  8:00       ` Ravi Bangoria
2018-07-03  8:00       ` Ravi Bangoria

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=0c543791-f3b7-5a4b-f002-e1c76bb430c0@linux.ibm.com \
    --to=ravi.bangoria@linux.ibm.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexis.berlemont@gmail.com \
    --cc=ananth@linux.vnet.ibm.com \
    --cc=corbet@lwn.net \
    --cc=jolsa@redhat.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=linux@armlinux.org.uk \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=naveen.n.rao@linux.vnet.ibm.com \
    --cc=oleg@redhat.com \
    --cc=paul.burton@mips.com \
    --cc=peterz@infradead.org \
    --cc=ralf@linux-mips.org \
    --cc=rostedt@goodmis.org \
    --cc=srikar@linux.vnet.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.