From patchwork Mon May 10 14:17:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 433158 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2896508jao; Mon, 10 May 2021 07:27:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQrF/SUcvitQJZrFmjUiH8+t8ABu956o3rPyhAHBgF4F/aDO3h/ngc6Kqn+Gt8mjo8rMuf X-Received: by 2002:a92:d9c2:: with SMTP id n2mr21646418ilq.284.1620656839836; Mon, 10 May 2021 07:27:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620656839; cv=none; d=google.com; s=arc-20160816; b=cuW9Q3bNQnRA7qkw5ea1qWAYdomusXggOk8IC3usUYPQIN0qi2Nvd/D20nlQltx109 L2fjSa2mCJ0zevvu/wacwNL1y67SYYYQbnURnJ2VK79sHmhiyLbuzpCltbpFC1FyxMMs Uv6Jlk8uu+yzURgJo1vSC/CXw4rxwbZloyoC/ekvUfj/6PO/4TZJuWvkglXMW7OS4cLK C7JFSzIp/fRK95x7vtYjWLIRFwXCnKMATdph6Tz/GUdwo7zppIUKHA+lX0T/VrEV5NlL uAPpgNZxKk34pXnxJWLa1z4lfHZ/NvUo256vCZ/c52dYdAg+JMsS5QfW10vxFskePtTB DDHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=SYz+gKiL94rtRZuO7lRzPwE8cgMG3n2nJaKJiAl4qn4=; b=HJWcnYsQDAX21K1jyeLuc88HKNE1UQaZNkwIz43nneTKGKRHVeZAqyt5NuCkHe43GB Nxs/bzURoyA4F4U8o7jW5Hcblv2i56qgS345Qz5p3ssPGoNdZz4NXKoobIQtJLIGoexz xgPIJf7KNgvx7tMi47TLRK8U7kVMPXMpdaR9IQ0rW142DJLYAkAji/e/POWMgNfY35/c jmqKgsRdNuOOc3ahKN0HLDvNRmQzqoa4AeSfGIDnsppD+zKIcwd7G1/toiW43Yq/ssTa RKro8sEyWDRPo/j/1uv6ldpNQeI+C+oTzvgkAmKVPuaVWSRxLcMS1is7+NfHWtHmbWBF zSYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si13610863ilr.121.2021.05.10.07.27.19 for ; Mon, 10 May 2021 07:27:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-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-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241872AbhEJO2T (ORCPT ); Mon, 10 May 2021 10:28:19 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2760 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238905AbhEJOZr (ORCPT ); Mon, 10 May 2021 10:25:47 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Ff38H3LXdzqTrV; Mon, 10 May 2021 22:19:11 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Mon, 10 May 2021 22:22:26 +0800 From: John Garry To: , , , , CC: , , , , , , John Garry Subject: [PATCH v2 05/15] iova: Add iova_domain_len_is_cached() Date: Mon, 10 May 2021 22:17:19 +0800 Message-ID: <1620656249-68890-6-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1620656249-68890-1-git-send-email-john.garry@huawei.com> References: <1620656249-68890-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add a function to check whether an IOVA domain currently caches a given upper IOVA len exactly. Signed-off-by: John Garry --- drivers/iommu/iova.c | 11 +++++++++++ include/linux/iova.h | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) -- 2.26.2 diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index 0e4c0e55178a..95892a0433cc 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -872,6 +872,17 @@ static void iova_magazine_push(struct iova_magazine *mag, unsigned long pfn) mag->pfns[mag->size++] = pfn; } +static unsigned long iova_len_to_rcache_max(unsigned long iova_len) +{ + return order_base_2(iova_len) + 1; +} + +/* Test if iova_len range cached upper limit matches that of IOVA domain */ +bool iova_domain_len_is_cached(struct iova_domain *iovad, unsigned long iova_len) +{ + return iova_len_to_rcache_max(iova_len) == iovad->rcache_max_size; +} + static void init_iova_rcaches(struct iova_domain *iovad) { struct iova_cpu_rcache *cpu_rcache; diff --git a/include/linux/iova.h b/include/linux/iova.h index 9974e1d3e2bc..04cc8eb6de38 100644 --- a/include/linux/iova.h +++ b/include/linux/iova.h @@ -136,7 +136,8 @@ static inline unsigned long iova_pfn(struct iova_domain *iovad, dma_addr_t iova) #if IS_ENABLED(CONFIG_IOMMU_IOVA) int iova_cache_get(void); void iova_cache_put(void); - +bool iova_domain_len_is_cached(struct iova_domain *iovad, + unsigned long iova_len); void free_iova(struct iova_domain *iovad, unsigned long pfn); void __free_iova(struct iova_domain *iovad, struct iova *iova); struct iova *alloc_iova(struct iova_domain *iovad, unsigned long size, @@ -158,6 +159,11 @@ int init_iova_flush_queue(struct iova_domain *iovad, struct iova *find_iova(struct iova_domain *iovad, unsigned long pfn); void put_iova_domain(struct iova_domain *iovad); #else +static inline bool iova_domain_len_is_cached(struct iova_domain *iovad, + unsigned long iova_len) +{ + return false; +} static inline int iova_cache_get(void) { return -ENOTSUPP;