Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1618021lqp; Mon, 15 Apr 2024 11:33:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV7sK6FX8tFcYzBwse8Fib9fcFVVHVUg7FaGsbml9hCZO85ThqVOoAMEfDHIGOfbKg+2bfogVoZp/ux5WgP/uzUYc3tPmPZYXmK3qBeVw== X-Google-Smtp-Source: AGHT+IHXH7O60zCDtlq7BGLC7b3e5Qkd7SwXshQOSim9iDdQUbxBKYXu65ob92DyDwRBJKlsbfCg X-Received: by 2002:a05:6a20:96d0:b0:1a7:8b88:96b3 with SMTP id hq16-20020a056a2096d000b001a78b8896b3mr13450209pzc.9.1713206029372; Mon, 15 Apr 2024 11:33:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713206029; cv=pass; d=google.com; s=arc-20160816; b=pANMl5+8GQCO/Kmk+2XIBkJi5xPI1PamdWRj2CXGW8J5oP/A5NKo4vOOgtI9Mg1lAS Ts0xh/rN6SqjV7yfELwUBXIX5G7NkGzd3Zu4zjXa+mv1YhsXYef4R6Q6sMO+4qd80pSs hjwGfctQnU2Zb3GE3gUb42qaho6ugqrbXgnoi8kNf9PQqVRIYmUk2SNCBoiwYwsI53xZ 0bBFhBmBKFD3fYADqm79PD8SMfPfC1R+lDlUo9cuY44oKDFOmfyJCQZgYhhAvbRa3B8b v38o1FH0tlsjrB4gJFtNX/Y8lT63AnPLF9jwHUpzlhzJh+qBQ/LwRvb1A0DY810wnSRn 3jNg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:cc:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=/fn16ORoqa+E+PXLbTdrI62OA21/9pS9m8VfggXMkxw=; fh=cCiDi0jR2Ip7rptm/BxVqx4wVcY6PQi1+swBWIVNFmg=; b=lw4wDZAj9LW0ZwXD+wYjky7kb65W67pEH+Tv35uSbdE38j1CA+fCpzTv/Z0Ivba7F2 L6nCoLGTaXC7JxD2YfKQqSQL6rxLEzEugPIGRagbMD2gXQqVzi6M4lkKGiMrfxiWjfA/ oCHWQmyfQgCETPZh1bpHAhR+KGpsqZ6cM+PWB6PX9lrHjNM9ueSDIU1V0yOQqiHyOkkr 74pJTs82DOSZzIeTet2fywta3FCda7v4NOfo1nnmfgOYPMNTxJdQ2oYpqCi7qFHHbxpj fFLt+KjSFtBfihNEpWrrodbWYh18jyyr3mjHi8Uv4mvUITk7b32VVIU0xERus0QglMN+ WaRg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=XJAvGcDq; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-145715-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145715-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id b185-20020a6367c2000000b005dc9bea60fdsi8286226pgc.415.2024.04.15.11.33.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 11:33:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145715-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=@collabora.com header.s=mail header.b=XJAvGcDq; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-145715-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145715-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com 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 D2120B21B5B for ; Mon, 15 Apr 2024 18:32:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AD864154425; Mon, 15 Apr 2024 18:32:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="XJAvGcDq" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE1F6153BF8; Mon, 15 Apr 2024 18:32:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713205938; cv=none; b=UqbHviE4gaeZRESii6o9CDEo38m/4gd1tIHJzpQDab58l6oR5sVs0s39WJep96vwNf7KRtPiOxjmPWzqNqibQV0OdlEFbBJohExjCVgk3B1pBKH2rWgkbUvsx9M7UtDo0HTBPnG7NL0iiCzW5uqHxPMFdbRCpp/U/dIwigcNVWs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713205938; c=relaxed/simple; bh=p8eY082JkC3KPLbfUGfr481x8SEdz/YLHgqGEpwKKdg=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=ixAOZ7jSpCoWPk5LyE3PGkoufqhZEWgpiEgPlVjQEouqMD7QmVaCY42vPRgPW5GyaI5j7WUwseTxZhECnAtUSbRgZ/Y8W43FPOZQcQB1SToXJnwZVBjBAMZhWk1pPAZrV0a82Ye9TImamiSfi1FBQfN1t71ZDmN7boa0VSIYzLU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=XJAvGcDq; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1713205934; bh=p8eY082JkC3KPLbfUGfr481x8SEdz/YLHgqGEpwKKdg=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=XJAvGcDqP0Vt+/a6ZRFb0h5+g8hgOaGIveEs1cMbQRBl/HGMq09mRCyIdSRVXp2t+ ENn77R12rxPJQ/Lb1mz+StEHb9MNSEq/dKH8XjzyPhuTDEGURTxML/th7/UrMJpv5N jX4BXGtF7O9UOaonMufXeo96KpZwpGcA3tOBMX12eh98k/mNS1T+0kPZJX6BZlwUSm xNqyrnvQBvgej7aS79D0qvlyIUIA0umXkTxHgOdPVb0Ml2RJwPYZhQnWt0ubIwFPw4 olR+R5Fozy0rTDurjH2xfpAJCea2xY20ILGEmSZJekpk/oLkal5DidGr4FkWHItcMZ R0Mq7SKaJherw== Received: from [10.193.1.1] (broslavsky.collaboradmins.com [68.183.210.73]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 73D9937810F1; Mon, 15 Apr 2024 18:32:09 +0000 (UTC) Message-ID: Date: Mon, 15 Apr 2024 23:32:41 +0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: Muhammad Usama Anjum , jeffxu@google.com, jorgelo@chromium.org, groeck@chromium.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, pedro.falcato@gmail.com, dave.hansen@intel.com, linux-hardening@vger.kernel.org, deraadt@openbsd.org Subject: Re: [PATCH v10 3/5] selftest mm/mseal memory sealing To: jeffxu@chromium.org, akpm@linux-foundation.org, keescook@chromium.org, jannh@google.com, sroettger@google.com, willy@infradead.org, gregkh@linuxfoundation.org, torvalds@linux-foundation.org, corbet@lwn.net, Liam.Howlett@oracle.com, surenb@google.com, merimus@google.com, rdunlap@infradead.org References: <20240415163527.626541-1-jeffxu@chromium.org> <20240415163527.626541-4-jeffxu@chromium.org> Content-Language: en-US From: Muhammad Usama Anjum In-Reply-To: <20240415163527.626541-4-jeffxu@chromium.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Please fix following for this and fifth patch as well: --> checkpatch.pl --codespell tools/testing/selftests/mm/mseal_test.c WARNING: Macros with flow control statements should be avoided #42: FILE: tools/testing/selftests/mm/mseal_test.c:42: +#define FAIL_TEST_IF_FALSE(c) do {\ + if (!(c)) {\ + ksft_test_result_fail("%s, line:%d\n", __func__, __LINE__);\ + goto test_end;\ + } \ + } \ + while (0) WARNING: Macros with flow control statements should be avoided #50: FILE: tools/testing/selftests/mm/mseal_test.c:50: +#define SKIP_TEST_IF_FALSE(c) do {\ + if (!(c)) {\ + ksft_test_result_skip("%s, line:%d\n", __func__, __LINE__);\ + goto test_end;\ + } \ + } \ + while (0) WARNING: Macros with flow control statements should be avoided #59: FILE: tools/testing/selftests/mm/mseal_test.c:59: +#define TEST_END_CHECK() {\ + ksft_test_result_pass("%s\n", __func__);\ + return;\ +test_end:\ + return;\ +} On 4/15/24 9:35 PM, jeffxu@chromium.org wrote: > From: Jeff Xu > > selftest for memory sealing change in mmap() and mseal(). > > Signed-off-by: Jeff Xu > --- > tools/testing/selftests/mm/.gitignore | 1 + > tools/testing/selftests/mm/Makefile | 1 + > tools/testing/selftests/mm/mseal_test.c | 1836 +++++++++++++++++++++++ > 3 files changed, 1838 insertions(+) > create mode 100644 tools/testing/selftests/mm/mseal_test.c > > diff --git a/tools/testing/selftests/mm/.gitignore b/tools/testing/selftests/mm/.gitignore > index d26e962f2ac4..98eaa4590f11 100644 > --- a/tools/testing/selftests/mm/.gitignore > +++ b/tools/testing/selftests/mm/.gitignore > @@ -47,3 +47,4 @@ mkdirty > va_high_addr_switch > hugetlb_fault_after_madv > hugetlb_madv_vs_map > +mseal_test > diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile > index eb5f39a2668b..95d10fe1b3c1 100644 > --- a/tools/testing/selftests/mm/Makefile > +++ b/tools/testing/selftests/mm/Makefile > @@ -59,6 +59,7 @@ TEST_GEN_FILES += mlock2-tests > TEST_GEN_FILES += mrelease_test > TEST_GEN_FILES += mremap_dontunmap > TEST_GEN_FILES += mremap_test > +TEST_GEN_FILES += mseal_test > TEST_GEN_FILES += on-fault-limit > TEST_GEN_FILES += pagemap_ioctl > TEST_GEN_FILES += thuge-gen > diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/selftests/mm/mseal_test.c > new file mode 100644 > index 000000000000..06c780d1d8e5 > --- /dev/null > +++ b/tools/testing/selftests/mm/mseal_test. > +static void __write_pkey_reg(u64 pkey_reg) > +{ > +#if defined(__i386__) || defined(__x86_64__) /* arch */ > + unsigned int eax = pkey_reg; > + unsigned int ecx = 0; > + unsigned int edx = 0; > + > + asm volatile(".byte 0x0f,0x01,0xef\n\t" > + : : "a" (eax), "c" (ecx), "d" (edx)); > + assert(pkey_reg == __read_pkey_reg()); Use ksft_exit_fail_msg instead of assert to stay inside TAP format if condition is false and error is generated. > +int main(int argc, char **argv) > +{ > + bool test_seal = seal_support(); > + > + ksft_print_header(); > + > + if (!test_seal) > + ksft_exit_skip("sealing not supported, check CONFIG_64BIT\n"); > + > + if (!pkey_supported()) > + ksft_print_msg("PKEY not supported\n"); > + > + ksft_set_plan(80); > + > + test_seal_addseal(); > + test_seal_unmapped_start(); > + test_seal_unmapped_middle(); > + test_seal_unmapped_end(); > + test_seal_multiple_vmas(); > + test_seal_split_start(); > + test_seal_split_end(); > + test_seal_invalid_input(); > + test_seal_zero_length(); > + test_seal_twice(); > + > + test_seal_mprotect(false); > + test_seal_mprotect(true); > + > + test_seal_start_mprotect(false); > + test_seal_start_mprotect(true); > + > + test_seal_end_mprotect(false); > + test_seal_end_mprotect(true); > + > + test_seal_mprotect_unalign_len(false); > + test_seal_mprotect_unalign_len(true); > + > + test_seal_mprotect_unalign_len_variant_2(false); > + test_seal_mprotect_unalign_len_variant_2(true); > + > + test_seal_mprotect_two_vma(false); > + test_seal_mprotect_two_vma(true); > + > + test_seal_mprotect_two_vma_with_split(false); > + test_seal_mprotect_two_vma_with_split(true); > + > + test_seal_mprotect_partial_mprotect(false); > + test_seal_mprotect_partial_mprotect(true); > + > + test_seal_mprotect_two_vma_with_gap(false); > + test_seal_mprotect_two_vma_with_gap(true); > + > + test_seal_mprotect_merge(false); > + test_seal_mprotect_merge(true); > + > + test_seal_mprotect_split(false); > + test_seal_mprotect_split(true); > + > + test_seal_munmap(false); > + test_seal_munmap(true); > + test_seal_munmap_two_vma(false); > + test_seal_munmap_two_vma(true); > + test_seal_munmap_vma_with_gap(false); > + test_seal_munmap_vma_with_gap(true); > + > + test_munmap_start_freed(false); > + test_munmap_start_freed(true); > + test_munmap_middle_freed(false); > + test_munmap_middle_freed(true); > + test_munmap_end_freed(false); > + test_munmap_end_freed(true); > + > + test_seal_mremap_shrink(false); > + test_seal_mremap_shrink(true); > + test_seal_mremap_expand(false); > + test_seal_mremap_expand(true); > + test_seal_mremap_move(false); > + test_seal_mremap_move(true); > + > + test_seal_mremap_shrink_fixed(false); > + test_seal_mremap_shrink_fixed(true); > + test_seal_mremap_expand_fixed(false); > + test_seal_mremap_expand_fixed(true); > + test_seal_mremap_move_fixed(false); > + test_seal_mremap_move_fixed(true); > + test_seal_mremap_move_dontunmap(false); > + test_seal_mremap_move_dontunmap(true); > + test_seal_mremap_move_fixed_zero(false); > + test_seal_mremap_move_fixed_zero(true); > + test_seal_mremap_move_dontunmap_anyaddr(false); > + test_seal_mremap_move_dontunmap_anyaddr(true); > + test_seal_discard_ro_anon(false); > + test_seal_discard_ro_anon(true); > + test_seal_discard_ro_anon_on_rw(false); > + test_seal_discard_ro_anon_on_rw(true); > + test_seal_discard_ro_anon_on_shared(false); > + test_seal_discard_ro_anon_on_shared(true); > + test_seal_discard_ro_anon_on_filebacked(false); > + test_seal_discard_ro_anon_on_filebacked(true); > + test_seal_mmap_overwrite_prot(false); > + test_seal_mmap_overwrite_prot(true); > + test_seal_mmap_expand(false); > + test_seal_mmap_expand(true); > + test_seal_mmap_shrink(false); > + test_seal_mmap_shrink(true); > + > + test_seal_merge_and_split(); > + test_seal_zero_address(); > + > + test_seal_discard_ro_anon_on_pkey(false); > + test_seal_discard_ro_anon_on_pkey(true); > + > + ksft_finished(); > + return 0; The return isn't needed as ksft_finished() calls exit() with right exit code. > +} -- BR, Muhammad Usama Anjum