From patchwork Thu Aug 15 12:11:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 171431 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp2103371ily; Thu, 15 Aug 2019 05:11:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqqyaJHKuwNYnMzaMR/je6oKIctPK0pzT8ePo6K5UNcb0LS6lURniIeRO7SslFrns5V5g3 X-Received: by 2002:a17:902:1e6:: with SMTP id b93mr3948609plb.295.1565871113598; Thu, 15 Aug 2019 05:11:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565871113; cv=none; d=google.com; s=arc-20160816; b=HU3WJVV5pdYvLREnMY+uIg1fj8mTZ9DVzHv072fpwedC9NlgxHPo5Ffi2B7q6sKSQ/ j7aW5yF7Z2+28DG8o5NXk6/XzOG55jNTwP4JV9av8nF79/LA3e5fMyB71zbD3LjhYPlQ LJuBAyjQWmF9OwE4wQ6sTr6+1JlzSD+VrdnKd2PHnCNQrUREL1i+UCBjSQq5wnPo8YCJ Klm2aoy1atzTkXMChq8vuQoL8YOKq7QjVxV8vmnQQHc7dJQjLbCseLMELusEVjX3guzT 2YUuolaKdZKfDwVvKU62emL4n1mJwOA0qQj95BKKjz6EPLznf5A8VOMrJE4pLkTUe1Ch zdQg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=2RR27ccmOXJMfdagP4Tod2X5aHvvEUUykC8v55+NLXA=; b=FQTBh4IUB2VvezwEAv9lSOFLhuj2bHCVeiIQJWtpRT/woFBAPir+6vrDVHY8pVl3SP vPue0C8UDB9ioqHk/+6cDy4hDVv2lVCsjAKeLV5CvQ4AOgx1KTdnSVwxmjskERB60bRx 3/yWLL6R6BDbwvL+4ExWbDZnALm0LmzbvpyA3OtehEkrOB4X7tPhkHHrd+1KzbADRkL3 LP2mYeO/ovgj+c+AvbLSm5h8XVN9XKtXrY9ITYtxoNbJ4HBG+5npQbiYClkEd8koGvpe q/500idEYWDkXRaeYU+pIqYTLE5TwlO3Gv+4QDEMb0ZM8+X40MGzk/WHcaAXtyAaxAdN VfnQ== 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 131si1737811pgf.597.2019.08.15.05.11.53; Thu, 15 Aug 2019 05:11:53 -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 S1731444AbfHOMLw (ORCPT + 28 others); Thu, 15 Aug 2019 08:11:52 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:50936 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730032AbfHOMLv (ORCPT ); Thu, 15 Aug 2019 08:11:51 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 71EE8288D19D6B69B9DB; Thu, 15 Aug 2019 20:11:40 +0800 (CST) Received: from HGHY4L002753561.china.huawei.com (10.133.215.186) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Thu, 15 Aug 2019 20:11:33 +0800 From: Zhen Lei To: Jean-Philippe Brucker , "Jean-Philippe Brucker" , John Garry , "Robin Murphy" , Will Deacon , Joerg Roedel , iommu , Omer Peleg , Adam Morrison , Shaohua Li , Ben Serebrin , David Woodhouse , linux-arm-kernel , linux-kernel CC: Zhen Lei Subject: [PATCH v2 1/2] iommu/iova: introduce iova_magazine_compact_pfns() Date: Thu, 15 Aug 2019 20:11:03 +0800 Message-ID: <20190815121104.29140-2-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190815121104.29140-1-thunder.leizhen@huawei.com> References: <20190815121104.29140-1-thunder.leizhen@huawei.com> 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)