From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: ross.lagerwall@citrix.com, xen-devel@lists.xenproject.org,
Andrew Cooper <andrew.cooper3@citrix.com>
Subject: Re: [PATCH v3 7/9] livepatch: NOP if func->new_[addr, size] is zero.
Date: Mon, 15 Aug 2016 10:38:31 -0400 [thread overview]
Message-ID: <20160815143831.GJ26970@char.us.oracle.com> (raw)
In-Reply-To: <57B1BCC80200007800105EA1@prv-mh.provo.novell.com>
On Mon, Aug 15, 2016 at 04:59:52AM -0600, Jan Beulich wrote:
> >>> On 14.08.16 at 23:52, <konrad.wilk@oracle.com> wrote:
> > The NOP functionality will NOP any of the code at
> > the 'old_addr' or at 'name' if the 'new_addr' and 'new_size'
> > are both zero. The purpose of this is to NOP out calls, such as:
> >
> > e9 <4-bytes-offset>
>
> Except that E9 is JMP; CALL is E8.
>
> > (5 byte insn), or on ARM a 4 byte insn for branching.
> >
> > We need the EIP of where we need to the NOP, and that can
> > be provided via the `old_addr` or `name`.
> >
> > If the `old_addr` is provided we will NOP
> > 5 instructions (on x86) at that location.
> >
> > If `name` is provided with the symbol+0x<offset/<len>
> > we make sure that <len> is 5 (on x86) and upon retrieving the
> > EIP based on `name` will NOP that location.
>
> So why does this need to be restricted to 5-byte (on x86) code
> blocks? I.e. what's wrong with NOP-ing out other code.
It can most certainly nop variable sizes. I will have to update
the design to make it clear that if 'new_addr' is zero then we will
NOP (and the .new_size will determine the amount of NOPs to sprinkle).
Let me do that along with your comments. Thanks!
>
> > @@ -46,18 +42,27 @@ int arch_livepatch_verify_func(const struct livepatch_func *func)
> >
> > void arch_livepatch_apply_jmp(struct livepatch_func *func)
> > {
> > - int32_t val;
> > uint8_t *old_ptr;
> > + uint8_t insn[PATCH_INSN_SIZE];
> >
> > BUILD_BUG_ON(PATCH_INSN_SIZE > sizeof(func->opaque));
> > - BUILD_BUG_ON(PATCH_INSN_SIZE != (1 + sizeof(val)));
> >
> > old_ptr = func->old_addr;
> > memcpy(func->opaque, old_ptr, PATCH_INSN_SIZE);
> >
> > - *old_ptr++ = 0xe9; /* Relative jump */
> > - val = func->new_addr - func->old_addr - PATCH_INSN_SIZE;
> > - memcpy(old_ptr, &val, sizeof(val));
> > + if ( func->new_size )
> > + {
> > + int32_t val;
> > +
> > + BUILD_BUG_ON(PATCH_INSN_SIZE != (1 + sizeof(val)));
> > +
> > + insn[0] = 0xe9;
> > + val = func->new_addr - func->old_addr - PATCH_INSN_SIZE;
> > + memcpy(&insn[1], &val, sizeof(val));
> > + } else
>
> Style.
>
> > --- a/xen/common/livepatch.c
> > +++ b/xen/common/livepatch.c
> > @@ -561,11 +561,15 @@ static int prepare_payload(struct payload *payload,
> > return -EOPNOTSUPP;
> > }
> >
> > - if ( !f->new_addr || !f->new_size )
> > + /* If both are zero then we are NOPing. */
> > + if ( (!f->new_addr || !f->new_size) )
>
> Comment and condition contradict one another. And you're adding
> unnecessary parentheses.
>
> Jan
>
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-08-15 14:38 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-14 21:52 [PATCH v3] Livepatch fixes and features for v4.8 Konrad Rzeszutek Wilk
2016-08-14 21:52 ` [PATCH v3 1/9] livepatch: Clear .bss when payload is reverted Konrad Rzeszutek Wilk
2016-08-15 10:27 ` Jan Beulich
2016-08-15 14:29 ` Konrad Rzeszutek Wilk
2016-08-15 15:10 ` Jan Beulich
2016-08-19 8:37 ` Ross Lagerwall
2016-08-19 8:42 ` Jan Beulich
2016-08-14 21:52 ` [PATCH v3 2/9] livepatch: Deal with payloads without any .text Konrad Rzeszutek Wilk
2016-08-15 10:28 ` Jan Beulich
2016-08-19 9:31 ` Ross Lagerwall
2016-08-14 21:52 ` [PATCH v3 3/9] version/livepatch: Move xen_build_id_check to version.h Konrad Rzeszutek Wilk
2016-08-15 10:35 ` Jan Beulich
2016-08-19 9:29 ` Ross Lagerwall
2016-08-14 21:52 ` [PATCH v3 4/9] livepatch: Sync cache of build-id before using it first time Konrad Rzeszutek Wilk
2016-08-15 10:38 ` Jan Beulich
2016-08-15 10:46 ` Andrew Cooper
2016-08-15 14:33 ` Konrad Rzeszutek Wilk
2016-08-14 21:52 ` [PATCH v3 5/9] livepatch: Move code from prepare_payload to own routine Konrad Rzeszutek Wilk
2016-08-15 10:41 ` Jan Beulich
2016-08-19 9:37 ` Ross Lagerwall
2016-08-14 21:52 ` [PATCH v3 6/9] livepatch: Add parsing for the symbol+0x<offset>/<len> Konrad Rzeszutek Wilk
2016-08-15 10:53 ` Jan Beulich
2016-08-15 14:35 ` Konrad Rzeszutek Wilk
2016-08-15 15:12 ` Jan Beulich
2016-08-15 15:21 ` Konrad Rzeszutek Wilk
2016-08-14 21:52 ` [PATCH v3 7/9] livepatch: NOP if func->new_[addr, size] is zero Konrad Rzeszutek Wilk
2016-08-15 10:59 ` Jan Beulich
2016-08-15 14:38 ` Konrad Rzeszutek Wilk [this message]
2016-08-14 21:52 ` [PATCH v3 8/9] symbols: Generate an xen-sym.map Konrad Rzeszutek Wilk
2016-08-15 11:02 ` Jan Beulich
2016-08-14 21:52 ` [PATCH v3 9/9] livepach: Add .livepatch.hooks functions and test-case Konrad Rzeszutek Wilk
2016-08-15 11:15 ` Jan Beulich
2016-08-15 14:46 ` Konrad Rzeszutek Wilk
2016-08-15 15:17 ` Jan Beulich
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=20160815143831.GJ26970@char.us.oracle.com \
--to=konrad.wilk@oracle.com \
--cc=JBeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=ross.lagerwall@citrix.com \
--cc=xen-devel@lists.xenproject.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).