Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6025328iog; Thu, 23 Jun 2022 09:48:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s7+2yQvtTIwlvKnIDce5aM5+Yh3kH2guTaDolZvnLcDDT2poJbmGA9SC4s3UatdSx++rpA X-Received: by 2002:a17:90b:1a81:b0:1ed:3c0:3abb with SMTP id ng1-20020a17090b1a8100b001ed03c03abbmr4880799pjb.5.1656002905813; Thu, 23 Jun 2022 09:48:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656002905; cv=none; d=google.com; s=arc-20160816; b=t3oriy1q4mclGSiYtx4OS0gDl+nOFZJR/tTptQ40UTleZH+okbXyi/xlme2cQLAXOu zwO27ot68rYIkk1k6/JAW5oNyUHqI9pOu+hmArsLB8S8EoAlFoC46TOvErLPgBSKfp+V JADgiHrgtxl+M9u/COrYCwt33g8DVp6TsohqeJr5sHNDT6tak2LPbypjmKYFCCMXczqM M2LAU4YpBeF4G7Pmd0ORq5xTjSEXFGNiZS0kn/7IqEcZAPW4gRAWf8xGMvCDaG8mVP7/ saKbq044WI5LW1Q6vh5oB67dZ4EOvy8z2LCjVTl+KgEGdYP0al0hE43SBHyS5lenMDS+ IlMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=p0H1iSQcDJbUvtJG+KGPPnxre+ECDIYiae0HlZqGFM8=; b=0nQOu8O+Arp9+lfem6mzoyloIYMnhG+HxP2ryH/gACT2Cu7gjveoGs1ocfNGD72GSK N3Zw+sNTXOIiEStHxMg35OwjHlDe+u9liirlY/d1U0+pp6X3WgWk8vN3Y1KeKCq4ARKD IZuEY0pctCaRaDCNmqK6WCvwtb0K5ysPmZKeOvriQYsJSpiOP8W24ze73Rc3p3c/9pSb Pvm3PVPSZqvnGy3EBmcogoqy1OOI1llHSNqK9qBnKTGBDFT0sB8IZ3UsUB+oR4wKH4Kn UeHd35BS1viey10VFfg17QC2rUPDI7Wzqwjm4sj8+QMxa5CIdscmKs2/KrXNl7dhib/v NN3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c7vkaHfM; 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 f13-20020a63f74d000000b003fd916fc798si8712923pgk.188.2022.06.23.09.48.13; Thu, 23 Jun 2022 09:48:25 -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=c7vkaHfM; 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 S232303AbiFWQIb (ORCPT + 99 others); Thu, 23 Jun 2022 12:08:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232031AbiFWQIS (ORCPT ); Thu, 23 Jun 2022 12:08:18 -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 299411AD8D for ; Thu, 23 Jun 2022 09:08:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656000484; 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=p0H1iSQcDJbUvtJG+KGPPnxre+ECDIYiae0HlZqGFM8=; b=c7vkaHfMflrS4yf016zcaR6mPPmSApupaLjfhzatVi0pfdgL7e2x38ZrJx+zQGXEeHr2Cb FCr0xVHWIUXok7wcKvGhwzZ0653kU+Hdpo8LDhtwYStQX7rBv53nsud+h8OHePbNCml7ey WloYAaebSa8hrp/N8pOWAb13eFiIZvI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-146-ePvZj1VdPKqa5ABW6Kv0RQ-1; Thu, 23 Jun 2022 12:08:00 -0400 X-MC-Unique: ePvZj1VdPKqa5ABW6Kv0RQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6590F8032ED; Thu, 23 Jun 2022 16:07:59 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 078392166B26; Thu, 23 Jun 2022 16:07:54 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: netdev@vger.kernel.org, Jason Wang , linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, "Michael S. Tsirkin" Cc: Parav Pandit , Christophe JAILLET , lulu@redhat.com, tanuj.kamde@amd.com, Si-Wei Liu , Piotr.Uminski@intel.com, habetsm.xilinx@gmail.com, gautam.dawar@amd.com, pabloc@xilinx.com, Zhu Lingshan , lvivier@redhat.com, Longpeng , dinang@xilinx.com, martinh@xilinx.com, martinpo@xilinx.com, Eli Cohen , ecree.xilinx@gmail.com, Wu Zongyong , Stefano Garzarella , Dan Carpenter , hanand@xilinx.com, Xie Yongji , Zhang Min Subject: [PATCH v6 3/4] vhost-vdpa: uAPI to suspend the device Date: Thu, 23 Jun 2022 18:07:37 +0200 Message-Id: <20220623160738.632852-4-eperezma@redhat.com> In-Reply-To: <20220623160738.632852-1-eperezma@redhat.com> References: <20220623160738.632852-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Spam-Status: No, score=-3.4 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 The ioctl adds support for suspending the device from userspace. This is a must before getting 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 a successful return of the ioctl call the device must not process more virtqueue descriptors. The device can answer to read or writes of config fields as if it were not suspended. In particular, writing to "queue_enable" with a value of 1 will not make the device start processing buffers of the virtqueue. Signed-off-by: Eugenio PĂ©rez --- drivers/vhost/vdpa.c | 19 +++++++++++++++++++ include/uapi/linux/vhost.h | 14 ++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 3d636e192061..7fa671ac4bdf 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -478,6 +478,22 @@ static long vhost_vdpa_get_vqs_count(struct vhost_vdpa *v, u32 __user *argp) return 0; } +/* After a successful return of ioctl the device must not process more + * virtqueue descriptors. The device can answer to read or writes of config + * fields as if it were not suspended. In particular, writing to "queue_enable" + * with a value of 1 will not make the device start processing buffers. + */ +static long vhost_vdpa_suspend(struct vhost_vdpa *v) +{ + struct vdpa_device *vdpa = v->vdpa; + const struct vdpa_config_ops *ops = vdpa->config; + + if (!ops->suspend) + return -EOPNOTSUPP; + + return ops->suspend(vdpa); +} + static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, void __user *argp) { @@ -654,6 +670,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, case VHOST_VDPA_GET_VQS_COUNT: r = vhost_vdpa_get_vqs_count(v, argp); break; + case VHOST_VDPA_SUSPEND: + r = vhost_vdpa_suspend(v); + break; default: r = vhost_dev_ioctl(&v->vdev, cmd, argp); if (r == -ENOIOCTLCMD) diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index cab645d4a645..6d9f45163155 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -171,4 +171,18 @@ #define VHOST_VDPA_SET_GROUP_ASID _IOW(VHOST_VIRTIO, 0x7C, \ struct vhost_vring_state) +/* Suspend or resume a device so it does not process virtqueue requests anymore + * + * After the return of ioctl with suspend != 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 suspend == 0, the device can continue + * processing buffers as long as typical conditions are met (vq is enabled, + * DRIVER_OK status bit is enabled, etc). + */ +#define VHOST_VDPA_SUSPEND _IOW(VHOST_VIRTIO, 0x7D, int) + #endif -- 2.31.1