Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp542015rdb; Thu, 15 Feb 2024 07:49:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVzRGLbh8sshl+sSN/AUIEEJoFEyz+skmhla7kBpd73ETEYvhtFWH+lX0iBwWw3Dxm/USqdt/5Meq+DXynpA6HrBb3RRU66JurN04Y/Fg== X-Google-Smtp-Source: AGHT+IEKmnQuv3wQclCovqk0T+eHi78UjBc0cyKPefHHLA9N0S8QJ6L4aPARwasGv1XIRXGZ/JK6 X-Received: by 2002:a0c:8f0a:0:b0:686:8ffe:1278 with SMTP id z10-20020a0c8f0a000000b006868ffe1278mr1898175qvd.4.1708012166295; Thu, 15 Feb 2024 07:49:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708012166; cv=pass; d=google.com; s=arc-20160816; b=fTrDP+1f5YWcmc7r7qqUY1/vstHbNeTgahL9BRSNHh3cGuJ/5UbVpCkvx5UuXB47/b nAt4Of/rShZicAddv0efyzIYfQfIobJcmcKfJKuj40uOkytdGACb3QaHobUWe+pGOV1+ vsn6x6wxKMFAYSYknv5Ls2gsYgOE6zk2xAK2nY21wI3kPBWwjT4NdQQS90v+j8guCtra vRP5B/HAJIPDhiDldkDdwwGJhdaaTODKGJ+Di2PJ0d37QSh55RQ7ubq4c2qSCraIZ4+o 2YIS4ulecf7t1IINThGmJch54fHc0U6fckLPCS7T+xotk/EpZl31vJhMRhcgD17h22Ej btBA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=zgRj/r6jJKBOT9E5bjhJrMIbJaqPHZG5ug6maI133dw=; fh=5qB8/iwn3gSxV7NmK/QCUNjJXmbdvuVrlt+cWMMkQjQ=; b=ZRmWR4UvcwCoIY6Sv/zopFunsT4FeBbhtILn81GJUYti5Hs2/9IUTndBRKqJK6vNe8 x6MC4FdGFDOxMdGm2q26yQXiZwBGkrlCbeN+zhGsK6iYMl2lSAQBYu9KxD+uk1iznEgC 0WvQ3QuT99A8khC00Kpe8HcN1Y7rPy2p4QCvAUSaEv81XxAUk6eo0Rke28L7OyNQXiDK 8RpMTwRe8Cf2eBgyTd5RnsE0XJuxZW2BM3TlFJhGsnQzzc9QNzU78Is5655Z2AN7Ed4S qVq8P/+NrzY7gtDbqbhEmw1Dn6BMKZ/rNJFR7JShuZ6R8DapjQlcZ0JDrZH5coNpOmIJ kqOA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ATXPKSXU; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-67235-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67235-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 15-20020a0562140d4f00b0068f2dbe3675si87139qvr.347.2024.02.15.07.49.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 07:49:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67235-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ATXPKSXU; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-67235-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67235-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 04AAC1C23799 for ; Thu, 15 Feb 2024 15:49:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 899D01339B4; Thu, 15 Feb 2024 15:45:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ATXPKSXU" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 0FC2312C548 for ; Thu, 15 Feb 2024 15:45:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708011913; cv=none; b=F3QACcgSnazbku2ONuC5XR+sRnS7uzCIgEqs7RQ3tIKirfhHD3cmt3ljxMrwpxwOc/qAdEJBm+48eWuj2OHUcNGCIqvydtnTtcbPdJvYp93sodB+vmh2Pj/knCHfFQGIfLttJboJR8gr3GH19wBcEAlR637i9AZYI83mdl6Jjio= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708011913; c=relaxed/simple; bh=jGrsuTrQ50aMOx/Q4bJMab8iuOMogw82FMKiSbI60CE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=A4ow7AqHV5hbRBzM1IEhPYUNoQg1ZkWUFcAxA2cATehowijwsN+O8b5fkaS1YS9+wA/gLy8NmJRwiAy6WAclBoDR/pMyuypwWz8iYRwn6xOsuqxwwrsm0CoVIH4s+TW3REpDdwktKrgMOANljPKR5afdlsLXpxySW8UFyU1ePOg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=ATXPKSXU; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708011910; 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=zgRj/r6jJKBOT9E5bjhJrMIbJaqPHZG5ug6maI133dw=; b=ATXPKSXUfTE16I3RJlsVWrpayfFr/38J8GeR88Vvi+xk7rhLQ5noM1+NPOQK98fz3rnGix 4vvWCB3rn6sypRAezpwYGz7BmWHyUyECMY97nLR5+yiwmG13pcns1XCxWYe5Kc72qOxNi5 9+7vBRzPOJ9NqpRgur6eqgu9xutOTv4= Received: from mail-yw1-f197.google.com (mail-yw1-f197.google.com [209.85.128.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-217-q4hhKtxyNxu0aM8dTBttYQ-1; Thu, 15 Feb 2024 10:45:08 -0500 X-MC-Unique: q4hhKtxyNxu0aM8dTBttYQ-1 Received: by mail-yw1-f197.google.com with SMTP id 00721157ae682-607df0c12abso6998467b3.1 for ; Thu, 15 Feb 2024 07:45:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708011908; x=1708616708; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zgRj/r6jJKBOT9E5bjhJrMIbJaqPHZG5ug6maI133dw=; b=CBDWjgmO4thw5rCybyzwZzKYQUTJZMgmbujpWRWKDsMz1pK5pmittTfGTgNJuVkpT/ mS7uXYBvLjKyrWmHveN9x5DjA63353Tb2kZYvUAArzoxhoRWTf3IO2nyKZ1ghofZ5YqY BK0OS9T9mhJ8C23C3M6VTUEoQzjpJPJyWLG2Xq8+fjgT87AeOuvmob1+dqKE9sYivWes FMD2E5cl3RIFb1EqWnvbQbnL/qRzyKwZCWJaNBvWSifxXglP4+0YrHjuVtHGSHh0G4cz r2hMajdPBdKxndX2xXv4cjl4CV5rUpcpPhw9Irm+EnZosEC4gtuRzOHe3DFfOz9bqltr gHqg== X-Forwarded-Encrypted: i=1; AJvYcCW66jTflHYacA2fdiYSXXWVjMw+OHIoCqzmX4Wz11H7enq9F0N/W3+M5NM0Hyb0hnxH2gA6+/eQUGUx3jJsiR7RSz7Uebpx7r3sgqdE X-Gm-Message-State: AOJu0YwO+CRDh+p8ChP82lB8x/W3gBjEAdM8xhjQjccj31tZaNLO1hto 4GnhOwMXgltMaZRghqtvJLV/52Xygbgo+DSuY1q9YaOKLGkzlrzeY27K7GCyAcw20oJkoT0lFFI RPOL0W3qxsSpRT1n8cdSqYwY4GnV+joP9VlYmjWvh5DSsJO9JXryX27RCvlGiNRtUZdNVKhEMPB 4p+NyFEqMBtEVXf7dZ+JgbsTIjSZ02wBAfp158 X-Received: by 2002:a0d:e2d6:0:b0:5ff:fdd5:d368 with SMTP id l205-20020a0de2d6000000b005fffdd5d368mr1990520ywe.44.1708011908408; Thu, 15 Feb 2024 07:45:08 -0800 (PST) X-Received: by 2002:a0d:e2d6:0:b0:5ff:fdd5:d368 with SMTP id l205-20020a0de2d6000000b005fffdd5d368mr1990454ywe.44.1708011907148; Thu, 15 Feb 2024 07:45:07 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <1707758174-142161-1-git-send-email-steven.sistare@oracle.com> <1707758174-142161-4-git-send-email-steven.sistare@oracle.com> <996cfabf-c612-43c8-9e56-03fb58a1ebec@oracle.com> In-Reply-To: <996cfabf-c612-43c8-9e56-03fb58a1ebec@oracle.com> From: Eugenio Perez Martin Date: Thu, 15 Feb 2024 16:44:30 +0100 Message-ID: Subject: Re: [PATCH V2 3/3] vdpa_sim: flush workers on suspend To: Steven Sistare Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Si-Wei Liu , Xie Yongji , Stefano Garzarella Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Feb 14, 2024 at 8:52=E2=80=AFPM Steven Sistare wrote: > > On 2/14/2024 2:39 PM, Eugenio Perez Martin wrote: > > On Wed, Feb 14, 2024 at 6:50=E2=80=AFPM Steven Sistare > > wrote: > >> > >> On 2/13/2024 11:10 AM, Eugenio Perez Martin wrote: > >>> On Mon, Feb 12, 2024 at 6:16=E2=80=AFPM Steve Sistare wrote: > >>>> > >>>> Flush to guarantee no workers are running when suspend returns. > >>>> > >>>> Signed-off-by: Steve Sistare > >>>> --- > >>>> drivers/vdpa/vdpa_sim/vdpa_sim.c | 13 +++++++++++++ > >>>> 1 file changed, 13 insertions(+) > >>>> > >>>> diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_si= m/vdpa_sim.c > >>>> index be2925d0d283..a662b90357c3 100644 > >>>> --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c > >>>> +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c > >>>> @@ -74,6 +74,17 @@ static void vdpasim_worker_change_mm_sync(struct = vdpasim *vdpasim, > >>>> kthread_flush_work(work); > >>>> } > >>>> > >>>> +static void flush_work_fn(struct kthread_work *work) {} > >>>> + > >>>> +static void vdpasim_flush_work(struct vdpasim *vdpasim) > >>>> +{ > >>>> + struct kthread_work work; > >>>> + > >>>> + kthread_init_work(&work, flush_work_fn); > >>> > >>> If the work is already queued, doesn't it break the linked list > >>> because of the memset in kthread_init_work? > >> > >> work is a local variable. It completes before vdpasim_flush_work retu= rns, > >> thus is never already queued on entry to vdpasim_flush_work. > >> Am I missing your point? > > > > No, sorry, I was the one missing that. Thanks for explaining it :)! > > > > I'm not so used to the kthread queue, but why not calling > > kthread_flush_work on vdpasim->work directly? > > vdpasim->work is not the only work posted to vdpasim->worker; see > vdpasim_worker_change_mm_sync. Posting a new no-op work guarantees > they are all flushed. > But it is ok to have concurrent mm updates, isn't it? Moreover, they can be enqueued immediately after the kthread_flush_work already, as there is no lock protecting it. > - Steve > > >>>> + kthread_queue_work(vdpasim->worker, &work); > >>>> + kthread_flush_work(&work); > >>>> +} > >>>> + > >>>> static struct vdpasim *vdpa_to_sim(struct vdpa_device *vdpa) > >>>> { > >>>> return container_of(vdpa, struct vdpasim, vdpa); > >>>> @@ -511,6 +522,8 @@ static int vdpasim_suspend(struct vdpa_device *v= dpa) > >>>> vdpasim->running =3D false; > >>>> mutex_unlock(&vdpasim->mutex); > >>>> > >>>> + vdpasim_flush_work(vdpasim); > >>> > >>> Do we need to protect the case where vdpasim_kick_vq and > >>> vdpasim_suspend are called "at the same time"? Correct userland shoul= d > >>> not be doing it but buggy or mailious could be. Just calling > >>> vdpasim_flush_work with the mutex acquired would solve the issue, > >>> doesn't it? > >> > >> Good catch. I need to serialize access to vdpasim->running plus the w= orker queue > >> in these two functions. vdpasim_kick_vq currently takes no locks. In = case it is called > >> from non-task contexts, I should define a new spinlock to be acquired = in both functions. > >> > >> - Steve > >> > > >