From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42])
	(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 F08231BE23D
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:33:43 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560026; cv=none; b=aYjZ2kK3xyDQrzAHO05DTlYrb2caS2PiJaYAc5vK9YkB7yQZqOwidpTMdid7QVu2b5chs2FtVqOsMM4MTfbBLtpDHqcYyeTZtKeSVhgmf9o6lagpG5jAA20AY5MsWT/EGEdsjAydvhbYYes1am9PsZ7RljhZPRSLeSrrjSXE31U=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560026; c=relaxed/simple;
	bh=qoiIkbAz4KJFocl2cDf/q68RonL97tQqXsLm1/NapfA=;
	h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:Cc; b=LQKc2j4gwNL2DgBRzBGjHczn8cENHad2FD9/O2RaFlT5dS1pUYojb9UJyszY7J/xt+HdtW05h+5KHoS99aM6taXJ+5M97HVWtTSaHl5THjvVc4/iNiWIBlSJOMDYD7vQnExMpE4wfYpCh1uYF8JJYs9RWhRY7r+POQKGhP/AYII=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Z/1Cobg6; arc=none smtp.client-ip=209.85.218.42
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Z/1Cobg6"
Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a997736106fso105082666b.3
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:33:43 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560022; x=1729164822; darn=vger.kernel.org;
        h=cc:to:content-transfer-encoding:mime-version:message-id:date
         :subject:from:from:to:cc:subject:date:message-id:reply-to;
        bh=jEyuiFWgoMlrQ/8epEbwWJkTaCNZnZTgvo3IasEf6I0=;
        b=Z/1Cobg6u2iDYdwkMwnvI2YyfC/fovxD/kTzMFQuJAFJ6ZGRQuPTBPsnT6dYq3Uyzu
         3M6mQ5LpJK0vlO/4NE5Omo0cebESXOslBUBl7kJ/juBTASKfw8RpRGSyElVZtaxh0o8a
         biYAJsC3cuje10+rexva3hdXwGEooomliHDK+0Bwic15XVuq0/dH9Zwg1wYsso9WSubv
         43UcyVkmaP33Ejn3qf8e7qXuu8MZOuNtP8YKq4xbt5tl0PR5wfMr7t7RBGf1gy/F2ijN
         kFPyIYIVw0yPj76Sp4lO1mw6W94kKyOGsRQFYQaKut5/nYJeK/Sxx9fe+lfnKHJRPlaG
         vKgQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560022; x=1729164822;
        h=cc:to:content-transfer-encoding:mime-version:message-id:date
         :subject:from:x-gm-message-state:from:to:cc:subject:date:message-id
         :reply-to;
        bh=jEyuiFWgoMlrQ/8epEbwWJkTaCNZnZTgvo3IasEf6I0=;
        b=eLoJvSB41pTrCRTwgVLmNi0rgXlKUsCXZ6J6dI+kwOJF7hK3mbc1bMsfKRFAn68VAl
         jDS4pDlSd/8tTbWJ/8eOCqc8msM8HLqxJK+QYbf7NMnfX+qDySi7BSzleOFr5OwuGtG7
         0KBYaNShmQR9jVr5ktxsb1AyKbHbyBR1wTrM0zTvz6ul6Nfy/q+bpVF5IP41vhTq2Cjy
         vLvonDd1n4YAiZL1HBGtgej8Qn31Q++s95PPQtgqR8D+oxCy4NT63hH4JYz9yjyMJ4aB
         TLNSlTaTv0NKTg4VZhHztjMIiqFJwtnRf0g0iPfKUy2Rfw/hJEhaTB9WTsfgmQ9N21Sg
         vUcQ==
X-Forwarded-Encrypted: i=1; AJvYcCX/Uwf9gi8Whcem6o3Gid1iBhU8SWpzeLBUDoa8b+XYLLrcVZd8u0pSCNaUK7mKFEUiVF90zGDKL8JONC4=@vger.kernel.org
X-Gm-Message-State: AOJu0YwPzYmDGVhCJyfc0KfVfZ4qo2fsn5zral3yERoNHZy3XRNEs1Zf
	P7aFC+yXbmWsV7crsH08EE0fAIOXLIUlXZ2IVLpAc/hYHt892SIsatWuunbfcXo=
X-Google-Smtp-Source: AGHT+IG9UpDR2ovzZ66IthivCf3I31e/FfM2orVk5ZJ1TTBxrgXO95elksQlw3k8TUdTAVU1enx42Q==
X-Received: by 2002:a17:907:1c82:b0:a99:8629:603a with SMTP id a640c23a62f3a-a998d328e6cmr536255766b.57.1728560022136;
        Thu, 10 Oct 2024 04:33:42 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.41
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:33:41 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Subject: [PATCH RFC 00/28] ARM: Switch to generic entry
Date: Thu, 10 Oct 2024 13:33:38 +0200
Message-Id: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
X-B4-Tracking: v=1; b=H4sIAJK7B2cC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE
 vPSU3UzU4B8JSMDIxMDSwNj3cSiXN301DygrmTd1LySokrdxJREQxNTY3OLpKRUJaC+gqLUtMw
 KsJnRSkFuzkqxtbUAH8tUv2gAAAA=
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

This patch series converts a slew of ARM assembly into the
corresponding C code, step by step moving the codebase
closer to the expectations of the generic entry code,
and as a last step switches ARM over to the generic
entry code.

This was inspired by Jinjie Ruans similar work for ARM64.

The low-level assembly calls into arch/arm/kernel/syscall.c
to invoke syscalls from userspace, and to the functions listed
in arch/arm/kernel/entry.c for any other transitions to
and from userspace. Looking at these functions and the
call sites in the assembly on the final result should give
a pretty good idea about how this works, and what the
generic entry expects from an architecture.

To test the code the following seccomp patch is needed
on older ARM systems:
https://lore.kernel.org/lkml/20241008-seccomp-compile-error-v1-1-f87de4007095@linaro.org

There is a git branch you can pull in and test (v6.12-rc1
based):
https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-integrator.git/log/?h=b4/arm-generic-entry-v6.12-rc1

Upsides:
- Same code paths as x86, S390, RISCV, Loongarch and probably
  soon ARM64 is used for the ARM systems. This includes some
  instrumentation stubs helping out with things we haven't
  even started to look at such as kmsan and live patching (!).

- By introducing the new callbacks to C, we can move away
  from the deprecated (and I think partly unmaintained) context
  tracking mechanism for RCU (user_exit_callable(),
  user_enter_callable()) in favor of what everyone else
  is using, i.e. calling rcu_irq_enter_check_tick() on
  IRQ entry.

- I think also lockdep is now behaving more according to
  expectations (the lockdep calls in ARM64 and generic entry
  seems different and more fine-granular from the ARM32 code)
  but I am no expert in lockdep so I cannot really tell if
  this is a real improvement.

Downsides:

- I had to remove the "fast syscall restart" from Al Viro.
  I don't know how much it will affect performance, but
  if this is something we must have, let's try to make
  the solution generic, i.e. add fast syscall restart in
  the generic entry code.

- The "superfast return to userspace" using just very
  small assembly snippets to get back to userspace on
  e.g. IRQs if and only if no instrumentation was compiled
  in, is no longer possible, since we unconditionally
  call into code written in C.

Testing:

- Booted into Versatile Express QEMU (ARMv7), Ux500 full
  graphic UI (PostmarketOS Phosh, ARMv7 on hardware,
  Gemini ARMv4 on hardware. No special issues.

- Tested some ptrace/strace obviously, such as issuing
  several instances of "ptrace find /" and let this scroll
  by in the terminal over some 10 minutes or so.

- Turned on RCU torture tests and ran for a while. Seems
  stable and the test outputs look normal.

- Ran stress-ng, which triggers the idle bug below that also
  appear during boot.

- perf top doesn't give any output, I don't really know how
  to enble interesting stuff in the kernel to run this
  tool. Help needed.

Potential bugs:

- This comes up during boot and stress-ng runs:

  ------------[ cut here ]------------
  WARNING: CPU: 0 PID: 0 at kernel/context_tracking.c:128
  ct_kernel_exit+0xf8/0x100
  CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Not tainted 6.12.0-rc1+ #31
  Hardware name: ARM-Versatile Express
  (...)

  It is emitted in kernel/context_tracking.c, ct_kernel_exit():
  WARN_ON_ONCE(ct_nmi_nesting() != CT_NESTING_IRQ_NONIDLE);

  I don't know exactly what's going on here, but it happens right
  after CPU1 is brought online at boot, so there might be some unexpected
  nesting of IPI:s happening when CPU1 is brought up?

Open questions:

- Generic entry requires PTRACE_SYSEMU and PTRACE_SYSEMU_SINGLESTEP
  to be defined. I added them but don't even know what they
  do or if generic entry magically adds support for them
  (probably not) so I need help here.

- I need Al Viro's input on how to deal with the "fast syscall
  restart" that I bluntly deleted, if we need to reincarnate it
  in the generic entry or what we shall do here.

- I need to test with an OABI rootfs.

- Performance impact. If this is major I think it's a no-go, we need
  to agree on metrics here however and I need suggestions on what
  to test with.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
Linus Walleij (28):
      ARM: Prepare includes for generic entry
      ARM: ptrace: Split report_syscall()
      ARM: entry: Skip ret_slow_syscall label
      ARM: process: Rewrite ret_from_fork i C
      ARM: process: Remove local restart
      ARM: entry: Invoke syscalls using C
      ARM: entry: Rewrite two asm calls in C
      ARM: entry: Move trace entry to C function
      ARM: entry: save the syscall sp in thread_info
      ARM: entry: move all tracing invocation to C
      ARM: entry: Merge the common and trace entry code
      ARM: entry: Rename syscall invocation
      ARM: entry: Create user_mode_enter/exit
      ARM: entry: Drop trace argument from usr_entry macro
      ARM: entry: Separate call path for syscall SWI entry
      ARM: entry: Drop argument to asm_irqentry macros
      ARM: entry: Implement syscall_exit_to_user_mode()
      ARM: entry: Drop the superfast ret_fast_syscall
      ARM: entry: Remove fast and offset register restore
      ARM: entry: Untangle ret_fast_syscall/to_user
      ARM: entry: Do not double-call exit functions
      ARM: entry: Move work processing to C
      ARM: entry: Stop exiting syscalls like IRQs
      ARM: entry: Complete syscall and IRQ transition to C
      ARM: entry: Create irqentry calls from kernel mode
      ARM: entry: Move in-kernel hardirq tracing to C
      ARM: entry: Add FIQ/NMI C callbacks
      ARM: entry: Convert to generic entry

 arch/arm/Kconfig                    |   1 +
 arch/arm/include/asm/entry-common.h |  66 ++++++++++++
 arch/arm/include/asm/entry.h        |  17 +++
 arch/arm/include/asm/ptrace.h       |   8 +-
 arch/arm/include/asm/signal.h       |   4 -
 arch/arm/include/asm/stacktrace.h   |   2 +-
 arch/arm/include/asm/switch_to.h    |   4 +
 arch/arm/include/asm/syscall.h      |   7 ++
 arch/arm/include/asm/thread_info.h  |  18 +---
 arch/arm/include/asm/traps.h        |   2 +-
 arch/arm/include/uapi/asm/ptrace.h  |   2 +
 arch/arm/kernel/Makefile            |   5 +-
 arch/arm/kernel/asm-offsets.c       |   1 +
 arch/arm/kernel/entry-armv.S        |  39 +++----
 arch/arm/kernel/entry-common.S      | 202 ++++++++++++++----------------------
 arch/arm/kernel/entry-header.S      | 108 +++++--------------
 arch/arm/kernel/entry.c             |  59 +++++++++++
 arch/arm/kernel/process.c           |  22 +++-
 arch/arm/kernel/ptrace.c            |  76 --------------
 arch/arm/kernel/signal.c            |  57 ++--------
 arch/arm/kernel/syscall.c           |  31 ++++++
 arch/arm/kernel/traps.c             |   2 +-
 22 files changed, 349 insertions(+), 384 deletions(-)
---
base-commit: e1dc5c87445c608a99e508fe4d3102e2b32858ef
change-id: 20240903-arm-generic-entry-ada145378bbe

Best regards,
-- 
Linus Walleij <linus.walleij@linaro.org>


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53])
	(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 006521BE874
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:33:45 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560027; cv=none; b=eDQyintHSK3cJ2gOc6C95ZVrOpGgieawFIKmjIwESbNeQdoPKrV6xXbr5tPu4+5Di26pu5vRx/6gV053YZxrB+PBXBiz79Sf3CWok1iKPePl9LBNeuVmJUmRCpV+CHKqsKXEYKZK6qEqRUIuhxxjRurVBeEH8GQ/abZSf/xKhFs=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560027; c=relaxed/simple;
	bh=EKV+QYYhMEK5XzmL1kz1mpSXJHzUUDAUOm6h5P/l9LI=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=A+5XUVPh+i7kcf7dxDeAJP0PIFw85B+p1pcIL4+p35hcQgM1sKF3vclEO6+AeHxbO6Syr3RglH1NLsg5UpUOQWxW9yIwbUZE3bYAgQJrTKJJMgVw/LFoH/I5BCV5TJzZ3c4co8Sv6CI7VbHWhXlAp1/2EGHeDwbEPht6pTXqcsE=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=k+RM+Zcy; arc=none smtp.client-ip=209.85.167.53
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="k+RM+Zcy"
Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-53997328633so1191989e87.3
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:33:45 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560024; x=1729164824; 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=2ECqHBAN3rDV9yo1zqeLO+ji9lVIoh6IkMKI7b6YgP4=;
        b=k+RM+ZcyZ9/TOy9ZGFZwWldRneAsKAbIJNkfj9uiTpeA4K02LPFee1Msr2Y82uod6J
         uFZTnAbYC+SBgR7UKEwV3xVBFZTRYPDWfz0g02y21Eun0WV4JvgxWrC7e9k9AIhaUtvA
         AaycTz2svptOYMSPlXPCHZWkgsb1eEM39iLK8ch+ocsAst/zy1/QbDEOLibClSN2xjwx
         lCeA5ZqlfV8z67LvNgolKrYoUvDqjPO27F/mE+aXm9ZzCVEQSBtvsbwmL3S3qaFo4cGO
         DA7hdVNFNiQC2vW/kQq9AeHpeOZxpL7LAOmXQkiZeqvkZa147TP73qlizpYlWgEjOb49
         34rA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560024; x=1729164824;
        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=2ECqHBAN3rDV9yo1zqeLO+ji9lVIoh6IkMKI7b6YgP4=;
        b=do21xVEvFI1+UcO3s2BNQ2SbekwlgRi78P514oXGGwa78BGLLSpUhAnrkTYwcMw3RA
         c3VovxiZkl/TJDOZjISmlRUfPfcepnTxT9nr5ZlOnJvB1uKFPq8yC5P8CHNPtI274qra
         HU4ciaGV9GdTqOVeberKM5E3Ach/YH3TxkA62g2SunRu7Ophc75GDDPuefx+/kIw8C6k
         mGycXaTllQDToTiHX6AYz6JX6milxZL9SHoWUWEto5IfFu92mbhFw+Zg1Y5pt8DoL5Lh
         6phdATqm+3MmPUK16JjWfxixO8nZp3H6jF2RYf++GQkE7XC/yhe5XKQ+37WkRE1Id+ux
         XNyQ==
X-Forwarded-Encrypted: i=1; AJvYcCWZF1FpGCzM5pl38T/fFlnsstmbSUOnk4naFVUcFlYRBwxM6A0d+nhqAdcaneBiMGwuOOPKZTT1ZyinKYg=@vger.kernel.org
X-Gm-Message-State: AOJu0Yxlgku9vVsvkzz92r5I9FdTnYBenQry+WBZxMEvMEDYEEfHoMHV
	xufI8EeG+ooo0upICV9Bx9Cr/6wwjCZsG4mcwTJXECcNY2snbCk1hDfeLvobT3M=
X-Google-Smtp-Source: AGHT+IEzOwjSeRaNRAgIP2djHbcgDjxIdas3zeUxGw2eRXDLl+1CJu9P76G7kqLMU7BvW+xxCPu7BQ==
X-Received: by 2002:a05:6512:31ca:b0:52c:e17c:cd7b with SMTP id 2adb3069b0e04-539c489fecdmr5606542e87.22.1728560023941;
        Thu, 10 Oct 2024 04:33:43 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.42
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:33:42 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:39 +0200
Subject: [PATCH RFC 01/28] ARM: Prepare includes for generic entry
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-1-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

The generic entry code needs a static inline function for
regs_irq_disabled() so add this, in further requires the signature
of on_thread_stack() to be __always_inline so add this as
well.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/include/asm/ptrace.h     | 5 +++++
 arch/arm/include/asm/stacktrace.h | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/ptrace.h b/arch/arm/include/asm/ptrace.h
index 6eb311fb2da0..a01c66f0ad90 100644
--- a/arch/arm/include/asm/ptrace.h
+++ b/arch/arm/include/asm/ptrace.h
@@ -52,6 +52,11 @@ struct svc_pt_regs {
 #define fast_interrupts_enabled(regs) \
 	(!((regs)->ARM_cpsr & PSR_F_BIT))
 
+static inline int regs_irqs_disabled(struct pt_regs *regs)
+{
+	return !interrupts_enabled(regs);
+}
+
 /* Are the current registers suitable for user mode?
  * (used to maintain security in signal handlers)
  */
diff --git a/arch/arm/include/asm/stacktrace.h b/arch/arm/include/asm/stacktrace.h
index f80a85b091d6..815b5f256af1 100644
--- a/arch/arm/include/asm/stacktrace.h
+++ b/arch/arm/include/asm/stacktrace.h
@@ -26,7 +26,7 @@ struct stackframe {
 #endif
 };
 
-static inline bool on_thread_stack(void)
+static __always_inline bool on_thread_stack(void)
 {
 	unsigned long delta = current_stack_pointer ^ (unsigned long)current->stack;
 

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49])
	(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 AD94B1C32EC
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:33:47 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560029; cv=none; b=hsOasugBai2D5n+fS3nmfO3/hV12AY/OklAu78WuPdqX2kcwWgYASY/tnYjfYYJ8DDf7LivAI4cWuSpaXivgAgPtHgtJff5jR2yXgusJU2knEL4aUIWj++AuiEXt+95mYs+uuPiqWfFBGau91DZ6GOldo6FKP+IIA1jLht7+0Ik=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560029; c=relaxed/simple;
	bh=0u2mldWq4lrnYPUiJZwplGdYFoRn/IGd4Af409B6kLE=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=P6oAVDFEIL0Imo+HVLIoJ1B1CHWYXySLzbs4HHYuU/ePBUlc1IoHax4BFWO/kmz/ouclN5hRUsxnL0kNAWeBF0m52Sw3v3k8F3mgfBshZwnttYGJITgUNgltHboQZhAPJz3Zzqkv6NrINYliO+x4P+xC3hJti4+teMcrwCKubGA=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=meuoJII3; arc=none smtp.client-ip=209.85.218.49
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="meuoJII3"
Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a9952ea05c5so135409366b.2
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:33:47 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560026; x=1729164826; 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=R4LTFu04v+ewJrCMf1qStO/yKKemj/dlkSOHqQ2h8u0=;
        b=meuoJII3VbN6cv+9I18IbBSiTZrVSn/lExOstWwCNmU8aIYkQD22xGENCIIg74Nfw8
         5xI5XIOCcNCo5xQNjXmijAwF9ePU6VY0pG81DqoFCnAoB7RORzvBKiTshw9tcGFP180+
         ZsikS10OvRWpe7SY+tyHbtUNp7wJwhV6RXlp81Gv/RR/1C+eoSUXhPF316j4tmPJUpYv
         lTK+utYG7tzFMAAqOR7IFJJQiqXjVGhDBMAEp9h/alrQixOLS+BE/8bY3+B7LqBRM/JK
         47l6GP1Is/dDwWH7zOoo7GClrWjnRbNIruQCcoajyfcbVXrBfWAzCrLWNrP1ILS4zHsm
         kiSg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560026; x=1729164826;
        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=R4LTFu04v+ewJrCMf1qStO/yKKemj/dlkSOHqQ2h8u0=;
        b=cAIwmrGawZ+jz1vn8kMbPNWBckcM11VEND1bWDkOnZLjen0ivVWCDagmCYM4ZlSL60
         7xCiDnUMTJVIZc+1jrAwrXaAUy5xJEKvhsHgmVGFRta5fZdNeu1x2DZ9RxFD3tSdjLzS
         4Y3SOKgENkrsaYpiwSk9nrAi4oqCgW/fUazqxz9Qiyi5n5s+0VrxKp6jbK5/XA7nM+ng
         1cSt0VRTeOBHawqurSgcK/WRxGVE5gPh/BYlQeaa9uYy7lvCa8zgz7Knb4a7u+QPVyYF
         oJwRwIgULFMfzWrM/PYxytblERNK4u8r5AZbl0llymMCv0Wc6k9bdyz5drWjGbQ+ttfF
         MaLA==
X-Forwarded-Encrypted: i=1; AJvYcCVHrVHwYJOojEgaUlSFk8X5ReC5CQmzHoh3C6e6MYlCuv3Tuf/93Oda77juVlj62xi4jpLe9D7FKRhRauU=@vger.kernel.org
X-Gm-Message-State: AOJu0Yyy2shHn8FumK41bg4IHX3hErs692/MFWKDc0fEZmnkzv4sfN7x
	UQakyRdm0WblyzjTwo+rl7nbe1QSCtpbTnJfTKMMSBOie7cTKgLrsetrmAOF9ZM=
X-Google-Smtp-Source: AGHT+IF/7BdKriGHfpakAch78gEDyPg7g4F5Squ3DH3oytxrvyGsFjm+zrnSb3mJBDsLPEmr+DbRWQ==
X-Received: by 2002:a17:907:7e84:b0:a99:62a4:3fc1 with SMTP id a640c23a62f3a-a998d315001mr502326466b.49.1728560026025;
        Thu, 10 Oct 2024 04:33:46 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.44
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:33:44 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:40 +0200
Subject: [PATCH RFC 02/28] ARM: ptrace: Split report_syscall()
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-2-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

The generic entry code requires that report_syscall() be provided
in two parts: report_syscall_enter() and report_syscall_exit()
so split the combined function in two.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/kernel/ptrace.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
index c421a899fc84..07b0daf47441 100644
--- a/arch/arm/kernel/ptrace.c
+++ b/arch/arm/kernel/ptrace.c
@@ -827,31 +827,45 @@ enum ptrace_syscall_dir {
 	PTRACE_SYSCALL_EXIT,
 };
 
-static void report_syscall(struct pt_regs *regs, enum ptrace_syscall_dir dir)
+static void report_syscall_enter(struct pt_regs *regs)
 {
 	unsigned long ip;
 
 	/*
 	 * IP is used to denote syscall entry/exit:
-	 * IP = 0 -> entry, =1 -> exit
+	 * IP = 0 -> entry
 	 */
 	ip = regs->ARM_ip;
-	regs->ARM_ip = dir;
+	regs->ARM_ip = PTRACE_SYSCALL_ENTER;
 
-	if (dir == PTRACE_SYSCALL_EXIT)
-		ptrace_report_syscall_exit(regs, 0);
-	else if (ptrace_report_syscall_entry(regs))
+	if (ptrace_report_syscall_entry(regs))
 		current_thread_info()->abi_syscall = -1;
 
 	regs->ARM_ip = ip;
 }
 
+static void report_syscall_exit(struct pt_regs *regs)
+{
+	unsigned long ip;
+
+	/*
+	 * IP is used to denote syscall entry/exit:
+	 * IP = 1 -> exit
+	 */
+	ip = regs->ARM_ip;
+	regs->ARM_ip = PTRACE_SYSCALL_EXIT;
+
+	ptrace_report_syscall_exit(regs, 0);
+
+	regs->ARM_ip = ip;
+}
+
 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
 {
 	int scno;
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE))
-		report_syscall(regs, PTRACE_SYSCALL_ENTER);
+		report_syscall_enter(regs);
 
 	/* Do seccomp after ptrace; syscall may have changed. */
 #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
@@ -892,5 +906,5 @@ asmlinkage void syscall_trace_exit(struct pt_regs *regs)
 		trace_sys_exit(regs, regs_return_value(regs));
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE))
-		report_syscall(regs, PTRACE_SYSCALL_EXIT);
+		report_syscall_exit(regs);
 }

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46])
	(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 C51AF1C3F28
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:33:49 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560031; cv=none; b=fw2XkPiRVT6+ibDXyPNhbN7GiXvn4IRs+YStjbNQZtK1QHLA3utr9QGUjNiQI6g+CwyAW4hxU15/BvAUUsmj71OidMzJobpj+b//TTxAXi0ZSA1k/9fZLemkG7eOQ2IMwRSgNZurQExKEwwmbpZsY+kYMUhtXrX0dvInEnJ5pYs=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560031; c=relaxed/simple;
	bh=F4l5jY4Wqe+bOqNg1KeOS2Pb/rQnbpWuqlfxyr64WII=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=j+C7O/nKQHPETAPUfMjNlJWrY0ZqiS7nvDc52647nRX27zUmKRO6WDNtkQnSwz1eGkO+vxYhEX80884wYRimuHl2x4xndq3BaCeN1lEf2AgRZYIJfAqgLvoVCZmCbWXWXU+tQCFa+UgENQPGGA/VDShgKdzm2qV5MsuhAf5XsMI=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=obBaYvyS; arc=none smtp.client-ip=209.85.208.46
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="obBaYvyS"
Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5c903f5bd0eso1046351a12.3
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:33:49 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560028; x=1729164828; 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=OxEtYMLSB1QX4C5qcE83rstSx0FEcAVbxyG1Gu9/c1s=;
        b=obBaYvySisvaa6lKRRxFTPets1IJkbEA/05bbdXKi5kdLXiYGHL67J2uEHianpqVjX
         9C8R6W2SXJmIrmnE8wq4oqzNau+LtNVw/anXlYq92UoZtI0BgdP+MGiaJ65w+ixl0Kjb
         AggvSuAU7FmQkeMnGJLhPeTD2CLfPRN/7pbFwMdQzuIvMCGqAx8nnk7pwZ5GNglT0D5H
         HA/e0JpkXIgStxwMZ0eApsqAXtlmR9Afp59LNAeZI/oG32KJbe4pTYRBRo7/uwLBth3+
         0OMyWMqKH4SYHUDs0WVnSlIeTCGr8/DLBZD1jmmYnln4Ewvb5BHStKgVJ6rwO+YHA7e6
         cuUg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560028; x=1729164828;
        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=OxEtYMLSB1QX4C5qcE83rstSx0FEcAVbxyG1Gu9/c1s=;
        b=Um0oB7MUIOqupQYWvKQSCsb3QBolj7OnYyMXrln+9dTRTAXyK+cjD3fmx4xmFZ7JXI
         EOvgQzwH+xSpbjaNLS8PNYou3UuvzkXgJ0iAKbM5+UQ5xWQu7K3Q0b7UJ7iL0B2h2Hcz
         nPv4g60UaKFhpN0K2WilqrJK7J2CMcXWGRGgHiBShOfSYl8EF5l1EvHC7+KJJ31zhlwJ
         ihCG7zfJTV89ttADHZaDuAU4wEh7tZN4gnM3S+eNRKKEDIOIUTgZFxksQOEgP1YcKJwa
         59G7CuIX/ggm6iByNnE1omicCPJa+MmMlaHdPBL3m7DBdv/xi1qaFpqQU9fr4ijUXm0G
         oB3A==
X-Forwarded-Encrypted: i=1; AJvYcCXnqpox4ib/FbaQNI0g70GO9kFgsix0ZD1EDhTs5bz8mCFgHAaVooMbnEIQnubv5OvRJ+EmXrzQOHYIa4U=@vger.kernel.org
X-Gm-Message-State: AOJu0Yz6yI5qDK4M8uJXsOSQAqNo41JE5AFhl47Gd418CU8/ajx2KNWL
	P9T7+MrF1XYsT3cKxqCA2khif316B8Axue4H89+y0kQB5umOzhrox0QlwKH9Dh0=
X-Google-Smtp-Source: AGHT+IGmKNJPIbWGBVZJfO8+b8zw8XAoQP29rf5wbFh2YjSEj93didfv6G/hdQTs2PTJu3Y9jhUpkw==
X-Received: by 2002:a17:907:360d:b0:a99:adc1:1432 with SMTP id a640c23a62f3a-a99adc11551mr84023666b.65.1728560028080;
        Thu, 10 Oct 2024 04:33:48 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.46
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:33:46 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:41 +0200
Subject: [PATCH RFC 03/28] ARM: entry: Skip ret_slow_syscall label
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-3-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

Don't introduce this extra label anymore now that we have
a clearly defined entry point for ret_to_user.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/kernel/entry-common.S | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index f379c852dcb7..2f93c2f6d5b8 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -102,7 +102,6 @@ ENDPROC(ret_fast_syscall)
  * do_work_pending() will update this state if necessary.
  */
 ENTRY(ret_to_user)
-ret_slow_syscall:
 #if IS_ENABLED(CONFIG_DEBUG_RSEQ)
 	/* do_rseq_syscall needs interrupts enabled. */
 	enable_irq_notrace			@ enable interrupts
@@ -136,7 +135,7 @@ ENTRY(ret_from_fork)
 	badrne	lr, 1f
 	retne	r5
 1:	get_thread_info tsk
-	b	ret_slow_syscall
+	b	ret_to_user
 ENDPROC(ret_from_fork)
 
 /*=============================================================================
@@ -310,13 +309,13 @@ __sys_trace_return_nosave:
 	enable_irq_notrace
 	mov	r0, sp
 	bl	syscall_trace_exit
-	b	ret_slow_syscall
+	b	ret_to_user
 
 __sys_trace_return:
 	str	r0, [sp, #S_R0 + S_OFF]!	@ save returned r0
 	mov	r0, sp
 	bl	syscall_trace_exit
-	b	ret_slow_syscall
+	b	ret_to_user
 
 	.macro	syscall_table_start, sym
 	.equ	__sys_nr, 0

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181])
	(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 1E6A31C4616
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:33:51 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560034; cv=none; b=qki3yZatpqLNTSfoeYGC1dG+uSmOOfcHQu1Qe2/GZGOF4PNSeu9+D59YB62Qm2bcuBwibrDYjZZcbJnSS0T9IVgl8QUx44u7Z7IRfRsMyC/HS0r6pHjRCm6PdDT+0uXxiN6PwvxOHj4wDOyltDbPKymRh0jHa6nV4azXwNOOFVM=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560034; c=relaxed/simple;
	bh=HgpuQCGct+VCXYretZz57uSNbkNJ0GIymihuDxTTfNw=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=cE2YHY9FjUdBzOzgEaNJEQOR1WklqudfmwrD2z/Nb/r2vNgljHtlfpzmYp9lRDKi2HcMdKhEmkbl7+7q4IEHp7FPPwxIw0Qr7CKkhZm5sOKdgIiASXNB/YwzpDCDD0gpzFno5443QDHDPAfQZ9ChLFiH65jxAdni1ArnK7C87jU=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=kq2qMXyE; arc=none smtp.client-ip=209.85.208.181
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="kq2qMXyE"
Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2fac6b3c220so12352001fa.2
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:33:51 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560030; x=1729164830; 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=TDl9iLJ9IcIQCUiDPdY7G7jOst94Sq4L5J+um8W/x4k=;
        b=kq2qMXyEtyL9KuI9wUVnuxiIUf0sWEap56hCMBAAMQZVRQI9YZXZ7TO0YJJnd7QTWE
         MV1ZdNN9h7Uzw4X8mIU2x4Y54CMPJsNXW5lZiiMIh52OU25hWP+UextpcoTKWrxej7Vy
         3QF84z36b2H8wMeZMfTccoAo/xZl79xozVsNmlh/SF5UgC7ik4QGXSzdoSzs04KkXAvv
         j1jyIllFF1EA+h/KX9Uls+mxJHUY6P5vc81GYiy1xE6VY5oOzgi9QYNfOCRXvmuunecC
         mijvzoSrtwPJIHhLLECRdKIPso1RTadni4L23zxjeq+d5Dko7dQ6bJajJYmy5u4lXQnx
         ZiYg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560030; x=1729164830;
        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=TDl9iLJ9IcIQCUiDPdY7G7jOst94Sq4L5J+um8W/x4k=;
        b=xH3vdtmh7CyLtzYUaY7cvSJ5It4vAWiSLDirQuc0l6agHYwPTGR8iOyOl5HEQxmyCs
         udkpjMus/zMT91tglYioFASJum0O4mtQwS+XClx+CHfOhuupcma5Gn7dkl/nZjr6FTSJ
         K4mUbuiKxh9ZCVBsAVeVZ1dUK16FUdAWOCYldazNecHeS8HvQ+V6NsigLzXOvINBL6Gx
         GbsLead8TbIijztwc676w39JCs7LzF7BkY/keD9wvDY0zdE/qxfshfZ+iFzIqyRnN0/x
         lQOT5st4+I2qcqAxN1djZ+mgoeRXDkWCTns0HxEy415u0TegBU2LPZG/J1I9Icveow/d
         ODsQ==
X-Forwarded-Encrypted: i=1; AJvYcCXUnpwmBsnYBnVvedmR747VBBGB1nXkyKM7MxODi1G+DKxyr/G58//kfpwIh1talrNX4wTU3aLMPiPgEqs=@vger.kernel.org
X-Gm-Message-State: AOJu0YxQko9yjoqaBRaZ2kvAcyijLblnx65DwyCWWHklD3A6EmrxcOjs
	QvnPEr/j2hYKv4yQbVDP3E/fpehiIGQQYcqpkPHVZwjn8BcosQL4/w1RpaUc9nk=
X-Google-Smtp-Source: AGHT+IFYXNUhaWmpiLq2q8xgds0Kykd3WYlCfTU5AddMN69mncHRj5KixgWaFupTNP5HEIlSrViaww==
X-Received: by 2002:a2e:b8cb:0:b0:2f3:f1ee:2256 with SMTP id 38308e7fff4ca-2fb18807a65mr56092621fa.44.1728560030103;
        Thu, 10 Oct 2024 04:33:50 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.48
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:33:48 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:42 +0200
Subject: [PATCH RFC 04/28] ARM: process: Rewrite ret_from_fork i C
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-4-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

Move the direct assembly call to schedule_tail() and the
call starting a kernel thread into a C version of ret_from_fork()
in process.c and rename the old ret_from_fork to ret_from_fork_asm
following the pattern in x86.

Leave a comment on what we will do when we get to switching to
generic entry with this as a base.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/include/asm/switch_to.h |  4 ++++
 arch/arm/kernel/entry-common.S   | 22 +++++++++++++++-------
 arch/arm/kernel/process.c        | 24 ++++++++++++++++++++++--
 3 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/arch/arm/include/asm/switch_to.h b/arch/arm/include/asm/switch_to.h
index 9372348516ce..18d084aff5a4 100644
--- a/arch/arm/include/asm/switch_to.h
+++ b/arch/arm/include/asm/switch_to.h
@@ -17,6 +17,10 @@
 #define __complete_pending_tlbi()
 #endif
 
+asmlinkage void ret_from_fork_asm(void);
+__visible void ret_from_fork(struct task_struct *prev, struct pt_regs *regs,
+			     int (*fn)(void *), void *fn_arg);
+
 /*
  * switch_to(prev, next) should switch from task `prev' to `next'
  * `prev' will never be the same as `next'.  schedule() itself
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index 2f93c2f6d5b8..df6961a1006b 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -5,6 +5,7 @@
  *  Copyright (C) 2000 Russell King
  */
 
+#include <linux/cfi_types.h>
 #include <asm/assembler.h>
 #include <asm/unistd.h>
 #include <asm/ftrace.h>
@@ -128,15 +129,22 @@ ENDPROC(ret_to_user)
 /*
  * This is how we return from a fork.
  */
-ENTRY(ret_from_fork)
-	bl	schedule_tail
-	cmp	r5, #0
-	movne	r0, r4
-	badrne	lr, 1f
-	retne	r5
+SYM_TYPED_FUNC_START(ret_from_fork_asm)
+	/*
+	 * ret_from_fork() expects:
+	 * r0: prev
+	 * r1: regs
+	 * r2: fn() for kernel process or NULL
+	 * r3: fn_arg for kernel process or N/A
+	 */
+	mov	r1, sp
+	mov	r2, r5
+	mov	r3, r4
+	bl	ret_from_fork
+	mov	r0, #0
 1:	get_thread_info tsk
 	b	ret_to_user
-ENDPROC(ret_from_fork)
+SYM_FUNC_END(ret_from_fork_asm)
 
 /*=============================================================================
  * SWI handler
diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
index e16ed102960c..81c1c3f98834 100644
--- a/arch/arm/kernel/process.c
+++ b/arch/arm/kernel/process.c
@@ -29,6 +29,7 @@
 #include <asm/processor.h>
 #include <asm/thread_notify.h>
 #include <asm/stacktrace.h>
+#include <asm/switch_to.h>
 #include <asm/system_misc.h>
 #include <asm/mach/time.h>
 #include <asm/tls.h>
@@ -230,7 +231,26 @@ void flush_thread(void)
 	thread_notify(THREAD_NOTIFY_FLUSH, thread);
 }
 
-asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
+/* The assembly stub sets up the parameters and calls ret_from_fork() */
+asmlinkage void ret_from_fork_asm(void) __asm__("ret_from_fork_asm");
+
+__visible void ret_from_fork(struct task_struct *prev, struct pt_regs *regs,
+				     int (*fn)(void *), void *fn_arg)
+{
+	schedule_tail(prev);
+
+	/* Is this a kernel thread? */
+	if (unlikely(fn)) {
+		fn(fn_arg);
+		/*
+		 * A kernel thread is allowed to return here after successfully
+		 * calling kernel_execve().  Exit to userspace to complete the
+		 * execve() syscall.
+		 */
+	}
+
+	/* syscall_exit_to_user_mode(regs); here once we switch to generic entry */
+}
 
 int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
 {
@@ -263,7 +283,7 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
 		thread->cpu_context.r5 = (unsigned long)args->fn;
 		childregs->ARM_cpsr = SVC_MODE;
 	}
-	thread->cpu_context.pc = (unsigned long)ret_from_fork;
+	thread->cpu_context.pc = (unsigned long)ret_from_fork_asm;
 	thread->cpu_context.sp = (unsigned long)childregs;
 
 	clear_ptrace_hw_breakpoint(p);

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47])
	(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 1420B1C5781
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:33:53 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560035; cv=none; b=LizaUI/2xcmHcuTwV+OfJixNvuecPAZl56ksiTmqVfyQ7SX9xko13bkqP23QuTuUQP4jMthHD/3Oqhef8Ci/aUnl4HA8ynegRSmvSR1Js4vSOfP+D/fUBpH7bvwlawAV+s7PdDwLhAK5Y9K8py2B0GUMBoqBm6wDYTya47Mo+Jc=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560035; c=relaxed/simple;
	bh=TXjj9xFMQ8ObJncCvfOXEQyxyh4pdr8dOD7N4vVAW1Y=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=lc6flr7DlK8iuC1Y8YKtvowWheJavyeudYhJQZnLg4l5SPnw5F07JXPTcNauf+du9TOyl4h/q5ZYUG+9kc1xd7PwitSw3VQGe7DQ15zGBYIIlGLscRznCuQ/2PkaAFNVCeoqfQsSey8Y5S5RwsD0f7Er0rJZjHy7w/Mf7ZoSG3w=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=F34EPHzy; arc=none smtp.client-ip=209.85.218.47
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="F34EPHzy"
Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a994c322aefso354079166b.1
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:33:53 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560032; x=1729164832; 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=FhwutFaJAhBwzUvxWfpVZxdfXLNUR2eiL6c/Y41YU9M=;
        b=F34EPHzyhAwnyesUBY+juUf5aVrU2ynaPG6OMmjt5jmThnLS/XMCkx+hoSpnLW5THD
         yPFvL11j3yL0qSgwpcoRpJY6JXM6BYnTYGrGQVjGJqRdvGsu0B9hXVZm0xSh6WEs3rwO
         teEC8h/tgRPXWcK1DPVgWKUwbf4s1N5mkrKAI0Lhk+brW6JRe/z+EEk2xQm72fk/kAmb
         ZS/T1NJwnOvfKg9rqfobenXk2dFrqPKn5IAMrUFoTZgP8Fgxcuxcnr6oXaaad/ADUAkv
         zw5bP995Etp5B/PAfu0o+zfBXEmD6VXgpJdxAYk6MXKF7mDzu4aI8XIgQ26k5ZCJC/jo
         Fz6g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560032; x=1729164832;
        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=FhwutFaJAhBwzUvxWfpVZxdfXLNUR2eiL6c/Y41YU9M=;
        b=wejiNae+bMAZcZKY2+loDHScDABxB5DsUdmwMbJfuyl2PGIzdKquGU9UaumVq9AVfc
         9vPJa9u/+BF26mvcSlFsHBFNJzhbOqv1NTbgT7RTGEgyTBu1hFqRbYgcrmYjWVmG5TOI
         4FHtqM4G8NFddEQ762rLdxc5Nehj3n8iPe/rbvYfBJ55D961Y2lrijbxH8tDwQaGzx0l
         +7JyGR1daiQBdv0ao7A6JNWeR9xYNzO5cFhi87nd5LWFEtWN6xhf+IAS1FV94dGByoFd
         b29YwGKQYYNc6eSmI5ZLwFr4FqRu+1DF+R0PKE9kHeZ4yq1qTW0hoBMfggaoQibszv5g
         pOcw==
X-Forwarded-Encrypted: i=1; AJvYcCUmezkf2LZk9SIX3fw9vN+MkaL2p6EcA4SYSV608LR55yYjfYlbGHbranl1ny4J9vjbuSJrtH/yOViAMSE=@vger.kernel.org
X-Gm-Message-State: AOJu0YweX8rs44tqA6s0UCPhRsHGFXXtLxgHyDGZO8XAlc1bjZCG7uhz
	yct4tNPtN4X72VZdVDQKWVbdGEDDq4qDaRXDM4xG/dHFxkZawy9FzB22w0q8D6Y=
X-Google-Smtp-Source: AGHT+IFaoE3sZWLkTplU7TDESmJsAO9u+n0GW9GsY4BElZ/Wg4eEpzfSZ1AqFssYL+f+8cp61QXAgw==
X-Received: by 2002:a17:906:6a11:b0:a86:8f9b:ef6e with SMTP id a640c23a62f3a-a99a10f7328mr306580766b.13.1728560032206;
        Thu, 10 Oct 2024 04:33:52 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.50
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:33:50 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:43 +0200
Subject: [PATCH RFC 05/28] ARM: process: Remove local restart
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-5-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

The ARM kernel contains a quirk to handle syscall restarts
inside the kernel without exiting to userspace. The generic
entry cannot handle this.

Rename do_signal() to arch_do_signal_or_restart() to fit
with the upcoming generic entry conversion.

This is essentially a revert of commit 81783786d5cf
"ARM: 7473/1: deal with handlerless restarts without leaving the kernel"
from 2012.

Other solutions may be possible, such as checking the PC after
do_work_pending and assume it is a local restart if that address
is inside the kernel, or modifying the generic entry code to
track local restarts like ARM does and pass that information
back.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/include/asm/signal.h  |  3 +--
 arch/arm/kernel/entry-common.S |  9 +--------
 arch/arm/kernel/signal.c       | 28 +++++++++-------------------
 3 files changed, 11 insertions(+), 29 deletions(-)

diff --git a/arch/arm/include/asm/signal.h b/arch/arm/include/asm/signal.h
index 8b84092d1518..7acccc96840c 100644
--- a/arch/arm/include/asm/signal.h
+++ b/arch/arm/include/asm/signal.h
@@ -24,7 +24,6 @@ typedef struct {
 #include <asm/sigcontext.h>
 
 void do_rseq_syscall(struct pt_regs *regs);
-int do_work_pending(struct pt_regs *regs, unsigned int thread_flags,
-		    int syscall);
+void do_work_pending(struct pt_regs *regs, unsigned int thread_flags);
 
 #endif
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index df6961a1006b..da5c2d4b62e5 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -86,14 +86,8 @@ ENDPROC(ret_fast_syscall)
 	bne	__sys_trace_return_nosave
 slow_work_pending:
 	mov	r0, sp				@ 'regs'
-	mov	r2, why				@ 'syscall'
 	bl	do_work_pending
-	cmp	r0, #0
-	beq	no_work_pending
-	movlt	scno, #(__NR_restart_syscall - __NR_SYSCALL_BASE)
-	str	scno, [tsk, #TI_ABI_SYSCALL]	@ make sure tracers see update
-	ldmia	sp, {r0 - r6}			@ have to reload r0 - r6
-	b	local_restart			@ ... and off we go
+	b	no_work_pending
 ENDPROC(ret_fast_syscall)
 
 /*
@@ -266,7 +260,6 @@ ENTRY(vector_swi)
 	 */
  TRACE(	ldmia	sp, {r0 - r3}		)
 
-local_restart:
 	ldr	r10, [tsk, #TI_FLAGS]		@ check for syscall tracing
 	stmdb	sp!, {r4, r5}			@ push fifth and sixth args
 
diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
index 79a6730fa0eb..7b1a16e86b23 100644
--- a/arch/arm/kernel/signal.c
+++ b/arch/arm/kernel/signal.c
@@ -18,6 +18,7 @@
 #include <asm/traps.h>
 #include <asm/unistd.h>
 #include <asm/vfp.h>
+#include <asm/syscall.h>
 #include <asm/syscalls.h>
 
 #include "signal.h"
@@ -534,9 +535,10 @@ static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
  * the kernel can handle, and then we build all the user-level signal handling
  * stack-frames in one go after that.
  */
-static int do_signal(struct pt_regs *regs, int syscall)
+static void arch_do_signal_or_restart(struct pt_regs *regs)
 {
 	unsigned int retval = 0, continue_addr = 0, restart_addr = 0;
+	bool syscall = (syscall_get_nr(current, regs) != -1);
 	struct ksignal ksig;
 	int restart = 0;
 
@@ -590,16 +592,14 @@ static int do_signal(struct pt_regs *regs, int syscall)
 	} else {
 		/* no handler */
 		restore_saved_sigmask();
-		if (unlikely(restart) && regs->ARM_pc == restart_addr) {
+		if (unlikely(restart) && regs->ARM_pc == restart_addr)
 			regs->ARM_pc = continue_addr;
-			return restart;
-		}
 	}
-	return 0;
+	return;
 }
 
-asmlinkage int
-do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
+asmlinkage void
+do_work_pending(struct pt_regs *regs, unsigned int thread_flags)
 {
 	/*
 	 * The assembly code enters us with IRQs off, but it hasn't
@@ -612,19 +612,10 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
 			schedule();
 		} else {
 			if (unlikely(!user_mode(regs)))
-				return 0;
+				return;
 			local_irq_enable();
 			if (thread_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) {
-				int restart = do_signal(regs, syscall);
-				if (unlikely(restart)) {
-					/*
-					 * Restart without handlers.
-					 * Deal with it without leaving
-					 * the kernel space.
-					 */
-					return restart;
-				}
-				syscall = 0;
+				arch_do_signal_or_restart(regs);
 			} else if (thread_flags & _TIF_UPROBE) {
 				uprobe_notify_resume(regs);
 			} else {
@@ -634,7 +625,6 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
 		local_irq_disable();
 		thread_flags = read_thread_flags();
 	} while (thread_flags & _TIF_WORK_MASK);
-	return 0;
 }
 
 struct page *get_signal_page(void)

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43])
	(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 2272D1C462B
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:33:54 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560037; cv=none; b=sQkWwRN9fOVXIcBt8Ht9nuOIESlJtrFij1UQ6luQ+3SQ+a7ibRhdfiwqE0GALNx57UkiYcy+3ygLd09NpfBl1QM2lOMqL0E3S53e2t+tsmLAgxJI/637fqtVXYuWhqbXZpmEsm6g2yulI5uoK9s7iiW/nEcvoZ960KpBITzWw7c=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560037; c=relaxed/simple;
	bh=tX5Wma4JHUbeyuYDZTw48n7VQjwfTQwWz6WO082EFwk=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=adQQf5mp/eM0rB3CQvRNhAjWex4u4sVXQc5DqNhtAd0QPEqze6Nc2lpH+piEzYymVlcTpXyIQcRc7qNVN0TE6Uh4z5zu0Fg7eGUAPo7ZJWaJf5L7VO/AvDoRFHP5wWQiPzOEqWk5fJKzb08eRksSScc0XCvp0DHp5LvJKRhnK4E=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=WE4b99Zj; arc=none smtp.client-ip=209.85.218.43
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="WE4b99Zj"
Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a9982159d98so132436666b.1
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:33:54 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560033; x=1729164833; 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=MQAt5SKeBz56FAHiHxrYIQX+VEnQ+LorFKx32LG+SI8=;
        b=WE4b99ZjDxfTGFWEI46pw5vsjyuIC/jwDrglfSuqvY0xOZoeGeyubH8I6qrmNg8IWT
         vy+VgU8J4qx3lLTJyudvARyTRbGyIeAzqks2y2MbS4ADsqrBCuORa206uyQZiEKEmo3t
         ncIn1fEnVk2gKmEP7ujtMEF+joDNXy2R3Wp9DUFSuVM4iIb8q4pj2qBNCkatAwx8T6rZ
         4+imC9GRE1TrmfwIBKkQU5FWGPK6E5fjSIDUVPN31jvwTX8jCARKEdmEPspZ1udcFMO9
         z5qxDto4S04g7GCEGVWzCIa2jzrS+EvAsHQA5+P9zbuDFXAUDhsn7OdPtifQWN7Qzur2
         zFWA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560033; x=1729164833;
        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=MQAt5SKeBz56FAHiHxrYIQX+VEnQ+LorFKx32LG+SI8=;
        b=uQJbQpD78ucp/nu347LAttNgTlWQFcy0xzRvbfdiBQqTms54xzX5japVijYP4qg5wL
         6kI+Rky+T8ROPe4oDdqAAzk0Zxe2Trdtj73B5tBjqZJbdSWUqp+w0XBZ9LPN9PeSfuVo
         5hfp604p8VONBczyC0FqRCRpZIWAVLIsgHbkYUBKijLmlNBkBOirMyr+Is2KV+WXmXsb
         eGVrNQDn4syaKXqphtOvr+Hpu5XodJLXYaqQ8PosQEtM4Ql99xdZ4L/nxPnLJLIUHvmT
         SpChCrjZ4qJbJASoYVavQFoZtbK+cbA5VxAcpSHNeTDrb/IP0tya/6xgKJ1N2dPh9jBz
         sm+Q==
X-Forwarded-Encrypted: i=1; AJvYcCXYnXup0MSW2vMMjXMetsiCvVyV4sst0rBtdL1fuxN8Ny5Kef+az46V9RfifLtpyGWt57AxXZuiX6Flwv4=@vger.kernel.org
X-Gm-Message-State: AOJu0Yw5DNcjR/g/flyIoAYWyDyCBKXxiVMmnIxnuFty238CgqK1PE+B
	GGw3tfLRjzvnZz9B9N7vqEcl9gTfoxO4RT8p7vbKWpcvi34yq0e6Lp5vedv3cnuJJyAmijte6JI
	1
X-Google-Smtp-Source: AGHT+IECf+nIoR64vGLK0N0tRyy3m6kGQh9nhQM+SGfR2yrRMxhPLMUSOA5Znclos1a6qtcyfJhm9w==
X-Received: by 2002:a17:907:3e23:b0:a8a:78bb:1e2 with SMTP id a640c23a62f3a-a998d117c0bmr654465266b.6.1728560033384;
        Thu, 10 Oct 2024 04:33:53 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.52
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:33:52 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:44 +0200
Subject: [PATCH RFC 06/28] ARM: entry: Invoke syscalls using C
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-6-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

This makes the assembly invoking syscalls switch over to
doing this from C with a small assembly stub to actually
jump into the syscall.

Split the syscall invocation into two paths: one for plain
invocation and one for tracing (also known as "reload"
as it was reloading the registers from regs). We rename
this path with the infix "trace" as that code will be
trace-specific as we move code over to C.

Some registers such as r1 and lr get cobbled during the
C calls and need to be restored when we return.

Right now the part in C doesn't do much more than check the
syscall number to be valid (a test previously done with
a cmp r #NR_syscalls inside the invoke_syscall macro)
but we will gradually factor over more assembly to C that can
then be switched to the generic entry code so the exercise
gets a point.

Tested with a full system boot and by issuing some command
line tools with strace to make sure the tracing path still
works.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/include/asm/syscall.h |  3 ++
 arch/arm/kernel/Makefile       |  3 +-
 arch/arm/kernel/entry-common.S | 65 ++++++++++++++++++++++++++++++++++++------
 arch/arm/kernel/entry-header.S | 25 ----------------
 arch/arm/kernel/syscall.c      | 26 +++++++++++++++++
 5 files changed, 88 insertions(+), 34 deletions(-)

diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h
index fe4326d938c1..1d21f26ecf51 100644
--- a/arch/arm/include/asm/syscall.h
+++ b/arch/arm/include/asm/syscall.h
@@ -19,6 +19,9 @@
 
 extern const unsigned long sys_call_table[];
 
+int invoke_syscall(void *table, struct pt_regs *regs, int scno, void *retp);
+int invoke_syscall_trace(void *table, struct pt_regs *regs, int scno, void *retp);
+
 static inline int syscall_get_nr(struct task_struct *task,
 				 struct pt_regs *regs)
 {
diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile
index aaae31b8c4a5..d5a128a4228d 100644
--- a/arch/arm/kernel/Makefile
+++ b/arch/arm/kernel/Makefile
@@ -20,7 +20,8 @@ CFLAGS_REMOVE_return_address.o = -pg
 obj-y		:= elf.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
+		   stacktrace.o sys_arm.o time.o traps.o \
+		   syscall.o
 
 KASAN_SANITIZE_stacktrace.o := n
 KASAN_SANITIZE_traps.o := n
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index da5c2d4b62e5..57aa1084a047 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -254,21 +254,23 @@ ENTRY(vector_swi)
 #else
 	str	scno, [tsk, #TI_ABI_SYSCALL]
 #endif
-	/*
-	 * Reload the registers that may have been corrupted on entry to
-	 * the syscall assembly (by tracing or context tracking.)
-	 */
- TRACE(	ldmia	sp, {r0 - r3}		)
-
+	mov	r1, sp				@ put regs into r1
 	ldr	r10, [tsk, #TI_FLAGS]		@ check for syscall tracing
 	stmdb	sp!, {r4, r5}			@ push fifth and sixth args
 
 	tst	r10, #_TIF_SYSCALL_WORK		@ are we tracing syscalls?
 	bne	__sys_trace
 
-	invoke_syscall tbl, scno, r10, __ret_fast_syscall
+	mov	r0, tbl
+	/* r1 already contains regs */
+	mov	r2, scno			@ syscall number from r7
+	badr	r3, __ret_fast_syscall
+	bl 	invoke_syscall
 
+	/* Restore regs into r1 and lr after C call */
+	badr	lr, __ret_fast_syscall
 	add	r1, sp, #S_OFF
+
 2:	cmp	scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
 	eor	r0, scno, #__NR_SYSCALL_BASE	@ put OS number back
 	bcs	arm_syscall
@@ -301,7 +303,16 @@ __sys_trace:
 	add	r0, sp, #S_OFF
 	bl	syscall_trace_enter
 	mov	scno, r0
-	invoke_syscall tbl, scno, r10, __sys_trace_return, reload=1
+	mov	r2, r0				@ scno into r2
+	add	r1, sp, #S_R0 + S_OFF		@ pointer to regs
+	mov	r0, tbl
+	badr	r3, __sys_trace_return
+	bl	invoke_syscall_trace
+
+	/* Restore regs into r1 and lr after C call */
+	add	r1, sp, #S_R0 + S_OFF		@ pointer to regs
+	badr	lr, __sys_trace_return
+
 	cmp	scno, #-1			@ skip the syscall?
 	bne	2b
 	add	sp, sp, #S_OFF			@ restore stack
@@ -415,6 +426,44 @@ sys_mmap2:
 		b	sys_mmap_pgoff
 ENDPROC(sys_mmap2)
 
+/*
+ * This call wants:
+ * r0: syscall table
+ * r1: regs
+ * r2: syscall number
+ * r3: pointer to return function
+ */
+SYM_TYPED_FUNC_START(invoke_syscall_asm)
+#ifdef CONFIG_CPU_SPECTRE
+	csdb
+#endif
+	mov	tbl, r0
+	mov	scno, r2
+	mov	lr, r3				@ return address
+	ldmia 	r1, {r0 - r3}			@ reload r0-r3
+	/* Arguments 5 and 6 are (hopefully) on the stack */
+	ldr	pc, [tbl, scno, lsl #2]		@ call sys_* routine
+SYM_FUNC_END(invoke_syscall_asm)
+
+/*
+ * This call wants:
+ * r0: syscall table
+ * r1: regs
+ * r2: syscall number
+ * r3: pointer to return function
+ */
+SYM_TYPED_FUNC_START(invoke_syscall_trace_asm)
+#ifdef CONFIG_CPU_SPECTRE
+	csdb
+#endif
+	mov	tbl, r0
+	mov	scno, r2
+	mov	lr, r3				@ return address
+	ldmia	r1, {r0 - r6}			@ reload r0-r6
+	stmia	sp, {r4, r5}			@ update stack arguments
+	ldr	pc, [tbl, scno, lsl #2]		@ call sys_* routine
+SYM_FUNC_END(invoke_syscall_trace_asm)
+
 #ifdef CONFIG_OABI_COMPAT
 
 /*
diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
index 99411fa91350..52b4fa97226d 100644
--- a/arch/arm/kernel/entry-header.S
+++ b/arch/arm/kernel/entry-header.S
@@ -389,31 +389,6 @@ ALT_UP_B(.L1_\@)
 #endif
 	.endm
 
-	.macro	invoke_syscall, table, nr, tmp, ret, reload=0
-#ifdef CONFIG_CPU_SPECTRE
-	mov	\tmp, \nr
-	cmp	\tmp, #NR_syscalls		@ check upper syscall limit
-	movcs	\tmp, #0
-	csdb
-	badr	lr, \ret			@ return address
-	.if	\reload
-	add	r1, sp, #S_R0 + S_OFF		@ pointer to regs
-	ldmiacc	r1, {r0 - r6}			@ reload r0-r6
-	stmiacc	sp, {r4, r5}			@ update stack arguments
-	.endif
-	ldrcc	pc, [\table, \tmp, lsl #2]	@ call sys_* routine
-#else
-	cmp	\nr, #NR_syscalls		@ check upper syscall limit
-	badr	lr, \ret			@ return address
-	.if	\reload
-	add	r1, sp, #S_R0 + S_OFF		@ pointer to regs
-	ldmiacc	r1, {r0 - r6}			@ reload r0-r6
-	stmiacc	sp, {r4, r5}			@ update stack arguments
-	.endif
-	ldrcc	pc, [\table, \nr, lsl #2]	@ call sys_* routine
-#endif
-	.endm
-
 /*
  * These are the registers used in the syscall handler, and allow us to
  * have in theory up to 7 arguments to a function - r0 to r6.
diff --git a/arch/arm/kernel/syscall.c b/arch/arm/kernel/syscall.c
new file mode 100644
index 000000000000..be193266299f
--- /dev/null
+++ b/arch/arm/kernel/syscall.c
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/syscalls.h>
+#include <asm/syscall.h>
+
+int invoke_syscall_asm(void *table, struct pt_regs *regs, int scno, void *retp);
+
+__visible int invoke_syscall(void *table, struct pt_regs *regs, int scno, void *retp)
+{
+	if (scno < NR_syscalls)
+		/* Doing this with return makes sure the stack gets pop:ed */
+		return invoke_syscall_asm(table, regs, scno, retp);
+
+	return 0;
+}
+
+int invoke_syscall_trace_asm(void *table, struct pt_regs *regs, int scno, void *retp);
+
+__visible int invoke_syscall_trace(void *table, struct pt_regs *regs, int scno, void *retp)
+{
+	if (scno < NR_syscalls)
+		/* Doing this with return makes sure the stack gets pop:ed */
+		return invoke_syscall_trace_asm(table, regs, scno, retp);
+
+	return 0;
+}

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52])
	(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 44D0B1C3F04
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:33:57 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560039; cv=none; b=C9TtGHJWwzI+RGZ/zwUoAwDS6hb1Jx0GxRDld3aw/cFhM7MMxHG9JA25eQu4LRiWw7hR5R14oWK/q2HkmWdf15gSiS0KhsKeylb3daP6M98cqgRglZhDKEPvBMg+0lva3/cB12RyCPd9dIhj/+W2DctcOL9LZjpjMF0MAkFDC60=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560039; c=relaxed/simple;
	bh=g9d64KHtUbVDBZrCbOcA7Q4EzM8BIaX3zFAaGvQCJXo=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=EvXPlMbixGub45wU1IklzHhcYO9KfoAk4vdJuWWW3aq5nhNS8iWnqDomlvTTgr6QxGm2ei2lu3pPId34+6TQt94xNZpgvQXxYFKaFotdZ2Vah04BoG+rUMFidzoSQFXpBcg4Gt9PnclKaPBoDA6Tz0G2Ye1O/PzrFNztFtljCVY=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=kLWjpBbI; arc=none smtp.client-ip=209.85.218.52
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="kLWjpBbI"
Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a9943897c07so114198766b.3
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:33:56 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560035; x=1729164835; 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=wUlF8zw6dAVB0pDGKJAXIn96hGOC+sJV5+syU6CZdaU=;
        b=kLWjpBbIrXBqwS6qs1zWRjSc/5q7TgCvxAlu32c2RWB7sr88Zhk3hFO8LM52xOs4bX
         MtYeLjSAZb9uqbni93qpoewFwhulBBQusI40bb5DYAH2gQA8zcxNyi/ha4VzAFtUtTfN
         TNtLh+8QgySboowWPDepbGHCUOHwf+/dBAio2ZLmTOs9AGjniEav9z7XlpSX6mglqPdS
         vYjRlWPaJx8hSQMj7HekkXL7qJC487Qo24H8aefvpOVySsTmmVOg9poxNtjEB2REppkr
         5vG8X1m3yOTnHMjP4aQpins5gncqtVxtuN5sQpipiU5u6MPwdsrXeMOXY3RodaNSZfSK
         kOYA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560035; x=1729164835;
        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=wUlF8zw6dAVB0pDGKJAXIn96hGOC+sJV5+syU6CZdaU=;
        b=bNZAldI1nxZ9W6K1GmDkHbCxdQyyZZ+eQM94RU0IJP9m47jXyNC2IZXBl8m+9DGi4/
         QEzVeBwvsamGUnpyvmz6ogL7HvkfoYjQQugCDZyYx9jBxB2Oi+qPk4ionClEA+NDrJdr
         8RTcu1GOaUXD6pGr0+h3St143R6qoisPH6AQHGY6E7rrxcG8xQ0Iic7e8+aV3X0duKsV
         E4npfltHpACM+g5WUJ0kgefQ+jHf21OcMQ1jLTf+/RHxPUnHomkhyNPbuesHixo30qqE
         ItaOj+DanZTkr2dfPk40ba6rJHdoqSuJD00C6vwWSHuYAjPni3PrQXQPvM8fasZbIdSo
         RQAA==
X-Forwarded-Encrypted: i=1; AJvYcCUfbttLTvUGqpkXS0umOWLHRb8ZzRw1pC9VVZFfrc2CGuDtOnw9704ZoSyV2TztAKdCHUYgMDPyetkMyHY=@vger.kernel.org
X-Gm-Message-State: AOJu0YzfI5ZXPKPW1w2S4rdq/nzA55y3Gynml0O6IredlK894b3jg716
	dmLqDgdd4KHHUK672rdDRqOjQRsbouKe9OyNXjXncQ5gAkvpp0M3swaNbgw4tp4=
X-Google-Smtp-Source: AGHT+IEIU5Pj5ZFEwE9UNRPJZ2YyGwVO4NXzcsvArZ+4K3EO08VhOOCr6/3XirfwIGeg5+bwIqCr5w==
X-Received: by 2002:a17:907:5083:b0:a99:8edf:a367 with SMTP id a640c23a62f3a-a998edfa4cbmr371973966b.57.1728560035569;
        Thu, 10 Oct 2024 04:33:55 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.53
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:33:54 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:45 +0200
Subject: [PATCH RFC 07/28] ARM: entry: Rewrite two asm calls in C
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-7-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

The normal and trace entry code calls out to arm_syscall()
and sys_ni_syscall() from assembly, but these calls can
be moved over to the new C implementation.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/include/asm/traps.h   |  2 +-
 arch/arm/kernel/entry-common.S | 23 +++++------------------
 arch/arm/kernel/syscall.c      | 13 +++++++++++--
 arch/arm/kernel/traps.c        |  2 +-
 4 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/arch/arm/include/asm/traps.h b/arch/arm/include/asm/traps.h
index 2621b9fb9b19..b888912c2450 100644
--- a/arch/arm/include/asm/traps.h
+++ b/arch/arm/include/asm/traps.h
@@ -40,7 +40,7 @@ asmlinkage void dump_backtrace_stm(u32 *stack, u32 instruction, const char *logl
 asmlinkage void do_undefinstr(struct pt_regs *regs);
 asmlinkage void handle_fiq_as_nmi(struct pt_regs *regs);
 asmlinkage void bad_mode(struct pt_regs *regs, int reason);
-asmlinkage int arm_syscall(int no, struct pt_regs *regs);
+int arm_syscall(int no, struct pt_regs *regs);
 asmlinkage void baddataabort(int code, unsigned long instr, struct pt_regs *regs);
 asmlinkage void __div0(void);
 asmlinkage void handle_bad_stack(struct pt_regs *regs);
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index 57aa1084a047..77801d039b5f 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -264,18 +264,10 @@ ENTRY(vector_swi)
 	mov	r0, tbl
 	/* r1 already contains regs */
 	mov	r2, scno			@ syscall number from r7
-	badr	r3, __ret_fast_syscall
-	bl 	invoke_syscall
-
-	/* Restore regs into r1 and lr after C call */
+	/* We return here no matter what, also pass this as an argument */
 	badr	lr, __ret_fast_syscall
-	add	r1, sp, #S_OFF
-
-2:	cmp	scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
-	eor	r0, scno, #__NR_SYSCALL_BASE	@ put OS number back
-	bcs	arm_syscall
-	mov	why, #0				@ no longer a real syscall
-	b	sys_ni_syscall			@ not private func
+	mov	r3, lr
+	b 	invoke_syscall
 
 #if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI)
 	/*
@@ -308,13 +300,8 @@ __sys_trace:
 	mov	r0, tbl
 	badr	r3, __sys_trace_return
 	bl	invoke_syscall_trace
-
-	/* Restore regs into r1 and lr after C call */
-	add	r1, sp, #S_R0 + S_OFF		@ pointer to regs
-	badr	lr, __sys_trace_return
-
-	cmp	scno, #-1			@ skip the syscall?
-	bne	2b
+	cmp	r0, #-1
+	bne	__sys_trace_return
 	add	sp, sp, #S_OFF			@ restore stack
 
 __sys_trace_return_nosave:
diff --git a/arch/arm/kernel/syscall.c b/arch/arm/kernel/syscall.c
index be193266299f..d1259c6d2805 100644
--- a/arch/arm/kernel/syscall.c
+++ b/arch/arm/kernel/syscall.c
@@ -11,16 +11,25 @@ __visible int invoke_syscall(void *table, struct pt_regs *regs, int scno, void *
 		/* Doing this with return makes sure the stack gets pop:ed */
 		return invoke_syscall_asm(table, regs, scno, retp);
 
-	return 0;
+	if (scno >= __ARM_NR_BASE)
+		return arm_syscall(scno, regs);
+
+	return sys_ni_syscall();
 }
 
 int invoke_syscall_trace_asm(void *table, struct pt_regs *regs, int scno, void *retp);
 
 __visible int invoke_syscall_trace(void *table, struct pt_regs *regs, int scno, void *retp)
 {
+	if (scno == -1)
+		return -1;
+
 	if (scno < NR_syscalls)
 		/* Doing this with return makes sure the stack gets pop:ed */
 		return invoke_syscall_trace_asm(table, regs, scno, retp);
 
-	return 0;
+	if (scno >= __ARM_NR_BASE)
+		return arm_syscall(scno, regs);
+
+	return sys_ni_syscall();
 }
diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
index 480e307501bb..42f6bb593eb4 100644
--- a/arch/arm/kernel/traps.c
+++ b/arch/arm/kernel/traps.c
@@ -606,7 +606,7 @@ do_cache_op(unsigned long start, unsigned long end, int flags)
  *  0x9f0000 - 0x9fffff are some more esoteric system calls
  */
 #define NR(x) ((__ARM_NR_##x) - __ARM_NR_BASE)
-asmlinkage int arm_syscall(int no, struct pt_regs *regs)
+int arm_syscall(int no, struct pt_regs *regs)
 {
 	if ((no >> 16) != (__ARM_NR_BASE>> 16))
 		return bad_syscall(no, regs);

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53])
	(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 3DE181C68A3
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:33:59 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560040; cv=none; b=G2i0pnwIgVUlTfIMDgJlcM6n/Ai6tqBtLjR+xaZ5FZL8MaWujyF+CRhlX2wf28sas1K72yNzKfr6x6tdPPeIJDqYJO2r7jmky7Qwnb0JB8+Wja96debAPXoHUWkJaIq/on3uSkPDhNRBQEVlsYsXDAlZetlX65ID5oz62BymrvI=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560040; c=relaxed/simple;
	bh=t98uwCV61GyOOlPQHbY+AntVKd7h/1gQX9jOuNSoZ9c=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=By5AKSdMD/Hk4V7xMHkoQXRzrDGwJ4igFuwKIPdLUBUV6FXNGjOtx22wODoalkzawtMn0osnWPydwU1bIQwRWjAs2t9e/QmklG6pUO/h4IzddmoV8avC4HCszYgiHa2gr46XyYN0831YJb0OLatCQ+G62bQitYL71AkXvpFkc20=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=KOJCmzIf; arc=none smtp.client-ip=209.85.218.53
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="KOJCmzIf"
Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a998a5ca499so116894566b.0
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:33:58 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560037; x=1729164837; 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=8kAN7grhcUpbCDFoKucfYZVBg7IClr2vppXay/MPoLQ=;
        b=KOJCmzIf6MWbl3PsaHXQdDWnQxHAmPCq/BDeIaATbyOBr8Q+bnl19bY0pEwNryudxO
         BLu8nYUQt2OmSsfLNntsdsiZKT+JcZY9ASNOpEVuh//8lmDabBfvFs70l0n2zZfFxSjE
         06V+pI8qHUObnhm/dg7S7+wjBZLWYrNgCoq3ZzXkhj5H5TDkDLdotNcWEUmsKS5vndqk
         NNvUct08ThcQu21Rjg+JGmN7R1JcyGoowSX+3pRj1+rO57/BwySWn4N+Q8PM1dUEIfkM
         +jxkRjDLuTcaFcQLHWs5hgk3O0ZeUzjbLoycIIzLWXrixSm4ST0LWzdAhIe1TEFbr4/h
         gBRA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560037; x=1729164837;
        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=8kAN7grhcUpbCDFoKucfYZVBg7IClr2vppXay/MPoLQ=;
        b=hADWL+H4WEpanvP7dDLPlYkKaiEHkgeCtpQqg0nbfm36a6MzkzbYV8pxZupfjsMwiA
         G7dJLQz2ZlSNMC3ZoKWvGaNnu7PpYHNSSnX/tXRnUBjJ6Bbmni8E2ff168NLc8dhxlzr
         7Ew9E22wdQ9n0MSzuOilkeQ2w6N5xrCMdOQRd8i8qKOQrdXUDFU5Tf1wPvalxQzaCfzp
         dQAyC3NN58AwIMzbGK5J1gnAw6D8xudmc6ObJYl6q86JF7PamczAmCkZJ6QKevoXK9q3
         qNn+8KonIXbcpoJ8gSIke0uQnXKvmk6SvgocLy0nT6DZdjfv9dAjRmuF8BXlgi2cxhwk
         LFiA==
X-Forwarded-Encrypted: i=1; AJvYcCU28W7n3V5LzBOz0ls5v1SlSBErzEWTkkTycr4v9cKK62dcqSbZAkdWqWCiPdK/jtSAXrmQMr+RhspzEP8=@vger.kernel.org
X-Gm-Message-State: AOJu0Yxll6To9pItVDsJsiI6Zfgb72n6eONV7ZJ+AbsvxxBbFl/N4i0q
	nftizzgLokkvm0KadqqRHFeYiNXocB3wGhgm9Fia9UMU/SsRuE6ELUl0gKuSxdc=
X-Google-Smtp-Source: AGHT+IFukWWZ+4l7WL4Af/FV3llg/yA4aFqolHoqsZkfDC6Tj/Nvfup8eye8T7q53dHtZfNUaRUeAQ==
X-Received: by 2002:a17:907:e2c1:b0:a8d:3085:a7b1 with SMTP id a640c23a62f3a-a998d205f31mr531467266b.38.1728560037608;
        Thu, 10 Oct 2024 04:33:57 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.55
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:33:56 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:46 +0200
Subject: [PATCH RFC 08/28] ARM: entry: Move trace entry to C function
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-8-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

This moves over the code entering into tracing into the
C syscall invocation code. As syscall_trace_enter() will
provide the current syscall number from the regs we need
not provide the syscall number to the invocation function
any more.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/include/asm/syscall.h | 2 +-
 arch/arm/kernel/entry-common.S | 6 +-----
 arch/arm/kernel/syscall.c      | 5 ++++-
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h
index 1d21f26ecf51..66067d165ba3 100644
--- a/arch/arm/include/asm/syscall.h
+++ b/arch/arm/include/asm/syscall.h
@@ -20,7 +20,7 @@
 extern const unsigned long sys_call_table[];
 
 int invoke_syscall(void *table, struct pt_regs *regs, int scno, void *retp);
-int invoke_syscall_trace(void *table, struct pt_regs *regs, int scno, void *retp);
+int invoke_syscall_trace(void *table, struct pt_regs *regs, void *retp);
 
 static inline int syscall_get_nr(struct task_struct *task,
 				 struct pt_regs *regs)
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index 77801d039b5f..3cfc6d952ff9 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -292,13 +292,9 @@ ENDPROC(vector_swi)
 	 * context switches, and waiting for our parent to respond.
 	 */
 __sys_trace:
-	add	r0, sp, #S_OFF
-	bl	syscall_trace_enter
-	mov	scno, r0
-	mov	r2, r0				@ scno into r2
 	add	r1, sp, #S_R0 + S_OFF		@ pointer to regs
 	mov	r0, tbl
-	badr	r3, __sys_trace_return
+	badr	r2, __sys_trace_return
 	bl	invoke_syscall_trace
 	cmp	r0, #-1
 	bne	__sys_trace_return
diff --git a/arch/arm/kernel/syscall.c b/arch/arm/kernel/syscall.c
index d1259c6d2805..815312f7b254 100644
--- a/arch/arm/kernel/syscall.c
+++ b/arch/arm/kernel/syscall.c
@@ -19,8 +19,11 @@ __visible int invoke_syscall(void *table, struct pt_regs *regs, int scno, void *
 
 int invoke_syscall_trace_asm(void *table, struct pt_regs *regs, int scno, void *retp);
 
-__visible int invoke_syscall_trace(void *table, struct pt_regs *regs, int scno, void *retp)
+__visible int invoke_syscall_trace(void *table, struct pt_regs *regs, void *retp)
 {
+	int scno;
+
+	scno = syscall_trace_enter(regs);
 	if (scno == -1)
 		return -1;
 

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51])
	(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 7DAA21C6F6E
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:01 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560043; cv=none; b=ickKB90Bewv9pIjPLxOCB29OBNL9KUmGQLlnNFv6x5+Po244qW5mVe3U5oP4lanU35HKzt/DsyTVT2b3K1FzZAaxQedEhZxoVQzgw+N3hdispml/4TnepRdpcbhgzwyD3Fy77Vm+IRaY5OhqkUvAt+WG/PBCFmXW8rcBBxjR4sg=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560043; c=relaxed/simple;
	bh=TeWXUuVvYN/LOwsrfz7FuUVO8Dn9W3GDV6NRqA6SalU=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=AigVKcYnwtstGEuo02VzMoF8fPQa/b6j/4/vVHzg+d5KxLcqFNz18m9V/BO80/6RcIWysrpx75CNLZvXoq0yspRi+VDKTZoqF5N67OLcBEh5tGQu++oH6N+qdUo13oqV/TfhwqdkQXXxwqLDakD/MET2U/V/QPtfnv2TfhAfDYI=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=FkTvQUFF; arc=none smtp.client-ip=209.85.218.51
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="FkTvQUFF"
Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a9943897c07so114208866b.3
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:01 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560040; x=1729164840; 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=wP1nC9llP2df/xsfs1zPIJ3oMrkiGOdpltxFcj+OFqQ=;
        b=FkTvQUFFMIeVnKksJ3t8DK5Fz0suq9GdbFPDmSb4evR0Wt2U4LU+k6z24jWsZQIBq/
         2Sz/mCao0qGhLFf9OhawE+mRfx7X4sTtRjDL/PtvrCi7mFe0p0OtVTF0UKsNoSHttVrS
         1HxbH8KsXuqC7D5l0+tBVA6Uc4BlY5Z7DDJIH7PHbu7RUimQSu2mFboxB9Ff8ga68RYz
         jGXtFbgRIsS0NgnC/fcsPzi1CzCp0qY3i93dzlRcnTmks3HAyp81GHAOMk+2Lprlc+hq
         dGAcDwIpo03xGy29DWzaTFVXKLqw8W6/Ertx44GvAxktYQcQ4kTBktnI2DUxYE5GqIHP
         GJmA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560040; x=1729164840;
        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=wP1nC9llP2df/xsfs1zPIJ3oMrkiGOdpltxFcj+OFqQ=;
        b=vFnpC0X2YxyBL6sktE2B8IqUkbhlTCoO5w2cRYXwV04igvdEXW9EX9dZqiTzZCfo9s
         t3fIrvjzSVSQTaIs86sqTWa/tVmRwekS4rZODdY35Si5IVaBrE3861yRH4n1AGX6jzng
         S7bRFISV2KZdlKfX7Ijb0t3etZiXGJc2osGY10ObI7ULncAp132rrzA74hpA+q7A1jBa
         uDLABAazuNBi3KRMaknuaFW3P90K5s4J/i5+dWPJ7LuDTsYLXevDPa6fPRSWlbJzI6Zc
         CCs5/yC6Y+vjFw+39pMac/vzgYnc3pFuUr+37/Mk+v+6VtwUuq+symi21cSrD8lEljh2
         Ri8g==
X-Forwarded-Encrypted: i=1; AJvYcCVuZ+VbHuh0jUyT6qs9rmijJBNruTSDPnyAuB5XnfL9B7W+pYriMmeHOV8nh86yaLWWhwgkUm/KBnCcaUQ=@vger.kernel.org
X-Gm-Message-State: AOJu0YzQhps6iQxxgjU7TG427rR35OcKLvzuLGkNx7tBWCSYkjwlp+G/
	zaYSDSM9oPASHvH+OW/Qf1FBo+gxCN/6OviDb1NvPz+mnIicqI2TjvT9Z+GKOsY=
X-Google-Smtp-Source: AGHT+IFueHlgiHQRsmvP//M3I79F0TgX4HWc1hPrICoYFkYMHOkR70UMR7ValzDrWStV4N5tCJsulQ==
X-Received: by 2002:a17:907:1c82:b0:a99:379b:6b2c with SMTP id a640c23a62f3a-a998d31be20mr575777066b.42.1728560039732;
        Thu, 10 Oct 2024 04:33:59 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.57
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:33:58 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:47 +0200
Subject: [PATCH RFC 09/28] ARM: entry: save the syscall sp in thread_info
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-9-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

We are going to rewrite the syscall handling in C, which
means that the stack used by the call code is no longer
predicatably 8 bytes (for syscall arguments r4 and r5)
but a varying number of bytes depending on how nested the
C code is.

However the current code is just assuming it can rewind
the stack by adding 8 to sp if a syscall is interrupted by
a sigreturn call.

Solve this by storing the entry sp in the per-task
struct thread_info and use that in the sigreturn wrapper
instead. We already have the thread info available in
the SWI entry and sigreturn is probably not so common
that retrieveing a pointer to thread_info should affect
anything very much.

Storing this per-task in thread_info makes the solution
SMP robust.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/include/asm/thread_info.h | 1 +
 arch/arm/kernel/asm-offsets.c      | 1 +
 arch/arm/kernel/entry-common.S     | 8 ++++++--
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
index 943ffcf069d2..d8a45c5a1049 100644
--- a/arch/arm/include/asm/thread_info.h
+++ b/arch/arm/include/asm/thread_info.h
@@ -67,6 +67,7 @@ struct thread_info {
 	__u32			cpu_domain;	/* cpu domain */
 	struct cpu_context_save	cpu_context;	/* cpu context */
 	__u32			abi_syscall;	/* ABI type and syscall nr */
+	__u32			sp_syscall;	/* SP when entering syscall */
 	unsigned long		tp_value[2];	/* TLS registers */
 	union fp_state		fpstate __attribute__((aligned(8)));
 	union vfp_state		vfpstate;
diff --git a/arch/arm/kernel/asm-offsets.c b/arch/arm/kernel/asm-offsets.c
index 4853875740d0..c9525cbb26b7 100644
--- a/arch/arm/kernel/asm-offsets.c
+++ b/arch/arm/kernel/asm-offsets.c
@@ -49,6 +49,7 @@ int main(void)
   DEFINE(TI_CPU_DOMAIN,		offsetof(struct thread_info, cpu_domain));
   DEFINE(TI_CPU_SAVE,		offsetof(struct thread_info, cpu_context));
   DEFINE(TI_ABI_SYSCALL,	offsetof(struct thread_info, abi_syscall));
+  DEFINE(TI_SP_SYSCALL,		offsetof(struct thread_info, sp_syscall));
   DEFINE(TI_TP_VALUE,		offsetof(struct thread_info, tp_value));
   DEFINE(TI_FPSTATE,		offsetof(struct thread_info, fpstate));
 #ifdef CONFIG_VFP
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index 3cfc6d952ff9..8baab7f97f59 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -232,6 +232,8 @@ ENTRY(vector_swi)
 
 	uaccess_disable tbl
 	get_thread_info tsk
+	/* Save a per-task copy of SP for sigreturn */
+	str	sp, [tsk, #TI_SP_SYSCALL]
 
 	adr	tbl, sys_call_table		@ load syscall table pointer
 
@@ -377,13 +379,15 @@ sys_syscall:
 ENDPROC(sys_syscall)
 
 sys_sigreturn_wrapper:
-		add	r0, sp, #S_OFF
+		get_thread_info tsk
+		ldr	r0, [tsk, #TI_SP_SYSCALL]	@ read back SP
 		mov	why, #0		@ prevent syscall restart handling
 		b	sys_sigreturn
 ENDPROC(sys_sigreturn_wrapper)
 
 sys_rt_sigreturn_wrapper:
-		add	r0, sp, #S_OFF
+		get_thread_info tsk
+		ldr	r0, [tsk, #TI_SP_SYSCALL]	@ read back SP
 		mov	why, #0		@ prevent syscall restart handling
 		b	sys_rt_sigreturn
 ENDPROC(sys_rt_sigreturn_wrapper)

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48])
	(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 AA80F1C7B67
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:02 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560044; cv=none; b=GSbhR8m8AdVJUKAmmxKU5cK2DTm+DDkL6WRhdYtGGSTZnw/QkyFwGYmU7+Y5i9kd070J5eVvlwNu7PM/2oKPba0oqF1EP0i/f40qnP2lQ4zl1AYfJqbv1jjOhVcP8oQ4jmmyJHJEGNSH5HjYsVBURYu0xp1Iy06S1sR5B7H6Mj0=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560044; c=relaxed/simple;
	bh=qkK3Y6eLdgBo76rzyOTfD4ef26pREyX7JWY2zTE4baU=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=n8v5j9eaa9FVqG7vqYT5EaM4Be2mGOMEIBC35m6mlIT4nJUwgnOOmuurFCB3Xnbps/71QdaDKL/0zWX13xPK6f+/0MwUB/ZGSaFpZiwz3C1JydcpxIiZgOdmKWMKQ/+Hi4T8VTjEtqp4nruNzOh5MF69EqWtlY2/I5HyhR0capo=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=GX9QxLvw; arc=none smtp.client-ip=209.85.218.48
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="GX9QxLvw"
Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a994cd82a3bso115417266b.2
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:02 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560041; x=1729164841; 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=HAeVmp86zd6G4zC8AXuoLcHe5Kdpm6JlP18N2B6Kh/4=;
        b=GX9QxLvw7RweniEJnurE8Xg/M6SpvMagxHmb3Xxeaj2KqgzXZ5gm5yHwxnyeB0hOjx
         y0NDdjj9pPrg4WzFf+2qNbuBM0JpPFx0jK1PS3yKxlcsRSIVjqo139opOOjJYXnld8CD
         ZAQ0UIOsxFAr4gz7tRfoW0DGmzRES7Tzo0k3e0yGV8tYMi/rxjDOIQ1mpg/lSeTy2Uvr
         lZSZ+0Htg2zPIHh8MbE57+E9UadY8enJ1QAkTiscXrMA9xLnyoTlN9pPYmNOw3M07sRg
         nx8j3FJXgSwLPV4U73K30NENirReUO0BcNC4LV1B7Ir8kQurBFox3RTsGb0RhfrDQQWM
         r0eQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560041; x=1729164841;
        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=HAeVmp86zd6G4zC8AXuoLcHe5Kdpm6JlP18N2B6Kh/4=;
        b=NMufihFKBpyrOjoUAGAJDrgHJcBYEViWInG8xCt2vERD9RvJPP0+j/t2jCRSwE35gg
         riB8z9x2H9ZMhhmYTFFP6Gi9BANObqOwUVbAdJREJjJU2J0AJZ29RBbjXCvidxxlv/M5
         b7kn6nP1xlDD+sQIelFaJzAmG+73y8AhEVj3mhtWEd2Ze6INXlqXKsqIJh68vVuS9gBY
         wbiybuMKkVtS3oHfDsbRYlKlXRU3sFwMycEdOKBMjd0Tiae3DJL36ciegXmImFwhIncf
         BrACta7ztqzVpT3JZsG6jY3WnndndoTqYbKlOOdVJqByWo6lwVzAs11jWMb9wj5RF1Us
         eYCA==
X-Forwarded-Encrypted: i=1; AJvYcCULbcxHRyCu7oSdjQsREHPPdqwDyrQUr1Sso9sdv/d+7OnbZbykdY5ra+Qb9pPq0RC9SYU/8voxcsjKtfE=@vger.kernel.org
X-Gm-Message-State: AOJu0YwFwTUIRRA7Qc2rqo7g7ZaOD9qb7q4e1L4FCTAnEZa399NHWNmt
	ZesMjEo2T9oNao+ya+5O8FD7OjnIrT5uQShAFEGBz4xVdXFY4olkfqNFJRmYMpE=
X-Google-Smtp-Source: AGHT+IFrAl7fhKtOJ2kSM3VOQKvmdXs79itsAMaItGxniru0zsN4lIQu3jpddRsSAmCeamwhHFpCEQ==
X-Received: by 2002:a17:907:940f:b0:a99:499f:4cb7 with SMTP id a640c23a62f3a-a998d1aad4fmr589155066b.23.1728560040814;
        Thu, 10 Oct 2024 04:34:00 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.33.59
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:34:00 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:48 +0200
Subject: [PATCH RFC 10/28] ARM: entry: move all tracing invocation to C
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-10-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

The traced invocation of syscall is rewritten in C, moving
over also the call to syscall_trace_exit() to C.

To do this we cannot have invoke_syscall_trace_asm() be a
leaf call, which is the mechanism we hithereto relied on
to make sure the stack is pulled back to the state we were
at before we called out to the code written in C.

Push the registers potentially used by C on the stack, and
make a copy of the two stack-pushed syscall arguments
on the top of the stack before invoking the syscall and
then drop these copied arguments and pop back the
registers before returning from invoke_syscall_trace_asm().

As we are now calling from and returning to C, we no
longer need to pass the regs pointer around so drop it.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/include/asm/syscall.h |  2 +-
 arch/arm/kernel/entry-common.S | 32 +++++++++++++++-----------------
 arch/arm/kernel/ptrace.c       |  2 +-
 arch/arm/kernel/syscall.c      | 30 +++++++++++++++++++++---------
 4 files changed, 38 insertions(+), 28 deletions(-)

diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h
index 66067d165ba3..cb0073c4151b 100644
--- a/arch/arm/include/asm/syscall.h
+++ b/arch/arm/include/asm/syscall.h
@@ -20,7 +20,7 @@
 extern const unsigned long sys_call_table[];
 
 int invoke_syscall(void *table, struct pt_regs *regs, int scno, void *retp);
-int invoke_syscall_trace(void *table, struct pt_regs *regs, void *retp);
+void invoke_syscall_trace(void *table, struct pt_regs *regs);
 
 static inline int syscall_get_nr(struct task_struct *task,
 				 struct pt_regs *regs)
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index 8baab7f97f59..dbc947d301ec 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -296,22 +296,11 @@ ENDPROC(vector_swi)
 __sys_trace:
 	add	r1, sp, #S_R0 + S_OFF		@ pointer to regs
 	mov	r0, tbl
-	badr	r2, __sys_trace_return
 	bl	invoke_syscall_trace
-	cmp	r0, #-1
-	bne	__sys_trace_return
-	add	sp, sp, #S_OFF			@ restore stack
-
-__sys_trace_return_nosave:
-	enable_irq_notrace
-	mov	r0, sp
-	bl	syscall_trace_exit
+	add	sp, sp, #S_OFF			@ restore stack pointer
 	b	ret_to_user
 
-__sys_trace_return:
-	str	r0, [sp, #S_R0 + S_OFF]!	@ save returned r0
-	mov	r0, sp
-	bl	syscall_trace_exit
+__sys_trace_return_nosave:
 	b	ret_to_user
 
 	.macro	syscall_table_start, sym
@@ -437,18 +426,27 @@ SYM_FUNC_END(invoke_syscall_asm)
  * r0: syscall table
  * r1: regs
  * r2: syscall number
- * r3: pointer to return function
  */
 SYM_TYPED_FUNC_START(invoke_syscall_trace_asm)
 #ifdef CONFIG_CPU_SPECTRE
 	csdb
 #endif
+	/* Save registers because we are being called from C */
+	push	{r4 - r10, lr}
 	mov	tbl, r0
+	/* Make space to copy the two syscall stack arguments */
+	sub	sp, sp, #S_OFF
 	mov	scno, r2
-	mov	lr, r3				@ return address
-	ldmia	r1, {r0 - r6}			@ reload r0-r6
-	stmia	sp, {r4, r5}			@ update stack arguments
+	badr	lr, __invoke_syscall_trace_ret	@ return right here
+	ldmia	r1, {r0 - r6}			@ reload r0-r6 from regs
+	stmia	sp, {r4, r5}			@ copy stack arguments
 	ldr	pc, [tbl, scno, lsl #2]		@ call sys_* routine
+__invoke_syscall_trace_ret:
+	/* Drop the copied stack arguments */
+	add	sp, sp, #S_OFF
+	pop	{r4 - r10, lr}
+ ARM(	mov	pc, lr		)
+ THUMB(	bx	lr		)
 SYM_FUNC_END(invoke_syscall_trace_asm)
 
 #ifdef CONFIG_OABI_COMPAT
diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
index 07b0daf47441..ac7b98ae4724 100644
--- a/arch/arm/kernel/ptrace.c
+++ b/arch/arm/kernel/ptrace.c
@@ -888,7 +888,7 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
 	return scno;
 }
 
-asmlinkage void syscall_trace_exit(struct pt_regs *regs)
+void syscall_trace_exit(struct pt_regs *regs)
 {
 	/*
 	 * Audit the syscall before anything else, as a debugger may
diff --git a/arch/arm/kernel/syscall.c b/arch/arm/kernel/syscall.c
index 815312f7b254..3ee367958298 100644
--- a/arch/arm/kernel/syscall.c
+++ b/arch/arm/kernel/syscall.c
@@ -17,22 +17,34 @@ __visible int invoke_syscall(void *table, struct pt_regs *regs, int scno, void *
 	return sys_ni_syscall();
 }
 
-int invoke_syscall_trace_asm(void *table, struct pt_regs *regs, int scno, void *retp);
+int invoke_syscall_trace_asm(void *table, struct pt_regs *regs, int scno);
 
-__visible int invoke_syscall_trace(void *table, struct pt_regs *regs, void *retp)
+__visible void invoke_syscall_trace(void *table, struct pt_regs *regs)
 {
 	int scno;
+	int ret;
 
 	scno = syscall_trace_enter(regs);
 	if (scno == -1)
-		return -1;
+		goto trace_exit_nosave;
 
-	if (scno < NR_syscalls)
-		/* Doing this with return makes sure the stack gets pop:ed */
-		return invoke_syscall_trace_asm(table, regs, scno, retp);
+	if (scno < NR_syscalls) {
+		ret = invoke_syscall_trace_asm(table, regs, scno);
+		goto trace_exit_save;
+	}
 
-	if (scno >= __ARM_NR_BASE)
-		return arm_syscall(scno, regs);
+	if (scno >= __ARM_NR_BASE) {
+		ret = arm_syscall(scno, regs);
+		goto trace_exit_save;
+	}
 
-	return sys_ni_syscall();
+	ret = sys_ni_syscall();
+
+trace_exit_save:
+	/* Save return value from syscall */
+	regs->ARM_r0 = ret;
+
+trace_exit_nosave:
+	local_irq_enable();
+	syscall_trace_exit(regs);
 }

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49])
	(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 2B16D1C7B85
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:03 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560046; cv=none; b=DUPj5Kk7ExAtBNyZaIyC0OKuBNIGcQhNCDnvetBmlyLxcvYj6qBpujO184C3mbk5BavAsp5F8D0C56IJrokKIAMNnDTQuxxV2Fv+Hfzhb2ke2rOHts7QaYA4BU8hrWDFKY3jzCzb8AVsPN3ws2I9VukK9R4D+0tDNyF+0K7trRY=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560046; c=relaxed/simple;
	bh=Xo+V1CZRSvq8YRy8tU8+41AjinOUKFVT3YCYSnKFWvk=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=udisWWGveKqIIPSnbfogZZewcGvJxqLswR6+oOEAozgETCaJFgHUnMJl7d2ceSyh3PwXKOpE+76AmXaS9AnQs+7AUXLt0ihnuqjVIMZcvGrtIYxmj0TLVRf3+OJ5HOXipHp0ZdutMmf7hhLwNfIkuwCB5RptE0dBcET3KMrT8dc=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=CfsC3bz/; arc=none smtp.client-ip=209.85.208.49
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="CfsC3bz/"
Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5c8af23a4fcso989924a12.0
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:03 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560042; x=1729164842; 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=+Ojsf1FDD3J/q7BWA6tzk7mG2LcyH7oHP8nC2ES9d2U=;
        b=CfsC3bz/svGs7eFrKyFrHpqw+hhYp7z4jr1sQiRXY4uBwEo9yYIeROsAMlz5fZXpQx
         Q5hodcVSgicP0DjszSjpYGRycHwe8DXjs1okTHPTXf6dmZnLqwKPdR0wEyxBf79f8dCM
         Vneg/U14uVTnlSbhulblRG9YyFMETtL6P03OeyQHo+67lC7fEtAEB1qi5EGLfsAKaZgl
         /8ER2JbYRBvEyQKdN/wq+opel2xQ9ce4Ynbztg0Bm5rX/AwvQjthQT80TrNO1kI9yGwN
         Sslxgo422kSrUDkelP8ccbQCCngI+qrRdz9hPW4sds4t9fZZt3drOT3ZbHbVJzGgh+Ng
         RiUQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560042; x=1729164842;
        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=+Ojsf1FDD3J/q7BWA6tzk7mG2LcyH7oHP8nC2ES9d2U=;
        b=aPz80xNyfndDaokPqUHJrKg8cODvC5hgBopkBC6S4D69FrZi4M3M/+gBk1CkinKSQ/
         fYQEwJJXNO8GFsT121Lmye9eY0FOxd/QzvXyq6Tc5l/y085Qi/eSMJ+sOSsDflYx5EW4
         orKaHQvdi3r3vxHsT9PRWwiGkzTQo9e5w6S1ow6Z7GHbz/wex+k9Z9kwxkXTpHga8Us7
         KoJKmb6WkCsj7494aD3GJqX6RJfLmSFd921WbTmD0eTnsFlN7eLbDEVf7AtFSVrMLlF7
         olguFl3AiMEhddSpuMDeF3E+/T2wpLeLEk3/7xsaHAHnfDFhV+abQH2GuY2KMm5fqtII
         BpUQ==
X-Forwarded-Encrypted: i=1; AJvYcCUYAi32g1ncaDfPO7IT9auyceE3tj+zCIoGnW8ks870oqhjZn/PGPyKzftm97tD2WmlAJFJ5CiilQ6ej/A=@vger.kernel.org
X-Gm-Message-State: AOJu0YwsDIh0d0uVdvbK9N7fpaoFj1fZw7btPXrX9gXq/+2mYe6y+ARl
	N5Y1XiqKqJTuQkBCuwNbQ7zUMZBxkY4T2EgXgpX1WZ9zpKNc5F+LdbnHpdLcsMw=
X-Google-Smtp-Source: AGHT+IEnD0Vl7gplgYYFyXbkA3DuwA6nUrMhw3YhotT21n+Ce3lTwwfBSn8bVKNVmOPEtF7j8R0Y7g==
X-Received: by 2002:a17:907:9705:b0:a99:4b58:c0b7 with SMTP id a640c23a62f3a-a999e8f41fbmr307100666b.57.1728560042464;
        Thu, 10 Oct 2024 04:34:02 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.00
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:34:01 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:49 +0200
Subject: [PATCH RFC 11/28] ARM: entry: Merge the common and trace entry
 code
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-11-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

The trace entry code now can handle recursive and complex
calls in C using stack.

Move the common code over to using that approach.

We now use the ret_fast_syscall return path also when tracing,
which appears to work just fine.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/include/asm/syscall.h |  3 +--
 arch/arm/kernel/entry-common.S | 61 +++++++++---------------------------------
 arch/arm/kernel/syscall.c      | 34 +++++++++++------------
 3 files changed, 28 insertions(+), 70 deletions(-)

diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h
index cb0073c4151b..9c664d8c5718 100644
--- a/arch/arm/include/asm/syscall.h
+++ b/arch/arm/include/asm/syscall.h
@@ -19,8 +19,7 @@
 
 extern const unsigned long sys_call_table[];
 
-int invoke_syscall(void *table, struct pt_regs *regs, int scno, void *retp);
-void invoke_syscall_trace(void *table, struct pt_regs *regs);
+int invoke_syscall_trace(void *table, struct pt_regs *regs, int scno);
 
 static inline int syscall_get_nr(struct task_struct *task,
 				 struct pt_regs *regs)
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index dbc947d301ec..f0f1f8723965 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -39,7 +39,6 @@ saved_pc	.req	lr
  * from those features make this path too inefficient.
  */
 ret_fast_syscall:
-__ret_fast_syscall:
  UNWIND(.fnstart	)
  UNWIND(.cantunwind	)
 	disable_irq_notrace			@ disable interrupts
@@ -47,13 +46,13 @@ __ret_fast_syscall:
 	movs	r1, r1, lsl #16
 	bne	fast_work_pending
 
-	restore_user_regs fast = 1, offset = S_OFF
+	restore_user_regs fast = 0, offset = S_OFF
  UNWIND(.fnend		)
 ENDPROC(ret_fast_syscall)
 
 	/* Ok, we need to do extra processing, enter the slow path. */
 fast_work_pending:
-	str	r0, [sp, #S_R0+S_OFF]!		@ returned r0
+	add	sp, sp, #(S_R0 + S_OFF)
 	/* fall through to work_pending */
 #else
 /*
@@ -63,10 +62,9 @@ fast_work_pending:
  * call.
  */
 ret_fast_syscall:
-__ret_fast_syscall:
  UNWIND(.fnstart	)
  UNWIND(.cantunwind	)
-	str	r0, [sp, #S_R0 + S_OFF]!	@ save returned r0
+	add	sp, sp, #(S_R0 + S_OFF)
 #if IS_ENABLED(CONFIG_DEBUG_RSEQ)
 	/* do_rseq_syscall needs interrupts enabled. */
 	mov	r0, sp				@ 'regs'
@@ -83,7 +81,9 @@ ENDPROC(ret_fast_syscall)
 #endif
 
 	tst	r1, #_TIF_SYSCALL_WORK
-	bne	__sys_trace_return_nosave
+	beq	slow_work_pending
+	b	ret_to_user
+
 slow_work_pending:
 	mov	r0, sp				@ 'regs'
 	bl	do_work_pending
@@ -257,19 +257,15 @@ ENTRY(vector_swi)
 	str	scno, [tsk, #TI_ABI_SYSCALL]
 #endif
 	mov	r1, sp				@ put regs into r1
-	ldr	r10, [tsk, #TI_FLAGS]		@ check for syscall tracing
 	stmdb	sp!, {r4, r5}			@ push fifth and sixth args
-
-	tst	r10, #_TIF_SYSCALL_WORK		@ are we tracing syscalls?
-	bne	__sys_trace
-
 	mov	r0, tbl
-	/* r1 already contains regs */
 	mov	r2, scno			@ syscall number from r7
-	/* We return here no matter what, also pass this as an argument */
-	badr	lr, __ret_fast_syscall
-	mov	r3, lr
-	b 	invoke_syscall
+	bl	invoke_syscall_trace
+	cmp	r0, #0
+	beq	ret_fast_syscall
+	/* This path taken when tracing */
+	add	sp, sp, #(S_R0 + S_OFF)
+	b	ret_to_user
 
 #if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI)
 	/*
@@ -289,20 +285,6 @@ ENTRY(vector_swi)
 ENDPROC(vector_swi)
 	.ltorg
 
-	/*
-	 * This is the really slow path.  We're going to be doing
-	 * context switches, and waiting for our parent to respond.
-	 */
-__sys_trace:
-	add	r1, sp, #S_R0 + S_OFF		@ pointer to regs
-	mov	r0, tbl
-	bl	invoke_syscall_trace
-	add	sp, sp, #S_OFF			@ restore stack pointer
-	b	ret_to_user
-
-__sys_trace_return_nosave:
-	b	ret_to_user
-
 	.macro	syscall_table_start, sym
 	.equ	__sys_nr, 0
 	.type	\sym, #object
@@ -402,25 +384,6 @@ sys_mmap2:
 		b	sys_mmap_pgoff
 ENDPROC(sys_mmap2)
 
-/*
- * This call wants:
- * r0: syscall table
- * r1: regs
- * r2: syscall number
- * r3: pointer to return function
- */
-SYM_TYPED_FUNC_START(invoke_syscall_asm)
-#ifdef CONFIG_CPU_SPECTRE
-	csdb
-#endif
-	mov	tbl, r0
-	mov	scno, r2
-	mov	lr, r3				@ return address
-	ldmia 	r1, {r0 - r3}			@ reload r0-r3
-	/* Arguments 5 and 6 are (hopefully) on the stack */
-	ldr	pc, [tbl, scno, lsl #2]		@ call sys_* routine
-SYM_FUNC_END(invoke_syscall_asm)
-
 /*
  * This call wants:
  * r0: syscall table
diff --git a/arch/arm/kernel/syscall.c b/arch/arm/kernel/syscall.c
index 3ee367958298..ab9e66da0a80 100644
--- a/arch/arm/kernel/syscall.c
+++ b/arch/arm/kernel/syscall.c
@@ -3,48 +3,44 @@
 #include <linux/syscalls.h>
 #include <asm/syscall.h>
 
-int invoke_syscall_asm(void *table, struct pt_regs *regs, int scno, void *retp);
-
-__visible int invoke_syscall(void *table, struct pt_regs *regs, int scno, void *retp)
+static inline bool has_syscall_work(unsigned long flags)
 {
-	if (scno < NR_syscalls)
-		/* Doing this with return makes sure the stack gets pop:ed */
-		return invoke_syscall_asm(table, regs, scno, retp);
-
-	if (scno >= __ARM_NR_BASE)
-		return arm_syscall(scno, regs);
-
-	return sys_ni_syscall();
+	return unlikely(flags & _TIF_SYSCALL_WORK);
 }
 
 int invoke_syscall_trace_asm(void *table, struct pt_regs *regs, int scno);
 
-__visible void invoke_syscall_trace(void *table, struct pt_regs *regs)
+__visible int invoke_syscall_trace(void *table, struct pt_regs *regs, int scno)
 {
-	int scno;
+	unsigned long flags = read_thread_flags();
 	int ret;
 
-	scno = syscall_trace_enter(regs);
-	if (scno == -1)
-		goto trace_exit_nosave;
+	if (has_syscall_work(flags)) {
+		scno = syscall_trace_enter(regs);
+		if (scno == -1)
+			goto trace_exit_nosave;
+	}
 
 	if (scno < NR_syscalls) {
 		ret = invoke_syscall_trace_asm(table, regs, scno);
-		goto trace_exit_save;
+		goto exit_save;
 	}
 
 	if (scno >= __ARM_NR_BASE) {
 		ret = arm_syscall(scno, regs);
-		goto trace_exit_save;
+		goto exit_save;
 	}
 
 	ret = sys_ni_syscall();
 
-trace_exit_save:
+exit_save:
 	/* Save return value from syscall */
 	regs->ARM_r0 = ret;
+	if (!has_syscall_work(flags))
+		return 0;
 
 trace_exit_nosave:
 	local_irq_enable();
 	syscall_trace_exit(regs);
+	return 1;
 }

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46])
	(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 45A1D1C8FAA
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:05 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560047; cv=none; b=CBMJn8/KYXrXQbWTpw/0ntZDZYXoLCI7E2WCd35GniidnqusoATFTm3hfABVUVKesUtFJrCrUuz9dkJMw84m/taNdwL4cmyENBMO4qVJvT+CI3yAVduRTqX5JCxIXB/SXtsrUVsPdXWGhmJXaNUspKcrNgo1KbZztpLRmL5ekkg=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560047; c=relaxed/simple;
	bh=GlhKGb3knP5MTTv+ON8XhDtdyIyG0oHge7Bj6y3E7+E=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=nMMXRH4raHVuAzkHx8UqpHsBQOFhDp1xwLOv3M/oJAWL+/WZFVmgy6SmT/xhyIpw1021xoDlOTFRPvE+vM7rNpw+KTnXXqs8UDUfV3CXjX8UQ62q6Ct/GKxzZDtv38CcV0hHqHbEv7F+m1ia6CMcA7KH2xx7iEqS77DdWqFxSqo=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=CIVz4mbO; arc=none smtp.client-ip=209.85.218.46
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="CIVz4mbO"
Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a99422929c5so96539766b.0
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:05 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560043; x=1729164843; 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=VzzrIJOoccLZThZLp3kOXktHyMNXE6/2voWdPpMOjWQ=;
        b=CIVz4mbOw7FagehXCAvCMDjfzh70O2in6V5eoGlYXWp+lFMttvl2sYdcF++D0XLdHT
         O5CCrDGTZWL5WsieI7bXhUS1Vzf18EjgtyjLIsd4/cZrum60U2DrP6N5CecFVaomFjK6
         Y1nRgr3RFXyKhxxcdRRrDemLHQF6TmbwgdbF2ayAd1IU6FGB+o5eRgWquuK6djB7lrUl
         sWBdxvIa3UN0tuOwJyyTiyvLOHJykiObfOIEiFxUhkcSYj9qchP5v3dFBFW9TlC4EJ5m
         G6l4lYb/eqSv/zWKvjcDJ0zhgekQzV8iHDaAhO3t/ssSikVAhcQn/nSiUUmIwbSU3/Y+
         psOg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560043; x=1729164843;
        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=VzzrIJOoccLZThZLp3kOXktHyMNXE6/2voWdPpMOjWQ=;
        b=bhnpv3rFf6OI2O0ZisDV/WXHWw66IQwU04+d/TucolKsYLkCJp2k/SRi4Fpx49SxpF
         K3p4Zd1uBcC5DlWzxsOKNdNAiEUj9HQ9JOKNd+ZMC1r+u/ZTJvQPtg3gwkB3YgjehDOj
         DdNrvuO0JZvqigY9vI0jfJ2aZ7J3rAObClNdeU8L/GB/w5ql2iyxvsAMlPPhUKoQWTeP
         aj3L5J/MJV+P24YJ1BSWG4SJBUbuItarGk77dZ46B9JcjkLgMJhA6pXlCRfZsqUOh2KA
         P921X8aTukb6FlBj3GyRCviHcGvxLrOPWLVqOssn0Uz07/4KYTv1D2fZrRGfkpniLpgQ
         1gsg==
X-Forwarded-Encrypted: i=1; AJvYcCWVRTByDutUsEn8ly/uc+6c7YIDkPJUyVX/gYTOcZ3HxkfPTuKn/ukJmxO31iggu1L7OctQmyAkSSEgLr4=@vger.kernel.org
X-Gm-Message-State: AOJu0YyMvEdNNwpDqXEjphBR6FmnsCLrxcoXZp+9mZLvd6yBZRtPCKXz
	odZKQdJjYP+Gu/21xlBidQ7pmfg3lDbmfnhHMvh0hdBTWi9H9EEf0W9ZCAIVkqs=
X-Google-Smtp-Source: AGHT+IHADUgNkk0hVOK1JFXtca7534b5748m22i8omloPYXVG1QKj3GD3Xqq0GICp3+Pdqz4GrjLzQ==
X-Received: by 2002:a17:906:730b:b0:a99:4a87:cc7c with SMTP id a640c23a62f3a-a998d34c373mr530776766b.58.1728560043498;
        Thu, 10 Oct 2024 04:34:03 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.02
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:34:03 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:50 +0200
Subject: [PATCH RFC 12/28] ARM: entry: Rename syscall invocation
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-12-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

Now that we do not have a separate trace syscall invocation
path, rename the invocation functions to be generic.

This can be squashed into the previous patch, it is just done
here for the previous patch to be easier to get a cleaner
diff and be easier to read.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/include/asm/syscall.h |  2 +-
 arch/arm/kernel/entry-common.S | 10 +++++-----
 arch/arm/kernel/syscall.c      |  6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h
index 9c664d8c5718..b94fd7ce17f8 100644
--- a/arch/arm/include/asm/syscall.h
+++ b/arch/arm/include/asm/syscall.h
@@ -19,7 +19,7 @@
 
 extern const unsigned long sys_call_table[];
 
-int invoke_syscall_trace(void *table, struct pt_regs *regs, int scno);
+int invoke_syscall(void *table, struct pt_regs *regs, int scno);
 
 static inline int syscall_get_nr(struct task_struct *task,
 				 struct pt_regs *regs)
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index f0f1f8723965..f1e48002bd30 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -260,7 +260,7 @@ ENTRY(vector_swi)
 	stmdb	sp!, {r4, r5}			@ push fifth and sixth args
 	mov	r0, tbl
 	mov	r2, scno			@ syscall number from r7
-	bl	invoke_syscall_trace
+	bl	invoke_syscall
 	cmp	r0, #0
 	beq	ret_fast_syscall
 	/* This path taken when tracing */
@@ -390,7 +390,7 @@ ENDPROC(sys_mmap2)
  * r1: regs
  * r2: syscall number
  */
-SYM_TYPED_FUNC_START(invoke_syscall_trace_asm)
+SYM_TYPED_FUNC_START(invoke_syscall_asm)
 #ifdef CONFIG_CPU_SPECTRE
 	csdb
 #endif
@@ -400,17 +400,17 @@ SYM_TYPED_FUNC_START(invoke_syscall_trace_asm)
 	/* Make space to copy the two syscall stack arguments */
 	sub	sp, sp, #S_OFF
 	mov	scno, r2
-	badr	lr, __invoke_syscall_trace_ret	@ return right here
+	badr	lr, __invoke_syscall_ret	@ return right here
 	ldmia	r1, {r0 - r6}			@ reload r0-r6 from regs
 	stmia	sp, {r4, r5}			@ copy stack arguments
 	ldr	pc, [tbl, scno, lsl #2]		@ call sys_* routine
-__invoke_syscall_trace_ret:
+__invoke_syscall_ret:
 	/* Drop the copied stack arguments */
 	add	sp, sp, #S_OFF
 	pop	{r4 - r10, lr}
  ARM(	mov	pc, lr		)
  THUMB(	bx	lr		)
-SYM_FUNC_END(invoke_syscall_trace_asm)
+SYM_FUNC_END(invoke_syscall_asm)
 
 #ifdef CONFIG_OABI_COMPAT
 
diff --git a/arch/arm/kernel/syscall.c b/arch/arm/kernel/syscall.c
index ab9e66da0a80..968cec945a7e 100644
--- a/arch/arm/kernel/syscall.c
+++ b/arch/arm/kernel/syscall.c
@@ -8,9 +8,9 @@ static inline bool has_syscall_work(unsigned long flags)
 	return unlikely(flags & _TIF_SYSCALL_WORK);
 }
 
-int invoke_syscall_trace_asm(void *table, struct pt_regs *regs, int scno);
+int invoke_syscall_asm(void *table, struct pt_regs *regs, int scno);
 
-__visible int invoke_syscall_trace(void *table, struct pt_regs *regs, int scno)
+__visible int invoke_syscall(void *table, struct pt_regs *regs, int scno)
 {
 	unsigned long flags = read_thread_flags();
 	int ret;
@@ -22,7 +22,7 @@ __visible int invoke_syscall_trace(void *table, struct pt_regs *regs, int scno)
 	}
 
 	if (scno < NR_syscalls) {
-		ret = invoke_syscall_trace_asm(table, regs, scno);
+		ret = invoke_syscall_asm(table, regs, scno);
 		goto exit_save;
 	}
 

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47])
	(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 6E5001C8FD7
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:07 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560049; cv=none; b=QZbvE/LJuqsvduj+MWqFYv27nb9J2RJOHY5Jz51tuK4eHSp0eT8eaUvxgn3IgAtwEIqgJPfY++og2x00guirxl145ZiNepwtpRVmE+1od8HgnjPW2L5NeV9ZesSzD0pG90EFH9wPRXmKDy1MTCImgQ+bRoliafO17Jo0AjxGRPs=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560049; c=relaxed/simple;
	bh=F5bQDfkVsSRu/OqASLHtGTld91a3P5BAk4tZTozpgOA=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=IoMXPJ8ERknFnrgEc8vKICS6rrFulCjZodmD54wCvwlEk1bUFAFoY8oD//aKOlz5+KtIdU/4bqBgNNdhEqlyx+dGq5LsmS5R/IszSuBJSNRRCBTmrfaD2vUZRK2Kg5LH3Kwej2oLYsTPh9K/Q2DnLNxSDWra+EahHQUmhuJSHW8=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=wXTJkkXv; arc=none smtp.client-ip=209.85.208.47
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="wXTJkkXv"
Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5c42f406e29so881947a12.2
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:07 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560046; x=1729164846; 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=Be+GUyUOPZhG4HeyC8y7wViGnm8iy+tOVPMx83A5Zgg=;
        b=wXTJkkXvsa7ny+SlAPIJ1UbWtrv18AcHzMjo0xyR+CBTvrmAxIKd3BcZwHdusQu+Tg
         z43sA5TycDtkxnsve0PeNdhYREQycH9cliuwIot9h4BzdNVVQ0R+IkVxtkv+JbMye9do
         FnhGf5gyTAx8U0XuwTGLSAEVLqgjZOHO3vt/ZnEkot6mwOZz/OzOzpHnhlj4il+EclPB
         qXpkL2WGehKKGDltNyjTkKvfv2IcqURsu83wB0RZtNK+54l9XUy9cmYnCRT/XDsxksih
         jp3fpkSxXTyYWXmNYak1EGbdo0jPaz+yHOYUtOEss2GVI/V/lHjUZxiiBWvQdnobLHhB
         harg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560046; x=1729164846;
        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=IL+PHlrpMb/AN2WoxYqUvpHJe6r5eXvA9rsAYhGqryxBAk8fX/WO8Xva7wvdf1o9kX
         araU5SoY+BuC2hx4lnj/F4LbHyLTIQHlBB4hcTtuvwfZjd1/45pYu07oZ5wRReBkF+8z
         yBRF3OeHKSLUv0gbK/WlKobfVqcPoq/SA7R42e9tVnFNjcxNb1nbP3fDT6Vo4dp3OOMI
         PhtdxSgYq81ivlj3vf7a2NwrEmxbJXT+uiYsMqDjvKvhE0xXEQhH/Kv8X82IEITI5VmH
         4ffI3P7hdgcDnGgodCJPWquhJa7F0i7AYDRm2R6+eg115a+00akzK9Crc5yVa3FaW9Cq
         ntyg==
X-Forwarded-Encrypted: i=1; AJvYcCVeNXUaLnrg6uEreblzrXV2UlaovV5oAVuMAzKNJ9Mxrp+8MmM6HCmBUgKLRXN1srcqZswk0zgt98M1wqM=@vger.kernel.org
X-Gm-Message-State: AOJu0YyvibLjK2SY5WjphrGnETm9ZT92ZSCBb+flr3m37+AE2Vg9xL7H
	bLCt9qGqd5SWbdO7LAzJiix0ZY/JER5NeL4p13MTzSuwYZBiRuwMP6QZmHl8gJs=
X-Google-Smtp-Source: AGHT+IGmc9n6VQianQrFxqDVPOVQDV5YCcFVpaGOA7jxGuHzUJl/veHr7yvG1GzHaeWsSpHDbkqbxQ==
X-Received: by 2002:a17:906:c151:b0:a8d:3338:a497 with SMTP id a640c23a62f3a-a999e628c38mr322887866b.4.1728560045769;
        Thu, 10 Oct 2024 04:34:05 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.03
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:34:04 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:51 +0200
Subject: [PATCH RFC 13/28] ARM: entry: Create user_mode_enter/exit
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-13-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

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 <linus.walleij@linaro.org>
---
 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 <asm/entry.h>
+#include <linux/context_tracking.h>
+
+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();
+}

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47])
	(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 B52841C9B87
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:08 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560050; cv=none; b=PThD2TqFgIiZjLCN4yQ9x6/cjdE8tv3Z1H6Q3WHJ7pwIzKNy64qb1h6xif7BF7jjWmqDKeme/637/JJAlVb/NcQTzNmsmBuTnX7x/bH+Z30+oQ0Vq8Z8Xui2FZgbClcoCrQc6bSNSy7cWk5JhgOix2anVtIlTwE4Teyd81NGtUA=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560050; c=relaxed/simple;
	bh=VwHPcRKEp6wrJTlkngBKpHSq3ywUIHnGGlB2f5ulxQw=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=HykXcl2qCl9h65MG34CftiTq2s9aE2bhJdFp1V8KvmOPTYGmEAQ1xZ+1+x5yt5fcipbHFnKMr5cgfHsXX8DOXkY2tb6enpTeADYxhP07nXq/OEPPACV+2ORJmh3HBkt09pM6YfcFQcm0mh/lAcd6IBA7q9Fs+FUosYjQnlTBtc0=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=xFils/bD; arc=none smtp.client-ip=209.85.208.47
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="xFils/bD"
Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5c9150f9ed4so940926a12.0
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:08 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560047; x=1729164847; 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=DsQ2/1OD1833y3AwH5IJOrZR5jmPSoKtfSG79U8bJN4=;
        b=xFils/bDWktfBBDsgHi46VJ+UM/w+07ATID6sSA90fi9ZhzZp3mGUVmU87i0IyHgfY
         of5RAeDYQGGd603N1U9b8FOoOPClRePSUU+sI6VdSBv8eCdoB87Bp5xs6spcB1fxZsjU
         5C/WLLa3+4zKdp+oFieMsycwzcMtaNbACukwJvZR5V3YpBKfBjbD2WfJazJZvBbo9eqB
         jFYPjcntUB8w1u79yHy9hk/xSDo6CdXvAfV00qoOXJkDwErjcJKTwIgQ/U8GL6wMUJQo
         088d2X1G/8CexEXnKxNo3TTeXkNPpw/4NZeQLBNX8dpC3feDJeUVrjUhguopIfAPE879
         jzVQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560047; x=1729164847;
        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=DsQ2/1OD1833y3AwH5IJOrZR5jmPSoKtfSG79U8bJN4=;
        b=naQbnuYRo1dB3WhUB0Oy8XDE3VEkdV+lX3ywg/7YP02MIs9SeG1bVEW88a0mXim3+b
         3X19U13HpNd6n77j9+s5Cnn7QXWlYSpAVwY6AtvKNwAKgAJZYMOJkZ/lXUY8OBBhjC64
         DIAOP5NsCzxNDohe4rAe3pUS5hpn1E+lBnT5ahrqnC09YkFvBH0ptPcSEB54hqvX+XTV
         Uedm3jI0V7iw0NW8cC03eovL0eGqoQYUO2i7nk9nantmGVF39XvTQvxoWgKbRrc8kV21
         FwolGBoMM/FX7r0is7pEZrODriqk+nph7+SLT/9vxdNDHodc/8OPmJJBDqyvBUrEw0H/
         IBIg==
X-Forwarded-Encrypted: i=1; AJvYcCW1v2TuLgkdbq8XfkUqKmC639dbrZhx/WvjVjVJYXhVPjBBMywEcK3EGlhct7UmcJ6mjCOSZ7I7gnV3Be8=@vger.kernel.org
X-Gm-Message-State: AOJu0YywgwI7rG+cCEZG6jObi2BFyypeBcD3wNugWSyJMqJd0EABEazp
	qvYqpKsSXlD3PolZDkaqrbL8RtEC3PU5ggCc9wTeqypIXg5hj0A8ykVVfjDaUiE=
X-Google-Smtp-Source: AGHT+IFtzNsWgaNiVVEj8OP/CCcRSjW/L9HZNJ/xW1811pDAMg/fQ7GHSKZ1D1WYhG9TkEqfw7s76w==
X-Received: by 2002:a17:907:e2d3:b0:a99:52aa:cae9 with SMTP id a640c23a62f3a-a998d1a256bmr530617366b.24.1728560046838;
        Thu, 10 Oct 2024 04:34:06 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.05
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:34:06 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:52 +0200
Subject: [PATCH RFC 14/28] ARM: entry: Drop trace argument from usr_entry
 macro
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-14-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

The trace argument select whether to look into tracing of
the hardirqs for the exceptions from userspace, but also
selects whether to call further down to establish context
for RCU.

Split off a second macro that is called on everything
except the FIQ since this is the only outlier.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/kernel/entry-armv.S | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
index d6e8b36c70f5..be2df297ec0a 100644
--- a/arch/arm/kernel/entry-armv.S
+++ b/arch/arm/kernel/entry-armv.S
@@ -356,7 +356,7 @@ ENDPROC(__fiq_abt)
 #error "sizeof(struct pt_regs) must be a multiple of 8"
 #endif
 
-	.macro	usr_entry, trace=1, uaccess=1
+	.macro	usr_entry, uaccess=1
  UNWIND(.fnstart	)
  UNWIND(.cantunwind	)	@ don't unwind the user space
 	sub	sp, sp, #PT_REGS_SIZE
@@ -400,13 +400,14 @@ ENDPROC(__fiq_abt)
 	@ Clear FP to mark the first stack frame
 	@
 	zero_fp
+	.endm
 
-	.if	\trace
+	/* Called after usr_entry for everything except FIQ */
+	.macro	usr_entry_enter
 #ifdef CONFIG_TRACE_IRQFLAGS
 	bl	trace_hardirqs_off
 #endif
 	asm_irqentry_enter_from_user_mode save = 0
-	.endif
 	.endm
 
 	.macro	kuser_cmpxchg_check
@@ -428,6 +429,7 @@ ENDPROC(__fiq_abt)
 	.align	5
 __dabt_usr:
 	usr_entry uaccess=0
+	usr_entry_enter
 	kuser_cmpxchg_check
 	mov	r2, sp
 	dabt_helper
@@ -438,6 +440,7 @@ ENDPROC(__dabt_usr)
 	.align	5
 __irq_usr:
 	usr_entry
+	usr_entry_enter
 	kuser_cmpxchg_check
 	irq_handler from_user=1
 	get_thread_info tsk
@@ -451,6 +454,7 @@ ENDPROC(__irq_usr)
 	.align	5
 __und_usr:
 	usr_entry uaccess=0
+	usr_entry_enter
 
 	@ IRQs must be enabled before attempting to read the instruction from
 	@ user space since that could cause a page/translation fault if the
@@ -475,6 +479,7 @@ ENDPROC(__und_usr)
 	.align	5
 __pabt_usr:
 	usr_entry
+	usr_entry_enter
 	mov	r2, sp				@ regs
 	pabt_helper
  UNWIND(.fnend		)
@@ -494,7 +499,7 @@ ENDPROC(ret_from_exception)
 
 	.align	5
 __fiq_usr:
-	usr_entry trace=0
+	usr_entry
 	kuser_cmpxchg_check
 	mov	r0, sp				@ struct pt_regs *regs
 	bl	handle_fiq_as_nmi

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41])
	(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 975741C3F2C
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:09 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560051; cv=none; b=I8Hv2fAgTTQ63awBAfsEHDPa+HuhPwDC6KfkqJSpjjFbEdteskt5FAOwO5jvpZNyJt+CY5hgYPgi1rcC4KET4Fz0eTRABact1b/xfZ7rpVJMzEAGA5i7BjdBIRHWck9sYhplvQlAl8Sps5MvqROYPizuDiXUtWH2k+loPuLVk9c=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560051; c=relaxed/simple;
	bh=GNeY2LQCUhc09WZjjbVfkXZmlZISRGueBzk8RTdV3Hg=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=r0kQtzudiH2NnB8tdMDtxcqM45dwF6rF6hjgVUbY6GpYZrtY2rpWTk7+cwYFsmk3lwfyCMuRuogWsL9ErLCrsr3c/GB3UIpX+toq1DpxgVVaIZh+BJC9Y/L8MdMLsOD8iG8SuC0aF04xeYZilbwr4D4ATtAkh+1pxAalyZ5/MIs=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=UWLHPC7X; arc=none smtp.client-ip=209.85.218.41
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="UWLHPC7X"
Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a993302fa02so131315666b.0
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:09 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560048; x=1729164848; 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=qPx4kMCDrheeY8xWYJ0qE47ahtpfJ0dLdCDyA5qyaAo=;
        b=UWLHPC7XwJaA5c9ffiQ0UdHdk5k7PbVLi6YynewmuHz/MzAZ+04MeB743dXFAfeQS+
         mkD2XvY8x1EoMf5Oo8PeozYXQvPbdCoB+4+9jy88h1gn1TnXHGCgbTmqE8hbx4PZwtoL
         y4kjhyNMP0d5oRTt5kxrvMTHU73I1/TjpeH6t1uQ427ufL5Mv7Vwaw9iePFfdmJA62nv
         JE8UrAc2rj/51p9arHDsUNFSO12EtX8T6Sq/2tRRjugdN5pB20IClZZoAbFhM9yD3uxf
         aN94jTIzz3djqiBj/umTCOQMMizkt5MdQqST3IIB9RyN8Y2pTMPassXTjx4gpUsuULb7
         wgRg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560048; x=1729164848;
        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=qPx4kMCDrheeY8xWYJ0qE47ahtpfJ0dLdCDyA5qyaAo=;
        b=I2VnbbPFptCdi9ZuvO0JRtmg57oYJoK0sBvXg0+lOtgtabaqUEUZwG5OeuNl38c/Tm
         xvtXp3B+UzyBsFCq0vN7RGP4teREU+l+HvRwclJarRxOHqFCqkg9oTmC4ipHc6ZZ/Xu6
         SwbsXqb2PTfT4Al83bLVrKTJnJRuUk+WC+YtyK8qV88v872FfM2C5qx4SHpnKwTv6rQK
         agOQUbawyIDC8VSevzkL0zBwUCdEQKi0PiGwkAegdrD5bNtanEAf/fezGUNO+v/A7GJO
         fKyeAiFYf5dWuIytvtZCzJSzLTRdY+yvVDK136g5StT6yZkMVHZHlr8C569hTew9dQeD
         VJSA==
X-Forwarded-Encrypted: i=1; AJvYcCV6ZGHFZfrEVqJDlv9xC8xhwRXHnjag4rfNj/3PWD5geZpgV7gApkVE7oPJUJyXf6l7vbv4ChDKCEolqP8=@vger.kernel.org
X-Gm-Message-State: AOJu0YynuUSUEK5Y6rq2ELttubeuGU4eSEK8Tn5JxyiRyepsmkqfVM9o
	WYgkeWl3uNjSKMlTzNnYPdr70qNHkTV8+zfVRL+4kvLPzsIEY3LoXkTYlizwiKo=
X-Google-Smtp-Source: AGHT+IEPVi1mk+/SGvuJTkVQs54hGFUGD5KsWVr2ppK+fAaiWlRn48WKs9o66a2GQRtPuO9/UgXQ1w==
X-Received: by 2002:a17:907:7da0:b0:a99:4e17:cdf2 with SMTP id a640c23a62f3a-a998d329a02mr518892266b.46.1728560047912;
        Thu, 10 Oct 2024 04:34:07 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.06
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:34:07 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:53 +0200
Subject: [PATCH RFC 15/28] ARM: entry: Separate call path for syscall SWI
 entry
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-15-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

The syscalls (SWIs, software interrupts) are deviating from how
any other interrupts are handled as they enable the IRQs again
while processing the syscall, while "hard" IRQs disable all
interrupts until they are handled.

Break out syscall_enter_from_user_mode() into its own function
and call it instead of irqentry_enter_from_user_mode().

As we are moving toward generic entry, we use the signature
from the generic function.

As the generic function requires the syscall number to be
determined, we move the call down below the code that
figures out the syscall number, the only practical effect
should be that interrupts are re-enabled a few instructions
later.

As we move the trace_hardirqs_on/off() calls into C, we can
just get rid of the helper macro usr_entry_enter again and
call asm_irqentry_enter_from_user_mode directly.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/include/asm/entry.h   |  1 +
 arch/arm/kernel/entry-armv.S   | 16 ++++------------
 arch/arm/kernel/entry-common.S | 18 +++++++++++++-----
 arch/arm/kernel/entry.c        | 14 ++++++++++++++
 4 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/arch/arm/include/asm/entry.h b/arch/arm/include/asm/entry.h
index e26f369375ca..e259b074caef 100644
--- a/arch/arm/include/asm/entry.h
+++ b/arch/arm/include/asm/entry.h
@@ -8,6 +8,7 @@ struct pt_regs;
  * These are copies of generic entry headers so we can transition
  * to generic entry once they are semantically equivalent.
  */
+long syscall_enter_from_user_mode(struct pt_regs *regs, long);
 void irqentry_enter_from_user_mode(struct pt_regs *regs);
 void irqentry_exit_to_user_mode(struct pt_regs *regs);
 
diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
index be2df297ec0a..0328860475e1 100644
--- a/arch/arm/kernel/entry-armv.S
+++ b/arch/arm/kernel/entry-armv.S
@@ -402,14 +402,6 @@ ENDPROC(__fiq_abt)
 	zero_fp
 	.endm
 
-	/* Called after usr_entry for everything except FIQ */
-	.macro	usr_entry_enter
-#ifdef CONFIG_TRACE_IRQFLAGS
-	bl	trace_hardirqs_off
-#endif
-	asm_irqentry_enter_from_user_mode save = 0
-	.endm
-
 	.macro	kuser_cmpxchg_check
 #if !defined(CONFIG_CPU_32v6K) && defined(CONFIG_KUSER_HELPERS)
 #ifndef CONFIG_MMU
@@ -429,7 +421,7 @@ ENDPROC(__fiq_abt)
 	.align	5
 __dabt_usr:
 	usr_entry uaccess=0
-	usr_entry_enter
+	asm_irqentry_enter_from_user_mode save = 0
 	kuser_cmpxchg_check
 	mov	r2, sp
 	dabt_helper
@@ -440,7 +432,7 @@ ENDPROC(__dabt_usr)
 	.align	5
 __irq_usr:
 	usr_entry
-	usr_entry_enter
+	asm_irqentry_enter_from_user_mode save = 0
 	kuser_cmpxchg_check
 	irq_handler from_user=1
 	get_thread_info tsk
@@ -454,7 +446,7 @@ ENDPROC(__irq_usr)
 	.align	5
 __und_usr:
 	usr_entry uaccess=0
-	usr_entry_enter
+	asm_irqentry_enter_from_user_mode save = 0
 
 	@ IRQs must be enabled before attempting to read the instruction from
 	@ user space since that could cause a page/translation fault if the
@@ -479,7 +471,7 @@ ENDPROC(__und_usr)
 	.align	5
 __pabt_usr:
 	usr_entry
-	usr_entry_enter
+	asm_irqentry_enter_from_user_mode save = 0
 	mov	r2, sp				@ regs
 	pabt_helper
  UNWIND(.fnend		)
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index ff1dd3169346..14b2495cae3c 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -109,8 +109,6 @@ ENTRY(ret_to_user_from_irq)
 	movs	r1, r1, lsl #16
 	bne	slow_work_pending
 no_work_pending:
-	asm_trace_hardirqs_on save = 0
-
 	asm_irqentry_exit_to_user_mode save = 0
 
 #ifdef CONFIG_GCC_PLUGIN_STACKLEAK
@@ -189,9 +187,6 @@ ENTRY(vector_swi)
 	reload_current r10, ip
 	zero_fp
 	alignment_trap r10, ip, cr_alignment
-	asm_trace_hardirqs_on save=0
-	enable_irq_notrace
-	asm_irqentry_enter_from_user_mode save = 0
 
 	/*
 	 * Get the system call number.
@@ -256,6 +251,19 @@ ENTRY(vector_swi)
 #else
 	str	scno, [tsk, #TI_ABI_SYSCALL]
 #endif
+
+	/*
+	 * Calling out to C to be careful to save and restore registers.
+	 * This call could modify the syscall number. scno is r7 so we
+	 * do not save and restore r7.
+	 */
+	mov	r0, sp				@ regs
+	mov	r1, scno
+	push	{r4 - r6, r8 - r10, lr}
+	bl	syscall_enter_from_user_mode
+	pop	{r4 - r6, r8 - r10, lr}
+	mov	scno, r0
+
 	mov	r1, sp				@ put regs into r1
 	stmdb	sp!, {r4, r5}			@ push fifth and sixth args
 	mov	r0, tbl
diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c
index 8b2e8ea66c13..1973947c7ad7 100644
--- a/arch/arm/kernel/entry.c
+++ b/arch/arm/kernel/entry.c
@@ -1,15 +1,29 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <asm/entry.h>
 #include <linux/context_tracking.h>
+#include <linux/irqflags.h>
+
+long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall)
+{
+	trace_hardirqs_on();
+	local_irq_enable();
+	/* This context tracking call has inverse naming */
+	user_exit_callable();
+
+	/* This will optionally be modified later */
+	return syscall;
+}
 
 noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs)
 {
+	trace_hardirqs_off();
 	/* This context tracking call has inverse naming */
 	user_exit_callable();
 }
 
 noinstr void irqentry_exit_to_user_mode(struct pt_regs *regs)
 {
+	trace_hardirqs_on();
 	/* This context tracking call has inverse naming */
 	user_enter_callable();
 }

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46])
	(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 3C46A1C9EBD
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:13 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560054; cv=none; b=UFUGg+WYqiD2SjtbeCTyNJt9UD73jd7G+Ru+r7W1TXMS5GtbUQPVBJEKFyTB07feYERz7Wn3dvI6Rgi5CeGmZQRHKB3kIIHuFy+Le0X0IZffkUnsvCcVi2xaBuUircft1rGlFXVapcJgzt4XvFU6lPQ0NyVfTMDbPL/kA99zEYs=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560054; c=relaxed/simple;
	bh=CpGlIrf5p+st0iXrAuSSydMx9vVrjXfwmalBa4qqxa4=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=Z8al2ImLFR1XwHnYcoTmhYpNUpfou8jhEVvru4k6Rg6DMvuzqWA8KKkzzOrtoAIu+dN4P0f31q1zPFhg7D3ErJb4T6yLgoVMb3K8jUUVKzIRxcFK1ODGWr7WFV+dpwGSSLKCJc6sLLPXpXxDTgCbOMD0Q42cHZj4Js7AEUGBlR4=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=JHZLuh0Q; arc=none smtp.client-ip=209.85.218.46
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="JHZLuh0Q"
Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a995f56ea2dso132029566b.1
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:13 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560051; x=1729164851; 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=JNSBA39L+uD3IEP0aKHjk6mvKlXPMhygyF+Shfug/O4=;
        b=JHZLuh0QMsOpu0imoIhu3PhzNXsQXyOW21PoZScNA9vhgOlguTedh32Sgntz9APDKv
         kMkpkpB3JVxfHDP6UwLdYxBPm08HkL7Dmw1EEhZzJDMZEDsJaSTEP0WTNmLSPIwPjKPN
         JDZiciiC5PLnISLr4iIWM9FMaTndDFIFdfvby6YuXUKpHhgCi9T1AQy3rH5sZJc+s0ux
         s3g9XV7rXkuOB6XRiSwzG0zIT5k+XQGQ5MikWxVjbDJJe9vjKl8jkfkEU1w8hOwNo2wI
         VUVKLS6p1KbpMZGuOHj8/mUTqnV2cqLBMJiraItuXWg45dKR6rB+UoiMRhiL89/S8IjI
         s6fQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560051; x=1729164851;
        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=JNSBA39L+uD3IEP0aKHjk6mvKlXPMhygyF+Shfug/O4=;
        b=ngMZoz7PbxbDSLSwiDVcH3MKQ4MCCRogTgkg2R7RsRn0BpOK8OR+Ht+yPKuvm7LDrP
         vh0bhNMFx7gROO13ZXLUpDiv97Y/RFitz52IESZP35IqSgHnYGbNRyhxllLqGfOAIYjZ
         4cx8N+G5HItpVA4nQFJulvdu+MS9k/aPm2DRqPUPo1Tj4rpqpLbOq5KGCkyNaGuot3Wl
         B0EjXjOolUU7liyFUylpavajxoIzK+G50Gux0B6cWblAb2XxfjXmNNiK3UzWTZEwNADs
         lKXn6wuyQ0t2tPe5CZLKtuCTivCrGkMQjcnVJR6Qx15ouKF6+V8rtNcS7jo9jKEO6ZKI
         I58g==
X-Forwarded-Encrypted: i=1; AJvYcCXx5d7fk9V5nl94Rb/U3CGjhlWLMqnWQAWLFp7JQx97hHOSKrOXJSOxVuMrSySufR2ZhXpqDXfZfFlj0DM=@vger.kernel.org
X-Gm-Message-State: AOJu0YzGmNRJLSbeXhpmDoeMkhzrfoYRRpfc5dGhpshO18qqT9U0anbo
	q1ulaJ9qRz53bkT6+AINwQgrq9Jqim6ixmXoDiYIA8R6qK7KO/B6ccQYu7KbO7M=
X-Google-Smtp-Source: AGHT+IE5VMKxvHaqB8TM4UQMzMj1+qpZY8SgS8d9OXFElPL9iiC2IKmw/Xc8WMoNH9f/aynvyMEWdg==
X-Received: by 2002:a17:907:e65c:b0:a99:5773:3612 with SMTP id a640c23a62f3a-a998d202140mr531002866b.36.1728560049978;
        Thu, 10 Oct 2024 04:34:09 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.08
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:34:08 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:54 +0200
Subject: [PATCH RFC 16/28] ARM: entry: Drop argument to asm_irqentry macros
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-16-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

asm_irqentry_enter_from_user_mode and asm_irqentry_exit_to_user_mode
have a "save" argument that will save and restore registers before
the call to the C function.

Now all invocations set this argument to 0 so drop the surplus
code.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/kernel/entry-armv.S   |  8 ++++----
 arch/arm/kernel/entry-common.S |  2 +-
 arch/arm/kernel/entry-header.S | 18 ++----------------
 3 files changed, 7 insertions(+), 21 deletions(-)

diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
index 0328860475e1..09ce1be1f677 100644
--- a/arch/arm/kernel/entry-armv.S
+++ b/arch/arm/kernel/entry-armv.S
@@ -421,7 +421,7 @@ ENDPROC(__fiq_abt)
 	.align	5
 __dabt_usr:
 	usr_entry uaccess=0
-	asm_irqentry_enter_from_user_mode save = 0
+	asm_irqentry_enter_from_user_mode
 	kuser_cmpxchg_check
 	mov	r2, sp
 	dabt_helper
@@ -432,7 +432,7 @@ ENDPROC(__dabt_usr)
 	.align	5
 __irq_usr:
 	usr_entry
-	asm_irqentry_enter_from_user_mode save = 0
+	asm_irqentry_enter_from_user_mode
 	kuser_cmpxchg_check
 	irq_handler from_user=1
 	get_thread_info tsk
@@ -446,7 +446,7 @@ ENDPROC(__irq_usr)
 	.align	5
 __und_usr:
 	usr_entry uaccess=0
-	asm_irqentry_enter_from_user_mode save = 0
+	asm_irqentry_enter_from_user_mode
 
 	@ IRQs must be enabled before attempting to read the instruction from
 	@ user space since that could cause a page/translation fault if the
@@ -471,7 +471,7 @@ ENDPROC(__und_usr)
 	.align	5
 __pabt_usr:
 	usr_entry
-	asm_irqentry_enter_from_user_mode save = 0
+	asm_irqentry_enter_from_user_mode
 	mov	r2, sp				@ regs
 	pabt_helper
  UNWIND(.fnend		)
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index 14b2495cae3c..df564388905e 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -109,7 +109,7 @@ ENTRY(ret_to_user_from_irq)
 	movs	r1, r1, lsl #16
 	bne	slow_work_pending
 no_work_pending:
-	asm_irqentry_exit_to_user_mode save = 0
+	asm_irqentry_exit_to_user_mode
 
 #ifdef CONFIG_GCC_PLUGIN_STACKLEAK
 	bl	stackleak_erase_on_task_stack
diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
index fb5bb019199b..50c0b55adc74 100644
--- a/arch/arm/kernel/entry-header.S
+++ b/arch/arm/kernel/entry-header.S
@@ -365,28 +365,14 @@ ALT_UP_B(.L1_\@)
  * Context tracking and other mode transitions. Used to instrument transitions
  * between user and kernel mode.
 */
-	.macro asm_irqentry_enter_from_user_mode, save = 1
-	.if	\save
-	stmdb   sp!, {r0-r3, ip, lr}
+	.macro asm_irqentry_enter_from_user_mode
 	mov	r0, sp				@ regs
 	bl	irqentry_enter_from_user_mode
-	ldmia	sp!, {r0-r3, ip, lr}
-	.else
-	mov	r0, sp				@ regs
-	bl	irqentry_enter_from_user_mode
-	.endif
 	.endm
 
-	.macro asm_irqentry_exit_to_user_mode, save = 1
-	.if	\save
-	stmdb   sp!, {r0-r3, ip, lr}
+	.macro asm_irqentry_exit_to_user_mode
 	mov	r0, sp				@ regs
 	bl	irqentry_exit_to_user_mode
-	ldmia	sp!, {r0-r3, ip, lr}
-	.else
-	mov	r0, sp				@ regs
-	bl	irqentry_exit_to_user_mode
-	.endif
 	.endm
 
 /*

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42])
	(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 455A81C9EDE
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:15 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560056; cv=none; b=PklK7T6BzL7UBTnOVsYVJWMUeQ8xVJpCzLuvOKyWZbm44ptS9LMQa9jExLdtB2I80Wb69Y2yHAzxiAFUejy1Q+l3qewxFFCYEQ9LQAdl2I41H5n5A5H7T2/A0cTP51MqjW/hGRtOX/3LQxWEmSWHUCDWJcEfaSz5bJKZjWFAy6s=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560056; c=relaxed/simple;
	bh=gNYk/dXXFiwzPEzltOa8cVyir3PP8qKub1uE6+vi5oc=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=er8jm/o5Gphft8/iROvSRVaWEo40TLq6XTIyVhfNd8l/cn9xIklpreneMqSwrGTUEmZxiw17+PANEyhDefjJI8LIWpxHnudvImfsPH2yUOOaDaNUgSz3CvZYt6q/OiC3tk+6iEPpXdrdueyhd/cBURsOGAYafoNahA252lFt7UU=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=siX9NnM9; arc=none smtp.client-ip=209.85.218.42
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="siX9NnM9"
Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a998a5ca499so116930966b.0
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:15 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560054; x=1729164854; 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=KWToKPY4NC+RvNbtP48N7l0nt4O+1hLmMWZz8WN9xgg=;
        b=siX9NnM9rN+yZssPIsmHClgQdK3E1rRA2moqgKICk1QwRHFjKn58DbjA5ROIghb4VO
         p7fyBL2KxKgv7RXef+xtY9EyuMAzBw8FyUMYjeiVwYWIvinAynuUzPvlj0W4QUMytFjW
         hH9oTIA2IlmCviRnK7c0TJCSHc2nDEWO9TbAiHfoEthUzMUeRWLs11vE06h5mbdDNZQ3
         WVNfjI+7a2hqnfAPHOQjObDmVOTofZARByNGcPL6p4rGvkivC1zN/7Ugg9iWkUxm6MHp
         mjXVFtNG2x0T18zXxhnFmQZ0mDIGnAZ2cpBNtMrTsGhKyk779EDatAxiZAotjPxPw6RU
         qRAQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560054; x=1729164854;
        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=KWToKPY4NC+RvNbtP48N7l0nt4O+1hLmMWZz8WN9xgg=;
        b=vjptisc/t/uP0d2SDhKUgZ0LxF5uW7jqCpMpiDDQgk3lQvnwb62x4yevJTRc6XeD/8
         ek6GyByDfZIQCvRuG2o2gR2716fujFuBKe5n2g3EAd7j+3VQLhHGJWxncGHLCBqHzyUN
         AQb8qBvTVFL3d4AQiboIrpwT8wQADnlxl5x11H8b7BI3xpG2PUDrriWjqS2fXm8VZYyJ
         vA9lzvRID8LOEdnjtYYoD5wQXzQL8sh++qSCOJbmZiJYKgmKtbSsYmlmTAmv37L4i44Q
         B6C2z4nY8JEaLfvx3CmYhEyNTjvemAeVQGmbbc8sH6NuIlmuOXJVbMUvp1d4BfuoxNMZ
         EwBA==
X-Forwarded-Encrypted: i=1; AJvYcCVc4iJrtT2DP25Fn24EC0Y/KzEDUYTjlSMAKiaanb8UrXTjiwo0kbYOINBrImWJaff1w9aHPmUHmkLLRZs=@vger.kernel.org
X-Gm-Message-State: AOJu0YzAVHmX/RLogW9z6Ty471HBVD+AgIOMbFUjcg/5SKLVt/xIkhWO
	yo7jPqi1uCxNHkdqEqrdo2uYzQCVi18LPFAn3lsbGJX/z2WLv9iWBUXjxHcWXrw=
X-Google-Smtp-Source: AGHT+IFDPzLaonbakRRWJT+0QxQclhlzU2yW7uKOVcDb6pVGDrHLXlnDxsO6QIKMg9pncKslUeaLQA==
X-Received: by 2002:a17:907:3fa5:b0:a99:75ba:baa8 with SMTP id a640c23a62f3a-a998d1fa613mr557910666b.31.1728560053677;
        Thu, 10 Oct 2024 04:34:13 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.12
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:34:13 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:56 +0200
Subject: [PATCH RFC 18/28] ARM: entry: Drop the superfast ret_fast_syscall
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-18-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

When not using any irqflags tracing, context tracking or rseq
debugging, the ARM kernel uses a "superfast" ret_fast_syscall
with a very few assembly instructions.

With generic entry, such local optimizations are not really
possible, we need to call C unconditionally and take the
(hopefully small) overhead.

With generic entry in C, most of the tracing (etc) calls are
replaced by stubs and optimized out by the compiler.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/kernel/entry-common.S | 29 +----------------------------
 1 file changed, 1 insertion(+), 28 deletions(-)

diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index 3559e0a9f5e0..dddbd6ba1eb9 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -30,34 +30,8 @@ saved_pc	.req	lr
 
 	.section .entry.text,"ax",%progbits
 	.align	5
-#if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING_USER) || \
-	IS_ENABLED(CONFIG_DEBUG_RSEQ))
 /*
- * This is the fast syscall return path.  We do as little as possible here,
- * such as avoiding writing r0 to the stack.  We only use this path if we
- * have tracing, context tracking and rseq debug disabled - the overheads
- * from those features make this path too inefficient.
- */
-ret_fast_syscall:
- UNWIND(.fnstart	)
- UNWIND(.cantunwind	)
-	disable_irq_notrace			@ disable interrupts
-	ldr	r1, [tsk, #TI_FLAGS]		@ re-check for syscall tracing
-	movs	r1, r1, lsl #16
-	bne	fast_work_pending
-
-	restore_user_regs fast = 0, offset = S_OFF
- UNWIND(.fnend		)
-ENDPROC(ret_fast_syscall)
-
-	/* Ok, we need to do extra processing, enter the slow path. */
-fast_work_pending:
-	add	sp, sp, #(S_R0 + S_OFF)
-	/* fall through to work_pending */
-#else
-/*
- * The "replacement" ret_fast_syscall for when tracing, context tracking,
- * or rseq debug is enabled.  As we will need to call out to some C functions,
+ * As we will need to call out to some C functions,
  * we save r0 first to avoid needing to save registers around each C function
  * call.
  */
@@ -75,7 +49,6 @@ ret_fast_syscall:
 ENDPROC(ret_fast_syscall)
 
 	/* Slower path - fall through to work_pending */
-#endif
 
 	tst	r1, #_TIF_SYSCALL_WORK
 	beq	slow_work_pending

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52])
	(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 425121C4603
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:14 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560057; cv=none; b=DzYbVxqM2V2jMpqb6LP5jvwcF/eATu49zG0IrtF1QhOpbxuomWLUFLb0NHycNtyeXPmueyvwYcJ8VEUvzL1hnm0dgDvYoGpsmJPsFxaVIYXDPHXWeTjhOsuU7Vw1rOmfGWraT6QhywpFX8w/bs570IQc8V9FPNw9E7cEbPY2Hl8=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560057; c=relaxed/simple;
	bh=xji/pcLoEPAUztYWn3ikVISlaHvrDnwTx4BX+5Les5s=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=Tn+09vJx7lPA3FThmHHPboo6ZadZ9q6mjw842mb1fY/xPAWvXdfBGZHfpkzKrNtucLKJaxK8RrKQSDheb5AoYUJDxpFJx1YFw2mjhmDi1PzzFRHq/MBudQ254JUnmUmE5yNNYiKu4a+CHXRAq+GWIrC0gM5/f2uUUI7Pn7m833g=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=bewWdoek; arc=none smtp.client-ip=209.85.218.52
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="bewWdoek"
Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a993302fa02so131327366b.0
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:14 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560053; x=1729164853; 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=hNYBR6ZSh2a4w1mSh6FqJlsw/BqZTd6AKV7VHjOwsQw=;
        b=bewWdoekEME/CtnGopmLKnTvnOcFa0NWLDJina4kg3ol+2gG49F2GrEZHPhhJd99rV
         76tncRoSvus2Kag4R7+Ci3wTBPTe2akBUu6VzSPgp1PmMJswTiit7NfkZo2RdncNdRh9
         3vyFQVIKR7a6VPV3rKYDTVkUb0rv/kBdm1w6S49gavzxAXlgkMMZKahQ1Iq8Ngk5AI9N
         wJQxEMt7K1OWM/SWc1PLGuX8Lk5M/KiuhL16hN5nXvOF4qvf75rbnCpWVyeTid9xZihk
         H7KEog03HSqU2Kjidl4YpPaVlJKQ5Sb3Pa9FrfTdEAdW4b1SwJ1Q20+mFC2VBPrJMu5N
         dGJA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560053; x=1729164853;
        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=hNYBR6ZSh2a4w1mSh6FqJlsw/BqZTd6AKV7VHjOwsQw=;
        b=FflyOzNU7JwTv+glIT2hzyHsKJWeysK7j6sf54b74O/nf7DHdSXIuTS32EILheUGGM
         FzBlJfFqQGKNoAzuXvqjNLsMqtdqtNYpkWcVdKDMxNYTqbO1oYXBYK/pSrgy3zM8wJp+
         VvYczXEgZPJDCbX9ioL8smiBajOcRwFhYpPUMY/E351zj1senZepf5rii+oicXC7mZDw
         a54CtueaVPKXSnua5HkYTgWbHth8howLcBmycWahODvjCUN7cQJqnZWiOwFjek5eriGE
         Yhd+/3xUpzbldY7mGWEQLpip8uu0WavvdeMaFdb7wxcOtuRqyfcce7dRSjOnpTV6UXq3
         ycgw==
X-Forwarded-Encrypted: i=1; AJvYcCUpuCbSWe8i+XGkExpPzF03sFRMxO6x9S6OX/4BvnCgycGx06qw8rqpN7MbQzCfnw7s+gaG3CjM0sRk4C0=@vger.kernel.org
X-Gm-Message-State: AOJu0Yzs3JYxVDvJVOj0XvgQRdV/g8N50XYPJGwxoNso+WcSasVXMQV9
	oO+qmWyv21yiAx/nSwDp8WE2XdxdY5KhWKKqaFGPoo8SWtC0EZuR0NKhutF5C8c=
X-Google-Smtp-Source: AGHT+IHL5fhjnV7jrHCiVi1KTSPjzJB1MdYFxv8NsvHT8D9zQW+FbMo3EZMj/2II5YwtAlSsYXswMA==
X-Received: by 2002:a17:906:d259:b0:a99:42e7:21f with SMTP id a640c23a62f3a-a998d224f32mr538373366b.37.1728560052587;
        Thu, 10 Oct 2024 04:34:12 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.11
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:34:12 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:55 +0200
Subject: [PATCH RFC 17/28] ARM: entry: Implement
 syscall_exit_to_user_mode()
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-17-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

Mirroring syscall_enter_from_user_mode() we create the sibling
call syscall_exit_to_user_mode() and start to move some stuff
over from assembly, first the rseq call and the interrupt
disablement.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/include/asm/entry.h   |  1 +
 arch/arm/include/asm/signal.h  |  1 -
 arch/arm/kernel/entry-common.S | 10 ++--------
 arch/arm/kernel/entry.c        |  8 ++++++++
 arch/arm/kernel/signal.c       |  7 -------
 5 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/arch/arm/include/asm/entry.h b/arch/arm/include/asm/entry.h
index e259b074caef..8b8cc9a1eefb 100644
--- a/arch/arm/include/asm/entry.h
+++ b/arch/arm/include/asm/entry.h
@@ -9,6 +9,7 @@ struct pt_regs;
  * to generic entry once they are semantically equivalent.
  */
 long syscall_enter_from_user_mode(struct pt_regs *regs, long);
+void syscall_exit_to_user_mode(struct pt_regs *regs);
 void irqentry_enter_from_user_mode(struct pt_regs *regs);
 void irqentry_exit_to_user_mode(struct pt_regs *regs);
 
diff --git a/arch/arm/include/asm/signal.h b/arch/arm/include/asm/signal.h
index 7acccc96840c..bb753cd3e29f 100644
--- a/arch/arm/include/asm/signal.h
+++ b/arch/arm/include/asm/signal.h
@@ -23,7 +23,6 @@ typedef struct {
 
 #include <asm/sigcontext.h>
 
-void do_rseq_syscall(struct pt_regs *regs);
 void do_work_pending(struct pt_regs *regs, unsigned int thread_flags);
 
 #endif
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index df564388905e..3559e0a9f5e0 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -65,12 +65,9 @@ ret_fast_syscall:
  UNWIND(.fnstart	)
  UNWIND(.cantunwind	)
 	add	sp, sp, #(S_R0 + S_OFF)
-#if IS_ENABLED(CONFIG_DEBUG_RSEQ)
 	/* do_rseq_syscall needs interrupts enabled. */
 	mov	r0, sp				@ 'regs'
-	bl	do_rseq_syscall
-#endif
-	disable_irq_notrace			@ disable interrupts
+	bl	syscall_exit_to_user_mode
 	ldr	r1, [tsk, #TI_FLAGS]		@ re-check for syscall tracing
 	movs	r1, r1, lsl #16
 	beq	no_work_pending
@@ -97,13 +94,10 @@ ENDPROC(ret_fast_syscall)
  * do_work_pending() will update this state if necessary.
  */
 ENTRY(ret_to_user)
-#if IS_ENABLED(CONFIG_DEBUG_RSEQ)
 	/* do_rseq_syscall needs interrupts enabled. */
 	enable_irq_notrace			@ enable interrupts
 	mov	r0, sp				@ 'regs'
-	bl	do_rseq_syscall
-#endif
-	disable_irq_notrace			@ disable interrupts
+	bl	syscall_exit_to_user_mode
 ENTRY(ret_to_user_from_irq)
 	ldr	r1, [tsk, #TI_FLAGS]
 	movs	r1, r1, lsl #16
diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c
index 1973947c7ad7..472338047337 100644
--- a/arch/arm/kernel/entry.c
+++ b/arch/arm/kernel/entry.c
@@ -1,7 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <asm/entry.h>
+#include <asm/signal.h>
 #include <linux/context_tracking.h>
 #include <linux/irqflags.h>
+#include <linux/rseq.h>
 
 long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall)
 {
@@ -14,6 +16,12 @@ long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall)
 	return syscall;
 }
 
+void syscall_exit_to_user_mode(struct pt_regs *regs)
+{
+	rseq_syscall(regs);
+	local_irq_disable();
+}
+
 noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs)
 {
 	trace_hardirqs_off();
diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
index 7b1a16e86b23..03b20637a2e1 100644
--- a/arch/arm/kernel/signal.c
+++ b/arch/arm/kernel/signal.c
@@ -659,13 +659,6 @@ struct page *get_signal_page(void)
 	return page;
 }
 
-#ifdef CONFIG_DEBUG_RSEQ
-asmlinkage void do_rseq_syscall(struct pt_regs *regs)
-{
-	rseq_syscall(regs);
-}
-#endif
-
 /*
  * Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as
  * changes likely come with new fields that should be added below.

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51])
	(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 CC6E61CB31C
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:17 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560059; cv=none; b=aOZMAGqZbdQXcw2rVlrlE3B5wb2+45DjimVe2Q/tfwG3jd9PV1zGEbWz6IJUVMSyuTBmO0C+6rIBE5BK/T2u9wpdXo2UvR2LP0sTu8hL7jQTpCbC14942rpHIjmfIqE+G5sF4Lu7skVFNatk97KqYyJIYXivO03wlbfmI+LCxIs=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560059; c=relaxed/simple;
	bh=U7+/gc2e2KuWRZx3ryccMQNU5ZCqQa+rXx8yeFy3Nh8=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=vBZSnSdSeUmn4eRkBIMX6k+tK5culGQZMkhnGzmiZU3DaRuWs3Z1axLvbjlgKb+ad5Bq+tFQE2ihR1m+bBLDkbb5eNPVxz9iQLbvyvahXtFOw0S86tYr6cAUqFO5BtUclbHKo/6EYLFoV5lISj0wdwRj7OTuo+ielkyQrzoaBZE=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=y+ngMCmj; arc=none smtp.client-ip=209.85.218.51
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="y+ngMCmj"
Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a9982f90e92so152088166b.0
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:17 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560056; x=1729164856; 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=hWWOf9VRKfs2/tqyRJcdO75r8/gLb8BcoV6DE9Ay3YY=;
        b=y+ngMCmj+bSsPqKc/Q0w5tRuLjwY9VQGzy9gEigmiB3/RsbMGw5jRDWvaaDLfUrbRq
         8Uc+lyFHf450WOksUO/Fli3YrQ198Gij05BOJ7fOSN6EY70XP9WVcx+WhWNHe6+3Zxn0
         bi3rRzCrdTnjFfnXzGuXMSATHHT0MrZhFeM+/wP185LOdGlhpJa/tWFEsWTBEbbpkBKo
         U0eF0Zxk9BIWfv69Yb6q9zJ27EITbq6iXD41qb9KRBw9Jpcv6edcBKNxH/HWzIuDwltu
         ThM4o8e15T5KyPZ1rQeSJnBt1nE7dKUBI0r11UfyinWFd7ERRv4k9qhPFPViac5a0x0O
         a5rw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560056; x=1729164856;
        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=hWWOf9VRKfs2/tqyRJcdO75r8/gLb8BcoV6DE9Ay3YY=;
        b=b/uJy3WUBKS22EOboTda/zueg+OQhC7axm0a8pfMA0tbtUOSdLfhPR8n6y3CorYNKp
         QlU9Y9dp98HGj1YtYWd6bDaNEvqF0xI4G+Su2opZwoX+zZPRjPvQLf3Yf4VMK9nj8J/8
         0yNALIK4i73jr76mp7CXMeosNNJtvTYHa442NyP+nnAD+z7MuKzHrdzG7+Kmz90bFVDU
         bypWa5iALZK+N28W55axFEYrmcFeScQBfIOYnfoS1sdjkUUu3hKd2Ast75t0DvnG7Gg7
         GODTWJakKOe7g/imkomx1BuVl3srR2uV0PEdbGBXraZqbEj2svzHQIkcrX+wFBveDMID
         jybg==
X-Forwarded-Encrypted: i=1; AJvYcCWawyMZQWxuzoqGqybFunZIkOcoB4rNF4zT86/T+L4+OwG/G9+hY7E4brwhsMkedyavSqBrGmgNaJuWcVM=@vger.kernel.org
X-Gm-Message-State: AOJu0YyjxQHh+4mYUFgmxvC0CdsCM5tYhOVqMbrQfAKWUtd2fl6feK/q
	Eij85dyVsHnwvprpbe2ln6wZt88BdjgOIU3zo2OftRisqnx+GJ0UYJbFHyBoin4=
X-Google-Smtp-Source: AGHT+IEHCTRRp7fVGYbHaZJRdCWztPF5Cmz1ArhsR37YdkkUHo8yQ2UvzGBEaqZF9J54+PdeX3iD/A==
X-Received: by 2002:a17:906:eec7:b0:a77:ab9e:9202 with SMTP id a640c23a62f3a-a99a0eb9349mr287624366b.4.1728560056112;
        Thu, 10 Oct 2024 04:34:16 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.14
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:34:15 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:58 +0200
Subject: [PATCH RFC 20/28] ARM: entry: Untangle ret_fast_syscall/to_user
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-20-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

The return to userspace is a bit hard to follow. To prepare
the ground for further refactorings we rewrite the functions
to ret_fast_syscall and ret_to_user are mostly stand-alone
symbols.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/kernel/entry-common.S | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index d27e34d7e97a..ece921571714 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -44,20 +44,23 @@ ret_fast_syscall:
 	bl	syscall_exit_to_user_mode
 	ldr	r1, [tsk, #TI_FLAGS]		@ re-check for syscall tracing
 	movs	r1, r1, lsl #16
-	beq	no_work_pending
- UNWIND(.fnend		)
-ENDPROC(ret_fast_syscall)
-
-	/* Slower path - fall through to work_pending */
+	beq	2f
 
 	tst	r1, #_TIF_SYSCALL_WORK
-	beq	slow_work_pending
+	beq	1f
+
 	b	ret_to_user
 
-slow_work_pending:
-	mov	r0, sp				@ 'regs'
+1:	mov	r0, sp				@ 'regs'
 	bl	do_work_pending
-	b	no_work_pending
+
+2:	asm_irqentry_exit_to_user_mode
+
+#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
+	bl	stackleak_erase_on_task_stack
+#endif
+	restore_user_regs
+ UNWIND(.fnend		)
 ENDPROC(ret_fast_syscall)
 
 /*
@@ -74,7 +77,9 @@ ENTRY(ret_to_user)
 ENTRY(ret_to_user_from_irq)
 	ldr	r1, [tsk, #TI_FLAGS]
 	movs	r1, r1, lsl #16
-	bne	slow_work_pending
+	beq	no_work_pending
+	mov	r0, sp				@ 'regs'
+	bl	do_work_pending
 no_work_pending:
 	asm_irqentry_exit_to_user_mode
 

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53])
	(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 E02931C460D
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:16 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560060; cv=none; b=hN5LRF5lQAw4Ph0wXHSL/XFk484d1v9WG1wUqwUWNqvH2caTFigcrwVbag+7gSayYs58maD8T1AF71GonCh8l/yxymsDHFQ9U7Va02b/FUpioKZy6PSthyT+6YyJo+RPvIx+1jQNing1s5WGDo12yXh53x1WNgrg2VdcNH0FQt4=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560060; c=relaxed/simple;
	bh=Qsa08BehM4uts93sI8Y9iubQvhsHZG2Sg6J31UXi3tM=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=prHWxGYNq5DYtrgbonmIlIjAEQiOUdW2dDPdInDSm6NwuXuLp3mS0iQ1qfJEl0Y/HO2e2ZHAOC6EXgdf3tsWiD2hjGtSDu8MLnRunl13+UjPqQ6k6zZWdOYjEa8Q6wJ9oChBr2CAzn5eEDtnQTg6xj0F2j2NPp7Vi8Ujv+s7n3o=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=SXwnFi0u; arc=none smtp.client-ip=209.85.218.53
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="SXwnFi0u"
Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a9951fba3b4so129047766b.1
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:16 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560055; x=1729164855; 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=4s7yTStZNPQghs61B8MN+wTLfopUv2dudvbP9oK+hzk=;
        b=SXwnFi0uylzXjvpfj8+NWPiSuc17ow80y/xIqTJ8WKz3N/JuLvOoHJfhBIsXQPo0Yr
         8NZp1SrfXJzaO3uhfvCFyikG9iikcZC7eEgfJ8LV9rtJAbQYtwCBSvcc8+HNYTZfegE6
         6Zy4NzeP1955inT1p8J+StMdbjQcbHKnHIUmf6ph/AZkzCNBVMF3TfxQe+1ipnyPAAwx
         CoNV8qxXP//ED7b2NBDAO4a84XHWw4a8ZGqTgWhB035FBQVmi+q84MaAzFXusG1Ynv7g
         05QprQRikL/ElRuc5lDGS76VgHJOCIp3O4+hCiQO3rainf/nidpsT011Gjhvol0QOxTq
         TDww==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560055; x=1729164855;
        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=4s7yTStZNPQghs61B8MN+wTLfopUv2dudvbP9oK+hzk=;
        b=Rdagh9IZ5mQ/tH1SlzKurLYt2zzvsMS4RyZ+9Dx4sJKGWhxnyRH0QovyoIlFzWJCoz
         EM66VXoKzZj92lIG1OzjNEb33nf/ssYfazYgcHK0ZBwP7PiULJVpDLksKnf3Er2cRb8V
         UrQYGoC1EZE++R/5lvESzoknE4opsxanBcGwBtt3XBU8waPO+HXEBs86NPd9dVcu/2TW
         eP6AIhAg0UvYzn0UkiQb29wQxquV06v3Fvu4jPHSPk6Yr4sqQC6LVH/QtvKb+Lee8qGj
         jFBF6C1cGK+C43OOFIy8/GchSgIsOyNPxlCSbj3yECkXEd/24B+9USMo+9i6Mzslm+/W
         0vgQ==
X-Forwarded-Encrypted: i=1; AJvYcCV+GpgL/c0FI3yO+E4nTfzaF0PXRZTl0cJGECXLpZaYITRCH1fnHp8C0R4sQkF8AFerNowaLThFNyiNpMM=@vger.kernel.org
X-Gm-Message-State: AOJu0Yyfopxuvwj7yoKrvEa50ZcNkeZ09mohI9wGo1WoMU9H/DclNAO1
	vT+lIxLwfIHQcQUydU3Gw+Jz6dFvCgOE55Z3zg9FQIYoCQzwq0InFUiiDgQmwww=
X-Google-Smtp-Source: AGHT+IG4ChkXSJOOJVtKgVJOl19DQS8X/tzmbK2e58/g2XwPHPYY2o/CB6c01S2WX4Js3ghS2dg9FA==
X-Received: by 2002:a17:907:8688:b0:a99:76a4:7052 with SMTP id a640c23a62f3a-a998d34db43mr548587466b.65.1728560054756;
        Thu, 10 Oct 2024 04:34:14 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.13
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:34:14 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:57 +0200
Subject: [PATCH RFC 19/28] ARM: entry: Remove fast and offset register
 restore
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-19-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

Now all remaining invocations of restore_user_regs has
fast = 0 and offset = 0 set, so drop these parameters
to the macro.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/kernel/entry-armv.S   |  2 +-
 arch/arm/kernel/entry-common.S |  2 +-
 arch/arm/kernel/entry-header.S | 29 +++++++++--------------------
 3 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
index 09ce1be1f677..bd468d58dc02 100644
--- a/arch/arm/kernel/entry-armv.S
+++ b/arch/arm/kernel/entry-armv.S
@@ -496,7 +496,7 @@ __fiq_usr:
 	mov	r0, sp				@ struct pt_regs *regs
 	bl	handle_fiq_as_nmi
 	get_thread_info tsk
-	restore_user_regs fast = 0, offset = 0
+	restore_user_regs
  UNWIND(.fnend		)
 ENDPROC(__fiq_usr)
 
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index dddbd6ba1eb9..d27e34d7e97a 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -81,7 +81,7 @@ no_work_pending:
 #ifdef CONFIG_GCC_PLUGIN_STACKLEAK
 	bl	stackleak_erase_on_task_stack
 #endif
-	restore_user_regs fast = 0, offset = 0
+	restore_user_regs
 ENDPROC(ret_to_user_from_irq)
 ENDPROC(ret_to_user)
 
diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
index 50c0b55adc74..51c7f93c1ded 100644
--- a/arch/arm/kernel/entry-header.S
+++ b/arch/arm/kernel/entry-header.S
@@ -290,7 +290,7 @@
 	.endm
 
 
-	.macro	restore_user_regs, fast = 0, offset = 0
+	.macro	restore_user_regs
 #if defined(CONFIG_CPU_32v6K) && \
     (!defined(CONFIG_CPU_V6) || defined(CONFIG_SMP))
 #ifdef CONFIG_CPU_V6
@@ -309,8 +309,8 @@ ALT_UP_B(.L1_\@)
 #ifndef CONFIG_THUMB2_KERNEL
 	@ ARM mode restore
 	mov	r2, sp
-	ldr	r1, [r2, #\offset + S_PSR]	@ get calling cpsr
-	ldr	lr, [r2, #\offset + S_PC]!	@ get pc
+	ldr	r1, [r2, S_PSR]			@ get calling cpsr
+	ldr	lr, [r2, S_PC]!			@ get pc
 	tst	r1, #PSR_I_BIT | 0x0f
 	bne	1f
 	msr	spsr_cxsf, r1			@ save in spsr_svc
@@ -318,31 +318,24 @@ ALT_UP_B(.L1_\@)
 	@ We must avoid clrex due to Cortex-A15 erratum #830321
 	strex	r1, r2, [r2]			@ clear the exclusive monitor
 #endif
-	.if	\fast
-	ldmdb	r2, {r1 - lr}^			@ get calling r1 - lr
-	.else
 	ldmdb	r2, {r0 - lr}^			@ get calling r0 - lr
-	.endif
 	mov	r0, r0				@ ARMv5T and earlier require a nop
 						@ after ldm {}^
-	add	sp, sp, #\offset + PT_REGS_SIZE
+	add	sp, sp, #PT_REGS_SIZE
 	movs	pc, lr				@ return & move spsr_svc into cpsr
 1:	bug	"Returning to usermode but unexpected PSR bits set?", \@
 #elif defined(CONFIG_CPU_V7M)
 	@ V7M restore.
 	@ Note that we don't need to do clrex here as clearing the local
 	@ monitor is part of the exception entry and exit sequence.
-	.if	\offset
-	add	sp, #\offset
-	.endif
-	v7m_exception_slow_exit ret_r0 = \fast
+	v7m_exception_slow_exit ret_r0 = 0
 #else
 	@ Thumb mode restore
 	mov	r2, sp
-	load_user_sp_lr r2, r3, \offset + S_SP	@ calling sp, lr
-	ldr	r1, [sp, #\offset + S_PSR]	@ get calling cpsr
-	ldr	lr, [sp, #\offset + S_PC]	@ get pc
-	add	sp, sp, #\offset + S_SP
+	load_user_sp_lr r2, r3, S_SP		@ calling sp, lr
+	ldr	r1, [sp, S_PSR]			@ get calling cpsr
+	ldr	lr, [sp, S_PC]			@ get pc
+	add	sp, sp, S_SP
 	tst	r1, #PSR_I_BIT | 0x0f
 	bne	1f
 	msr	spsr_cxsf, r1			@ save in spsr_svc
@@ -350,11 +343,7 @@ ALT_UP_B(.L1_\@)
 	@ We must avoid clrex due to Cortex-A15 erratum #830321
 	strex	r1, r2, [sp]			@ clear the exclusive monitor
 
-	.if	\fast
-	ldmdb	sp, {r1 - r12}			@ get calling r1 - r12
-	.else
 	ldmdb	sp, {r0 - r12}			@ get calling r0 - r12
-	.endif
 	add	sp, sp, #PT_REGS_SIZE - S_SP
 	movs	pc, lr				@ return & move spsr_svc into cpsr
 1:	bug	"Returning to usermode but unexpected PSR bits set?", \@

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50])
	(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 E4C001C4610
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:19 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560061; cv=none; b=ttgnSJjUI3GNDLfulqkLMLtx7bJbJDC4ulVqAkDTZy9+GmFdDUlAmhnwQ7ywbmGKlCwhtYmOTHgdkTVYgUHzSESR8U4KdUZcjMoC0o/dvMngvPXTeJydY6A8Bbzx4LW26juws1Vu8DNqVILQfLqDc93QdPB8AHOIMCIF+X9SnbM=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560061; c=relaxed/simple;
	bh=6+lTQ2GqQK5nFNzuJ9HvRyHeFh0UjePZM0yliybbYSY=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=V9V9Gd7eJ3z+63noCSAQ8DT09XGDLt6Yl13LljoOUxg10NYt3rtlh/fXMM2Lqu8PmsUtevfeI5n9ivE7bvw4KT+PAkWiA8ipUIaYxj9KRe2zw/jeO0zWks8bb01gfjk7J3dQ9H+iHv+S0ePS9LsgBG11HASSoBTC7gADWlkDBVI=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=MFavN5Td; arc=none smtp.client-ip=209.85.218.50
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="MFavN5Td"
Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a7aa086b077so115801766b.0
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:19 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560058; x=1729164858; 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=P2OP9NgXP8OYjhdkePmH5sP15xkO/BVCD1VA0/cLgTg=;
        b=MFavN5Tds+CPqSMPLsUYWVoAqQRCbVHZ77DEcxQ9xKW/+6+gJyYrIATM41l6NPVqCb
         hyPujHeSIYOUN40Sny/R9wMYc9VQbtIlM3aBjgqnF6wqfkKviEde4bGpJyJsChjSsvwn
         kjI2HGQfjq+cFqQb0y8cwlH6YmEYaREyKppGXSYT9O+LO3QYfEqm8iG0pZwIJ5HdzUdc
         hjZrwH9hfB6YDgLTI8HJurVH4a/VvvV63tTPUPyamAEFAXn+GtqPMVeI+tSk0OQXlF7R
         S5OTO8wSjqDcQwBsy3RCKhOBf4NO5SpsdYW+FBElck8peeXN5n0vuoDdnu0K8mDLKh0T
         cScw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560058; x=1729164858;
        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=P2OP9NgXP8OYjhdkePmH5sP15xkO/BVCD1VA0/cLgTg=;
        b=uSXz6lXS/xON1JCkOWDye12nC4RI9WqW05QG1TcczPuO4KDGIr+49EOcGhegM2hqlf
         3rixXf2rcakZJNwK/iPYxUDFxv5dL96PJxZhO3zxnAFJkt9IX/U1IWY2URPoC4tbhPJj
         f90Ac0tBoPGudFEh3itgySpQfxPbxUUPXMoKBjUaEHMuR6wvXdLlhq2JFcdz33B94+1h
         PMwYal5fSeZrk2K49t7LUtC9OIApWo+kwPYOfG8H53BUrm9+6GBQKwo74/qzKr0tLWeI
         mEkOiM0nAptHC9ZC5zKFLEcx92Xlm7XsE4w7yN+yF6yrR9e+HprMmSaIzsD8SinmWLQs
         SW3w==
X-Forwarded-Encrypted: i=1; AJvYcCWfNljsezBHsDsyCzfMNKd4E4Sj+0vHRGD5trSZgilZCITfubr6N86VIWyyFkTn601JQC5Am63t3xXTMf8=@vger.kernel.org
X-Gm-Message-State: AOJu0YwOf/OisIIt8w030JvWQvqtSnO9EKBXklbStsYtIOG0OUMw/nbY
	CV1Wjwd0NV/TVzYeeqCudvqRrW/hbGcJu1RJ5wHgWIyTmwYnLUFxu76F6bD8iYo=
X-Google-Smtp-Source: AGHT+IHjkGGKiDc97wWL2KlgD9Onfb1ojmEjNcRbkL8DUMdOhIwDFVL57b9sjrWd7TF2zYrCFdqZEA==
X-Received: by 2002:a17:907:7ba9:b0:a99:442e:34ac with SMTP id a640c23a62f3a-a999e8c9f03mr327117266b.40.1728560058140;
        Thu, 10 Oct 2024 04:34:18 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.16
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:34:16 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:33:59 +0200
Subject: [PATCH RFC 21/28] ARM: entry: Do not double-call exit functions
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-21-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

This is a semantic change to ret_fast_syscall: if there is no
work pending the function used to jump to ret_to_user, instead
we proceed to return from the syscall.

If we jump to ret_to_user, IRQs are enabled and we call
syscall_exit_to_user_mode a second time; at this point a
this just means a second call to rseq_syscall(), but it
seems wrong and we want syscall_exit_to_user_mode to be called
exactly once.

Apparently the ARM kernel has under some circumstances called
rseq_syscall() twice on the exit to userspace without side effects.

ret_to_user also checks for pending work a second time under
ret_to_user_from_irq, but this isn't even needed any more on
the fast return path: this was needed because the syscall
invocation enabled interrupts when doing syscall tracing, and
all tracing invocation has been moved over to C in earlier
patches.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/kernel/entry-common.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index ece921571714..33bc9e7c5b32 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -49,7 +49,7 @@ ret_fast_syscall:
 	tst	r1, #_TIF_SYSCALL_WORK
 	beq	1f
 
-	b	ret_to_user
+	b	2f
 
 1:	mov	r0, sp				@ 'regs'
 	bl	do_work_pending

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46])
	(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 D03A31CB52F
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:21 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560063; cv=none; b=CsfFpO/jCGydAz6fbhDs4tufJrlIsp4MMK5NTyTlEsb/o1D16aPFSvRRxEup4b/acvg7I6irkLjwAPfn1Ck24q90X4lNkwTGNWuSxeztwmdgmvPTRbT//RGDz02jTCeN5HgEw1doFYhSVpuk98P3FuTrEZqq0hyk62HmwslkoHs=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560063; c=relaxed/simple;
	bh=oB6HP3SopbCX1pJb2/iEaIAmUOMLymz+4GahfTzk35I=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=Ongiox0DeKO9CQqdrpL+S8Ww0MiqDbvrLW9fST/bl0ZYYv+WNkiRCQZD3MDbQ3sWk0t8nyGV7MmzHXB4aoohFuinNAPbZTYwNAJNkjgVCytXsd9SbIr3NvKtTi11iw09H0NF74z0eZrrDpwAv7BUgepUqpetAGQCFOJ6AGwx8Jk=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=cni6dLyH; arc=none smtp.client-ip=209.85.218.46
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="cni6dLyH"
Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a99415adecaso340306066b.0
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:21 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560060; x=1729164860; 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=Gi2KcUYCbZkPlsUdwrNEo9QLrpmnXM+YJIWNYO7+o8Y=;
        b=cni6dLyHsCCvLlMUb4SeWPDVDfo+x1aGg30gbaF8IEP8hZE//4nJTX252D6PFkhrs/
         zogwdb+vNVJcamarzWoNHon4U395sr4iO3apMyRdVic7vrVlgv9cEfc9JT9GfPW5bFe9
         0Qyg/F8QzM2SOx2Kfyx8nf+etefaHL+aZ0AlIG+L0B2nrNLd2HLLm6CMD4/25vOLjcNU
         /bHVGFvDjVarlpQnQijKcYrdnz7qyhhxCDb6Waum7JGQubp/diWMvBl4iPm848L9DFQY
         y0/YIWYJ9ipDYprfbRSwJJN/R+2IX9pLX9f1mYAH0vdbMq14E350aYTuwdxp5BgIXcWp
         ON/Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560060; x=1729164860;
        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=Gi2KcUYCbZkPlsUdwrNEo9QLrpmnXM+YJIWNYO7+o8Y=;
        b=w27mR13VoHuEO4iC45uiiK5AiAYMS8FbguXKyBRAPWF2eMF4meQFdYswPfVrSWJh45
         csGaoI9ttg5WpvtabWPAWFi4kFuqGQe+waBAkpVrajXdBYirYpu/gNLWV2C8rJAf6x0j
         vgHwG58N6XdqLNgdUc8p1i2RxjulqH2gf4ja0DL1T2019eGbehnOMPLTaoXhCwYwKdmi
         RVH1tYoiSWHulsid4cA9jlT0Ogd4XQTbtSk/U8E4rsmY2auhddZMaF6Fw6BnuAJTXSA8
         U4r3HmJWbFLlSxuVkSWB/n1uaMeO02pV+OrbgtB+AiZGFIjoyzet+Y0TZ6JUqmXhBhVk
         DIBA==
X-Forwarded-Encrypted: i=1; AJvYcCUoTei8x6O4AiCuBpUPwu8rcBKBRjiiILHZmJGhoaGnJre9i3z+RmafhhNqqB94ZDEMlUvymVpy+OClYDM=@vger.kernel.org
X-Gm-Message-State: AOJu0YxEjTXPAvgBQMzShGwRQkXXg9JMtKPp3qRpzfiYc4pc5AYcP0R8
	4H1ewQ1ZjPH3XdGAsnZ8kkAN2Na48vudIa4RXNILHYGYWAUshGC/qzDaSE+SYgs=
X-Google-Smtp-Source: AGHT+IG0T9Kw9rtdvh8MtWNWqvxS8ro6kLfwIAoOvd9amat2XPjlnHbF8UXzNiDyhtYS8hL41xf2rA==
X-Received: by 2002:a17:907:7f8e:b0:a8d:4954:c209 with SMTP id a640c23a62f3a-a99a13ae710mr266075066b.22.1728560060101;
        Thu, 10 Oct 2024 04:34:20 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.18
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:34:18 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:34:00 +0200
Subject: [PATCH RFC 22/28] ARM: entry: Move work processing to C
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-22-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

At the end of a syscall software interrupt and every time we exit
an interrupt handler we check if there is work to do, i.e. if the
current thread (userspace or kernel daemon) has set the
_TIF_SYSCALL_WORK flag.

Move this processing over to the C entry code.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/kernel/entry-common.S | 14 +-------------
 arch/arm/kernel/entry.c        | 10 ++++++++++
 2 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index 33bc9e7c5b32..5385574c4339 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -42,19 +42,7 @@ ret_fast_syscall:
 	/* do_rseq_syscall needs interrupts enabled. */
 	mov	r0, sp				@ 'regs'
 	bl	syscall_exit_to_user_mode
-	ldr	r1, [tsk, #TI_FLAGS]		@ re-check for syscall tracing
-	movs	r1, r1, lsl #16
-	beq	2f
-
-	tst	r1, #_TIF_SYSCALL_WORK
-	beq	1f
-
-	b	2f
-
-1:	mov	r0, sp				@ 'regs'
-	bl	do_work_pending
-
-2:	asm_irqentry_exit_to_user_mode
+	asm_irqentry_exit_to_user_mode
 
 #ifdef CONFIG_GCC_PLUGIN_STACKLEAK
 	bl	stackleak_erase_on_task_stack
diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c
index 472338047337..0e3960844b94 100644
--- a/arch/arm/kernel/entry.c
+++ b/arch/arm/kernel/entry.c
@@ -1,10 +1,16 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <asm/entry.h>
+#include <asm/ptrace.h>
 #include <asm/signal.h>
 #include <linux/context_tracking.h>
 #include <linux/irqflags.h>
 #include <linux/rseq.h>
 
+static inline bool has_syscall_work(unsigned long flags)
+{
+	return unlikely(flags & _TIF_SYSCALL_WORK);
+}
+
 long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall)
 {
 	trace_hardirqs_on();
@@ -18,8 +24,12 @@ long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall)
 
 void syscall_exit_to_user_mode(struct pt_regs *regs)
 {
+	unsigned long flags = read_thread_flags();
+
 	rseq_syscall(regs);
 	local_irq_disable();
+	if (has_syscall_work(flags))
+		do_work_pending(regs, flags);
 }
 
 noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs)

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43])
	(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 BF7E41CBEA8
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:23 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560065; cv=none; b=jhYKYL/NEH8ceh2ZQo+sp/HD7iSf0cB8aVQd4FEZoYIbZkcIlXNr1YSM1ERKTUX0H60ad/Q6hkJCsC5ajWHu5JB2/8mJEAjRQrrpMcSddkouWUl8i24qpDRd1/tLwJWeRIkXKNhXKvw/Vazg5SzQCQudh/gnIMAqBVCO4+nUUYQ=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560065; c=relaxed/simple;
	bh=iM/dQm4bBW4OzU1EedLHO9rK90B09M3TWGeyZRpr9ek=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=CLp/La3hCM2Ar8GZ9A5+eOOeSuFoVDd48EvNP8kGdKfNKQ5gqvq+fYy9xTipQ8+aWjTT3EL3XFz/wMEoT9aC4u7N5qUE/dVVNf4Ct8CrlmnNKcTyUPZ21YmfrciIyolPuBh4HIWsoxKm3F1IAiTWTfQjCSNKYWvEwIycY8g5ags=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=OLW2V3Dz; arc=none smtp.client-ip=209.85.218.43
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="OLW2V3Dz"
Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a99422c796eso133963566b.3
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:23 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560062; x=1729164862; 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=bckn3YFGIgJxyi6JuzR+D6XCfS8U3/QVQiTYkjNWbHI=;
        b=OLW2V3DzOLhZ3k3Hm4ty64ImRMcgL9oTfjheEv5h/UMFOe6Otv+ImKxFgzlgT/9CJ1
         sKbmd85b+D3a7WO97ar5AsOxD/o6MVS1/SdcJey6fq+DBUhEjc4J9hdCHVf88VsCXW2h
         4H+Ygf18IGO8cDYPDkNGuV94UYsdOK7s+s0vobPNW2QJKGV/HCoQLH6uNBubk+IwQiHn
         2UYOpTXxgNueYZe/D4F0xjrauxziHUGdbVuX1Be1sLm3SqqTkj5Q89VhKTQyzgh2A5vB
         YodDGvblBv2hDW434k01KWOb3cBuiFPM8IfYrecJZTUGN6UQCHQccq7VBx+xkLETZtIz
         YkAQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560062; x=1729164862;
        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=bckn3YFGIgJxyi6JuzR+D6XCfS8U3/QVQiTYkjNWbHI=;
        b=I3dX+4za5P9SqndaTLFK+sxODSA9tjdX3bXptCG4eo0sMCdK94PSZvDsKCBLIYH2i9
         bbH8j/LdWgjdx76VGWpZ/KDNkewNWUsrjZml8XQfJqxXhXjSjN724u9tUIH3E3IgVSB9
         Cf0yzIv6icRdAXviVpdh3yYd2GoFx3QbofQjceeBLBBWJpyNUL5rpMb/q/rcxzKF7/sb
         jEvD2f0s274UWQlU3wPF77tbDmLTLU/WN6PADBMES51d4KtLju3iX7Le+KxTZRljmrfl
         /MnzM1c1guTjuz82X/ZfBkydT9r7AKhbSQstsBGStfh3JzcCuksSzn1DqDsRrLKIMNlL
         8KCg==
X-Forwarded-Encrypted: i=1; AJvYcCUF95dW6PFFRHV7s4HngtRhuFCRI6lP5n00A++a50Wu9Op3Ygz+AJvgsqj2R/ilugsJrXPz+cidY8g/PWc=@vger.kernel.org
X-Gm-Message-State: AOJu0Yy1IHOYf6Ka6K01yqnqfkWZvK6T/gZqVy7FmkzkzKCXeiTHyPRY
	tZDnCvnPLOLZTP+tFg2HpFsqMtf28ZDfuWDTMfVrzWRtUvVzxp8WYRJ93LUWV7Q=
X-Google-Smtp-Source: AGHT+IFigyJ/4+OGI1gC8uCP0lgfYv0O7YK2EBVE6+TDguBMfdVneKhgbLHN8YNte2qxqNUZjO00NA==
X-Received: by 2002:a17:907:944d:b0:a99:5baf:12a4 with SMTP id a640c23a62f3a-a999e695b35mr298335366b.17.1728560062133;
        Thu, 10 Oct 2024 04:34:22 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.20
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:34:20 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:34:01 +0200
Subject: [PATCH RFC 23/28] ARM: entry: Stop exiting syscalls like IRQs
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-23-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

The syscalls are issued as software interrupts, and to this point
they were sharing code with the other exception handlers, but
this does not work with generic entry.

Make syscall_exit_to_user_mode do what irqentry_exit_to_user_mode
does at it's tail, and drop the invocations of
irqentry_exit_to_user_mode from the syscall path so that these
are now exception-exclusive.

Split ret_to_user and ret_to_user_from_irq into two distinct
execution paths.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/kernel/entry-common.S | 14 ++++++++++++--
 arch/arm/kernel/entry.c        |  4 ++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index 5385574c4339..e2ac6d3216b6 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -42,7 +42,6 @@ ret_fast_syscall:
 	/* do_rseq_syscall needs interrupts enabled. */
 	mov	r0, sp				@ 'regs'
 	bl	syscall_exit_to_user_mode
-	asm_irqentry_exit_to_user_mode
 
 #ifdef CONFIG_GCC_PLUGIN_STACKLEAK
 	bl	stackleak_erase_on_task_stack
@@ -62,6 +61,18 @@ ENTRY(ret_to_user)
 	enable_irq_notrace			@ enable interrupts
 	mov	r0, sp				@ 'regs'
 	bl	syscall_exit_to_user_mode
+	ldr	r1, [tsk, #TI_FLAGS]
+	movs	r1, r1, lsl #16
+	beq	1f
+	mov	r0, sp				@ 'regs'
+	bl	do_work_pending
+1:
+#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
+	bl	stackleak_erase_on_task_stack
+#endif
+	restore_user_regs
+ENDPROC(ret_to_user)
+
 ENTRY(ret_to_user_from_irq)
 	ldr	r1, [tsk, #TI_FLAGS]
 	movs	r1, r1, lsl #16
@@ -76,7 +87,6 @@ no_work_pending:
 #endif
 	restore_user_regs
 ENDPROC(ret_to_user_from_irq)
-ENDPROC(ret_to_user)
 
 /*
  * This is how we return from a fork.
diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c
index 0e3960844b94..88a7a699306a 100644
--- a/arch/arm/kernel/entry.c
+++ b/arch/arm/kernel/entry.c
@@ -30,6 +30,10 @@ void syscall_exit_to_user_mode(struct pt_regs *regs)
 	local_irq_disable();
 	if (has_syscall_work(flags))
 		do_work_pending(regs, flags);
+
+	trace_hardirqs_on();
+	/* This context tracking call has inverse naming */
+	user_enter_callable();
 }
 
 noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs)

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49])
	(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 04C7A1CB53B
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:24 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560066; cv=none; b=XyvQhh0tO6c3fcW2TpBcDacgVdTBLuVj1oxst/PBZq4S8yrfEsVXyQjhnDAkfD6OJd71uk2xD0d3w/nhRcRfJ3A2uxAGEzs48DT7RcHdoUWInQ0/+lF41CRm/AiJJv+RY+27tBEHxevEAK27qzBr0uzbG2Vv0e/0dFgXKJrCL2Y=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560066; c=relaxed/simple;
	bh=pM9plyuaboA4oYUAVGKr/KBZR4661Ija+Nu2nTY/g5A=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=kEOm47htgXtnZrQKSPg61Hl5jZnKq4N3/N0zYH2I6uKbEfI439pcSIrzu+KXNCQyx80WwfY0u4PTW6RlIuPuBvlu05c1hdRKVcv2DpYsHL3m67r2whA02kuHZ+sRuY/fyBsX428Gc9lk38FkSDMGMCLf1IKmO/mdDElzu7Wgi1s=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=uOi84F2v; arc=none smtp.client-ip=209.85.218.49
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="uOi84F2v"
Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a9982159d98so132498566b.1
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:24 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560063; x=1729164863; 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=Y1Hv1gsrpr1we4HbxlxxqJW/y8rgdVZEtXO9KHxWDAg=;
        b=uOi84F2vjQrzznL/V2mC57q3XXYZwrhxToJ4KRl9Lc4Y7RwM4X0MhB3ssj8Joqkf/4
         V6XLl9u6AfS6zd+Vbm5XZsu3tNteass4YUZ1e6pZ2QnpWKHvenxiULfITtmmRor3XqVS
         vJYbP1pq6iSZM+nScvbR8mPdxqpYMeOQ71rvcWhTdMrKC5Nm+JLDXO1wQdwWe/tJ/ZmY
         8F6WjTkxZJ0AdznZSwx9nsSxmNtm/cVcgSqh94r0tMEZcONX2oaPPjY6GJilpeI0478V
         gOfsBA0mS7A0InSU9W+UbD5MriYQNAd/aB5aK7rMjT+Asc9MJ9rDRoUd4EQmfaxeaWIJ
         Etaw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560063; x=1729164863;
        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=Y1Hv1gsrpr1we4HbxlxxqJW/y8rgdVZEtXO9KHxWDAg=;
        b=JaSGR4szJVAqyWE6ARDB705g2u/B+HI+cmLrb9qDUo5eWkHkM9GDGyl1mfGeTFhCer
         5b1Y9yrWWcyixDeBJOupBleoW90x2jqD6KLuFT2x65KJnifAcGqpuS+jegIcuuUpPGAG
         6k2wRNhEgO+r4wVFYeWY4FFgDI3rl4XFe8ikbjra5hTsHvsGt+bYi3LxBN5rjbNv50Mv
         AZt01jbMo734mm7xaAL5/booybQNK7xzlFPvJCflDBL2FoDCOPFbH0AM5QdQYGoGSzhs
         RBn02uI5EaPVxXQfCSNC2J7Cd4+4mQz7V+RxZggoy6YSrDD0+DjUEt+/qoVsv1KsjPJg
         +sPg==
X-Forwarded-Encrypted: i=1; AJvYcCWNYLal/B1wDBFzEvO+M/Y3bFcYUU8PfOXB18zlUYeoDUheoqoXWzgBcr+pXpPQ2xJDs50CXbmJFve4DZ8=@vger.kernel.org
X-Gm-Message-State: AOJu0Yy2S7zky0AFjWdodV2LoyGrsGhIgXQuQzyZLJWdN7I0TITsD6ez
	gkIKfmm3BtxWyWf87wIxvQEHoNOGxiiPqZmnsH4mIY2a7zK5MzHEPKkqNfUFhlM=
X-Google-Smtp-Source: AGHT+IHJRHiR4KzKVHqPedhfFs92LdPjHSU6zPVuDKN5K3YQhsffs0YsSzQJndzJhUDXQSRYclCqMA==
X-Received: by 2002:a17:907:e648:b0:a99:5985:bf39 with SMTP id a640c23a62f3a-a998d117e0amr515807466b.13.1728560063234;
        Thu, 10 Oct 2024 04:34:23 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.22
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:34:22 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:34:02 +0200
Subject: [PATCH RFC 24/28] ARM: entry: Complete syscall and IRQ transition
 to C
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-24-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

This moves over the last few lines of assembly to C. The
subtle change is that in return to userspace from syscall
(SWI) or interrupt, we need to call do_work_pending()
as soon as the thread flags are != 0, just checking for
work with _TIF_SYSCALL_WORK is not enough (the machine will
freeze if we do that).

This is because do_work_pending() does not just handle
work: it handles _TIF_NEED_RESCHED, _TIF_SIGPENDING,
_TIF_NOTIFY_SIGNAL and _TIF_UPROBE as well.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/kernel/entry-common.S | 13 +------------
 arch/arm/kernel/entry.c        | 19 +++++++++++++------
 arch/arm/kernel/signal.c       |  3 +--
 3 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index e2ac6d3216b6..6b0f86786a7d 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -61,12 +61,7 @@ ENTRY(ret_to_user)
 	enable_irq_notrace			@ enable interrupts
 	mov	r0, sp				@ 'regs'
 	bl	syscall_exit_to_user_mode
-	ldr	r1, [tsk, #TI_FLAGS]
-	movs	r1, r1, lsl #16
-	beq	1f
-	mov	r0, sp				@ 'regs'
-	bl	do_work_pending
-1:
+
 #ifdef CONFIG_GCC_PLUGIN_STACKLEAK
 	bl	stackleak_erase_on_task_stack
 #endif
@@ -74,12 +69,6 @@ ENTRY(ret_to_user)
 ENDPROC(ret_to_user)
 
 ENTRY(ret_to_user_from_irq)
-	ldr	r1, [tsk, #TI_FLAGS]
-	movs	r1, r1, lsl #16
-	beq	no_work_pending
-	mov	r0, sp				@ 'regs'
-	bl	do_work_pending
-no_work_pending:
 	asm_irqentry_exit_to_user_mode
 
 #ifdef CONFIG_GCC_PLUGIN_STACKLEAK
diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c
index 88a7a699306a..d7fdb9df3331 100644
--- a/arch/arm/kernel/entry.c
+++ b/arch/arm/kernel/entry.c
@@ -6,11 +6,6 @@
 #include <linux/irqflags.h>
 #include <linux/rseq.h>
 
-static inline bool has_syscall_work(unsigned long flags)
-{
-	return unlikely(flags & _TIF_SYSCALL_WORK);
-}
-
 long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall)
 {
 	trace_hardirqs_on();
@@ -28,7 +23,11 @@ void syscall_exit_to_user_mode(struct pt_regs *regs)
 
 	rseq_syscall(regs);
 	local_irq_disable();
-	if (has_syscall_work(flags))
+	/*
+	 * It really matters that we check for flags != 0 and not
+	 * just for pending work here!
+	 */
+	if (flags)
 		do_work_pending(regs, flags);
 
 	trace_hardirqs_on();
@@ -45,6 +44,14 @@ noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs)
 
 noinstr void irqentry_exit_to_user_mode(struct pt_regs *regs)
 {
+	unsigned long flags = read_thread_flags();
+
+	/*
+	 * It really matters that we check for flags != 0 and not
+	 * just for pending work here!
+	 */
+	if (flags)
+		do_work_pending(regs, flags);
 	trace_hardirqs_on();
 	/* This context tracking call has inverse naming */
 	user_enter_callable();
diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
index 03b20637a2e1..a39ee14ec5b7 100644
--- a/arch/arm/kernel/signal.c
+++ b/arch/arm/kernel/signal.c
@@ -598,8 +598,7 @@ static void arch_do_signal_or_restart(struct pt_regs *regs)
 	return;
 }
 
-asmlinkage void
-do_work_pending(struct pt_regs *regs, unsigned int thread_flags)
+void do_work_pending(struct pt_regs *regs, unsigned int thread_flags)
 {
 	/*
 	 * The assembly code enters us with IRQs off, but it hasn't

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53])
	(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 326781CC16E
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:27 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560069; cv=none; b=Y2m57wlfxz1dGUBGuWXA47yM6Nl0jh9Hukc2NM+cfbA5rtmvKeiFPEjZwn2KKyMCNdIykb1dXnm2KKz9DdLgX0MfBM+JldZHY6ERIok/oayd2UJEI84mjv7eVEQRDoZPUrRFbrF4ZYoDFcNQX1Uw20KNDKXus5JT91rjj4pLnl4=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560069; c=relaxed/simple;
	bh=p++J5jDdayY9hU28M7/pcg9MrpkZxPTcO20YZjwEn6Q=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=pcLa8j4pe8dvgUHzUzviCTeXUHV/8rub9ukWRfFf/ankgteLWv6XhnM6TyS/fLZzMMXq+TiU8WG7DesrqiYHdzW3qbFLrSyVXhtdfI7F4VjT/+L5tjYd4vFG71eROEbUILa5qd6syUe4mq60ABkd9TYh3BNVELuVM60Wy8kjBa4=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=ZtOa91WW; arc=none smtp.client-ip=209.85.218.53
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ZtOa91WW"
Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a93c1cc74fdso139081466b.3
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:26 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560065; x=1729164865; 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=ZScZ0+O1z+KD5ly1wGwp6XJNh1QIX+DiUm/Qzjn1DDQ=;
        b=ZtOa91WWZGwpZ+4DDZ/AJU37MR+VJKP/mrTjf4uWOtXhhCQgG/KtSOgptCtftuTJ3R
         i6PPmlRpqVVTck575zsLbHynYPwNWLpBpflN4hmp1QfeAg79wXHF9cpjwu4u3J8q4khA
         k/xlREfyoyYfZitkh4hvFd075MRkGN+yIKLV+rOFtIeNrnr4XGIqWrE7B79+6F9dB1Ui
         4KsdVDiRpfPm7Rd42wJAd2C3Gj3ZGen+jzf9WhkdyocucbxRaKw2HYAehfIJarJCSkGF
         8E6A6wzRzr9a73+0Uqno5XheYDUbIJcdb0S8QUycMipwNOCC2GBQbxIRA0of/K+3AvJT
         K7Uw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560065; x=1729164865;
        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=ZScZ0+O1z+KD5ly1wGwp6XJNh1QIX+DiUm/Qzjn1DDQ=;
        b=G3onmkYnxHvtjR9eKpBQ+4lYykERTJhPhPW8CQz6G2jD9SCWU3NhZoeIS//blTLVME
         JfKz/fSRsHdVeCGg2rteO8k+T4hAEfYyw45W3Ng7bJdUpI3KiMdMtrdUZxTC/z81dU8w
         zUmr11Bw7JVYywlzZ1lghO6F7LWsysnxj1jMLcZ+VNjUAYaKNCP4dxkzas4NG/gvr4eK
         JO1vcjUabyO704j2wOKvAEjXING4STOZjRZqcFMwyzxK6LRxzxe3oWNVZJA1YZU3ct9c
         /SXh7Jufpj4VI8C7YivDerhtceja/NzekLVx7VUJQqVnzVAydS7qOFhugKkkynvoPdcU
         Jm5w==
X-Forwarded-Encrypted: i=1; AJvYcCXHQUpZvMRxBEfuTY+mKNfgpkawz+jQuuj6Xx2pB4Gs0CcvwGfYo6HQjRzA0U+XpSRIttBIVObMAg/qdmg=@vger.kernel.org
X-Gm-Message-State: AOJu0YxcMKUG8/948Fz5It/LOYmastKwEISjqv1rPOhHi7/sOZqRsVaW
	ho8R3An+g0an3XRN7ujp9/7JHL6ryViJRv6WjwpB+ZpGlelTTABiv8J0snamQ9A=
X-Google-Smtp-Source: AGHT+IGPbjmbOuudiYSl7s9WBi8ngVmIAJNEhV6kvE7fpNTobtjhLab6+DrMs8j68CZRmdtyA7IjSw==
X-Received: by 2002:a17:907:9810:b0:a99:4fce:c343 with SMTP id a640c23a62f3a-a998d1cb499mr538738466b.26.1728560065458;
        Thu, 10 Oct 2024 04:34:25 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.24
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:34:25 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:34:04 +0200
Subject: [PATCH RFC 26/28] ARM: entry: Move in-kernel hardirq tracing to C
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-26-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

Move the code tracing hardirqs on/off into the C callbacks
for irqentry_enter_from_kernel_mode() and
irqentry_exit_to_kernel_mode().

The semantic difference occurred is that we alsways check
the PSR_I_BIT to determine if (hard) interrupts were enabled
or not. The assembly has a tweak to avoid this if we are
exiting an IRQ since it is obvious that IRQs must have been
enabled to get there, but for simplicity we just check it
for all exceptions.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/kernel/entry-armv.S   | 13 ++++---------
 arch/arm/kernel/entry-header.S | 19 ++-----------------
 arch/arm/kernel/entry.c        |  5 +++++
 3 files changed, 11 insertions(+), 26 deletions(-)

diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
index 21b11fe199cb..600375f6f5d8 100644
--- a/arch/arm/kernel/entry-armv.S
+++ b/arch/arm/kernel/entry-armv.S
@@ -157,7 +157,7 @@ ENDPROC(__und_invalid)
 #define SPFIX(code...)
 #endif
 
-	.macro	svc_entry, stack_hole=0, trace=1, uaccess=1, overflow_check=1
+	.macro	svc_entry, stack_hole=0 uaccess=1, overflow_check=1
  UNWIND(.fnstart		)
 	sub	sp, sp, #(SVC_REGS_SIZE + \stack_hole)
  THUMB(	add	sp, r1		)	@ get SP in a GPR without
@@ -207,11 +207,6 @@ ENDPROC(__und_invalid)
 	mov	r0, sp				@ 'regs'
 	bl	irqentry_enter_from_kernel_mode
 
-	.if \trace
-#ifdef CONFIG_TRACE_IRQFLAGS
-	bl	trace_hardirqs_off
-#endif
-	.endif
 	.endm
 
 	.align	5
@@ -238,7 +233,7 @@ __irq_svc:
 	blne	svc_preempt
 #endif
 
-	svc_exit r5, irq = 1			@ return from exception
+	svc_exit r5				@ return from exception
  UNWIND(.fnend		)
 ENDPROC(__irq_svc)
 
@@ -302,7 +297,7 @@ ENDPROC(__pabt_svc)
 
 	.align	5
 __fiq_svc:
-	svc_entry trace=0
+	svc_entry
 	mov	r0, sp				@ struct pt_regs *regs
 	bl	handle_fiq_as_nmi
 	svc_exit_via_fiq
@@ -320,7 +315,7 @@ ENDPROC(__fiq_svc)
 @
 	.align 5
 __fiq_abt:
-	svc_entry trace=0
+	svc_entry
 
  ARM(	msr	cpsr_c, #ABT_MODE | PSR_I_BIT | PSR_F_BIT )
  THUMB( mov	r0, #ABT_MODE | PSR_I_BIT | PSR_F_BIT )
diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
index 49a9c5cf6fd5..cfaf14d71378 100644
--- a/arch/arm/kernel/entry-header.S
+++ b/arch/arm/kernel/entry-header.S
@@ -199,26 +199,11 @@
 	.endm
 
 
-	.macro	svc_exit, rpsr, irq = 0
-	.if	\irq != 0
-	@ IRQs already off
-#ifdef CONFIG_TRACE_IRQFLAGS
-	@ The parent context IRQs must have been enabled to get here in
-	@ the first place, so there's no point checking the PSR I bit.
-	bl	trace_hardirqs_on
-#endif
-	.else
+	.macro	svc_exit, rpsr
+
 	@ IRQs off again before pulling preserved data off the stack
 	disable_irq_notrace
 
-#ifdef CONFIG_TRACE_IRQFLAGS
-	tst	\rpsr, #PSR_I_BIT
-	bleq	trace_hardirqs_on
-	tst	\rpsr, #PSR_I_BIT
-	blne	trace_hardirqs_off
-#endif
-	.endif
-
 	mov	r0, sp				@ 'regs'
 	bl	irqentry_exit_to_kernel_mode
 
diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c
index 674b5adcec00..1e1284cc4cae 100644
--- a/arch/arm/kernel/entry.c
+++ b/arch/arm/kernel/entry.c
@@ -59,8 +59,13 @@ noinstr void irqentry_exit_to_user_mode(struct pt_regs *regs)
 
 noinstr void irqentry_enter_from_kernel_mode(struct pt_regs *regs)
 {
+	trace_hardirqs_off();
 }
 
 noinstr void irqentry_exit_to_kernel_mode(struct pt_regs *regs)
 {
+	if (interrupts_enabled(regs))
+		trace_hardirqs_on();
+	else
+		trace_hardirqs_off();
 }

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44])
	(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 118091CC888
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:25 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560069; cv=none; b=qzJWTrUqqTTx89NFR1AuR5IfN7DNSxFmFQzfkedsfZU9nXXQjrCmjy3CPGW50WwKexHwDCalquU1jr2wCz/409Cm6Ra77syFhbsqShZBLw/roIjnzI4HCZetUm1mtn0y5b0R25yFF7ZUDnwg5KOTpAb11D3XAH7d+nnoo1rRh/E=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560069; c=relaxed/simple;
	bh=1+xGn+I5zGJWUmASKFRl6SMQB/wIv78GqsCAwMsFqAA=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=jSXeaC+8mJvLqVZa4z0P5hs3aEk34fKHT93OMoPqdb8ZUdJTHhtka39DvVqFjOBDLk8zZ1/b00ik9SENEzMnCo2A8EYDRNddsXPCouuDGHRXkrwuExcNbFwumNTPL/j41HDobtLZPYyxqaHrxU29Ig1tz1vhQYbwGUmMqwhxE5g=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=MMKJjPOq; arc=none smtp.client-ip=209.85.218.44
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="MMKJjPOq"
Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a99422c796eso133967866b.3
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:25 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560064; x=1729164864; 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=e/3IXPLtEzkdPxakYsKtSl6x7P98QonT1kDDJ6tUink=;
        b=MMKJjPOqhQ8V4bLtNtkBSCmOJ2MbWwbR29lC4DTx33+UqiFlHG56NhVyDuTrFf+9QF
         sC3LC59VhvR7/EcN3brdDjyGBCXZkCmmILFP6IsnbIDY8zEa7iE076lZOzKDect3SFvX
         L3pyGOViMHhibZfw1pBn4JS46Ww48pU4lz5PmFQ+56osMHDvtLMkmATyB7+aie0oMjQW
         2S7fNErwPOvWvbQfn8rLzZsW1HCSgVzOtFFotSGLz2uirLmdB5kvCOXZs4lYlhdIcU53
         Zx1JKdma/Ga539wEGdtVP+eVL92s4/eD1yeBvutL0mXC+zzTMKrBfTzdjbpJqg10OPpd
         YS3g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560064; x=1729164864;
        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=e/3IXPLtEzkdPxakYsKtSl6x7P98QonT1kDDJ6tUink=;
        b=GZeiz2CvBt0RTGrXMbzEp9jC9zOI3fTrRljVeoeH2L8c2RuQ6gDznjMLJ6DJO1zM/3
         G8OEoFoS3Y8a6sM/RbA4F/WrSKQK7LYojM1iI6/3dUwDM2gyuaQsI31IWb5Z5DVJ2Uqv
         iFbfJwl+2GutJ7NfN1nFSFz8hd5lnH3AT+CXdfGqllkPVqXBlFXZE8YSKonXIo1KfHfV
         kxJsY/3NKeK/NMMhZE3A96c+VLzUAf72YelZZAOj8lUF+HwXWVtjAz8eGBKM4jWdSXL7
         4Ytkva6EunTykcSchrUxFLkza05YNFcva5RU8GF9Hht0/UYMeK5ZmWK0f2O5C1MkPSWE
         7ECw==
X-Forwarded-Encrypted: i=1; AJvYcCW+n0RHVJ5E2Zu06+kVl9vN/ulZ8VyccTNS4pkmKhjVuF7/uR7XoBOPPiZX5AfnCFaoNEZzVRbPfz3OkZw=@vger.kernel.org
X-Gm-Message-State: AOJu0YxnLLlOmmdKj4fZd8v9S082Xi4622fkxguVCjEkVS2+rACrIqmg
	Fyw0nv40ETLG6Jmcl8s/TnNAnVLygaDUmk4D23bf/xboFJJ4xZuXU0zz0zgQZPk=
X-Google-Smtp-Source: AGHT+IGSkGuyhdw8AmjZaYSG3AbwkYxBJPVivMy155PvJBG22/KVJmiGE/T4Z0mI0+yJzLqzOiUsfg==
X-Received: by 2002:a17:906:c109:b0:a99:403e:2578 with SMTP id a640c23a62f3a-a999e628eb0mr313283366b.5.1728560064365;
        Thu, 10 Oct 2024 04:34:24 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.23
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:34:23 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:34:03 +0200
Subject: [PATCH RFC 25/28] ARM: entry: Create irqentry calls from kernel
 mode
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-25-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

This adds a few calls to C when exceptions enter/exit from
the kernel itself, so these can be used for generic entry.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/include/asm/entry.h   | 2 ++
 arch/arm/kernel/entry-armv.S   | 3 +++
 arch/arm/kernel/entry-header.S | 5 +++++
 arch/arm/kernel/entry.c        | 8 ++++++++
 4 files changed, 18 insertions(+)

diff --git a/arch/arm/include/asm/entry.h b/arch/arm/include/asm/entry.h
index 8b8cc9a1eefb..a78bc5054b09 100644
--- a/arch/arm/include/asm/entry.h
+++ b/arch/arm/include/asm/entry.h
@@ -12,5 +12,7 @@ long syscall_enter_from_user_mode(struct pt_regs *regs, long);
 void syscall_exit_to_user_mode(struct pt_regs *regs);
 void irqentry_enter_from_user_mode(struct pt_regs *regs);
 void irqentry_exit_to_user_mode(struct pt_regs *regs);
+void irqentry_enter_from_kernel_mode(struct pt_regs *regs);
+void irqentry_exit_to_kernel_mode(struct pt_regs *regs);
 
 #endif /* __ASM_ENTRY_H__ */
diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
index bd468d58dc02..21b11fe199cb 100644
--- a/arch/arm/kernel/entry-armv.S
+++ b/arch/arm/kernel/entry-armv.S
@@ -204,6 +204,9 @@ ENDPROC(__und_invalid)
 	get_thread_info tsk
 	uaccess_entry tsk, r0, r1, r2, \uaccess
 
+	mov	r0, sp				@ 'regs'
+	bl	irqentry_enter_from_kernel_mode
+
 	.if \trace
 #ifdef CONFIG_TRACE_IRQFLAGS
 	bl	trace_hardirqs_off
diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
index 51c7f93c1ded..49a9c5cf6fd5 100644
--- a/arch/arm/kernel/entry-header.S
+++ b/arch/arm/kernel/entry-header.S
@@ -210,6 +210,7 @@
 	.else
 	@ IRQs off again before pulling preserved data off the stack
 	disable_irq_notrace
+
 #ifdef CONFIG_TRACE_IRQFLAGS
 	tst	\rpsr, #PSR_I_BIT
 	bleq	trace_hardirqs_on
@@ -217,6 +218,10 @@
 	blne	trace_hardirqs_off
 #endif
 	.endif
+
+	mov	r0, sp				@ 'regs'
+	bl	irqentry_exit_to_kernel_mode
+
 	uaccess_exit tsk, r0, r1
 
 #ifndef CONFIG_THUMB2_KERNEL
diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c
index d7fdb9df3331..674b5adcec00 100644
--- a/arch/arm/kernel/entry.c
+++ b/arch/arm/kernel/entry.c
@@ -56,3 +56,11 @@ noinstr void irqentry_exit_to_user_mode(struct pt_regs *regs)
 	/* This context tracking call has inverse naming */
 	user_enter_callable();
 }
+
+noinstr void irqentry_enter_from_kernel_mode(struct pt_regs *regs)
+{
+}
+
+noinstr void irqentry_exit_to_kernel_mode(struct pt_regs *regs)
+{
+}

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47])
	(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 4D3EF1CC89F
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:29 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560071; cv=none; b=HZHBGPMIMJvnu3xbp07VQj5gpsD3GzPRc2B5Nl7ESaROLr+qjd/mdto2/cNkBkvK9+PhB810m63bBq1379TFOw4Ng1TpCB5RLdfhR63suZj/VrRBA1bRFfIe2NA1iQ9c9bXDvizl2T+aS4qHLOKs8RfBSdcxbocuPQ2hXXCgDsw=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560071; c=relaxed/simple;
	bh=LswCk2i9g8K5KyBn9gI4xldOhoqS7tQiTwGUwHGEJZs=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=IRCI8OMMUbDxQOsWbxTq5nNCbQkgJo1TCYE0G7cg4QfVFBoTkNridMTfPcnjyZ60sntDjbutgjV9Pwbj/tYEU6idmvSYktYAdzqgXqdj5YEYnvbZv/kLrM7htp+NdZ+Oqt0K6/1XOcJTeZ7a9aWz/K7UbarPSaxIEllDGF2+spw=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=kDijuVN0; arc=none smtp.client-ip=209.85.218.47
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="kDijuVN0"
Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a995ec65c35so137467366b.1
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:29 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560067; x=1729164867; 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=/aytaH1oLbxE7oXL5Lh1BICkPib3Ft7vQWy4tTKokWI=;
        b=kDijuVN05AoRJDlnxR80lc9daqXdgtuMnzldu6eFJaIkeQm6a9/2IN60AcqdCRJ0gs
         Ty+2ho0QjTFk97O7mcA6PosqMYFextqI/A83Emrwd54Mj1TOqhCTq2X7HVQxIlMl36tV
         O2UDpIIbZYP8ohf4xSSc+H4omr2l+nXgrP0j91EPtkAjqsHr0/eg19TRRo0urhlgVXAJ
         8qbsKQzxJA7N4B1jhkN4RihZZKRaRbh4MxI9+2m7SqkKGr7zCyQoRtW3B5RXzRh5NgEp
         t4OPZlZt0dgKu0n6r+SzZ1iViIOW0j+s5qlmaMyaCJSJE3tCNZCrPosjS6cmgy8IyXAx
         1D3A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560067; x=1729164867;
        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=/aytaH1oLbxE7oXL5Lh1BICkPib3Ft7vQWy4tTKokWI=;
        b=AYe4DnUZJjRIJvgW7ni0soh6DDbcQpfQKZ2qWuLkDGtZ0XXpqIeJ4Zw/1a/z0l+k8n
         H8thkJbwXibNccsBn8wruKVPmtbTNUY34JzVDJYU4/YfQYdN0dZUU/97fEmhDBIWzEgX
         z4CRZsWWT1yfiQ8G1pJVOMXKLmEN4rAX4IcdV9o/khiOZn9pct2t4xguCoihAWSHO3BP
         9fm7iKsAuUTlE7Ls+QSAtveyxf5RxfPL/UYxS9/DW/jEPG7KD/rzPKVg5Af7eanntjqL
         x/ABkUiTRnz1aQUVrUNNaBwMqRcRZ+CK20qOuOX/jtF+fVWDRE6bjUOPCy1Nom49necm
         uSVg==
X-Forwarded-Encrypted: i=1; AJvYcCXx3uCr8/tlrCKgiqSm+PZYcfu9DYFR9kwk/QIMtX6d7zh7i+W0IaBbVjj6hoEklTN7yf9GFI6vSQc8VfM=@vger.kernel.org
X-Gm-Message-State: AOJu0YyJ35E39wm6Qu+Eg1U1x6iRnZbqN0WbYlFKCTS2+DC453gQYwxX
	G7xEJj2ucCFk7VGR+IUwnb2hZYhRpE2nJ9XT9N3sdyfsqBfI3jVUMVFC3PLubUw=
X-Google-Smtp-Source: AGHT+IHJCZC9ttmjEV4fugv9O8uxWYQ1Bo3ztMHrIb7V/zI60wobNn2BdMO/fiOPIzAK9oQNZ6UZoA==
X-Received: by 2002:a17:907:940a:b0:a99:55ca:3758 with SMTP id a640c23a62f3a-a99a10e840emr242802266b.8.1728560067473;
        Thu, 10 Oct 2024 04:34:27 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.25
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:34:26 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:34:05 +0200
Subject: [PATCH RFC 27/28] ARM: entry: Add FIQ/NMI C callbacks
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-27-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

These NMI (FIQ) callbacks are added to complete the calls expected
by the generic entry. They are perfectly fine to add code to
but are left empty for now.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/include/asm/entry.h   |  4 ++++
 arch/arm/kernel/entry-armv.S   | 14 +++++++++++---
 arch/arm/kernel/entry-header.S |  2 ++
 arch/arm/kernel/entry.c        | 16 ++++++++++++++++
 4 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/arch/arm/include/asm/entry.h b/arch/arm/include/asm/entry.h
index a78bc5054b09..2e7ccd87f0eb 100644
--- a/arch/arm/include/asm/entry.h
+++ b/arch/arm/include/asm/entry.h
@@ -14,5 +14,9 @@ void irqentry_enter_from_user_mode(struct pt_regs *regs);
 void irqentry_exit_to_user_mode(struct pt_regs *regs);
 void irqentry_enter_from_kernel_mode(struct pt_regs *regs);
 void irqentry_exit_to_kernel_mode(struct pt_regs *regs);
+void irqentry_nmi_enter_from_user_mode(struct pt_regs *regs);
+void irqentry_nmi_exit_to_user_mode(struct pt_regs *regs);
+void irqentry_nmi_enter_from_kernel_mode(struct pt_regs *regs);
+void irqentry_nmi_exit_to_kernel_mode(struct pt_regs *regs);
 
 #endif /* __ASM_ENTRY_H__ */
diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
index 600375f6f5d8..839f3ebe7228 100644
--- a/arch/arm/kernel/entry-armv.S
+++ b/arch/arm/kernel/entry-armv.S
@@ -157,7 +157,7 @@ ENDPROC(__und_invalid)
 #define SPFIX(code...)
 #endif
 
-	.macro	svc_entry, stack_hole=0 uaccess=1, overflow_check=1
+	.macro	svc_entry, stack_hole=0 uaccess=1, overflow_check=1, nmi=0
  UNWIND(.fnstart		)
 	sub	sp, sp, #(SVC_REGS_SIZE + \stack_hole)
  THUMB(	add	sp, r1		)	@ get SP in a GPR without
@@ -205,7 +205,11 @@ ENDPROC(__und_invalid)
 	uaccess_entry tsk, r0, r1, r2, \uaccess
 
 	mov	r0, sp				@ 'regs'
+	.if \nmi
+	bl	irqentry_nmi_enter_from_kernel_mode
+	.else
 	bl	irqentry_enter_from_kernel_mode
+	.endif
 
 	.endm
 
@@ -297,7 +301,7 @@ ENDPROC(__pabt_svc)
 
 	.align	5
 __fiq_svc:
-	svc_entry
+	svc_entry nmi=1
 	mov	r0, sp				@ struct pt_regs *regs
 	bl	handle_fiq_as_nmi
 	svc_exit_via_fiq
@@ -315,7 +319,7 @@ ENDPROC(__fiq_svc)
 @
 	.align 5
 __fiq_abt:
-	svc_entry
+	svc_entry nmi=1
 
  ARM(	msr	cpsr_c, #ABT_MODE | PSR_I_BIT | PSR_F_BIT )
  THUMB( mov	r0, #ABT_MODE | PSR_I_BIT | PSR_F_BIT )
@@ -490,9 +494,13 @@ ENDPROC(ret_from_exception)
 	.align	5
 __fiq_usr:
 	usr_entry
+	mov	r0, sp
+	bl	irqentry_nmi_enter_from_user_mode
 	kuser_cmpxchg_check
 	mov	r0, sp				@ struct pt_regs *regs
 	bl	handle_fiq_as_nmi
+	mov	r0, sp
+	bl	irqentry_nmi_exit_to_user_mode
 	get_thread_info tsk
 	restore_user_regs
  UNWIND(.fnend		)
diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
index cfaf14d71378..ec8a6e193802 100644
--- a/arch/arm/kernel/entry-header.S
+++ b/arch/arm/kernel/entry-header.S
@@ -252,6 +252,8 @@
 	@
 	.macro  svc_exit_via_fiq
 	uaccess_exit tsk, r0, r1
+	mov	r0, sp
+	bl	irqentry_nmi_exit_to_kernel_mode
 #ifndef CONFIG_THUMB2_KERNEL
 	@ ARM mode restore
 	mov	r0, sp
diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c
index 1e1284cc4cae..09109215dfdf 100644
--- a/arch/arm/kernel/entry.c
+++ b/arch/arm/kernel/entry.c
@@ -69,3 +69,19 @@ noinstr void irqentry_exit_to_kernel_mode(struct pt_regs *regs)
 	else
 		trace_hardirqs_off();
 }
+
+noinstr void irqentry_nmi_enter_from_user_mode(struct pt_regs *regs)
+{
+}
+
+noinstr void irqentry_nmi_exit_to_user_mode(struct pt_regs *regs)
+{
+}
+
+noinstr void irqentry_nmi_enter_from_kernel_mode(struct pt_regs *regs)
+{
+}
+
+noinstr void irqentry_nmi_exit_to_kernel_mode(struct pt_regs *regs)
+{
+}

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50])
	(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 619841CC17A
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:34:30 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728560072; cv=none; b=Q7w9NEv0F32rjRSZLLIY0O3ad3ahuC1Yahs4LTbSUBO7KaJRPH1W9nqHtQBgD3mpLHXtYqa27aw15ZgqouoEqXburpFzXk3zS8vLr115YUlnJFpwZyovmQhPjkrKatgIv0tvSciE6PCbofLvMMk56bDAU/hW4iIKsbInO4w8toI=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728560072; c=relaxed/simple;
	bh=uPeneaNYhI5as6kmA2he0Saqo+6XyjuMdjrSQcWI3QE=;
	h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References:
	 In-Reply-To:To:Cc; b=jLzHNfcr2ai5rvEIT1aGRi/Xaji2dlnvYqzar0gepK853d/Ej58jincH8S37DgFfRHaS5c0XYJRJb9SKLs61HODJwraZMk0802U4xUuFneQE220whqoqbLUVOzfY3CRXL7FqqZcypayXV2Wg2iHOuV07BnjilxTdNFlMXmSPyF4=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=TirkKSVU; arc=none smtp.client-ip=209.85.218.50
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="TirkKSVU"
Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a998a5ca499so116965866b.0
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 04:34:30 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728560069; x=1729164869; 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=n0vhef1d/tO4V+dCGdQHkCwxrnfd2znP3qGknf9D7ME=;
        b=TirkKSVUtuEEj0qON0nZwYZAP2mH+sENKk7BnMAFKphV3O0Gb18Lwo7Iuz8L7wEU/Z
         L9u39KQj+JeUpZEy0N81uQiGFE5xGhA2tmFxiAVHerOym4N6Qfu0m5oXv5je2kQPocqK
         hdEjjdQwGP09doKTNlq9tQ3eburBDd+oxBFL5l59oH9e2YaytyyMw+cmNECksPEPW3AD
         atMA3/57Dqoau9sxfFPIfbex/SI2ucpMGmcnDx15e94X2oskJ0a8dzxVS8WkPMKE93s6
         2f8juCMlc1B3QPvrwzW1ma1ei4I75/09Y19ctlhUw832+dz9cfNb2Y39QK7vwQbid8JZ
         dP4A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728560069; x=1729164869;
        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=n0vhef1d/tO4V+dCGdQHkCwxrnfd2znP3qGknf9D7ME=;
        b=Ac2nKIRQhLXdnHFDRh8HoDXx3Ftbd02O9A3quR44IknSXGoJ1UaVfTimSVpoSilo0T
         PuiEXfflMdjPJ5+Z8w3KCtEvjeXzV+OiBGM5zmmDoaJ8ivrfnNkJLIWMI/ZqvqHwYeQF
         fOBOOpctrSPZL5IyXOwpnqEc+wxN71dsqUP0rBH4M4Y2qVJ1YnxfmUG5OBEbNnE3FOdn
         qJLseqXlqVPnawKMTZr4HBE8lmsxu6oSeWd0vtWAmDxzKGX+yx684uRueh6pEBKO8uD1
         JWaEtP6FV2RK36muGt+2Lfd8Cueda6mssAiNqKbQCuJUWMCoLe0zgcvaF0xLvnCgi9Zb
         jlDA==
X-Forwarded-Encrypted: i=1; AJvYcCUkvXzQ4b5cJ781WKaY8kjEIXDuZfp8OexHPHmInMXEAi2BRjE97fbqlLWq7r70Y8cYyAbnS5dyXoFQ6xA=@vger.kernel.org
X-Gm-Message-State: AOJu0YzgUhPmYWX6cn8gLp77jhtH4Lu0lAvHhZlLyPXxHSNHuH9sMHQj
	T443DSQLguQkbsqQi0fQ3KW8AAAal+A+eNwxPsQchN1wLUzB21CrJ8LHUkjiWYc=
X-Google-Smtp-Source: AGHT+IFKm2rdDuCf/QsWQ4NxI2MXBXXxaL2dIFKygtqouLDYiJ7ZzQmqCTl6FWi1bJEBc6ec7JRyjg==
X-Received: by 2002:a17:906:794b:b0:a99:35eb:1301 with SMTP id a640c23a62f3a-a998d19971cmr549151466b.18.1728560068636;
        Thu, 10 Oct 2024 04:34:28 -0700 (PDT)
Received: from lino.lan ([85.235.12.238])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a7f25406sm77619066b.69.2024.10.10.04.34.27
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 10 Oct 2024 04:34:28 -0700 (PDT)
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 13:34:06 +0200
Subject: [PATCH RFC 28/28] ARM: entry: Convert to generic entry
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Message-Id: <20241010-arm-generic-entry-v1-28-b94f451d087b@linaro.org>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
To: Oleg Nesterov <oleg@redhat.com>, Russell King <linux@armlinux.org.uk>, 
 Kees Cook <kees@kernel.org>, Andy Lutomirski <luto@amacapital.net>, 
 Will Drewry <wad@chromium.org>, Frederic Weisbecker <frederic@kernel.org>, 
 "Paul E. McKenney" <paulmck@kernel.org>, 
 Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, 
 Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, 
 Linus Walleij <linus.walleij@linaro.org>
X-Mailer: b4 0.14.0

This rewrites ARM to use the generic entry.

All of the irqentry_* callbacks are renamed to arm_irqentry_*
and made to call into the generic entry code.

The state for IRQ and NMI for usermode and kernelmode is
stored into a static local variable as interrupts are
not reentrant.

The syscall_enter_from_user_mode(), syscall_exit_to_user_mode(),
do_work_pending() constructs are replaced with generic code.

The syscall invocation now enables syscall tracing "work" using
the generic callbacks and no extra actions are needed to
enable/disable syscall tracing.

The old context tracking with user_exit_callable()
user_enter_callable() is no longer used. Only CSKY and Xtensa
use this deprecated mechanism now.

Like with the ARM64 proposed patch for generic entry, it is
necessary to create a small call "arm_exit_to_user_mode()"
that is used for things such as ret_from_fork, i.e. when
we create a completely new execution context with a botched
return from interrupt.

Open questions:

- I had to add defines for PTRACE_SYSEMU and
  PTRACE_SYSEMU_SINGLESTEP and I have no idea what those
  are or why they are required. Sorry for my ignorance,
  I need help to figure out how we deal with this.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/Kconfig                    |  1 +
 arch/arm/include/asm/entry-common.h | 66 +++++++++++++++++++++++++++
 arch/arm/include/asm/entry.h        | 23 ++++------
 arch/arm/include/asm/ptrace.h       |  3 --
 arch/arm/include/asm/signal.h       |  2 -
 arch/arm/include/asm/syscall.h      |  7 ++-
 arch/arm/include/asm/thread_info.h  | 17 +------
 arch/arm/include/uapi/asm/ptrace.h  |  2 +
 arch/arm/kernel/entry-armv.S        |  8 ++--
 arch/arm/kernel/entry-common.S      | 34 +++++---------
 arch/arm/kernel/entry-header.S      |  8 ++--
 arch/arm/kernel/entry.c             | 80 +++++++++++----------------------
 arch/arm/kernel/process.c           |  2 -
 arch/arm/kernel/ptrace.c            | 90 -------------------------------------
 arch/arm/kernel/signal.c            | 31 +------------
 arch/arm/kernel/syscall.c           | 27 +++--------
 16 files changed, 137 insertions(+), 264 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 749179a1d162..8155a4be7c9b 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -66,6 +66,7 @@ config ARM
 	select GENERIC_CPU_AUTOPROBE
 	select GENERIC_CPU_DEVICES
 	select GENERIC_EARLY_IOREMAP
+	select GENERIC_ENTRY
 	select GENERIC_IDLE_POLL_SETUP
 	select GENERIC_IRQ_MULTI_HANDLER
 	select GENERIC_IRQ_PROBE
diff --git a/arch/arm/include/asm/entry-common.h b/arch/arm/include/asm/entry-common.h
new file mode 100644
index 000000000000..7b1f108512db
--- /dev/null
+++ b/arch/arm/include/asm/entry-common.h
@@ -0,0 +1,66 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _ASM_ARM_ENTRY_COMMON_H
+#define _ASM_ARM_ENTRY_COMMON_H
+
+#include <linux/thread_info.h>
+
+#include <asm/stacktrace.h>
+
+enum ptrace_syscall_dir {
+	PTRACE_SYSCALL_ENTER = 0,
+	PTRACE_SYSCALL_EXIT,
+};
+
+static inline unsigned long
+arch_prepare_report_syscall_entry(struct pt_regs *regs)
+{
+	unsigned long ip;
+
+	/*
+	 * IP is used to denote syscall entry/exit:
+	 * IP = 0 -> entry
+	 */
+	ip = regs->ARM_ip;
+	regs->ARM_ip = PTRACE_SYSCALL_ENTER;
+
+	return ip;
+}
+#define arch_prepare_report_syscall_entry arch_prepare_report_syscall_entry
+
+static inline void
+arch_post_report_syscall_entry(struct pt_regs *regs,
+			       unsigned long saved_reg, long ret)
+{
+	regs->ARM_ip = saved_reg;
+}
+#define arch_post_report_syscall_entry arch_post_report_syscall_entry
+
+
+static inline unsigned long
+arch_prepare_report_syscall_exit(struct pt_regs *regs,
+				 unsigned long work)
+{
+	unsigned long ip;
+
+	/*
+	 * IP is used to denote syscall entry/exit:
+	 * IP = 1 -> exit
+	 */
+	ip = regs->ARM_ip;
+	regs->ARM_ip = PTRACE_SYSCALL_EXIT;
+
+	return ip;
+}
+#define arch_prepare_report_syscall_exit arch_prepare_report_syscall_exit
+
+static inline void
+arch_post_report_syscall_exit(struct pt_regs *regs,
+			      unsigned long saved_reg,
+			      unsigned long work)
+{
+	regs->ARM_ip = saved_reg;
+}
+#define arch_post_report_syscall_exit arch_post_report_syscall_exit
+
+#endif /* _ASM_ARM_ENTRY_COMMON_H */
diff --git a/arch/arm/include/asm/entry.h b/arch/arm/include/asm/entry.h
index 2e7ccd87f0eb..dadf0064c65b 100644
--- a/arch/arm/include/asm/entry.h
+++ b/arch/arm/include/asm/entry.h
@@ -4,19 +4,14 @@
 
 struct pt_regs;
 
-/*
- * These are copies of generic entry headers so we can transition
- * to generic entry once they are semantically equivalent.
- */
-long syscall_enter_from_user_mode(struct pt_regs *regs, long);
-void syscall_exit_to_user_mode(struct pt_regs *regs);
-void irqentry_enter_from_user_mode(struct pt_regs *regs);
-void irqentry_exit_to_user_mode(struct pt_regs *regs);
-void irqentry_enter_from_kernel_mode(struct pt_regs *regs);
-void irqentry_exit_to_kernel_mode(struct pt_regs *regs);
-void irqentry_nmi_enter_from_user_mode(struct pt_regs *regs);
-void irqentry_nmi_exit_to_user_mode(struct pt_regs *regs);
-void irqentry_nmi_enter_from_kernel_mode(struct pt_regs *regs);
-void irqentry_nmi_exit_to_kernel_mode(struct pt_regs *regs);
+void arm_irqentry_enter_from_user_mode(struct pt_regs *regs);
+void arm_irqentry_exit_to_user_mode(struct pt_regs *regs);
+void arm_irqentry_enter_from_kernel_mode(struct pt_regs *regs);
+void arm_irqentry_exit_to_kernel_mode(struct pt_regs *regs);
+void arm_irqentry_nmi_enter_from_user_mode(struct pt_regs *regs);
+void arm_irqentry_nmi_exit_to_user_mode(struct pt_regs *regs);
+void arm_irqentry_nmi_enter_from_kernel_mode(struct pt_regs *regs);
+void arm_irqentry_nmi_exit_to_kernel_mode(struct pt_regs *regs);
+void arm_exit_to_user_mode(struct pt_regs *regs);
 
 #endif /* __ASM_ENTRY_H__ */
diff --git a/arch/arm/include/asm/ptrace.h b/arch/arm/include/asm/ptrace.h
index a01c66f0ad90..8a7de4020cbc 100644
--- a/arch/arm/include/asm/ptrace.h
+++ b/arch/arm/include/asm/ptrace.h
@@ -200,8 +200,5 @@ static inline unsigned long it_advance(unsigned long cpsr)
 	return cpsr;
 }
 
-int syscall_trace_enter(struct pt_regs *regs);
-void syscall_trace_exit(struct pt_regs *regs);
-
 #endif /* __ASSEMBLY__ */
 #endif
diff --git a/arch/arm/include/asm/signal.h b/arch/arm/include/asm/signal.h
index bb753cd3e29f..45885383646c 100644
--- a/arch/arm/include/asm/signal.h
+++ b/arch/arm/include/asm/signal.h
@@ -23,6 +23,4 @@ typedef struct {
 
 #include <asm/sigcontext.h>
 
-void do_work_pending(struct pt_regs *regs, unsigned int thread_flags);
-
 #endif
diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h
index b94fd7ce17f8..a6c8f0e799bb 100644
--- a/arch/arm/include/asm/syscall.h
+++ b/arch/arm/include/asm/syscall.h
@@ -19,7 +19,12 @@
 
 extern const unsigned long sys_call_table[];
 
-int invoke_syscall(void *table, struct pt_regs *regs, int scno);
+void invoke_syscall(void *table, struct pt_regs *regs, int scno);
+
+static inline bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs)
+{
+	return false;
+}
 
 static inline int syscall_get_nr(struct task_struct *task,
 				 struct pt_regs *regs)
diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
index d8a45c5a1049..84e58a9cdab6 100644
--- a/arch/arm/include/asm/thread_info.h
+++ b/arch/arm/include/asm/thread_info.h
@@ -74,6 +74,7 @@ struct thread_info {
 #ifdef CONFIG_ARM_THUMBEE
 	unsigned long		thumbee_state;	/* ThumbEE Handler Base register */
 #endif
+	unsigned long		syscall_work;	/* SYSCALL_WORK_ flags */
 };
 
 #define INIT_THREAD_INFO(tsk)						\
@@ -149,30 +150,14 @@ extern int vfp_restore_user_hwstate(struct user_vfp *,
 #define TIF_USING_IWMMXT	17
 #define TIF_MEMDIE		18	/* is terminating due to OOM killer */
 #define TIF_RESTORE_SIGMASK	19
-#define TIF_SYSCALL_TRACE	20	/* syscall trace active */
-#define TIF_SYSCALL_AUDIT	21	/* syscall auditing active */
-#define TIF_SYSCALL_TRACEPOINT	22	/* syscall tracepoint instrumentation */
-#define TIF_SECCOMP		23	/* seccomp syscall filtering active */
-
 
 #define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
 #define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
 #define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
 #define _TIF_UPROBE		(1 << TIF_UPROBE)
-#define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
-#define _TIF_SYSCALL_AUDIT	(1 << TIF_SYSCALL_AUDIT)
-#define _TIF_SYSCALL_TRACEPOINT	(1 << TIF_SYSCALL_TRACEPOINT)
-#define _TIF_SECCOMP		(1 << TIF_SECCOMP)
 #define _TIF_NOTIFY_SIGNAL	(1 << TIF_NOTIFY_SIGNAL)
 #define _TIF_USING_IWMMXT	(1 << TIF_USING_IWMMXT)
 
-/* Checks for any syscall work in entry-common.S */
-#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
-			   _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
-
-/*
- * Change these and you break ASM code in entry-common.S
- */
 #define _TIF_WORK_MASK		(_TIF_NEED_RESCHED | _TIF_SIGPENDING | \
 				 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
 				 _TIF_NOTIFY_SIGNAL)
diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
index 8896c23ccba7..336a5beb282f 100644
--- a/arch/arm/include/uapi/asm/ptrace.h
+++ b/arch/arm/include/uapi/asm/ptrace.h
@@ -33,6 +33,8 @@
 #define PTRACE_GETHBPREGS	29
 #define PTRACE_SETHBPREGS	30
 #define PTRACE_GETFDPIC		31
+#define PTRACE_SYSEMU		32
+#define PTRACE_SYSEMU_SINGLESTEP 33
 
 #define PTRACE_GETFDPIC_EXEC	0
 #define PTRACE_GETFDPIC_INTERP	1
diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
index 839f3ebe7228..1bbadf13136e 100644
--- a/arch/arm/kernel/entry-armv.S
+++ b/arch/arm/kernel/entry-armv.S
@@ -206,9 +206,9 @@ ENDPROC(__und_invalid)
 
 	mov	r0, sp				@ 'regs'
 	.if \nmi
-	bl	irqentry_nmi_enter_from_kernel_mode
+	bl	arm_irqentry_nmi_enter_from_kernel_mode
 	.else
-	bl	irqentry_enter_from_kernel_mode
+	bl	arm_irqentry_enter_from_kernel_mode
 	.endif
 
 	.endm
@@ -495,12 +495,12 @@ ENDPROC(ret_from_exception)
 __fiq_usr:
 	usr_entry
 	mov	r0, sp
-	bl	irqentry_nmi_enter_from_user_mode
+	bl	arm_irqentry_nmi_enter_from_user_mode
 	kuser_cmpxchg_check
 	mov	r0, sp				@ struct pt_regs *regs
 	bl	handle_fiq_as_nmi
 	mov	r0, sp
-	bl	irqentry_nmi_exit_to_user_mode
+	bl	arm_irqentry_nmi_exit_to_user_mode
 	get_thread_info tsk
 	restore_user_regs
  UNWIND(.fnend		)
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index 6b0f86786a7d..b3b2455ab0a1 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -39,10 +39,6 @@ ret_fast_syscall:
  UNWIND(.fnstart	)
  UNWIND(.cantunwind	)
 	add	sp, sp, #(S_R0 + S_OFF)
-	/* do_rseq_syscall needs interrupts enabled. */
-	mov	r0, sp				@ 'regs'
-	bl	syscall_exit_to_user_mode
-
 #ifdef CONFIG_GCC_PLUGIN_STACKLEAK
 	bl	stackleak_erase_on_task_stack
 #endif
@@ -60,7 +56,7 @@ ENTRY(ret_to_user)
 	/* do_rseq_syscall needs interrupts enabled. */
 	enable_irq_notrace			@ enable interrupts
 	mov	r0, sp				@ 'regs'
-	bl	syscall_exit_to_user_mode
+	bl	arm_exit_to_user_mode
 
 #ifdef CONFIG_GCC_PLUGIN_STACKLEAK
 	bl	stackleak_erase_on_task_stack
@@ -94,7 +90,14 @@ SYM_TYPED_FUNC_START(ret_from_fork_asm)
 	bl	ret_from_fork
 	mov	r0, #0
 1:	get_thread_info tsk
-	b	ret_to_user
+	enable_irq_notrace			@ enable interrupts
+	mov	r0, sp				@ 'regs'
+	bl	syscall_exit_to_user_mode
+
+#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
+	bl	stackleak_erase_on_task_stack
+#endif
+	restore_user_regs
 SYM_FUNC_END(ret_from_fork_asm)
 
 /*=============================================================================
@@ -210,29 +213,12 @@ ENTRY(vector_swi)
 #else
 	str	scno, [tsk, #TI_ABI_SYSCALL]
 #endif
-
-	/*
-	 * Calling out to C to be careful to save and restore registers.
-	 * This call could modify the syscall number. scno is r7 so we
-	 * do not save and restore r7.
-	 */
-	mov	r0, sp				@ regs
-	mov	r1, scno
-	push	{r4 - r6, r8 - r10, lr}
-	bl	syscall_enter_from_user_mode
-	pop	{r4 - r6, r8 - r10, lr}
-	mov	scno, r0
-
 	mov	r1, sp				@ put regs into r1
 	stmdb	sp!, {r4, r5}			@ push fifth and sixth args
 	mov	r0, tbl
 	mov	r2, scno			@ syscall number from r7
 	bl	invoke_syscall
-	cmp	r0, #0
-	beq	ret_fast_syscall
-	/* This path taken when tracing */
-	add	sp, sp, #(S_R0 + S_OFF)
-	b	ret_to_user
+	b	ret_fast_syscall
 
 #if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI)
 	/*
diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
index ec8a6e193802..b5d61b871dec 100644
--- a/arch/arm/kernel/entry-header.S
+++ b/arch/arm/kernel/entry-header.S
@@ -205,7 +205,7 @@
 	disable_irq_notrace
 
 	mov	r0, sp				@ 'regs'
-	bl	irqentry_exit_to_kernel_mode
+	bl	arm_irqentry_exit_to_kernel_mode
 
 	uaccess_exit tsk, r0, r1
 
@@ -253,7 +253,7 @@
 	.macro  svc_exit_via_fiq
 	uaccess_exit tsk, r0, r1
 	mov	r0, sp
-	bl	irqentry_nmi_exit_to_kernel_mode
+	bl	arm_irqentry_nmi_exit_to_kernel_mode
 #ifndef CONFIG_THUMB2_KERNEL
 	@ ARM mode restore
 	mov	r0, sp
@@ -348,12 +348,12 @@ ALT_UP_B(.L1_\@)
 */
 	.macro asm_irqentry_enter_from_user_mode
 	mov	r0, sp				@ regs
-	bl	irqentry_enter_from_user_mode
+	bl	arm_irqentry_enter_from_user_mode
 	.endm
 
 	.macro asm_irqentry_exit_to_user_mode
 	mov	r0, sp				@ regs
-	bl	irqentry_exit_to_user_mode
+	bl	arm_irqentry_exit_to_user_mode
 	.endm
 
 /*
diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c
index 09109215dfdf..7302ed8025a9 100644
--- a/arch/arm/kernel/entry.c
+++ b/arch/arm/kernel/entry.c
@@ -1,87 +1,59 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <asm/entry.h>
-#include <asm/ptrace.h>
-#include <asm/signal.h>
 #include <linux/context_tracking.h>
+#include <linux/entry-common.h>
 #include <linux/irqflags.h>
 #include <linux/rseq.h>
 
-long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall)
-{
-	trace_hardirqs_on();
-	local_irq_enable();
-	/* This context tracking call has inverse naming */
-	user_exit_callable();
-
-	/* This will optionally be modified later */
-	return syscall;
-}
+static irqentry_state_t user_irq_state;
+static irqentry_state_t kernel_irq_state;
+static irqentry_state_t user_nmi_state;
+static irqentry_state_t kernel_nmi_state;
 
-void syscall_exit_to_user_mode(struct pt_regs *regs)
+noinstr void arm_irqentry_enter_from_user_mode(struct pt_regs *regs)
 {
-	unsigned long flags = read_thread_flags();
-
-	rseq_syscall(regs);
-	local_irq_disable();
-	/*
-	 * It really matters that we check for flags != 0 and not
-	 * just for pending work here!
-	 */
-	if (flags)
-		do_work_pending(regs, flags);
-
-	trace_hardirqs_on();
-	/* This context tracking call has inverse naming */
-	user_enter_callable();
+	user_irq_state = irqentry_enter(regs);
 }
 
-noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs)
+noinstr void arm_irqentry_exit_to_user_mode(struct pt_regs *regs)
 {
-	trace_hardirqs_off();
-	/* This context tracking call has inverse naming */
-	user_exit_callable();
+	irqentry_exit(regs, user_irq_state);
 }
 
-noinstr void irqentry_exit_to_user_mode(struct pt_regs *regs)
+noinstr void arm_irqentry_enter_from_kernel_mode(struct pt_regs *regs)
 {
-	unsigned long flags = read_thread_flags();
-
-	/*
-	 * It really matters that we check for flags != 0 and not
-	 * just for pending work here!
-	 */
-	if (flags)
-		do_work_pending(regs, flags);
-	trace_hardirqs_on();
-	/* This context tracking call has inverse naming */
-	user_enter_callable();
+	kernel_irq_state = irqentry_enter(regs);
 }
 
-noinstr void irqentry_enter_from_kernel_mode(struct pt_regs *regs)
+noinstr void arm_irqentry_exit_to_kernel_mode(struct pt_regs *regs)
 {
-	trace_hardirqs_off();
+	irqentry_exit(regs, kernel_irq_state);
 }
 
-noinstr void irqentry_exit_to_kernel_mode(struct pt_regs *regs)
+noinstr void arm_irqentry_nmi_enter_from_user_mode(struct pt_regs *regs)
 {
-	if (interrupts_enabled(regs))
-		trace_hardirqs_on();
-	else
-		trace_hardirqs_off();
+	irqentry_enter_from_user_mode(regs);
+	user_nmi_state = irqentry_nmi_enter(regs);
 }
 
-noinstr void irqentry_nmi_enter_from_user_mode(struct pt_regs *regs)
+noinstr void arm_irqentry_nmi_exit_to_user_mode(struct pt_regs *regs)
 {
+	irqentry_nmi_exit(regs, user_nmi_state);
+	irqentry_exit_to_user_mode(regs);
 }
 
-noinstr void irqentry_nmi_exit_to_user_mode(struct pt_regs *regs)
+noinstr void arm_irqentry_nmi_enter_from_kernel_mode(struct pt_regs *regs)
 {
+	kernel_nmi_state = irqentry_nmi_enter(regs);
 }
 
-noinstr void irqentry_nmi_enter_from_kernel_mode(struct pt_regs *regs)
+noinstr void arm_irqentry_nmi_exit_to_kernel_mode(struct pt_regs *regs)
 {
+	irqentry_nmi_exit(regs, kernel_nmi_state);
 }
 
-noinstr void irqentry_nmi_exit_to_kernel_mode(struct pt_regs *regs)
+asmlinkage void arm_exit_to_user_mode(struct pt_regs *regs)
 {
+	local_irq_disable();
+	irqentry_exit_to_user_mode(regs);
 }
diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
index 81c1c3f98834..6c525a33fa6d 100644
--- a/arch/arm/kernel/process.c
+++ b/arch/arm/kernel/process.c
@@ -248,8 +248,6 @@ __visible void ret_from_fork(struct task_struct *prev, struct pt_regs *regs,
 		 * execve() syscall.
 		 */
 	}
-
-	/* syscall_exit_to_user_mode(regs); here once we switch to generic entry */
 }
 
 int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
index ac7b98ae4724..89afe714cedc 100644
--- a/arch/arm/kernel/ptrace.c
+++ b/arch/arm/kernel/ptrace.c
@@ -27,9 +27,6 @@
 #include <asm/syscall.h>
 #include <asm/traps.h>
 
-#define CREATE_TRACE_POINTS
-#include <trace/events/syscalls.h>
-
 #define REG_PC	15
 #define REG_PSR	16
 /*
@@ -821,90 +818,3 @@ long arch_ptrace(struct task_struct *child, long request,
 
 	return ret;
 }
-
-enum ptrace_syscall_dir {
-	PTRACE_SYSCALL_ENTER = 0,
-	PTRACE_SYSCALL_EXIT,
-};
-
-static void report_syscall_enter(struct pt_regs *regs)
-{
-	unsigned long ip;
-
-	/*
-	 * IP is used to denote syscall entry/exit:
-	 * IP = 0 -> entry
-	 */
-	ip = regs->ARM_ip;
-	regs->ARM_ip = PTRACE_SYSCALL_ENTER;
-
-	if (ptrace_report_syscall_entry(regs))
-		current_thread_info()->abi_syscall = -1;
-
-	regs->ARM_ip = ip;
-}
-
-static void report_syscall_exit(struct pt_regs *regs)
-{
-	unsigned long ip;
-
-	/*
-	 * IP is used to denote syscall entry/exit:
-	 * IP = 1 -> exit
-	 */
-	ip = regs->ARM_ip;
-	regs->ARM_ip = PTRACE_SYSCALL_EXIT;
-
-	ptrace_report_syscall_exit(regs, 0);
-
-	regs->ARM_ip = ip;
-}
-
-asmlinkage int syscall_trace_enter(struct pt_regs *regs)
-{
-	int scno;
-
-	if (test_thread_flag(TIF_SYSCALL_TRACE))
-		report_syscall_enter(regs);
-
-	/* Do seccomp after ptrace; syscall may have changed. */
-#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
-	if (secure_computing() == -1)
-		return -1;
-#else
-	/* XXX: remove this once OABI gets fixed */
-	secure_computing_strict(syscall_get_nr(current, regs));
-#endif
-
-	/* Tracer or seccomp may have changed syscall. */
-	scno = syscall_get_nr(current, regs);
-
-	if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
-		trace_sys_enter(regs, scno);
-
-	audit_syscall_entry(scno, regs->ARM_r0, regs->ARM_r1, regs->ARM_r2,
-			    regs->ARM_r3);
-
-	return scno;
-}
-
-void syscall_trace_exit(struct pt_regs *regs)
-{
-	/*
-	 * Audit the syscall before anything else, as a debugger may
-	 * come in and change the current registers.
-	 */
-	audit_syscall_exit(regs);
-
-	/*
-	 * Note that we haven't updated the ->syscall field for the
-	 * current thread. This isn't a problem because it will have
-	 * been set on syscall entry and there hasn't been an opportunity
-	 * for a PTRACE_SET_SYSCALL since then.
-	 */
-	if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
-		trace_sys_exit(regs, regs_return_value(regs));
-
-	if (test_thread_flag(TIF_SYSCALL_TRACE))
-		report_syscall_exit(regs);
-}
diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
index a39ee14ec5b7..35d2bb3cd2b4 100644
--- a/arch/arm/kernel/signal.c
+++ b/arch/arm/kernel/signal.c
@@ -4,6 +4,7 @@
  *
  *  Copyright (C) 1995-2009 Russell King
  */
+#include <linux/entry-common.h>
 #include <linux/errno.h>
 #include <linux/random.h>
 #include <linux/signal.h>
@@ -535,7 +536,7 @@ static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
  * the kernel can handle, and then we build all the user-level signal handling
  * stack-frames in one go after that.
  */
-static void arch_do_signal_or_restart(struct pt_regs *regs)
+void arch_do_signal_or_restart(struct pt_regs *regs)
 {
 	unsigned int retval = 0, continue_addr = 0, restart_addr = 0;
 	bool syscall = (syscall_get_nr(current, regs) != -1);
@@ -598,34 +599,6 @@ static void arch_do_signal_or_restart(struct pt_regs *regs)
 	return;
 }
 
-void do_work_pending(struct pt_regs *regs, unsigned int thread_flags)
-{
-	/*
-	 * The assembly code enters us with IRQs off, but it hasn't
-	 * informed the tracing code of that for efficiency reasons.
-	 * Update the trace code with the current status.
-	 */
-	trace_hardirqs_off();
-	do {
-		if (likely(thread_flags & _TIF_NEED_RESCHED)) {
-			schedule();
-		} else {
-			if (unlikely(!user_mode(regs)))
-				return;
-			local_irq_enable();
-			if (thread_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) {
-				arch_do_signal_or_restart(regs);
-			} else if (thread_flags & _TIF_UPROBE) {
-				uprobe_notify_resume(regs);
-			} else {
-				resume_user_mode_work(regs);
-			}
-		}
-		local_irq_disable();
-		thread_flags = read_thread_flags();
-	} while (thread_flags & _TIF_WORK_MASK);
-}
-
 struct page *get_signal_page(void)
 {
 	unsigned long ptr;
diff --git a/arch/arm/kernel/syscall.c b/arch/arm/kernel/syscall.c
index 968cec945a7e..26ec3a151652 100644
--- a/arch/arm/kernel/syscall.c
+++ b/arch/arm/kernel/syscall.c
@@ -1,25 +1,16 @@
 // SPDX-License-Identifier: GPL-2.0
 
+#include <linux/entry-common.h>
 #include <linux/syscalls.h>
 #include <asm/syscall.h>
 
-static inline bool has_syscall_work(unsigned long flags)
-{
-	return unlikely(flags & _TIF_SYSCALL_WORK);
-}
-
 int invoke_syscall_asm(void *table, struct pt_regs *regs, int scno);
 
-__visible int invoke_syscall(void *table, struct pt_regs *regs, int scno)
+__visible void invoke_syscall(void *table, struct pt_regs *regs, int scno)
 {
-	unsigned long flags = read_thread_flags();
 	int ret;
 
-	if (has_syscall_work(flags)) {
-		scno = syscall_trace_enter(regs);
-		if (scno == -1)
-			goto trace_exit_nosave;
-	}
+	scno = syscall_enter_from_user_mode(regs, scno);
 
 	if (scno < NR_syscalls) {
 		ret = invoke_syscall_asm(table, regs, scno);
@@ -34,13 +25,7 @@ __visible int invoke_syscall(void *table, struct pt_regs *regs, int scno)
 	ret = sys_ni_syscall();
 
 exit_save:
-	/* Save return value from syscall */
-	regs->ARM_r0 = ret;
-	if (!has_syscall_work(flags))
-		return 0;
-
-trace_exit_nosave:
-	local_irq_enable();
-	syscall_trace_exit(regs);
-	return 1;
+	syscall_set_return_value(current, regs, 0, ret);
+
+	syscall_exit_to_user_mode(regs);
 }

-- 
2.46.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [78.32.30.218])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 461681BE23D
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 11:55:41 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=78.32.30.218
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728561344; cv=none; b=AKf4CG9foMZj50HvyiXJ9/XqHFRMhpCHgf6p4PZm8wch8ddKaiq00NoJ/t7Br2egjsWPTa3rxfEMLm/z60mELIFwxcOm9/ehtjdr2RPIO9bj/0DG4jED6BjPHhEz3WfCmFCoJZw8CXT++LXM016MbY0C1tdk/1DZ++aza/6u90M=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728561344; c=relaxed/simple;
	bh=9ypUntO+knrZwXW14pBBJWuCGp9e8ARsbAZz6ZyvuJA=;
	h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:
	 Content-Type:Content-Disposition:In-Reply-To; b=VPd96FPP78hv3K+RX8SqhYfSu/KA/Cns4Px30VvsvplnhTLIgFTZmZBgkx6Ac6aAiKhQH7BBKX1Q+SmWbvkSTC+c23mqX05rDHb9JYyEkCxySIARHgQ6yR3rUE3dPfUnOxwUaELRTpd5eAa+CrdEydeXCeNmXzB8kEPxZbdJd+8=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=armlinux.org.uk; spf=none smtp.mailfrom=armlinux.org.uk; dkim=pass (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b=IIe+J1UD; arc=none smtp.client-ip=78.32.30.218
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=armlinux.org.uk
Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=armlinux.org.uk
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b="IIe+J1UD"
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
	d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type:
	MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To:
	Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:
	Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:
	List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive;
	bh=Jgzc/uLviO7J54OVqHpsyMnCk4VTRuOJ3qugkDERST8=; b=IIe+J1UD8SkmQSXtqZvX4LjYxM
	/0Qpcshk2xUqgwE/jU5u5u9nB6ve8edCv9dFAsxYsM3S+wjJZD+ytsnuWIIx0lbtBnTmW70PGy/Yg
	dhq8BZm077nnWVQf3Ucm0qP01tA13M774TFjnv4b2zZekyAYVM0HKzbPVdH8lElXZSh8hnskU40yw
	9uQ3M1J73m7NhJRRDeKEZf514jrZ1G4Gdmzvj/8Vl9ladGZy6kRKzrMjnP+BJC0ha7VTjxjMn40Sg
	heqvJhzhOJfoe353S5xm8RhxMf8zN8UUHuNKHPTZDrBkvkarvSNRmIc3ZCCpFgA/4jVj0MqTUgQtZ
	LqmG04VA==;
Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:53502)
	by pandora.armlinux.org.uk with esmtpsa  (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
	(Exim 4.96)
	(envelope-from <linux@armlinux.org.uk>)
	id 1syrlZ-0002IO-0l;
	Thu, 10 Oct 2024 12:55:36 +0100
Received: from linux by shell.armlinux.org.uk with local (Exim 4.96)
	(envelope-from <linux@shell.armlinux.org.uk>)
	id 1syrlU-0007HP-2r;
	Thu, 10 Oct 2024 12:55:32 +0100
Date: Thu, 10 Oct 2024 12:55:32 +0100
From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Oleg Nesterov <oleg@redhat.com>, Kees Cook <kees@kernel.org>,
	Andy Lutomirski <luto@amacapital.net>,
	Will Drewry <wad@chromium.org>,
	Frederic Weisbecker <frederic@kernel.org>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>,
	Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>,
	linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RFC 00/28] ARM: Switch to generic entry
Message-ID: <ZwfAtJfNm95sXgo8@shell.armlinux.org.uk>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
Sender: Russell King (Oracle) <linux@armlinux.org.uk>

On Thu, Oct 10, 2024 at 01:33:38PM +0200, Linus Walleij wrote:
> This patch series converts a slew of ARM assembly into the
> corresponding C code, step by step moving the codebase
> closer to the expectations of the generic entry code,
> and as a last step switches ARM over to the generic
> entry code.

I haven't looked at the series yet, but I guess we're throwing away
all the effort I put in to make stuff like syscalls as fast as
possible.

So the question is... do we want performance, or do we want generic
(and slower) code?

It seems insane to me that we spend time micro-optimising things like
memcpy, memset, divide routines, but then go and throw away performance
that applications actually rely upon, such as syscall performance.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177])
	(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 093F118FDBE
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 12:11:23 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728562285; cv=none; b=cnf0umK6iYA4JRZ1V2nF/PlemcB/ZvNdqlLFxrMeuqDsM44hEkJ8pEjNPYP39WjSmHI16eihYIGaHkky8ajWP3UNW90Bzqi0g7sonntIaI3REp7VQhz3ijUVn9yOnIF5lLBpcCcljmlNufZBdvl7yCeEY58ZQRTywQ9FZkM6n40=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728562285; c=relaxed/simple;
	bh=9IwGJpkMTMBw0yGJitvUVuWUOMwCQ/DbccBrOqTbNus=;
	h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:
	 To:Cc:Content-Type; b=DupBT7N2f7SlJsVL2Q1S3uKpd7k7AdkQaBJA3MFBUvam1zfWSCGqZNIrjPI0JLurK3tuqZdE1VabN1ou0vjE5uy12zOTLp6Ih+gePZu44DcoS7Tqjos7pV0Lw9ZH4H+Gju06+qDM6vLjrMkVmpTAsTv06SyWnsaPxMgm40RADLw=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=eea0MmAz; arc=none smtp.client-ip=209.85.208.177
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="eea0MmAz"
Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2fad6de2590so12243641fa.0
        for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 05:11:23 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=linaro.org; s=google; t=1728562282; x=1729167082; darn=vger.kernel.org;
        h=content-transfer-encoding:cc:to:subject:message-id:date:from
         :in-reply-to:references:mime-version:from:to:cc:subject:date
         :message-id:reply-to;
        bh=9IwGJpkMTMBw0yGJitvUVuWUOMwCQ/DbccBrOqTbNus=;
        b=eea0MmAzBrJrcpoB2Z+JoanHdRQMf7zBb8NRwNSbsdaoVOtdd3/OetdEvZlwaE8y9o
         wR+KghN0P1fBDS6pPYAeYtK9aRTJfDyOp8i5eXvTT9Ml0BOO5Vi0Ld6Q6h3ebm4Tybs6
         rESpQvj5KcooezEgI1Hmj9IwR5Vc4R/uoZBjbltDbjrRdomvkbKtRhpNiV5RB7DaoPFD
         vqYWKbGLhNkK4QZrO+jKQqkbUzsPHZYo4QhhXTJKOnX8SblmJCuFn9IJczz9ODnwoBgo
         tX6XtvsmtQwo8Xu6QtOrOcMIY3oNQWXpwaS9T+T6igfx74peot63/ecVZUKz4+ZIUQK0
         l7+Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1728562282; x=1729167082;
        h=content-transfer-encoding:cc:to:subject:message-id:date:from
         :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=9IwGJpkMTMBw0yGJitvUVuWUOMwCQ/DbccBrOqTbNus=;
        b=XXPYLgYXyb8BzpJsneBS0lpq7Qfo/xo9pHIdQ5YgJM9VYLuEjAoCTjn3fczVaTDiUp
         /UzQdR1Qxj7jKAKmTf93thTQfsBXQsCSlAc+j75p1HwjmhBywdJDDDJ764jT4L67YRzD
         gVwXh50nGQA4qQq1tvVvKnREHHjOfiAw/WwNoQnQpdilQoc1WtHM8DvpZpA1b8xrioW2
         ahUKwJ1557D7TdunmC7bKebvMpw4KpQV7BM5m7lqAiFKMoZLdHnpncrU4bOXlk0M/TZd
         tkQHVHVQWqe6HPLBNCb3D3J7v4I0ukS87/mTvQNuehQd4m4qQvIFGNwp1ruBgKOHwMTs
         MRMw==
X-Forwarded-Encrypted: i=1; AJvYcCVdCBjnxj1bP9q2l+bQ2BJobdAGDilbBrp6tReSvOKHkpv+4aZORqVmE++NtD1tY62gqegMloYVQRGBp00=@vger.kernel.org
X-Gm-Message-State: AOJu0YzdFSGAUKVVWzNnYoxzd9ZMmmAtIL7vAJncUnD+N+lEa+Q8QgIk
	TVzfnh35CSo6Mi76ip/RmdwP4YcW4MUrVEbJneeZgy6ZPDjjq59pj9vhjyqaxQRHndCmVEVtslK
	NDWeHyHiofwVliejae1EYaekHNyOe303Ls1rThw==
X-Google-Smtp-Source: AGHT+IHjcaQoBqfpJ8FYrx1gfWjq+eWVknX20o4i9A4+sUsdM9VmYBZstGFuWFa39n9O361+kyXBgz7xYBS4U1aZZok=
X-Received: by 2002:a05:651c:1548:b0:2fa:c0b5:ac8c with SMTP id
 38308e7fff4ca-2fb1873dfe2mr55267331fa.21.1728562281963; Thu, 10 Oct 2024
 05:11:21 -0700 (PDT)
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org> <ZwfAtJfNm95sXgo8@shell.armlinux.org.uk>
In-Reply-To: <ZwfAtJfNm95sXgo8@shell.armlinux.org.uk>
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 10 Oct 2024 14:11:09 +0200
Message-ID: <CACRpkdYPmqXQrt4r5pxCUugHWHkBVF4qPSkvU5X09QB=1sscjA@mail.gmail.com>
Subject: Re: [PATCH RFC 00/28] ARM: Switch to generic entry
To: "Russell King (Oracle)" <linux@armlinux.org.uk>
Cc: Oleg Nesterov <oleg@redhat.com>, Kees Cook <kees@kernel.org>, 
	Andy Lutomirski <luto@amacapital.net>, Will Drewry <wad@chromium.org>, 
	Frederic Weisbecker <frederic@kernel.org>, "Paul E. McKenney" <paulmck@kernel.org>, 
	Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>, Ard Biesheuvel <ardb@kernel.org>, 
	Al Viro <viro@zeniv.linux.org.uk>, linux-arm-kernel@lists.infradead.org, 
	linux-kernel@vger.kernel.org
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Thu, Oct 10, 2024 at 1:55=E2=80=AFPM Russell King (Oracle)
<linux@armlinux.org.uk> wrote:

> I haven't looked at the series yet, but I guess we're throwing away
> all the effort I put in to make stuff like syscalls as fast as
> possible.
>
> So the question is... do we want performance, or do we want generic
> (and slower) code?

Yes, the very same question that came to me as I was working on it, we
need to reach some conclusion here. Al Viro also put some nice
assembly optimizations in the syscall restart that just go out the
window as well.

Some of the C interpersing relates to the RCU context tracking that
really likes to be called at every single IRQ, FIQ or SWI, and where ARM32
is one of the few last users of the user_exit_callable()/user_enter_callabl=
e()
API which is obviously less intrusive as it only needs to get called
at transitions to/from userspace, while these calls are marked
with big block letters as obsolete in the context tracker.

> It seems insane to me that we spend time micro-optimising things like
> memcpy, memset, divide routines, but then go and throw away performance
> that applications actually rely upon, such as syscall performance.

Yes, this series is a real RFC in the true sense of the word.

Yours,
Linus Walleij

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [78.32.30.218])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id F20C61C1ABE
	for <linux-kernel@vger.kernel.org>; Thu, 10 Oct 2024 13:07:22 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=78.32.30.218
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1728565645; cv=none; b=NOAwKDLBIjcYatHOiqPDaR+ct+CU6XF0FdFSLkXq0aKQg8Wn475Qt7jwo8DZ996qztweUdHoZeDxPxGGfXeS06lT9snVnTn2iT1Ef6YkBhgZvjJu+0jpt4sSg0G60NQzOVsKQ9NuJfLetwJEDK8eySdH8Jep/5wA4jyE6TBwuiE=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1728565645; c=relaxed/simple;
	bh=jGIDhOgbBBnvGGws+4ezzx3fHtN8cTFB8fAxoxJmHeA=;
	h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:
	 Content-Type:Content-Disposition:In-Reply-To; b=I/ftpdEwojI7UEXHcWh6JXLG/js+icJ8OW0TCBmVnJLXkdiBTJWgHRboQhVakHB6aZKAt+rWe+9pGgIUmn3xo6tz9RFeRKR/rQAMtdx7uqq7cj2hRgWZ5Y4zOmqLbPpQvrOvlQL601KdCUCY4lnXIDQo5Vkc6X7et/adEi83hns=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=armlinux.org.uk; spf=none smtp.mailfrom=armlinux.org.uk; dkim=pass (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b=WEZg5zkt; arc=none smtp.client-ip=78.32.30.218
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=armlinux.org.uk
Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=armlinux.org.uk
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b="WEZg5zkt"
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
	d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:
	Content-Transfer-Encoding:Content-Type: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-Id:
	List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive;
	bh=3At5dVj4t33J4waOW38XOA4KtkhXoc0tdeqH/X13qaw=; b=WEZg5zkty+Hus1IYYJ/ieHqlnq
	hT2akM7MI42YBu3nQRcUocW+A5gY/JAoT7Vj+ktinyn2hY4FUA2cIQtcx/ZEDa7lHz+uU7QXgagN7
	BrW2fxW00LTkrHnKwWOZ+Bk9i38rCVYcZUdWnAxwO29qpsCaPePr3R2h1+Wk7ba75MwYUTB7y0MSd
	1Bj7cjBxzkPzKqx3P4pI1skS/o/u3ErvInKOXifZ8d472rqwfg5w2tgYQ6C12oaIy5neNazYOPxDR
	TfvjO+9RiFwEreg0loBnf/AGXd5Btel/+OnPzdBi/6+9L83Audp/OmmHNxrZ44kcsnNfqY0stgLOZ
	hgPcmHtA==;
Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:56804)
	by pandora.armlinux.org.uk with esmtpsa  (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
	(Exim 4.96)
	(envelope-from <linux@armlinux.org.uk>)
	id 1syssw-0002Qq-1f;
	Thu, 10 Oct 2024 14:07:18 +0100
Received: from linux by shell.armlinux.org.uk with local (Exim 4.96)
	(envelope-from <linux@shell.armlinux.org.uk>)
	id 1sysss-0007KE-0u;
	Thu, 10 Oct 2024 14:07:14 +0100
Date: Thu, 10 Oct 2024 14:07:14 +0100
From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Oleg Nesterov <oleg@redhat.com>, Kees Cook <kees@kernel.org>,
	Andy Lutomirski <luto@amacapital.net>,
	Will Drewry <wad@chromium.org>,
	Frederic Weisbecker <frederic@kernel.org>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Jinjie Ruan <ruanjinjie@huawei.com>, Arnd Bergmann <arnd@arndb.de>,
	Ard Biesheuvel <ardb@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>,
	linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RFC 00/28] ARM: Switch to generic entry
Message-ID: <ZwfRglFliZ8_bLHU@shell.armlinux.org.uk>
References: <20241010-arm-generic-entry-v1-0-b94f451d087b@linaro.org>
 <ZwfAtJfNm95sXgo8@shell.armlinux.org.uk>
 <CACRpkdYPmqXQrt4r5pxCUugHWHkBVF4qPSkvU5X09QB=1sscjA@mail.gmail.com>
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <CACRpkdYPmqXQrt4r5pxCUugHWHkBVF4qPSkvU5X09QB=1sscjA@mail.gmail.com>
Sender: Russell King (Oracle) <linux@armlinux.org.uk>

On Thu, Oct 10, 2024 at 02:11:09PM +0200, Linus Walleij wrote:
> On Thu, Oct 10, 2024 at 1:55 PM Russell King (Oracle)
> <linux@armlinux.org.uk> wrote:
> 
> > I haven't looked at the series yet, but I guess we're throwing away
> > all the effort I put in to make stuff like syscalls as fast as
> > possible.
> >
> > So the question is... do we want performance, or do we want generic
> > (and slower) code?
> 
> Yes, the very same question that came to me as I was working on it, we
> need to reach some conclusion here. Al Viro also put some nice
> assembly optimizations in the syscall restart that just go out the
> window as well.
> 
> Some of the C interpersing relates to the RCU context tracking that
> really likes to be called at every single IRQ, FIQ or SWI, and where ARM32
> is one of the few last users of the user_exit_callable()/user_enter_callable()
> API which is obviously less intrusive as it only needs to get called
> at transitions to/from userspace, while these calls are marked
> with big block letters as obsolete in the context tracker.
> 
> > It seems insane to me that we spend time micro-optimising things like
> > memcpy, memset, divide routines, but then go and throw away performance
> > that applications actually rely upon, such as syscall performance.
> 
> Yes, this series is a real RFC in the true sense of the word.

I think we need to quantify what the effect is on performance by making
these changes, and I think we need to do more than just syscall entry/
exit performance, but the overall performance impact on userspace when
the system is under a certain interrupt load.

One of the things we have to remember is that applications like to
endlessly get system time. Many of these other architectures that have
been converted to this generic code support VDSO. However, 32-bit ARM
generally does not have VDSO to avoid the syscall over head for
e.g. gettimeofday().

So, we also need to time real workloads as well to properly understand
what the effect of making these changes is.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

