forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge patch series "RISC-V: mm: Make SV48 the default address space"
Charlie Jenkins <[email protected]> says: Make sv48 the default address space for mmap as some applications currently depend on this assumption. Users can now select a desired address space using a non-zero hint address to mmap. Previously, requesting the default address space from mmap by passing zero as the hint address would result in using the largest address space possible. Some applications depend on empty bits in the virtual address space, like Go and Java, so this patch provides more flexibility for application developers. * b4-shazam-merge: RISC-V: mm: Document mmap changes RISC-V: mm: Update pgtable comment documentation RISC-V: mm: Add tests for RISC-V mm RISC-V: mm: Restrict address space for sv39,sv48,sv57 Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
- Loading branch information
Showing
11 changed files
with
261 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mmap_bottomup | ||
mmap_default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# SPDX-License-Identifier: GPL-2.0 | ||
# Copyright (C) 2021 ARM Limited | ||
# Originally tools/testing/arm64/abi/Makefile | ||
|
||
# Additional include paths needed by kselftest.h and local headers | ||
CFLAGS += -D_GNU_SOURCE -std=gnu99 -I. | ||
|
||
TEST_GEN_FILES := testcases/mmap_default testcases/mmap_bottomup | ||
|
||
TEST_PROGS := testcases/run_mmap.sh | ||
|
||
include ../../lib.mk | ||
|
||
$(OUTPUT)/mm: testcases/mmap_default.c testcases/mmap_bottomup.c testcases/mmap_tests.h | ||
$(CC) -o$@ $(CFLAGS) $(LDFLAGS) $^ |
35 changes: 35 additions & 0 deletions
35
tools/testing/selftests/riscv/mm/testcases/mmap_bottomup.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
#include <sys/mman.h> | ||
#include <testcases/mmap_test.h> | ||
|
||
#include "../../kselftest_harness.h" | ||
|
||
TEST(infinite_rlimit) | ||
{ | ||
// Only works on 64 bit | ||
#if __riscv_xlen == 64 | ||
struct addresses mmap_addresses; | ||
|
||
EXPECT_EQ(BOTTOM_UP, memory_layout()); | ||
|
||
do_mmaps(&mmap_addresses); | ||
|
||
EXPECT_NE(MAP_FAILED, mmap_addresses.no_hint); | ||
EXPECT_NE(MAP_FAILED, mmap_addresses.on_37_addr); | ||
EXPECT_NE(MAP_FAILED, mmap_addresses.on_38_addr); | ||
EXPECT_NE(MAP_FAILED, mmap_addresses.on_46_addr); | ||
EXPECT_NE(MAP_FAILED, mmap_addresses.on_47_addr); | ||
EXPECT_NE(MAP_FAILED, mmap_addresses.on_55_addr); | ||
EXPECT_NE(MAP_FAILED, mmap_addresses.on_56_addr); | ||
|
||
EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.no_hint); | ||
EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_37_addr); | ||
EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_38_addr); | ||
EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_46_addr); | ||
EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.on_47_addr); | ||
EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.on_55_addr); | ||
EXPECT_GT(1UL << 56, (unsigned long)mmap_addresses.on_56_addr); | ||
#endif | ||
} | ||
|
||
TEST_HARNESS_MAIN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
#include <sys/mman.h> | ||
#include <testcases/mmap_test.h> | ||
|
||
#include "../../kselftest_harness.h" | ||
|
||
TEST(default_rlimit) | ||
{ | ||
// Only works on 64 bit | ||
#if __riscv_xlen == 64 | ||
struct addresses mmap_addresses; | ||
|
||
EXPECT_EQ(TOP_DOWN, memory_layout()); | ||
|
||
do_mmaps(&mmap_addresses); | ||
|
||
EXPECT_NE(MAP_FAILED, mmap_addresses.no_hint); | ||
EXPECT_NE(MAP_FAILED, mmap_addresses.on_37_addr); | ||
EXPECT_NE(MAP_FAILED, mmap_addresses.on_38_addr); | ||
EXPECT_NE(MAP_FAILED, mmap_addresses.on_46_addr); | ||
EXPECT_NE(MAP_FAILED, mmap_addresses.on_47_addr); | ||
EXPECT_NE(MAP_FAILED, mmap_addresses.on_55_addr); | ||
EXPECT_NE(MAP_FAILED, mmap_addresses.on_56_addr); | ||
|
||
EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.no_hint); | ||
EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_37_addr); | ||
EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_38_addr); | ||
EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_46_addr); | ||
EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.on_47_addr); | ||
EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.on_55_addr); | ||
EXPECT_GT(1UL << 56, (unsigned long)mmap_addresses.on_56_addr); | ||
#endif | ||
} | ||
|
||
TEST_HARNESS_MAIN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-only */ | ||
#ifndef _TESTCASES_MMAP_TEST_H | ||
#define _TESTCASES_MMAP_TEST_H | ||
#include <sys/mman.h> | ||
#include <sys/resource.h> | ||
#include <stddef.h> | ||
|
||
#define TOP_DOWN 0 | ||
#define BOTTOM_UP 1 | ||
|
||
struct addresses { | ||
int *no_hint; | ||
int *on_37_addr; | ||
int *on_38_addr; | ||
int *on_46_addr; | ||
int *on_47_addr; | ||
int *on_55_addr; | ||
int *on_56_addr; | ||
}; | ||
|
||
static inline void do_mmaps(struct addresses *mmap_addresses) | ||
{ | ||
/* | ||
* Place all of the hint addresses on the boundaries of mmap | ||
* sv39, sv48, sv57 | ||
* User addresses end at 1<<38, 1<<47, 1<<56 respectively | ||
*/ | ||
void *on_37_bits = (void *)(1UL << 37); | ||
void *on_38_bits = (void *)(1UL << 38); | ||
void *on_46_bits = (void *)(1UL << 46); | ||
void *on_47_bits = (void *)(1UL << 47); | ||
void *on_55_bits = (void *)(1UL << 55); | ||
void *on_56_bits = (void *)(1UL << 56); | ||
|
||
int prot = PROT_READ | PROT_WRITE; | ||
int flags = MAP_PRIVATE | MAP_ANONYMOUS; | ||
|
||
mmap_addresses->no_hint = | ||
mmap(NULL, 5 * sizeof(int), prot, flags, 0, 0); | ||
mmap_addresses->on_37_addr = | ||
mmap(on_37_bits, 5 * sizeof(int), prot, flags, 0, 0); | ||
mmap_addresses->on_38_addr = | ||
mmap(on_38_bits, 5 * sizeof(int), prot, flags, 0, 0); | ||
mmap_addresses->on_46_addr = | ||
mmap(on_46_bits, 5 * sizeof(int), prot, flags, 0, 0); | ||
mmap_addresses->on_47_addr = | ||
mmap(on_47_bits, 5 * sizeof(int), prot, flags, 0, 0); | ||
mmap_addresses->on_55_addr = | ||
mmap(on_55_bits, 5 * sizeof(int), prot, flags, 0, 0); | ||
mmap_addresses->on_56_addr = | ||
mmap(on_56_bits, 5 * sizeof(int), prot, flags, 0, 0); | ||
} | ||
|
||
static inline int memory_layout(void) | ||
{ | ||
int prot = PROT_READ | PROT_WRITE; | ||
int flags = MAP_PRIVATE | MAP_ANONYMOUS; | ||
|
||
void *value1 = mmap(NULL, sizeof(int), prot, flags, 0, 0); | ||
void *value2 = mmap(NULL, sizeof(int), prot, flags, 0, 0); | ||
|
||
return value2 > value1; | ||
} | ||
#endif /* _TESTCASES_MMAP_TEST_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
original_stack_limit=$(ulimit -s) | ||
|
||
./mmap_default | ||
|
||
# Force mmap_bottomup to be ran with bottomup memory due to | ||
# the unlimited stack | ||
ulimit -s unlimited | ||
./mmap_bottomup | ||
ulimit -s $original_stack_limit |