Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp1619789rwp; Thu, 13 Jul 2023 13:50:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlHIuF8UezW1/E5MRd1PuepBnVA1xiTm61Wb+rW+9C6UTnHSvJBV5pK/cCIeqiNTloMdXAEG X-Received: by 2002:a05:6a00:b91:b0:682:713e:e520 with SMTP id g17-20020a056a000b9100b00682713ee520mr2871169pfj.8.1689281411274; Thu, 13 Jul 2023 13:50:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689281411; cv=none; d=google.com; s=arc-20160816; b=CRDY+2Fv0te0Gtyb5gL0MiUIlNXW6+J84HF9DuzcTWhV4TVaXiPytRziLBZqLdCj3I WbjgIL99Ho8Z2uOjCQey4UdjVie45Gq70ATxrrc68E7QpdreAWTOJAFs4WL2v5smf8QF cLiTaby/9DtagaCDVA6oeRLfW8QPBWlrUEXBLovHItOYZmdXeuCn1U/K6yWvUHmlUoHx cWXMCqVXqviYBNXECTAGjaT0jNis/MZhxhYiNbbt/N6c8nYhrJS9hSXFsGL+ZzzJcfkS jiHC6L2qybtpKUsJUTBr8zjeJdlY8/vHGZJ5beStZckBLUlDIuzmLpplkGuCE1REXjPj ceXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=Glu9diDse55rsV811+9nqVZ+PoNZRy2iR/szkZLi0tY=; fh=uJMLtksqvJZrsv4Tz47lujlNMgmmE8Yxkkg7Yj3ceBg=; b=kYH4u/vVg2ZjV+fu6W67yDmlk7Im9/MW9VfVxBZC5yuK6njNmvW37mLQlrK3vZIep5 o8PRXs7hhDzrzvIGrss1f1KbYDL7WI963SKwXYRB092ZBhtdMfdGsMexgzN7i3MltTbM 4/F1zNeJ+i6EMHH4yweD0djn2lFSc0YyvaulaQvQcDSMStWDRlVcY6jWnuvRK1IhTwZI zhb12+LBKIrm6pfJr38ETXfu16bhHI1+xI5NhItjnBfM29lDMUKisEl2xwh7wIrqOHOH 2DsdvqdhG+9r/L6vVVCx8WtXcTYPCG/old3tEok2Jb2JBA35Y+ta2ZAnQ1s19LWjWdrl hlmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IFrTAcPE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f7-20020a056a001ac700b006761adef5ddsi5591483pfv.274.2023.07.13.13.49.58; Thu, 13 Jul 2023 13:50:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IFrTAcPE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232782AbjGMULu (ORCPT + 99 others); Thu, 13 Jul 2023 16:11:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232197AbjGMULq (ORCPT ); Thu, 13 Jul 2023 16:11:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7C7D30CB; Thu, 13 Jul 2023 13:11:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 93DB261B50; Thu, 13 Jul 2023 20:11:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69A12C433C8; Thu, 13 Jul 2023 20:11:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689279062; bh=pefhisUmRsg+2EzyXrIeOHRp6qKwWRumC3ginNtyGbg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=IFrTAcPEgpsvm3EHMhXwpsqfxTmSpuqajNYjOslXWK4dh+jbHplsmrSs8Fb6BnPRu CP/eYAUyWRjG/clgJo6KawD8+bHtKBSRatScz+MU+zn3ba3eLIBx5ELADNKxZHETYT B612okPlZ36n26mv4SEQOe4elNK6vE4BfNQYE2Xiaic2aAu1VhqnHx35YmEbxICcmM k3sIx6dj2lYhkdfd6QfaBIjC3lsour570ZCzl2vaaPAaplL0J24rN448pwWcrwnHmR ZxD15ZG2avOCNBMStj97lD96phzejTBFWlG6jrKLissj6rA5wnKVR8U8artAcYi5/L Lcocnrmnll3Nw== From: Mark Brown Date: Thu, 13 Jul 2023 21:06:05 +0100 Subject: [PATCH 2/3] kselftest/arm64: Add a test case for SVE VL changes with SME active MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230713-arm64-fix-sve-sme-vl-change-v1-2-129dd8611413@kernel.org> References: <20230713-arm64-fix-sve-sme-vl-change-v1-0-129dd8611413@kernel.org> In-Reply-To: <20230713-arm64-fix-sve-sme-vl-change-v1-0-129dd8611413@kernel.org> To: Catalin Marinas , Will Deacon , Shuah Khan Cc: David Spickett , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-099c9 X-Developer-Signature: v=1; a=openpgp-sha256; l=4758; i=broonie@kernel.org; h=from:subject:message-id; bh=pefhisUmRsg+2EzyXrIeOHRp6qKwWRumC3ginNtyGbg=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBksFpOcK0+T8pCWAuXL/8zAm0/WFELWdgLFEWfAMyI 3YX08uSJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZLBaTgAKCRAk1otyXVSH0Hi+B/ 9h4U7cnGc47k8jKeNn8cCML9cHNXsPXGEqUE1GNoIL2sW8X20OnE36eQbPm2qXE5xpYeQ1biIhue9g gZq7RiqwAyz4jO6vHRhjEjLLBDJkfPdNeWw0n4Ay+V4BmGAPwN8Wxwgy8NuLtis5spMxgqrZ4JaKEo pxgo5E/xFGMGc4yHoF2zCSFfibZTnfGVRp055aPQSR+vT6l7nP/riYdEBvhVreROazVrYncHmcJyTI +9GbgrNFratJ7XMUKwQrAZ1JiPtEQBJlTkVlHGCdtFMDhlTD0h2T+9J3oqopAAyHfoxNLV9lHDbGML 5daepMDk/Di9fa3vXuOOBgrXXunnvA X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We just fixed an issue where changing the SVE VL while SME was active could result in us attempting to save the streaming mode SVE vectors without any backing storage. Add a test case which provokes that issue, ideally we should also verify that the contents of ZA are unaffected by any of what we did. Note that since we need to keep streaming mode enabled we can't use any syscalls to trigger the issue, we have to sit in a loop in usersapce and hope to be preempted. The chosen numbers trigger with defconfig on all the virtual platforms for me, this won't be 100% on all systems but avoid an overcomplicated test implementation. Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/fp/vec-syscfg.c | 105 +++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/arm64/fp/vec-syscfg.c b/tools/testing/selftests/arm64/fp/vec-syscfg.c index 9bcfcdc34ee9..58ea4bde5be7 100644 --- a/tools/testing/selftests/arm64/fp/vec-syscfg.c +++ b/tools/testing/selftests/arm64/fp/vec-syscfg.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -39,9 +40,11 @@ struct vec_data { int max_vl; }; +#define VEC_SVE 0 +#define VEC_SME 1 static struct vec_data vec_data[] = { - { + [VEC_SVE] = { .name = "SVE", .hwcap_type = AT_HWCAP, .hwcap = HWCAP_SVE, @@ -51,7 +54,7 @@ static struct vec_data vec_data[] = { .prctl_set = PR_SVE_SET_VL, .default_vl_file = "/proc/sys/abi/sve_default_vector_length", }, - { + [VEC_SME] = { .name = "SME", .hwcap_type = AT_HWCAP2, .hwcap = HWCAP2_SME, @@ -644,18 +647,107 @@ static const test_type tests[] = { prctl_set_all_vqs, }; +static inline void smstart(void) +{ + asm volatile("msr S0_3_C4_C7_3, xzr"); +} + +static inline void smstart_sm(void) +{ + asm volatile("msr S0_3_C4_C3_3, xzr"); +} + +static inline void smstop(void) +{ + asm volatile("msr S0_3_C4_C6_3, xzr"); +} + + +/* + * Verify we can change the SVE vector length while SME is active and + * continue to use SME afterwards. + */ +static void change_sve_with_za(void) +{ + struct vec_data *sve_data = &vec_data[VEC_SVE]; + bool pass = true; + int ret, i; + + if (sve_data->min_vl == sve_data->max_vl) { + ksft_print_msg("Only one SVE VL supported, can't change\n"); + ksft_test_result_skip("change_sve_while_sme\n"); + return; + } + + /* Ensure we will trigger a change when we set the maximum */ + ret = prctl(sve_data->prctl_set, sve_data->min_vl); + if (ret != sve_data->min_vl) { + ksft_print_msg("Failed to set SVE VL %d: %d\n", + sve_data->min_vl, ret); + pass = false; + } + + /* Enable SM and ZA */ + smstart(); + + /* Trigger another VL change */ + ret = prctl(sve_data->prctl_set, sve_data->max_vl); + if (ret != sve_data->max_vl) { + ksft_print_msg("Failed to set SVE VL %d: %d\n", + sve_data->max_vl, ret); + pass = false; + } + + /* + * Spin for a bit with SM enabled to try to trigger another + * save/restore. We can't use syscalls without exiting + * streaming mode. + */ + for (i = 0; i < 100000000; i++) + smstart_sm(); + + /* + * TODO: Verify that ZA was preserved over the VL change and + * spin. + */ + + /* Clean up after ourselves */ + smstop(); + ret = prctl(sve_data->prctl_set, sve_data->default_vl); + if (ret != sve_data->default_vl) { + ksft_print_msg("Failed to restore SVE VL %d: %d\n", + sve_data->default_vl, ret); + pass = false; + } + + ksft_test_result(pass, "change_sve_with_za\n"); +} + +typedef void (*test_all_type)(void); + +static const struct { + const char *name; + test_all_type test; +} all_types_tests[] = { + { "change_sve_with_za", change_sve_with_za }, +}; + int main(void) { + bool all_supported = true; int i, j; ksft_print_header(); - ksft_set_plan(ARRAY_SIZE(tests) * ARRAY_SIZE(vec_data)); + ksft_set_plan(ARRAY_SIZE(tests) * ARRAY_SIZE(vec_data) + + ARRAY_SIZE(all_types_tests)); for (i = 0; i < ARRAY_SIZE(vec_data); i++) { struct vec_data *data = &vec_data[i]; unsigned long supported; supported = getauxval(data->hwcap_type) & data->hwcap; + if (!supported) + all_supported = false; for (j = 0; j < ARRAY_SIZE(tests); j++) { if (supported) @@ -666,5 +758,12 @@ int main(void) } } + for (i = 0; i < ARRAY_SIZE(all_types_tests); i++) { + if (all_supported) + all_types_tests[i].test(); + else + ksft_test_result_skip("%s\n", all_types_tests[i].name); + } + ksft_exit_pass(); } -- 2.30.2