linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Burton <paul.burton@mips.com>
To: Gary Fu <qfu@wavecomp.com>
Cc: "linux-mips@vger.kernel.org" <linux-mips@vger.kernel.org>,
	Paul Burton <pburton@wavecomp.com>,
	Archer Yan <ayan@wavecomp.com>, James Hogan <jhogan@kernel.org>
Subject: Re: [PATCH] KVM: Fix an issue in non-preemptible kernel.
Date: Wed, 4 Sep 2019 14:02:30 +0000	[thread overview]
Message-ID: <20190904135343.gbqfs4nlpnjvyfhc@pburton-laptop> (raw)
In-Reply-To: <20190902090148.10356-1-qfu@wavecomp.com>

Hi Gary,

On Mon, Sep 02, 2019 at 09:02:32AM +0000, Gary Fu wrote:
> Add a cond_resched() to give the scheduler a chance to run madvise
> task to avoid endless loop here in non-preemptible kernel.

Thanks for the patch!

> Otherwise, the kvm_mmu_notifier would have no chance to be descreased

s/descreased/decreased/
(and in the comment too)

> to 0 by madvise task -> syscall -> zap_page_range ->
> mmu_notifier_invalidate_range_end ->
> __mmu_notifier_invalidate_range_end -> invalidate_range_end ->
> kvm_mmu_notifier_invalidate_range_end, as the madvise task would be
> scheduled when running unmap_single_vma -> unmap_page_range ->
> zap_p4d_range -> zap_pud_range -> zap_pmd_range -> cond_resched which
> is called before mmu_notifier_invalidate_range_end in zap_page_range.

I'm not entirely sure I follow - could you clarify whether the task
invoking the madvise syscall is related to the task using KVM?

> Signed-off-by: Gary Fu <qfu@wavecomp.com>
> ---
>  arch/mips/kvm/mmu.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/arch/mips/kvm/mmu.c b/arch/mips/kvm/mmu.c
> index 97e538a8c1be..e52e63d225f4 100644
> --- a/arch/mips/kvm/mmu.c
> +++ b/arch/mips/kvm/mmu.c
> @@ -746,6 +746,22 @@ static int kvm_mips_map_page(struct kvm_vcpu *vcpu, unsigned long gpa,
>  		 */
>  		spin_unlock(&kvm->mmu_lock);
>  		kvm_release_pfn_clean(pfn);
> +		/*
> +		 * Add a cond_resched() to give the scheduler a chance to run
> +		 * madvise task to avoid endless loop here in non-preemptible
> +		 * kernel.
> +		 * Otherwise, the kvm_mmu_notifier would have no chance to be
> +		 * descreased to 0 by madvise task -> syscall -> zap_page_range
> +		 * -> mmu_notifier_invalidate_range_end ->
> +		 * __mmu_notifier_invalidate_range_end -> invalidate_range_end
> +		 * -> kvm_mmu_notifier_invalidate_range_end, as the madvise task
> +		 * would be scheduled when running unmap_single_vma ->
> +		 * unmap_page_range -> zap_p4d_range -> zap_pud_range ->
> +		 * zap_pmd_range -> cond_resched which is called before
> +		 * mmu_notifier_invalidate_range_end in zap_page_range.
> +		 */
> +		if (need_resched())
> +			cond_resched();

Can we remove the need_resched() check here? cond_resched() already
checks should_resched(0) which tests the same thread-info flag as
need_resched(). So we should be fine to just call cond_resched()
unconditionally.

Thanks,
    Paul

>  		goto retry;
>  	}
>  
> -- 
> 2.17.1
> 

  reply	other threads:[~2019-09-04 14:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-02  9:02 [PATCH] KVM: Fix an issue in non-preemptible kernel Gary Fu
2019-09-04 14:02 ` Paul Burton [this message]
2019-09-05 13:54   ` Gary Fu
2019-09-09  2:49 Gary Fu

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=20190904135343.gbqfs4nlpnjvyfhc@pburton-laptop \
    --to=paul.burton@mips.com \
    --cc=ayan@wavecomp.com \
    --cc=jhogan@kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=pburton@wavecomp.com \
    --cc=qfu@wavecomp.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;
as well as URLs for NNTP newsgroup(s).