From nobody Tue Oct 7 12:25:23 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2EA7239E8D for ; Wed, 9 Jul 2025 20:55:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752094535; cv=none; b=mk9tHRXMZ14b3a1iWIs+92ITg+oXlgnrRynNYnO3uHrfoynXUNA5trb8FaeRQ/0coP3uzdrJj7hQjZGFjsiUP89l2IgjLJLESA51wv06SLpNbttrmRQn9etbYdIUv+/vGoKfxxVdsLdPkm7TcW8tCzCWknTR+w3LFE/LSRdF9Uk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752094535; c=relaxed/simple; bh=/lA1LK7ZnNLfv04veBIb9q69E0+yXfc1RvkXI5Te3eQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kV+ZTsFN0WZpY7vpx4AeTOdVaWXhi6wH55DSShOC4y+jkmC0wNp77MxinTJWwZAfYtR0MVde+frAkdfbKTMQdrGCAGi1n0d/dDSO4L8ZSQpDw1YhbSPy5PHLWz2Vo2PKJTMKmX8Alo/qWx8HJre9s43w07CB/E5N/51g92r8BAc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fte7i4p3; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fte7i4p3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752094531; 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=8+8HiDmuIb1V4xNcjsZubuM5A9uuKBpDTrFrPT0qP+4=; b=fte7i4p3l1W7DUXkzbd2MItTxn3SdSrwynlag+fjuU2ZdgUOwNanU3ZYPKfruAXOAIPkTx Qizazb8t9SPic04OTfgnxOzrm72xxUZIAgleFZ2H3u6s9WcIoPnoch4PdmNa5DnLJAInqe 0I2YeMMlClggwZ6OtbibOjdXAaP/6Mk= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-303-wLXvm3zBMcqXnMeaNvCHyg-1; Wed, 09 Jul 2025 16:55:30 -0400 X-MC-Unique: wLXvm3zBMcqXnMeaNvCHyg-1 X-Mimecast-MFC-AGG-ID: wLXvm3zBMcqXnMeaNvCHyg_1752094529 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-453817323afso1332775e9.1 for ; Wed, 09 Jul 2025 13:55:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752094529; x=1752699329; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8+8HiDmuIb1V4xNcjsZubuM5A9uuKBpDTrFrPT0qP+4=; b=e2bZZxnMTSC8hbij+EuwoNx/jpRziUZz7bghRySTNq4iMHxnp9GJ2MK+UE3k80fQuk +LD14Qae04y+HEWij61NribOgZKNjp/tC4/tvtthfOzaYdWnXLiT7Mv43Oo+O+XdImTg zP6SD7kvOEHn8Jb1HobxBB0chuo1tz61TVEFULDPKgtTB5YV2QuaMjsPcwuaW66YMn+T XZf1Z8dWQGryN6wO00CKXnh8XEgN5biQ6+3NsvkoLHKwwY+IgbO3ghrbTHvuu04mIQcC VjC+6vyB5/nibCF3t7cxNta7+1PGPFDxGDL1r5CPD4QVr2sVruVDFeSkcOd+jrwiEXz6 QJmg== X-Gm-Message-State: AOJu0YyWyhDfQzRzx8Bae3zptMVo9m/LaNfMsPkq2itDFdcPB7tW2ztE J0LgAiyuYtmkkmyQigsKl8eKvsT7AAZiIYoOkRsO4/hL6slsQ67k/TSa2z6/ef/FyDm3OPHZi3R BVt+k/8jKq7Yw67j5+P/jttOx1kKe1rEF7isMTTAnlbWbGcXT2uc8rHazcu+tLEvpxc/YJUl71A SDaA0b7LmuKwGeALyWRPO4ycxQpVASzazCwS1Tq0LojKA= X-Gm-Gg: ASbGncvtVwwiidtc7BxdSI8eH+eWpacpSMBb0p2mR/hxJrZD9r3icyAQbx+x8+413go AVZ2mm2B0nvKAo5zrTSngEn7jtCG7rWxA/SA4MJ02+rdt7Ft3PU9vW9+Crimusd7H63E8mTniT4 9X8KNn10geHHo8wx/GkAtD4ryD8AzUeAVNB74oof1vEHsQhDqe7LFlJzVeKF1eA7sB3ZGhOBJ6u HYEgH4g62Wb7jit2OYNFGj6x/5FtMcXdxKeyogTKMehUuvPeNr1t70pE9C7GDiAZhp0ZVp0yMRH fc0r1A6Pnl8hIeI= X-Received: by 2002:a05:600c:4f55:b0:453:9317:8aa0 with SMTP id 5b1f17b1804b1-454dbd82ee3mr6024905e9.32.1752094529022; Wed, 09 Jul 2025 13:55:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IErXLt//6ePHOG7+onYgqo8lbrjY4/WxLy3ge58RAx7s9NzBFIJkuYjIjs37Zgj4r08N1hruA== X-Received: by 2002:a05:600c:4f55:b0:453:9317:8aa0 with SMTP id 5b1f17b1804b1-454dbd82ee3mr6024675e9.32.1752094528475; Wed, 09 Jul 2025 13:55:28 -0700 (PDT) Received: from redhat.com ([2a0d:6fc0:150d:fc00:de3:4725:47c6:6809]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454d5062119sm39984855e9.18.2025.07.09.13.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jul 2025 13:55:28 -0700 (PDT) Date: Wed, 9 Jul 2025 16:55:26 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Lukas Wunner , Keith Busch , Bjorn Helgaas , Parav Pandit , virtualization@lists.linux.dev, stefanha@redhat.com, alok.a.tiwari@oracle.com, linux-pci@vger.kernel.org Subject: [PATCH RFC v5 1/5] pci: report surprise removal event Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" At the moment, in case of a surprise removal, the regular remove callback is invoked, exclusively. This works well, because mostly, the cleanup would be the same. However, there's a race: imagine device removal was initiated by a user action, such as driver unbind, and it in turn initiated some cleanup and is now waiting for an interrupt from the device. If the device is now surprise-removed, that never arrives and the remove callback hangs forever. For example, this was reported for virtio-blk: 1. the graceful removal is ongoing in the remove() callback, where disk deletion del_gendisk() is ongoing, which waits for the requests +to complete, 2. Now few requests are yet to complete, and surprise removal started. At this point, virtio block driver will not get notified by the driver core layer, because it is likely serializing remove() happening by +user/driver unload and PCI hotplug driver-initiated device removal. So vblk driver doesn't know that device is removed, block layer is waiting for requests completions to arrive which it never gets. So del_gendisk() gets stuck. Drivers can artificially add timeouts to handle that, but it can be flaky. Instead, let's add a way for the driver to be notified about the disconnect. It can then do any necessary cleanup, knowing that the device is inactive. Since cleanups can take a long time, this takes an approach of a work struct that the driver initiates and enables on probe, and tears down on remove. Signed-off-by: Michael S. Tsirkin --- drivers/pci/pci.h | 6 ++++++ include/linux/pci.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 12215ee72afb..3ca4ebfd46be 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -553,6 +553,12 @@ static inline int pci_dev_set_disconnected(struct pci_= dev *dev, void *unused) pci_dev_set_io_state(dev, pci_channel_io_perm_failure); pci_doe_disconnected(dev); =20 + if (READ_ONCE(dev->disconnect_work_enable)) { + /* Make sure work is up to date. */ + smp_rmb(); + schedule_work(&dev->disconnect_work); + } + return 0; } =20 diff --git a/include/linux/pci.h b/include/linux/pci.h index 05e68f35f392..723b17145b62 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -548,6 +548,10 @@ struct pci_dev { /* These methods index pci_reset_fn_methods[] */ u8 reset_methods[PCI_NUM_RESET_METHODS]; /* In priority order */ =20 + /* Report disconnect events. 0x0 - disable, 0x1 - enable */ + u8 disconnect_work_enable; + struct work_struct disconnect_work; + #ifdef CONFIG_PCIE_TPH u16 tph_cap; /* TPH capability offset */ u8 tph_mode; /* TPH mode */ @@ -1993,6 +1997,47 @@ pci_release_mem_regions(struct pci_dev *pdev) pci_select_bars(pdev, IORESOURCE_MEM)); } =20 +/* + * Run this first thing after getting a disconnect work, to prevent it from + * running multiple times. + * Returns: true if disconnect was enabled, proceed. false if disabled, ab= ort. + */ +static inline bool pci_test_and_clear_disconnect_enable(struct pci_dev *pd= ev) +{ + u8 enable =3D 0x1; + u8 disable =3D 0x0; + return try_cmpxchg(&pdev->disconnect_work_enable, &enable, disable); +} + +/* + * Caller must initialize @pdev->disconnect_work before invoking this. + * The work function must run and check pci_test_and_clear_disconnect_enab= le. + * Note that device can go away right after this call. + */ +static inline void pci_set_disconnect_work(struct pci_dev *pdev) +{ + /* Make sure WQ has been initialized already */ + smp_wmb(); + + WRITE_ONCE(pdev->disconnect_work_enable, 0x1); + + /* check the device did not go away meanwhile. */ + mb(); + + if (!pci_device_is_present(pdev)) + schedule_work(&pdev->disconnect_work); +} + +static inline void pci_clear_disconnect_work(struct pci_dev *pdev) +{ + WRITE_ONCE(pdev->disconnect_work_enable, 0x0); + + /* Make sure to stop using work from now on. */ + smp_wmb(); + + cancel_work_sync(&pdev->disconnect_work); +} + #else /* CONFIG_PCI is not enabled */ =20 static inline void pci_set_flags(int flags) { } --=20 MST From nobody Tue Oct 7 12:25:23 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD5EE241C89 for ; Wed, 9 Jul 2025 20:55:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752094537; cv=none; b=MTJf0WLz0/MC2rod+ocyObQbnvsMnzwNcSY4C96FyGlFn3An3KiLifMDnU9wPnoCjEa8oyq9znVRuIZYEINPgOReaRH+4BJ44txj5muGnaSv+ih1TL+J8Waz9xEgfgQMDDx0Mt1tRhq9b5otyOO9EIRXNjPizCRG4M+TMbZ9zFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752094537; c=relaxed/simple; bh=fM0VFuiMREMNY+584mngGa0LdaJ7mBTcKY8yQT4Zb4I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=a67EBxUU61Snq+pomEO57/ljwx+X9BgSBsRc8LjMgGvx+nF13EQ4TA3FjX34A/xq7A1jUdIwEg1SApb9VjamWkl+fa9cvXgfn3HE9mEMN5yv249+3JcdD0cUJa0iI5ydgKEdm9p7ivAxWiQez1WPLHCuClWoJZH3LkZDRucpPMc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=cKZZ/7WV; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cKZZ/7WV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752094534; 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=zmW6YKzoCEgs1ffMR1uB9KKsFPVquRoas1pcF/ETX4A=; b=cKZZ/7WVut/lrD8/7j4TRUR+KCt9nse13+/ROXjv5n25oDTBwUpK9qgY4a1ToP4c4LoDFT z6amiwiqfIm1iiwCsUxDoZcOhPn+1TjPh0uijrboiup3wK3bJlIFrObTjJhlbntUQpA+wX v3m4rmUxAJf+4eRoanm2SyFfvNAdJCI= 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-392-zPrwApLaOIS0gce2saqxNQ-1; Wed, 09 Jul 2025 16:55:33 -0400 X-MC-Unique: zPrwApLaOIS0gce2saqxNQ-1 X-Mimecast-MFC-AGG-ID: zPrwApLaOIS0gce2saqxNQ_1752094532 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-450de98b28eso6126545e9.0 for ; Wed, 09 Jul 2025 13:55:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752094532; x=1752699332; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=zmW6YKzoCEgs1ffMR1uB9KKsFPVquRoas1pcF/ETX4A=; b=O9vTCK9Q2HIQqNU/ASREIllDwhh2ZvSN9045WoxvelRP0+RqYmedWqvpFMsFGSG5sA LS72ZVyJ53CaRRyKSuSAcMlPI8UqRPv6dawAzXmwoJFmguC8mz+cD7nzs4FtJ0kDKftD 0nehG/GsxJYmYJaBHPFtDVa+lOJYBLrcPuehwat8ihielT7K0vjZkQCls9prLG6V3aPg oVlGS/asiK7XUbUlHBBNqIcdU9pXM2FuX0W2dmbCiZt+m1CgTSKEw2/q0RSgRPIlan53 pyhIZ8JPq5mnrq2TKfBQWph2rXX5Aln5RgPIRLOZFlzz10y2Zw4UJ4ybgvjKlqkrBpjb iT6A== X-Gm-Message-State: AOJu0YxQs90eHEZW3w08rVcvmV6Rj284jH8JLfD37+mTOT0aoi9Y6s8Z x2BW3hKNQIibdzF1AFYSN8HWiWUmFlporh9+ciGpG4lVOiCH9+phE3JpvKz8sW1E+ypbAxC/mlm IhmeLmsCo+06s+ejo1GQFCdzZREAhvENurmDfwTZQIG/FILnnSoT/D44BYLYU56tie/PCQAEP4N vdUKBkFB/IW5I07agohd1YUh/Z0WAeXBhvAyB/0cv6g6I= X-Gm-Gg: ASbGncsiDIwIFBt5bjhX7V993bECKejsherrgOSEuM684in2ZBHd4jXnrh+MAbZLI4/ DvGvNWKnzD4vkEqVf4X4aa4nlH/fUB1LSIC9i1WyAgX9MOEfMdhljKUS1KkWQO8rniZFtNgSPfY LdOQ24asui1yX2RocxlUnBOpfk7nfTP5FW+s+zVwzeF+E+ZT7uj4kuWbwJiYLFx7chH84/ef2a1 qJMjX/fEuPUhQud5nMFSNjiJ2Xxg0XCewUllzIfMqgm68Z2Og4k9m10MgL3O0u43048qHS+AlST hBnlGEL5kKmhuDc= X-Received: by 2002:a05:6000:2c02:b0:3a0:b565:a2cb with SMTP id ffacd0b85a97d-3b5e7f0fa20mr1068455f8f.1.1752094531961; Wed, 09 Jul 2025 13:55:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IELRCPBRiwlO7UWH2UvIq0Agob7X2Ahog6Ap+1+2gzcAlXmS2/uyF9cmiofhMLKAIdBSTyk9A== X-Received: by 2002:a05:6000:2c02:b0:3a0:b565:a2cb with SMTP id ffacd0b85a97d-3b5e7f0fa20mr1068418f8f.1.1752094531470; Wed, 09 Jul 2025 13:55:31 -0700 (PDT) Received: from redhat.com ([2a0d:6fc0:150d:fc00:de3:4725:47c6:6809]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b471b966c0sm17407320f8f.52.2025.07.09.13.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jul 2025 13:55:31 -0700 (PDT) Date: Wed, 9 Jul 2025 16:55:28 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Lukas Wunner , Keith Busch , Bjorn Helgaas , Parav Pandit , virtualization@lists.linux.dev, stefanha@redhat.com, alok.a.tiwari@oracle.com, Jason Wang , Xuan Zhuo , Eugenio =?utf-8?B?UMOpcmV6?= Subject: [PATCH RFC v5 2/5] virtio: fix comments, readability Message-ID: <7b74a55a5f3dc066d954472f5b68c29022f11b43.1752094439.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fix a couple of comments to match reality. Initialize config_driver_disabled to be consistent with other fields (note: the structure is already zero initialized, so this is not a bugfix as such). Signed-off-by: Michael S. Tsirkin --- drivers/virtio/virtio.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c index 95d5d7993e5b..c441c8cc71ef 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c @@ -147,7 +147,7 @@ EXPORT_SYMBOL_GPL(virtio_config_changed); =20 /** * virtio_config_driver_disable - disable config change reporting by drive= rs - * @dev: the device to reset + * @dev: the device to disable * * This is only allowed to be called by a driver and disabling can't * be nested. @@ -162,7 +162,7 @@ EXPORT_SYMBOL_GPL(virtio_config_driver_disable); =20 /** * virtio_config_driver_enable - enable config change reporting by drivers - * @dev: the device to reset + * @dev: the device to enable * * This is only allowed to be called by a driver and enabling can't * be nested. @@ -530,6 +530,7 @@ int register_virtio_device(struct virtio_device *dev) goto out_ida_remove; =20 spin_lock_init(&dev->config_lock); + dev->config_driver_disabled =3D false; dev->config_core_enabled =3D false; dev->config_change_pending =3D false; =20 --=20 MST From nobody Tue Oct 7 12:25:23 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 909F923BCE2 for ; Wed, 9 Jul 2025 20:55:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752094540; cv=none; b=o/sA0JbkaYCr6jUfT1rT6TcX8d9xNHNvNQ472RmDIKB2e+5dXNQ04ZvufFBar3xL8pp6MgdjgYH4rLBsdj8eSONY4zw+57C6MUNckirQ9C/JZpYKBMc9eZc1KXBfe8iyLgadQe9ohZ7aBSkKQjj/fwOtBMsyOjt+ymSUHW1n3Vg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752094540; c=relaxed/simple; bh=PUGyVN4OJqSqheGuV7u25IOAaInhgOsYis9mxDJwLeY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=R1+XEXmI//GxJMViBDkMmscINxL8MBcWhp5ECl5jozp5KaArxdnV0YoKW4rFexD+llM25Yy0CbCWO4khdiYahp5EcM/3/Z/tbSa5SgiGaT00WazFQsfES8zvJ4epYa8tMA+RUTFCkrtm9EDDUI7PYl0lNhD0poaIjijKcQkDWr4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Yur/WbOc; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Yur/WbOc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752094536; 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=Y/PjBes3xfnhRnjsZQuw1IljDm3PZO9lLi6jhdLLbvQ=; b=Yur/WbOc0GGe2uQTkZBdvhuhqbTPO+ePWJQq2p/NWJtq9CLCpiBrO4knP8ccw3lKJPt1U/ am9Yu1yp2E1gjGVq9I+cJFOQ3F1ymjKv2poS7UllYwxTjjPlZFcZ7+azG1cSaCRq1ZbVGg bZ8NPGtw9GsDEdo1Wh78FFZZzmyYM0w= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-629-9B7F8_BRPlSbuYo9hEiMyA-1; Wed, 09 Jul 2025 16:55:35 -0400 X-MC-Unique: 9B7F8_BRPlSbuYo9hEiMyA-1 X-Mimecast-MFC-AGG-ID: 9B7F8_BRPlSbuYo9hEiMyA_1752094534 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4538a2f4212so1183155e9.2 for ; Wed, 09 Jul 2025 13:55:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752094534; x=1752699334; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Y/PjBes3xfnhRnjsZQuw1IljDm3PZO9lLi6jhdLLbvQ=; b=UoVomPQoQX655rags98v/coUJsMLpAHYrYA/F3G9eVhyf4L5NDQea/Wcoy5gfgSZ1Z mStNxJBZXqLteLRnLXZmd4Jtmu46TrAiZJB6dNXgIoukDb6lUjsCB3FQGyxzP13uYBfj gT4LsZDEq1+xPBgT+qsVxoTn+/Bsdc+5aNbqMivOJVG/80ub1k0P5PA66+s9YiOHJF0p 8uiyVTVpbEXeS7EJqqLGYRHb4d88QfIa2GMWh7ScQiq7MC4a2yfNUUgU2aM4gsIBMvDx cUhxPyqrjkEA4jkBlEtlBguS0AlLktTX8sbfgAxMr0Ilcx6o2NGYFKwJZso7r3uzjapP CeIw== X-Gm-Message-State: AOJu0Ywid8Dir2TpAMpk7WwtuSwC7x1hk6evhBbaanqR9LzuTpd13G8L MrQYY/4IDHcGiCyZnxSmpM8wqcWGtAY0QOPdU7FGCFtFZPatSmuB/cCub8dejK5Gcy/UzwMCuGg lx9T0yWIQAvlSDbCOCgG38eCMjrIm8uHbPJdI4Js3CAWDInraJ7xn7al8R8a2uHe23H1VyrDqH6 U5h1Zavqz68BCCp0MMnc1eR9Edji65v3hjhal7DD9yvCA= X-Gm-Gg: ASbGncsfpCfLC4tl08kdt+3qh5a5euYbxz04/0bP+DvwmS8R7Qvw1LaCIKlewOhyyCu j3BoS2raWa3xeBQitR8Si7ZDAQi/bJoOdX16yCsJ4qdpuXAj9dTiLZYRHkCcM0yNAsvtK2KRIhv 8BS+pUIQ/XPoTTuY11PP70k6DRxzgZrUN8GJSmoK/gvTKreX39lujGe5TFOufFvHipeqLBk/NsI 9XxitCJ1beFXlWNqniBKR2JGHJd9Vqyjl8zhrefG5wHRpRFG1lVwqgfWO/vqSq3Fn3Mgbaavlnw 10fLVBYXKVIHhXI= X-Received: by 2002:a05:600c:19d1:b0:441:d4e8:76c6 with SMTP id 5b1f17b1804b1-454d53f3136mr41919385e9.30.1752094534200; Wed, 09 Jul 2025 13:55:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvtzRfPYPigjuG7evCZ9GSCMu34t4nH9W9Zvmdr8ctw27FNFQTVrA3clj+tm0lA0zRoYKbtg== X-Received: by 2002:a05:600c:19d1:b0:441:d4e8:76c6 with SMTP id 5b1f17b1804b1-454d53f3136mr41919085e9.30.1752094533725; Wed, 09 Jul 2025 13:55:33 -0700 (PDT) Received: from redhat.com ([2a0d:6fc0:150d:fc00:de3:4725:47c6:6809]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b47225a2dcsm17021160f8f.71.2025.07.09.13.55.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jul 2025 13:55:33 -0700 (PDT) Date: Wed, 9 Jul 2025 16:55:31 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Lukas Wunner , Keith Busch , Bjorn Helgaas , Parav Pandit , virtualization@lists.linux.dev, stefanha@redhat.com, alok.a.tiwari@oracle.com, Jason Wang , Xuan Zhuo , Eugenio =?utf-8?B?UMOpcmV6?= Subject: [PATCH RFC v5 3/5] virtio: pack config changed flags Message-ID: <65da7bde75cdd7ca7ecbca7ca10f51277b44f86f.1752094439.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In anticipation of adding more, use bit-fields instead of bool. Signed-off-by: Michael S. Tsirkin --- include/linux/virtio.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 64cb4b04be7a..be0beb16b487 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -149,9 +149,9 @@ struct virtio_admin_cmd { struct virtio_device { int index; bool failed; - bool config_core_enabled; - bool config_driver_disabled; - bool config_change_pending; + u8 config_core_enabled:1; + u8 config_driver_disabled:1; + u8 config_change_pending:1; spinlock_t config_lock; spinlock_t vqs_list_lock; struct device dev; --=20 MST From nobody Tue Oct 7 12:25:23 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0150E248F55 for ; Wed, 9 Jul 2025 20:55:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752094542; cv=none; b=CtQsGgqZpeM1X1MRRwtA1Z6kyOXpCTQFAQ3YtfsPDKY/beUmUpz/3wVOuqazyyQgz9/2/+vz02wyWexFTItQ4+8XcdhI721+k0OVhAYpTjaDNGZ0TG/NXAOyk8XKn39p+ZuLW68v4Yx/7unfhwsdCFliyM6tJRn4neGjVCErFIg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752094542; c=relaxed/simple; bh=ixhuBTYfea3ddE2iz9G1mIy9dwkewDEfDsZY+6NW2nw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Y8C1OB7kR0QIZ67KZXfGfHl0W8cvseiGXBZ7rMraDYozAe+yQrMw0kj/C6Uzo1PocUYm7ta0bO9wd7URdeaRYT9OpJT9+L6V62iDW1Am0xYXjIu4GvJaw2jAO5nMBX5n+V84jiGhX7gMXzw1EFDqQCKXQGruyaAZGfw6VG81xY8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=bha1WtoZ; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bha1WtoZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752094540; 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=iyE61h0zJVl0tJYFuJIzKM7tu1ObimreBAr/5qShF90=; b=bha1WtoZWxjBIU0xAzrmdZNgXAVmYwaIq8VWSCaBBfquEggxGEYF+TMrNiWwiBycLiCKBC LTN7yKx+spylWl/1YkOO1vJ0WJZkDYxHASZBVMwR5zBM9jzNxTLMgBprfp1Vm5QwVoXIBu 1RuJcfxyVMmm6ttZKfabkH59vb2D+no= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-118-7uLTOtpgNnOOt49OV9tlBg-1; Wed, 09 Jul 2025 16:55:38 -0400 X-MC-Unique: 7uLTOtpgNnOOt49OV9tlBg-1 X-Mimecast-MFC-AGG-ID: 7uLTOtpgNnOOt49OV9tlBg_1752094537 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3a4e9252ba0so208185f8f.0 for ; Wed, 09 Jul 2025 13:55:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752094536; x=1752699336; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=iyE61h0zJVl0tJYFuJIzKM7tu1ObimreBAr/5qShF90=; b=OCckP++CU7BqbQyW1tjbzcsNLAXa7nQLqkCMm2Bbx9img9ytwIwpL24bF0zu5ZH/Ui lE5WKkSedXTUcIq9UnyUl0rkJ9Hu80KCPNshKmYP67zKWEvJbmuX4CDoFPwMgS3xADyO YUvFDdPs5KzMOk2SwzT31wPjC86+3PimWTUzU6Fv9IqfI3Od/uKrHLyZ9vjgMv+GNU23 QQxfCDl1YeAQkqkwBHt1MfPrDTj5CzHpfz/ks/hCiGn7V4fNQD1R/AVIKEB2zMqbjbZl Jbaaeyt1glTrY9PlXo1hEtMyZuBPYe6Kii7k84a1bK1Z75nnWKAh44lHk9rVL9EmyuGU RlZQ== X-Gm-Message-State: AOJu0YwUt3bBAbto3zrCqCOY67H9EFfKZjqNsdexJnz4wI5CNrksHwUZ 9fN095kB2MyxKNpohplqwSMUMTqQNfNSh6Inss7gINkDYk+zaqtLdKOlCW57ruHbiMJkvnMcMVm ZD1W1velGJLty1/iIuRHyBjlg+VAmF3PLOlOU/VHz4bQoMk1mnWo5zJSGOVIAaTgGB27HwfO3gC P/zGEEg1Mb7qRMhUPi7jY+WTjZFKRwB6Z+kmPFFRgcLtw= X-Gm-Gg: ASbGncvnny5+WKEq0cs2fWqtVNvqTRgKD1rK06fBiwGVxj4Beax759lS5H5KA/thF5N OKJus5MaDBwN+KRp3rphGMW3QyNGOuZnzdtT4WIUnMtENpmS3MRfa3G/zAi5uh6dKCspvep8rD8 7subGCYVI3ZAQf62O9LjIzGztoL7jfVzV2LutOwse4vO+0qzHF7iQFzzZR/0Zltal3dGKkT7daY wo6EA/jTqpapwReGV/SDUi7EQ9Oy0loIIcOynrUVVt905/KrNfKTF63PiKRyFNKapn0Zq332W6T UqVCFDkxaIaKnVI= X-Received: by 2002:a05:6000:40d9:b0:3b2:fe84:a10 with SMTP id ffacd0b85a97d-3b5e7650d66mr1214807f8f.0.1752094536435; Wed, 09 Jul 2025 13:55:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpsMPu7CU6gE5ErnQ6ZCj2ysNbEZlkEPok6bMsjf7y8BkX7URX96NcV6dlU7ULjAJLQlSWtg== X-Received: by 2002:a05:6000:40d9:b0:3b2:fe84:a10 with SMTP id ffacd0b85a97d-3b5e7650d66mr1214783f8f.0.1752094535966; Wed, 09 Jul 2025 13:55:35 -0700 (PDT) Received: from redhat.com ([2a0d:6fc0:150d:fc00:de3:4725:47c6:6809]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b47030bd90sm17238302f8f.15.2025.07.09.13.55.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jul 2025 13:55:35 -0700 (PDT) Date: Wed, 9 Jul 2025 16:55:33 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Lukas Wunner , Keith Busch , Bjorn Helgaas , Parav Pandit , virtualization@lists.linux.dev, stefanha@redhat.com, alok.a.tiwari@oracle.com, Jason Wang , Xuan Zhuo , Eugenio =?utf-8?B?UMOpcmV6?= Subject: [PATCH RFC v5 4/5] virtio: allow transports to suppress config change Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Will be used on surprise removal, so we don't need to re-check. Signed-off-by: Michael S. Tsirkin --- drivers/virtio/virtio.c | 18 +++++++++++++++++- include/linux/virtio.h | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c index c441c8cc71ef..1dd5cdf68c1d 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c @@ -127,7 +127,8 @@ static void __virtio_config_changed(struct virtio_devic= e *dev) { struct virtio_driver *drv =3D drv_to_virtio(dev->dev.driver); =20 - if (!dev->config_core_enabled || dev->config_driver_disabled) + if (!dev->config_core_enabled || dev->config_driver_disabled || + dev->config_transport_disabled) dev->config_change_pending =3D true; else if (drv && drv->config_changed) { drv->config_changed(dev); @@ -193,6 +194,20 @@ static void virtio_config_core_enable(struct virtio_de= vice *dev) spin_unlock_irq(&dev->config_lock); } =20 +/** + * virtio_config_transport_disable - disable config change reporting by tr= ansport + * @dev: the device in question + * + * This must only be called by transport and enabling is not allowed. + */ +void virtio_config_transport_disable(struct virtio_device *dev) +{ + spin_lock_irq(&dev->config_lock); + dev->config_transport_disabled =3D true; + spin_unlock_irq(&dev->config_lock); +} +EXPORT_SYMBOL_GPL(virtio_config_transport_disable); + void virtio_add_status(struct virtio_device *dev, unsigned int status) { might_sleep(); @@ -530,6 +545,7 @@ int register_virtio_device(struct virtio_device *dev) goto out_ida_remove; =20 spin_lock_init(&dev->config_lock); + dev->config_transport_disabled =3D false; dev->config_driver_disabled =3D false; dev->config_core_enabled =3D false; dev->config_change_pending =3D false; diff --git a/include/linux/virtio.h b/include/linux/virtio.h index be0beb16b487..072a25f6622c 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -151,6 +151,7 @@ struct virtio_device { bool failed; u8 config_core_enabled:1; u8 config_driver_disabled:1; + u8 config_transport_disabled:1; u8 config_change_pending:1; spinlock_t config_lock; spinlock_t vqs_list_lock; @@ -185,6 +186,7 @@ void virtio_config_changed(struct virtio_device *dev); void virtio_config_driver_disable(struct virtio_device *dev); void virtio_config_driver_enable(struct virtio_device *dev); =20 +void virtio_config_transport_disable(struct virtio_device *dev); #ifdef CONFIG_PM_SLEEP int virtio_device_freeze(struct virtio_device *dev); int virtio_device_restore(struct virtio_device *dev); --=20 MST From nobody Tue Oct 7 12:25:23 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 707B6238C2C for ; Wed, 9 Jul 2025 20:55:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752094544; cv=none; b=HI+PVyxGtwRadoLJvxekSiiOydIy65Nm/5J3nK5Y5cZcLXWeYR3JukpimllzfntjZ6Uayq16lt6ZHskhlITfLv/wF98tL8Nc0H2Al2Mao+s4SjfGlw60WDGUBQquN5IsymJHrsI1Vm+cO1l9eTsR3VjZrlJAOepnoGr/TaglGbE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752094544; c=relaxed/simple; bh=tkgblbTFuQnMgah+b3qVfqQkZaZdA6aVb5an/8MM4jU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=l5B3gFTq2wZLh+JwiZxUfopPmyWeurUNTRvvtCbwrx+KuaznlG19jS5oZXQNXIczPnwQaWEQHE9RtPbONoo/PZ9Ldsxg/Hxp3BrTBIdlCHGOJJpXy45UlomErmov0xFxhyJSs9aUAQMdtciV2mOnOGpW6Ml9V0yEl5bFVx/aiag= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HT0nDw4w; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HT0nDw4w" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752094541; 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=6MdKqwpmU7OaPUd1S1vImlbly2qp2E4LikNix66Cy2A=; b=HT0nDw4wrjDh7b6sR44mfYUcwM5kopIps8E7/QLCsm5A6JKBzVl0CcGfhwkLG3MerBhvNp xRZZ3LwXT16utyRGo9vTV68Wk+ISFqWoiB4hX5dmu3Exo+pA51gJz1bEAo+dJh4hwLxBQP j/G/F7QJgayEnqjQpHKDiLQYrXf6aK0= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-376--JeTEhiePYe-gtltvNhGbw-1; Wed, 09 Jul 2025 16:55:40 -0400 X-MC-Unique: -JeTEhiePYe-gtltvNhGbw-1 X-Mimecast-MFC-AGG-ID: -JeTEhiePYe-gtltvNhGbw_1752094539 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-453a5d50b81so2130495e9.1 for ; Wed, 09 Jul 2025 13:55:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752094539; x=1752699339; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=6MdKqwpmU7OaPUd1S1vImlbly2qp2E4LikNix66Cy2A=; b=lzNNh66VE+y1W8ccbhtK6O23FKc+qzakB2469gKjJDebuVLnXBKuGwg2sNFz27hrIY tD3szSmT5XwZMUZKy/+ANDoaQsd/ldm2Z+t3ffKJOgn5cUDqxIXz3G1tXPqj0c3O8nAU h3bdFV96dLHG18TsANh//cNQv4IDiF3MLNXqPJvV/W3kS4zoUfmgiw9aI/Tsg8/uZXXw D1sTGU36XrZ01VNGE1Tq0DCOjUONXCLWNUlkGfefwHdp6Lft/yTSy/mTu7M0OjDsMvOY 8dpmcMBXQgMq7OSdypmlfmTuEININEThP6vorYK1f5Geaf+MYjkrcCnFCvw3aqk7RF+w JJoA== X-Gm-Message-State: AOJu0YwK+IWHUhXBLMY+17O+hxMTzJqNxKRu22o4+TbTLgTS4tvjZrr9 eOH1Ead05oz1uLDPT86dhICIxZ7EZLWaB7rnnlx3myVoJZf96IWLuwb0myXuvgYXhC3ML3uIsto mPabphKdLCx5JJh55eCqrvFwSOljH7nZmvA6NOZ0R7XdqriFImG4kyI7U/4d3aqoK7UQn5Dqmu9 FQO4mgpP3URwt83aRFL4KYRHxvpedqJxMAufrWP4qqAu8= X-Gm-Gg: ASbGncuj0aRG3raRdYb/69UEj5VREuEikz0u2KPDopja/e8/DCODepfAJoCByHV8dq1 JH4+tUxn5j1sxN6Khz0fHBI416iVKcNPpMi7RXmEMtg3xEdKFRRY0oWTM3bKZVF56b9gXMfGCPU brtqRxYTJ9Rkxhp/Hg2Koln5xmVUvQPCIRXaynP24jOnBiPN2LD3tknvaPwYNZUtplzp2GTk8T7 ZZR23aYJEk/KdPPTJiFKU3aLWF0WagJBQBKg4xeMH2zuBwFOUwUjFImv/R3EPiIyzT3jCQYUcpr 69o8knW4xEGwPM8= X-Received: by 2002:a5d:6f12:0:b0:3a5:541c:b40f with SMTP id ffacd0b85a97d-3b5e866b02bmr183405f8f.9.1752094538678; Wed, 09 Jul 2025 13:55:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGJ4OTW3qeDU0VFbFiSP2ZORT0sgD3mqD8ErTstfRPkAX+VrNK2OCpVJElnxX5MKjetOlmwww== X-Received: by 2002:a5d:6f12:0:b0:3a5:541c:b40f with SMTP id ffacd0b85a97d-3b5e866b02bmr183376f8f.9.1752094538214; Wed, 09 Jul 2025 13:55:38 -0700 (PDT) Received: from redhat.com ([2a0d:6fc0:150d:fc00:de3:4725:47c6:6809]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454d50328b9sm39543455e9.4.2025.07.09.13.55.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jul 2025 13:55:37 -0700 (PDT) Date: Wed, 9 Jul 2025 16:55:36 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Lukas Wunner , Keith Busch , Bjorn Helgaas , Parav Pandit , virtualization@lists.linux.dev, stefanha@redhat.com, alok.a.tiwari@oracle.com, Jason Wang , Xuan Zhuo , Eugenio =?utf-8?B?UMOpcmV6?= Subject: [PATCH RFC v5 5/5] virtio: support device disconnect Message-ID: <8fc65f847b898c0e179e42f24defadc79590e7cf.1752094439.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This adds support for device disconnect: upon device surprise removal, virtio core makes sure to no callbacks are running, and then notifies the driver. At the moment, virtio pci is the only transport with this functionality enabled, it does nothing for other transports. Signed-off-by: Michael S. Tsirkin --- drivers/virtio/virtio_pci_common.c | 45 ++++++++++++++++++++++++++++++ drivers/virtio/virtio_pci_common.h | 3 ++ drivers/virtio/virtio_pci_legacy.c | 2 ++ drivers/virtio/virtio_pci_modern.c | 2 ++ include/linux/virtio.h | 3 ++ include/linux/virtio_config.h | 32 +++++++++++++++++++++ 6 files changed, 87 insertions(+) diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci= _common.c index d6d79af44569..a475f47052eb 100644 --- a/drivers/virtio/virtio_pci_common.c +++ b/drivers/virtio/virtio_pci_common.c @@ -594,6 +594,51 @@ const struct cpumask *vp_get_vq_affinity(struct virtio= _device *vdev, int index) vp_dev->vqs[index]->msix_vector); } =20 +/* Report disconnect to the driver. */ +static void virtio_pci_disconnect_work(struct work_struct *work) +{ + struct pci_dev *pci_dev =3D container_of(work, struct pci_dev, + disconnect_work); + struct virtio_pci_device *vp_dev =3D pci_get_drvdata(pci_dev); + struct virtio_device *vdev =3D &vp_dev->vdev; + struct virtio_driver *drv =3D drv_to_virtio(vdev->dev.driver); + + if (!pci_test_and_clear_disconnect_enable(pci_dev)) + return; + + virtio_config_transport_disable(vdev); + virtio_break_device(vdev); + + vp_synchronize_vectors(vdev); + + drv->disconnect(&vp_dev->vdev); +} + +void virtio_pci_enable_disconnect(struct virtio_device *vdev) +{ + struct virtio_pci_device *vp_dev =3D to_vp_device(vdev); + struct pci_dev *pci_dev =3D vp_dev->pci_dev; + struct virtio_driver *drv =3D drv_to_virtio(vdev->dev.driver); + + if (!drv->disconnect) + return; + + INIT_WORK(&pci_dev->disconnect_work, virtio_pci_disconnect_work); + pci_set_disconnect_work(pci_dev); +} + +void virtio_pci_disable_disconnect(struct virtio_device *vdev) +{ + struct virtio_pci_device *vp_dev =3D to_vp_device(vdev); + struct pci_dev *pci_dev =3D vp_dev->pci_dev; + struct virtio_driver *drv =3D drv_to_virtio(vdev->dev.driver); + + if (!drv->disconnect) + return; + + pci_clear_disconnect_work(pci_dev); +} + #ifdef CONFIG_PM_SLEEP static int virtio_pci_freeze(struct device *dev) { diff --git a/drivers/virtio/virtio_pci_common.h b/drivers/virtio/virtio_pci= _common.h index 8cd01de27baf..982c4c8aabc8 100644 --- a/drivers/virtio/virtio_pci_common.h +++ b/drivers/virtio/virtio_pci_common.h @@ -161,6 +161,9 @@ static inline void virtio_pci_legacy_remove(struct virt= io_pci_device *vp_dev) int virtio_pci_modern_probe(struct virtio_pci_device *); void virtio_pci_modern_remove(struct virtio_pci_device *); =20 +void virtio_pci_enable_disconnect(struct virtio_device *); +void virtio_pci_disable_disconnect(struct virtio_device *); + struct virtio_device *virtio_pci_vf_get_pf_dev(struct pci_dev *pdev); =20 #define VIRTIO_LEGACY_ADMIN_CMD_BITMAP \ diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci= _legacy.c index d9cbb02b35a1..cd424f619b47 100644 --- a/drivers/virtio/virtio_pci_legacy.c +++ b/drivers/virtio/virtio_pci_legacy.c @@ -191,6 +191,8 @@ static const struct virtio_config_ops virtio_pci_config= _ops =3D { .set =3D vp_set, .get_status =3D vp_get_status, .set_status =3D vp_set_status, + .enable_disconnect =3D virtio_pci_enable_disconnect, + .disable_disconnect =3D virtio_pci_disable_disconnect, .reset =3D vp_reset, .find_vqs =3D vp_find_vqs, .del_vqs =3D vp_del_vqs, diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci= _modern.c index 7182f43ed055..b3dfb403913f 100644 --- a/drivers/virtio/virtio_pci_modern.c +++ b/drivers/virtio/virtio_pci_modern.c @@ -1230,6 +1230,8 @@ static const struct virtio_config_ops virtio_pci_conf= ig_nodev_ops =3D { .generation =3D vp_generation, .get_status =3D vp_get_status, .set_status =3D vp_set_status, + .enable_disconnect =3D virtio_pci_enable_disconnect, + .disable_disconnect =3D virtio_pci_disable_disconnect, .reset =3D vp_reset, .find_vqs =3D vp_modern_find_vqs, .del_vqs =3D vp_del_vqs, diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 072a25f6622c..a091651e3144 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -214,6 +214,8 @@ size_t virtio_max_dma_size(const struct virtio_device *= vdev); * @scan: optional function to call after successful probe; intended * for virtio-scsi to invoke a scan. * @remove: the function to call when a device is removed. + * @disconnect: the function to call on disconnect (surprise removal), + * before remove. * @config_changed: optional function to call when the device configuration * changes; may be called in interrupt context. * @freeze: optional function to call during suspend/hibernation. @@ -235,6 +237,7 @@ struct virtio_driver { int (*validate)(struct virtio_device *dev); int (*probe)(struct virtio_device *dev); void (*scan)(struct virtio_device *dev); + void (*disconnect)(struct virtio_device *dev); void (*remove)(struct virtio_device *dev); void (*config_changed)(struct virtio_device *dev); int (*freeze)(struct virtio_device *dev); diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index b3e1d30c765b..861198a74be2 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h @@ -58,6 +58,10 @@ struct virtqueue_info { * @set_status: write the status byte * vdev: the virtio_device * status: the new status byte + * @enable_disconnect: driver will get disconnect callbacks + * vdev: the virtio_device + * @disable_disconnect: driver will not get disconnect callbacks + * vdev: the virtio_device * @reset: reset the device * vdev: the virtio device * After this, status and feature negotiation must be done again @@ -113,6 +117,8 @@ struct virtio_config_ops { u32 (*generation)(struct virtio_device *vdev); u8 (*get_status)(struct virtio_device *vdev); void (*set_status)(struct virtio_device *vdev, u8 status); + void (*enable_disconnect)(struct virtio_device *vdev); + void (*disable_disconnect)(struct virtio_device *vdev); void (*reset)(struct virtio_device *vdev); int (*find_vqs)(struct virtio_device *vdev, unsigned int nvqs, struct virtqueue *vqs[], @@ -299,6 +305,32 @@ void virtio_device_ready(struct virtio_device *dev) dev->config->set_status(dev, status | VIRTIO_CONFIG_S_DRIVER_OK); } =20 +/** + * virtio_device_enable_disconnect - enable disconnect callback + * @dev: the virtio device + * + * Driver must call this in the probe function. + */ +static inline +void virtio_device_enable_disconnect(struct virtio_device *dev) +{ + if (dev->config->enable_disconnect) + dev->config->enable_disconnect(dev); +} + +/** + * virtio_device_disable_disconnect - enable disconnect callback + * @dev: the virtio device + * + * Driver must call this in the remove function. + */ +static inline +void virtio_device_disable_disconnect(struct virtio_device *dev) +{ + if (dev->config->disable_disconnect) + dev->config->disable_disconnect(dev); +} + static inline const char *virtio_bus_name(struct virtio_device *vdev) { --=20 MST