Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1017558ybh; Thu, 16 Jul 2020 00:21:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8uK7FdQnaw2+7KE/R6IDOqXtQdpT+UX+n3OXRaUiseNCQOQrG6tmtMK7FUcQGulyxsmFt X-Received: by 2002:a17:906:6897:: with SMTP id n23mr2356424ejr.473.1594884076708; Thu, 16 Jul 2020 00:21:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594884076; cv=none; d=google.com; s=arc-20160816; b=ezdrLMZPqBVFFS4P7fyuZjZ2MdesvVnP7CPvhcHB7PNds4HE4gm5BQGlOldfL4L/9C IGdsJs210bQrnaYOyfx+SUa2zRGN1r2TxOxNwnrl94WrLOaeksWUGPeFAHUJbt4Utd9A L8bD7p5EHS0qbJI9yZwHTBFeVHm+EHKRIowbHu08iibkpAcIl2Ul3ScfbTRWw/HI/4qI R+6ZsDiUb79QgQ3TMtZ5DPG43x9lzz8SS7PumU8v8qafiRvXf3W6wCwuwRV52Tmin+xw 3bSQJwyouE4hpMNkymbT4rdaMPskxBN7/eOXnEeyaWzjEbtFCYcOBXyHiuB9SHsULZ7Y 5h8A== 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 :dkim-signature; bh=6kTol5GJuQxW55C0DALb7A0VHIIQ+s0sQAconNEeDfM=; b=s232LonXqrY+C8FMBAJgGbA8w6VawqqaVgaHWpX8YRg8iBrNjQ7WqX9qqhaepld0hO s76KkWXQugg8F+vRa4Agk9R4VUOsKjQSPY1ftSlj9eMospIersyutRa3DyuG7jKyZTOl h8lI9956RbVqIV1dBh9uayGygeDcqIiLHpJsQCBk9yW7QLlJv3FFG7Ik0+s9Lk5+c/zd LzkFcFK2YWJ/0CEMtfsHAXUYIQYC5PWj92baMcqRx1hdDN6CTbbxXlzvoe3TARZdcX/O dn7ccLEAQ27POMQsxcn6T4JfWbIrs3MsFxCsN+9pjyCqnz1/2HlS8sUz89bRYPzzNtaK UlWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lbrRNiW+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z27si2964803ejl.277.2020.07.16.00.20.54; Thu, 16 Jul 2020 00:21:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lbrRNiW+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728335AbgGPHRs (ORCPT + 99 others); Thu, 16 Jul 2020 03:17:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726547AbgGPHRs (ORCPT ); Thu, 16 Jul 2020 03:17:48 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C4CFC061755 for ; Thu, 16 Jul 2020 00:17:48 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id e13so4634767qkg.5 for ; Thu, 16 Jul 2020 00:17:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6kTol5GJuQxW55C0DALb7A0VHIIQ+s0sQAconNEeDfM=; b=lbrRNiW+DfxjpEXQTrZI6+0GTWdiR8d/1wJUN5MeczqIZPRM/Da3QIyy3INppiFCju 8xxfGA5AxN1hIH5+GYNE2uhLThWIOwMknucUIzOVtXFCymzzDPeTz8cv75eGo8rGwns2 J7FUISIqhjYs7PRTQUpsxZ07cklnEaUOgr0aIgweLAfB96kfw09noDCWjlzlu2UETWwO qlvJVgLclRGIKg4fL8viUE04DuCzN6rD3Fi3hVJR2ou0/ZfLEzdfOw9RlQdqzNCFozzm 3J1oPyyg97jyJdlE1kSVekQGzGSfyCmUDmmaf8Uyp78p/yU8QIl33kDeDbf2ADUl28/u CSkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6kTol5GJuQxW55C0DALb7A0VHIIQ+s0sQAconNEeDfM=; b=eh49VM0rbpKcxTYE4PTqanTYv4IvlPILJmFyw+h491De7Gyp089KC9dWG8q5uTBxjs GYm8m5wFqOWBYD9Mg4shJuIsaHMM/YYozoKvnwnxvuy0Tpdo1lnvyLyxFRJdWxMlIoof jiNloEeROnNQDtLJbWd5xuYSR98XdsecAGw6GyylzZLCsZ/HNsruSS97JCf2iknQ6esV 1V4EqP6CCcxZUVLEVBYcmvDvANT1v86LyQwITO9G+iWoonhFtx4nsGnBaNAFYJ3M6yzR pJVs1ugAqWX+OXHGTm4+hJoQcUepCPd+K8sxOmEvhTou928mmfDlEmsM3TE/g+PlH+zZ 4/dg== X-Gm-Message-State: AOAM530ucfHPDA0Gu/4SbWTZ4kT7sXXXXzvahVC2VP7PLdZLEOgnZ+8m S912mi/omplhkpKhRDzd/wk= X-Received: by 2002:a37:7682:: with SMTP id r124mr2501311qkc.43.1594883867335; Thu, 16 Jul 2020 00:17:47 -0700 (PDT) Received: from LeoBras.ibmuc.com (200-236-239-31.dynamic.desktop.com.br. [200.236.239.31]) by smtp.gmail.com with ESMTPSA id a5sm6637989qtd.84.2020.07.16.00.17.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jul 2020 00:17:46 -0700 (PDT) From: Leonardo Bras To: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alexey Kardashevskiy , Joel Stanley , Christophe Leroy , Leonardo Bras , Thiago Jung Bauermann , Ram Pai , Brian King Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 5/7] powerpc/iommu: Move iommu_table cleaning routine to iommu_table_clean Date: Thu, 16 Jul 2020 04:16:57 -0300 Message-Id: <20200716071658.467820-6-leobras.c@gmail.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200716071658.467820-1-leobras.c@gmail.com> References: <20200716071658.467820-1-leobras.c@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move the part of iommu_table_free() that does struct iommu_table cleaning into iommu_table_clean, so we can invoke it separately. This new function is useful for cleaning struct iommu_table before initializing it again with a new DMA window, without having it freed and allocated again. Signed-off-by: Leonardo Bras --- arch/powerpc/kernel/iommu.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c index 9704f3f76e63..c3242253a4e7 100644 --- a/arch/powerpc/kernel/iommu.c +++ b/arch/powerpc/kernel/iommu.c @@ -735,21 +735,10 @@ struct iommu_table *iommu_init_table(struct iommu_table *tbl, int nid, return tbl; } -static void iommu_table_free(struct kref *kref) +static void iommu_table_clean(struct iommu_table *tbl) { unsigned long bitmap_sz; unsigned int order; - struct iommu_table *tbl; - - tbl = container_of(kref, struct iommu_table, it_kref); - - if (tbl->it_ops->free) - tbl->it_ops->free(tbl); - - if (!tbl->it_map) { - kfree(tbl); - return; - } iommu_table_release_pages(tbl); @@ -763,6 +752,23 @@ static void iommu_table_free(struct kref *kref) /* free bitmap */ order = get_order(bitmap_sz); free_pages((unsigned long) tbl->it_map, order); +} + +static void iommu_table_free(struct kref *kref) +{ + struct iommu_table *tbl; + + tbl = container_of(kref, struct iommu_table, it_kref); + + if (tbl->it_ops->free) + tbl->it_ops->free(tbl); + + if (!tbl->it_map) { + kfree(tbl); + return; + } + + iommu_table_clean(tbl); /* free table */ kfree(tbl); -- 2.25.4