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 2F341C433F5 for ; Wed, 4 May 2022 12:34:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349633AbiEDMi3 (ORCPT ); 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 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