Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3486197ioo; Wed, 25 May 2022 01:30:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+YTHCLTPsHr0WM8zucYqfdknMpTUzSUB6QHBb99WZlu6viLyyuyi0j6dZgQ57Ko2lFHLw X-Received: by 2002:a17:902:6b41:b0:15f:2c60:2459 with SMTP id g1-20020a1709026b4100b0015f2c602459mr31744994plt.41.1653467410571; Wed, 25 May 2022 01:30:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653467410; cv=none; d=google.com; s=arc-20160816; b=RjUoS3HuwfaWJruxsQKu+iE0kjetR24wAJ3YVDERjdyyzvptyw8500YXEz2GPes1KU ry3QD0KXZdopvBtionGtlhBxllhJDM6Ij+9eV90aXt71PcB2ER/OmYkhXaLheB+9wAjB 6qxkHsRJt4UCz0IZyNtA2nhhqcOnvOtTeS00+bjlrBivPnG7rkAnoFcU8luwam04Bg7H zxR7hKZHJXPtlspzE+l6VbP7GTOvKD9JaH+ZJtAeALamb8s37ub2IZxDXBwCDrPvn5y7 FDZuOoI+QxTS1p8hovBsAXDMocVnUn+c35H3uGkQp65mje85DNpfD/Ds4aVRLfck5/1e pcCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=L6n7+yQgn+nVFUYyJzAWXpzjroQrckSxh/1Ms4Uuyq4=; b=lBkb6Kf+gcvs1NoLQSg6LIUcUwNu63Z9TDclOS1aRwQZrLcJo7VBhEFQ7wR9z94ehf WCf4g3RkFbNnkhgwPgvC7ZbIjhbApc9D670HtBIW977MhupFBIcl1qsmr1mePK2gX6cf WOafEhAdGa46zlI7Am7FOpQUFJNzPJWXjerUyUejvaenqpZhlS8EvEpnKIxT2mC1of7d ck4CP3BSTiAazdfCiSXHXDV+E97E8/2C7NqW4eQGB2JG7jpPixL9APxUMs1P5dg0wwNx i11ruiOUZUjmylHCyG4Ua/SpDus0jgT+1dljLw3vFhZvC6m+w78mguZANWRrxxxf8LSw ot3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QogKXykY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d14-20020a63360e000000b003c5d8888cb4si14146752pga.831.2022.05.25.01.29.57; Wed, 25 May 2022 01:30:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QogKXykY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240516AbiEYCyg (ORCPT + 99 others); Tue, 24 May 2022 22:54:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241637AbiEYCyf (ORCPT ); Tue, 24 May 2022 22:54:35 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9284613FBC for ; Tue, 24 May 2022 19:54:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653447273; 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=L6n7+yQgn+nVFUYyJzAWXpzjroQrckSxh/1Ms4Uuyq4=; b=QogKXykY8GRczE+uIg9F2Dpya0T9W5csFPscnI+jfJfxi9Mpht4VM1lGesHeD9SItio9jh YJjUZ9A4fxt5aLwyaI85ddIpb7SEM8vXKxDOO7TKKTOIppNnoRdEQ1Ll0Bycj/nPcSqB3y 7pA2+gVnV33hG2+IC642QdHU1eRPLBo= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-362-fKFg8ftKMUC5DLvSFe7WVA-1; Tue, 24 May 2022 22:54:32 -0400 X-MC-Unique: fKFg8ftKMUC5DLvSFe7WVA-1 Received: by mail-lf1-f69.google.com with SMTP id u13-20020a05651206cd00b00477c7503103so8392076lff.15 for ; Tue, 24 May 2022 19:54:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=L6n7+yQgn+nVFUYyJzAWXpzjroQrckSxh/1Ms4Uuyq4=; b=Psr76bhbw/8esUn8S4/XWxldvaM5mEOibHC4dfMyPR6dPzkaN4h0A6JzYNlUBOedjK kg/S6SrOswVR9XQXW1MU4+2Gj8djWR1rvgJImNYv3Oq8kba59XxZsLMraNVWuzRsufpn lW7vDZBy6/C34KdwertH+XsSDpWxP27pP63Fng5hAp2xE99+wXp5uuGjZEU9uuU3bKer QjnKZLndKroFfIS84geokBM1BGHhFI2yhd680pBE4hsdPZOVw3OcQOfOKBYbEUt3+YZU SSFphsfYs9GmBKMQhrAyQLSdSh0atfrWVDaM1L98Dcii4JaAc5CiVGRlCCoE+QIljivW oCLw== X-Gm-Message-State: AOAM530rqiayk132wSgo20zXC5Ezv3cielDDtz9xwP3FzJjWxPQiBqDl nx26UJNsHWljpLo+k0efV9kzcjVZfXUpvHuX9RWDY/MqcGuw40H1B+r+PpxPQRgLmF2wEnCjITl sDN1mIP+3WqJXckPfC3QiIMg+/At5B5560/rDSzT3 X-Received: by 2002:a2e:1651:0:b0:253:d7ce:22df with SMTP id 17-20020a2e1651000000b00253d7ce22dfmr16348502ljw.315.1653447270769; Tue, 24 May 2022 19:54:30 -0700 (PDT) X-Received: by 2002:a2e:1651:0:b0:253:d7ce:22df with SMTP id 17-20020a2e1651000000b00253d7ce22dfmr16348477ljw.315.1653447270564; Tue, 24 May 2022 19:54:30 -0700 (PDT) MIME-Version: 1.0 References: <20220524170610.2255608-1-eperezma@redhat.com> <20220524170610.2255608-5-eperezma@redhat.com> In-Reply-To: <20220524170610.2255608-5-eperezma@redhat.com> From: Jason Wang Date: Wed, 25 May 2022 10:54:19 +0800 Message-ID: Subject: Re: [PATCH v2 4/4] vdpa_sim: Implement stop vdpa op To: =?UTF-8?Q?Eugenio_P=C3=A9rez?= Cc: netdev , virtualization , "Michael S. Tsirkin" , kvm , linux-kernel , Parav Pandit , Zhang Min , Harpreet Singh Anand , Zhu Lingshan , tanuj.kamde@amd.com, "Dawar, Gautam" , Christophe JAILLET , Xie Yongji , Dinan Gunawardena , habetsm.xilinx@gmail.com, Eli Cohen , Pablo Cascon Katchadourian , Laurent Vivier , Dan Carpenter , Cindy Lu , Wu Zongyong , ecree.xilinx@gmail.com, "Uminski, Piotr" , Martin Porter , Stefano Garzarella , Si-Wei Liu , Longpeng , Martin Petrus Hubertus Habets Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 25, 2022 at 1:06 AM Eugenio P=C3=A9rez wr= ote: > > Implement stop operation for vdpa_sim devices, so vhost-vdpa will offer > that backend feature and userspace can effectively stop the device. > > This is a must before get virtqueue indexes (base) for live migration, > since the device could modify them after userland gets them. There are > individual ways to perform that action for some devices > (VHOST_NET_SET_BACKEND, VHOST_VSOCK_SET_RUNNING, ...) but there was no > way to perform it for any vhost device (and, in particular, vhost-vdpa). > > After the return of ioctl with stop !=3D 0, the device MUST finish any > pending operations like in flight requests. It must also preserve all > the necessary state (the virtqueue vring base plus the possible device > specific states) that is required for restoring in the future. The > device must not change its configuration after that point. > > After the return of ioctl with stop =3D=3D 0, the device can continue > processing buffers as long as typical conditions are met (vq is enabled, > DRIVER_OK status bit is enabled, etc). > > In the future, we will provide features similar to > VHOST_USER_GET_INFLIGHT_FD so the device can save pending operations. > > Signed-off-by: Eugenio P=C3=A9rez > --- > drivers/vdpa/vdpa_sim/vdpa_sim.c | 21 +++++++++++++++++++++ > drivers/vdpa/vdpa_sim/vdpa_sim.h | 1 + > drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 3 +++ > drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 3 +++ > 4 files changed, 28 insertions(+) > > diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdp= a_sim.c > index 50d721072beb..0515cf314bed 100644 > --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c > +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c > @@ -107,6 +107,7 @@ static void vdpasim_do_reset(struct vdpasim *vdpasim) > for (i =3D 0; i < vdpasim->dev_attr.nas; i++) > vhost_iotlb_reset(&vdpasim->iommu[i]); > > + vdpasim->running =3D true; > spin_unlock(&vdpasim->iommu_lock); > > vdpasim->features =3D 0; > @@ -505,6 +506,24 @@ static int vdpasim_reset(struct vdpa_device *vdpa) > return 0; > } > > +static int vdpasim_stop(struct vdpa_device *vdpa, bool stop) > +{ > + struct vdpasim *vdpasim =3D vdpa_to_sim(vdpa); > + int i; > + > + spin_lock(&vdpasim->lock); > + vdpasim->running =3D !stop; > + if (vdpasim->running) { > + /* Check for missed buffers */ > + for (i =3D 0; i < vdpasim->dev_attr.nvqs; ++i) > + vdpasim_kick_vq(vdpa, i); > + > + } > + spin_unlock(&vdpasim->lock); > + > + return 0; > +} > + > static size_t vdpasim_get_config_size(struct vdpa_device *vdpa) > { > struct vdpasim *vdpasim =3D vdpa_to_sim(vdpa); > @@ -694,6 +713,7 @@ static const struct vdpa_config_ops vdpasim_config_op= s =3D { > .get_status =3D vdpasim_get_status, > .set_status =3D vdpasim_set_status, > .reset =3D vdpasim_reset, > + .stop =3D vdpasim_stop, > .get_config_size =3D vdpasim_get_config_size, > .get_config =3D vdpasim_get_config, > .set_config =3D vdpasim_set_config, > @@ -726,6 +746,7 @@ static const struct vdpa_config_ops vdpasim_batch_con= fig_ops =3D { > .get_status =3D vdpasim_get_status, > .set_status =3D vdpasim_set_status, > .reset =3D vdpasim_reset, > + .stop =3D vdpasim_stop, > .get_config_size =3D vdpasim_get_config_size, > .get_config =3D vdpasim_get_config, > .set_config =3D vdpasim_set_config, > diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdp= a_sim.h > index 622782e92239..061986f30911 100644 > --- a/drivers/vdpa/vdpa_sim/vdpa_sim.h > +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h > @@ -66,6 +66,7 @@ struct vdpasim { > u32 generation; > u64 features; > u32 groups; > + bool running; > /* spinlock to synchronize iommu table */ > spinlock_t iommu_lock; > }; > diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c b/drivers/vdpa/vdpa_sim= /vdpa_sim_blk.c > index 42d401d43911..bcdb1982c378 100644 > --- a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c > +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c > @@ -204,6 +204,9 @@ static void vdpasim_blk_work(struct work_struct *work= ) > if (!(vdpasim->status & VIRTIO_CONFIG_S_DRIVER_OK)) > goto out; > > + if (!vdpasim->running) > + goto out; > + > for (i =3D 0; i < VDPASIM_BLK_VQ_NUM; i++) { > struct vdpasim_virtqueue *vq =3D &vdpasim->vqs[i]; > > diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c b/drivers/vdpa/vdpa_sim= /vdpa_sim_net.c > index 5125976a4df8..886449e88502 100644 > --- a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c > +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c > @@ -154,6 +154,9 @@ static void vdpasim_net_work(struct work_struct *work= ) > > spin_lock(&vdpasim->lock); > > + if (!vdpasim->running) > + goto out; > + Do we need to check vdpasim->running in vdpasim_kick_vq()? Thanks > if (!(vdpasim->status & VIRTIO_CONFIG_S_DRIVER_OK)) > goto out; > > -- > 2.27.0 >