[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v4 6/7] xen/riscv: page table handling
On Tue, 2024-08-20 at 15:47 +0200, Jan Beulich wrote: > On 20.08.2024 15:18, oleksii.kurochko@xxxxxxxxx wrote: > > On Tue, 2024-08-13 at 12:31 +0200, Jan Beulich wrote: > > > > + * Sanity check of the entry > > > > + * mfn is not valid and we are not populating page table. This > > > > means > > > > > > How does this fit with ... > > > > > > > + * we either modify entry or remove an entry. > > > > + */ > > > > +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) ) > > > > > > ... the MFN check here? And why is (valid,INVALID_MFN) an > > > indication > > > of a modification? > > Because as mentioned here: > > ``` > > /* > > * If `mfn` equals `INVALID_MFN`, it indicates that the following > > page > > table > > * update operation might be related to either populating the > > table, > > * destroying a mapping, or modifying an existing mapping. > > */ > > static int pt_update(unsigned long virt, > > ``` > > That's in the description of another function. How would one know > that > the rules on (mfn,flags) tuples there would apply here as well, > without > you saying so explicitly? It may not be necessary to repeat the other > comment, but at least you want to reference it. > > > And so if requested flags are PTE_VALID ( present ) and mfn=INVALID > > it > > will mean that we are going to modify an entry. > > > > > > > But then ... > > > > > > > + { > > > > + /* We don't allow modifying an invalid entry. */ > > > > + if ( !pte_is_valid(entry) ) > > > > + { > > > > + printk("Modifying invalid entry is not > > > > allowed.\n"); > > > > + return false; > > > > + } > > > > > > ... I also don't understand what this is about. IOW I'm afraid > > > I'm > > > still confused about the purpose of this function as well as the > > > transitions you want to permit / reject. > > In the case if the caller call modify_xen_mappings() on a region > > that > > doesn't exist. > > Perhaps. What I think is missing is a clear statement somewhere to > describe > what the various combinations of (mfn,flags) mean, in terms of the > operation > to be carried out. This may then also help with ... > > > > I wonder whether the > > > flags & PTE_VALID and pte_is_valid(entry) aren't in need of > > > swapping. > > I am not sure that I understand what you mean. > > ... this: It's hard to see what cannot be understood about my earlier > comment. In the code commented on you have a flags & PTE_VALID check > and a > pte_is_valid(entry) one. I'm wondering whether the two simply are the > wrong > way round. Sure. I'll add additional comments and reference in the next patch version to clarify that moment. > > > > > +/* Update an entry at the level @target. */ > > > > +static int pt_update_entry(mfn_t root, unsigned long virt, > > > > + mfn_t mfn, unsigned int target, > > > > + unsigned int flags) > > > > +{ > > > > + int rc; > > > > + unsigned int level = HYP_PT_ROOT_LEVEL; > > > > + pte_t *table; > > > > + /* > > > > + * The intermediate page tables are read-only when the MFN > > > > is > > > > not valid > > > > + * and we are not populating page table. > > > > > > The way flags are handled in PTEs, how can page tables be read- > > > only? > > This is not needed for everyone case. In case of entry removing an > > intermediate page table should be created in case when the user is > > trying to remove a mapping that doesn't exist. > > I don't follow: For one, how is this related to "read-only"-ness? And > then, why would any kind of removal, whether of a present or non- > present mapping, ever result in page tables being created? If the mapping doesn't exist and it was requested ( accidentally by the caller ) then then the logic of PT update will try to allocate the page table what is actually a bogus behaviour... I have to double-check that. > > > > > + * This means we either modify permissions or remove an > > > > entry. > > > > > > From all I can determine we also get here when making brand new > > > entries. > > > What am I overlooking? > > Yes, but in this case an intermediate page tables should be > > read_only, > > so alloc_only will be true and it will be allowed to create new > > intermediate page table. > > Hmm, so instead of "read-only" do you maybe mean page tables are not > supposed to be modified? There's a difference here: When they're > read-only, you can't write to them (or a fault will result). Whereas > when in principle they can be modified, there still may be a rule > saying "in this case they shouldn't be altered". There is such rule which checks that page tables aren't supposed to be modified ( so that is why they are read-only ): ``` /* Sanity check when modifying an entry. */ if ( (flags & PTE_VALID) && mfn_eq(mfn, INVALID_MFN) ) { ... /* We don't allow modifying a table entry */ if ( pte_is_table(entry) ) { printk("Modifying a table entry is not allowed.\n"); return false; } ``` ~ Oleksii
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |