|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v2 1/4] xen/riscv: add exception table support
On 08/04/2026 10:29 am, Oleksii Kurochko wrote:
>
>
> 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.
"insn_a - insn_b" is a very common bug in cmp() functions. It does
cause the sort/search to malfunction when the subtraction overflows.
However, the form you've got (a > b) - (b > a) is a very common correct
form. I'd drop the comment.
~Andrew
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |