All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleksii Kurochko <oleksii.kurochko@gmail.com>
To: Baptiste Le Duc <baptiste.le-duc@vates.tech>
Cc: xen-devel@lists.xenproject.org,
	"Romain Caritey" <Romain.Caritey@microchip.com>,
	"Zheng Zhang" <zhangzheng@iscas.ac.cn>,
	"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>,
	"Jan Beulich" <jbeulich@suse.com>,
	"Julien Grall" <julien@xen.org>,
	"Roger Pau Monné" <roger@xenproject.org>,
	"Stefano Stabellini" <sstabellini@kernel.org>
Subject: Re: [PATCH v3 29/39] xen/riscv: prepare new IMSIC VS-file
Date: Thu, 5 Nov 2026 13:49:37 +0100	[thread overview]
Message-ID: <81b0b1fa-1aa4-4646-bdfa-5e773cb876f4@gmail.com> (raw)
In-Reply-To: <1792760165.8631fc262581453bbf619ec5b2062170.1a168d535ab000f79f@vates.tech>



On 10/23/26 2:55 PM, Baptiste Le Duc wrote:
>> [ ... 64 lines skipped ... ]
>> diff --git a/xen/arch/riscv/aia.c b/xen/arch/riscv/aia.c
>> index e31c9c2d24..229ab4b867 100644
>> --- a/xen/arch/riscv/aia.c
>> +++ b/xen/arch/riscv/aia.c
>> @@ -1,8 +1,10 @@
>>   /* SPDX-License-Identifier: GPL-2.0-only */
>>   
>> +#include <xen/bug.h>
>>   #include <xen/errno.h>
>>   #include <xen/init.h>
>>   #include <xen/sections.h>
>> +#include <xen/sched.h>
> Nit: Why xen/sched.h? The stub doesn't dereference v, and asm/aia.h already
> forward-declares struct vcpu. If it stays: sched < sections, so it goes one
> line up.

Indeed, nothing needs it here. I'll include <asm/aia.h> instead, which
aia.c doesn't include yet: without that the stub's struct vcpu would 
only be declared inside the parameter list. <xen/sched.h> then moves to 
the patch where v gets dereferenced first.

>> [ ... 30 lines skipped ... ]
>> +#define imsic_vs_csr_write(c, v)    \
>> +do {                                \
>> +    csr_write(CSR_VSISELECT, c);    \
>> +    csr_write(CSR_VSIREG, v);       \
>> +} while (0)
>> +
>> +/*
>> + * Leaf macros for the switchcase expansion pyramid below:
>> + * imsic_switchcase_break(ireg, op, v) - emit "case ireg: op(ireg, v); break"
>> + */
>> +#define imsic_switchcase_break(ireg, op, v) \
>> +    case ireg:                              \
>> +        op(ireg, v);                        \
>> +        break
>> +
>> +/*
>> + * Generic switchcase expansion pyramid.
>> + * F is the per-operation leaf macro, ireg is the base register index.
>> + * Extra args (e.g. an operation and/or a value) are forwarded to F via
>> + * __VA_ARGS__.
>> + */
>> +#define imsic_switchcase_2(F, ireg, ...)             \
>> +    F((ireg) + 0, __VA_ARGS__);                      \
>> +    F((ireg) + 1, __VA_ARGS__)
>> +#define imsic_switchcase_4(F, ireg, ...)             \
>> +    imsic_switchcase_2(F, (ireg) + 0, __VA_ARGS__);  \
>> +    imsic_switchcase_2(F, (ireg) + 2, __VA_ARGS__)
>> +#define imsic_switchcase_8(F, ireg, ...)             \
>> +    imsic_switchcase_4(F, (ireg) + 0, __VA_ARGS__);  \
>> +    imsic_switchcase_4(F, (ireg) + 4, __VA_ARGS__)
>> +#define imsic_switchcase_16(F, ireg, ...)            \
>> +    imsic_switchcase_8(F, (ireg) + 0, __VA_ARGS__);  \
>> +    imsic_switchcase_8(F, (ireg) + 8, __VA_ARGS__)
>> +#define imsic_switchcase_32(F, ireg, ...)            \
>> +    imsic_switchcase_16(F, (ireg) + 0, __VA_ARGS__); \
>> +    imsic_switchcase_16(F, (ireg) + 16, __VA_ARGS__)
>> +#define imsic_switchcase_64(F, ireg, ...)            \
>> +    imsic_switchcase_32(F, (ireg) + 0, __VA_ARGS__); \
>> +    imsic_switchcase_32(F, (ireg) + 32, __VA_ARGS__)
>> +
>> +static void imsic_eix_write(unsigned int ireg, unsigned long val)
>> +{
>> +    switch ( ireg )
>> +    {
>> +    imsic_switchcase_64(imsic_switchcase_break, IMSIC_EIP0,
>> +                        imsic_vs_csr_write, val);
>> +    imsic_switchcase_64(imsic_switchcase_break, IMSIC_EIE0,
>> +                        imsic_vs_csr_write, val);
>> +    default:
>> +        ASSERT_UNREACHABLE();
>> +        break;
>> +    }
>> +}
>> +
> What does the switch buy? ireg only ends up as the value written to
> vsiselect, not as a CSR number, so it doesn't need to be a compile-time
> constant. imsic_vs_csr_write(ireg, val) does the same, without the 128 case
> labels and the macro pyramid. If there's a reason, it wants stating in a
> comment; otherwise please drop the pyramid (an ASSERT() on the range can
> stay if you want one).

Good point.

I will drop it and use the following instead:

/*
  * On RV64 a 64-bit EIx group is the even-numbered register alone, 
whereas on
  * RV32 it is split into the even-numbered (low half) and the following
  * odd-numbered (high half) register. ireg names the first, even-numbered
  * register of such a group, among eip0..eip63 or eie0..eie63.
  */
static void imsic_eix_check(unsigned int ireg)
{
     ASSERT(!(ireg & 1));
     ASSERT((ireg >= IMSIC_EIP0 && ireg < IMSIC_EIP0 + 64) ||
            (ireg >= IMSIC_EIE0 && ireg < IMSIC_EIE0 + 64));
}

/* Write a whole 64-bit EIx group, laid out as described above. */
static void imsic_eix_write64(unsigned int ireg, uint64_t val)
{
     imsic_eix_check(ireg);
     imsic_vs_csr_write(ireg, val);
     if ( IS_ENABLED(CONFIG_RISCV_32) )
         imsic_vs_csr_write(ireg + 1, val >> 32);
}

I will applt the similar patter to other patches where the pyramid was used.


> 
> Typo (only if the macros stay): "Leaf macros" - there's only one here. And
> `case ireg:` / `op(ireg, v)` as well as c and v in imsic_vs_csr_write()
> want parenthesizing (MISRA 20.7).

As to c and v in imsic_vs_csr_write(): they're passed as whole arguments
to csr_write() and the other csr_*() macros, which is covered by the
R20.7 deviation for macro parameters used as macro arguments. That's 
also why the parentheses were dropped in v3.

>> [ ... 67 lines skipped ... ]
>> +static void cf_check imsic_vsfile_local_clear(void *data)
>> +{
>> +    unsigned int i;
>> +    const struct imsic_vsfile_data *idata = data;
>> +    unsigned long new_hstatus, old_hstatus, old_vsiselect;
>> +
>> +    /* We can only zero-out if we have a IMSIC VS-file */
> Typo: s/a IMSIC/an IMSIC/
>> [ ... 31 lines skipped ... ]
>>   void imsic_migrate_vcpu(struct vcpu *v)
>>   {
>> +    struct imsic_vsfile_data vsfile_data = {
>> +        .nr_eix = imsic_cfg.nr_eix,
>> +    };
>> +
>>       /*
>>        * The scheduler can mark a freshly created vCPU's unit as migrated and
>>        * invoke this before the vCPU has ever run (see the migrated branch in
>> @@ -703,5 +849,18 @@ void imsic_migrate_vcpu(struct vcpu *v)
>>       if ( v->arch.last_cpu == CPU_NONE )
>>           return;
>>   
>> +    /*
>> +     * At this point, all interrupt producers are still using the old IMSIC
>> +     * VS-file.
>> +     */
>> +
>> +    vsfile_data.hgei = vgein_assign(v);
>> +
>> +    /* We don't support SW interrupt files at the moment. */
>> +    BUG_ON(!vsfile_data.hgei);
>> +
>> +    /* Zero-out new IMSIC VS-file */
>> +    imsic_call_on_cpu(v->processor, imsic_vsfile_local_clear, &vsfile_data);
> Nit: The comment restates the call; drop it.
> 

Agreed, I will drop.

Thanks!

~ Oleksii




  reply	other threads:[~2026-11-05 12:50 UTC|newest]

Thread overview: 152+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 16:18 [PATCH v3 00/39] [PATCH v2 00/39] [RISC-V] virtual interrupt controller (vAPLIC/vIMSIC) support Oleksii Kurochko
2026-09-30 16:18 ` [PATCH v3 01/39] xen/riscv: drop INSN_{16,32}BIT_MASK and report unknown instruction lengths Oleksii Kurochko
2026-10-05 10:01   ` Baptiste Le Duc
2026-10-08 14:35     ` Jan Beulich
2026-09-30 16:18 ` [PATCH v3 02/39] xen/riscv: set the domain type for 64-bit kernel images Oleksii Kurochko
2026-10-05 10:01   ` Baptiste Le Duc
2026-10-08 14:36     ` Jan Beulich
2026-09-30 16:18 ` [PATCH v3 03/39] xen/riscv: introduce csr_volatile_read64() Oleksii Kurochko
2026-10-05 10:01   ` Baptiste Le Duc
2026-10-09 13:29     ` Oleksii Kurochko
2026-10-08 14:46   ` Jan Beulich
2026-10-09 14:00     ` Oleksii Kurochko
2026-10-09 14:19       ` Jan Beulich
2026-09-30 16:18 ` [PATCH v3 04/39] xen/riscv: request a G-stage flush on vmenter when VMIDs are disabled Oleksii Kurochko
2026-10-05 10:01   ` Baptiste Le Duc
2026-10-08 14:53     ` Jan Beulich
2026-09-30 16:18 ` [PATCH v3 05/39] xen/riscv: use ~0 instead of ULONG_MAX to disable the VS-timer Oleksii Kurochko
2026-10-08 14:54   ` Jan Beulich
2026-09-30 16:18 ` [PATCH v3 06/39] xen/riscv: introduce device-agnostic MMIO emulation dispatch Oleksii Kurochko
2026-10-05 10:01   ` Baptiste Le Duc
2026-10-08 14:57     ` Jan Beulich
2026-10-12 13:51       ` Oleksii Kurochko
2026-10-12 13:50     ` Oleksii Kurochko
2026-10-12 15:28   ` Jan Beulich
2026-10-14 10:51     ` Oleksii Kurochko
2026-09-30 16:18 ` [PATCH v3 07/39] xen/riscv: introduce CPU_NONE Oleksii Kurochko
2026-10-05 14:53   ` Baptiste Le Duc
2026-10-12 14:27     ` Oleksii Kurochko
2026-10-12 15:40   ` Jan Beulich
2026-10-14 11:35     ` Oleksii Kurochko
2026-09-30 16:18 ` [PATCH v3 08/39] xen/riscv: implement virtual APLIC MMIO emulation Oleksii Kurochko
2026-10-05 14:53   ` Baptiste Le Duc
2026-10-13 16:06     ` Oleksii Kurochko
2026-10-14  6:16       ` Jan Beulich
2026-10-14 11:45         ` Oleksii Kurochko
2026-10-14 13:52   ` Jan Beulich
2026-10-15 14:57     ` Oleksii Kurochko
2026-09-30 16:18 ` [PATCH v3 09/39] xen/riscv: build the target hart index via aplic_hart_index() Oleksii Kurochko
2026-10-06  9:02   ` Baptiste Le Duc
2026-10-14 13:42     ` Oleksii Kurochko
2026-10-14 14:03   ` Jan Beulich
2026-10-15  8:32     ` Oleksii Kurochko
2026-09-30 16:23 ` [PATCH v3 10/39] xen/riscv: add helper to check APLIC MSI mode Oleksii Kurochko
2026-09-30 16:23 ` [PATCH v3 11/39] xen/riscv: implement vCPU context switching Oleksii Kurochko
2026-10-06 16:50   ` Baptiste Le Duc
2026-10-07  8:04     ` Jan Beulich
2026-10-07  8:27       ` Baptiste Le Duc
2026-10-14 14:05     ` Oleksii Kurochko
2026-11-10 15:52   ` Jan Beulich
2026-11-12 11:00     ` Oleksii Kurochko
2026-09-30 16:23 ` [PATCH v3 12/39] xen/riscv: save and restore vsiselect on vCPU context switch Oleksii Kurochko
2026-10-07  8:53   ` Baptiste Le Duc
2026-10-14 14:53     ` Oleksii Kurochko
2026-11-10 16:46     ` Jan Beulich
2026-09-30 16:23 ` [PATCH v3 13/39] xen/riscv: introduce vintc_ctxt_switch_{from,to}() Oleksii Kurochko
2026-10-07  9:11   ` Baptiste Le Duc
2026-09-30 16:23 ` [PATCH v3 14/39] xen/riscv: add IMSIC vCPU context switch handlers Oleksii Kurochko
2026-10-08  9:54   ` Baptiste Le Duc
2026-10-14 15:12     ` Oleksii Kurochko
2026-11-10 16:49   ` Jan Beulich
2026-09-30 16:23 ` [PATCH v3 15/39] xen/riscv: extend exception tables with type and data fields Oleksii Kurochko
2026-10-20 14:59   ` Baptiste Le Duc
2026-11-04 11:00     ` Oleksii Kurochko
2026-09-30 16:23 ` [PATCH v3 16/39] xen/riscv: decouple INSN_PSEUDO_VS_* from the hypervisor's XLEN Oleksii Kurochko
2026-10-20 14:59   ` Baptiste Le Duc
2026-11-10 16:52   ` Jan Beulich
2026-09-30 16:23 ` [PATCH v3 17/39] xen/riscv: add guest page fault handling stub Oleksii Kurochko
2026-10-20 14:59   ` Baptiste Le Duc
2026-11-04 11:33     ` Oleksii Kurochko
2026-09-30 16:23 ` [PATCH v3 18/39] xen/riscv: implement trap redirection to a guest Oleksii Kurochko
2026-10-20 15:22   ` Baptiste Le Duc
     [not found]   ` <179250973602.489973.14893581320042795275.b4-review@b4>
2026-10-20 15:25     ` Baptiste Le Duc
2026-11-04 11:41       ` Oleksii Kurochko
2026-09-30 16:23 ` [PATCH v3 19/39] xen/riscv: detect Shtvala Oleksii Kurochko
2026-10-20 15:26   ` Baptiste Le Duc
2026-11-10 16:53     ` Jan Beulich
2026-09-30 16:23 ` [PATCH v3 20/39] xen/riscv: resolve the faulting guest physical address Oleksii Kurochko
2026-10-21 11:45   ` Baptiste Le Duc
2026-11-04 11:49     ` Oleksii Kurochko
2026-09-30 16:23 ` [PATCH v3 21/39] xen/riscv: add guest memory read helper Oleksii Kurochko
2026-10-21 14:56   ` Baptiste Le Duc
2026-11-04 12:25     ` Oleksii Kurochko
2026-10-21 15:11   ` Baptiste Le Duc
2026-11-04 12:39     ` Oleksii Kurochko
2026-11-04 13:28       ` Jan Beulich
2026-11-04 15:25         ` Oleksii Kurochko
2026-09-30 16:23 ` [PATCH v3 22/39] xen/riscv: look up the exception table for any trap taken in Xen context Oleksii Kurochko
2026-10-21 15:28   ` Baptiste Le Duc
2026-09-30 16:23 ` [PATCH v3 23/39] xen/riscv: add helpers for decoding a trapped load or store Oleksii Kurochko
2026-10-22 10:02   ` Baptiste Le Duc
2026-11-04 16:38     ` Oleksii Kurochko
2026-11-05  8:17       ` Jan Beulich
2026-11-05  8:48         ` Oleksii Kurochko
2026-11-05  9:35       ` Baptiste Le Duc
2026-09-30 16:23 ` [PATCH v3 24/39] xen/riscv: add guest load emulation for trapped MMIO accesses Oleksii Kurochko
2026-10-15 14:59   ` Oleksii Kurochko
2026-10-22 12:13     ` Baptiste Le Duc
2026-11-04 16:44       ` Oleksii Kurochko
2026-10-22 12:30     ` Baptiste Le Duc
2026-11-04 16:46       ` Oleksii Kurochko
2026-09-30 16:23 ` [PATCH v3 25/39] xen/riscv: add guest store " Oleksii Kurochko
2026-10-22 12:37   ` Baptiste Le Duc
2026-11-04 16:51     ` Oleksii Kurochko
2026-09-30 16:23 ` [PATCH v3 26/39] xen/riscv: introduce arch_move_irqs() Oleksii Kurochko
2026-09-30 16:23 ` [PATCH v3 27/39] xen/riscv: handle the case when no vCPU migration is needed Oleksii Kurochko
2026-10-22 12:39   ` Baptiste Le Duc
2026-09-30 16:23 ` [PATCH v3 28/39] xen/riscv: introduce vaplic_reconfigure_target() Oleksii Kurochko
2026-10-22 13:38   ` Baptiste Le Duc
2026-11-05 11:43     ` Oleksii Kurochko
2026-09-30 16:23 ` [PATCH v3 29/39] xen/riscv: prepare new IMSIC VS-file Oleksii Kurochko
2026-10-23 12:55   ` Baptiste Le Duc
2026-11-05 12:49     ` Oleksii Kurochko [this message]
2026-11-05 15:27       ` Baptiste Le Duc
2026-11-05 16:41         ` Oleksii Kurochko
2026-09-30 16:23 ` [PATCH v3 30/39] xen/riscv: implement APLIC-IMSIC-hart sync barrier for vCPU migration Oleksii Kurochko
2026-10-06 14:25   ` Oleksii Kurochko
2026-10-23 13:51     ` Baptiste Le Duc
2026-11-05 14:21       ` Oleksii Kurochko
2026-11-05 15:32         ` Baptiste Le Duc
2026-11-05 15:49           ` Oleksii Kurochko
2026-11-05 15:59             ` Baptiste Le Duc
2026-11-05 16:26               ` Oleksii Kurochko
2026-09-30 16:23 ` [PATCH v3 31/39] xen/riscv: remap interrupts to new IMSIC VS-file Oleksii Kurochko
2026-10-26 14:06   ` Baptiste Le Duc
2026-11-05 16:57     ` Oleksii Kurochko
2026-11-06 13:26       ` Baptiste Le Duc
2026-11-09 10:19         ` Oleksii Kurochko
2026-11-09 15:01           ` Oleksii Kurochko
2026-11-09 15:22             ` Baptiste Le Duc
2026-09-30 16:23 ` [PATCH v3 32/39] xen/riscv: save and clear the old IMSIC VS-file on vCPU migration Oleksii Kurochko
2026-11-03 16:02   ` Baptiste Le Duc
2026-11-06  9:52     ` Oleksii Kurochko
2026-11-06 13:31       ` Baptiste Le Duc
2026-09-30 16:23 ` [PATCH v3 33/39] xen/riscv: restore register state in the new IMSIC VS-file Oleksii Kurochko
2026-11-03 16:45   ` Baptiste Le Duc
2026-11-06 10:04     ` Oleksii Kurochko
2026-11-06 13:33       ` Baptiste Le Duc
2026-09-30 16:23 ` [PATCH v3 34/39] xen/riscv: add basic VGEIN management for AIA guests Oleksii Kurochko
2026-09-30 16:23 ` [PATCH v3 35/39] xen/riscv: wake up a descheduled vCPU on a guest external interrupt Oleksii Kurochko
2026-11-04 10:37   ` Baptiste Le Duc
2026-11-06 10:58     ` Oleksii Kurochko
2026-09-30 16:23 ` [PATCH v3 36/39] xen/riscv: map IMSIC interrupt file for vCPUs Oleksii Kurochko
2026-09-30 16:23 ` [PATCH v3 37/39] xen/riscv: implement continue_new_vcpu() Oleksii Kurochko
2026-11-04 14:00   ` Baptiste Le Duc
2026-11-06 11:31     ` Oleksii Kurochko
2026-09-30 16:23 ` [PATCH v3 38/39] xen/riscv: set the guest's XLEN explicitly in hstatus.VSXL Oleksii Kurochko
2026-11-04 14:37   ` Baptiste Le Duc
2026-11-06 11:59     ` Oleksii Kurochko
2026-11-06 13:43       ` Baptiste Le Duc
2026-09-30 16:23 ` [PATCH v3 39/39] xen/riscv: introduce IMSIC h/w interrupt file attaching to vcpu Oleksii Kurochko
2026-11-04 15:06   ` Baptiste Le Duc
2026-11-06 12:31     ` 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=81b0b1fa-1aa4-4646-bdfa-5e773cb876f4@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=baptiste.le-duc@vates.tech \
    --cc=connojdavis@gmail.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=roger@xenproject.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    --cc=zhangzheng@iscas.ac.cn \
    /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.