From patchwork Tue Oct 10 09:02:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Si-Wei Liu X-Patchwork-Id: 150594 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp57290vqb; Tue, 10 Oct 2023 02:06:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZPyqq/8mKiE2xSE2tVtIkPj7gI9EAhXsIru1tF/MmwzxLE6GxBKv+WeSdB2ttT/UahLSf X-Received: by 2002:a05:6a00:180c:b0:690:d008:8cfc with SMTP id y12-20020a056a00180c00b00690d0088cfcmr19295533pfa.32.1696928786835; Tue, 10 Oct 2023 02:06:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696928786; cv=none; d=google.com; s=arc-20160816; b=fU0Jqu2PlBDgpEdRH0AThFyzVjmqURY66lc4uTPmacICt40JXdk2/0vBxIdtU1TKHZ 2C0WY2S5/1pCTJqnYAFlfksyUjqgOJkDAa+av1KCy3Qg2nWNDuz+e1c4um+X+DM2iVHc 7CxfuRLYemXdKFb4LHNuKGw+VmEDO+4f/FQtC/oIzY110wAyplVLRvUaUtHc6TmlSHoi 69eNYa9GT2zb/e8RnSwjqzMIlJWHBU63KH4Xk3rKFall9TQt1o1Q8ql3iOjJ6yDKs5ZG BzP5io61HYjSOr3uMIOOHys/husMp32kU17SL09Tfgq+0tiRfZ5BAz6+8SNUOdoLoT0J Dr2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=OR1Mg65jkrHjEjNGA3NuJOUmbwtflXaMlM5D2J5Mle8=; fh=FYvCndxPQizgygd8hAQJp2i0SXZazO8uVJMWtxk8XU4=; b=jfBfLttcRnok0FJEXXGAVcwzWB+9TPu/1Hzeq/1fk3escv6Fpmhb2wMNBVQg6cN3oH XiM3Ruesx7Cf6j0AlmJIrcJOPHcFDFYakeLnC9aIPDjGjzAuNgQzxOzCk5Kh1FBxTabL beM3EHf0axwb41c7r4KkLxx2QBdeSWig7vh5VT2eHiTj5TDoG3PFmUSaieYwr0Jw2Ajn /JWNCFOGDdF7L71uLtq45hJIocQqrmnswCAX+TX9hwLEGGGYeiOWVWINoUJYmZcppi1K 8kpCHhviHtxDQnUb57nVoOc4Ff4u0V8RvztmRO3C2E0uIaDk9YtAgW+sloleY8Awh96e 1F5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=XQV0JY97; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id bs70-20020a632849000000b00565f182839asi11241196pgb.28.2023.10.10.02.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 02:06:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=XQV0JY97; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 8C7DC8329A90; Tue, 10 Oct 2023 02:06:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229775AbjJJJFs (ORCPT + 20 others); Tue, 10 Oct 2023 05:05:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229516AbjJJJFp (ORCPT ); Tue, 10 Oct 2023 05:05:45 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28042BA for ; Tue, 10 Oct 2023 02:05:42 -0700 (PDT) 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 39A7xm4n017321; Tue, 10 Oct 2023 09:05:36 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-03-30; bh=OR1Mg65jkrHjEjNGA3NuJOUmbwtflXaMlM5D2J5Mle8=; b=XQV0JY97HpvsePs8RzztkmT4Rntm8557ItgXjVdFiahdkGvMiaAueu7oH0CdgzBjqzfy XkYGZVUUZ5STP1ERL8xA7L/vUKAeB9llQ64o+AFdpP5wl02QfEx55Mo0m2NW0GAaupo6 V9QVLG/XupAz6ESMzyr0BDDjRqw4y9jnx4mpndZXQJjqFGHJ8y4NpqlZa7jfvEliJunS i7LQlKz39eSHcDtLEGC/G8rE8gyGiJaDDAqBrk7rgSBCEJIEbmz/V+5JOCZAtA+3cDG7 4B1SfvxEnf1ZySgR8aPmt5TAhIglEuHC9fgvbwP+ePzt/YF8GiUd1O0mFTB+nXv+1nTq 7w== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3tjx8cck9a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 09:05:36 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 39A6sxrD021395; Tue, 10 Oct 2023 09:05:34 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3tjwsc5cy2-2; Tue, 10 Oct 2023 09:05:34 +0000 From: Si-Wei Liu To: jasowang@redhat.com, mst@redhat.com, eperezma@redhat.com, xuanzhuo@linux.alibaba.com, dtatulea@nvidia.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] vdpa: introduce .reset_map operation callback Date: Tue, 10 Oct 2023 02:02:57 -0700 Message-Id: <1696928580-7520-2-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1696928580-7520-1-git-send-email-si-wei.liu@oracle.com> References: <1696928580-7520-1-git-send-email-si-wei.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_04,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 suspectscore=0 malwarescore=0 adultscore=0 spamscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100067 X-Proofpoint-ORIG-GUID: 2nX3W0JHB2ZaF5l04tF0rfaY7HthgzBa X-Proofpoint-GUID: 2nX3W0JHB2ZaF5l04tF0rfaY7HthgzBa X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 10 Oct 2023 02:06:22 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779358799285890919 X-GMAIL-MSGID: 1779358799285890919 Device specific IOMMU parent driver who wishes to see mapping to be decoupled from virtio or vdpa device life cycle (device reset) can use it to restore memory mapping in the device IOMMU to the initial or default state. The reset of mapping is done per address space basis. The reason why a separate .reset_map op is introduced is because this allows a simple on-chip IOMMU model without exposing too much device implementation details to the upper vdpa layer. The .dma_map/unmap or .set_map driver API is meant to be used to manipulate the IOTLB mappings, and has been abstracted in a way similar to how a real IOMMU device maps or unmaps pages for certain memory ranges. However, apart from this there also exists other mapping needs, in which case 1:1 passthrough mapping has to be used by other users (read virtio-vdpa). To ease parent/vendor driver implementation and to avoid abusing DMA ops in an unexpacted way, these on-chip IOMMU devices can start with 1:1 passthrough mapping mode initially at the he time of creation. Then the .reset_map op can be used to switch iotlb back to this initial state without having to expose a complex two-dimensional IOMMU device model. Signed-off-by: Si-Wei Liu Acked-by: Jason Wang --- include/linux/vdpa.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index d376309..26ae6ae 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -327,6 +327,15 @@ struct vdpa_map_file { * @iova: iova to be unmapped * @size: size of the area * Returns integer: success (0) or error (< 0) + * @reset_map: Reset device memory mapping to the default + * state (optional) + * Needed for devices that are using device + * specific DMA translation and prefer mapping + * to be decoupled from the virtio life cycle, + * i.e. device .reset op does not reset mapping + * @vdev: vdpa device + * @asid: address space identifier + * Returns integer: success (0) or error (< 0) * @get_vq_dma_dev: Get the dma device for a specific * virtqueue (optional) * @vdev: vdpa device @@ -405,6 +414,7 @@ struct vdpa_config_ops { u64 iova, u64 size, u64 pa, u32 perm, void *opaque); int (*dma_unmap)(struct vdpa_device *vdev, unsigned int asid, u64 iova, u64 size); + int (*reset_map)(struct vdpa_device *vdev, unsigned int asid); int (*set_group_asid)(struct vdpa_device *vdev, unsigned int group, unsigned int asid); struct device *(*get_vq_dma_dev)(struct vdpa_device *vdev, u16 idx);