Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2608742pxb; Sun, 17 Oct 2021 20:23:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzn1/J8Qq+UY8VytpiWOKIFr4GRKar6XdTG5BGBEaHe67OJ17WgZwQSWOO2BP7kU/dVEJ24 X-Received: by 2002:a17:90a:de16:: with SMTP id m22mr30696568pjv.54.1634527401021; Sun, 17 Oct 2021 20:23:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634527401; cv=none; d=google.com; s=arc-20160816; b=ySrzr7k2bW79WTCOFUojTIeKnZcAAtcWBeKwhZ562eiB6qc/uStRX5jp7o97iwKAHe HNSrA0zjoBn3Lm1BkFp0154g09Z9HV2bSN00r1HBs1dO8Ikyg0JgqboTKN9XkaPbd4Ma khiseESIrYiBRJJZXfE7IqDe/QMbjd4duwNHerLUO3KU2VFzrl5AgUWCquDTgAf4kxd0 3PsLuaoABCD9+9OXvsbDcrCPtEcQlwhf4TpVbm93ljVH/jltB/17VH+n3yTmmTj3mqOS roF7Fyno6v1PV03mJ/m4i91e01FHAJY+L0kFURXDbSwJq1lfNNcRbMPm7DkfXJq5piJ3 Z/JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=uJ2YVnKXuCapD+GC+e6jPtJ+8reV521rhOMXMMjLFFQ=; b=ICzc3vcB8OVarfeVpj2h80aBemUt+WJLSPoak+r2PoizJUUXkG4hcteCli3aN/Y6FB lJe+usXIrQ19x8P22GOhTZ664mJJNJ07wSfzLOnkaDwZvTCB+Rv/J9y4+RdHrAw/hnbc ux4chW0+JjDRehmWUkxWweo7nDmHeRf5C1MPl/t+1+qLgiXIFwdUDpp5p8iPrj7r+tha nnl6E6LenCIK3Jzm8P7dPEpSaeWLREj5lbEwtr2J6qDTRU9suyzaH3y1cWkGC7WPwIrQ q7rT0cDiOgpowGGbP42mpVzdpeyVl0MUVjvG8ucYArO5mNhygYinxINkfQSdb+mFWueJ DH3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FEKBFlN5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si12981477pgr.51.2021.10.17.20.23.09; Sun, 17 Oct 2021 20:23:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FEKBFlN5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243505AbhJOX2c (ORCPT + 98 others); Fri, 15 Oct 2021 19:28:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243493AbhJOX2b (ORCPT ); Fri, 15 Oct 2021 19:28:31 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 094EBC061570 for ; Fri, 15 Oct 2021 16:26:25 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id g184so9899845pgc.6 for ; Fri, 15 Oct 2021 16:26:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=uJ2YVnKXuCapD+GC+e6jPtJ+8reV521rhOMXMMjLFFQ=; b=FEKBFlN5wG9yAV2kBppjcw/xoIl103tlpwWPoOYcaTivN6B+Q7J4gJ4HIwRveDvqZj cUUk4ke64+QNWZUYnzC1ERhlCUwZcaO3PnfOHgNqTTK8e2tOii+RRN/zfPoIQAxUNf4m QMGuUSKp7X8D7JzkiI3kyqTDZvpJvQla44ATmJzLuhPjQgasY9W3ALSdSO6UeUmDX6lo VwZEln3HpV2MoWwzKX+7oQh5b9aFgDJrJMnFW63YVxVomjzmf2ZYcxayTLyhK/wVzTYJ slyL+KWyioSrGuspuUxNMjjqCnUC7+D+4N6d43OEm61HhmOxmHyL79eSEYIo5IZpFxAw 2hEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=uJ2YVnKXuCapD+GC+e6jPtJ+8reV521rhOMXMMjLFFQ=; b=daYTRO8YI+3IaC5ACYNY3Fs1rmQzlWHb5+anobh8tBqObozUbSDgpNEToayWYvgNZx x5ProYy8PIXf++CmfYTZ0Tn5XVbG017rCxJa4NK84o0HJxWVudUtnuVO5SX7VnOp4COZ 919+eRZ60ho5lWuzHRHmQ79/V6yoqAlfb5TeltyK0TQMn5H8zrFHmv1cKk0Hr8SUFcue sT34tFHmXpXFBjrMP1JK4OJcuehlUbRYWpOkP9AKOqiaLWAohz1QNrJ/E9Fo0GnCNAZN ZaYcW2tAkbIYkpzB6PdhPMLvuGYTb4Whky1eKo98jpF87utSdMeLvhujfGrBMKhVaeCY Ycsg== X-Gm-Message-State: AOAM530/6mWAvFVx0r68XXGoun6pt+1INsKTR3QFnjB4QpDI824VZ4PK RuWlQCVubdFslqXSYIn9WSP3DA== X-Received: by 2002:aa7:949c:0:b0:44c:a0df:2c7f with SMTP id z28-20020aa7949c000000b0044ca0df2c7fmr14727451pfk.34.1634340384249; Fri, 15 Oct 2021 16:26:24 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id t22sm1451643pfg.148.2021.10.15.16.26.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Oct 2021 16:26:23 -0700 (PDT) Date: Fri, 15 Oct 2021 23:26:19 +0000 From: Sean Christopherson To: Wanpeng Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel Subject: Re: [PATCH v2 3/3] KVM: vCPU kick tax cut for running vCPU Message-ID: References: <1633770532-23664-1-git-send-email-wanpengli@tencent.com> <1633770532-23664-3-git-send-email-wanpengli@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1633770532-23664-3-git-send-email-wanpengli@tencent.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Oct 09, 2021, Wanpeng Li wrote: > From: Wanpeng Li > > Sometimes a vCPU kick is following a pending request, even if @vcpu is > the running vCPU. It suffers from both rcuwait_wake_up() which has > rcu/memory barrier operations and cmpxchg(). Let's check vcpu->wait > before rcu_wait_wake_up() and whether @vcpu is the running vCPU before > cmpxchg() to tax cut this overhead. > > We evaluate the kvm-unit-test/vmexit.flat on an Intel ICX box, most of the > scores can improve ~600 cpu cycles especially when APICv is disabled. > > tscdeadline_immed > tscdeadline > self_ipi_sti_nop > .............. > x2apic_self_ipi_tpr_sti_hlt > > Suggested-by: Sean Christopherson > Signed-off-by: Wanpeng Li > --- > v1 -> v2: > * move checking running vCPU logic to kvm_vcpu_kick > * check rcuwait_active(&vcpu->wait) etc > > virt/kvm/kvm_main.c | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 7851f3a1b5f7..18209d7b3711 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -3314,8 +3314,15 @@ void kvm_vcpu_kick(struct kvm_vcpu *vcpu) > { > int me, cpu; > > - if (kvm_vcpu_wake_up(vcpu)) > - return; > + me = get_cpu(); > + > + if (rcuwait_active(&vcpu->wait) && kvm_vcpu_wake_up(vcpu)) This needs to use kvm_arch_vcpu_get_wait(), not vcpu->wait, because PPC has some funky wait stuff. One potential issue I didn't think of before. rcuwait_active() comes with the below warning, which means we might be at risk of a false negative that could result in a missed wakeup. I'm not postive on that though. /* * Note: this provides no serialization and, just as with waitqueues, * requires care to estimate as to whether or not the wait is active. */ > + goto out; > + > + if (vcpu == __this_cpu_read(kvm_running_vcpu)) { > + WARN_ON_ONCE(vcpu->mode == IN_GUEST_MODE); > + goto out; > + } > > /* > * Note, the vCPU could get migrated to a different pCPU at any point > @@ -3324,12 +3331,12 @@ void kvm_vcpu_kick(struct kvm_vcpu *vcpu) > * IPI is to force the vCPU to leave IN_GUEST_MODE, and migrating the > * vCPU also requires it to leave IN_GUEST_MODE. > */ > - me = get_cpu(); > if (kvm_arch_vcpu_should_kick(vcpu)) { > cpu = READ_ONCE(vcpu->cpu); > if (cpu != me && (unsigned)cpu < nr_cpu_ids && cpu_online(cpu)) > smp_send_reschedule(cpu); > } > +out: > put_cpu(); > } > EXPORT_SYMBOL_GPL(kvm_vcpu_kick); > -- > 2.25.1 >