From 69f5352cb6a1df1f6614ae73cc2748f5b3f8f9f3 Mon Sep 17 00:00:00 2001 From: Omar Sandoval Date: Wed, 22 Feb 2023 02:02:13 -0800 Subject: [PATCH] tests: replace mmap with test kernel module for test_read_physical() tests.linux_kernel.helpers.test_mm.TestMm.test_read_physical() fails on Arm when the user page is mapped from high memory. Replace it with a test case that uses the test physical address from the test kernel module and asserts the expected PRNG data. (We will probably run into more tests that fail with high memory once #244 is merged.) Signed-off-by: Omar Sandoval --- tests/linux_kernel/helpers/test_mm.py | 17 +++++++++++------ tests/linux_kernel/kmod/drgn_test.c | 9 +++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/tests/linux_kernel/helpers/test_mm.py b/tests/linux_kernel/helpers/test_mm.py index fdf7c390e..c9b9bf4b1 100644 --- a/tests/linux_kernel/helpers/test_mm.py +++ b/tests/linux_kernel/helpers/test_mm.py @@ -6,6 +6,7 @@ import mmap import os import struct +import sys import tempfile import unittest @@ -43,6 +44,7 @@ from tests.linux_kernel import ( LinuxKernelTestCase, mlock, + prng32, skip_unless_have_full_mm_support, skip_unless_have_test_kmod, ) @@ -227,13 +229,16 @@ def test_virt_to_phys(self): virt_to_phys(self.prog["drgn_test_va"]), self.prog["drgn_test_pa"] ) + @skip_unless_have_test_kmod def test_read_physical(self): - with self._pages() as (map, _, pfns): - for i, pfn in enumerate(pfns): - self.assertEqual( - self.prog.read(pfn * mmap.PAGESIZE, mmap.PAGESIZE, True), - map[i * mmap.PAGESIZE : (i + 1) * mmap.PAGESIZE], - ) + expected = bytearray() + for x in prng32("PAGE"): + expected.extend(x.to_bytes(4, sys.byteorder)) + if len(expected) >= mmap.PAGESIZE: + break + self.assertEqual( + self.prog.read(self.prog["drgn_test_pa"], mmap.PAGESIZE, True), expected + ) @skip_unless_have_full_mm_support def test_access_process_vm(self): diff --git a/tests/linux_kernel/kmod/drgn_test.c b/tests/linux_kernel/kmod/drgn_test.c index a32c3c1a8..11171f751 100644 --- a/tests/linux_kernel/kmod/drgn_test.c +++ b/tests/linux_kernel/kmod/drgn_test.c @@ -150,6 +150,9 @@ struct page *drgn_test_compound_page; static int drgn_test_mm_init(void) { + u32 fill; + size_t i; + drgn_test_page = alloc_page(GFP_KERNEL); if (!drgn_test_page) return -ENOMEM; @@ -157,6 +160,12 @@ static int drgn_test_mm_init(void) if (!drgn_test_compound_page) return -ENOMEM; drgn_test_va = page_address(drgn_test_page); + // Fill the page with a PRNG sequence. + fill = drgn_test_prng32_seed("PAGE"); + for (i = 0; i < PAGE_SIZE / sizeof(fill); i++) { + fill = drgn_test_prng32(fill); + ((u32 *)drgn_test_va)[i] = fill; + } drgn_test_pa = virt_to_phys(drgn_test_va); drgn_test_pfn = PHYS_PFN(drgn_test_pa); return 0;