From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10078.outbound.protection.outlook.com [40.107.1.78]) by dpdk.org (Postfix) with ESMTP id 716BA1B90C; Fri, 14 Dec 2018 19:51:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OBWjqPxCi2oWessqiFLvKmALC1LHQi99xeBSAC5DotM=; b=KL8HlFUOoo27IM45Tar4GSFwqUPfl3WF/FyCT2m2pkGa6CA2p57FdAIRYEcsrer5Nei9n+EIoRqvVlemQrlLT7JN5b9o7iNt9tfsTWdalO3Tm4s6mL0Q3rEnz01km4etJDgInHC0CSfVJCgN/Kfhgh4xQR011lsrg9vKCPWihBg= Received: from DB3PR0502MB3980.eurprd05.prod.outlook.com (52.134.72.27) by DB3PR0502MB4043.eurprd05.prod.outlook.com (52.134.68.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.18; Fri, 14 Dec 2018 18:51:14 +0000 Received: from DB3PR0502MB3980.eurprd05.prod.outlook.com ([fe80::dcbc:4578:3018:50f3]) by DB3PR0502MB3980.eurprd05.prod.outlook.com ([fe80::dcbc:4578:3018:50f3%5]) with mapi id 15.20.1404.026; Fri, 14 Dec 2018 18:51:14 +0000 From: Yongseok Koh To: Anatoly Burakov CC: dev , Shahaf Shuler , "stable@dpdk.org" Thread-Topic: [PATCH] malloc: make alignment requirements more stringent Thread-Index: AQHUk6O4FJ2vMXu+oUClo+IW1bjcvaV+lLGA Date: Fri, 14 Dec 2018 18:51:14 +0000 Message-ID: <8164A185-3807-404C-9678-61513386BB64@mellanox.com> References: <245b643cbfb5f3a0f96e44603339e20278b34e76.1544788410.git.anatoly.burakov@intel.com> In-Reply-To: <245b643cbfb5f3a0f96e44603339e20278b34e76.1544788410.git.anatoly.burakov@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=yskoh@mellanox.com; x-originating-ip: [209.116.155.178] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB3PR0502MB4043; 6:pSHT3JEHg18SxAE8H0LIHESnMC/u5uGh7KV9LdoIGciwE8eamMIwM+tEYNoDdPDVN64Es36phPU7k+M+JyDQzlqmKfObH/fM3HFL7D3FxRaaiZZPgpXZ+VGeZHzF2ajv3J4auf/i0P+jxdSmT4hZKt0ESc59iCT0ecYAHN7ezzyjg9face01q8kF7lUullfOlaQMnaeQ5Oy2lBJHr4YakQi2vBySzPr1X5jP/XyuENFCM7EJUEjgTvzcUVQwnX/lYYq0GWElGLrPIHzWg1wKPjmorlq0X3OVULg3nCSuTSJierDVxJY/3mcgKgLdvqHIr207WIzsq9b0A+oO6LNyuE2UTf7jvoEz+IPv4GpIXyFOWPy+AeMgRuBvCsivZ1aIqOPqvRIJO1XGZktXkGh2S5o1+QrJ5CkHWDDa6MJaL3qlCADKZrdqfqFuulXtpmjzAdzhputzrAuHhx9OxhvrqA==; 5:pLhnpbq2pMVDeBhU/6iT+AkCh25Me1f8rT6YNHKiFpFC3wg8ceqFB8C+Ujjd5srRgi8wA35vVh99JoDNJTjgS28pHYu2ZFb6ip0+JDuIt994WQRO37Kqe1E8sH/FZgRxbnEzHoTB7HagQ7Op7vImiuHJns5vbhHGq5j+s4VM2o8=; 7:hT07HKK2ZaxAj1YwMNL22a4MwWl40Mkr0nvtBLojQh+CaJcEU6YuS98H48Aod37wu8ZxhJUPksAnflEQYu6uwGMExaYAVTi2ebaDUKNvwqKpy0H2cJLF6XFd2SE8G2F+XM/l7JW06qazsD/yZoo1EA== x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: 26560b9e-08c3-46b9-63fd-08d661f51f93 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:DB3PR0502MB4043; x-ms-traffictypediagnostic: DB3PR0502MB4043: x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(3230021)(999002)(6040522)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(3231475)(944501520)(52105112)(3002001)(6055026)(148016)(149066)(150057)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(201708071742011)(7699051)(76991095); SRVR:DB3PR0502MB4043; BCL:0; PCL:0; RULEID:; SRVR:DB3PR0502MB4043; x-forefront-prvs: 08864C38AC x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(366004)(346002)(136003)(396003)(39850400004)(189003)(199004)(2906002)(97736004)(33656002)(229853002)(102836004)(82746002)(36756003)(6506007)(316002)(186003)(8936002)(53546011)(26005)(6916009)(54906003)(478600001)(106356001)(71200400001)(66066001)(105586002)(14454004)(86362001)(2616005)(3846002)(6246003)(11346002)(446003)(8676002)(81166006)(7736002)(4326008)(305945005)(71190400001)(68736007)(14444005)(5660300001)(25786009)(81156014)(486006)(6512007)(99286004)(6116002)(256004)(6436002)(53936002)(476003)(6486002)(76176011)(83716004); DIR:OUT; SFP:1101; SCL:1; SRVR:DB3PR0502MB4043; H:DB3PR0502MB3980.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: l4Z5Z1ofX5Hu9Yt0loe+c8JlRKPSc+FcEVFjWhWozUO+djhb8qJ2j0INvk5ZJr6BJktg0FyT9YJPg3a/P2f9VdQMc4YlFMsFdxnTZsKDIZvAg1TW6pobt2z7MWvggXeGsjUwFx6NoKtanRnE7xtQFCVo6/hC/BJIEkxChoP1S0/BsF95ZF72J5JN6JT8aIkgrL10J/gphyNuOys5inUaTMAWSmvHtaW9M/7hVMItWdtY79Z5xFcJxgS0YR0jt1m1KQXzI4cVhTwyNTUk+m6goLEaJ2K26CIBJn3y0dJev4DG277yP4KH2nQ7Khszf/yr spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-ID: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 26560b9e-08c3-46b9-63fd-08d661f51f93 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Dec 2018 18:51:14.2927 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0502MB4043 Subject: Re: [dpdk-dev] [PATCH] malloc: make alignment requirements more stringent X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Dec 2018 18:51:17 -0000 > On Dec 14, 2018, at 3:54 AM, Anatoly Burakov = wrote: >=20 > The external heaps API already implicitly expects start address > of the external memory area to be page-aligned, but it is not > enforced or documented. Fix this by implementing additional > parameter checks at memory add call, and document the page > alignment requirement explicitly. >=20 > Fixes: 7d75c31014f7 ("malloc: allow adding memory to named heaps") > Cc: stable@dpdk.org >=20 > Signed-off-by: Anatoly Burakov > Suggested-by: Yongseok Koh > --- Acked-by: Yongseok Koh =20 Thanks > lib/librte_eal/common/include/rte_malloc.h | 4 ++-- > lib/librte_eal/common/rte_malloc.c | 8 +++----- > 2 files changed, 5 insertions(+), 7 deletions(-) >=20 > diff --git a/lib/librte_eal/common/include/rte_malloc.h b/lib/librte_eal/= common/include/rte_malloc.h > index 7249e6aae..a5290b074 100644 > --- a/lib/librte_eal/common/include/rte_malloc.h > +++ b/lib/librte_eal/common/include/rte_malloc.h > @@ -282,9 +282,9 @@ rte_malloc_get_socket_stats(int socket, > * @param heap_name > * Name of the heap to add memory chunk to > * @param va_addr > - * Start of virtual area to add to the heap > + * Start of virtual area to add to the heap. Must be aligned by ``page= _sz``. > * @param len > - * Length of virtual area to add to the heap > + * Length of virtual area to add to the heap. Must be aligned by ``pag= e_sz``. > * @param iova_addrs > * Array of page IOVA addresses corresponding to each page in this memo= ry > * area. Can be NULL, in which case page IOVA addresses will be set to > diff --git a/lib/librte_eal/common/rte_malloc.c b/lib/librte_eal/common/r= te_malloc.c > index 0da5ad5e8..46abbfcf6 100644 > --- a/lib/librte_eal/common/rte_malloc.c > +++ b/lib/librte_eal/common/rte_malloc.c > @@ -345,6 +345,9 @@ rte_malloc_heap_memory_add(const char *heap_name, voi= d *va_addr, size_t len, >=20 > if (heap_name =3D=3D NULL || va_addr =3D=3D NULL || > page_sz =3D=3D 0 || !rte_is_power_of_2(page_sz) || > + RTE_ALIGN(len, page_sz) !=3D len || > + !rte_is_aligned(va_addr, page_sz) || > + ((len / page_sz) !=3D n_pages && iova_addrs !=3D NULL) || > strnlen(heap_name, RTE_HEAP_NAME_MAX_LEN) =3D=3D 0 || > strnlen(heap_name, RTE_HEAP_NAME_MAX_LEN) =3D=3D > RTE_HEAP_NAME_MAX_LEN) { > @@ -367,11 +370,6 @@ rte_malloc_heap_memory_add(const char *heap_name, vo= id *va_addr, size_t len, > goto unlock; > } > n =3D len / page_sz; > - if (n !=3D n_pages && iova_addrs !=3D NULL) { > - rte_errno =3D EINVAL; > - ret =3D -1; > - goto unlock; > - } >=20 > rte_spinlock_lock(&heap->lock); > ret =3D malloc_heap_add_external_memory(heap, va_addr, iova_addrs, n, > --=20 > 2.17.1