Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp4081427ioo; Wed, 25 May 2022 14:34:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWroYRnAgvjtNtu+3v8PRbt9t8JrJ5RjEdZdtyLki7+4EJfFRjfJtVsEuN40jS63wYZK7H X-Received: by 2002:a62:8206:0:b0:518:3c6a:21ba with SMTP id w6-20020a628206000000b005183c6a21bamr34729576pfd.63.1653514470827; Wed, 25 May 2022 14:34:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653514470; cv=none; d=google.com; s=arc-20160816; b=L97Krm4C3UY8EnVjPnwjOLcaedO9N+fOifJ2COUhFfoF/cw6OL2o7Ty0/GOAJ4JUAE gF3RZt/qHH0ONyMBqHxxOH7WMt7YOBwqt8nA6kDaRym2cVl0TxNF3ZazKRXVoAwKJX12 9FrcOCe6AnW9pbR6pG0hLcac1cw5v6gL+zI07ABbQPSCCMYtfSabHpNxKT+A50B8N3Im 57Jtz+kLaNhWepJ8RISp+S4pMAGAGvp7JQv3JJOWxXipHj/XN98q43jvRdXb2J6kjuHJ AE4HabsTYIyt0clSmWEsv5M1s1scFA2Q7pW5YUwZ+7kkd3q6jpXijGunNyplVgzPcu3U zlTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Ys9N/aStuUczJG1d59vIuu5WRFG0fOE8qpuySSttVig=; b=RlCYhWZpkJ4kUugfIowfE4XFQlTRXs8zwVQhrXZZALUm0FbmrBCPJNHXNw+VAwh/h3 YLEzdbpLnCePjNJFsVZZqj4oZ2OjwJxvixV49bP2OmZUP36TeF534lwpCjRgBFSGkE1h Vg3ltkvRXvXSodMDfMf+EliCQDv+a33Yi2J2RkAYnKpfMJFuYhLYwDvkCvjCvprLhsx/ frFmSCkSYyzh/Q8tau+LAoCTm38PW0vUF1AKaZDKZvUVkbltz2egK9BUirHtd+jYIcXx Y5HjxnXzi52vmhELUzEE9/FtC1cwUurjQx6RK41htWOfVGQGyvk7LNzpyn1uoMiOnkK0 SJZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=C6yCOzrS; 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 bw13-20020a056a00408d00b00518724edb0bsi19560264pfb.229.2022.05.25.14.34.02; Wed, 25 May 2022 14:34:30 -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=C6yCOzrS; 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 S231562AbiEYHm4 (ORCPT + 99 others); Wed, 25 May 2022 03:42:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229693AbiEYHmx (ORCPT ); Wed, 25 May 2022 03:42:53 -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 9B63540A28 for ; Wed, 25 May 2022 00:42:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653464569; 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=Ys9N/aStuUczJG1d59vIuu5WRFG0fOE8qpuySSttVig=; b=C6yCOzrS/O5rMel2k59r+QyBYB6D3iJp6Msr6T0dcs2lDlAixTxTjH/e/eBem4lw93fdy5 oy++D2FREGpFsaLHZx7GlMuOJUERzsND2gjUNJyJJuyydg2IE1FyN1ADtlwB4tuXPR6CdN zfxLeY1W96k0bapLzC9S4Bp0gYSgpAk= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-612-BOyp51BLPRK0ks5jHN_lgQ-1; Wed, 25 May 2022 03:42:45 -0400 X-MC-Unique: BOyp51BLPRK0ks5jHN_lgQ-1 Received: by mail-qk1-f198.google.com with SMTP id o18-20020a05620a2a1200b006a0cc3d8463so15135084qkp.4 for ; Wed, 25 May 2022 00:42:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=Ys9N/aStuUczJG1d59vIuu5WRFG0fOE8qpuySSttVig=; b=ox4DGvLkC61bio86Fu1PXWCVrekcpoLhln33szoahZdHms8bS/6ps7sRE9dNi1U0dD mbzSYfeUaic0c2RmpqqQdHqaXSfmIoJkH0F+vGNZ7LYSAjLNOrj2abyLTT414nDV7H9a 39eClXz1JYSG3FvMw7DVUvTE+h6a03By4KtwGHxd9pzMfWQ8feQAYEY7KVUPbSpLCZK/ 00W0N4+J8kwbRhapT3eUcMZEuk42ZZpz1U6hnAHqTsZQ+ZHCMZYX/r8gjnKYW4+B9FtG e+ydo8Hs/wlEoboQvP+h/AkDzXVpdgirVYIMcUCxDOnaU/eY5fbZH0RcP6Vqi6elBAiL iCbw== X-Gm-Message-State: AOAM531RdY/xJeMOOAKmSPia5objr57KSf/sgMzoBB9ihcTLXM95uNok Uf4H15SN1y5yRE6qm69xIJujD0wXNXOMjUNJG1StSOqONhXuaEsXTxutxvcDV18+xR3sA/aHksM pa9Cbi3aIVZcAXxQstmAsbyzQ X-Received: by 2002:ac8:5813:0:b0:2fa:a441:ba8a with SMTP id g19-20020ac85813000000b002faa441ba8amr2204477qtg.162.1653464565023; Wed, 25 May 2022 00:42:45 -0700 (PDT) X-Received: by 2002:ac8:5813:0:b0:2fa:a441:ba8a with SMTP id g19-20020ac85813000000b002faa441ba8amr2204464qtg.162.1653464564785; Wed, 25 May 2022 00:42:44 -0700 (PDT) Received: from sgarzare-redhat (host-87-12-25-16.business.telecomitalia.it. [87.12.25.16]) by smtp.gmail.com with ESMTPSA id b14-20020ac84f0e000000b002f96db4519csm922248qte.37.2022.05.25.00.42.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 00:42:44 -0700 (PDT) Date: Wed, 25 May 2022 09:41:56 +0200 From: Stefano Garzarella To: Eugenio =?utf-8?B?UMOpcmV6?= Cc: netdev@vger.kernel.org, virtualization@lists.linux-foundation.org, Jason Wang , "Michael S. Tsirkin" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Parav Pandit , Zhang Min , hanand@xilinx.com, Zhu Lingshan , tanuj.kamde@amd.com, gautam.dawar@amd.com, Christophe JAILLET , Xie Yongji , dinang@xilinx.com, habetsm.xilinx@gmail.com, Eli Cohen , pabloc@xilinx.com, lvivier@redhat.com, Dan Carpenter , lulu@redhat.com, Wu Zongyong , ecree.xilinx@gmail.com, Piotr.Uminski@intel.com, martinpo@xilinx.com, Si-Wei Liu , Longpeng , martinh@xilinx.com Subject: Re: [PATCH v2 4/4] vdpa_sim: Implement stop vdpa op Message-ID: <20220525074156.rwyesinlzrza72cn@sgarzare-redhat> References: <20220524170610.2255608-1-eperezma@redhat.com> <20220524170610.2255608-5-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220524170610.2255608-5-eperezma@redhat.com> X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 Tue, May 24, 2022 at 07:06:10PM +0200, Eugenio P?rez wrote: >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 != 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 == 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?rez >--- > 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/vdpa_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 = 0; i < vdpasim->dev_attr.nas; i++) > vhost_iotlb_reset(&vdpasim->iommu[i]); > >+ vdpasim->running = true; > spin_unlock(&vdpasim->iommu_lock); > > vdpasim->features = 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 = vdpa_to_sim(vdpa); >+ int i; >+ >+ spin_lock(&vdpasim->lock); >+ vdpasim->running = !stop; >+ if (vdpasim->running) { >+ /* Check for missed buffers */ >+ for (i = 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 = vdpa_to_sim(vdpa); >@@ -694,6 +713,7 @@ static const struct vdpa_config_ops vdpasim_config_ops = { > .get_status = vdpasim_get_status, > .set_status = vdpasim_set_status, > .reset = vdpasim_reset, >+ .stop = vdpasim_stop, > .get_config_size = vdpasim_get_config_size, > .get_config = vdpasim_get_config, > .set_config = vdpasim_set_config, >@@ -726,6 +746,7 @@ static const struct vdpa_config_ops vdpasim_batch_config_ops = { > .get_status = vdpasim_get_status, > .set_status = vdpasim_set_status, > .reset = vdpasim_reset, >+ .stop = vdpasim_stop, > .get_config_size = vdpasim_get_config_size, > .get_config = vdpasim_get_config, > .set_config = vdpasim_set_config, >diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_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; >+ Not related to this series, but I think in vdpa_sim_blk.c we should implement something similar to what we already do in vdpa_sim_net.c and re-schedule the work after X requests handled, otherwise we risk never stopping if there are always requests to handle. Also for supporting multiple queues, that could be a problem, but for now we only support one, so there should be no problem. I have other patches to send for vdpa_sim_blk.c, so if you want I can do that in my series. Thanks, Stefano > for (i = 0; i < VDPASIM_BLK_VQ_NUM; i++) { > struct vdpasim_virtqueue *vq = &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.27.0 >