kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Wanpeng Li <kernellwp@gmail.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: Sean Christopherson <seanjc@google.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
	Ben Segall <bsegall@google.com>,
	Venkatesh Srinivas <venkateshs@chromium.org>,
	David Matlack <dmatlack@google.com>,
	Paul Mackerras <paulus@ozlabs.org>,
	Suraj Jitindar Singh <sjitindarsingh@gmail.com>
Subject: Re: [PATCH v4 1/5] KVM: exit halt polling on need_resched() for both book3s and generic halt-polling
Date: Mon, 24 May 2021 15:46:43 +0200	[thread overview]
Message-ID: <f0247587-e90a-1695-1399-47a67c44d861@redhat.com> (raw)
In-Reply-To: <1621339235-11131-1-git-send-email-wanpengli@tencent.com>

On 18/05/21 14:00, Wanpeng Li wrote:
> From: Wanpeng Li <wanpengli@tencent.com>
> 
> Inspired by commit 262de4102c7bb8 (kvm: exit halt polling on need_resched()
> as well), CFS_BANDWIDTH throttling will use resched_task() when there is just
> one task to get the task to block. It was likely allowing VMs to overrun their
> quota when halt polling. Due to PPC implements an arch specific halt polling
> logic, we should add the need_resched() checking there as well. This
> patch adds a helper function that to be shared between book3s and generic
> halt-polling loop.
> 
> Reviewed-by: David Matlack <dmatlack@google.com>
> Reviewed-by: Venkatesh Srinivas <venkateshs@chromium.org>
> Cc: Ben Segall <bsegall@google.com>
> Cc: Venkatesh Srinivas <venkateshs@chromium.org>
> Cc: Jim Mattson <jmattson@google.com>
> Cc: David Matlack <dmatlack@google.com>
> Cc: Paul Mackerras <paulus@ozlabs.org>
> Cc: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> ---
> v3 -> v4:
>   * rename to kvm_vcpu_can_poll
> v2 -> v3:
>   * add a helper function
> v1 -> v2:
>   * update patch description
> 
>   arch/powerpc/kvm/book3s_hv.c | 2 +-
>   include/linux/kvm_host.h     | 2 ++
>   virt/kvm/kvm_main.c          | 8 ++++++--
>   3 files changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index 28a80d240b76..7360350e66ff 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -3936,7 +3936,7 @@ static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc)
>   				break;
>   			}
>   			cur = ktime_get();
> -		} while (single_task_running() && ktime_before(cur, stop));
> +		} while (kvm_vcpu_can_poll(cur, stop));
>   
>   		spin_lock(&vc->lock);
>   		vc->vcore_state = VCORE_INACTIVE;
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 2f34487e21f2..ba682f738a25 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -1583,4 +1583,6 @@ static inline void kvm_handle_signal_exit(struct kvm_vcpu *vcpu)
>   /* Max number of entries allowed for each kvm dirty ring */
>   #define  KVM_DIRTY_RING_MAX_ENTRIES  65536
>   
> +bool kvm_vcpu_can_poll(ktime_t cur, ktime_t stop);
> +
>   #endif
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 6b4feb92dc79..62522c12beba 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -2945,6 +2945,11 @@ update_halt_poll_stats(struct kvm_vcpu *vcpu, u64 poll_ns, bool waited)
>   		vcpu->stat.halt_poll_success_ns += poll_ns;
>   }
>   
> +bool kvm_vcpu_can_poll(ktime_t cur, ktime_t stop)
> +{
> +	return single_task_running() && !need_resched() && ktime_before(cur, stop);
> +}
> +
>   /*
>    * The vCPU has executed a HLT instruction with in-kernel mode enabled.
>    */
> @@ -2973,8 +2978,7 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
>   				goto out;
>   			}
>   			poll_end = cur = ktime_get();
> -		} while (single_task_running() && !need_resched() &&
> -			 ktime_before(cur, stop));
> +		} while (kvm_vcpu_can_poll(cur, stop));
>   	}
>   
>   	prepare_to_rcuwait(&vcpu->wait);
> 

Queued all five, thanks.

Paolo


      parent reply	other threads:[~2021-05-24 13:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-18 12:00 [PATCH v4 1/5] KVM: exit halt polling on need_resched() for both book3s and generic halt-polling Wanpeng Li
2021-05-18 12:00 ` [PATCH v4 2/5] KVM: X86: Bail out of direct yield in case of under-committed scenarios Wanpeng Li
2021-05-18 19:21   ` Sean Christopherson
2021-05-19  2:57     ` Wanpeng Li
2021-05-24 13:42       ` Paolo Bonzini
2021-05-24 13:47         ` Wanpeng Li
2021-05-18 12:00 ` [PATCH v4 3/5] KVM: X86: Fix vCPU preempted state from guest's point of view Wanpeng Li
2021-05-18 12:00 ` [PATCH v4 4/5] KVM: X86: hyper-v: Task srcu lock when accessing kvm_memslots() Wanpeng Li
2021-05-18 12:00 ` [PATCH v4 5/5] KVM: LAPIC: Narrow the timer latency between wait_lapic_expire and world switch Wanpeng Li
2021-05-18 19:13   ` Sean Christopherson
2021-05-24 13:46 ` Paolo Bonzini [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=f0247587-e90a-1695-1399-47a67c44d861@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=bsegall@google.com \
    --cc=dmatlack@google.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kernellwp@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulus@ozlabs.org \
    --cc=seanjc@google.com \
    --cc=sjitindarsingh@gmail.com \
    --cc=venkateshs@chromium.org \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.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).