Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/mm: protection_keys: save/restore nr_hugepages settings

Save and restore nr_hugepages before changing it during the test. A test
should not change system wide settings.

Link: https://lkml.kernel.org/r/20240125154608.720072-5-usama.anjum@collabora.com
Fixes: 5f23f6d082a9 ("x86/pkeys: Add self-tests")
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Muhammad Usama Anjum and committed by
Andrew Morton
c23ea617 7d695b1c

+34
+34
tools/testing/selftests/mm/protection_keys.c
··· 54 54 u64 shadow_pkey_reg; 55 55 int dprint_in_signal; 56 56 char dprint_in_signal_buffer[DPRINT_IN_SIGNAL_BUF_SIZE]; 57 + char buf[256]; 57 58 58 59 void cat_into_file(char *str, char *file) 59 60 { ··· 1745 1744 shadow_pkey_reg = __read_pkey_reg(); 1746 1745 } 1747 1746 1747 + void restore_settings_atexit(void) 1748 + { 1749 + cat_into_file(buf, "/proc/sys/vm/nr_hugepages"); 1750 + } 1751 + 1752 + void save_settings(void) 1753 + { 1754 + int fd; 1755 + int err; 1756 + 1757 + if (geteuid()) 1758 + return; 1759 + 1760 + fd = open("/proc/sys/vm/nr_hugepages", O_RDONLY); 1761 + if (fd < 0) { 1762 + fprintf(stderr, "error opening\n"); 1763 + perror("error: "); 1764 + exit(__LINE__); 1765 + } 1766 + 1767 + /* -1 to guarantee leaving the trailing \0 */ 1768 + err = read(fd, buf, sizeof(buf)-1); 1769 + if (err < 0) { 1770 + fprintf(stderr, "error reading\n"); 1771 + perror("error: "); 1772 + exit(__LINE__); 1773 + } 1774 + 1775 + atexit(restore_settings_atexit); 1776 + close(fd); 1777 + } 1778 + 1748 1779 int main(void) 1749 1780 { 1750 1781 int nr_iterations = 22; ··· 1784 1751 1785 1752 srand((unsigned int)time(NULL)); 1786 1753 1754 + save_settings(); 1787 1755 setup_handlers(); 1788 1756 1789 1757 printf("has pkeys: %d\n", pkeys_supported);