Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp405181lqm; Wed, 1 May 2024 04:35:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXFVZVhm3CqOxJH9G7QeiMiOM3Hpi/KaXsuhUXYx17T/pYj9+yvOZYRNlfZJUiN4kK3Q9j6ZqcNh973MWjl5nrbBzpDuycAtR92DDKzAQ== X-Google-Smtp-Source: AGHT+IGsxMaU6DOK26v78cnAQ8/gDGaQ7SzOlpwGs6BpRD8l1izK/O8ykHsPkxVB2A20nF24QIPm X-Received: by 2002:a25:800d:0:b0:dc8:5e26:f501 with SMTP id m13-20020a25800d000000b00dc85e26f501mr1944238ybk.61.1714563325051; Wed, 01 May 2024 04:35:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714563325; cv=pass; d=google.com; s=arc-20160816; b=owplgtUou19rdc1P9lfcRd8nCiBABf86L7uujOOLVf+B5t+0UtjdELfOgqxpNiizQD 2f+0uCVGspQVE5gllkcCayuUjXLj89J3b+4dSVbIY+I2x3kE4iQlMg9jx7rzsfekCFcI wX+SgXn2HPc8HFgYf+kaPN8K17KSgicl74GO2wVFWKCsjdL1ujf0qWTGlvg8nL840oV7 CT0z/g3oQW5TR6JxdEYVPlVynn4a4W7Wc87U15UOOqsXIr7cFRqGcb6k9D+OmA3f6oq4 1vym9lY/4vSkVbxEOWc0op9X9r3dYFF7J6O9V602iK6dEnzjM97Z5aqH5rg/a33FOiGk TgLg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=zH9SL71kzsrSFUk4RZjfiBx6FvwI8pe/vtpUVkDTryc=; fh=vtz5ABhGCod5ZK9EVo6Gc1HKGH8gQJE94gnkkOuY9uo=; b=D8Xu1oCAFOtz2pPWB5iyqtodNt0btPNkXNMhrOyK4l+aDum5HzgRaaScSYaxM0c8tN dWFivGAavH6ieDowQmrOdyFJIzTLZXKdsyTk8DPMQZW8q+j7vwTFD0CORLuTXRdHGBfI 2s0NKCX2/qCSORfMFYGmmH89+kZ84hAdxEdrpdmHBLCybSuD6U9UwhjtVic5HU/lBqMi h27PM3P2GTSOxM8d1sHnpl3Mf4/VtAdW5ZInT9sCRU+CrSILngkbKWKuS5tk9bNd18Em 0S/QsUwzSfhr4ZZwaeQPJg07iaD7qXO+dJ8ZqYv+11Xx1YdyXQ6KWnbi0JybaSXYwTmi tfaQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-165188-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165188-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id fz22-20020a05622a5a9600b00439f992a850si19451064qtb.758.2024.05.01.04.35.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 04:35:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-165188-linux.lists.archive=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; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-165188-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165188-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 9FF3C1C217EA for ; Wed, 1 May 2024 11:35:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6ADA87D414; Wed, 1 May 2024 11:35:18 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE6E964A98; Wed, 1 May 2024 11:35:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714563317; cv=none; b=KMdqh4RadnsJK81FdXebAUy4Q9HZyKUkr5FZYiV7bETB8O+6D4cvhoFJeEiKCs0SziD6WjpwSX3FVJ0bFLjKQFKb6+f9/OHNPCP3tZ7gwwv65oWKxqNGNvr79RYCOsxxjJc488Vtj+KNNxCWKuFE8Y9Zo2e4rJ/cc+X/1AtAgF4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714563317; c=relaxed/simple; bh=wJy87bfpS7s04Gzynz66njZDUrj0KmFwHecK8KcHmF8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lG8hRjyphwkzGvnBnqZGnVE/+7L44wDINj7fNUS4smBuOnvNKicXiCwUK3otDUFXNxiqAP5flexkjR3G+YkZGRVFM8kg5Skhbi3SdftG0a+bM+jC0xKB8b6iHtUFnCrKttkeD1oBK2Zg1H9c4Q5ORu8NvhWYrlwy2ZEiyccKJnQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 82CB42F4; Wed, 1 May 2024 04:35:41 -0700 (PDT) Received: from e133380.arm.com (e133380.arm.com [10.1.197.52]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 347083F793; Wed, 1 May 2024 04:35:14 -0700 (PDT) Date: Wed, 1 May 2024 12:35:08 +0100 From: Dave Martin To: Dorine Tipo Cc: Catalin Marinas , Will Deacon , Shuah Khan , linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, Javier Carrasco Subject: Re: [PATCH] selftests:arm64: Test PR_SVE_VL_INHERIT after a double fork Message-ID: References: <20240429044012.5018-1-dorine.a.tipo@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240429044012.5018-1-dorine.a.tipo@gmail.com> On Mon, Apr 29, 2024 at 04:40:12AM +0000, Dorine Tipo wrote: > [PATCH] selftests:arm64: Test PR_SVE_VL_INHERIT after a double fork Nit: Please follow the same commit message prefix convention as in the existing code (e.g., try git log tools/testing/selftests/arm64/fp/ ). [...] > Add a new test, double_fork_test() to check the inheritance of the SVE > vector length after a double fork. > The `EXPECTED_TESTS` macro has been updated to account for this additional > test. > This patch addresses task 7 on the TODO list. > > Signed-off-by: Dorine Tipo > --- > tools/testing/selftests/arm64/fp/za-fork.c | 95 +++++++++++++++++++++- > 1 file changed, 94 insertions(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/arm64/fp/za-fork.c b/tools/testing/selftests/arm64/fp/za-fork.c > index 587b94648222..35229e570dcf 100644 > --- a/tools/testing/selftests/arm64/fp/za-fork.c > +++ b/tools/testing/selftests/arm64/fp/za-fork.c > @@ -11,7 +11,7 @@ > > #include "kselftest.h" > > -#define EXPECTED_TESTS 1 > +#define EXPECTED_TESTS 2 > > int fork_test(void); > int verify_fork(void); > @@ -69,6 +69,97 @@ int fork_test_c(void) > } "git am" or "patch" report the patch as corrupted here, any idea why? Fixing the whitespace here allows the patch to be applied, but it still doesn't seem to build, so I think there are bigger problems here. > } > > +int double_fork_test(void) > +{ > + pid_t newpid, grandchild_pid, waiting; > + int ret, child_status, parent_result; > + > + ret = prctl(PR_SVE_SET_VL, vl | PR_SVE_VL_INHERIT); > + if (ret < 0) > + ksft_exit_fail_msg("Failed to set SVE VL %d\n", vl); Thanks for the attempt, but this file doesn't look like the correct place to add these tests. This file is specific to testing SME (the "ZA" register array is specific to SME). Looking at the history of the TODO file, it looks like the entry you're looking at was related to the tests in vec-syscfg.c. That looks like a better place to test the API behaviour of these prctl calls; most of the needed framework is already there. So, please consider adapting vec-syscfg.c to add the double-fork tests, rather than trying to write this from scratch. (See commit e96595c55d23 ("kselftest/arm64: Add a TODO list for floating point tests") for history.) If you haven't already done so, you should go and look at the following to get a better idea of how these prctl calls are supposed to work: Documentation/arch/arm64/sve.rst Documentation/arch/arm64/sme.rst The prctl(2) man page also documents the SVE prctls: https://man7.org/linux/man-pages/man2/prctl.2.html . [more comments below] > + > + newpid = fork(); > + if (newpid == 0) { > + /* In child */ > + if (!verify_fork()) { > + ksft_print_msg("ZA state invalid in child\n"); > + exit(0); > + } > + > + grandchild_pid = fork(); > + if (grandchild_pid == 0) { > + /* in grandchild */ > + if (!verfy_fork()) { > + ksft_print_msg("ZA state invalid in grandchild\n"); > + exit(0); > + } > + > + ret = prctl(PR_SVE_GET_VL); > + if (ret & PR_SVE_VL_INHERIT) { > + ksft_print_msg("prctl() reports _INHERIT\n"); > + return; > + } > + ksft_print_msg("prctl() does not report _INHERIT\n"); > + > + } else if (grandchild_pid < 0) { > + ksft_print_msg("fork() failed in first child: %d\n", grandchild_pid); > + return 0; > + } > + > + /* Wait for the grandchild process to exit */ > + waiting = waitpid(grandchild_pid, &child_status, 0); > + if (waiting < 0) { > + if (errno == EINTR) > + continue; > + ksft_print_msg("waitpid() failed: %d\n", errno); > + return 0; > + } > + if (waiting != grandchild_pid) { > + ksft_print_msg("waitpid() returned wrong PID\n"); > + return 0; > + } > + > + if (!WIFEXITED(child_status)) { > + ksft_print_msg("grandchild did not exit\n"); > + return 0; > + } > + > + exit(1); > + } > + } > + if (newpid < 0) { > + ksft_print_msg("fork() failed: %d\n", newpid); > + > + return 0; > + } > + > + parent_result = verify_fork(); > + if (!parent_result) > + ksft_print_msg("ZA state invalid in parent\n"); > + > + for (;;) { > + waiting = waitpid(newpid, &child_status, 0); > + > + if (waiting < 0) { > + if (errno == EINTR) > + continue; > + ksft_print_msg("waitpid() failed: %d\n", errno); > + return 0; > + } > + if (waiting != newpid) { > + ksft_print_msg("waitpid() returned wrong PID\n"); > + return 0; > + } > + > + if (!WIFEXITED(child_status)) { > + ksft_print_msg("child did not exit\n"); > + return 0; > + } > + > + return WEXITSTATUS(child_status) && parent_result; > + } > +} > + > int main(int argc, char **argv) > { > int ret, i; > @@ -86,11 +177,13 @@ int main(int argc, char **argv) > ret = open("/proc/sys/abi/sme_default_vector_length", O_RDONLY, 0); > if (ret >= 0) { > ksft_test_result(fork_test(), "fork_test\n"); > + ksft_test_result(double_fork_test(), "double_fork_test\n"); > > } else { > ksft_print_msg("SME not supported\n"); > for (i = 0; i < EXPECTED_TESTS; i++) { > ksft_test_result_skip("fork_test\n"); > + ksft_test_result_skip("double_fork_test\n"); I'm not very familiar with the kselftest framework, but this looks weird to me. Why should we skip both tests twice when there are two tests? (Looking at the history, I think this loop may have been left behind from an old edit and perhaps shouldn't be there any more. Comparing with the way ksft_test_result_skip() is used in other tests may provide a clue. Maybe Mark Brown remembers...) > } > } And finally... how are you running these tests? Cheers ---Dave