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]
Date:   Wed, 31 Aug 2022 17:40:13 -0500
From:   Alex Elder <elder@...aro.org>
To:     davem@...emloft.net, edumazet@...gle.com, kuba@...nel.org,
        pabeni@...hat.com
Cc:     mka@...omium.org, evgreen@...omium.org, bjorn.andersson@...aro.org,
        quic_cpratapa@...cinc.com, quic_avuyyuru@...cinc.com,
        quic_jponduru@...cinc.com, quic_subashab@...cinc.com,
        elder@...nel.org, netdev@...r.kernel.org,
        linux-arm-msm@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH net-next 2/6] net: ipa: track allocated transactions with an ID

Transactions for a channel are now managed in an array, with a free
transaction ID indicating which is the next one free.

Add another transaction ID field to track the first element in the
array that has been allocated.  Advance it when a transaction is
committed (because that is when that transaction leaves allocated
state).

Temporarily add warnings that verify that the first allocated
transaction tracked by the ID matches the first element on the
allocated list, both when allocating and committing a transaction.

Signed-off-by: Alex Elder <elder@...aro.org>
---

NOTE: I find these temporary WARN_ON() calls helpful in proving
      the new index refers to the same transaction as the first
      element of an "old" list.  I'll gladly remove these if
      requested.  (This comment applies throughout this series.)

 drivers/net/ipa/gsi.h       |  1 +
 drivers/net/ipa/gsi_trans.c | 28 ++++++++++++++++++++++++++--
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ipa/gsi.h b/drivers/net/ipa/gsi.h
index 4a88aec7e7d92..6bbbda6f27eae 100644
--- a/drivers/net/ipa/gsi.h
+++ b/drivers/net/ipa/gsi.h
@@ -84,6 +84,7 @@ struct gsi_trans_info {
 	atomic_t tre_avail;		/* TREs available for allocation */
 
 	u16 free_id;			/* first free trans in array */
+	u16 allocated_id;		/* first allocated transaction */
 	struct gsi_trans *trans;	/* transaction array */
 	struct gsi_trans **map;		/* TRE -> transaction map */
 
diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c
index 9775e50d0423f..d84400e13487f 100644
--- a/drivers/net/ipa/gsi_trans.c
+++ b/drivers/net/ipa/gsi_trans.c
@@ -246,12 +246,26 @@ static void gsi_trans_move_committed(struct gsi_trans *trans)
 {
 	struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id];
 	struct gsi_trans_info *trans_info = &channel->trans_info;
+	u16 trans_index;
 
 	spin_lock_bh(&trans_info->spinlock);
 
 	list_move_tail(&trans->links, &trans_info->committed);
 
+	trans = list_first_entry_or_null(&trans_info->alloc,
+					 struct gsi_trans, links);
+
 	spin_unlock_bh(&trans_info->spinlock);
+
+	/* This allocated transaction is now committed */
+	trans_info->allocated_id++;
+
+	if (trans) {
+		trans_index = trans_info->allocated_id % channel->tre_count;
+		WARN_ON(trans != &trans_info->trans[trans_index]);
+	} else {
+		WARN_ON(trans_info->allocated_id != trans_info->free_id);
+	}
 }
 
 /* Move transactions from the committed list to the pending list */
@@ -378,8 +392,14 @@ struct gsi_trans *gsi_channel_trans_alloc(struct gsi *gsi, u32 channel_id,
 
 	list_add_tail(&trans->links, &trans_info->alloc);
 
+	trans = list_first_entry(&trans_info->alloc, struct gsi_trans, links);
+
 	spin_unlock_bh(&trans_info->spinlock);
 
+	WARN_ON(trans_info->allocated_id == trans_info->free_id);
+	trans_index = trans_info->allocated_id % channel->tre_count;
+	WARN_ON(trans != &trans_info->trans[trans_index]);
+
 	return trans;
 }
 
@@ -408,7 +428,10 @@ void gsi_trans_free(struct gsi_trans *trans)
 	if (!last)
 		return;
 
-	if (trans->used_count)
+	/* Unused transactions are allocated but never committed */
+	if (!trans->used_count)
+		trans_info->allocated_id++;
+	else
 		ipa_gsi_trans_release(trans);
 
 	/* Releasing the reserved TREs implicitly frees the sgl[] and
@@ -744,7 +767,8 @@ int gsi_channel_trans_init(struct gsi *gsi, u32 channel_id)
 				    GFP_KERNEL);
 	if (!trans_info->trans)
 		return -ENOMEM;
-	trans_info->free_id = 0;	/* modulo channel->tre_count */
+	trans_info->free_id = 0;	/* all modulo channel->tre_count */
+	trans_info->allocated_id = 0;
 
 	/* A completion event contains a pointer to the TRE that caused
 	 * the event (which will be the last one used by the transaction).
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ