From mboxrd@z Thu Jan 1 00:00:00 1970 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 3035F2080DF for ; Mon, 3 Feb 2025 14:49:09 +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=1738594153; cv=none; b=l2oqKUI9KsobBO2KqsgsJz17pZnJbrCFs3w5quQ4u6wdIlLLIqXAuGeGU7GZh6c5r471EDz2t4LcNtVLXKQgFWqfhakXnXgfa0RD/C4TF9jg7t2LdFhzC8b6cEU7A5O+Fhp8efa1SG4m+7J8tpFonvdFrTCNPupcrqtQT6s/cLU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738594153; c=relaxed/simple; bh=15kWMmNxkUMTSvkiTnVBrfsxV44/Ms3rMk3fOE2f0Q8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=C8Uc9zAzMikyMwSqtuujehC+lm78G4yVaL2rKNdfMhanEGoaKndhlphjP+Fh83SD1Chwz8rAjJOx1e9ZaC215kvj4vTP03nokT870cze+y/izcV5K7uF8ZMPXWF44S31UeXD3luVg8RNmbVOAGl1UO0PLAFd8tixAuWnae/GGKk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=X6hVvvuw; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="X6hVvvuw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738594149; 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=e4CveGpWscXAPpXhsgoWdG7ssIIW1D0dKJfj/YwXZHk=; b=X6hVvvuwkzarKtlFJ9Cl0hZ4huY19WkI6v56nChwB/woNO6BIvyUOqWP7MVbCipWmCO8fs e+xFSGXVmIxgsrNbA6UkKUViRgDbz+jdnHebSCg2C7+Vw4+RoPyHiUCGZf8LF0a8Ysa2uu AalC/rS5IPRWNc1FhLGvSKF8uRYtcwQ= 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-520-H6hNJjlkP9KwFhEiCHBS9g-1; Mon, 03 Feb 2025 09:49:05 -0500 X-MC-Unique: H6hNJjlkP9KwFhEiCHBS9g-1 X-Mimecast-MFC-AGG-ID: H6hNJjlkP9KwFhEiCHBS9g Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-385e3cbf308so1778814f8f.2 for ; Mon, 03 Feb 2025 06:49:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738594144; x=1739198944; 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=e4CveGpWscXAPpXhsgoWdG7ssIIW1D0dKJfj/YwXZHk=; b=RJGKVUHMhuqm6hkpksLUxRpLHhMi5Xfe2lwNuqPZBpOYDSszFzFfDbxtugj4TOhv26 i8hIEkH2NA0UTw7HyIqUPOBXigGPpnEeBVlo+f7DDOg1aqYGy8o2MnWyyTPHx1TzmNsq 3yau+IYLzVh8wUX4hTysOJeHjxsJrWN39AYVID411dao4r/iiQak/+TNX9zFlWEBgSQc zseQW7GgyHcPyx3r1W8b3fbXCpbPktc19ogPbwq4KzkEiIQmdjhxrvYnNLgu+plOPkv2 CcUaEAQjDqxw7hlmpYggv+bseQCoYOe9tZTV+GR5m4ALTKXK1stK2JS5HUotl3VJPPv/ w9Cw== X-Forwarded-Encrypted: i=1; AJvYcCVVYIX5SAoEV0o09AtFBk2EB3Smkj12qxpVOzbKEo9pSpjRrvWgtspD6/EDmjFmaGk3v6Tq6kw3gF33vMg=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4sI8mXIeX1bIE5JNKFcpu/fWMrPPH3zpHjUKx88XbPmb/MPA7 /J80ct05s/yrhbDYfjtzOKJEh3DyCtLkxkvpjhj4m+VM/bsG4TW7s08fh+x+ykaItzi6HR1vdn5 Zx44h+mUDBszWZFOi3MhCMses4uV+QqHMrHQRfD2kTUtPBWhuvhcMG4EB5cIx+g== X-Gm-Gg: ASbGncs8H5fCwGdwM2kk1+S+mbRv0/85rxJ3iSIhJAT5t7+p/28OwqwwXFi/PHJ0JrN 8uST4sSGEDTRegmVTLv4NvCJbG4lWpfO6VrbtmnnERY0oZvaTqb/w5oRAfoaxgLkZq2Kj+Z5RKT 87hY+kKniKWKUSODdt4JR/I14Omftai/GIlPQ6BzxNnEyvoThoz3AHK6VtqnHzo90GHJ10uPsgz 7IGDS8xhgn+Lwmpjsf25O9CGrPplS3GWE3e4BPQw/vEhrrUmkgXqKgWcx2CmHe2ZMsHsPu0w64= X-Received: by 2002:a05:6000:2a9:b0:385:fbb7:672d with SMTP id ffacd0b85a97d-38c5209753cmr17471719f8f.52.1738594143828; Mon, 03 Feb 2025 06:49:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHFyFH+M2Te1TzwrsPgiAkNfzpyODrQhYKLHyFrAPwNqv4qZzpsT+b1HGtHLK7rKOHLDFMakQ== X-Received: by 2002:a05:6000:2a9:b0:385:fbb7:672d with SMTP id ffacd0b85a97d-38c5209753cmr17471694f8f.52.1738594143415; Mon, 03 Feb 2025 06:49:03 -0800 (PST) Received: from redhat.com ([2a02:14f:1f2:ac69:6791:4264:88f3:ab93]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438e244f0d2sm160681555e9.30.2025.02.03.06.48.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 06:49:02 -0800 (PST) Date: Mon, 3 Feb 2025 09:48:56 -0500 From: "Michael S. Tsirkin" To: Eric Auger Cc: "Kirill A. Shutemov" , Jason Wang , Xuan Zhuo , Eugenio =?iso-8859-1?Q?P=E9rez?= , Zhenzhong Duan , virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, Hongyu Ning Subject: Re: [PATCH] virtio: Remove virtio devices on device_shutdown() Message-ID: <20250203094700-mutt-send-email-mst@kernel.org> References: <20240808075141.3433253-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri, Jan 31, 2025 at 10:53:15AM +0100, Eric Auger wrote: > Hi Kirill, Michael > > On 8/8/24 9:51 AM, Kirill A. Shutemov wrote: > > Hongyu reported a hang on kexec in a VM. QEMU reported invalid memory > > accesses during the hang. > > > > Invalid read at addr 0x102877002, size 2, region '(null)', reason: rejected > > Invalid write at addr 0x102877A44, size 2, region '(null)', reason: rejected > > ... > > > > It was traced down to virtio-console. Kexec works fine if virtio-console > > is not in use. > > > > Looks like virtio-console continues to write to the MMIO even after > > underlying virtio-pci device is removed. > > > > The problem can be mitigated by removing all virtio devices on virtio > > bus shutdown. > > > > Signed-off-by: Kirill A. Shutemov > > Reported-by: Hongyu Ning > > Gentle ping on that patch that seems to have fallen though the cracks. > > I think this fix is really needed. I have another test case with a > rebooting guest exposed with virtio-net (backed by vhost-net) and > viommu. Since there is currently no shutdown for the virtio-net, on > reboot, the IOMMU is disabled through the native_machine_shutdown()/ > x86_platform.iommu_shutdown() while the virtio-net is still alive. > > Normally device_shutdown() should call virtio-net shutdown before the > IOMMU tear down and we wouldn't see any spurious transactions after > iommu shutdown. > > With that fix, the above test case is fixed and I do not see spurious > vhost IOTLB miss spurious requests. > > For more details, see qemu thread ([PATCH] hw/virtio/vhost: Disable > IOTLB callbacks when IOMMU gets disabled, > https://lore.kernel.org/all/20250120173339.865681-1-eric.auger@redhat.com/) > > > Reviewed-by: Eric Auger > Tested-by: Eric Auger > > Thanks > > Eric > > > --- > > drivers/virtio/virtio.c | 10 ++++++++++ > > 1 file changed, 10 insertions(+) > > > > diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c > > index a9b93e99c23a..6c2f908eb22c 100644 > > --- a/drivers/virtio/virtio.c > > +++ b/drivers/virtio/virtio.c > > @@ -356,6 +356,15 @@ static void virtio_dev_remove(struct device *_d) > > of_node_put(dev->dev.of_node); > > } > > > > +static void virtio_dev_shutdown(struct device *_d) > > +{ > > + struct virtio_device *dev = dev_to_virtio(_d); > > + struct virtio_driver *drv = drv_to_virtio(dev->dev.driver); > > + > > + if (drv && drv->remove) > > + drv->remove(dev); I am concerned that full remove is a heavyweight operation. Do not want to slow down reboots even more. How about just doing a reset, instead? > > +} > > + > > static const struct bus_type virtio_bus = { > > .name = "virtio", > > .match = virtio_dev_match, > > @@ -363,6 +372,7 @@ static const struct bus_type virtio_bus = { > > .uevent = virtio_uevent, > > .probe = virtio_dev_probe, > > .remove = virtio_dev_remove, > > + .shutdown = virtio_dev_shutdown, > > }; > > > > int __register_virtio_driver(struct virtio_driver *driver, struct module *owner)