From patchwork Tue Oct 10 09:02:58 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: 150596 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp57747vqb; Tue, 10 Oct 2023 02:07:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5vNsIL5xwBLEXszl0dWsHcZDJd7ROUJgelMy+Ulc3qMb496dBmVknF0G/kFvSI2Z+o/Yz X-Received: by 2002:a05:6808:1442:b0:3a7:6ff5:c628 with SMTP id x2-20020a056808144200b003a76ff5c628mr24134844oiv.11.1696928852202; Tue, 10 Oct 2023 02:07:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696928852; cv=none; d=google.com; s=arc-20160816; b=btbo7+70E84ABMsiG+5OCH7cUVmLrSG3nQl20S032E+bagZYbMghs3Wr0+5WJZ1SzV qUxm1lH3XEY0UbdNI+Qk3+IWiLkXX8iPF7f5oIkPP00mHkxIoNmwwKNe8xoCb5cRBMDM ayrmlWNMF2R15zYFZglYUiTXeylln1xNEa4ZE1/fYDnmaF2VS2viGCht2TFOVJ3tyE55 bW2dKrE3OqyvwD5NllcIWTMPzkf0wMZzPs2Vk9hxJ9wHQ+z+a0KuAyD9orX+laKopQA8 vmdBURYtRvPjKF6cIVshTTnLqlXDS6Z+dPsDjhYQ0YB8nvQdL5e9fVlsqTwznM+zyzHI KYJQ== 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=qu/sS9ZNID3yHvjNcXeEspAM15qF3bafmisnhPGsjhQ=; fh=FYvCndxPQizgygd8hAQJp2i0SXZazO8uVJMWtxk8XU4=; b=AQBQnnflaV4zaznPap1FlX8clzj1q/fZzSL0PMdYNi/To/Z7BEJeYuruQCiGNB9cG7 46IHqpKj03eqdskxKim4lVF4TOduXG8etzQIInEY6PrKnRXuq64LhLfrk+RyBgHzb8np Np+Bgm1vahDoOQb2w6VwGbDVCKfWDB7Ax3Eu2CixVBEfGiPtT+7jr43FtWiWXTxDP6cQ gNXTPOnbBxBzKJRf5/R+ys6Ep0jb8g5oFQ6kdPipC+2I1oZVUrOHWEdFfR8h6NvHKnSU uMKqugZ994LLDf2poXw3Pbkhs0oFO6aPpVlxIjC/7Wxu+R60IHNXmb++kC1+++TFICU1 aj0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=dqPzgY4T; 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 d4-20020a633604000000b00578a44df6c1si11431918pga.640.2023.10.10.02.07.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 02:07:32 -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=dqPzgY4T; 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 021998088698; Tue, 10 Oct 2023 02:06:18 -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 S229868AbjJJJGF (ORCPT + 20 others); Tue, 10 Oct 2023 05:06:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229694AbjJJJFt (ORCPT ); Tue, 10 Oct 2023 05:05:49 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5878A7 for ; Tue, 10 Oct 2023 02:05:47 -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 39A7xYjd002212; 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=qu/sS9ZNID3yHvjNcXeEspAM15qF3bafmisnhPGsjhQ=; b=dqPzgY4Tp0iqzSl72qjlk/AFSBvvW9sKi4q8sOEjDRyjsZjErLwOKLuLftvGSbdB6Kh1 qjT7JpYgZkX2EpkqiPIqRl/SzaLZFf83X41dph0q7GEQoUIomASpqPsehgEZLh9KYlrE rd7CLZAym29NmevKTzK9T7UOgteEFjDxX8woiXLsDZW/QJ0KuZuedWZ8SbBG3b1F/GZi He7nhIJMAxBR6SpoE5HtTEZq6vn4YYXMshSH5icoa7WpeTgw61vnH9ebHvHTO2mlgHgh xAyJ1fyIXMietd7ScqG58m45Y6CSPpapU7/tvlB0iB56oOOD15DgDSzNCjjo6gs5mVBn 2Q== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3tjyvumg51-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 39A6sxrE021395; Tue, 10 Oct 2023 09:05:35 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-3; Tue, 10 Oct 2023 09:05:35 +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 2/4] vhost-vdpa: reset vendor specific mapping to initial state in .release Date: Tue, 10 Oct 2023 02:02:58 -0700 Message-Id: <1696928580-7520-3-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: gxDNOQCin2U6REVSseR0sYShSUBxZDDW X-Proofpoint-GUID: gxDNOQCin2U6REVSseR0sYShSUBxZDDW X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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]); Tue, 10 Oct 2023 02:06:18 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779358868290604037 X-GMAIL-MSGID: 1779358868290604037 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 --- drivers/vhost/vdpa.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 851535f..a3f8160 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;