Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp117518lqp; Mon, 10 Jun 2024 21:28:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW4gqQUvZ95NdglXHGmLyal6bR4RSdllTm1SRAWtqWaxSD5o9tHHVLHyG0juQ6ADL8RuMCt+J9TQyPvzUzfLVW9wkTEK6aW/gK9pmCYsQ== X-Google-Smtp-Source: AGHT+IGaCKmccFaBNlZLz+ucXWoXfC4NseYJlqTmJg8ei/1VTuqwrnhK2A/MxlZYA5N8/2pxeaDi X-Received: by 2002:a05:6871:3397:b0:24f:e478:6e6c with SMTP id 586e51a60fabf-25464465698mr13960208fac.17.1718080099733; Mon, 10 Jun 2024 21:28:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718080099; cv=pass; d=google.com; s=arc-20160816; b=a9hwqi2GoPGHO1X7OCI72gUhY/DbJoSuUO1B36T9tZZdH6SPsFJI5h4SgQxv0vxjVj NYFxXTS0dm+tcZ9kzc2uZ3OTpyDMz3VN/STP3fIkz1WwJjOV4/eMOFDqOKxvbi0nTB5R 37t8j86DowOxye+KkPpNelwjEkzzIK+ja5IfqYcoG/XjC3vVOIYgOAsc7+oI0+6x2GgV z+R8GUFlyd29tE9UfljCOotn4kqtp3ZaxYZFYADHIW96kQ1kxNothHApyB5HaV+6Rfls QZxlO5HPzwuyXo2edglAFtj5D8KIuN/j1Rf7s8I8wZn/IA9SyslL1l98z76Haye13P5k Cbiw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=hvZm3Ca28/2854H04bb2+N9aiZyWs2w67vdjUbOwxNg=; fh=/3q4Ns1lnOWQo7d5G37G1ZP97eQ0D1XScywJDTBLnoc=; b=TXrzxVrfrZsi7+wHFKZI6Qrz+1cJdh28Ey3tTfKJTUmLlfbVraOrZMJtAvwyWny5Le ajLRz3OtOyrV0Zo+GN3Kr8IX10QRfqrBtY7yUM6i9kSvaGqXBebyqsTeRsnJPC4p1HUi zCzOCuiOIt/Zpov82lnbWnTpEKpeIWXEadZkY6hntDxthepI4ABIeVQW7NWvbHm76Qbg 3nEBNGEQU+tHnt+GWCle9apo/5ZsEwAekdg+bOdIZ8X/0gLZnJAUhbsTDXKuyJ7T/2+T i+Duo6KgrjCXxcQNT6NksyTFPvS/pROPQLpMQSVWSpEma8yTt3NxuII9Vc4uBk5z+ysH fPdQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mrFkt3PF; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-209248-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209248-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6e7e7a28cd1si5215806a12.382.2024.06.10.21.28.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 21:28:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-209248-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mrFkt3PF; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-209248-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209248-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A6F3FB210A1 for ; Tue, 11 Jun 2024 04:27:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DAB2716FF39; Tue, 11 Jun 2024 04:27:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="mrFkt3PF" Received: from mail-oa1-f44.google.com (mail-oa1-f44.google.com [209.85.160.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4403D2570 for ; Tue, 11 Jun 2024 04:27:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718080031; cv=none; b=dde0AOTWoi/9eIlkolGR01M+jJybBMHBcYhIlK2A2HzLlTwPuk4U5YEvTYqWj8f0bEkTGTIN5yLvRgpO3pzqTTBIZTxoB8WPQDHmUbt6ZM/pc/p2OVgVpqW6YXaldj4LHbr3VgEX7VuNPt1zHxpm9V1+f37ZPu+3b7JuIrwjqGA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718080031; c=relaxed/simple; bh=TthFiFrpcOTwjcjWnFwvN7lj9pJIycfnZg7Q1vqVT9I=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=MS9iook5b66vC1px9/4n6PO5s9udT1vl21tQ0OzuBIRc3Um3tj/H2uuNHZ+AQw+ILEA5URWYf+aOhlTs74X2wvyatOCSbZbdpFtNtdb7jzleeinRYQtpl5Yfbsoz/dobCOO6+/mEct7HMxvds4X9TRBeYLoha8GpkY5qpkD4GxI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=mrFkt3PF; arc=none smtp.client-ip=209.85.160.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-oa1-f44.google.com with SMTP id 586e51a60fabf-254a5c82b3fso295162fac.3 for ; Mon, 10 Jun 2024 21:27:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1718080029; x=1718684829; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=hvZm3Ca28/2854H04bb2+N9aiZyWs2w67vdjUbOwxNg=; b=mrFkt3PFrQa2Vw3E8XzbL6nXfHRe3y7BopKFLOhtkdD4fR9WLojJN5IJhjwWJamYSJ 1nOyBvGm5q5ooCGhVOkfqr6jy6PfhJTEMM00kBLrsEsmEWNGMV/d7aqCth2BxptXxHgR XKM8EhxvgbWY8lqktbGpR7k5l3yDmv/4yFnc8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718080029; x=1718684829; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hvZm3Ca28/2854H04bb2+N9aiZyWs2w67vdjUbOwxNg=; b=sa1zfNgaxEZTek7CPu/8vDkbtlaI8EoYKjTBWRAwAMdPX2CGj/qIX5G3IpSET2xOMF Y/MekvkmaivwGbIUrmhta6Qw3qyhVpBtSGP9fqHp706YI+jQllbKvM/lVsRF6aLokJcA 70/7aGSmMii38G10TbQXrg7uzHudS4bDjKDMiapU95/NhKzBo8nEaQtUDq99vSA2i3D2 rnPzTHe/MWUUnIivf/Keg67JBYdnuXIlqZHJH2h7DlZW0JnNRIdE97PRDpKoDf+Sef8K GDHIdTSTmagcJkPVHJvp2A+C/UeEJBVyQCZKyETeuJPl+EV+6CJWdOPM+0pPYKk+4Tfr m9xw== X-Forwarded-Encrypted: i=1; AJvYcCWb/QCXvWmDQ/qd/DfXbljXG7KfNipzH/JyPvzXrrj+JK8u8uequ2z9wC6FxizfAwRoUWodiFY1ZKv4PiA4Ju90FpxFSsRRZCx5lywi X-Gm-Message-State: AOJu0Yz/nLYzUsH/4olZUgtF568TWXMhoRQMN0wuXwCaw0aM2xD++77u RbAmJZzFK3kCmdOHSs/d6ufE4hQQhkvtmrLqPwyyXC4jGfG84i7ONoySqk4TbNw7anVJ4+KfAtT qs8WBxygrxVw5JgQMdJyTwOIkBHTzv8j5hC40 X-Received: by 2002:a05:6870:89a4:b0:254:b1b1:7ea5 with SMTP id 586e51a60fabf-254b1b18dc3mr7909032fac.37.1718080029420; Mon, 10 Jun 2024 21:27:09 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240608021023.176027-1-jhubbard@nvidia.com> <20240608021023.176027-5-jhubbard@nvidia.com> In-Reply-To: <20240608021023.176027-5-jhubbard@nvidia.com> From: Jeff Xu Date: Mon, 10 Jun 2024 21:26:58 -0700 Message-ID: Subject: Re: [PATCH 4/5] selftests/mm: mseal, self_elf: factor out test macros and other duplicated items To: John Hubbard Cc: Andrew Morton , Shuah Khan , Andrei Vagin , Axel Rasmussen , Christian Brauner , David Hildenbrand , Kees Cook , Kent Overstreet , "Liam R . Howlett" , Muhammad Usama Anjum , Peter Xu , Rich Felker , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jun 7, 2024 at 7:10=E2=80=AFPM John Hubbard w= rote: > > Clean up and move some copy-pasted items into mseal_helpers.h. > > 1. The test macros can be made safer and simpler, by observing that they > are invariably called when about to return. This means that the macros > do not need an intrusive label to goto; they can simply return. > > 2. PKEY* items. We cannot, unfortunately use pkey-helpers.h. The best we > can do is to factor out these few items into mseal_helpers.h. > > 3. These tests still need their own definition of u64, so also move that > to the header file. > > Cc: Jeff Xu > Signed-off-by: John Hubbard Reviewed-by: Jeff Xu Tested-by: Jeff Xu > --- > tools/testing/selftests/mm/mseal_helpers.h | 40 ++++++++++++++++++ > tools/testing/selftests/mm/mseal_test.c | 48 ---------------------- > tools/testing/selftests/mm/seal_elf.c | 32 --------------- > 3 files changed, 40 insertions(+), 80 deletions(-) > > diff --git a/tools/testing/selftests/mm/mseal_helpers.h b/tools/testing/s= elftests/mm/mseal_helpers.h > index b922d453a014..8c3bf77dcf19 100644 > --- a/tools/testing/selftests/mm/mseal_helpers.h > +++ b/tools/testing/selftests/mm/mseal_helpers.h > @@ -3,3 +3,43 @@ > #ifndef __NR_mseal > #define __NR_mseal 462 > #endif > + > +#define FAIL_TEST_IF_FALSE(test_passed) = \ > + do { \ > + if (!(test_passed)) { \ > + ksft_test_result_fail("%s: line:%d\n", \ > + __func__, __LINE__); \ > + return; \ > + } \ > + } while (0) > + > +#define SKIP_TEST_IF_FALSE(test_passed) = \ > + do { \ > + if (!(test_passed)) { \ > + ksft_test_result_skip("%s: line:%d\n", \ > + __func__, __LINE__); \ > + return; \ > + } \ > + } while (0) > + > +#define TEST_END_CHECK() ksft_test_result_pass("%s\n", __func__) > + > +#ifndef PKEY_DISABLE_ACCESS > +#define PKEY_DISABLE_ACCESS 0x1 > +#endif > + > +#ifndef PKEY_DISABLE_WRITE > +#define PKEY_DISABLE_WRITE 0x2 > +#endif > + > +#ifndef PKEY_BITS_PER_PKEY > +#define PKEY_BITS_PER_PKEY 2 > +#endif > + > +#ifndef PKEY_MASK > +#define PKEY_MASK (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE) > +#endif > + > +#ifndef u64 > +#define u64 unsigned long long > +#endif > diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/self= tests/mm/mseal_test.c > index 20949617a036..a29935d82027 100644 > --- a/tools/testing/selftests/mm/mseal_test.c > +++ b/tools/testing/selftests/mm/mseal_test.c > @@ -19,54 +19,6 @@ > #include > #include "mseal_helpers.h" > > -/* > - * need those definition for manually build using gcc. > - * gcc -I ../../../../usr/include -DDEBUG -O3 -DDEBUG -O3 mseal_test.= c -o mseal_test > - */ > -#ifndef PKEY_DISABLE_ACCESS > -# define PKEY_DISABLE_ACCESS 0x1 > -#endif > - > -#ifndef PKEY_DISABLE_WRITE > -# define PKEY_DISABLE_WRITE 0x2 > -#endif > - > -#ifndef PKEY_BITS_PER_PKEY > -#define PKEY_BITS_PER_PKEY 2 > -#endif > - > -#ifndef PKEY_MASK > -#define PKEY_MASK (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE) > -#endif > - > -#define FAIL_TEST_IF_FALSE(c) do {\ > - if (!(c)) {\ > - ksft_test_result_fail("%s, line:%d\n", __func__, = __LINE__);\ > - goto test_end;\ > - } \ > - } \ > - while (0) > - > -#define SKIP_TEST_IF_FALSE(c) do {\ > - if (!(c)) {\ > - ksft_test_result_skip("%s, line:%d\n", __func__, = __LINE__);\ > - goto test_end;\ > - } \ > - } \ > - while (0) > - > - > -#define TEST_END_CHECK() {\ > - ksft_test_result_pass("%s\n", __func__);\ > - return;\ > -test_end:\ > - return;\ > -} > - > -#ifndef u64 > -#define u64 unsigned long long > -#endif > - > static unsigned long get_vma_size(void *addr, int *prot) > { > FILE *maps; > diff --git a/tools/testing/selftests/mm/seal_elf.c b/tools/testing/selfte= sts/mm/seal_elf.c > index 4053951a535c..0fd129259647 100644 > --- a/tools/testing/selftests/mm/seal_elf.c > +++ b/tools/testing/selftests/mm/seal_elf.c > @@ -18,38 +18,6 @@ > #include > #include "mseal_helpers.h" > > -/* > - * need those definition for manually build using gcc. > - * gcc -I ../../../../usr/include -DDEBUG -O3 -DDEBUG -O3 seal_elf.c = -o seal_elf > - */ > -#define FAIL_TEST_IF_FALSE(c) do {\ > - if (!(c)) {\ > - ksft_test_result_fail("%s, line:%d\n", __func__, = __LINE__);\ > - goto test_end;\ > - } \ > - } \ > - while (0) > - > -#define SKIP_TEST_IF_FALSE(c) do {\ > - if (!(c)) {\ > - ksft_test_result_skip("%s, line:%d\n", __func__, = __LINE__);\ > - goto test_end;\ > - } \ > - } \ > - while (0) > - > - > -#define TEST_END_CHECK() {\ > - ksft_test_result_pass("%s\n", __func__);\ > - return;\ > -test_end:\ > - return;\ > -} > - > -#ifndef u64 > -#define u64 unsigned long long > -#endif > - > /* > * define sys_xyx to call syscall directly. > */ > -- > 2.45.2 >