From patchwork Tue Jan 5 07:36:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Isaac J. Manjarres" X-Patchwork-Id: 11998345 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51881C433E9 for ; Tue, 5 Jan 2021 08:22:08 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F2A5722257 for ; Tue, 5 Jan 2021 08:22:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F2A5722257 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AC2956E093; Tue, 5 Jan 2021 08:21:24 +0000 (UTC) Received: from so254-31.mailgun.net (so254-31.mailgun.net [198.61.254.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id EFB036E041 for ; Tue, 5 Jan 2021 07:37:05 +0000 (UTC) DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1609832228; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=0K5VBSFi9Zn+RM5dSDQee5wwyKqTX6V1so6lTB/p7kQ=; b=ZOkhe9D0lfht00IN8Kvr6LVtwvYDBXHojb89Ik7/vinkLl1HBsu4P0kZ9YwGq6KAC+1TGcDY HjaJTBg+6i3OogVmN3s8myDAQnrL/N9mv1TvXQiniboVuwIoY8I+C9YWIRdp/9UWPVgEisXZ suT0KXhcepZ17aUSx+ZSaxx/QCU= X-Mailgun-Sending-Ip: 198.61.254.31 X-Mailgun-Sid: WyJkOTU5ZSIsICJkcmktZGV2ZWxAbGlzdHMuZnJlZWRlc2t0b3Aub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n09.prod.us-east-1.postgun.com with SMTP id 5ff4171c584481b01b7b8364 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Tue, 05 Jan 2021 07:37:00 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id A3906C433ED; Tue, 5 Jan 2021 07:36:59 +0000 (UTC) Received: from isaacm-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: isaacm) by smtp.codeaurora.org (Postfix) with ESMTPSA id 5E9A2C433ED; Tue, 5 Jan 2021 07:36:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 5E9A2C433ED Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=isaacm@codeaurora.org From: "Isaac J. Manjarres" To: will@kernel.org, robin.murphy@arm.com, joro@8bytes.org, robdclark@gmail.com, sean@poorly.run, airlied@linux.ie, daniel@ffwll.ch, steven.price@arm.com, alyssa.rosenzweig@collabora.com, robh@kernel.org, tomeu.vizoso@collabora.com Subject: [PATCH RESEND 2/7] iommu/io-pgtable: Add refcounting for io-pgtable format modules Date: Mon, 4 Jan 2021 23:36:40 -0800 Message-Id: <1609832205-10055-3-git-send-email-isaacm@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1609832205-10055-1-git-send-email-isaacm@codeaurora.org> References: <1609832205-10055-1-git-send-email-isaacm@codeaurora.org> X-Mailman-Approved-At: Tue, 05 Jan 2021 08:21:09 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Isaac J. Manjarres" , freedreno@lists.freedesktop.org, pdaly@codeaurora.org, pratikp@codeaurora.org, dri-devel@lists.freedesktop.org, iommu@lists.linux-foundation.org, kernel-team@android.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In preparation for modularizing io-pgtable formats, add support for reference counting the io-pgtable format modules to ensure that the modules are not unloaded while they are in use. Signed-off-by: Isaac J. Manjarres --- drivers/iommu/io-pgtable-arm-v7s.c | 1 + drivers/iommu/io-pgtable-arm.c | 5 +++++ drivers/iommu/io-pgtable.c | 12 ++++++++++-- include/linux/io-pgtable.h | 2 ++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c index 080881b..7e81135 100644 --- a/drivers/iommu/io-pgtable-arm-v7s.c +++ b/drivers/iommu/io-pgtable-arm-v7s.c @@ -839,6 +839,7 @@ static struct io_pgtable *arm_v7s_alloc_pgtable(struct io_pgtable_cfg *cfg, static struct io_pgtable_init_fns io_pgtable_arm_v7s_init_fns = { .alloc = arm_v7s_alloc_pgtable, .free = arm_v7s_free_pgtable, + .owner = THIS_MODULE, }; #ifdef CONFIG_IOMMU_IO_PGTABLE_ARMV7S_SELFTEST diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index e1f8d54..8ed52a0 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -1054,26 +1054,31 @@ static struct arm_lpae_io_pgtable_init_fns arm_lpae_init_fns_table[] = { .fmt = ARM_32_LPAE_S1, .init_fns.alloc = arm_32_lpae_alloc_pgtable_s1, .init_fns.free = arm_lpae_free_pgtable, + .init_fns.owner = THIS_MODULE, }, { .fmt = ARM_32_LPAE_S2, .init_fns.alloc = arm_32_lpae_alloc_pgtable_s2, .init_fns.free = arm_lpae_free_pgtable, + .init_fns.owner = THIS_MODULE, }, { .fmt = ARM_64_LPAE_S1, .init_fns.alloc = arm_64_lpae_alloc_pgtable_s1, .init_fns.free = arm_lpae_free_pgtable, + .init_fns.owner = THIS_MODULE, }, { .fmt = ARM_64_LPAE_S2, .init_fns.alloc = arm_64_lpae_alloc_pgtable_s2, .init_fns.free = arm_lpae_free_pgtable, + .init_fns.owner = THIS_MODULE, }, { .fmt = ARM_MALI_LPAE, .init_fns.alloc = arm_mali_lpae_alloc_pgtable, .init_fns.free = arm_lpae_free_pgtable, + .init_fns.owner = THIS_MODULE, }, }; diff --git a/drivers/iommu/io-pgtable.c b/drivers/iommu/io-pgtable.c index 95e872d..9792e25 100644 --- a/drivers/iommu/io-pgtable.c +++ b/drivers/iommu/io-pgtable.c @@ -10,6 +10,7 @@ #include #include #include +#include #include static struct io_pgtable_init_fns *io_pgtable_init_table[IO_PGTABLE_NUM_FMTS]; @@ -28,9 +29,14 @@ struct io_pgtable_ops *alloc_io_pgtable_ops(enum io_pgtable_fmt fmt, if (!fns) return NULL; + if (!try_module_get(fns->owner)) + return NULL; + iop = fns->alloc(cfg, cookie); - if (!iop) + if (!iop) { + module_put(fns->owner); return NULL; + } iop->fmt = fmt; iop->cookie = cookie; @@ -55,8 +61,10 @@ void free_io_pgtable_ops(struct io_pgtable_ops *ops) iop = io_pgtable_ops_to_pgtable(ops); io_pgtable_tlb_flush_all(iop); fns = io_pgtable_init_table[iop->fmt]; - if (fns) + if (fns) { fns->free(iop); + module_put(fns->owner); + } } EXPORT_SYMBOL_GPL(free_io_pgtable_ops); diff --git a/include/linux/io-pgtable.h b/include/linux/io-pgtable.h index a460ae1..bdf0a01 100644 --- a/include/linux/io-pgtable.h +++ b/include/linux/io-pgtable.h @@ -168,10 +168,12 @@ struct io_pgtable_ops { * * @alloc: Allocate a set of page tables described by cfg. * @free: Free the page tables associated with iop. + * @owner: Driver module providing these ops. */ struct io_pgtable_init_fns { struct io_pgtable *(*alloc)(struct io_pgtable_cfg *cfg, void *cookie); void (*free)(struct io_pgtable *iop); + struct module *owner; }; /**