From patchwork Thu Sep 26 15:20:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13813454 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44885CDE012 for ; Thu, 26 Sep 2024 15:21:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC79F6B0096; Thu, 26 Sep 2024 11:21:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A76B06B0098; Thu, 26 Sep 2024 11:21:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 918BD6B0099; Thu, 26 Sep 2024 11:21:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 6E4466B0096 for ; Thu, 26 Sep 2024 11:21:01 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 206B9140729 for ; Thu, 26 Sep 2024 15:21:01 +0000 (UTC) X-FDA: 82607252322.05.4508EAD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 497D04000A for ; Thu, 26 Sep 2024 15:20:59 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=H8B2gVRN; spf=pass (imf12.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727363997; a=rsa-sha256; cv=none; b=c+SimJHHF5+kJ8wZamxlrAUw9k72DkeR0QsA+lHo7lJb5uu+xvQtYjCVI8b9J3KsBn9clm aRk7JZ0T+TJSuwBqtRtjTiPDTadOM7KSL1JPsICyVcZ0tPyEZZO5G76kO/smdCSJOp8/ly W3Cfezs66+1aYX3DTdsAtbi8SlWRai4= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=H8B2gVRN; spf=pass (imf12.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727363997; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dEU685hmTiGjO6vRfe2s3dQC7sd7dLb6c9biHu+eUc8=; b=0RR2kAZyjEVUFbWwtF7UMSTFQDq6o4lzsm/VSV3NOlG4KIXoGcWaYMC5nUCwqcsX2yB4O3 14zQ+ec1LiEwLEBOUfYk++mK+w3VE8GGz7yq2aXUMuECerw1gGhO2roOlgpECrFfDQ+fet zydJ37DcBUrdMO+Xh889Nd1p6YnuE0o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727364058; 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=H8B2gVRNmoYqnqAmhtdTlcO5V3+9rFGzP0tOcBNKy9swV1sy8GRMcTIo3rmsQ5aRstRvSa QKFKz4Wd1c0EzxVwXvYIku+v0KoZTC30vOTBFbtEJY/vumgnblMxIGTBzntk9zIKDRK1Fs 7/iK1awNSeTwOoahqJZCyrs3fCvneHI= 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> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Stat-Signature: z13os5jnfeo33d595thj4j756hpo46et X-Rspamd-Queue-Id: 497D04000A X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1727364059-736240 X-HE-Meta: U2FsdGVkX1/9mlg+8SZWcYCg2a8PPUcyZrvvm0WAIPFY8VOgqh0Wa38VwQutb2S3M8kQa1kXdJBnps1NgaiV5mEfKZiI7ZVvefZVGihKIimxoFP20SF44IC4K1uQ7+5qoEZqPwLgr3hUtgQzHXvILC9ji9s3EXYNgDt+tUX8Wirio4hSGlceYl862+O2YyH2ZOXMw4ae4E3m9zzWhSa6VpKsKzArbFgiTgINXAGw2QNt3/93PMS4X0M29y+TDLLi+E94pTFnmReJmUCPwS1AqKCiqpi0U6ETePmmc0IAz073FkGzxzqw+3Zy+R/enqrKjyADnkfSUsNKgYWeeSfQM9jtJH/16xio3b/uPTdsrR1bdlQy34BjwMkNoLAxPCIR+S2AzwnIlcTRJLgWHqeKf9B9vGJNG3rFWYJ04QfkIUpreLRh4YbJcGEO+qSXAm/MhRD1IK2xRTv9815Y81TdRYhwddoD7uQlSfNXY6YIOAJvHyjm1z+LMsK+XQ/Y+BEZZ3nnRj33UTOVgJOtNCRSCuybhodq5fm7Rf+txjXVMXrOFTQFZRvZaLKEZOEkp+5f1N3FiQvH8oZfukdJXLzECg0lOJqAY4iV1eRJXlzQL07iFJiMCMEXfK5mSjEBi4EN0CgoWYvR+8FnpBtr4rAoBazSgyL7/n/S1878JwuW1OLa0CrEuTtyr1++fydu064AUgQAdopdOOo4zzE8+Rfhh56MARXZ0EO+48fmG0XATO7qgnSLJp7lJvlBR/dR1xM64lILBZyOgkTGBmVvOI7ed5Jauyqu2Ia20LCVm0nbkCL2f4fTuQaJIx4sQSpfLYJMFvhT0gptkvkKBC+pxYsMDmLt5A8pdVfYJ0hV0ohGBSY6aYnIiSUY2j9IbpglbM3StzoPgF6njZAoIBLx+AOBM0AR8+lVYz0/4YVtJ93ajZA23R8X919yWrTEYugs4hcL3GCkE3a2SkV8+SEttD2 +ytgnteR Y0gossZCz66n2+rRezbhaxRrUnKJBJRp2+ULy3RA2KphOOZnFtTcw5Vl1que5qlQEqXjN0EED2r4YNkOPSxSnZfszbPyzzoXoArEd1UvuHz9AWZfeNIs71eMkaa9MI7O1YtSo5PgUMsWfo6IcbpFCz7F1D+SsAk77nnb17Nu/RZodjJiwSoh+fAcITC0FSKmrBohmO/MnBskliCJuveuaeOayvOrtdZicbj6UAn05yxnM+CwvOuWNqWbFVqy1V2JnEfoKVXY+krujWVA1GE8nSsprVZbO26F53I2gTEwBLv1k2cNhRPJhYm0fl8PnE/0N85kzwKacKkh/pA1UxLvrc3CeZiLBU6s/VtQSRgjz7pBuWQ43n7D2/U5A4w== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: Shuah Khan Reviewed-by: Breno Leitao --- .../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" -#define MMAP_SIZE (1 << 21) #define INLOOP_ITER 100 -char *huge_ptr; +static char *huge_ptr; +static size_t huge_page_size; /* Touch the memory while it is being madvised() */ void *touch(void *unused) @@ -30,7 +30,7 @@ void *madv(void *unused) usleep(rand() % 10); for (int i = 0; i < INLOOP_ITER; i++) - madvise(huge_ptr, MMAP_SIZE, MADV_DONTNEED); + madvise(huge_ptr, huge_page_size, MADV_DONTNEED); return NULL; } @@ -47,6 +47,10 @@ int main(void) srand(getpid()); + huge_page_size = default_huge_page_size(); + if (!huge_page_size) + ksft_exit_skip("Could not detect default hugetlb page size."); + free_hugepages = get_free_hugepages(); if (free_hugepages != 1) { ksft_exit_skip("This test needs one and only one page to execute. Got %lu\n", @@ -54,7 +58,7 @@ int main(void) } while (max--) { - huge_ptr = mmap(NULL, MMAP_SIZE, PROT_READ | PROT_WRITE, + huge_ptr = mmap(NULL, huge_page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); @@ -66,7 +70,7 @@ int main(void) pthread_join(thread1, NULL); pthread_join(thread2, NULL); - munmap(huge_ptr, MMAP_SIZE); + munmap(huge_ptr, huge_page_size); } return KSFT_PASS; From patchwork Thu Sep 26 15:20:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13813455 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72879CDE015 for ; Thu, 26 Sep 2024 15:21:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 066496B0098; Thu, 26 Sep 2024 11:21:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0195B6B0099; Thu, 26 Sep 2024 11:21:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E48FB6B009A; Thu, 26 Sep 2024 11:21:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id BF3A06B0098 for ; Thu, 26 Sep 2024 11:21:03 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E682B1A1A32 for ; Thu, 26 Sep 2024 15:21:02 +0000 (UTC) X-FDA: 82607252364.05.6A43ACF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 3C753100017 for ; Thu, 26 Sep 2024 15:21:01 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GTcd6+ND; spf=pass (imf14.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727363939; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SnbjnYmt3l0aTxSupRXPM1juyT6aAAemxQXR6PSRwdY=; b=NK8Xxk/EWl/VT58yiubPx9TJoxwH67pWgdZMKtxDaptyKfp1CKRFBWU5qXaprLOvhU8U5e zsSvchuJ5JBGCqmvcXpjrPM5FmJjS2HVwZc40o+MpHfp/2h0hDZCeFRTRsb1gzX7bQz8RS 2nJ5HHhnRaS2IfnWt+2/DyIhcSPiZVs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727363939; a=rsa-sha256; cv=none; b=gDtXZCGDgmreKLwHaqUrvLuM76mlJAvgaSWt4HKTWoY6dz+MeR6m1WlW3S8Jo736rwIrwE V9Ta7uHzQ0qjMHkrEfsEbd3COMLFdU4xyL6Y8Qk1tx4g3iQLSD6AcBhP+NOffrqfH5ot8v bP4/V9WbkzNd5B42AlcJ5qibCL1+3VY= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GTcd6+ND; spf=pass (imf14.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com 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> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Stat-Signature: 8dy6wdbscoqcd69wr5gjztttufi91wwf X-Rspamd-Queue-Id: 3C753100017 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1727364061-602234 X-HE-Meta: U2FsdGVkX19Bs3VQCAB6eVVcsfxIS4enVPpT1HH1QNG9kKwhxIVQin1GFyis08oKric6P2V5sfX2s5wC/uOhN6qFssNhQy27u0pDeEBxGY3k8IQ55yTWzf+KK+NtMjC7wZ9Ai+Wa5Pet+XAuUCI8siUCF6D59+URhcrBWniytYR2edsixPhTYAPWpo0l4b0OFhVj8sJc31WBKTzsWo69ZuennxO1y1H4NQIx1ljU8rxd3C+IMjm8tPZTgtL3gyeLhEpzIUm4mVd7HFNGY7JU64B7rIivZIVriZrjRXLgpHKy7HaoXO8UyCGyjB1M+RISl2z05Qx043+eGd7xg8Nc6OMnzbJkap//I5VP3rLfOrG9p5cpCbTZYOC3osUlzo7XxVGhMQG0ieQtCl8snOV6M21LUElVxE7wpWVzq0Rp/ZF3QIL56v5LymSkcTK0TqCneGJZEXT9Srh/zEOIkFhN1GGl3Bdz6HVHt7tACNadjoaKs7ASFCMQaiWhNhaP02ibxZ4kllx5r+wyEGYCBwyhyEBJ99LP4WfG0jPjRFFqOOPgYxbz3n0LQgseBYClu7N3MnWpKSKzVavOKMEVFtgn9COYoOUZZuEO/EiTuvtnVYQms3EGOxMa6pOCcbfcQMRDSN/LXgsBqJdD0YrYK55l73FcS99HH0Hs8NApXmAV/hG/iUpImvTBXK7VDwU59tgXtlU+ag3hZJ8sQThrEfPXODwnEjB46P1d5C6W5nFS33aG0M8jUR63Yn3s+lJYJP+tygArscIMaqlnytVQhJ/IyuNa0+xcz+8KWmGy10DJnC4SYX7iWIrpTKjYlZmGkh+HGwLUUB+qpYTBxBXVX034dQR/Cq4oc6kXgPnG38b6+Ao1UvkDoTjQORVrnC1bWb8CcDRaGtUWsatY9CeUWq326dV/7V0AQGcy14ADsh2TGE4AhQScT6KHZYi2DQs81c6WAstWoeb27h1SpAOg5lF mqI6DnGI 1B4cUshAKusYdJuQDfBLL9WG4A37HQKr+mxe1c4qZp9qf/hXhOscWMsylkphGFUJzyV/WXmAUTNDtfrIqXHqklwRk17AlGVONOZqK/wviS5plIBnyTYRb4Cz7wp5FJH2LvEC5be4CBsD2HZz0cORGLJT0SNtA7mtcGaEIQ+69Nfc2heocFiBqqZuap/vAd4fMmQLIsDDSpd9q24WDgrdRlb+rtQfsLxtfF956UqkbBTL8QV+bqGIRYvG+4JHXX9GwABIW44bon6fZOx6IJ12smSvq0UAcSq5FsFB85W9BHa7VVNpL8QfX7706rQA5XO3tlGLKK6/I57L7S9bWsDy6XfBthUXz6fO8Jei0pyhFF/3GKKPXUxIYe4I2PA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 --- .../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 #include "vm_util.h" #include "../kselftest.h" @@ -14,11 +16,25 @@ static char *huge_ptr; static size_t huge_page_size; +static sigjmp_buf sigbuf; +static bool sigbus_triggered; + +static void signal_handler(int signal) +{ + if (signal == SIGBUS) { + sigbus_triggered = true; + siglongjmp(sigbuf, 1); + } +} + /* Touch the memory while it is being madvised() */ void *touch(void *unused) { char *ptr = (char *)huge_ptr; + if (sigsetjmp(sigbuf, 1)) + return NULL; + for (int i = 0; i < INLOOP_ITER; i++) ptr[0] = '.'; @@ -44,13 +60,23 @@ int main(void) * interactions */ int max = 10000; + int err; + + ksft_print_header(); + ksft_set_plan(1); srand(getpid()); + if (signal(SIGBUS, signal_handler) == SIG_ERR) + ksft_exit_skip("Could not register signal handler."); + huge_page_size = default_huge_page_size(); if (!huge_page_size) ksft_exit_skip("Could not detect default hugetlb page size."); + ksft_print_msg("[INFO] detected default hugetlb page size: %zu KiB\n", + huge_page_size / 1024); + free_hugepages = get_free_hugepages(); if (free_hugepages != 1) { ksft_exit_skip("This test needs one and only one page to execute. Got %lu\n", @@ -73,5 +99,11 @@ int main(void) munmap(huge_ptr, huge_page_size); } - return KSFT_PASS; + ksft_test_result(!sigbus_triggered, "SIGBUS behavior\n"); + + err = ksft_get_fail_cnt(); + if (err) + ksft_exit_fail_msg("%d out of %d tests failed\n", + err, ksft_test_num()); + ksft_exit_pass(); }