Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp712349lqs; Tue, 5 Mar 2024 14:18:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWLF6cH7h/APW4DBK5MyMIyp36T8NE91otWV7NN9jhsCLWLwio9qPQ2bbulRQedhIT4/0lFb8iWZ1Y3FdN62x3Tgfe8ND6Sv9/noAy55w== X-Google-Smtp-Source: AGHT+IHpF584AKv7Kddf4SaeHqBTmwQGgqG56LocD0anh5qEtBgotMNmkMD6+tySRPoiuQqeWH/w X-Received: by 2002:aa7:da93:0:b0:567:c0ac:b31d with SMTP id q19-20020aa7da93000000b00567c0acb31dmr1092663eds.37.1709677133129; Tue, 05 Mar 2024 14:18:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709677133; cv=pass; d=google.com; s=arc-20160816; b=sUw+tqtl+hqSpNlT/FouolUoTolDcHBGcM/tSzJUHhm4yLuaOgM7CI3Gnz2+1NvV4A F2ghvFK83i4MuRROn8W+BU2FoziNspCbUUPFoUJMtOaQMtdwKXKk8gF4NMDoEZlBqe9g ZDFsMwCvAgf2VFR3XyILUexFZg3t7l9IVkjDhF0ygf82TW3iTs4EQod0xVd1+NFWkrbO ewBGjo+00MPQeTAnyMQPVb33vgOD4ADOBRyKD8SpjNdIVcRKSjvUeqt/DONQqb9q0FWf Puk+AKCP5EpTF7I2CRCdi7NWbaldQ+KG2es03wFL03Z2tMVhtxsL77bJyfLXcb6+ck16 t/Vg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=Nu/tNKa3/JvRTvJEzCkvd8pbDvMbKs1ppWS4VNdFEoM=; fh=R9kHZPkuXwk3WQbWYRnY8mQ8SY5t8rBTAKjPpxW1S/E=; b=iX3C6iNTaNyZlEV81jzcwLvOs0ljZCrnVDuuQajM/AeXxheMc7hYrDbZo0yoA016yW vlQ5LRiuN7PramdJmXdQ+4HP9OGNHDfvWwDGkMTwvNqHqKOhMwhsAnBaYOi8njlh0yjJ OiE/gbdQeUxGNsuhmEg709pfDkW+bdvAmWHOcHUDM9ADkvedfwtu94MlRxcDxaKZa+xF szs8VeScYHR2fq1PaFI/bAZtIPP/T+HXLvYwz6l9XKVVoQci7JqnHL/IcjA8C3lrIZh9 0rq+YAAwDgv4LgKwEbDzgl3c8/t0Xx4HIYq9Gp8k7lHGb5+S5P+L36lgvK+z2yviH5tM pBmg==; 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-93039-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93039-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v3-20020a056402348300b005640c092a86si5506588edc.87.2024.03.05.14.18.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 14:18:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-93039-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-93039-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93039-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 am.mirrors.kernel.org (Postfix) with ESMTPS id D51401F240B5 for ; Tue, 5 Mar 2024 22:18:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B8FF12D1FD; Tue, 5 Mar 2024 22:18:38 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A62E118E29; Tue, 5 Mar 2024 22:18:35 +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=1709677117; cv=none; b=f9d9Di1UOzjOCpj1QgwaK0pKMNvcfZKUvEKK/y8Gb+lCMCYfvYv+wZs0OQkVW/T6M0B1WacO+nWJEgd1ubSpHmLBKtSNFr6MxceB5Qti+FZYgGk7iNuvGk7yhNcx5ccYjGsGoMAFUp6DhEW1vrBJqYSwoeyQ8Jk7bT+gEXgrrr0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709677117; c=relaxed/simple; bh=rOMbBrw6dKCy0QI69rgKxwVJpe5Z9XH8c/ETM0PM1tM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=f/J33RPTTNB1NzxVPtw4QDnqNDZkyPV12rZrJuH4xaeCyymzxjg9zSTyT29VMTuDqL1wQOBJVW2YM1c5oo+Z9ppTyGdrkUj38z4Wn+BXm35x9f7VP4ifmem8SiX0s9x9akdI2YMVi15LMdTUgV3IEVqkvItJtSiYTFoQ6hsOvPE= 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 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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(-) -- 2.43.0