Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3190263pxk; Mon, 5 Oct 2020 03:38:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgw8FqYzc0zeVdmW6aNNhrMHISuFtu3cm+naMpV43RnPYbkpXPq+7G9Ekn5Hwkfq1bpYOf X-Received: by 2002:a50:84a2:: with SMTP id 31mr16589241edq.138.1601894294734; Mon, 05 Oct 2020 03:38:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601894294; cv=none; d=google.com; s=arc-20160816; b=MsgvCBZ4hAV6sFlOgSwYhvbNOBy9YhO9Qre1u1jp8PhE5Bwd9+8G3fM55TXA9K+ih+ sazFMLkqv9cyW+n5RoeOjVcHBbhKfOppEeSV14V9vxi6TNJwFQK93fYefJ72J8nAV36D HmZJBCus8xjdSzs69KGJkeSX7Hb7K4SeZyxtsNWMugvES2MeKNVSQaNNR5xcY9RdPf1L GMcswGeSDEjVhWa45dKb/lVajz6K2UrWt8lxH8nrXRK4toJqvW5UPTustA0o/AJZqh8h 6Uwh8OZgByWN0xohz3fQeJWSMqSn0jCVb6tuqvqSwliIWrr4nYCDBY89QwyOsMcOAtgE Bg7w== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=MQoy07rudHVDbwGQZ06RtJ0lgZnOJvH35iKQkmwrl/8=; b=w08fqyCpPgfL7KZdVDHzt3CH29nXriR3zjdtIMvwZoWS7g3WWcb5Km20rpDFScwkiI CXE9y75KWXozTZE2VUxxgiF2ezNgP3hrbESoYuTYQOFQJNYY3h0Dp5T/WXpmb1QESynt EK389XCDpIRjYoK6sGqh6fZvEer/cEatnS8gxd9Le/oLvtV90+Bk3lKO0w5MhuYc9J/G bhT2rh7VjXLYs+xSv3kB9oVVwEaVMYrTXcTb2L0MHWLNCABKU6iQttKdcmKJYkyk8k+v POB5cXiRuVcIFntYXw3iRSx+rlrE02Eq9j9c440TEzb+Lpv3D0btf16J8uS3EwwHtm3m 4hEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y10si7088358eds.17.2020.10.05.03.37.50; Mon, 05 Oct 2020 03:38:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725919AbgJEKfn (ORCPT + 99 others); Mon, 5 Oct 2020 06:35:43 -0400 Received: from lhrrgout.huawei.com ([185.176.76.210]:2956 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725843AbgJEKfn (ORCPT ); Mon, 5 Oct 2020 06:35:43 -0400 Received: from lhreml710-chm.china.huawei.com (unknown [172.18.7.107]) by Forcepoint Email with ESMTP id 966FAD6551D65A98996D; Mon, 5 Oct 2020 11:35:41 +0100 (IST) Received: from localhost (10.52.124.175) by lhreml710-chm.china.huawei.com (10.201.108.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1913.5; Mon, 5 Oct 2020 11:35:41 +0100 Date: Mon, 5 Oct 2020 11:33:57 +0100 From: Jonathan Cameron To: Suravee Suthikulpanit CC: , , Subject: Re: [PATCH v3 14/14] iommu/amd: Adopt IO page table framework Message-ID: <20201005103357.000062d9@Huawei.com> In-Reply-To: <20201004014549.16065-15-suravee.suthikulpanit@amd.com> References: <20201004014549.16065-1-suravee.suthikulpanit@amd.com> <20201004014549.16065-15-suravee.suthikulpanit@amd.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.52.124.175] X-ClientProxiedBy: lhreml730-chm.china.huawei.com (10.201.108.81) To lhreml710-chm.china.huawei.com (10.201.108.61) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 4 Oct 2020 01:45:49 +0000 Suravee Suthikulpanit wrote: > Switch to using IO page table framework for AMD IOMMU v1 page table. > > Signed-off-by: Suravee Suthikulpanit One minor thing inline. > --- > drivers/iommu/amd/iommu.c | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > > diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c > index 77f44b927ae7..6f8316206fb8 100644 > --- a/drivers/iommu/amd/iommu.c > +++ b/drivers/iommu/amd/iommu.c > @@ -32,6 +32,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -1573,6 +1574,22 @@ static int pdev_iommuv2_enable(struct pci_dev *pdev) > return ret; > } > > +struct io_pgtable_ops * > +amd_iommu_setup_io_pgtable_ops(struct iommu_dev_data *dev_data, > + struct protection_domain *domain) > +{ > + struct amd_iommu *iommu = amd_iommu_rlookup_table[dev_data->devid]; > + > + domain->iop.pgtbl_cfg = (struct io_pgtable_cfg) { > + .pgsize_bitmap = AMD_IOMMU_PGSIZES, > + .ias = IOMMU_IN_ADDR_BIT_SIZE, > + .oas = IOMMU_OUT_ADDR_BIT_SIZE, > + .iommu_dev = &iommu->dev->dev, > + }; > + > + return alloc_io_pgtable_ops(AMD_IOMMU_V1, &domain->iop.pgtbl_cfg, domain); > +} > + > /* > * If a device is not yet associated with a domain, this function makes the > * device visible in the domain > @@ -1580,6 +1597,7 @@ static int pdev_iommuv2_enable(struct pci_dev *pdev) > static int attach_device(struct device *dev, > struct protection_domain *domain) > { > + struct io_pgtable_ops *pgtbl_ops; > struct iommu_dev_data *dev_data; > struct pci_dev *pdev; > unsigned long flags; > @@ -1623,6 +1641,12 @@ static int attach_device(struct device *dev, > skip_ats_check: > ret = 0; > > + pgtbl_ops = amd_iommu_setup_io_pgtable_ops(dev_data, domain); > + if (!pgtbl_ops) { Perhaps cleaner to not store in a local variable if you aren't going to use it? if (!amd_iommu_setup_io_pgtable_ops(dev_data, domain)) { > + ret = -ENOMEM; > + goto out; > + } > + > do_attach(dev_data, domain); > > /* > @@ -1958,6 +1982,8 @@ static void amd_iommu_domain_free(struct iommu_domain *dom) > if (domain->dev_cnt > 0) > cleanup_domain(domain); > > + free_io_pgtable_ops(&domain->iop.iop.ops); > + > BUG_ON(domain->dev_cnt != 0); > > if (!dom)