From patchwork Tue Feb 7 19:35:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 9560947 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B974D6047A for ; Tue, 7 Feb 2017 19:37:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABFE228485 for ; Tue, 7 Feb 2017 19:37:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A085228487; Tue, 7 Feb 2017 19:37:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B3EF28485 for ; Tue, 7 Feb 2017 19:37:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754414AbdBGThR (ORCPT ); Tue, 7 Feb 2017 14:37:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38152 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755045AbdBGTgB (ORCPT ); Tue, 7 Feb 2017 14:36:01 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E622981253; Tue, 7 Feb 2017 19:36:01 +0000 (UTC) Received: from t450s.home (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v17Ja1x2009540; Tue, 7 Feb 2017 14:36:01 -0500 Date: Tue, 7 Feb 2017 12:35:59 -0700 From: Alex Williamson To: Alexey Kardashevskiy Cc: linuxppc-dev@lists.ozlabs.org, David Gibson , kvm@vger.kernel.org Subject: Re: [PATCH kernel] vfio/spapr_tce: Set window when adding additional groups to container Message-ID: <20170207123559.2b878948@t450s.home> In-Reply-To: <20170207062657.21606-1-aik@ozlabs.ru> References: <20170207062657.21606-1-aik@ozlabs.ru> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 07 Feb 2017 19:36:02 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Tue, 7 Feb 2017 17:26:57 +1100 Alexey Kardashevskiy wrote: > If a container already has a group attached, attaching a new group > should just program already created IOMMU tables to the hardware via > the iommu_table_group_ops::set_window() callback. > > However 6f01cc692 "vfio/spapr: Add a helper to create default DMA window" > did not just simplify the code but also removed the set_window() calls > in the case of attaching groups to a container which already has tables > so it broke VFIO PCI hotplug. > > This reverts set_window() bits in tce_iommu_take_ownership_ddw(). > > Fixes: 6f01cc692 See Documentation/process/submitting-patches.rst for the expected format here, 12 char SHA-1 + --oneline summary. > Signed-off-by: Alexey Kardashevskiy > --- > drivers/vfio/vfio_iommu_spapr_tce.c | 21 +++++++++++++++++++++ > 1 file changed, 21 insertions(+) > > diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c > index 7690e5bf3cf1..14c62a8495a2 100644 > --- a/drivers/vfio/vfio_iommu_spapr_tce.c > +++ b/drivers/vfio/vfio_iommu_spapr_tce.c > @@ -1245,6 +1245,8 @@ static void tce_iommu_release_ownership_ddw(struct tce_container *container, > static long tce_iommu_take_ownership_ddw(struct tce_container *container, > struct iommu_table_group *table_group) > { > + long i, ret = 0; > + > if (!table_group->ops->create_table || !table_group->ops->set_window || > !table_group->ops->release_ownership) { > WARN_ON_ONCE(1); > @@ -1253,7 +1255,26 @@ static long tce_iommu_take_ownership_ddw(struct tce_container *container, > > table_group->ops->take_ownership(table_group); > > + /* Set all windows to the new group */ > + for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i) { > + struct iommu_table *tbl = container->tables[i]; checkpatch wants a blank line here. > + if (!tbl) > + continue; > + > + ret = table_group->ops->set_window(table_group, i, tbl); > + if (ret) > + goto release_exit; > + } > + > return 0; > + > +release_exit: > + for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i) > + table_group->ops->unset_window(table_group, i); > + > + table_group->ops->release_ownership(table_group); > + > + return ret; > } > > static int tce_iommu_attach_group(void *iommu_data, I've fixed these as shown below. David, please review/ack as well and I'll send a pull for v4.10. Thanks, Alex commit c019167838156a2efcc60a15fa4207710bac6e82 Author: Alexey Kardashevskiy Date: Tue Feb 7 17:26:57 2017 +1100 vfio/spapr_tce: Set window when adding additional groups to container If a container already has a group attached, attaching a new group should just program already created IOMMU tables to the hardware via the iommu_table_group_ops::set_window() callback. However commit 6f01cc692a16 ("vfio/spapr: Add a helper to create default DMA window") did not just simplify the code but also removed the set_window() calls in the case of attaching groups to a container which already has tables so it broke VFIO PCI hotplug. This reverts set_window() bits in tce_iommu_take_ownership_ddw(). Fixes: 6f01cc692a16 ("vfio/spapr: Add a helper to create default DMA window") Signed-off-by: Alexey Kardashevskiy Signed-off-by: Alex Williamson Reviewed-by: David Gibson diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c index 7690e5bf3cf1..59b3f62a2d64 100644 --- a/drivers/vfio/vfio_iommu_spapr_tce.c +++ b/drivers/vfio/vfio_iommu_spapr_tce.c @@ -1245,6 +1245,8 @@ static void tce_iommu_release_ownership_ddw(struct tce_container *container, static long tce_iommu_take_ownership_ddw(struct tce_container *container, struct iommu_table_group *table_group) { + long i, ret = 0; + if (!table_group->ops->create_table || !table_group->ops->set_window || !table_group->ops->release_ownership) { WARN_ON_ONCE(1); @@ -1253,7 +1255,27 @@ static long tce_iommu_take_ownership_ddw(struct tce_container *container, table_group->ops->take_ownership(table_group); + /* Set all windows to the new group */ + for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i) { + struct iommu_table *tbl = container->tables[i]; + + if (!tbl) + continue; + + ret = table_group->ops->set_window(table_group, i, tbl); + if (ret) + goto release_exit; + } + return 0; + +release_exit: + for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i) + table_group->ops->unset_window(table_group, i); + + table_group->ops->release_ownership(table_group); + + return ret; } static int tce_iommu_attach_group(void *iommu_data,