Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp762352ybi; Wed, 17 Jul 2019 04:31:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqzEO4gmJK0VqjUfgDE2h4ZrnQ5mU0fIjH/650Pp+10olrY9sXe/eOlhXRIVwvddE/WV/E/v X-Received: by 2002:a63:f510:: with SMTP id w16mr41240219pgh.0.1563363102529; Wed, 17 Jul 2019 04:31:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563363102; cv=none; d=google.com; s=arc-20160816; b=DyTG9/n0M5sDXOH6M6zgfHYogqXQOMMXiCfwyg4mmRanPcGfHRtkSe+JeTlaZI5H/3 aVqExv2zM0GoUxA510SiogDVi521nhoUdP4JqzNcl4dVCkO7smnJYx9yQ0cz0GbZMcTM Vuu+wvM1N7FpGQx8BzJghGTnw9K9W2J5vqVqhYkBDKGWDQIWXBBJtVDnoXSAjz4DsXpr 8Y+P5NeXqAdZ60JAX3fil8sWKqcX9vyCyZXcnzjnDgyKnL7jFBPRsXQwGqX+rPobQhWi rPoSFuofJl7A8mwLd6TBfnI8XY7Kpbtk/kIABD1ySih+JIAagOvFgFm0mDPx0CGtdYr4 nX/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=PngNPTzxPOVcikU4mQgKVw8fAICW+5sxJzO9D5MQ7QY=; b=MJ+zXsuq4VIDiRfqNagPgBA9+WQTkk8+i09izKx2x2XBgXz9yOAKY74vA2c4E1/rwU mS9wFmHHUAjhJlkDfVwPNVlmwxZyh/kQcvhDOX0OtpGaHz0zON+A7xJbEnM25xvUSfbc Ce72mfFuIsmvBqF0w/OKCNdyzd0OeNzViJS8lla6OQDozhQOscA5osuur1NfJYgq0i2j eD95r05f8U+trgdFV5Qy5haoy378eJggz6smXT38Uzx4SoJUYvh8kk3a+auVrkdA7Bnp eGGRzncod8ilKS8/bG/j8fc00/3tex7ZEvNKUrIfjNWMBmNWKmbRA6LSpAKRjQ3vNvo6 rziQ== 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 d7si21855856pgc.470.2019.07.17.04.31.26; Wed, 17 Jul 2019 04:31:42 -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 S1731443AbfGQLav (ORCPT + 99 others); Wed, 17 Jul 2019 07:30:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46758 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731248AbfGQLat (ORCPT ); Wed, 17 Jul 2019 07:30:49 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8F45D81F19; Wed, 17 Jul 2019 11:30:49 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-116-100.ams2.redhat.com [10.36.116.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7AFF45C28C; Wed, 17 Jul 2019 11:30:47 +0000 (UTC) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Stefan Hajnoczi , "David S. Miller" , virtualization@lists.linux-foundation.org, Jason Wang , kvm@vger.kernel.org, "Michael S. Tsirkin" Subject: [PATCH v4 3/5] vsock/virtio: fix locking in virtio_transport_inc_tx_pkt() Date: Wed, 17 Jul 2019 13:30:28 +0200 Message-Id: <20190717113030.163499-4-sgarzare@redhat.com> In-Reply-To: <20190717113030.163499-1-sgarzare@redhat.com> References: <20190717113030.163499-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 17 Jul 2019 11:30:49 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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