Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp232433iog; Tue, 28 Jun 2022 21:40:08 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sRQAayYzo0F1tYxWdL+KVidv5RenlqDFkvQ5ccIHKOkqr7Y9JZ0fCoQNlVQJASGMVK+pdr X-Received: by 2002:a17:907:2cc3:b0:722:e993:c420 with SMTP id hg3-20020a1709072cc300b00722e993c420mr1381344ejc.145.1656477608564; Tue, 28 Jun 2022 21:40:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656477608; cv=none; d=google.com; s=arc-20160816; b=n8mDVsqJ1ooG44Y6ZliDXlPSf235c4bSP9iTUdV9RjXLSW+x83Z1rBita/xQkzOXd7 qjLSjqIPLN+V65NbMUICMRXwlcmuh7T7ISQzGZP8w1ellzS5MZ4oxAyKhbUWv+OSn/JO lHS4NU2Zuv7duDlx6H1wDH7fsuiayVryshJcAs8ZdtCU8LmeuXaXVMkyl8/O9GV7vmJV Epa86NVYyizzSrNSffMYFyQMHeNxUnLfxmQphtC7Ah/+zOBc6fPF6xiMVd9/yY6um0zM erFQAl4WIEoPdZQCCTyK/O5zEC1VrnBZ2tzSMu8xILPd4kxqDc0kGCgxD0Fh5s0eaV3G TzNA== 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=2h8ccNqJU95HAa4G/EVV71yAZ0Ts5Xe8taofTuRNpD4=; b=E8Krf5rTya6BWTveN4evT+2KkryZQAVxS+mlZAub9sDQV4HNOiBqchn40rfm8KiSgE dkhdQDZFqOVfIk92H1F/JPF3fTRITQ20V8bPF1V1+5A5EC4m4d+B/APejbPGTYWX8PJ2 5hqDjN6P0AO6bjrOeuqKoY+zwzdELUUeD766P8bFoSfGcxjsMgyLJ91ewuBul/UxZpPj X8DgAWvL1lDChBVs+2PptjhzezD3dJJGZBhLG4gzWP26nviVUmLgk5wU2JjojB3o9PKM KUv/IvQ1d9Ncjsc2wb+DRRk/sKnQh8oe65bNz+lmBiBYeY5EfHQ7+WsXXKste0DZE3hg KoaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KuDIBN5y; 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 f22-20020a50fe16000000b004356a3f38aasi5038923edt.193.2022.06.28.21.39.43; Tue, 28 Jun 2022 21:40:08 -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=KuDIBN5y; 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 S231563AbiF2ESv (ORCPT + 99 others); Wed, 29 Jun 2022 00:18:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231491AbiF2ESp (ORCPT ); Wed, 29 Jun 2022 00:18:45 -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 ESMTP id 86CE215825 for ; Tue, 28 Jun 2022 21:18:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656476323; 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=2h8ccNqJU95HAa4G/EVV71yAZ0Ts5Xe8taofTuRNpD4=; b=KuDIBN5yCUclroqoOwQEEe+1GRPs7moeAaCagkOez2LA2HxlTdGBKRHEfTy97okg1TcutR u5dpZk3tZGnjDngPpj6jot48sihQtrDCPMtguaV4UmhJAkZG5Z3o7M/xaXBg8rGgESUa7O g9boLwJMdik1nl0s5YVAxdD7JaJp3ZI= 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-417-lNaEQU1aNAqdQNpB1hDVtw-1; Wed, 29 Jun 2022 00:18:41 -0400 X-MC-Unique: lNaEQU1aNAqdQNpB1hDVtw-1 Received: by mail-lf1-f69.google.com with SMTP id p36-20020a05651213a400b004779d806c13so7162038lfa.10 for ; Tue, 28 Jun 2022 21:18:41 -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=2h8ccNqJU95HAa4G/EVV71yAZ0Ts5Xe8taofTuRNpD4=; b=dspJQsbBTXmd8xwaqEGCmY6efUc8pmutueKfLT/kQeMpPp9aCE/QXxjZdsFVp5dwZn JXTaHULktpzKKhSST/eilz/TGZ641EaLDM+eqcFQ7yPll3yUjCtl2kwzOjxRBwIENX9T orxDadicTLEBzGnb8LC+kkw+qAcIpDDhSPP2ME2qPLk9Xbur7rIFdHrrsdo8tKuLgFj4 qbudKcZClce7uEsAr0koeXdW0jqWpbvmKO/HxG/zT3hR5wY6xrLLWMCjGMBCKjjQeUU9 DhSnAuqKuUJfOmRqh2VrRVlNL48i4UZ/N7POAMKn4EIHp50dPTvrohZpXVPdLIj9ceMv VDuQ== X-Gm-Message-State: AJIora9/KWw+lgJz4aBvNdIE0tgswbsdCbf20HwRB/sS8SUnSGRTXSp2 hCe09H9q15FRxNEa4RS39hSpU6hQ5dLRzcnkG8uTkQZveGKY7cL8QLdiDJdeiM/6ecS3Q+DbQda E9LZ93TeyLivSxH9HhF3XkfnFHi7+VHNCbYyISdyt X-Received: by 2002:a05:6512:158d:b0:47f:718c:28b5 with SMTP id bp13-20020a056512158d00b0047f718c28b5mr811923lfb.397.1656476318736; Tue, 28 Jun 2022 21:18:38 -0700 (PDT) X-Received: by 2002:a05:6512:158d:b0:47f:718c:28b5 with SMTP id bp13-20020a056512158d00b0047f718c28b5mr811892lfb.397.1656476318523; Tue, 28 Jun 2022 21:18:38 -0700 (PDT) MIME-Version: 1.0 References: <20220623160738.632852-1-eperezma@redhat.com> <20220623160738.632852-5-eperezma@redhat.com> In-Reply-To: <20220623160738.632852-5-eperezma@redhat.com> From: Jason Wang Date: Wed, 29 Jun 2022 12:18:27 +0800 Message-ID: Subject: Re: [PATCH v6 4/4] vdpa_sim: Implement suspend vdpa op To: =?UTF-8?Q?Eugenio_P=C3=A9rez?= Cc: netdev , linux-kernel , virtualization , kvm , "Michael S. Tsirkin" , Parav Pandit , Christophe JAILLET , Cindy Lu , "Kamde, Tanuj" , Si-Wei Liu , "Uminski, Piotr" , habetsm.xilinx@gmail.com, "Dawar, Gautam" , Pablo Cascon Katchadourian , Zhu Lingshan , Laurent Vivier , Longpeng , Dinan Gunawardena , Martin Petrus Hubertus Habets , Martin Porter , Eli Cohen , ecree.xilinx@gmail.com, Wu Zongyong , Stefano Garzarella , Dan Carpenter , Harpreet Singh Anand , Xie Yongji , Zhang Min Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3.2 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=unavailable 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 Fri, Jun 24, 2022 at 12:08 AM Eugenio P=C3=A9rez w= rote: > > Implement suspend operation for vdpa_sim devices, so vhost-vdpa will > offer that backend feature and userspace can effectively suspend 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). > > Reviewed-by: Stefano Garzarella > 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 0f2865899647..213883487f9b 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_suspend(struct vdpa_device *vdpa) > +{ > + struct vdpasim *vdpasim =3D vdpa_to_sim(vdpa); > + int i; > + > + spin_lock(&vdpasim->lock); > + vdpasim->running =3D false; > + if (vdpasim->running) { > + /* Check for missed buffers */ > + for (i =3D 0; i < vdpasim->dev_attr.nvqs; ++i) > + vdpasim_kick_vq(vdpa, i); This seems only valid if we allow resuming? Thanks > + > + } > + 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, > + .suspend =3D vdpasim_suspend, > .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, > + .suspend =3D vdpasim_suspend, > .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; > + > if (!(vdpasim->status & VIRTIO_CONFIG_S_DRIVER_OK)) > goto out; > > -- > 2.31.1 >