lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240620175703.605111-40-yury.norov@gmail.com>
Date: Thu, 20 Jun 2024 10:57:02 -0700
From: Yury Norov <yury.norov@...il.com>
To: linux-kernel@...r.kernel.org,
	Jassi Brar <jassisinghbrar@...il.com>
Cc: Yury Norov <yury.norov@...il.com>,
	Alexey Klimov <alexey.klimov@...aro.org>,
	Bart Van Assche <bvanassche@....org>,
	Jan Kara <jack@...e.cz>,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Matthew Wilcox <willy@...radead.org>,
	Mirsad Todorovac <mirsad.todorovac@....unizg.hr>,
	Rasmus Villemoes <linux@...musvillemoes.dk>,
	Sergey Shtylyov <s.shtylyov@....ru>
Subject: [PATCH v4 39/40] mailbox: bcm-flexrm: simplify locking scheme

Use atomic find_and_set_bit() and drop locking around
ring->requests_bmap.

Signed-off-by: Yury Norov <yury.norov@...il.com>
---
 drivers/mailbox/bcm-flexrm-mailbox.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/drivers/mailbox/bcm-flexrm-mailbox.c b/drivers/mailbox/bcm-flexrm-mailbox.c
index b1abc2a0c971..7aca533a1068 100644
--- a/drivers/mailbox/bcm-flexrm-mailbox.c
+++ b/drivers/mailbox/bcm-flexrm-mailbox.c
@@ -23,6 +23,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/dmapool.h>
 #include <linux/err.h>
+#include <linux/find_atomic.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/mailbox_controller.h>
@@ -989,21 +990,17 @@ static int flexrm_new_request(struct flexrm_ring *ring,
 	msg->error = 0;
 
 	/* If no requests possible then save data pointer and goto done. */
-	spin_lock_irqsave(&ring->lock, flags);
-	reqid = bitmap_find_free_region(ring->requests_bmap,
-					RING_MAX_REQ_COUNT, 0);
-	spin_unlock_irqrestore(&ring->lock, flags);
-	if (reqid < 0)
+	reqid = find_and_set_bit(ring->requests_bmap, RING_MAX_REQ_COUNT);
+	if (reqid >= RING_MAX_REQ_COUNT)
 		return -ENOSPC;
+
 	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;
-		spin_lock_irqsave(&ring->lock, flags);
-		bitmap_release_region(ring->requests_bmap, reqid, 0);
-		spin_unlock_irqrestore(&ring->lock, flags);
+		clear_bit(reqid, ring->requests_bmap);
 		return ret;
 	}
 
@@ -1063,9 +1060,7 @@ static int flexrm_new_request(struct flexrm_ring *ring,
 	if (exit_cleanup) {
 		flexrm_dma_unmap(ring->mbox->dev, msg);
 		ring->requests[reqid] = NULL;
-		spin_lock_irqsave(&ring->lock, flags);
-		bitmap_release_region(ring->requests_bmap, reqid, 0);
-		spin_unlock_irqrestore(&ring->lock, flags);
+		clear_bit(reqid, ring->requests_bmap);
 	}
 
 	return ret;
@@ -1130,9 +1125,7 @@ static int flexrm_process_completions(struct flexrm_ring *ring)
 
 		/* Release reqid for recycling */
 		ring->requests[reqid] = NULL;
-		spin_lock_irqsave(&ring->lock, flags);
-		bitmap_release_region(ring->requests_bmap, reqid, 0);
-		spin_unlock_irqrestore(&ring->lock, flags);
+		clear_bit(reqid, ring->requests_bmap);
 
 		/* Unmap DMA mappings */
 		flexrm_dma_unmap(ring->mbox->dev, msg);
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ