Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1444900iob; Thu, 5 May 2022 01:05:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3S69UkcgHSSz74/tC1W1RTcV6IxsUhMLYndvfZFeDGKadOLeO4U0xT2veOy1b7EUUM5Zg X-Received: by 2002:a17:906:7d5:b0:6f3:a6a5:28c6 with SMTP id m21-20020a17090607d500b006f3a6a528c6mr24924485ejc.11.1651737942020; Thu, 05 May 2022 01:05:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651737942; cv=none; d=google.com; s=arc-20160816; b=0uLozV10um6uKnAOKO7j7sUGQON9omWBzU+l/W1lazBJDeEi2kne+k5K38lDCSrBE3 dGu+tfzzfXzsR88bN8jogOonaN7ONPilscSSzz+DXwAzncqibhkVZsw6EX9XKiwG0kEP 5YML56DSprFAT9/zx6pNIS2LFio/4GaKHJCbLQuQKHkQD7cMoXQT+O258eAj0guWoaIv 35shQuaeVFT/qbmEN1QVreRfx600T1OOExAF9uBGNyQcJg+ecVrfaUrgYqoev6E6tya2 66/Fjf5UMtrgFYw4dKR/L0TLP15ZBBWLRJmOiB4iDENKsn/GmQ6Eu2023nBysnwbWB5H pZzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=ct2PlEY6QQ3N5sgB9Tu4Cg6jVTTmJssD5F6j4gnRtK4=; b=tIbrRY2PIlu/i/JdkQ83SM4OaxYe8qMYsq6kVxCub6AqibIi7Co8fr6Exlb+1+vf7D KAINpI67ec76drBAHKqf43V8nl2QyXTwF0alVeF91zi1wU/GEEUx0sCcXAcFzglg8l+i NZiBjeT/djgIMmjTZsdXACZBApd3KRhJRjZ7hMIwwe4gcei8eTwv2Cuzjg3eUsgJCn9g Zl7gmdleBUHJvBzsLvoKkZmJrLc0BGCGkdvN12pSVJ/zQxTwQQS7SAhF7obWcv6RG/wG q/fUR5joGqYlQzIxNGzc+YZ8zTs7Z3GVvItaLpbcLI5JveL+CwIVo5bmq6qdx0Wg/ert mzHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=F6luokug; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga41-20020a1709070c2900b006f372b0ce85si1744008ejc.680.2022.05.05.01.05.18; Thu, 05 May 2022 01:05:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=F6luokug; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240449AbiEDMi3 (ORCPT + 99 others); Wed, 4 May 2022 08:38:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349674AbiEDMi0 (ORCPT ); Wed, 4 May 2022 08:38:26 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 371FC26ADC for ; Wed, 4 May 2022 05:34:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651667687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ct2PlEY6QQ3N5sgB9Tu4Cg6jVTTmJssD5F6j4gnRtK4=; b=F6luokugMjKoUekuWCn08h8HR6nPWTG7THp4mrk0HQ+OBiXwW8KSWotxE6Fdmf4bIRLTZn HwrY2z73rTriA94V4yCzWx8imlKGX8u2Gajeq7F59TzoK6o1BE02daYaW1mzltm9XdXeXN uU4sYviCVLZ8WSEk56TkcUl6u/lRzbw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-656-TFrKv3fMMoeKwU5CoYnd8w-1; Wed, 04 May 2022 08:34:42 -0400 X-MC-Unique: TFrKv3fMMoeKwU5CoYnd8w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A3DBE185A7BA; Wed, 4 May 2022 12:34:41 +0000 (UTC) Received: from starship (unknown [10.40.192.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F7B640CF8F8; Wed, 4 May 2022 12:34:39 +0000 (UTC) Message-ID: <93e65bad6bbb8b1c198aa4da295d4d48ad5e24f3.camel@redhat.com> Subject: Re: [PATCH v3 13/14] KVM: SVM: Use target APIC ID to complete x2AVIC IRQs when possible From: Maxim Levitsky To: Suravee Suthikulpanit , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: pbonzini@redhat.com, seanjc@google.com, joro@8bytes.org, jon.grimm@amd.com, wei.huang2@amd.com, terry.bowman@amd.com Date: Wed, 04 May 2022 15:34:38 +0300 In-Reply-To: <20220504073128.12031-14-suravee.suthikulpanit@amd.com> References: <20220504073128.12031-1-suravee.suthikulpanit@amd.com> <20220504073128.12031-14-suravee.suthikulpanit@amd.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2022-05-04 at 02:31 -0500, Suravee Suthikulpanit wrote: > For x2AVIC, the index from incomplete IPI #vmexit info is invalid > for logical cluster mode. Only ICRH/ICRL values can be used > to determine the IPI destination APIC ID. > > Since QEMU defines guest physical APIC ID to be the same as > vCPU ID, it can be used to quickly identify the target vCPU to deliver IPI, > and avoid the overhead from searching through all vCPUs to match the target > vCPU. > > Signed-off-by: Suravee Suthikulpanit > --- > arch/x86/kvm/svm/avic.c | 21 ++++++++++++++++++++- > 1 file changed, 20 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c > index 3b6a96043633..a526fbc60bbd 100644 > --- a/arch/x86/kvm/svm/avic.c > +++ b/arch/x86/kvm/svm/avic.c > @@ -377,7 +377,26 @@ static int avic_kick_target_vcpus_fast(struct kvm *kvm, struct kvm_lapic *source > /* For xAPIC logical mode, the index is for logical APIC table. */ > apic_id = avic_logical_id_table[index] & 0x1ff; > } else { > - return -EINVAL; > + /* For x2APIC logical mode, cannot leverage the index. > + * Instead, calculate physical ID from logical ID in ICRH. > + */ > + int apic; > + int first = ffs(icrh & 0xffff); > + int last = fls(icrh & 0xffff); > + int cluster = (icrh & 0xffff0000) >> 16; > + > + /* > + * If the x2APIC logical ID sub-field (i.e. icrh[15:0]) contains zero > + * or more than 1 bits, we cannot match just one vcpu to kick for > + * fast path. > + */ > + if (!first || (first != last)) > + return -EINVAL; > + > + apic = first - 1; > + if ((apic < 0) || (apic > 15) || (cluster >= 0xfffff)) > + return -EINVAL; > + apic_id = (cluster << 4) + apic; > } > } > Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky