|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v1 3/3] xen/riscv: implement p2m_ctx_switch_{to,from}_state()
On 2/5/26 1:21 PM, Jan Beulich wrote: On 05.02.2026 11:32, Oleksii Kurochko wrote:On 2/4/26 4:02 PM, Jan Beulich wrote:On 02.02.2026 13:57, Oleksii Kurochko wrote: If there are such situation then it makes sense. + new_vmid = p_vmid->vmid; + +#ifdef P2M_DEBUG + printk(XENLOG_INFO, "%pv: oldvmid(%d) new_vmid(%d), need_flush(%d)\n", + n, old_vmid, new_vmid, need_flush); +#endif + + csr_write(CSR_HGATP, construct_hgatp(p2m_get_hostp2m(current->domain), + new_vmid)); + + if ( unlikely(need_flush) ) + local_hfence_gvma_all(); + + /* + * According to the RISC-V specification, speculation can happen + * during an update of hgatp and vsatp: + * No mechanism is provided to atomically change vsatp and hgatp + * together. Hence, to prevent speculative execution causing one + * guest’s VS-stage translations to be cached under another guest’s + * VMID, world-switch code should zero vsatp, then swap hgatp, then + * finally write the new vsatp value. Similarly, if henvcfg.PBMTE + * need be world-switched, it should be switched after zeroing vsatp + * but before writing the new vsatp value, obviating the need to + * execute an HFENCE.VVMA instruction. + * So just flush TLBs for VS-Stage and G-stage after both of regs are + * touched. + */ + flush_tlb_guest_local();Which "both regs" does the comment talk about? Doesn't the flush want to come ...+ /* + * The vsatp register is a VSXLEN-bit read/write register that is + * VS-mode’s version of supervisor register satp, so the following is + * true for VSATP registers: + * Changing satp.MODE from Bare to other modes and vice versa also takes + * effect immediately, without the need to execute an SFENCE.VMA + * instruction. Likewise, changes to satp.ASID take effect immediately. + * Considering the mentioned above and that VS-stage TLB flush has been + * already done there is no need to flush VS-stage TLB after an update + * of VSATP from Bare mode to what is written in `n->arch.vsatp`. + */ + csr_write(CSR_VSATP, n->arch.vsatp);... after this? Then some of the commentary also doesn't look to be necessary. I overlooked that it Gvma in local_hfence_gvma_all(). Then it make sense for having both local_hfence_gvma_all() and flush_tlb_guest_local(). But it is still look like flush_tlb_guest_local() shouldn't be called in p2m context switch, because of what I mentioned in the first paragraph above what allow not to introduce flush_tlb_guest_local() now. ~ Oleksii
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |