Re: [PATCH v3 10/21] KVM: arm64: Add support for stage-2 page-aging in generic page-table

Gavin Shan
2020-09-04T01:03:13Z

Hi Will,

On 9/4/20 2:48 AM, Will Deacon wrote:
> On Thu, Sep 03, 2020 at 02:33:22PM +1000, Gavin Shan wrote:
>> On 8/25/20 7:39 PM, Will Deacon wrote:
>>> Add stage-2 mkyoung(), mkold() and is_young() operations to the generic
>>> page-table code.
>>>
>>> Cc: Marc Zyngier <maz@kernel.org>
>>> Cc: Quentin Perret <qperret@google.com>
>>> Signed-off-by: Will Deacon <will@kernel.org>
>>> ---
>>> arch/arm64/include/asm/kvm_pgtable.h | 38 ++++++++++++
>>> arch/arm64/kvm/hyp/pgtable.c | 86 ++++++++++++++++++++++++++++
>>> 2 files changed, 124 insertions(+)
>
> [...]
>
>>> +static int stage2_update_leaf_attrs(struct kvm_pgtable *pgt, u64 addr,
>>> + u64 size, kvm_pte_t attr_set,
>>> + kvm_pte_t attr_clr, kvm_pte_t *orig_pte)
>>> +{
>>> + int ret;
>>> + kvm_pte_t attr_mask = KVM_PTE_LEAF_ATTR_LO | KVM_PTE_LEAF_ATTR_HI;
>>> + struct stage2_attr_data data = {
>>> + .attr_set = attr_set & attr_mask,
>>> + .attr_clr = attr_clr & attr_mask,
>>> + };
>>> + struct kvm_pgtable_walker walker = {
>>> + .cb = stage2_attr_walker,
>>> + .arg = &data,
>>> + .flags = KVM_PGTABLE_WALK_LEAF,
>>> + };
>>> +
>>> + ret = kvm_pgtable_walk(pgt, addr, size, &walker);
>>> + if (ret)
>>> + return ret;
>>> +
>>> + if (orig_pte)
>>> + *orig_pte = data.pte;
>>> + return 0;
>>> +}
>>> +
>>
>> The @size is always 1 from the caller, which means the parameter
>> can be dropped from stage2_update_leaf_attrs(). In the meanwhile,
>> we don't know the page is mapped by PUD, PMD or PTE. So to have
>> fixed value ("1") looks meaningless.
>
> I add extra callers later on, for example kvm_pgtable_stage2_wrprotect(),
> which pass a size, so it's needed for that.
>

Yes, we still need @size in the subsequent patches. So this suggestion
isn't valid.

Thanks,
Gavin