From: maobibo <maobibo@loongson.cn>
To: Huacai Chen <chenhuacai@kernel.org>
Cc: Tianrui Zhao <zhaotianrui@loongson.cn>,
WANG Xuerui <kernel@xen0n.name>,
Sean Christopherson <seanjc@google.com>,
kvm@vger.kernel.org, loongarch@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 6/6] LoongArch: KVM: Mark page accessed and dirty with page ref added
Date: Mon, 24 Jun 2024 09:12:32 +0800 [thread overview]
Message-ID: <a0a695cb-8fe7-b68b-8d39-8be0e32f9f4d@loongson.cn> (raw)
In-Reply-To: <CAAhV-H4YHBMG=YYatmmUKBm==53czOdrOoze3a_+CTNXF52N2g@mail.gmail.com>
On 2024/6/22 下午1:21, Huacai Chen wrote:
> Hi, Bibo,
>
> What is the relationship between this patch and the below one?
> https://lore.kernel.org/loongarch/20240611034609.3442344-1-maobibo@loongson.cn/T/#u
It is updated version about the patch listed at this website, I put all
migration relative patches into one patch set, to prevent that it is
lost in so many mail threads:)
Regards
Bibo Mao
>
>
> Huacai
>
> On Wed, Jun 19, 2024 at 4:09 PM Bibo Mao <maobibo@loongson.cn> wrote:
>>
>> Function kvm_map_page_fast() is fast path of secondary mmu page fault
>> flow, pfn is parsed from secondary mmu page table walker. However
>> the corresponding page reference is not added, it is dangerious to
>> access page out of mmu_lock.
>>
>> Here page ref is added inside mmu_lock, function kvm_set_pfn_accessed()
>> and kvm_set_pfn_dirty() is called with page ref added, so that the
>> page will not be freed by others.
>>
>> Also kvm_set_pfn_accessed() is removed here since it is called in
>> the following function kvm_release_pfn_clean().
>>
>> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
>> ---
>> arch/loongarch/kvm/mmu.c | 23 +++++++++++++----------
>> 1 file changed, 13 insertions(+), 10 deletions(-)
>>
>> diff --git a/arch/loongarch/kvm/mmu.c b/arch/loongarch/kvm/mmu.c
>> index 3b862f3a72cb..5a820a81fd97 100644
>> --- a/arch/loongarch/kvm/mmu.c
>> +++ b/arch/loongarch/kvm/mmu.c
>> @@ -557,6 +557,7 @@ static int kvm_map_page_fast(struct kvm_vcpu *vcpu, unsigned long gpa, bool writ
>> gfn_t gfn = gpa >> PAGE_SHIFT;
>> struct kvm *kvm = vcpu->kvm;
>> struct kvm_memory_slot *slot;
>> + struct page *page;
>>
>> spin_lock(&kvm->mmu_lock);
>>
>> @@ -599,19 +600,22 @@ static int kvm_map_page_fast(struct kvm_vcpu *vcpu, unsigned long gpa, bool writ
>> if (changed) {
>> kvm_set_pte(ptep, new);
>> pfn = kvm_pte_pfn(new);
>> + page = kvm_pfn_to_refcounted_page(pfn);
>> + if (page)
>> + get_page(page);
>> }
>> spin_unlock(&kvm->mmu_lock);
>>
>> - /*
>> - * Fixme: pfn may be freed after mmu_lock
>> - * kvm_try_get_pfn(pfn)/kvm_release_pfn pair to prevent this?
>> - */
>> - if (kvm_pte_young(changed))
>> - kvm_set_pfn_accessed(pfn);
>> + if (changed) {
>> + if (kvm_pte_young(changed))
>> + kvm_set_pfn_accessed(pfn);
>>
>> - if (kvm_pte_dirty(changed)) {
>> - mark_page_dirty(kvm, gfn);
>> - kvm_set_pfn_dirty(pfn);
>> + if (kvm_pte_dirty(changed)) {
>> + mark_page_dirty(kvm, gfn);
>> + kvm_set_pfn_dirty(pfn);
>> + }
>> + if (page)
>> + put_page(page);
>> }
>> return ret;
>> out:
>> @@ -920,7 +924,6 @@ static int kvm_map_page(struct kvm_vcpu *vcpu, unsigned long gpa, bool write)
>> kvm_set_pfn_dirty(pfn);
>> }
>>
>> - kvm_set_pfn_accessed(pfn);
>> kvm_release_pfn_clean(pfn);
>> out:
>> srcu_read_unlock(&kvm->srcu, srcu_idx);
>> --
>> 2.39.3
>>
prev parent reply other threads:[~2024-06-24 1:12 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-19 8:09 [PATCH v2 0/6] LoongArch: KVM: Fix some issues relative with mmu Bibo Mao
2024-06-19 8:09 ` [PATCH v2 1/6] LoongArch: KVM: Delay secondary mmu tlb flush until guest entry Bibo Mao
2024-06-23 7:54 ` Huacai Chen
2024-06-24 1:22 ` maobibo
2024-06-24 1:58 ` Huacai Chen
2024-06-24 2:35 ` maobibo
2024-06-19 8:09 ` [PATCH v2 2/6] LoongArch: KVM: Select huge page only if secondary mmu supports it Bibo Mao
2024-06-23 7:55 ` Huacai Chen
2024-06-24 1:28 ` maobibo
2024-06-19 8:09 ` [PATCH v2 3/6] LoongArch: KVM: Discard dirty page tracking on readonly memslot Bibo Mao
2024-06-19 8:09 ` [PATCH v2 4/6] LoongArch: KVM: Add memory barrier before update pmd entry Bibo Mao
2024-06-23 10:18 ` Huacai Chen
2024-06-24 1:37 ` maobibo
2024-06-24 1:56 ` Huacai Chen
2024-06-24 2:21 ` maobibo
2024-06-24 4:18 ` Huacai Chen
2024-06-24 6:00 ` WANG Rui
2024-06-19 8:09 ` [PATCH v2 5/6] LoongArch: KVM: Add dirty bitmap initially all set support Bibo Mao
2024-06-19 8:09 ` [PATCH v2 6/6] LoongArch: KVM: Mark page accessed and dirty with page ref added Bibo Mao
2024-06-20 3:05 ` kernel test robot
2024-06-22 5:21 ` Huacai Chen
2024-06-24 1:12 ` maobibo [this message]
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=a0a695cb-8fe7-b68b-8d39-8be0e32f9f4d@loongson.cn \
--to=maobibo@loongson.cn \
--cc=chenhuacai@kernel.org \
--cc=kernel@xen0n.name \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=seanjc@google.com \
--cc=zhaotianrui@loongson.cn \
/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
all inboxes | Powered by JetHome®