From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95538C4332F for ; Fri, 7 Jan 2022 15:55:14 +0000 (UTC) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 630F34067E; Fri, 7 Jan 2022 16:55:13 +0100 (CET) Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2069.outbound.protection.outlook.com [40.107.212.69]) by mails.dpdk.org (Postfix) with ESMTP id C203540140 for ; Fri, 7 Jan 2022 16:55:11 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gGBjzl4UsXBSwcNYJVWnj02KTtriy3+fd7ejHnJU4jKxu1k084Lxp6BnQK2GRM6F24KXUwJ1nNa20XK51XNAIlyYyIlJ+czR7A8MzNeiy5PjTTdNpSsIrGrdwSTn6Yv4NK9j7Itoe3QtMj0WxfFi0E4zLtTtjn9OWDLdCJd4S2M6Tnn1LYxliH3jjDle2OW/BUBJ5D6Ctnvgn7tAib9kbte5G4AMa3uIo8woOiyOQBHmzuLcpNFqCJOoOr3bG9LMuIHXPuBhKPVl9+ubY7fI7dDwQNAgYtAZ0pzo/J3f1jR2FeiVTalbb6tnxmlAYNVeP9c+gMePQbgp4sCYs6svMw== 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=Z3qdMllQLFZqOfxFqgyFsp0x0dx3r0IMgRgPP9NhB/w=; b=i9vLEWHZg50aOfUuudbjxeUxiFsiwy49kpqRXY37IbFolUqNf2L2tFejbQ0Wq2jR06IA6uMS99OSAduiiHCsGJJ2TeWy6SmuPZ2f3iYC/zpv1im0tl3XsEIkqpNHtaHXG/Co5qSfJ+uIbNDWN3cg8pPNBlj+KRMck6bR9WBo6tYj9SRjucBdfKRah7AIpt80ziZIXi8c8/XJY+tnLT93Ujm6U6HCfLqbb31NKM0S1NMG+ggqEivqz+azN11qMdJkLsSPVg8LEGwqixsXoBsZ5UvRnw2PajdHhZu9oRwAnLTuIHViqeIbKDprn5yKOW5XIq+5BBho5vOy4FrR+coGzg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=dpdk.org 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 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=Z3qdMllQLFZqOfxFqgyFsp0x0dx3r0IMgRgPP9NhB/w=; b=WJdweEHVYzxYcA9Ys2IdxzXd3GRpANAKE8zRblLN+Haxh3jwU0QYXqB2Dg7d0vj8BZ60+uv8mLvpHFgeZVsnYy562jHv1h7+JzHWclULQx3eLck6KXq7UUCSnk0N/CL4RWVb26ue3u4g/HJXA6V6tn2zmptNOHQy3Bd6CXPcKskuC1ZY4HnuFi7UXV0tki99UHrcHrNIpEaPD8eyJpeIk/NrOvOVWsEYcyxH3OQ7H7UCnMej7lLsny31vnu083Vy0wfjcuG083B4mRS/wqWruFFsGm8q4IbGsn93O2I3u4HIfM7uGNfp9CWeaEs00JVe/1zBqNyZcSGzh8gn+NYh4Q== Received: from DM6PR06CA0014.namprd06.prod.outlook.com (2603:10b6:5:120::27) by BN6PR1201MB2547.namprd12.prod.outlook.com (2603:10b6:404:aa::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4867.9; Fri, 7 Jan 2022 15:55:10 +0000 Received: from DM6NAM11FT029.eop-nam11.prod.protection.outlook.com (2603:10b6:5:120:cafe::3b) by DM6PR06CA0014.outlook.office365.com (2603:10b6:5:120::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4867.9 via Frontend Transport; Fri, 7 Jan 2022 15:55:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) 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 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.236) by DM6NAM11FT029.mail.protection.outlook.com (10.13.173.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4867.7 via Frontend Transport; Fri, 7 Jan 2022 15:55:09 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 7 Jan 2022 15:55:08 +0000 Received: from nvidia.com (172.20.187.5) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.986.9; Fri, 7 Jan 2022 07:55:07 -0800 From: To: CC: Elena Agostini Subject: [PATCH v3] gpudev: expose GPU memory Date: Sat, 8 Jan 2022 00:04:57 +0000 Message-ID: <20220108000457.31104-1-eagostini@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220104023408.13379-1-eagostini@nvidia.com> References: <20220104023408.13379-1-eagostini@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: afdf67fc-dd7e-4827-0630-08d9d1f6156d X-MS-TrafficTypeDiagnostic: BN6PR1201MB2547:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:267; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KE5/YCxjLbrtntNfamZCfThAeynjNQOsLIspO9KpbbJ1k2zuauooW0jqR/+sOe2C2fXt4K9bTC71xL3J3J7cppQc7DSg/CNJTZMMa1JB3vUn5U3o+rEKGL9AnGzwO/8VfEXqUqsazo5J45CuPC1A70Zpu3zSa3N2AjCAAjuBndLRCV7f0mx1XTTDMmBnIDiwoJI4p+h940MDiQ/5Z5PzVGGe0cIjXlNu4sMZiyZuC+O0T65OdYjgGThu5RpvvF3wtHK3oFyNEg3b0Ja7IqsAtgkDdXg3HrhHdC45adTCd0+OHizVYfA5DRrdCRvFmEuIS7lFEODE+/Tz3yFTo9Y52VAVGaYcyFQtqDq8xoOoJkWgIxIS9N9eEWa6QQcpqulf7ymj5ZiysP/gshqKdUVIkCUOthOCqjCctDZAxnPL4iDZGeg2pqvA8cNYmznpEoY8mcFa5AkLcCgC2+XnV1ftnUjqP729b8k1WVa/gZpu63fwiCeajRq6a0Os3zBt9hSqTmIkVRrb1u7y0OLGrmQlabXA6V6ZHmJ0NPGT7B1IZ6arHbrnbcBARcKw+NJ20B9R8psvuw+2GNz2L9Zi61UGa3rZJYsGbhH6rJc8dmzdZ+cKOUOEnBiPrruuEXECqxVumd7Od43MP8JDMAhOfwHRhnMJGgBOcyc1Ncu/bFvwaqfd9jgkn2pjBRrPm7CnIokbSRg/Q4ViddMcW0DVGmkf2i2aSuoKV/05vbkDTIAgr2bnugxGq9MeebwokHVbaKwPMNOhND1Rn0PgDo1mcvuRjZ3/6Y7dK5ZKWRUwYyRke9U= X-Forefront-Antispam-Report: CIP:12.22.5.236; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(4636009)(40470700002)(46966006)(36840700001)(47076005)(6666004)(36860700001)(6916009)(2876002)(1076003)(86362001)(2906002)(83380400001)(186003)(16526019)(508600001)(70206006)(4326008)(107886003)(8936002)(40460700001)(5660300002)(70586007)(8676002)(6286002)(2616005)(26005)(82310400004)(426003)(336012)(7696005)(55016003)(316002)(36756003)(356005)(81166007)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2022 15:55:09.9856 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: afdf67fc-dd7e-4827-0630-08d9d1f6156d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.236]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT029.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1201MB2547 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Elena Agostini Enable the possibility to expose a GPU memory area and make it accessible from the CPU. GPU memory has to be allocated via rte_gpu_mem_alloc(). This patch allows the gpudev library to expose (and unexpose), through the GPU driver, a chunk of GPU memory and to return a memory pointer usable by the CPU to access the GPU memory area. Changelog: - Move to pin/unpin naming to expose/unexpose - Minor changes to function definitions Signed-off-by: Elena Agostini --- lib/gpudev/gpudev.c | 61 ++++++++++++++++++++++++++++++++++++++ lib/gpudev/gpudev_driver.h | 6 ++++ lib/gpudev/rte_gpudev.h | 49 ++++++++++++++++++++++++++++++ lib/gpudev/version.map | 2 ++ 4 files changed, 118 insertions(+) diff --git a/lib/gpudev/gpudev.c b/lib/gpudev/gpudev.c index 9ae36dbae9..eafd5909e3 100644 --- a/lib/gpudev/gpudev.c +++ b/lib/gpudev/gpudev.c @@ -634,6 +634,67 @@ rte_gpu_mem_unregister(int16_t dev_id, void *ptr) return GPU_DRV_RET(dev->ops.mem_unregister(dev, ptr)); } +void * +rte_gpu_mem_expose(int16_t dev_id, size_t size, void *ptr) +{ + struct rte_gpu *dev; + void *ptr_out; + int ret; + + dev = gpu_get_by_id(dev_id); + if (dev == NULL) { + GPU_LOG(ERR, "expose mem for invalid device ID %d", dev_id); + rte_errno = ENODEV; + return NULL; + } + + if (dev->ops.mem_expose == NULL) { + GPU_LOG(ERR, "mem exposure not supported"); + rte_errno = ENOTSUP; + return NULL; + } + + if (ptr == NULL || size == 0) /* dry-run */ + return NULL; + + ret = GPU_DRV_RET(dev->ops.mem_expose(dev, size, ptr, &ptr_out)); + + switch (ret) { + case 0: + return ptr_out; + case -ENOMEM: + case -E2BIG: + rte_errno = -ret; + return NULL; + default: + rte_errno = -EPERM; + return NULL; + } +} + +int +rte_gpu_mem_unexpose(int16_t dev_id, void *ptr) +{ + struct rte_gpu *dev; + + dev = gpu_get_by_id(dev_id); + if (dev == NULL) { + GPU_LOG(ERR, "unexpose mem for invalid device ID %d", dev_id); + rte_errno = ENODEV; + return -rte_errno; + } + + if (dev->ops.mem_unexpose == NULL) { + rte_errno = ENOTSUP; + return -rte_errno; + } + + if (ptr == NULL) /* dry-run */ + return 0; + + return GPU_DRV_RET(dev->ops.mem_unexpose(dev, ptr)); +} + int rte_gpu_wmb(int16_t dev_id) { diff --git a/lib/gpudev/gpudev_driver.h b/lib/gpudev/gpudev_driver.h index cb7b101f2f..9049d11280 100644 --- a/lib/gpudev/gpudev_driver.h +++ b/lib/gpudev/gpudev_driver.h @@ -31,6 +31,8 @@ typedef int (rte_gpu_mem_alloc_t)(struct rte_gpu *dev, size_t size, void **ptr); typedef int (rte_gpu_mem_free_t)(struct rte_gpu *dev, void *ptr); typedef int (rte_gpu_mem_register_t)(struct rte_gpu *dev, size_t size, void *ptr); typedef int (rte_gpu_mem_unregister_t)(struct rte_gpu *dev, void *ptr); +typedef int (rte_gpu_mem_expose_t)(struct rte_gpu *dev, size_t size, void *ptr_in, void **ptr_out); +typedef int (rte_gpu_mem_unexpose_t)(struct rte_gpu *dev, void *ptr); typedef int (rte_gpu_wmb_t)(struct rte_gpu *dev); struct rte_gpu_ops { @@ -46,6 +48,10 @@ struct rte_gpu_ops { rte_gpu_mem_register_t *mem_register; /* Unregister CPU memory from device. */ rte_gpu_mem_unregister_t *mem_unregister; + /* Pin GPU memory. */ + rte_gpu_mem_expose_t *mem_expose; + /* Unpin GPU memory. */ + rte_gpu_mem_unexpose_t *mem_unexpose; /* Enforce GPU write memory barrier. */ rte_gpu_wmb_t *wmb; }; diff --git a/lib/gpudev/rte_gpudev.h b/lib/gpudev/rte_gpudev.h index fa3f3aad4f..2048133790 100644 --- a/lib/gpudev/rte_gpudev.h +++ b/lib/gpudev/rte_gpudev.h @@ -447,6 +447,55 @@ int rte_gpu_mem_register(int16_t dev_id, size_t size, void *ptr); __rte_experimental int rte_gpu_mem_unregister(int16_t dev_id, void *ptr); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Expose a chunk of GPU memory to make it accessible from the CPU + * using the memory pointer returned by the function. + * GPU memory has to be allocated via rte_gpu_mem_alloc(). + * + * @param dev_id + * Device ID requiring exposed memory. + * @param size + * Number of bytes to expose. + * Requesting 0 will do nothing. + * @param ptr + * Pointer to the GPU memory area to be exposed. + * NULL is a no-op accepted value. + + * @return + * A pointer to the exposed GPU memory usable by the CPU, otherwise NULL and rte_errno is set: + * - ENODEV if invalid dev_id + * - ENOTSUP if operation not supported by the driver + * - E2BIG if size is higher than limit + * - ENOMEM if out of space + * - EPERM if driver error + */ +__rte_experimental +void *rte_gpu_mem_expose(int16_t dev_id, size_t size, void *ptr); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Unexpose a chunk of GPU memory previously exposed with rte_gpu_mem_expose() + * + * @param dev_id + * Reference device ID. + * @param ptr + * Pointer to the memory area to be unexposed. + * NULL is a no-op accepted value. + * + * @return + * 0 on success, -rte_errno otherwise: + * - ENODEV if invalid dev_id + * - ENOTSUP if operation not supported by the driver + * - EPERM if driver error + */ +__rte_experimental +int rte_gpu_mem_unexpose(int16_t dev_id, void *ptr); + /** * @warning * @b EXPERIMENTAL: this API may change without prior notice. diff --git a/lib/gpudev/version.map b/lib/gpudev/version.map index 2e414c65cc..dce6085e44 100644 --- a/lib/gpudev/version.map +++ b/lib/gpudev/version.map @@ -20,8 +20,10 @@ EXPERIMENTAL { rte_gpu_init; rte_gpu_is_valid; rte_gpu_mem_alloc; + rte_gpu_mem_expose; rte_gpu_mem_free; rte_gpu_mem_register; + rte_gpu_mem_unexpose; rte_gpu_mem_unregister; rte_gpu_wmb; }; -- 2.17.1