From nobody Thu Dec 25 23:30:39 2025 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 508734EB3A for ; Wed, 10 Jan 2024 20:40:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="gCI+N7HB" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AIEK96001454; Wed, 10 Jan 2024 20:40:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=942sXqvaN/YRz+5JZ7VDvcQeVeKMBRPm66kgeJtsQ+o=; b=gCI+N7HB3jkpEu0c/s6uCDQ75z+yo382dhvlRZrT5FmVjpxye0UkkQZ6GkWmJCeYFUW8 R2Ua0vSSzXXu+RLwBAvC80fTLUurym+q9pENZG8oPGAT0Q+DOy6in3hIsCMK8fyQCmYf A+R0DLmB1ohxf7TGxMXAaGILQCJgqj3lXZRcEt1S/MUmlcINlk2rfTGO2gq351y8pUhJ YuDgmyIgN/ZygHNrYK3AzkYM/WQ21b3tvZPlJ9tG3J+HHU3eJl57ZyaJZnVP9YBHFfUN 2pzBRNAw9kbnnU0PmYMcu1FUFz/tNCm7Iys0cNoW1LmUNkAhrrnsXUvvFBuhGZrdyYJ4 zw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vhvgm8x67-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:19 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJGHj8030139; Wed, 10 Jan 2024 20:40:18 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vfutp5x74-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:18 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40AKeGrR005067; Wed, 10 Jan 2024 20:40:18 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3vfutp5x5e-2; Wed, 10 Jan 2024 20:40:17 +0000 From: Steve Sistare To: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: "Michael S. Tsirkin" , Jason Wang , Si-Wei Liu , Eugenio Perez Martin , Xuan Zhuo , Dragos Tatulea , Eli Cohen , Xie Yongji , Steve Sistare Subject: [RFC V1 01/13] vhost-vdpa: count pinned memory Date: Wed, 10 Jan 2024 12:40:03 -0800 Message-Id: <1704919215-91319-2-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> References: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=985 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100163 X-Proofpoint-GUID: MBKjZoLFFMSDreR2dbLPd74JjlZNwlV9 X-Proofpoint-ORIG-GUID: MBKjZoLFFMSDreR2dbLPd74JjlZNwlV9 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Remember the count of pinned memory for the device. Signed-off-by: Steve Sistare --- drivers/vhost/vdpa.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index da7ec77cdaff..10fb95bcca1a 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -59,6 +59,7 @@ struct vhost_vdpa { int in_batch; struct vdpa_iova_range range; u32 batch_asid; + long pinned_vm; }; =20 static DEFINE_IDA(vhost_vdpa_ida); @@ -893,6 +894,7 @@ static void vhost_vdpa_pa_unmap(struct vhost_vdpa *v, s= truct vhost_iotlb *iotlb, unpin_user_page(page); } atomic64_sub(PFN_DOWN(map->size), &dev->mm->pinned_vm); + v->pinned_vm -=3D PFN_DOWN(map->size); vhost_vdpa_general_unmap(v, map, asid); vhost_iotlb_map_free(iotlb, map); } @@ -975,9 +977,10 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, struct= vhost_iotlb *iotlb, return r; } =20 - if (!vdpa->use_va) + if (!vdpa->use_va) { atomic64_add(PFN_DOWN(size), &dev->mm->pinned_vm); - + v->pinned_vm +=3D PFN_DOWN(size); + } return 0; } =20 --=20 2.39.3 From nobody Thu Dec 25 23:30:39 2025 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5D874EB5B for ; Wed, 10 Jan 2024 20:40:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="PIM4LLkY" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AKYvku003775; Wed, 10 Jan 2024 20:40:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=jh11dyvSQNnKUo1r6jhKPY0j2VffYmGM4O1HGJByISA=; b=PIM4LLkYmEQ+tK+uFZ+xx1zuW3yPDNKiMIB0fIViO9BtXcH4rBcThTe0CeSZCTLXghf8 dSUW3wy/GY1JwW7zIook+oae4XiQS3rcxbvoOk9NLwVwgXuQGJ7wqKo9rxJMgeGSv7G9 UErJne9l+FHIvEbQTGjbN7CyIoQO1oOkCroTUas8e4kxvqcnm7JQOYT+rPxenWDe9HUv H+YJDrkFAJB1i1l9KcrI+LG6Cz/W1ZLXa4pctVLMEOyyVLhyatKyukgZUM5FiIRXwlYN FK4c6HaGkbjqTNPEaUm+BO0Yii7OgSMA8NNxZzJox4jCi/RLMWZ+H1/mnULn8QG3EDu+ tg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vhpg7hn7k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:20 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJa7an030210; Wed, 10 Jan 2024 20:40:19 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vfutp5x7p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:19 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40AKeGrT005067; Wed, 10 Jan 2024 20:40:18 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3vfutp5x5e-3; Wed, 10 Jan 2024 20:40:18 +0000 From: Steve Sistare To: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: "Michael S. Tsirkin" , Jason Wang , Si-Wei Liu , Eugenio Perez Martin , Xuan Zhuo , Dragos Tatulea , Eli Cohen , Xie Yongji , Steve Sistare Subject: [RFC V1 02/13] vhost-vdpa: pass mm to bind Date: Wed, 10 Jan 2024 12:40:04 -0800 Message-Id: <1704919215-91319-3-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> References: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100163 X-Proofpoint-ORIG-GUID: Wrwtw6lCuAAEQU4M8EjggS-ALikU6A5v X-Proofpoint-GUID: Wrwtw6lCuAAEQU4M8EjggS-ALikU6A5v Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Pass the target mm to vhost_vdpa_bind_mm. No functional change. Signed-off-by: Steve Sistare --- drivers/vhost/vdpa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 10fb95bcca1a..2269988d6d33 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -248,7 +248,7 @@ static int vhost_vdpa_reset(struct vhost_vdpa *v) return _compat_vdpa_reset(v); } =20 -static long vhost_vdpa_bind_mm(struct vhost_vdpa *v) +static long vhost_vdpa_bind_mm(struct vhost_vdpa *v, struct mm_struct *mm) { struct vdpa_device *vdpa =3D v->vdpa; const struct vdpa_config_ops *ops =3D vdpa->config; @@ -256,7 +256,7 @@ static long vhost_vdpa_bind_mm(struct vhost_vdpa *v) if (!vdpa->use_va || !ops->bind_mm) return 0; =20 - return ops->bind_mm(vdpa, v->vdev.mm); + return ops->bind_mm(vdpa, mm); } =20 static void vhost_vdpa_unbind_mm(struct vhost_vdpa *v) @@ -855,7 +855,7 @@ static long vhost_vdpa_unlocked_ioctl(struct file *file= p, =20 switch (cmd) { case VHOST_SET_OWNER: - r =3D vhost_vdpa_bind_mm(v); + r =3D vhost_vdpa_bind_mm(v, v->vdev.mm); if (r) vhost_dev_reset_owner(d, NULL); break; --=20 2.39.3 From nobody Thu Dec 25 23:30:39 2025 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A97594F209 for ; Wed, 10 Jan 2024 20:40:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Sf5ruoHq" Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AIEHMj031366; Wed, 10 Jan 2024 20:40:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=p6iyspjvKTXuB4yF6u/9MqWV7tzJix+S8H6uFyg3zco=; b=Sf5ruoHqoaMYwd+pyQ8JlItRsJpxnnSA2o3p5B6VlB+6TyiXyyhmzHiKzLDZ0o48L/AP a2X8Qq2DBq8rZimMIZSttTNn0+ApZB2yBRyssQfVpKhelQYGFA/p9vtGHpzL8TyhZiTc 7iWv8xtX9c1kumKCRCh4kV1nwhUOzSOyRZYczAX/+FxHd3SoRi69VktCrFf6HJqTIk8Y fagmNpgOGB5T1wEUJnjvjkaMgIkTMRr/Z7W5DGdZb57NA5kQiu5mkNLatcB9563Xb/hV Ato41YqNtT3bgHMGZVLVrDbpe+29smUMEyTlAKgLTYucFd+v/gJKvQKRu68mtZmFyREx XA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vhx8q0mpr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:20 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJCi37030209; Wed, 10 Jan 2024 20:40:20 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vfutp5x84-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:19 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40AKeGrV005067; Wed, 10 Jan 2024 20:40:19 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3vfutp5x5e-4; Wed, 10 Jan 2024 20:40:19 +0000 From: Steve Sistare To: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: "Michael S. Tsirkin" , Jason Wang , Si-Wei Liu , Eugenio Perez Martin , Xuan Zhuo , Dragos Tatulea , Eli Cohen , Xie Yongji , Steve Sistare Subject: [RFC V1 03/13] vhost-vdpa: VHOST_NEW_OWNER Date: Wed, 10 Jan 2024 12:40:05 -0800 Message-Id: <1704919215-91319-4-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> References: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100163 X-Proofpoint-GUID: 6HP6DkR9nx9-HSrTDL3w2q_xJtSn1aEZ X-Proofpoint-ORIG-GUID: 6HP6DkR9nx9-HSrTDL3w2q_xJtSn1aEZ Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add an ioctl to transfer file descriptor ownership and pinned memory accounting from one process to another. Signed-off-by: Steve Sistare --- drivers/vhost/vdpa.c | 37 +++++++++++++++++++++++++++++++++++++ drivers/vhost/vhost.c | 15 +++++++++++++++ drivers/vhost/vhost.h | 1 + include/uapi/linux/vhost.h | 10 ++++++++++ 4 files changed, 63 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 2269988d6d33..eb3a95e703b0 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -613,6 +613,40 @@ static long vhost_vdpa_resume(struct vhost_vdpa *v) return ops->resume(vdpa); } =20 +static long vhost_vdpa_new_owner(struct vhost_vdpa *v) +{ + int r; + struct vhost_dev *vdev =3D &v->vdev; + struct mm_struct *mm_old =3D vdev->mm; + struct mm_struct *mm_new =3D current->mm; + long pinned_vm =3D v->pinned_vm; + unsigned long lock_limit =3D PFN_DOWN(rlimit(RLIMIT_MEMLOCK)); + + if (!mm_old) + return -EINVAL; + + if (!v->vdpa->use_va && + pinned_vm + atomic64_read(&mm_new->pinned_vm) > lock_limit) + return -ENOMEM; + + r =3D vhost_vdpa_bind_mm(v, mm_new); + if (r) + return r; + + r =3D vhost_dev_new_owner(vdev); + if (r) { + vhost_vdpa_bind_mm(v, mm_old); + return r; + } + + if (!v->vdpa->use_va) { + atomic64_sub(pinned_vm, &mm_old->pinned_vm); + atomic64_add(pinned_vm, &mm_new->pinned_vm); + } + + return r; +} + static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, void __user *argp) { @@ -843,6 +877,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *file= p, case VHOST_VDPA_RESUME: r =3D vhost_vdpa_resume(v); break; + case VHOST_NEW_OWNER: + r =3D vhost_vdpa_new_owner(v); + break; default: r =3D vhost_dev_ioctl(&v->vdev, cmd, argp); if (r =3D=3D -ENOIOCTLCMD) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index e0c181ad17e3..0ce7ee9834f4 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -907,6 +907,21 @@ long vhost_dev_set_owner(struct vhost_dev *dev) } EXPORT_SYMBOL_GPL(vhost_dev_set_owner); =20 +/* Caller should have device mutex */ +long vhost_dev_new_owner(struct vhost_dev *dev) +{ + if (dev->mm =3D=3D current->mm) + return -EBUSY; + + if (!vhost_dev_has_owner(dev)) + return -EINVAL; + + vhost_detach_mm(dev); + vhost_attach_mm(dev); + return 0; +} +EXPORT_SYMBOL_GPL(vhost_dev_new_owner); + static struct vhost_iotlb *iotlb_alloc(void) { return vhost_iotlb_alloc(max_iotlb_entries, diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index f60d5f7bef94..cd0dab21d99e 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -185,6 +185,7 @@ void vhost_dev_init(struct vhost_dev *, struct vhost_vi= rtqueue **vqs, int (*msg_handler)(struct vhost_dev *dev, u32 asid, struct vhost_iotlb_msg *msg)); long vhost_dev_set_owner(struct vhost_dev *dev); +long vhost_dev_new_owner(struct vhost_dev *dev); bool vhost_dev_has_owner(struct vhost_dev *dev); long vhost_dev_check_owner(struct vhost_dev *); struct vhost_iotlb *vhost_dev_reset_owner_prepare(void); diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index 649560c685f1..5e3cdce4c0cf 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -123,6 +123,16 @@ #define VHOST_SET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x25, __u64) #define VHOST_GET_BACKEND_FEATURES _IOR(VHOST_VIRTIO, 0x26, __u64) =20 +/* Set current process as the new owner of this file descriptor. The fd m= ust + * already be owned, via a prior call to VHOST_SET_OWNER. The pinned memo= ry + * count is transferred from the previous to the new owner. + * Errors: + * EINVAL: not owned + * EBUSY: caller is already the owner + * ENOMEM: RLIMIT_MEMLOCK exceeded + */ +#define VHOST_NEW_OWNER _IO(VHOST_VIRTIO, 0x27) + /* VHOST_NET specific defines */ =20 /* Attach virtio net ring to a raw socket, or tap device. --=20 2.39.3 From nobody Thu Dec 25 23:30:39 2025 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22F424F887 for ; Wed, 10 Jan 2024 20:40:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="gYMmM0Pm" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AK3w0s029998; Wed, 10 Jan 2024 20:40:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=FpiZoHvSUlbsgeuYSF8i9bTFE5kjVtx0H07bVgfyAlU=; b=gYMmM0PmVOwVx3w4/XFZ8XbmGCKfA8vKeDYw9pbl2jHzMrerwU0XgleXNGZ1ki/XRR5z mu7Htr+2rlg9o/8m/AcEDLoYzB05SIbiy48bxTvogj7Heta/SaGVY5SHWPzsIl7pRfaz V5ekQR1koWy8rmp+TBxlOBUoUGVCgAMlO8nF01trnp0nXmtOu1VbXAL/V3uC0+crMZBB WmewGFAATsknj20g3g9uFqHhzPfiOHyt5OsNJ0FLRUyT8At2K6irxU+Xi2hhlpttMMep YcJRsJEOZ8y27mMzUNe8zvfVfLS6Tu5LG9KDOhtnH7JGWlwr7ryOi64CMOS8RzL7sNUh Pg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vhpg7hn7m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:21 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40AKO3M9030351; Wed, 10 Jan 2024 20:40:20 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vfutp5x8f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:20 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40AKeGrX005067; Wed, 10 Jan 2024 20:40:20 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3vfutp5x5e-5; Wed, 10 Jan 2024 20:40:20 +0000 From: Steve Sistare To: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: "Michael S. Tsirkin" , Jason Wang , Si-Wei Liu , Eugenio Perez Martin , Xuan Zhuo , Dragos Tatulea , Eli Cohen , Xie Yongji , Steve Sistare Subject: [RFC V1 04/13] vhost-vdpa: VHOST_BACKEND_F_NEW_OWNER Date: Wed, 10 Jan 2024 12:40:06 -0800 Message-Id: <1704919215-91319-5-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> References: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100163 X-Proofpoint-ORIG-GUID: a7Axpk9an_Q3GVL_3g0hV04yn0LVxpTx X-Proofpoint-GUID: a7Axpk9an_Q3GVL_3g0hV04yn0LVxpTx Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add the VHOST_BACKEND_F_NEW_OWNER backend capability, which indicates that VHOST_NEW_OWNER is supported. Signed-off-by: Steve Sistare --- drivers/vhost/vdpa.c | 7 ++++++- include/uapi/linux/vhost_types.h | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index eb3a95e703b0..faed6471934a 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -621,6 +621,10 @@ static long vhost_vdpa_new_owner(struct vhost_vdpa *v) struct mm_struct *mm_new =3D current->mm; long pinned_vm =3D v->pinned_vm; unsigned long lock_limit =3D PFN_DOWN(rlimit(RLIMIT_MEMLOCK)); + u64 features =3D vhost_vdpa_get_backend_features(v); + + if (!(features & BIT_ULL(VHOST_BACKEND_F_NEW_OWNER))) + return -EOPNOTSUPP; =20 if (!mm_old) return -EINVAL; @@ -784,7 +788,8 @@ static long vhost_vdpa_unlocked_ioctl(struct file *file= p, BIT_ULL(VHOST_BACKEND_F_IOTLB_PERSIST) | BIT_ULL(VHOST_BACKEND_F_SUSPEND) | BIT_ULL(VHOST_BACKEND_F_RESUME) | - BIT_ULL(VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK))) + BIT_ULL(VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK) | + BIT_ULL(VHOST_BACKEND_F_NEW_OWNER))) return -EOPNOTSUPP; if ((features & BIT_ULL(VHOST_BACKEND_F_SUSPEND)) && !vhost_vdpa_can_suspend(v)) diff --git a/include/uapi/linux/vhost_types.h b/include/uapi/linux/vhost_ty= pes.h index d7656908f730..9177843951e9 100644 --- a/include/uapi/linux/vhost_types.h +++ b/include/uapi/linux/vhost_types.h @@ -192,5 +192,7 @@ struct vhost_vdpa_iova_range { #define VHOST_BACKEND_F_DESC_ASID 0x7 /* IOTLB don't flush memory mapping across device reset */ #define VHOST_BACKEND_F_IOTLB_PERSIST 0x8 +/* Supports VHOST_NEW_OWNER */ +#define VHOST_BACKEND_F_NEW_OWNER 0x9 =20 #endif --=20 2.39.3 From nobody Thu Dec 25 23:30:39 2025 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CEE5A5024C for ; Wed, 10 Jan 2024 20:40:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="DNlXjkqM" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AIEKYd001460; Wed, 10 Jan 2024 20:40:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=dMCCREUha/f4rs7C2GyYgBNQR+v/C2SrOcmk5JSsA44=; b=DNlXjkqMufFKyp/XRiG5Cp55JWfT76/fidbY873HI1BSxR9/lufWuRag0DQmM+V2JRHi cb+i+vPqrtKD444hrvpvdFbJ6mXPSaV0iSvloT1L1WG+lsdfEe2VYmjiANU3Ram94ZHj X/plyFlaVNoyjFeRBolYwaCPQYZ2I0TI90JEmu95t9EIA2+5ITdVsXy25L5X11j55jkE s8/5V2OXGz/paaYrtwKlFJs4gBoTnxxt/Gtom54weKJnHNZtw0qKHZt60tZBxznl+4aw ppeX+nPvHlFBa2Ob9L7ydSXuQdFiMVJf6mBjWNOq/r5ef0B+KIqYeCChL1AECg799rF8 vQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vhvgm8x6a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:22 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJ29e8030110; Wed, 10 Jan 2024 20:40:21 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vfutp5x98-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:21 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40AKeGrZ005067; Wed, 10 Jan 2024 20:40:21 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3vfutp5x5e-6; Wed, 10 Jan 2024 20:40:20 +0000 From: Steve Sistare To: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: "Michael S. Tsirkin" , Jason Wang , Si-Wei Liu , Eugenio Perez Martin , Xuan Zhuo , Dragos Tatulea , Eli Cohen , Xie Yongji , Steve Sistare Subject: [RFC V1 05/13] vhost-vdpa: VHOST_IOTLB_REMAP Date: Wed, 10 Jan 2024 12:40:07 -0800 Message-Id: <1704919215-91319-6-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> References: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100163 X-Proofpoint-GUID: F5HIFZ2cDW3w2vviq-JwN_fv0su8Y40M X-Proofpoint-ORIG-GUID: F5HIFZ2cDW3w2vviq-JwN_fv0su8Y40M Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When device ownership is passed to a new process via VHOST_NEW_OWNER, some devices need to know the new userland addresses of the dma mappings. Define the new iotlb message type VHOST_IOTLB_REMAP to update the uaddr of a mapping. The new uaddr must address the same memory object as originally mapped. The user must suspend the device before the old address is invalidated, and cannot resume it until after VHOST_IOTLB_REMAP is called, but this requirement is not enforced by the API. Signed-off-by: Steve Sistare --- drivers/vhost/vdpa.c | 34 ++++++++++++++++++++++++++++++++ include/uapi/linux/vhost_types.h | 11 ++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index faed6471934a..ec5ca20bd47d 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -1219,6 +1219,37 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v, =20 } =20 +static int vhost_vdpa_process_iotlb_remap(struct vhost_vdpa *v, + struct vhost_iotlb *iotlb, + struct vhost_iotlb_msg *msg) +{ + struct vdpa_device *vdpa =3D v->vdpa; + const struct vdpa_config_ops *ops =3D vdpa->config; + u32 asid =3D iotlb_to_asid(iotlb); + u64 start =3D msg->iova; + u64 last =3D start + msg->size - 1; + struct vhost_iotlb_map *map; + int r =3D 0; + + if (msg->perm || !msg->size) + return -EINVAL; + + map =3D vhost_iotlb_itree_first(iotlb, start, last); + if (!map) + return -ENOENT; + + if (map->start !=3D start || map->last !=3D last) + return -EINVAL; + + /* batch will finish with remap. non-batch must do it now. */ + if (!v->in_batch) + r =3D ops->set_map(vdpa, asid, iotlb); + if (!r) + map->addr =3D msg->uaddr; + + return r; +} + static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v, struct vhost_iotlb *iotlb, struct vhost_iotlb_msg *msg) @@ -1298,6 +1329,9 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_= dev *dev, u32 asid, ops->set_map(vdpa, asid, iotlb); v->in_batch =3D false; break; + case VHOST_IOTLB_REMAP: + r =3D vhost_vdpa_process_iotlb_remap(v, iotlb, msg); + break; default: r =3D -EINVAL; break; diff --git a/include/uapi/linux/vhost_types.h b/include/uapi/linux/vhost_ty= pes.h index 9177843951e9..35908315ff55 100644 --- a/include/uapi/linux/vhost_types.h +++ b/include/uapi/linux/vhost_types.h @@ -79,7 +79,7 @@ struct vhost_iotlb_msg { /* * VHOST_IOTLB_BATCH_BEGIN and VHOST_IOTLB_BATCH_END allow modifying * multiple mappings in one go: beginning with - * VHOST_IOTLB_BATCH_BEGIN, followed by any number of + * VHOST_IOTLB_BATCH_BEGIN, followed by any number of VHOST_IOTLB_REMAP or * VHOST_IOTLB_UPDATE messages, and ending with VHOST_IOTLB_BATCH_END. * When one of these two values is used as the message type, the rest * of the fields in the message are ignored. There's no guarantee that @@ -87,6 +87,15 @@ struct vhost_iotlb_msg { */ #define VHOST_IOTLB_BATCH_BEGIN 5 #define VHOST_IOTLB_BATCH_END 6 + +/* + * VHOST_IOTLB_REMAP registers a new uaddr for the existing mapping at iov= a. + * The new uaddr must address the same memory object as originally mapped. + * Failure to do so will result in user memory corruption and/or device + * misbehavior. iova and size must match the arguments used to create the + * an existing mapping. Protection is not changed, and perm must be 0. + */ +#define VHOST_IOTLB_REMAP 7 __u8 type; }; =20 --=20 2.39.3 From nobody Thu Dec 25 23:30:39 2025 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEC484F60F for ; Wed, 10 Jan 2024 20:40:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="FW3HzgVP" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJgBcx024051; Wed, 10 Jan 2024 20:40:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=ozrzwgDgje72Ak3YBhfPtWMph3qwJiDzAJ5pWQvnhwU=; b=FW3HzgVPCn/KF8o9W0qOaX8hff+KWsWzT6rhTE2jPd/COIYCzZ4fsWBMW/3cKMx/npvu HXSKmq/CQ7/f2VV0jIt0h+hqZxNsdq5OQRFgl0ihxbXrFq75A34ycjX95nLjP3IUknuU go/AaQ9fKn/zb+QK2hodsUaqJP3DcIiJRo3mBwaTIg08fpS3YIXIROXZXzENs7YkovCw gcW17hRYWOub6l7dPbMi76badfMeHh+iDoky3+HSwIVZwtLh+lQ0FAv0s5EyTmrJw56e Fd5puGnq9KT0r80rDpvt5dffZg+tAoDn0+kmt3e9jEm4L735AGJn/bNLJVBSehMi6RUA 0w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vj1m5r493-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:22 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40AKbb9b030303; Wed, 10 Jan 2024 20:40:22 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vfutp5x9t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:22 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40AKeGrb005067; Wed, 10 Jan 2024 20:40:21 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3vfutp5x5e-7; Wed, 10 Jan 2024 20:40:21 +0000 From: Steve Sistare To: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: "Michael S. Tsirkin" , Jason Wang , Si-Wei Liu , Eugenio Perez Martin , Xuan Zhuo , Dragos Tatulea , Eli Cohen , Xie Yongji , Steve Sistare Subject: [RFC V1 06/13] vhost-vdpa: VHOST_BACKEND_F_IOTLB_REMAP Date: Wed, 10 Jan 2024 12:40:08 -0800 Message-Id: <1704919215-91319-7-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> References: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100163 X-Proofpoint-ORIG-GUID: -Vu2mJH_2nflUo3UQH3FAAxeRLutXKmC X-Proofpoint-GUID: -Vu2mJH_2nflUo3UQH3FAAxeRLutXKmC Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add the VHOST_BACKEND_F_IOTLB_REMAP backend capability, which indicates that VHOST_IOTLB_REMAP is supported. If VHOST_BACKEND_F_IOTLB_REMAP is advertised, then the user must call VHOST_IOTLB_REMAP after ownership of a device is transferred to a new process via VHOST_NEW_OWNER. Disabling the feature during negotiation does not negate this requirement. Signed-off-by: Steve Sistare --- drivers/vhost/vdpa.c | 8 +++++++- include/uapi/linux/vhost_types.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index ec5ca20bd47d..8fe1562d24af 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -789,7 +789,8 @@ static long vhost_vdpa_unlocked_ioctl(struct file *file= p, BIT_ULL(VHOST_BACKEND_F_SUSPEND) | BIT_ULL(VHOST_BACKEND_F_RESUME) | BIT_ULL(VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK) | - BIT_ULL(VHOST_BACKEND_F_NEW_OWNER))) + BIT_ULL(VHOST_BACKEND_F_NEW_OWNER) | + BIT_ULL(VHOST_BACKEND_F_IOTLB_REMAP))) return -EOPNOTSUPP; if ((features & BIT_ULL(VHOST_BACKEND_F_SUSPEND)) && !vhost_vdpa_can_suspend(v)) @@ -1229,11 +1230,16 @@ static int vhost_vdpa_process_iotlb_remap(struct vh= ost_vdpa *v, u64 start =3D msg->iova; u64 last =3D start + msg->size - 1; struct vhost_iotlb_map *map; + u64 features; int r =3D 0; =20 if (msg->perm || !msg->size) return -EINVAL; =20 + features =3D ops->get_backend_features(vdpa); + if (!(features & BIT_ULL(VHOST_BACKEND_F_IOTLB_REMAP))) + return -EOPNOTSUPP; + map =3D vhost_iotlb_itree_first(iotlb, start, last); if (!map) return -ENOENT; diff --git a/include/uapi/linux/vhost_types.h b/include/uapi/linux/vhost_ty= pes.h index 35908315ff55..7e79e9bd0f7b 100644 --- a/include/uapi/linux/vhost_types.h +++ b/include/uapi/linux/vhost_types.h @@ -203,5 +203,7 @@ struct vhost_vdpa_iova_range { #define VHOST_BACKEND_F_IOTLB_PERSIST 0x8 /* Supports VHOST_NEW_OWNER */ #define VHOST_BACKEND_F_NEW_OWNER 0x9 +/* Supports VHOST_IOTLB_REMAP */ +#define VHOST_BACKEND_F_IOTLB_REMAP 0xa =20 #endif --=20 2.39.3 From nobody Thu Dec 25 23:30:39 2025 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AE1B4F8AD for ; Wed, 10 Jan 2024 20:40:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="WbPA2ye3" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AK8Rre021239; Wed, 10 Jan 2024 20:40:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=KZgdO8D8ThqWqmTr9W+5D2aKyTLHuIlU6faRNQ9Rhag=; b=WbPA2ye3JVDFRNlWxlIhbD458+tsIL5a6Q5z9y5rLA3TrrgvYRTuZQo+0NeIiMSYhW8g qsfhgN4lnb4/pZCOwmMk0UZRmmXx8+yPn3Km+gZwpMMlPaUZgM2j52jAJnXzBquPzSLU YH5s66pHhs0YnOLPIdn9XRDvzTQQV4GvV0VtbINYs2jHDNuob/a+K6IT9KG6OsJ/EoTl rA0iYpBMVlaDJhkezyfaok/KwGmxlokKlIeGGWTcj3gnMMldJkzUSjHgv2LRMsiz7zoV gVj9cqdL5cKgrOoQlxe4M8XIv9JdulCagneN2kRrhQI3DyBZEpi1q+8kxFXFRMJvzePn MQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vj1atg550-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:23 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40AKUqbL030093; Wed, 10 Jan 2024 20:40:23 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vfutp5xad-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:22 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40AKeGrd005067; Wed, 10 Jan 2024 20:40:22 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3vfutp5x5e-8; Wed, 10 Jan 2024 20:40:22 +0000 From: Steve Sistare To: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: "Michael S. Tsirkin" , Jason Wang , Si-Wei Liu , Eugenio Perez Martin , Xuan Zhuo , Dragos Tatulea , Eli Cohen , Xie Yongji , Steve Sistare Subject: [RFC V1 07/13] vhost-vdpa: flush workers on suspend Date: Wed, 10 Jan 2024 12:40:09 -0800 Message-Id: <1704919215-91319-8-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> References: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100163 X-Proofpoint-ORIG-GUID: JTWauBm8GQEyesMnMyowOTvYe7YbdRP1 X-Proofpoint-GUID: JTWauBm8GQEyesMnMyowOTvYe7YbdRP1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" To pass ownership of a live vdpa device to a new process, the user suspends the device, calls VHOST_NEW_OWNER to change the mm, and calls VHOST_IOTLB_REMAP to change the user virtual addresses to match the new mm. Flush workers in suspend to guarantee that no worker sees the new mm and old VA in between. Signed-off-by: Steve Sistare --- drivers/vhost/vdpa.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 8fe1562d24af..9673e8e20d11 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -591,10 +591,14 @@ static long vhost_vdpa_suspend(struct vhost_vdpa *v) { struct vdpa_device *vdpa =3D v->vdpa; const struct vdpa_config_ops *ops =3D vdpa->config; + struct vhost_dev *vdev =3D &v->vdev; =20 if (!ops->suspend) return -EOPNOTSUPP; =20 + if (vdev->use_worker) + vhost_dev_flush(vdev); + return ops->suspend(vdpa); } =20 --=20 2.39.3 From nobody Thu Dec 25 23:30:39 2025 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C9274F60C for ; Wed, 10 Jan 2024 20:40:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="YwjuYn2S" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJfmVP028156; Wed, 10 Jan 2024 20:40:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=h71dZ5JIuyeY4E0yCnqZDDaeoo7HDhGRC726pRtjHQU=; b=YwjuYn2SLz0xe5VkayBFoZr9EXJ73Hw0soGv/rlO9PHqsfT3ZC+/skZTteKsregCnTxc pXDKZbWiYARJJqsupF57xGDZfzizVwMKpbGN4HK/yWYcaFqa9wwJQbH5wJKrVn+4qDiU 60uAAh6JkJIhixK8bByD7rNJvApXoYSsU0QRMVO92GbNnERG9tHNT4SWEl6gLrEuyMxQ 7X+i01WvTBCU0vsEZNVBYLrxO51fZFk2R2REBs6A+xbvKgJk+XwPVOpi6Bhs00YEaTe8 e9Pqsw04MDdpHCBpfIGuadZGUtXarz9CNigcIyN0A4DjsrsAuFqB/zyi/NwM7BWjg249 ow== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vj1m404a9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:24 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40AKdD5K030150; Wed, 10 Jan 2024 20:40:23 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vfutp5xay-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:23 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40AKeGrf005067; Wed, 10 Jan 2024 20:40:23 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3vfutp5x5e-9; Wed, 10 Jan 2024 20:40:23 +0000 From: Steve Sistare To: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: "Michael S. Tsirkin" , Jason Wang , Si-Wei Liu , Eugenio Perez Martin , Xuan Zhuo , Dragos Tatulea , Eli Cohen , Xie Yongji , Steve Sistare Subject: [RFC V1 08/13] vduse: flush workers on suspend Date: Wed, 10 Jan 2024 12:40:10 -0800 Message-Id: <1704919215-91319-9-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> References: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100163 X-Proofpoint-ORIG-GUID: 8NpbJVwE_0qX_hcElGpqR-L_JVyvHOtf X-Proofpoint-GUID: 8NpbJVwE_0qX_hcElGpqR-L_JVyvHOtf Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" To pass ownership of a live vdpa device to a new process, the user suspends the device, calls VHOST_NEW_OWNER to change the mm, and calls VHOST_IOTLB_REMAP to change the user virtual addresses to match the new mm. Flush workers in suspend to guarantee that no worker sees the new mm and old VA in between. Signed-off-by: Steve Sistare --- drivers/vdpa/vdpa_user/vduse_dev.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vd= use_dev.c index 0ddd4b8abecb..6b25457a037d 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -472,6 +472,18 @@ static void vduse_dev_reset(struct vduse_dev *dev) up_write(&dev->rwsem); } =20 +static void vduse_flush_work(struct vduse_dev *dev) +{ + flush_work(&dev->inject); + + for (int i =3D 0; i < dev->vq_num; i++) { + struct vduse_virtqueue *vq =3D dev->vqs[i]; + + flush_work(&vq->inject); + flush_work(&vq->kick); + } +} + static int vduse_vdpa_set_vq_address(struct vdpa_device *vdpa, u16 idx, u64 desc_area, u64 driver_area, u64 device_area) @@ -713,6 +725,17 @@ static int vduse_vdpa_reset(struct vdpa_device *vdpa) return ret; } =20 +static int vduse_vdpa_suspend(struct vdpa_device *vdpa) +{ + struct vduse_dev *dev =3D vdpa_to_vduse(vdpa); + + down_write(&dev->rwsem); + vduse_flush_work(dev); + up_write(&dev->rwsem); + + return 0; +} + static u32 vduse_vdpa_get_generation(struct vdpa_device *vdpa) { struct vduse_dev *dev =3D vdpa_to_vduse(vdpa); @@ -794,6 +817,7 @@ static const struct vdpa_config_ops vduse_vdpa_config_o= ps =3D { .set_vq_affinity =3D vduse_vdpa_set_vq_affinity, .get_vq_affinity =3D vduse_vdpa_get_vq_affinity, .reset =3D vduse_vdpa_reset, + .suspend =3D vduse_vdpa_suspend, .set_map =3D vduse_vdpa_set_map, .free =3D vduse_vdpa_free, }; --=20 2.39.3 From nobody Thu Dec 25 23:30:39 2025 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A1294F885 for ; Wed, 10 Jan 2024 20:40:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="YBIbjuLQ" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJfwkn023889; Wed, 10 Jan 2024 20:40:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=89vnNv40odEsIYEKtdQ3B5jHeyloLMbotUzx7nKsXSE=; b=YBIbjuLQ1HpFrExWVf1gyNml6J1/psthAgyOlc2WnbkasD+qrTiK4Z8BD67l9/t/HBFp CpKg1vk9w5ut+svEjlcV8etkQY189WX4Ng+I3gjXbf46Tnr0cYIT6eEVYxh4vKYVJaQJ EO8OG8eI5eo1SVnuYTxJsM1FI4WS4Cix9PUFr6Hoct1PFVuhIGezEquXgLcYI+Ncx5pO W4Duux6rDeJuV+zbb2jgO863ILhxDXuihnU8T8IgfmS2yCM/iytoud+nrO7HZNk9SmZg qevvN86FKmIYqzQpvHYhGyq1akBBlD00MBVmwN8u0SxFDPmrXDgIB77dh4C+aoXDHQqV Gg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vj1m5r496-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:25 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJW0k8030071; Wed, 10 Jan 2024 20:40:24 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vfutp5xbs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:24 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40AKeGrh005067; Wed, 10 Jan 2024 20:40:23 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3vfutp5x5e-10; Wed, 10 Jan 2024 20:40:23 +0000 From: Steve Sistare To: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: "Michael S. Tsirkin" , Jason Wang , Si-Wei Liu , Eugenio Perez Martin , Xuan Zhuo , Dragos Tatulea , Eli Cohen , Xie Yongji , Steve Sistare Subject: [RFC V1 09/13] vdpa_sim: reset must not run Date: Wed, 10 Jan 2024 12:40:11 -0800 Message-Id: <1704919215-91319-10-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> References: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100163 X-Proofpoint-ORIG-GUID: q-Rtur_15lquKQ2NCJ_uyoEGBjDEaIDr X-Proofpoint-GUID: q-Rtur_15lquKQ2NCJ_uyoEGBjDEaIDr Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" vdpasim_do_reset sets running to true, which is wrong, as it allows vdpasim_kick_vq to post work requests before the device has been configured. To fix, do not set running until VIRTIO_CONFIG_S_FEATURES_OK is set. Signed-off-by: Steve Sistare Reviewed-by: Eugenio P=C3=A9rez --- drivers/vdpa/vdpa_sim/vdpa_sim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_= sim.c index be2925d0d283..6304cb0b4770 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -160,7 +160,7 @@ static void vdpasim_do_reset(struct vdpasim *vdpasim, u= 32 flags) } } =20 - vdpasim->running =3D true; + vdpasim->running =3D false; spin_unlock(&vdpasim->iommu_lock); =20 vdpasim->features =3D 0; @@ -483,6 +483,7 @@ static void vdpasim_set_status(struct vdpa_device *vdpa= , u8 status) =20 mutex_lock(&vdpasim->mutex); vdpasim->status =3D status; + vdpasim->running =3D (status & VIRTIO_CONFIG_S_FEATURES_OK) !=3D 0; mutex_unlock(&vdpasim->mutex); } =20 --=20 2.39.3 From nobody Thu Dec 25 23:30:39 2025 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2567357339 for ; Wed, 10 Jan 2024 20:40:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="GXDavQHm" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJfmVQ028156; Wed, 10 Jan 2024 20:40:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=NFZx/EFKZOPMSB3OaPzQiVb/lgOe0vt9g+rSbf9Taic=; b=GXDavQHmS5tUjLInShR585JNceUqkw1Lcofpv0QDo4qb/0J+I24z9u6xaAnHQQ5COOHK xupM/kJoP5+xpbhsc4+BpaarrutY+fbyD3h8TzkJ9/xeS+RF/YM5Tr6dr8IC2mKeGpe0 aumsDcU3D3JWqPq/VVG7mDXZrgQsJ8TckBpNVlkVoV3Cg3BXUqCXmIf+2m0tzkP9y02k ssXh82bebZ2Mj7K3bwfoLYzpOYod6dRs0sjOd5DXdEA2eqyCejWnUWKxEvO4Kae/eN+u NjS7xZaIMbblmX76WAZO9miDAttcQYJAxP9xoMV/uCBTq16DzlmkG6PbLMNwRjBSQGAm dA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vj1m404ac-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:26 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40AIvv0U030295; Wed, 10 Jan 2024 20:40:25 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vfutp5xcd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:25 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40AKeGrj005067; Wed, 10 Jan 2024 20:40:24 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3vfutp5x5e-11; Wed, 10 Jan 2024 20:40:24 +0000 From: Steve Sistare To: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: "Michael S. Tsirkin" , Jason Wang , Si-Wei Liu , Eugenio Perez Martin , Xuan Zhuo , Dragos Tatulea , Eli Cohen , Xie Yongji , Steve Sistare Subject: [RFC V1 10/13] vdpa_sim: flush workers on suspend Date: Wed, 10 Jan 2024 12:40:12 -0800 Message-Id: <1704919215-91319-11-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> References: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100163 X-Proofpoint-ORIG-GUID: R2OpFmtsJ-lX7DSIEv1LxOHwtgQ4LfMP X-Proofpoint-GUID: R2OpFmtsJ-lX7DSIEv1LxOHwtgQ4LfMP Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" To pass ownership of a live vdpa device to a new process, the user suspends the device, calls VHOST_NEW_OWNER to change the mm, and calls VHOST_IOTLB_REMAP to change the user virtual addresses to match the new mm. Flush workers in suspend to guarantee that no worker sees the new mm and old VA in between. Signed-off-by: Steve Sistare --- drivers/vdpa/vdpa_sim/vdpa_sim.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_= sim.c index 6304cb0b4770..8734834983cb 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -74,6 +74,17 @@ static void vdpasim_worker_change_mm_sync(struct vdpasim= *vdpasim, kthread_flush_work(work); } =20 +static void flush_work_fn(struct kthread_work *work) {} + +static void vdpasim_flush_work(struct vdpasim *vdpasim) +{ + struct kthread_work work; + + kthread_init_work(&work, flush_work_fn); + kthread_queue_work(vdpasim->worker, &work); + kthread_flush_work(&work); +} + static struct vdpasim *vdpa_to_sim(struct vdpa_device *vdpa) { return container_of(vdpa, struct vdpasim, vdpa); @@ -512,6 +523,8 @@ static int vdpasim_suspend(struct vdpa_device *vdpa) vdpasim->running =3D false; mutex_unlock(&vdpasim->mutex); =20 + vdpasim_flush_work(vdpasim); + return 0; } =20 --=20 2.39.3 From nobody Thu Dec 25 23:30:39 2025 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACF6750243 for ; Wed, 10 Jan 2024 20:40:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="DHSE3yQK" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJfjWG028143; Wed, 10 Jan 2024 20:40:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=hhvQOBFamiyiEmHuupz5eDq1YRqBcTmmT3w2YGrrD10=; b=DHSE3yQK/9Ol1yXpkKhUrTD9n7+DqGMPNsRbhSRvzLSx+yCGCwkmc19UoFXFNpDAONU5 qYTSVX/3tqhOVUfu0lyDm0KTHx9VhQ6639pG8QAokUSJkyYk415uSo/wji2qGXIXkiKe K96+ihbtESCeHPwOZeNmmLJjySnN2xw572lmeABrD/mvCMN+8IeRG5jcHrEzQAdFol90 KrActpbdXASCsew+2eyLiNrSpMtxFGWePKz72r/rWrRtzEt1YqQCNC2PqK180Z8dPkST KHXkq6x184vrozJJ/XAK7eDTzQpn4YPrw+Zpw0Xnr/FcqTcS6pG/g2Q8C7Fzl+NXVRTj Cw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vj1m404ad-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:26 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJJe28030160; Wed, 10 Jan 2024 20:40:26 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vfutp5xcu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:26 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40AKeGrl005067; Wed, 10 Jan 2024 20:40:25 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3vfutp5x5e-12; Wed, 10 Jan 2024 20:40:25 +0000 From: Steve Sistare To: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: "Michael S. Tsirkin" , Jason Wang , Si-Wei Liu , Eugenio Perez Martin , Xuan Zhuo , Dragos Tatulea , Eli Cohen , Xie Yongji , Steve Sistare Subject: [RFC V1 11/13] vdpa/mlx5: new owner capability Date: Wed, 10 Jan 2024 12:40:13 -0800 Message-Id: <1704919215-91319-12-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> References: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100163 X-Proofpoint-ORIG-GUID: CLFuHUGjgvH2x-cylsNPOygAE-HFhxhe X-Proofpoint-GUID: CLFuHUGjgvH2x-cylsNPOygAE-HFhxhe Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The mlx5 vdpa device supports ownership transfer to a new process, so advertise VHOST_BACKEND_F_NEW_OWNER. User virtual addresses are not used after they are initially translated to physical, so VHOST_IOTLB_REMAP is not required, hence VHOST_BACKEND_F_IOTLB_REMAP is not advertised. Signed-off-by: Steve Sistare --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5= _vnet.c index 26ba7da6b410..26f24fb0e160 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -2562,7 +2562,8 @@ static void unregister_link_notifier(struct mlx5_vdpa= _net *ndev) =20 static u64 mlx5_vdpa_get_backend_features(const struct vdpa_device *vdpa) { - return BIT_ULL(VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK); + return BIT_ULL(VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK) | + BIT_ULL(VHOST_BACKEND_F_NEW_OWNER); } =20 static int mlx5_vdpa_set_driver_features(struct vdpa_device *vdev, u64 fea= tures) --=20 2.39.3 From nobody Thu Dec 25 23:30:39 2025 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E91C50265 for ; Wed, 10 Jan 2024 20:40:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="AMF44scT" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AIEJun001445; Wed, 10 Jan 2024 20:40:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=ikIw1YDf0Rr6UcV7EZ53FO7vqQLcCSbKuHARKKX1+Ec=; b=AMF44scTd1h/vOMAg4m/JXSD/W/oS5Br13EfU1SLMwmvZ1YhNVBQrPWsTg91CeLZpoY0 57HQElys8YxeiMJqOngCkrRj4S4jvpjqdbLWfPSt6scineUafGZmsc27MNEoToEFmDR6 ZRqXDJoB50Edt79HV1t6JRJMLaA7RrUzNSU/bG059Wcss2gNO4aPLyLJs4yXlXesGppM cOSByOs7GLMYBpXr9It70cE9Isv4TZ2VVzp8ywOlORhsJsxbjExVPenblLVdfX4TdyBm xvhBM89Ofqarae9dsjZG5Z3Qu9Db4Vvj2ieX5Z8qrHaExrc5zXOBraU12dqr4mZ8PWZp Fg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vhvgm8x6f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:27 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJa7ar030210; Wed, 10 Jan 2024 20:40:26 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vfutp5xd7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:26 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40AKeGrn005067; Wed, 10 Jan 2024 20:40:26 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3vfutp5x5e-13; Wed, 10 Jan 2024 20:40:26 +0000 From: Steve Sistare To: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: "Michael S. Tsirkin" , Jason Wang , Si-Wei Liu , Eugenio Perez Martin , Xuan Zhuo , Dragos Tatulea , Eli Cohen , Xie Yongji , Steve Sistare Subject: [RFC V1 12/13] vdpa_sim: new owner capability Date: Wed, 10 Jan 2024 12:40:14 -0800 Message-Id: <1704919215-91319-13-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> References: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100163 X-Proofpoint-GUID: 2Hu1AOJmzavdJfK1M9mH4m5SRgKm8PAD X-Proofpoint-ORIG-GUID: 2Hu1AOJmzavdJfK1M9mH4m5SRgKm8PAD Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The vdpa_sim device supports ownership transfer to a new process, so advertise VHOST_BACKEND_F_NEW_OWNER. User virtual addresses are used by the software iommu, so VHOST_IOTLB_REMAP is required after VHOST_NEW_OWNER, so advertise VHOST_BACKEND_F_IOTLB_REMAP. Signed-off-by: Steve Sistare --- drivers/vdpa/vdpa_sim/vdpa_sim.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_= sim.c index 8734834983cb..d037869d8a89 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -430,7 +430,13 @@ static u64 vdpasim_get_device_features(struct vdpa_dev= ice *vdpa) =20 static u64 vdpasim_get_backend_features(const struct vdpa_device *vdpa) { - return BIT_ULL(VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK); + u64 features =3D BIT_ULL(VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK) | + BIT_ULL(VHOST_BACKEND_F_NEW_OWNER); + + if (use_va) + features +=3D BIT_ULL(VHOST_BACKEND_F_IOTLB_REMAP); + + return features; } =20 static int vdpasim_set_driver_features(struct vdpa_device *vdpa, u64 featu= res) --=20 2.39.3 From nobody Thu Dec 25 23:30:39 2025 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC9D8524D0 for ; Wed, 10 Jan 2024 20:40:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Z4I/SpWy" Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AHu6Er013238; Wed, 10 Jan 2024 20:40:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=UhQmkXl9GVu7w+z1TCplSHMQcWUnpv9XttZYc9CaLWI=; b=Z4I/SpWyGdRErY15n9ByLfWec96Ujkt4wHnw7OGouauwqVVHz9v5a0lCcNadOlUEwkPy VmE1a7/3INCEp0XRVfi0mkK7zbU9mlnAS192WkBv/rmo3IcLK9UrXzPCCSqso0+iAHTl BN800/wBesdL58Gj4O+WnEJ9f9EDSyiVxIUd6twX1VLHmN7XZFnCKd0FDkWDUkLgzcnT gUb8Kd6ZrMsHfVAk4W6Ig7qtcejv1x5M8F3Az7TOVOXDrMe4oEHgZ0jVj60bndwqAkEu iBkrBhq31myp2UPqP5GfFQOPPDHLN5cDua9iPNWwdHvD/Qy+I5HZx/++JYrkadO6u6dr aA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vhs1x1b3p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:28 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40AK51Ds030094; Wed, 10 Jan 2024 20:40:27 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vfutp5xdw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:27 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40AKeGrp005067; Wed, 10 Jan 2024 20:40:26 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3vfutp5x5e-14; Wed, 10 Jan 2024 20:40:26 +0000 From: Steve Sistare To: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: "Michael S. Tsirkin" , Jason Wang , Si-Wei Liu , Eugenio Perez Martin , Xuan Zhuo , Dragos Tatulea , Eli Cohen , Xie Yongji , Steve Sistare Subject: [RFC V1 13/13] vduse: new owner capability Date: Wed, 10 Jan 2024 12:40:15 -0800 Message-Id: <1704919215-91319-14-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> References: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100163 X-Proofpoint-ORIG-GUID: qAWOh5yp6HJp_t3u4k72qvHhZf-98H8a X-Proofpoint-GUID: qAWOh5yp6HJp_t3u4k72qvHhZf-98H8a Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The vduse device supports ownership transfer to a new process, so advertise VHOST_BACKEND_F_NEW_OWNER. User virtual addresses are used by the software iommu, so VHOST_IOTLB_REMAP is required after VHOST_NEW_OWNER, so advertise VHOST_BACKEND_F_IOTLB_REMAP. Signed-off-by: Steve Sistare --- drivers/vdpa/vdpa_user/vduse_dev.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vd= use_dev.c index 6b25457a037d..67815f6391db 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -608,6 +609,12 @@ static u32 vduse_vdpa_get_vq_align(struct vdpa_device = *vdpa) return dev->vq_align; } =20 +static u64 vduse_vdpa_get_backend_features(const struct vdpa_device *vdpa) +{ + return BIT_ULL(VHOST_BACKEND_F_IOTLB_REMAP) | + BIT_ULL(VHOST_BACKEND_F_NEW_OWNER); +} + static u64 vduse_vdpa_get_device_features(struct vdpa_device *vdpa) { struct vduse_dev *dev =3D vdpa_to_vduse(vdpa); @@ -801,6 +808,7 @@ static const struct vdpa_config_ops vduse_vdpa_config_o= ps =3D { .set_vq_state =3D vduse_vdpa_set_vq_state, .get_vq_state =3D vduse_vdpa_get_vq_state, .get_vq_align =3D vduse_vdpa_get_vq_align, + .get_backend_features =3D vduse_vdpa_get_backend_features, .get_device_features =3D vduse_vdpa_get_device_features, .set_driver_features =3D vduse_vdpa_set_driver_features, .get_driver_features =3D vduse_vdpa_get_driver_features, --=20 2.39.3