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 52B13C433EF for ; Wed, 6 Jul 2022 09:55:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C2CD16B0073; Wed, 6 Jul 2022 05:55:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BB6A28E0002; Wed, 6 Jul 2022 05:55:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7D078E0001; Wed, 6 Jul 2022 05:55:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 99AB06B0073 for ; Wed, 6 Jul 2022 05:55:52 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 65D113314F for ; Wed, 6 Jul 2022 09:55:52 +0000 (UTC) X-FDA: 79656218544.05.B660063 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) by imf11.hostedemail.com (Postfix) with ESMTP id D6F9C4002E for ; Wed, 6 Jul 2022 09:55:51 +0000 (UTC) Received: by mail-ej1-f53.google.com with SMTP id h23so26095873ejj.12 for ; Wed, 06 Jul 2022 02:55:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wowsignal-io.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fZ4uXetT0fWJuevVciMaW8iGdC3k3dibolkt2/UmDTA=; b=DPAnNhhyksBZZb/8Epdb7eq0wlazEIZ1SXSbctpLnL733dF6Slls3X8xgXl7pQUw5I ImVIWHsZQQcWANUIfnrhx+mA/u6IRCnhHWmoq2Asm+WeJRRzC42FpsNgN1eJ38PXHUWV hh9MPrIiForQxKZ/Mo3OzKVWpzBSM5zAS34WxmfWW390UyXzbZ0yzN/HvOAZTWp1BdpV U4mEUA0jp6kXxfAdZiGG0i1EcccIJZLwe4N9YuJOB8ZMsftr+bKDI/Mw11KQxuO1oYe+ hWdPdRMJC5iSAsn3ftqAFGEshg8Z+W0QWrj3DHd8bcepK1YWjhOgB/z5tle5m1dFdmjS BOyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=fZ4uXetT0fWJuevVciMaW8iGdC3k3dibolkt2/UmDTA=; b=kzPBsEGod3EqblkEQZRwBpeUr0amo5GaLXsY3Yw5lex8Eu69q49zBiDIk5VYACc8Nc sWCXUAeROdXdhBaPd2ppgQqkazSBfJPNx8f/LunBy+GRfzcRFReBSF2TNa4VtJ51qHXA LhpZIJzLJvv3tM9VJNmFm2cH5CEEjOAeJ2fEVx27dvxNPa39UI+3fXue4YzZU6oH4eTt u7p0XULWPRe1jyzPKNnjcNCAV+M2P2snNWBR9nQvfW/dnmDVN1RqtB7LP5XkFE+U1YmI TuQcH8vhFvCh9asRV8Q7BB04hjtzbkwiqKZuDQnEQfdQTdCDOu1IhKG+I4GCUSUmVbDY Kj7g== X-Gm-Message-State: AJIora+AufdbXuwg4RcfXsIsCyPZJvjnsA1I/Mlk9fO+5TYkz9T6mETL 1OZUBKwlh1T/43jiAgwwor+OPQ== X-Google-Smtp-Source: AGRyM1usAeLiy+Fg6n+BwXa0oz6leEAc+bQEnBNGZcgOiGTbiB0XKO71NNny2bIjA5IB0YgpF3XNJw== X-Received: by 2002:a17:907:9606:b0:70a:e140:6329 with SMTP id gb6-20020a170907960600b0070ae1406329mr39047833ejc.471.1657101350433; Wed, 06 Jul 2022 02:55:50 -0700 (PDT) Received: from localhost (212-51-140-210.fiber7.init7.net. [212.51.140.210]) by smtp.gmail.com with ESMTPSA id 15-20020a170906300f00b0072a47b18f7csm9418572ejz.42.2022.07.06.02.55.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 02:55:49 -0700 (PDT) Date: Wed, 6 Jul 2022 11:55:48 +0200 From: Adam Sindelar To: Suren Baghdasaryan Cc: David Vernet , Andrew Morton , linux-mm , Adam Sindelar , kernel-team@fb.com Subject: Re: [PATCH v2] selftests/vm: fix errno handling in mrelease_test Message-ID: References: <20220704173351.19595-1-adam@wowsignal.io> <20220705150015.o3omwkc7c23dbtkh@dev0025.ash9.facebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657101352; a=rsa-sha256; cv=none; b=ubbINxhoqHa8Auh45E0BjGq0WN92XUl4ZMegDPK+4dxNSRngpy9KlxQWEFbgx/9bUR+exT bbjFbziVIFDilLYAvLM2XNACNv5bQTNAZmw0gFf+9oV8FIM7kgDT39mmXoPIn79hli0cuE jFuF6LsEbgX+sTXJllJeheU7lZQT7pk= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=wowsignal-io.20210112.gappssmtp.com header.s=20210112 header.b=DPAnNhhy; dmarc=none; spf=none (imf11.hostedemail.com: domain of adam@wowsignal.io has no SPF policy when checking 209.85.218.53) smtp.mailfrom=adam@wowsignal.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657101352; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fZ4uXetT0fWJuevVciMaW8iGdC3k3dibolkt2/UmDTA=; b=4KFWBzmpd/UOPT1KRqbi9QYkJIKnNLycl9ZgaCQE63QP/wf0qUeOa6XX7c5L16pfR0ZF4n EMIFczKIhCbmi0+hctzeYDckqaaJYSK8jf5qfQHrE5OhMuYkHzj7F9FO+HV8yomwVfjKuz ddhxhdYGThhUFi8Dr9hozZqJiekiqeQ= X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: D6F9C4002E X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=wowsignal-io.20210112.gappssmtp.com header.s=20210112 header.b=DPAnNhhy; dmarc=none; spf=none (imf11.hostedemail.com: domain of adam@wowsignal.io has no SPF policy when checking 209.85.218.53) smtp.mailfrom=adam@wowsignal.io X-Stat-Signature: fib8ibeio77ym8pfzaon7w9cey53y6da X-HE-Tag: 1657101351-506378 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: On Tue, Jul 05, 2022 at 10:02:08AM -0700, Suren Baghdasaryan wrote: > On Tue, Jul 5, 2022 at 9:41 AM David Vernet wrote: > > > > On Mon, Jul 04, 2022 at 07:33:51PM +0200, Adam Sindelar wrote: > > > > Thanks for fixing this, Adam. > > > > > mrelease_test should return KSFT_SKIP when process_mrelease is not > > > defined, but due to a perror call consuming the errno, it returns > > > KSFT_FAIL. > > > > > > This patch decides the exit code before calling perror. > > > > > > > We should probably also include a "Fixes" line here (see [0]): > > > > Fixes: 33776141b812 ("selftests: vm: add process_mrelease tests") > > > > [0]: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes > > > > > Signed-off-by: Adam Sindelar > > > --- > > > v1->v2: Fixed second instance in the same file > > > > > > tools/testing/selftests/vm/mrelease_test.c | 7 +++++-- > > > 1 file changed, 5 insertions(+), 2 deletions(-) > > > > > > diff --git a/tools/testing/selftests/vm/mrelease_test.c b/tools/testing/selftests/vm/mrelease_test.c > > > index 96671c2f7d48..e8b17258579b 100644 > > > --- a/tools/testing/selftests/vm/mrelease_test.c > > > +++ b/tools/testing/selftests/vm/mrelease_test.c > > > @@ -100,8 +100,10 @@ int main(void) > > > > > > /* Test a wrong pidfd */ > > > if (!syscall(__NR_process_mrelease, -1, 0) || errno != EBADF) { > > > + /* perror overwrites errno, so this line must be first */ > > > + res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); > > > perror("process_mrelease with wrong pidfd"); > > > - exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); > > > + exit(res); > > > } > > > > > > /* Start the test with 1MB child memory allocation */ > > > @@ -156,8 +158,9 @@ int main(void) > > > run_negative_tests(pidfd); > > > > > > if (kill(pid, SIGKILL)) { > > > + res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); > > > perror("kill"); > > > - exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); > > > + exit(res); > > > } > > > > > > success = (syscall(__NR_process_mrelease, pidfd, 0) == 0); > > > -- > > > 2.35.1 > > > > > > > This looks good to me, but it looks like there are a couple of other places > > where we're doing the wrong thing, i.e. in run_negative_tests() and after > > calling waitpid(). Could you please fix those as well? > > > > Also adding Suren to cc. > > Thanks for adding me, David! > > The fixes look good but there are 5 places in all this fix is needed: > https://elixir.bootlin.com/linux/v5.19-rc5/source/tools/testing/selftests/vm/mrelease_test.c#L68 > https://elixir.bootlin.com/linux/v5.19-rc5/source/tools/testing/selftests/vm/mrelease_test.c#L76 > https://elixir.bootlin.com/linux/v5.19-rc5/source/tools/testing/selftests/vm/mrelease_test.c#L103 > https://elixir.bootlin.com/linux/v5.19-rc5/source/tools/testing/selftests/vm/mrelease_test.c#L159 > https://elixir.bootlin.com/linux/v5.19-rc5/source/tools/testing/selftests/vm/mrelease_test.c#L175 > Thanks for catching this, Adam! > Suren. > > > > > - David Ah, well spotted. I've fixed the remaining instances in v3. -Adam