From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: xen-devel@lists.xenproject.org, konrad@kernel.org,
ross.lagerwall@citrix.com
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Julien Grall <julien.grall@arm.com>,
Stefano Stabellini <sstabellini@kernel.org>,
Jan Beulich <jbeulich@suse.com>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Subject: [PATCH v4 6/9] livepatch: Add parsing for the symbol+0x<offset>
Date: Tue, 23 Aug 2016 22:22:09 -0400 [thread overview]
Message-ID: <1472005332-32207-7-git-send-email-konrad.wilk@oracle.com> (raw)
In-Reply-To: <1472005332-32207-1-git-send-email-konrad.wilk@oracle.com>
in case we want to patch at specific offsets inside
a function. (for example if we want to do NOP patching).
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Ross Lagerwall <ross.lagerwall@citrix.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Julien Grall <julien.grall@arm.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
v3: First submission
v4: Drop the /<len> part of the symbol.
---
docs/misc/livepatch.markdown | 2 +-
xen/common/livepatch.c | 32 ++++++++++++++++++++++++++++++--
xen/include/xen/livepatch.h | 1 +
3 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/docs/misc/livepatch.markdown b/docs/misc/livepatch.markdown
index 89c1050..7e82047 100644
--- a/docs/misc/livepatch.markdown
+++ b/docs/misc/livepatch.markdown
@@ -312,7 +312,7 @@ The size of the structure is 64 bytes on 64-bit hypervisors. It will be
* `name` is the symbol name of the old function. Only used if `old_addr` is
zero, otherwise will be used during dynamic linking (when hypervisor loads
- the payload).
+ the payload). The format can be _symbol_ or _symbol+0x<offset>_.
* `old_addr` is the address of the function to be patched and is filled in at
payload generation time if hypervisor function address is known. If unknown,
diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c
index e5968a7..c234424 100644
--- a/xen/common/livepatch.c
+++ b/xen/common/livepatch.c
@@ -237,13 +237,34 @@ static const char *livepatch_symbols_lookup(unsigned long addr,
static int resolve_old_address(struct livepatch_func *f,
const struct livepatch_elf *elf)
{
+ const char *s;
+ char *plus = NULL;
+ unsigned long offset = 0;
+
if ( f->old_addr )
return 0;
- f->old_addr = (void *)symbols_lookup_by_name(f->name);
+ s = f->name;
+ /* +<offset> */
+ plus = strchr(f->name, '+');
+ if ( plus )
+ {
+ const char *endp = NULL;
+
+ offset = simple_strtoul(plus + 1, &endp, 16);
+
+ if ( *endp != '\0' )
+ return -EINVAL;
+
+ /* So that symbol lookup works. */
+ *plus = '\0';
+ s = f->name;
+ }
+
+ f->old_addr = (void *)symbols_lookup_by_name(s);
if ( !f->old_addr )
{
- f->old_addr = (void *)livepatch_symbols_lookup_by_name(f->name);
+ f->old_addr = (void *)livepatch_symbols_lookup_by_name(s);
if ( !f->old_addr )
{
dprintk(XENLOG_ERR, LIVEPATCH "%s: Could not resolve old address of %s\n",
@@ -251,6 +272,13 @@ static int resolve_old_address(struct livepatch_func *f,
return -ENOENT;
}
}
+
+ if ( plus )
+ {
+ *plus = '+';
+ f->old_addr += offset;
+ }
+
dprintk(XENLOG_DEBUG, LIVEPATCH "%s: Resolved old address %s => %p\n",
elf->name, f->name, f->old_addr);
diff --git a/xen/include/xen/livepatch.h b/xen/include/xen/livepatch.h
index 02f4572..2e64686 100644
--- a/xen/include/xen/livepatch.h
+++ b/xen/include/xen/livepatch.h
@@ -44,6 +44,7 @@ unsigned long livepatch_symbols_lookup_by_name(const char *symname);
bool_t is_patch(const void *addr);
/* Arch hooks. */
+int arch_verify_insn_length(unsigned long len);
int arch_livepatch_verify_elf(const struct livepatch_elf *elf);
int arch_livepatch_perform_rel(struct livepatch_elf *elf,
const struct livepatch_elf_sec *base,
--
2.4.11
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-08-24 2:22 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-24 2:22 [PATCH v4] Livepatch fixes and features for v4.8 Konrad Rzeszutek Wilk
2016-08-24 2:22 ` [PATCH v4 1/9] livepatch: Clear .bss when payload is reverted Konrad Rzeszutek Wilk
2016-08-24 8:55 ` Jan Beulich
2016-08-25 16:08 ` Andrew Cooper
2016-09-06 16:51 ` Konrad Rzeszutek Wilk
2016-09-07 9:18 ` Jan Beulich
2016-09-06 16:47 ` Konrad Rzeszutek Wilk
2016-09-07 8:02 ` Jan Beulich
2016-09-08 9:25 ` Konrad Rzeszutek Wilk
2016-09-09 13:33 ` Ross Lagerwall
2016-09-09 13:50 ` Konrad Rzeszutek Wilk
2016-09-09 13:58 ` Ross Lagerwall
2016-09-09 15:28 ` Jan Beulich
2016-08-24 2:22 ` [PATCH v4 2/9] livepatch: Deal with payloads without any .text Konrad Rzeszutek Wilk
2016-08-24 2:22 ` [PATCH v4 3/9] version/livepatch: Move xen_build_id_check to version.h Konrad Rzeszutek Wilk
2016-08-24 2:22 ` [PATCH v4 4/9] version: Print build-id at bootup Konrad Rzeszutek Wilk
2016-08-24 8:58 ` Jan Beulich
2016-09-06 16:57 ` Konrad Rzeszutek Wilk
2016-09-07 8:03 ` Jan Beulich
2016-09-09 13:37 ` Ross Lagerwall
2016-08-24 2:22 ` [PATCH v4 5/9] livepatch: Move code from prepare_payload to own routine Konrad Rzeszutek Wilk
2016-08-25 16:02 ` Ross Lagerwall
2016-08-24 2:22 ` Konrad Rzeszutek Wilk [this message]
2016-08-24 9:08 ` [PATCH v4 6/9] livepatch: Add parsing for the symbol+0x<offset> Jan Beulich
2016-09-06 19:56 ` Konrad Rzeszutek Wilk
2016-09-07 8:10 ` Jan Beulich
2016-09-08 9:22 ` Konrad Rzeszutek Wilk
2016-09-08 10:01 ` Jan Beulich
2016-09-09 14:28 ` Ross Lagerwall
2016-08-24 2:22 ` [PATCH v4 7/9] livepatch: NOP if func->new_[addr] is zero Konrad Rzeszutek Wilk
2016-08-24 9:13 ` Jan Beulich
2016-09-06 20:05 ` Konrad Rzeszutek Wilk
2016-09-07 8:13 ` Jan Beulich
2016-08-24 2:22 ` [PATCH v4 8/9] symbols: Generate an xen-sym.map Konrad Rzeszutek Wilk
2016-08-24 9:16 ` Jan Beulich
2016-09-09 13:43 ` Ross Lagerwall
2016-08-24 2:22 ` [PATCH v4 9/9] livepach: Add .livepatch.hooks functions and test-case Konrad Rzeszutek Wilk
2016-09-06 17:22 ` Konrad Rzeszutek Wilk
2016-09-06 18:25 ` Andrew Cooper
2016-09-08 1:18 ` Konrad Rzeszutek Wilk
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=1472005332-32207-7-git-send-email-konrad.wilk@oracle.com \
--to=konrad.wilk@oracle.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=julien.grall@arm.com \
--cc=konrad@kernel.org \
--cc=ross.lagerwall@citrix.com \
--cc=sstabellini@kernel.org \
--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).