From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 43F76C4332F for ; Wed, 16 Mar 2022 14:19:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id E738684341; Wed, 16 Mar 2022 14:19:23 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BzlzMAolLLq7; Wed, 16 Mar 2022 14:19:23 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id 8A4C581397; Wed, 16 Mar 2022 14:19:22 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6395CC0012; Wed, 16 Mar 2022 14:19:22 +0000 (UTC) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id A7B0CC000B for ; Wed, 16 Mar 2022 14:19:21 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 831D340A8C for ; Wed, 16 Mar 2022 14:19:21 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nLf91ttX1lgE for ; Wed, 16 Mar 2022 14:19:20 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by smtp2.osuosl.org (Postfix) with ESMTPS id 7EE0840A84 for ; Wed, 16 Mar 2022 14:19:20 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CCE61B81B7A; Wed, 16 Mar 2022 14:19:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 536C7C340E9; Wed, 16 Mar 2022 14:19:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647440356; bh=JuKv5L/0AOr+bAEI9MVsl38mgm5zbqJuHhNnytpvgeE=; h=From:To:Cc:Subject:Date:From; b=Yx2Zq9++e1+aE9AVdWRxgPGZOd8vQCEQEkoEc+GSZL6pBOJhh6kbXfY9luCCz3Ppi VG6ugaOTgh9yq21iMHb7U5hz6iuuRlWlGLdmDbO4Vqk8IbedCq1Tp8T6yg+J7t2LdV YfB5ADjXAUFUbjTSQd3Etz3DCbZ3scGJUI5A3EYQPPQnj129w7eBI9XsUoF9MxPcbB gRJK54WPhJ2a7RUrd0AA0If0Y9SrFtnOew8TrtYYkYrZMlmOyTxqCjIoLnadD+qkO+ FhslkgW6qiB3M88rJUhOX0UQxirtDj6P+Qiyv+1JR0h8gmTgjbmU6zqGMMMHVZyIft EXZ2HjQ70Kg2Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 1/2] virtio_console: break out of buf poll on remove Date: Wed, 16 Mar 2022 10:19:07 -0400 Message-Id: <20220316141908.248848-1-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Cc: Sasha Levin , gregkh@linuxfoundation.org, amit@kernel.org, virtualization@lists.linux-foundation.org, "Michael S. Tsirkin" X-BeenThere: virtualization@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux virtualization List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: virtualization-bounces@lists.linux-foundation.org Sender: "Virtualization" From: "Michael S. Tsirkin" [ Upstream commit 0e7174b9d5877130fec41fb4a16e0c2ee4958d44 ] A common pattern for device reset is currently: vdev->config->reset(vdev); .. cleanup .. reset prevents new interrupts from arriving and waits for interrupt handlers to finish. However if - as is common - the handler queues a work request which is flushed during the cleanup stage, we have code adding buffers / trying to get buffers while device is reset. Not good. This was reproduced by running modprobe virtio_console modprobe -r virtio_console in a loop. Fix this up by calling virtio_break_device + flush before reset. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1786239 Signed-off-by: Michael S. Tsirkin Signed-off-by: Sasha Levin --- drivers/char/virtio_console.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 2632b0fdb1b5..a6b6dc204c1f 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -2004,6 +2004,13 @@ static void virtcons_remove(struct virtio_device *vdev) list_del(&portdev->list); spin_unlock_irq(&pdrvdata_lock); + /* Device is going away, exit any polling for buffers */ + virtio_break_device(vdev); + if (use_multiport(portdev)) + flush_work(&portdev->control_work); + else + flush_work(&portdev->config_work); + /* Disable interrupts for vqs */ vdev->config->reset(vdev); /* Finish up work that's lined up */ -- 2.34.1 _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA3D0C43219 for ; Wed, 16 Mar 2022 14:24:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356800AbiCPOZh (ORCPT ); Wed, 16 Mar 2022 10:25:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356784AbiCPOWB (ORCPT ); Wed, 16 Mar 2022 10:22:01 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14FB95F4C4; Wed, 16 Mar 2022 07:19:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 928D5B81B40; Wed, 16 Mar 2022 14:19:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 536C7C340E9; Wed, 16 Mar 2022 14:19:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647440356; bh=JuKv5L/0AOr+bAEI9MVsl38mgm5zbqJuHhNnytpvgeE=; h=From:To:Cc:Subject:Date:From; b=Yx2Zq9++e1+aE9AVdWRxgPGZOd8vQCEQEkoEc+GSZL6pBOJhh6kbXfY9luCCz3Ppi VG6ugaOTgh9yq21iMHb7U5hz6iuuRlWlGLdmDbO4Vqk8IbedCq1Tp8T6yg+J7t2LdV YfB5ADjXAUFUbjTSQd3Etz3DCbZ3scGJUI5A3EYQPPQnj129w7eBI9XsUoF9MxPcbB gRJK54WPhJ2a7RUrd0AA0If0Y9SrFtnOew8TrtYYkYrZMlmOyTxqCjIoLnadD+qkO+ FhslkgW6qiB3M88rJUhOX0UQxirtDj6P+Qiyv+1JR0h8gmTgjbmU6zqGMMMHVZyIft EXZ2HjQ70Kg2Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Michael S. Tsirkin" , Sasha Levin , amit@kernel.org, gregkh@linuxfoundation.org, virtualization@lists.linux-foundation.org Subject: [PATCH AUTOSEL 4.9 1/2] virtio_console: break out of buf poll on remove Date: Wed, 16 Mar 2022 10:19:07 -0400 Message-Id: <20220316141908.248848-1-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Michael S. Tsirkin" [ Upstream commit 0e7174b9d5877130fec41fb4a16e0c2ee4958d44 ] A common pattern for device reset is currently: vdev->config->reset(vdev); .. cleanup .. reset prevents new interrupts from arriving and waits for interrupt handlers to finish. However if - as is common - the handler queues a work request which is flushed during the cleanup stage, we have code adding buffers / trying to get buffers while device is reset. Not good. This was reproduced by running modprobe virtio_console modprobe -r virtio_console in a loop. Fix this up by calling virtio_break_device + flush before reset. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1786239 Signed-off-by: Michael S. Tsirkin Signed-off-by: Sasha Levin --- drivers/char/virtio_console.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 2632b0fdb1b5..a6b6dc204c1f 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -2004,6 +2004,13 @@ static void virtcons_remove(struct virtio_device *vdev) list_del(&portdev->list); spin_unlock_irq(&pdrvdata_lock); + /* Device is going away, exit any polling for buffers */ + virtio_break_device(vdev); + if (use_multiport(portdev)) + flush_work(&portdev->control_work); + else + flush_work(&portdev->config_work); + /* Disable interrupts for vqs */ vdev->config->reset(vdev); /* Finish up work that's lined up */ -- 2.34.1