[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC] xen/arm64: livepatch: enable attaching callbacks


  • To: andrew.cooper3@xxxxxxxxxx
  • From: Ryo Takakura <takakura@xxxxxxxxxxxxx>
  • Date: Wed, 1 Jul 2026 18:11:23 +0900
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=valinux.co.jp; dmarc=pass action=none header.from=valinux.co.jp; dkim=pass header.d=valinux.co.jp; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Lw8adwinFUP4ZxnfUnxkGTnsKQin0zV3wPPajUUvSSg=; b=raONHWeUjfgxZ62CoEVSV7DmipmNjMtvoRxoCU+oCaFyWY0yRgPuq6QsNGgmJz7mvfxVOefSi5lDn8IiyBs3Nx8vGCxpFVBMqmlbhjq8aqn2dV8y/fPFwZFk1FCColZSiNaISYAPtWhevSO2R9E3ukiXW7rrwd5xepSeHt9qmsw1hkFEwWem3G4R7EOXOTSXBKIdCJOVeHsWV8Zwvtla2fXtNxvBak2qTuefF1ImSxOdp5es8d4RrTM471znX8xB9g8lRG1+xMBPOie01QTwbkJhTtqzBS0aPmL77KdFqdjFc5TjaNrDsztUMIujjd39Q930vmBh+drNBB8atimu5A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CT41lXqD5OHiVwGeebk41nIfKTrw3JOzr0a5uPthT5RTrIflG6rH1oF4P846KWM0iRhkGUoXLqKy0/5495GQfdD9vJR15XG9KZAbx5rQJJJmhhbA1l/OXFQa3IfR/0UWKaPPebFcSEMQLgUQHAIEdn1z14xlJvmiixRIq6+E5l4vgpFzxgUcEpNGWKImJyrg24rfYJdONiEaeP1vqXtQR5ruY1z5JScRWoClNo1kmj74aVvx3dVzIdUyl8o/xAtb7wjIJTP5SfJcYwqjbqLDPCmerF/2bb1562pkt7PBH1l5vcPVohOvZtzKDzIGBDig1uOuMyPFYlqOi9ZjEsMk/g==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=valinux.co.jp header.i="@valinux.co.jp" header.h="From:Date:Subject:Message-Id:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=valinux.co.jp;
  • Cc: roger.pau@xxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx, ross.lagerwall@xxxxxxxxxx, sstabellini@xxxxxxxxxx, julien@xxxxxxx, bertrand.marquis@xxxxxxx, michal.orzel@xxxxxxx, Volodymyr_Babchuk@xxxxxxxx, anthony.perard@xxxxxxxxxx, jbeulich@xxxxxxxx, taka@xxxxxxxxxxxxx, den@xxxxxxxxxxxxx
  • Delivery-date: Wed, 01 Jul 2026 09:11:32 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi Andrew,

On Tue, 30 Jun 2026 10:57:38 +0000, Andrew Cooper wrote:
>On 30/06/2026 11:43 am, Ryo Takakura wrote:
>>>> diff --git a/xen/arch/arm/arm64/livepatch.c 
>>>> b/xen/arch/arm/arm64/livepatch.c
>>>> index e135bd5bf9..b7c9aba94e 100644
>>>> --- a/xen/arch/arm/arm64/livepatch.c
>>>> +++ b/xen/arch/arm/arm64/livepatch.c
>>>> @@ -34,12 +57,87 @@ void arch_livepatch_apply(const struct livepatch_func
>>>> *func,
>>>>      /* Save old ones. */
>>>>      memcpy(state->insn_buffer, func->old_addr, len);
>>>>
>>>> -    if ( func->new_addr )
>>>> +    if ( !func->new_addr )
>>>> +    {
>>>> +        insn = aarch64_insn_gen_nop();
>>>> +    }
>>>> +    else if ( func->trampoline_buf )
>>>> +    {
>>>> +        int rc;
>>>> +        uint32_t *trampoline = func->trampoline_buf;
>>>> +        uint32_t *tp = trampoline;
>>>> +        void *orig_cont_addr = (void *)func->old_addr + len;
>>>> +        unsigned int trampoline_code_size = len + 12 * 
>>>> ARCH_PATCH_INSN_SIZE;
>>>> +        unsigned long trampoline_start = (unsigned long)trampoline &
>>>> PAGE_MASK;
>>>> +        unsigned long trampoline_end =
>>>> +            PAGE_ALIGN((unsigned long)trampoline + trampoline_code_size);
>>>> +
>>>> +        /*
>>>> +         * Make the payload text area writeable while generating
>>>> +         * the trampoline instructions.
>>>> +         */
>>>> +        rc = modify_xen_mappings(trampoline_start, trampoline_end,
>>>> +                                 PAGE_HYPERVISOR);
>>>> +        if ( rc )
>>>> +        {
>>>> +            printk(XENLOG_ERR LIVEPATCH
>>>> +                   "Failed to make trampoline writable: %d\n", rc);
>>>> +            return;
>>>> +        }
>>> This ought not to be necessary.
>>>
>>> The trampoline is executable code, so should have space reserved for it
>>> in .text of the livepatch.
>>>
>>> Then, you can identify it simply by references in a new section, without
>>> having to have a pointer with a sentinel value (void *)1 in (which MISRA
>>> will have a fit at).
>> I like this idea as well! I'll try this together with the earlier
>> suggestion using __attribute__((no_caller_saved_registers)).
>
>If you reserve space in the function preamble, and use
>__attribute__((no_caller_saved_registers)), then you don't need
>trampolines at all.
>
>The preamble just needs to turn into `call newfunc` when the callback
>function is attached, and then it's regular return will do the right thing.

Understood!

Sincerely,
Ryo Takakura

>~Andrew



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.