Linux KVM/arm64 development list
 help / color / mirror / Atom feed
From: Gavin Shan <gshan@redhat.com>
To: Ricardo Koller <ricarkol@google.com>
Cc: pbonzini@redhat.com, maz@kernel.org, oupton@google.com,
	yuzenghui@huawei.com, dmatlack@google.com, kvm@vger.kernel.org,
	kvmarm@lists.linux.dev, qperret@google.com,
	catalin.marinas@arm.com, andrew.jones@linux.dev,
	seanjc@google.com, alexandru.elisei@arm.com,
	suzuki.poulose@arm.com, eric.auger@redhat.com, reijiw@google.com,
	rananta@google.com, bgardon@google.com, ricarkol@gmail.com
Subject: Re: [PATCH v2 04/12] KVM: arm64: Add kvm_pgtable_stage2_split()
Date: Fri, 10 Feb 2023 09:48:11 +1100	[thread overview]
Message-ID: <e8513463-75cc-ca11-2fe8-1ba1b32411d8@redhat.com> (raw)
In-Reply-To: <CAOHnOrwprM8v3xXCA5sEVD1cHVQRS6vsPvdXiC1NocrzyQcoYw@mail.gmail.com>

On 2/10/23 3:17 AM, Ricardo Koller wrote:
> "(> > > +     if (data->mc_capacity < nr_pages)
>>>> +             return -ENOMEM;
>>>> +
>>>> +     phys = kvm_pte_to_phys(pte);
>>>> +     prot = kvm_pgtable_stage2_pte_prot(pte);
>>>> +
>>>> +     ret = kvm_pgtable_stage2_create_unlinked(data->mmu->pgt, &new, phys,
>>>> +                                              level, prot, mc, force_pte);
>>>> +     if (ret)
>>>> +             return ret;
>>>> +
>>>> +     if (!stage2_try_break_pte(ctx, data->mmu)) {
>>>> +             childp = kvm_pte_follow(new, mm_ops);
>>>> +             kvm_pgtable_stage2_free_unlinked(mm_ops, childp, level);
>>>> +             mm_ops->put_page(childp);
>>>> +             return -EAGAIN;
>>>> +     }
>>>> +
>>>> +     /*
>>>> +      * Note, the contents of the page table are guaranteed to be made
>>>> +      * visible before the new PTE is assigned because stage2_make_pte()
>>>> +      * writes the PTE using smp_store_release().
>>>> +      */
>>>> +     stage2_make_pte(ctx, new);
>>>> +     dsb(ishst);
>>>> +     data->mc_capacity -= nr_pages;
>>>> +     return 0;
>>>> +}
>>>> +
>>>
>>> I think it's possible 'data->mc_capability' to be replaced by 'mc->nobjs'
>>> because they're same thing. With this, we needn't to maintain a duplicate
>>> 'data->mc_capability' since 'data->mc' has been existing.
>>
>> Ah, nice, yes. That would be simpler.
>>
> 
> Actually, there's a complication. The memcache details are hidden
> inside of pgtable.c,
> so different types of memcaches (for vhe and nvhe) can be used for allocations.
> Specifically, the memcache objects are passed as an opaque pointer ("void *")
> and can be used with "struct hyp_pool" and "struct kvm_mmu_memory_cache".
> 
> So, here are all the options that I can think of:
> 
>          1. stage2_split_walker() is just used on the VHE case with the
>          "struct kvm_mmu_memory_cache" memcache, so we could just use it
>          instead of a "void *":
> 
>                  kvm_pgtable_stage2_split(..., struct kvm_mmu_memory_cache *mc);
> 
>          However, it could be used for the NVHE case as well, plus
>          this would go against the overall design of pgtable.c which tries
>          to use opaque objects for most things.
> 
>          2. add a "get_nobjs()" method to both memcaches. This is tricky
>          because "struct hyp_pool" doesn't directly track its capacity. I
>          would rather not mess with it.
> 
>          3. This whole accounting of available pages in the memcache is
>          needed because of the way I implemented stage2_split_walker() and
>          the memcache interface.  stage2_split_walker() tries to allocate
>          as many pages for the new table as allowed by the capacity of the
>          memcache. The issue with blindingly trying until the allocation
>          fails is that kvm_mmu_memory_cache_alloc() WARNs and tries to
>          allocate using GFP_ATOMIC when !nobjs. We don't want to do that,
>          so we could extend kvm_pgtable_mm_ops.zalloc_page() with a
>          NO_GFP_ATOMIC_ON_EMPTY (or similar). This flag would have to be
>          ignored on the hyp side.
> 
>          4. what this patch is currently doing: tracking the capacity by
>          hand.
> 
> I prefer options 4 and 3. WDYT?
> 

Yeah, stage2_split_walker() is currently only used by VHE and it calls to
stage2_map_walker() to create the unlinked page table, which is shared by
VHE and nVHE. I think option 3 would be better than 4 because we generally
just want to fetch the pre-allocated page table, instead of allocating a
new page table with GFP_ATOMIC. However, I'm also fine with option 4. I
think this can be improved in the future if you agree.

>>
>>>
>>>> +int kvm_pgtable_stage2_split(struct kvm_pgtable *pgt, u64 addr, u64 size,
>>>> +                          void *mc, u64 mc_capacity)
>>>> +{
>>>> +     struct stage2_split_data split_data = {
>>>> +             .mmu            = pgt->mmu,
>>>> +             .memcache       = mc,
>>>> +             .mc_capacity    = mc_capacity,
>>>> +     };
>>>> +
>>>> +     struct kvm_pgtable_walker walker = {
>>>> +             .cb     = stage2_split_walker,
>>>> +             .flags  = KVM_PGTABLE_WALK_LEAF,
>>>> +             .arg    = &split_data,
>>>> +     };
>>>> +
>>>> +     return kvm_pgtable_walk(pgt, addr, size, &walker);
>>>> +}
>>>> +
>>>>    int __kvm_pgtable_stage2_init(struct kvm_pgtable *pgt, struct kvm_s2_mmu *mmu,
>>>>                              struct kvm_pgtable_mm_ops *mm_ops,
>>>>                              enum kvm_pgtable_stage2_flags flags,
>>>>
>>>

Thanks,
Gavin


  reply	other threads:[~2023-02-09 22:48 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-06 16:58 [PATCH v2 00/12] Implement Eager Page Splitting for ARM Ricardo Koller
2023-02-06 16:58 ` [PATCH v2 01/12] KVM: arm64: Add KVM_PGTABLE_WALK ctx->flags for skipping BBM and CMO Ricardo Koller
2023-02-06 16:58 ` [PATCH v2 02/12] KVM: arm64: Rename free_unlinked to free_removed Ricardo Koller
2023-02-06 16:58 ` [PATCH v2 03/12] KVM: arm64: Add helper for creating unlinked stage2 subtrees Ricardo Koller
2023-02-07 14:51   ` Ricardo Koller
2023-02-06 16:58 ` [PATCH v2 04/12] KVM: arm64: Add kvm_pgtable_stage2_split() Ricardo Koller
2023-02-09  5:58   ` Gavin Shan
2023-02-09 12:40     ` Ricardo Koller
2023-02-09 16:17       ` Ricardo Koller
2023-02-09 22:48         ` Gavin Shan [this message]
2023-02-15 17:43           ` Ricardo Koller
2023-02-06 16:58 ` [PATCH v2 05/12] KVM: arm64: Refactor kvm_arch_commit_memory_region() Ricardo Koller
2023-02-09  6:02   ` Gavin Shan
2023-02-15 17:47     ` Ricardo Koller
2023-02-06 16:58 ` [PATCH v2 06/12] KVM: arm64: Add kvm_uninit_stage2_mmu() Ricardo Koller
2023-02-06 16:58 ` [PATCH v2 07/12] KVM: arm64: Export kvm_are_all_memslots_empty() Ricardo Koller
2023-02-06 16:58 ` [PATCH v2 08/12] KVM: arm64: Add KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE Ricardo Koller
2023-02-08 11:05   ` Gavin Shan
2023-02-06 16:58 ` [PATCH v2 09/12] KVM: arm64: Split huge pages when dirty logging is enabled Ricardo Koller
2023-02-09  6:26   ` Gavin Shan
2023-02-09 12:50     ` Ricardo Koller
2023-02-09 23:09       ` Gavin Shan
2023-02-15 16:25       ` Ricardo Koller
2023-02-06 16:58 ` [PATCH v2 10/12] KVM: arm64: Open-code kvm_mmu_write_protect_pt_masked() Ricardo Koller
2023-02-06 16:58 ` [PATCH v2 11/12] KVM: arm64: Split huge pages during KVM_CLEAR_DIRTY_LOG Ricardo Koller
2023-02-09  6:29   ` Gavin Shan
2023-02-06 16:58 ` [PATCH v2 12/12] KVM: arm64: Use local TLBI on permission relaxation Ricardo Koller
2023-02-14  5:57 ` [PATCH v2 00/12] Implement Eager Page Splitting for ARM Gavin Shan
2023-02-14  7:33   ` Oliver Upton
2023-02-14 21:59     ` Ricardo Koller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e8513463-75cc-ca11-2fe8-1ba1b32411d8@redhat.com \
    --to=gshan@redhat.com \
    --cc=alexandru.elisei@arm.com \
    --cc=andrew.jones@linux.dev \
    --cc=bgardon@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=dmatlack@google.com \
    --cc=eric.auger@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@google.com \
    --cc=pbonzini@redhat.com \
    --cc=qperret@google.com \
    --cc=rananta@google.com \
    --cc=reijiw@google.com \
    --cc=ricarkol@gmail.com \
    --cc=ricarkol@google.com \
    --cc=seanjc@google.com \
    --cc=suzuki.poulose@arm.com \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox