[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v8 6/7] xen/riscv: page table handling
On 27.09.2024 18:33, Oleksii Kurochko wrote: > +static bool pt_check_entry(pte_t entry, mfn_t mfn, unsigned int flags) > +{ > + /* Sanity check when modifying an entry. */ > + if ( (flags & PTE_VALID) && mfn_eq(mfn, INVALID_MFN) ) > + { > + /* We don't allow modifying an invalid entry. */ > + if ( !pte_is_valid(entry) ) > + { > + dprintk(XENLOG_ERR, "Modifying invalid entry is not allowed\n"); > + return false; > + } > + > + /* We don't allow modifying a table entry */ > + if ( pte_is_table(entry) ) > + { > + dprintk(XENLOG_ERR, "Modifying a table entry is not allowed\n"); > + return false; > + } > + } > + /* Sanity check when inserting a mapping */ > + else if ( flags & PTE_VALID ) > + { > + /* > + * We don't allow replacing any valid entry. > + * > + * Note that the function pt_update() relies on this > + * assumption and will skip the TLB flush (when Svvptc > + * extension will be ratified). The function will need > + * to be updated if the check is relaxed. > + */ > + if ( pte_is_valid(entry) ) > + { > + if ( pte_is_mapping(entry) ) > + dprintk(XENLOG_ERR, "Changing MFN for valid PTE is not > allowed (%#"PRI_mfn" -> %#"PRI_mfn")\n", > + mfn_x(mfn_from_pte(entry)), mfn_x(mfn)); Nit: Indentation is now off by one. > +#define XEN_TABLE_MAP_NONE 0 > +#define XEN_TABLE_MAP_NOMEM 1 > +#define XEN_TABLE_SUPER_PAGE 2 > +#define XEN_TABLE_NORMAL 3 > + > +/* > + * Take the currently mapped table, find the corresponding entry, > + * and map the next table, if available. > + * > + * The alloc_tbl parameters indicates whether intermediate tables should > + * be allocated when not present. > + * > + * Return values: > + * XEN_TABLE_MAP_FAILED: Either alloc_only was set and the entry > + * was empty, or allocating a new page failed. > + * XEN_TABLE_NORMAL: next level or leaf mapped normally > + * XEN_TABLE_SUPER_PAGE: The next entry points to a superpage. This part of the comment is now stale. > + */ > +static int pt_next_level(bool alloc_tbl, pte_t **table, unsigned int offset) > +{ > + pte_t *entry; > + mfn_t mfn; > + > + entry = *table + offset; > + > + if ( !pte_is_valid(*entry) ) > + { > + if ( !alloc_tbl ) > + return XEN_TABLE_MAP_NONE; > + > + if ( create_table(entry) ) > + return XEN_TABLE_MAP_NOMEM; At the risk of being overly picky: You still lose -ENOMEM here. I'd suggest to make create_table() return boolean (success / fail) to eliminate that concern. Any hypothetical plan for someone to add another error code there will then hit the return type aspect, pointing out that call sites need looking at for such a change to be correct. Jan
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |