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 5606AC433EF for ; Mon, 27 Jun 2022 22:55:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242773AbiF0Wze (ORCPT ); Mon, 27 Jun 2022 18:55:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236092AbiF0Wzc (ORCPT ); Mon, 27 Jun 2022 18:55:32 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CA6B6B32 for ; Mon, 27 Jun 2022 15:55:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656370530; 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=7bjvkZS62junHocgoqnop/+MjbdA1dU+9EW2nxvBCLc=; b=g65lDIzQAHE8WOEP9xPHjsFaZg0gziCIUGnexzSXhTnsiy7gqP+53+lKw6hycX2h2cGpwi bxVeooUYbyFtx+B8RnPYAkSnW54iLSTb7zSjzykM7we61q8j3P1ZWkrtTZkMxyTS3KGOjk TTkRHhWJcFAIJGkr2o5iq8hSF13N23w= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-561-3vvwLABbPkyzyMQG_h41LA-1; Mon, 27 Jun 2022 18:55:27 -0400 X-MC-Unique: 3vvwLABbPkyzyMQG_h41LA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1073A1C05EA2; Mon, 27 Jun 2022 22:55:27 +0000 (UTC) Received: from starship (unknown [10.40.194.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id CDC331415108; Mon, 27 Jun 2022 22:55:24 +0000 (UTC) Message-ID: Subject: Re: [PATCH v6 15/17] KVM: SVM: Use target APIC ID to complete x2AVIC IRQs when possible From: Maxim Levitsky To: Paolo Bonzini , Suravee Suthikulpanit , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com, joro@8bytes.org, jon.grimm@amd.com, wei.huang2@amd.com, terry.bowman@amd.com Date: Tue, 28 Jun 2022 01:55:23 +0300 In-Reply-To: References: <20220519102709.24125-1-suravee.suthikulpanit@amd.com> <20220519102709.24125-16-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.85 on 10.11.54.7 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2022-06-24 at 18:41 +0200, Paolo Bonzini wrote: > On 5/19/22 12:27, Suravee Suthikulpanit wrote: > > + * 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; > > Neither of these is possible: first == 0 has been cheked above, and > ffs(icrh & 0xffff) cannot exceed 15. Likewise, cluster is actually > limited to 16 bits, not 20. > > Plus, C is not Pascal so no parentheses. :) > > Putting everything together, it can be simplified to this: > > + int cluster = (icrh & 0xffff0000) >> 16; > + int apic = ffs(icrh & 0xffff) - 1; > + > + /* > + * If the x2APIC logical ID sub-field (i.e. icrh[15:0]) > + * contains anything but a single bit, we cannot use the > + * fast path, because it is limited to a single vCPU. > + */ > + if (apic < 0 || icrh != (1 << apic)) > + return -EINVAL; > + > + l1_physical_id = (cluster << 4) + apic; > > > > + apic_id = (cluster << 4) + apic; Hi Paolo and Suravee Suthikulpanit! Note that this patch is not needed anymore, I fixed the avic_kick_target_vcpus_fast function, and added the support for x2apic because it was very easy to do (I already needed to parse logical id for flat and cluser modes) Best regards, Maxim Levitsky