From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1431C433EF for ; Wed, 8 Dec 2021 01:55:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243391AbhLHB6x (ORCPT ); Tue, 7 Dec 2021 20:58:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243363AbhLHB6h (ORCPT ); Tue, 7 Dec 2021 20:58:37 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3C07C061B38 for ; Tue, 7 Dec 2021 17:55:05 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id e10-20020a17090301ca00b00141fbe2569dso268682plh.14 for ; Tue, 07 Dec 2021 17:55:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=sWS8lI0gUmOyHyHSjJQNlBlA+evEhEXiCmD7ctQTR2I=; b=IGqaujrdw3pJA8/VhNCiiJK2demMr9npnPg8OO94u4zJussXfBB3Cqu07hb5L7vmoo /c6MfWai3Vea5erWwSXjPyme/mdg306Z4WzeqPKrZhYYQBJGzaKAveodHtgEkT8tGWUZ PcpS5xXAqfMzOfKNtBI5GkB/zi4X5qcK3VVJcB7cjBoby9q8TRWgFnv/iAXQVa0SD/En CozCyLTvHHATnEtLUrsJYhslqGc5KRzmC/q9aBARyhCobQnFyxrw8rUgkz6UAiq3kgzx Taw5NHJldSf8XzoSB8uGZbZbfhVVGSr8PCF//rfTWwBTVMqeUGHKmFD1J+qhibeA4Ou/ sLhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=sWS8lI0gUmOyHyHSjJQNlBlA+evEhEXiCmD7ctQTR2I=; b=TZPp7H3e2emq8WBfrKmst8R6yK77JgHa7z+vphPJfh1PO6oSVAFd6CwHridpdmp7sJ Bt9YT+KkUjoERezoyfzyo+e10XXl5P1ZPPipEstxD6ZrIozY9MU66X02yaRoJT9OLYww BbJ6P/9nZo6mg0Z+rvl3dnH0abkxqQLiumBvNiceyQg/y+hVv5jHtG32mpYy81jT97S2 mUgub/+BHzszaBeRf648Y6DB7wuEZUfF46IajAhGNqWWuvf85rBiq0b0z9lFf1E9wT9a r39Twkzvi+77UZ39LPgMs5MaokTVLq4dvX4jD0DnyWNEs4L7Azwe0LFC0ODsBz2qQWop dWKw== X-Gm-Message-State: AOAM530utCbB9j5NUOp4TIoRYkHJxK/TjQpabeLjI7VogffMDLalcBPc lwnzTWI4OoQh58AiWbEtDSmY+Pe6jjE= X-Google-Smtp-Source: ABdhPJzthhrK0JA6NDs214v10Pktv2tAPLKbFKJ7sATCDbyBlSHPGWuwB1tBteo7rjgt3jNfMh86Ubp8Krc= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a63:a0b:: with SMTP id 11mr27831511pgk.282.1638928505499; Tue, 07 Dec 2021 17:55:05 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 8 Dec 2021 01:52:21 +0000 In-Reply-To: <20211208015236.1616697-1-seanjc@google.com> Message-Id: <20211208015236.1616697-12-seanjc@google.com> Mime-Version: 1.0 References: <20211208015236.1616697-1-seanjc@google.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog Subject: [PATCH v3 11/26] KVM: SVM: Don't bother checking for "running" AVIC when kicking for IPIs From: Sean Christopherson To: Paolo Bonzini , Joerg Roedel Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Suravee Suthikulpanit , kvm@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Maxim Levitsky Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Drop the avic_vcpu_is_running() check when waking vCPUs in response to a VM-Exit due to incomplete IPI delivery. The check isn't wrong per se, but it's not 100% accurate in the sense that it doesn't guarantee that the vCPU was one of the vCPUs that didn't receive the IPI. The check isn't required for correctness as blocking == !running in this context. >From a performance perspective, waking a live task is not expensive as the only moderately costly operation is a locked operation to temporarily disable preemption. And if that is indeed a performance issue, kvm_vcpu_is_blocking() would be a better check than poking into the AVIC. Signed-off-by: Sean Christopherson Reviewed-by: Maxim Levitsky --- arch/x86/kvm/svm/avic.c | 15 +++++++++------ arch/x86/kvm/svm/svm.h | 11 ----------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index e2e4e9f04458..37575b71cdf3 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -295,13 +295,16 @@ static void avic_kick_target_vcpus(struct kvm *kvm, struct kvm_lapic *source, struct kvm_vcpu *vcpu; unsigned long i; + /* + * Wake any target vCPUs that are blocking, i.e. waiting for a wake + * event. There's no need to signal doorbells, as hardware has handled + * vCPUs that were in guest at the time of the IPI, and vCPUs that have + * since entered the guest will have processed pending IRQs at VMRUN. + */ kvm_for_each_vcpu(i, vcpu, kvm) { - bool m = kvm_apic_match_dest(vcpu, source, - icrl & APIC_SHORT_MASK, - GET_APIC_DEST_FIELD(icrh), - icrl & APIC_DEST_MASK); - - if (m && !avic_vcpu_is_running(vcpu)) + if (kvm_apic_match_dest(vcpu, source, icrl & APIC_SHORT_MASK, + GET_APIC_DEST_FIELD(icrh), + icrl & APIC_DEST_MASK)) kvm_vcpu_wake_up(vcpu); } } diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 9f153c59f2c8..ca51d6dfc8e6 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -574,17 +574,6 @@ extern struct kvm_x86_nested_ops svm_nested_ops; #define VMCB_AVIC_APIC_BAR_MASK 0xFFFFFFFFFF000ULL -static inline bool avic_vcpu_is_running(struct kvm_vcpu *vcpu) -{ - struct vcpu_svm *svm = to_svm(vcpu); - u64 *entry = svm->avic_physical_id_cache; - - if (!entry) - return false; - - return (READ_ONCE(*entry) & AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK); -} - int avic_ga_log_notifier(u32 ga_tag); void avic_vm_destroy(struct kvm *kvm); int avic_vm_init(struct kvm *kvm); -- 2.34.1.400.ga245620fadb-goog From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6ED85C433EF for ; Wed, 8 Dec 2021 01:55:10 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 2E3C860F0B; Wed, 8 Dec 2021 01:55:10 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bnvUgcN8N5ro; Wed, 8 Dec 2021 01:55:09 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id 076A360F04; Wed, 8 Dec 2021 01:55:09 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id D2B71C001E; Wed, 8 Dec 2021 01:55:08 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 10110C001E for ; Wed, 8 Dec 2021 01:55:07 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id A78AE82660 for ; Wed, 8 Dec 2021 01:55:06 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=google.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QJm5QAwMQTSq for ; Wed, 8 Dec 2021 01:55:06 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by smtp1.osuosl.org (Postfix) with ESMTPS id 15B08824EE for ; Wed, 8 Dec 2021 01:55:06 +0000 (UTC) Received: by mail-pg1-x549.google.com with SMTP id n6-20020a632706000000b00330ca963fc3so450789pgn.3 for ; Tue, 07 Dec 2021 17:55:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=sWS8lI0gUmOyHyHSjJQNlBlA+evEhEXiCmD7ctQTR2I=; b=IGqaujrdw3pJA8/VhNCiiJK2demMr9npnPg8OO94u4zJussXfBB3Cqu07hb5L7vmoo /c6MfWai3Vea5erWwSXjPyme/mdg306Z4WzeqPKrZhYYQBJGzaKAveodHtgEkT8tGWUZ PcpS5xXAqfMzOfKNtBI5GkB/zi4X5qcK3VVJcB7cjBoby9q8TRWgFnv/iAXQVa0SD/En CozCyLTvHHATnEtLUrsJYhslqGc5KRzmC/q9aBARyhCobQnFyxrw8rUgkz6UAiq3kgzx Taw5NHJldSf8XzoSB8uGZbZbfhVVGSr8PCF//rfTWwBTVMqeUGHKmFD1J+qhibeA4Ou/ sLhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=sWS8lI0gUmOyHyHSjJQNlBlA+evEhEXiCmD7ctQTR2I=; b=KcDnCg9HD/EtdKXrb34RNdQ19ksHOGzoyzIfWy4UdFX53ZRair9Ki3ZjJ4cDO3KWEf gXeAEG6p5ZM0ZO+RHO7qPk+v1vAEV2fl2JUvLNrMwIqiyIVYkCydtKEDpNthW/aYPPVl uWhS1E34UWiWA+KmoqdReLla4a3rw1vBVe/IQmVdoMv8GY7P16pnCsEJykpwNl34FdPh /Kip7e7+C5obZgwhnjeR0BLSwTXd/6UDDWrHnxaPdE8Yi0evNMGH63qGAqZEVe9zVF61 PX9ukUaqoSKvjO36ojZgVocz9U9a9NLCnEW411LPY56TvLR7vx1hnwX6q93CoAoPvOtI YlfQ== X-Gm-Message-State: AOAM531or/B7DaLVyot/yq6gdG72zPK4cLkBgMHgGDJMIZT9sJuibeak sGgwnGMwkVswoylqWuf18fzUkTc+ipw= X-Google-Smtp-Source: ABdhPJzthhrK0JA6NDs214v10Pktv2tAPLKbFKJ7sATCDbyBlSHPGWuwB1tBteo7rjgt3jNfMh86Ubp8Krc= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a63:a0b:: with SMTP id 11mr27831511pgk.282.1638928505499; Tue, 07 Dec 2021 17:55:05 -0800 (PST) Date: Wed, 8 Dec 2021 01:52:21 +0000 In-Reply-To: <20211208015236.1616697-1-seanjc@google.com> Message-Id: <20211208015236.1616697-12-seanjc@google.com> Mime-Version: 1.0 References: <20211208015236.1616697-1-seanjc@google.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog Subject: [PATCH v3 11/26] KVM: SVM: Don't bother checking for "running" AVIC when kicking for IPIs To: Paolo Bonzini , Joerg Roedel Cc: Wanpeng Li , kvm@vger.kernel.org, Sean Christopherson , linux-kernel@vger.kernel.org, Maxim Levitsky , iommu@lists.linux-foundation.org, Vitaly Kuznetsov , Jim Mattson X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sean Christopherson via iommu Reply-To: Sean Christopherson Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" Drop the avic_vcpu_is_running() check when waking vCPUs in response to a VM-Exit due to incomplete IPI delivery. The check isn't wrong per se, but it's not 100% accurate in the sense that it doesn't guarantee that the vCPU was one of the vCPUs that didn't receive the IPI. The check isn't required for correctness as blocking == !running in this context. >From a performance perspective, waking a live task is not expensive as the only moderately costly operation is a locked operation to temporarily disable preemption. And if that is indeed a performance issue, kvm_vcpu_is_blocking() would be a better check than poking into the AVIC. Signed-off-by: Sean Christopherson Reviewed-by: Maxim Levitsky --- arch/x86/kvm/svm/avic.c | 15 +++++++++------ arch/x86/kvm/svm/svm.h | 11 ----------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index e2e4e9f04458..37575b71cdf3 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -295,13 +295,16 @@ static void avic_kick_target_vcpus(struct kvm *kvm, struct kvm_lapic *source, struct kvm_vcpu *vcpu; unsigned long i; + /* + * Wake any target vCPUs that are blocking, i.e. waiting for a wake + * event. There's no need to signal doorbells, as hardware has handled + * vCPUs that were in guest at the time of the IPI, and vCPUs that have + * since entered the guest will have processed pending IRQs at VMRUN. + */ kvm_for_each_vcpu(i, vcpu, kvm) { - bool m = kvm_apic_match_dest(vcpu, source, - icrl & APIC_SHORT_MASK, - GET_APIC_DEST_FIELD(icrh), - icrl & APIC_DEST_MASK); - - if (m && !avic_vcpu_is_running(vcpu)) + if (kvm_apic_match_dest(vcpu, source, icrl & APIC_SHORT_MASK, + GET_APIC_DEST_FIELD(icrh), + icrl & APIC_DEST_MASK)) kvm_vcpu_wake_up(vcpu); } } diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 9f153c59f2c8..ca51d6dfc8e6 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -574,17 +574,6 @@ extern struct kvm_x86_nested_ops svm_nested_ops; #define VMCB_AVIC_APIC_BAR_MASK 0xFFFFFFFFFF000ULL -static inline bool avic_vcpu_is_running(struct kvm_vcpu *vcpu) -{ - struct vcpu_svm *svm = to_svm(vcpu); - u64 *entry = svm->avic_physical_id_cache; - - if (!entry) - return false; - - return (READ_ONCE(*entry) & AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK); -} - int avic_ga_log_notifier(u32 ga_tag); void avic_vm_destroy(struct kvm *kvm); int avic_vm_init(struct kvm *kvm); -- 2.34.1.400.ga245620fadb-goog _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu