From patchwork Tue Oct 17 00:39:55 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: 153835 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3816087vqb; Mon, 16 Oct 2023 17:43:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE8d5mnn2QshkEpdzoscogxWHRkwwypYizlhDY3z+kRfIiWFkEgQm55pk5UTCuLbh+E9ftf X-Received: by 2002:a05:6a20:ce9a:b0:16c:b95c:6d38 with SMTP id if26-20020a056a20ce9a00b0016cb95c6d38mr634383pzb.2.1697503387747; Mon, 16 Oct 2023 17:43:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697503387; cv=none; d=google.com; s=arc-20160816; b=aSMxQPTZccYwazhzbKaFKGLcOrOftSrGkCPqoR5rrjxJsGLhA0ypSTJP731gXQVTWF P+ycOH5XH2nF6f3HWpHPCcl6YFCMc0CiInFL0EEqG2Jm9yuZpzFgKgEPp7dLsNuIU/hA aWIr7027AnE/x6gfNO/+hlbKVehPGT+uMpZr5cVWwEHS5DtEY3U44Ri4hpmQYQW+6eKx CPlRyGkkDgV+DPfxpm2H/9C9/P9YvsoQr3rCpAUz19k/XIkWuLg9h20BP5wb5VXc0a5o mtUWHNpUlGTrxtzUkqv3WcJkKTBGuZZG6iudgXTIelVli3iu1EZq3aJl45hm2iXvfthM FifQ== 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=IDcJMsPyKM2GyU6ZB9/xv6m5PTlDgNod8sH4SwkNOK4=; fh=oDOqP7sFVfy8hE2JW+RNYDdlQLyeIHOxyj9Z/wRrGAI=; b=KJSkYxzlW8nufd/Nv/+m01a8khhrXOMOggZ9xjdeNQAQKxzJOmPQ55mZtFtHFbmpOY 0QxzbLBjaAbBJJbJX4ulXFphFyEXOwEwlpMGvgU9cJYfLXS90TA6nYqT4cI2Z+iuR7gw IGTau4FU9gj+keVqMXj9WEc0j2u1Jfo5l4jIW0p2NNjNgxjX9lWNsk++s8HavjgYq6XS Ldtcj++FUSKKh3iUYitau1ztKgJLp8Cq4ni/1tl+66mssizmoC570uQptTINLHLhMfwc mM4Po791ezn/PJpBOR8dESkWBrJ7IXK5P3aYhLO057pkPx8ICPtpGOeSTBDOj/RJgQk0 n4Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=IekHjyXE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id 192-20020a6301c9000000b0059ff7c499c8si509224pgb.746.2023.10.16.17.43.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 17:43:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=IekHjyXE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 2E8E68041EA9; Mon, 16 Oct 2023 17:43:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234264AbjJQAmu (ORCPT + 18 others); Mon, 16 Oct 2023 20:42:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233634AbjJQAms (ORCPT ); Mon, 16 Oct 2023 20:42:48 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B51B0AB for ; Mon, 16 Oct 2023 17:42:46 -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 39GKO4wl027744; Tue, 17 Oct 2023 00:42:40 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=IDcJMsPyKM2GyU6ZB9/xv6m5PTlDgNod8sH4SwkNOK4=; b=IekHjyXEpcAYb1ceZF8zo28I0mdCseO++R85dOjDSLbZnbTsRhb4+fpjmAS4fCNykMk0 vYgKBoRiA846OIpdDKECrwawdAKrZfE3QsoBw82IMSGePiX2aF2acIZ7yozO/xnvWgNA d/pbgMTC7b1XBxMM231CJJbRcXjekXV9ZC/TcVgodYyWRIdL7bFOB4apOEBUcBUbGtYN wUaiR3q1UfzW2YHcDQrBqmQoyoQ+4HNUusaRgLL8OAU/HpCj7ZEhOTnWp681q/yZiuMZ GV5neI1FH3lntyoAyk7iKDBHGQkSaT3KAEKPgKHQMuL2eVBkTshahlRoMtuc15UQ2YBS sQ== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3tqk1cc1s5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 00:42:39 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 39GNB27J027141; Tue, 17 Oct 2023 00:42:38 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3trg535bja-3; Tue, 17 Oct 2023 00:42:38 +0000 From: Si-Wei Liu To: jasowang@redhat.com, mst@redhat.com, eperezma@redhat.com, xuanzhuo@linux.alibaba.com, dtatulea@nvidia.com, sgarzare@redhat.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/4] vhost-vdpa: reset vendor specific mapping to initial state in .release Date: Mon, 16 Oct 2023 17:39:55 -0700 Message-Id: <1697503197-15935-3-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1697503197-15935-1-git-send-email-si-wei.liu@oracle.com> References: <1697503197-15935-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-16_13,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 phishscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170003 X-Proofpoint-ORIG-GUID: 4TVzLTo0akgalRbDmG5s7ktKewo1HLu_ X-Proofpoint-GUID: 4TVzLTo0akgalRbDmG5s7ktKewo1HLu_ 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 agentk.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 (agentk.vger.email [0.0.0.0]); Mon, 16 Oct 2023 17:43:05 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779961312658467154 X-GMAIL-MSGID: 1779961312658467154 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 solely manipulate mappings by its own, independent of virtio device state. For instance, device reset does not cause mapping go away on such IOTLB model in need of persistent mapping. Before vhost-vdpa is going away, give them 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 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 851535f57b95..a3f8160c9807 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,13 @@ 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 is not done + * through device reset, as the IOTLB mapping manipulation + * could be decoupled from the virtio device life cycle. + */ + vhost_vdpa_reset_map(v, asid); kfree(as); return 0;