Skip to content

Commit 6f1848e

Browse files
bergwolfgregkh
authored andcommitted
vsock: track pkt owner vsock
[ Upstream commit 36d277b ] So that we can cancel a queued pkt later if necessary. Signed-off-by: Peng Tao <bergwolf@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7ff28d3 commit 6f1848e

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

include/linux/virtio_vsock.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ struct virtio_vsock_pkt {
4848
struct virtio_vsock_hdr hdr;
4949
struct work_struct work;
5050
struct list_head list;
51+
/* socket refcnt not held, only use for cancellation */
52+
struct vsock_sock *vsk;
5153
void *buf;
5254
u32 len;
5355
u32 off;
@@ -56,6 +58,7 @@ struct virtio_vsock_pkt {
5658

5759
struct virtio_vsock_pkt_info {
5860
u32 remote_cid, remote_port;
61+
struct vsock_sock *vsk;
5962
struct msghdr *msg;
6063
u32 pkt_len;
6164
u16 type;

net/vmw_vsock/virtio_transport_common.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ virtio_transport_alloc_pkt(struct virtio_vsock_pkt_info *info,
5757
pkt->len = len;
5858
pkt->hdr.len = cpu_to_le32(len);
5959
pkt->reply = info->reply;
60+
pkt->vsk = info->vsk;
6061

6162
if (info->msg && len > 0) {
6263
pkt->buf = kmalloc(len, GFP_KERNEL);
@@ -180,6 +181,7 @@ static int virtio_transport_send_credit_update(struct vsock_sock *vsk,
180181
struct virtio_vsock_pkt_info info = {
181182
.op = VIRTIO_VSOCK_OP_CREDIT_UPDATE,
182183
.type = type,
184+
.vsk = vsk,
183185
};
184186

185187
return virtio_transport_send_pkt_info(vsk, &info);
@@ -519,6 +521,7 @@ int virtio_transport_connect(struct vsock_sock *vsk)
519521
struct virtio_vsock_pkt_info info = {
520522
.op = VIRTIO_VSOCK_OP_REQUEST,
521523
.type = VIRTIO_VSOCK_TYPE_STREAM,
524+
.vsk = vsk,
522525
};
523526

524527
return virtio_transport_send_pkt_info(vsk, &info);
@@ -534,6 +537,7 @@ int virtio_transport_shutdown(struct vsock_sock *vsk, int mode)
534537
VIRTIO_VSOCK_SHUTDOWN_RCV : 0) |
535538
(mode & SEND_SHUTDOWN ?
536539
VIRTIO_VSOCK_SHUTDOWN_SEND : 0),
540+
.vsk = vsk,
537541
};
538542

539543
return virtio_transport_send_pkt_info(vsk, &info);
@@ -560,6 +564,7 @@ virtio_transport_stream_enqueue(struct vsock_sock *vsk,
560564
.type = VIRTIO_VSOCK_TYPE_STREAM,
561565
.msg = msg,
562566
.pkt_len = len,
567+
.vsk = vsk,
563568
};
564569

565570
return virtio_transport_send_pkt_info(vsk, &info);
@@ -581,6 +586,7 @@ static int virtio_transport_reset(struct vsock_sock *vsk,
581586
.op = VIRTIO_VSOCK_OP_RST,
582587
.type = VIRTIO_VSOCK_TYPE_STREAM,
583588
.reply = !!pkt,
589+
.vsk = vsk,
584590
};
585591

586592
/* Send RST only if the original pkt is not a RST pkt */
@@ -826,6 +832,7 @@ virtio_transport_send_response(struct vsock_sock *vsk,
826832
.remote_cid = le64_to_cpu(pkt->hdr.src_cid),
827833
.remote_port = le32_to_cpu(pkt->hdr.src_port),
828834
.reply = true,
835+
.vsk = vsk,
829836
};
830837

831838
return virtio_transport_send_pkt_info(vsk, &info);

0 commit comments

Comments
 (0)