Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3329477iob; Mon, 16 May 2022 19:36:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygZnTZsh8EE7VlbrkKv/bKp+yhLRu8Ih5gfv7gyHNM9p5ekUevP8gBMy8PYCt7zVs3HSbx X-Received: by 2002:a17:907:9487:b0:6f8:747a:845e with SMTP id dm7-20020a170907948700b006f8747a845emr17973164ejc.299.1652755015687; Mon, 16 May 2022 19:36:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652755015; cv=none; d=google.com; s=arc-20160816; b=pLiYHja4vSytNgGQHy/wLesG76U+wwJSwlB9cPKplf5WkozNbOjdBSI4ZffpC+Q+HG I4ueWWB9p8Pea6hrfMfY7pBJ0yeZotXBOKEQd43Y1RdVbFOnGtkZBaHQE/78G7ARsSgV s5FG1sY+CewHLqQLd7/11oMeLKmlBiN5OGUBBjwYDO9ROV5R0/NoHzcPLRi8T+j96p4G 5RX6DJYadHKFAySPD0l2BYoEHO3FPxCG5IhA19XaYQPekkzk4uSe+tRP8guR6pAR8ulJ ZNIAgmOiZnTPPD8T+7NbVnQ+hpGjH0kf+nw0LW1eJev9xPRd3G3QPvp5c/GOOCUrk7oC Gb0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=aB42P+32Sum2YGY8sIwFisRp1PF9vp9paSBH6A92ZaE=; b=IezAtqDW1n3FszmwBfFO9kpHRnp0YpMOFvccgOMcnuppsuJ1jlAWc84lB1e8RJxI0U ob2eAZUND9vQ3/M2gJjAbKItTP64TxBJvJAzJk4mDZhwjZ3ApwByDr1rn5+mrGsxdnMS jK6JjfeVZ3GaTgPMO1FvB+C/FW1Qbt+nh+7+3U7OeQQR4A+lIB7Ol+WMFHCqgGLWO897 kWjsAvheJorxSVMqZBjW82nj5FKqliIi9IjB4LErCTyy7Y/XK4VtWxUuAEQaX08vdBuf nCkbpFM7qCITNeLtU5mPqM9UX7lrURhtMXHLj41uZ9zcg2bFm2dtkn/egfsVwYfJMmqC wTgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=Zv6HbJak; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sc17-20020a1709078a1100b006e7edaf2b8asi856534ejc.371.2022.05.16.19.36.30; Mon, 16 May 2022 19:36:55 -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=@linuxfoundation.org header.s=google header.b=Zv6HbJak; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240408AbiEPX2I (ORCPT + 99 others); Mon, 16 May 2022 19:28:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238157AbiEPX2H (ORCPT ); Mon, 16 May 2022 19:28:07 -0400 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 264D137030 for ; Mon, 16 May 2022 16:28:04 -0700 (PDT) Received: by mail-il1-x12e.google.com with SMTP id i5so11611535ilv.0 for ; Mon, 16 May 2022 16:28:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=aB42P+32Sum2YGY8sIwFisRp1PF9vp9paSBH6A92ZaE=; b=Zv6HbJakhqS+8wMgeAmCsL+LluuM1WF/O/iD6PBZbTfwaeoxl+nGIXjE0bxK3qLegV rZW7Cm8pz7iuOCC10rLuWZIo+EWIs3JKeOwt3XQu3Vv5z7pwl+sjDUwqFeUCC/RluqIs EIx+Op8FRpoPxCIwiSmmxs5FlU8Ez8p/fHPf0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=aB42P+32Sum2YGY8sIwFisRp1PF9vp9paSBH6A92ZaE=; b=p0gNQcnbcdihuI/FMYDpuYOk2VqgpFW40k7biZvydDEJtboBWKcDYuXuyTMCUdF0ac t0L53LQGGwHIEJIqzxLuYRdsEtwYi2FxgxLPLXU5Wstml6cf1VZSHbHWpnBczRk3c/EH IrM2OkZGBtFv+NYr0CK3fOrykmf/EmdN7lvGpjAoDgVHce3F5jWFmI2grFN46x4lpVY9 5NXagJ7ksiE9/pkpZzXlsTDRXGVBhclGW6kxS8VlhxPOEnlteDv97455+YW6Z1CY1Tsl 7eY0LM8bu7Mr0DEad8rSCP7/O851VIiXMvx3D4dCmGbfxZW7vaQ3jPCuJ8+mva8QCjkj U5bw== X-Gm-Message-State: AOAM531Hke6rlsIqFB+iCA+l1CSXYdAMT59B79gOerR67Qlezug1qLSr SFvVqJyiIen1gUYe7WHntwRaqA== X-Received: by 2002:a05:6e02:1905:b0:2cf:1afa:7523 with SMTP id w5-20020a056e02190500b002cf1afa7523mr10791194ilu.234.1652743683444; Mon, 16 May 2022 16:28:03 -0700 (PDT) Received: from [192.168.1.128] ([38.15.45.1]) by smtp.gmail.com with ESMTPSA id d76-20020a6bcd4f000000b0065a9e81df9dsm202417iog.4.2022.05.16.16.28.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 May 2022 16:28:02 -0700 (PDT) Subject: Re: [PATCH v2 1/1] selftests: vm: add process_mrelease tests To: Suren Baghdasaryan 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 , Shuah Khan References: <20220516075538.1276644-1-surenb@google.com> <78c3a163-551b-ef53-4018-7b6ba0640757@linuxfoundation.org> From: Shuah Khan Message-ID: <7f0fd407-18f5-2718-40b5-b16804163197@linuxfoundation.org> Date: Mon, 16 May 2022 17:28:01 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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 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, -- Shuah