From patchwork Thu Dec 14 13:26:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13493063 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="hwZeiXas" Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2045.outbound.protection.outlook.com [40.107.223.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76820131 for ; Thu, 14 Dec 2023 05:26:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QNiTGfiLmvZ9MbvJ+k42FOc/X/Onn4Zxwrh7A9NWGBvJp3dxRrZ0c4G7OrWtqdE+/arzR3wAzm0glfN0yIgCAovBuOjXHWNZG4iBDOunB+/lGZ/ldUnV5OkwLosw0dPZauWOnC6H6GdGVPCoYGDMbwHpE5pSDEB5CWqvfyxOPT+1y59uEmkvSJ5TcdO759sbjjGdmK9Tpj9Qel3pB1ScgC/EsxRHpbtQgXOharG9iUckw1kb+8EZgvs65+KgCW+20tiNYd1KEJqIhX0iNhRj88nDLOryeRy1bDTsVNeHVadzZLuo2Su/+AgUJaGsxLpoqR++lHwzo3xJJ6M81e+NNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=wYvVSRFTgY2wWY/42+MsPX2QgXrFds9afsSovT6ix2I=; b=mdMPj02FmNe2bjssAfKfhyGPi2f78y/g9m24Vcrz0MEYBa0QUL45UeiWhvPFPd63l/u6yuaochZUAgfnC8QMHZCdMMwY6hpy3rN4+jN5NwGSFoTfgI1Jx7/oJelOYUUYzDKEmROHSpCUbOG1zPvZ+2a5k6Al3GKn5As7CE5kUnbsiIQ+c7kAAqIH5r6r6S7NKpgKsfg5Im7exbv9G9aE1CYJzyaMTlctbEKSkO21XwcRCEE3CeSiggndcxRjqnF+ycmdL+tJpeEPfb8FYr5UckHryB1/cfdjWz7Q7TJ6KefLCw0YOJyXvWKT3ta4BcBpRzu0EUAD6OEWrayhOogt7Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none 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=wYvVSRFTgY2wWY/42+MsPX2QgXrFds9afsSovT6ix2I=; b=hwZeiXasfAg0D/P2JMlU/5rkiT/cK7uRTpkO1Xy9BaTXWmnE+QRAzFqb0hxEmX4GSyHnDs5ciMDGA/ShVYQpP5zX1xPASNq75BzHhi3IriGsQMHdrwzvgaRxoebn9vdcLKGqItp4QcRLCgFSlRaUgXFOn7uI2Z6ImG1rGHno+XmbwtM0UWZiTzlA2wp+rUGqGt537qohvf5a+AEIdF6gZtY2TKbvN5+gWTtpVngVomgxg/DkK4GLU5MJV4v/aqXh7bE4RxwqeSYlKhGBQvqdCQEd3aAcRUpO9zm0Ci3RTUPdCvNhvvZH2mPMKqION7LMZgVLd9MLdZPWKmVnc6wONg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from SJ1PR12MB6075.namprd12.prod.outlook.com (2603:10b6:a03:45e::8) by MW6PR12MB8708.namprd12.prod.outlook.com (2603:10b6:303:242::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.28; Thu, 14 Dec 2023 13:26:52 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7091.028; Thu, 14 Dec 2023 13:26:52 +0000 From: Aurelien Aptel To: linux-nvme@lists.infradead.org, netdev@vger.kernel.org, sagi@grimberg.me, hch@lst.de, kbusch@kernel.org, axboe@fb.com, chaitanyak@nvidia.com, davem@davemloft.net, kuba@kernel.org Cc: aaptel@nvidia.com, aurelien.aptel@gmail.com, smalin@nvidia.com, malin1024@gmail.com, ogerlitz@nvidia.com, yorayz@nvidia.com, borisp@nvidia.com, galshalom@nvidia.com, mgurtovoy@nvidia.com, viro@zeniv.linux.org.uk Subject: [PATCH v21 03/20] iov_iter: skip copy if src == dst for direct data placement Date: Thu, 14 Dec 2023 13:26:06 +0000 Message-Id: <20231214132623.119227-4-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231214132623.119227-1-aaptel@nvidia.com> References: <20231214132623.119227-1-aaptel@nvidia.com> X-ClientProxiedBy: FR0P281CA0145.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:96::18) To SJ1PR12MB6075.namprd12.prod.outlook.com (2603:10b6:a03:45e::8) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PR12MB6075:EE_|MW6PR12MB8708:EE_ X-MS-Office365-Filtering-Correlation-Id: 1f2164c6-2e9e-4666-6792-08dbfca8552f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /mLj9bTmxeEdGa94OIjqeXftXwkAH+vXqDjrSOsUCfcHOGKWHn1w0BQGdrtXvvqo8QU9P68PWcBuTS/MlopgNw2cLx+vRzcGwsX1cYiZowM3SEaFVhOKYrT8/ZI886QxHZd5LufU3Jm0UBWOaTxqatOdN4DbHH5olyW5jTaeGJBKuiwzP7npxQPQba7gHLL8JaHMAh6oeBYPYbKyz+y1hqpbAZymPA4Sgz6v/nZW4kFKkEmoFvC5CzXeSfVv9IO8LNQkd3Of4DF+byk75l2p/Jv1l47fPiGKbkwbA1zbddfyexkQrE0K7Nynct/IFCyA5ffGZ87mHqLk9iMj1HF3LYHHsHqOzo6LqAE/rKwAL8KSC8xIycLNotyiZpSS9RBredYfk9ZI++xyc6KWmOiMCci44oIFP55b4anGb/jgpj1ynBihHKgptAo7ypp6BtOSJQbTtK79I+UwugJa+0kzjzP2EVUtVNYVz69vNYLmVrumg7JUnW7QezziglJ97IA0Mlo+68Sl896823pqUOn1FRwN27Li2o0uA448RjABMnJbFQEbyreV4GuW2lnbUhcB X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ1PR12MB6075.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(346002)(396003)(366004)(39860400002)(136003)(230922051799003)(186009)(64100799003)(451199024)(1800799012)(7416002)(2906002)(38100700002)(36756003)(41300700001)(86362001)(2616005)(4326008)(8676002)(8936002)(6512007)(6486002)(6666004)(478600001)(83380400001)(66476007)(66556008)(316002)(66946007)(6506007)(5660300002)(1076003)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9XqB3AE6kqO6KoyIykEvuDYN3xYCjf2+6qe71s3qeieZli5B1KgTVE9hGEO1r5nCyN/q0xAkPw1pOIgdS/nc3m0nlVvG9ylr0MasDvOMn+UXzRsrxYm5vexlUflgqNoYeASkocI2MNkpVRd4y4vNVq0XEFIzwpsFseUR1do30aSObf1aDdUiaoKzwTsAx/seDQN2Yr95fiRHXGAqgHjhExLx/e8ICKU/5K+HMT/meFnMGGnzNqZCIy3cHKRG+ucdY4P0pGt72IrZoy8G/waBI5di9NDfNynCx74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b6Bal9i0tKb90TXYBvajhKQEei0RhA+LJ88GxCfYckgHathLT3KEx3Y4WzrJh3k+3Ve7kpB5ey8fbllqenZ6H7J6Y1TJd0woBmXO9HDgGbCR+Oi5PI81z4Umf1Ier4yiP8aHpSFcjyEp/oz4Xf6maBJAG8hkYEjkt1yz4DccEzb4hy9vv8WYx+2RZ4VBy3hwy84d5GDcUPo/r8XlYXYvQ6ywHHir7+0vN5mYwg/w573SeelFrSX X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1f2164c6-2e9e-4666-6792-08dbfca8552f X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2023 13:26:51.9699 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Tdnh32oSY5aqZE0RBb4rdgi+gDJmsdRPk+mEAICUqDhRkraw0KXFMTdketJ5lpvRd4HCm8FwD4/Va9X/u2Kgxg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8708 From: Ben Ben-Ishay When using direct data placement (DDP) the NIC could write the payload directly into the destination buffer and constructs SKBs such that they point to this data. To skip copies when SKB data already resides in the destination buffer we check if (src == dst), and skip the copy when it's true. Signed-off-by: Ben Ben-Ishay Signed-off-by: Boris Pismenny Signed-off-by: Or Gerlitz Signed-off-by: Yoray Zack Signed-off-by: Shai Malin Signed-off-by: Aurelien Aptel Reviewed-by: Chaitanya Kulkarni --- lib/iov_iter.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 8ff6824a1005..b96d8b6f5818 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -62,7 +62,14 @@ static __always_inline size_t memcpy_to_iter(void *iter_to, size_t progress, size_t len, void *from, void *priv2) { - memcpy(iter_to, from + progress, len); + /* + * When using direct data placement (DDP) the hardware writes + * data directly to the destination buffer, and constructs + * IOVs such that they point to this data. + * Thus, when the src == dst we skip the memcpy. + */ + if (iter_to != from + progress) + memcpy(iter_to, from + progress, len); return 0; }