From nobody Thu Nov 28 21:46:09 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 6797915383A for ; Thu, 26 Sep 2024 15:21:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727364062; cv=none; b=P4F7nwhHJa/YvER7E/+uXOZNKQ/TR0kT3YfW//msnEczHWDoCy874fEB+RB5hkOkvZagTKKt6gjDEC7Oh/89V2LpI84ofe21yMJZT2QJrah73vJ0kdQdM+53S81uy9KlznoUlN0Xa872tiK5weMNfa0M6MEtGq3NSOdHaXAUXqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727364062; c=relaxed/simple; bh=txWuXuILBv5S6sJcY8jEKBUNzgwD+nBQjS66HY/0zYE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V4il1Vp2zhQiJHjq5O8zCGJ5/0NhAqSQRdNTgI5Jd4YIoPUlFSbky+wYXdxCM6in6P5LnT1MiMpepKaoyTmwS2I7rYxWoIv40o7pXw7jClZL+ZM2MRjd2rH5QHkKL8poTwQ7hUiZCviuVA2ruLjiz3JC+JwxQcL+G2cWCx2lahM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=V1R9LKUG; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="V1R9LKUG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727364059; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dEU685hmTiGjO6vRfe2s3dQC7sd7dLb6c9biHu+eUc8=; b=V1R9LKUG5vhHWUQwDPCH+b8S3413Wpx1vJtWj80ccnSJaU3XNftFpGchSNX4J/NjX74bt3 9MxCCXbVsAAARoboSAPS7usq+xHZ96TDASmZgxx2uYVcxvd20Rv78UBAu0faSfTQrctRQi G+RjBaAq0S33Hrj9//AdIK6uBkFPHKw= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-620-e8N7HJqHNUW0sILja7qzCw-1; Thu, 26 Sep 2024 11:20:54 -0400 X-MC-Unique: e8N7HJqHNUW0sILja7qzCw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3681B190FEFC; Thu, 26 Sep 2024 15:20:53 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.16.71]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C20001944D16; Thu, 26 Sep 2024 15:20:50 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, David Hildenbrand , Andrew Morton , Shuah Khan , Mario Casquero , Breno Leitao Subject: [PATCH v1 1/2] selftests/mm: hugetlb_fault_after_madv: use default hguetlb page size Date: Thu, 26 Sep 2024 17:20:43 +0200 Message-ID: <20240926152044.2205129-2-david@redhat.com> In-Reply-To: <20240926152044.2205129-1-david@redhat.com> References: <20240926152044.2205129-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Content-Type: text/plain; charset="utf-8" We currently assume that the hugetlb page size is 2 MiB, which is why we mmap() a 2 MiB range. Is the default hugetlb size is larger, mmap() will fail because the range is not suitable. If the default hugetlb size is smaller (e.g., s390x), mmap() will fail because we would need more than one hugetlb page, but just asserted that we have exactly one. So let's simply use the default hugetlb page size instead of hard-coded 2 MiB, so the test isn't unconditionally skipped on architectures like s390x. Before this patch on s390x: $ ./hugetlb_fault_after_madv 1..0 # SKIP Failed to allocated huge page With this change on s390x: $ ./hugetlb_fault_after_madv While at it, make "huge_ptr" static. Reported-by: Mario Casquero Signed-off-by: David Hildenbrand Reviewed-by: Breno Leitao Reviewed-by: Shuah Khan Tested-by: Mario Casquero --- .../selftests/mm/hugetlb_fault_after_madv.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c b/tools/= testing/selftests/mm/hugetlb_fault_after_madv.c index 73b81c632366..ff3ba675278d 100644 --- a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c +++ b/tools/testing/selftests/mm/hugetlb_fault_after_madv.c @@ -9,10 +9,10 @@ #include "vm_util.h" #include "../kselftest.h" =20 -#define MMAP_SIZE (1 << 21) #define INLOOP_ITER 100 =20 -char *huge_ptr; +static char *huge_ptr; +static size_t huge_page_size; =20 /* Touch the memory while it is being madvised() */ void *touch(void *unused) @@ -30,7 +30,7 @@ void *madv(void *unused) usleep(rand() % 10); =20 for (int i =3D 0; i < INLOOP_ITER; i++) - madvise(huge_ptr, MMAP_SIZE, MADV_DONTNEED); + madvise(huge_ptr, huge_page_size, MADV_DONTNEED); =20 return NULL; } @@ -47,6 +47,10 @@ int main(void) =20 srand(getpid()); =20 + huge_page_size =3D default_huge_page_size(); + if (!huge_page_size) + ksft_exit_skip("Could not detect default hugetlb page size."); + free_hugepages =3D get_free_hugepages(); if (free_hugepages !=3D 1) { ksft_exit_skip("This test needs one and only one page to execute. Got %l= u\n", @@ -54,7 +58,7 @@ int main(void) } =20 while (max--) { - huge_ptr =3D mmap(NULL, MMAP_SIZE, PROT_READ | PROT_WRITE, + huge_ptr =3D mmap(NULL, huge_page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); =20 @@ -66,7 +70,7 @@ int main(void) =20 pthread_join(thread1, NULL); pthread_join(thread2, NULL); - munmap(huge_ptr, MMAP_SIZE); + munmap(huge_ptr, huge_page_size); } =20 return KSFT_PASS; --=20 2.46.1 From nobody Thu Nov 28 21:46:09 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 723AE84E1C for ; Thu, 26 Sep 2024 15:21:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727364063; cv=none; b=ovGTRuUrFGXrFY/pezK2RKdGtwrb2qqu7/0Judx4seRcXaK08oVRYtxHVKli05qFSt7radqA1EDavaDr30n1x/wF3Ed+iTD8RMGkH/+jXTs6yA7jJoGm7BiJYKmtj0kbcvvNXusC9UN7Ly5GXvRklM8ciubEflbcbSTxYa8DFzo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727364063; c=relaxed/simple; bh=XBqWDfNJG/2q9rjmUvR7KopetYbDazuFgLdnXBBgHJs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XqvBgBL/fi4MjBOjXT9OmjvMhV7aCcx9RbrNd61fkiQi9LjrNmLucvfgBrQGZUyI1C0wLQq0Qc3pnPXkPe8bbZ/LYGjZBdTQd3mNwVKqo28Er7Dp/jtcxHUpdY5ZWvczXSliJzXI3kFUX2TzkXPBAkUjCVRKeb8sPcP4a5+ImJI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=GTcd6+ND; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GTcd6+ND" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727364060; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SnbjnYmt3l0aTxSupRXPM1juyT6aAAemxQXR6PSRwdY=; b=GTcd6+NDNpTk93ZC6y8gj8odeAv/IjDmKayVQAVlzwE0A+2ACBEMiihhmtr4YZELcbPR5i tvATEwm/QtMjgKHPUNw1kFq+IMi1I9o1aYayjDkJdmtpFRyFpfDDJoEMVh5/ihXjuefJc6 ux+CATSteh3zBd7Ht68IloyolyqIXv4= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-64-ZKadytkVMWCA608fWmDaRg-1; Thu, 26 Sep 2024 11:20:57 -0400 X-MC-Unique: ZKadytkVMWCA608fWmDaRg-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 229791936CF3; Thu, 26 Sep 2024 15:20:56 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.16.71]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A157C1944D16; Thu, 26 Sep 2024 15:20:53 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, David Hildenbrand , Andrew Morton , Shuah Khan , Mario Casquero , Breno Leitao Subject: [PATCH v1 2/2] selftests/mm: hugetlb_fault_after_madv: improve test output Date: Thu, 26 Sep 2024 17:20:44 +0200 Message-ID: <20240926152044.2205129-3-david@redhat.com> In-Reply-To: <20240926152044.2205129-1-david@redhat.com> References: <20240926152044.2205129-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Content-Type: text/plain; charset="utf-8" Let's improve the test output. For example, print the proper test result. Install a SIGBUS handler to catch any SIGBUS instead of crashing the test on failure. With unsuitable hugetlb page count: $ ./hugetlb_fault_after_madv TAP version 13 1..1 # [INFO] detected default hugetlb page size: 2048 KiB ok 2 # SKIP This test needs one and only one page to execute. Got 0 # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0 On a failure: $ ./hugetlb_fault_after_madv TAP version 13 1..1 not ok 1 SIGBUS behavior Bail out! 1 out of 1 tests failed On success: $ ./hugetlb_fault_after_madv TAP version 13 1..1 # [INFO] detected default hugetlb page size: 2048 KiB ok 1 SIGBUS behavior # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0 Signed-off-by: David Hildenbrand Reviewed-by: Breno Leitao Tested-by: Mario Casquero --- .../selftests/mm/hugetlb_fault_after_madv.c | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c b/tools/= testing/selftests/mm/hugetlb_fault_after_madv.c index ff3ba675278d..e2640529dbb2 100644 --- a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c +++ b/tools/testing/selftests/mm/hugetlb_fault_after_madv.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include =20 #include "vm_util.h" #include "../kselftest.h" @@ -14,11 +16,25 @@ static char *huge_ptr; static size_t huge_page_size; =20 +static sigjmp_buf sigbuf; +static bool sigbus_triggered; + +static void signal_handler(int signal) +{ + if (signal =3D=3D SIGBUS) { + sigbus_triggered =3D true; + siglongjmp(sigbuf, 1); + } +} + /* Touch the memory while it is being madvised() */ void *touch(void *unused) { char *ptr =3D (char *)huge_ptr; =20 + if (sigsetjmp(sigbuf, 1)) + return NULL; + for (int i =3D 0; i < INLOOP_ITER; i++) ptr[0] =3D '.'; =20 @@ -44,13 +60,23 @@ int main(void) * interactions */ int max =3D 10000; + int err; + + ksft_print_header(); + ksft_set_plan(1); =20 srand(getpid()); =20 + if (signal(SIGBUS, signal_handler) =3D=3D SIG_ERR) + ksft_exit_skip("Could not register signal handler."); + huge_page_size =3D default_huge_page_size(); if (!huge_page_size) ksft_exit_skip("Could not detect default hugetlb page size."); =20 + ksft_print_msg("[INFO] detected default hugetlb page size: %zu KiB\n", + huge_page_size / 1024); + free_hugepages =3D get_free_hugepages(); if (free_hugepages !=3D 1) { ksft_exit_skip("This test needs one and only one page to execute. Got %l= u\n", @@ -73,5 +99,11 @@ int main(void) munmap(huge_ptr, huge_page_size); } =20 - return KSFT_PASS; + ksft_test_result(!sigbus_triggered, "SIGBUS behavior\n"); + + err =3D ksft_get_fail_cnt(); + if (err) + ksft_exit_fail_msg("%d out of %d tests failed\n", + err, ksft_test_num()); + ksft_exit_pass(); } --=20 2.46.1