From: Oleksii Kurochko <oleksii.kurochko@gmail.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>,
xen-devel@lists.xenproject.org
Cc: "Alistair Francis" <alistair.francis@wdc.com>,
"Bob Eshleman" <bobbyeshleman@gmail.com>,
"Connor Davis" <connojdavis@gmail.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.pau@citrix.com>,
"Stefano Stabellini" <sstabellini@kernel.org>
Subject: Re: [PATCH v1 2/6] xen/riscv: introduce things necessary for p2m initialization
Date: Mon, 12 May 2025 11:33:28 +0200 [thread overview]
Message-ID: <7aa60d22-b2c6-4e11-bb40-c5d6d66a6182@gmail.com> (raw)
In-Reply-To: <b7dc409e-d18c-40eb-bbdf-86ba43b5ce74@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2891 bytes --]
On 5/12/25 11:24 AM, Oleksii Kurochko wrote:
>
>
> On 5/9/25 6:14 PM, Andrew Cooper wrote:
>> On 09/05/2025 4:57 pm, Oleksii Kurochko wrote:
>>> diff --git a/xen/arch/riscv/p2m.c b/xen/arch/riscv/p2m.c
>>> new file mode 100644
>>> index 0000000000..ad4beef8f9
>>> --- /dev/null
>>> +++ b/xen/arch/riscv/p2m.c
>>> @@ -0,0 +1,168 @@
>>> +#include <xen/domain_page.h>
>>> +#include <xen/iommu.h>
>>> +#include <xen/lib.h>
>>> +#include <xen/mm.h>
>>> +#include <xen/pfn.h>
>>> +#include <xen/rwlock.h>
>>> +#include <xen/sched.h>
>>> +#include <xen/spinlock.h>
>>> +
>>> +#include <asm/page.h>
>>> +#include <asm/p2m.h>
>>> +
>>> +/*
>>> + * Force a synchronous P2M TLB flush.
>>> + *
>>> + * Must be called with the p2m lock held.
>>> + *
>>> + * TODO: add support of flushing TLB connected to VMID.
>>> + */
>>> +static void p2m_force_tlb_flush_sync(struct p2m_domain *p2m)
>>> +{
>>> + ASSERT(p2m_is_write_locked(p2m));
>>> +
>>> + /*
>>> + * TODO: shouldn't be this flush done for each physical CPU?
>>> + * If yes, then SBI call sbi_remote_hfence_gvma() could
>>> + * be used for that.
>>> + */
>>> +#if defined(__riscv_hh) || defined(__riscv_h)
>>> + asm volatile ( "hfence.gvma" ::: "memory" );
>>> +#else
>>> + asm volatile ( ".insn r 0x73, 0x0, 0x31, x0, x0, x0" ::: "memory" );
>>> +#endif
>> TLB flushing needs to happen for each pCPU which potentially has cached
>> a mapping.
>>
>> In other arches, this is tracked by d->dirty_cpumask which is the bitmap
>> of pCPUs where this domain is scheduled.
> I could only find usage of|d->dirty_cpumask| in x86 and common code (grant
> tables) for flushing the TLB. However, it seems that|d->dirty_cpumask| is
> not set anywhere for ARM. Is it sufficient to set a bit in|d->dirty_cpumask|
> in|startup_cpu_idle_loop()|?
And one more thing.
If|d->dirty_cpumask| is empty (for example, on p2m initialization stage) then
p2m TLB flush could be skipped at all, right?
~ Oleksii
> In addition, it’s also necessary to set and clear bits in|d->dirty_cpumask|
> during|context_switch|, correct? Set it before switching from the previous
> domain, and clear it after switching to the new domain?
> Also, when a bit is set in|d->dirty_cpumask|, the|v->processor| value is also
> stored in|v->dirty_cpu|. Is this needed to track which processor is
> currently being used for the vCPU?
>> CPUs need to flush their TLBs before removing themselves from
>> d->dirty_cpumask, which is typically done during context switch, but it
>> means that to flush the P2M, you only need to IPI a subset of CPUs.
> I can't find where the P2M flush happens for x86/ARM. Could you please point me
> to where it is handled?
>
> Also, I found guest_flush_tlb_mask() for x86. I assume that it is x86 specific
> and generally it is enough to have only flush_tlb_mask(), right?
>
> Thanks in advance for the answers.
> ~ Oleksii
[-- Attachment #2: Type: text/html, Size: 4545 bytes --]
next prev parent reply other threads:[~2025-05-12 9:33 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-09 15:57 [PATCH v1 0/6] xen/riscv: introduce p2m functionality Oleksii Kurochko
2025-05-09 15:57 ` [PATCH v1 1/6] xen/riscv: add inclusion of xen/bitops.h to asm/cmpxchg.h Oleksii Kurochko
2025-05-09 16:00 ` Andrew Cooper
2025-05-09 15:57 ` [PATCH v1 2/6] xen/riscv: introduce things necessary for p2m initialization Oleksii Kurochko
2025-05-09 16:14 ` Andrew Cooper
2025-05-12 9:24 ` Oleksii Kurochko
2025-05-12 9:33 ` Oleksii Kurochko [this message]
2025-05-20 13:47 ` Jan Beulich
2025-05-20 13:37 ` Jan Beulich
2025-05-22 15:53 ` Oleksii Kurochko
2025-05-22 16:09 ` Jan Beulich
2025-05-23 9:44 ` Oleksii Kurochko
2025-06-02 11:04 ` Jan Beulich
2025-06-05 14:10 ` Oleksii Kurochko
2025-06-05 14:19 ` Jan Beulich
2025-06-05 15:28 ` Oleksii Kurochko
2025-05-09 15:57 ` [PATCH v1 3/6] xen/riscv: construct the P2M pages pool for guests Oleksii Kurochko
2025-05-20 14:38 ` Jan Beulich
2025-05-23 10:27 ` Oleksii Kurochko
2025-06-02 11:08 ` Jan Beulich
2025-06-05 14:22 ` Oleksii Kurochko
2025-05-09 15:57 ` [PATCH v1 4/6] xen/riscv: define pt_t and pt_walk_t structures Oleksii Kurochko
2025-05-20 15:04 ` Jan Beulich
2025-05-23 10:48 ` Oleksii Kurochko
2025-05-09 15:57 ` [PATCH v1 5/6] xen/riscv: add new p2m types and helper macros for type classification Oleksii Kurochko
2025-05-20 15:11 ` Jan Beulich
2025-05-23 11:34 ` Oleksii Kurochko
2025-06-02 11:12 ` Jan Beulich
2025-05-09 15:57 ` [PATCH v1 6/6] xen/riscv: implement p2m mapping functionality Oleksii Kurochko
2025-05-20 15:16 ` Jan Beulich
2025-05-23 11:47 ` 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=7aa60d22-b2c6-4e11-bb40-c5d6d66a6182@gmail.com \
--to=oleksii.kurochko@gmail.com \
--cc=alistair.francis@wdc.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=bobbyeshleman@gmail.com \
--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.