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 CD0FDECAAD4 for ; Wed, 31 Aug 2022 00:38:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232255AbiHaAiQ (ORCPT ); Tue, 30 Aug 2022 20:38:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229883AbiHaAh3 (ORCPT ); Tue, 30 Aug 2022 20:37:29 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA593AB18F for ; Tue, 30 Aug 2022 17:35:59 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id z14-20020a170903018e00b00174fff57d17so3064588plg.14 for ; Tue, 30 Aug 2022 17:35:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc; bh=wFaEqzZozhtqmNn0e7C55y4Mw9837tqb72zXdm7HEXg=; b=m47lnlh0bMmxDPeqAWzcjqHjbiSUGITV4W62KnmVkp+F4sJvmaiZr0PaxYPdNcRASE nfyxSE+Ok0LjqmRY6SHPU55wwO7mJD4DlI6mrWXAR8UZCaYwjMrapALQRt8BG4Yw6xaZ y1/mdec3bxaxkPKLwau1WZIhrjbO83hQK8PnryVscEJuYA6A/BkInijkJKJb38Be4u7u ZVNV3NugVSVZel2HPBphgnE8Tx+oN00qjydm+OLGKmkjA9GU4Poc/plMsVhqIM1SDDUq /ZduO/vVAG1EWinEnK52wdNUkeI7eGcLjIFlwgKbrdJ5v0MR/z3xqd740f7ccQl5D31h Txhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc; bh=wFaEqzZozhtqmNn0e7C55y4Mw9837tqb72zXdm7HEXg=; b=cl93LWypCBmrBRJeq47T8/EPZ6vd3X1Xyg58qyBW3igTpHJgh2y1vEc/FT6+XdciG8 liEYN/kf0HwiOi79xnVzgdD+y5WSZ/P+AaxBIvMqQ+xCrWcTsGV6AOsuh0/muIA2Stpu 3X3oYGSDsKFnKUa4v0CuNMZmIt1UXGT+DL2woGEvnxymOTUHqC6pCfDdQ+3f8PPGtZbY +WfyzuFGOuqOGWNPbYyfrpAheja1xwqhTgmdx94cReKJ9WLD3WOmC9FxKDI+6FnncZC+ Nib1+ABqM6g0bEqTf5Qpe+QpwnovxWoeMQhqQ20otHjK2iL8Mhgvch2whuF8HBqbdC0v fMNg== X-Gm-Message-State: ACgBeo1aUDRfQS+KLW8GxLcRKTJ6Pp/MmPOL3e5YRuomVUtRVZ5IYt/K TIiy5lR2uaGRZSigD6n8bTMUzluW5Yw= X-Google-Smtp-Source: AA6agR6LhPKafXpIoPCYpbT1uDPrPxv+h9/n6jWQhQwWZHcFZ4OoDPz98WMIfVahlZOQnfqziyguccqBl2s= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:760c:b0:172:adc5:fc9 with SMTP id k12-20020a170902760c00b00172adc50fc9mr23592405pll.102.1661906126398; Tue, 30 Aug 2022 17:35:26 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 31 Aug 2022 00:34:57 +0000 In-Reply-To: <20220831003506.4117148-1-seanjc@google.com> Mime-Version: 1.0 References: <20220831003506.4117148-1-seanjc@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220831003506.4117148-11-seanjc@google.com> Subject: [PATCH 10/19] KVM: SVM: Document that vCPU ID == APIC ID in AVIC kick fastpatch From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Suravee Suthikulpanit , Maxim Levitsky , Li RongQing Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Document that AVIC is inhibited if any vCPU's APIC ID diverges from its vCPU ID, i.e. that there's no need to check for a destination match in the AVIC kick fast path. Opportunistically tweak comments to remove "guest bug", as that suggests KVM is punting on error handling, which is not the case. Targeting a non-existent vCPU or no vCPUs _may_ be a guest software bug, but whether or not it's a guest bug is irrelevant. Such behavior is architecturally legal and thus needs to faithfully emulated by KVM (and it is). Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/avic.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index 05a1cde8175c..3959d4766911 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -380,8 +380,8 @@ static int avic_kick_target_vcpus_fast(struct kvm *kvm, struct kvm_lapic *source cluster = (dest >> 4) << 2; } + /* Nothing to do if there are no destinations in the cluster. */ if (unlikely(!bitmap)) - /* guest bug: nobody to send the logical interrupt to */ return 0; if (!is_power_of_2(bitmap)) @@ -399,7 +399,7 @@ static int avic_kick_target_vcpus_fast(struct kvm *kvm, struct kvm_lapic *source if (WARN_ON_ONCE(index != logid_index)) return -EINVAL; - /* guest bug: non existing/reserved logical destination */ + /* Nothing to do if the logical destination is invalid. */ if (unlikely(!(logid_entry & AVIC_LOGICAL_ID_ENTRY_VALID_MASK))) return 0; @@ -418,9 +418,13 @@ static int avic_kick_target_vcpus_fast(struct kvm *kvm, struct kvm_lapic *source } } + /* + * KVM inhibits AVIC if any vCPU ID diverges from the vCPUs APIC ID, + * i.e. APIC ID == vCPU ID. Once again, nothing to do if the target + * vCPU doesn't exist. + */ target_vcpu = kvm_get_vcpu_by_id(kvm, l1_physical_id); if (unlikely(!target_vcpu)) - /* guest bug: non existing vCPU is a target of this IPI*/ return 0; target_vcpu->arch.apic->irr_pending = true; -- 2.37.2.672.g94769d06f0-goog