Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp4792256rwp; Sun, 16 Jul 2023 10:53:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlFuyNOpcbYFKnp4tqnA94M8x0X94j1hvM+gt+2EWe1u2gjaPWRnEB6efCzkiEHEk9ByV4wi X-Received: by 2002:a17:902:ec87:b0:1b8:9215:9163 with SMTP id x7-20020a170902ec8700b001b892159163mr5382740plg.6.1689529987903; Sun, 16 Jul 2023 10:53:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689529987; cv=none; d=google.com; s=arc-20160816; b=pI10/E1e2J+1n3wqVeEW8yprLVGMmpw7wmU+OL7UOb3TW5h2W6Cs0P3NHVj4/jqfpT bqw2O6t+kVLEm8bkka9BKQ5Rtqa5jnQ9qkGLbcuAqMBTa0ZenDRmm9yhNtmY7+2xgDT5 6GliJYdd+NWPKBSmmsxsWqjOoNLMPJaruH3VcJXBAm2kyt30sf3sb0vffqR7L+DWSxJ2 Oux6kgK+j2bI7P3vVneiUyYdGXrbOyDvsybihN+oTB39bmnKt+/bP8UxMTkqXuAG9F7q S2Z7QL3sLK6PaC7I75rhq31fnMQtFw8WnmgGfulXlpVNxdmLwBgg4j4JODeU4dSpF7Vq doYg== 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=/KVlZQmI2J+qgb+TedcgFwBZVLKNZd5JE7lwgnntcBI=; fh=IGCcjdEBjjovXHjeHimapVcyznQdBjOMfoNiqvsQg/I=; b=Whdq/QZeAqMIcOSAZeCpGXE4h/tK89PWW4RS4EBkoYaf/LNzzhNBEzCtU3jf9GfLjD IUDufnbacK1Um6mG4j7fG33oasNfjOeZaMx8us+naZVKteUsgk7ekDJUVA6mFEGXnzgs 5jrOTDzJXWgaCIg/FLaml4Z6/bf2OUm/tWKbiUWaWgJ7Az5lVxiXVQJLn7NuMYDPdA5q QCBMFTadp3a65gm6+yG0hEqJyPi72L9PX9fdRceDXQrHz9d6xPsCtz9c1f5RUfJQ7XP4 HN/5afKRYE9MgL9qHFXH7t+7HbDZqE1X4LuTCuCMOW99iWTgnN+wKAKoZGLu3ru+kYo4 GgrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="D9WTZ//z"; 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 k12-20020a170902c40c00b001b8944aa943si10809612plk.315.2023.07.16.10.52.55; Sun, 16 Jul 2023 10:53:07 -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="D9WTZ//z"; 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 S229986AbjGPRBB (ORCPT + 99 others); Sun, 16 Jul 2023 13:01:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbjGPRBA (ORCPT ); Sun, 16 Jul 2023 13:01:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40E661B1; Sun, 16 Jul 2023 10:00:59 -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) server-digest SHA256) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D294360C63; Sun, 16 Jul 2023 17:00:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E623C433C8; Sun, 16 Jul 2023 17:00:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689526858; bh=sO+ETVQWwYmOPn5mUIbEvZ8OhqTGaw4+3C16oa1rjoY=; h=From:To:Cc:Subject:Date:From; b=D9WTZ//zIycNG2Zu7PGosYaEot35CiRW0/6tu5BYDDX0BJiybw2teSY/UupPPP3O4 F13Qqp0KRsPkUJ8YIGJsPnS9J967sf9o4YNeKD9fbDPMCNMqw27Uh+cMmIRvXSK0tY cCQ9R2a5H54xVQZWGvw7d5xl8Y+0DuXvB2RoyETmpCI6CJa5sWsfK3GebTvZyQYmtZ gglw5j6oZj1Q+3j7oCdAvKBZIPpmAn9obwu8mFK8KjDsKAoNl9wuDttRXJRSMKmUfh aW6tJI6+c3xqYi/EK3YdJErbBKinpfXloKd2jBlbsLXHp7TwBToQvoBjfhtWokgeCS PmW8po/y6zc4w== 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 v2] riscv: support PREEMPT_DYNAMIC with static keys Date: Mon, 17 Jul 2023 00:49:25 +0800 Message-Id: <20230716164925.1858-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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 --- since v1: - keep Kconfig entries sorted - group asm-generic modifications under CONFIG_PREEMPT_DYNAMIC && CONFIG_HAVE_PREEMPT_DYNAMIC_KEY) 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..686df6902947 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -130,6 +130,7 @@ config RISCV select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP select HAVE_POSIX_CPU_TIMERS_TASK_WORK + select HAVE_PREEMPT_DYNAMIC_KEY if !XIP_KERNEL select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RETHOOK if !XIP_KERNEL select HAVE_RSEQ diff --git a/include/asm-generic/preempt.h b/include/asm-generic/preempt.h index b4d43a4af5f7..51f8f3881523 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); + +#if defined(CONFIG_PREEMPT_DYNAMIC) && defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY) + +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 || !CONFIG_HAVE_PREEMPT_DYNAMIC_KEY*/ + +#define __preempt_schedule() preempt_schedule() #define __preempt_schedule_notrace() preempt_schedule_notrace() + +#endif /* CONFIG_PREEMPT_DYNAMIC && CONFIG_HAVE_PREEMPT_DYNAMIC_KEY*/ #endif /* CONFIG_PREEMPTION */ #endif /* __ASM_PREEMPT_H */ -- 2.40.1