Received: by 10.223.176.5 with SMTP id f5csp1692397wra; Wed, 31 Jan 2018 10:05:05 -0800 (PST) X-Google-Smtp-Source: AH8x227/oSt2MJDEyhxzzqbHAt/jJ5uQWRhdR4ad3NwS7oDc/aafjf/3FXg6E9p2nARnJwA5XJCD X-Received: by 10.98.59.80 with SMTP id i77mr34711198pfa.146.1517421905782; Wed, 31 Jan 2018 10:05:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517421905; cv=none; d=google.com; s=arc-20160816; b=RFSmLg62DTTBctGjPa2TcvLWT9hMxiA/bSeR0+1ZUfmIwGrF5KLHxhgh/ZfOoJEzfa czR1Iu4wxXvnKf6ZhvjRsoskSvw72k+gVD21HdUbJJCsfhE9geUEc23G4ALYDgSXNdbI j0Fy+tXlnQr91S0G3SwZcu0z/V41aFqclq6I8LtegYYePmq07VD85PLxvCpeZuc4Oocn ONTHQp1RVpMEYYztxlf1PsWv2B79kxw058qvgd6/HARfMvQjviEnG4Up7L/YAljtBOi+ /nkwyAMGrOB2gtlA9scNLhCZhblPYRXZSo8AlW9oJ2Mtu289lBUessR2kQ1Sh+6+p/4z jvug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=cgkLjfzDaayJjuqszb8DbNPApgQtg679vW0UfeBTI5I=; b=GcbSXl5xPGQ8QrxIwx0nuekJXS4XxSIXqznphKXpKmELYY9qnYAbmDcmaSUN3/vAes bnMbao3xmFCzvB6r1rtxfKoxtvFWe2vjdbP1UqwqLD5St4xNNKMdukjiYE8dagtdvglB 5kLCX2XzI7R1qt1Uv1ypXV34rDTnZaau7MBzHpHGaBS0zVAHFDRG8wgPQBAcJ62inYh4 Lzv4tULtRO17ZzyBgPNvbjuOhizZ8eSBGo/rD4x3UEdXFtDHFGmf7zcgPUkXFw6WTI/U d6hTNJ+TpW6DBHUoZyTPcrOoEuPzGDMuEhsYQUU4+mnaE6lI2yArNyDdsCwiuvOcibod /ecw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bj8-v6si2191503plb.238.2018.01.31.10.04.50; Wed, 31 Jan 2018 10:05:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753563AbeAaSCw (ORCPT + 99 others); Wed, 31 Jan 2018 13:02:52 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:40892 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752824AbeAaSCu (ORCPT ); Wed, 31 Jan 2018 13:02:50 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 40C341529; Wed, 31 Jan 2018 10:02:50 -0800 (PST) Received: from [10.1.210.88] (e110467-lin.cambridge.arm.com [10.1.210.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4DE1A3F487; Wed, 31 Jan 2018 10:02:49 -0800 (PST) Subject: Re: [PATCH 1/2] iommu: Fix iommu_unmap and iommu_unmap_fast return type To: Suravee Suthikulpanit , iommu@lists.linux-foundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jroedel@suse.de References: <1517363285-89304-1-git-send-email-suravee.suthikulpanit@amd.com> <1517363285-89304-2-git-send-email-suravee.suthikulpanit@amd.com> From: Robin Murphy Message-ID: Date: Wed, 31 Jan 2018 18:02:47 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1517363285-89304-2-git-send-email-suravee.suthikulpanit@amd.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Suravee, On 31/01/18 01:48, Suravee Suthikulpanit wrote: > Currently, iommu_unmap and iommu_unmap_fast return unmapped > pages with size_t. However, the actual value returned could > be error codes (< 0), which can be misinterpreted as large > number of unmapped pages. Therefore, change the return type to ssize_t. > > Cc: Joerg Roedel > Cc: Alex Williamson > Signed-off-by: Suravee Suthikulpanit > --- > drivers/iommu/amd_iommu.c | 6 +++--- > drivers/iommu/intel-iommu.c | 4 ++-- Er, there are a few more drivers than that implementing iommu_ops ;) It seems like it might be more sensible to fix the single instance of a driver returning -EINVAL (which appears to be a "should never happen if used correctly" kinda thing anyway) and leave the API-internal callback prototype as-is. I do agree the inconsistency of iommu_unmap() itself wants sorting, though (particularly the !IOMMU_API stubs which are wrong either way). Robin. > drivers/iommu/iommu.c | 16 ++++++++-------- > include/linux/iommu.h | 20 ++++++++++---------- > 4 files changed, 23 insertions(+), 23 deletions(-) > > diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c > index 7d5eb00..3609f51 100644 > --- a/drivers/iommu/amd_iommu.c > +++ b/drivers/iommu/amd_iommu.c > @@ -3030,11 +3030,11 @@ static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova, > return ret; > } > > -static size_t amd_iommu_unmap(struct iommu_domain *dom, unsigned long iova, > - size_t page_size) > +static ssize_t amd_iommu_unmap(struct iommu_domain *dom, unsigned long iova, > + size_t page_size) > { > struct protection_domain *domain = to_pdomain(dom); > - size_t unmap_size; > + ssize_t unmap_size; > > if (domain->mode == PAGE_MODE_NONE) > return -EINVAL; > diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c > index 4a2de34..15ba866 100644 > --- a/drivers/iommu/intel-iommu.c > +++ b/drivers/iommu/intel-iommu.c > @@ -5068,8 +5068,8 @@ static int intel_iommu_map(struct iommu_domain *domain, > return ret; > } > > -static size_t intel_iommu_unmap(struct iommu_domain *domain, > - unsigned long iova, size_t size) > +static ssize_t intel_iommu_unmap(struct iommu_domain *domain, > + unsigned long iova, size_t size) > { > struct dmar_domain *dmar_domain = to_dmar_domain(domain); > struct page *freelist = NULL; > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > index 3de5c0b..8f7da8a 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -1557,12 +1557,12 @@ int iommu_map(struct iommu_domain *domain, unsigned long iova, > } > EXPORT_SYMBOL_GPL(iommu_map); > > -static size_t __iommu_unmap(struct iommu_domain *domain, > - unsigned long iova, size_t size, > - bool sync) > +static ssize_t __iommu_unmap(struct iommu_domain *domain, > + unsigned long iova, size_t size, > + bool sync) > { > const struct iommu_ops *ops = domain->ops; > - size_t unmapped_page, unmapped = 0; > + ssize_t unmapped_page, unmapped = 0; > unsigned long orig_iova = iova; > unsigned int min_pagesz; > > @@ -1617,15 +1617,15 @@ static size_t __iommu_unmap(struct iommu_domain *domain, > return unmapped; > } > > -size_t iommu_unmap(struct iommu_domain *domain, > - unsigned long iova, size_t size) > +ssize_t iommu_unmap(struct iommu_domain *domain, > + unsigned long iova, size_t size) > { > return __iommu_unmap(domain, iova, size, true); > } > EXPORT_SYMBOL_GPL(iommu_unmap); > > -size_t iommu_unmap_fast(struct iommu_domain *domain, > - unsigned long iova, size_t size) > +ssize_t iommu_unmap_fast(struct iommu_domain *domain, > + unsigned long iova, size_t size) > { > return __iommu_unmap(domain, iova, size, false); > } > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > index 41b8c57..78df048 100644 > --- a/include/linux/iommu.h > +++ b/include/linux/iommu.h > @@ -199,8 +199,8 @@ struct iommu_ops { > void (*detach_dev)(struct iommu_domain *domain, struct device *dev); > int (*map)(struct iommu_domain *domain, unsigned long iova, > phys_addr_t paddr, size_t size, int prot); > - size_t (*unmap)(struct iommu_domain *domain, unsigned long iova, > - size_t size); > + ssize_t (*unmap)(struct iommu_domain *domain, unsigned long iova, > + size_t size); > size_t (*map_sg)(struct iommu_domain *domain, unsigned long iova, > struct scatterlist *sg, unsigned int nents, int prot); > void (*flush_iotlb_all)(struct iommu_domain *domain); > @@ -299,10 +299,10 @@ extern void iommu_detach_device(struct iommu_domain *domain, > extern struct iommu_domain *iommu_get_domain_for_dev(struct device *dev); > extern int iommu_map(struct iommu_domain *domain, unsigned long iova, > phys_addr_t paddr, size_t size, int prot); > -extern size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, > - size_t size); > -extern size_t iommu_unmap_fast(struct iommu_domain *domain, > - unsigned long iova, size_t size); > +extern ssize_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, > + size_t size); > +extern ssize_t iommu_unmap_fast(struct iommu_domain *domain, > + unsigned long iova, size_t size); > extern size_t default_iommu_map_sg(struct iommu_domain *domain, unsigned long iova, > struct scatterlist *sg,unsigned int nents, > int prot); > @@ -465,14 +465,14 @@ static inline int iommu_map(struct iommu_domain *domain, unsigned long iova, > return -ENODEV; > } > > -static inline int iommu_unmap(struct iommu_domain *domain, unsigned long iova, > - size_t size) > +static inline ssize_t iommu_unmap(struct iommu_domain *domain, > + unsigned long iova, size_t size) > { > return -ENODEV; > } > > -static inline int iommu_unmap_fast(struct iommu_domain *domain, unsigned long iova, > - int gfp_order) > +static inline ssize_t iommu_unmap_fast(struct iommu_domain *domain, > + unsigned long iova, int gfp_order) > { > return -ENODEV; > } >