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 B55A5C433EF for ; Mon, 13 Dec 2021 22:34:57 +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=iVv1kwQ4QZl+0tEKMJsj6xoJUxCmFskgYU8gm4uzEp0=; b=EYPbLmtmPKVtsR tNBtpwo0UhPoDuU4e6vqvtyMTe5GEQMtnbZ4jgcVISdDR5yeDdE5rVmfT/mkAL8XCVMegh4nNdoOQ OvwhkCq8fnAWxYKMwBj9cbW+wM4LpecyFUV1ACLudC65a1JlYbxBVunvmgchhycOBFVwAnDoN+OL/ s/3xBsS91HaZuaCnb6UrCIJv/HRSLCjo1EvCArDS7x4RuBoRz+TunlMyF/8TW0C3V/72/3W+FoWxV jYd+B+YgL2HGHwh7xNwsP9I5nhvPMLNIq9yQ2yQzYKD8zW5WSMlS+Um6/+joNow33+heF6X5X9vdt g41CkWXTQZxPxgcCIAHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwtsV-00BlYs-A4; Mon, 13 Dec 2021 22:33:04 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwtRS-00Bax5-7m for linux-arm-kernel@lists.infradead.org; Mon, 13 Dec 2021 22:05:07 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 72B0C61187; Mon, 13 Dec 2021 22:05:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39756C34600; Mon, 13 Dec 2021 22:05:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639433104; bh=Qf6Ek4AOVKGXkCaS8N754FOQ4GZ8VNQHP64V66crnEQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=tZCzX39AH4q4ioXr/G3bKEcNN56zLDou2/2aV8RcQCyTQ1u/pd7+nymSI/ZHf/EX9 Cz9yANRak/h0I32gKptVTMHGNMS2WLpMRiepFg9yJ0dqs9UHf9YR3iMRJElvonzfA4 LQMX9/lXLIiUf+jp5BIfmrYVL8IyznK6uXOalXiEO63nUU2ut8wr4IHHaHYS/jfwhX MuhRME8kiEtNCPqj1fi9Jg3ylNAnRsVKAUYfUp5izF0H2VO4RUg18tAtaGlaVNcbI+ 7lRY4+KakBolGtoXdg2CCLarXf55bx7ORqpKMEd1WxUESVfQfGGnZTypJlABuxOyGC vux/qapmO4r+A== Date: Mon, 13 Dec 2021 23:05:01 +0100 From: Frederic Weisbecker To: Mark Rutland , Peter Zijlstra Cc: linux-arm-kernel@lists.infradead.org, ardb@kernel.org, catalin.marinas@arm.com, juri.lelli@redhat.com, linux-kernel@vger.kernel.org, mingo@redhat.com, will@kernel.org Subject: Re: [PATCH 5/6] sched/preempt: add PREEMPT_DYNAMIC using static keys Message-ID: <20211213220501.GB786870@lothringen> References: <20211109172408.49641-1-mark.rutland@arm.com> <20211109172408.49641-6-mark.rutland@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20211109172408.49641-6-mark.rutland@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211213_140506_437934_CB0F8DAC X-CRM114-Status: GOOD ( 25.10 ) 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 On Tue, Nov 09, 2021 at 05:24:07PM +0000, Mark Rutland wrote: > Where an architecture selects HAVE_STATIC_CALL but not > HAVE_STATIC_CALL_INLINE, each static call has an out-of-line trampoline > which will either branch to a callee or return to the caller. > > On such architectures, a number of constraints can conspire to make > those trampolines more complicated and potentially less useful than we'd > like. For example: > > * Hardware and software control flow integrity schemes can require the > additition of "landing pad" instructions (e.g. `BTI` for arm64), which > will also be present at the "real" callee. > > * Limited branch ranges can require that trampolines generate or load an > address into a registter and perform an indirect brach (or at least > have a slow path that does so). This loses some of the benefits of > having a direct branch. > > * Interaction with SW CFI schemes can be complicated and fragile, e.g. > requiring that we can recognise idiomatic codegen and remove > indirections understand, at least until clang proves more helpful > mechanisms for dealing with this. > > For PREEMPT_DYNAMIC, we don't need the full power of static calls, as we > really only need to enable/disable specific preemption functions. We can > achieve the same effect without a number of the pain points above by > using static keys to fold early return cases into the preemption > functions themselves rather than in an out-of-line trampoline, > effectively inlining the trampoline into the start of the function. > > For arm64, this results in good code generation, e.g. the > dynamic_cond_resched() wrapper looks as follows (with the first `B` being > replaced with a `NOP` when the function is disabled): > > | : > | bti c > | b > | mov w0, #0x0 // #0 > | ret > | mrs x0, sp_el0 > | ldr x0, [x0, #8] > | cbnz x0, > | paciasp > | stp x29, x30, [sp, #-16]! > | mov x29, sp > | bl > | mov w0, #0x1 // #1 > | ldp x29, x30, [sp], #16 > | autiasp > | ret > > ... compared to the regular form of the function: > > | <__cond_resched>: > | bti c > | mrs x0, sp_el0 > | ldr x1, [x0, #8] > | cbz x1, <__cond_resched+0x18> > | mov w0, #0x0 // #0 > | ret > | paciasp > | stp x29, x30, [sp, #-16]! > | mov x29, sp > | bl > | mov w0, #0x1 // #1 > | ldp x29, x30, [sp], #16 > | autiasp > | ret > > Any architecture which implements static keys should be able to use this > to implement PREEMPT_DYNAMIC with similar cost to non-inlined static > calls. > > Signed-off-by: Mark Rutland > Cc: Ard Biesheuvel > Cc: Frederic Weisbecker > Cc: Ingo Molnar > Cc: Juri Lelli > Cc: Peter Zijlstra Anyone has an opinion on that? Can we do better on the arm64 static call side or should we resign ourself to using that static keys direction? Also I assume that, sooner or later, arm64 will eventually need a static call implementation.... Thanks. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel