Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3435694iog; Mon, 27 Jun 2022 16:21:11 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vAFftwMWiaOPYpy1z50FDzFJDl48W5O9DTmfbqQmyMNZPIUuf73Cd+lZKaHxCZEvOVCB1D X-Received: by 2002:a17:906:58c8:b0:6fe:91d5:18d2 with SMTP id e8-20020a17090658c800b006fe91d518d2mr15351150ejs.190.1656372071131; Mon, 27 Jun 2022 16:21:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656372071; cv=none; d=google.com; s=arc-20160816; b=OJStX4RmroNh6u5Nx3qKOCNM3ZRXitB+o3ZUehYOrbLJWo8fKz+m3GMbzPP64PBsdz DNu2+hwDcPjLo1LoIvHefTMQoNYMKrMOehIk6W7ZTg7h9dlvvvClVzgtNONubGgO9YWd LKnA3+3r7M53dRC3WekxC+AG26MWtiXNO6aOprKzTUWPi6UgEw4fN4n4lfU1bSk1EiK7 RaOLUVxoO+99XP/fL275HgVWkjgW4FejnN/0gAy5oLvU6UTlbR185SlKne2Sz7jCdk3K uCEmDU5aVqcV9jQZLh/vlSYecDpscG64n6pb2v9+g9YxYyvxE116cyeFUB5qPs9M1uA4 T4zA== 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=7bjvkZS62junHocgoqnop/+MjbdA1dU+9EW2nxvBCLc=; b=NZzcd0vjW6c5Z53xkzJzlVd+/sJ13i4J5w9hXz5sHsw2Ik7oNlESSJMygyBRveH08d loQYoDLumQrP4FI35/h6lj3Ph+6xw53sA0cL7aRSuX5t5ugAlklTIeRXTsj+ubEVTGuQ Q8/nvKO9MEx2xJM99w3ztFLw7RtgFjIHbrSpwql2cp1Z/x+DxmdM1htEBdM+MT3mw8sE mKVdiAa1mJpKeJUujgiRy1dq5WXcwNcH1By14DIA7SzrzMWRL6OVBipY831k4LuN7i/s 36BsZyFfov6XDXRtYDL7uyJuoYL+O9jMhQsjTUDaBf5md4fMXOAaQt15de5v+1SDmiOh AuqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=g65lDIzQ; 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 qa12-20020a170907868c00b007065d999015si16111967ejc.232.2022.06.27.16.20.44; Mon, 27 Jun 2022 16:21:11 -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=g65lDIzQ; 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 S242771AbiF0Wze (ORCPT + 99 others); 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 X-Spam-Status: No, score=-3.2 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 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