Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH] RDMA/siw: Trim size of page array to max size needed
@ 2024-01-19 13:05 Bernard Metzler
  2024-01-23  2:43 ` Guoqing Jiang
  0 siblings, 1 reply; 9+ messages in thread
From: Bernard Metzler @ 2024-01-19 13:05 UTC (permalink / raw)
  To: linux-rdma; +Cc: jgg, leon, Bernard Metzler, ionut_n2001

siw tries sending all parts of an iWarp wire frame in one socket
send operation. If user data can be send without copy, user data
pages for one wire frame are referenced in an fixed size page array.
The size of this array can be made 2 elements smaller, since it
does not reference iWarp header and trailer crc. Trimming
the page array reduces the affected siw_tx_hdt() functions frame
size, staying below 1024 bytes. This avoids the following
compile-time warning:

 drivers/infiniband/sw/siw/siw_qp_tx.c: In function 'siw_tx_hdt':
 drivers/infiniband/sw/siw/siw_qp_tx.c:677:1: warning: the frame
 size of 1040 bytes is larger than 1024 bytes [-Wframe-larger-than=]

Fixes: b9be6f18cf9e ("rdma/siw: transmit path")
Reported-by: ionut_n2001@yahoo.com
Link: https://bugzilla.kernel.org/show_bug.cgi?id=218375
Signed-off-by: Bernard Metzler <bmt@zurich.ibm.com>
---
 drivers/infiniband/sw/siw/siw_qp_tx.c | 29 +++++++++++++++------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/infiniband/sw/siw/siw_qp_tx.c b/drivers/infiniband/sw/siw/siw_qp_tx.c
index 64ad9e0895bd..7ffc91bac606 100644
--- a/drivers/infiniband/sw/siw/siw_qp_tx.c
+++ b/drivers/infiniband/sw/siw/siw_qp_tx.c
@@ -432,7 +432,7 @@ static int siw_tx_hdt(struct siw_iwarp_tx *c_tx, struct socket *s)
 	struct siw_wqe *wqe = &c_tx->wqe_active;
 	struct siw_sge *sge = &wqe->sqe.sge[c_tx->sge_idx];
 	struct kvec iov[MAX_ARRAY];
-	struct page *page_array[MAX_ARRAY];
+	struct page *page_array[MAX_ARRAY-2];
 	struct msghdr msg = { .msg_flags = MSG_DONTWAIT | MSG_EOR };
 
 	int seg = 0, do_crc = c_tx->do_crc, is_kva = 0, rv;
@@ -491,7 +491,6 @@ static int siw_tx_hdt(struct siw_iwarp_tx *c_tx, struct socket *s)
 
 		while (sge_len) {
 			size_t plen = min((int)PAGE_SIZE - fp_off, sge_len);
-			void *kaddr;
 
 			if (!is_kva) {
 				struct page *p;
@@ -503,14 +502,12 @@ static int siw_tx_hdt(struct siw_iwarp_tx *c_tx, struct socket *s)
 					rv = -EFAULT;
 					goto done_crc;
 				}
-				page_array[seg] = p;
-
 				if (!c_tx->use_sendpage) {
-					void *kaddr = kmap_local_page(p);
+					void *pa = kmap_local_page(p);
 
 					/* Remember for later kunmap() */
 					kmap_mask |= BIT(seg);
-					iov[seg].iov_base = kaddr + fp_off;
+					iov[seg].iov_base = pa + fp_off;
 					iov[seg].iov_len = plen;
 
 					if (do_crc)
@@ -518,12 +515,17 @@ static int siw_tx_hdt(struct siw_iwarp_tx *c_tx, struct socket *s)
 							c_tx->mpa_crc_hd,
 							iov[seg].iov_base,
 							plen);
-				} else if (do_crc) {
-					kaddr = kmap_local_page(p);
-					crypto_shash_update(c_tx->mpa_crc_hd,
-							    kaddr + fp_off,
-							    plen);
-					kunmap_local(kaddr);
+				} else {
+					page_array[seg] = p;
+					if (do_crc) {
+						void *pa = kmap_local_page(p);
+
+						crypto_shash_update(
+							c_tx->mpa_crc_hd,
+							pa + fp_off,
+							plen);
+						kunmap_local(pa);
+					}
 				}
 			} else {
 				/*
@@ -545,7 +547,8 @@ static int siw_tx_hdt(struct siw_iwarp_tx *c_tx, struct socket *s)
 			data_len -= plen;
 			fp_off = 0;
 
-			if (++seg >= (int)MAX_ARRAY) {
+			if (++seg >= (int)MAX_ARRAY ||
+			    (c_tx->use_sendpage && seg >= (int)MAX_ARRAY-2)) {
 				siw_dbg_qp(tx_qp(c_tx), "to many fragments\n");
 				siw_unmap_pages(iov, kmap_mask, seg-1);
 				wqe->processed -= c_tx->bytes_unsent;
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-02-08 12:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-19 13:05 [PATCH] RDMA/siw: Trim size of page array to max size needed Bernard Metzler
2024-01-23  2:43 ` Guoqing Jiang
2024-01-24 19:59   ` Bernard Metzler
2024-01-25  9:15     ` Guoqing Jiang
2024-01-25 17:27       ` Bernard Metzler
2024-01-26  1:51         ` Guoqing Jiang
2024-01-26 11:05         ` Leon Romanovsky
2024-02-08 11:32           ` Bernard Metzler
2024-02-08 12:03             ` Leon Romanovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox