From patchwork Mon Jan 22 16:04:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 190233 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2715271dyb; Mon, 22 Jan 2024 09:16:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IF0y7BPvibIAbWYX9gYZqRQPtuT8OXO3mEtwMO+/YJgauuYG5NOLS05BXmdOUkG6CuXpG7a X-Received: by 2002:a05:6820:808:b0:598:6ed0:4018 with SMTP id bg8-20020a056820080800b005986ed04018mr2532747oob.16.1705943795620; Mon, 22 Jan 2024 09:16:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705943795; cv=pass; d=google.com; s=arc-20160816; b=xFw4cTrP5PMPBpuNRPnGG7jALbopFDR3LKKri+KNCg8ObCurNX3kmodkhLOv8RCf9R QOvBrp9/BJcq+OooD+6qgQUF2+B1P4kC6XTL4X/ACLMqidxrhoZvOr0/P/Oyp8JyRto/ /GoKWbJ5SK/afoqMdVfHIQm6EVdPiyPUO5bCQS5gPOPcOb/GOaQTGkYSsq6w2rG2vs7f DZL43GwTPNixPCPX4khfcjcu0swpVauoD8xXxmeEnrKfq3qSyzjJAlWybni0VZ7AD4GF vy5I/MDBnAyqbj08JfRV6m/M+NlK5i7TcFlR6U200Yjkw8hZ+CJaXokDaoUDBtu3jf7k 0hNQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=8CgMtc7ncuTLqhafMYTdlfE+W16GMoxkWvvs+4ORRAw=; fh=eBs+z3cdUgmHt86TGE0VSSkyDyUe/TSov8Em/nz9veM=; b=dsVg3NaMjn6NgId4N81yCHHFD8VArzQe2vMw35mtTX5P7MDiiNpmHzgn1UHPYte8/m mB7if/C76LjVi7ZWdj8s2lhYcwitK6nfhE1QVwBTPnWMX4UzFAZQ3juaVNzwOmQZCCNf 3aXPvu6Pks5QjDXFkJ2FG5nvQ2wO3X+FB+227aBLsupqpYFLATKej+kEaTLAJWS3KBlt KHbFhLBb/IrSQuuRfzO0/3EukVJyGCuMfkrYz0KPePg+mi41ZvIOzlu7GMhpwhQv6afW 3kgULjjFvLvf1tk3c/pphDmGEsoslI1GAOnFK+lSrBIxPtnHhbg6ktzmSVtK6PzxvKOk 3/Qw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ehWpv7mM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-33650-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33650-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id h20-20020a0cab14000000b00680bb9364f6si6212867qvb.84.2024.01.22.09.16.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 09:16:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-33650-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ehWpv7mM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-33650-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33650-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 028011C24F91 for ; Mon, 22 Jan 2024 17:15:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CBDF2634E5; Mon, 22 Jan 2024 16:04:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ehWpv7mM" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 9A9D0633F1; Mon, 22 Jan 2024 16:04:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705939469; cv=none; b=p9gYb/dxiS1WYoX6MUq5/XONHF1H5wiLd9ZblPF/97aZSq+AevorXio2NYjyPsFdM6BZDo/2w0myOS2h/OdlZwQQSW9efxl1AjLIzRxi+aDIpmtvjsZa3u+1KA9AE+4FNNA0n1hu0t3eO7lxy7I2KrAEegrjJLLWZXRpLaaFMu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705939469; c=relaxed/simple; bh=xnODDqrpQCt2Usa5KTDk01X54nQ4U4UJ8wKdaF12AcA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=t/jDOFBg/V8Ls8Qq9mnAyi+YnQM+yaHIWO9hzEmVabUvT2PtqosnvblEF1ciZqrB6AIwuwbOlSYRVy4DHG/qKxzQDuwWDm081oRhAAhIieLd7p0XGfLnSYExlsa3H8N9fE4zeAXW4ff29AdIP02RC0qkpd7nXtuZemsVrk3POQA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ehWpv7mM; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63C46C433C7; Mon, 22 Jan 2024 16:04:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705939469; bh=xnODDqrpQCt2Usa5KTDk01X54nQ4U4UJ8wKdaF12AcA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ehWpv7mMx0kZH5qh0AnEMa69gi129WJubBJSPnoohE853y67ZBo1QLR7YwZPGI3Tt bZHQ0YtBJfhJMJTu5Qc8WvguEw0uF5NhxIVDRQQ3t+1CGJRAs6ol1Ym5W2Oe/y0nAT Qy6YobUKuJsn6G5EW1eogKOZnD5rhG0i45kePMYc3wJAw8PyiIawXQ2BOxYkLmROsP S7qpe7JiFt76QPvXK12bV+ESEW1WuoVc2AHK2kODUIbNVqvAJ0+Yb8FyJyitToYsie cVmNpN0YvrOrqJA9jAbyRQlUtuOvVOG0VBlWSBAxxJXIa220STUCLkPDZf54wkPbBG 68ZnAS4JjmSZg== From: Mark Brown Date: Mon, 22 Jan 2024 16:04:15 +0000 Subject: [PATCH v2 1/2] kselftest/seccomp: Use kselftest output functions for benchmark Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240122-b4-kselftest-seccomp-benchmark-ktap-v2-1-aed137eaea41@kernel.org> References: <20240122-b4-kselftest-seccomp-benchmark-ktap-v2-0-aed137eaea41@kernel.org> In-Reply-To: <20240122-b4-kselftest-seccomp-benchmark-ktap-v2-0-aed137eaea41@kernel.org> To: Kees Cook , Andy Lutomirski , Will Drewry , Shuah Khan Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown , Anders Roxell X-Mailer: b4 0.13-dev-5c066 X-Developer-Signature: v=1; a=openpgp-sha256; l=6351; i=broonie@kernel.org; h=from:subject:message-id; bh=xnODDqrpQCt2Usa5KTDk01X54nQ4U4UJ8wKdaF12AcA=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlrpIHCO0I/3oSK3L4ZWNNjejV0PoGiyAEk/GBoq9h fofPpEqJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZa6SBwAKCRAk1otyXVSH0OQ3B/ 4kGNKoJPJv3Jzds/m0NjzAyBQgxuP3qP8qXWPfh3gxIBmtozc2mZB8cBt7nWTmkmrQmmo1zejlqHj+ 7yjagcKOynaW73z/hqJ8I6LqFXIkoyuOHgRR16LL0c01kXX32vfxv7G06ua3pOmbWwr232kCq5j/yv Ix5ogbgYkOiLAqFm7wfP1rdbzDm0Y1fzAo26EuCiLgg82AvyVRkQ05P7Zsc5idMrUN5vZD6tEZkjDo GESu5BRK7/leO/2hw4lrKVrogBr7Vsxvv1iuxeuRSeR/SZL6LhBEgN15mq9kZ4nAthgoqw637K+n/M 7R6/UOUkGsUo5ln66KudMMLyEEHDN1 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788811721457443686 X-GMAIL-MSGID: 1788811721457443686 In preparation for trying to output the test results themselves in TAP format rework all the prints in the benchmark to use the kselftest output functions. The uses of system() all produce single line output so we can avoid having to deal with fully managing the child process and continue to use system() by simply printing an empty message before we invoke system(). We also leave one printf() used to complete a line of output in place. Tested-by: Anders Roxell Signed-off-by: Mark Brown Acked-by: Kees Cook --- .../testing/selftests/seccomp/seccomp_benchmark.c | 45 ++++++++++++---------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/seccomp/seccomp_benchmark.c b/tools/testing/selftests/seccomp/seccomp_benchmark.c index 5b5c9d558dee..93168dd2c1e3 100644 --- a/tools/testing/selftests/seccomp/seccomp_benchmark.c +++ b/tools/testing/selftests/seccomp/seccomp_benchmark.c @@ -38,10 +38,10 @@ unsigned long long timing(clockid_t clk_id, unsigned long long samples) i *= 1000000000ULL; i += finish.tv_nsec - start.tv_nsec; - printf("%lu.%09lu - %lu.%09lu = %llu (%.1fs)\n", - finish.tv_sec, finish.tv_nsec, - start.tv_sec, start.tv_nsec, - i, (double)i / 1000000000.0); + ksft_print_msg("%lu.%09lu - %lu.%09lu = %llu (%.1fs)\n", + finish.tv_sec, finish.tv_nsec, + start.tv_sec, start.tv_nsec, + i, (double)i / 1000000000.0); return i; } @@ -53,7 +53,7 @@ unsigned long long calibrate(void) pid_t pid, ret; int seconds = 15; - printf("Calibrating sample size for %d seconds worth of syscalls ...\n", seconds); + ksft_print_msg("Calibrating sample size for %d seconds worth of syscalls ...\n", seconds); samples = 0; pid = getpid(); @@ -102,14 +102,14 @@ long compare(const char *name_one, const char *name_eval, const char *name_two, { bool good; - printf("\t%s %s %s (%lld %s %lld): ", name_one, name_eval, name_two, - (long long)one, name_eval, (long long)two); + ksft_print_msg("\t%s %s %s (%lld %s %lld): ", name_one, name_eval, name_two, + (long long)one, name_eval, (long long)two); if (one > INT_MAX) { - printf("Miscalculation! Measurement went negative: %lld\n", (long long)one); + ksft_print_msg("Miscalculation! Measurement went negative: %lld\n", (long long)one); return 1; } if (two > INT_MAX) { - printf("Miscalculation! Measurement went negative: %lld\n", (long long)two); + ksft_print_msg("Miscalculation! Measurement went negative: %lld\n", (long long)two); return 1; } @@ -145,12 +145,15 @@ int main(int argc, char *argv[]) setbuf(stdout, NULL); - printf("Running on:\n"); + ksft_print_msg("Running on:\n"); + ksft_print_msg(""); system("uname -a"); - printf("Current BPF sysctl settings:\n"); + ksft_print_msg("Current BPF sysctl settings:\n"); /* Avoid using "sysctl" which may not be installed. */ + ksft_print_msg(""); system("grep -H . /proc/sys/net/core/bpf_jit_enable"); + ksft_print_msg(""); system("grep -H . /proc/sys/net/core/bpf_jit_harden"); if (argc > 1) @@ -158,11 +161,11 @@ int main(int argc, char *argv[]) else samples = calibrate(); - printf("Benchmarking %llu syscalls...\n", samples); + ksft_print_msg("Benchmarking %llu syscalls...\n", samples); /* Native call */ native = timing(CLOCK_PROCESS_CPUTIME_ID, samples) / samples; - printf("getpid native: %llu ns\n", native); + ksft_print_msg("getpid native: %llu ns\n", native); ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); assert(ret == 0); @@ -172,33 +175,33 @@ int main(int argc, char *argv[]) assert(ret == 0); bitmap1 = timing(CLOCK_PROCESS_CPUTIME_ID, samples) / samples; - printf("getpid RET_ALLOW 1 filter (bitmap): %llu ns\n", bitmap1); + ksft_print_msg("getpid RET_ALLOW 1 filter (bitmap): %llu ns\n", bitmap1); /* Second filter resulting in a bitmap */ ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &bitmap_prog); assert(ret == 0); bitmap2 = timing(CLOCK_PROCESS_CPUTIME_ID, samples) / samples; - printf("getpid RET_ALLOW 2 filters (bitmap): %llu ns\n", bitmap2); + ksft_print_msg("getpid RET_ALLOW 2 filters (bitmap): %llu ns\n", bitmap2); /* Third filter, can no longer be converted to bitmap */ ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog); assert(ret == 0); filter1 = timing(CLOCK_PROCESS_CPUTIME_ID, samples) / samples; - printf("getpid RET_ALLOW 3 filters (full): %llu ns\n", filter1); + ksft_print_msg("getpid RET_ALLOW 3 filters (full): %llu ns\n", filter1); /* Fourth filter, can not be converted to bitmap because of filter 3 */ ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &bitmap_prog); assert(ret == 0); filter2 = timing(CLOCK_PROCESS_CPUTIME_ID, samples) / samples; - printf("getpid RET_ALLOW 4 filters (full): %llu ns\n", filter2); + ksft_print_msg("getpid RET_ALLOW 4 filters (full): %llu ns\n", filter2); /* Estimations */ #define ESTIMATE(fmt, var, what) do { \ var = (what); \ - printf("Estimated " fmt ": %llu ns\n", var); \ + ksft_print_msg("Estimated " fmt ": %llu ns\n", var); \ if (var > INT_MAX) \ goto more_samples; \ } while (0) @@ -218,7 +221,7 @@ int main(int argc, char *argv[]) ESTIMATE("seccomp per-filter overhead (filters / 4)", per_filter2, (filter2 - native - entry) / 4); - printf("Expectations:\n"); + ksft_print_msg("Expectations:\n"); ret |= compare("native", "≤", "1 bitmap", native, le, bitmap1); bits = compare("native", "≤", "1 filter", native, le, filter1); if (bits) @@ -230,7 +233,7 @@ int main(int argc, char *argv[]) bits = compare("1 bitmapped", "≈", "2 bitmapped", bitmap1 - native, approx, bitmap2 - native); if (bits) { - printf("Skipping constant action bitmap expectations: they appear unsupported.\n"); + ksft_print_msg("Skipping constant action bitmap expectations: they appear unsupported.\n"); goto out; } @@ -242,7 +245,7 @@ int main(int argc, char *argv[]) goto out; more_samples: - printf("Saw unexpected benchmark result. Try running again with more samples?\n"); + ksft_print_msg("Saw unexpected benchmark result. Try running again with more samples?\n"); out: return 0; } From patchwork Mon Jan 22 16:04:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 190236 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2716043dyb; Mon, 22 Jan 2024 09:17:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFnNkSxo4y99eZ2YrPrSju9nB6+FCkuVLOwXROejavHFJaPngUVNWC8oHYgWChcmS7QQCnT X-Received: by 2002:a17:90a:989:b0:28e:96b:f8ca with SMTP id 9-20020a17090a098900b0028e096bf8camr1561660pjo.55.1705943867891; Mon, 22 Jan 2024 09:17:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705943867; cv=pass; d=google.com; s=arc-20160816; b=LcZbkQoj77YvIrFWU9Mgi/owmefVLYQI2CJCY16oCTnbX2wP4asiwHUIEMZyRnpIW+ qp1n7BpUD4uj4I2pPUk4vTcC8YbhqGLjMDo+5VRY4yc0gpZVXsG2YBASuJ6LzSykNHTD x7GitTDishiSqG/2b2E0ToCFmy0HZHm8U6A7bKwicEUZj9AH+/ns1qbMwQiq/gCXIVLA EtHLvx6MqRD9jwQrfFXHeIJQvHLvqGU+K6TdNUFCtz1rbSuqPUZqXfYs/GosxBTbEnNf ujwN07Wx9KUBYfvJaKYeeLCf/BjtGP0RgayFWdnCzmU7FQkcop+4z/ll1DSjWlMRDWcz fIMA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=VraQ8jiim1sb9AO6L2h927bf3brh2MF4v4KAbGtSU0g=; fh=eBs+z3cdUgmHt86TGE0VSSkyDyUe/TSov8Em/nz9veM=; b=owdKQFBecNah08WoeKqdI5Jby21RXY7nPy4uoO65x26tbH/9XfK9PXhg0sFiKqwasM Fbz2F9UgXcsihr09Y9TwKaL63Ie2sLMPJaXgdF4IP55/Ni1CkB+CM1OonJMtQy/+GIzC dygHYYfwKPiqcqqPKDS/87e4v1NkBd3NEZAn7xiAAPhDNgQjvorOpGfP8Kv3QTCuStK5 KwGSvAySlWVEJBVqspe9ST1qVafZMsC7ewgAwvHVqtzZQArzLrBemuVktBGXk0ZlrbNk nSisux3TmzkG1Dh1rA8r0/RkFE6aA9OvukJucwbv1DpMax9GScIhUsTbm2x/UHArSs9A vD2Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pcofZQaJ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-33651-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33651-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id lp8-20020a17090b4a8800b00290bc6502cbsi651040pjb.90.2024.01.22.09.17.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 09:17:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-33651-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pcofZQaJ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-33651-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33651-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A2AE3285B3A for ; Mon, 22 Jan 2024 17:15:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 873C7634F7; Mon, 22 Jan 2024 16:04:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pcofZQaJ" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 702B463409; Mon, 22 Jan 2024 16:04:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705939471; cv=none; b=jpRZysHbtG5EFghgcMFL49F6TC2b5vnoMdHYLFk4SIi+pvPcBGBHclAoB6AVUkwsAkShhzlgxPA3HSBuz2z3aYucBlbCT/NzdEJi3UTCHdh7SZb/s8ZQv5VRuL/lPDi1bhD6DGTvffgLOkSGKS45ZafvmXRapGSvVZ6IgWgu/lE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705939471; c=relaxed/simple; bh=drSCH2vqjER5uFfaL/EFbAZqdSb/+RdMNKpIpIhecn4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ar5LRtg/3lm9Nhf5wHNDIvOWgkgMj9bKKvwyHTa4tadlFW/4rrQXUPnqClJrSn66qjUVPb78EtJ/0AqvpCSGLxq6NLY/AC+AZ6GQT8jhJ4IFRkRDjjAf8RDuUUlV2+e5V3+BV+iu93zl4OMoAH4bVAKZsPfcZYv6LVAiL6MzOZk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pcofZQaJ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E29EC43390; Mon, 22 Jan 2024 16:04:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705939471; bh=drSCH2vqjER5uFfaL/EFbAZqdSb/+RdMNKpIpIhecn4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=pcofZQaJjswkaya1B7aqa8ONUq/WwbpI6+Xw46D5tUEbdiSNnN9cVSbCkDQJJQ1aU lKJsBqc33gaWnbSzIElF8ZKQvjOY8zt2AYabsOaP8qrRRpNO5U459mkdh1h0W7aZ6l gXsRECGAwrVT6DrAk+GfBTxUzKSzOCU+QRMXM4baDBTIOiyoNyf3GEkcU0fVu5Oead M2L4SUmzoxVyz8mTdvsg6iB/E5s+fYk858eejen9piljHxzST+2hbFMQ09gOo5qea7 6cdZ9KCQSeicH3ICjF0kY9mi/Q8aIIagwoMwwSCDkKXbexROKS1sKTBMDr13LJD/QK 6VRCYlOyf1z2A== From: Mark Brown Date: Mon, 22 Jan 2024 16:04:16 +0000 Subject: [PATCH v2 2/2] kselftest/seccomp: Report each expectation we assert as a KTAP test Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240122-b4-kselftest-seccomp-benchmark-ktap-v2-2-aed137eaea41@kernel.org> References: <20240122-b4-kselftest-seccomp-benchmark-ktap-v2-0-aed137eaea41@kernel.org> In-Reply-To: <20240122-b4-kselftest-seccomp-benchmark-ktap-v2-0-aed137eaea41@kernel.org> To: Kees Cook , Andy Lutomirski , Will Drewry , Shuah Khan Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown , Anders Roxell X-Mailer: b4 0.13-dev-5c066 X-Developer-Signature: v=1; a=openpgp-sha256; l=5022; i=broonie@kernel.org; h=from:subject:message-id; bh=drSCH2vqjER5uFfaL/EFbAZqdSb/+RdMNKpIpIhecn4=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlrpIIANr/QODbYott0+MPNEx8QxfMi4WvaG/FAilk Rga98WKJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZa6SCAAKCRAk1otyXVSH0K0QB/ kBMl4FyvfS8KRKzKZ2ALUkyTOfNzgnzNgAEm0VmIfGIsLWeBdftXOfYY2Lc3Iwhn1QEMoslH/qCRVd +Ec1cay6W4Os5fO4xpgG1krUQihvFEQQgpmB8HPEz5O5uwRLOsB0oXibCkcb0XSMOJyKamP2Fufx/9 nOUy2InBk1+O4oZpDC7IpgHc/aBZYgfjE/nuTNJn0ICiQE8R0qtRR/1dO75wPZ7KAsFQOSQwMEdpTc hSVfBY8xmnnzNAwln/4pyqqUtJxMcGherYhV+G23oQDDnaBSK9tIZB1zlxnogvfEqk4R0VLS3jGxzc bhgY0BEN8GKJ90E4LgvtdioyulLlYE X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788811796784803041 X-GMAIL-MSGID: 1788811796784803041 The seccomp benchmark test makes a number of checks on the performance it measures and logs them to the output but does so in a custom format which none of the automated test runners understand meaning that the chances that anyone is paying attention are slim. Let's additionally log each result in KTAP format so that automated systems parsing the test output will see each comparison as a test case. The original logs are left in place since they provide the actual numbers for analysis. As part of this rework the flow for the main program so that when we skip tests we still log all the tests we skip, this is because the standard KTAP headers and footers include counts of the number of expected and run tests. Tested-by: Anders Roxell Acked-by: Kees Cook --- .../testing/selftests/seccomp/seccomp_benchmark.c | 62 +++++++++++++++------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/seccomp/seccomp_benchmark.c b/tools/testing/selftests/seccomp/seccomp_benchmark.c index 93168dd2c1e3..436a527b8235 100644 --- a/tools/testing/selftests/seccomp/seccomp_benchmark.c +++ b/tools/testing/selftests/seccomp/seccomp_benchmark.c @@ -98,24 +98,36 @@ bool le(int i_one, int i_two) } long compare(const char *name_one, const char *name_eval, const char *name_two, - unsigned long long one, bool (*eval)(int, int), unsigned long long two) + unsigned long long one, bool (*eval)(int, int), unsigned long long two, + bool skip) { bool good; + if (skip) { + ksft_test_result_skip("%s %s %s\n", name_one, name_eval, + name_two); + return 0; + } + ksft_print_msg("\t%s %s %s (%lld %s %lld): ", name_one, name_eval, name_two, (long long)one, name_eval, (long long)two); if (one > INT_MAX) { ksft_print_msg("Miscalculation! Measurement went negative: %lld\n", (long long)one); - return 1; + good = false; + goto out; } if (two > INT_MAX) { ksft_print_msg("Miscalculation! Measurement went negative: %lld\n", (long long)two); - return 1; + good = false; + goto out; } good = eval(one, two); printf("%s\n", good ? "✔️" : "❌"); +out: + ksft_test_result(good, "%s %s %s\n", name_one, name_eval, name_two); + return good ? 0 : 1; } @@ -142,9 +154,13 @@ int main(int argc, char *argv[]) unsigned long long samples, calc; unsigned long long native, filter1, filter2, bitmap1, bitmap2; unsigned long long entry, per_filter1, per_filter2; + bool skip = false; setbuf(stdout, NULL); + ksft_print_header(); + ksft_set_plan(7); + ksft_print_msg("Running on:\n"); ksft_print_msg(""); system("uname -a"); @@ -202,8 +218,10 @@ int main(int argc, char *argv[]) #define ESTIMATE(fmt, var, what) do { \ var = (what); \ ksft_print_msg("Estimated " fmt ": %llu ns\n", var); \ - if (var > INT_MAX) \ - goto more_samples; \ + if (var > INT_MAX) { \ + skip = true; \ + ret |= 1; \ + } \ } while (0) ESTIMATE("total seccomp overhead for 1 bitmapped filter", calc, @@ -222,30 +240,34 @@ int main(int argc, char *argv[]) (filter2 - native - entry) / 4); ksft_print_msg("Expectations:\n"); - ret |= compare("native", "≤", "1 bitmap", native, le, bitmap1); - bits = compare("native", "≤", "1 filter", native, le, filter1); + ret |= compare("native", "≤", "1 bitmap", native, le, bitmap1, + skip); + bits = compare("native", "≤", "1 filter", native, le, filter1, + skip); if (bits) - goto more_samples; + skip = true; ret |= compare("per-filter (last 2 diff)", "≈", "per-filter (filters / 4)", - per_filter1, approx, per_filter2); + per_filter1, approx, per_filter2, skip); bits = compare("1 bitmapped", "≈", "2 bitmapped", - bitmap1 - native, approx, bitmap2 - native); + bitmap1 - native, approx, bitmap2 - native, skip); if (bits) { ksft_print_msg("Skipping constant action bitmap expectations: they appear unsupported.\n"); - goto out; + skip = true; } - ret |= compare("entry", "≈", "1 bitmapped", entry, approx, bitmap1 - native); - ret |= compare("entry", "≈", "2 bitmapped", entry, approx, bitmap2 - native); + ret |= compare("entry", "≈", "1 bitmapped", entry, approx, + bitmap1 - native, skip); + ret |= compare("entry", "≈", "2 bitmapped", entry, approx, + bitmap2 - native, skip); ret |= compare("native + entry + (per filter * 4)", "≈", "4 filters total", - entry + (per_filter1 * 4) + native, approx, filter2); - if (ret == 0) - goto out; + entry + (per_filter1 * 4) + native, approx, filter2, + skip); -more_samples: - ksft_print_msg("Saw unexpected benchmark result. Try running again with more samples?\n"); -out: - return 0; + if (ret) { + ksft_print_msg("Saw unexpected benchmark result. Try running again with more samples?\n"); + } + + ksft_finished(); }