From patchwork Tue Oct 29 10:52:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854800 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 31B8DD2AB29 for ; Tue, 29 Oct 2024 11:58:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Be+GUyUOPZhG4HeyC8y7wViGnm8iy+tOVPMx83A5Zgg=; b=F9PnA/Ipx8KpPhyFKDvnrwBWCj Vj1V0RO6u8d7ad4ZV3xq7qRkNu/qz6qpLM6BIvQV1uonkadvPju+QXdFx97UMMnst5KFYBpptFXfM F2vv8VnvWMJ6JxB6zauE6BidI+ODAnMY7O0ymlrfYl1PPsfXcUoUUAJfms6qnurpseYn4rdcjD4Ak g2/PQ9oxmdQatQ0UjRkwrhTZyn0LeBlb6YApjU4U34dJTJoF78aVqszcaTpbmviU98TcIkCCEMXQY CIAYVK0WsNrXzCq+K2mbbxsyarNXnC4syJe+1mWupv1sGMuzAVpLLrOYURPV8Cn3+ZgLN+hbsXAZQ V9VJJezw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5krr-0000000EJhb-0nb3; Tue, 29 Oct 2024 11:58:35 +0000 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5jqa-0000000E7M4-06gu for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2024 10:53:13 +0000 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-53a007743e7so6043972e87.1 for ; Tue, 29 Oct 2024 03:53:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730199190; x=1730803990; darn=lists.infradead.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=Be+GUyUOPZhG4HeyC8y7wViGnm8iy+tOVPMx83A5Zgg=; b=AaxaRzYNY6EWvZ73zYDt7Jg0afxLBDq78MWo7WZ/ia8epGjcxpHkl0SVaGsQO6vw1z QRdR03l+3Kv8YNdJIziCaS6yJFe4DlgPZJxCeofF+8p8X/EQsNFVN9o7MiNuktZQ4kn0 pgS9gmu9nGhkmpMHqAzmx08qkkTfquqUt96/0hssmyDGI7OXzWDbBShd6ztPAG0lGOH1 tlpWojtyREhdExeuy9yG99t+bIl8bxH2AHb9WFKJNjRTP3PljHa+BY5bH806LJ+5z18k OSK6kWBJklePIfBVpe+MSWHRQsxFLTHiQC2P7jL2qBiclLB4zdq1XplPulc3YAEPAHad d6Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730199190; x=1730803990; 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=Be+GUyUOPZhG4HeyC8y7wViGnm8iy+tOVPMx83A5Zgg=; b=PBpA3YOQYSx0lFjGdGFP5om4y6WXR8eWOsErKMYz01KOrZhMZOYJpjehFGsSpRamSx 4Q2YxriXEj936huUgfICwtpwg+UpCPqdrWWqOPe5L0+IsyQS/FwiRmh8ecFeOLPfhr5o Se/CQmKiEYzpcMad8b1KRjzwxHu0+jnQeFrXNwbt3vpqEz7nmvLIoa1xQEkC1kXEFqk8 ENPxHIyrdAYvWZIsW6pJKyo/Ovcy92A/1GpMHB063wP5Faxs5uqshm8FwM9AvYOwV8+1 qZeHjyDE84PP1srQ35CrYph2V0HrqOJGx/L1tK1EdknmZxwqqkgENPaJHdRqU8tJcU7m M3Ow== X-Gm-Message-State: AOJu0YzpFgK70OzKzz1jHkA9z+TerL65PFLQS1zKzpqBeMIrPGvOED1u H40LCYTMJTqiiPGMfDVd9iXykmXFDj4jabOxRKay4dJdx6c3k3ag51rNU11wtAo= X-Google-Smtp-Source: AGHT+IHnu3r1g0OwvCLOiPYGKbeTf+Hv9O68OAgzGiZtRX6hJe7xHb3GGSvsAVORAIl1GunSQigcZQ== X-Received: by 2002:a05:6512:33d5:b0:53a:3a:f4f4 with SMTP id 2adb3069b0e04-53b348e599cmr4735466e87.31.1730199190072; Tue, 29 Oct 2024 03:53:10 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53b2e12452fsm1351307e87.73.2024.10.29.03.53.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:53:08 -0700 (PDT) From: Linus Walleij Date: Tue, 29 Oct 2024 11:52:53 +0100 Subject: [PATCH RFC v2 13/28] ARM: entry: Create user_mode_enter/exit MIME-Version: 1.0 Message-Id: <20241029-arm-generic-entry-v2-13-573519abef38@linaro.org> References: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> In-Reply-To: <20241029-arm-generic-entry-v2-0-573519abef38@linaro.org> To: Oleg Nesterov , Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Frederic Weisbecker , "Paul E. McKenney" , Jinjie Ruan , Arnd Bergmann , Ard Biesheuvel , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.14.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241029_035312_217754_227140E0 X-CRM114-Status: GOOD ( 19.16 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The callbacks to the context tracking will be repurposed for several uses that are needed on the IRQ transition to/from userspace. Rename the macro, establish call sites in C calling into the context tracking following the corresponding generic entry function prototypes, despite the assembly macro names become a bit long this makes it clear to readers exactly what is going on and where this call will go. Drop the ifdefs pertaining to context tracking from the macro. The C calls we will use have stubs that will compile these out anyway. The inversion of the signature of the context tracking calls are especially confusing since the generic entry uses the reverse semantics: *enter from* user mode (to kernel mode) and *exit to* user mode (from kernel mode) instead of the other way around as the old context tracker code user_exit_callable() and user_enter_callable() which have inverted semantics. Signed-off-by: Linus Walleij --- arch/arm/include/asm/entry.h | 14 ++++++++++++++ arch/arm/kernel/Makefile | 2 +- arch/arm/kernel/entry-armv.S | 2 +- arch/arm/kernel/entry-common.S | 4 ++-- arch/arm/kernel/entry-header.S | 24 ++++++++++++------------ arch/arm/kernel/entry.c | 15 +++++++++++++++ 6 files changed, 45 insertions(+), 16 deletions(-) diff --git a/arch/arm/include/asm/entry.h b/arch/arm/include/asm/entry.h new file mode 100644 index 000000000000..e26f369375ca --- /dev/null +++ b/arch/arm/include/asm/entry.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_ENTRY_H__ +#define __ASM_ENTRY_H__ + +struct pt_regs; + +/* + * These are copies of generic entry headers so we can transition + * to generic entry once they are semantically equivalent. + */ +void irqentry_enter_from_user_mode(struct pt_regs *regs); +void irqentry_exit_to_user_mode(struct pt_regs *regs); + +#endif /* __ASM_ENTRY_H__ */ diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile index d5a128a4228d..9a6ac0974110 100644 --- a/arch/arm/kernel/Makefile +++ b/arch/arm/kernel/Makefile @@ -17,7 +17,7 @@ CFLAGS_REMOVE_return_address.o = -pg # Object file lists. -obj-y := elf.o entry-common.o irq.o opcodes.o \ +obj-y := elf.o entry.o entry-common.o irq.o opcodes.o \ process.o ptrace.o reboot.o io.o \ setup.o signal.o sigreturn_codes.o \ stacktrace.o sys_arm.o time.o traps.o \ diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index 1dfae1af8e31..d6e8b36c70f5 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -405,7 +405,7 @@ ENDPROC(__fiq_abt) #ifdef CONFIG_TRACE_IRQFLAGS bl trace_hardirqs_off #endif - ct_user_exit save = 0 + asm_irqentry_enter_from_user_mode save = 0 .endif .endm diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index f1e48002bd30..ff1dd3169346 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -111,7 +111,7 @@ ENTRY(ret_to_user_from_irq) no_work_pending: asm_trace_hardirqs_on save = 0 - ct_user_enter save = 0 + asm_irqentry_exit_to_user_mode save = 0 #ifdef CONFIG_GCC_PLUGIN_STACKLEAK bl stackleak_erase_on_task_stack @@ -191,7 +191,7 @@ ENTRY(vector_swi) alignment_trap r10, ip, cr_alignment asm_trace_hardirqs_on save=0 enable_irq_notrace - ct_user_exit save=0 + asm_irqentry_enter_from_user_mode save = 0 /* * Get the system call number. diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S index 52b4fa97226d..fb5bb019199b 100644 --- a/arch/arm/kernel/entry-header.S +++ b/arch/arm/kernel/entry-header.S @@ -362,31 +362,31 @@ ALT_UP_B(.L1_\@) .endm /* - * Context tracking subsystem. Used to instrument transitions + * Context tracking and other mode transitions. Used to instrument transitions * between user and kernel mode. - */ - .macro ct_user_exit, save = 1 -#ifdef CONFIG_CONTEXT_TRACKING_USER +*/ + .macro asm_irqentry_enter_from_user_mode, save = 1 .if \save stmdb sp!, {r0-r3, ip, lr} - bl user_exit_callable + mov r0, sp @ regs + bl irqentry_enter_from_user_mode ldmia sp!, {r0-r3, ip, lr} .else - bl user_exit_callable + mov r0, sp @ regs + bl irqentry_enter_from_user_mode .endif -#endif .endm - .macro ct_user_enter, save = 1 -#ifdef CONFIG_CONTEXT_TRACKING_USER + .macro asm_irqentry_exit_to_user_mode, save = 1 .if \save stmdb sp!, {r0-r3, ip, lr} - bl user_enter_callable + mov r0, sp @ regs + bl irqentry_exit_to_user_mode ldmia sp!, {r0-r3, ip, lr} .else - bl user_enter_callable + mov r0, sp @ regs + bl irqentry_exit_to_user_mode .endif -#endif .endm /* diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c new file mode 100644 index 000000000000..8b2e8ea66c13 --- /dev/null +++ b/arch/arm/kernel/entry.c @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include + +noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs) +{ + /* This context tracking call has inverse naming */ + user_exit_callable(); +} + +noinstr void irqentry_exit_to_user_mode(struct pt_regs *regs) +{ + /* This context tracking call has inverse naming */ + user_enter_callable(); +}