mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jinjie Ruan <ruanjinjie@huawei.com>
To: Mark Rutland <mark.rutland@arm.com>
Cc: <oleg@redhat.com>, <linux@armlinux.org.uk>, <will@kernel.org>,
	<catalin.marinas@arm.com>, <sstabellini@kernel.org>,
	<maz@kernel.org>, <tglx@linutronix.de>, <peterz@infradead.org>,
	<luto@kernel.org>, <kees@kernel.org>, <wad@chromium.org>,
	<akpm@linux-foundation.org>, <samitolvanen@google.com>,
	<arnd@arndb.de>, <ojeda@kernel.org>, <rppt@kernel.org>,
	<hca@linux.ibm.com>, <aliceryhl@google.com>,
	<samuel.holland@sifive.com>, <paulmck@kernel.org>,
	<aquini@redhat.com>, <petr.pavlu@suse.com>,
	<viro@zeniv.linux.org.uk>, <rmk+kernel@armlinux.org.uk>,
	<ardb@kernel.org>, <wangkefeng.wang@huawei.com>,
	<surenb@google.com>, <linus.walleij@linaro.org>,
	<yangyj.ee@gmail.com>, <broonie@kernel.org>, <mbenes@suse.cz>,
	<puranjay@kernel.org>, <pcc@google.com>, <guohanjun@huawei.com>,
	<sudeep.holla@arm.com>, <Jonathan.Cameron@huawei.com>,
	<prarit@redhat.com>, <liuwei09@cestc.cn>, <dwmw@amazon.co.uk>,
	<oliver.upton@linux.dev>, <kristina.martsenko@arm.com>,
	<ptosi@google.com>, <frederic@kernel.org>, <vschneid@redhat.com>,
	<thiago.bauermann@linaro.org>, <joey.gouly@arm.com>,
	<liuyuntao12@huawei.com>, <leobras@redhat.com>,
	<linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<xen-devel@lists.xenproject.org>
Subject: Re: [PATCH -next v4 02/19] arm64: entry: Refactor the entry and exit for exceptions from EL1
Date: Thu, 31 Oct 2024 11:35:28 +0800	[thread overview]
Message-ID: <69389d62-a520-fb1a-2c73-fecc9bc8a71f@huawei.com> (raw)
In-Reply-To: <ZyDyS4TT6xgRIN1w@J2N7QTR9R3.cambridge.arm.com>



On 2024/10/29 22:33, Mark Rutland wrote:
> On Fri, Oct 25, 2024 at 06:06:43PM +0800, Jinjie Ruan wrote:
>> These changes refactor the entry and exit routines for the exceptions
>> from EL1. They store the RCU and lockdep state in a struct
>> irqentry_state variable on the stack, rather than recording them
>> in the fields of pt_regs, since it is safe enough for these context.
> 
> In general, please descirbe *why* we want to make the change first, e.g.
> 
> | The generic entry code uses irqentry_state_t to track lockdep and RCU
> | state across exception entry and return. For historical reasons, arm64
> | embeds similar fields within its pt_regs structure.
> |
> | In preparation for moving arm64 over to the generic entry code, pull
> | these fields out of arm64's pt_regs, and use a seperate structure,
> | matching the style of the generic entry code.
> 
>> Before:
>> 	struct pt_regs {
>> 		...
>> 		u64 lockdep_hardirqs;
>> 		u64 exit_rcu;
>> 	}
>>
>> 	enter_from_kernel_mode(regs);
>> 	...
>> 	exit_to_kernel_mode(regs);
>>
>> After:
>> 	typedef struct irqentry_state {
>> 		union {
>> 			bool    exit_rcu;
>> 			bool    lockdep;
>> 		};
>> 	} irqentry_state_t;
>>
>> 	irqentry_state_t state = enter_from_kernel_mode(regs);
>> 	...
>> 	exit_to_kernel_mode(regs, state);
> 
> I don't think this part is necessary.

Thank you, will remove it and explain why.

> 
>>
>> No functional changes.
>>
>> Suggested-by: Mark Rutland <mark.rutland@arm.com>
>> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
>> ---
>>  arch/arm64/include/asm/ptrace.h  |  11 ++-
>>  arch/arm64/kernel/entry-common.c | 129 +++++++++++++++++++------------
>>  2 files changed, 85 insertions(+), 55 deletions(-)
>>
>> diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h
>> index 3e5372a98da4..5156c0d5fa20 100644
>> --- a/arch/arm64/include/asm/ptrace.h
>> +++ b/arch/arm64/include/asm/ptrace.h
>> @@ -149,6 +149,13 @@ static inline unsigned long pstate_to_compat_psr(const unsigned long pstate)
>>  	return psr;
>>  }
>>  
>> +typedef struct irqentry_state {
>> +	union {
>> +		bool	exit_rcu;
>> +		bool	lockdep;
>> +	};
>> +} irqentry_state_t;
> 
> AFAICT this can be moved directly into arch/arm64/kernel/entry-common.c.
> 
>> +
>>  /*
>>   * This struct defines the way the registers are stored on the stack during an
>>   * exception. struct user_pt_regs must form a prefix of struct pt_regs.
>> @@ -169,10 +176,6 @@ struct pt_regs {
>>  
>>  	u64 sdei_ttbr1;
>>  	struct frame_record_meta stackframe;
>> -
>> -	/* Only valid for some EL1 exceptions. */
>> -	u64 lockdep_hardirqs;
>> -	u64 exit_rcu;
>>  };
>>  
>>  /* For correct stack alignment, pt_regs has to be a multiple of 16 bytes. */
>> diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
>> index c547e70428d3..68a9aecacdb9 100644
>> --- a/arch/arm64/kernel/entry-common.c
>> +++ b/arch/arm64/kernel/entry-common.c
>> @@ -36,29 +36,36 @@
>>   * This is intended to match the logic in irqentry_enter(), handling the kernel
>>   * mode transitions only.
>>   */
>> -static __always_inline void __enter_from_kernel_mode(struct pt_regs *regs)
>> +static __always_inline irqentry_state_t __enter_from_kernel_mode(struct pt_regs *regs)
>>  {
>> -	regs->exit_rcu = false;
>> +	irqentry_state_t ret = {
>> +		.exit_rcu = false,
>> +	};
> 
> I realise that the generic entry code calls this 'ret' in
> irqentry_enter() and similar, but could we please use 'state'
> consistently in the arm64 code?
> 
> [...]
> 
>>  /*
>> @@ -190,9 +199,11 @@ asmlinkage void noinstr asm_exit_to_user_mode(struct pt_regs *regs)
>>   * mode. Before this function is called it is not safe to call regular kernel
>>   * code, instrumentable code, or any code which may trigger an exception.
>>   */
>> -static void noinstr arm64_enter_nmi(struct pt_regs *regs)
>> +static noinstr irqentry_state_t arm64_enter_nmi(struct pt_regs *regs)
>>  {
>> -	regs->lockdep_hardirqs = lockdep_hardirqs_enabled();
>> +	irqentry_state_t irq_state;
> 
> Likewise, please use 'state' rather than 'irq_state'.
> 
> In future we should probably have a separate structure for the NMI
> paths, and get rid of the union, which would avoid the possiblity of
> using mismatched helpers.
> 
> Mark.
> 
> 

  reply	other threads:[~2024-10-31  3:35 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-25 10:06 [PATCH -next v4 00/19] arm64: entry: Convert to generic entry Jinjie Ruan
2024-10-25 10:06 ` [PATCH -next v4 01/19] arm64: ptrace: Replace interrupts_enabled() with regs_irqs_disabled() Jinjie Ruan
2024-10-29 14:19   ` Mark Rutland
2024-10-31  3:34     ` Jinjie Ruan
2024-10-25 10:06 ` [PATCH -next v4 02/19] arm64: entry: Refactor the entry and exit for exceptions from EL1 Jinjie Ruan
2024-10-29 14:33   ` Mark Rutland
2024-10-31  3:35     ` Jinjie Ruan [this message]
2024-10-25 10:06 ` [PATCH -next v4 03/19] arm64: entry: Remove __enter_from_user_mode() Jinjie Ruan
2024-10-29 14:42   ` Mark Rutland
2024-10-31  3:40     ` Jinjie Ruan
2024-10-25 10:06 ` [PATCH -next v4 04/19] arm64: entry: Remove __enter_from_kernel_mode() Jinjie Ruan
2024-10-29 14:37   ` Mark Rutland
2024-10-31  3:56     ` Jinjie Ruan
2024-10-25 10:06 ` [PATCH -next v4 05/19] arm64: entry: Remove __exit_to_kernel_mode() Jinjie Ruan
2024-10-25 10:06 ` [PATCH -next v4 06/19] arm64: entry: Move arm64_preempt_schedule_irq() into exit_to_kernel_mode() Jinjie Ruan
2024-10-29 14:52   ` Mark Rutland
2024-10-31  4:02     ` Jinjie Ruan
2024-10-25 10:06 ` [PATCH -next v4 07/19] arm64: entry: Call arm64_preempt_schedule_irq() only if irqs enabled Jinjie Ruan
2024-10-29 14:55   ` Mark Rutland
2024-10-25 10:06 ` [PATCH -next v4 08/19] arm64: entry: Rework arm64_preempt_schedule_irq() Jinjie Ruan
2024-10-25 10:06 ` [PATCH -next v4 09/19] arm64: entry: Use preempt_count() and need_resched() helper Jinjie Ruan
2024-10-25 10:06 ` [PATCH -next v4 10/19] arm64: entry: preempt_schedule_irq() only if PREEMPTION enabled Jinjie Ruan
2024-10-25 10:06 ` [PATCH -next v4 11/19] arm64: entry: Extract raw_irqentry_exit_cond_resched() function Jinjie Ruan
2024-10-25 10:06 ` [PATCH -next v4 12/19] arm64: entry: Check dynamic key ahead Jinjie Ruan
2024-10-25 10:06 ` [PATCH -next v4 13/19] arm64: entry: Check dynamic resched when PREEMPT_DYNAMIC enabled Jinjie Ruan
2024-10-25 10:06 ` [PATCH -next v4 14/19] entry: Split into irq entry and syscall Jinjie Ruan
2024-10-25 10:06 ` [PATCH -next v4 15/19] entry: Add arch irqentry_exit_need_resched() for arm64 Jinjie Ruan
2024-10-28 18:05   ` Thomas Gleixner
2024-10-28 22:15     ` Thomas Gleixner
2024-10-29  2:33     ` Jinjie Ruan
2024-10-25 10:06 ` [PATCH -next v4 16/19] arm64: entry: Switch to generic IRQ entry Jinjie Ruan
2024-10-25 10:06 ` [PATCH -next v4 17/19] entry: Add syscall arch functions to use generic syscall for arm64 Jinjie Ruan
2024-10-28 18:21   ` Thomas Gleixner
2024-10-25 10:06 ` [PATCH -next v4 18/19] arm64/ptrace: Split report_syscall() into separate enter and exit functions Jinjie Ruan
2024-10-25 10:07 ` [PATCH -next v4 19/19] arm64: entry: Convert to generic entry Jinjie Ruan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=69389d62-a520-fb1a-2c73-fecc9bc8a71f@huawei.com \
    --to=ruanjinjie@huawei.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=aliceryhl@google.com \
    --cc=aquini@redhat.com \
    --cc=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=dwmw@amazon.co.uk \
    --cc=frederic@kernel.org \
    --cc=guohanjun@huawei.com \
    --cc=hca@linux.ibm.com \
    --cc=joey.gouly@arm.com \
    --cc=kees@kernel.org \
    --cc=kristina.martsenko@arm.com \
    --cc=leobras@redhat.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=liuwei09@cestc.cn \
    --cc=liuyuntao12@huawei.com \
    --cc=luto@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=mbenes@suse.cz \
    --cc=ojeda@kernel.org \
    --cc=oleg@redhat.com \
    --cc=oliver.upton@linux.dev \
    --cc=paulmck@kernel.org \
    --cc=pcc@google.com \
    --cc=peterz@infradead.org \
    --cc=petr.pavlu@suse.com \
    --cc=prarit@redhat.com \
    --cc=ptosi@google.com \
    --cc=puranjay@kernel.org \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=rppt@kernel.org \
    --cc=samitolvanen@google.com \
    --cc=samuel.holland@sifive.com \
    --cc=sstabellini@kernel.org \
    --cc=sudeep.holla@arm.com \
    --cc=surenb@google.com \
    --cc=tglx@linutronix.de \
    --cc=thiago.bauermann@linaro.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=vschneid@redhat.com \
    --cc=wad@chromium.org \
    --cc=wangkefeng.wang@huawei.com \
    --cc=will@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    --cc=yangyj.ee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®