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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 A416DC88E50 for ; Fri, 11 Sep 2026 12:39:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:In-Reply-To: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=3o3AUP2GR4e8bKS56CF9rGMsnzBPpsvQ/7QSZVFmj6g=; b=dxrDHqEPCMiaFx1n7c2MRhemc9 WY7cL1LBxOU3IMod5QMKJL+B2Of1eQOPefTR04mmhWYbVgwFOkhQ6yFj+Rkbixf6T+Q29d+Zd7OEL DagPJvLxKvWDrKhcuU13IC1xftZvGHRc0tgmfvuwomuF5aU3vzTKS2ZXl2UvBcRsZKl5clkvGZjbl A6fJU4r+eiGPArj94UB/0bhl5ty757rZjnE8xSNzIAR7JAN4QkjITgT3VvC80LtkGPPnwSV9FaQN0 582u8JQw01C2oL+tglKL1IpO3JQYxr/EQwWqf3b4grINxgEzpMB/E6qH/B+JILx4WdaAUaFqZFjOe 3gqDRVdg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x50Xa-0000000Ge1p-2l6F; Fri, 11 Sep 2026 12:39:38 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x50XY-0000000Ge1S-0d4Z for linux-um@lists.infradead.org; Fri, 11 Sep 2026 12:39:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789130373; 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=3o3AUP2GR4e8bKS56CF9rGMsnzBPpsvQ/7QSZVFmj6g=; b=MxtqT1iyLvIMbsg69wDC3iwbEuaPPQqn6okc4ie5s65UB2TMd0dGT0SNfMh/mc8yjMv/oO oV0s5uv70q2OK4rCuRoCbJjY2ApLy5PhJz7lY3//drmcc4pOhT6PPHN+oeRqDE/jyzh3R7 qFgUd9GVVjsxC7KYy6vczjR15DkHHoI= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-327-7llZfMbePOe2a78EgQdqdg-1; Fri, 11 Sep 2026 08:39:32 -0400 X-MC-Unique: 7llZfMbePOe2a78EgQdqdg-1 X-Mimecast-MFC-AGG-ID: 7llZfMbePOe2a78EgQdqdg_1789130371 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-495689bfcc8so6668685e9.1 for ; Fri, 11 Sep 2026 05:39:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789130371; x=1789735171; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=3o3AUP2GR4e8bKS56CF9rGMsnzBPpsvQ/7QSZVFmj6g=; b=Quin8ixOIFRUD3bDr/XLaYbRyGYPikdh4GCUrxRDtSOd46hTebEtlil8Q3Lpuqsuh8 d3IOKnmI2VKy3iHku+HFQ4phnQ374jolHUM6FxhYvK3I6NsRGog41pIpP3IU5v8KxwEM jXVnBhIc0rNK3fkYi5svJZQmbaqTvjEH7wYdimlrtbXYBxIyQKmhbkI92jPTjQ4EiG9/ snEtBB/zXvCwWh5EYVzgux4HSeX+77bOUx/5lWM6LqifRPvUs3KNsL2ni6ocNut8cgwv skQzdkc2SOPeAKLArKSWbf1I8JL8Kdn3EgPLUcjbRB/eEumgOMw8RTkn9hwHT27GFkyy RZdQ== X-Forwarded-Encrypted: i=1; AKwUvBzpjsofIWp3osadQqCgDA8Tlb0JpRdtaEMjeUQHH8kNNhvZiStIuAsNYQE6lj5nJCAaqnauinfaVA==@lists.infradead.org X-Gm-Message-State: AFuF++kPorA/HLf85//WmRtdvxub/XFFqbO01XY5NpGlTQnm42kK6SY3 xAIOo5bCIrzvJJKBwCy0d+yvSOkgC72pS3Db/TTT08c8/eZ+Iu7w84QZsRewLcOfSLe7zkWPm1V ox/PADi4sSQcUB/a30HGicJQqBSF5+TW6ks2bOBImhKVOelKmQWdUF47rugGfo5z82A== X-Gm-Gg: AYBFou2ZZzJ2O639iYhe+JrR1KLHkM3iSDL+AvYPR0R1+DsuHQa/Sp9XQngzS2Kadt5 5Y1NwaB0bEfOj3Hkhyzgysz0yBDc6Mr3wyJY+VeWqWGhkqWrFdzEu1Xd4Mgl5mzf1+s9FWGmyay TQPiKg2B2Q0f6/EbLvM1X6KBtWy6Qwz19OOKBDdiav4FkVqtY/L+EbqRIPyfpO/QDAdtCNvUiGu DZpKn3zSUAWXly0PdE+ZtxfosaSyGgA+GjZ85/1o7XvBczDKVMTQOR0zuMcmMcirg6yvcO20Oqe pN+Dcx44YsKogs7MJH8OvNEXLP6xn02uMHe9IbKmzZUMGF8upbXA6vRegkV5VNO9p/F+JSPNyMY qEzWxFRA1JkMi+p1z3tKAhuQ= X-Received: by 2002:a05:600d:4452:20b0:499:b65d:124f with SMTP id 5b1f17b1804b1-49e6198c2aemr35358045e9.11.1789130370700; Fri, 11 Sep 2026 05:39:30 -0700 (PDT) X-Received: by 2002:a05:600d:4452:20b0:499:b65d:124f with SMTP id 5b1f17b1804b1-49e6198c2aemr35357705e9.11.1789130370161; Fri, 11 Sep 2026 05:39:30 -0700 (PDT) Received: from redhat.com (IGLD-80-230-79-236.inter.net.il. [80.230.79.236]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49e6420de77sm22739175e9.3.2026.09.11.05.39.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 05:39:29 -0700 (PDT) Date: Fri, 11 Sep 2026 08:39:25 -0400 From: "Michael S. Tsirkin" To: Karl Mehltretter Cc: Jason Wang , Gerd Hoffmann , Xuan Zhuo , Eugenio =?iso-8859-1?Q?P=E9rez?= , Dmitry Torokhov , Rusty Russell , Pawel Moll , Cornelia Huck , Halil Pasic , Eric Farman , Richard Weinberger , Anton Ivanov , Johannes Berg , Hans de Goede , Ilpo =?iso-8859-1?Q?J=E4rvinen?= , Vadim Pasternak , Bjorn Andersson , Mathieu Poirier , virtualization@lists.linux.dev, linux-input@vger.kernel.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, linux-um@lists.infradead.org, platform-driver-x86@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 0/3] virtio: synchronize callbacks during device reset Message-ID: <20260911083848-mutt-send-email-mst@kernel.org> References: <20260905152059.89560-1-kmehltretter@gmail.com> MIME-Version: 1.0 In-Reply-To: <20260905152059.89560-1-kmehltretter@gmail.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: O8sXaPHbZ8F_sAb3Qi3f7y2hmrMCurlUU8mG6z9ISQg_1789130371 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260911_053936_264026_EF7B6C9D X-CRM114-Status: GOOD ( 23.79 ) X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+linux-um=archiver.kernel.org@lists.infradead.org On Sat, Sep 05, 2026 at 05:20:56PM +0200, Karl Mehltretter wrote: > A virtqueue callback can outlive virtio_reset_device() and race with a > driver freeing the state it uses. The reset helper documents that no > callbacks remain in progress, but that depends on the transport: > virtio-pci waits in vp_reset(), while virtio-mmio does not. > > virtio_input has a related ordering problem: it unregisters the input > device before resetting the virtio device, while an event callback may > still be using the input device. > > Patch 1 moves the callback wait into the core, using the existing > virtio_synchronize_cbs() operation. Patch 2 fixes the virtio_input teardown > order. Patch 3 adds the missing synchronize_cbs hooks for UML, TmFIFO, > remoteproc and virtio-vdpa. Remoteproc uses one SRCU domain per processor. > > The new hooks wait for callbacks already running. UML, TmFIFO and > remoteproc still allow new callbacks after reset; fixing that is separate > work. The event-virtqueue DMA mapping issue is also separate. > > Changes in v2: > - Patch 1: move the wait into the core instead of fixing only MMIO, as > Michael suggested. Remove the duplicate PCI wait, preserve its shutdown > wait, and fix CCW callback locking. Drop the MMIO polling: reset polling > for v3 and newer is already in fa8833c085b6 ("virtio-mmio: add support > for transport version 3"). > - Patch 2: keep draining completed events when ready becomes false, > instead of breaking out, so teardown does not truncate an input packet. > - Patch 3 is new, at Michael's request. > > I reran the 120-cycle unbind/rebind test in an arm64 KASAN guest with four > vCPUs and a 5 ms busy delay per event. With patch 2 alone over virtio-mmio, > reset returned with the callback still running in all 84 overlapping > cycles. With the series, it waited in all 103. Over PCI with per-queue > MSI-X, it waited in all 66, including runs with threadirqs. No KASAN or > lockdep reports. These runs predate the per-rproc change, which leaves > the tested MMIO and PCI paths unchanged. They confirmed the missing wait, > but did not reproduce a use-after-free: with evdev attached, > input_unregister_device() waits for an RCU grace period that the IRQ > callback blocks. > > That version also passed QEMU input, rebind and shutdown checks on arm64 > MMIO and x86-64 PCI, including arm64 RT, KASAN and KCSAN builds, and x86 > UP/Tiny SRCU. A legacy INTx NIC was present for an additional x86 > shutdown check. The changed objects built with W=1 without warnings on > arm64, x86-64, s390 and SMP UML. The per-rproc version built with W=1 > on arm64 KASAN and x86 Tiny SRCU, and passed six remoteproc callback and > lifetime KUnit tests on each, using mock remoteproc devices. > > Link: https://lore.kernel.org/r/20260818040433.66986-1-kmehltretter@gmail.com I posted a version of patch 1, split up, just to give direction. Feel free to take over it, or test and ack. Thanks a lot for your work!