From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: Andy Lutomirski <luto@amacapital.net>
Cc: Eugene Shatokhin <eugene.shatokhin@rosalab.ru>,
Ingo Molnar <mingo@kernel.org>, Ingo Molnar <mingo@redhat.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] kprobes/x86: Use 16 bytes for each instruction slot again
Date: Wed, 03 Jun 2015 06:42:49 +0900 [thread overview]
Message-ID: <556E2359.7050305@hitachi.com> (raw)
In-Reply-To: <CALCETrXB+L8g2dEqCmXg_L2m8khNn-_8ZGMH9CEFDbn4Lv4q6Q@mail.gmail.com>
On 2015/06/02 6:57, Andy Lutomirski wrote:
> On Mon, Jun 1, 2015 at 2:49 PM, Masami Hiramatsu
> <masami.hiramatsu.pt@hitachi.com> wrote:
>> On 2015/06/02 2:04, Andy Lutomirski wrote:
>>> On Mon, Jun 1, 2015 at 9:32 AM, Eugene Shatokhin
>>> <eugene.shatokhin@rosalab.ru> wrote:
>>>> Commit 91e5ed49fca0 ("x86/asm/decoder: Fix and enforce max instruction
>>>> size in the insn decoder") has changed MAX_INSN_SIZE from 16 to 15 bytes
>>>> on x86.
>>>>
>>>> As a side effect, the slots Kprobes use to store the instructions became
>>>> 1 byte shorter. This is unfortunate because, for example, the Kprobes'
>>>> "boost" feature can not be used now for the instructions of length 11,
>>>> like a quite common kind of MOV:
>>>> * movq $0xffffffffffffffff,-0x3fe8(%rax) (48 c7 80 18 c0 ff ff ff ff ff ff)
>>>> * movq $0x0,0x88(%rdi) (48 c7 87 88 00 00 00 00 00 00 00)
>>>> and so on.
>>>>
>>>> This patch makes the insn slots 16 bytes long, like they were before while
>>>> keeping MAX_INSN_SIZE intact.
>>>>
>>>> Other tools may benefit from this change as well.
>>>
>>> What is a "slot" and why does this patch make sense? Naively, I'd
>>> expect that the check you're patching is entirely unnecessary -- I
>>> don't see what the size of the instruction being probed has to do with
>>> the safety of executing it out of line and then jumping back.
>>>
>>> Is there another magic 16 somewhere that this is enforcing that we
>>> don't overrun?
>>
>> The kprobe-"booster" adds a jump back code (jmp <probed address + insn length>)
>> right after the instruction in the out-of-code buffer(slot). So we need at least
>> the insn-length + 5 bytes for the slot, it's the trick of the magic :)
>
> This still doesn't explain what a "slot" is.
>
> I broke (?) something because I didn't see anything that looked
> relevant that I was changing. But now I see it:
>
> - .insn_size = MAX_INSN_SIZE,
> + .insn_size = KPROBE_INSN_SLOT_SIZE,
>
> Would it make sense to clean this up? insn_size isn't the size of an
> instruction at all -- it's the size of a kprobe jump target in units
> of sizeof(kprobe_opcode_t).
>
> How about renaming insn_size to something sensible (and maybe
> specifying the size in *bytes*)?
Ah, I see what you meant. Indeed, ".insn_size" is very easy to mislead, which
is the size of code buffer. At least it should be "insn_slot_size".
Since the code on the buffer(slot) must be executable, we need to use
module_alloc. That is why I introduced new allocation logic, and named it
"slot" for each part of the buffer, since module_alloc allocates pages not
a slab object.
Anyway, I'll rename it.
Thank you!
--
Masami HIRAMATSU
Linux Technology Research Center, System Productivity Research Dept.
Center for Technology Innovation - Systems Engineering
Hitachi, Ltd., Research & Development Group
E-mail: masami.hiramatsu.pt@hitachi.com
next prev parent reply other threads:[~2015-06-02 21:43 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-01 16:32 [PATCH 0/2] kprobes/x86: Allow "boost" for 10- and 11-byte instructions Eugene Shatokhin
2015-06-01 16:32 ` [PATCH 1/2] kprobes/x86: boost: Fix checking if there is enough room for a jump Eugene Shatokhin
2015-06-01 21:51 ` Masami Hiramatsu
2015-06-01 16:32 ` [PATCH 2/2] kprobes/x86: Use 16 bytes for each instruction slot again Eugene Shatokhin
2015-06-01 17:04 ` Andy Lutomirski
2015-06-01 21:49 ` Masami Hiramatsu
2015-06-01 21:57 ` Andy Lutomirski
2015-06-02 21:42 ` Masami Hiramatsu [this message]
2015-06-02 5:44 ` Ingo Molnar
2015-06-02 21:46 ` Masami Hiramatsu
2015-06-02 21:55 ` Andy Lutomirski
2015-06-04 21:59 ` Masami Hiramatsu
2015-06-03 7:28 ` Ingo Molnar
2015-06-01 21:58 ` Masami Hiramatsu
2015-06-02 5:47 ` Ingo Molnar
2015-06-01 21:44 ` [PATCH 0/2] kprobes/x86: Allow "boost" for 10- and 11-byte instructions Masami Hiramatsu
2015-06-03 7:54 ` [PATCH v2 2/2] kprobes/x86: Use 16 bytes for each instruction slot again Eugene Shatokhin
2015-06-04 14:42 ` Jeff Epler
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=556E2359.7050305@hitachi.com \
--to=masami.hiramatsu.pt@hitachi.com \
--cc=eugene.shatokhin@rosalab.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mingo@kernel.org \
--cc=mingo@redhat.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