From patchwork Tue Mar 5 22:18:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Linton X-Patchwork-Id: 13583060 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 246D8C54798 for ; Tue, 5 Mar 2024 22:18:56 +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:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=NYceC5kzQY0VDS8LaWBR7FaxmdFDdzHhlKsa4hPi0jQ=; b=iHlpaNpVTXWwot kbSq7XgBeTo63A7Pr5W3aJPs26OPSddA8T3kiegfIdrI4Mf22xeMmYmzUqKKLbUfk5qDUp+m0Ihu4 ea13Tuibkdwdnc0G6sIf2viHFd9gshPgAKsCrGuhFlzQjlkMSM4oS02l/QvvblGJgFmlLL0JOoLTn N8T9JQlJsID7zGJOu37h9BS+pjbEBicSSIlJkqFGM7utx4T552jIYSJcR7D9JqFJbmb62CXYCeU92 PvAtcB36xIOU7dl9cTxqCNwOInuOiyRGlgLTb714JFqycBfHmIzd86GK6F86NrKijcKFj31oa6Ba3 rohYcYnPsVrFdz+E95Rg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rhd7Q-0000000FQq3-0Z1m; Tue, 05 Mar 2024 22:18:40 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rhd7M-0000000FQmW-0GmC for linux-arm-kernel@lists.infradead.org; Tue, 05 Mar 2024 22:18:37 +0000 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 E73031FB; Tue, 5 Mar 2024 14:19:05 -0800 (PST) Received: from mammon-tx2.austin.arm.com (mammon-tx2.austin.arm.com [10.118.28.65]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 990143F738; Tue, 5 Mar 2024 14:18:28 -0800 (PST) From: Jeremy Linton To: linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, will@kernel.org, keescook@chromium.org, Jason@zx2c4.com, gustavoars@kernel.org, mark.rutland@arm.com, rostedt@goodmis.org, arnd@arndb.de, broonie@kernel.org, guohui@uniontech.com, Manoj.Iyer@arm.com, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Jeremy Linton Subject: [PATCH 0/1] Bring kstack randomized perf closer to unrandomized Date: Tue, 5 Mar 2024 16:18:23 -0600 Message-ID: <20240305221824.3300322-1-jeremy.linton@arm.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240305_141836_171956_4227C90F X-CRM114-Status: UNSURE ( 8.26 ) X-CRM114-Notice: Please train this message. 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently with kstack randomization there is somewhere on the order of 5x worse variation in response latencies vs unrandomized syscalls. This is down from ~10x on pre 6.2 kernels where the RNG reseeding was moved out of the syscall path, but get_random_uXX() still contains a fair amount of additional global state manipulation which is problematic. So, lets replace the full get_random_u16 in the syscall path with prandom_u32_state(). This also has the advantage of bringing the randomized and unrandomized overall syscall performace much closer together. Although in the syscall path, prandom_u32_state() remains measurably worse than other architectures relying on non-random functions (cycle counters) with respect to perf/latency measurements. By comparison, the algorithm presented in the RFC which had basically no impact given recent OoO cores are able to hide all of the overhead from the the handful of additional instructions. I'm still looking for suggestions reseeding prandom_u32_state() if needed or improving the performace of get_random_u16. so consider this somewhate more than an RFC and maybe less of a full patch request. RFC->V1: Replace custom inline RNG with prandom_u32_state Jeremy Linton (1): arm64: syscall: Direct PRNG kstack randomization arch/arm64/kernel/syscall.c | 42 ++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-)