xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@arm.com>
To: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	konrad@kernel.org, xen-devel@lists.xenproject.org,
	ross.lagerwall@citrix.com, sstabellini@kernel.org
Subject: Re: [PATCH v5 14/16] livepatch: Initial ARM32 support.
Date: Tue, 27 Sep 2016 09:39:06 -0700	[thread overview]
Message-ID: <829630b3-e7ca-b62d-d3a1-7742d64fcc05@arm.com> (raw)
In-Reply-To: <1474479154-20991-15-git-send-email-konrad.wilk@oracle.com>

Hi Konrad,

On 21/09/2016 10:32, Konrad Rzeszutek Wilk wrote:
> The patch piggybacks on: livepatch: Initial ARM64 support, which
> brings up all of the necessary livepatch infrastructure pieces in.
>
> This patch adds three major pieces:
>
>  1) ELF relocations. ARM32 uses SHT_REL instead of SHT_RELA which
>     means the adddendum had to be extracted from within the
>     instruction. Which required parsing BL/BLX, B/BL<cond>,
>     MOVT, and MOVW instructions.
>
>     The code was written from scratch using the ARM ELF manual
>     (and the ARM Architecture Reference Manual)
>
>  2) Inserting an trampoline. We use the B (branch to address)
>     which uses an offset that is based on the PC value: PC + imm32.
>     Because we insert the branch at the start of the old function
>     we have to account for the instruction already being fetched
>     and subtract -8 from the delta (new_addr - old_addr). See
>     ARM DDI 0406C.c, see A2.3 (pg 45) and A8.8.18 pg (pg 334,335)
>
>  3) Allows the test-cases to be built under ARM 32.
>     The "livepatch: tests: Make them compile under ARM64"
>     put in the right infrastructure for it and we piggyback on it.
>
> Acked-by: Julien Grall <julien.grall@arm.com>
> Acked-by: Jan Beulich <jbeulich@suse.com> [for non-ARM parts]
> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> ---
> Cc: Julien Grall <julien.grall@arm.com>
> Cc: Stefano Stabellini <sstabellini@kernel.org>
>
> v2: First submission.
> v3: Use LIVEPATCH_ARCH_RANGE instead of NEGATIVE_32MB macro
>    -Use PATCH_INSN_SIZE instead of the value 4.
>    -Ditch the old_ptr local variable.
>    -Use 8 for evaluating the branch instead of 4. Based on ARM docs.
>    -NOP patch up to sizeof(opaque) % PATCH_INSN_SIZE (so 7 instructions).
>    -Don't mask 0x00FFFFF_E_ after shifting, instead mask by 0x00FFFFF_F_.
>     The reason is that offset is constructed by shifting by two the insn
>     (except the first two bytes) by left which meant we would have cleared
>     offset[2]! - and jumped to a location that was -4 bytes off.
>    -Update commit description to have -8 instead of -4 delta and also
>     include reference to spec.
> v4: Added Jan's Ack.
>    s/PATCH_INSN_SIZE/ARCH_PATCH_INSN_SIZE/
>    s/arch_livepatch_insn_len/livepatch_insn_len/
>    s/LIVEPATCH_ARCH_RANGE/ARCH_LIVEPATCH_RANGE/
> v5: Added Julien's Ack.

IHMO my ack should not have been retained given that ...

>    - Rebased on "livepatch: Drop _jmp from arch_livepatch_[apply,revert]_jmp"
>    - Added explanation for the usage of data cache and why we need to sync it.

... you also replace the clean_and_invalidate to the old_ptr by 
clean_and_invalidate to the new_ptr.

> diff --git a/xen/arch/arm/arm32/livepatch.c b/xen/arch/arm/arm32/livepatch.c
> index 80f9646..3f47326 100644
> --- a/xen/arch/arm/arm32/livepatch.c
> +++ b/xen/arch/arm/arm32/livepatch.c
> @@ -3,28 +3,303 @@
>   */
>
>  #include <xen/errno.h>
> +#include <xen/kernel.h>
>  #include <xen/lib.h>
>  #include <xen/livepatch_elf.h>
>  #include <xen/livepatch.h>
>
> +#include <asm/page.h>
> +#include <asm/livepatch.h>
> +
>  void arch_livepatch_apply(struct livepatch_func *func)
>  {

[...]

> +    /*
> +    * When we upload the payload, it will go through the data cache
> +    * (the region is cacheable). Until the data cache is cleaned, the data
> +    * may not reach the memory. And in the case the data and instruction cache
> +    * are separated, we may read invalid instruction from the memory because
> +    * the data cache have not yet synced with the memory. Hence sync it.
> +    */
> +    if ( func->new_addr )
> +        clean_and_invalidate_dcache_va_range(func->new_addr, func->new_size);

The clean_and_invalidate on the new_ptr needs to be add back here and ...

>  }
>
>  void arch_livepatch_revert(const struct livepatch_func *func)
>  {
> +    uint32_t *new_ptr;
> +    unsigned int i, len;
> +
> +    new_ptr = func->old_addr - (void *)_start + vmap_of_xen_text;
> +    len = livepatch_insn_len(func) / sizeof(uint32_t);
> +    for ( i = 0; i < len; i++ )
> +    {
> +        uint32_t insn;
> +
> +        memcpy(&insn, func->opaque + (i * sizeof(uint32_t)), ARCH_PATCH_INSN_SIZE);
> +        /* PATCH! */
> +        *(new_ptr + i) = insn;
> +    }

here. See the comments on the ARM64 part (i.e patch #5).

>  }

Regards,

-- 
Julien Grall

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  reply	other threads:[~2016-09-27 16:39 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-21 17:32 [PATCH v5] Livepatch for ARM 64 and 32 Konrad Rzeszutek Wilk
2016-09-21 17:32 ` [PATCH v5 01/16] arm64: s/ALTERNATIVE/HAS_ALTERNATIVE/ Konrad Rzeszutek Wilk
2016-09-22 12:21   ` Julien Grall
2016-09-21 17:32 ` [PATCH v5 02/16] arm/x86/common: Add HAS_[ALTERNATIVE|EX_TABLE] Konrad Rzeszutek Wilk
2016-09-22 12:23   ` Julien Grall
2016-09-22 15:30   ` Ross Lagerwall
2016-09-21 17:32 ` [PATCH v5 03/16] livepatch: Reject payloads with .alternative or .ex_table if support is not built-in Konrad Rzeszutek Wilk
2016-09-23 12:47   ` Ross Lagerwall
2016-09-21 17:32 ` [PATCH v5 04/16] arm: poison initmem when it is freed Konrad Rzeszutek Wilk
2016-09-22 12:28   ` Julien Grall
2016-09-21 17:32 ` [PATCH v5 05/16] livepatch: Initial ARM64 support Konrad Rzeszutek Wilk
2016-09-22 12:49   ` Julien Grall
2016-09-23 13:38   ` Ross Lagerwall
2016-09-23 15:44     ` Konrad Rzeszutek Wilk
2016-09-27 16:42       ` Julien Grall
2016-09-21 17:32 ` [PATCH v5 06/16] livepatch: ARM/x86: Check displacement of old_addr and new_addr Konrad Rzeszutek Wilk
2016-09-22 12:55   ` Julien Grall
2016-09-23 14:36   ` Ross Lagerwall
2016-09-23 15:37     ` Konrad Rzeszutek Wilk
2016-09-23 15:59       ` Konrad Rzeszutek Wilk
2016-09-28 10:21         ` Ross Lagerwall
2016-09-21 17:32 ` [PATCH v5 07/16] livepatch: ARM 32|64: Ignore mapping symbols: $[d, a, x] Konrad Rzeszutek Wilk
2016-09-22 12:56   ` Julien Grall
2016-09-23 14:44   ` Ross Lagerwall
2016-09-23 16:13     ` Konrad Rzeszutek Wilk
2016-09-21 17:32 ` [PATCH v5 08/16] livepatch/arm/x86: Check payload for for unwelcomed symbols Konrad Rzeszutek Wilk
2016-09-22 13:00   ` Julien Grall
2016-09-23  1:29     ` Konrad Rzeszutek Wilk
2016-09-27  8:49       ` Ross Lagerwall
2016-09-23 14:49   ` Ross Lagerwall
2016-09-23 16:15     ` Konrad Rzeszutek Wilk
2016-09-21 17:32 ` [PATCH v5 09/16] livepatch: Move test-cases to their own sub-directory in test Konrad Rzeszutek Wilk
2016-09-22 13:01   ` Julien Grall
2016-09-23 14:51   ` Ross Lagerwall
2016-09-21 17:32 ` [PATCH v5 10/16] livepatch: x86, ARM, alternative: Expose FEATURE_LIVEPATCH Konrad Rzeszutek Wilk
2016-09-22 13:03   ` Julien Grall
2016-09-27  9:49   ` Ross Lagerwall
2016-09-21 17:32 ` [PATCH v5 11/16] livepatch: tests: Make them compile under ARM64 Konrad Rzeszutek Wilk
2016-09-22 13:10   ` Julien Grall
2016-09-22 19:26     ` Konrad Rzeszutek Wilk
2016-09-23  1:33     ` Konrad Rzeszutek Wilk
2016-09-23  9:50       ` Julien Grall
2016-09-27  9:49       ` Ross Lagerwall
2016-09-21 17:32 ` [PATCH v5 12/16] xen/arm32: Add an helper to invalidate all instruction caches Konrad Rzeszutek Wilk
2016-09-22 13:17   ` Julien Grall
2016-09-21 17:32 ` [PATCH v5 13/16] bug/x86/arm: Align bug_frames sections Konrad Rzeszutek Wilk
2016-09-21 17:32 ` [PATCH v5 14/16] livepatch: Initial ARM32 support Konrad Rzeszutek Wilk
2016-09-27 16:39   ` Julien Grall [this message]
2016-09-27 17:50     ` Konrad Rzeszutek Wilk
2016-09-27 23:13       ` Julien Grall
2016-09-21 17:32 ` [PATCH v5 15/16] livepatch, arm[32|64]: Share arch_livepatch_revert Konrad Rzeszutek Wilk
2016-09-23 14:59   ` Ross Lagerwall
2016-09-23 16:15     ` Konrad Rzeszutek Wilk
2016-09-21 17:32 ` [PATCH v5 16/16] livepatch: arm[32, 64], x86: NOP test-case Konrad Rzeszutek Wilk
2016-09-22 13:23   ` Julien Grall
2016-09-23  1:35     ` Konrad Rzeszutek Wilk
2016-09-23  9:53       ` Julien Grall

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=829630b3-e7ca-b62d-d3a1-7742d64fcc05@arm.com \
    --to=julien.grall@arm.com \
    --cc=konrad.wilk@oracle.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).