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.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 4FAA02D1913 for ; Mon, 22 Jun 2026 14:58:42 +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=1782140323; cv=none; b=CvKt3pJtb+S7MbuC8mhCEv9SiSvQc7QqXXOP24KOUaDfGw2knUCTQvILQ8x3YyrMHWbjwmQzA9GL3YBX9EwLJTwmUC0norjH2w/pTMWP1ivLJhcVBQIq2/TDwfAs43DmrK/K+1F/pQXblwPlk/OqKzREHUcizKoyRms1+jXBpCU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782140323; c=relaxed/simple; bh=aSGgG9KnpqfwEvch2LMjPA4okhZC7xQVuMZup5njJsc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=U60rKNdfMSnqFyd8/KqcSmmgdirxpph4onRUXYl3D+Tv3iMB9PTvplpufjif90FFg5JUG9NpIXmAUQ2HykDsaS51JWI2HQlZn8OHCFFSYPP4zOgsE3sPpnDTutQIp7nnWVu/j3hgpf9lfNLDPiK8eiwQopsbQrVaOF/nS3U6fh0= 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=iEi9aJ3r; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=rT2Wzg7n; 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="iEi9aJ3r"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="rT2Wzg7n" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782140321; 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=hGbjuSGTfMEtkMyDobc9j0xZ/49pPMvHeh7tIkGswH4=; b=iEi9aJ3rVzp4c0PtRuM3sMbiVmoEpEMWkgXJexE+IZSHj+MjPDR1yyEjJ8tMS5FoDzBoEa wi+AinWfwd6dgh0mjH3cGIzu7m9LSzemGYuCxKF5y4gxLmCtkghSshBSQRUInckNM95N5G bVP7h+9hiF8BAIA8SUsMsKakFaU4Eq0= 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-39-WnfpyHm_NHu-0CqUi6V-bg-1; Mon, 22 Jun 2026 10:58:39 -0400 X-MC-Unique: WnfpyHm_NHu-0CqUi6V-bg-1 X-Mimecast-MFC-AGG-ID: WnfpyHm_NHu-0CqUi6V-bg_1782140319 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4923411f041so36286975e9.2 for ; Mon, 22 Jun 2026 07:58:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1782140318; x=1782745118; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=hGbjuSGTfMEtkMyDobc9j0xZ/49pPMvHeh7tIkGswH4=; b=rT2Wzg7nBE+GkS+tbNrU9YSj0Y2vLX1sxSc/Kx9EjZol97Z7RKy2ZqDe6nLyt4g5QN 5VtgEjWQmodqd6BGb0iJpdRxJEovdsW7LBbVQOxr7JpL4AepeeJj0ZE5Cs7yTRtF8cxF gGr6nvElsKcuuyYdTja+4Wp3at0wm6O0l0/Gw+YxmZtvKWg4dbHvxch1gSKFbJTuitO3 egb8oAJ1Q5f8OvLizmFqMRyB3M4GoiAjBAKWyqP7IBwqJL91Eajx+Vm4pHVgGOZn5xBl +REw9x+Eta195+hMA1Oc4psQWGumIthZNHpSWmI4U5r67ljTe2mr+jjKpJzKpJ8LTCJk LHtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782140318; x=1782745118; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hGbjuSGTfMEtkMyDobc9j0xZ/49pPMvHeh7tIkGswH4=; b=oBMkZzwFlPqAp19XUUJbCfm9MlfFzRJnBR90n6a05CPPmmvjwAuWWrPNqkoPH5jf7V A3115AXbVJaNBGCR696c4SdNZPJ6hsuV1kWioi2TIIMGcIvINrj1l3j734PrOepYuzVG jDeGahmrkdLODCOiqwWwgNIJ6EZmwDlFFn+oV5aY0xW3YPulbKQhmvEtzEJNWY9zJISm 6z87m8GgP+HwM5EOsCrDH0OeY1AE600m3OpizxXsBSpqKYh6v4Mfps9HhF1N9UXawwCR gOhN6Kg2Q8rK55mE0MgQkY+34V4zFJDmT/xgYMQalYODpCLyJsg126XMfJy0scYXCJqb CGYw== X-Forwarded-Encrypted: i=1; AFNElJ88TluF5SizehZfea8OkML7Rx0ot7IrxIhTdoB5va1cKRIWS89gp/pHptNlRxnpvz3BROO+Fi6ENYrHjAs=@vger.kernel.org X-Gm-Message-State: AOJu0Yxj1xo7MG6xpDyGc7TZ/SOdOPzgf7r5n+gTGBx90EtqCQKUb+LC CVzMIolo20wJqHYTmh2qJIX+5oIIoUZ8hsaKzrlC4qLnOCWthlAApYDBZOn6pR8vaC4RVs4V91Z LFfOe4KwITxRBfr4axB3ZrLA5KYytGFwyFhAsVwy/7fkGVe2ugauNLO84xsRe6Z7a4QVe+7vlSA == X-Gm-Gg: AfdE7cmHLnr/kVXdmanM1PT1pqoB+BjYNznVEsVoaS2m5PIM9xJ1T3fog30EvtfOEwU EnPlSA5ZV4hpoSUvQ+LtZt+XQbXxy1uVbDqrWURapLw/ziCHPz9eZX7Xr5pz33cfvCfU0GtKj2a VaSpkOJDsVfgMUjy5e1nYifkmElhY/k8cbGiGGHqFOW4T1Qryf3FjZcx7qQ6IAw7LREYhYaZvjk Bwh+/4bGbjGR//hLjroMO4MP068Zs4UeBM/TXLr6lrcgU6XtTjdAigs5VOoLqocgPjAimfmEDL8 bVT9vEtChbnC7aNrLlIk11OCxdywxpW4Y1NQJTrwnzjsNvP6f0Alx1XTfW7cn2w/YJQU1keL9sS DePGO706bCKPJ9EpTA38jvEZP49xL0CEp X-Received: by 2002:a05:600c:8b2b:b0:492:4a56:690b with SMTP id 5b1f17b1804b1-4924a5669d3mr168320545e9.35.1782140318490; Mon, 22 Jun 2026 07:58:38 -0700 (PDT) X-Received: by 2002:a05:600c:8b2b:b0:492:4a56:690b with SMTP id 5b1f17b1804b1-4924a5669d3mr168320045e9.35.1782140317925; Mon, 22 Jun 2026 07:58:37 -0700 (PDT) Received: from redhat.com (IGLD-80-230-85-71.inter.net.il. [80.230.85.71]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4923fe7ba08sm301101105e9.11.2026.06.22.07.58.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2026 07:58:37 -0700 (PDT) Date: Mon, 22 Jun 2026 10:58:35 -0400 From: "Michael S. Tsirkin" To: "David Hildenbrand (Arm)" Cc: "Denis V. Lunev" , virtualization@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] virtio_balloon: quiesce balloon work before device shutdown Message-ID: <20260622105806-mutt-send-email-mst@kernel.org> References: <20260622133715.3707707-1-den@openvz.org> <20260622133715.3707707-3-den@openvz.org> <8b83f251-3a3e-4fc9-8ea9-8d101fb92919@kernel.org> 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: <8b83f251-3a3e-4fc9-8ea9-8d101fb92919@kernel.org> On Mon, Jun 22, 2026 at 04:38:54PM +0200, David Hildenbrand (Arm) wrote: > On 6/22/26 15:37, Denis V. Lunev wrote: > > Commit 8bd2fa086a04 ("virtio: break and reset virtio devices on > > device_shutdown()") added a generic virtio bus .shutdown handler that > > breaks and resets every virtio device during device_shutdown(), i.e. on > > reboot and kexec. > > > > virtio_balloon provides no .shutdown of its own, so that generic path > > runs while the balloon's asynchronous work is still armed. Once the > > device has been broken, virtqueue_add_inbuf() in > > virtballoon_free_page_report() returns -EIO and trips its > > WARN_ON_ONCE(). On a kernel booted with panic_on_warn that turns an > > ordinary reboot, for example a kexec based upgrade, into a fatal panic > > in the middle of device_shutdown(), so the machine never reaches the > > new kernel. > > > > Relaxing that single WARN_ON_ONCE() would only hide the symptom: the > > inflate/deflate and OOM paths do not warn, they call > > wait_event(vb->acked, ...) and would instead block forever on a broken > > queue that can no longer complete. The device has to be quiesced, not > > just kept quiet. > > Ah, so > > /* We should always be able to add one buffer to an empty queue. */ > virtqueue_add_outbuf(vq, &sg, 1, vb, GFP_KERNEL); > > is not actually correct. Yes - we can't if the device is completely gone) > Yeah, quiescing sounds cleaner, although I am thinking whether we should also > warn if virtqueue_add_outbuf() fails, similar to what we do in > virtballoon_free_page_report(). > > > > > Add a .shutdown handler that quiesces the balloon via the shared > > virtballoon_quiesce() helper while the device is still alive, and only > > then breaks and resets it. The break and reset are repeated here rather > > than reused from virtio_dev_shutdown(): drv->shutdown replaces the > > generic handler rather than augmenting it, so that drivers such as > > virtio-gpu can opt out of the reset. Unlike virtballoon_remove() the > > balloon workqueue is not destroyed, as shutdown does not free the > > device and cancel_work_sync() together with stop_update already prevent > > any further work from being queued. > > > > Fixes: 8bd2fa086a04 ("virtio: break and reset virtio devices on device_shutdown()") > > Signed-off-by: Denis V. Lunev > > --- > > drivers/virtio/virtio_balloon.c | 10 ++++++++++ > > 1 file changed, 10 insertions(+) > > > > diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c > > index 5b02d9191ac6..e35ada767b4b 100644 > > --- a/drivers/virtio/virtio_balloon.c > > +++ b/drivers/virtio/virtio_balloon.c > > @@ -1137,6 +1137,15 @@ static void virtballoon_remove(struct virtio_device *vdev) > > kfree(vb); > > } > > > > +static void virtballoon_shutdown(struct virtio_device *vdev) > > +{ > > + virtballoon_quiesce(vdev->priv); > > + > > + virtio_break_device(vdev); > > + virtio_synchronize_cbs(vdev); > > + vdev->config->reset(vdev); > > I guess it would be good if we wouldn't have to copy what the default handler > does, but could instead just have it in a reusable core function? > > > +} > > + > > -- > Cheers, > > David