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 705AB37B41A for ; Wed, 8 Jul 2026 08:42:20 +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=1783500141; cv=none; b=HjBFl/obM1ZrxtqK9PbKxtDU5jcdVYaJtEi0zYToH38UdR0EJK4MXucUSNJQAN2Kwlg9oWwp3QzqQApx2oj9NcJaLGYk7awNzNtqYF2NtysAkncjyEb3kBBHR6szqCVyX3wGRV+60Ah16pVR9mRnxNhlT+4T70bPe4QN5SBrbao= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783500141; c=relaxed/simple; bh=LrhEbLSxsFCV2EGe3KsKnfpv2xsw+MjT3I3fHAkrdvA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Lut/IpSAVtvAtRGmB7Mi9U61zi8GL2ZgAZiZi0VCAdPC9UqzKyFi2c20f0Tm0bCblnmGwgKd6UVEFrxv86fSJXHi0wsrNCQwIO6OGjdjqVpi5Pjny+8+/zFSZhrOth92v1Rltie/Wk+wBfqYP4w0Y2489BcYxc5yptgyRetOg+0= 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=AFcKj6e6; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=PP6XE0uS; 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="AFcKj6e6"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="PP6XE0uS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783500139; 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=NmMU+EsZ9VD1RTQBTt6H2ulayInlrK2cv4kko1/OW2c=; b=AFcKj6e66j/Me2AwL9Auq6xfypM+rvLxMSBSns1ePe2oTlhPdTgcqERaXZc7cB1WY3IALi lfbX7H/un4Yg0sZjwNpF/MBKSNpW0yo6W2qDoiwLkhZbM5Rc6KC7tzINmb/OmdBsDNbu33 eplgXrlZs38Zy4dXtvgK1Xl7u07QDtY= 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-170-JHnuENqZOTSZ2oOarkIOyw-1; Wed, 08 Jul 2026 04:42:18 -0400 X-MC-Unique: JHnuENqZOTSZ2oOarkIOyw-1 X-Mimecast-MFC-AGG-ID: JHnuENqZOTSZ2oOarkIOyw_1783500137 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-493c619bb52so3277575e9.1 for ; Wed, 08 Jul 2026 01:42:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1783500137; x=1784104937; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=NmMU+EsZ9VD1RTQBTt6H2ulayInlrK2cv4kko1/OW2c=; b=PP6XE0uS/q+mwHpaZdDaZAMYUGsEOBcubXpEhtadcwEZA0IAjAJ3OMTbL7oI9Ikv2g MTNwer/MbDLVX/DkG1YIHgrcSedNbpnniT3uhqBmVCozLqKxNG+k+4vaRyUiJkqFaSg4 zPj7zqWB3EOcgHslpFeIfcsh0V6WTwhbDdye9mDzF+rkzf+YViu715kVAfn4rj6bA7rh 9CT4fhUozOiVkaYI/nsbNjt3p67YvDYMnlUZ8vqYLMMgeXZS20tJ52pTTKo8azy1moDt gqiaZswXG4m+DAj6MQ0bCmeSt09LvOkAfFBYfVVervrws5SAB4l2v5Jxp7Bo5xTeADjr LaVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783500137; x=1784104937; h=in-reply-to:content-disposition:content-type: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 :content-type; bh=NmMU+EsZ9VD1RTQBTt6H2ulayInlrK2cv4kko1/OW2c=; b=FYQNq0YsU0HXlx2Wj0jebey7/0Cz2/BTr3IvKJ0LWZndrcwKzR8cSTVdDUwbj8Inbe s3Nb2dcUGLOuSZfZFYlWrtt5TXMG6nmlOcoRafoi2SYH3ioCdJI6KvT6Uet06xzkc+DC OjOI+wmd9i6D0RhZYrRFK+Gl5deyE0dAIKAHqxINF4nKNX8haN7w5pIsy9ISAw4OYTNw RS8MFzIDdGrxMKJemNqC2sveMUpfncyPyAjiC5A3hsBiw/rp/EZ/sHcXHXUJGj/7x7wZ YOu7B70lUFobHfK5U6n4GbJxT2vBkdU478bF+52B+XfEWCOTxtCV0oidrqrmyWtzajWk eK+w== X-Gm-Message-State: AOJu0YypJkWgDzH73PWYUHO7qWpQoDF99VvyF8MbnSfjqmguwA/1gVCG C/761vE6qIxi5iJgipSbEfxPXlaySyzL/+NMn5FjbqAWbNzEe+xLfA7vi+Zq7DyXv48THvfdRRv CgEi4j2B3sUDgjYLiTOef/Xb9cBPAuHw5SyfduVgyzmFTMNkqzJcvcM3irlKJibSFzA== X-Gm-Gg: AfdE7cmWUTJJ/XLgqlMsJtey/hxV46yfe/ZGtYCLxNL0DzNz95zlQodGfay8QrbQIb4 D9/CDiOgE/M1GhTDmikLAWjArPMW7nbWJGDnj0gruVEAYUS2aXGUPANfG89u9G5G6FXG3lXZGxi W6rYGpp6TLzgitEY2xo/rLUR7yGZ5S0WV4wf3u8RKg/5Nzw75po8kNjemrAFeayll78VRl7EEuL VzxUGKaHNUvk5E2qeev6n9jwi/2KyDA9EXwcpWoCoB9Rtv141cwTn3CONVZa0eBMlghzKmg4RDH 0kdibTevJS2ZwU/LX58i9J18vyV01z1R+kaml2jgmSdfMQW2IzxaEz76Qw3s2NVYBj9focbNQkY GMmLX8dpKkQUzqMUsOz52nAL7bg0UsN2w X-Received: by 2002:a05:600c:630a:b0:493:c84c:2b57 with SMTP id 5b1f17b1804b1-493e686c848mr14560025e9.29.1783500136986; Wed, 08 Jul 2026 01:42:16 -0700 (PDT) X-Received: by 2002:a05:600c:630a:b0:493:c84c:2b57 with SMTP id 5b1f17b1804b1-493e686c848mr14559595e9.29.1783500136377; Wed, 08 Jul 2026 01:42:16 -0700 (PDT) Received: from redhat.com (IGLD-80-230-68-31.inter.net.il. [80.230.68.31]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47aa039af67sm47289710f8f.17.2026.07.08.01.42.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2026 01:42:15 -0700 (PDT) Date: Wed, 8 Jul 2026 04:42:13 -0400 From: "Michael S. Tsirkin" To: "David Hildenbrand (Arm)" Cc: linux-kernel@vger.kernel.org, Jason Wang , Xuan Zhuo , Eugenio =?iso-8859-1?Q?P=E9rez?= , Adam Litke , Rusty Russell , virtualization@lists.linux.dev Subject: Re: [PATCH v4] virtio_balloon: prime stats vq after virtio_device_ready() Message-ID: <20260708043903-mutt-send-email-mst@kernel.org> References: <135278ef075f563ca5b0f3a40e2afcfeb7454f99.1783457622.git.mst@redhat.com> <9e2c389b-ae96-40bb-8edd-5f8a68b571df@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: <9e2c389b-ae96-40bb-8edd-5f8a68b571df@kernel.org> On Wed, Jul 08, 2026 at 10:13:58AM +0200, David Hildenbrand (Arm) wrote: > On 7/7/26 23:00, Michael S. Tsirkin wrote: > > The virtio spec requires the driver not to kick the device before > > DRIVER_OK is set. init_vqs() primes the stats virtqueue with a buffer > > and kicks the device before virtio_device_ready() is called in > > virtballoon_probe(), violating this requirement. > > > > Further, if the device responds to the early kick by processing the > > buffer before DRIVER_OK, stats_request() fires and queues > > update_balloon_stats_work. Should probe then fail and free vb, the work > > runs against freed memory. > > > > To fix, move buffer setup to after DRIVER_OK. Be careful to > > disable update_balloon_stats_work while this is going on, > > to make sure it does not race with the setup. > > > > Testing: tested that stats still work after the change. > > > > Fixes: 9564e138b1f6 ("virtio: Add memory statistics reporting to the balloon driver (V4)") > > Reported-by: Sashiko:gemini-3.1-pro-preview > > Cc: David Hildenbrand > > Assisted-by: Claude:claude-sonnet-4-6 > > Signed-off-by: Michael S. Tsirkin > > > > --- > > v4: extract stats_update_and_send() helper; call get_buf() before > > updating stats buffer in stats_handle_request(). > > also ignore add bug failures (never trigger anyway) (reported by sashiko) > > v3: add disable_work comment and BUG_ON -> WARN_ON_ONCE (David Hildenbrand) > > v2: check that work enable/disable is balanced; explain how add_outbuf > > never fails in probe/restore > > drivers/virtio/virtio_balloon.c | 67 +++++++++++++++++++-------------- > > 1 file changed, 39 insertions(+), 28 deletions(-) > > > > diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c > > index 088b3a0e6ce6..4c4b9bea4356 100644 > > --- a/drivers/virtio/virtio_balloon.c > > +++ b/drivers/virtio/virtio_balloon.c > > @@ -417,6 +417,17 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb) > > return idx; > > } > > > > +static void stats_update_and_send(struct virtio_balloon *vb) > > +{ > > + struct scatterlist sg; > > + unsigned int num_stats; > > Could do > > const unsigned int num_stats = update_balloon_stats(vb); > Indeed, a bit nicer. Thanks. > LGTM. > > -- > Cheers, > > David