From nobody Fri Dec 19 20:12:22 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2689151126; Wed, 13 Mar 2024 17:05:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710349525; cv=none; b=RSqofSm/z/ZuTUKogO7UDydHmBuiujDv/2XaD0+L74J+pNhCIdNCAmQxlG4EQO7Y4r1j7rFdb0ND9ITDvN6pvoAfsjfctjUchZWTHYsXOlq77B3oBhKJy7r9Bc6Hf1XoApuYp+yFGN83Zk2/FEX8Sn3vNURldnjDmGsKPaSHLlg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710349525; c=relaxed/simple; bh=C0l9zfBD03qqUENYkRjOgyyKCuXIjG2HyK6nNyqrk+o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k3kvhaMuY0TCsJ+6kclGbMz7CtQvyOxzUXkKajT3Y1ZZ1NURyxWaAWMU65saU+YjixgrB75xbUxfl83YAjRi6e5DFWA1tNESHfFAO6XapyKw5NX9mnKoJjTUTtk6dj7E8rO/V6Bv+3LIFveqvqjnikyimAHVaIvCL6eksoik7R4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BhiMiup8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BhiMiup8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C457C43394; Wed, 13 Mar 2024 17:05:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710349523; bh=C0l9zfBD03qqUENYkRjOgyyKCuXIjG2HyK6nNyqrk+o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BhiMiup8Gp0lS0/qWP4DaP8GTdjLpfULgsp89gABClOVMpjOmbSNx4Ika169xX6q1 jbuELS1ckdH9mkVlYrxT/HY4+mDFC3pqfD6YR8qvUlvov+pnL8ux/CF+jc0+3chiWO gKxheJnpBS+jqQjtw3UG+EV9rstF2Q5KCRlPfLh2kjG7S01qeH2Rod+PYa6fWjLrVQ vY21UWQpRpYZv/iWeYUl55nRfd0g0TOem/eMVgJybmWNfxjj1LMuyBm9S46i3i5gbn I/aAHkvf3Y0NQvXOsZRWBxRFxdNs3FdyRT0jUvTFKXh8CEVsWoMr2asPblK9/F2ezf NMBQcURzNEfMg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Christophe Leroy , Andrew Morton , Leonardo Bras , Michael Ellerman , Shuah Khan , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 40/41] selftests/vm: fix map_hugetlb length used for testing read and write Date: Wed, 13 Mar 2024 13:04:34 -0400 Message-ID: <20240313170435.616724-41-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240313170435.616724-1-sashal@kernel.org> References: <20240313170435.616724-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.19.310-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.19.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.19.310-rc1 X-KernelTest-Deadline: 2024-03-15T17:04+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Christophe Leroy [ Upstream commit cabc30da10e677c67ab9a136b1478175734715c5 ] Commit fa7b9a805c79 ("tools/selftest/vm: allow choosing mem size and page size in map_hugetlb") added the possibility to change the size of memory mapped for the test, but left the read and write test using the default value. This is unnoticed when mapping a length greater than the default one, but segfaults otherwise. Fix read_bytes() and write_bytes() by giving them the real length. Also fix the call to munmap(). Fixes: fa7b9a805c79 ("tools/selftest/vm: allow choosing mem size and page s= ize in map_hugetlb") Signed-off-by: Christophe Leroy Signed-off-by: Andrew Morton Reviewed-by: Leonardo Bras Cc: Michael Ellerman Cc: Shuah Khan Cc: Link: http://lkml.kernel.org/r/9a404a13c871c4bd0ba9ede68f69a1225180dd7e.158= 0978385.git.christophe.leroy@c-s.fr Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- tools/testing/selftests/vm/map_hugetlb.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/vm/map_hugetlb.c b/tools/testing/selft= ests/vm/map_hugetlb.c index 7b41cc6ecb0bf..c65c55b7a789f 100644 --- a/tools/testing/selftests/vm/map_hugetlb.c +++ b/tools/testing/selftests/vm/map_hugetlb.c @@ -46,20 +46,20 @@ static void check_bytes(char *addr) printf("First hex is %x\n", *((unsigned int *)addr)); } =20 -static void write_bytes(char *addr) +static void write_bytes(char *addr, size_t length) { unsigned long i; =20 - for (i =3D 0; i < LENGTH; i++) + for (i =3D 0; i < length; i++) *(addr + i) =3D (char)i; } =20 -static int read_bytes(char *addr) +static int read_bytes(char *addr, size_t length) { unsigned long i; =20 check_bytes(addr); - for (i =3D 0; i < LENGTH; i++) + for (i =3D 0; i < length; i++) if (*(addr + i) !=3D (char)i) { printf("Mismatch at %lu\n", i); return 1; @@ -103,11 +103,11 @@ int main(int argc, char **argv) =20 printf("Returned address is %p\n", addr); check_bytes(addr); - write_bytes(addr); - ret =3D read_bytes(addr); + write_bytes(addr, length); + ret =3D read_bytes(addr, length); =20 /* munmap() length of MAP_HUGETLB memory must be hugepage aligned */ - if (munmap(addr, LENGTH)) { + if (munmap(addr, length)) { perror("munmap"); exit(1); } --=20 2.43.0