From nobody Tue Feb 10 09:24:30 2026 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5223978F45 for ; Thu, 6 Mar 2025 00:44:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741221853; cv=none; b=jee44+JbFILeKKv3Ehvr1I/sbfIooOVkCv5xV633VSz112DFknGfKpqhTGO8G7MN/HjhHgY+L+LRoKHdDd1ekg3OHoaSZH9qUJa/5u21yCZnrf4gtj76VfFF1TvLCgDsjGAtc+EuMRW+zq3pCCdtjwCxhbzgtSWhguN6DswU1OU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741221853; c=relaxed/simple; bh=j7ZO4FXV1Hf14yiJt7JLsFHCp0FLrXbd7xunBuFQ9j8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IUfUvvcJ4B0swdvqiRHJlxL40zxjWiSRIq9BAreTiBERDnlV2waninCAjDtUlb9GTm+JVUM8fp9Dc3gRRs32wRqYQ9izISr9eoP6STT5ea9tOROGB3S8zvhuxaAQ0FRNl7OZUIgxiMjSbcTV5sRU1gpm8tyzgA2QujezFzrRl7o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=uPht16Ve; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="uPht16Ve" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-223785beedfso842015ad.1 for ; Wed, 05 Mar 2025 16:44:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1741221852; x=1741826652; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=p30t3bidsL8DH7wJ55Ht0+lyyt5ZTgdtBsNdg8zXD0s=; b=uPht16Vevt5Pro3U735j8NPJmveA4xj4p2utyJ6Poai4KyoNl72q8xfWkbsmPTBLmk 5mP+rLO30WvBZPTKQRViHzwJDzVtytZVPGxP0++ULSyzwZ/5RYyqjpvXdP5pTO5scMzF y3rKrhxNk7S+46VUr80uwHaFA3+5ycz9zoMiwzaCWjmVuBI/1m58bHZgwFacHBOJxU2f Qmvi59yJdpS3D9Z1uoT2hNYZzt2OK+CRp9ocH/hzThHvKA/SEQKaXejSS3u10YuRlyta 3t6KezPcJozv/KIH02/8c/dMUnT6nD1YVc7+i2sieYckOk96nWch1+MrHLre/Wzr+Dwp lSug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741221852; x=1741826652; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p30t3bidsL8DH7wJ55Ht0+lyyt5ZTgdtBsNdg8zXD0s=; b=Hdij4/rjzNDjGTJgT4+jK6luQKHpNA/uumR2vqX/gr0C3fFbVQ2j/SLARd+MGki4Bh z36dMQd2gcVfPuNo9mG9drp9hvzG0putL2xZT6CZAa2cetRtBkbBV+p+6TKEN+sRmjKQ lM5LqPddqUkzb0L6+GlFjoUy7ncPWrvz6p9OaGn5g6RR1XChJ8veg4RMjodgQyYjzB6O 8PbuiEkfyRaMe0B6Pf8TU/21zkxYMu6g6MTeLrAkdtyujBIAlHOOKj2X6dmut4cdKgcV Q9Aqlbgg7+920sYGxt3CIW7rzI9/7IcybLXw2yuHCw88hlVPIMzqu/zFF77p1ZV5MoAm Ju7Q== X-Forwarded-Encrypted: i=1; AJvYcCV+4QTt2e5GzvdWnAkV3lTaK7uWdoUsivVl2bCE4kP32vYvkLVCnBVtvZA0R6CX8GjHLyXa0cpGhszOPcE=@vger.kernel.org X-Gm-Message-State: AOJu0YzPputQiieF9KlqSKI0HMNFzfR4DbWsLMQNVX9QuoL4bnJsqGJn /K7lB2njBwYaLB4fJVZGZfvoAa+03QccBazRE5M3UF97wRR5Ud/BxEFJNjQe6S4= X-Gm-Gg: ASbGncv3JEdhEUaDRJQoYkFr07wAuvrv+1xS5xcvyivxfe8bGed/3gnIu/HFLcHjdO0 bB5PbGRqnOupMxhkHUuEipk6EoHnhia8oxo0l77dOtoxMVR2edJNzvvhFt+WPN3M9ZM6Ewxbgjk ixtczZDsGmgedIhF9iFYNmXnQrGEqEezexRyG7DpopFq4oILPtxsbsHMdyTCqd9iwkInnkRGSmO 6G+plB0VEU7tm1LT9lCh1OJlqEG9uW4mNZGMv33LrrS0tsftW0r+Z+n24oF8Y6rCRl6wvZFeEHY xgrYihaahYuACQoTz6u8J0pNA1gon/d2tbgzoIaWVdwm/Vh0FJcfb8YHILrK X-Google-Smtp-Source: AGHT+IE3udje6D9ToJozjElnL03nykz3gt3O3YbFzCSzOAeX2/0ggHbBiX1+w1/L3X8PtcJZLOlRYA== X-Received: by 2002:a17:902:d549:b0:224:3c9:19ae with SMTP id d9443c01a7336-22403c91a6cmr43245075ad.34.1741221851852; Wed, 05 Mar 2025 16:44:11 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22410a7f7efsm347085ad.132.2025.03.05.16.44.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Mar 2025 16:44:11 -0800 (PST) From: Charlie Jenkins Date: Wed, 05 Mar 2025 16:43:47 -0800 Subject: [PATCH v5 4/4] entry: Inline syscall_exit_to_user_mode() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250305-riscv_optimize_entry-v5-4-6507b5dff3ce@rivosinc.com> References: <20250305-riscv_optimize_entry-v5-0-6507b5dff3ce@rivosinc.com> In-Reply-To: <20250305-riscv_optimize_entry-v5-0-6507b5dff3ce@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Huacai Chen , WANG Xuerui , Thomas Gleixner , Peter Zijlstra , Andy Lutomirski , Alexandre Ghiti Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, Charlie Jenkins X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5141; i=charlie@rivosinc.com; h=from:subject:message-id; bh=j7ZO4FXV1Hf14yiJt7JLsFHCp0FLrXbd7xunBuFQ9j8=; b=owGbwMvMwCXWx5hUnlvL8Y3xtFoSQ/qJ95d9ndq3LQ44de6FoLjnP4Wflp+6lvkeeNEuvN8vl k/soW5mRykLgxgXg6yYIgvPtQbm1jv6ZUdFyybAzGFlAhnCwMUpABNRWMDIsEH+59MDmer/fzAU vvxYZjyFw/HQm6w1f54Er/xks8PGu5mRoa1Us0Hzc7CdgfrJc8aZ75wz9rt7hrUu4uo1/VOqxcH FAQA= X-Developer-Key: i=charlie@rivosinc.com; a=openpgp; fpr=7D834FF11B1D8387E61C776FFB10D1F27D6B1354 Architectures using the generic entry code can be optimized by having syscall_exit_to_user_mode inlined. Signed-off-by: Charlie Jenkins Reviewed-by: Alexandre Ghiti --- include/linux/entry-common.h | 43 ++++++++++++++++++++++++++++++++++++-- kernel/entry/common.c | 49 +---------------------------------------= ---- 2 files changed, 42 insertions(+), 50 deletions(-) diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h index fc61d0205c97084acc89c8e45e088946f5e6d9b2..f94f3fdf15fc0091223cc9f7b82= 3970302e67312 100644 --- a/include/linux/entry-common.h +++ b/include/linux/entry-common.h @@ -14,6 +14,7 @@ #include =20 #include +#include =20 /* * Define dummy _TIF work flags if not defined by the architecture or for @@ -366,6 +367,15 @@ static __always_inline void exit_to_user_mode(void) lockdep_hardirqs_on(CALLER_ADDR0); } =20 +/** + * syscall_exit_work - Handle work before returning to user mode + * @regs: Pointer to current pt_regs + * @work: Current thread syscall work + * + * Do one-time syscall specific work. + */ +void syscall_exit_work(struct pt_regs *regs, unsigned long work); + /** * syscall_exit_to_user_mode_work - Handle work before returning to user m= ode * @regs: Pointer to currents pt_regs @@ -379,7 +389,30 @@ static __always_inline void exit_to_user_mode(void) * make the final state transitions. Interrupts must stay disabled between * return from this function and the invocation of exit_to_user_mode(). */ -void syscall_exit_to_user_mode_work(struct pt_regs *regs); +static __always_inline void syscall_exit_to_user_mode_work(struct pt_regs = *regs) +{ + unsigned long work =3D READ_ONCE(current_thread_info()->syscall_work); + unsigned long nr =3D syscall_get_nr(current, regs); + + CT_WARN_ON(ct_state() !=3D CT_STATE_KERNEL); + + if (IS_ENABLED(CONFIG_PROVE_LOCKING)) { + if (WARN(irqs_disabled(), "syscall %lu left IRQs disabled", nr)) + local_irq_enable(); + } + + rseq_syscall(regs); + + /* + * Do one-time syscall specific work. If these work items are + * enabled, we want to run them exactly once per syscall exit with + * interrupts enabled. + */ + if (unlikely(work & SYSCALL_WORK_EXIT)) + syscall_exit_work(regs, work); + local_irq_disable_exit_to_user(); + exit_to_user_mode_prepare(regs); +} =20 /** * syscall_exit_to_user_mode - Handle work before returning to user mode @@ -410,7 +443,13 @@ void syscall_exit_to_user_mode_work(struct pt_regs *re= gs); * exit_to_user_mode(). This function is preferred unless there is a * compelling architectural reason to use the separate functions. */ -void syscall_exit_to_user_mode(struct pt_regs *regs); +static __always_inline void syscall_exit_to_user_mode(struct pt_regs *regs) +{ + instrumentation_begin(); + syscall_exit_to_user_mode_work(regs); + instrumentation_end(); + exit_to_user_mode(); +} =20 /** * irqentry_enter_from_user_mode - Establish state before invoking the irq= handler diff --git a/kernel/entry/common.c b/kernel/entry/common.c index e33691d5adf7aab4af54cf2bf8e5ef5bd6ad1424..f55e421fb196dd5f9d4e34dd85a= e096c774cf879 100644 --- a/kernel/entry/common.c +++ b/kernel/entry/common.c @@ -146,7 +146,7 @@ static inline bool report_single_step(unsigned long wor= k) return work & SYSCALL_WORK_SYSCALL_EXIT_TRAP; } =20 -static void syscall_exit_work(struct pt_regs *regs, unsigned long work) +void syscall_exit_work(struct pt_regs *regs, unsigned long work) { bool step; =20 @@ -173,53 +173,6 @@ static void syscall_exit_work(struct pt_regs *regs, un= signed long work) ptrace_report_syscall_exit(regs, step); } =20 -/* - * Syscall specific exit to user mode preparation. Runs with interrupts - * enabled. - */ -static void syscall_exit_to_user_mode_prepare(struct pt_regs *regs) -{ - unsigned long work =3D READ_ONCE(current_thread_info()->syscall_work); - unsigned long nr =3D syscall_get_nr(current, regs); - - CT_WARN_ON(ct_state() !=3D CT_STATE_KERNEL); - - if (IS_ENABLED(CONFIG_PROVE_LOCKING)) { - if (WARN(irqs_disabled(), "syscall %lu left IRQs disabled", nr)) - local_irq_enable(); - } - - rseq_syscall(regs); - - /* - * Do one-time syscall specific work. If these work items are - * enabled, we want to run them exactly once per syscall exit with - * interrupts enabled. - */ - if (unlikely(work & SYSCALL_WORK_EXIT)) - syscall_exit_work(regs, work); -} - -static __always_inline void __syscall_exit_to_user_mode_work(struct pt_reg= s *regs) -{ - syscall_exit_to_user_mode_prepare(regs); - local_irq_disable_exit_to_user(); - exit_to_user_mode_prepare(regs); -} - -void syscall_exit_to_user_mode_work(struct pt_regs *regs) -{ - __syscall_exit_to_user_mode_work(regs); -} - -__visible noinstr void syscall_exit_to_user_mode(struct pt_regs *regs) -{ - instrumentation_begin(); - __syscall_exit_to_user_mode_work(regs); - instrumentation_end(); - exit_to_user_mode(); -} - noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs) { enter_from_user_mode(regs); --=20 2.43.0