Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2813168imu; Thu, 17 Jan 2019 23:10:26 -0800 (PST) X-Google-Smtp-Source: ALg8bN5G3N0rz72gzBs759Y0Ykd0PfpEDGIIyJtm98EBhT7BkSGt+ew6oec8G8lv8jydfh/9A9f8 X-Received: by 2002:a17:902:7005:: with SMTP id y5mr18145571plk.7.1547795426514; Thu, 17 Jan 2019 23:10:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547795426; cv=none; d=google.com; s=arc-20160816; b=knbYVrww1AB5bNuxkxF5uoYHCFTnnHxTYaSKKxkRxhOxeEbmgte20DLKf1AqXDzhwU zPKU3CJVa9FOv/QVbLlFqDyzgLRzXhcIBBMvJZurIN/w34MSLz26fOdeW4QeJZFmST2J dEPgMGa4PSlxbV+InXZywmOwU2aDUGz4OcoGAbOmqruRzFHiLzEZ4IoCHSqFRCoLjk/x mQk2L+pZcIFElD6AwZAvsYtIhcXBW9SF7m/BBXg8Rq5YUK8REt7il1LoYD5uq11uIN68 b3zaJiYZNkgLUlxtWlGLr60rnejGtUU8vBXLFV9udqjbyLEnkXX2IKH5LKAl+e9sqjEM 5TzQ== 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=tgxKLYIOTtTJae48OZZZCv2XxhdZLT84wNofYlg82YI=; b=FkHa0NMkc/1UfHC9BNcliR0SBKZd9Mlopdfw/zbL/j3IElsFVEfvkrOx9h4q4IjRw+ nQrhTZMAm3fYEEho4hrdMYjn667vF3SyMYn8aNp2PxxRuOnDPXYUNlwSkn+T/x3TearA wqMNpYq+1Mvv+5yY5S+Qqscyi4UHx4mDBllHsN6zRzCGG5SRirnNLgkE5F3WG7moI6l5 jYJeMthHraeiFvVUdc3gKcKe3Da2Ko+CROlRSN1nsnaxSxUALcRCbYDKZy3eZhuf4vfa WkYcthIdNgwzOc7j2kvUclv9ttP/aKQLjhjDu2aF1vJ8Sk8gP94mlNlbg4+96wQxtsvp 5IYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=T22PYKo8; 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 p26si3884771pfj.244.2019.01.17.23.10.10; Thu, 17 Jan 2019 23:10:26 -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=T22PYKo8; 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 S1727313AbfARHIh (ORCPT + 99 others); Fri, 18 Jan 2019 02:08:37 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:53486 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727080AbfARHIf (ORCPT ); Fri, 18 Jan 2019 02:08:35 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0I74fCh091884; Fri, 18 Jan 2019 07:08:25 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=tgxKLYIOTtTJae48OZZZCv2XxhdZLT84wNofYlg82YI=; b=T22PYKo8rhkqV6c6HjAWEwdKFgjkt4Cd1uMVhRZna7i0bR9ygqqRhKGn4yzChMDDd52u 9027Z1JTItMdPKQVEBVKw870tyhgRjzp0rduwnHlkc3y3G5X4jhABrj1HzJB+G2Yy4bg kr0jt31J9N7WoTwduzdoK2KiPVNNcrtZEXF/qfy/qU5lQguCMsTB8vt/mEka0Ubw0u4j 1D9VMbfkQj7h43ZJdSolY4H3yL91y9pMOavj/Qc0O2RAgtbXLgeF/xXWvTWE3gF27XNe 2K6RkQiJWXO1vNPQZsys5BcuWkPr6INFr5Y4lHVbGzwD1NAtE7+aW8Z0du33+wbOTF9b Og== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2pybjp3x0w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Jan 2019 07:08:25 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x0I78KAp032728 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Jan 2019 07:08:20 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x0I78KHk023932; Fri, 18 Jan 2019 07:08:20 GMT Received: from linux.cn.oracle.com (/10.182.71.41) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 17 Jan 2019 23:08:19 -0800 From: Dongli Zhang To: linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.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 v3 3/3] swiotlb: checking whether swiotlb buffer is full with io_tlb_used Date: Fri, 18 Jan 2019 15:10:28 +0800 Message-Id: <1547795428-10595-3-git-send-email-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1547795428-10595-1-git-send-email-dongli.zhang@oracle.com> References: <1547795428-10595-1-git-send-email-dongli.zhang@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9139 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=686 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901180054 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 --- Changed since v2: * move #ifdef folding to previous patch (suggested by Konrad Rzeszutek Wilk) kernel/dma/swiotlb.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index bedc9f9..a01b83e 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -483,6 +483,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; -- 2.7.4