Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4483402ybx; Mon, 4 Nov 2019 14:10:55 -0800 (PST) X-Google-Smtp-Source: APXvYqzgZh4rUEI3Igz8E/UQ/ZV1BbtzEPjYEh6j2eszg2EvIGb8+I1ltBXfFkGM0As770wq6laq X-Received: by 2002:a05:6402:168b:: with SMTP id a11mr3702537edv.107.1572905455412; Mon, 04 Nov 2019 14:10:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572905455; cv=none; d=google.com; s=arc-20160816; b=co98HTGujx+87uXnTx919m6o2VFbvDGbgdFXaZU6p7U0cvpP7IRaZG2BjS8dxRXWN2 lUwrbWGgtuMAY0CBqBl500mVOXp8YGHiu6jqnjjJHnBhIkf/0MqTWb1x+HEu1sxHLONB dg9WRz1POYxSGpRw4eLSEJuAzUNlelaUVe5Ag1VRYxZ6++pD6rAbE/5Ss3t/qBXKn603 2geed+a2DsvbJHUfMueZTsXr1+vhy2UP6qfkhEj1v/cihpkF7pe6LaphN5Cs5sqwHo3i ktZBdOj4wvjaJSuPJeDtf2nKQGMizdMRO5ZMCyt59w0v8Lh4QQgvj2/PC9y+x7RQhNwq XwXg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UKwtdbvLpsVJcF/NuDG+WHCqf7tMmhQ9JpRFNtN4+Y8=; b=LQ88vSgECmO5quVA2744WKmTLjQjo+mjmPlJREMTk9PXWjrt2KJm8CZb6JVu+4a23T ZWnZz7tyIe94J6fmfAnmPVIfFnMXDmClgyF/EDK2Q6mrPTi4JZClfiv9ZFYuQ3Jdd0HD aYZk0aLJTXCmzosSqkHO+9HzSJSyB1ouW2CR3eltiq9GN+vChLUoe0wwHekSg0RiBUoi vxe/LvTa9p6GZsF8KMQUJe5cZbzkB6qQ83urnmv1D8P5CmL43cTWujk4yr8QRLgAav6t dNEHgN6IsOJfub1Mv4OF/5zy4EGyNx5Hj/6+NMOZbWYOMra67XQw26YNy+mxI3tan++t OC3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="g/UmEb3m"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 63si9262361edp.302.2019.11.04.14.10.32; Mon, 04 Nov 2019 14:10:55 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b="g/UmEb3m"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389886AbfKDWJ4 (ORCPT + 99 others); Mon, 4 Nov 2019 17:09:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:43028 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389452AbfKDWJx (ORCPT ); Mon, 4 Nov 2019 17:09:53 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 23672205C9; Mon, 4 Nov 2019 22:09:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572905392; bh=pUXAuHhbZFgiGOo8c2/CTCXAlpeJgcFS7eJ7UugIV0c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g/UmEb3m2QNHjd21jiomwTBGIVL/s6W/f1+XRUX7LagZaGyB/lxHf74R76pOGx2qo SxbemCS5q2432vmmFpAtT00dg/WkIdUK2T9HU3WuOPIht/6IVsvXAab9g32T16sRYc 77VHtG6Ex8ZB9onWQWO8O0Wbbmim9cC+zIzEi3gk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jason Wang , Marvin Liu , "Michael S. Tsirkin" Subject: [PATCH 5.3 129/163] virtio_ring: fix stalls for packed rings Date: Mon, 4 Nov 2019 22:45:19 +0100 Message-Id: <20191104212149.645712072@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212140.046021995@linuxfoundation.org> References: <20191104212140.046021995@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marvin Liu commit 40ce7919d8730f5936da2bc8a21b46bd07db6411 upstream. When VIRTIO_F_RING_EVENT_IDX is negotiated, virtio devices can use virtqueue_enable_cb_delayed_packed to reduce the number of device interrupts. At the moment, this is the case for virtio-net when the napi_tx module parameter is set to false. In this case, the virtio driver selects an event offset and expects that the device will send a notification when rolling over the event offset in the ring. However, if this roll-over happens before the event suppression structure update, the notification won't be sent. To address this race condition the driver needs to check wether the device rolled over the offset after updating the event suppression structure. With VIRTIO_F_RING_PACKED, the virtio driver did this by reading the flags field of the descriptor at the specified offset. Unfortunately, checking at the event offset isn't reliable: if descriptors are chained (e.g. when INDIRECT is off) not all descriptors are overwritten by the device, so it's possible that the device skipped the specific descriptor driver is checking when writing out used descriptors. If this happens, the driver won't detect the race condition and will incorrectly expect the device to send a notification. For virtio-net, the result will be a TX queue stall, with the transmission getting blocked forever. With the packed ring, it isn't easy to find a location which is guaranteed to change upon the roll-over, except the next device descriptor, as described in the spec: Writes of device and driver descriptors can generally be reordered, but each side (driver and device) are only required to poll (or test) a single location in memory: the next device descriptor after the one they processed previously, in circular order. while this might be sub-optimal, let's do exactly this for now. Cc: stable@vger.kernel.org Cc: Jason Wang Fixes: f51f982682e2a ("virtio_ring: leverage event idx in packed ring") Signed-off-by: Marvin Liu Signed-off-by: Michael S. Tsirkin Signed-off-by: Greg Kroah-Hartman --- drivers/virtio/virtio_ring.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -1499,9 +1499,6 @@ static bool virtqueue_enable_cb_delayed_ * counter first before updating event flags. */ virtio_wmb(vq->weak_barriers); - } else { - used_idx = vq->last_used_idx; - wrap_counter = vq->packed.used_wrap_counter; } if (vq->packed.event_flags_shadow == VRING_PACKED_EVENT_FLAG_DISABLE) { @@ -1518,7 +1515,9 @@ static bool virtqueue_enable_cb_delayed_ */ virtio_mb(vq->weak_barriers); - if (is_used_desc_packed(vq, used_idx, wrap_counter)) { + if (is_used_desc_packed(vq, + vq->last_used_idx, + vq->packed.used_wrap_counter)) { END_USE(vq); return false; }