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 31BF6C433EF for ; Tue, 1 Mar 2022 20:20:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BCC248D0003; Tue, 1 Mar 2022 15:20:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B55518D0001; Tue, 1 Mar 2022 15:20:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A1BE48D0003; Tue, 1 Mar 2022 15:20:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id 92A488D0001 for ; Tue, 1 Mar 2022 15:20:40 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 462E2181C9D34 for ; Tue, 1 Mar 2022 20:20:40 +0000 (UTC) X-FDA: 79196935440.17.9C89082 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf05.hostedemail.com (Postfix) with ESMTP id 9D8D910000E for ; Tue, 1 Mar 2022 20:20:39 +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 EF87B60AE2; Tue, 1 Mar 2022 20:20:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5754C340EE; Tue, 1 Mar 2022 20:20:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646166038; bh=6u5hYmnVqzpjLai+66w0PPoKJevf0lUcfY+US3gukLs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=APXBf5BDjidGgtcoqz7mSLkoct3N5I0FfAFLE7WlFQaHbHGkSH5b8+O5JkB+uLJKd CG7xE3p1W3T/D4+ARL2Ne477K1U38YLKsKERxrv6Uy43RCMojunkrTO2MHJvUoIS13 8Npjkf1od5xIyZMtMd8nR3maz7Qt6Vdq6djO7QWYhUrPDK/Fsh7dk0qqhoGE6UjD99 9YFM7DRIDVUW4Rbj1sNtQJ1QUgsaPDpkZLMXb23auDQ+sadV5tcM5o9VpempbaoejM 84a/DGK5W1oGoFpQmOwlLH1JgRZJHpHTzFuukRgPKvt7xUjLToqWjEN5hHNHHQ3PIB 6xcLtXHjY274A== 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.4 10/11] selftest/vm: fix map_fixed_noreplace test failure Date: Tue, 1 Mar 2022 15:19:43 -0500 Message-Id: <20220301201951.19066-10-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220301201951.19066-1-sashal@kernel.org> References: <20220301201951.19066-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-Rspamd-Queue-Id: 9D8D910000E X-Stat-Signature: hdpt17yjzq8uwtptqz4n9wnmyxeiri1g X-Rspam-User: Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=APXBf5BD; spf=pass (imf05.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-Rspamd-Server: rspam07 X-HE-Tag: 1646166039-208968 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