vsock.c (16ba7e312045cd5d32fba0156312b4303f200787) vsock.c (01fcb1cbc88effb3493c6197efc96b69b9f4823a)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * vhost transport for vsock
4 *
5 * Copyright (C) 2013-2015 Red Hat, Inc.
6 * Author: Asias He <asias@redhat.com>
7 * Stefan Hajnoczi <stefanha@redhat.com>
8 */

--- 167 unchanged lines hidden (view full) ---

176 nbytes = copy_to_iter(pkt->buf + pkt->off, payload_len,
177 &iov_iter);
178 if (nbytes != payload_len) {
179 virtio_transport_free_pkt(pkt);
180 vq_err(vq, "Faulted on copying pkt buf\n");
181 break;
182 }
183
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * vhost transport for vsock
4 *
5 * Copyright (C) 2013-2015 Red Hat, Inc.
6 * Author: Asias He <asias@redhat.com>
7 * Stefan Hajnoczi <stefanha@redhat.com>
8 */

--- 167 unchanged lines hidden (view full) ---

176 nbytes = copy_to_iter(pkt->buf + pkt->off, payload_len,
177 &iov_iter);
178 if (nbytes != payload_len) {
179 virtio_transport_free_pkt(pkt);
180 vq_err(vq, "Faulted on copying pkt buf\n");
181 break;
182 }
183
184 vhost_add_used(vq, head, sizeof(pkt->hdr) + payload_len);
185 added = true;
186
187 /* Deliver to monitoring devices all correctly transmitted
188 * packets.
184 /* Deliver to monitoring devices all packets that we
185 * will transmit.
189 */
190 virtio_transport_deliver_tap_pkt(pkt);
191
186 */
187 virtio_transport_deliver_tap_pkt(pkt);
188
189 vhost_add_used(vq, head, sizeof(pkt->hdr) + payload_len);
190 added = true;
191
192 pkt->off += payload_len;
193 total_len += payload_len;
194
195 /* If we didn't send all the payload we can requeue the packet
196 * to send it with the next available buffer.
197 */
198 if (pkt->off < pkt->len) {
192 pkt->off += payload_len;
193 total_len += payload_len;
194
195 /* If we didn't send all the payload we can requeue the packet
196 * to send it with the next available buffer.
197 */
198 if (pkt->off < pkt->len) {
199 /* We are queueing the same virtio_vsock_pkt to handle
200 * the remaining bytes, and we want to deliver it
201 * to monitoring devices in the next iteration.
202 */
203 pkt->tap_delivered = false;
204
199 spin_lock_bh(&vsock->send_pkt_list_lock);
200 list_add(&pkt->list, &vsock->send_pkt_list);
201 spin_unlock_bh(&vsock->send_pkt_list_lock);
202 } else {
203 if (pkt->reply) {
204 int val;
205
206 val = atomic_dec_return(&vsock->queued_replies);

--- 414 unchanged lines hidden (view full) ---

621
622 vqs[VSOCK_VQ_TX] = &vsock->vqs[VSOCK_VQ_TX];
623 vqs[VSOCK_VQ_RX] = &vsock->vqs[VSOCK_VQ_RX];
624 vsock->vqs[VSOCK_VQ_TX].handle_kick = vhost_vsock_handle_tx_kick;
625 vsock->vqs[VSOCK_VQ_RX].handle_kick = vhost_vsock_handle_rx_kick;
626
627 vhost_dev_init(&vsock->dev, vqs, ARRAY_SIZE(vsock->vqs),
628 UIO_MAXIOV, VHOST_VSOCK_PKT_WEIGHT,
205 spin_lock_bh(&vsock->send_pkt_list_lock);
206 list_add(&pkt->list, &vsock->send_pkt_list);
207 spin_unlock_bh(&vsock->send_pkt_list_lock);
208 } else {
209 if (pkt->reply) {
210 int val;
211
212 val = atomic_dec_return(&vsock->queued_replies);

--- 414 unchanged lines hidden (view full) ---

627
628 vqs[VSOCK_VQ_TX] = &vsock->vqs[VSOCK_VQ_TX];
629 vqs[VSOCK_VQ_RX] = &vsock->vqs[VSOCK_VQ_RX];
630 vsock->vqs[VSOCK_VQ_TX].handle_kick = vhost_vsock_handle_tx_kick;
631 vsock->vqs[VSOCK_VQ_RX].handle_kick = vhost_vsock_handle_rx_kick;
632
633 vhost_dev_init(&vsock->dev, vqs, ARRAY_SIZE(vsock->vqs),
634 UIO_MAXIOV, VHOST_VSOCK_PKT_WEIGHT,
629 VHOST_VSOCK_WEIGHT, NULL);
635 VHOST_VSOCK_WEIGHT, true, NULL);
630
631 file->private_data = vsock;
632 spin_lock_init(&vsock->send_pkt_list_lock);
633 INIT_LIST_HEAD(&vsock->send_pkt_list);
634 vhost_work_init(&vsock->send_pkt_work, vhost_transport_send_pkt_work);
635 return 0;
636
637out:

--- 221 unchanged lines hidden ---
636
637 file->private_data = vsock;
638 spin_lock_init(&vsock->send_pkt_list_lock);
639 INIT_LIST_HEAD(&vsock->send_pkt_list);
640 vhost_work_init(&vsock->send_pkt_work, vhost_transport_send_pkt_work);
641 return 0;
642
643out:

--- 221 unchanged lines hidden ---