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 2B8E9316905 for ; Thu, 6 Aug 2026 13:35:41 +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=1786023348; cv=none; b=McQwS2hlaSKEO6U9M/Pak6HoCgKlJ9NiSsvVZ6BlRus3e1xe3iLVlQ0Zgi+pZgsA3HaoH0Spusbb4zoe0nNRYARwLm4GscXFtgXx8XXe8Db2yfTgFwysfaDIFdUNzBLEIy92jE463S4GCE1boMg8WfOD9nQ+XmZ3kuhvyo1DiR4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786023348; c=relaxed/simple; bh=ObD7bPWSxhbklQOHrMfvrjgdmbGQvAlacZ3UlKZDW7w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hqk/ejqLtkTBAT1CjMyNM9vtjESMJb9L9icp3DxasGL1exqnKxxSPMNIkP8gE/MWM6DV6a354yEqobvhiabNsc2BBVabYBzb9h+2mrCI7U+V+IL5A7bHbcnojXzRg4c5Unza9lDLDxNv/3g1nD3GC2J82NN9KLAeuXHpMGLDj2k= 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=ZDYb50vW; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=VBW2twy3; 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="ZDYb50vW"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="VBW2twy3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786023338; 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=rILtqoeBHE7LGqRbLxT9biwUTl88ABJkJnpfbIm4pB0=; b=ZDYb50vWu4hGH63pBR4ioUf7l/utb1YDqsIGk6KTKvWQp75JxZwcBuzR5g1DV6xXz5vnRk RLitIP+2HOMjFg1M/Mtsjv4BhlkhQiJKMnKgGYt+AB2+jGkOSdnssjSy1ofOxQct5JXf0I xKvsHDKYZ8nuaa1sCLVb2HX6E/hm280= 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-82-9yRecd8vO3ykRSrNBDZEeA-1; Thu, 06 Aug 2026 09:35:37 -0400 X-MC-Unique: 9yRecd8vO3ykRSrNBDZEeA-1 X-Mimecast-MFC-AGG-ID: 9yRecd8vO3ykRSrNBDZEeA_1786023336 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4957287363bso13091145e9.0 for ; Thu, 06 Aug 2026 06:35:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1786023336; x=1786628136; 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=rILtqoeBHE7LGqRbLxT9biwUTl88ABJkJnpfbIm4pB0=; b=VBW2twy3z5dXVYruSZh4BbeqeNLSBAiXJuC2aBrZQVbuHUAYn7T2RGG+RVhjNf0Brx UoFiXNpGoXbAxw+37uaBMv7SHD/RchK0VRAG5QuFgaXcCBlwonb/mzwizHqSCMRAMb0w pDzK/07n+oaizJvClFilz2SfjNgYetiteux2LuGg4hIMT71uARvLVFbJORk+qXKpX8rK tWJKhvE1l+Ixyu6xrDJ8tAKoLHNBknIMIEL9soFUBkYLXgewmEbm5SXomNDyzGQv0yUK W7LD9ZBPr6UzFgj0G3lA1ggsOn6sbDMVmmNOVQZllh6dQYj+CB4LkeVUp7nLmkoFvY+c bnVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786023336; x=1786628136; 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=rILtqoeBHE7LGqRbLxT9biwUTl88ABJkJnpfbIm4pB0=; b=eGsnZ+oY9+GlgTiFH/tdi2MNXAXQcMhukKCDuwuPH5Dy25+X00jkXORwjRwPNzLjU8 hAy2JIuIDzrLz4uUE4nWfj6IQGK0sdln6+kOwvwrtn/jj8VtmQqGdoKjAbSEojcQSrUt 9E51o3gIDGpixOf2MFTXIXmcAQfBfy9IlHsuLBuNKznXTr2xzDdfQZZMmXTH/ybSNYbz G1qALJ/QnjafYrK3LkUlPd4mS25XH+AsXOg+vRw6Sj8UoRirKaJWiy49xTWATXAiCdFX /tJ10/4GV8MLdRSIx7OtRx0s5ipOwuCEdgZuLHOTCMwO1EgbVFBoGNUrIdMO8MGuoI4Q 3f+Q== X-Gm-Message-State: AOJu0YyIEcahLdznA9/twncZ6TpMzwtaHk7+qectXnNIdLiwDSR7Lvv+ CSZTZFvRYoviYhhuDJEr3DnRG2fz0p2+H6MpzlprmEr5kHCOh8StFkPl38tnS6kTO5j1JviYSJL WKQNbYiOSXFiXzHIi1u0JUjEQTmNqeajsTNy6rdcfPkksBGFLTySHLTeMCudvvz7pJA== X-Gm-Gg: AR+sD11H9q6/hi++Md8u+lYVtOorLkOd5grCq+ZVVdfJjh0wn7p2grOOVpo+LTRECSc WVWjm6nowlvd/6AaaiuWgYiK7VtsLnWQqKV9YlxxooNVstCXXl/fIAapOtuzf/nGxRY91B6/Mc+ zmwBjk0OXy1LCmc8FeUAwm5zZNguH4nvirWXL3Ay1aPlQlhnjkh1FJOfQkXxDKq4mpxB6B5RpsW PxQXzqa82RhxJAqbSmyl4iQynONGilGwwtEMceBjD6tEuIfMW1+ZajTP71eEMnJwxmVpaUMRJzf yyweozpsCh5YAaaaESY3rylImbeCX6mO+NP1E3+TJzeN6n/xiXe+yir+wdYxTF80h/DC3sz3Lrh 4hdM= X-Received: by 2002:a05:600c:8485:b0:493:e974:41ac with SMTP id 5b1f17b1804b1-4994e7d646cmr224933935e9.16.1786023335691; Thu, 06 Aug 2026 06:35:35 -0700 (PDT) X-Received: by 2002:a05:600c:8485:b0:493:e974:41ac with SMTP id 5b1f17b1804b1-4994e7d646cmr224932915e9.16.1786023335225; Thu, 06 Aug 2026 06:35:35 -0700 (PDT) Received: from sgarzare-redhat ([5.77.117.129]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49954228a47sm95181535e9.12.2026.08.06.06.35.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2026 06:35:34 -0700 (PDT) Date: Thu, 6 Aug 2026 15:35:27 +0200 From: Stefano Garzarella To: Andrey Drobyshev Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, mst@redhat.com, stefanha@redhat.com, jasowangio@gmail.com, eperezma@redhat.com Subject: Re: [PATCH] vhost: clear vq->worker under vq->mutex when freeing workers Message-ID: References: <20260723153310.745855-1-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; format=flowed Content-Disposition: inline In-Reply-To: <20260723153310.745855-1-andrey.drobyshev@virtuozzo.com> On Thu, Jul 23, 2026 at 06:33:10PM +0300, Andrey Drobyshev wrote: >Every other update of vq->worker is done under vq->mutex - the worker >attach/swap ioctls and vhost_worker_killed(). vhost_workers_free() is >the sole exception: it clears vq->worker without holding the lock. mmm, vhost_dev_cleanup() updates vq->worker without the mutex too IIUC. > >The effect is harmless in practice, as this only happens while the >owning process (and thus the whole device) is dying, but the lockless >write is inconsistent with the rest of the code. Clear vq->worker under >vq->mutex, like everyone else, so that all writers of vq->worker follow >the same locking rule. > >This issue was found by Sashiko AI review. Can you share a link to the review? I don't know if it's common or not, but having the link in the commit or after --- will help the reviewers. > >Signed-off-by: Andrey Drobyshev >--- > drivers/vhost/vhost.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > >diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c >index 4c525b3e16ea..dbb6cb5eccea 100644 >--- a/drivers/vhost/vhost.c >+++ b/drivers/vhost/vhost.c >@@ -722,13 +722,19 @@ static void vhost_worker_destroy(struct vhost_dev *dev, > static void vhost_workers_free(struct vhost_dev *dev) > { > struct vhost_worker *worker; >+ struct vhost_virtqueue *vq; > unsigned long i; > > if (!dev->use_worker) > return; > >- for (i = 0; i < dev->nvqs; i++) >- rcu_assign_pointer(dev->vqs[i]->worker, NULL); >+ for (i = 0; i < dev->nvqs; i++) { >+ vq = dev->vqs[i]; >+ >+ mutex_lock(&vq->mutex); >+ rcu_assign_pointer(vq->worker, NULL); >+ mutex_unlock(&vq->mutex); >+ } Pre-existing, but IIUC vhost_workers_free() is called only by vhost_dev_cleanup() at the bottom, after a loop calls vhost_vq_reset() on each virtqueue (without the mutex) where we already set `vq->worker` to NULL, so IMO at this point it's already NULL, no? Thanks, Stefano > /* > * Free the default worker we created and cleanup workers userspace > * created but couldn't clean up (it forgot or crashed). >-- >2.47.1 >