Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp240791rdh; Thu, 26 Oct 2023 00:18:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEwR9jOpzmKJihsySy7xK+O0JxATAPWZaLikBRCcK2xjqVuthstN91MdWGUekUmpLLIkfIm X-Received: by 2002:a25:d68c:0:b0:d9a:60c8:c5ff with SMTP id n134-20020a25d68c000000b00d9a60c8c5ffmr17160617ybg.65.1698304693388; Thu, 26 Oct 2023 00:18:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698304693; cv=none; d=google.com; s=arc-20160816; b=d11GGxOQ/hflx+pkZdJoRrmowg72AF9bM5uOKr7kPr8KMyA3oynrCM8rOfd5P4v6Ny m+kuBjBuueKbIHzN1nsA4CEp27Sv9fSmMnoOabmKX+qLpI0GtfMJyTPxFlOhh7S/dcwW so2EJbEWW4hvSbiXuw5Euvo+6g0tvL4hrZd0I6rs+eQueiBzq/CT72VAeKawhr4+USKY P2T+mx6V+1cZf5QAPbbFVMPUbZdcqbKIm7P9UbqwO8lTi1PMaHTJJabsq/UShVkX5Fca rg1obSmWo8/osQMlDAa2jJxOaBrRfx64Ck7qbkijRoljxDf3DUMeqzsCuCyTzGfHIZLq ECaw== 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=rQlggAy4pN3gnMyAshWWZTOLkhIWgVAQ+BfTTFPvYKY=; fh=ozy2CkLebIOzbpPF40kmeuF6jbAmH8vZa/HD/EKOE2c=; b=kY9/JG01BvLkNL8WJChBUTt8ZMYekilyUQQUZm1ZRscJbeWXGcY7LTTGGe1FTi81Hm 1ZJ7Z60NrtiJvCxGOi4aL305H4Hx3Iq1tn2yZa2txdRh7+Kt9r7f6p1ymTZWVeLxUZFY eh3e36VhY40Qj/ZxJ8Ig9SpjZ1EjaAqUJLNtRalW9c/rRICuOFBwdqd/mDDUsC0781p5 XJdPQ/5q4jUp3JXPvPlhXgJfehZ1pt0AegABrsYYn93wCjhPi6EGv4wIaOdz+CE4juRx BHGF4WmDIiLiGXB2SaUq8zxjuyJNJQZvW8WbMYd98zW/rDXCMpU+JM1YJ7yL3zMdW9zR 4x3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=daRW5WBT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id p200-20020a2574d1000000b00d818ac3b1d7si7975267ybc.545.2023.10.26.00.18.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 00:18:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=daRW5WBT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id DF806822742F; Thu, 26 Oct 2023 00:18:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344419AbjJZHRo (ORCPT + 99 others); Thu, 26 Oct 2023 03:17:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344229AbjJZHRg (ORCPT ); Thu, 26 Oct 2023 03:17:36 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 050F118F for ; Thu, 26 Oct 2023 00:17:35 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39Q3lOxJ006422; Thu, 26 Oct 2023 07:17:31 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=rQlggAy4pN3gnMyAshWWZTOLkhIWgVAQ+BfTTFPvYKY=; b=daRW5WBTqGlQmcgY331Z9u0A5CNfagRyBb7fBhI8U7B6p5Jsfa9pCxGlSeZJGyLbR5IG UA/GFeGriJA82tgPblW3DUbEeh77GHsmp6dL8srAhNUgWZqtSux0WgP/BzwT8llilTRQ 59UkcD7Ja5WVP9Z597dnBzrFIwDmdtmOUAYNAs8Uf1F1yRFyGQov3Jnx6HM1h6d18Fc6 D+g9IQQGkjLOrmY7DYdN1Pjv33zC/95mP94f2rjY/bbt7k+4NVpNsdbmwoz8ElbPNI/j 1xc/V3Zry+yHstjSSlvfqAsrEpNeskZyaIwh2p4TtwBXqPUJdl9nFcXwHvMq4wOhRHGu 6Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3tv581tau1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Oct 2023 07:17:30 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 39Q6tbAJ015200; Thu, 26 Oct 2023 07:17:30 GMT Received: from ban25x6uut24.us.oracle.com (ban25x6uut24.us.oracle.com [10.153.73.24]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3tv537t53r-5; Thu, 26 Oct 2023 07:17:30 +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 v5 4/7] vdpa: introduce .compat_reset operation callback Date: Thu, 26 Oct 2023 00:14:37 -0700 Message-Id: <1698304480-18463-5-git-send-email-si-wei.liu@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1698304480-18463-1-git-send-email-si-wei.liu@oracle.com> References: <1698304480-18463-1-git-send-email-si-wei.liu@oracle.com> 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-26_04,2023-10-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 spamscore=0 malwarescore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310260060 X-Proofpoint-GUID: 6_9-eNJDoV-zs31ISSPnoNnTXGyRyCcj X-Proofpoint-ORIG-GUID: 6_9-eNJDoV-zs31ISSPnoNnTXGyRyCcj 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 26 Oct 2023 00:18:04 -0700 (PDT) Some device specific IOMMU parent drivers have long standing bogus behaviour that mistakenly clean up the maps during .reset. By definition, this is violation to the on-chip IOMMU ops (i.e. .set_map, or .dma_map & .dma_unmap) in those offending drivers, as the removal of internal maps is completely agnostic to the upper layer, causing inconsistent view between the userspace and the kernel. Some userspace app like QEMU gets around of this brokenness by proactively removing and adding back all the maps around vdpa device reset, but such workaround actually penaltize other well-behaved driver setup, where vdpa reset always comes with the associated mapping cost, especially for kernel vDPA devices (use_va=false) that have high cost on pinning. It's imperative to rectify this behaviour and remove the problematic code from all those non-compliant parent drivers. However, we cannot unconditionally remove the bogus map-cleaning code from the buggy .reset implementation, as there might exist userspace apps that already rely on the behaviour on some setup. Introduce a .compat_reset driver op to keep compatibility with older userspace. New and well behaved parent driver should not bother to implement such op, but only those drivers that are doing or used to do non-compliant map-cleaning reset will have to. Signed-off-by: Si-Wei Liu --- include/linux/vdpa.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index 26ae6ae1eac3..6b8cbf75712d 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -252,6 +252,17 @@ struct vdpa_map_file { * @reset: Reset device * @vdev: vdpa device * Returns integer: success (0) or error (< 0) + * @compat_reset: Reset device with compatibility quirks to + * accommodate older userspace. Only needed by + * parent driver which used to have bogus reset + * behaviour, and has to maintain such behaviour + * for compatibility with older userspace. + * Historically compliant driver only has to + * implement .reset, Historically non-compliant + * driver should implement both. + * @vdev: vdpa device + * @flags: compatibility quirks for reset + * Returns integer: success (0) or error (< 0) * @suspend: Suspend the device (optional) * @vdev: vdpa device * Returns integer: success (0) or error (< 0) @@ -393,6 +404,8 @@ struct vdpa_config_ops { u8 (*get_status)(struct vdpa_device *vdev); void (*set_status)(struct vdpa_device *vdev, u8 status); int (*reset)(struct vdpa_device *vdev); + int (*compat_reset)(struct vdpa_device *vdev, u32 flags); +#define VDPA_RESET_F_CLEAN_MAP 1 int (*suspend)(struct vdpa_device *vdev); int (*resume)(struct vdpa_device *vdev); size_t (*get_config_size)(struct vdpa_device *vdev); -- 2.39.3