Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1289150 > unrolled thread

[RFC] kprobe'ing conditionally executed instructions

Started byDavid Long <dave.long@linaro.org>
First post2015-12-11 06:10 +0100
Last post2015-12-11 17:20 +0100
Articles 6 — 5 participants

Back to article view | Back to linux.kernel


Contents

  [RFC] kprobe'ing conditionally executed instructions David Long <dave.long@linaro.org> - 2015-12-11 06:10 +0100
    Re: [RFC] kprobe'ing conditionally executed instructions Steve Capper <steve.capper@linaro.org> - 2015-12-11 10:40 +0100
    Re: [RFC] kprobe'ing conditionally executed instructions "Jon Medhurst (Tixy)" <tixy@linaro.org> - 2015-12-11 11:30 +0100
      Re: [RFC] kprobe'ing conditionally executed instructions Russell King - ARM Linux <linux@arm.linux.org.uk> - 2015-12-11 11:40 +0100
        Re: [RFC] kprobe'ing conditionally executed instructions "Jon Medhurst (Tixy)" <tixy@linaro.org> - 2015-12-11 13:20 +0100
    Re: [RFC] kprobe'ing conditionally executed instructions William Cohen <wcohen@redhat.com> - 2015-12-11 17:20 +0100

#1289150 — [RFC] kprobe'ing conditionally executed instructions

FromDavid Long <dave.long@linaro.org>
Date2015-12-11 06:10 +0100
Subject[RFC] kprobe'ing conditionally executed instructions
Message-ID<qEo7U-84p-29@gated-at.bofh.it>
There is a moderate amount of code already in kprobes on ARM and the 
current ARMv8 patch to deal with conditional execution of instructions. 
One aspect of how this is handled is that instructions that fail their 
predicate and are not (technically) executed are also not treated as a 
hit kprobe. Steve Capper has suggested that the probe handling should 
still take place because we stepped through the instruction even if it 
was effectively a nop.  This would be a significant change in how it 
currently works on 32-bit ARM, and a change in the patch for ARMv8 
(although it's not likely to be much of a change in the kernel code).

I need input on this.  Do people have opinions?

-dl

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

[toc] | [next] | [standalone]


#1289358

FromSteve Capper <steve.capper@linaro.org>
Date2015-12-11 10:40 +0100
Message-ID<qEslb-2l8-3@gated-at.bofh.it>
In reply to#1289150
On 11 December 2015 at 13:05, David Long <dave.long@linaro.org> wrote:
> There is a moderate amount of code already in kprobes on ARM and the current
> ARMv8 patch to deal with conditional execution of instructions. One aspect
> of how this is handled is that instructions that fail their predicate and
> are not (technically) executed are also not treated as a hit kprobe. Steve
> Capper has suggested that the probe handling should still take place because
> we stepped through the instruction even if it was effectively a nop.  This
> would be a significant change in how it currently works on 32-bit ARM, and a
> change in the patch for ARMv8 (although it's not likely to be much of a
> change in the kernel code).
>
> I need input on this.  Do people have opinions?

Hi David,
Thanks for posting this.

Just to clarify the reasoning behind my suggestion for kprobes always
being hit was to achieve parity with x86.

I highlighted an example of discrepancy in behaviour between arm64 and
x86 in the following email:
http://lists.infradead.org/pipermail/linux-arm-kernel/2015-August/364201.html

Cheers,
--
Steve
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1289397

From"Jon Medhurst (Tixy)" <tixy@linaro.org>
Date2015-12-11 11:30 +0100
Message-ID<qEt7A-2X2-23@gated-at.bofh.it>
In reply to#1289150
On Fri, 2015-12-11 at 00:05 -0500, David Long wrote:
> There is a moderate amount of code already in kprobes on ARM and the 
> current ARMv8 patch to deal with conditional execution of instructions. 
> One aspect of how this is handled is that instructions that fail their 
> predicate and are not (technically) executed are also not treated as a 
> hit kprobe. Steve Capper has suggested that the probe handling should 
> still take place because we stepped through the instruction even if it 
> was effectively a nop.  This would be a significant change in how it 
> currently works on 32-bit ARM

32-bit ARM uses undefined instructions for kprobe 'breakpoints' and the
ARM ARM says it's implementation defined behaviour whether these
generate exceptions or not, i.e. whether the kprobe handler will be
called. You could say that we could always use unconditional
breakpoints, but this doesn't work with thumb where the instruction
could be in an IT block. So, the only way to have consistent behaviour
on all platforms is to not call kprobe handlers if condition check
fails. Which is the reason for the current implementation's design.

Also, if we change the current implementation as suggested, then looking
at things from a source code point of view...

if (test)
	foo()
else
	bar();

If you put a probe on the call to foo() and the compiler uses a branch
instruction for the test you're never going to hit the probe
fortest==false. But if it decides to use conditional instructions it
will (on some CPU implementations). And the choice between
branch/conditional instructions probably varies between GCC version and
kernel configs.

So again, IMO, the current kprobes implementation leads to consistency.

-- 
Tixy 


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

[toc] | [prev] | [next] | [standalone]


#1289402

FromRussell King - ARM Linux <linux@arm.linux.org.uk>
Date2015-12-11 11:40 +0100
Message-ID<qEthf-311-9@gated-at.bofh.it>
In reply to#1289397
On Fri, Dec 11, 2015 at 10:27:13AM +0000, Jon Medhurst (Tixy) wrote:
> On Fri, 2015-12-11 at 00:05 -0500, David Long wrote:
> > There is a moderate amount of code already in kprobes on ARM and the 
> > current ARMv8 patch to deal with conditional execution of instructions. 
> > One aspect of how this is handled is that instructions that fail their 
> > predicate and are not (technically) executed are also not treated as a 
> > hit kprobe. Steve Capper has suggested that the probe handling should 
> > still take place because we stepped through the instruction even if it 
> > was effectively a nop.  This would be a significant change in how it 
> > currently works on 32-bit ARM
> 
> 32-bit ARM uses undefined instructions for kprobe 'breakpoints' and the
> ARM ARM says it's implementation defined behaviour whether these
> generate exceptions or not, i.e. whether the kprobe handler will be
> called.

There are two classes of undefined instructions.  There are those which
fall into the above category, and there are those which are guaranteed
to raise an exception.  We should always be using the guaranteed ones,
not the other set.

-- 
RMK's Patch system: http://www.arm.linux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1289513

From"Jon Medhurst (Tixy)" <tixy@linaro.org>
Date2015-12-11 13:20 +0100
Message-ID<qEuQ2-486-17@gated-at.bofh.it>
In reply to#1289402
On Fri, 2015-12-11 at 10:34 +0000, Russell King - ARM Linux wrote:
> On Fri, Dec 11, 2015 at 10:27:13AM +0000, Jon Medhurst (Tixy) wrote:
> > On Fri, 2015-12-11 at 00:05 -0500, David Long wrote:
> > > There is a moderate amount of code already in kprobes on ARM and the 
> > > current ARMv8 patch to deal with conditional execution of instructions. 
> > > One aspect of how this is handled is that instructions that fail their 
> > > predicate and are not (technically) executed are also not treated as a 
> > > hit kprobe. Steve Capper has suggested that the probe handling should 
> > > still take place because we stepped through the instruction even if it 
> > > was effectively a nop.  This would be a significant change in how it 
> > > currently works on 32-bit ARM
> > 
> > 32-bit ARM uses undefined instructions for kprobe 'breakpoints' and the
> > ARM ARM says it's implementation defined behaviour whether these
> > generate exceptions or not, i.e. whether the kprobe handler will be
> > called.
> 
> There are two classes of undefined instructions.  There are those which
> fall into the above category, and there are those which are guaranteed
> to raise an exception.  We should always be using the guaranteed ones,
> not the other set.

I wonder if I'm going senile or have been subject to having the ARM ARM
evolve under me. I could swear we used instructions that were defined as
undefined (so to speak) and that conditional versions of undefined
instructions were UNPREDICTABLE. However, checking the ARM ARM again I
see those instruction encodings are for the BKPT instruction which says:

  Breakpoint causes a software breakpoint to occur.
  Breakpoint is always unconditional, even when inside an IT block.

So, my previous statements about not being able to implement the
proposed kprobe changes consistently aren't true.

-- 
Tixy


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

[toc] | [prev] | [next] | [standalone]


#1289714

FromWilliam Cohen <wcohen@redhat.com>
Date2015-12-11 17:20 +0100
Message-ID<qEyAj-6Pb-29@gated-at.bofh.it>
In reply to#1289150
On 12/11/2015 12:05 AM, David Long wrote:
> There is a moderate amount of code already in kprobes on ARM and the current ARMv8 patch to deal with conditional execution of instructions. One aspect of how this is handled is that instructions that fail their predicate and are not (technically) executed are also not treated as a hit kprobe. Steve Capper has suggested that the probe handling should still take place because we stepped through the instruction even if it was effectively a nop.  This would be a significant change in how it currently works on 32-bit ARM, and a change in the patch for ARMv8 (although it's not likely to be much of a change in the kernel code).
> 
> I need input on this.  Do people have opinions?
> 
> -dl
> 

Hi Dave,

Conditionally executing the kprobes would violate the assumptions made for perf and systemtap collecting data. Even if the instruction is predicated and treated as a NOP it should still reliably trigger the kprobe.  However, for efficiency the simulation/emulation/single-step of the instruction could be skipped if the instruction is known to have no change on the machine state other than changing the program counter.

-Will Cohen
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web