Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3328316iob; Mon, 16 May 2022 19:34:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJ2/PcwTZIY/PfS8AlA4obkc63gyxSQnQIpdI0IIGr0AHLfifiqqb2XIb3/9GkAq+QotFA X-Received: by 2002:a17:90a:5515:b0:1dc:c1f1:59bd with SMTP id b21-20020a17090a551500b001dcc1f159bdmr33674706pji.81.1652754849020; Mon, 16 May 2022 19:34:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652754849; cv=none; d=google.com; s=arc-20160816; b=MKxWz1mAhwgyjv345jQ/sJVOAhPanABNgXjXJSdO++QPMAHrWY74ue82KRpJHCu4VU u+3FCcH+fIxcFvKQNbEQeizlhh9a67Q4LKrquTQKkUzHPvWcSQUMWHIS8tlpNYALHxyD 8U+pY3ZxquWCCfKvDXfpmnwedRT00EL9bNqR0QMTDqvehyYWCzzqnQBBqK41pKsEEvDy 4ZxDjcbC2PE3uzhhSIRIuAm0AVSy9OpVJsgGpZDsC+lFSMHVYlrRLZw4KuwhYwe4CD2X p/RWjmvr08MyizCgwPk4QsH+XN38IOQOlMTOweJhedSxjdE3/EsLxNDHex6vZDib1xGE OZ8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=i606HfEWVO/qnL8GVN8QjqxjzHn2kHFuQ0+GTOY9ccY=; b=AHKGlyHEMqCDZ/W4RePogWbVeJq+4CxLnKrRwP4XliSceSwK0rDpU1Fmy5xHZ+1cnQ RTkf/aHxp2/4aJi7xnAAHf07S4Ri3SL8XeNX7YneqAPlj/G0j9VS8UHsZIJtYi1AsdO9 VarpNJCjtLo2b4zFHTWd3WhfGQHsyYLTt6E2bOgCUz2UCpjmuaL1R1F9t11lzbhYn297 uK8AgXUnJ5FyhogQWczhEEYlRyZEtbBuZaZcWwRPCHXh/+dWR7CB4k/7Y1oXA/k20Zt2 dSeG4Q1Hj2sai2fv1X8cIIO5IRXXchXisie4kFgELL7btKWd+XrQZog/rxbGZOT1AT3c NemQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="n+DIO+7/"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z8-20020a17090a540800b001df6ce033fasi1137218pjh.57.2022.05.16.19.33.56; Mon, 16 May 2022 19:34:09 -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=@google.com header.s=20210112 header.b="n+DIO+7/"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349348AbiEPXwA (ORCPT + 99 others); Mon, 16 May 2022 19:52:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350404AbiEPXv5 (ORCPT ); Mon, 16 May 2022 19:51:57 -0400 Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E31B3FD91 for ; Mon, 16 May 2022 16:51:55 -0700 (PDT) Received: by mail-yb1-xb30.google.com with SMTP id a3so10719763ybg.5 for ; Mon, 16 May 2022 16:51:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=i606HfEWVO/qnL8GVN8QjqxjzHn2kHFuQ0+GTOY9ccY=; b=n+DIO+7/hs5dubTKEpbxjG3NWXawGNH+U5W3/PTMqu1oU0UFB9TtNUYil1wX+uO6yH naYC4DdWVKhp384hBvQJSkpBNrFmunkQbfljVYDe7NdgbOZXE6OdvV/9UV5HaVzr4U/G Ozw1o91PaZqKW+xWqVTDMRKC402IK5R8WjYODJ7cAJa65THZWGX8kut+xKsfzhfB37Et 7PvY2KVP3rbyrRpbJEv6snQanikc9Bm68A2JmNYS5qml1jJcp+wyNolOD5mxUs087RFM w5OYrjpQs1PN36UXYIwvth6TRpSpIiHayEsbY2xabi0fhhvPRZoHX85Vb0McblFrLATl KMNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=i606HfEWVO/qnL8GVN8QjqxjzHn2kHFuQ0+GTOY9ccY=; b=FBOw14ZXXHYMKXfCLy8r+trrEJ+QtKxEOiNYEimFeu3OeSUVpTYhac0uMlr0DIclda OKNf6hqFlhcIXFAEmZCQKD/0C3WhgJEFkqaDSw/HzB9KaXPpzqamWDIJJMdgi5skCyxG er6Dcysat3/v0KPxXDrOkRC5fPcnKjfiMYId9W/9zBCHQF4BOof75KKdiZ3SRRFwEJWk VTuflxMsTcKFejrTKrQFbC8VYmnvdgm8RMwKL88DdwR/CRQro8CA8c8HLV6Xof7nPnNb XKg3wOLmYkJlRMGmYXrgEdfiqI8JK/EIu2PLIFaqOBxNptT4pbHGL4Ryalb2NpvO/EeI mzWw== X-Gm-Message-State: AOAM532Ve4bMc1L4o6gRJgpRB+YWBlH8muR/RlpD8O7rwq2gKUlT52Mf YOm/lIM+UGNCO0/XkFQgOnV0bxZB5UZbRWmgXM003w== X-Received: by 2002:a05:6902:389:b0:633:31c1:d0f7 with SMTP id f9-20020a056902038900b0063331c1d0f7mr19940675ybs.543.1652745114021; Mon, 16 May 2022 16:51:54 -0700 (PDT) MIME-Version: 1.0 References: <20220516075538.1276644-1-surenb@google.com> <78c3a163-551b-ef53-4018-7b6ba0640757@linuxfoundation.org> <7f0fd407-18f5-2718-40b5-b16804163197@linuxfoundation.org> In-Reply-To: <7f0fd407-18f5-2718-40b5-b16804163197@linuxfoundation.org> From: Suren Baghdasaryan Date: Mon, 16 May 2022 16:51:43 -0700 Message-ID: Subject: Re: [PATCH v2 1/1] selftests: vm: add process_mrelease tests To: Shuah Khan Cc: Andrew Morton , Michal Hocko , David Rientjes , Matthew Wilcox , Johannes Weiner , Roman Gushchin , Minchan Kim , "Kirill A. Shutemov" , Andrea Arcangeli , Christian Brauner , Christoph Hellwig , Oleg Nesterov , David Hildenbrand , Jann Horn , Shakeel Butt , Peter Xu , John Hubbard , shuah@kernel.org, LKML , linux-mm , linux-kselftest@vger.kernel.org, kernel-team Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 On Mon, May 16, 2022 at 4:28 PM Shuah Khan wrote: > > On 5/16/22 2:47 PM, Suren Baghdasaryan wrote: > > On Mon, May 16, 2022 at 1:29 PM Shuah Khan wrote: > >> > >> On 5/16/22 1:55 AM, Suren Baghdasaryan wrote: > >>> Introduce process_mrelease syscall sanity tests which include tests > >>> which expect to fail: > >>> - process_mrelease with invalid pidfd and flags inputs > >>> - process_mrelease on a live process with no pending signals > >>> and valid process_mrelease usage which is expected to succeed. > >>> Because process_mrelease has to be used against a process with a pending > >>> SIGKILL, it's possible that the process exits before process_mrelease > >>> gets called. In such cases we retry the test with a victim that allocates > >>> twice more memory up to 1GB. This would require the victim process to > >>> spend more time during exit and process_mrelease has a better chance of > >>> catching the process before it exits and succeeding. > >>> > >>> On success the test reports the amount of memory the child had to > >>> allocate for reaping to succeed. Sample output: > >>> Success reaping a child with 1MB of memory allocations > >>> > >>> On failure the test reports the failure. Sample outputs: > >>> All process_mrelease attempts failed! > >>> process_mrelease: Invalid argument > >>> > >> > >> Nit: Please format this better - include actual example output from the > >> command and how to run the test examples. > > > > Hmm... Those are the actual outputs from the command and it does not > > take any input arguments. Do you mean smth like this: > > > > $ mrelease_test > > Success reaping a child with 1MB of memory allocations > > > > $ mrelease_test > > All process_mrelease attempts failed! > > > > $ mrelease_test > > process_mrelease: Invalid argument > > > > ? > > This looks good. > > > > >> > >>> Signed-off-by: Suren Baghdasaryan > >>> --- > >>> tools/testing/selftests/vm/.gitignore | 1 + > >>> tools/testing/selftests/vm/Makefile | 1 + > >>> tools/testing/selftests/vm/mrelease_test.c | 214 +++++++++++++++++++++ > >>> tools/testing/selftests/vm/run_vmtests.sh | 16 ++ > >>> 4 files changed, 232 insertions(+) > >>> create mode 100644 tools/testing/selftests/vm/mrelease_test.c > >>> > > [snip] > > >> > >> Okay these above 3 routines are called once. I am not seeing any point > >> in making these separate routines. I made the same comment on v1. > > > > I must have misunderstood your previous comment. Will change. > > > > Thank you. > > >> > > >> > >> Now the above code can be a separate function which will make it readable. > > > > Ack. > > > >> > > >>> + > >> > >> Why do you need these ifdefs - syscall will return ENOSYS and you can > >> key off that. Please take a look at other usages of syscall in the > >> repo. > > > > The issue is that I need to provide the syscall number when calling > > syscall() (in my case __NR_pidfd_open and __NR_process_mrelease) and > > if that number is not defined in the userspace headers on a given > > system then what should I pass instead? > > When implementing this I followed the examples of > > https://elixir.bootlin.com/linux/latest/source/tools/testing/selftests/vm/memfd_secret.c#L30 > > and https://elixir.bootlin.com/linux/latest/source/tools/testing/selftests/vm/userfaultfd.c#L65. > > My original implementation was modeled after this approach: > > https://elixir.bootlin.com/linux/latest/source/tools/testing/selftests/vm/mlock2.h#L15. > > If none of these are correct, could you please point me to the example > > you want me to follow? > > > > kselftests include kernel headers. As long as these syscalls are > defined in the kernel headers, the test will build. > > Looks it is defined in include/uapi/asm-generic/unistd.h > > You can assume it is defined and then if we find architectures that > don't, you can follow what tools/testing/selftests/pidfd/pidfd.h > does. > > This way the test can simply call syscall and handle ENOSYS. Thanks for the guidance! I'll try that approach. Suren. > > thanks, > -- Shuah > > > > > -- > To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com. >