From: Oleksii Kurochko <oleksii.kurochko@gmail.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "Romain Caritey" <Romain.Caritey@microchip.com>,
"Alistair Francis" <alistair.francis@wdc.com>,
"Connor Davis" <connojdavis@gmail.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Anthony PERARD" <anthony.perard@vates.tech>,
"Michal Orzel" <michal.orzel@amd.com>,
"Julien Grall" <julien@xen.org>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
xen-devel@lists.xenproject.org
Subject: Re: [PATCH v2 1/4] xen/riscv: add exception table support
Date: Wed, 8 Apr 2026 11:29:02 +0200 [thread overview]
Message-ID: <4ebcb77b-7666-4087-b7c4-07e64260e5de@gmail.com> (raw)
In-Reply-To: <a6c95e44-e324-493d-8e55-532223e56b17@suse.com>
On 4/2/26 8:24 AM, Jan Beulich wrote:
> On 31.03.2026 21:04, Oleksii Kurochko wrote:
>> --- /dev/null
>> +++ b/xen/arch/riscv/extable.c
>> @@ -0,0 +1,85 @@
>> +/* SPDX-License-Identifier: GPL-2.0-only */
>> +
>> +#include <xen/init.h>
>> +#include <xen/bsearch.h>
>> +#include <xen/lib.h>
>> +#include <xen/livepatch.h>
>> +#include <xen/sort.h>
>> +#include <xen/virtual_region.h>
>> +
>> +#include <asm/extable.h>
>> +#include <asm/processor.h>
>> +
>> +#define EX_FIELD(ptr, field) ((unsigned long)&(ptr)->field + (ptr)->field)
>> +
>> +static inline unsigned long ex_insn(const struct exception_table_entry *ex)
>> +{
>> + return EX_FIELD(ex, insn);
>> +}
>> +
>> +static inline unsigned long ex_fixup(const struct exception_table_entry *ex)
>> +{
>> + return EX_FIELD(ex, fixup);
>> +}
>> +
>> +static void __init cf_check swap_ex(void *a, void *b)
>> +{
>> + struct exception_table_entry *x = a, *y = b, tmp;
>> + long delta = b - a;
>> +
>> + tmp = *x;
>> + x->insn = y->insn + delta;
>> + y->insn = tmp.insn - delta;
>> +
>> + x->fixup = y->fixup + delta;
>> + y->fixup = tmp.fixup - delta;
>> +}
>> +
>> +static int cf_check cmp_ex(const void *a, const void *b)
>> +{
>> + const unsigned long insn_a = ex_insn(a);
>> + const unsigned long insn_b = ex_insn(b);
>> +
>> + /* avoid overflow */
>> + return (insn_a > insn_b) - (insn_a < insn_b);
>
> What is the (slightly malformed) comment about? I don't see anything close
> to possibly causing overflow here.
Originally, I thought to imeplement this function something like:
return insn_a - insn_b;
It'd get integer overflow when insn_a is a very small number and insn_b
is very large.
It could drop the comment to avoid confusion.
>
>> --- /dev/null
>> +++ b/xen/arch/riscv/include/asm/extable.h
>> @@ -0,0 +1,58 @@
>> +/* SPDX-License-Identifier: GPL-2.0-only */
>> +
>> +#ifndef ASM__RISCV__ASM_EXTABLE_H
>> +#define ASM__RISCV__ASM_EXTABLE_H
>> +
>> +#ifdef __ASSEMBLER__
>> +
>> +#define ASM_EXTABLE(insn, fixup) \
>> + .pushsection .ex_table, "a"; \
>> + .balign 4; \
>> + .long ((insn) - .); \
>> + .long ((fixup) - .); \
>
> For readability's sake I'm generally advocating for having enough, but
> not more parentheses than necessary. What's the purpose of the outer pair
> here and ...
>
>> + .popsection;
>> +
>> +.macro asm_extable, insn, fixup
>> + ASM_EXTABLE(\insn, \fixup)
>> +.endm
>> +
>> +#else /* __ASSEMBLER__ */
>> +
>> +#include <xen/stringify.h>
>> +#include <xen/types.h>
>> +
>> +struct cpu_user_regs;
>> +
>> +#define ASM_EXTABLE(insn, fixup) \
>> + ".pushsection .ex_table, \"a\"\n" \
>> + ".balign 4\n" \
>> + ".long ((" #insn ") - .)\n" \
>> + ".long ((" #fixup ") - .)\n" \
>
> ... here?
It looked visually better to me but I am okay to drop them.
>
> I'm also uncertain about the use of .long (generally in RISC-V code, and
> really also in some other architectures). Imo, considering suffixes used
> in the instruction set (e.g. load/store insns or OP-32 ones in RV64) .word
> may be the more expressive directive.
Agree, we could use .word instead of .long.
>
> Preferably with the adjustments:
> Acked-by: Jan Beulich <jbeulich@suse.com>
Thanks a lot.
> Happy to carry out while committing, provided you agree.
I would be happy with that.
~ Oleksii
next prev parent reply other threads:[~2026-04-08 9:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 19:04 [PATCH v2 0/4] RISCV: Intrdouce SSTC support in Xen Oleksii Kurochko
2026-03-31 19:04 ` [PATCH v2 1/4] xen/riscv: add exception table support Oleksii Kurochko
2026-04-02 6:24 ` Jan Beulich
2026-04-08 9:29 ` Oleksii Kurochko [this message]
2026-04-08 9:45 ` Andrew Cooper
2026-03-31 19:04 ` [PATCH v2 2/4] xen/riscv: add csr_read_safe() helper Oleksii Kurochko
2026-04-02 6:30 ` Jan Beulich
2026-04-08 9:38 ` Oleksii Kurochko
2026-03-31 19:04 ` [PATCH v2 3/4] xen/riscv: allow Xen to use SSTC while hiding it from guests Oleksii Kurochko
2026-04-02 6:41 ` Jan Beulich
2026-04-08 10:58 ` Oleksii Kurochko
2026-04-08 11:25 ` Jan Beulich
2026-04-08 11:52 ` Oleksii Kurochko
2026-03-31 19:04 ` [PATCH v2 4/4] xen/riscv: init_csr_masks()-related improvements Oleksii Kurochko
2026-04-01 6:19 ` Jan Beulich
2026-04-01 13:39 ` Oleksii Kurochko
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=4ebcb77b-7666-4087-b7c4-07e64260e5de@gmail.com \
--to=oleksii.kurochko@gmail.com \
--cc=Romain.Caritey@microchip.com \
--cc=alistair.francis@wdc.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=connojdavis@gmail.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=roger.pau@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.