From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Ross Lagerwall <ross.lagerwall@citrix.com>,
Julien Grall <julien.grall@arm.com>,
Stefano Stabellini <sstabellini@kernel.org>,
Jan Beulich <JBeulich@suse.com>,
Xen-devel <xen-devel@lists.xen.org>
Subject: Re: [PATCH 1/2] xen/livepatch: Clean up arch relocation handling
Date: Wed, 14 Jun 2017 09:44:07 -0400 [thread overview]
Message-ID: <20170614134407.GA15061@char.us.oracle.com> (raw)
In-Reply-To: <1497387096-19058-1-git-send-email-andrew.cooper3@citrix.com>
On Tue, Jun 13, 2017 at 09:51:35PM +0100, Andrew Cooper wrote:
> * Reduce symbol scope and initalisation as much as possible
> * Annotate a fallthrough case in arm64
> * Fix switch statement style in arm32
>
> No functional change.
>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> CC: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> CC: Ross Lagerwall <ross.lagerwall@citrix.com>
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Stefano Stabellini <sstabellini@kernel.org>
> CC: Julien Grall <julien.grall@arm.com>
>
> The purpose of this patch is simply to make the following patch easier to
> review.
> ---
> xen/arch/arm/arm32/livepatch.c | 27 ++++++++++++---------------
> xen/arch/arm/arm64/livepatch.c | 19 +++++++------------
> xen/arch/x86/livepatch.c | 13 +++++--------
> 3 files changed, 24 insertions(+), 35 deletions(-)
>
> diff --git a/xen/arch/arm/arm32/livepatch.c b/xen/arch/arm/arm32/livepatch.c
> index a7fd5e2..a328179 100644
> --- a/xen/arch/arm/arm32/livepatch.c
> +++ b/xen/arch/arm/arm32/livepatch.c
> @@ -224,21 +224,21 @@ int arch_livepatch_perform(struct livepatch_elf *elf,
> const struct livepatch_elf_sec *rela,
> bool use_rela)
> {
> - const Elf_RelA *r_a;
> - const Elf_Rel *r;
> - unsigned int symndx, i;
> - uint32_t val;
> - void *dest;
> + unsigned int i;
> int rc = 0;
>
> for ( i = 0; i < (rela->sec->sh_size / rela->sec->sh_entsize); i++ )
> {
> + unsigned int symndx;
> + uint32_t val;
> + void *dest;
> unsigned char type;
> - s32 addend = 0;
> + s32 addend;
>
> if ( use_rela )
> {
> - r_a = rela->data + i * rela->sec->sh_entsize;
> + const Elf_RelA *r_a = rela->data + i * rela->sec->sh_entsize;
> +
> symndx = ELF32_R_SYM(r_a->r_info);
> type = ELF32_R_TYPE(r_a->r_info);
> dest = base->load_addr + r_a->r_offset; /* P */
> @@ -246,10 +246,12 @@ int arch_livepatch_perform(struct livepatch_elf *elf,
> }
> else
> {
> - r = rela->data + i * rela->sec->sh_entsize;
> + const Elf_Rel *r = rela->data + i * rela->sec->sh_entsize;
> +
> symndx = ELF32_R_SYM(r->r_info);
> type = ELF32_R_TYPE(r->r_info);
> dest = base->load_addr + r->r_offset; /* P */
> + addend = get_addend(type, dest);
> }
>
> if ( symndx > elf->nsym )
> @@ -259,13 +261,11 @@ int arch_livepatch_perform(struct livepatch_elf *elf,
> return -EINVAL;
> }
>
> - if ( !use_rela )
> - addend = get_addend(type, dest);
This was added right after the symndx > elf->nsym check as
way to make sure we won't dereference the dest (b/c the symbol
may be outside the bounds).
> -
> val = elf->sym[symndx].sym->st_value; /* S */
>
> rc = perform_rel(type, dest, val, addend);
> - switch ( rc ) {
> + switch ( rc )
> + {
> case -EOVERFLOW:
> dprintk(XENLOG_ERR, LIVEPATCH "%s: Overflow in relocation %u in %s for %s!\n",
> elf->name, i, rela->name, base->name);
> @@ -275,9 +275,6 @@ int arch_livepatch_perform(struct livepatch_elf *elf,
> dprintk(XENLOG_ERR, LIVEPATCH "%s: Unhandled relocation #%x\n",
> elf->name, type);
> break;
> -
> - default:
> - break;
> }
>
> if ( rc )
> diff --git a/xen/arch/arm/arm64/livepatch.c b/xen/arch/arm/arm64/livepatch.c
> index dae64f5..63929b1 100644
> --- a/xen/arch/arm/arm64/livepatch.c
> +++ b/xen/arch/arm/arm64/livepatch.c
> @@ -241,19 +241,16 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
> const struct livepatch_elf_sec *base,
> const struct livepatch_elf_sec *rela)
> {
> - const Elf_RelA *r;
> - unsigned int symndx, i;
> - uint64_t val;
> - void *dest;
> - bool_t overflow_check;
> + unsigned int i;
>
> for ( i = 0; i < (rela->sec->sh_size / rela->sec->sh_entsize); i++ )
> {
> + const Elf_RelA *r = rela->data + i * rela->sec->sh_entsize;
> + unsigned int symndx = ELF64_R_SYM(r->r_info);
> + void *dest = base->load_addr + r->r_offset; /* P */
> + bool overflow_check = true;
> int ovf = 0;
> -
> - r = rela->data + i * rela->sec->sh_entsize;
> -
> - symndx = ELF64_R_SYM(r->r_info);
> + uint64_t val;
>
> if ( symndx > elf->nsym )
> {
> @@ -262,11 +259,8 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
> return -EINVAL;
> }
>
> - dest = base->load_addr + r->r_offset; /* P */
> val = elf->sym[symndx].sym->st_value + r->r_addend; /* S+A */
>
> - overflow_check = true;
> -
> /* ARM64 operations at minimum are always 32-bit. */
> if ( r->r_offset >= base->sec->sh_size ||
> (r->r_offset + sizeof(uint32_t)) > base->sec->sh_size )
> @@ -403,6 +397,7 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
>
> case R_AARCH64_ADR_PREL_PG_HI21_NC:
> overflow_check = false;
> + /* Fallthrough. */
> case R_AARCH64_ADR_PREL_PG_HI21:
> ovf = reloc_insn_imm(RELOC_OP_PAGE, dest, val, 12, 21,
> AARCH64_INSN_IMM_ADR);
OK, that part is fine.
> diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c
> index dd50dd1..7917610 100644
> --- a/xen/arch/x86/livepatch.c
> +++ b/xen/arch/x86/livepatch.c
> @@ -161,16 +161,14 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
> const struct livepatch_elf_sec *base,
> const struct livepatch_elf_sec *rela)
> {
> - const Elf_RelA *r;
> - unsigned int symndx, i;
> - uint64_t val;
> - uint8_t *dest;
> + unsigned int i;
>
> for ( i = 0; i < (rela->sec->sh_size / rela->sec->sh_entsize); i++ )
> {
> - r = rela->data + i * rela->sec->sh_entsize;
> -
> - symndx = ELF64_R_SYM(r->r_info);
> + const Elf_RelA *r = rela->data + i * rela->sec->sh_entsize;
> + unsigned int symndx = ELF64_R_SYM(r->r_info);
> + uint8_t *dest = base->load_addr + r->r_offset;
> + uint64_t val;
>
> if ( symndx > elf->nsym )
> {
> @@ -179,7 +177,6 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
> return -EINVAL;
> }
>
> - dest = base->load_addr + r->r_offset;
> val = r->r_addend + elf->sym[symndx].sym->st_value;
>
> switch ( ELF64_R_TYPE(r->r_info) )
And this is fine too.
> --
> 2.1.4
>
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-06-14 13:44 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-13 20:51 [PATCH 1/2] xen/livepatch: Clean up arch relocation handling Andrew Cooper
2017-06-13 20:51 ` [PATCH 2/2] xen/livepatch: Don't crash on encountering STN_UNDEF relocations Andrew Cooper
2017-06-13 21:13 ` Andrew Cooper
2017-06-14 10:03 ` Jan Beulich
2017-06-14 10:11 ` Jan Beulich
2017-06-14 10:13 ` Andrew Cooper
2017-06-14 10:24 ` Jan Beulich
2017-06-14 14:18 ` Konrad Rzeszutek Wilk
2017-06-14 18:33 ` Andrew Cooper
2017-06-14 18:49 ` Jan Beulich
2017-06-19 18:30 ` Konrad Rzeszutek Wilk
2017-06-19 23:05 ` Andrew Cooper
2017-06-20 7:15 ` Jan Beulich
2017-06-20 13:30 ` Konrad Rzeszutek Wilk
2017-06-14 19:08 ` Konrad Rzeszutek Wilk
2017-06-21 18:13 ` [PATCH for-4.9 v2] " Andrew Cooper
2017-06-22 1:26 ` Konrad Rzeszutek Wilk
2017-06-22 15:27 ` Konrad Rzeszutek Wilk
2017-06-22 16:10 ` Konrad Rzeszutek Wilk
2017-06-22 16:33 ` Konrad Rzeszutek Wilk
2017-06-22 17:05 ` Konrad Rzeszutek Wilk
2017-06-23 9:44 ` Jan Beulich
2017-06-22 7:40 ` Jan Beulich
2017-06-22 9:49 ` Ross Lagerwall
2017-06-14 9:25 ` [PATCH 1/2] xen/livepatch: Clean up arch relocation handling Jan Beulich
2017-06-14 13:44 ` Konrad Rzeszutek Wilk [this message]
2017-06-14 14:02 ` Jan Beulich
2017-06-14 18:28 ` Andrew Cooper
2017-06-19 18:18 ` Konrad Rzeszutek Wilk
2017-06-20 7:36 ` Jan Beulich
2017-06-20 7:39 ` Andrew Cooper
2017-06-20 7:41 ` Andrew Cooper
2017-06-20 7:56 ` Jan Beulich
2017-06-20 13:36 ` Konrad Rzeszutek Wilk
2017-06-22 1:27 ` Is [PATCH for-4.9] Was:Re: " 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=20170614134407.GA15061@char.us.oracle.com \
--to=konrad.wilk@oracle.com \
--cc=JBeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=julien.grall@arm.com \
--cc=ross.lagerwall@citrix.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xen.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).