Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1306790ioo; Fri, 27 May 2022 06:09:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuPtomKhx3/17cWAAA0yfH5Aja9pdqCMqtSmvSUcqYkN1OV9hDkryNEvo35l2aVTTQeSUb X-Received: by 2002:a17:907:6d0c:b0:6fe:f835:ae54 with SMTP id sa12-20020a1709076d0c00b006fef835ae54mr20779710ejc.173.1653656981816; Fri, 27 May 2022 06:09:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653656981; cv=none; d=google.com; s=arc-20160816; b=UTyW4CI0G3Oab18PrRTPdHbdbu/q9gQbJCi68pfgV6i7yPoLPJacoUPHQUm/1CrnjM XeMRcuMFF9OrUvhe8r0BWv1Zhp6z2PXQpQnnCTMYk2pxpOIMK4PuEW1qTfxn4fqFMVPY 2M/TlnlBsphMZ4FR4RENkwg8ErLjgvV/HblcuG+N388/pmxO1JDsoRFhVu8JvmZRV5Rk +GzuJdXQB0tMiPn1Iw9xjZgtUyITOmvh37d5YSnTHhRoMSsV4RVKRWM8sUxaNSL6WbQu AgwGWYmplbPWIxrB4jXbm/y0fze2zzyERekE1kHv+aGKHiDmJ760uaOZ5TwjUYBLVV4n MlmA== 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=REW5eBj0k51HdxwQT5MIo/NGzv21C0HdYvY4KP3ZBC8=; b=Q93sGP7SmoNWSP9MozdVIRUr7B0H0f1Nz1AROi0NRE2LMbn9ZAfqj4oRa1G8yfk/6T Epg5hUfhqZipGH23hwwuK7dgtnWtIXNY8hrd+5xIvOALh2OvPANSa1i5XFVCaMhaS1J7 GLzNWjMGaSVfjwvmRMnJFYGAx/iJnhB4hvEKTSZFdA/0vbA5PqDZL4TpqsjQVWcg3NLg GXK2GuWRreM3+1tmqQdUjS483vvThvapSS0Emx1OmrWCyngUyomQB6o9+69BTDYpKe6o vBWEussfISK1yKudqIpgudsy8YiQeBx/stpD/9YG6fFUg2jBdPgX1jzg89cBkqpDB3Hk GtKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=O+AU9r87; 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 g2-20020a17090613c200b006fed9376070si1107149ejc.155.2022.05.27.06.08.56; Fri, 27 May 2022 06:09:41 -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=O+AU9r87; 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 S1343949AbiEZOZV (ORCPT + 99 others); Thu, 26 May 2022 10:25:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232670AbiEZOZT (ORCPT ); Thu, 26 May 2022 10:25:19 -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 9A1F5C5DB3 for ; Thu, 26 May 2022 07:25:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653575117; 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=REW5eBj0k51HdxwQT5MIo/NGzv21C0HdYvY4KP3ZBC8=; b=O+AU9r87Vr2L1aY61ozgGAeSt2f5VJspMoTgabqCMbaMGUnknB4LA1iu2B36GD112san0p 8JwTDaPmdziozLWv6WPKve4k3REtV40gtyrc1AzCNsW77QX2lS8li0fPgVIAZsAlBGvUBr a82RdgB/W8NfnafqLbQZP15GbXo8HGo= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-195-kluf1NFaNTmq6IPq8sNQaQ-1; Thu, 26 May 2022 10:25:16 -0400 X-MC-Unique: kluf1NFaNTmq6IPq8sNQaQ-1 Received: by mail-qt1-f200.google.com with SMTP id m6-20020ac866c6000000b002f52f9fb4edso1668226qtp.19 for ; Thu, 26 May 2022 07:25:16 -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=REW5eBj0k51HdxwQT5MIo/NGzv21C0HdYvY4KP3ZBC8=; b=ZmUAGfI5jAcueATg3QtFwmjpQc/c/7BOP5J2/LYSoFrcFeOCo/6CMb5AgI33hKIBC+ W6ENJsuM4rYEd0fEEM4B2uZIiXA2F4ZHFq8Rgtset8hXB/FCypCmAjz9naBxHig/o04P Cnbg9jGdpE77Q7vFsf5HX1d0AHxg0WJp9rZ0UG65MpDlaj1dZcKOKPugNpv2UrVUVc09 mO0m+dPhDPA1XDvaGGQiVYkffwlbSzL1mFpQbmIsv2doxmTl1WyrfH5nD+QFYpRruBIw 8HPFor6Ra8sn3aEvD27Qf5du+o+ToSu/XuJyOVk0OY4Pf640qQ0U06VhwxcBFptLv7yD +u9Q== X-Gm-Message-State: AOAM53139Qw/4gCkrH9NpfUVzZ/I+FCTlcK+haEBTwg0E2tosMxgAVPw OYZBJon6PDmemtSUpPsCjwwJ+V6X2QItTuaDiU+KTYlF3/QwAICXTLFglbawb68nFP1IS4j1iGy uX+n+zqJFjmDSvDJL8szQKCvu X-Received: by 2002:a05:6214:27cf:b0:462:6338:f19c with SMTP id ge15-20020a05621427cf00b004626338f19cmr7054555qvb.123.1653575115871; Thu, 26 May 2022 07:25:15 -0700 (PDT) X-Received: by 2002:a05:6214:27cf:b0:462:6338:f19c with SMTP id ge15-20020a05621427cf00b004626338f19cmr7054515qvb.123.1653575115597; Thu, 26 May 2022 07:25:15 -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 z20-20020a05622a061400b002f39b99f6a2sm1112748qta.60.2022.05.26.07.25.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 07:25:14 -0700 (PDT) Date: Thu, 26 May 2022 16:25:06 +0200 From: Stefano Garzarella To: Eugenio =?utf-8?B?UMOpcmV6?= Cc: "Michael S. Tsirkin" , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Jason Wang , netdev@vger.kernel.org, martinh@xilinx.com, martinpo@xilinx.com, lvivier@redhat.com, pabloc@xilinx.com, Parav Pandit , Eli Cohen , Dan Carpenter , Xie Yongji , Christophe JAILLET , Zhang Min , Wu Zongyong , lulu@redhat.com, Zhu Lingshan , Piotr.Uminski@intel.com, Si-Wei Liu , ecree.xilinx@gmail.com, gautam.dawar@amd.com, habetsm.xilinx@gmail.com, tanuj.kamde@amd.com, hanand@xilinx.com, dinang@xilinx.com, Longpeng Subject: Re: [PATCH v4 4/4] vdpa_sim: Implement stop vdpa op Message-ID: <20220526142506.4c2j2mguwu3ejg7i@sgarzare-redhat> References: <20220526124338.36247-1-eperezma@redhat.com> <20220526124338.36247-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: <20220526124338.36247-5-eperezma@redhat.com> 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 Thu, May 26, 2022 at 02:43:38PM +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). > >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(+) Reviewed-by: Stefano Garzarella > >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; >+ > 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.31.1 >