From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932658AbcGKS7u (ORCPT ); Mon, 11 Jul 2016 14:59:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48059 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932515AbcGKS7s (ORCPT ); Mon, 11 Jul 2016 14:59:48 -0400 Date: Mon, 11 Jul 2016 20:59:43 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Suravee Suthikulpanit Cc: joro@8bytes.org, pbonzini@redhat.com, alex.williamson@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, sherry.hurwitz@amd.com Subject: Re: [PART2 PATCH v3 07/11] iommu/amd: Introduce amd_iommu_update_ga() Message-ID: <20160711185943.GA1375@potion> References: <1468231899-6987-1-git-send-email-suravee.suthikulpanit@amd.com> <1468231899-6987-8-git-send-email-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1468231899-6987-8-git-send-email-suravee.suthikulpanit@amd.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 11 Jul 2016 18:59:48 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2016-07-11 05:11-0500, Suravee Suthikulpanit: > From: Suravee Suthikulpanit > > Introduces a new IOMMU API, amd_iommu_update_ga(), which allows > KVM (SVM) to update existing posted interrupt IOMMU IRTE when > load/unload vcpu. > > Signed-off-by: Suravee Suthikulpanit > --- > diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c > @@ -4481,4 +4481,67 @@ int amd_iommu_create_irq_domain(struct amd_iommu *iommu) > +int amd_iommu_update_ga(u32 vcpu_id, u32 cpu, u32 ga_tag, > + u64 base, bool is_run) Not just in this function does the interface between svm and iommu split ga_tag into its two components (vcpu_id and ga_tag), but it seems that the combined value could always be used instead ... Is there an advantage to passing two values? > +{ > + unsigned long flags; > + struct amd_iommu *iommu; > + > + if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)) > + return 0; > + > + for_each_iommu(iommu) { > + struct amd_ir_data *ir_data; > + > + spin_lock_irqsave(&iommu->ga_hash_lock, flags); > + > + /* Note: Update all possible ir_data for a particular > + * vcpu in a particular vm. > + */ > + hash_for_each_possible(iommu->ga_hash, ir_data, hnode, > + AMD_IOMMU_GATAG(ga_tag, vcpu_id)) { > + struct irte_ga *irte = (struct irte_ga *) ir_data->entry; (The ga_tag check is missing here too.) > + if (!irte->lo.fields_vapic.guest_mode) > + continue; > + > + update_irte_ga((struct irte_ga *)ir_data->ref, > + ir_data->irq_2_irte.devid, > + base, cpu, is_run); (The lookup leading up to here is avoidable -- svm, the caller, has the ability to map ga_tag into irte/ir_data directly with a pointer. I'm not sure if the lookup is slow enough to pardon optimization, but it might make the code simpler as well.) > + iommu_flush_irt(iommu, ir_data->irq_2_irte.devid); > + iommu_completion_wait(iommu); > + } > + > + spin_unlock_irqrestore(&iommu->ga_hash_lock, flags);