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 DE1B9448CF8 for ; Thu, 23 Jul 2026 15:18:19 +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=1784819905; cv=none; b=qXZ2Php6tkrqEfwlJIBuuO1+gLBxKVAMZiyfxU3htsZIwzDgdVMoLjaN/0Q9KtdNHDvKDXO1+UMLgISP7Kt+jCCL+akJcqUWZ8GeIE5MAmvIitH+dJJiz+yMVcrR6HqV92fKRsPd+aG+q6Ru2/hwLakBPyqn1aCn1C9hcR0veJU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784819905; c=relaxed/simple; bh=rSe9HD907K8IRLWvdPwE7ouRnZKLSw9p6mExkMka2to=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QimQcmy4L6ML+aPk7o3BRYhbl4n0vWzYLRxl2/YCxd8WqEGa8t0JKOj/sVBw8MiYYSEdJD6dr/gKOsBD+pYXUS8/17+nK23whBYhS35uvDy+fP6FD9m0+0ECe9jqgsKJ3gamNVMk+vr9cdYCUO+OIdpm3spT9h3sr0PfMWj4004= 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=LzENcHB1; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=gkg1nX1Y; 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="LzENcHB1"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="gkg1nX1Y" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784819892; 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=9OUorP8L7Hv+mWbQVnXQe/Nap+PNXLSDh1VLwTpZtYE=; b=LzENcHB1cpLjBEdZ9cuFWNVyohdTFmqAa5uS1Qe12rANZDve9zhxVseFElVf7pXst9gXQl RDr2tHAWamFHBsAgkwbkUq6vtPq+yuMrpPPXY77n4VvCCFAdCwm3Rh7b0pUYOQIASf0a7H Vl8cTZaFt8CghHIzzF8VvfxLetY4OfA= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-448-M8y7zjDaOhiacaolrSNZ-A-1; Thu, 23 Jul 2026 11:18:11 -0400 X-MC-Unique: M8y7zjDaOhiacaolrSNZ-A-1 X-Mimecast-MFC-AGG-ID: M8y7zjDaOhiacaolrSNZ-A_1784819890 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-4629f312a67so630560f8f.2 for ; Thu, 23 Jul 2026 08:18:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1784819890; x=1785424690; 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=9OUorP8L7Hv+mWbQVnXQe/Nap+PNXLSDh1VLwTpZtYE=; b=gkg1nX1YT69VX0y5vDJvJlU5Ajwm54l9OrTPblcGsl7N/P5Q64J5ADGi3YYcK3keQd aPeOK8yxFJxjvp4sVV1AdSpW/VpQPV3d6YTctd6h4js2uObCoQBrJ0Dy8AnTOcm4EpIt kBe1hhAI+STkwIjJ5ccgisfMHwVaQrSjfcjqQYW1tNS0pXzOA4KJezqQ58RqlnqyizdX 4Z7tkrjKNXmU4DSWLeKHZ5G6jqViE5mJJhe/OwgYis7okSKb4tkzaNy2kaDTlk5uUu0J lOsYmjp12snxs/7ILSF6h8QKQxAuNtEUdsmbe2NCvnoPPneEd16TgzT1hCml928Yn41q ty3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784819890; x=1785424690; 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=9OUorP8L7Hv+mWbQVnXQe/Nap+PNXLSDh1VLwTpZtYE=; b=gnOdF6XMQiXNrjjFsjRNMuTuE6cLmvb2iawjzJph3/Gbwwl6BbTCN0t3QTtEkhK3Ql Bh/mRjKruuoOv8k1/8OjBlCJ/7nHPJofrgt2DmVD5y74CabCAYhvvkPDsWE6qDtGssja 7KUTZaE5TY6FYjy7mX0HRs5Cco5O25JoofgPg+mhEzFoZAP/oCA8xjoYrG52G5qhtAER zss2YrC0vRPbGbUoGu9p1ZY8BU1z6vMyr9h+HcLHalfKhh4wZX16EPh/zTsS+Llas5zZ VkaRXdwDt78rwcQVjhK+hoqwEv6cz2TjEQp2hnHJi0Lcyx+L74FaX4xfefbUlyz4Zgwy uIUw== X-Gm-Message-State: AOJu0YyIfUX85idPRLjPoaqaUfbchS/HS6As+AFQ80XuxVhh1IB5pTWA kOX/3xgh8jKC4XX4+8Z9wr0ospi5IQe4JpRpZgOisQeBQkdHEEy+Jkzod5aQcEWElWggfgxAHQ5 WGpmXrRuYiQk0uSJWgvvsTRgM1MDTWBwgmdt0xrfkUlVPr1TmiHMFmEenJfvfH6NICS4shHiNwQ == X-Gm-Gg: AR+sD13W0+qdj+GGm+HIl/AqEr9UbGm/AyTcRlETNIbwAtoD9OxXhRFwtwjhmjcSkA7 16mkuElsgn2RCiVu+5cxjbY/JNXOOLVDb+UGfRxZ9OYdYPv09hWT5RhBo27yqHhtVOMGJRfN6nD 1Q/lIne1Q1kj01FbIOG3dNFDMBUVZNlHNsk9nXxWnkB7II7ynfQH6Mvo1lfN17tcOfFfy8NFF34 jlTGPZjXTofbQmIpBmNGCWB7+Jrn9tpTtO5QCnVufWsro7SQ84nHwuqekMHeroxHf6CYClvM0e3 UCvufjUAe72+LOo9J+yYF5JaLrKe3JNMM+PX+J/h+o8EFGTqjI7ddd/pUPyXyS2TKhM5LYbxp8T bpiMb6gF8pUouUpTn4Lc5vA== X-Received: by 2002:a05:6000:4386:b0:474:13ac:a91b with SMTP id ffacd0b85a97d-47f8d7564edmr4641359f8f.32.1784819889714; Thu, 23 Jul 2026 08:18:09 -0700 (PDT) X-Received: by 2002:a05:6000:4386:b0:474:13ac:a91b with SMTP id ffacd0b85a97d-47f8d7564edmr4641303f8f.32.1784819889120; Thu, 23 Jul 2026 08:18:09 -0700 (PDT) Received: from redhat.com (IGLD-80-230-37-66.inter.net.il. [80.230.37.66]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f85bc62basm16346454f8f.13.2026.07.23.08.18.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2026 08:18:08 -0700 (PDT) Date: Thu, 23 Jul 2026 11:18:05 -0400 From: "Michael S. Tsirkin" To: Andrey Drobyshev Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, sgarzare@redhat.com, stefanha@redhat.com, dongli.zhang@oracle.com, maciej.szmigiero@oracle.com, bchaney@akamai.com, mark.kanda@oracle.com, ptikhomirov@virtuozzo.com, den@openvz.org Subject: Re: [PATCH v5 4/5] vhost: synchronize with RCU readers when freeing workers Message-ID: <20260723111557-mutt-send-email-mst@kernel.org> References: <20260720102241.371610-1-andrey.drobyshev@virtuozzo.com> <20260720102241.371610-5-andrey.drobyshev@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=us-ascii Content-Disposition: inline In-Reply-To: <20260720102241.371610-5-andrey.drobyshev@virtuozzo.com> On Mon, Jul 20, 2026 at 01:22:40PM +0300, Andrey Drobyshev wrote: > vhost_vq_work_queue() only holds the RCU read lock while it dereferences > vq->worker and queues work on it. vhost_workers_free() however clears > the vq->worker pointers and immediately frees the workers, without > waiting for a grace period. A caller that fetched the worker right > before the pointer was cleared can therefore still be queueing work on > it while it is freed. And even when the queueing itself wins the race, > the work is never run, so its VHOST_WORK_QUEUED bit stays set and all > future attempts to queue it are silently skipped. > > None of the current callers can actually hit this: net and scsi stop > their virtqueues before the workers are freed, and vsock unhashes the > device and does synchronize_rcu() of its own in vhost_vsock_dev_release() > before the workers go away. But the upcoming VHOST_RESET_OWNER support > in vhost-vsock keeps the device hashed while its workers are freed, so > the lockless send/cancel paths become able to race with the teardown. > > Fix this by clearing the vq->worker pointers, waiting for a grace > period, and then flushing the workers so any work the last readers > queued runs before the workers are freed. > Fixes: 228a27cf78af ("vhost: Allow worker switching while work is queueing") > Suggested-by: Stefano Garzarella > Signed-off-by: Andrey Drobyshev > --- > drivers/vhost/vhost.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > index 4c525b3e16ea..d6e235c25254 100644 > --- a/drivers/vhost/vhost.c > +++ b/drivers/vhost/vhost.c > @@ -729,6 +729,17 @@ static void vhost_workers_free(struct vhost_dev *dev) > > for (i = 0; i < dev->nvqs; i++) > rcu_assign_pointer(dev->vqs[i]->worker, NULL); > + > + /* > + * vhost_vq_work_queue() reads vq->worker under rcu_read_lock(), so a > + * reader that fetched a worker before we cleared the pointers above > + * may still be queueing work on it. Wait for those readers to > + * finish, then flush so any work they queued runs (clearing > + * VHOST_WORK_QUEUED) before the workers are freed. > + */ > + synchronize_rcu(); Any way not to add this for all devices that don't need it? Or preferably, even for vsock in absense of the new ioctl? > + vhost_dev_flush(dev); > + > /* > * Free the default worker we created and cleanup workers userspace > * created but couldn't clean up (it forgot or crashed). > -- > 2.47.1