Re: [PATCH 08/14] KVM: arm64: Add support for tagging shared pages in page-table
From: Fuad Tabba
Date: Wed Jul 21 2021 - 03:36:30 EST
On Tue, Jul 20, 2021 at 3:06 PM Quentin Perret <qperret@xxxxxxxxxx> wrote:
> On Tuesday 20 Jul 2021 at 14:48:09 (+0100), Fuad Tabba wrote:
> > This might tie in to Marc's comments for using enums, but
> > consolidating the translation between prot and ignored/software bits
> > in one place would be good: thinking about patch 10 as well, where you
> > get the prot from the ignored bits. Even though you have documented
> > it, I'm finding the part where a field can be borrowed and shared as
> > opposed to being only shared not very intuitive, and I need to reread
> > the comment here to remember the difference while going through the
> > code.
> > You also mention lending as potentially reserved for the future, but I
> > think that lending is the other side of borrowing (depends on who's
> > doing the giving/taking). I wonder if in this case it would be clearer
> > to describe it in terms of whether it's exclusively owned vs owned but
> > shared (for the owner), and just shared for the sharer...
> Argh so I actually found the encoding pretty neat :/
> The idea is the following:
> - an entity that has a page mapped as SHARED in its PT means it
> doesn't have exclusive access to the page;
> - an entity that has a page mapped as BORROWED in its PT means it has
> access to a page it doesn't own;
> From that we can build the states we need:
> - when an entity shares a page with another, the original owner gets a
> SHARED mapping, and the recipient a SHARED+BORROWED mapping.
> - and in the future when/if we implement lending (which means an
> entity gives exclusive access to a page to another entity, but
> retains ownership) we can map the page in the recipient as
> 'BORROWED' only, but not 'SHARED'. And the original owner will have
> an invalid mapping with a new state 'LENT', which is encoded with
> both SW bits set.
> How does that sound? Did you have something else in mind?
The encoding is very neat by the way :D
I see where you're going with the lent state now, and I understand the
states as well as the possible transitions now that you've explained
It's the terminology that confused me a bit (especially when you
mention lending, which seemed to imply is something distinct from
borrowing as opposed to just the other side of it). What for me would
help is to document this, and the possible combinations/legal states.
kvm_pgtable.h describes the prots a bit, but maybe you could expand
that similar to what you've done in this email:
@KVM_PGTABLE_STATE_BORROWED: Page borrowed from another entity: has
access to the page but no ownership
Not sure if defining aliases for all legal combinations would also
help or add to the confusion, thinking out loud, something along the
lines of cache state taxonomy (e.g., Sweazy and Smith fig 3 ). You
have that in the borrowed (as opposed to owned), and shared (as
opposed to exclusive). So aliases to build on these:
#define KVM_PGTABLE_STATE_BORROWED_SHARED (KVM_PGTABLE_STATE_SHARED |
#define KVM_PGTABLE_STATE_BORROWED_EXCLUSIVE (KVM_PGTABLE_STATE_BORROWED)
#define KVM_PGTABLE_STATE_OWNED_SHARED (KVM_PGTABLE_STATE_SHARED)
#define KVM_PGTABLE_STATE_OWNED_EXCLUSIVE (0ULL)
You have thought about this way more than I have. But I think that
having clear documentation, ideally in the code itself via
helpers/enums/aliases could help people like me who come to the code
later not shoot themselves in the foot.