Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp199889pxb; Wed, 3 Nov 2021 02:41:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUuLIdH78mPffIl/xJErp37LnzA2f0W7HaxadFZRJYm9xQWan0t8cNjzbrCK0V24P4rGMJ X-Received: by 2002:a17:907:2dac:: with SMTP id gt44mr52684700ejc.265.1635932462531; Wed, 03 Nov 2021 02:41:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635932462; cv=none; d=google.com; s=arc-20160816; b=n4W8aoLzvriVntcJTqKlBRFdLKobN74Dy/TQN5v6Ep/Tq0D+4uYIA6SnXzpbMjiLHh dedzbAm5dg6P622rjfvCf6XGfbkgdvzDfmvywyhQAS5VKhs8aV5tIKO1uHXBDuAiV8LJ ZbiTwp/0yDCdZMZjUs+o4QaGSRtvIL/yuxlp9Els5jG5vlb6Bn1J4kHZxg5EPVsI8Mt3 x4s4K/QAWz8ZSkZ0eyQZiCtxmeNjUqiUDaB44886w7xx8zJeQr9hIbwBNMtWGfcxg1Gv eU2iEtBKau0I8qd1/yW0d9OE4xjw4Hgv6d9j8q09ceMScbYOsIjD3ztpRakH0uZahdob 0yfQ== 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=zEyIczqFSHpavkegJTGcffG0KJRQlbVgPG2I11SEzIk=; b=Vy0EGAwQzHDCKkNhoFxoDKK4ZWC5y0Ax6fk+94/PGWjzSM7I4uv7ZI4ljxaO68z6B/ z//lLs03aZAgjc+NKSWTL9Jn+6281O1pYrk9Jyz1UDGyaXM8FWWSmE0goju1LznAMlnn zLBOsp2Ual9EwcV/ssz4AAR2hXTr2YYEfAG7nFJzJziTMLTpB/MEU/T5ipcBz4TaQc3V 4SkILk/sebCC+yYuKTCWtyo+/3fwJRMrKP10pjsIYNz+dVyOFeLWJc62k0TPJKGtMiJS kCgjSMelazEUmysFBBHVFH30lMa7YvPkyyueu2Ndx3j/eahNl3QdXtWV17TCYt3e4Bwy G9wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vE8celaA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g5si2886610ejo.390.2021.11.03.02.40.32; Wed, 03 Nov 2021 02:41:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vE8celaA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231755AbhKCJlZ (ORCPT + 99 others); Wed, 3 Nov 2021 05:41:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231749AbhKCJlX (ORCPT ); Wed, 3 Nov 2021 05:41:23 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 246D2C061203 for ; Wed, 3 Nov 2021 02:38:30 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id f4so6821494edx.12 for ; Wed, 03 Nov 2021 02:38:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zEyIczqFSHpavkegJTGcffG0KJRQlbVgPG2I11SEzIk=; b=vE8celaAZhFLiXMY3hj+ux1f4WpUOtB+IYPgxA+T3rNqveRNEQm86XNOSQ7+s9eVJn GELJidoE/FALVgt0sG3aOE+fD/QYwbJjtvBMP2BG/I77YXX1+zxkPFgFEjzuIi9SoMwO RSXHZld3YZhMd6yXkQNEk15b28o4td9KGN+hOkrjxmr4fN6kxERAFDOB8ralLISEDiFK Z4lpDlK9gSUHrwPDYHDoV30hbKcHE/jPhgpceG9mTT47ADu5zyKrpUs/PmasPL51k1Q/ 8Nda7xOAFirJX1iOO0xRXBrMaHaSyz/0FrkkVQsPv4JijQpkp77F7idxvjr0jZXCLle8 O+yQ== 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=zEyIczqFSHpavkegJTGcffG0KJRQlbVgPG2I11SEzIk=; b=C8qPGVlen+98a19o3jhpkEV9oF01PVLXQIyQk7NncOFLYdd2FGvS32envntXD52V0m y/rCYWR0Nm0NsbP7tj9oACwqb329B1Oz4gXXMI37NMsdodhA/fAAM0/w3+zbgktJHt0+ eUx8adqFA7mNu9n5gZRjGEzdhWmSspKbi5Wf/R9fNnm666gm1AwzbZvJL4f+YIXjCPzj krj9C6wOCtoVb3+6/xqOuQo/HBhnu8OOpdzVGgY39bdA1tEIUIgnxqaEjPP2F0oKObBf 77F9NH1Q+UavnQ6AW/EEtVIaXoaNKgigLQ2USfZNaSW7E9Eyf1M3wVBoyMZyKJZC2Mee PcWA== X-Gm-Message-State: AOAM531QCZEoAkUoHvcpgjfESKSpeH6ETvEIgWaKeDhHlqrzb20dmQTu qn9JrOnKGVYCpZDUx83DvLPl0ZR1aX67gL5F95EE3Q== X-Received: by 2002:a17:907:10cf:: with SMTP id rv15mr2446809ejb.383.1635932308691; Wed, 03 Nov 2021 02:38:28 -0700 (PDT) MIME-Version: 1.0 References: <20211029114312.1921603-1-anders.roxell@linaro.org> <834d18b6-4106-045f-0264-20e54edf47bc@linuxfoundation.org> In-Reply-To: From: Anders Roxell Date: Wed, 3 Nov 2021 10:38:17 +0100 Message-ID: Subject: Re: [PATCH] selftests: kselftest.h: mark functions with 'noreturn' To: Nick Desaulniers Cc: Shuah Khan , shuah@kernel.org, fenghua.yu@intel.com, reinette.chatre@intel.com, john.stultz@linaro.org, tglx@linutronix.de, akpm@linux-foundation.org, nathan@kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, llvm@lists.linux.dev, Mike Rapoport Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2 Nov 2021 at 23:04, Anders Roxell wrote: > > On Sat, 30 Oct 2021 at 00:08, Nick Desaulniers wrote: > > > > On Fri, Oct 29, 2021 at 11:19 AM Shuah Khan wrote: > > > > > > On 10/29/21 5:43 AM, Anders Roxell wrote: > > > > When building kselftests/capabilities the following warning shows up: > > > > > > > > clang -O2 -g -std=gnu99 -Wall test_execve.c -lcap-ng -lrt -ldl -o test_execve > > > > test_execve.c:121:13: warning: variable 'have_outer_privilege' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] > > > > } else if (unshare(CLONE_NEWUSER | CLONE_NEWNS) == 0) { > > > > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > test_execve.c:136:9: note: uninitialized use occurs here > > > > return have_outer_privilege; > > > > ^~~~~~~~~~~~~~~~~~~~ > > > > test_execve.c:121:9: note: remove the 'if' if its condition is always true > > > > } else if (unshare(CLONE_NEWUSER | CLONE_NEWNS) == 0) { > > > > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > test_execve.c:94:27: note: initialize the variable 'have_outer_privilege' to silence this warning > > > > bool have_outer_privilege; > > > > ^ > > > > = false > > > > > > > > Rework so all the ksft_exit_*() functions have attribue > > > > '__attribute__((noreturn))' so the compiler knows that there wont be > > > > any return from the function. That said, without > > > > '__attribute__((noreturn))' the compiler warns about the above issue > > > > since it thinks that it will get back from the ksft_exit_skip() > > > > function, which it wont. > > > > Cleaning up the callers that rely on ksft_exit_*() return code, since > > > > the functions ksft_exit_*() have never returned anything. > > > > > > > > Signed-off-by: Anders Roxell > > > > > > Lot of changes to fix this warning. Is this necessary? I would > > > like to explore if there is an easier and localized change that > > > can fix the problem. > > > > via `man 3 exit`: > > ``` > > The exit() function causes normal process termination ... > > ... > > RETURN VALUE > > The exit() function does not return. > > ``` > > so seeing `ksft_exit_pass`, `ksft_exit_fail`, `ksft_exit_fail_msg`, > > `ksft_exit_xfail`, `ksft_exit_xpass`, and `ksft_exit_skip` all > > unconditional call `exit` yet return an `int` looks wrong to me on > > first glance. So on that point this patch and its resulting diffstat > > LGTM. > > I'll respin the patch with these changes only. > > > > > That said, there are many changes that explicitly call `ksft_exit` > > with an expression; are those setting the correct exit code? Note that > > ksft_exit_pass is calling exit with KSFT_PASS which is 0. So some of > > the negations don't look quite correct to me. For example: > > > > - return !ksft_get_fail_cnt() ? ksft_exit_pass() : ksft_exit_fail(); > > + ksft_exit(!ksft_get_fail_cnt()); > > > > so if ksft_get_fail_cnt() returns 0, then we were calling > > ksft_exit_pass() which exited with 0. Now we'd be exiting with 1? > > oh, right, thank you for your review. > I will drop all the 'ksft_exit()' changes, they should be fixed and go > in as separete patches. tools/testing/selftests/vm/memfd_secret.c has the 'ksft_exit(!ksft_get_fail_cnt())' statement and when I looked at it it when I did this patch it looked correct. However, when I look at it now I get a bit confused how ksft_exit() can be used with ksft_get_fail_cnt(). @Mike can you please clarify the 'ksft_exit(!ksft_get_fail_cnt())' instance in tools/testing/selftests/vm/memfd_secret.c. Cheers, Anders