Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3854258pxv; Mon, 19 Jul 2021 10:18:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGr/9SIm3EOxBZYWkaU0bHvMRuBpWFNKNM9m8qeHJF2IZinCc64AiPvkWYl1wXhCrciPCe X-Received: by 2002:a17:907:7708:: with SMTP id kw8mr29380784ejc.111.1626715128414; Mon, 19 Jul 2021 10:18:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626715128; cv=none; d=google.com; s=arc-20160816; b=cavutLk+zymshm/sSctNnzdVgKoVxhtnFVCqhH7Rv8zf6OTtwZYSDKgQgDShFBnP6h 6udSdgppoP8ur/8k02cbM3ds/LCbG6IYiRD42fugFmE5TyzzEa/RhsykMEGYPLKivrt/ UrS0XboAjlzzhPsmdYCU5zD8nZsnjvsX+nZO8vKvVy3jCyVTdNU/aiaewKF9lVEizYPk HWuOpFtnS0KbKUlN5IbrkGbyk6gq+LNI7GxzKszNCayyHbl4/PopeCDsV7i6NwhUZngD w21cGjbKOKsFSAIWvWx048pUqFL4RH5Ke+31tdlKw68mEdPLRQw9wWKnMsHD+G8d2ZSz GwGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XWuqXEoJgAsWQkyjnBk/mhY99ETmDqPrE8k+hpmofHc=; b=L4957S9p9U8u01llTJEkdEd60+1Q+dhxBnPVymyuSE4I6wkEec+xIhxSBP9TgmUDIk QiHIXrar4WuTHZjgUZhs9CKfNIuxqRjrKfsPYQB6V8wNLgi11cwdZO6Zn3wl/MzTbspF uso3Qp1O65JiUp0ds9kXV3UjpINwWZnL4qaeE3elj0oZ4zLdPeSp5rOtaRVAe0lob8K/ 3c84z06zo3Y0L1mPWW55Ev/B8hy4Ga+zvFOsINVOiFouc85OZsFAbdCSLtfKYAPyjiUK WEiG13Dt+CuogWy0fpYPAghEVCAWxntQi1z3QfHk6/iAibjZk8oY/UYIuvWTt2knngs7 t4Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gydYbcil; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j24si4765055edt.93.2021.07.19.10.18.25; Mon, 19 Jul 2021 10:18:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gydYbcil; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353062AbhGSQep (ORCPT + 99 others); Mon, 19 Jul 2021 12:34:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:56906 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347709AbhGSPUM (ORCPT ); Mon, 19 Jul 2021 11:20:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 20515613F7; Mon, 19 Jul 2021 15:59:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626710344; bh=O1dqbL5v9Pk/htBaCbRsgljVqbpZTvU1GsfbxVTbALY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gydYbcilQtNGxcfKbt9IiA1PA/QD0wRuymaSGuLzAd5+0C9wp3MIqbB85KbJ9welh TzWbdRA5kuNCF+0gigomMNRvd7pFdliQ+BE4VxUVawyFN/WsCwa8bn3W9q/cjpbhp6 9gKqyLmakruvbaWQFUSWm6a5elDPX/PHyWn3SnME= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Michael S. Tsirkin" , Sasha Levin Subject: [PATCH 5.10 176/243] virtio_net: move tx vq operation under tx queue lock Date: Mon, 19 Jul 2021 16:53:25 +0200 Message-Id: <20210719144946.586016208@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.904087935@linuxfoundation.org> References: <20210719144940.904087935@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael S. Tsirkin [ Upstream commit 5a2f966d0f3fa0ef6dada7ab9eda74cacee96b8a ] It's unsafe to operate a vq from multiple threads. Unfortunately this is exactly what we do when invoking clean tx poll from rx napi. Same happens with napi-tx even without the opportunistic cleaning from the receive interrupt: that races with processing the vq in start_xmit. As a fix move everything that deals with the vq to under tx lock. Fixes: b92f1e6751a6 ("virtio-net: transmit napi") Signed-off-by: Michael S. Tsirkin Signed-off-by: Sasha Levin --- drivers/net/virtio_net.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 345a0f51e8d7..7d1f609306f9 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -1519,6 +1519,8 @@ static int virtnet_poll_tx(struct napi_struct *napi, int budget) struct virtnet_info *vi = sq->vq->vdev->priv; unsigned int index = vq2txq(sq->vq); struct netdev_queue *txq; + int opaque; + bool done; if (unlikely(is_xdp_raw_buffer_queue(vi, index))) { /* We don't need to enable cb for XDP */ @@ -1528,10 +1530,28 @@ static int virtnet_poll_tx(struct napi_struct *napi, int budget) txq = netdev_get_tx_queue(vi->dev, index); __netif_tx_lock(txq, raw_smp_processor_id()); + virtqueue_disable_cb(sq->vq); free_old_xmit_skbs(sq, true); + + opaque = virtqueue_enable_cb_prepare(sq->vq); + + done = napi_complete_done(napi, 0); + + if (!done) + virtqueue_disable_cb(sq->vq); + __netif_tx_unlock(txq); - virtqueue_napi_complete(napi, sq->vq, 0); + if (done) { + if (unlikely(virtqueue_poll(sq->vq, opaque))) { + if (napi_schedule_prep(napi)) { + __netif_tx_lock(txq, raw_smp_processor_id()); + virtqueue_disable_cb(sq->vq); + __netif_tx_unlock(txq); + __napi_schedule(napi); + } + } + } if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS) netif_tx_wake_queue(txq); -- 2.30.2