From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8ABCCA0032; Wed, 14 Sep 2022 23:13:02 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7E5484113F; Wed, 14 Sep 2022 23:13:02 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2074.outbound.protection.outlook.com [40.107.20.74]) by mails.dpdk.org (Postfix) with ESMTP id 635C040156 for ; Wed, 14 Sep 2022 23:13:00 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jm9qT+fOf71lhpdgVZarCJGvIkfDMbprQhCb8pM4RGWmthvPZXNM24AmE8pgJfx4TwDXygVaB+9+2xU1ebXyWTXh50wF2wQEqmitB+/aumV9CyTuqUqSlQev/FSNwU2pe0rkq6jqJa6D4kaIBXqavvEAr/YSECOzt/4kPK1aQo534/mdRTLArIqfs84kz1kSUr8vv1OYerypudLhyf+NlLtC3Z2OtSOV4ItjgnCu8CoEoQrn3dqFipvZGt0dCH1og55xDjRGE3e/C/R6XeB8Gicclu98aKgg5O+xBE16BzqrbOIHnBVE/UlWaMcbl+86IQAi8X6TimhrxU2jX4MM1g== 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=vuyLoZ1wv+KDISSpCG15cXz8GQ3e7lZq04PmF5QvZ8c=; b=lT5lUazX/IHAkkj9Ug5k98s85IBclm7hodcNSzV5FUP48m0o4OO8rTWWFXWLgeIB7PXpCaoLakgjE+URS7omT/6kU9W6j5Yy6Dh+R1I/RFDZxq4f0Q5l2KC6cR5716gxMMnjHV1+KZxvbxA3tJLfErMhVUAUdwjOF4gw5vClHYvxjPbeeFbuAIAtqKGOenBDuXDSmGJh/WCWkI6m5Bkq9d/rjDKYmrO9ku+3FfcD+PZr2DiY7kgfqGoXGjFRwpjT8XxfzmF+cnac+0gh+fQSGC3jSP9RkJFBwZZ4S1rz1ickiCZwh82gM/eA55zf8chOZeWstK3GjOipVXWBbH9wsw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=xsightlabs.com; dmarc=pass action=none header.from=xsightlabs.com; dkim=pass header.d=xsightlabs.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xsightlabs.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vuyLoZ1wv+KDISSpCG15cXz8GQ3e7lZq04PmF5QvZ8c=; b=T+VHKY04IsiMfAuij1ns177s3B7MRHyaumcz4F9Yuh67cfhr2FXdRcNqIMIYBeRpTF+lBUnhAl/CT3EKK17xszIzrzLQ+j3JO1wfK10WrJZw7BXiS/OoBgdqQqcfp3kVHAqlYKlMP9KLKhGb1wvlaRuRNzLd8n3ebHjhROAJaNk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=xsightlabs.com; Received: from DB9P193MB1482.EURP193.PROD.OUTLOOK.COM (2603:10a6:10:2a6::7) by GV1P193MB2199.EURP193.PROD.OUTLOOK.COM (2603:10a6:150:28::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.12; Wed, 14 Sep 2022 21:12:59 +0000 Received: from DB9P193MB1482.EURP193.PROD.OUTLOOK.COM ([fe80::600e:205f:e0e1:f828]) by DB9P193MB1482.EURP193.PROD.OUTLOOK.COM ([fe80::600e:205f:e0e1:f828%3]) with mapi id 15.20.5612.022; Wed, 14 Sep 2022 21:12:59 +0000 From: Don Wallwork To: dev@dpdk.org Cc: dmitry.kozliuk@gmail.com, mb@smartsharesystems.com, bruce.richardson@intel.com, anatoly.burakov@intel.com, Don Wallwork Subject: [RFC v2] eal/linux: add support for fast virt/iova translation Date: Wed, 14 Sep 2022 17:12:01 -0400 Message-Id: <20220914211201.32940-2-donw@xsightlabs.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220914211201.32940-1-donw@xsightlabs.com> References: <20220914211201.32940-1-donw@xsightlabs.com> Content-Type: text/plain X-ClientProxiedBy: BL1P222CA0029.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::34) To DB9P193MB1482.EURP193.PROD.OUTLOOK.COM (2603:10a6:10:2a6::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB9P193MB1482:EE_|GV1P193MB2199:EE_ X-MS-Office365-Filtering-Correlation-Id: cdbab9c3-cb2a-4bf3-2c33-08da9695e677 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2wLAdtL6T1hktMhf98R0/mns2hkoA7LcZXfIlqOtSwAvxnEKFOUurpoZGM/IPc83SZQnohdz5ITqHSRkpxjK/hhCuAzASWLxb5C0m4d5U2Lf8Rg4t6A2WcSCXs53uM882BIVtYIexE9itcn9x1umoG1BZqLNryDs890g++xd96El/gBM4UR8tWCRQUebtWenAEoJF0Un/Vix0JcTvtxxrLnGFOdOuMS1fVvBGnQTPsSopw59V61+zFIyT/ip0iIpVuJqMKkiT9YlnWaQbxGMBKVe9d7l7ZzE+T/l79H+7pWWPaydSxQnr20wcNgWMGVDWCy28uAQC+V+Z/vMFu6i3OUyD9go2h9oGAhtvZhwnsIGGQ0p+fz7oEhrbpg7m9uiiLMVMZt/xZEI9NiIdllCky4aVjgTjCyUENqMuoOdPdGe1bMDWnqdDP5LJ/Y79OsS7a5EpoPBfSFfOPud68x2FB8HehK8H44c9s3DE58AvjawrBTjL//fhT/FAQ3Ljc+pXkM2GbwlR6Unpw/CG7qk7qWtRqqYxkhAeUmMoPUO9rIU6kDmYKDeeEq/jfBq8GmkNsBoqKCQikKED8r8MOItG1q5pr54UzP3jz/8dj23zke/TC8JF3uafyMoMlznk970TQxfah8aLmkaNFEJjWfOnaWcqEmztDchYgK2Wsab7vmh3FGlk8SjE5FzgXNe2ngWSV5FBkdUmrk3PiywKzf9coLDswQ6cq5J+AEgPoPlPV3QTMV4lid4gCFOIBuXBDt5+scNLfCpsPbeCooL+a0Oqg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9P193MB1482.EURP193.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230022)(4636009)(39850400004)(376002)(346002)(366004)(136003)(396003)(451199015)(6486002)(83380400001)(186003)(2616005)(1076003)(8676002)(66476007)(6916009)(5660300002)(6666004)(4326008)(66556008)(86362001)(52116002)(66946007)(107886003)(6506007)(38100700002)(6512007)(316002)(8936002)(38350700002)(478600001)(2906002)(36756003)(41300700001)(26005)(30864003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?X6XGYJKoPcDrfx9zpLgmAVdPiip6PP11ae/URnW5l7LnnhVMEnt9w7IwtA0e?= =?us-ascii?Q?CdAkYIIEEnPh3ZiJ5ZH/Aw41qxg6AdDCPK0O64IxxnHzsFhSGUJ9D4yHjUv8?= =?us-ascii?Q?D6wsU21OG80VAjqeP6NP/hkdGxRNnBasa+mJK8zvWpQBPUYSgOLZ9R74TfPa?= =?us-ascii?Q?bzqd34ymNZHNS8iAz+YX4LzGO/lc1Eo/2Oeo0j5GEenxg5QphZwpI5Dj0S6/?= =?us-ascii?Q?zrLxlv/hYw0X4wyLRvA37FE6DlnSM5DXBRv81V6WNT0XRUESKdX3Ig1g8VrB?= =?us-ascii?Q?TofpF6YvqQ49mtUi8Pjt1xrupTHMTp2yrlB0iXVsQfXaYQky67gHhZLn/OHJ?= =?us-ascii?Q?JZ226VzeCdA04H4HYkYj172A/pXK7f7amZ+y1EVd09C/C/Zl2lUwOsxMqUZs?= =?us-ascii?Q?9wBeWtbilQaw7wN9KmEdIyLKNqRGGTi1tU3ooXUCjotF3iYsvT+n5/gnJ0oh?= =?us-ascii?Q?ztmr1QcLR59rTgX4TgiU4UK1eXpOeKZVPbR3sVGu4L44ERZimombjWSU4sV6?= =?us-ascii?Q?/NQrFkbtNuRsJh1PCjgf8gpe+iEvS93Vz59MRFcK8dEGuyntKXtXGlf3i+JF?= =?us-ascii?Q?hDpVcYIUncS7M2dCep/WKW21ye5JchYmb2da5fNpHijtcc1gV3USwfb83ws/?= =?us-ascii?Q?LMI4H/xOYHpfSJaSjyCo5lvihx8KNlQUdOR21mxI0XBVpiL1w97GKVeIi0i0?= =?us-ascii?Q?+J+JIWi6DJjQW3LtVe8/o2heyglKPp3baGCE+H0whKzagx+Gv79XPVAoRQov?= =?us-ascii?Q?hBNHu/dzCn9WZl0ej4nPB9wrxvGToS0VrPFp3c7gEt6BVs/mZhMcy4fppTFq?= =?us-ascii?Q?NZjZf2VvwVxu8pYX1Col0b+qEWriwxS1/HwyYmdwTVLx+xDWXWkUVjyK4Pzg?= =?us-ascii?Q?aWWsfPChiogqtgNWao1XIt1vhEzB25QrnkFb1y+IFbxqUjErdTu7cCT+oOPP?= =?us-ascii?Q?TU0Ps8TdRjkT6fV4Qv6MWrGaxruq3TxicXWyFC2G/5D5aDHFCSZB2gF4Yg3T?= =?us-ascii?Q?i4Cm7V7/nw48RfaTPZWXDN6exiWY06CdmSCMDm8o3NolQ0Jqrxm828A5CZ4C?= =?us-ascii?Q?/q/r7LBUlHBsLDOAPzc6ebRzvkcZm/rGSWTzLODzPG/Cf68rhgqDVeCCwkAk?= =?us-ascii?Q?bcp0Qe1VRzG3pDBaH7vYhSjVB5GRB79tVSvcN7Z/4eMQyJDbWydcrCqMkkYy?= =?us-ascii?Q?gZnDPLk1/DMdwF0ZkGBlDuIgbYSnII+148Ejoo1LFJbptqpSd6obTmA3aBwE?= =?us-ascii?Q?VMGrCfcP6czzyyYlVMiq1pALdOCpflbpJL0CXuLM/bLkeO4J0VeoyMUJsvDj?= =?us-ascii?Q?22T8crJzOisOhMlF3RnqvBnX3CAGNvit5AEM3T/NgbkF2UUvNDHM16v7rXhe?= =?us-ascii?Q?jlnZOSNYT3hsv02E8YpgG24YuVZsmGeHpjTiYbkId+WtZn+LXGxtHcKAv8jT?= =?us-ascii?Q?4n7E1MQSQXIIx68tT7UBuBXGQp912thp6iOAGobV1hr+SzGaWDu/89fyneVB?= =?us-ascii?Q?bwc0fwuhkzrGd9TRTAaGvq2HvA0O8id2r/VIyPujFliU4+Hz7tANsau6hM7v?= =?us-ascii?Q?aXYrWELu1aIj7GZljkqFrHvwm/4ozS6D1lw5uSV3?= X-OriginatorOrg: xsightlabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: cdbab9c3-cb2a-4bf3-2c33-08da9695e677 X-MS-Exchange-CrossTenant-AuthSource: DB9P193MB1482.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2022 21:12:58.9396 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 646a3e34-83ea-4273-9177-ab01923abaa9 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ldwUkfG/Cb5t9FzxT8Siddz1xvGO5CCaXVgdskTMiIz6K+KpYIBiI5+9dWRBndhVXe+vM6KMJOynjPfcNjMvLQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1P193MB2199 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 This patch maps hugepage memory such that address translation from virtual to iova or vice versa can be done by simple addition/ subtraction of a constant value without any page table walks. A new '--const-translate' EAL option is added to enable this mode. The following example describes how this works: Say you have a system with 4 huge pages that are 1G each and the physical addresses are 10, 11, 17 and 22G. If we map 13G of virtual address space, that will be enough to cover all of the huge page physical addresses. If the VA region starts at 1G, all of the hugepage PAs can be mapped into that region as shown below under Proposed heading. For comparison, existing mapping that would be done in legacy mode is shown under the Current heading. Proposed Current (Legacy) VA | PA VA | PA ----+---- ----+---- 1G | 10G 1G | 10G 2G | 11G 2G | 11G 3G | - 3G | - 4G | - 4G | 17G 5G | - 5G | - 6G | - 6G | 22G 7G | - 8G | 17G 9G | - 10G | - 11G | - 12G | - 13G | 22G So in this example, we have a fixed offset of 9G to translate between VA to PA or vice versa.This works whether the huge pages happen to be allocated statically (legacy mode) or dynamically. The unused VA address space from 3G-7G and 9G-12G can be unmapped in just two unmap calls. This patch applies to legacy-mem mode only. --- doc/guides/linux_gsg/eal_args.include.rst | 5 + .../prog_guide/env_abstraction_layer.rst | 10 ++ lib/eal/common/eal_common_options.c | 6 + lib/eal/common/eal_internal_cfg.h | 2 + lib/eal/common/eal_options.h | 2 + lib/eal/include/rte_memory.h | 28 +++ lib/eal/linux/eal.c | 6 + lib/eal/linux/eal_memory.c | 165 +++++++++++++++++- 8 files changed, 218 insertions(+), 6 deletions(-) diff --git a/doc/guides/linux_gsg/eal_args.include.rst b/doc/guides/linux_gsg/eal_args.include.rst index 9cfbf7de84..cb3d554f5a 100644 --- a/doc/guides/linux_gsg/eal_args.include.rst +++ b/doc/guides/linux_gsg/eal_args.include.rst @@ -122,6 +122,11 @@ Memory-related options to system pthread stack size unless the optional size (in kbytes) is specified. +* ``--const-translate`` + + Prepare hugepage memory such that the offset between any hugepage virtual + address is a constant offset from physical address and vice versa. + Debugging options ~~~~~~~~~~~~~~~~~ diff --git a/doc/guides/prog_guide/env_abstraction_layer.rst b/doc/guides/prog_guide/env_abstraction_layer.rst index 67842ae272..c7ffada7ef 100644 --- a/doc/guides/prog_guide/env_abstraction_layer.rst +++ b/doc/guides/prog_guide/env_abstraction_layer.rst @@ -350,6 +350,16 @@ if the optional size parameter is not specified. hugepage worker thread stacks given the same thread stack size and loading conditions. +Constant Address Translation +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +When the ``--const-translate`` EAL option is specified, hugepage +memory is initialized to provide a constant offset between hugepage +virtual and physical addresses. + +This allows device drivers to quickly translate from both virtual to +physical and physical to virtual addresses for any hugepage address. + Support for Externally Allocated Memory ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index 4c2def0155..ba4151a65c 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -104,6 +104,7 @@ eal_long_options[] = { {OPT_NO_TELEMETRY, 0, NULL, OPT_NO_TELEMETRY_NUM }, {OPT_FORCE_MAX_SIMD_BITWIDTH, 1, NULL, OPT_FORCE_MAX_SIMD_BITWIDTH_NUM}, {OPT_HUGE_WORKER_STACK, 2, NULL, OPT_HUGE_WORKER_STACK_NUM }, + {OPT_CONST_TRANSLATE, 0, NULL, OPT_CONST_TRANSLATE_NUM }, {0, 0, NULL, 0 } }; @@ -2086,6 +2087,11 @@ eal_check_common_options(struct internal_config *internal_cfg) "be specified together with --"OPT_NO_HUGE"\n"); return -1; } + if (internal_cfg->no_hugetlbfs && internal_cfg->const_translate) { + RTE_LOG(ERR, EAL, "Option --"OPT_CONST_TRANSLATE" cannot " + "be specified together with --"OPT_NO_HUGE"\n"); + return -1; + } if (internal_conf->force_socket_limits && internal_conf->legacy_mem) { RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_LIMIT " is only supported in non-legacy memory mode\n"); diff --git a/lib/eal/common/eal_internal_cfg.h b/lib/eal/common/eal_internal_cfg.h index 167ec501fa..d4a034d823 100644 --- a/lib/eal/common/eal_internal_cfg.h +++ b/lib/eal/common/eal_internal_cfg.h @@ -103,6 +103,8 @@ struct internal_config { struct simd_bitwidth max_simd_bitwidth; /**< max simd bitwidth path to use */ size_t huge_worker_stack_size; /**< worker thread stack size */ + volatile unsigned const_translate; + /**< true to enable constant VA->PA, PA->VA address translation */ }; void eal_reset_internal_config(struct internal_config *internal_cfg); diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index 3cc9cb6412..98cd22fd32 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -89,6 +89,8 @@ enum { OPT_FORCE_MAX_SIMD_BITWIDTH_NUM, #define OPT_HUGE_WORKER_STACK "huge-worker-stack" OPT_HUGE_WORKER_STACK_NUM, +#define OPT_CONST_TRANSLATE "const-translate" + OPT_CONST_TRANSLATE_NUM, OPT_LONG_MAX_NUM }; diff --git a/lib/eal/include/rte_memory.h b/lib/eal/include/rte_memory.h index 68b069fd04..c87777ca01 100644 --- a/lib/eal/include/rte_memory.h +++ b/lib/eal/include/rte_memory.h @@ -134,6 +134,34 @@ rte_iova_t rte_mem_virt2iova(const void *virt); void * rte_mem_iova2virt(rte_iova_t iova); +/** + * Get IO virtual address of any mapped virtual address in the current process. + * + * @note This function provides a fast implementation of virtual to physical + * addresses that does not walk any page tables. Suitable for use in + * data plane threads. + * + * @param virt + * The virtual address. + * @return + * The IO address or RTE_BAD_IOVA on error. + */ +rte_iova_t rte_mem_fast_virt2iova(const void *virt); + +/** + * Get virtual memory address corresponding to iova address. + * + * @note This function provides a fast implementation of physical to virtual to + * addresses. Suitable for use in data plane threads. + * + * @param iova + * The iova address. + * @return + * Virtual address corresponding to iova address (or NULL if address does not + * exist within DPDK memory map). + */ +void *rte_mem_fast_iova2virt(rte_iova_t iova); + /** * Get memseg to which a particular virtual address belongs. * diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 37d29643a5..6e4e60d8c1 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -455,6 +455,8 @@ eal_usage(const char *prgname) " Allocate worker thread stacks from hugepage memory.\n" " Size is in units of kbytes and defaults to system\n" " thread stack size if not specified.\n" + " --"OPT_CONST_TRANSLATE" Constant delta between hugepage " + "physical and virtual addresses\n" "\n"); /* Allow the application to print its usage message too if hook is set */ if (hook) { @@ -767,6 +769,10 @@ eal_parse_args(int argc, char **argv) } break; + case OPT_CONST_TRANSLATE_NUM: + internal_conf->const_translate = 1; + break; + default: if (opt < OPT_LONG_MIN_NUM && isprint(opt)) { RTE_LOG(ERR, EAL, "Option %c is not supported " diff --git a/lib/eal/linux/eal_memory.c b/lib/eal/linux/eal_memory.c index c890c42106..3fefb3dc9d 100644 --- a/lib/eal/linux/eal_memory.c +++ b/lib/eal/linux/eal_memory.c @@ -148,6 +148,47 @@ rte_mem_virt2iova(const void *virtaddr) return rte_mem_virt2phy(virtaddr); } +static void *const_va_pa_delta; + +#ifdef RTE_MEM_SANITY_CHECK +#define __rte_mem_validate(v) rte_mem_validate(v) + +static int rte_mem_validate(const void *virtaddr) +{ + if (!rte_mem_virt2memseg(virt, NULL)) { + RTE_LOG(ERR, EAL, "Invalid virtual address %p\n", virtaddr); + return -1; + } + return 0; +} +#else +#define __rte_mem_validate(v) 0 +#endif + +rte_iova_t rte_mem_fast_virt2iova(const void *virtaddr) +{ + if (rte_eal_iova_mode() == RTE_IOVA_VA) + return (uintptr_t)virtaddr; + + if (__rte_mem_validate(virtaddr) != 0) + return RTE_BAD_IOVA; + + return (rte_iova_t)((uintptr_t)virtaddr - (uintptr_t)const_va_pa_delta); +} + +void *rte_mem_fast_iova2virt(rte_iova_t iova) +{ + if (rte_eal_iova_mode() == RTE_IOVA_VA) + return (void *)(uintptr_t)iova; + + void *virtaddr = (void *)((uintptr_t)const_va_pa_delta + iova); + + if (__rte_mem_validate(virtaddr) != 0) + return NULL; + + return virtaddr; +} + /* * For each hugepage in hugepg_tbl, fill the physaddr value. We find * it by browsing the /proc/self/pagemap special file. @@ -664,10 +705,9 @@ remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end) uint64_t page_sz; size_t memseg_len; int socket_id; -#ifndef RTE_ARCH_64 const struct internal_config *internal_conf = eal_get_internal_configuration(); -#endif + page_sz = hugepages[seg_start].size; socket_id = hugepages[seg_start].socket_id; seg_len = seg_end - seg_start; @@ -691,6 +731,12 @@ remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end) ms_idx = rte_fbarray_find_next_n_free(arr, 0, seg_len + (empty ? 0 : 1)); + if (internal_conf->const_translate && + internal_conf->legacy_mem && + rte_eal_iova_mode() == RTE_IOVA_PA && + ms_idx != 0) + continue; + /* memseg list is full? */ if (ms_idx < 0) continue; @@ -735,7 +781,12 @@ remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end) return -1; } memseg_len = (size_t)page_sz; - addr = RTE_PTR_ADD(msl->base_va, ms_idx * memseg_len); + if (internal_conf->const_translate && + internal_conf->legacy_mem && + rte_eal_iova_mode() == RTE_IOVA_PA) + addr = RTE_PTR_ADD(const_va_pa_delta, hfile->physaddr); + else + addr = RTE_PTR_ADD(msl->base_va, ms_idx * memseg_len); /* we know this address is already mmapped by memseg list, so * using MAP_FIXED here is safe @@ -1085,6 +1136,98 @@ huge_recover_sigbus(void) } } +static int +remap_hugepages_const_xlate(struct hugepage_file *hugepage, int n_pages, + int nr_hugepages) +{ + struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; + int i, remap_failed = 0; + void *addr; + + /* Adjust VA bases in memory segment lists to enable constant + * va->pa and pa->va address translation + */ + if (rte_eal_iova_mode() == RTE_IOVA_PA) { + RTE_LOG(INFO, EAL, + "Enabling constant address translation support...\n"); + + /* Allocate virtual address space to cover the full + * range of huge page physical addresses + */ + size_t va_mem_sz = + hugepage[nr_hugepages - 1].physaddr + + hugepage[nr_hugepages - 1].size - + hugepage[0].physaddr; + size_t page_sz = 0; + + for (i = 0; i < nr_hugepages; i++) + if (hugepage[i].size > page_sz) + page_sz = hugepage[i].size; + + void *va_base = + eal_get_virtual_area(NULL, &va_mem_sz, page_sz, 0, 0); + + if (va_base == NULL) { + RTE_LOG(ERR, EAL, "Cannot reserve memory\n"); + return -ENOMEM; + } + const_va_pa_delta = RTE_PTR_ADD(va_base, -hugepage[0].physaddr); + + /* Unmap gaps in virtual address space when there are gaps + * between huge page physical addresses + */ + for (i = 1; i < nr_hugepages; i++) { + size_t gap_sz = hugepage[i].physaddr - + (hugepage[i-1].physaddr + hugepage[i-1].size); + + if (gap_sz) { + addr = RTE_PTR_ADD(const_va_pa_delta, + hugepage[i-1].physaddr + + hugepage[i-1].size); + + if (munmap(addr, gap_sz) != 0) + RTE_LOG(ERR, EAL, "Gap unmap failed\n"); + } + } + } + + /* remap all pages we do need into memseg list VA space, so that those + * pages become first-class citizens in DPDK memory subsystem + */ + if (remap_needed_hugepages(hugepage, n_pages)) { + RTE_LOG(ERR, EAL, + "Couldn't remap hugepage files into memseg lists\n"); + remap_failed = 1; + } + + /* Unmap the existing virtual address space in each MSL with + * allocated pages. Modify MSL base_va to be the VA of the + * first page of the segment list. Adjust the msl->len to the + * length of the address space consumed by the msl. + */ + for (i = 0; i < RTE_MAX_MEMSEG_LISTS; i++) { + struct rte_memseg_list *msl = &mcfg->memsegs[i]; + struct rte_memseg *ms; + + /* skip inactive lists */ + if (msl->base_va == NULL) + continue; + + /* skip lists where there are no pages allocated */ + if (!msl->memseg_arr.count) + continue; + + /* release current VA space */ + munmap(msl->base_va, msl->len); + + /* assign new VA base and len */ + ms = rte_fbarray_get(&msl->memseg_arr, 0); + msl->base_va = ms->addr; + msl->len = (msl->page_sz * msl->memseg_arr.count); + } + return remap_failed; +} + /* * Prepare physical memory mapping: fill configuration structure with * these infos, return 0 on success. @@ -1413,9 +1556,19 @@ eal_legacy_hugepage_init(void) /* remap all pages we do need into memseg list VA space, so that those * pages become first-class citizens in DPDK memory subsystem */ - if (remap_needed_hugepages(hugepage, nr_hugefiles)) { - RTE_LOG(ERR, EAL, "Couldn't remap hugepage files into memseg lists\n"); - goto fail; + if (internal_conf->const_translate) { + if (remap_hugepages_const_xlate(hugepage, nr_hugefiles, + nr_hugepages)) { + RTE_LOG(ERR, EAL, + "Couldn't remap hugepage files into memseg lists\n"); + goto fail; + } + } else { + if (remap_needed_hugepages(hugepage, nr_hugefiles)) { + RTE_LOG(ERR, EAL, + "Couldn't remap hugepage files into memseg lists\n"); + goto fail; + } } /* free the hugepage backing files */ -- 2.17.1