Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp983420ybi; Wed, 17 Jul 2019 07:52:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzfYQdiJgnUk422yv0RH5vDpMnRota16YI8OkDsuEz9tXdDb5xcr2uqVp3T/xy7RZrjJlx8 X-Received: by 2002:a17:902:8696:: with SMTP id g22mr42491669plo.249.1563375156328; Wed, 17 Jul 2019 07:52:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563375156; cv=none; d=google.com; s=arc-20160816; b=idU6u0NwIY8z1hw1IrQce7Ho0bLwJrUurQ/wUe5ik8/fm4dPttRm5nAZ+lXknVxQIa ZGL74jmKDtt5ZvCzNnsJ3HXiun9ZoMIKBKX1aT7paOoV53q6FdX9jhiSsKZQlqI+sYl9 4L3ovya+mHRLXwIZy6eC8tl4iXylX6OVa9xyti6mLrvtwlDbULtMFmocY6mcYe2w3aZ4 XDeDj7WbfstJGYgjSpoAEDo132yrSo1dk70P09Gdp3wUY8FcSgfsnzpAzZ1P01QAeSDk g0XyrfHVc+DYK10I8Iv4rNdKbhH4oOyHIU3sUTWT3GdVQlxBqEXF6doXhugmIAKl9T0K uPZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=uGVFQip4F6yldZhgkpkV9IZIvVqnTlsuKDYFhodjYNs=; b=AOkZ28o4AXX5vnkqjmv6vmTGb3n06ikY9b+BK742L/zazd3qRK1XSv8pLPB61NdtOr VIf4+43TYd7Qpi/4rhL+wqpIzN+nAPI/ylo+ik58D/9U0DgFVwVyihXHSYMxyebuWpZs fXkAZ78tK/fujBFcti2rKskXbEPbuuKsReCjviU/c0iiUFl2YoaFdzv+zw4HO3cgAgYk cUH4/nUA7s3gnvD9MHtlUYRUeYg6pcKF01gEtIBQGuofvnfihswE6U5+/+mqeyUa/qaU 2mjae8EB2x5Wf/P5yEpSYJWC+8eDnavMi187AxbKJLJHVmzW8eX6lJTXQv2w3SWghtZ1 9WKg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d19si13463926pgl.53.2019.07.17.07.52.19; Wed, 17 Jul 2019 07:52:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727385AbfGQOv7 (ORCPT + 99 others); Wed, 17 Jul 2019 10:51:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40112 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725936AbfGQOv7 (ORCPT ); Wed, 17 Jul 2019 10:51:59 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AFE9581F19; Wed, 17 Jul 2019 14:51:58 +0000 (UTC) Received: from redhat.com (ovpn-125-71.rdu2.redhat.com [10.10.125.71]) by smtp.corp.redhat.com (Postfix) with SMTP id 7D6B660BEE; Wed, 17 Jul 2019 14:51:51 +0000 (UTC) Date: Wed, 17 Jul 2019 10:51:47 -0400 From: "Michael S. Tsirkin" To: Stefano Garzarella Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Hajnoczi , "David S. Miller" , virtualization@lists.linux-foundation.org, Jason Wang , kvm@vger.kernel.org Subject: Re: [PATCH v4 3/5] vsock/virtio: fix locking in virtio_transport_inc_tx_pkt() Message-ID: <20190717105056-mutt-send-email-mst@kernel.org> References: <20190717113030.163499-1-sgarzare@redhat.com> <20190717113030.163499-4-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190717113030.163499-4-sgarzare@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 17 Jul 2019 14:51:58 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 17, 2019 at 01:30:28PM +0200, Stefano Garzarella wrote: > fwd_cnt and last_fwd_cnt are protected by rx_lock, so we should use > the same spinlock also if we are in the TX path. > > Move also buf_alloc under the same lock. > > Signed-off-by: Stefano Garzarella Wait a second is this a bugfix? If it's used under the wrong lock won't values get corrupted? Won't traffic then stall or more data get to sent than credits? > --- > include/linux/virtio_vsock.h | 2 +- > net/vmw_vsock/virtio_transport_common.c | 4 ++-- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h > index 49fc9d20bc43..4c7781f4b29b 100644 > --- a/include/linux/virtio_vsock.h > +++ b/include/linux/virtio_vsock.h > @@ -35,7 +35,6 @@ struct virtio_vsock_sock { > > /* Protected by tx_lock */ > u32 tx_cnt; > - u32 buf_alloc; > u32 peer_fwd_cnt; > u32 peer_buf_alloc; > > @@ -43,6 +42,7 @@ struct virtio_vsock_sock { > u32 fwd_cnt; > u32 last_fwd_cnt; > u32 rx_bytes; > + u32 buf_alloc; > struct list_head rx_queue; > }; > > diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c > index a85559d4d974..34a2b42313b7 100644 > --- a/net/vmw_vsock/virtio_transport_common.c > +++ b/net/vmw_vsock/virtio_transport_common.c > @@ -210,11 +210,11 @@ static void virtio_transport_dec_rx_pkt(struct virtio_vsock_sock *vvs, > > void virtio_transport_inc_tx_pkt(struct virtio_vsock_sock *vvs, struct virtio_vsock_pkt *pkt) > { > - spin_lock_bh(&vvs->tx_lock); > + spin_lock_bh(&vvs->rx_lock); > vvs->last_fwd_cnt = vvs->fwd_cnt; > pkt->hdr.fwd_cnt = cpu_to_le32(vvs->fwd_cnt); > pkt->hdr.buf_alloc = cpu_to_le32(vvs->buf_alloc); > - spin_unlock_bh(&vvs->tx_lock); > + spin_unlock_bh(&vvs->rx_lock); > } > EXPORT_SYMBOL_GPL(virtio_transport_inc_tx_pkt); > > -- > 2.20.1