Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3071977imu; Sun, 9 Dec 2018 16:38:51 -0800 (PST) X-Google-Smtp-Source: AFSGD/UywDt1BJoE2jfLzfliLoadRZwMvHIjmkBMgaqjlVog3dgBrZurg65aM5PG1ROW+w+X1pv+ X-Received: by 2002:a63:7b06:: with SMTP id w6mr9079231pgc.288.1544402331038; Sun, 09 Dec 2018 16:38:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544402331; cv=none; d=google.com; s=arc-20160816; b=CRdg9tDkHM9LHjQolVU7fyd1i0GHhbOAQuC3yXejhMRcIdGK9/VLxS+Vcc+09lPotE tl5uXzm5UMrCQuT3iW7aa4Pt54Fn44Upp8kTE2/O9FVkqDhFutOBcTDhhj7igZwWcCrl zhcYERGLcn64gidiw8v89zZgIAUykHdZfE7DWtHbPQT+YZTvp5krLt1DH1pYH2CQgiMV jyDmdqFaJJ5XHKQ4dI73/m3ZRbxAh2B+N6tBUutde0Bs05foK+rmCbNyhxEwqPf/JETF sSCSZr8KRztLSTI+0KyictraU1aR/ORTbAvE6eC/VunRf0PONOWP1/f9mX976Bdd13Kd B6DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=AAAJaR+x+qU37PF8a6qz97uABI2WDq58EMRbRYKVo/0=; b=rd61VVA454e0kNZbn4sK6HzxexaUJjAUA0IpzeUMcHN42CQzLAwC7DPv7SEFD/ZY67 tXwWJ4MXEfZIn9jq2n6ygdGb1bncg207FmQkvnQ+ZL+CBgn2rFoLtGjeZ8dGNsFtP7a+ s9yJk5n6vNulOWlZxVYjIWevhiUxPAahneqrdb/9r0/59mNx9osrdZSffZiGCfVWb9z1 72/kaHPaKjuecMWWy+6mdWW+Q/0e+PU7wxtsgN1UogrAd2GDNnuRi2b5mQLt+H1e5l9A qxbw3P2pD+Tj35eGyI9HV7/MJdo/RubzEsN4WCXmjjhS+O0vnYgtfoiH4WLyUHRhN+uZ GUGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=rt7gDOvQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w11si8366185plz.327.2018.12.09.16.38.35; Sun, 09 Dec 2018 16:38:50 -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; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=rt7gDOvQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726552AbeLJAg1 (ORCPT + 99 others); Sun, 9 Dec 2018 19:36:27 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:47284 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726534AbeLJAgZ (ORCPT ); Sun, 9 Dec 2018 19:36:25 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wBA0Y9G8045438; Mon, 10 Dec 2018 00:36:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=AAAJaR+x+qU37PF8a6qz97uABI2WDq58EMRbRYKVo/0=; b=rt7gDOvQs1NpLS3OXJY76DNmY2JK4n7+5mIj92OAdeIvPysQ6ZbJT2uNxQC7KyhmQrVY iQJq6K94buR3kpJC6VVwLOZPwmB22a5TerIx4XxYBgmgXN1lg/8c04gBGTozaEUbC9Tg YCwfay4fcQ5iR5E6nt7XWZOH3ny350p3zdtgQRbmL+yPrF7r1eT2P5XwdEzkNubGoNse MTENLqiRdDPBXvVJOhWLdMeAW7c2DKpVPOCAZyrcaKgWTKPC+KtD/YkiGHH2f7ITSKAA CZs4PLAxWHFoUoJQrC1xUoNTsVUQ0WO2VspQEIjp0K0n7nfPKT60O8DOEqIJEa7KK3Kv Sw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2p86kqk6as-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Dec 2018 00:36:15 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wBA0a97V032634 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Dec 2018 00:36:09 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wBA0a7hm021194; Mon, 10 Dec 2018 00:36:08 GMT Received: from linux.cn.oracle.com (/10.182.71.9) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 09 Dec 2018 16:36:06 -0800 From: Dongli Zhang To: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: konrad.wilk@oracle.com, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, joe.jin@oracle.com, dongli.zhang@oracle.com Subject: [PATCH v2 2/2] swiotlb: checking whether swiotlb buffer is full with io_tlb_used Date: Mon, 10 Dec 2018 08:37:58 +0800 Message-Id: <1544402278-8175-2-git-send-email-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1544402278-8175-1-git-send-email-dongli.zhang@oracle.com> References: <1544402278-8175-1-git-send-email-dongli.zhang@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9102 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=807 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812100004 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch uses io_tlb_used to help check whether swiotlb buffer is full. io_tlb_used is no longer used for only debugfs. It is also used to help optimize swiotlb_tbl_map_single(). Suggested-by: Joe Jin Signed-off-by: Dongli Zhang --- kernel/dma/swiotlb.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 3979c2c..9300341 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -76,12 +76,10 @@ static phys_addr_t io_tlb_start, io_tlb_end; */ static unsigned long io_tlb_nslabs; -#ifdef CONFIG_DEBUG_FS /* * The number of used IO TLB block */ static unsigned long io_tlb_used; -#endif /* * This is a free list describing the number of free entries available from @@ -489,6 +487,10 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, * request and allocate a buffer from that IO TLB pool. */ spin_lock_irqsave(&io_tlb_lock, flags); + + if (unlikely(nslots > io_tlb_nslabs - io_tlb_used)) + goto not_found; + index = ALIGN(io_tlb_index, stride); if (index >= io_tlb_nslabs) index = 0; @@ -538,9 +540,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, dev_warn(hwdev, "swiotlb buffer is full (sz: %zd bytes)\n", size); return SWIOTLB_MAP_ERROR; found: -#ifdef CONFIG_DEBUG_FS io_tlb_used += nslots; -#endif spin_unlock_irqrestore(&io_tlb_lock, flags); /* @@ -602,9 +602,7 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, for (i = index - 1; (OFFSET(i, IO_TLB_SEGSIZE) != IO_TLB_SEGSIZE -1) && io_tlb_list[i]; i--) io_tlb_list[i] = ++count; -#ifdef CONFIG_DEBUG_FS io_tlb_used -= nslots; -#endif } spin_unlock_irqrestore(&io_tlb_lock, flags); } -- 2.7.4