Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp2941157pxb; Mon, 6 Sep 2021 08:41:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3PV0ycHnz5i30wE6N3jPRTxpsktSMBfCF9427uKy2Yr11iOyxTHsHZK6/3ZNrziMzBx3P X-Received: by 2002:a05:6e02:1645:: with SMTP id v5mr8605361ilu.322.1630942869599; Mon, 06 Sep 2021 08:41:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630942869; cv=none; d=google.com; s=arc-20160816; b=H3jzKxWo8hnI/akXBZ9jKq4d+rNj55/RkQS8TXti+t7nEAPcNGPa8+Ym2sU77oa7WS 6s2TsmhKYJmNOfM6IH2r1bPyIsfmchIle0PqZqxefIkmGWdbCV9ReOoEaoBvtTb/4Yj1 IVDgdVDsOQPAZVMBAZkO8HAeBOfJgFiy1HiSSM8J4z+Rp6uJcdmaMVCAzQR446TyhlFH s42fg3sjQxl1oXnnhT4mQDjFe7RcpYl12qDEaiZuO69hFO7sT8RauNPhPrWz45lMb46Z ha1nBDA6gWxH4RHDPktmpqO0S+yoywuAR9CIyL7pmiUnoFzHOwih3YnnDDF/dLIQ34Q3 QUeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=kgdlut4j5hhuAHnNJHiggZ2QyP4suVpRdgQkI8pg7R0=; b=DY0OJrrWMe3pClYXoQoNzBFYxgmNho6jVUiQYsEpjhO25n3qToVsglPZwp10tjJLyF q17HGl4wJw8sImnCf5E1H8mLvvHynsUa25jsofNl2S4VXk7lghEML8i1BxFdFt2jA+cr ktZjoPA/frHOzsN6OfTAAF2jWIkDCS/6y7RepK2bRluR2t6v9PBvTbwZ4Jzkv7fbTQdE TDkAGgoupoW3WoJEy4hYAT76sVFnwkP8BoMLXLfPvYP9No85VaRvSzVn1cTBQtiGHjvA jBLS3GgeyDtjxDkXbDmW6zvV1eohajmyl6x8j60D0qE7yEpcV9IiBYKRRYvCnsLJPrib N+kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Q0t0CR9R; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p5si8678651ilc.89.2021.09.06.08.40.57; Mon, 06 Sep 2021 08:41:09 -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=@redhat.com header.s=mimecast20190719 header.b=Q0t0CR9R; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242065AbhIFPUQ (ORCPT + 99 others); Mon, 6 Sep 2021 11:20:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:27128 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbhIFPUP (ORCPT ); Mon, 6 Sep 2021 11:20:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630941550; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kgdlut4j5hhuAHnNJHiggZ2QyP4suVpRdgQkI8pg7R0=; b=Q0t0CR9RLMw9R0UUwcFO1xKcMBmqPhDyDSnsqjU45zeULaEuOvt9875BK66nR8/CCMWJ7R POSNDJ3VKCtYZJIPQWwVY5vLIa6c5jzMuxADlHntzgQ0po/7NYNdgXetR/kWX/wE6e3F0S xDFPx3cZ+6o5RLlgvmzqnjCo1j/ixr4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-268-V4udaKiDNheFJQaw9DUDSA-1; Mon, 06 Sep 2021 11:19:07 -0400 X-MC-Unique: V4udaKiDNheFJQaw9DUDSA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8C51518766D0; Mon, 6 Sep 2021 15:19:06 +0000 (UTC) Received: from localhost (unknown [10.39.194.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5D4C19711; Mon, 6 Sep 2021 15:18:57 +0000 (UTC) Date: Mon, 6 Sep 2021 16:18:56 +0100 From: Stefan Hajnoczi To: "Michael S. Tsirkin" Cc: virtualization@lists.linux-foundation.org, Gerd Hoffmann , linux-kernel@vger.kernel.org, David Airlie , vgoyal@redhat.com, jasowang@redhat.com Subject: Re: [RFC PATCH 0/1] virtio: false unhandled irqs from vring_interrupt() Message-ID: References: <20210824105944.172659-1-stefanha@redhat.com> <20210824072622-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="lPM85ySJm1oUCXyU" Content-Disposition: inline In-Reply-To: <20210824072622-mutt-send-email-mst@kernel.org> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --lPM85ySJm1oUCXyU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Aug 24, 2021 at 07:31:29AM -0400, Michael S. Tsirkin wrote: > On Tue, Aug 24, 2021 at 11:59:43AM +0100, Stefan Hajnoczi wrote: > > While investigating an unhandled irq from vring_interrupt() with virtio= fs I > > stumbled onto a possible race that also affects virtio_gpu. This theory= is > > based on code inspection and hopefully you can point out something that= makes > > this a non-issue in practice :). > >=20 > > The vring_interrupt() function returns IRQ_NONE when an MSI-X interrupt= is > > taken with no used (completed) buffers in the virtqueue. The kernel dis= ables > > the irq and the driver is no longer receives irqs when this happens: > >=20 > > irq 77: nobody cared (try booting with the "irqpoll" option) > > ... > > handlers: > > [<00000000a40a49bb>] vring_interrupt > > Disabling IRQ #77 > >=20 > > Consider the following: > >=20 > > 1. An virtiofs irq is handled and the virtio_fs_requests_done_work() wo= rk > > function is scheduled to dequeue used buffers: > > vring_interrupt() -> virtio_fs_vq_done() -> schedule_work() > >=20 > > 2. The device adds more used requests and just before... > >=20 > > 3. ...virtio_fs_requests_done_work() empties the virtqueue with > > virtqueue_get_buf(). > >=20 > > 4. The device raises the irq and vring_interrupt() is called after > > virtio_fs_requests_done_work emptied the virtqueue: > >=20 > > irqreturn_t vring_interrupt(int irq, void *_vq) > > { > > struct vring_virtqueue *vq =3D to_vvq(_vq); > >=20 > > if (!more_used(vq)) { > > pr_debug("virtqueue interrupt with no work for %p\n", vq); > > return IRQ_NONE; > > ^^^^^^^^^^^^^^^^ > >=20 > > I have included a patch that switches virtiofs from spin_lock() to > > spin_lock_irqsave() to prevent vring_interrupt() from running while the > > virtqueue is processed from a work function. > >=20 > > virtio_gpu has a similar case where virtio_gpu_dequeue_ctrl_func() and > > virtio_gpu_dequeue_cursor_func() work functions only use spin_lock(). > > I think this can result in the same false unhandled irq problem as virt= iofs. > >=20 > > This race condition could in theory affect all drivers. The VIRTIO > > specification says: > >=20 > > Neither of these notification suppression methods are reliable, as th= ey are > > not synchronized with the device, but they serve as useful optimizati= ons. > >=20 > > If virtqueue_disable_cb() is just a hint and might not disable virtqueu= e irqs > > then virtio_net and other drivers have a problem because because an irq= could > > be raised while the driver is dequeuing used buffers. I think we haven'= t seen > > this because software VIRTIO devices honor virtqueue_disable_cb(). Hard= ware > > devices might cache the value and not disable notifications for some ti= me... > >=20 > > Have I missed something? > >=20 > > The virtiofs patch I attached is being stress tested to see if the unha= ndled > > irqs still occur. > >=20 > > Stefan Hajnoczi (1): > > fuse: disable local irqs when processing vq completions > >=20 > > fs/fuse/virtio_fs.c | 15 ++++++++++----- > > 1 file changed, 10 insertions(+), 5 deletions(-) >=20 > Fundamentally it is not a problem to have an unhandled IRQ > once in a while. It's only a problem if this happens time > after time. >=20 >=20 > Does the kernel you are testing include > commit 8d622d21d24803408b256d96463eac4574dcf067 > Author: Michael S. Tsirkin > Date: Tue Apr 13 01:19:16 2021 -0400 >=20 > virtio: fix up virtio_disable_cb >=20 > ? >=20 > If not it's worth checking whether the latest kernel still > has the issue. A new kernel with your patch doesn't have this issue. Please disregard the patch I posted, your patch seems to be enough. Stefan --lPM85ySJm1oUCXyU Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEhpWov9P5fNqsNXdanKSrs4Grc8gFAmE2MWAACgkQnKSrs4Gr c8h9vwf/TvphpnVlEkCnWdWs0t0kMgy5CKuVPH3KAkkGI8l4P/GCoSU2DelelBvF w17DEUCANUwpUq9ztmwj3L0iXWm+xoloiKsrVhhy0QygYuJ7T8Rot2O/j3+43DXV JBVTOHnTD1rZoPVLiARBGe0PpPvBp01vWOe2wsPvpVzwTCdd0SI/Jll/2HjcaT3q mEJCFJ0/6DXRhDIxkg5XoVn/b0Rqh7dBYXBTqxgGOy0nmTug/9ViGHzQB3W/d47i TsL727I7jYgmfhqlMt64jpHC0I/lu7prYWAzV3jo3meRlAUUHnxu1faO5UA+Gjn3 ZwjFVWt2eidR327qaotQ4wK470gZNA== =zSYe -----END PGP SIGNATURE----- --lPM85ySJm1oUCXyU--