From patchwork Thu Jul 27 23:26:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13330964 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0D6EC001DC for ; Thu, 27 Jul 2023 23:27:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231697AbjG0X1E (ORCPT ); Thu, 27 Jul 2023 19:27:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229929AbjG0X1D (ORCPT ); Thu, 27 Jul 2023 19:27:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58C6E30C5 for ; Thu, 27 Jul 2023 16:26:59 -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 D573561F7C for ; Thu, 27 Jul 2023 23:26:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6DD7C433CC; Thu, 27 Jul 2023 23:26:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690500418; bh=17quVgwOUPp97Iqg3owW8+YLOqublPdMuTjqZWkARPo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=nkjp21yMDGAvaeHDkJINc7Yk4jYHJd6TVWwyVsWQ34LHn+p66SHnj9bdZLBqXAsbM oqCSS8+IEOyZaUy+EikWmvjemOoC3hXfqqwqhN0PM31fMD12PDPaaD0ksIbsizHF2h Sh+5pwlwqqCrYs3c8/dSnZf1JG+UKI8UETFh9mNi9qxMIysiu9RUcT0N1wghmtaJme xQ/QAKgsDFivbvnypgxgHtHlZQLf6Kvhj3u5PisjaLaC3HdIpHSUYBy/xJatZnOkS1 57ybyZnMwdF8b4UKHgSCNGiPeZ+DXXS53B0MhZelrrvrJMVXbA4KyrNmb7aYypDKBu Y9BNwnyhg4Wxg== From: Mark Brown Date: Fri, 28 Jul 2023 00:26:12 +0100 Subject: [PATCH v4 1/6] kselftest/arm64: Exit streaming mode after collecting signal context MIME-Version: 1.0 Message-Id: <20230728-arm64-signal-memcpy-fix-v4-1-0c1290db5d46@kernel.org> References: <20230728-arm64-signal-memcpy-fix-v4-0-0c1290db5d46@kernel.org> In-Reply-To: <20230728-arm64-signal-memcpy-fix-v4-0-0c1290db5d46@kernel.org> To: Catalin Marinas , Will Deacon , Shuah Khan , Arnaldo Carvalho de Melo Cc: linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-099c9 X-Developer-Signature: v=1; a=openpgp-sha256; l=3033; i=broonie@kernel.org; h=from:subject:message-id; bh=17quVgwOUPp97Iqg3owW8+YLOqublPdMuTjqZWkARPo=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBkwv05VrGqW153ETqB2RJgnxvIF7+LzYv/IlYjhZ6Z s8dnsWSJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZML9OQAKCRAk1otyXVSH0MWiB/ 0WLVRgq5i6hfMb4hl9vOiSFuzNvjGpyAaNmITZMvRqoaXQqNMCrVQXbcmW8BJhnEbdXq9f689krKZJ dWBcisXyxaUCfUh4TwQdOByvBjuIPRX88f9M3hgscq420v63Zdr3RTkmaFoXOFqRFI5dr0BDnveseH YSUtg6kEvpBEtEZR2rCbA3vqBGOtZLnQrf93RrUSrNA384N8IKOxSpnRauUiYRZekWZgUNOREZU/ej TlOl2k1QVVsXVM7+oRFrsP1rkJd1fUzqgRE2UfCGsk8KkDJbKp2VOribAg3KwJCEfkNZRdr5rYixX0 liQAB9Bj+61qzyJAfNPJlOj0hSZhXm X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org When we collect a signal context with one of the SME modes enabled we will have enabled that mode behind the compiler and libc's back so they may issue some instructions not valid in streaming mode, causing spurious failures. For the code prior to issuing the BRK to trigger signal handling we need to stay in streaming mode if we were already there since that's a part of the signal context the caller is trying to collect. Unfortunately this code includes a memset() which is likely to be heavily optimised and is likely to use FP instructions incompatible with streaming mode. We can avoid this happening by open coding the memset(), inserting a volatile assembly statement to avoid the compiler recognising what's being done and doing something in optimisation. This code is not performance critical so the inefficiency should not be an issue. After collecting the context we can simply exit streaming mode, avoiding these issues. Use a full SMSTOP for safety to prevent any issues appearing with ZA. Reported-by: Will Deacon Signed-off-by: Mark Brown --- .../selftests/arm64/signal/test_signals_utils.h | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/arm64/signal/test_signals_utils.h b/tools/testing/selftests/arm64/signal/test_signals_utils.h index 222093f51b67..c7f5627171dd 100644 --- a/tools/testing/selftests/arm64/signal/test_signals_utils.h +++ b/tools/testing/selftests/arm64/signal/test_signals_utils.h @@ -60,13 +60,25 @@ static __always_inline bool get_current_context(struct tdescr *td, size_t dest_sz) { static volatile bool seen_already; + int i; + char *uc = (char *)dest_uc; assert(td && dest_uc); /* it's a genuine invocation..reinit */ seen_already = 0; td->live_uc_valid = 0; td->live_sz = dest_sz; - memset(dest_uc, 0x00, td->live_sz); + + /* + * This is a memset() but we don't want the compiler to + * optimise it into either instructions or a library call + * which might be incompatible with streaming mode. + */ + for (i = 0; i < td->live_sz; i++) { + uc[i] = 0; + __asm__ ("" : "=r" (uc[i]) : "0" (uc[i])); + } + td->live_uc = dest_uc; /* * Grab ucontext_t triggering a SIGTRAP. @@ -103,6 +115,17 @@ static __always_inline bool get_current_context(struct tdescr *td, : : "memory"); + /* + * If we were grabbing a streaming mode context then we may + * have entered streaming mode behind the system's back and + * libc or compiler generated code might decide to do + * something invalid in streaming mode, or potentially even + * the state of ZA. Issue a SMSTOP to exit both now we have + * grabbed the state. + */ + if (td->feats_supported & FEAT_SME) + asm volatile("msr S0_3_C4_C6_3, xzr"); + /* * If we get here with seen_already==1 it implies the td->live_uc * context has been used to get back here....this probably means From patchwork Thu Jul 27 23:26:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13330963 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08B90C41513 for ; Thu, 27 Jul 2023 23:27:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229929AbjG0X1F (ORCPT ); Thu, 27 Jul 2023 19:27:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231605AbjG0X1D (ORCPT ); Thu, 27 Jul 2023 19:27:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2196130CD for ; Thu, 27 Jul 2023 16:27:01 -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 B40E161F7C for ; Thu, 27 Jul 2023 23:27:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4194C433CB; Thu, 27 Jul 2023 23:26:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690500420; bh=jXMPykm8Sa7SRlmo5xtzHOIlSIk5Hq+qJ6dIW9lIji4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gM52nhQMToDrNZbOQX4DUuuR/CzhvuP3nCm0/uSOtAuHCbgUImUxjsue5HeACy+NA 6G4nByfh3BVo/4HM7b8CEgr72bc9l8B7oFWMmX3H7fcHpf12i7HJwPCTeRlwLt9Oi0 HXlUSMJr/Lh+KYjwnO82u2aPL5VH/kplEMlS7nTe+7je0oyee8oGDDEh8djNIoqp1p rhp8n0vnPkr7IcY06BWpY1R2yFiVVk+TyaSpARzLoKBbqNxgUO+yAttnnePy5RWyiN JKNBjlwz0wzwrpslxSm33c8gjaNgVT8Aqq5LbHO9yqHPFVNv9SkF9rjY5uuyr9t6kF r7NVgg9ZAUjdg== From: Mark Brown Date: Fri, 28 Jul 2023 00:26:13 +0100 Subject: [PATCH v4 2/6] tools compiler.h: Add OPTIMIZER_HIDE_VAR() MIME-Version: 1.0 Message-Id: <20230728-arm64-signal-memcpy-fix-v4-2-0c1290db5d46@kernel.org> References: <20230728-arm64-signal-memcpy-fix-v4-0-0c1290db5d46@kernel.org> In-Reply-To: <20230728-arm64-signal-memcpy-fix-v4-0-0c1290db5d46@kernel.org> To: Catalin Marinas , Will Deacon , Shuah Khan , Arnaldo Carvalho de Melo Cc: linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-099c9 X-Developer-Signature: v=1; a=openpgp-sha256; l=845; i=broonie@kernel.org; h=from:subject:message-id; bh=jXMPykm8Sa7SRlmo5xtzHOIlSIk5Hq+qJ6dIW9lIji4=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBkwv063LfMOVtDu/PC70CFOI6dnptcjxsMx0BeCTqD G+2FKZKJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZML9OgAKCRAk1otyXVSH0BeqB/ 9St4zvcVA9AM5uZQ6iXsgGbrRYpAQ2GF9jDM2QSQZjfgaqcwhNuH8s7zUG1EfjTnUS+fkklj0iISTF 4s/SVoqGco4pKmKSsQaTx2t72WX1P2klXpJosUBr7AJsmezlqabHHc7vXcwIsHkabcALJqHgQUJ/e9 6Sw2X36LvFHp4Qua+RzWH96L5GV6nUNcftVPp5Gx1UnIBKJ+2+w1GCoX8scYJXYTjgxQ1T78sVH27n P4VSH757Cj82weBwXP5Vsv8Dy5m9zGcFjPbiHANEetNZWoSVZx3uaPP4poqby4sdLk6fsqLBuW/ek9 YA+RfSx0/GXLhU5yeezLdoBmc81JK2 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Port over the definition of OPTIMIZER_HIDE_VAR() so we can use it in kselftests. Signed-off-by: Mark Brown --- tools/include/linux/compiler.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h index 9d36c8ce1fe7..f75cced41d59 100644 --- a/tools/include/linux/compiler.h +++ b/tools/include/linux/compiler.h @@ -190,4 +190,10 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s #define ___PASTE(a, b) a##b #define __PASTE(a, b) ___PASTE(a, b) +#ifndef OPTIMIZER_HIDE_VAR +/* Make the optimizer believe the variable can be manipulated arbitrarily. */ +#define OPTIMIZER_HIDE_VAR(var) \ + __asm__ ("" : "=r" (var) : "0" (var)) +#endif + #endif /* _TOOLS_LINUX_COMPILER_H */ From patchwork Thu Jul 27 23:26:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13330967 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1122EB64DD for ; Thu, 27 Jul 2023 23:27:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231704AbjG0X1F (ORCPT ); Thu, 27 Jul 2023 19:27:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231618AbjG0X1E (ORCPT ); Thu, 27 Jul 2023 19:27:04 -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 007EA30D2 for ; Thu, 27 Jul 2023 16:27:02 -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 8A69161F84 for ; Thu, 27 Jul 2023 23:27:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91005C433C9; Thu, 27 Jul 2023 23:27:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690500422; bh=Znm9gRTwsFwQfwD1M+msy3+6gP9lF4h25ZTmsNIMG+8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=WXvhCx3tVGtpH7KM3WsPf+wJKi5tzA8AnxDAawXXSng2MmFBYN0/MOXK0hpTf1zmq 4OHjaNBIFFH3UAccIjni55fGQFBVuTPLXT+t3urAataGB7cePSb0kFKv2TP1GatcaG aPzOQovlIspJwoFZqRTLmSsj5s+6MiFqj4c7yeALO8SVg9C13lrx6WgmWZvDwCBXbu Boz2mn5Q0wKvEvWiUTD3dL9pEKqA0/mgQypPE/e5U0CEQjYle5JI7JgcLPD2AMcRU1 J3ManrUKmRAZnIY9U3lhMr893MAvaOM+1JoBgusZacBW5rkYCQU4MYuyParCK8q1z3 mwEhAlv4/o42Q== From: Mark Brown Date: Fri, 28 Jul 2023 00:26:14 +0100 Subject: [PATCH v4 3/6] tools include: Add some common function attributes MIME-Version: 1.0 Message-Id: <20230728-arm64-signal-memcpy-fix-v4-3-0c1290db5d46@kernel.org> References: <20230728-arm64-signal-memcpy-fix-v4-0-0c1290db5d46@kernel.org> In-Reply-To: <20230728-arm64-signal-memcpy-fix-v4-0-0c1290db5d46@kernel.org> To: Catalin Marinas , Will Deacon , Shuah Khan , Arnaldo Carvalho de Melo Cc: linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-099c9 X-Developer-Signature: v=1; a=openpgp-sha256; l=895; i=broonie@kernel.org; h=from:subject:message-id; bh=Znm9gRTwsFwQfwD1M+msy3+6gP9lF4h25ZTmsNIMG+8=; b=owGbwMvMwMWocq27KDak/QLjabUkhpRDf60vB71y215inrJV+E2EvtuMndOPcufzzNzl5MwV+Hzv Vf5vnYzGLAyMXAyyYoosa59lrEoPl9g6/9H8VzCDWJlApjBwcQrARFqY2f/X7OoRrrAS0kqpYioQzq nK0o7ktSu1PC/Nt2ihyavyes2Vfp4fb32arL/5T5mD5+M//xgaNiUeCk2XuvaHvccveOu1Z3OdzT46 a4r0KKaoWcpxNFucLtg/SUw1wK+3kmtGjGKsr8f/CR1GveLSq26zehhIHHTMDP2w0apD/OhHA9Wzsa U7/kVMzzHdqHnO91v3ul/PbdbV8i+Qlrp59vyrHas25S+Kcc1/vKPuccdv16k+tuazJfonf7bn6spO DnRya1z3pCH2UsqpzR4nKr6fl3OpNvz6cut0pntr1Vh9k2t3HWF0ZU8ICRM6Jc7UweD2OWfqr8aFV2 /qN0ruOfzjdOr/PBXpYjaHJAdbAA== X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org We don't have definitions of __always_unused or __noreturn in the tools version of compiler.h, add them so we can use them in kselftests. Signed-off-by: Mark Brown --- tools/include/linux/compiler.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h index f75cced41d59..1684216e826a 100644 --- a/tools/include/linux/compiler.h +++ b/tools/include/linux/compiler.h @@ -42,6 +42,18 @@ # define __always_inline inline __attribute__((always_inline)) #endif +#ifndef __always_unused +#define __always_unused __attribute__((__unused__)) +#endif + +#ifndef __noreturn +#define __noreturn __attribute__((__noreturn__)) +#endif + +#ifndef unreachable +#define unreachable() __builtin_unreachable() +#endif + #ifndef noinline #define noinline #endif From patchwork Thu Jul 27 23:26:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13330965 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB7C2C04E69 for ; Thu, 27 Jul 2023 23:27:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229573AbjG0X1H (ORCPT ); Thu, 27 Jul 2023 19:27:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231703AbjG0X1F (ORCPT ); Thu, 27 Jul 2023 19:27:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3A862D40 for ; Thu, 27 Jul 2023 16:27:04 -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 62E9561F89 for ; Thu, 27 Jul 2023 23:27:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68E1BC433C7; Thu, 27 Jul 2023 23:27:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690500423; bh=3Twxt+ztmPtVD0NHowFG7vKtvYRRWttH91DBpHBezI0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZewPS2cTsNisFWlRk/n/RKJhsrj9H3CELspdWuitrGRnprnemAQxNUSQXdescoYYG jKRJlkTsK+EJjc+EnyVmoyMCUdPouf+Y6I36UAwUyy+xO5nnGFmP4AtIkgk6pjGhwK +5TSOInCLFslFOfSzycjHN750UwrZHmjqa0S5Yjaw6bXdPldwogORaOMsI5zvWydNn +qQNSZugsczBIOczeOtC2Nqz1X6osFou49tdFWb/YblxaWJedI7sHntQo0kB+7Iy4I sDQPpIZ3a/iWrb0xvF6qydxKgmFBDEej0l6x+VQ/8TWrfxUNhOG1Um13FlFsZdBYld pzJPh/3jCBjEw== From: Mark Brown Date: Fri, 28 Jul 2023 00:26:15 +0100 Subject: [PATCH v4 4/6] kselftest/arm64: Make the tools/include headers available MIME-Version: 1.0 Message-Id: <20230728-arm64-signal-memcpy-fix-v4-4-0c1290db5d46@kernel.org> References: <20230728-arm64-signal-memcpy-fix-v4-0-0c1290db5d46@kernel.org> In-Reply-To: <20230728-arm64-signal-memcpy-fix-v4-0-0c1290db5d46@kernel.org> To: Catalin Marinas , Will Deacon , Shuah Khan , Arnaldo Carvalho de Melo Cc: linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-099c9 X-Developer-Signature: v=1; a=openpgp-sha256; l=679; i=broonie@kernel.org; h=from:subject:message-id; bh=3Twxt+ztmPtVD0NHowFG7vKtvYRRWttH91DBpHBezI0=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBkwv08T3Xmn3L+KDEN17Ziv1NJDSuu1hCzTrzS5/3j 8N2YXtOJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZML9PAAKCRAk1otyXVSH0CiJB/ 9ZvL1M+upvI8SckwQ3t7MnnK28cyuCGBUjdWIBKplPv1nlemi4c/pqZfO6zlTC5YASi3j02mMbST3e eKVB54k497BtzlMyMf4ey3HzQbBKKU+GRBrBzY3WdaZ+M7XZRCSlS04GSM+CKu4pqkB6Or4LQ1Su6l kMVBEsMXvXwSqeRuYvi0fM+rW6/5VUzPiYbG2k9pzN7eE0TEi4hA2cWXbf8T3tStrldONWLT0M6Q9y i8uiiYoBpfktwjLuI2k+uwa7uqggY5WrErTY7CPIedU62xatcELrugd7kx3AjlrVDKSnfduMszGPB/ hfUqp5TCNNwTtyHjZGPyOeow9ReB0R X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Make the generic tools/include headers available to the arm64 selftests so we can reduce some duplication. Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/arm64/Makefile b/tools/testing/selftests/arm64/Makefile index ace8b67fb22d..28b93cab8c0d 100644 --- a/tools/testing/selftests/arm64/Makefile +++ b/tools/testing/selftests/arm64/Makefile @@ -19,6 +19,8 @@ CFLAGS += -I$(top_srcdir)/tools/testing/selftests/ CFLAGS += $(KHDR_INCLUDES) +CFLAGS += -I$(top_srcdir)/tools/include + export CFLAGS export top_srcdir From patchwork Thu Jul 27 23:26:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13330968 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28632C001DC for ; Thu, 27 Jul 2023 23:27:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231703AbjG0X1I (ORCPT ); Thu, 27 Jul 2023 19:27:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231618AbjG0X1H (ORCPT ); Thu, 27 Jul 2023 19:27:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFDF62D40 for ; Thu, 27 Jul 2023 16:27:06 -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 5FBEF61F8C for ; Thu, 27 Jul 2023 23:27:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46960C433CC; Thu, 27 Jul 2023 23:27:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690500425; bh=U9eF72eZ37CI1cE+xa8X28h+BbO8qk9SjWJn/oLYilE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OrYEkASthgU4BOmTQSZsyI6Zu2kEP+1oN+V2Qyabjpcv3eLyHdT8vXXL5m9LNwtGv hjVsCWRewoRwjCgX0zCLlyLfVHd+8zyLW6zjx9fzEasiGhGmBXNY+3h3xBHG465CI+ Ks9Lf1Vsi5IbwsSrHwNF3flnjGFS0u4dGN9KYZzDjKZj/Niexr7yS4ofqROTmGYlq+ HZBm17eGJgXoa7joDPunZgw30CjYa3FFqA5yuFQiusdJ9dL9G8/YBqmxk0rK1+cscY W0I3QfkL0mCWFk0zzbBT9mhVuN3A6BNoK/Hx1o1SMiJz7cfRj2t+FmnmeVFKyD8CA0 BU6U8QIHsGBuw== From: Mark Brown Date: Fri, 28 Jul 2023 00:26:16 +0100 Subject: [PATCH v4 5/6] kselftest/arm64: Use shared OPTIMZER_HIDE_VAR() definiton MIME-Version: 1.0 Message-Id: <20230728-arm64-signal-memcpy-fix-v4-5-0c1290db5d46@kernel.org> References: <20230728-arm64-signal-memcpy-fix-v4-0-0c1290db5d46@kernel.org> In-Reply-To: <20230728-arm64-signal-memcpy-fix-v4-0-0c1290db5d46@kernel.org> To: Catalin Marinas , Will Deacon , Shuah Khan , Arnaldo Carvalho de Melo Cc: linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-099c9 X-Developer-Signature: v=1; a=openpgp-sha256; l=1124; i=broonie@kernel.org; h=from:subject:message-id; bh=U9eF72eZ37CI1cE+xa8X28h+BbO8qk9SjWJn/oLYilE=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBkwv09X8Mjn1yqAaOEMjsKIen70RXP0QJW8nIpTkh3 lnMxM1qJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZML9PQAKCRAk1otyXVSH0OI2B/ 9hXA4a3MhVplF/KUp49gZNZsDo+mb986YfPqBSVFgJXJR84jb8JBGk33xkR+fP78xIbq1x+YlH3Cor Trtjoa9QCbFbP5CpMW81jl7+0MRED48409wD74jGIxqWDnK9qEtdc+iZGmnC8u9EWP542zl1qZM4jT ZT3uWzmROX6NM1HUHTqy2vu6zsJtG6Gphkx5B0Xi437PUT1HT9deIP1RzLjg7Nih13uwVu1yeWM3aZ qUTXbOdZyXgfv32g2tOrXccCWBLmvRU4mD/biSzv4fH1f6SvqDospwE2+RYxtwMbd46t1i1ZYzjAnD jHeXqfxXILhpxL8v413Cr7UILUrRJe X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org We had open coded the definition of OPTIMIZER_HIDE_VAR() as a fix but now that we have the generic tools/include available and that has had a definition of OPTIMIZER_HIDE_VAR() we can switch to the define. Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/signal/test_signals_utils.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/arm64/signal/test_signals_utils.h b/tools/testing/selftests/arm64/signal/test_signals_utils.h index c7f5627171dd..762c8fe9c54a 100644 --- a/tools/testing/selftests/arm64/signal/test_signals_utils.h +++ b/tools/testing/selftests/arm64/signal/test_signals_utils.h @@ -8,6 +8,8 @@ #include #include +#include + #include "test_signals.h" int test_init(struct tdescr *td); @@ -76,7 +78,7 @@ static __always_inline bool get_current_context(struct tdescr *td, */ for (i = 0; i < td->live_sz; i++) { uc[i] = 0; - __asm__ ("" : "=r" (uc[i]) : "0" (uc[i])); + OPTIMIZER_HIDE_VAR(uc[0]); } td->live_uc = dest_uc; From patchwork Thu Jul 27 23:26:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13330969 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFD95EB64DD for ; Thu, 27 Jul 2023 23:27:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231741AbjG0X1L (ORCPT ); Thu, 27 Jul 2023 19:27:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231618AbjG0X1K (ORCPT ); Thu, 27 Jul 2023 19:27:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68BC62D40 for ; Thu, 27 Jul 2023 16:27:09 -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 07BBC61F8F for ; Thu, 27 Jul 2023 23:27:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F0ADC43395; Thu, 27 Jul 2023 23:27:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690500428; bh=9k3w2GBcBAqmmGMPcYLsGGGPHhPVChgtpgxlIPZIOJc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=E0t01Qv+n6eKa+pxbIMDfoirGbEwAEgWccJu5vrJYO2FEgtdWqw47uCHBxvhGNGNj Q/JYRe8HhOcXyS9FfQqEjnqABMLh39l+SR1JH40f9IZN9/D9VjBn3AdQ+34booim9c 9uTGIW0mP8Uw1C0e5Wsz2wXKVhFnYe0ITOOQ+4qsmQGlXYIwoNWFah0Ia1zn9cHP1d UoM+YS/Y6jFzeGxOCQWlwzcyPIMgTcPuonNfG/htvQqm3JZL4Zuw3TltJ7wbRiTCK/ OjH+xIm8ZDtkEK061340hDNO/nzKfwddY5d+C0tdEOgSY2NeT6I0APhTof/NLfC7Gg Wpi4GsJmvvWzw== From: Mark Brown Date: Fri, 28 Jul 2023 00:26:17 +0100 Subject: [PATCH v4 6/6] kselftest/arm64: Use the tools/include compiler.h rather than our own MIME-Version: 1.0 Message-Id: <20230728-arm64-signal-memcpy-fix-v4-6-0c1290db5d46@kernel.org> References: <20230728-arm64-signal-memcpy-fix-v4-0-0c1290db5d46@kernel.org> In-Reply-To: <20230728-arm64-signal-memcpy-fix-v4-0-0c1290db5d46@kernel.org> To: Catalin Marinas , Will Deacon , Shuah Khan , Arnaldo Carvalho de Melo Cc: linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-099c9 X-Developer-Signature: v=1; a=openpgp-sha256; l=3009; i=broonie@kernel.org; h=from:subject:message-id; bh=9k3w2GBcBAqmmGMPcYLsGGGPHhPVChgtpgxlIPZIOJc=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBkwv09LNwFQCF4CRRL0scso9UK+3zOt7IV4CbSxiXS 1PHiYZ+JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZML9PQAKCRAk1otyXVSH0JSjB/ 40eJ999zzsbI5ThnpILemnJjHqCswwKHRtduJHlB0FLL12fQX4/zXt7TK9eK8/uiLzsWi//nwQObtt WsamOENoa3zfgCaBFzj4j+F/sFkjN0mr/t56ZzINLHZhWO6rSzVbzD5a+9C3n4rzAQhHdKFxRGksj0 1aH020PnCSz1I43wDX8UoFB86XkxMOKERLAOkRy8rROErcI6XJ8ktqw7GDmGJvGjKlzHmEx8n1oDm0 l9uFG/Kp4Fk4A3JWK4I7XVe3gIZOiJtI2SV74q7GqJV6lhu61gqgIWmef6ZWRHg585uGx93nE+ChDF +VYwf+d1XSdaMaRA8rtxEZCLX7FuJp X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The BTI test program started life as standalone programs outside the kselftest suite so provided it's own compiler.h. Now that we have updated the tools/include compiler.h to have all the definitions that we are using and the arm64 selftsets pull in tools/includes let's drop our custom version. __unreachable() is named unreachable() there requiring an update in the code. Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/bti/compiler.h | 21 --------------------- tools/testing/selftests/arm64/bti/system.c | 4 +--- tools/testing/selftests/arm64/bti/system.h | 4 ++-- tools/testing/selftests/arm64/bti/test.c | 1 - 4 files changed, 3 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/arm64/bti/compiler.h b/tools/testing/selftests/arm64/bti/compiler.h deleted file mode 100644 index ebb6204f447a..000000000000 --- a/tools/testing/selftests/arm64/bti/compiler.h +++ /dev/null @@ -1,21 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (C) 2019 Arm Limited - * Original author: Dave Martin - */ - -#ifndef COMPILER_H -#define COMPILER_H - -#define __always_unused __attribute__((__unused__)) -#define __noreturn __attribute__((__noreturn__)) -#define __unreachable() __builtin_unreachable() - -/* curse(e) has value e, but the compiler cannot assume so */ -#define curse(e) ({ \ - __typeof__(e) __curse_e = (e); \ - asm ("" : "+r" (__curse_e)); \ - __curse_e; \ -}) - -#endif /* ! COMPILER_H */ diff --git a/tools/testing/selftests/arm64/bti/system.c b/tools/testing/selftests/arm64/bti/system.c index 6385d8d4973b..93d772b00bfe 100644 --- a/tools/testing/selftests/arm64/bti/system.c +++ b/tools/testing/selftests/arm64/bti/system.c @@ -8,12 +8,10 @@ #include -#include "compiler.h" - void __noreturn exit(int n) { syscall(__NR_exit, n); - __unreachable(); + unreachable(); } ssize_t write(int fd, const void *buf, size_t size) diff --git a/tools/testing/selftests/arm64/bti/system.h b/tools/testing/selftests/arm64/bti/system.h index aca118589705..2e9ee1284a0c 100644 --- a/tools/testing/selftests/arm64/bti/system.h +++ b/tools/testing/selftests/arm64/bti/system.h @@ -14,12 +14,12 @@ typedef __kernel_size_t size_t; typedef __kernel_ssize_t ssize_t; #include +#include + #include #include #include -#include "compiler.h" - long syscall(int nr, ...); void __noreturn exit(int n); diff --git a/tools/testing/selftests/arm64/bti/test.c b/tools/testing/selftests/arm64/bti/test.c index 2cd8dcee5aec..28a8e8a28a84 100644 --- a/tools/testing/selftests/arm64/bti/test.c +++ b/tools/testing/selftests/arm64/bti/test.c @@ -17,7 +17,6 @@ typedef struct ucontext ucontext_t; #include "btitest.h" -#include "compiler.h" #include "signal.h" #define EXPECTED_TESTS 18