Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1398652rwr; Thu, 20 Apr 2023 14:35:37 -0700 (PDT) X-Google-Smtp-Source: AKy350aRVkA7CVNwPhHvzfA2tyxFOW+Sx/PWfLHKfiHUej7exR8s4nEm4WvKBRKPbHPXmotsTzRk X-Received: by 2002:a17:90a:cb88:b0:246:8b47:3d5b with SMTP id a8-20020a17090acb8800b002468b473d5bmr2850378pju.18.1682026537067; Thu, 20 Apr 2023 14:35:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682026537; cv=none; d=google.com; s=arc-20160816; b=jsd7mFuA5HDteQ2oFtKxG41zFj+vU5GchY6VM7vMx3xByRuQ4nMV/p6KlHMH+wBGGj NDGnwpEyso9RB+ZrTOcuQ9HARFsZoDX4uTQu1ymcr98tAKarVNE263/JBrW7xzKO+QJF RDkbfCI4BpRVMM/bDotW+dO4Ov03ullM2l1ftGLIOJi6hy8t5g5Ac6i8rJIOqdYnxEAx 6CeoVL+6oXk1quWw6IURe1oIWHeOeEKpc/9LQ5f+9Ml2dixuX6pbnPEdnNu7b0NII+fr qy9DpAlJa45P963WoFNh8iJoabxQ6SP+QCBIRY4wZGDL9bJm9JdLOBePFx+ML4pOAO2R Dqvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date:subject :cc:to:from:user-agent:references:feedback-id:dkim-signature :dkim-signature; bh=ZXYrfI6mL8GAp9EePATK2aQWfA9YdeSnO3RSGAF64I4=; b=Y5x7Jo2szmFm/ha6um63oobIx8LWbsWN3XQKFw0N9FgQpxh5rUUUSFSlF33GA6ggXt ZIy+kRhnpit1SRmEMvid3qEyAqoRPrQus8IeHUSex2+tJMs1Dj9tbFAiu0q/QRGzwVN6 mjDg6HTtoaKyJ6N0DEp5KC/ZkogrtGcfzgmndGw7xhvgr8ZDY/AUFkqNcV5acNw4n99n Qs2nOm0qZJJRpzfNHKTCgxsIOqleJNCt+3Hnqd5c6QGywehNU6KL+yhxbVtIixCuJl6w nfKqyh6VGTqGL3lOKJa++uNg1YYaBjJWzUo3SNPYrSHebWQBeIMUz5ODk1MZm52iumvp O8mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@devkernel.io header.s=fm1 header.b=p8kEYQdx; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=YSOcMtrQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a656944000000b00517d81adf00si2536283pgq.624.2023.04.20.14.35.22; Thu, 20 Apr 2023 14:35:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@devkernel.io header.s=fm1 header.b=p8kEYQdx; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=YSOcMtrQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232354AbjDTVbj (ORCPT + 99 others); Thu, 20 Apr 2023 17:31:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229599AbjDTVbh (ORCPT ); Thu, 20 Apr 2023 17:31:37 -0400 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06115123; Thu, 20 Apr 2023 14:31:36 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 707A632003D3; Thu, 20 Apr 2023 17:31:34 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 20 Apr 2023 17:31:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=devkernel.io; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1682026294; x=1682112694; bh=ZX YrfI6mL8GAp9EePATK2aQWfA9YdeSnO3RSGAF64I4=; b=p8kEYQdx9RWw5rbetM QyZ1FZuFi9mZ/hL9rpsNZhtwVtWiQlqd2jNOUHyIRq24ktiOuzUhQ/QJ4YYedAdW cGDPAjNoc9efPMk8bdUt/8v1jcb8E3yNnjdpIfWgX0zUXpUQTMMYftmmpnZh+Cpb GVye3SaWnQnY3HL1SvsPrMbKZSB4R9wHW70wPuAmnLWIdEQDSfzbUWDDVengPffQ BiOx8ImhbByAQMh26rb9QvC67Dyb4iRYeh6NS/KgE/d0cPK0sEjn/Emhyo73svIe nTGibaGugyIm8q6wLeGoKQ45B9ezLiBYZlbNN9k4l7MN6thnGUhzzefdivaCM3cO Wf6g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1682026294; x=1682112694; bh=ZXYrfI6mL8GAp 9EePATK2aQWfA9YdeSnO3RSGAF64I4=; b=YSOcMtrQLX9Uap02KYGPHEXxUuMKz Y5uL3pEhH8KdyD6yP47dcwEk2g1xf/4GSynj16hZEkQgrFiGQSYUfrm9UQtknvRh UUQiEOUJ9aojuTPRrI7Nr23u+2ZvTsNcnglQOnOmGsR1RZ2u0rlYaAiAzWG4vo1P lu3Y7f6e32DAJk9azAbkL7Pcgylc/Q+ZxVrozAXAJQ80aDrI8dVjAjcn5sT0b+0C ptBfugWmwWV9WmP4Zg4UIb1W/fSObY0kYX2dIFLN8Z5qvQDDpb783c9X1kXLXi5W FBBFHNd0UtvQEc73TTSHlY7a/dvbGIvIviPpyeISL6ozanF0aWvML17iA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfedtvddgudeiudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpehffgfhvfevufffjgfkgggtsehttdertddtredtnecuhfhrohhmpefuthgv fhgrnhcutfhovghstghhuceoshhhrhesuggvvhhkvghrnhgvlhdrihhoqeenucggtffrrg htthgvrhhnpeevlefggffhheduiedtheejveehtdfhtedvhfeludetvdegieekgeeggfdu geeutdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hshhhrseguvghvkhgvrhhnvghlrdhioh X-ME-Proxy: Feedback-ID: i84614614:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 20 Apr 2023 17:31:31 -0400 (EDT) References: <20230418051342.1919757-1-shr@devkernel.io> <20230418152849.505124-1-david@redhat.com> <20230418152849.505124-3-david@redhat.com> User-agent: mu4e 1.10.1; emacs 28.2.50 From: Stefan Roesch To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-s390@vger.kernel.org, linux-kselftest@vger.kernel.org, Andrew Morton , Rik van Riel , Johannes Weiner , Michal Hocko , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Heiko Carstens , Vasily Gorbik , Sven Schnelle , Shuah Khan Subject: Re: [PATCH v1 2/3] selftests/ksm: ksm_functional_tests: add prctl unmerge test Date: Thu, 20 Apr 2023 14:30:57 -0700 In-reply-to: <20230418152849.505124-3-david@redhat.com> Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org David Hildenbrand writes: > Let's test whether setting PR_SET_MEMORY_MERGE to 0 after setting it to > 1 will unmerge pages, similar to how setting MADV_UNMERGEABLE after setting > MADV_MERGEABLE would. > > Signed-off-by: David Hildenbrand > --- > .../selftests/mm/ksm_functional_tests.c | 46 ++++++++++++++++--- > 1 file changed, 40 insertions(+), 6 deletions(-) > > diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c > index 7bc9fc17c9f0..26853badae70 100644 > --- a/tools/testing/selftests/mm/ksm_functional_tests.c > +++ b/tools/testing/selftests/mm/ksm_functional_tests.c > @@ -91,9 +91,10 @@ static int ksm_merge(void) > return 0; > } > > -static char *mmap_and_merge_range(char val, unsigned long size) > +static char *mmap_and_merge_range(char val, unsigned long size, bool use_prctl) > { > char *map; > + int ret; > > map = mmap(NULL, size, PROT_READ|PROT_WRITE, > MAP_PRIVATE|MAP_ANON, -1, 0); > @@ -110,7 +111,17 @@ static char *mmap_and_merge_range(char val, unsigned long size) > > /* Make sure each page contains the same values to merge them. */ > memset(map, val, size); > - if (madvise(map, size, MADV_MERGEABLE)) { > + > + if (use_prctl) { > + ret = prctl(PR_SET_MEMORY_MERGE, 1, 0, 0, 0); > + if (ret < 0 && errno == EINVAL) { > + ksft_test_result_skip("PR_SET_MEMORY_MERGE not supported\n"); > + goto unmap; > + } else if (ret) { > + ksft_test_result_fail("PR_SET_MEMORY_MERGE=1 failed\n"); > + goto unmap; > + } > + } else if (madvise(map, size, MADV_MERGEABLE)) { > ksft_test_result_fail("MADV_MERGEABLE failed\n"); > goto unmap; > } > @@ -133,7 +144,7 @@ static void test_unmerge(void) > > ksft_print_msg("[RUN] %s\n", __func__); > > - map = mmap_and_merge_range(0xcf, size); > + map = mmap_and_merge_range(0xcf, size, false); > if (map == MAP_FAILED) > return; > > @@ -155,7 +166,7 @@ static void test_unmerge_discarded(void) > > ksft_print_msg("[RUN] %s\n", __func__); > > - map = mmap_and_merge_range(0xcf, size); > + map = mmap_and_merge_range(0xcf, size, false); > if (map == MAP_FAILED) > return; > > @@ -187,7 +198,7 @@ static void test_unmerge_uffd_wp(void) > > ksft_print_msg("[RUN] %s\n", __func__); > > - map = mmap_and_merge_range(0xcf, size); > + map = mmap_and_merge_range(0xcf, size, false); > if (map == MAP_FAILED) > return; > > @@ -323,9 +334,31 @@ static void test_prctl_fork(void) > ksft_test_result_pass("PR_SET_MEMORY_MERGE value is inherited\n"); > } > > +static void test_prctl_unmerge(void) > +{ > + const unsigned int size = 2 * MiB; > + char *map; > + > + ksft_print_msg("[RUN] %s\n", __func__); > + > + map = mmap_and_merge_range(0xcf, size, true); > + if (map == MAP_FAILED) > + return; > + > + if (prctl(PR_SET_MEMORY_MERGE, 0, 0, 0, 0)) { > + ksft_test_result_fail("PR_SET_MEMORY_MERGE=0 failed\n"); > + goto unmap; > + } > + > + ksft_test_result(!range_maps_duplicates(map, size), > + "Pages were unmerged\n"); > +unmap: > + munmap(map, size); > +} > + > int main(int argc, char **argv) > { > - unsigned int tests = 4; > + unsigned int tests = 5; > int err; > > #ifdef __NR_userfaultfd > @@ -355,6 +388,7 @@ int main(int argc, char **argv) > > test_prctl(); > test_prctl_fork(); > + test_prctl_unmerge(); > > err = ksft_get_fail_cnt(); > if (err) Acked-by: Stefan Roesch