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 D7ADB38AC85 for ; Tue, 23 Jun 2026 19:28:07 +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=1782242890; cv=none; b=famSTyOZB2GmL7or211hnXUg5pAzWA/xqNz3/aXx3RjoWdiGM5DYMH6N/qjoCa2ST5vezGfddKlt9Oa3zDrNCVHjPnm+J73L5IcgIDb6PmK5G5b4A1QXf+kHEoPopuBj45XtzW9CN0tmZWmcg34vM1oy7959ouLCUMkxvWrzufY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782242890; c=relaxed/simple; bh=D2ChaHDfvZmhwhjvRFMulLjrdG7KcK4kwhYUmtPbung=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=d9XYv/9pLsulRJS5USKUaYzoDZ/73R5Qy1V47DDs9/+B+XDegjWhxlaHUB2Z3y2btjpXclHrpcuEPLB54vu296PnVfyrhGshUpvDPi2jHfEIt1R1mF1ki3LD7vQG8ayA8LHJglQANzoqsdWddi0/+S6O4okJ4TpZQHSWaHxoYfk= 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=F2Mtr+CE; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=M+o7Z0hz; 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="F2Mtr+CE"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="M+o7Z0hz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782242886; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ufEo9/wdHySq3bUGk+mPJWG9M7FBYrnTov6P95M0vSw=; b=F2Mtr+CEuWVyTz9Biia+/jh/kzbgGJosmeBfmawW8E9Y3GfLkDnWdmlZfY6jyDbHa9/t3/ RqyLSR1mycBPVxkvcAkU+9pDUroOahUbeKsmagQbr+xCys06Q7APqWVmngAEYEd15oMR2G reWrEbMC162th6csUTT4VpXGklUcodM= 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-80-a-tw-EAYPOiGnjBpbEo9jQ-1; Tue, 23 Jun 2026 15:28:05 -0400 X-MC-Unique: a-tw-EAYPOiGnjBpbEo9jQ-1 X-Mimecast-MFC-AGG-ID: a-tw-EAYPOiGnjBpbEo9jQ_1782242884 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-46067399d5dso113807f8f.2 for ; Tue, 23 Jun 2026 12:28:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1782242884; x=1782847684; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=ufEo9/wdHySq3bUGk+mPJWG9M7FBYrnTov6P95M0vSw=; b=M+o7Z0hzw3QHuhbvctuU/18q0BJAVah4wMBW7wICZNiaFAHcbREr1Z/HFfXeBfMGtF 7Xuv1uJsJvyQYykFe9wDqLUucjB7am0J4/fxYfgmGna/1xSddr6ujGSNvrkzeGBCRGNi 5fdLoBSqC13kBCPAJ1BNd5qpqiBY5hazgP13phevvrgAL7eHpanSPCckRqIa6s1koUsq N+HwE/FsEa1bDEVaH4iWkBbqV/+lZW7iQvaWYVZM/oO4L9X7pDi3RUMYxEwefzboucJj DXmxnpp8hFwFsyIJrJqhZztzASk7PZtMlGapVvc2xM5bDpvJHTbKo/+w0ZwOHBt7pFL5 E+ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782242884; x=1782847684; h=in-reply-to:content-transfer-encoding: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=ufEo9/wdHySq3bUGk+mPJWG9M7FBYrnTov6P95M0vSw=; b=YqGrUNs9GdEB/ArJTNmuSjkP4tii5aGFKFKpBAd95/zDDvF4zNdkpEcmZcLUq8YY+p jaWwFx39RkrkwkdXXNOoe60O1BInSJgmM4+yK9LPoPQHMwXtlRwSI8zpLN8hhS7b9cOA PXVfvOaL13Hk48ZVY+rH0evPQKVGhR6sfcPSFiGZbnixm+pKgqZWwNjBsn+k0kHa3E4e nAl/4tAhzEvDVNi+tIYT3Vz6WWPY1iXfdo2A1syGHx9WoD18BDusgDO+/esmhP9+kgDM uO+ajf0GJWCbkdIKFg3Mh3gM0KRbrRk65gPVPNJWinZ/h4/PlpEHY5cm7G6X/IKY+AL6 /Lgw== X-Forwarded-Encrypted: i=1; AFNElJ9Q/lJpMt39m3Vt4eXJjNmYSqID2WcGxobeY/rbCgKO0Q6H80jeEAzCg/x1rZ61+S1TazbiWQO4Rhp2b8U=@vger.kernel.org X-Gm-Message-State: AOJu0YwTqv1Dse/Xl7dVSafWGrKRaOJdBo858d9bidiImNXIwjxA5naM e1I4Ygv4OqUGWIu/A2KUd02ePKlRFyXB0pStfYbWCrFryPhFiBo+WMBz9+upIlCmTjNxnuEIkV5 t53AvvotMeJneK8ZKLkSG7WLdTODXSXBOlBzo2UlcrfTq1/dfMrqesQLrFlrvQp4TDQ== X-Gm-Gg: AfdE7cmvYlSfuPFtZr1owTcIfG2jEVP7Hi5REoG/G09ZJvwquf/kox4lRmGOmoOsl3o yt8ByGRuKjQsIlbwaB25suouHrsmZHcuaxShRSjB23tPwE4MnpV4evDf7COIuhWv7H7PRAdH8N4 vYBXKEu8c6xBHlId0/3aTM3Am6uBY06FmkUMmmS0IhgMSWvV+xVY8UYawkISWmsTVVD0oigmdgN /Zy+Mbnlfn6ezauOt++J7m3MMFQkNzlkVAdDls2AyzzSNTtg1Q+SyheqWDfb4ov2od7yy00xf7o c11Exj/oVyLhdYT1kvOCJF0L26EKaxZrLD9HpytR/9qbLiYNxGHss9KCR/gqurrWlROWX+CWoiX TwIYpm6iqKVy0IrAL5vArK5NK8hwuiRY+ X-Received: by 2002:a05:600c:4ecc:b0:492:259d:567 with SMTP id 5b1f17b1804b1-4925b379aafmr69873655e9.23.1782242884240; Tue, 23 Jun 2026 12:28:04 -0700 (PDT) X-Received: by 2002:a05:600c:4ecc:b0:492:259d:567 with SMTP id 5b1f17b1804b1-4925b379aafmr69873285e9.23.1782242883768; Tue, 23 Jun 2026 12:28:03 -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-4923ff8a9e3sm424966045e9.14.2026.06.23.12.28.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2026 12:28:03 -0700 (PDT) Date: Tue, 23 Jun 2026 15:27:59 -0400 From: "Michael S. Tsirkin" To: "Denis V. Lunev" Cc: "David Hildenbrand (Arm)" , "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: <20260623152729-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> <33fba3a4-cebc-4f13-923a-31cb5753222b@virtuozzo.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=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <33fba3a4-cebc-4f13-923a-31cb5753222b@virtuozzo.com> On Tue, Jun 23, 2026 at 09:25:18PM +0200, Denis V. Lunev wrote: > On 6/22/26 16:38, David Hildenbrand (Arm) wrote: > > This email originated from an IP that might not be authorized by the domain it was sent from. > > Do not click links or open attachments unless it is an email you expected to receive. > > 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. > > > > 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(). > Good catch, will do., separate patch pls. > >> 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? > Ok. Sounds great. Will do. > > Thanks for review, >     Den