public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <marc.zyngier@arm.com>
To: David Long <dave.long@linaro.org>
Cc: "Catalin Marinas" <catalin.marinas@arm.com>,
	"Will Deacon" <will.deacon@arm.com>,
	"Sandeepa Prabhu" <sandeepa.s.prabhu@gmail.com>,
	"William Cohen" <wcohen@redhat.com>,
	"Pratyush Anand" <panand@redhat.com>,
	"Steve Capper" <steve.capper@linaro.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	"Dave P Martin" <Dave.Martin@arm.com>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Robin Murphy" <Robin.Murphy@arm.com>,
	"Ard Biesheuvel" <ard.biesheuvel@linaro.org>,
	"Jens Wiklander" <jens.wiklander@linaro.org>,
	"Christoffer Dall" <christoffer.dall@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Yang Shi" <yang.shi@linaro.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Viresh Kumar" <viresh.kumar@linaro.org>,
	"Suzuki K. Poulose" <suzuki.poulose@arm.com>,
	"Kees Cook" <keescook@chromium.org>,
	"Zi Shen Lim" <zlim.lnx@gmail.com>,
	"John Blackwood" <john.blackwood@ccur.com>,
	"Feng Kan" <fkan@apm.com>,
	"Balamurugan Shanmugam" <bshanmugam@apm.com>,
	"James Morse" <james.morse@arm.com>,
	"Vladimir Murzin" <Vladimir.Murzin@arm.com>,
	"Mark Salyzyn" <salyzyn@android.com>,
	"Petr Mladek" <pmladek@suse.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Mark Brown" <broonie@kernel.org>
Subject: Re: [PATCH v10 6/9] arm64: kprobes instruction simulation support
Date: Thu, 3 Mar 2016 08:01:39 +0000	[thread overview]
Message-ID: <20160303080139.3d415d17@arm.com> (raw)
In-Reply-To: <56D7C573.8030401@linaro.org>

On Thu, 3 Mar 2016 00:02:43 -0500
David Long <dave.long@linaro.org> wrote:

> On 03/01/2016 01:04 PM, Marc Zyngier wrote:
> > On 01/03/16 02:57, David Long wrote:
> >> From: Sandeepa Prabhu <sandeepa.s.prabhu@gmail.com>
> >>
> >> Kprobes needs simulation of instructions that cannot be stepped
> >> from different memory location, e.g.: those instructions
> >> that uses PC-relative addressing. In simulation, the behaviour
> >> of the instruction is implemented using a copy of pt_regs.
> >>
> >> Following instruction catagories are simulated:
> >>   - All branching instructions(conditional, register, and immediate)
> >>   - Literal access instructions(load-literal, adr/adrp)
> >>
> >> Conditional execution is limited to branching instructions in
> >> ARM v8. If conditions at PSTATE do not match the condition fields
> >> of opcode, the instruction is effectively NOP. Kprobes considers
> >> this case as 'miss'.
> >>
> >> This code also replaces the use of arch/arm/opcodes.c for
> >> arm_check_condition().
> >
> > Outdated comment?
> >
> 
> Yeah.  I'll remove it.
> 
> >>
> >> Thanks to Will Cohen for assorted suggested changes.
> >>
> >> Signed-off-by: Sandeepa Prabhu <sandeepa.s.prabhu@gmail.com>
> >> Signed-off-by: William Cohen <wcohen@redhat.com>
> >> Signed-off-by: David A. Long <dave.long@linaro.org>
> >> ---
> >>   arch/arm64/include/asm/insn.h            |   1 +
> >>   arch/arm64/include/asm/probes.h          |   5 +-
> >>   arch/arm64/kernel/Makefile               |   3 +-
> >>   arch/arm64/kernel/insn.c                 |   1 +
> >>   arch/arm64/kernel/kprobes-arm64.c        |  29 +++++
> >>   arch/arm64/kernel/kprobes.c              |  32 +++++-
> >>   arch/arm64/kernel/probes-simulate-insn.c | 187 +++++++++++++++++++++++++++++++
> >>   arch/arm64/kernel/probes-simulate-insn.h |  28 +++++
> >>   8 files changed, 280 insertions(+), 6 deletions(-)
> >>   create mode 100644 arch/arm64/kernel/probes-simulate-insn.c
> >>   create mode 100644 arch/arm64/kernel/probes-simulate-insn.h
> >>

[...]

> >> +/*
> >> + * instruction simulation functions
> >> + */
> >> +void __kprobes
> >> +simulate_adr_adrp(u32 opcode, long addr, struct pt_regs *regs)
> >> +{
> >> +	long imm, xn, val;
> >> +
> >> +	xn = opcode & 0x1f;
> >> +	imm = ((opcode >> 3) & 0x1ffffc) | ((opcode >> 29) & 0x3);
> >> +	imm = sign_extend(imm, 20);
> >> +	if (opcode & 0x80000000)
> >> +		val = (imm<<12) + (addr & 0xfffffffffffff000);
> >> +	else
> >> +		val = imm + addr;
> >> +
> >> +	regs->regs[xn] = val;
> >
> > What happens when you have something like "adr xzr, blah"? I haven't
> > found out where you are writing that back yet, but that could be really
> > fun for SP...
> >
> 
> It hadn't occurred to me that xzr could be an output register. Sigh. 
> That could mean a bit of repeated code to handle this special case.  I 
> wonder what the implications would be of adding xzr to the pt_regs 
> structure to avoid that.

xzr is not a register. It is an encoding that tells the CPU to discard
the result of an operation. As such, there is no need to store it.

An easy fix for this would be to have an accessor that actually checks
for the register number, and only allows the range 0-30. We've used
similar things in KVM for the same reasons (vcpu_get_reg/vcpu_set_reg).

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny.

  reply	other threads:[~2016-03-03  8:01 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-01  2:57 [PATCH v10 0/9] arm64: Add kernel probes (kprobes) support David Long
2016-03-01  2:57 ` [PATCH v10 1/9] arm64: Add HAVE_REGS_AND_STACK_ACCESS_API feature David Long
2016-03-14  9:41   ` 平松雅巳 / HIRAMATU,MASAMI
2016-03-01  2:57 ` [PATCH v10 2/9] arm64: Add more test functions to insn.c David Long
2016-03-01  2:57 ` [PATCH v10 3/9] arm64: add copy_to/from_user to kprobes blacklist David Long
2016-03-01  2:57 ` [PATCH v10 4/9] arm64: add conditional instruction simulation support David Long
2016-03-01 17:43   ` Marc Zyngier
2016-03-02  5:14     ` David Long
2016-03-01  2:57 ` [PATCH v10 5/9] arm64: Kprobes with single stepping support David Long
2016-03-01  2:57 ` [PATCH v10 6/9] arm64: kprobes instruction simulation support David Long
2016-03-01 18:04   ` Marc Zyngier
2016-03-03  5:02     ` David Long
2016-03-03  8:01       ` Marc Zyngier [this message]
2016-03-03 15:14         ` David Long
2016-03-03 15:32           ` Marc Zyngier
2016-03-01  2:57 ` [PATCH v10 7/9] arm64: Add trampoline code for kretprobes David Long
2016-03-01 18:19   ` Marc Zyngier
2016-03-02 21:20     ` William Cohen
2016-03-08  5:42       ` David Long
2016-03-01  2:57 ` [PATCH v10 8/9] arm64: Add kernel return probes support (kretprobes) David Long
2016-03-01  2:57 ` [PATCH v10 9/9] kprobes: Add arm64 case in kprobe example module David Long
2016-03-14  9:36 ` [PATCH v10 0/9] arm64: Add kernel probes (kprobes) support 平松雅巳 / HIRAMATU,MASAMI

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=20160303080139.3d415d17@arm.com \
    --to=marc.zyngier@arm.com \
    --cc=Dave.Martin@arm.com \
    --cc=Robin.Murphy@arm.com \
    --cc=Vladimir.Murzin@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex.bennee@linaro.org \
    --cc=ard.biesheuvel@linaro.org \
    --cc=broonie@kernel.org \
    --cc=bshanmugam@apm.com \
    --cc=catalin.marinas@arm.com \
    --cc=christoffer.dall@linaro.org \
    --cc=dave.long@linaro.org \
    --cc=fkan@apm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=james.morse@arm.com \
    --cc=jens.wiklander@linaro.org \
    --cc=john.blackwood@ccur.com \
    --cc=keescook@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=panand@redhat.com \
    --cc=pmladek@suse.com \
    --cc=salyzyn@android.com \
    --cc=sandeepa.s.prabhu@gmail.com \
    --cc=steve.capper@linaro.org \
    --cc=suzuki.poulose@arm.com \
    --cc=viresh.kumar@linaro.org \
    --cc=wcohen@redhat.com \
    --cc=will.deacon@arm.com \
    --cc=yang.shi@linaro.org \
    --cc=zlim.lnx@gmail.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