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

Re: [PATCH v2 1/4] xen/riscv: add exception table support


  • To: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Wed, 8 Apr 2026 10:45:05 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; 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=88syfBqlfNyzWnKeT6tZhpZjD64F/wZ/ihzykZrB3fI=; b=caejmzAzOIG7geKI+nn+fat1acXtz86faURz1k99JAk8S3rIxGJMBMS3nauqo0lvuVYMRT6pMT+Ayvt5iu4Wo8xEW18h52qbckjTUgVfkcfEPpZTS2L+yMfVVLuzT/2hbfgO/aY1zP3jkE0ChQ6G+sGWQJftYVH/UWxSDqua6m8UnKGDDVqs7QR3npPm+tldyrz/WhdRepXFvt+GrNCM7dZhxiQVjtjw9xjig7a40xtp0fU9RTa1TtmCMTDpfVAryziiHy3mOWpybg1u8qTpyh8MdOZuHApevIPM/aqKPjhcgQ+os4WykXdow1Nmx5AkvA6AXyBGUJ+ox6IMRAIjvg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=belj4vrmHV/oJBbrddtD/ZqwL5sEXuVTQEpaFKclygHxDWCthcfVDkyms/dXjAuY+/YnzgvSZvvryrIvnsfsDvbQpJpLphKiptE4UJYFovk2tCJ7L4emJkI5pIo7X1na/s8fmNyVRvQ37e8jcLOlcnek0DRGZ2tNS+GMdeN7KCxz/GqhZfs6ctPTn+gruPv+oaUzkoeyIe1bPaO4ObsY5OKpo0aCNzwQiiqGqH2bzf9fNfpM8Yt/cTkwdI12g9iYlUH3ibQOrpSlVUsAORrn5ed2w/bePO6ujK4f0tJZePzftJUBeVYxrrstxu0POs1O0bXPYOmW4qDvHVLwy/bx9A==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" 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=citrix.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Romain Caritey <Romain.Caritey@xxxxxxxxxxxxx>, Alistair Francis <alistair.francis@xxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Wed, 08 Apr 2026 09:45:19 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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



 


Rackspace

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