Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74B0FC6FD1F for ; Tue, 14 Mar 2023 05:32:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229636AbjCNFcl (ORCPT ); Tue, 14 Mar 2023 01:32:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229648AbjCNFci (ORCPT ); Tue, 14 Mar 2023 01:32:38 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7B0C6A2DF for ; Mon, 13 Mar 2023 22:31:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678771912; 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=jyUBoPolIWIdJ1iODF+bsaf4nIiYQ/NV9Gc2xnehBsk=; b=XMy8TV/0C8cGhfMaFvJBQYNiFKbh4tNqTEyyDitII74+my8KZPGEIRh1/zmvRH51GkxgmS qac0Fw2LXCN+pqvErgoAjN9REp5XTZLmf7OvrnsfFBKL4FZiQ1nMrAkS9+k8gJ7YkwLSMX kyjkcJpwQaTL9aR2xRwBqQjDQca8g3E= Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-359-w4ywiMpqOjO_zREOdEZ8aw-1; Tue, 14 Mar 2023 01:31:50 -0400 X-MC-Unique: w4ywiMpqOjO_zREOdEZ8aw-1 Received: by mail-ot1-f72.google.com with SMTP id cm26-20020a056830651a00b006983a82ef15so13504otb.18 for ; Mon, 13 Mar 2023 22:31:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678771909; 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=jyUBoPolIWIdJ1iODF+bsaf4nIiYQ/NV9Gc2xnehBsk=; b=hVaJpZlJRx9edP32P95LZ9NPHXaKQXwm1Ufh4VYNm2JdfsK62sIcRds6spf8Qkdd2v VSDIqELcdDZZiLPJTnx5Nm87zvju2kQjGgEwvuYuBE5rxFs8lnrHD/mlan71dvvTd1Ph M8IFHMdrVUwhu1H58UP+6yLyws5lMzwNmlbF9NNPA+jXKfS1uq5DCcMpQ+w38OfaJW0Z b7pigx46Ah393LPClAi30lI+McPU1omSvb/R3tzaUiiRDnezZpuRDzis2Ujcp1LnuAht YO1AQNLJRyTRCUAbCR/3DIi1mTCeB+1+2Z1IaDV/35c30xg8s2XaOAS49LJEMvKa6U6d PQaw== X-Gm-Message-State: AO0yUKVeXeStTW9flJiPEYWhT88dDUIdp/2tS8Oj751Rk3ENZor+wLeD /SITo3DveAsU8zw54+374wVtLpc6GmvJ+grcqwSg7wfgg4Hmfw40n3iO7ivPnBxotQYmaqHviwe yKge660sBs4IN0H1a6Uwbh0oG/z8lTE1euVKIEQoY X-Received: by 2002:a05:6870:1110:b0:17a:adbe:2ba4 with SMTP id 16-20020a056870111000b0017aadbe2ba4mr206960oaf.9.1678771909520; Mon, 13 Mar 2023 22:31:49 -0700 (PDT) X-Google-Smtp-Source: AK7set/6fO95dK426XWuh5jUuIFpmqvpj5E0M3mNetmj/iPdAKEwidMc3TkD2je67h5nibAYAxs+plvrkjI57ZStLJc= X-Received: by 2002:a05:6870:1110:b0:17a:adbe:2ba4 with SMTP id 16-20020a056870111000b0017aadbe2ba4mr206950oaf.9.1678771909283; Mon, 13 Mar 2023 22:31:49 -0700 (PDT) MIME-Version: 1.0 References: <20230302113421.174582-1-sgarzare@redhat.com> <20230302113421.174582-7-sgarzare@redhat.com> In-Reply-To: <20230302113421.174582-7-sgarzare@redhat.com> From: Jason Wang Date: Tue, 14 Mar 2023 13:31:38 +0800 Message-ID: Subject: Re: [PATCH v2 6/8] vdpa_sim: use kthread worker To: Stefano Garzarella Cc: virtualization@lists.linux-foundation.org, Andrey Zhadchenko , eperezma@redhat.com, netdev@vger.kernel.org, stefanha@redhat.com, linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 2, 2023 at 7:35=E2=80=AFPM Stefano Garzarella wrote: > > Let's use our own kthread to run device jobs. > This allows us more flexibility, especially we can attach the kthread > to the user address space when vDPA uses user's VA. > > Signed-off-by: Stefano Garzarella Acked-by: Jason Wang Thanks > --- > drivers/vdpa/vdpa_sim/vdpa_sim.h | 3 ++- > drivers/vdpa/vdpa_sim/vdpa_sim.c | 17 ++++++++++++----- > 2 files changed, 14 insertions(+), 6 deletions(-) > > diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdp= a_sim.h > index acee20faaf6a..ce83f9130a5d 100644 > --- a/drivers/vdpa/vdpa_sim/vdpa_sim.h > +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h > @@ -57,7 +57,8 @@ struct vdpasim_dev_attr { > struct vdpasim { > struct vdpa_device vdpa; > struct vdpasim_virtqueue *vqs; > - struct work_struct work; > + struct kthread_worker *worker; > + struct kthread_work work; > struct vdpasim_dev_attr dev_attr; > /* spinlock to synchronize virtqueue state */ > spinlock_t lock; > diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdp= a_sim.c > index a6ee830efc38..6feb29726c2a 100644 > --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c > +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c > @@ -11,8 +11,8 @@ > #include > #include > #include > +#include > #include > -#include > #include > #include > #include > @@ -116,7 +116,7 @@ static void vdpasim_do_reset(struct vdpasim *vdpasim) > static const struct vdpa_config_ops vdpasim_config_ops; > static const struct vdpa_config_ops vdpasim_batch_config_ops; > > -static void vdpasim_work_fn(struct work_struct *work) > +static void vdpasim_work_fn(struct kthread_work *work) > { > struct vdpasim *vdpasim =3D container_of(work, struct vdpasim, wo= rk); > > @@ -159,7 +159,13 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_at= tr *dev_attr, > > vdpasim =3D vdpa_to_sim(vdpa); > vdpasim->dev_attr =3D *dev_attr; > - INIT_WORK(&vdpasim->work, vdpasim_work_fn); > + > + kthread_init_work(&vdpasim->work, vdpasim_work_fn); > + vdpasim->worker =3D kthread_create_worker(0, "vDPA sim worker: %s= ", > + dev_attr->name); > + if (IS_ERR(vdpasim->worker)) > + goto err_iommu; > + > spin_lock_init(&vdpasim->lock); > spin_lock_init(&vdpasim->iommu_lock); > > @@ -212,7 +218,7 @@ EXPORT_SYMBOL_GPL(vdpasim_create); > > void vdpasim_schedule_work(struct vdpasim *vdpasim) > { > - schedule_work(&vdpasim->work); > + kthread_queue_work(vdpasim->worker, &vdpasim->work); > } > EXPORT_SYMBOL_GPL(vdpasim_schedule_work); > > @@ -612,7 +618,8 @@ static void vdpasim_free(struct vdpa_device *vdpa) > struct vdpasim *vdpasim =3D vdpa_to_sim(vdpa); > int i; > > - cancel_work_sync(&vdpasim->work); > + kthread_cancel_work_sync(&vdpasim->work); > + kthread_destroy_worker(vdpasim->worker); > > for (i =3D 0; i < vdpasim->dev_attr.nvqs; i++) { > vringh_kiov_cleanup(&vdpasim->vqs[i].out_iov); > -- > 2.39.2 >