From patchwork Wed Aug 21 12:31:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13771333 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 46168C52D6F for ; Wed, 21 Aug 2024 12:31:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9E8B6B010E; Wed, 21 Aug 2024 08:31:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C4CE76B010F; Wed, 21 Aug 2024 08:31:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AEF066B0110; Wed, 21 Aug 2024 08:31:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8F4636B010E for ; Wed, 21 Aug 2024 08:31:27 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 415D040C5D for ; Wed, 21 Aug 2024 12:31:27 +0000 (UTC) X-FDA: 82476188214.28.7D9940E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 9B59DA0013 for ; Wed, 21 Aug 2024 12:31:24 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WSrbf4hA; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724243425; a=rsa-sha256; cv=none; b=6odEvmerMDwA+HRV/RUp8RcwUAWk80FH9BGeLgcqWybIrqov/6nvbeh/4i3Mp5Yv8izocO 1h/UAmebkVnuKqiiDYSOOBeA0kEJULjjioblmC4RlChDvEl/NQB24/WCeakY30Yeepgoqm 3jJ0kH2y+eSQZedUk0BA7fEkSCVW8pc= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WSrbf4hA; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724243425; 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:references:dkim-signature; bh=uTThmUg5wuoJfO3r03jKUAbEQehuHQdGxd4e0MokVn4=; b=MwDSbL/gjnJxM42Fkx8DdIHMUMwQMMl//HvODsGnfaDPW0BqqOOChHeael+kkNY319Jdg7 vznDD3+lcne1e4iYp4wSq4ExknneJlkPb26xqNymULi3ZR9jrOsZjtXYJCv6NpB+RnScpH N202DT/DSfNGHbIQnEr3axtRWMyX08w= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724243483; 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; bh=uTThmUg5wuoJfO3r03jKUAbEQehuHQdGxd4e0MokVn4=; b=WSrbf4hA888NAnssJS7pMTvpZMNsBusZdA+XHFJb81g6tVNIGGQFVisurpANxmoaLRoEGa 89ctaIF2FF3FV0cZg8zK+FGC22aci4Lz/lKqPlSVWVxIdicdFWQdLAikGsKLWaz97YlWyo fubh4ndOShkjxftYNhBFM4CdLEP4+9Q= 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-145-TzjHRiQGO-WSsisDXkMm9Q-1; Wed, 21 Aug 2024 08:31:22 -0400 X-MC-Unique: TzjHRiQGO-WSsisDXkMm9Q-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 BF1AA1955BF1; Wed, 21 Aug 2024 12:31:20 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.194.120]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2C40E19560AA; Wed, 21 Aug 2024 12:31:16 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, David Hildenbrand , Mario Casquero , Andrew Morton , Shuah Khan , Muchun Song , Mina Almasry Subject: [PATCH v1] selftests/mm: fix charge_reserved_hugetlb.sh test Date: Wed, 21 Aug 2024 14:31:15 +0200 Message-ID: <20240821123115.2068812-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Queue-Id: 9B59DA0013 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: gfj4wngxazmpzfd1bq33irhwth7psd6j X-HE-Tag: 1724243484-785719 X-HE-Meta: U2FsdGVkX1/jRESNW6hz/jnTkT22brZzKbgVjzDgbe3xcHafQDw2IRknwUaKib7sQHpHyulrpuvniT64ECwCiEC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z1Y2IzLhn3Pvw6FUC5f183mOImauLPVSkkuM1XyvR3WZx4SP7qrhP3NH2GBTKmzgb4FZe6jis4Cx2UozHR2BLYMYhvk2e+2s56EXrflbljLPRnALbBt3hWYwkrO3PO00XhEeurumYePUys4epYdfYTKC7nNPt3s8r/XgbH5Yh4T//SeanlFaGsNVLlvWlbhRwtYqISGRKsRHbto0XkCXUb9Gkm6JZDWEluh4cJGwBr2ClYEpqV/FZIXdxZJgZNOBEoGFtcYOyh8cyMedhSbYlODYxTHp/pWg/rYZi/reoL9Btgkkxyq3hsZ/xdEj3IizOEn2g= 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: Currently, running the charge_reserved_hugetlb.sh selftest we can sometimes observe something like: $ ./charge_reserved_hugetlb.sh -cgroup-v2 ... write_result is 0 After write: hugetlb_usage=0 reserved_usage=10485760 killing write_to_hugetlbfs Received 2. Deleting the memory Detach failure: Invalid argument umount: /mnt/huge: target is busy. Both cases are issues in the test. While the unmount error seems to be racy, it will make the test fail: $ ./run_vmtests.sh -t hugetlb ... # [FAIL] not ok 10 charge_reserved_hugetlb.sh -cgroup-v2 # exit=32 The issue is that we are not waiting for the write_to_hugetlbfs process to quit. So it might still have a hugetlbfs file open, about which umount is not happy. Fix that by making "killall" wait for the process to quit. The other error ("Detach failure: Invalid argument") does not seem to result in a test error, but is misleading. Turns out write_to_hugetlbfs.c unconditionally tries to cleanup using shmdt(), even when we only mmap()'ed a hugetlb file. Even worse, shmaddr is never even set for the SHM case. Fix that as well. With this change it seems to work as expected. Fixes: 29750f71a9b4 ("hugetlb_cgroup: add hugetlb_cgroup reservation tests") Reported-by: Mario Casquero Cc: Andrew Morton Cc: Shuah Khan Cc: Muchun Song Cc: Mina Almasry Signed-off-by: David Hildenbrand Reviewed-by: Mina Almasry Tested-by: Mario Casquero --- .../selftests/mm/charge_reserved_hugetlb.sh | 2 +- .../testing/selftests/mm/write_to_hugetlbfs.c | 21 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/mm/charge_reserved_hugetlb.sh b/tools/testing/selftests/mm/charge_reserved_hugetlb.sh index d680c00d2853a..67df7b47087f0 100755 --- a/tools/testing/selftests/mm/charge_reserved_hugetlb.sh +++ b/tools/testing/selftests/mm/charge_reserved_hugetlb.sh @@ -254,7 +254,7 @@ function cleanup_hugetlb_memory() { local cgroup="$1" if [[ "$(pgrep -f write_to_hugetlbfs)" != "" ]]; then echo killing write_to_hugetlbfs - killall -2 write_to_hugetlbfs + killall -2 --wait write_to_hugetlbfs wait_for_hugetlb_memory_to_get_depleted $cgroup fi set -e diff --git a/tools/testing/selftests/mm/write_to_hugetlbfs.c b/tools/testing/selftests/mm/write_to_hugetlbfs.c index 6a2caba19ee1d..1289d311efd70 100644 --- a/tools/testing/selftests/mm/write_to_hugetlbfs.c +++ b/tools/testing/selftests/mm/write_to_hugetlbfs.c @@ -28,7 +28,7 @@ enum method { /* Global variables. */ static const char *self; -static char *shmaddr; +static int *shmaddr; static int shmid; /* @@ -47,15 +47,17 @@ void sig_handler(int signo) { printf("Received %d.\n", signo); if (signo == SIGINT) { - printf("Deleting the memory\n"); - if (shmdt((const void *)shmaddr) != 0) { - perror("Detach failure"); + if (shmaddr) { + printf("Deleting the memory\n"); + if (shmdt((const void *)shmaddr) != 0) { + perror("Detach failure"); + shmctl(shmid, IPC_RMID, NULL); + exit(4); + } + shmctl(shmid, IPC_RMID, NULL); - exit(4); + printf("Done deleting the memory\n"); } - - shmctl(shmid, IPC_RMID, NULL); - printf("Done deleting the memory\n"); } exit(2); } @@ -211,7 +213,8 @@ int main(int argc, char **argv) shmctl(shmid, IPC_RMID, NULL); exit(2); } - printf("shmaddr: %p\n", ptr); + shmaddr = ptr; + printf("shmaddr: %p\n", shmaddr); break; default: