From patchwork Sat Oct 21 09:25: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: 156417 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp199346vqx; Sat, 21 Oct 2023 02:29:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHby8rvqwl8VX8UffHGm/Ede+7hfsZ4SmCWo2yp2S9L14VYYM2k/pyF0jKRymRQMRv3+Py6 X-Received: by 2002:a05:6e02:1d07:b0:345:d58d:9ae5 with SMTP id i7-20020a056e021d0700b00345d58d9ae5mr6125407ila.7.1697880579029; Sat, 21 Oct 2023 02:29:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697880579; cv=none; d=google.com; s=arc-20160816; b=OTCgQR+Hq/Y0IedoqyyIsnnSDMZwpOXXiDk523H8jx1gGfJWOpT39NtYvDFpVm6DMz bs0L4OJ7HvKpTXTvMLowTvqzwLFDbpHGCBKXFnB1BGhz5oLxOfJnIW011rB+C0BgBPC+ TwIq6CYgkwReCikq1o0iDeBv/0ktHlKksNaWpWhrduf2/1dz5tLL01lR2nNV2prCJRbe D4qXOVQSiroiV58hii90lfOMvwRy4GXIGA6gRdXuKC8jKVgKhwnzyPWkcpWrf4t0AlrG kZvEHEZ3PNvJd0dFVCokVLDwnTiBRZjrEUJThTtoSwW2hLbcMbafGD+mWg8qlbEnoRXe GEVQ== 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=XMke14vYG8UhRAuK8/FbiZ7AEIT4nF/4fIUeZ85zpTE=; fh=ozy2CkLebIOzbpPF40kmeuF6jbAmH8vZa/HD/EKOE2c=; b=TnPP/0KwJBr2EdZ/ZLYjF/AekNnkvVM/JG4gqbY0pwbAS0yi/o5tzHKDdJWsYYm2qO /obR9agtK04//Z8pIL2ZsZDbsUGyxb0C8FSBIUkre/edTdWc68B2K9lOjvN3K1QW+Tjd ffphq5AOTZ6/As1bqU7nrqVlzqrtdklfba8xCJ/VQWpUzCXaLZd9biNC4WuMgqoeEJc4 dS3PCozO9QoDhxxd+eU5aMmQObJlnM7Mbq9yQjQ+isqCLSj7/PgCcuIdeWzMTumwqr9F 8xzO1Xyn8wFgKuqIjPQmWTjeUF9FKg5lu9bCraNEVoiN6PeJx/sf4lKch/eiGIE4ZsN+ HXgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=fzHvb7F5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id y7-20020a170902b48700b001bde9e8a29fsi3139370plr.183.2023.10.21.02.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Oct 2023 02:29:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=fzHvb7F5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 93F1B80F4E22; Sat, 21 Oct 2023 02:29:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231216AbjJUJ2s (ORCPT + 26 others); Sat, 21 Oct 2023 05:28:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230218AbjJUJ2e (ORCPT ); Sat, 21 Oct 2023 05:28:34 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EA96D76 for ; Sat, 21 Oct 2023 02:28:31 -0700 (PDT) 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 39L5Oo6K023901; Sat, 21 Oct 2023 09:28: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 : mime-version : content-type : content-transfer-encoding; s=corp-2023-03-30; bh=XMke14vYG8UhRAuK8/FbiZ7AEIT4nF/4fIUeZ85zpTE=; b=fzHvb7F5SlWoKTdm48UF9vUnpOg2SDxFkTj/7mL1TiWElm5CaZIxELBDA6dXZzK0B31o gAlBlUyzThzC6oCzc1tlXqJ85EtinOOukGM+eCYPUmknLySWNJT6XznPgdf7Q2dNaudW l7ea2C0USn9pkZYg+nBDMytNgGZdioticg1uukqLOOcMVncWgaaJC4+zf3TOVkI66/Ht 3psvPOEqfOy3cvod9wnyXelOpkP66E1mEKYcAO3MY7ZoKuDWDSfiLlxJN17GcheQGfsF AxxhFjNYrA5M1/hIAPLqHUyln5lljK0MsK/Kq5gml00izyE+BV5Gh3tg3y0g01MroHPA 1g== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3tv6pcrbv6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 21 Oct 2023 09:28:20 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 39L6FU6E019120; Sat, 21 Oct 2023 09:28:20 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3tv532gf44-3; Sat, 21 Oct 2023 09:28:20 +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 v4 2/7] vhost-vdpa: reset vendor specific mapping to initial state in .release Date: Sat, 21 Oct 2023 02:25:14 -0700 Message-Id: <1697880319-4937-3-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1697880319-4937-1-git-send-email-si-wei.liu@oracle.com> References: <1697880319-4937-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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 bulkscore=0 mlxscore=0 suspectscore=0 phishscore=0 adultscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310210086 X-Proofpoint-GUID: PZpPIxEzfvIjigMl35SlSAAYSgzW_BtQ X-Proofpoint-ORIG-GUID: PZpPIxEzfvIjigMl35SlSAAYSgzW_BtQ X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Sat, 21 Oct 2023 02:29:36 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780356825866047241 X-GMAIL-MSGID: 1780356825866047241 Devices with on-chip IOMMU or vendor specific IOTLB implementation may need to restore iotlb mapping to the initial or default state using the .reset_map op, as it's desirable for some parent devices to not work with DMA ops and maintain a simple IOMMU model with .reset_map. In particular, device reset should not cause mapping to go away on such IOTLB model, so persistent mapping is implied across reset. Before the userspace process using vhost-vdpa is gone, give it a chance to reset iotlb back to the initial state in vhost_vdpa_cleanup(). Signed-off-by: Si-Wei Liu Acked-by: Eugenio PĂ©rez --- drivers/vhost/vdpa.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 851535f57b95..c6bfe9bdde42 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -131,6 +131,15 @@ static struct vhost_vdpa_as *vhost_vdpa_find_alloc_as(struct vhost_vdpa *v, return vhost_vdpa_alloc_as(v, asid); } +static void vhost_vdpa_reset_map(struct vhost_vdpa *v, u32 asid) +{ + struct vdpa_device *vdpa = v->vdpa; + const struct vdpa_config_ops *ops = vdpa->config; + + if (ops->reset_map) + ops->reset_map(vdpa, asid); +} + static int vhost_vdpa_remove_as(struct vhost_vdpa *v, u32 asid) { struct vhost_vdpa_as *as = asid_to_as(v, asid); @@ -140,6 +149,14 @@ static int vhost_vdpa_remove_as(struct vhost_vdpa *v, u32 asid) hlist_del(&as->hash_link); vhost_vdpa_iotlb_unmap(v, &as->iotlb, 0ULL, 0ULL - 1, asid); + /* + * Devices with vendor specific IOMMU may need to restore + * iotlb to the initial or default state, which cannot be + * cleaned up in the all range unmap call above. Give them + * a chance to clean up or reset the map to the desired + * state. + */ + vhost_vdpa_reset_map(v, asid); kfree(as); return 0;