[PATCH 1/5] xen/riscv: always set A/D bits at boot time
Baptiste Le Duc <[email protected]>
| Newsgroups | gmane.comp.emulators.xen.devel |
|---|---|
| Message-ID | <1787844808.8631fc262581453bbf619ec5b2062170.1a043dad0d3000c4f3@vates.tech> |
Always set the PTE A/D bits at boot time to avoid an unhandled page fault on platforms that implement neither Svade nor Svadu, and on platforms that declare both in the device tree. Rewrite the comment to enumerate the four possible Svade/Svadu combinations (inspired by [1]) and set A/D unconditionally, which is correct in all four cases until Svadu is fully supported (full support requires the SBI FWFT call to enable hardware updating of A/D bits). [1] https://lwn.net/Articles/980016/ Assisted-by: Claude:claude-opus-5 Signed-off-by: Baptiste Le Duc <[email protected]> --- xen/arch/riscv/p2m.c | 70 ++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/xen/arch/riscv/p2m.c b/xen/arch/riscv/p2m.c index 1cea86512c..11dc289f0f 100644 --- a/xen/arch/riscv/p2m.c +++ b/xen/arch/riscv/p2m.c @@ -591,38 +591,52 @@ static void p2m_set_permission(pte_t *e, p2m_type_t t) e->pte |= PTE_USER; /* - * Two schemes to manage the A and D bits are defined: - * • The Svade extension: when a virtual page is accessed and the A bit - * is clear, or is written and the D bit is clear, a page-fault - * exception is raised. - * • When the Svade extension is not implemented, the following scheme - * applies. - * When a virtual page is accessed and the A bit is clear, the PTE is - * updated to set the A bit. When the virtual page is written and the - * D bit is clear, the PTE is updated to set the D bit. When G-stage - * address translation is in use and is not Bare, the G-stage virtual - * pages may be accessed or written by implicit accesses to VS-level - * memory management data structures, such as page tables. - * Thereby to avoid a page-fault in case of Svade is available, it is - * necessary to set A and D bits. + * Svade and Svadu extensions represent two schemes for managing the PTE + * A/D bits. When the PTE A/D bits need to be set, the Svade extension + * indicates that a page fault will be raised. In contrast, the Svadu + * extension supports hardware updating of the PTE A/D bits. * - * TODO: For now, it’s fine to simply set the A/D bits, since OpenSBI - * delegates page faults to a lower privilege mode and so OpenSBI - * isn't expect to handle page-faults occured in lower modes. - * By setting the A/D bits here, page faults that would otherwise - * be generated due to unset A/D bits will not occur in Xen. + * There are 4 possible combinations of these extensions in the device + * tree. The default hardware behavior for each is: * - * Currently, Xen on RISC-V does not make use of the information - * that could be obtained from handling such page faults, which - * could otherwise be useful for several use cases such as demand - * paging, cache-flushing optimizations, memory access tracking,etc. + * 1) Neither Svade nor Svadu present in DT => It is technically unknown + * whether the platform uses Svade or Svadu. Xen should be prepared to + * handle either hardware updating of the PTE A/D bits or page faults + * when they need updating. To support both, Xen always sets the 'A' and + * 'D' PTE bits at boot time. * - * To support the more general case and the optimizations mentioned - * above, it would be better to stop setting the A/D bits here and - * instead handle page faults that occur due to unset A/D bits. + * 2) Only Svade present in DT => Xen must assume Svade to be always + * enabled. + * + * 3) Only Svadu present in DT => Xen must assume Svadu to be always + * enabled. + * + * 4) Both Svade and Svadu present in DT => Xen must assume Svadu is turned + * off at boot time by setting A/D bits. To use Svadu, the supervisor + * must explicitly enable it using the SBI FWFT extension. + * + * The Svade extension is mandatory and the Svadu extension is optional in + * the RVA23 profile. Platforms wanting to take advantage of Svadu can + * choose option 3. Platforms aware of the profile can choose option 4, and + * Linux won't get the benefit of Svadu until the SBI FWFT extension is + * available. + * + * Currently, Xen on RISC-V does not make use of the information that could + * be obtained from handling such page faults, which could otherwise be + * useful for several use cases such as demand paging, cache-flushing + * optimizations, memory access tracking, etc. + * + * To support the more general case and the optimizations mentioned above, + * it would be better to stop setting the A/D bits here and instead handle + * page faults that occur due to unset A/D bits. + */ + + /* + * Preset unconditionally for all 4 cases above, harmless when Svadu + * manages the bits (case 3). Skipping it for case 3 requires SBI FWFT + * which is not yet supported. */ - if ( riscv_isa_extension_available(NULL, RISCV_ISA_EXT_svade) ) - e->pte |= PTE_ACCESSED | PTE_DIRTY; + e->pte |= PTE_ACCESSED | PTE_DIRTY; switch ( t ) {