From patchwork Thu Aug 1 12:21:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 170377 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp5364820ile; Thu, 1 Aug 2019 05:22:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqytqTpCZSSceVZi1rNQYZl5nNYVVUl3GvFU8dvgYmFWCuG9BOIOALlHcxoH02u1STrDXkiD X-Received: by 2002:a63:f443:: with SMTP id p3mr38405532pgk.345.1564662155465; Thu, 01 Aug 2019 05:22:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564662155; cv=none; d=google.com; s=arc-20160816; b=DFfsE1jOfwev7DJAuONBshhCsRyKLWECak4uX5cPJNwc4NxF8MfEx2edoTNlkha/yQ P5j2UwpH4spjcW0/PHouOUYCY2sdUd8ixms5j6HRoivcsOL6ksKvVVBqMEE/P08w8qcz e+3RQlWpnQ0Yqk1T9DGgzewVykdNMEyJrPo+JM2R7URG/fXsKMbDsj9PnEAoz+rKET3E +8aHSOVFwSHzkoKuMHIm7h4a60Kz1TUB9BaNCNsWdyjIRK1YtIRMaEZQWFAiGM5fWF6k 8OF84AFHj37V6K7lNJbj/LXpBPiPxs/5c/LDiyUY9H3W5YeFm/vSkefXlY+0lJvbXpuV b6jg== 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:mime-version :message-id:date:subject:cc:to:from; bh=2RR27ccmOXJMfdagP4Tod2X5aHvvEUUykC8v55+NLXA=; b=kHcNuogcR8ChS0zBy2pMR7CLmdGtOhwRLYpuaGNxfyDT2FL0vQ0oY1G3xl/fvcp+fG aOQPdqsDcakiDFC5T2TPXW+EDBa3NLHpHSDng3wba2eD4R9sqMfAjIv01iGFgZB6LlRt GoYGl9ENJXFb+rCG+LJ6+IcKEogzN3WqRBXDkW5/aBJX08/JZllH82V3nxdn8y+rYhqI z5e7RgMV1Py3oE+RflvwqfJ7BKJ6/zK6DLj15byUCKvZE2oXqguEDZTaaF8xH027PvQy 5geMsyXbHamT/3PBv5PD3juovz2ul/n9C/d8fAxvZ+a1MKt+9gyv5NsOWwy9tb0YSiYR JliQ== 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 i189si38269331pge.253.2019.08.01.05.22.35; Thu, 01 Aug 2019 05:22:35 -0700 (PDT) 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 S1731228AbfHAMWe (ORCPT + 29 others); Thu, 1 Aug 2019 08:22:34 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:3692 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728217AbfHAMWc (ORCPT ); Thu, 1 Aug 2019 08:22:32 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 00C158748E0FA7FF6A83; Thu, 1 Aug 2019 20:22:27 +0800 (CST) Received: from HGHY4L002753561.china.huawei.com (10.133.215.186) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Thu, 1 Aug 2019 20:22:16 +0800 From: Zhen Lei To: Jean-Philippe Brucker , John Garry , Robin Murphy , Will Deacon , Joerg Roedel , linux-arm-kernel , iommu , linux-kernel CC: Zhen Lei Subject: [PATCH 1/2] iommu/iova: introduce iova_magazine_compact_pfns() Date: Thu, 1 Aug 2019 20:21:53 +0800 Message-ID: <20190801122154.18820-1-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.21.0.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.133.215.186] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org iova_magazine_free_pfns() can only free the whole magazine buffer, add iova_magazine_compact_pfns() to support free part of it. Signed-off-by: Zhen Lei --- drivers/iommu/iova.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) -- 1.8.3 diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index 3e1a8a6755723a9..4b7a9efa0ef40af 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -795,18 +795,19 @@ static void iova_magazine_free(struct iova_magazine *mag) kfree(mag); } -static void -iova_magazine_free_pfns(struct iova_magazine *mag, struct iova_domain *iovad) +static void iova_magazine_compact_pfns(struct iova_magazine *mag, + struct iova_domain *iovad, + unsigned long newsize) { unsigned long flags; int i; - if (!mag) + if (!mag || mag->size <= newsize) return; spin_lock_irqsave(&iovad->iova_rbtree_lock, flags); - for (i = 0 ; i < mag->size; ++i) { + for (i = newsize; i < mag->size; ++i) { struct iova *iova = private_find_iova(iovad, mag->pfns[i]); BUG_ON(!iova); @@ -815,7 +816,13 @@ static void iova_magazine_free(struct iova_magazine *mag) spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); - mag->size = 0; + mag->size = newsize; +} + +static void +iova_magazine_free_pfns(struct iova_magazine *mag, struct iova_domain *iovad) +{ + iova_magazine_compact_pfns(mag, iovad, 0); } static bool iova_magazine_full(struct iova_magazine *mag)