Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp34063465rwd; Sun, 9 Jul 2023 04:32:51 -0700 (PDT) X-Google-Smtp-Source: APBJJlEZ241zdZTMY0pPCmKx0u2ocG1qC4/NpIUJYudWfoSlTGGuGIYG11Ua5ENOpOxB4LUVOJPq X-Received: by 2002:a17:903:230e:b0:1b5:47fc:5864 with SMTP id d14-20020a170903230e00b001b547fc5864mr9955638plh.56.1688902371468; Sun, 09 Jul 2023 04:32:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688902371; cv=none; d=google.com; s=arc-20160816; b=ZkcsTO1CC6Drd/wENWlWmUQy2F3EJCQ7+4v25sRY4gAIwo1dDVbCpJcE211+PvdPdZ 5+RHMPF9nEVbPI4IG3SmEEEiEC0W/h/PBSU6ognRpaShxu4c2g9LgloBAg+LxuI8AqNS tUc2sPK7DtwlCW9z46bXBDBrgNapMUyYfTq0HStqfbwx9Wk/HpmGWoS5VONk2sH+09Fc I7GFUXuRlcOjmROmtu4jfglpRDmSC99pfYIhuF/gCFYFgac5QLCDjQjG0Q4YqFiVf8uA Y/XeXK+J9A5Z6e7k91hT66YWgS/OAZ13C+Yi8q+HS3MkZWUKe+T+AuTUdYczrb5BIVCX 8BLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=8KHTlhbhjfkMyNM/j8qR6apEzRXHdX7jhIVsOAbcAGA=; fh=IGCcjdEBjjovXHjeHimapVcyznQdBjOMfoNiqvsQg/I=; b=IiC7PIoN+KLrt/cIsnHiWVi+50m0KKvTc3lIM8d2YXxGVcPEtJWqDC5XJNJ81EeY7f z97x9emtgWytcKEiNPzWF0NsgYmBzbVcsPlzJZsMSobKrS3j84S/GvymMjkYRvBWVm36 fQM72d3ZgT54Bc4dSdp8OttHlnK9uIdYEMWpdA3HoPozcz1J0PVp+HX0UQ7fVNat8ap9 bI5AciEf0Mk0hbnI2h076Zd/zJC4atC9Up+FwmZX/48dLWubvkp4r7ORcCMty0fSadGH YE/6iEUadqOeiOlocsF+AW7lwUKHohTJQ4/dWXnU4KF0FP7U/kZtCzIMSEqNRmD326/Q Lg2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lYtFlNfT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f20-20020a170902f39400b001b89654fa42si6622863ple.476.2023.07.09.04.32.39; Sun, 09 Jul 2023 04:32:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lYtFlNfT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230272AbjGIK20 (ORCPT + 99 others); Sun, 9 Jul 2023 06:28:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229973AbjGIK2Z (ORCPT ); Sun, 9 Jul 2023 06:28:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89D1C12A; Sun, 9 Jul 2023 03:28:24 -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 CD09060BBE; Sun, 9 Jul 2023 10:28:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD141C433C8; Sun, 9 Jul 2023 10:28:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688898503; bh=3sPwX4GVTHH+apYt2dKBk43WvXcfJBHi7r9smnLvACE=; h=From:To:Cc:Subject:Date:From; b=lYtFlNfTAA3tzzCsF5XPl5cdaF4pDoSIR4OXiGBZwf1uVoC0y/782/ax77YFkq+dx HneYNDBK60xClp0GRzi2efpbIArOF+5gCm81Hp4PVvQiE9EUotpox3RlJhp1e6MCqS 7G+2zA5VaMB0WO4sfXCbHViLzpvPhFWmDLeDSCCYu0iee/Zo2WuAbjhDrKZZRuQN72 AL1dr44g8+MKXM8LvXjAoCdiwgZLjt7sT3ezMhkX4oX6Ahkbz0lnyAqhqTaw5ALV9Z Vxm6gqbMi3NBaEY6rF7/4wmzaI+VxTWoJklhOsH922ffrHGk0JZldKIn0gm6OXNlCx HzQJNAG5kA61g== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Arnd Bergmann Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Subject: [PATCH] riscv: support PREEMPT_DYNAMIC with static keys Date: Sun, 9 Jul 2023 18:16:53 +0800 Message-Id: <20230709101653.720-1-jszhang@kernel.org> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, each architecture can support PREEMPT_DYNAMIC through either static calls or static keys. To support PREEMPT_DYNAMIC on riscv, we face three choices: 1. only add static calls support to riscv As Mark pointed out in commit 99cf983cc8bc ("sched/preempt: Add PREEMPT_DYNAMIC using static keys"), static keys "...should have slightly lower overhead than non-inline static calls, as this effectively inlines each trampoline into the start of its callee. This may avoid redundant work, and may integrate better with CFI schemes." So even we add static calls(without inline static calls) to riscv, static keys is still a better choice. 2. add static calls and inline static calls to riscv Per my understanding, inline static calls requires objtool support which is not easy. 3. use static keys While riscv doesn't have static calls support, it supports static keys perfectly. So this patch selects HAVE_PREEMPT_DYNAMIC_KEY to enable support for PREEMPT_DYNAMIC on riscv, so that the preemption model can be chosen at boot time. It also patches asm-generic/preempt.h, mainly to add __preempt_schedule() and __preempt_schedule_notrace() macros for PREEMPT_DYNAMIC case. Other architectures which use generic preempt.h can also benefit from this patch by simply selecting HAVE_PREEMPT_DYNAMIC_KEY to enable PREEMPT_DYNAMIC if they supports static keys. Signed-off-by: Jisheng Zhang --- arch/riscv/Kconfig | 1 + include/asm-generic/preempt.h | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 4c07b9189c86..bdea2e5a9f34 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -129,6 +129,7 @@ config RISCV select HAVE_PERF_EVENTS select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP + select HAVE_PREEMPT_DYNAMIC_KEY if !XIP_KERNEL select HAVE_POSIX_CPU_TIMERS_TASK_WORK select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RETHOOK if !XIP_KERNEL diff --git a/include/asm-generic/preempt.h b/include/asm-generic/preempt.h index b4d43a4af5f7..1f476aec7e4c 100644 --- a/include/asm-generic/preempt.h +++ b/include/asm-generic/preempt.h @@ -80,9 +80,21 @@ static __always_inline bool should_resched(int preempt_offset) #ifdef CONFIG_PREEMPTION extern asmlinkage void preempt_schedule(void); -#define __preempt_schedule() preempt_schedule() extern asmlinkage void preempt_schedule_notrace(void); + +#ifdef CONFIG_PREEMPT_DYNAMIC + +void dynamic_preempt_schedule(void); +void dynamic_preempt_schedule_notrace(void); +#define __preempt_schedule() dynamic_preempt_schedule() +#define __preempt_schedule_notrace() dynamic_preempt_schedule_notrace() + +#else /* CONFIG_PREEMPT_DYNAMIC */ + +#define __preempt_schedule() preempt_schedule() #define __preempt_schedule_notrace() preempt_schedule_notrace() + +#endif /* CONFIG_PREEMPT_DYNAMIC */ #endif /* CONFIG_PREEMPTION */ #endif /* __ASM_PREEMPT_H */ -- 2.40.1