From patchwork Mon Mar 20 09:23:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liulongfang X-Patchwork-Id: 72045 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1113077wrt; Mon, 20 Mar 2023 02:35:58 -0700 (PDT) X-Google-Smtp-Source: AK7set9lUyUXyEATqBAF6OfJDhXTcweb4v+M/X+8zmaFnv4IdNihpPTmcex8BzjsG6BNAaIHotU/ X-Received: by 2002:a05:6a21:3284:b0:cb:8d74:112e with SMTP id yt4-20020a056a21328400b000cb8d74112emr20317828pzb.45.1679304958277; Mon, 20 Mar 2023 02:35:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679304958; cv=none; d=google.com; s=arc-20160816; b=kgXVPttHM1n09dvRqnENS+XjHRa0P3RXJ3mQvc4q5w2hLsFxwUs/CU5HUjgljxG0gb IwP0CFEqUjyZxPMI4JhIBggVJArR+XFtxpkcvhMNVWYcJZivPRZtpQBXPv3Ghnmvm4jz 5IY0w36YKKC4eoJGQYcI+K2X4sSW9MxxjCN9pbFrvvZfNPwaNP1nPusrMutP7CKh0qrP z+ozxmneXX3yia5btndcvSh/FlOC8C49vYJuJxGba+O55Fs4CGZtYoN39d64Gw9zpwA2 lOJJjFzTiBW5rXgNptsi5+G6wwWt+qnM/fnQlqrAry1FUAhWtjAZWunNuvAMnyCNAghX d4tA== 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; bh=8+NtyFto6YTXMGoD1QCDh0OE44U6cbSOyvwFwqvdemk=; b=IMyRqOIl/dydKl2E1bW6JdTD8xB/p1MdvYMWHDU67DJKNuylRI3hz6+xveS73R36ct TxYwfVrMjDCH5R7rkjy/MNjDrzLTl+dflMfw+Qr9fZ/7/rdvmDJ/ZHR8tUedkJRpU5R0 oJS958/bR5SZI0hjREvkXU8uHzG/mb0e7/7v9guafo64OKtdH2RIIgq7Tux55sbGEJNE WV/lKzNL3/RyRzH6qheERkRE72zvkcuT+0KTEk3h9PVweokjrymSJW2+7ADiD4ooV2fS a1VrLvSibl0cqOxUlGkviLpmk2QacJkHKrsWzuRIX3TxWPaPPFyCLkdnKxkzPi6D/Oih vWlg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bn22-20020a056a00325600b005e176560a0dsi9671371pfb.307.2023.03.20.02.35.43; Mon, 20 Mar 2023 02:35:58 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231219AbjCTJZm (ORCPT + 99 others); Mon, 20 Mar 2023 05:25:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231222AbjCTJZO (ORCPT ); Mon, 20 Mar 2023 05:25:14 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A79281A646 for ; Mon, 20 Mar 2023 02:24:44 -0700 (PDT) Received: from kwepemm600005.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Pg8Rz2PMTzrVNl; Mon, 20 Mar 2023 17:23:43 +0800 (CST) Received: from huawei.com (10.50.163.32) by kwepemm600005.china.huawei.com (7.193.23.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Mon, 20 Mar 2023 17:24:41 +0800 From: Longfang Liu To: , , , CC: , , , Subject: [PATCH v9 1/5] vfio/migration: Add debugfs to live migration driver Date: Mon, 20 Mar 2023 17:23:34 +0800 Message-ID: <20230320092338.2889-2-liulongfang@huawei.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20230320092338.2889-1-liulongfang@huawei.com> References: <20230320092338.2889-1-liulongfang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600005.china.huawei.com (7.193.23.191) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760878875891883455?= X-GMAIL-MSGID: =?utf-8?q?1760878875891883455?= There are multiple devices, software and operational steps involved in the process of live migration. An error occurred on any node may cause the live migration operation to fail. This complex process makes it very difficult to locate and analyze the cause when the function fails. In order to quickly locate the cause of the problem when the live migration fails, I added a set of debugfs to the vfio live migration driver. +-------------------------------------------+ | | | | | QEMU | | | | | +---+----------------------------+----------+ | ^ | ^ | | | | | | | | v | v | +---------+--+ +---------+--+ |src vfio_dev| |dst vfio_dev| +--+---------+ +--+---------+ | ^ | ^ | | | | v | | | +-----------+----+ +-----------+----+ |src dev debugfs | |dst dev debugfs | +----------------+ +----------------+ The entire debugfs directory will be based on the definition of the CONFIG_DEBUG_FS macro. If this macro is not enabled, the interfaces in vfio.h will be empty definitions, and the creation and initialization of the debugfs directory will not be executed. vfio | +--- | +---migration | +--state | +--hisi_acc | +--attr | +--data | +--debug | +--- +---migration +--state +--hisi_acc +--attr +--data +--debug debugfs will create a public root directory "vfio" file. then create a dev_name() file for each live migration device. First, create a unified state acquisition file of "migration" in this device directory. Then, create a public live migration state lookup file "state" Finally, create a directory file based on the device type, and then create the device's own debugging files under this directory file. Here, HiSilicon accelerator creates three debug files: attr: used to obtain the attribute parameters of the current live migration device. data: used to get the live migration data of the current live migration device. debug: Used to debug the current live migration device through commands. The live migration function of the current device can be tested by operating the debug files, and the functional status of the equipment and software at each stage can be tested step by step without performing the complete live migration function. And after the live migration is performed, the migration device data of the live migration can be obtained through the debug files. Signed-off-by: Longfang Liu --- drivers/vfio/Makefile | 2 +- drivers/vfio/vfio.h | 14 +++++++ drivers/vfio/vfio_debugfs.c | 80 +++++++++++++++++++++++++++++++++++++ drivers/vfio/vfio_main.c | 5 +++ include/linux/vfio.h | 8 ++++ 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 drivers/vfio/vfio_debugfs.c diff --git a/drivers/vfio/Makefile b/drivers/vfio/Makefile index 70e7dcb302ef..1debcff31d30 100644 --- a/drivers/vfio/Makefile +++ b/drivers/vfio/Makefile @@ -7,7 +7,7 @@ vfio-y += vfio_main.o \ vfio-$(CONFIG_IOMMUFD) += iommufd.o vfio-$(CONFIG_VFIO_CONTAINER) += container.o vfio-$(CONFIG_VFIO_VIRQFD) += virqfd.o - +vfio-$(CONFIG_DEBUG_FS) += vfio_debugfs.o obj-$(CONFIG_VFIO_IOMMU_TYPE1) += vfio_iommu_type1.o obj-$(CONFIG_VFIO_IOMMU_SPAPR_TCE) += vfio_iommu_spapr_tce.o obj-$(CONFIG_VFIO_PCI) += pci/ diff --git a/drivers/vfio/vfio.h b/drivers/vfio/vfio.h index e9721d8424bc..8e5cafa6aa3a 100644 --- a/drivers/vfio/vfio.h +++ b/drivers/vfio/vfio.h @@ -258,4 +258,18 @@ static inline void vfio_device_put_kvm(struct vfio_device *device) } #endif +#ifdef CONFIG_DEBUG_FS +void vfio_debugfs_create_root(void); +void vfio_debugfs_remove_root(void); + +void vfio_device_debugfs_init(struct vfio_device *vdev); +void vfio_device_debugfs_exit(struct vfio_device *vdev); +#else +static inline void vfio_debugfs_create_root(void) { } +static inline void vfio_debugfs_remove_root(void) { } + +static inline void vfio_device_debugfs_init(struct vfio_device *vdev) { } +static inline void vfio_device_debugfs_exit(struct vfio_device *vdev) { } +#endif /* CONFIG_DEBUG_FS */ + #endif diff --git a/drivers/vfio/vfio_debugfs.c b/drivers/vfio/vfio_debugfs.c new file mode 100644 index 000000000000..f5b6bf2a1d48 --- /dev/null +++ b/drivers/vfio/vfio_debugfs.c @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2023, HiSilicon Ltd. + */ + +#include +#include +#include +#include +#include "vfio.h" + +static struct dentry *vfio_debugfs_root; + +static int vfio_device_state_read(struct seq_file *seq, void *data) +{ + struct device *vf_dev = seq->private; + struct vfio_device *vdev = container_of(vf_dev, struct vfio_device, device); + enum vfio_device_mig_state state; + int ret; + + ret = vdev->mig_ops->migration_get_state(vdev, &state); + if (ret) + return -EINVAL; + + switch (state) { + case VFIO_DEVICE_STATE_RUNNING: + seq_printf(seq, "%s\n", "RUNNING"); + break; + case VFIO_DEVICE_STATE_STOP_COPY: + seq_printf(seq, "%s\n", "STOP_COPY"); + break; + case VFIO_DEVICE_STATE_STOP: + seq_printf(seq, "%s\n", "STOP"); + break; + case VFIO_DEVICE_STATE_RESUMING: + seq_printf(seq, "%s\n", "RESUMING"); + break; + case VFIO_DEVICE_STATE_RUNNING_P2P: + seq_printf(seq, "%s\n", "RESUMING_P2P"); + break; + case VFIO_DEVICE_STATE_ERROR: + seq_printf(seq, "%s\n", "ERROR"); + break; + default: + seq_printf(seq, "%s\n", "Invalid"); + } + + return 0; +} + +void vfio_device_debugfs_init(struct vfio_device *vdev) +{ + struct dentry *vfio_dev_migration = NULL; + struct device *dev = &vdev->device; + + vdev->debug_root = debugfs_create_dir(dev_name(vdev->dev), vfio_debugfs_root); + vfio_dev_migration = debugfs_create_dir("migration", vdev->debug_root); + + debugfs_create_devm_seqfile(dev, "state", vfio_dev_migration, + vfio_device_state_read); +} +EXPORT_SYMBOL_GPL(vfio_device_debugfs_init); + +void vfio_device_debugfs_exit(struct vfio_device *vdev) +{ + debugfs_remove_recursive(vdev->debug_root); +} +EXPORT_SYMBOL_GPL(vfio_device_debugfs_exit); + +void vfio_debugfs_create_root(void) +{ + vfio_debugfs_root = debugfs_create_dir("vfio", NULL); +} + +void vfio_debugfs_remove_root(void) +{ + debugfs_remove_recursive(vfio_debugfs_root); + vfio_debugfs_root = NULL; +} + diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index 3a597e799918..09772fd3a396 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -1408,6 +1408,9 @@ static int __init vfio_init(void) } pr_info(DRIVER_DESC " version: " DRIVER_VERSION "\n"); + + vfio_debugfs_create_root(); + return 0; err_dev_class: @@ -1425,6 +1428,8 @@ static void __exit vfio_cleanup(void) vfio_virqfd_exit(); vfio_group_cleanup(); xa_destroy(&vfio_device_set_xa); + + vfio_debugfs_remove_root(); } module_init(vfio_init); diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 93134b023968..fa6b898ebb58 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -63,6 +63,14 @@ struct vfio_device { struct iommufd_ctx *iommufd_ictx; bool iommufd_attached; #endif + +#ifdef CONFIG_DEBUG_FS + /* + * debug_root is a static property of the vfio_device + * which must be set prior to registering the vfio_device. + */ + struct dentry *debug_root; +#endif }; /** From patchwork Mon Mar 20 09:23:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liulongfang X-Patchwork-Id: 72049 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1113788wrt; Mon, 20 Mar 2023 02:37:56 -0700 (PDT) X-Google-Smtp-Source: AK7set+RlneVP+ru4uFqa6+6yGnnZzz6sGnDHKTM1V5WK9Caz/WrflF+YK0/FoOOjfRjhvykrfIX X-Received: by 2002:a05:6a20:bb12:b0:da:24f5:ff25 with SMTP id fc18-20020a056a20bb1200b000da24f5ff25mr386675pzb.48.1679305076422; Mon, 20 Mar 2023 02:37:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679305076; cv=none; d=google.com; s=arc-20160816; b=XJJ4MgSJ9PcVblB5Sc9THuwqjk3hEs2oJIRCZlxyZYmv0YK49EjN2ALPG9exwYo/X7 SZcTC+ZNQEhJJizAmVd7u/HJOm27rTnj6mFKR4qVTY5f91xj+PJtPYJHcoBP6FB1pND7 Zj8bfqBJX9gd9R2Oy8TYoJfzEWyGhhOPhhd67biHp7oU1IPe8LW6Iqu8j3N+nz6WyVxK Hwh1xOMqFmUp4sPZ5D+OQtrOwesNDgZpe3m1hZL0c59USoLPHB4zZTxF5RZxstgKQzIZ AIPGyOfhTkLG/WonO/s47ncFsx5Nqkq7EoPvkQlCHzlcz/oJWejNQ6jk8KWUaQSjUseP AYjQ== 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; bh=36XFJD0n9X43UnKMuCNyotopW10jJT7imtId3pNlR4M=; b=CDbwv5fxB37z4YOSpVTyd4T0bWkcHm5rE2uofnrRVDlmvCZZgcEuuh1ML1ps8yssq5 b7p/AmWCXMAH3kN4mpSVCqB6C8NcSvdozKBbIy0RqonxOq1hg9HYqNK2/DxlLDd+LvUb +aCzZcUwziIjJjnD0uU6DhRYKmIZq1aCAZuBXcWfm7vM10ghfOcfxkUK30gZT+AsEpnp NjSADnAG80PMDPR01hnM44fNAnWI+R7YCdgw/Bw4P4SXGUrWaKAVsQK2/LfE0LcDmqxN 14Y9ecfEzSqNbDWRcU0aT3QBaGyAueLKLis6sghYuabahecmEmGcQhscw1o64kvP/K6x WMCQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s16-20020a656910000000b004fc2396c157si10107134pgq.61.2023.03.20.02.37.41; Mon, 20 Mar 2023 02:37:56 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231350AbjCTJ0P (ORCPT + 99 others); Mon, 20 Mar 2023 05:26:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231372AbjCTJZo (ORCPT ); Mon, 20 Mar 2023 05:25:44 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75E601206B for ; Mon, 20 Mar 2023 02:25:15 -0700 (PDT) Received: from kwepemm600005.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Pg8SZ1K0vzrVP5; Mon, 20 Mar 2023 17:24:14 +0800 (CST) Received: from huawei.com (10.50.163.32) by kwepemm600005.china.huawei.com (7.193.23.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Mon, 20 Mar 2023 17:25:12 +0800 From: Longfang Liu To: , , , CC: , , , Subject: [PATCH v9 2/5] hisi_acc_vfio_pci: extract public functions for container_of Date: Mon, 20 Mar 2023 17:23:35 +0800 Message-ID: <20230320092338.2889-3-liulongfang@huawei.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20230320092338.2889-1-liulongfang@huawei.com> References: <20230320092338.2889-1-liulongfang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600005.china.huawei.com (7.193.23.191) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760878999994265263?= X-GMAIL-MSGID: =?utf-8?q?1760878999994265263?= In the current driver, vdev is obtained from struct hisi_acc_vf_core_device through the container_of function. This method is used in many places in the driver. In order to reduce this repetitive operation, I extracted a public function to replace it. Signed-off-by: Longfang Liu Reviewed-by: Jason Gunthorpe --- .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c index a117eaf21c14..a1589947e721 100644 --- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c @@ -630,6 +630,12 @@ static void hisi_acc_vf_disable_fds(struct hisi_acc_vf_core_device *hisi_acc_vde } } +static struct hisi_acc_vf_core_device *hisi_acc_get_vf_dev(struct vfio_device *vdev) +{ + return container_of(vdev, struct hisi_acc_vf_core_device, + core_device.vdev); +} + /* * This function is called in all state_mutex unlock cases to * handle a 'deferred_reset' if exists. @@ -1042,8 +1048,7 @@ static struct file * hisi_acc_vfio_pci_set_device_state(struct vfio_device *vdev, enum vfio_device_mig_state new_state) { - struct hisi_acc_vf_core_device *hisi_acc_vdev = container_of(vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(vdev); enum vfio_device_mig_state next_state; struct file *res = NULL; int ret; @@ -1084,8 +1089,7 @@ static int hisi_acc_vfio_pci_get_device_state(struct vfio_device *vdev, enum vfio_device_mig_state *curr_state) { - struct hisi_acc_vf_core_device *hisi_acc_vdev = container_of(vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(vdev); mutex_lock(&hisi_acc_vdev->state_mutex); *curr_state = hisi_acc_vdev->mig_state; @@ -1301,8 +1305,7 @@ static long hisi_acc_vfio_pci_ioctl(struct vfio_device *core_vdev, unsigned int static int hisi_acc_vfio_pci_open_device(struct vfio_device *core_vdev) { - struct hisi_acc_vf_core_device *hisi_acc_vdev = container_of(core_vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(core_vdev); struct vfio_pci_core_device *vdev = &hisi_acc_vdev->core_device; int ret; @@ -1325,8 +1328,7 @@ static int hisi_acc_vfio_pci_open_device(struct vfio_device *core_vdev) static void hisi_acc_vfio_pci_close_device(struct vfio_device *core_vdev) { - struct hisi_acc_vf_core_device *hisi_acc_vdev = container_of(core_vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(core_vdev); struct hisi_qm *vf_qm = &hisi_acc_vdev->vf_qm; iounmap(vf_qm->io_base); @@ -1341,8 +1343,7 @@ static const struct vfio_migration_ops hisi_acc_vfio_pci_migrn_state_ops = { static int hisi_acc_vfio_pci_migrn_init_dev(struct vfio_device *core_vdev) { - struct hisi_acc_vf_core_device *hisi_acc_vdev = container_of(core_vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(core_vdev); struct pci_dev *pdev = to_pci_dev(core_vdev->dev); struct hisi_qm *pf_qm = hisi_acc_get_pf_qm(pdev); From patchwork Mon Mar 20 09:23:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liulongfang X-Patchwork-Id: 72050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1114015wrt; Mon, 20 Mar 2023 02:38:32 -0700 (PDT) X-Google-Smtp-Source: AK7set9axT1djs15BHeukP4VXgIsTO8INk6t4JZI0d7A+6c66uhG7DaqNhHZRfD3X3Z0j9JFjQ1d X-Received: by 2002:a17:90a:1910:b0:23f:2757:ce99 with SMTP id 16-20020a17090a191000b0023f2757ce99mr15635854pjg.49.1679305112730; Mon, 20 Mar 2023 02:38:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679305112; cv=none; d=google.com; s=arc-20160816; b=GbpCzAY2dmiIbTAaMmFb7twk3CVdM/TtJkM/hbvMBrnqiSo1W6+UCk/kOA3qmq6qpg scEKWy+LvEjwUQ7N8wfYstP8Ybwm5/c0o9z9q1c6RllC9Ebfz2BH7mWQdDa90586l1OH PjqC8VCZ2DunV9CT4qBUas7lpjAVWAEr9KVRLIPk0MwXu+yJ+WeIASFbEQmw2I/YyKGh wzcBnOio4X4jWo01KIwZftPN+2cUi22TZOPXVj3D9pFoc8QQ6h+whe8rT9SgJy3nYjcv DqRATVWxed73kB6HL5tyj9ssrb1xrvHS2hcpR7oiHf5n4PH22/IJagiG9/dl8atlB/hP SUpA== 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; bh=PVPhpx6Rd8odrXh4RHI3WmsYlnClZ7TeO1JgTZbBDk0=; b=1C7Es8Y3pBYeZzLIyk0oHbCbXVa0HAqSHNmzRR1g9hGtsiX5jnzqnBV52CZy+tVr0a d4sVsFVwLU+WquyntS19rhKabmVyiHT98eLZ23zGOkzhePLezRsdhy/DXZ26Y1m8hRGx Gih+tzozu6qt6mrIx+HOr71QsYlNpF4cUidOWecXLdOrAy0840q8RlltUIFqxvvaOoaB WGSC9rEN/0y1F6XliK/6WXEgxttqVlra7VsNzsVNb035w0fMsHmFNVGD/2DK6EMzeonj +HANAsuNMs1hQ6ywCC67ei9rZ6JVYx9fhA43Kk8N5/JEEgY7LZA5oB1/zJNmsy08It2U 6AoQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z1-20020a17090a7b8100b0023b4b4aa79dsi15177273pjc.143.2023.03.20.02.38.18; Mon, 20 Mar 2023 02:38:32 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229931AbjCTJ02 (ORCPT + 99 others); Mon, 20 Mar 2023 05:26:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230329AbjCTJ0E (ORCPT ); Mon, 20 Mar 2023 05:26:04 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8E0018163 for ; Mon, 20 Mar 2023 02:25:45 -0700 (PDT) Received: from kwepemm600005.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Pg8QP6NZSzSmbP; Mon, 20 Mar 2023 17:22:21 +0800 (CST) Received: from huawei.com (10.50.163.32) by kwepemm600005.china.huawei.com (7.193.23.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Mon, 20 Mar 2023 17:25:43 +0800 From: Longfang Liu To: , , , CC: , , , Subject: [PATCH v9 3/5] hisi_acc_vfio_pci: register debugfs for hisilicon migration driver Date: Mon, 20 Mar 2023 17:23:36 +0800 Message-ID: <20230320092338.2889-4-liulongfang@huawei.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20230320092338.2889-1-liulongfang@huawei.com> References: <20230320092338.2889-1-liulongfang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600005.china.huawei.com (7.193.23.191) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760879037729863111?= X-GMAIL-MSGID: =?utf-8?q?1760879037729863111?= On the debugfs framework of VFIO, if the CONFIG_DEBUG_FS macro is enabled, the debug function is registered for the live migration driver of the HiSilicon accelerator device. After registering the HiSilicon accelerator device on the debugfs framework of live migration of vfio, a directory file "hisi_acc" of debugfs is created, and then three debug function files are created in this directory: data file: used to get the migration data of the live migration device attr file: used to get device attributes of the live migration device debug file: used to test for acquiring and writing device state data for VF device. Signed-off-by: Longfang Liu --- .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 290 ++++++++++++++++++ .../vfio/pci/hisilicon/hisi_acc_vfio_pci.h | 11 + 2 files changed, 301 insertions(+) diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c index a1589947e721..22ebe0e8f90f 100644 --- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c @@ -15,6 +15,7 @@ #include #include "hisi_acc_vfio_pci.h" +#include "../../vfio.h" /* Return 0 on VM acc device ready, -ETIMEDOUT hardware timeout */ static int qm_wait_dev_not_ready(struct hisi_qm *qm) @@ -606,6 +607,18 @@ hisi_acc_check_int_state(struct hisi_acc_vf_core_device *hisi_acc_vdev) } } +static void hisi_acc_vf_migf_save(struct hisi_acc_vf_migration_file *src_migf, + struct hisi_acc_vf_migration_file *dst_migf) +{ + if (!dst_migf) + return; + + dst_migf->disabled = false; + dst_migf->total_length = src_migf->total_length; + memcpy(&dst_migf->vf_data, &src_migf->vf_data, + sizeof(struct acc_vf_data)); +} + static void hisi_acc_vf_disable_fd(struct hisi_acc_vf_migration_file *migf) { mutex_lock(&migf->lock); @@ -618,12 +631,16 @@ static void hisi_acc_vf_disable_fd(struct hisi_acc_vf_migration_file *migf) static void hisi_acc_vf_disable_fds(struct hisi_acc_vf_core_device *hisi_acc_vdev) { if (hisi_acc_vdev->resuming_migf) { + hisi_acc_vf_migf_save(hisi_acc_vdev->resuming_migf, + hisi_acc_vdev->debug_migf); hisi_acc_vf_disable_fd(hisi_acc_vdev->resuming_migf); fput(hisi_acc_vdev->resuming_migf->filp); hisi_acc_vdev->resuming_migf = NULL; } if (hisi_acc_vdev->saving_migf) { + hisi_acc_vf_migf_save(hisi_acc_vdev->saving_migf, + hisi_acc_vdev->debug_migf); hisi_acc_vf_disable_fd(hisi_acc_vdev->saving_migf); fput(hisi_acc_vdev->saving_migf->filp); hisi_acc_vdev->saving_migf = NULL; @@ -1303,6 +1320,273 @@ static long hisi_acc_vfio_pci_ioctl(struct vfio_device *core_vdev, unsigned int return vfio_pci_core_ioctl(core_vdev, cmd, arg); } +static int hisi_acc_vf_debug_io(struct vfio_device *vdev) +{ + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(vdev); + struct hisi_qm *vf_qm = &hisi_acc_vdev->vf_qm; + struct device *dev = vdev->dev; + u64 data; + int ret; + + ret = qm_wait_dev_not_ready(vf_qm); + if (ret) + dev_err(dev, "VF device not ready!\n"); + + data = readl(vf_qm->io_base + QM_MB_CMD_SEND_BASE); + dev_info(dev, "debug mailbox val: 0x%llx\n", data); + + return ret; +} + +static int hisi_acc_vf_debug_resume(struct vfio_device *vdev) +{ + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(vdev); + struct hisi_acc_vf_migration_file *migf = hisi_acc_vdev->debug_migf; + struct device *dev = vdev->dev; + int ret; + + ret = vf_qm_state_save(hisi_acc_vdev, migf); + if (ret) { + dev_err(dev, "failed to save device data!\n"); + return -EINVAL; + } + + ret = vf_qm_check_match(hisi_acc_vdev, migf); + if (ret) { + dev_err(dev, "failed to match the VF!\n"); + return -EINVAL; + } + + ret = vf_qm_load_data(hisi_acc_vdev, migf); + if (ret) { + dev_err(dev, "failed to recover the VF!\n"); + return -EINVAL; + } + + vf_qm_fun_reset(&hisi_acc_vdev->vf_qm); + dev_info(dev, "successful to resume device data!\n"); + + return 0; +} + +static int hisi_acc_vf_debug_save(struct vfio_device *vdev) +{ + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(vdev); + struct hisi_acc_vf_migration_file *migf = hisi_acc_vdev->debug_migf; + struct device *dev = vdev->dev; + int ret; + + ret = vf_qm_state_save(hisi_acc_vdev, migf); + if (ret) { + dev_err(dev, "failed to save device data!\n"); + return -EINVAL; + } + dev_info(dev, "successful to save device data!\n"); + + return 0; +} + +static int +hisi_acc_vf_debug_operate(struct vfio_device *vdev, unsigned int cmd) +{ + int ret; + + switch (cmd) { + case STATE_SAVE: + ret = hisi_acc_vf_debug_save(vdev); + if (ret) + return ret; + break; + case STATE_RESUME: + ret = hisi_acc_vf_debug_resume(vdev); + if (ret) + return ret; + break; + case RW_IO_TEST: + ret = hisi_acc_vf_debug_io(vdev); + if (ret) + return ret; + break; + default: + return -EINVAL; + } + + return 0; +} + +static int hisi_acc_vf_debug_check(struct vfio_device *vdev) +{ + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(vdev); + struct hisi_acc_vf_migration_file *migf = hisi_acc_vdev->debug_migf; + enum vfio_device_mig_state state; + + if (!vdev->mig_ops || !migf) { + dev_err(vdev->dev, "device not support debugfs!\n"); + return -EINVAL; + } + + /* If device not opened, the debugfs operation will trigger calltrace */ + (void)vdev->mig_ops->migration_get_state(vdev, &state); + if (state == VFIO_DEVICE_STATE_ERROR || + state == VFIO_DEVICE_STATE_STOP) { + dev_err(vdev->dev, "device not opened!\n"); + return -EINVAL; + } + + return 0; +} + +static ssize_t hisi_acc_vf_debug_write(struct file *filp, const char __user *buffer, + size_t count, loff_t *pos) +{ + struct vfio_device *vdev = filp->private_data; + char tbuf[VFIO_DEV_DBG_LEN]; + unsigned long cmd; + int len, ret; + + if (*pos) + return 0; + + if (count >= VFIO_DEV_DBG_LEN) + return -ENOSPC; + + ret = hisi_acc_vf_debug_check(vdev); + if (ret) + return -EINVAL; + + len = simple_write_to_buffer(tbuf, VFIO_DEV_DBG_LEN - 1, + pos, buffer, count); + if (len < 0 || len > VFIO_DEV_DBG_LEN - 1) + return -EINVAL; + tbuf[len] = '\0'; + if (kstrtoul(tbuf, 0, &cmd)) + return -EFAULT; + + ret = hisi_acc_vf_debug_operate(vdev, cmd); + if (ret) { + dev_err(vdev->dev, "device debug test failed!\n"); + return -EINVAL; + } + + return count; +} + +static const struct file_operations hisi_acc_vf_debug_fops = { + .owner = THIS_MODULE, + .open = simple_open, + .write = hisi_acc_vf_debug_write, +}; + +static void seq_print_hex_data(struct seq_file *seq, const void *buf, size_t len) +{ +#define HEX_LINE_SIZE 131 +#define HEX_ROW_SIZE 16 + unsigned char linebuf[HEX_LINE_SIZE]; + int i, linelen, remaining = len; + const u8 *ptr = buf; + + for (i = 0; i < len; i += HEX_ROW_SIZE) { + linelen = min(remaining, HEX_ROW_SIZE); + remaining -= HEX_ROW_SIZE; + + hex_dump_to_buffer(ptr + i, linelen, HEX_ROW_SIZE, 1, + linebuf, sizeof(linebuf), false); + + seq_printf(seq, "%s%.8x: %s\n", "Mig Data:", i, linebuf); + } +} + +static int hisi_acc_vf_data_read(struct seq_file *seq, void *data) +{ + struct device *vf_dev = seq->private; + struct vfio_pci_core_device *core_device = dev_get_drvdata(vf_dev); + struct vfio_device *vdev = &core_device->vdev; + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(vdev); + struct hisi_acc_vf_migration_file *debug_migf = hisi_acc_vdev->debug_migf; + size_t vf_data_sz = offsetofend(struct acc_vf_data, padding); + + if (debug_migf && debug_migf->total_length) + seq_print_hex_data(seq, (unsigned char *)&debug_migf->vf_data, + vf_data_sz); + else + seq_printf(seq, "%s\n", "device not migrated!"); + + return 0; +} + +static int hisi_acc_vf_attr_read(struct seq_file *seq, void *data) +{ + struct device *vf_dev = seq->private; + struct vfio_pci_core_device *core_device = dev_get_drvdata(vf_dev); + struct vfio_device *vdev = &core_device->vdev; + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(vdev); + struct hisi_acc_vf_migration_file *debug_migf = hisi_acc_vdev->debug_migf; + + if (debug_migf && debug_migf->total_length) { + seq_printf(seq, + "acc device:\n" + "device state: %d\n" + "device ready: %u\n" + "data valid: %d\n" + "data size: %lu\n", + hisi_acc_vdev->mig_state, + hisi_acc_vdev->vf_qm_state, + debug_migf->disabled, + debug_migf->total_length); + } else { + seq_printf(seq, "%s\n", "device not migrated!"); + } + + return 0; +} + +static int hisi_acc_vfio_debug_init(struct hisi_acc_vf_core_device *hisi_acc_vdev) +{ + struct vfio_device *vdev = &hisi_acc_vdev->core_device.vdev; + struct dentry *vfio_dev_migration = NULL; + struct dentry *vfio_hisi_acc = NULL; + struct device *dev = vdev->dev; + void *migf = NULL; + + if (!debugfs_initialized()) + return 0; + + vfio_device_debugfs_init(vdev); + + migf = kzalloc(sizeof(struct hisi_acc_vf_migration_file), GFP_KERNEL); + if (!migf) + return -ENOMEM; + + hisi_acc_vdev->debug_migf = migf; + + vfio_dev_migration = debugfs_lookup("migration", vdev->debug_root); + if (!vfio_dev_migration) { + dev_err(dev, "failed to lookup migration debugfs file!\n"); + return -ENODEV; + } + + vfio_hisi_acc = debugfs_create_dir("hisi_acc", vfio_dev_migration); + debugfs_create_devm_seqfile(dev, "data", vfio_hisi_acc, + hisi_acc_vf_data_read); + debugfs_create_devm_seqfile(dev, "attr", vfio_hisi_acc, + hisi_acc_vf_attr_read); + debugfs_create_file("debug", 0200, vfio_hisi_acc, + vdev, &hisi_acc_vf_debug_fops); + + return 0; +} + +static void hisi_acc_vf_debugfs_exit(struct hisi_acc_vf_core_device *hisi_acc_vdev) +{ + struct vfio_device *vdev = &hisi_acc_vdev->core_device.vdev; + + if (!debugfs_initialized()) + return; + + vfio_device_debugfs_exit(vdev); + kfree(hisi_acc_vdev->debug_migf); +} + static int hisi_acc_vfio_pci_open_device(struct vfio_device *core_vdev) { struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(core_vdev); @@ -1416,6 +1700,9 @@ static int hisi_acc_vfio_pci_probe(struct pci_dev *pdev, const struct pci_device if (IS_ERR(hisi_acc_vdev)) return PTR_ERR(hisi_acc_vdev); + if (ops == &hisi_acc_vfio_pci_migrn_ops) + hisi_acc_vfio_debug_init(hisi_acc_vdev); + dev_set_drvdata(&pdev->dev, &hisi_acc_vdev->core_device); ret = vfio_pci_core_register_device(&hisi_acc_vdev->core_device); if (ret) @@ -1423,6 +1710,8 @@ static int hisi_acc_vfio_pci_probe(struct pci_dev *pdev, const struct pci_device return 0; out_put_vdev: + if (ops == &hisi_acc_vfio_pci_migrn_ops) + hisi_acc_vf_debugfs_exit(hisi_acc_vdev); vfio_put_device(&hisi_acc_vdev->core_device.vdev); return ret; } @@ -1431,6 +1720,7 @@ static void hisi_acc_vfio_pci_remove(struct pci_dev *pdev) { struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_drvdata(pdev); + hisi_acc_vf_debugfs_exit(hisi_acc_vdev); vfio_pci_core_unregister_device(&hisi_acc_vdev->core_device); vfio_put_device(&hisi_acc_vdev->core_device.vdev); } diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.h b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.h index dcabfeec6ca1..ef50b12f018d 100644 --- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.h +++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.h @@ -49,6 +49,14 @@ #define QM_EQC_DW0 0X8000 #define QM_AEQC_DW0 0X8020 +#define VFIO_DEV_DBG_LEN 256 + +enum mig_debug_cmd { + STATE_SAVE, + STATE_RESUME, + RW_IO_TEST, +}; + struct acc_vf_data { #define QM_MATCH_SIZE offsetofend(struct acc_vf_data, qm_rsv_state) /* QM match information */ @@ -113,5 +121,8 @@ struct hisi_acc_vf_core_device { spinlock_t reset_lock; struct hisi_acc_vf_migration_file *resuming_migf; struct hisi_acc_vf_migration_file *saving_migf; + + /* For debugfs */ + struct hisi_acc_vf_migration_file *debug_migf; }; #endif /* HISI_ACC_VFIO_PCI_H */ From patchwork Mon Mar 20 09:23:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liulongfang X-Patchwork-Id: 72051 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1114290wrt; Mon, 20 Mar 2023 02:39:20 -0700 (PDT) X-Google-Smtp-Source: AK7set/AoJDpHsoeOwciTpcQmiWlQrpxJq/SAOOZNNnCLUuF8u2TgqpGDVLoQfVkuIADk3SPSl60 X-Received: by 2002:a17:902:f0d1:b0:1a1:ca37:525a with SMTP id v17-20020a170902f0d100b001a1ca37525amr3877053pla.36.1679305159827; Mon, 20 Mar 2023 02:39:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679305159; cv=none; d=google.com; s=arc-20160816; b=xN1C6vaKqxRuc7oPBXAM/1s4ChXNj2itMX8qjGAf3lIJbG9Nzg4yNVXs2dfguiO3hz vUh91cyBuQXnM+W363o+SD/KLbgX9BAk38QFNjoIsFEWMsULyhewFsO+D3Qp/OQ9B3Hr jgjzJsFCrOSD2bhtyaE1ps97xcLD3cXuik1NCdXUkvDadJSZbnGoT0EjRKAcckdQWZ5m E19fhMNbrXi6OmKGOSlBl7FWV74SxAG/puCUttGeMIq1gw3HheiNX8OFegY1TApNNxF8 zkZOFJKxJVHi7ZnsK8hUEdN/iDljQhXcZrxJAJXgHh3KKCKKGtIgrNtoaF7l3fddbTtH +yYg== 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; bh=mheMePcb2rkJR4cr/jHmUahWB2JTGrQDtFZBBF60HhQ=; b=kDf8TsvqnD2DKci/QALeOPewwMdm/6ma3fo1lY50cMo1r2Wh3j8wsZY6Pk7eq3bUlN TN19THmoTGHNzAmcqZzAt/Fs90mi8ev9CBzwsDmlVQa4DhFsT7NfB9yY8XFadg1VaRJ/ cqulnUwPFdSaa9iAwsXyS6RQ3HiKhK9R4304Mmt3AIh+bUQhV5fE1/KdoGOVOrrTYObE DgsqU2S+zB175KLDflXaTXVfgubMe6BaM2F/RHrVcHiPrziZrBIkPWHTtqq61AfusfsP dL0YlPuogh6fP6Ux6KS4K0VTwdUCDW76Cv0OO954C5/OOmDkkQwxYVzdqXgsPMB7apZA hj9Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u15-20020a170903124f00b0019e2fdaba57si11262809plh.288.2023.03.20.02.39.05; Mon, 20 Mar 2023 02:39:19 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231298AbjCTJ1X (ORCPT + 99 others); Mon, 20 Mar 2023 05:27:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230270AbjCTJ0y (ORCPT ); Mon, 20 Mar 2023 05:26:54 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AC752448D for ; Mon, 20 Mar 2023 02:26:17 -0700 (PDT) Received: from kwepemm600005.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Pg8RL4mKCznYgh; Mon, 20 Mar 2023 17:23:10 +0800 (CST) Received: from huawei.com (10.50.163.32) by kwepemm600005.china.huawei.com (7.193.23.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Mon, 20 Mar 2023 17:26:14 +0800 From: Longfang Liu To: , , , CC: , , , Subject: [PATCH v9 4/5] Documentation: add debugfs description for vfio Date: Mon, 20 Mar 2023 17:23:37 +0800 Message-ID: <20230320092338.2889-5-liulongfang@huawei.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20230320092338.2889-1-liulongfang@huawei.com> References: <20230320092338.2889-1-liulongfang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600005.china.huawei.com (7.193.23.191) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760879087493602428?= X-GMAIL-MSGID: =?utf-8?q?1760879087493602428?= Add two debugfs document description file to help users understand how to use the accelerator live migration driver's debugfs. Signed-off-by: Longfang Liu --- .../ABI/testing/debugfs-hisi-migration | 28 +++++++++++++++++++ Documentation/ABI/testing/debugfs-vfio | 25 +++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 Documentation/ABI/testing/debugfs-hisi-migration create mode 100644 Documentation/ABI/testing/debugfs-vfio diff --git a/Documentation/ABI/testing/debugfs-hisi-migration b/Documentation/ABI/testing/debugfs-hisi-migration new file mode 100644 index 000000000000..ffcf4b5ecd51 --- /dev/null +++ b/Documentation/ABI/testing/debugfs-hisi-migration @@ -0,0 +1,28 @@ +What: /sys/kernel/debug/vfio//migration/hisi_acc/data +Date: Mar 2023 +KernelVersion: 6.2 +Contact: Longfang Liu +Description: Read the live migration data of the vfio device. + The output format of the data is defined by the live + migration driver. + +What: /sys/kernel/debug/vfio//migration/hisi_acc/attr +Date: Mar 2023 +KernelVersion: 6.2 +Contact: Longfang Liu +Description: Read the live migration attributes of the vfio device. + The output format of the attributes is defined by the live + migration driver. + +What: /sys/kernel/debug/vfio//migration/hisi_acc/debug +Date: Mar 2023 +KernelVersion: 6.2 +Contact: Longfang Liu +Description: This debug file supports "echo" command write operations. + The command is actually represented by an integer number, and the + specific meaning is defined by the corresponding device driver. + For example, three commands are defined in the HiSilicon accelerator + live migration driver: + 0: State save + 1: State resume + 2: IO test diff --git a/Documentation/ABI/testing/debugfs-vfio b/Documentation/ABI/testing/debugfs-vfio new file mode 100644 index 000000000000..81a66cf60553 --- /dev/null +++ b/Documentation/ABI/testing/debugfs-vfio @@ -0,0 +1,25 @@ +What: /sys/kernel/debug/vfio +Date: Mar 2023 +KernelVersion: 6.2 +Contact: Longfang Liu +Description: This debugfs file directory is used for debugging + of vfio devices. + Each device can create a device subdirectory under this + directory by referencing the public registration interface. + +What: /sys/kernel/debug/vfio//migration +Date: Mar 2023 +KernelVersion: 6.2 +Contact: Longfang Liu +Description: This debugfs file directory is used for debugging + of vfio devices that support live migration. + The debugfs of each vfio device that supports live migration + could be created under this directory. + +What: /sys/kernel/debug/vfio//migration/state +Date: Mar 2023 +KernelVersion: 6.2 +Contact: Longfang Liu +Description: Read the live migration status of the vfio device. + The status of these live migrations includes: + ERROR, RUNNING, STOP, STOP_COPY, RESUMING. From patchwork Mon Mar 20 09:23:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liulongfang X-Patchwork-Id: 72044 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1110813wrt; Mon, 20 Mar 2023 02:30:02 -0700 (PDT) X-Google-Smtp-Source: AK7set/lteU2i+9Z1PnD2nkmJjVGaM6jLJOLFQATb0YDTnGB6BIS12gTiCZPEoOdHyskfHsTnUF9 X-Received: by 2002:a17:902:f681:b0:19f:8bbf:9c56 with SMTP id l1-20020a170902f68100b0019f8bbf9c56mr19038302plg.3.1679304602423; Mon, 20 Mar 2023 02:30:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679304602; cv=none; d=google.com; s=arc-20160816; b=ahBGBZAjivLVg0isSGdT5o77vwoc4qjvxPtmnw9YbTxW+GIy+dk4RfdeEBAJ+c0VOt jzpR5cIbMwCKjITvtSxBEMkEVsdaBeL1iTd+ATLQebfwFFxTPrcAeDQ/dojD3iRkDTOV xxtSjyOzqzDFpGvrogzU+VBYfE4iKs0Gwa9puDJOkCJi4oXgVsX7LTzmEFpEHHWPevRq CtCCULrmQAuqPf7WHWmQMck/B4q3h4EwK1owES44k1+iFuGPQZ8V4aEM8gzZsFv6l7Co 0Nsdzjr6lzcOPzsrIIl0QhDP/HG5GKwgPo3NogYG7TGGsJSN/s6kJEhO6SDavHzYnj8Z jhUQ== 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; bh=CVTM2g1sCIEQPC4nrUAbQR6rp/F5edw+pIbMGORRf8I=; b=vh1TKEKkxL8nB5v3mMU3TbxSGME/EjETV6kENBymKMUOgXWHGJKO9nmmKKzA1dl2ZZ HLgGWSx/yfLLrUfA+IueHcvO4lG4KIyg7F3CyJ+F5F69esyzP8IeV42U9MwBLYtsdyHr QQkv2c4mW93pC4NBGlLKkrjWfG5ys5CM2bspikTnePkVQRe1cneCxfdJd0NZ2l/XUf50 eJXf0//qarwjXBf+aCP5IkP/CsPJUFsWysDCzmxhKsKHOabu/MHUensD+6I5U/7nGB57 k6IigS05eHqNRZcRaDNRQj+icJfzFiHZoxbu9QXu3N9nPAnGT9A5Jduu3tLwh48zOyzs hqWQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q19-20020a170902f35300b0019c93e0dce0si9389300ple.254.2023.03.20.02.29.50; Mon, 20 Mar 2023 02:30:02 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231327AbjCTJ1w (ORCPT + 99 others); Mon, 20 Mar 2023 05:27:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230316AbjCTJ1f (ORCPT ); Mon, 20 Mar 2023 05:27:35 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE7DD24BDD for ; Mon, 20 Mar 2023 02:26:49 -0700 (PDT) Received: from kwepemm600005.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Pg8Ry2YM9z17MZW; Mon, 20 Mar 2023 17:23:42 +0800 (CST) Received: from huawei.com (10.50.163.32) by kwepemm600005.china.huawei.com (7.193.23.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Mon, 20 Mar 2023 17:26:45 +0800 From: Longfang Liu To: , , , CC: , , , Subject: [PATCH v9 5/5] vfio: update live migration device status Date: Mon, 20 Mar 2023 17:23:38 +0800 Message-ID: <20230320092338.2889-6-liulongfang@huawei.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20230320092338.2889-1-liulongfang@huawei.com> References: <20230320092338.2889-1-liulongfang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600005.china.huawei.com (7.193.23.191) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760878502980093056?= X-GMAIL-MSGID: =?utf-8?q?1760878502980093056?= migration debugfs needs to perform debug operations based on the status of the current device. If the device is not loaded or has stopped, debugfs does not allow operations. so, after the live migration function is executed and the device is turned off, the device no longer needs to be accessed. At this time, the status of the device needs to be set to stop. Signed-off-by: Longfang Liu --- drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 3 +++ drivers/vfio/pci/mlx5/main.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c index 22ebe0e8f90f..54573b4f7f6d 100644 --- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c @@ -1615,6 +1615,9 @@ static void hisi_acc_vfio_pci_close_device(struct vfio_device *core_vdev) struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(core_vdev); struct hisi_qm *vf_qm = &hisi_acc_vdev->vf_qm; + if (core_vdev->mig_ops) + hisi_acc_vdev->mig_state = VFIO_DEVICE_STATE_STOP; + iounmap(vf_qm->io_base); vfio_pci_core_close_device(core_vdev); } diff --git a/drivers/vfio/pci/mlx5/main.c b/drivers/vfio/pci/mlx5/main.c index e897537a9e8a..dc3564436946 100644 --- a/drivers/vfio/pci/mlx5/main.c +++ b/drivers/vfio/pci/mlx5/main.c @@ -1269,6 +1269,9 @@ static void mlx5vf_pci_close_device(struct vfio_device *core_vdev) struct mlx5vf_pci_core_device *mvdev = container_of( core_vdev, struct mlx5vf_pci_core_device, core_device.vdev); + if (mvdev->migrate_cap) + mvdev->mig_state = VFIO_DEVICE_STATE_STOP; + mlx5vf_cmd_close_migratable(mvdev); vfio_pci_core_close_device(core_vdev); }