Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2404724pxb; Tue, 13 Apr 2021 00:40:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFvOl9VDMQdZjCLNFku5YaEwkuHaItu6cn0coJWdfkdVXKxy9BiKBcaonUGi2YSFEukmkh X-Received: by 2002:a17:907:33cb:: with SMTP id zk11mr14301027ejb.231.1618299645292; Tue, 13 Apr 2021 00:40:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618299645; cv=none; d=google.com; s=arc-20160816; b=KWCzrkV37RdTC5z9l2PvOg7yZW+WgzAsyPZwWx4ZgFnh5MI4XATjad2wKp8vUsII7C P9XbAOUxMm4lc0x8nPjsRoR7llN0mPAwmwQdmdDgzqsQ+MFjQPZmyUIY/uBpF3bCDzhl kzwfYNdo2Xtj7Wmuu/ZHBdAmRxCBmsyEans7KJBPmE9XEXnArZJJHkPtI6Gmqnd7Ak9H Gy3LAnYLgRcK5Oruc0lEF6/iS/vzzBU1yzKdqQ8t1uDWyFCRGtmzyiCBbhcX0me0HY2i X7Ns/2bIWbGwuW/030g+gQ+XlibpMr7I4HfpRDk9b/dpR/UpzZaSq6AuAK6E3I0BdtHq H+3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=9EqnlogH5isQlGb9PUZU+sBFac6P9z09li9XFpdBRsY=; b=KyIpdZiOPN9A5qkD7+KnIbUgiTqm8B+3k5HvdQRygvPq2My3xr8ghMzzatitZ3+8RC lAlfcsCx/VXzlcLXnN3OfD/wuXgvOhb2CuI+742yuBYbmUPrbx0XHZgGO5MxafBVdQ7R Njfe/kuH4QVPxieALy+QVA1Cgvo3X4DDgr9fnz4xw5cv9+pYs//8tcJnW2GKkLCaH7WI 45408NGCcruFdU0HArjJiaUszjTPo7XU4jx/FaWAd4x1mWQhTIjNVv0swYcglRSSb4zu M+DJYxZrL+kKZ/anLlFg+WiiL5XryfZOOh6215+8oKbcfpEBc8XWij9I/qXxmEQKq8iR w3kQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i11si10964432edb.109.2021.04.13.00.40.22; Tue, 13 Apr 2021 00:40:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240563AbhDMBXd (ORCPT + 99 others); Mon, 12 Apr 2021 21:23:33 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:17317 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235837AbhDMBX2 (ORCPT ); Mon, 12 Apr 2021 21:23:28 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FK78h0wy4z9yyP; Tue, 13 Apr 2021 09:20:52 +0800 (CST) Received: from huawei.com (10.67.165.24) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Tue, 13 Apr 2021 09:22:58 +0800 From: Longfang Liu To: CC: , , , Subject: [RFC PATCH 3/3] vfio/hisilicom: add debugfs for driver Date: Tue, 13 Apr 2021 09:20:21 +0800 Message-ID: <1618276821-8320-4-git-send-email-liulongfang@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1618276821-8320-1-git-send-email-liulongfang@huawei.com> References: <1618276821-8320-1-git-send-email-liulongfang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add debugfs debugging interface to live migration driver Signed-off-by: Longfang Liu --- drivers/vfio/pci/hisilicon/acc_vf_migration.c | 193 ++++++++++++++++++++++++++ drivers/vfio/pci/hisilicon/acc_vf_migration.h | 2 + 2 files changed, 195 insertions(+) diff --git a/drivers/vfio/pci/hisilicon/acc_vf_migration.c b/drivers/vfio/pci/hisilicon/acc_vf_migration.c index 45382c7..b0f7f09 100644 --- a/drivers/vfio/pci/hisilicon/acc_vf_migration.c +++ b/drivers/vfio/pci/hisilicon/acc_vf_migration.c @@ -16,6 +16,9 @@ #define VDM_OFFSET(x) offsetof(struct vfio_device_migration_info, x) void vfio_pci_hisilicon_acc_uninit(struct acc_vf_migration *acc_vf_dev); +static void vf_debugfs_exit(struct acc_vf_migration *acc_vf_dev); +static struct dentry *mig_debugfs_root; +static int mig_root_ref; /* return 0 mailbox ready, -ETIMEDOUT hardware timeout */ static int qm_wait_mb_ready(struct hisi_qm *qm) @@ -934,6 +937,193 @@ static const struct vfio_pci_regops vfio_pci_acc_regops = { .add_capability = acc_vf_migration_add_capability, }; +static ssize_t acc_vf_debug_read(struct file *filp, char __user *buffer, + size_t count, loff_t *pos) +{ + char buf[VFIO_DEV_DBG_LEN]; + int len; + + len = scnprintf(buf, VFIO_DEV_DBG_LEN, "%s\n", + "echo 0: test vf data store\n" + "echo 1: test vf data writeback\n" + "echo 2: test vf send mailbox\n" + "echo 3: dump vf dev data\n" + "echo 4: dump migration state\n"); + + return simple_read_from_buffer(buffer, count, pos, buf, len); +} + +static ssize_t acc_vf_debug_write(struct file *filp, const char __user *buffer, + size_t count, loff_t *pos) +{ + struct acc_vf_migration *acc_vf_dev = filp->private_data; + struct device *dev = &acc_vf_dev->vf_dev->dev; + struct hisi_qm *qm = acc_vf_dev->vf_qm; + char tbuf[VFIO_DEV_DBG_LEN]; + unsigned long val; + u64 data; + int len, ret; + + if (*pos) + return 0; + + if (count >= VFIO_DEV_DBG_LEN) + return -ENOSPC; + + len = simple_write_to_buffer(tbuf, VFIO_DEV_DBG_LEN - 1, + pos, buffer, count); + if (len < 0) + return len; + tbuf[len] = '\0'; + if (kstrtoul(tbuf, 0, &val)) + return -EFAULT; + + switch (val) { + case STATE_SAVE: + ret = vf_qm_state_save(qm, acc_vf_dev); + if (ret) + return -EINVAL; + break; + case STATE_RESUME: + ret = vf_qm_state_resume(qm, acc_vf_dev); + if (ret) + return -EINVAL; + break; + case MB_TEST: + data = readl(qm->io_base + QM_MB_CMD_SEND_BASE); + dev_info(dev, "debug mailbox addr: 0x%lx, mailbox val: 0x%llx\n", + (uintptr_t)qm->io_base, data); + break; + case MIG_DATA_DUMP: + dev_info(dev, "dumped vf migration data:\n"); + print_hex_dump(KERN_INFO, "Mig Data:", DUMP_PREFIX_OFFSET, + VFIO_DBG_LOG_LEN, 1, + (unsigned char *)acc_vf_dev->vf_data, + sizeof(struct acc_vf_data), false); + break; + case MIG_DEV_SHOW: + if (!acc_vf_dev->mig_ctl) + dev_info(dev, "migration region have release!\n"); + else + dev_info(dev, + "device state: %u\n" + "pending bytes: %llu\n" + "data offset: %llu\n" + "data size: %llu\n" + "data addr: 0x%lx\n", + acc_vf_dev->mig_ctl->device_state, + acc_vf_dev->mig_ctl->pending_bytes, + acc_vf_dev->mig_ctl->data_offset, + acc_vf_dev->mig_ctl->data_size, + (uintptr_t)acc_vf_dev->vf_data); + break; + default: + return -EINVAL; + } + + return count; +} + +static const struct file_operations acc_vf_debug_fops = { + .owner = THIS_MODULE, + .open = simple_open, + .read = acc_vf_debug_read, + .write = acc_vf_debug_write, +}; + +static ssize_t acc_vf_state_read(struct file *filp, char __user *buffer, + size_t count, loff_t *pos) +{ + struct acc_vf_migration *acc_vf_dev = filp->private_data; + char buf[VFIO_DEV_DBG_LEN]; + u32 state; + int len; + + if (!acc_vf_dev->mig_ctl) { + len = scnprintf(buf, VFIO_DEV_DBG_LEN, "%s\n", "Invalid\n"); + } else { + state = acc_vf_dev->mig_ctl->device_state; + switch (state) { + case VFIO_DEVICE_STATE_RUNNING: + len = scnprintf(buf, VFIO_DEV_DBG_LEN, "%s\n", + "RUNNING\n"); + break; + case VFIO_DEVICE_STATE_SAVING | VFIO_DEVICE_STATE_RUNNING: + len = scnprintf(buf, VFIO_DEV_DBG_LEN, "%s\n", + "SAVING and RUNNING\n"); + break; + case VFIO_DEVICE_STATE_SAVING: + len = scnprintf(buf, VFIO_DEV_DBG_LEN, "%s\n", + "SAVING\n"); + break; + case VFIO_DEVICE_STATE_STOP: + len = scnprintf(buf, VFIO_DEV_DBG_LEN, "%s\n", + "STOP\n"); + break; + case VFIO_DEVICE_STATE_RESUMING: + len = scnprintf(buf, VFIO_DEV_DBG_LEN, "%s\n", + "RESUMING\n"); + break; + default: + len = scnprintf(buf, VFIO_DEV_DBG_LEN, "%s\n", + "Error\n"); + } + } + + return simple_read_from_buffer(buffer, count, pos, buf, len); +} + +static const struct file_operations acc_vf_state_fops = { + .owner = THIS_MODULE, + .open = simple_open, + .read = acc_vf_state_read, +}; + +static void vf_debugfs_init(struct acc_vf_migration *acc_vf_dev) +{ + char name[VFIO_DEV_DBG_LEN]; + int node_id; + + if (!mig_root_ref) + mig_debugfs_root = debugfs_create_dir("vfio_acc", NULL); + mutex_lock(&acc_vf_dev->reflock); + mig_root_ref++; + mutex_unlock(&acc_vf_dev->reflock); + + node_id = dev_to_node(&acc_vf_dev->vf_dev->dev); + if (node_id < 0) + node_id = 0; + + if (acc_vf_dev->acc_type == HISI_SEC) + scnprintf(name, VFIO_DEV_DBG_LEN, "sec_vf%d-%d", + node_id, acc_vf_dev->vf_id); + else if (acc_vf_dev->acc_type == HISI_HPRE) + scnprintf(name, VFIO_DEV_DBG_LEN, "hpre_vf%d-%d", + node_id, acc_vf_dev->vf_id); + else + scnprintf(name, VFIO_DEV_DBG_LEN, "zip_vf%d-%d", + node_id, acc_vf_dev->vf_id); + + acc_vf_dev->debug_root = debugfs_create_dir(name, mig_debugfs_root); + + debugfs_create_file("debug", 0644, acc_vf_dev->debug_root, + acc_vf_dev, &acc_vf_debug_fops); + debugfs_create_file("state", 0444, acc_vf_dev->debug_root, + acc_vf_dev, &acc_vf_state_fops); +} + +static void vf_debugfs_exit(struct acc_vf_migration *acc_vf_dev) +{ + debugfs_remove_recursive(acc_vf_dev->debug_root); + + mutex_lock(&acc_vf_dev->reflock); + mig_root_ref--; + mutex_unlock(&acc_vf_dev->reflock); + + if (!mig_root_ref) + debugfs_remove_recursive(mig_debugfs_root); +} + static int qm_acc_type_init(struct acc_vf_migration *acc_vf_dev) { struct pci_dev *pdev = acc_vf_dev->vf_dev; @@ -1137,6 +1327,8 @@ int vfio_pci_hisilicon_acc_init(struct vfio_pci_device *vdev) goto register_error; } + vf_debugfs_init(acc_vf_dev); + return 0; register_error: @@ -1159,6 +1351,7 @@ void vfio_pci_hisilicon_acc_uninit(struct acc_vf_migration *acc_vf_dev) acc_vf_dev->regions = NULL; acc_vf_dev->num_regions = 0; + vf_debugfs_exit(acc_vf_dev); kfree(acc_vf_dev); } diff --git a/drivers/vfio/pci/hisilicon/acc_vf_migration.h b/drivers/vfio/pci/hisilicon/acc_vf_migration.h index 26c79e4..38d4035 100644 --- a/drivers/vfio/pci/hisilicon/acc_vf_migration.h +++ b/drivers/vfio/pci/hisilicon/acc_vf_migration.h @@ -159,11 +159,13 @@ struct acc_vf_migration { struct hisi_qm *vf_qm; int vf_id; u8 acc_type; + struct mutex reflock; struct vfio_device_migration_info *mig_ctl; struct acc_vf_data *vf_data; struct vfio_pci_region *regions; int num_regions; + struct dentry *debug_root; }; #endif /* ACC_MIG_H */ -- 2.8.1