From patchwork Wed Mar 15 01:32:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Tao X-Patchwork-Id: 9624689 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9288D604CC for ; Wed, 15 Mar 2017 01:35:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82636285E8 for ; Wed, 15 Mar 2017 01:35:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7559A285ED; Wed, 15 Mar 2017 01:35:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF7D5285DC for ; Wed, 15 Mar 2017 01:35:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751412AbdCOBez (ORCPT ); Tue, 14 Mar 2017 21:34:55 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:34959 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750985AbdCOBew (ORCPT ); Tue, 14 Mar 2017 21:34:52 -0400 Received: by mail-pg0-f68.google.com with SMTP id g2so385565pge.2; Tue, 14 Mar 2017 18:34:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ja5a/Rf1d5IgoVCVD+xcsPjmtCSZ0asytZE8F1cQ5eo=; b=iV4ihzKTAHF0eojxBsezy0vUALVAFWWEYlCKmU9ppaH9JQya8tv9/rSRv4kt8h33Gm qDaf1vMlNG8ECM3vDoxJsyEdKPAQ6t4RItidfR8V28jBrlyr66TGJg2DJk4VeCp443G2 OcT/FXok+cATPVzm13rHLa+nF9ynYT8QDnspcGfBc8Bq9kU53avbSyVXRKE9j7wXs5jr /2h9ifD5RdvXXAStqEmhVq1DtfasIX0od4Qk4W72oMAhNfWaT9LxC93uAwkE0gN/GHFX XEkiatA4qIlHP6iVz1rxHRwcMLlzsxe0H5wXSRVpOxOT22Ec4K5STap1AIs6ii/bdrBl 99lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ja5a/Rf1d5IgoVCVD+xcsPjmtCSZ0asytZE8F1cQ5eo=; b=UrSbk7bxrGfUSqEzc2hh2FSwfSwnxKyDETTbU2VwWuHfFuN60GwFI3wmP3QgnPT0k9 tHhnXJxC3HXQ30n64v/LOrcHo62hMb+PRBxLDpbIqFHmZMP9mEO9hQF33oCghEXcbd1l ABBM6SEncr+6WaYCR2b0jsiwlupGxJ+ySVxzcZmZgI83XP9kl+2FLNjj1DB5LF6pCen+ 8DAfH9IrIs9T5/eitkJCIyNNRpJLt7J1kbFjt7EZhvxBqCRPb8owNFzu16+npbGiYTgk eCs+cn/9/a6tOOlOvifojYdfEbj6NkmYn+t8qznyRRShELvrXQmJyxi9lbuEqQl3lwVv cJ0A== X-Gm-Message-State: AFeK/H0Y1Dr/+Mbh65Jupxh4WjKSrdX2/VJLiSTMMTm9CKT1c2XGD2MHHJaXupq1l9+e6g== X-Received: by 10.84.173.4 with SMTP id o4mr983148plb.106.1489541686624; Tue, 14 Mar 2017 18:34:46 -0700 (PDT) Received: from lear.localdomain (ec2-52-78-240-164.ap-northeast-2.compute.amazonaws.com. [52.78.240.164]) by smtp.gmail.com with ESMTPSA id o125sm326822pfb.109.2017.03.14.18.34.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Mar 2017 18:34:45 -0700 (PDT) From: Peng Tao To: David Miller Cc: netdev@vger.kernel.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, Stefan Hajnoczi , Jorgen Hansen , Peng Tao Subject: [PATCH-v5 2/4] vhost-vsock: add pkt cancel capability Date: Wed, 15 Mar 2017 09:32:15 +0800 Message-Id: <1489541537-130429-3-git-send-email-bergwolf@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1489541537-130429-1-git-send-email-bergwolf@gmail.com> References: <1489541537-130429-1-git-send-email-bergwolf@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP To allow canceling all packets of a connection. Reviewed-by: Stefan Hajnoczi Reviewed-by: Jorgen Hansen Signed-off-by: Peng Tao --- drivers/vhost/vsock.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/net/af_vsock.h | 3 +++ 2 files changed, 44 insertions(+) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index ce5e63d..57babce 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -223,6 +223,46 @@ vhost_transport_send_pkt(struct virtio_vsock_pkt *pkt) return len; } +static int +vhost_transport_cancel_pkt(struct vsock_sock *vsk) +{ + struct vhost_vsock *vsock; + struct virtio_vsock_pkt *pkt, *n; + int cnt = 0; + LIST_HEAD(freeme); + + /* Find the vhost_vsock according to guest context id */ + vsock = vhost_vsock_get(vsk->remote_addr.svm_cid); + if (!vsock) + return -ENODEV; + + spin_lock_bh(&vsock->send_pkt_list_lock); + list_for_each_entry_safe(pkt, n, &vsock->send_pkt_list, list) { + if (pkt->vsk != vsk) + continue; + list_move(&pkt->list, &freeme); + } + spin_unlock_bh(&vsock->send_pkt_list_lock); + + list_for_each_entry_safe(pkt, n, &freeme, list) { + if (pkt->reply) + cnt++; + list_del(&pkt->list); + virtio_transport_free_pkt(pkt); + } + + if (cnt) { + struct vhost_virtqueue *tx_vq = &vsock->vqs[VSOCK_VQ_TX]; + int new_cnt; + + new_cnt = atomic_sub_return(cnt, &vsock->queued_replies); + if (new_cnt + cnt >= tx_vq->num && new_cnt < tx_vq->num) + vhost_poll_queue(&tx_vq->poll); + } + + return 0; +} + static struct virtio_vsock_pkt * vhost_vsock_alloc_pkt(struct vhost_virtqueue *vq, unsigned int out, unsigned int in) @@ -675,6 +715,7 @@ static struct virtio_transport vhost_transport = { .release = virtio_transport_release, .connect = virtio_transport_connect, .shutdown = virtio_transport_shutdown, + .cancel_pkt = vhost_transport_cancel_pkt, .dgram_enqueue = virtio_transport_dgram_enqueue, .dgram_dequeue = virtio_transport_dgram_dequeue, diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h index f275896..f32ed9a 100644 --- a/include/net/af_vsock.h +++ b/include/net/af_vsock.h @@ -100,6 +100,9 @@ struct vsock_transport { void (*destruct)(struct vsock_sock *); void (*release)(struct vsock_sock *); + /* Cancel all pending packets sent on vsock. */ + int (*cancel_pkt)(struct vsock_sock *vsk); + /* Connections. */ int (*connect)(struct vsock_sock *);