Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2277100rdb; Thu, 21 Sep 2023 13:48:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEmHuP9NlSq3ZDkfkss2SGumbHDFGMJwIZBnHCxbM3RLBMfw8LISkXlxJ64oaK+e9mVLDzA X-Received: by 2002:a17:902:bb8f:b0:1c4:202d:8747 with SMTP id m15-20020a170902bb8f00b001c4202d8747mr5170759pls.50.1695329317229; Thu, 21 Sep 2023 13:48:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695329317; cv=none; d=google.com; s=arc-20160816; b=e/pwu7zM8p/g0vqvXmlExx2/Rt6sFHk+k0dqexJL6VCUB0rCBtVxJZD3O+RgNJAvao Skc6H2TlsYlxVMBApsoYs+2pt1nHjAnkgnQVtiqu3E6l06L/isBEtIu5TDUjLmBBPz3p IE6PxWWrjSdlVSzt6WLCT9d3cnrLwP5S/hL5UVPA1/entvqK32yHn9a3nIw9CML3z8FS Ep7XcYCDoPRbwE/ywK3nUepT3HSEIchFfWnK2zZRkfGn+amBHN8NGcbrOffOvKIoK04F wAVALcMDUCxBznWfIJioxnRX1lG/lKQ7wVmRssuyFl7fY9po5XLMpvKkl4y0+h7osVBN sHQw== 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=Z4KTSVuT7KTNJQDkW80sMex9LfoppnMnFr8nX3dMwCI=; fh=bfQiakWAvDNKtrSkzJPjktKQf8cBmdZZtJcoO52Y1KQ=; b=VqP9jwlu5ec7L1m8LRHFF2E1rhOJgjhA0PGb+iA6pMoxD7SDzMKz0BBE9SJNKy3w4P 782vYErLCPVQEirNiwg4qs+HitaoaQEypXJiUUK18yMVY5vbCPZZJ9wlPAXkd/qWp+4A 5LzMUqlURh8O6U5iF63HiY6XvXHZ9HaVP8+vt3djT0TUicb9m0CphuLDJ+geMe/LaNG+ 1ifHF67W3FY6uOotc5nYkR248zRykNOsTEG754iG1+3UNoB5lU+JDGrY7yY7FZ1+hZIy +YWFz7Lx/XY7XddsWh2YGAKFPhUM84ILKkO3h8GeIl5r7E+4c/KDN5Wo36aXafdJ9IAO 6rBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@devkernel.io header.s=fm3 header.b="Fz0czn+/"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=dbJGRNkm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id j10-20020a170902da8a00b001c563263222si2300091plx.376.2023.09.21.13.48.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 13:48:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@devkernel.io header.s=fm3 header.b="Fz0czn+/"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=dbJGRNkm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 4EEC280A4175; Thu, 21 Sep 2023 10:32:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229757AbjIURcE (ORCPT + 99 others); Thu, 21 Sep 2023 13:32:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230190AbjIURb7 (ORCPT ); Thu, 21 Sep 2023 13:31:59 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC4907EF2 for ; Thu, 21 Sep 2023 10:10:51 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 768F85C00D9; Thu, 21 Sep 2023 12:26:57 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 21 Sep 2023 12:26:57 -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=fm3; t=1695313617; x=1695400017; bh=Z4 KTSVuT7KTNJQDkW80sMex9LfoppnMnFr8nX3dMwCI=; b=Fz0czn+/yTiq1GYfus vKWoXAaohjlfOZULNdSTrC09A8RtoVBuWppooW2W1ktthlcDHqomphrj181K12gt 2WA2/+G5AwVeR3qLS7IXnoh3dT22v16ak0vMHkvKBlrVqMv0q1BYIdpqISpAKRjo SULEg88zbUiET25cITjD4OiggmcpEOKz2RYoH4YY8hLMlvjuArl5Sp1H7naRcKA3 9amqaOZCj0rmWuzFRSm1UeJKYSxUnEThrYrj92nqq44qJ9rbewwEzsBdQWXrqrNG VI99fFrGY6R6QjRXtvuNYLqQKzRssLbFC2nOXV7zxut5mx1EfwVD1RfBGzXFBeBI GX2g== 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=fm2; t=1695313617; x=1695400017; bh=Z4KTSVuT7KTNJ QDkW80sMex9LfoppnMnFr8nX3dMwCI=; b=dbJGRNkmrurrKLejhuj4yx604dXkV /LfUhIe9v0WlyCQbs+Y01sZmOcuU2XphlZpgNRgXsM3zG+ZkUK/xDYaTImfFowe+ FX9WkmV9Y+x/P0dqX9wYXn23NoIrq7dLT7f5wTAbp7KxiLLF8//xjKOvUeui9S6N fqgT8m66ZngeAh0F7OoV7EGTKBnnE3xPQ2fcibN5Fr9Lj+QqejV9EIAntWlaCofj R/P4hdyqxTaRCPPSMZvciMi24lnysJ7U5tjPI3uTswyCZy7H86PNzRcpeJgNAcdC gHoh3vYNZ6hVjFtkKS7z+JlLbjoTmJSJotwXqqHyslTcK7ePyQ7hgSA0Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudekiedguddttdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpehffgfhvfevufffjgfkgggtsehttdertddtredtnecuhfhrohhmpefuthgv fhgrnhcutfhovghstghhuceoshhhrhesuggvvhhkvghrnhgvlhdrihhoqeenucggtffrrg htthgvrhhnpeevlefggffhheduiedtheejveehtdfhtedvhfeludetvdegieekgeeggfdu geeutdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hshhhrseguvghvkhgvrhhnvghlrdhioh X-ME-Proxy: Feedback-ID: i84614614:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 21 Sep 2023 12:26:56 -0400 (EDT) References: <20230920190117.784151-1-shr@devkernel.io> <20230920190117.784151-3-shr@devkernel.io> User-agent: mu4e 1.10.1; emacs 28.2.50 From: Stefan Roesch To: David Hildenbrand Cc: kernel-team@fb.com, akpm@linux-foundation.org, hannes@cmpxchg.org, riel@surriel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2 2/2] mm/ksm: Test case for prctl fork/exec workflow Date: Thu, 21 Sep 2023 09:25:46 -0700 In-reply-to: Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 21 Sep 2023 10:32:11 -0700 (PDT) David Hildenbrand writes: > On 20.09.23 21:01, Stefan Roesch wrote: >> This adds a new test case to the ksm functional tests to make sure that >> the KSM setting is inherited by the child process when doing a >> fork/exec. >> Signed-off-by: Stefan Roesch >> --- >> .../selftests/mm/ksm_functional_tests.c | 67 ++++++++++++++++++- >> 1 file changed, 66 insertions(+), 1 deletion(-) >> diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c >> b/tools/testing/selftests/mm/ksm_functional_tests.c >> index 901e950f9138..40b86c9caf3a 100644 >> --- a/tools/testing/selftests/mm/ksm_functional_tests.c >> +++ b/tools/testing/selftests/mm/ksm_functional_tests.c >> @@ -26,6 +26,7 @@ >> #define KiB 1024u >> #define MiB (1024 * KiB) >> +#define FORK_EXEC_CHILD_PRG_NAME "ksm_fork_exec_child" >> static int mem_fd; >> static int ksm_fd; >> @@ -479,6 +480,65 @@ static void test_prctl_fork(void) >> ksft_test_result_pass("PR_SET_MEMORY_MERGE value is inherited\n"); >> } >> +static int ksm_fork_exec_child(void) >> +{ >> + /* Test if KSM is enabled for the process. */ >> + int ksm = prctl(PR_GET_MEMORY_MERGE, 0, 0, 0, 0); >> + return ksm == 1; > > You can simply do "return prctl(PR_GET_MEMORY_MERGE, 0, 0, 0, 0) == 1;" > > Or maybe even "return prctl(PR_GET_MEMORY_MERGE, 0, 0, 0, 0);" and adjust the > comparison below in the caller. > I'll use the first one, then its all in one place. >> +} >> + >> +static void test_prctl_fork_exec(void) >> +{ >> + int ret, status; >> + pid_t child_pid; >> + >> + ksft_print_msg("[RUN] %s\n", __func__); >> + >> + 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"); >> + return; >> + } else if (ret) { >> + ksft_test_result_fail("PR_SET_MEMORY_MERGE=1 failed\n"); >> + return; >> + } >> + >> + child_pid = fork(); >> + if (child_pid == -1) { >> + ksft_test_result_skip("fork() failed\n"); >> + return; >> + } else if (child_pid == 0) { >> + char *prg_name = "./ksm_functional_tests"; >> + char *argv_for_program[] = { prg_name, FORK_EXEC_CHILD_PRG_NAME }; >> + > > I'd simply have used the magic number "1" or so. But this works as well. > I think the current one makes it easier in case we have to add a second one later. > Reviewed-by: David Hildenbrand