From patchwork Fri Jul 21 06:55:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 9856253 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A879260392 for ; Fri, 21 Jul 2017 06:57:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8579C2876B for ; Fri, 21 Jul 2017 06:57:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 786662877C; Fri, 21 Jul 2017 06:57:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0AB3E2876B for ; Fri, 21 Jul 2017 06:57:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=GOqqY86TIo2j7mi0g4NClZzax1APaQceJSC7eyyfgfk=; b=PPT2ZTK4AJV+oxcR4VPhRpjLH4 eW+nhmi33atsmbiylrAC45iOQDyDu9ZgazK4JgZSa6Ym3NYYAgn+b5d6btXgGQVW2OKQy1xpTxxjN eFGMcFSR/WK/lNyGwubokLE/apKVD1hzQAyva7MWiztq2SgwWdptfvTQZ+RID9kh8ssOrHVRd9GvS 1ZQYUl9gae2mvUA9ak6ksqvKI7uiZArjFfwcn9EhFV6RlswNgfQ1LskECY8tmFICbgdd67w4FTu48 C/6nNT2tC/IZTilC5j6DwMECjzyshR07BDbSnIFr4/SyhtCXs51MePkJiXsxzOpI6SOplOxeUj29Q G6AK0k5w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dYRsn-0006ts-E1; Fri, 21 Jul 2017 06:57:53 +0000 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dYRro-0005oL-8E for linux-arm-kernel@lists.infradead.org; Fri, 21 Jul 2017 06:56:58 +0000 Received: by mail-wm0-x22b.google.com with SMTP id e131so5796768wme.0 for ; Thu, 20 Jul 2017 23:56:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jj1BsLYiqDohoGJ7EOffoKYYjy1jRNZC3QnLd122Rgw=; b=akru4X6LmlaGGES8t3Ckl9wFZT3nBKY62kAEEOtUECwMKiSgCgDzw7IXO+BkZSEcXv 2YpjuwGlZBpNM4UN+hXDbqRJjV8LRM6DdKINCIIeof1BAR5+qqWv1fFbWLec+dKjmzom uSq2O70LRUyZCgfU5wCLxJ06T+19alY3bnLyE= 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; bh=jj1BsLYiqDohoGJ7EOffoKYYjy1jRNZC3QnLd122Rgw=; b=EVhe8qXrriaHTiYUu9vbgqNR+LEMUjIfE7bwBJY/FSItCIKcEYw86AA+wv2xGDKjub 3k1FvwVFw6v+nLN/gru2w2FYhhtjifpgtpcfqUXn0cm5AT1suV3o4llusOIfRPF2OCSl ie/54lrXyaLDzeTRb1RTnpLWXveF5OlSV47GAVRE68k2qx8Uuywbxojmulw9NGNIgyHf xOMF2C5fuO/Ds4ahrULgimwIVPhO+isqUdHv75mf2qQ5pC1RkrvCOEPeSSTxlGNwSSEs Za2LuaGzwj9xcudPZn43mR6tZ5gaDK1lpA9RAKunrhKuOOaiNMhYBK4NugQ4eAx+xhw6 Zsdw== X-Gm-Message-State: AIVw110si9NJ4Qdxnh8TlbD5dhcdMpTVQg3PVQViBlMCaCBhSudNyUCG LGWjayiaonqwAMub X-Received: by 10.28.236.8 with SMTP id k8mr4135966wmh.139.1500620189945; Thu, 20 Jul 2017 23:56:29 -0700 (PDT) Received: from anup-HP-Compaq-8100-Elite-CMT-PC.dhcp.avagotech.net ([192.19.237.250]) by smtp.gmail.com with ESMTPSA id 77sm751684wmk.8.2017.07.20.23.56.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Jul 2017 23:56:29 -0700 (PDT) From: Anup Patel To: Rob Herring , Mark Rutland , Catalin Marinas , Will Deacon , Jassi Brar Subject: [PATCH v2 4/7] mailbox: bcm-flexrm-mailbox: Use bitmap instead of IDA Date: Fri, 21 Jul 2017 12:25:39 +0530 Message-Id: <1500620142-910-5-git-send-email-anup.patel@broadcom.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500620142-910-1-git-send-email-anup.patel@broadcom.com> References: <1500620142-910-1-git-send-email-anup.patel@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170720_235653_113626_EF9132D1 X-CRM114-Status: GOOD ( 17.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Florian Fainelli , Anup Patel , Scott Branden , Ray Jui , linux-kernel@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, we are using IDA library for managing IDs on a FlexRM ring. The IDA library dynamically allocates memory for underlying data structures which can cause potential locking issue when allocating/free IDs from flexrm_new_request() and flexrm_process_completions(). To tackle this, we replace use of IDA with bitmap for each FlexRM ring and also protect the bitmap with FlexRM ring lock. Signed-off-by: Anup Patel --- drivers/mailbox/bcm-flexrm-mailbox.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/drivers/mailbox/bcm-flexrm-mailbox.c b/drivers/mailbox/bcm-flexrm-mailbox.c index 46ad305..9873818 100644 --- a/drivers/mailbox/bcm-flexrm-mailbox.c +++ b/drivers/mailbox/bcm-flexrm-mailbox.c @@ -18,13 +18,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include #include #include #include @@ -265,7 +265,6 @@ struct flexrm_ring { cpumask_t irq_aff_hint; unsigned int msi_timer_val; unsigned int msi_count_threshold; - struct ida requests_ida; struct brcm_message *requests[RING_MAX_REQ_COUNT]; void *bd_base; dma_addr_t bd_dma_base; @@ -277,6 +276,7 @@ struct flexrm_ring { atomic_t msg_cmpl_count; /* Protected members */ spinlock_t lock; + DECLARE_BITMAP(requests_bmap, RING_MAX_REQ_COUNT); struct brcm_message *last_pending_msg; u32 cmpl_read_offset; }; @@ -994,10 +994,10 @@ static int flexrm_new_request(struct flexrm_ring *ring, msg->error = 0; /* If no requests possible then save data pointer and goto done. */ - reqid = ida_simple_get(&ring->requests_ida, 0, - RING_MAX_REQ_COUNT, GFP_KERNEL); + spin_lock_irqsave(&ring->lock, flags); + reqid = bitmap_find_free_region(ring->requests_bmap, + RING_MAX_REQ_COUNT, 0); if (reqid < 0) { - spin_lock_irqsave(&ring->lock, flags); if (batch_msg) ring->last_pending_msg = batch_msg; else @@ -1005,13 +1005,16 @@ static int flexrm_new_request(struct flexrm_ring *ring, spin_unlock_irqrestore(&ring->lock, flags); return 0; } + spin_unlock_irqrestore(&ring->lock, flags); ring->requests[reqid] = msg; /* Do DMA mappings for the message */ ret = flexrm_dma_map(ring->mbox->dev, msg); if (ret < 0) { ring->requests[reqid] = NULL; - ida_simple_remove(&ring->requests_ida, reqid); + spin_lock_irqsave(&ring->lock, flags); + bitmap_release_region(ring->requests_bmap, reqid, 0); + spin_unlock_irqrestore(&ring->lock, flags); return ret; } @@ -1088,7 +1091,9 @@ static int flexrm_new_request(struct flexrm_ring *ring, if (exit_cleanup) { flexrm_dma_unmap(ring->mbox->dev, msg); ring->requests[reqid] = NULL; - ida_simple_remove(&ring->requests_ida, reqid); + spin_lock_irqsave(&ring->lock, flags); + bitmap_release_region(ring->requests_bmap, reqid, 0); + spin_unlock_irqrestore(&ring->lock, flags); } return ret; @@ -1163,7 +1168,9 @@ static int flexrm_process_completions(struct flexrm_ring *ring) /* Release reqid for recycling */ ring->requests[reqid] = NULL; - ida_simple_remove(&ring->requests_ida, reqid); + spin_lock_irqsave(&ring->lock, flags); + bitmap_release_region(ring->requests_bmap, reqid, 0); + spin_unlock_irqrestore(&ring->lock, flags); /* Unmap DMA mappings */ flexrm_dma_unmap(ring->mbox->dev, msg); @@ -1414,7 +1421,6 @@ static void flexrm_shutdown(struct mbox_chan *chan) /* Release reqid for recycling */ ring->requests[reqid] = NULL; - ida_simple_remove(&ring->requests_ida, reqid); /* Unmap DMA mappings */ flexrm_dma_unmap(ring->mbox->dev, msg); @@ -1424,6 +1430,9 @@ static void flexrm_shutdown(struct mbox_chan *chan) mbox_chan_received_data(chan, msg); } + /* Clear requests bitmap */ + bitmap_zero(ring->requests_bmap, RING_MAX_REQ_COUNT); + /* Release IRQ */ if (ring->irq_requested) { irq_set_affinity_hint(ring->irq, NULL); @@ -1581,7 +1590,6 @@ static int flexrm_mbox_probe(struct platform_device *pdev) ring->irq_requested = false; ring->msi_timer_val = MSI_TIMER_VAL_MASK; ring->msi_count_threshold = 0x1; - ida_init(&ring->requests_ida); memset(ring->requests, 0, sizeof(ring->requests)); ring->bd_base = NULL; ring->bd_dma_base = 0; @@ -1590,6 +1598,7 @@ static int flexrm_mbox_probe(struct platform_device *pdev) atomic_set(&ring->msg_send_count, 0); atomic_set(&ring->msg_cmpl_count, 0); spin_lock_init(&ring->lock); + bitmap_zero(ring->requests_bmap, RING_MAX_REQ_COUNT); ring->last_pending_msg = NULL; ring->cmpl_read_offset = 0; } @@ -1701,9 +1710,7 @@ static int flexrm_mbox_probe(struct platform_device *pdev) static int flexrm_mbox_remove(struct platform_device *pdev) { - int index; struct device *dev = &pdev->dev; - struct flexrm_ring *ring; struct flexrm_mbox *mbox = platform_get_drvdata(pdev); mbox_controller_unregister(&mbox->controller); @@ -1715,11 +1722,6 @@ static int flexrm_mbox_remove(struct platform_device *pdev) dma_pool_destroy(mbox->cmpl_pool); dma_pool_destroy(mbox->bd_pool); - for (index = 0; index < mbox->num_rings; index++) { - ring = &mbox->rings[index]; - ida_destroy(&ring->requests_ida); - } - return 0; }