Skip to content

Commit 3abc898

Browse files
tonanli66-codegregkh
authored andcommitted
net/rds: handle zerocopy send cleanup before the message is queued
commit 44b550d upstream. A zerocopy send can fail after user pages have been pinned but before the message is attached to the sending socket. The purge path currently infers zerocopy state from rm->m_rs, so an unqueued message can be cleaned up as if it owned normal payload pages. However, zerocopy ownership is really determined by the presence of op_mmp_znotifier, regardless of whether the message has reached the socket queue. Capture op_mmp_znotifier up front in rds_message_purge() and use it as the cleanup discriminator. If the message is already associated with a socket, keep the existing completion path. Otherwise, drop the pinned page accounting directly and release the notifier before putting the payload pages. This keeps early send failure cleanup consistent with the zerocopy lifetime rules without changing the normal queued completion path. Fixes: 0cebacc ("rds: zerocopy Tx support.") Cc: stable@kernel.org Reported-by: Yuan Tan <yuantan098@gmail.com> Reported-by: Yifan Wu <yifanwucs@gmail.com> Reported-by: Juefei Pu <tomapufckgml@gmail.com> Reported-by: Xin Liu <bird@lzu.edu.cn> Co-developed-by: Xiao Liu <lx24@stu.ynu.edu.cn> Signed-off-by: Xiao Liu <lx24@stu.ynu.edu.cn> Signed-off-by: Nan Li <tonanli66@gmail.com> Signed-off-by: Ren Wei <n05ec@lzu.edu.cn> Reviewed-by: Allison Henderson <achender@kernel.org> Link: https://patch.msgid.link/d2ea98a6313d5467bac00f7c9fef8c7acddb9258.1777550074.git.tonanli66@gmail.com Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 311fdd2 commit 3abc898

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

net/rds/message.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,24 +129,34 @@ static void rds_rm_zerocopy_callback(struct rds_sock *rs,
129129
*/
130130
static void rds_message_purge(struct rds_message *rm)
131131
{
132+
struct rds_znotifier *znotifier;
132133
unsigned long i, flags;
133-
bool zcopy = false;
134+
bool zcopy;
134135

135136
if (unlikely(test_bit(RDS_MSG_PAGEVEC, &rm->m_flags)))
136137
return;
137138

138139
spin_lock_irqsave(&rm->m_rs_lock, flags);
140+
znotifier = rm->data.op_mmp_znotifier;
141+
rm->data.op_mmp_znotifier = NULL;
142+
zcopy = !!znotifier;
143+
139144
if (rm->m_rs) {
140145
struct rds_sock *rs = rm->m_rs;
141146

142-
if (rm->data.op_mmp_znotifier) {
143-
zcopy = true;
144-
rds_rm_zerocopy_callback(rs, rm->data.op_mmp_znotifier);
147+
if (znotifier) {
148+
rds_rm_zerocopy_callback(rs, znotifier);
145149
rds_wake_sk_sleep(rs);
146-
rm->data.op_mmp_znotifier = NULL;
147150
}
148151
sock_put(rds_rs_to_sk(rs));
149152
rm->m_rs = NULL;
153+
} else if (znotifier) {
154+
/*
155+
* Zerocopy can fail before the message is queued on the
156+
* socket, so there is no rs to carry the notification.
157+
*/
158+
mm_unaccount_pinned_pages(&znotifier->z_mmp);
159+
kfree(rds_info_from_znotifier(znotifier));
150160
}
151161
spin_unlock_irqrestore(&rm->m_rs_lock, flags);
152162

0 commit comments

Comments
 (0)