From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D4EF5EB64DD for ; Thu, 20 Jul 2023 10:31:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YXG47SgWKcbyu8t9ISoUroEQ2iADgHToMTOqbLb6c50=; b=qCh7cAVHi3FLr9 xL8NWE9JxFsrrJUM7181r76kqKVw2X6qlf7fQskSQqG41/4jaipa7j4EVuTpCdZqErUji71sJfZwN YWON5DVHrtGZaDBs7BhhUakry/H3sRpyUGojan8RZihTPV69+NWmp5Yn/ctzNpBqe+9qTCwnPNXot mc6hJhMf8P7a+yBkBeQUqoPL0oFSk1wIgaJdqQUZ/PKw1EvS+MvGawf7+yyn37JdB5LuNgGXhK9TM d3RmLUF0dEDklHGmoEB/W9i1/BmDiE4sAmnqvcQu3SPYp1BWkvnrSe07VZjk8a7uaKf7lwbUBzbw3 WQCowjeSU7VUrKCYUdHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qMQwN-00Aq6A-16; Thu, 20 Jul 2023 10:31:23 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qMQwL-00Aq3o-0Y for linux-arm-kernel@lists.infradead.org; Thu, 20 Jul 2023 10:31:22 +0000 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 7195E61A05; Thu, 20 Jul 2023 10:31:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8535C433C7; Thu, 20 Jul 2023 10:31:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689849078; bh=J75VgyCyMOY4uCVubQ02MoxyKNXvNaiEKCHSA0oocXs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IYhuewxIOIozhxLyaQzjLN74pujj/a3exBH06uQTom5IvOVid8aDiTflLeZzm5uHg 08243Z/whH+358t36ORt45RWh+c+Y51XBopl47o8zMbzsIeH/g13QUYcMNSbZMNu8E BUgHDYOh6e8F7lRGY3GkYdw6KCsCg0TfKVbO1ZMwNsgWWeR7hBD+Nn+/lKcN0sQlMW mK9heIEdJxoKkG7YdmJD+nWaNPg0QhK5Q+nvFJl5xqgTWk2aadpt5/MkH1TPndrUbr m/MtFlVmajFkz7AXXLeo+FveOvVRJq9gRfsldq+wK0HNdrpVrsfDlQuc+epFPxoOc0 BzRPPehhzfDPw== Date: Thu, 20 Jul 2023 11:31:13 +0100 From: Will Deacon To: Mark Brown Cc: Catalin Marinas , Shuah Khan , linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v2] kselftest/arm64: Exit streaming mode after collecting signal context Message-ID: <20230720103113.GA11034@willie-the-truck> References: <20230712-arm64-signal-memcpy-fix-v2-1-494f7025caf6@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230712-arm64-signal-memcpy-fix-v2-1-494f7025caf6@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230720_033121_320706_04D9008C X-CRM114-Status: GOOD ( 27.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Mark, On Wed, Jul 12, 2023 at 12:02:30PM +0100, Mark Brown wrote: > 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. Thanks for looking at this. Comments inline. > diff --git a/tools/testing/selftests/arm64/signal/test_signals_utils.h b/tools/testing/selftests/arm64/signal/test_signals_utils.h > index 222093f51b67..db28409fd44b 100644 > --- a/tools/testing/selftests/arm64/signal/test_signals_utils.h > +++ b/tools/testing/selftests/arm64/signal/test_signals_utils.h > @@ -60,13 +60,28 @@ 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++) { > + asm volatile("nop" > + : "+m" (*dest_uc) > + : > + : "memory"); I don't think it's save to use "+m" here, since the compiler can assume that the address is used exactly once in the asm. If a post-indexed addressing mode is generated, then you can end up with register corruption. Stepping back, why not use either barrier() or OPTIMIZER_HIDE_VAR() instead? The most robust fix would be to write all of the streaming mode code in asm, but I can appreciate that's a tonne of work for a testcase. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel