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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB2D3C433F5 for ; Tue, 1 Mar 2022 20:16:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2809A8D0002; Tue, 1 Mar 2022 15:16:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 230098D0001; Tue, 1 Mar 2022 15:16:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0FBD08D0002; Tue, 1 Mar 2022 15:16:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0089.hostedemail.com [216.40.44.89]) by kanga.kvack.org (Postfix) with ESMTP id F3FD88D0001 for ; Tue, 1 Mar 2022 15:16:21 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id AA8C09CA14 for ; Tue, 1 Mar 2022 20:16:21 +0000 (UTC) X-FDA: 79196924562.27.3B9BF96 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf16.hostedemail.com (Postfix) with ESMTP id 0F19718001B for ; Tue, 1 Mar 2022 20:16:15 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1755961746; Tue, 1 Mar 2022 20:16:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D45B5C340EE; Tue, 1 Mar 2022 20:16:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646165774; bh=6u5hYmnVqzpjLai+66w0PPoKJevf0lUcfY+US3gukLs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mlX+h0vIjKf6Xdt/yOCL/Yt84kpIYb4MuNhSRa2npSxj+4Swkl6lZRdkFaEn8e2js Yjlhh2DFRj0jUc+DNWMw0lgx+Rar8i2nNHXLUTWGEO7Ua0Ly1qvGBxMIl/I6gCWHb4 ewTYiFUCsC67O6TkxHiN/cMsh5eJYtfecBrXKSxnqNPta11yzePg3k62Y8pMzZAY1L aY2/t5Xd62VGt3CJAoFC9ruF7rgWCxuQ1kKUO8uLxY466UdOdenDyCItOc9wwwtVPP LDy6QIiatjjlkjbU02oyMuRqx0dA30+XxoM1k52JTRD42RZlUELfnJPpTjvOWMct7I eap3n/0Dc/WgA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Aneesh Kumar K.V" , Michael Ellerman , Jann Horn , Shuah Khan , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org, linux-kselftest@vger.kernel.org Subject: [PATCH AUTOSEL 5.16 27/28] selftest/vm: fix map_fixed_noreplace test failure Date: Tue, 1 Mar 2022 15:13:32 -0500 Message-Id: <20220301201344.18191-27-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220301201344.18191-1-sashal@kernel.org> References: <20220301201344.18191-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 0F19718001B X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=mlX+h0vI; spf=pass (imf16.hostedemail.com: domain of sashal@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Stat-Signature: js31i49chuiopedx1emgnkbrpyy7h11u X-HE-Tag: 1646165775-85987 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: "Aneesh Kumar K.V" [ Upstream commit f39c58008dee7ab5fc94c3f1995a21e886801df0 ] On the latest RHEL the test fails due to executable mapped at 256MB address # ./map_fixed_noreplace mmap() @ 0x10000000-0x10050000 p=3D0xffffffffffffffff result=3DFile e= xists 10000000-10010000 r-xp 00000000 fd:04 34905657 = /root/rpmbuild/BUILD/kernel-5.14.0-56.el9/linux-5.14.0-56.el9.ppc64le= /tools/testing/selftests/vm/map_fixed_noreplace 10010000-10020000 r--p 00000000 fd:04 34905657 = /root/rpmbuild/BUILD/kernel-5.14.0-56.el9/linux-5.14.0-56.el9.ppc64le= /tools/testing/selftests/vm/map_fixed_noreplace 10020000-10030000 rw-p 00010000 fd:04 34905657 = /root/rpmbuild/BUILD/kernel-5.14.0-56.el9/linux-5.14.0-56.el9.ppc64le= /tools/testing/selftests/vm/map_fixed_noreplace 10029b90000-10029bc0000 rw-p 00000000 00:00 0 = [heap] 7fffbb510000-7fffbb750000 r-xp 00000000 fd:04 24534 = /usr/lib64/libc.so.6 7fffbb750000-7fffbb760000 r--p 00230000 fd:04 24534 = /usr/lib64/libc.so.6 7fffbb760000-7fffbb770000 rw-p 00240000 fd:04 24534 = /usr/lib64/libc.so.6 7fffbb780000-7fffbb7a0000 r--p 00000000 00:00 0 = [vvar] 7fffbb7a0000-7fffbb7b0000 r-xp 00000000 00:00 0 = [vdso] 7fffbb7b0000-7fffbb800000 r-xp 00000000 fd:04 24514 = /usr/lib64/ld64.so.2 7fffbb800000-7fffbb810000 r--p 00040000 fd:04 24514 = /usr/lib64/ld64.so.2 7fffbb810000-7fffbb820000 rw-p 00050000 fd:04 24514 = /usr/lib64/ld64.so.2 7fffd93f0000-7fffd9420000 rw-p 00000000 00:00 0 = [stack] Error: couldn't map the space we need for the test Fix this by finding a free address using mmap instead of hardcoding BASE_ADDRESS. Link: https://lkml.kernel.org/r/20220217083417.373823-1-aneesh.kumar@linu= x.ibm.com Signed-off-by: Aneesh Kumar K.V Cc: Michael Ellerman Cc: Jann Horn Cc: Shuah Khan Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- .../selftests/vm/map_fixed_noreplace.c | 49 ++++++++++++++----- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/vm/map_fixed_noreplace.c b/tools/tes= ting/selftests/vm/map_fixed_noreplace.c index d91bde5112686..eed44322d1a63 100644 --- a/tools/testing/selftests/vm/map_fixed_noreplace.c +++ b/tools/testing/selftests/vm/map_fixed_noreplace.c @@ -17,9 +17,6 @@ #define MAP_FIXED_NOREPLACE 0x100000 #endif =20 -#define BASE_ADDRESS (256ul * 1024 * 1024) - - static void dump_maps(void) { char cmd[32]; @@ -28,18 +25,46 @@ static void dump_maps(void) system(cmd); } =20 +static unsigned long find_base_addr(unsigned long size) +{ + void *addr; + unsigned long flags; + + flags =3D MAP_PRIVATE | MAP_ANONYMOUS; + addr =3D mmap(NULL, size, PROT_NONE, flags, -1, 0); + if (addr =3D=3D MAP_FAILED) { + printf("Error: couldn't map the space we need for the test\n"); + return 0; + } + + if (munmap(addr, size) !=3D 0) { + printf("Error: couldn't map the space we need for the test\n"); + return 0; + } + return (unsigned long)addr; +} + int main(void) { + unsigned long base_addr; unsigned long flags, addr, size, page_size; char *p; =20 page_size =3D sysconf(_SC_PAGE_SIZE); =20 + //let's find a base addr that is free before we start the tests + size =3D 5 * page_size; + base_addr =3D find_base_addr(size); + if (!base_addr) { + printf("Error: couldn't map the space we need for the test\n"); + return 1; + } + flags =3D MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE; =20 // Check we can map all the areas we need below errno =3D 0; - addr =3D BASE_ADDRESS; + addr =3D base_addr; size =3D 5 * page_size; p =3D mmap((void *)addr, size, PROT_NONE, flags, -1, 0); =20 @@ -60,7 +85,7 @@ int main(void) printf("unmap() successful\n"); =20 errno =3D 0; - addr =3D BASE_ADDRESS + page_size; + addr =3D base_addr + page_size; size =3D 3 * page_size; p =3D mmap((void *)addr, size, PROT_NONE, flags, -1, 0); printf("mmap() @ 0x%lx-0x%lx p=3D%p result=3D%m\n", addr, addr + size, = p); @@ -80,7 +105,7 @@ int main(void) * +4 | free | new */ errno =3D 0; - addr =3D BASE_ADDRESS; + addr =3D base_addr; size =3D 5 * page_size; p =3D mmap((void *)addr, size, PROT_NONE, flags, -1, 0); printf("mmap() @ 0x%lx-0x%lx p=3D%p result=3D%m\n", addr, addr + size, = p); @@ -101,7 +126,7 @@ int main(void) * +4 | free | */ errno =3D 0; - addr =3D BASE_ADDRESS + (2 * page_size); + addr =3D base_addr + (2 * page_size); size =3D page_size; p =3D mmap((void *)addr, size, PROT_NONE, flags, -1, 0); printf("mmap() @ 0x%lx-0x%lx p=3D%p result=3D%m\n", addr, addr + size, = p); @@ -121,7 +146,7 @@ int main(void) * +4 | free | new */ errno =3D 0; - addr =3D BASE_ADDRESS + (3 * page_size); + addr =3D base_addr + (3 * page_size); size =3D 2 * page_size; p =3D mmap((void *)addr, size, PROT_NONE, flags, -1, 0); printf("mmap() @ 0x%lx-0x%lx p=3D%p result=3D%m\n", addr, addr + size, = p); @@ -141,7 +166,7 @@ int main(void) * +4 | free | */ errno =3D 0; - addr =3D BASE_ADDRESS; + addr =3D base_addr; size =3D 2 * page_size; p =3D mmap((void *)addr, size, PROT_NONE, flags, -1, 0); printf("mmap() @ 0x%lx-0x%lx p=3D%p result=3D%m\n", addr, addr + size, = p); @@ -161,7 +186,7 @@ int main(void) * +4 | free | */ errno =3D 0; - addr =3D BASE_ADDRESS; + addr =3D base_addr; size =3D page_size; p =3D mmap((void *)addr, size, PROT_NONE, flags, -1, 0); printf("mmap() @ 0x%lx-0x%lx p=3D%p result=3D%m\n", addr, addr + size, = p); @@ -181,7 +206,7 @@ int main(void) * +4 | free | new */ errno =3D 0; - addr =3D BASE_ADDRESS + (4 * page_size); + addr =3D base_addr + (4 * page_size); size =3D page_size; p =3D mmap((void *)addr, size, PROT_NONE, flags, -1, 0); printf("mmap() @ 0x%lx-0x%lx p=3D%p result=3D%m\n", addr, addr + size, = p); @@ -192,7 +217,7 @@ int main(void) return 1; } =20 - addr =3D BASE_ADDRESS; + addr =3D base_addr; size =3D 5 * page_size; if (munmap((void *)addr, size) !=3D 0) { dump_maps(); --=20 2.34.1