From: "D. Wythe" <alibuda@linux.alibaba.com>
To: kgraul@linux.ibm.com, wenjia@linux.ibm.com, jaka@linux.ibm.com,
wintera@linux.ibm.com
Cc: kuba@kernel.org, davem@davemloft.net, netdev@vger.kernel.org,
linux-s390@vger.kernel.org, linux-rdma@vger.kernel.org,
"D. Wythe" <alibuda@linux.alibaba.com>,
Heiko Carstens <hca@linux.ibm.com>
Subject: [PATCH net 2/5] net/smc: fix incorrect barrier usage
Date: Wed, 11 Oct 2023 15:33:17 +0800 [thread overview]
Message-ID: <1697009600-22367-3-git-send-email-alibuda@linux.alibaba.com> (raw)
In-Reply-To: <1697009600-22367-1-git-send-email-alibuda@linux.alibaba.com>
From: "D. Wythe" <alibuda@linux.alibaba.com>
This patch add explicit CPU barrier to ensure memory
consistency rather than compiler barrier.
Besides, the atomicity between READ_ONCE and cmpxhcg cannot
be guaranteed, so we need to use atomic ops. The simple way
is to replace READ_ONCE with xchg.
Fixes: 475f9ff63ee8 ("net/smc: fix application data exception")
Co-developed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
Links: https://lore.kernel.org/netdev/1b7c95be-d3d9-53c3-3152-cd835314d37c@linux.ibm.com/T/
---
net/smc/smc_core.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index d520ee6..cc7d72e 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -1133,9 +1133,10 @@ static void smcr_buf_unuse(struct smc_buf_desc *buf_desc, bool is_rmb,
smc_buf_free(lgr, is_rmb, buf_desc);
} else {
- /* memzero_explicit provides potential memory barrier semantics */
- memzero_explicit(buf_desc->cpu_addr, buf_desc->len);
- WRITE_ONCE(buf_desc->used, 0);
+ memset(buf_desc->cpu_addr, 0, buf_desc->len);
+ /* make sure buf_desc->used not be reordered ahead */
+ smp_mb__before_atomic();
+ xchg(&buf_desc->used, 0);
}
}
@@ -1146,17 +1147,21 @@ static void smc_buf_unuse(struct smc_connection *conn,
if (!lgr->is_smcd && conn->sndbuf_desc->is_vm) {
smcr_buf_unuse(conn->sndbuf_desc, false, lgr);
} else {
- memzero_explicit(conn->sndbuf_desc->cpu_addr, conn->sndbuf_desc->len);
- WRITE_ONCE(conn->sndbuf_desc->used, 0);
+ memset(conn->sndbuf_desc->cpu_addr, 0, conn->sndbuf_desc->len);
+ /* make sure buf_desc->used not be reordered ahead */
+ smp_mb__before_atomic();
+ xchg(&conn->sndbuf_desc->used, 0);
}
}
if (conn->rmb_desc) {
if (!lgr->is_smcd) {
smcr_buf_unuse(conn->rmb_desc, true, lgr);
} else {
- memzero_explicit(conn->rmb_desc->cpu_addr,
- conn->rmb_desc->len + sizeof(struct smcd_cdc_msg));
- WRITE_ONCE(conn->rmb_desc->used, 0);
+ memset(conn->rmb_desc->cpu_addr, 0,
+ conn->rmb_desc->len + sizeof(struct smcd_cdc_msg));
+ /* make sure buf_desc->used not be reordered ahead */
+ smp_mb__before_atomic();
+ xchg(&conn->rmb_desc->used, 0);
}
}
}
--
1.8.3.1
next prev parent reply other threads:[~2023-10-11 7:33 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-11 7:33 [PATCH net 0/5] net/smc: bugfixs for smc-r D. Wythe
2023-10-11 7:33 ` [PATCH net 1/5] net/smc: fix dangling sock under state SMC_APPFINCLOSEWAIT D. Wythe
2023-10-11 14:00 ` Dust Li
2023-10-11 20:31 ` Wenjia Zhang
2023-10-12 2:47 ` D. Wythe
[not found] ` <f8089b26-bb11-f82d-8070-222b1f8c1db1@linux.alibaba.com>
2023-10-12 11:51 ` Wenjia Zhang
2023-10-13 5:32 ` Dust Li
2023-10-13 11:52 ` Wenjia Zhang
2023-10-13 12:27 ` Dust Li
2023-10-17 2:00 ` D. Wythe
2023-10-17 8:39 ` Dust Li
2023-10-17 17:03 ` Wenjia Zhang
[not found] ` <4065e94f-f7ea-7943-e2cc-0c7d3f9c788b@linux.alibaba.com>
2023-10-19 11:54 ` Wenjia Zhang
2023-10-23 20:53 ` Wenjia Zhang
2023-10-11 7:33 ` D. Wythe [this message]
2023-10-11 8:44 ` [PATCH net 2/5] net/smc: fix incorrect barrier usage Heiko Carstens
2023-10-11 8:57 ` D. Wythe
2023-10-11 7:33 ` [PATCH net 3/5] net/smc: allow cdc msg send rather than drop it with NULL sndbuf_desc D. Wythe
2023-10-11 20:37 ` Wenjia Zhang
2023-10-12 2:49 ` D. Wythe
2023-10-12 15:15 ` Wenjia Zhang
2023-10-11 7:33 ` [PATCH net 4/5] net/smc: protect connection state transitions in listen work D. Wythe
2023-10-12 17:14 ` Wenjia Zhang
2023-10-31 3:04 ` D. Wythe
2023-10-11 7:33 ` [PATCH net 5/5] net/smc: put sk reference if close work was canceled D. Wythe
2023-10-11 14:54 ` Dust Li
2023-10-12 19:04 ` Wenjia Zhang
[not found] ` <ee641ca5-104b-d1ec-5b2a-e20237c5378a@linux.alibaba.com>
2023-10-18 20:26 ` Wenjia Zhang
2023-10-19 7:33 ` D. Wythe
2023-10-19 17:40 ` Wenjia Zhang
2023-10-20 2:41 ` D. Wythe
2023-10-23 8:19 ` Wenjia Zhang
2023-10-23 8:52 ` D. Wythe
2023-10-23 10:28 ` Wenjia Zhang
2023-10-23 11:56 ` Dust Li
[not found] ` <59c0c75f-e9df-2ef1-ead2-7c5c97f3e750@linux.alibaba.com>
2023-10-23 20:52 ` Wenjia Zhang
2023-10-12 13:43 ` [PATCH net 0/5] net/smc: bugfixs for smc-r Alexandra Winter
2023-10-17 1:56 ` D. Wythe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1697009600-22367-3-git-send-email-alibuda@linux.alibaba.com \
--to=alibuda@linux.alibaba.com \
--cc=davem@davemloft.net \
--cc=hca@linux.ibm.com \
--cc=jaka@linux.ibm.com \
--cc=kgraul@linux.ibm.com \
--cc=kuba@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=wenjia@linux.ibm.com \
--cc=wintera@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).