Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7954015rwl; Tue, 10 Jan 2023 07:22:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXu3Kgu18JAF6dCjRhjvPfv8CM2E5ba+XM+xvPNH3rzuQG3hrA7NyzMzoHUi+MVwxsmHJxtj X-Received: by 2002:a17:907:c689:b0:84d:122d:4af3 with SMTP id ue9-20020a170907c68900b0084d122d4af3mr17696880ejc.27.1673364167649; Tue, 10 Jan 2023 07:22:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673364167; cv=none; d=google.com; s=arc-20160816; b=kyAv/t1Jc3SfbIvTf6lQz/hArKqN5A9otn84u6x6lfH77VTwhTn0RDlWY1Qf89rATT L4EunCX/RKzuMhUpOJlw/deb/8lCqX6cFNXlwhY6kR86NsmZU0HANA2AnkQqWHWarLVc E/YUXmYwK2l/S89izf8pl3hsSvob79abSQPvjFuSVpwhBOVlAg67Sva+PFmHKrsnZ4uu LHNKB1+Iy2dulq+pxNxU4ijGzTAQ1cnridqQ2czEF5e0WHDkYEeat/V9uL/b3hyEtRf1 mLcPlWj3+f2R9paENuF5vE4EkCm56TBsPhlo3in0eOYaojYvkyUtR1r6CBZeFHI7nVJs 5eRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=0t9NUuvuGP/O06dkJf3cim/GYsClraG3OzauChQxows=; b=joVRz+FQjJIlvde8wsVSIeueS232ae/QyCi4wHsdEccnUWLa3KGYub2RVKIu5/Gt/R o3Y4YaX0Ep2u4d04nJmEDhewixGMMwSxpnwa95OpcoONNJV57fRGVu5A4fII/0nUR6ZI 4zo/lZgAuOPx1uU+7ffPOgO0eiEiWUc6vhjHjvqgColGn7Iyn6AFO3Ap/IOqDOVDIayU 3vMmYJjLwmEJd89JUvqHBxZSqkN0kejlXdhMVFGYkmFO/A9Im8zuQeP6iyKMhowm/Xg6 yF3z/bN8u2UyJHBEE1UVDAIsFtRJFOmscykdDjZurdwFgq8ExHgEvjTIEzA/mivIoIiQ s/mw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l6-20020a170906794600b007c0a4c149bfsi13959697ejo.403.2023.01.10.07.22.34; Tue, 10 Jan 2023 07:22:47 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238896AbjAJPMb (ORCPT + 53 others); Tue, 10 Jan 2023 10:12:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238905AbjAJPLx (ORCPT ); Tue, 10 Jan 2023 10:11:53 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1E96C192B0 for ; Tue, 10 Jan 2023 07:11:29 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 35D6B2F4; Tue, 10 Jan 2023 07:12:11 -0800 (PST) Received: from [10.57.76.227] (unknown [10.57.76.227]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E92853F67D; Tue, 10 Jan 2023 07:11:27 -0800 (PST) Message-ID: Date: Tue, 10 Jan 2023 15:11:23 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH 3/4] iommu: Introduce IOMMU call-back for processing struct KVM assigned to VFIO Content-Language: en-GB To: Suravee Suthikulpanit , linux-kernel@vger.kernel.org, iommu@lists.linux.dev Cc: joro@8bytes.org, ashish.kalra@amd.com, thomas.lendacky@amd.com, vasant.hegde@amd.com, jon.grimm@amd.com References: <20230110143137.54517-1-suravee.suthikulpanit@amd.com> <20230110143137.54517-4-suravee.suthikulpanit@amd.com> From: Robin Murphy In-Reply-To: <20230110143137.54517-4-suravee.suthikulpanit@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=ham 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 2023-01-10 14:31, Suravee Suthikulpanit wrote: > Currently, VFIO provide an kvm_vfio_file_set_kvm() interface for assigning > a KVM structure to a VFIO group. The information in struct KVM is also > useful for IOMMU drivers when setting up VFIO domain. > > Introduce struct iommu_domain_ops.set_kvm call-back function to allow > IOMMU drivers to provide call-back to process the struct KVM assigned. Hmm, it sounds like this has quite some overlap of intent with the existing "enable_nesting" op, and my gut feeling is that it's not great to have two completely different "this is a VFIO domain" mechanisms... :/ Robin. > Signed-off-by: Suravee Suthikulpanit > --- > drivers/iommu/iommu.c | 10 ++++++++++ > drivers/vfio/vfio_main.c | 1 + > include/linux/iommu.h | 4 ++++ > 3 files changed, 15 insertions(+) > > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > index 65a3b3d886dc..5116d5fe35f2 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -3231,3 +3231,13 @@ bool iommu_group_dma_owner_claimed(struct iommu_group *group) > return user; > } > EXPORT_SYMBOL_GPL(iommu_group_dma_owner_claimed); > + > +void iommu_set_kvm(struct iommu_group *group, struct kvm *kvm) > +{ > + if (!group || !group->domain || !group->domain->ops) > + return; > + > + if (group->domain->ops->set_kvm) > + group->domain->ops->set_kvm(group->domain, kvm); > +} > +EXPORT_SYMBOL_GPL(iommu_set_kvm); > diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c > index 2d168793d4e1..7641e3a0c986 100644 > --- a/drivers/vfio/vfio_main.c > +++ b/drivers/vfio/vfio_main.c > @@ -1652,6 +1652,7 @@ void vfio_file_set_kvm(struct file *file, struct kvm *kvm) > > mutex_lock(&group->group_lock); > group->kvm = kvm; > + iommu_set_kvm(group->iommu_group, kvm); > mutex_unlock(&group->group_lock); > } > EXPORT_SYMBOL_GPL(vfio_file_set_kvm); > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > index 3c9da1f8979e..43000231d3d7 100644 > --- a/include/linux/iommu.h > +++ b/include/linux/iommu.h > @@ -42,6 +42,7 @@ struct notifier_block; > struct iommu_sva; > struct iommu_fault_event; > struct iommu_dma_cookie; > +struct kvm; > > /* iommu fault flags */ > #define IOMMU_FAULT_READ 0x0 > @@ -314,6 +315,8 @@ struct iommu_domain_ops { > unsigned long quirks); > > void (*free)(struct iommu_domain *domain); > + > + void (*set_kvm)(struct iommu_domain *domain, struct kvm *kvm); > }; > > /** > @@ -391,6 +394,7 @@ void iommu_device_sysfs_remove(struct iommu_device *iommu); > int iommu_device_link(struct iommu_device *iommu, struct device *link); > void iommu_device_unlink(struct iommu_device *iommu, struct device *link); > int iommu_deferred_attach(struct device *dev, struct iommu_domain *domain); > +void iommu_set_kvm(struct iommu_group *group, struct kvm *kvm); > > static inline struct iommu_device *dev_to_iommu_device(struct device *dev) > {