From nobody Wed Dec 17 10:40:43 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 8ACC616FF2A for ; Fri, 12 Jul 2024 13:19:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720790351; cv=none; b=AdnbJ/qYJeGi+nsYmPrLUFnJHKJ+qjduPqej4eHze8OW+1YyMNYwyteR5NiYeZXgHgUTn+AVy6jvA4WaabGIEpWG026jLm781Rb0L1Zc+UKqv3SqOPXI1j2oWp2/WDTIeQDSpjZhr598qdxB7pnnlnuDdYvHjy/4zx4ACR1EyTM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720790351; c=relaxed/simple; bh=mpPEqNHUboHg5X4DuAYbZYtk5ez8+vBp8ZUbNSPbIkI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=T7eYMotHora9Qc3047wu64bQjwnf7hmLyDCfCWgBdvmVbBOgNKueVKE6wnDRJLEwW4Z+xL29AR22S7Ia1Dqlx7jLLBaKGcS9nhXdOMFlXnxWieyNAFuS2fD9D36geSAnumAxHy7TULt7xFTxdunXNmo0kZiVO06PTlqcjYYyJOM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=oMAGvgJ1; arc=none smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="oMAGvgJ1" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46CDILjo023659; Fri, 12 Jul 2024 13:18:56 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=UoIL+vCtOh0fhA5lR3F1t22mJvNzXPZjXUGWRT0A8lY=; b= oMAGvgJ1av1S92KxLZpNDpMZ441JMOeBFZ5STUhmTN36ehXhmayNIRRrgnQH+F9r CSt/ihMS46oaumteLnb4bQkW43lKFTwc41pqKnZKHCSSAbUa/hwB08yyX5Tf+pPU vDkgsd+v4hNGhG2kv5OdJcvbRYx0o+gna+Ay8aXKbBM8RtpUZfqr98JwSa00SnjO 0+DQBddO/SpznMe2pJVAr3LRh0b0SgkAwy4FFr3fCyDuzbBgq8OYPP0flPhQ31QP oRoctodnPVzcvb77kH64h8PT2TwklcUoCtsZZWNEsknywLDQSpZE3qaoHqjt6to9 ewF1RPFV9NnNE/n5is05Bg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 407emt34yc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 13:18:56 +0000 (GMT) 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 46CCVnUM022018; Fri, 12 Jul 2024 13:18:55 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv3snpr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 13:18:55 +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 46CDIsD9029886; Fri, 12 Jul 2024 13:18:54 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 409vv3snp2-2; Fri, 12 Jul 2024 13:18:54 +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 , Steve Sistare Subject: [PATCH V2 1/7] vhost-vdpa: count pinned memory Date: Fri, 12 Jul 2024 06:18:47 -0700 Message-Id: <1720790333-456232-2-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1720790333-456232-1-git-send-email-steven.sistare@oracle.com> References: <1720790333-456232-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-12_09,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407120089 X-Proofpoint-GUID: bbr0eCVG20NSa_bbxeF3aQ5F1lkneOWZ X-Proofpoint-ORIG-GUID: bbr0eCVG20NSa_bbxeF3aQ5F1lkneOWZ 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 63a53680a85c..963f3704bc39 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -60,6 +60,7 @@ struct vhost_vdpa { struct vdpa_iova_range range; u32 batch_asid; bool suspended; + long pinned_vm; }; =20 static DEFINE_IDA(vhost_vdpa_ida); @@ -926,6 +927,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); } @@ -1009,9 +1011,10 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, stru= ct 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 Wed Dec 17 10:40:43 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 8AC8216FF28 for ; Fri, 12 Jul 2024 13:19:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720790351; cv=none; b=BnZ5BE2tPjEtHgStVXTr9IR25a7HtjY/WJX6iJJu19XeFM2mNWE2ulYJrXcT2vHfRi684tYeFUODkT17j3MizlvuI5PzEs2o9oBpOwqe/93oTUAI7D5sW3rZXe+NpuReYO7p6BOERz+5SqmcwqL5OtLJ8fNqnvhq00cvFfW6Klg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720790351; c=relaxed/simple; bh=SifNTPkrOyt1o72VGP+1ZHcebiT2mNEzcaMyfAUlc4E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=ki1mMPtIdJJP0bRhf5Sz6/X3hPIAk8XE23UfJzLDjEdRZlzeTrDrh+BZxKc8JzeEIIHPClhFYj2atqSVTWZNKMWtQa6cBQTo4UWaW9PUVxoG899Huy6zUDQR6NTUqtcOhkEw/ejheVheR47sUaNyhz+VrwI+awtJWngzRI+sU+I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=QPybPh3x; arc=none smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="QPybPh3x" Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46CDIL4V006325; Fri, 12 Jul 2024 13:18:56 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=GbTtDJldqRAxtpXcP6RAUB5I1SetiV86HUhK1VvYzyg=; b= QPybPh3x9OrLBEipWifKbVVm1KbZIdj20eMYA71mvvSH7zULgcqHCX1JwaUL5mwz jl1BmF9CsYviqZq6OLC646qwZxwcS7nCtIvrKiqzH820jDXv/5IjY1dD+1fFBOpr CxTsIyOHR3e4/UXJZ3s1pccsp5sDQHgyctHyTAwn7ieKFEcPsevYrArX+Hdl/RBB D13ZnTeixfAljQl36qYMq089OAiH+MMAzsG7sg0qkPelJIuYu8pBjqknSX28T5PW z/Ml5Cs3saiQQHt8LT/bGrumx6itcc9CHXPtPYnbf/Uw9wDCfq3e6vgPDUCf1O/n oYBbrxM76OR3DgE9e7EDmA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406wkcks2q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 13:18:56 +0000 (GMT) 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 46CD61QH022053; Fri, 12 Jul 2024 13:18:55 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv3snq2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 13:18:55 +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 46CDIsDB029886; Fri, 12 Jul 2024 13:18:55 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 409vv3snp2-3; Fri, 12 Jul 2024 13:18:55 +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 , Steve Sistare Subject: [PATCH V2 2/7] vhost-vdpa: pass mm to bind Date: Fri, 12 Jul 2024 06:18:48 -0700 Message-Id: <1720790333-456232-3-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1720790333-456232-1-git-send-email-steven.sistare@oracle.com> References: <1720790333-456232-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-12_09,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407120089 X-Proofpoint-ORIG-GUID: 9K6Lu_tlx0jqHi6mCbXlUPlqqKvHkhrB X-Proofpoint-GUID: 9K6Lu_tlx0jqHi6mCbXlUPlqqKvHkhrB 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 963f3704bc39..b49e5831b3f0 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -251,7 +251,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; @@ -259,7 +259,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) @@ -888,7 +888,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 Wed Dec 17 10:40:43 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 933F216FF37 for ; Fri, 12 Jul 2024 13:19:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720790352; cv=none; b=qLNL8eyMEib1hAOx2OhUuKquSnQiLTu+2gMuSjEZ8A06ASIKbPRAdQteur8T8tV5ed4zNBwtZwWl6vssGBpn0eVjr9hEofjkOC/bP6qVOt3OfWvu5/grqfvEGLtC/1/q5xQXARCaZRN3t0k2CqOQWUGtnhNWSjxKyEUkuKbTWsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720790352; c=relaxed/simple; bh=ewuv2DScA0KHxHepz7iXXuaiIDkgzMtLA9LufqTlxbQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=eP2DTxIQjJzzKmMuw0Z4Km/+CydeEpO31+gitqvf2kR1w/UokWpKk/QuKiDmJTg3Tctv8Rxr0XBCJOhec9QdyWaC1OHMqSWmJHT8uOxadtuXlQbfxyBsCQMcgWi7fk07N3VzSu1CBsKPL0RA2PW4S/4M3GGVuVv59rdrjhDlOeI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=NxbMcKV/; arc=none smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="NxbMcKV/" Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46CDIMh6006357; Fri, 12 Jul 2024 13:18:57 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=NKJsM7SEgeGt3SGI1oZ28F9YAfkS43VBsojMb2tfJ4c=; b= NxbMcKV/ywPtyLZRPasj3UaP9A39pjhmzmwj/ZvxWq7HDFNGrVWrL6vBqe8LRvtz 1CUwKG5XHMnCtVLghE68W/CyTDLypyUPK+XR+XBum2qCOxeVJKsQ0ymO145uxlaO By24YmV7NrHZDoyCHLpVjaAtWUQfqQVhujIP8ouE8mi/RxKItqm4oa5NDjbo4kys GhGenKdaBBGwmsQ/UDpZT0Xl9p7ffizBq+QDd9cDuhjvZgpgKTZKx/UAQjtu5Lim +CbKqvOQR/vxvvAMfkJZ3JZP2QG2Q+9TsiD9ALOcyDBTDFpOi6Y+Yni0dlNysAfA 719VCHQ6TKXIMjXqXda1bQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406wkcks2r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 13:18:57 +0000 (GMT) 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 46CCVnUN022018; Fri, 12 Jul 2024 13:18:56 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv3snqc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 13:18:56 +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 46CDIsDD029886; Fri, 12 Jul 2024 13:18:55 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 409vv3snp2-4; Fri, 12 Jul 2024 13:18:55 +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 , Steve Sistare Subject: [PATCH V2 3/7] vhost-vdpa: VHOST_NEW_OWNER Date: Fri, 12 Jul 2024 06:18:49 -0700 Message-Id: <1720790333-456232-4-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1720790333-456232-1-git-send-email-steven.sistare@oracle.com> References: <1720790333-456232-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-12_09,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407120089 X-Proofpoint-ORIG-GUID: No6kTf_mUWNt04cQaojtpklUJkOHJeFn X-Proofpoint-GUID: No6kTf_mUWNt04cQaojtpklUJkOHJeFn 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. This is more efficient than VHOST_RESET_OWNER followed by VHOST_SET_OWNER, as that would unpin all physical pages, requiring them to be repinned in the new process. That would cost multiple seconds for large memories, and be incurred during a virtual machine's pause time during live update. Signed-off-by: Steve Sistare --- drivers/vhost/vdpa.c | 41 ++++++++++++++++++++++++++++++++++++++ drivers/vhost/vhost.c | 15 ++++++++++++++ drivers/vhost/vhost.h | 1 + include/uapi/linux/vhost.h | 10 ++++++++++ 4 files changed, 67 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index b49e5831b3f0..5cf55ca4ec02 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -632,6 +632,44 @@ static long vhost_vdpa_resume(struct vhost_vdpa *v) return ret; } =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; + mmgrab(mm_old); + + if (!v->vdpa->use_va && + pinned_vm + atomic64_read(&mm_new->pinned_vm) > lock_limit) { + r =3D -ENOMEM; + goto out; + } + r =3D vhost_vdpa_bind_mm(v, mm_new); + if (r) + goto out; + + r =3D vhost_dev_new_owner(vdev); + if (r) { + vhost_vdpa_bind_mm(v, mm_old); + goto out; + } + + if (!v->vdpa->use_va) { + atomic64_sub(pinned_vm, &mm_old->pinned_vm); + atomic64_add(pinned_vm, &mm_new->pinned_vm); + } + +out: + mmdrop(mm_old); + return r; +} + static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, void __user *argp) { @@ -876,6 +914,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 b60955682474..ab40ae50552f 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -963,6 +963,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 bb75a292d50c..8b2018bb02b1 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -187,6 +187,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 b95dd84eef2d..543d0e3434c3 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 Wed Dec 17 10:40:43 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 8ABE716F91D for ; Fri, 12 Jul 2024 13:19:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720790351; cv=none; b=iZvWWbbbmgBlC/qWd47lyoBg+F2CJDTzvw6t8xJkCSFn5tl5IrtbxEHdCrWl52iCe1wbu88NNFjy43R/ctkzgIvt8tVesZdhi/H0djZPF+wFTNNnixoX8j7LUqMytf5iG7JXCVz0BrDIp/Guokn4DNZQmkV/p4KG7O00ooXB1uQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720790351; c=relaxed/simple; bh=hlBTCWc/+N1wCk/wXZAgKGiPA/PMmWCVwg+g7qOTjBg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=JMfBp4evJzBYVWr9FhRPfXiVmu4WziFcEK1/XaiThxuktFUWLPXV8n7LBAIwdgqdYDZZYxFJxg9HVwz+DeVbSPO9yS6Y9mRuyH8UelLa9eG6JtJup7wh4Q4dnEHuyiaQrTKn8HgiViZu3LrVgDPn0HjJ+PzoenlGqteUNihGhk4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=QzsYmGqN; arc=none smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="QzsYmGqN" Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46CDIL99006342; Fri, 12 Jul 2024 13:18:58 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=1Rs0R5MKc/0Zr7T6CVE7wYEZGdaXmFH0mlVQdxtpyTU=; b= QzsYmGqNemciHyLWVRxSdNuoVkZR7kewd6CKw8lkrns7ts0ZKFBsf1eNxvzXTvYX 7idphuzJM3rK1CABIZKX35nIv84uHRrHpYG954qDij04biyhzcm8ketegq+r3iBR 5j0Ue5EZO6tyYaUl6epXxylKBcNT9VB5Zeum+Qob6MB0LyybotYb5kzdwJm+nbYB mLARP85UcVUPeP1gkf5jNPlO14rTUzm12Zz5fTdg8bzTnr/KPoxvVL/NSEAu1LQ3 M9nt6V2PDDXYPkAv6rQHIuIYAshubauwwtfn5VXXL+L0ZlwlCP795EXkiJPIJ6X6 xUBLyfsRg2/4/H0gYYow6g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406wkcks2s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 13:18:58 +0000 (GMT) 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 46CBneZm022757; Fri, 12 Jul 2024 13:18:57 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv3snqy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 13:18:57 +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 46CDIsDF029886; Fri, 12 Jul 2024 13:18:56 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 409vv3snp2-5; Fri, 12 Jul 2024 13:18:56 +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 , Steve Sistare Subject: [PATCH V2 4/7] vhost-vdpa: VHOST_BACKEND_F_NEW_OWNER Date: Fri, 12 Jul 2024 06:18:50 -0700 Message-Id: <1720790333-456232-5-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1720790333-456232-1-git-send-email-steven.sistare@oracle.com> References: <1720790333-456232-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-12_09,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407120089 X-Proofpoint-ORIG-GUID: chDgWWEaTXrQPr8cdirWfMwHY5c3WKC4 X-Proofpoint-GUID: chDgWWEaTXrQPr8cdirWfMwHY5c3WKC4 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 5cf55ca4ec02..4396fe1a90c4 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -640,6 +640,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; @@ -821,7 +825,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 Wed Dec 17 10:40:43 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 9727716FF47 for ; Fri, 12 Jul 2024 13:19:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720790352; cv=none; b=Un+PLn5vv/PttgjRQEe3cKzwTjnqU4cmU+QgN99I5UeF1E0fNToa5p+qMhbx3TzgsIE0HIirVGI3FYoWId0/cx084gi3nL4zmHWLlhinafzWw8RRrFjBGUBFLZBOZ/aA7mZMLFavK054+f0UyysFZvXXnuUunznyLMItYlK0LhA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720790352; c=relaxed/simple; bh=9pwK6KrwmEJnnyWxiHLvu2P+MPBI7Vx0jWETI5yoDzE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=N/5BbkE7pJmeFvmA0dgzJPdV8zd9GHzhWVItuyPtu/wC9exrsZUL7yxwlxfIYBPtbFUFNNQOa1LaeEtIMOwpX/NRJ0lmPYEo//BflZvOmZL7Tw6j6r8f+tTV3DHWWIo6JNHTjf/GvWeB3PZx/92B7cv4dALnLUmLkVW8MmcBtxQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=KvGfkySM; arc=none smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="KvGfkySM" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46CDIMWI025593; Fri, 12 Jul 2024 13:18:59 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=nJg4BRPsRkeaHY4ExSNlZDmpNt3E+wvWdny45AqoH2w=; b= KvGfkySMAtB5Kx9FE7vt503C3TF2pLSViEKCy0alJLqrEyCqmFDo/RTFQ9B0YY4y YLSRQ0sADAOgAQDqgG/eQlEhvwDNpdmuHmTZYT+kGVsWzYkx+mvoko1nJACesozB M/5N0DezIMTw0Nf6+23gjp0ObMZie3oYnjKS/KS9CvqPmZsMvtkHc03ugpwL6B2M tXmgwRW2rJloNrGssXlAy1g3DebBP1uR+pxrTE8s2vouwh6ZGqiQ7KCaVgCXIAmI ZRANV/tJ8kUrbR29QeUbUd4Xe6KjnkIFri/3Akta0axk5W1OnRTgJraRNlglPrLm mIT2rTSv9RX2uZHc4mrzZg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406wknuv05-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 13:18:58 +0000 (GMT) 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 46CBMAAP022638; Fri, 12 Jul 2024 13:18:57 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv3snrk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 13:18:57 +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 46CDIsDH029886; Fri, 12 Jul 2024 13:18:57 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 409vv3snp2-6; Fri, 12 Jul 2024 13:18:57 +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 , Steve Sistare Subject: [PATCH V2 5/7] vhost-vdpa: VHOST_IOTLB_REMAP Date: Fri, 12 Jul 2024 06:18:51 -0700 Message-Id: <1720790333-456232-6-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1720790333-456232-1-git-send-email-steven.sistare@oracle.com> References: <1720790333-456232-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-12_09,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407120089 X-Proofpoint-GUID: oioFsCUpcQ48RdZWJWfGTBMl75UlGpS6 X-Proofpoint-ORIG-GUID: oioFsCUpcQ48RdZWJWfGTBMl75UlGpS6 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 | 58 ++++++++++++++++++++++++++++++++ include/uapi/linux/vhost_types.h | 11 +++++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 4396fe1a90c4..51f71c45c4a9 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -1257,6 +1257,61 @@ 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; + + /* + * The current implementation does not support the platform iommu + * with use_va. And if !use_va, remap is not necessary. + */ + if (!ops->set_map && !ops->dma_map) + return -EINVAL; + + /* + * The current implementation supports set_map but not dma_map. + */ + if (!ops->set_map) + return -EINVAL; + + /* + * Do not verify that the new size@uaddr points to the same physical + * pages as the old size@uaddr, because that would take time O(npages), + * and would increase guest down time during live update. If the app + * is buggy and they differ, then the app may corrupt its own memory, + * but no one else's. + */ + + /* + * Batch will finish later in BATCH_END by calling set_map for the new + * addresses collected here. 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) @@ -1336,6 +1391,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 Wed Dec 17 10:40:43 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 8AC3016FF26 for ; Fri, 12 Jul 2024 13:19:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720790352; cv=none; b=N22mfwP0VYgU4dhpzSf4IDcpF2lubHlsnKasJpCkPi0ia39OLzbdF29jNzpB33Xm+uc2IqIH3/0GbpcYfqwkWetaSiuI/rT65Xdfk3rN/dBcKDvydciXVmfr+nshpQgGz+Xbz7AK4J50nSB/0S3PkVmGAwoWkDyC7VFDL9A9uFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720790352; c=relaxed/simple; bh=wCvW00aBdlJDx2fw9Sb9Aw6FcCB2yoyvOxsFnqJNtbU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=FVyTo6v4MlemiRoCeb+vKrElTcxw/95QbGVgsvsRnvVIYcZFsPYnR7y/VNDgovNGmy7lSnVlfMwHCAB6rXV9De9dpEpSQdCj8EbXzFn9ewphcn1oSimsFtvfOJQRnnIlJb1J+3g/+JrRp3/H9zYs88btQL5ZIFAFQmEnWLj2GZs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=EZ4yXVxc; arc=none smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="EZ4yXVxc" Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46CDIK6e014260; Fri, 12 Jul 2024 13:18:59 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=kt586yo3yoOuzwKRIaw5fOFI+WJWJXsv6eQwBzv0uqo=; b= EZ4yXVxcbAlG+oOYkDzPlMfdFpEeXNcPvLXIkClf7Xjfj11Q1myltu6jjjTQH2zI fkLKmdteAu91vEzj4nTlA8igh7qc/qrJAQ3+of14iJzufjys61eYu45yL3uXt7j/ VytOuciNTKweLW0TOa+xlzf0rCc0Eoo6pFENl2tu96CoIVquXmT6yJ4jc8o8tJZ6 b80reSBjdBqcy71UYPI3pBXeB0jBEJhKzwp5V68ue6L2XhLbTpxokwDRTkX4hcE6 CLqQ1jusGTXn2E0ZrrbuPxZdJBJ0pzV7c6hrGc4Urf2a29fiyTG88/77QxunF5Mv 5/dnsK9VgcLvbFpxhr4/aw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406wybuyg5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 13:18:59 +0000 (GMT) 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 46CCPDTo022608; Fri, 12 Jul 2024 13:18:58 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv3sns3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 13:18:58 +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 46CDIsDJ029886; Fri, 12 Jul 2024 13:18:57 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 409vv3snp2-7; Fri, 12 Jul 2024 13:18:57 +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 , Steve Sistare Subject: [PATCH V2 6/7] vhost-vdpa: VHOST_BACKEND_F_IOTLB_REMAP Date: Fri, 12 Jul 2024 06:18:52 -0700 Message-Id: <1720790333-456232-7-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1720790333-456232-1-git-send-email-steven.sistare@oracle.com> References: <1720790333-456232-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-12_09,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407120089 X-Proofpoint-GUID: nVgFF2Y_xTo6E4M_Geqi21C8MZyyqQaI X-Proofpoint-ORIG-GUID: nVgFF2Y_xTo6E4M_Geqi21C8MZyyqQaI 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 51f71c45c4a9..1ec1f1382fd7 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -826,7 +826,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)) @@ -1267,11 +1268,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 Wed Dec 17 10:40:43 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 95C0816FF45 for ; Fri, 12 Jul 2024 13:19:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720790351; cv=none; b=g7aeBV4me635V3yN/mbr2N0JTe/34D8M6Xa35wVcyRf+EUfsZxKui73a7VHc6Ns7Xvx0xKp7/AID77mO16m8DkVeBR6FPgueykTkhPmtTeKd4skLIIlSmrlpm2QAQGG4od7wGJOr7sfZJ7SWhE2NUd6aPkSKF2mahox4PBC7Bc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720790351; c=relaxed/simple; bh=dN4nSJyVUk1dN2K4WL25CJ+DanbiyhmkRdutX8DGPEo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=YTsXhpy1TpkdYArg+MxS8sYlLKlLYmEN5hDNT/ZUa87fgBLEyO7lGQw9Y/ecdf1jkPqHuXYVIDPyaLL2AwFJKEKxtWbkRy6FRSEJpugO4qn5m2lQNwvP4yxa14CBinFWWr3CUpvB54Zj9S5w+sBslYcyNL0xBP/DzGY5fEINC0Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=ek3m3TW4; arc=none smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="ek3m3TW4" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46CDILeT025537; Fri, 12 Jul 2024 13:19:00 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=7twIdosg+tLq6GhSfBDMiJ/UOzlk+u2dnfv1CdH0B4A=; b= ek3m3TW4f7X33wlg8gpBSSSeib5FDuy76Pr0vnreLbotWO/iFthKK5bK6rJMHV0p uTSwTbv9GHUSRG0rsBY8JuMbCjD2zVsd4pG2khdhu9kqhAU7MzEKhxPyNcOqpluf CfFD8gua7/RiQNFspP8vudnePjLwmljRjIjDXdjwCBAempH6tSCpVQHcxRLTROZF hoY4I4dAnYAuGh7BFLiqZtI8QrkXBmPP5RI5FrKeWDVtPxYml+qfYdoDw3GIRtQH jQyw2/PR1aJ2pH4gpwxoXhImrpppe35TXO+YovTcCLy69UYSaHTaAvp6ZTPgIrvK iY9xW+BbqsfnMtjSG5hwnQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406wknuv06-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 13:18:59 +0000 (GMT) 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 46CDGAop022665; Fri, 12 Jul 2024 13:18:59 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv3snsf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2024 13:18:58 +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 46CDIsDL029886; Fri, 12 Jul 2024 13:18:58 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 409vv3snp2-8; Fri, 12 Jul 2024 13:18:58 +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 , Steve Sistare Subject: [PATCH V2 7/7] vdpa/mlx5: new owner capability Date: Fri, 12 Jul 2024 06:18:53 -0700 Message-Id: <1720790333-456232-8-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1720790333-456232-1-git-send-email-steven.sistare@oracle.com> References: <1720790333-456232-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-12_09,2024-07-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407120089 X-Proofpoint-GUID: HTQ-eJL4yOmSDO90ENaV7xnBeb0JrbnM X-Proofpoint-ORIG-GUID: HTQ-eJL4yOmSDO90ENaV7xnBeb0JrbnM 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 ecfc16151d61..b8b16dc499da 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -2698,7 +2698,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