From patchwork Thu Oct 19 01:10:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Si-Wei Liu X-Patchwork-Id: 155247 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp96528vqb; Wed, 18 Oct 2023 18:13:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH2GkWIVLJ6bc8dfeQQKP5PSIzhjWd66tb0Vohtw/iAYuQ8kMETo+St7xZ03r003R7SlKl+ X-Received: by 2002:a17:90a:1e:b0:27d:375d:c16e with SMTP id 30-20020a17090a001e00b0027d375dc16emr662404pja.42.1697677995384; Wed, 18 Oct 2023 18:13:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697677995; cv=none; d=google.com; s=arc-20160816; b=dul1cdPMQ2DKR0Wc1rVuoGU8I6XrKbn+XSGoSlkvkmWGIkfMzLUt4DMX5j9t9DTdnS iMFj+u2waLwocqDZg/i0MjQ24nJ2brvi8W9lNey4prhKqXRnM2ZyEdvNljIidFEaVzCo fCGfqWFllaLGeUWO2n0enOCXTbW3FrB5XgMisiygARlbmxc3C4Va33Jvur61ROlN3Cwr Ka39FtJyMec+A65jgc3RI+ic333fDK28BuI9rgIX4Y8oVHxkRsicwt1b+P7EWMV+CEOQ Ik/SEHnwwSVNCA4gyF/DGhT1HgDcqbFDFrejl8m9U+qho7U0HYhTrPEXaPzoyLfbGwEm V6Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EDhfB7JA2J6D7sXgXuclzb2hlADtZpOfMMez4ap+xqE=; fh=ozy2CkLebIOzbpPF40kmeuF6jbAmH8vZa/HD/EKOE2c=; b=Q6cS49dVYhkcsJV0qOmToAswkrzy//pN25RzXaRe1ZTAGQb57CTyBEM7zlXGMvp2zJ xuOIN4p99+2rfwqHIfrb7ApWuegvf1fA5zW1aSrP46hZ2aSINC7QsKRftI8iFkOAyjPs tsY1iEaIaQhtt0lw57xH8R9wv0a1OXrvo4h+CqbS7qnwsrj/T9anyyUJKgqrB/yYlK6p vBeWLxsw/q7YlfHbKw/P2VJEnLfX5pwwHeWgfmVVGDKCdQJ+rYpDF53f3vubsPxU2nVe nDs53Lgn29tmMkwVCUMmEM0cAieyM56Aev8/YQ0DEqbI9OdTG9xEAXcyScpNgAoc2B8T rZwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=VlV9zGyJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id hk7-20020a17090b224700b002746ab58dfcsi1114039pjb.18.2023.10.18.18.13.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 18:13:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=VlV9zGyJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 4402281BA647; Wed, 18 Oct 2023 18:13:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232257AbjJSBNL (ORCPT + 24 others); Wed, 18 Oct 2023 21:13:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231204AbjJSBNJ (ORCPT ); Wed, 18 Oct 2023 21:13:09 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C10BD133 for ; Wed, 18 Oct 2023 18:13:04 -0700 (PDT) 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 39IIp6h9018131; Thu, 19 Oct 2023 01:13: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 : mime-version : content-type : content-transfer-encoding; s=corp-2023-03-30; bh=EDhfB7JA2J6D7sXgXuclzb2hlADtZpOfMMez4ap+xqE=; b=VlV9zGyJHTWGOwwYaSB8DBwctBW7zyZeKYccK6N6hsLSNERZWDUskXEEhzakeiuI17St TVvMbzJT9WBlnmybPa1USj0Ytq0przeiMF5bVRkU3Xjbvn4uoeNEnwB3APaB9K0GSmvo mhPQUi/UZQSLKG6MXU5lTnOHqmJTCbrZv3EZqL0LYFm+K/gYkRSOPtr9oSuCpY+GKNPW FaKlzsy+MbojNwuINugPEkqKyuSimI/MM2AXvcljE2gUPBnNnTp927nrO96XNsHiHTOG sERNLAh7I5y4LcRL52IdOiSvsRmSRfkozgXnXaRIpk4zmkW+2kras/phTECPr1FiVAfj ng== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3tqkhu95mw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Oct 2023 01:12:59 +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 39J0UpS0015251; Thu, 19 Oct 2023 01:12:58 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 3trg1h8w2d-2; Thu, 19 Oct 2023 01:12:58 +0000 From: Si-Wei Liu To: jasowang@redhat.com, mst@redhat.com, eperezma@redhat.com, sgarzare@redhat.com, dtatulea@nvidia.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/5] vdpa: introduce .reset_map operation callback Date: Wed, 18 Oct 2023 18:10:14 -0700 Message-Id: <1697677818-11371-2-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1697677818-11371-1-git-send-email-si-wei.liu@oracle.com> References: <1697677818-11371-1-git-send-email-si-wei.liu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-19_01,2023-10-18_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 suspectscore=0 mlxscore=0 mlxlogscore=993 bulkscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310190007 X-Proofpoint-GUID: Yq2AfOlhAYoIBciWxMaPxlaCO_aTQkPR X-Proofpoint-ORIG-GUID: Yq2AfOlhAYoIBciWxMaPxlaCO_aTQkPR X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 18 Oct 2023 18:13:14 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780144401533168921 X-GMAIL-MSGID: 1780144401533168921 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. The .reset_map is not a MUST for every parent that implements the .dma_map or .set_map API, because there could be software vDPA devices (which has use_va=true) that don't have to pin kernel memory so they don't care much about high mapping cost during device reset. And those software devices may have also implemented their own DMA ops, so don't have to use .reset_map to achieve a simple IOMMU device model for 1:1 passthrough mapping, either. Signed-off-by: Si-Wei Liu Acked-by: Eugenio PĂ©rez 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 d376309b99cf..26ae6ae1eac3 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);