From nobody Wed Oct 8 01:59:42 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 82A712D77F0 for ; Thu, 3 Jul 2025 09:26:33 +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=1751534795; cv=none; b=NebRRzAlK8vfOfDeymLPw8cBJpaIYkZiW5N3eu33AT6dLfdoovhfYI1rPxYIfZsLlRbMzQV1EPXqCyXMrJ7+/Tk4vTzn6t8l6XPDox0yKCzkcnE047MImFnCDX5QZ1l4y9E3cpANGvR8djgEuB2Wnr3TOcyqQEY0P7bRPQwFwM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751534795; c=relaxed/simple; bh=iltIWFybhY5jS6gtEpq39rDX9ZwmJ62wzSNTjBqR7K4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gn6z/CcgA+7VBeW/n2YVOXqJM3o/v7IN1hAJKMUMhGWtwJ0ES6ZkjNxdyI+JPosQnZ2ouvAUVZz8pJQuolPCbOauaduWSmiAbYYyVAFo5WiXXGqA/1uoDw9xcoVhinFMSGT+cT8wlt5M8WJKOZct5NShDqPHa+mw9vJk+zc78fY= 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=IYmvmR1q; 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="IYmvmR1q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751534792; 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=gmPV116twb9Z/nZT/xaKI7fsE44yiiTxfBwVEer8aB8=; b=IYmvmR1q3WyuFEoR0iYPSkAG9fvniwZKxBCVOIWHghjbVSqHk+kL6cVpHBGJvOK9aS52hX q0zFxk2WY0Sth37ZdJnUB9/uK0xMArtdrNIBzJQZGIpzVpsUEVTAUxJH/8pJDhANz2qnxr 8ePljYDlo00f50K2Eq/VYdQ22z0EDzY= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-zVEskGfTPaaUevFZLG5_Lg-1; Thu, 03 Jul 2025 05:26:31 -0400 X-MC-Unique: zVEskGfTPaaUevFZLG5_Lg-1 X-Mimecast-MFC-AGG-ID: zVEskGfTPaaUevFZLG5_Lg_1751534790 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3a523ce0bb2so2836094f8f.0 for ; Thu, 03 Jul 2025 02:26:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751534790; x=1752139590; 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=gmPV116twb9Z/nZT/xaKI7fsE44yiiTxfBwVEer8aB8=; b=XLTH9t3aALB08Kp2vis7H54Mjq7wZv7x0oW/cX7TbwCzckxH8SG2TMNLdbWETLbgWx iXxIl6+piF8v4llcMaM7DkIdij7b+bDrkUUF3/rVkSl0ITLhlHrNNBPOPORxkF7ez0gL NLqqy11SLGB+5iKAhiql/w047IMvqt7YAA5PdRKWRacRE4lUk+ycDd1sXKbAgJsufUOX b917PriwM8ozz5Ytf4r5r0xWhk3m7ham6fMz1za6rf9dqSH0r9tgvz8uD3kTZevKFxl1 bUTDy75aVxGfreNBBHpj08xXaVh6iN8/O2NQMbLUhcvkr0HUdCl0gphUPqboahsqgWsn Q4jQ== X-Gm-Message-State: AOJu0YwFbPrLEIaA09doY6Z28k1xfPhNqmkCf/K/sb5nQHtHUj11dSMa a2MnmRk6LvilkbgubazIavp4J+RRyFrWUeKF5yQ40PBDC5RcmOAm8QgNREe4XKZabSitV8RPQ8A 9C060injhnR5tEV3A5x+faOdoZ5j/045tDiz/4Nn9giAZHz9MrLjrwDMKiiSMnBMgEvPUP36TZQ eg5QzkV3rdC7va3RezKM1PSEZaxXiDuzIp9uPds9LWFSs= X-Gm-Gg: ASbGncs9IMFwbnCERtjuGKG2gZDFxw3S8PXuVUd65yi2d3oY/5ALVAJsQ7ku6PTtKnU y1UntWiPupG08++n571Ty4HGBBYf4hoZaPzS8okeBvIxeSQyfiN0vDGcygDIP1RIwmH0OLNGZFH o7SxhRemCCe06O9lbzbkvqDpyJ2OsUXH2G5revBooXa6VB2AuJYmQ1MmDecwJtIdo7bf00Cchmo lVz10t2n3fEjyjo/UID7bW97OvCGcEEJIA1nTyQAlKMEWWIHLlGDLxhNEWEmj8624PSNE+IT6bk gkniJLwm+H9rZ1hH X-Received: by 2002:a05:6000:2f85:b0:3a6:d5fd:4687 with SMTP id ffacd0b85a97d-3b1fe6b72c6mr5557008f8f.18.1751534789786; Thu, 03 Jul 2025 02:26:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMW+7SNj2wAPKclz3m66/sgSUats1gZ/kW9YtYL5R1Qqdu66ZwcRX5icVo4fMXovRSJLS0VA== X-Received: by 2002:a05:6000:2f85:b0:3a6:d5fd:4687 with SMTP id ffacd0b85a97d-3b1fe6b72c6mr5556975f8f.18.1751534789159; Thu, 03 Jul 2025 02:26:29 -0700 (PDT) Received: from redhat.com ([2a0d:6fc0:152e:1400:856d:9957:3ec3:1ddc]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a892e5f8b6sm18462327f8f.91.2025.07.03.02.26.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jul 2025 02:26:28 -0700 (PDT) Date: Thu, 3 Jul 2025 05:26: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 v4 1/5] pci: report surprise removal event Message-ID: <9a2fc64af1d7187c55bfdc710cb3d585cd38cd11.1751534711.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" 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 b81e99cd4b62..208b4cab534b 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -549,6 +549,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 51e2bd6405cd..7fbc377de08a 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -550,6 +550,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 */ @@ -2657,6 +2661,47 @@ static inline bool pci_is_dev_assigned(struct pci_de= v *pdev) return (pdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED) =3D=3D PCI_DEV_FLAGS_AS= SIGNED; } =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); +} + /** * pci_ari_enabled - query ARI forwarding status * @bus: the PCI bus --=20 MST From nobody Wed Oct 8 01:59:43 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 16E742D8763 for ; Thu, 3 Jul 2025 09:26:35 +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=1751534797; cv=none; b=Er9o1S5Z1zsdFG23Qi6qngn3g2TajUUyb5Qp7a0OQMdd0G2KO8dci8MsdKyTVeuqIvo+8kju88D83IErw+OeJ+e2WaQ5cEoH3edT409PmYt8shcEJYC4aoiENH6NyxgPv0bIztlKB46v4auwzXwyAzWo9GKpfVr5niekSktdztM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751534797; 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=FeLMQ4Y9Tp4KeNZW7r4a6Qsi/KC/pBfWqBuUvUvovsZJgpMzCKcpJu3dzTwakD7XLOpTzDAF9HoOYaB2LKOu5BsiPkhaI+jwmCcFcXhi5g0UmlOjpYUEWkwyFNq3URm3PLph2t1ZDhEAOG1VqJ79q0hPsy1T2O4kH/2g/R2Nyks= 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=EEmw5i1b; 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="EEmw5i1b" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751534795; 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=EEmw5i1bf1yCVadQ7dLkgk/hU6VYwmGYePsG3SL5cx5B/UQR2dsYjVgqClqslMPixLwbJl 8nK6ZzocJWesWPHQO6/mHWPVbvgH5oSGDdf3MSOoXV3ukqh0H/jHvCU9lEIxIAr8+3ru0d mBjcV3ngPIdFGX2SGrJkj9xOifQxMZc= 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-497-y-SnSMwLPAWpHAddGjZ8iQ-1; Thu, 03 Jul 2025 05:26:34 -0400 X-MC-Unique: y-SnSMwLPAWpHAddGjZ8iQ-1 X-Mimecast-MFC-AGG-ID: y-SnSMwLPAWpHAddGjZ8iQ_1751534793 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3a4e9252ba0so3290597f8f.0 for ; Thu, 03 Jul 2025 02:26:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751534792; x=1752139592; 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=wizEUn7cw6j6RxeOW1j6VMHiC2+BE0YQl0HDkTOkTVPaX7Mr701b1A+6e6CI72gajU UGGv8ZIy20N8c/eqxgscKovA85Mn625zKyccz27zFOIS32w+y4N69IJ7FcAHJXRaKa0g DsWNvwbw0iBIlZurcGWfPnS785ipnGJeXv3/e5vVZaiI+jsVa/ROYbeangdGzu1W1o6C DOeLhQcpr0DW/1xUxlg3gEizaYQF7LN5EIaagF1BVHKLqyJgDYNH1cKaoEz2UxqAHnYV nqapG7BrWOyY+16iUjp0jBtsiF/9P2j/fppixbb/P0dAvS+iX/5VRPwEiHt1SCe7fSow m1TA== X-Gm-Message-State: AOJu0Yxb8vfrn1iQUvQSLvZ4Z852fKzrtxHlHYTu3Z5Vxc8XH3+HPTwr NMKYFtF2UiOUGAEUEkKf4ky7km4zJPmyQJeR/VrbeWlwo8u9vPXawZU7t+DItiBYW1FRKFg8Q8t p1ylr5P/82PK2JxFtO6UUCXlWBbAeXgrvdYXaTuOEl8g0gMyQnHXx866/kUn1BppWupqSGXdgp7 e4BktQK2xtoWN3q4F8kzdK+kMiMFsGuxnsva8EtbCCADo= X-Gm-Gg: ASbGncs3Gz7wwe22nW65ZAzw7xzpyntx+d+awDhqIMD5BsO61GF5W/l2yMEEQ4eshNe PS3TTngn+t90qUILY6fh23N3qW8RmYwdlUT0NRPGzA46gu99A6lc+yb1DvHQBxP4NpQnutOtgVt 57xcV6GLMUPTLaiG7o4/jECAvpjLu5GQ8JPZTQl2XJwuJGWkYsFrX1qeqZNt8UnknZCO4TSrrbH c9POQa+iOxdKT+t31eqLUPM2/uGVVfmMxM3u5l6P40ulhiF1gWhp7E9g8nNLZOxtOJY9tZzTZc7 IoyAYKY10IwLLh07 X-Received: by 2002:a05:6000:491a:b0:3a4:ef33:e60 with SMTP id ffacd0b85a97d-3b32da93488mr1960770f8f.40.1751534792425; Thu, 03 Jul 2025 02:26:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE8b1TQBfjA4pFNMI59PREmCgzTYZIOsLlPCQGGaGlAM2M5yrv0rTLLaT3Od8ohCZ61d5wRvQ== X-Received: by 2002:a05:6000:491a:b0:3a4:ef33:e60 with SMTP id ffacd0b85a97d-3b32da93488mr1960735f8f.40.1751534791959; Thu, 03 Jul 2025 02:26:31 -0700 (PDT) Received: from redhat.com ([2a0d:6fc0:152e:1400:856d:9957:3ec3:1ddc]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a88c7fa8fasm18050453f8f.28.2025.07.03.02.26.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jul 2025 02:26:31 -0700 (PDT) Date: Thu, 3 Jul 2025 05:26:29 -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 v4 2/5] virtio: fix comments, readability Message-ID: <5cc87ae71e8a61f53e4534bab92f7ad19fc3524a.1751534711.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 Acked-by: Jason Wang --- 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 Wed Oct 8 01:59:43 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 A02F52D8DB9 for ; Thu, 3 Jul 2025 09:26:38 +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=1751534800; cv=none; b=nF6wCD9xdV2rVDkNg79t7XLPElLfdjcOs4K3gjuyIp0XA8eeeFNAPNhmXHUOwlEEhk/WuPiAF7RzB2xtUSKb7EQmD3PbgcZ5u0lBW6NveMF8qEr7KwIGWHBPwwOaRN8wIPin1FWxFyCK/jHX7P0m8QWNwfCwv3TmdEGcCoFmlN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751534800; c=relaxed/simple; bh=PUGyVN4OJqSqheGuV7u25IOAaInhgOsYis9mxDJwLeY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LzydfyKCEm5Wbhl4ST7Zx+JsqLe17ocuEV3cQ3H1hpNyX4zJKHfslR+d3mKDKcFSK5V7ocK35JFAZPioLt2CwRkujeOe7bke76kmjo9mRW7cnVKMC+exRwCfViQgBL/Qw7H77ZgjTcc4KqndgoH6nYBmD0oEQsS37ZSFzis6jAI= 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=KUHP7OWv; 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="KUHP7OWv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751534797; 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=KUHP7OWveXLHAwxHTvqQjbm/kKP72mEbrNBS/swNeR8vHOtK88KcSqhRNasJ4CVfgJaLY/ f2XEiFh5cdDXZqnsH6t2/INIxdQdIBHF+p6oYogb3+ysVBPM/5NGPPDTzUMBhvRBCGXToO rJlX+avFiSZELyOhX/xvRnjStfanFMI= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-643-0aaJju2kNjCDYiZmR1iA3w-1; Thu, 03 Jul 2025 05:26:36 -0400 X-MC-Unique: 0aaJju2kNjCDYiZmR1iA3w-1 X-Mimecast-MFC-AGG-ID: 0aaJju2kNjCDYiZmR1iA3w_1751534795 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3a4e9252ba0so3290642f8f.0 for ; Thu, 03 Jul 2025 02:26:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751534795; x=1752139595; 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=PxLeMybtOMH2ux/N0C5VfdQ7gN6yEMRPA1CYBp1R49KHjfuhaGs+INqoH0LLbFy5FA 5g1aMzkov2GvU+29CusdqobOxotjmI5ZHPobY1t3q3TqQFtE7Uup6PyM78cnN970YgXC HOijAKxCya0O9JlRSyozvKcG+2ieG4EmW7jNsId+CT688zvxZdoxa5bN/yx44gquNT3m IzxVSQK7c4LpWWjaeMJyZnw8UHdDVlhoYiALe8HN0cNBphDwCVEprgkT912KozKa5L1b b/88hcvaQOYaV3xt1crIUKXCUzkRlpycMtHLJTbpOVqqkjMWpXDE7jA76zFxGKnnM8/G UsnQ== X-Gm-Message-State: AOJu0YwRxGpuhrht8ySjSq++e5gWQXDSnK/3L5SLErvayQslBXqnNxJH vBsBbgECYLcwXGwhDnVa1a8xfsNiUhzprARKP36QvayxwitIAhe5JWMxnVo/UjajgJsFKAIR+1X TWx48DxG5Xbun5JeF+gH0/n9+w3LnXto7/dYkkGfAE14C0+w2DeGSDT15Ph2YgPf0zwUe+SB0Y+ 4k+WFVgf9RBJ41NXeN8NFRTQH5lL8C6MHI7TKPu84mWaE= X-Gm-Gg: ASbGncsOyO0uCVkmc1FJdWqlAHpaylueufwA4SH4LXPqWoTFE1uUnCLMTGFS2g73vZg SRHdhJ931FjsVFXTp1eKdT/8XZIi5NhjmTYi19Mik4YY1dfxndHCmIG8KkWVw2AzrnQqO9350kp 285uw2UiAbP2imrSm9XPWbghP4Z2qUgBFkA/0GXj3qJmRwLmNtLd9VWU7hmccmJ22cMqBNdRy53 A2j5frotXNLNBSExlRScj7qWXlg439vl+hDYKl4CIkUJYsLFUZhjMq1zXBNO8ur3ZepsiqRcGMR QqFdcDZXaikXgVeX X-Received: by 2002:a05:6000:22c5:b0:3a3:6e85:a529 with SMTP id ffacd0b85a97d-3b32e5209b1mr2046008f8f.51.1751534795063; Thu, 03 Jul 2025 02:26:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGfswN2F1WSnecEwI4IFFwD4JVrRDEDFHdlQdrbIQbLQDH7ysTzQt9L3uJYclxAObpUi6v/jw== X-Received: by 2002:a05:6000:22c5:b0:3a3:6e85:a529 with SMTP id ffacd0b85a97d-3b32e5209b1mr2045960f8f.51.1751534794544; Thu, 03 Jul 2025 02:26:34 -0700 (PDT) Received: from redhat.com ([2a0d:6fc0:152e:1400:856d:9957:3ec3:1ddc]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454a997af9esm21221155e9.14.2025.07.03.02.26.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jul 2025 02:26:34 -0700 (PDT) Date: Thu, 3 Jul 2025 05:26:32 -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 v4 3/5] virtio: pack config changed flags 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" 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 Wed Oct 8 01:59:43 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 099982D9498 for ; Thu, 3 Jul 2025 09:26:41 +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=1751534803; cv=none; b=BMhgdaibnEfxCR50WOysvsskF06uNv5PdaNDka4+Z7sliQSu2OoaehkiyS4fVy1YKJomN5ui7B/WYmZ+V5zHHSf1XwlFjl+sbbxrV6sZoitNZUpC6Myner0UzirtUVfZ8PEUU3oAiWVOoJYdgBEZqwbKL0QdLRJIdDpVwiVCfIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751534803; 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=ELwgAWt1GzYQUKXDvsnuwcrggBIbq9xVJzucXVkmTSoa1Id1i4CBJ4pxS4KVf4mXZFt244fwbDErpwv0GCh4fcJTWyJHWymUS7045p2yk9moq2C128CTElgy4ADXcBe9i/7xKgqwJOKfLEwpp94fMV7IJiZXjxsl3bUbjp7/d7I= 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=JV7p1hwc; 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="JV7p1hwc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751534801; 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=JV7p1hwczMQT3wV5ClOVODdhHoT0y4XCsA0w8P2UkvECFZ31BpShmk/Wga7z80b2EwpBY4 SlmjeXgxLHbAAjN+ldpSkf/o/lvzkUYOAOaVtKMOxrPclDGU7oMXXmAtob8E/ls46kuoMD 5V8YxKz3YzwnAIGZuqEUjFYGdgfxDEE= 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-159-tLobdSrtOP6LM1usileXcw-1; Thu, 03 Jul 2025 05:26:39 -0400 X-MC-Unique: tLobdSrtOP6LM1usileXcw-1 X-Mimecast-MFC-AGG-ID: tLobdSrtOP6LM1usileXcw_1751534799 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-450eaae2934so39707145e9.2 for ; Thu, 03 Jul 2025 02:26:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751534798; x=1752139598; 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=wHOdLXMMbgdGSc8ZUDgD9FNbQUi1VjFPFAGDdVBQfvzTX6qL3gnd7HRppTIhA3zu45 3Wtx+NK419SsMJAVTfhvPkhWSvFJqi6npuqV3ZGbrgmAB4QYMQxDbtKZuagJVH4XLx+v 2an2JEXFIb88NGkRHvs2f7SQ07VHEYz3ViByfYXF9PtauhCa1m0UrqN4DqiFpFsSzqRL LLxfDOMA8Zxzzc85TSqttCGo8IgRt7azvFgsfOJ3GRtRksBEs09J/TmSxqVgeVNenSkc Y+t7OW6IrySVIwp0E/zMxzI2XTxVZNEUQ8XkZI5Vxs6ilQjD7Jne6jTsZUicNppaKI5M xLXA== X-Gm-Message-State: AOJu0Yz6+vpStYZ3HTBI8TRwFBPY6jkeW9yCYc0jTafXx8cbnmDInUTk eObgWse/md7u4Ce5IoojtNL3OZSsfx7f/HRfSyaYphqHcL6KkC8BzvxtO1qoWHqX4r6S03TfWoW oOic59QA2uP/eJsOEWILnOkv03wPKRuVsLu73gaGxO349vafTQvM+QwDEPty+TuXEIJSfpuQ38N NMQMaGD57O9hAlSWivHbF5qGvfEVfMJ6on3dxu5EOXfEo= X-Gm-Gg: ASbGncs+nJz9HeMJMGRV9vJZlrJgu+V/sRLOk1ryTg8PJgpsPMWmzhZAITFLKYHCnen FysGtg0MT7U1ciQidsusJyZylqFSfc7+UANjnOQrDpDk2CzwJzl5F/kFZhJRUGp8N/BbWUgXKBa SqCUk2njmJzEfoLrZ5M0L5/uGFN8G9wrsi14SKGknsUDZQhUrv6NJOVkfuQjJzNfXi8UjKF6JBc 7rZ4zKPYs4zBvtZjfCe5DdysCiK/t5gioLohsUW3oY+jUtivLxBFCY72QxBRUwBp9fynwV1QIIs EKMrvMyteUGsNcg2 X-Received: by 2002:a05:600c:8883:b0:454:ab1a:8c39 with SMTP id 5b1f17b1804b1-454ab1a8f9cmr14501015e9.26.1751534798129; Thu, 03 Jul 2025 02:26:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGULZivx6PdRE/Oj0oek5elGryB9j+UIWwEzss/nUl15lX5SquQnoBTrb+1G3/c7vEVKSP2+Q== X-Received: by 2002:a05:600c:8883:b0:454:ab1a:8c39 with SMTP id 5b1f17b1804b1-454ab1a8f9cmr14500675e9.26.1751534797611; Thu, 03 Jul 2025 02:26:37 -0700 (PDT) Received: from redhat.com ([2a0d:6fc0:152e:1400:856d:9957:3ec3:1ddc]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454a99a35f9sm21176835e9.27.2025.07.03.02.26.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jul 2025 02:26:37 -0700 (PDT) Date: Thu, 3 Jul 2025 05:26:35 -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 v4 4/5] virtio: allow transports to suppress config change Message-ID: <57feb6b4c9969e153c70dfaa8ec86a304dfee490.1751534711.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" 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 Wed Oct 8 01:59:43 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 57CF22D94AF for ; Thu, 3 Jul 2025 09:26:46 +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=1751534808; cv=none; b=BKd7zRC8NhXx/AbXIoCToJDBRIEKlc8iZc7d5iufKobAuj2Df1J4H8eTeAUfDOdc6dz07Qy1i5WtfkcWjwAGt0C+fpEl0qhIqxbr+B7z9xRjbvZ4k9Li0JcOPuCYtFxoEkbR64mhOw0QFMbPul+FYjkXOMCNruwnHEpejxfFQUo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751534808; 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=CNHnxHpScpJa8RXmfH1vJwWLlsQsHyWwcS3oDE/VKBuFt6LSApLI+WmL2HarZpzTUS9wQBod+KfQ9oDZDrSBBq0ZASGMqHneoYcjD4fDTJxqI39H+SEX3vAGvpYHQcdV2jiYaWWL0EHW0nd9vCrErCSt/F3tbrb3CVnCIWAopQw= 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=Al7k0xG3; 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="Al7k0xG3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751534805; 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=Al7k0xG3P24AvTG7db/SySDOXO3lj8Dnx6KRIysEOhErH35LtGX1HoqDehEctpNpwDLmLX 7BBWlVbVGb8DO0gm9q3BCQszQtPZE1Pu5vovorSPpJyNE8cS6LMwb6yxrrvsUsWwSxTSII jXzqiOF/jzibGysiL4z+21YLi8RG0bs= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-283-f-U-mx1INRyUNsBKAbsLzg-1; Thu, 03 Jul 2025 05:26:42 -0400 X-MC-Unique: f-U-mx1INRyUNsBKAbsLzg-1 X-Mimecast-MFC-AGG-ID: f-U-mx1INRyUNsBKAbsLzg_1751534801 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3a4f858bc5eso3832290f8f.0 for ; Thu, 03 Jul 2025 02:26:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751534801; x=1752139601; 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=S9TnCfOrA541XyVOKUR3mHPwS6NQogOFrAuRMFseyxhHEHuwEYGECFY/y1WJVvpBbM L6nTBbyPIaGoHrwLtIPeg/yyFsAwR4Q0B+Y8uPcYKYOg8xbqJizxaVPKoEp4T1NtdP1d evG6/fAmbM+OIx+fWNMtriM7tInSO/6DwytFc4oR3gcervJSMcqgERuKAxSiXiYjhlA8 /upAn1oEuiRj7nz3U2V7USbXkPS4pZB9pH8I1hwRfMep5MRwos7WCTPyY55MPIX7vw0D eEW+XgsCY0WxOi90SMbXdVr7aBKRCkXeFaBMId4qEQ0R6A98PRvT18aqrSplBNDLQsjY dgCQ== X-Gm-Message-State: AOJu0YyQO9RicOmn4rnWbIw7b6dPFH6MivKvKkIvYMbZXuJIhMPunhpU vsuiGhVJn1mR7hZPhXbs8gJioiV3YRkiUmcea/36SJMLo22NvvPRyTKmeOnTBG5c/WmitGHjriY qb7CL8/L/z/qA9GaisDUrrwDrXVQ23BCWmrwq8Izew/7Nuy/Gqb1999ZXOqtvwbO62xzbrJ0na6 585lEKstoPtkSL+YVW4rOmo5wItpolvBR6kJtpf+TbpLY= X-Gm-Gg: ASbGncsROSoqBKjI7MtUrC/c9Gvj6i5QSchIJdlSn2UroyEM/GormC3u5Da9GQcugUV BoahfbVmKIQc4+vQWrZukXg++lSfht3+mdYZMarLHi6kunvRcSi+x9wJJ2KkCiP0e02sYJdYro6 Z7jeOuud6dTq3ABoylirPznh+lfjxoUGn0aNc9eH8jEftvveL5ndueJnOUbqeRE3sFPHvYWXRbK 12BGKw2fu1/XQfe6PANYoVYOc/2RUhkegd5O1tmmu975W8r0gDhQdDHnezUiaqmo4GdDXC1Zoo2 YYpxrYdid606m2K0 X-Received: by 2002:a05:6000:2c01:b0:3b3:a6e1:135c with SMTP id ffacd0b85a97d-3b3a6e113afmr893722f8f.42.1751534800716; Thu, 03 Jul 2025 02:26:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFkQtx6dTZNMo9PhkqNuSJxJCajqjzjsNPok7wcdjiw76P3Vf7cyfZYrozQCIx+rHWOI+RfQg== X-Received: by 2002:a05:6000:2c01:b0:3b3:a6e1:135c with SMTP id ffacd0b85a97d-3b3a6e113afmr893677f8f.42.1751534800113; Thu, 03 Jul 2025 02:26:40 -0700 (PDT) Received: from redhat.com ([2a0d:6fc0:152e:1400:856d:9957:3ec3:1ddc]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a88c7fab6esm18489438f8f.31.2025.07.03.02.26.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jul 2025 02:26:39 -0700 (PDT) Date: Thu, 3 Jul 2025 05:26:37 -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 v4 5/5] virtio: support device disconnect Message-ID: <1854be16aefc3c0f033472099c909c442d3bc555.1751534711.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