[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] xen/riscv: allow Xen to use SSTC while hiding it from guests
- To: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
- From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
- Date: Fri, 10 Apr 2026 18:41:27 +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=gfu7roJvbPHD/ETMldfDilvOFITe9DSQltzRwvMt2Xg=; b=SP23ZSkyvKayCsnIWq7cI+w3YYADynUKMP7qKk3iceeWvflNlN2mojVA4JZlXZc/FkShFGjADBjHUm8BJLiTfTdEIGkHWk+hdpDNClXpyoG18bUlW6/43FtNBCM+tf9Ea8yVJqbmnAeMLYAypRRFEWPdjsvo676JSFng9WSdqQZJw+wzfnh5kFVjgJxoCAV4vB+koKWXwexTdeLbhG8c9rVmMKiKOyWLDXFWwaa/mrT8havDHcZRA0vXZtSjPRam+SRr1psZXABuFP5k0lcv6yXsVhWqhu1ISJ+2uHf/x3HYD1l5+ir+rF0s4bHJkfNo/JJXw6crnhJ3ug00ZozriQ==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GEcJ4gdU2/yO88as9sBHBHih1jvebj+/p4TI2I9DCxQ7itN2weN2xpcoMVyvGhlX97Z8xMSxbwmIq+PWNUmWTGmy07kgGoD1kYRBJpLeOZFFqljnbFp1a+88RH6iVc3cOTYZq5eWD5F5ntcAwj60K+7LFCxko+VTPp59s4er9tR+DmDltWXlLdLlmhdN2YxHjbo1C/mdQjBOnlp0Hz2BWO6IvqGpOapAP72lX5LLc0uIXDmvgGkB5dkZ7R0RLQZw6pjsbRVt0zd5UcUXHem2p7QbkE/H7MwoPp6VkXD3OGn/hTSCmcLVzFp57TQBJkACncwjsJGIg6rvKYB1J9jjhg==
- 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>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
- Delivery-date: Fri, 10 Apr 2026 17:41:45 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 10/04/2026 4:45 pm, Oleksii Kurochko wrote:
> diff --git a/xen/arch/riscv/time.c b/xen/arch/riscv/time.c
> index 7efa76fdbcb1..80f0e9ddae6a 100644
> --- a/xen/arch/riscv/time.c
> +++ b/xen/arch/riscv/time.c
> @@ -91,4 +90,23 @@ void __init preinit_xen_time(void)
> panic("%s: ACPI isn't supported\n", __func__);
>
> boot_clock_cycles = get_cycles();
> +
> + /* set_xen_timer must have been set by sbi_init() already */
> + ASSERT(set_xen_timer);
> +
> + if ( riscv_isa_extension_available(NULL, RISCV_ISA_EXT_sstc) )
> + {
> + set_xen_timer = sstc_set_xen_timer;
> +
> + /*
> + * A VS-timer interrupt becomes pending whenever the value of
> + * (time + htimedelta) is greater than or equal to vstimecmp CSR.
> + * Thereby to avoid spurious VS-timer irqs set vstimecmp CSR to
> + * ULONG_MAX.
> + */
> + csr_write(CSR_VSTIMECMP, ULONG_MAX);
> +#ifdef CONFIG_RISCV_32
> + csr_write(CSR_VSTIMECMPH, ULONG_MAX);
> +#endif
You've got this pattern twice in this patch alone, and these aren't the
only CSRs which are formed of pairs to get a 64bit value in 32bit mode.
Sadly, the numbering isn't consistent for the high constant, but we can
let the compiler do most of the hard work for us.
#ifdef CONFIG_RISCV_32
# define __csr_write32h(csr, val) csr_write(csr ## H, (val) >> 32)
#else
# define __csr_write32h(csr, val) (void)(csr, val)
#endif
#define csr_write64(csr, val) ({
uint64_t _v = (val);
csr_write(csr, _v);
__csr_write32h(csr, _v);
})
will get you a csr_write64(CSR_FOO, bar) which does the right thing on
32bit mode.
~Andrew
|