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 09/12] KVM: arm64: Split huge pages when dirty logging is enabled
Date: Fri, 10 Feb 2023 10:09:40 +1100	[thread overview]
Message-ID: <f1e8d587-8c7a-8e97-522f-337915489cda@redhat.com> (raw)
In-Reply-To: <CAOHnOrzGXU29JK+8aRq0SnMe6Ske04YWffJhPU6iUXjGyyoQtA@mail.gmail.com>

Hi Ricardo,

On 2/9/23 11:50 PM, Ricardo Koller wrote:
> On Wed, Feb 8, 2023 at 10:26 PM Gavin Shan <gshan@redhat.com> wrote:

[...]

>>
>>> +static int kvm_mmu_split_huge_pages(struct kvm *kvm, phys_addr_t addr,
>>> +                                 phys_addr_t end)
>>> +{
>>> +     struct kvm_mmu_memory_cache *cache;
>>> +     struct kvm_pgtable *pgt;
>>> +     int ret;
>>> +     u64 next;
>>> +     u64 chunk_size = kvm->arch.mmu.split_page_chunk_size;
>>> +     int cache_capacity = kvm_mmu_split_nr_page_tables(chunk_size);
>>> +
>>> +     if (chunk_size == 0)
>>> +             return 0;
>>> +
>>> +     lockdep_assert_held_write(&kvm->mmu_lock);
>>> +
>>> +     cache = &kvm->arch.mmu.split_page_cache;
>>> +
>>> +     do {
>>> +             if (need_topup_split_page_cache_or_resched(kvm,
>>> +                                                        cache_capacity)) {
>>> +                     write_unlock(&kvm->mmu_lock);
>>> +                     cond_resched();
>>> +                     /* Eager page splitting is best-effort. */
>>> +                     ret = __kvm_mmu_topup_memory_cache(cache,
>>> +                                                        cache_capacity,
>>> +                                                        cache_capacity);
>>> +                     write_lock(&kvm->mmu_lock);
>>> +                     if (ret)
>>> +                             break;
>>> +             }
>>> +
>>> +             pgt = kvm->arch.mmu.pgt;
>>> +             if (!pgt)
>>> +                     return -EINVAL;
>>
>> I don't think the check to see @pgt is existing or not because the VM can't be
>> created with its page-table isn't allocated and set in kvm_init_stage2_mmu().
> 
> GIven that the lock is released/acquired every chunk, the intent was to check
> that the page-table wasn't freed in between.
> 

I don't understand how it can be possible. @pgt is free'd when the VM is released
when its reference count reaches zero. The major cross-point is close(vm-fd) and
this ioctl(). The VM file's release function won't be invoked until the file's
reference count is dropped to zero. The ioctl() already had one reference count
on the VM file taken to avoid it.

There may be other cases I missed. If so, I think a comment is still needed to
help reader to understand.

Thanks,
Gavin


  reply	other threads:[~2023-02-09 23:09 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
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 [this message]
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=f1e8d587-8c7a-8e97-522f-337915489cda@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