From patchwork Tue Aug 1 10:35:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 9874105 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 B641B603B4 for ; Tue, 1 Aug 2017 10:38:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B73B328173 for ; Tue, 1 Aug 2017 10:38:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC320285DE; Tue, 1 Aug 2017 10:38:37 +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 9B44F28689 for ; Tue, 1 Aug 2017 10:38:34 +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=uM3ofnrVTNcpK1Z0unptIMleRU JHYMtuzSH0Rt+5Fd9l2+SuP5CLuko9t3gO1ze2TWjRNFygJn1tggdTFFp2KI81qIdUHZxPRVmPR6q pTTad6e+CtBixVJ3p1ar7nOsQ/0gbiTUQerPiKTPyMuiIWxgKUhM2nkmazeu+0hGiNbIMwe6c8AH2 893vr04aFNYdI8xCEOeHZ90vNXb+rnb6kkuXlRsYG9zCvMXaabXxDMMAi9Dg4+ZSf7M9UoXL+JEyn PSA8573BZUxhGVA1H4E3kTECqVgCkZLOCONS44jerPP9z36iF9RH4mC9oQ2Q4gmxCLtlsOzibbtYY PEAP8Biw==; 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 1dcUYp-0002s6-1e; Tue, 01 Aug 2017 10:37:59 +0000 Received: from mail-qk0-x229.google.com ([2607:f8b0:400d:c09::229]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dcUXy-0001tF-8q for linux-arm-kernel@lists.infradead.org; Tue, 01 Aug 2017 10:37:13 +0000 Received: by mail-qk0-x229.google.com with SMTP id u139so6455604qka.1 for ; Tue, 01 Aug 2017 03:36:50 -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=Brvpk2Fhvri2aklUzPQ6h+eUHo2G/0tK8kmaKNaDW09eRjtE/C6lGNYvmts2HbJ6Uz PPrAC/rr4aR7B3sKNe0XFwimrV0S71Ya96TqEATgYMIMRw06DH/DE3klQvWvFy9Ek1fK 43khFiTponC8cT8BD/aDRQefVCrTk6VPx0gS4= 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=Q9futanonjkYFY4BlWfySqpeuJHHCLlfK5CZXgZTWzG5bWI8OUqFXlhG8ZiOsY/PFZ yUjRwMqrZtI4UcvS0Qq77G/5971Rl7tJptK6jOsQKYubkWLf0fg4+Zx2hAAToidmBT9O oc+LCD4egXmJTQj82uNirrB5lwCW+Yr6PI+xFe3mXDZm9Vi3V9uWQ58J6ygWUznthept U1iOMG2papwadAFugp4PwsAHUV3WbRdGK9qjaDbAj21ivgM/XC+IX/CWuqOO1tBN781y RA/7TFF9mLEYDAiRmu19XhXZHKqexPz/sqlyVYR6kEtfbtiXr+g7I7Nekd73lTuNbElj S8fQ== X-Gm-Message-State: AIVw111UglYmwVexksubr5wK3Euq8zwtf1P3uND1cnRb9kRkHvpKWCaT YzZbLOknGSoUt4iv X-Received: by 10.55.203.17 with SMTP id d17mr26278877qkj.147.1501583809649; Tue, 01 Aug 2017 03:36:49 -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 d14sm23961629qtd.21.2017.08.01.03.36.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 01 Aug 2017 03:36:49 -0700 (PDT) From: Anup Patel To: Rob Herring , Mark Rutland , Catalin Marinas , Will Deacon , Jassi Brar Subject: [PATCH v3 4/5] mailbox: bcm-flexrm-mailbox: Use bitmap instead of IDA Date: Tue, 1 Aug 2017 16:05:53 +0530 Message-Id: <1501583754-31969-5-git-send-email-anup.patel@broadcom.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1501583754-31969-1-git-send-email-anup.patel@broadcom.com> References: <1501583754-31969-1-git-send-email-anup.patel@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170801_033706_720240_A6725F9F X-CRM114-Status: GOOD ( 17.71 ) 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; }