Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6973632rwb; Mon, 5 Dec 2022 22:17:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf4JxImwMb15xIQRyI8ZiKus0swGFaWOMR7QrN5jIOeHkLouIfVK40y597AWa3loylAxsxlH X-Received: by 2002:aa7:da10:0:b0:46c:43ff:6961 with SMTP id r16-20020aa7da10000000b0046c43ff6961mr13752551eds.14.1670307457575; Mon, 05 Dec 2022 22:17:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670307457; cv=none; d=google.com; s=arc-20160816; b=Mu/lWWrH2xKVcTuh9pNswDqpGHfPJe5zAYwbGrpcVXq1JWP9xEd6RnWbHl5CE6dH/j rwxIMfzcbfr4oykG9jAec8OJiMgw49LXgsAyHzvMRSmMbSegUtB1yR00LwPm8wlxCuw0 f1flxOHwN0050DbXq3hcog9x9FVQUp3UbAVabVMzzCYcRWSlJQOziAcAQrjLumH8NXXs wJp/bO7gtUFLoiOdJ2Y4+xY1e4h1POWQbooD4LihCSK+ygMtI50VoDUHkzc+D9PzxhKo dkpyrZPcPLVo6KhX4OjVTHtHv+sAWGW4FEd1wbwr0idFrBJTnr5xtFYS+w0EZWwAWVv2 TCiA== 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=dV8FFVi+ppXoSPI6BQOk097hk8tMgvc+UEl7bQteqcM=; b=xxGfzva5B46O9ggKJd3Nx897fYUjINLFy9EmZjNhghhkrmFHh/g9sgnOyw58beALVk 5EGDIS3FqVWQHZyGMSgA5rJN82l9gG0XO+QIdUcEASQpLRSPAA9xP46DYxCXX3D0AXpI wGtUvJMspFd7xk1OcMG17oNMbleNVwsadhJDbwiIGI1rSVxyirk8/5TbX80XI4oVh0JU skCHLMz6UqetXMZjig3O+oZfuZZeb4//G09ds3jZdnOFhfEkPcq7IVZRW91iGoLODZ5Q dcUT4whf6as7yoOf4DRisPTJUZwAdkrT0PbsrLXSCnKkBvfkwiXAGBdypD7MHJfUZR4c MzYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="m2gUfz2/"; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v18-20020a1709064e9200b007ae4ed41508si1656281eju.738.2022.12.05.22.17.19; Mon, 05 Dec 2022 22:17:37 -0800 (PST) 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=@intel.com header.s=Intel header.b="m2gUfz2/"; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230437AbiLFF7c (ORCPT + 79 others); Tue, 6 Dec 2022 00:59:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233637AbiLFF7H (ORCPT ); Tue, 6 Dec 2022 00:59:07 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BE7927140; Mon, 5 Dec 2022 21:59:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670306343; x=1701842343; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9CnQAmoATTPKUFpttCxBP0OKKTyZY2W0SyyLmyVLCtc=; b=m2gUfz2/TTX/k3a63KziwsFuG894D2E3LRLNIX28gQhFis6EtJAZi1aM 6aO1ymb0Yq8FX7w6cNLvGRjeaqLX/vfhRcloON+ESzVxOLisVMypHlXKO sTL0ZTHh9xjbaM5/iW7oLgveH9fRtRrUdpwKUhEsg6C4oWj/Rqn8r18pb D5bM13ypNjE7p4y9olRN6U5WxjD6wXVAlOVSYlMwwaD4I+mWK3B+SF6Ic imcCP31KqIN3GAUILzxGj/oigphWzn7vd7dkGxtyipq5+aenabJvp+2hl F/S8ow0HsPPy+YlAXF9cT5OSH9eHxVRndNjrSzzP7P8C6S9pIZTwa5AZo w==; X-IronPort-AV: E=McAfee;i="6500,9779,10552"; a="378706716" X-IronPort-AV: E=Sophos;i="5.96,220,1665471600"; d="scan'208";a="378706716" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Dec 2022 21:58:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10552"; a="648211408" X-IronPort-AV: E=Sophos;i="5.96,220,1665471600"; d="scan'208";a="648211408" Received: from leirao-pc.bj.intel.com ([10.238.156.101]) by fmsmga007.fm.intel.com with ESMTP; 05 Dec 2022 21:58:48 -0800 From: Lei Rao To: kbusch@kernel.org, axboe@fb.com, kch@nvidia.com, hch@lst.de, sagi@grimberg.me, alex.williamson@redhat.com, cohuck@redhat.com, jgg@ziepe.ca, yishaih@nvidia.com, shameerali.kolothum.thodi@huawei.com, kevin.tian@intel.com, mjrosato@linux.ibm.com, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, kvm@vger.kernel.org Cc: eddie.dong@intel.com, yadong.li@intel.com, yi.l.liu@intel.com, Konrad.wilk@oracle.com, stephen@eideticom.com, hang.yuan@intel.com, Lei Rao Subject: [RFC PATCH 4/5] nvme-vfio: check if the hardware supports live migration Date: Tue, 6 Dec 2022 13:58:15 +0800 Message-Id: <20221206055816.292304-5-lei.rao@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221206055816.292304-1-lei.rao@intel.com> References: <20221206055816.292304-1-lei.rao@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 NVMe device can extend the vendor-specific field in the identify controller data structure to indicate whether live migration is supported. This patch checks if the NVMe device supports live migration. Signed-off-by: Lei Rao Signed-off-by: Yadong Li Signed-off-by: Chaitanya Kulkarni Reviewed-by: Eddie Dong Reviewed-by: Hang Yuan --- drivers/vfio/pci/nvme/nvme.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/vfio/pci/nvme/nvme.c b/drivers/vfio/pci/nvme/nvme.c index 698e470a4e53..2ffc90ad556d 100644 --- a/drivers/vfio/pci/nvme/nvme.c +++ b/drivers/vfio/pci/nvme/nvme.c @@ -473,6 +473,36 @@ static void nvmevf_pci_close_device(struct vfio_device *core_vdev) vfio_pci_core_close_device(core_vdev); } +static bool nvmevf_check_migration(struct pci_dev *pdev) +{ + struct nvme_command c = { }; + struct nvme_id_ctrl *id; + u8 live_mig_support; + int ret; + + c.identify.opcode = nvme_admin_identify; + c.identify.cns = NVME_ID_CNS_CTRL; + + id = kmalloc(sizeof(struct nvme_id_ctrl), GFP_KERNEL); + if (!id) + return false; + + ret = nvme_submit_vf_cmd(pdev, &c, NULL, id, sizeof(struct nvme_id_ctrl)); + if (ret) { + dev_warn(&pdev->dev, "Get identify ctrl failed (ret=0x%x)\n", ret); + goto out; + } + + live_mig_support = id->vs[0]; + if (live_mig_support) { + kfree(id); + return true; + } +out: + kfree(id); + return false; +} + static const struct vfio_migration_ops nvmevf_pci_mig_ops = { .migration_set_state = nvmevf_pci_set_device_state, .migration_get_state = nvmevf_pci_get_device_state, @@ -489,6 +519,10 @@ static int nvmevf_migration_init_dev(struct vfio_device *core_vdev) if (!pdev->is_virtfn) return ret; + /* Get the identify controller data structure to check the live migration support */ + if (!nvmevf_check_migration(pdev)) + return ret; + nvmevf_dev->migrate_cap = 1; vf_id = pci_iov_vf_id(pdev); -- 2.34.1