From nobody Thu Dec 18 12:10:37 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82448C83F0C for ; Sat, 26 Aug 2023 01:25:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231651AbjHZBYo (ORCPT ); Fri, 25 Aug 2023 21:24:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231644AbjHZBYP (ORCPT ); Fri, 25 Aug 2023 21:24:15 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A87A1E77 for ; Fri, 25 Aug 2023 18:24:12 -0700 (PDT) Received: from kwepemm600016.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RXfDZ5JXJzVkJP; Sat, 26 Aug 2023 09:21:50 +0800 (CST) Received: from linux-hNCriV.Euler.HZ (10.175.124.27) by kwepemm600016.china.huawei.com (7.193.23.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 26 Aug 2023 09:24:09 +0800 From: Jiang Dongxu To: , CC: jiangdongxu , , , , Subject: [PATCH 1/2] vdpa: add log operations Date: Sat, 26 Aug 2023 09:23:31 +0800 Message-ID: <5b93796745b277ab8a8b8981ce04456763a9bcaa.1693012755.git.jiangdongxu1@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600016.china.huawei.com (7.193.23.20) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: jiangdongxu Several new interfaces are introduced to allow vdpa device logging guest memory during live migration and return to the VMM. The set_log_base interface is used to set the base address for buffer storing bitmaps. The set_log_size interface is used to set the size of buffer used for storing bitmaps. The log_sync interface is used to copy the bitmaps from kernel space to user space of VMM. These operations are optional. If they are not implemented, these operations will return EOPNOTSUPP. Signed-off-by: jiangdongxu --- include/linux/vdpa.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index db1b0eaef4eb..985eed4f05b3 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -327,6 +327,15 @@ struct vdpa_map_file { * @unbind_mm: Unbind the device from the address space * bound using the bind_mm callback. (optional) * @vdev: vdpa device + * @set_log_base Set base address for logging. (optional) + * @vdev: vdpa device + * @base: base address + * @set_log_size Set buffer size for logging. (optional) + * @vdev: vdpa device + * @size: logging buffer size + * @log_sync Synchronize logging buffer from kernel space to + * user space. (optional) + * @vdev: vdpa device * @free: Free resources that belongs to vDPA (optional) * @vdev: vdpa device */ @@ -396,6 +405,11 @@ struct vdpa_config_ops { int (*bind_mm)(struct vdpa_device *vdev, struct mm_struct *mm); void (*unbind_mm)(struct vdpa_device *vdev); =20 + /* Log ops */ + int (*set_log_base)(struct vdpa_device *vdev, uint64_t base); + int (*set_log_size)(struct vdpa_device *vdev, uint64_t size); + int (*log_sync)(struct vdpa_device *vdev); + /* Free device resources */ void (*free)(struct vdpa_device *vdev); }; --=20 2.27.0 From nobody Thu Dec 18 12:10:37 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 910EBC83F13 for ; Sat, 26 Aug 2023 01:25:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231656AbjHZBYo (ORCPT ); Fri, 25 Aug 2023 21:24:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231645AbjHZBYQ (ORCPT ); Fri, 25 Aug 2023 21:24:16 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C16C71FC3 for ; Fri, 25 Aug 2023 18:24:13 -0700 (PDT) Received: from kwepemm600016.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4RXfCh34hkzJrmt; Sat, 26 Aug 2023 09:21:04 +0800 (CST) Received: from linux-hNCriV.Euler.HZ (10.175.124.27) by kwepemm600016.china.huawei.com (7.193.23.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 26 Aug 2023 09:24:11 +0800 From: Jiang Dongxu To: , CC: jiangdongxu , , , , Subject: [PATCH 2/2] vhost-vdpa: add uAPI for logging Date: Sat, 26 Aug 2023 09:23:32 +0800 Message-ID: <0495a6ca0a025ff3b1e29d24d4a4b30a3e468bde.1693012755.git.jiangdongxu1@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600016.china.huawei.com (7.193.23.20) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: jiangdongxu These new ioctl add support for setting bitmaps config, like base address and buffer size from userspace. When setup migration, VMM will call VHOST_SET_LOG_BASE and VHOST_SET_LOG_SIZE to set address and size of buffer used for storing bitmaps. Then VMM start live migration, VMM will enable logging vhost device by set feature VHOST_F_LOG_ALL. And during live migration iterate, VMM get dirty page info from vhost device by calling VHOST_LOG_SYNC. Signed-off-by: jiangdongxu --- drivers/vhost/vdpa.c | 49 ++++++++++++++++++++++++++++++++++++++ include/uapi/linux/vhost.h | 4 ++++ 2 files changed, 53 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index b43e8680eee8..75e17d9b136b 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -556,6 +556,47 @@ static long vhost_vdpa_resume(struct vhost_vdpa *v) return ops->resume(vdpa); } =20 +static long vhost_vdpa_set_log_base(struct vhost_vdpa *v, u64 __user *argp) +{ + struct vdpa_device *vdpa =3D v->vdpa; + const struct vdpa_config_ops *ops =3D vdpa->config; + u64 log; + + if (!ops->set_log_base) + return -EOPNOTSUPP; + + if (copy_from_user(&log, argp, sizeof(uint64_t))) + return -EFAULT; + + return ops->set_log_base(vdpa, log); +} + +static long vhost_vdpa_set_log_size(struct vhost_vdpa *v, u64 __user *size= p) +{ + struct vdpa_device *vdpa =3D v->vdpa; + const struct vdpa_config_ops *ops =3D vdpa->config; + u64 log_size; + + if (!ops->set_log_size) + return -EOPNOTSUPP; + + if (copy_from_user(&log_size, sizep, sizeof(log_size))) + return -EFAULT; + + return ops->set_log_size(vdpa, log_size); +} + +static long vhost_vdpa_log_sync(struct vhost_vdpa *v) +{ + struct vdpa_device *vdpa =3D v->vdpa; + const struct vdpa_config_ops *ops =3D vdpa->config; + + if (!ops->log_sync) + return -EOPNOTSUPP; + + return ops->log_sync(vdpa); +} + static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, void __user *argp) { @@ -729,6 +770,14 @@ static long vhost_vdpa_unlocked_ioctl(struct file *fil= ep, r =3D -EFAULT; break; case VHOST_SET_LOG_BASE: + r =3D vhost_vdpa_set_log_base(v, argp); + break; + case VHOST_SET_LOG_SIZE: + r =3D vhost_vdpa_set_log_size(v, argp); + break; + case VHOST_LOG_SYNC: + r =3D vhost_vdpa_log_sync(v); + break; case VHOST_SET_LOG_FD: r =3D -ENOIOCTLCMD; break; diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index f5c48b61ab62..ce9d187432d1 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -43,6 +43,10 @@ * The bit is set using an atomic 32 bit operation. */ /* Set base address for logging. */ #define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64) +/* Set buffer size for logging */ +#define VHOST_SET_LOG_SIZE _IOW(VHOST_VIRTIO, 0x05, __u64) +/* Synchronize logging buffer from kernel space to user space */ +#define VHOST_LOG_SYNC _IO(VHOST_VIRTIO, 0x06) /* Specify an eventfd file descriptor to signal on log write. */ #define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int) /* By default, a device gets one vhost_worker that its virtqueues share. T= his --=20 2.27.0