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 E3CCD2AD20 for ; Sun, 15 Mar 2026 15:30:08 +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=1773588610; cv=none; b=J1xPRCc85oxX/Ckw/SXjkcuOMxh7wrjHdYAVl8dc5tz5B7BZydkzH+IHGVoWYG7UX4QNzYAmifsOIHUiePr5Ss7lTGNx08ieJKfrjaH0YeQNCxFm2yefhMPZAaisPzTv1UA9l60RBNJZwdc1TvXP2RFKLAGh0S7YO9nQTG9cHYY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773588610; c=relaxed/simple; bh=EyOiydOuPLuOTj6QEmQI4rH9HhV6xLu3F9vI8CesZBc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BY2K2fNmyx4ErjaGNgnYK3r7ObOkFbHmRDsY4hV6RLb2NGOIHzLcH0jCNuQJKnuOqJELCD1jjDrzk4qlLdwu+WRCLZ5PVptiYwvF2pGq7r9kdS/AWa2l/95HDQQwnQ/fCPUV9oBKuMhvHl91erTWKnSPu1umXa2rXrGpY8NUWc0= 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=K1G4N6rU; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=YKsHfQz0; 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="K1G4N6rU"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="YKsHfQz0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773588607; 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=iiiFUzJ9tbUShPW9dcm9hP1jmyIzZs8zb+I7tXGQA24=; b=K1G4N6rU6fpxOZFvHEaRiPyKZ9QKwNna7niLCreJU7AMomQyAgojzEcvPyUjC00BU+fvmX As4wdPFPqoF6tykcPGQUM3rT6NVviu9VEzDCCCayp7PPILQMPS3rSP7ttjyF3VxMNf9xar ZQ2PTIw8cW1ZFyqvxPFPQEJXAWVMBSA= 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-74-SS-jxGRHOge97d5Zxno-pQ-1; Sun, 15 Mar 2026 11:30:06 -0400 X-MC-Unique: SS-jxGRHOge97d5Zxno-pQ-1 X-Mimecast-MFC-AGG-ID: SS-jxGRHOge97d5Zxno-pQ_1773588605 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-48532df52c5so52200215e9.1 for ; Sun, 15 Mar 2026 08:30:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1773588605; x=1774193405; 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=iiiFUzJ9tbUShPW9dcm9hP1jmyIzZs8zb+I7tXGQA24=; b=YKsHfQz0CI5QO6HTqxyOYm0mClvGO1ddsO1mouRiYnHYhpfr9TG7e9tetUyYDYgTr7 kAq4liLggrtHPPaGlaHOswCoWeVTJ76UTNyWD7AlwKVmN1+ED5IMkOx1NUPDvIwVMM9u UE/EOT4/1evnZq6RXOMR6lwnqKCHPXDgI03R2yg+zaiGEbjwXldSAQL9sPOfElKsXR1W yxChtM2U7TTl3s+jYr6R7x1NFRlkD4ep6v568l10t0Er8+Kk6h1lqhNbkacjbPujQz6n /WOKfa3ZUIvZ69/CA4jCyYDEpO1scs+t4E47mA2Lg04Y65XjPAdevfmMM4h88JYd3Ydc wuEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773588605; x=1774193405; 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=iiiFUzJ9tbUShPW9dcm9hP1jmyIzZs8zb+I7tXGQA24=; b=GAnXH98C7kfYFIUeeDgoKOeVVimbglMgrXTPqfcSl6VW0lJeOHx/U0mUjTXt7krBld ODPIsGIlBK7FfzJo6ZuzZw0CQvk0ihaN/OsCDCuCIGNTvusvGRIbzrYuJQ7TzSlEJXzx y23p2xzoCeNEJ3NKXWs7xDLYtDU9gFD9GfTmX5BxMtKBN1YgtQFx++Nt7kDlNvG/STKx pOVFV6o/iDf5Ua+lOAOWKJNYyffix8tFzZXEESHpBqZjQrBKblzRC4+47EVySEnFy5MR Y3Ko4zZyRmOOctKnhWD1XehzPS5SmQEwUAxw1QTx7HA9B0unyfxHNec156z7vIbTxFuq sPzw== X-Forwarded-Encrypted: i=1; AJvYcCWHZZoeLaqpXnwqp/14z3P1Y0wrPyydJm60EiHwjGE0opnbqKDjWagSkf2baVXenip6X77k56pKMIcGhCQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxVqxYVkCNeRMi6BOY9fJzyydJfKX2O5v7G7BlKZ1Ixqt9Do/Hm i5MjwcsLWDU5A5k/llbMKFd5njTj5V6RtygWmfOM27lJUgXjAgBm6m1fij0nw4Bzhs7jtSEbcBC sazcXVjAXIIFPOOhzLn57Wm96PcBbUn6m/NBADuAjGncUSQK33nDOfVosjyDAQsG/dw== X-Gm-Gg: ATEYQzwPvdjeZ/kzKwskT487M7kHRyxuLMrbOHUF3JnlVmKrkoy4xJWlG0T7YGE17KG oLJu1kiZT+XQ2hi6umedHxwgFOXJTxO5vvxx9zaKhbyr3tBojry3KxLNt8R4Y1eE3r0Vo7ZzZXH 1sxT5QPGLhS8x2zgIbOyKlHV5WUnyoPpKKGumI1oHVd1Tb4THyTIfsdd5bU9dAs6kdhHYm1S/EZ R5rXMy1lQs7cY36naORkjYlzZ4pM1mZP3nLB1mTq+/FkyT15f23EiboQzbhMOLX6Z9c4irOTjVU KebFYbAf6ojey4jQGvIpwPp2RQwMtb4pBBzK47RIL90vYB4R9rwGkYiSBORdn+FairjFu1pWSxm EP905CMOaCmdLXA6c0sGCKPmFd1V1u2JdXuPoFPEKWGyvig== X-Received: by 2002:a05:600c:c162:b0:485:3fd1:992c with SMTP id 5b1f17b1804b1-485566d2fe7mr153624635e9.1.1773588605005; Sun, 15 Mar 2026 08:30:05 -0700 (PDT) X-Received: by 2002:a05:600c:c162:b0:485:3fd1:992c with SMTP id 5b1f17b1804b1-485566d2fe7mr153624055e9.1.1773588604468; Sun, 15 Mar 2026 08:30:04 -0700 (PDT) Received: from redhat.com (IGLD-80-230-79-166.inter.net.il. [80.230.79.166]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4854e67ea40sm301596055e9.7.2026.03.15.08.30.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Mar 2026 08:30:03 -0700 (PDT) Date: Sun, 15 Mar 2026 11:30:01 -0400 From: "Michael S. Tsirkin" To: Shengwen Cheng Cc: jasowang@redhat.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] virtio_ring: reject NULL recycle callback in reset/resize helpers Message-ID: <20260315112904-mutt-send-email-mst@kernel.org> References: <20260315152403.127645-1-shengwen1997.tw@gmail.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: <20260315152403.127645-1-shengwen1997.tw@gmail.com> On Sun, Mar 15, 2026 at 11:24:03PM +0800, Shengwen Cheng wrote: > virtqueue_reset() and virtqueue_resize() rely on the recycle callback > to release each detached unused buffer after disable_vq_and_reset(). > > As a defensive change, reject a NULL recycle callback explicitly to make > this requirement clear. Update virtqueue_disable_and_recycle() to warn > and return -EINVAL when @recycle is NULL, and update the descriptions > for virtqueue_reset() and virtqueue_resize() to document that @recycle > must not be %NULL. I see little point in this change, sorry. > --- > drivers/virtio/virtio_ring.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index 335692d41617..563cee634426 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -2698,6 +2698,9 @@ static int virtqueue_disable_and_recycle(struct virtqueue *_vq, > void *buf; > int err; > > + if (WARN_ON_ONCE(!recycle)) > + return -EINVAL; > + > if (!vq->we_own_ring) > return -EPERM; > > @@ -3311,7 +3314,7 @@ EXPORT_SYMBOL_GPL(vring_create_virtqueue_map); > * virtqueue_resize - resize the vring of vq > * @_vq: the struct virtqueue we're talking about. > * @num: new ring num > - * @recycle: callback to recycle unused buffers > + * @recycle: callback to recycle unused buffers, must not be %NULL > * @recycle_done: callback to be invoked when recycle for all unused buffers done > * > * When it is really necessary to create a new vring, it will set the current vq > @@ -3367,7 +3370,7 @@ EXPORT_SYMBOL_GPL(virtqueue_resize); > /** > * virtqueue_reset - detach and recycle all unused buffers > * @_vq: the struct virtqueue we're talking about. > - * @recycle: callback to recycle unused buffers > + * @recycle: callback to recycle unused buffers, must not be %NULL > * @recycle_done: callback to be invoked when recycle for all unused buffers done > * > * Caller must ensure we don't call this with other virtqueue operations > -- > 2.34.1