From patchwork Mon Oct 21 13:40:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13844168 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2066.outbound.protection.outlook.com [40.107.94.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F2E411185; Mon, 21 Oct 2024 13:41:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729518077; cv=fail; b=ZOljvh0ofaR3Rrvs3TY8BIi5XL8l3I9MOI82exMiC4kfAJUZRWK802Yp1m2ua6DzFxIWERNzUuqI4CU0hJrPgDT2fdjyLYb/wl/oa0SxGylhYi5+8FoAcadR+HWcaWBhKeelREAwNho0pWunpvzAN1q3wZtUl2N5c+U5OlD6KlI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729518077; c=relaxed/simple; bh=Rf1RHoaCf/6Na474D6SyfsJ9wRZ5SBLjPmdsEE8j3bo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jUzfTeeyOmyj8l5B/EMCQpN/4iV0L9ScTvOjktNYcHPHDUH1XcvnqPERgoawGdob12cfXZPC4uICd0wQ9j/gRP8rqbdSJAOqSsLYSclofhXu7Lq+ljx2V4+rBKrjSPTEZ4/lx5sjr9c0NNxxWYyEY3U80rf2jGXNZiOckUq8xyI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=FNUUdWDh; arc=fail smtp.client-ip=40.107.94.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="FNUUdWDh" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=irQJ/aNR9Bnz+QqglvKnOb/yGe29gPQya5JjTRuHPeZ5TkctqCC/w2M20R5Doqltq7PNim91rvO6jUeGokaPiKEUvfbOFHIxplgE2qdyNyeut8sMKUOx/osQBeb3kajncJtOG9sLSNCdaJ6jU5B8mx/zi0nnpMD/PlxKjUKM2CvXzN4KCLg1ueIRBz896KVA1mLaXfm5Ii/edre7xJ0JMBbDqZDG+82X4L3sUzpnjSCQC8hTwXqdXSt8Vzz1i+qdCT5gf5kHZyjBt0VB1lnyxVzUkq5xI1XMmeFCD0mpZ/7UynkI0pVmoKxfz9yUJQ/XfO8PL7hLcXHxqJFtnUIcqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jDNjLU02G8PpOuJ6Z9jxPjx5558biv/L88IuCeaadmo=; b=UpD0NPVcigooKU4CwljZ9m8/8Im8YzHReyaAuc2bMelOo5nEcJ0KCLxDzQdb3YIdM0QGShmhM0eoDvB3l5RY3qLMQjYss0pZOEQ60sfJSZwlCw0U0gKCj8DKPtfNTd7FUsYcdHt+C9fhL2lowAAtY6X8QNBJb1z51jxtr1wX0gp8HpyiLrra7mVpJdUMKWi3/qGpxTtE1YWj7vBCLP+MM1q/v1T6xdsBgmwqYjBSqq3OEgmMldnlnoo6UMxSNSK2Uj2hrMZDl4g9aaPa7yRKWlyMyg+ZPLTsiskJT5YOmnR1QJD+ojW+neRonW9Duq0UzK+kNt4859cMCszJXpfD+g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jDNjLU02G8PpOuJ6Z9jxPjx5558biv/L88IuCeaadmo=; b=FNUUdWDhIWgU3K9TC5nMaMO31UqU4hhhXZtGP0YWiw6UF+5tDmuTil77FFtQka7BhXa20c29qn8II9pBIJbGq6LeCQMn3K3qHDoqWCXPu5XA+eLS+ZwIc3yPGb/5IlzUGdL+tz/XtsybWdmxNDQ5+9xitIWbG8WUrJG5445WvOp3kVytd08VQF4BgDEwOhvmLzuSCCBCqMgB1nAQFMgSZh7rrhBRDORmbr29V27hxRTrF8cgfpQHZRc5I1bloKlKQHFLK5wCihHN9KAgsRqS4J+PX7SJTfhTCsEHbCRSNqCjwywVCG7h/4LvXVMyfsgNxqT8uGgZzjZ/5LKYPObWkA== Received: from MN2PR04CA0026.namprd04.prod.outlook.com (2603:10b6:208:d4::39) by MW4PR12MB7263.namprd12.prod.outlook.com (2603:10b6:303:226::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Mon, 21 Oct 2024 13:41:12 +0000 Received: from BN2PEPF000044AA.namprd04.prod.outlook.com (2603:10b6:208:d4:cafe::7c) by MN2PR04CA0026.outlook.office365.com (2603:10b6:208:d4::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.26 via Frontend Transport; Mon, 21 Oct 2024 13:41:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BN2PEPF000044AA.mail.protection.outlook.com (10.167.243.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.14 via Frontend Transport; Mon, 21 Oct 2024 13:41:11 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 21 Oct 2024 06:40:54 -0700 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 21 Oct 2024 06:40:54 -0700 Received: from c-237-113-220-225.mtl.labs.mlnx (10.127.8.12) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 21 Oct 2024 06:40:50 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , , Si-Wei Liu CC: Dragos Tatulea , Jason Wang , Eugenio Perez Martin , , , Gal Pressman , Parav Pandit , Xuan Zhuo , Subject: [PATCH vhost 1/2] vdpa/mlx5: Fix PA offset with unaligned starting iotlb map Date: Mon, 21 Oct 2024 16:40:39 +0300 Message-ID: <20241021134040.975221-2-dtatulea@nvidia.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241021134040.975221-1-dtatulea@nvidia.com> References: <20241021134040.975221-1-dtatulea@nvidia.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044AA:EE_|MW4PR12MB7263:EE_ X-MS-Office365-Filtering-Correlation-Id: 66cacbac-bf91-4b5b-a6f3-08dcf1d606c4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: TP7Z3vVDh6hOFfgoWMpl26eN5qCmdSfp943kCNlmkHEt3qglS2rwKhIywyWVVxjM5Qf+R2Fjz+/8QJbSiC2acdrKyZhhQwVJU45FnidzQYw8HJFyTQpBJgLspFzsHJt5MPxZrInvFpI7tsw8+hPF2BXdoRkve2UB+PwiCz4IFf1IoKYSoQx5lDDJl3prgJi3+gWwnSkBJ7oCrcV3vQF7F6wbw/Pr5hpm+/kuE2EUTZmT74R3rLopgR/D3AwgaZvxP79RadO+hRgPQi2aww24RaO3IDmVnpk8LXU4AdGwsZZlD2OJNkLVrFCdAbvTytM+l3ODLfhk3DwjDmTVy3gPB579fAgui85iTCLfvQq/ATRoF2tLu65S1QtfkN+Tf5EbZ4/nPXzSiAAUUYZmMBegtyIzIdmMe3G3IcGDnmwQ40dwRkIbSKSKcjiPsRoxqy3ysmTMVfTZIUh8zvI9jtYSDihN1heVEZ5odFuYMnuqNnYnNl/iKQFgzCtpOLeFpNa+0mZUk1ddseh99+SmQSqL1S3Oz47FYc8VszNZQIs7B4dePPE7SqR4Aim99a6HBMeUjI3mLxZyHr4cNlMWmmcp36u1zlULlHj2xNZ2yTeSuK4MhT7vEmNNX240gp+coPFjVpTAvXvyXrDrDKS91+tshqpL7x1d+K8my5jTiZ8SmcqFcllBvx4hnOd8lygFCqamBIuDWJUfkMP3gKmaWNzuR5dtaAnu7yxWM4rulC87c5HeyrobpygWP0HO2SIr+uQBHsN+7p0mH/A+DCX/tIQ4d+U8HAuquWISh7+82sIoMfZhgbgbhDntENoJ9rwpgco4SaJifw8Id7X4WYkqDV6rTAzVrd3ymZCG6ysxdV99nSHY194lM6eX9LG65yj0+LJUQc44rdL0FcNmSA2JsyTtaFF8N22P2av4Gb5Trfgi6SayPQqT+y59eVOclD5HtTqtYtFv7Cpkh6L7M7ALk9AcfzFERJBYlYVpvbC5NqAoxn+YfrPogCH8URtz307E1qNy6idRzJAcZoAw+yzCP2o1XwO8+qIEwJck9vem52f+GLgPyf/9+vzV3Bq36HcxyIKOuz+VP96AcbzRJ7iZj4QL7crMlWMwD4GpJ3Pj5pZZeWeLIE8yg9fOeusmMfZZw6duUB1nvGNh+amJDSyEBEdHHV77xxLP958ZUkdpopepUvEPLAHw8ZaTPvf6MLbZS6WOsxpXQy5iNdsIx7X+3iDgnD94CRUY3obk/9UYDSC8n1jdXu6pVqzCyyr1AQKe0GPUjUt+kEztI8yYRG08dmzXR/yrjalUszC7yu4wlvonHngu5vnxOx9fXuZG+NXLjeX3OQycFN6X6pGrxm9/pHuQfmGhoZv39MYARRmSIg9PWObN4egtemKtdW389NLhwBY1B8eb+c6/wdisyBw1tswRhw== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Oct 2024 13:41:11.6583 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 66cacbac-bf91-4b5b-a6f3-08dcf1d606c4 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF000044AA.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7263 From: Si-Wei Liu When calculating the physical address range based on the iotlb and mr [start,end) ranges, the offset of mr->start relative to map->start is not taken into account. This leads to some incorrect and duplicate mappings. For the case when mr->start < map->start the code is already correct: the range in [mr->start, map->start) was handled by a different iteration. Fixes: 94abbccdf291 ("vdpa/mlx5: Add shared memory registration code") Cc: stable@vger.kernel.org Signed-off-by: Si-Wei Liu Signed-off-by: Dragos Tatulea Acked-by: Jason Wang --- drivers/vdpa/mlx5/core/mr.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/vdpa/mlx5/core/mr.c b/drivers/vdpa/mlx5/core/mr.c index 2dd21e0b399e..7d0c83b5b071 100644 --- a/drivers/vdpa/mlx5/core/mr.c +++ b/drivers/vdpa/mlx5/core/mr.c @@ -373,7 +373,7 @@ static int map_direct_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_direct_mr struct page *pg; unsigned int nsg; int sglen; - u64 pa; + u64 pa, offset; u64 paend; struct scatterlist *sg; struct device *dma = mvdev->vdev.dma_dev; @@ -396,8 +396,10 @@ static int map_direct_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_direct_mr sg = mr->sg_head.sgl; for (map = vhost_iotlb_itree_first(iotlb, mr->start, mr->end - 1); map; map = vhost_iotlb_itree_next(map, mr->start, mr->end - 1)) { - paend = map->addr + maplen(map, mr); - for (pa = map->addr; pa < paend; pa += sglen) { + offset = mr->start > map->start ? mr->start - map->start : 0; + pa = map->addr + offset; + paend = map->addr + offset + maplen(map, mr); + for (; pa < paend; pa += sglen) { pg = pfn_to_page(__phys_to_pfn(pa)); if (!sg) { mlx5_vdpa_warn(mvdev, "sg null. start 0x%llx, end 0x%llx\n", From patchwork Mon Oct 21 13:40:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13844169 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2059.outbound.protection.outlook.com [40.107.237.59]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF9D31F8EFF; Mon, 21 Oct 2024 13:41:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729518081; cv=fail; b=ZXZm8F2WOc0V+oEoDV/GGEq5nxId6Yi9OaHahBaQZVA+u+86E+JdGwzdgZPIWKGYGO2wVvknJtVpd4oW9M5llvonkj3CtPKQNWbGqCh+YRtXyaPxZZumQ3miCs79EHLqW8n9cOD4+nq74Hd3VR9aOPkuqPVxNqv5LmhEhfx8e14= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729518081; c=relaxed/simple; bh=xrRRikhqvPyy5Vv3acnh5jRxnJ3CkacGq4Xq8EZdx9I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=evdq7Fxtq41rFqHZjwJv6GvqKno81J/UvSDYEMtXwLAk3D9bXuQmdj6qDT3szPjT5yrbQdkmvFd+hXZKFNXLeekMbDV29hbAbYQUjNeF3t9Oj5+VK3qjEbITfgP4sPCzxBqO64UVXFSp2aqPSXtVtTRpTDCcZt3AqY/0nqEfa9k= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=KxTN4t4l; arc=fail smtp.client-ip=40.107.237.59 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="KxTN4t4l" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YftiulqBK2KYyjD+cpxMvZkRkY1M2GirEQQf7jCOdRLXkgry/fVDjPPEOMuEOpqUm6lJjJzQWC4HTBxs+29B1IKMKboZVdMvHkzkywddFiBNH3zIfuouGdi5+quk4mxFWQPqg5p7euspfg+5/hK2Io/SUczys2fpk5jRuC6m/PAc9wj8mIkoFmMgndpUDLLT8A7xvJInYvHkkwdwCFrsBoRsLJ8m90BUy+eUM6t4d8eCSqlrSvzDWZT9FPTcdG8wwZAzhrXeBQkniEHPx3Pf8GMjEJSsVrND5B+tUmHjS3LDAsMUHCsLYku7T78nLlEU8VKBQiUU+l0PmLOrdNKQVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0HdS+0ODh3Mj8EkgoOiXEfHPfYf4+5ZG7Xpgrtzf08g=; b=x20h7XOMrZe9v7C44qPrRsNMuz/x7vg5nSw3aK7SeoGejfZ/PBQcMS3eiTlJNz0oAvhY0Fnwc3s4Cs+yeTfB9BsrZmtVk0aTEQ6YVk3UgM20PkN8Iv6dsbQi8yt9a+BigkB3hPFb/RRphkzwkfcfzO3u9HXwCb1nDyghdk2HTVhkFUeD/qTfzhWd67/+hlPvJzWYrMtnUMWtB3vpYqVO43BBDG4R/AzS2XCsCso+kFxtqNuhXwnliRzd00EV2c9JhS+h/ncCgqmft2K6EltsbLSgmaG/aJLybd1tcnTYhOx2jb2AVs6AvFzwQLKmxrwUgR/CqA87ryRFbLWqhn7kGA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0HdS+0ODh3Mj8EkgoOiXEfHPfYf4+5ZG7Xpgrtzf08g=; b=KxTN4t4l5/TdvLp5hOmpVjkQwaT6PuYNoS3ChZK6GqzmI17u1CQV8DvgG37jHGT2fH1GrJqHz8ev7SjU1i31j+WsQCiI0NjeK8hUvdZeeb1+P4S6zHRVsB/Y2bPef8HRLkSE5/bZs1x8POuIDj7FBTmNOCoFND/aKDNFBT0q6jzj/N1c+6w0LHBSJs7L6gE+8Bp0WfcmL/RMudO29xjaPX2FwfFAcCAzirtWN8HX+9ayRoAqFLwT42oNncwSfXIPlMxnTCVIVpaXIuspf2dopdPXq78xpTVrELtNSXrZK+lUTR936/DEjP2mFoLjm6CqIjiDENyYNuNgd1FVShElEw== Received: from DS7PR03CA0288.namprd03.prod.outlook.com (2603:10b6:5:3ad::23) by DS7PR12MB5792.namprd12.prod.outlook.com (2603:10b6:8:77::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Mon, 21 Oct 2024 13:41:15 +0000 Received: from DS3PEPF0000C37E.namprd04.prod.outlook.com (2603:10b6:5:3ad:cafe::f5) by DS7PR03CA0288.outlook.office365.com (2603:10b6:5:3ad::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28 via Frontend Transport; Mon, 21 Oct 2024 13:41:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by DS3PEPF0000C37E.mail.protection.outlook.com (10.167.23.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.14 via Frontend Transport; Mon, 21 Oct 2024 13:41:15 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 21 Oct 2024 06:41:00 -0700 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 21 Oct 2024 06:40:59 -0700 Received: from c-237-113-220-225.mtl.labs.mlnx (10.127.8.12) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 21 Oct 2024 06:40:56 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , , Si-Wei Liu CC: Dragos Tatulea , Jason Wang , Eugenio Perez Martin , , , Gal Pressman , Parav Pandit , Xuan Zhuo Subject: [PATCH vhost 2/2] vdpa/mlx5: Fix suboptimal range on iotlb iteration Date: Mon, 21 Oct 2024 16:40:40 +0300 Message-ID: <20241021134040.975221-3-dtatulea@nvidia.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241021134040.975221-1-dtatulea@nvidia.com> References: <20241021134040.975221-1-dtatulea@nvidia.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37E:EE_|DS7PR12MB5792:EE_ X-MS-Office365-Filtering-Correlation-Id: 4122f495-1e9a-452f-1586-08dcf1d608da X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700013|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: ZStn1M40ojNvQEqli+4vNg8522gIXy70ceu5E2pLIrOs4SZ6XRa4QdByJiga/pZC/rMHTeuJWiWqaJ1xNu9q07yhvb+QEbqptELxIJLoeTO0vF7s34jFmvcseKV3ldWpfA/LOTVALDqk+DpOYc6E33qfXAntjqkEru5dPPvsQ44RyohBnuwMDXbkcvil5DeByg0ZbN+Mey3dzXZB1s6AKsWINb6HWJGxAU/7rdCiSpt2DuBmyVfhYHdrbMQDQ20MCpVUHFXMvWj/nIRBvtCwSNmN3PZZoCjBxYyupjWxJ2mKrzaJX6j6CMUoL5V+OqHTVuB5zidb/vqMnCNVzjlTTOzbNJE6NjXV8/3MC4AGrqdFgDyOgL1v6AUQ51WbvpTOa6TmfoUT3ZQiEehQWtWFCGWPnPf1bwT0ci02MwJmDYbZlNI/LM6faNHgbjG+eBnWgs+P3Bp8EjiMzgzIVVQc/o9/YFeJe2nQNUMjRCq5hmEZsEBVN4jrWL0fNtWz0pWeaeRFGOHbEgzyzZ8IIv3esGFJa34aTBWK7P9ZdIWy+Zd1N2ogwnairJQOUnMnV3MQIDMaEitm2ylHV7asr3MCDhlNDCKduP8BH6kYh4LlRqpCM6WwX31vgHV707H0wMk25ncpy6r4ypNeXSzvzXqNDKUQblqoFlsIT3dmqdYiZPRAJuO/5nl9oNgJbAzfM0fzfXzU/HmAFzXGSog6r1dedvC1szleWMqPJyfVCvTtVv8LoP9lqbf/WjbuagoN+WBvXeypGm2Lg0vNCb80AOKy5aHM4Pzk0EXGH1knZFvFW1b9E1RzRcO1AzNiPocjX2YtTfYujde7pt8eZ/pI0UtD64OvEgHLKQXLKq86sReTyBZ3/Dfd1JnE+lD9Gyp55KBIKo5M3TaEBSf16/0PRjZDHMHKb3874bpFwOJ0JUzs2S70HclS8Av6kMKM585cIHIVbA4qZkAUTQFsXV0BO9v7kNcUPz1KkcMubOps6buN6NfG3vErH3piQOpgsVl048hMRtwc5LWatMIcak5FGfbXt1z1aYhY+5bJBFJEuU8VUfiLPJqgGI2KiTmK97mzX/ffJMiDo8F59RvGi70JohLwWs48nm+bh1UDsOM/wEGVelL80MWxwUfIWw5hkP6oQHnC6TXH68yeWqSqfdkqBOWYfpt2QnODGjGstntJgeUoxg3LM8YWqK6OJ7hWFojIXm0rKoyha9URIB/T6xjbosoaytJt7VJrYnboDq0SvytQbl7lbC1ZcFGXgN6YCKS2GORV/c0C9tR9rBuGebGWKq5w2tzYWspO0neShoL+AVDSL+o+MJz229xMJuMPoO496p9j+TDesblXi+HjzxU8pTg9dnCgrKfIrg6/xPcuLYf1Z8I/oqCOOqZPIdG9E77qHafa9tnCIwW7JTnqimGs1V6yPg== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(36860700013)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Oct 2024 13:41:15.2010 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4122f495-1e9a-452f-1586-08dcf1d608da X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C37E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5792 From: Si-Wei Liu The starting iova address to iterate iotlb map entry within a range was set to an irrelevant value when passing to the itree_next() iterator, although luckily it doesn't affect the outcome of finding out the granule of the smallest iotlb map size. Fix the code to make it consistent with the following for-loop. Fixes: 94abbccdf291 ("vdpa/mlx5: Add shared memory registration code") Signed-off-by: Si-Wei Liu Signed-off-by: Dragos Tatulea Acked-by: Jason Wang --- drivers/vdpa/mlx5/core/mr.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/vdpa/mlx5/core/mr.c b/drivers/vdpa/mlx5/core/mr.c index 7d0c83b5b071..8455f08f5d40 100644 --- a/drivers/vdpa/mlx5/core/mr.c +++ b/drivers/vdpa/mlx5/core/mr.c @@ -368,7 +368,6 @@ static int map_direct_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_direct_mr unsigned long lgcd = 0; int log_entity_size; unsigned long size; - u64 start = 0; int err; struct page *pg; unsigned int nsg; @@ -379,10 +378,9 @@ static int map_direct_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_direct_mr struct device *dma = mvdev->vdev.dma_dev; for (map = vhost_iotlb_itree_first(iotlb, mr->start, mr->end - 1); - map; map = vhost_iotlb_itree_next(map, start, mr->end - 1)) { + map; map = vhost_iotlb_itree_next(map, mr->start, mr->end - 1)) { size = maplen(map, mr); lgcd = gcd(lgcd, size); - start += size; } log_entity_size = ilog2(lgcd);