From: Julien Thierry <julien.thierry@arm.com>
To: Mark Rutland <mark.rutland@arm.com>
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, daniel.thompson@linaro.org,
joel@joelfernandes.org, marc.zyngier@arm.com,
christoffer.dall@arm.com, james.morse@arm.com,
catalin.marinas@arm.com, will.deacon@arm.com,
Dave Martin <Dave.Martin@arm.com>
Subject: Re: [PATCH v6 07/24] arm64: Make PMR part of task context
Date: Fri, 30 Nov 2018 09:25:09 +0000 [thread overview]
Message-ID: <92b85c6c-029d-d1d6-f299-32129c81009e@arm.com> (raw)
In-Reply-To: <20181129164600.ddr2ja5p7vc3qikb@lakrids.cambridge.arm.com>
On 29/11/18 16:46, Mark Rutland wrote:
> On Mon, Nov 12, 2018 at 11:56:58AM +0000, Julien Thierry wrote:
>> If ICC_PMR_EL1 is used to mask interrupts, its value should be
>> saved/restored whenever a task is context switched out/in or
>> gets an exception.
>>
>> Add PMR to the registers to save in the pt_regs struct upon kernel entry,
>> and restore it before ERET. Also, initialize it to a sane value when
>> creating new tasks.
>
> Could you please elaborate on when this matters?
>
> Does this actually matter for context-switch? Can we do that in a
> pseudo-NMI handler?
>
> Or does this only matter for exception entry/return, and not
> context-switch?
>
Yes, PMR becomes an equivalent of PSR.I and in the same way it will need
to be saved/restored on exception entry/return (except this is not done
by the architecture for PMR).
It is also necessary when context switching to a task that was preempted
in exception context (el1_preempt, return from syscall, ...). In the
same way as spsr_el1.
I'll update the commit message.
Thanks,
Julien
>
>> Signed-off-by: Julien Thierry <julien.thierry@arm.com>
>> Cc: Catalin Marinas <catalin.marinas@arm.com>
>> Cc: Will Deacon <will.deacon@arm.com>
>> Cc: Dave Martin <Dave.Martin@arm.com>
>> ---
>> arch/arm64/include/asm/processor.h | 3 +++
>> arch/arm64/include/asm/ptrace.h | 14 +++++++++++---
>> arch/arm64/kernel/asm-offsets.c | 1 +
>> arch/arm64/kernel/entry.S | 13 +++++++++++++
>> arch/arm64/kernel/process.c | 6 ++++++
>> 5 files changed, 34 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h
>> index 6b0d4df..b2315ef 100644
>> --- a/arch/arm64/include/asm/processor.h
>> +++ b/arch/arm64/include/asm/processor.h
>> @@ -168,6 +168,9 @@ static inline void start_thread_common(struct pt_regs *regs, unsigned long pc)
>> memset(regs, 0, sizeof(*regs));
>> forget_syscall(regs);
>> regs->pc = pc;
>> +
>> + if (system_supports_irq_prio_masking())
>> + regs->pmr_save = GIC_PRIO_IRQON;
>> }
>>
>> static inline void start_thread(struct pt_regs *regs, unsigned long pc,
>> diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h
>> index ce6998c..0ad46f5 100644
>> --- a/arch/arm64/include/asm/ptrace.h
>> +++ b/arch/arm64/include/asm/ptrace.h
>> @@ -19,6 +19,8 @@
>> #ifndef __ASM_PTRACE_H
>> #define __ASM_PTRACE_H
>>
>> +#include <asm/cpufeature.h>
>> +
>> #include <uapi/asm/ptrace.h>
>>
>> /* Current Exception Level values, as contained in CurrentEL */
>> @@ -173,7 +175,8 @@ struct pt_regs {
>> #endif
>>
>> u64 orig_addr_limit;
>> - u64 unused; // maintain 16 byte alignment
>> + /* Only valid when ARM64_HAS_IRQ_PRIO_MASKING is enabled. */
>> + u64 pmr_save;
>> u64 stackframe[2];
>> };
>>
>> @@ -208,8 +211,13 @@ static inline void forget_syscall(struct pt_regs *regs)
>> #define processor_mode(regs) \
>> ((regs)->pstate & PSR_MODE_MASK)
>>
>> -#define interrupts_enabled(regs) \
>> - (!((regs)->pstate & PSR_I_BIT))
>> +#define irqs_priority_unmasked(regs) \
>> + (system_supports_irq_prio_masking() ? \
>> + (regs)->pmr_save & GIC_PRIO_STATUS_BIT : \
>> + true)
>> +
>> +#define interrupts_enabled(regs) \
>> + (!((regs)->pstate & PSR_I_BIT) && irqs_priority_unmasked(regs))
>>
>> #define fast_interrupts_enabled(regs) \
>> (!((regs)->pstate & PSR_F_BIT))
>> diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c
>> index 323aeb5..bab4122 100644
>> --- a/arch/arm64/kernel/asm-offsets.c
>> +++ b/arch/arm64/kernel/asm-offsets.c
>> @@ -78,6 +78,7 @@ int main(void)
>> DEFINE(S_ORIG_X0, offsetof(struct pt_regs, orig_x0));
>> DEFINE(S_SYSCALLNO, offsetof(struct pt_regs, syscallno));
>> DEFINE(S_ORIG_ADDR_LIMIT, offsetof(struct pt_regs, orig_addr_limit));
>> + DEFINE(S_PMR_SAVE, offsetof(struct pt_regs, pmr_save));
>> DEFINE(S_STACKFRAME, offsetof(struct pt_regs, stackframe));
>> DEFINE(S_FRAME_SIZE, sizeof(struct pt_regs));
>> BLANK();
>> diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
>> index 039144e..eb8120e 100644
>> --- a/arch/arm64/kernel/entry.S
>> +++ b/arch/arm64/kernel/entry.S
>> @@ -249,6 +249,12 @@ alternative_else_nop_endif
>> msr sp_el0, tsk
>> .endif
>>
>> + /* Save pmr */
>> +alternative_if ARM64_HAS_IRQ_PRIO_MASKING
>> + mrs_s x20, SYS_ICC_PMR_EL1
>> + str x20, [sp, #S_PMR_SAVE]
>> +alternative_else_nop_endif
>> +
>> /*
>> * Registers that may be useful after this macro is invoked:
>> *
>> @@ -269,6 +275,13 @@ alternative_else_nop_endif
>> /* No need to restore UAO, it will be restored from SPSR_EL1 */
>> .endif
>>
>> + /* Restore pmr */
>> +alternative_if ARM64_HAS_IRQ_PRIO_MASKING
>> + ldr x20, [sp, #S_PMR_SAVE]
>> + msr_s SYS_ICC_PMR_EL1, x20
>> + dsb sy
>> +alternative_else_nop_endif
>> +
>> ldp x21, x22, [sp, #S_PC] // load ELR, SPSR
>> .if \el == 0
>> ct_user_enter
>> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
>> index d9a4c2d..71e8850 100644
>> --- a/arch/arm64/kernel/process.c
>> +++ b/arch/arm64/kernel/process.c
>> @@ -231,6 +231,9 @@ void __show_regs(struct pt_regs *regs)
>>
>> printk("sp : %016llx\n", sp);
>>
>> + if (system_supports_irq_prio_masking())
>> + printk("pmr_save: %08llx\n", regs->pmr_save);
>> +
>> i = top_reg;
>>
>> while (i >= 0) {
>> @@ -362,6 +365,9 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start,
>> if (arm64_get_ssbd_state() == ARM64_SSBD_FORCE_DISABLE)
>> childregs->pstate |= PSR_SSBS_BIT;
>>
>> + if (system_supports_irq_prio_masking())
>> + childregs->pmr_save = GIC_PRIO_IRQON;
>> +
>> p->thread.cpu_context.x19 = stack_start;
>> p->thread.cpu_context.x20 = stk_sz;
>> }
>> --
>> 1.9.1
>>
--
Julien Thierry
next prev parent reply other threads:[~2018-11-30 9:25 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-12 11:56 [PATCH v6 00/24] arm64: provide pseudo NMI with GICv3 Julien Thierry
2018-11-12 11:56 ` [PATCH v6 01/24] arm64: Remove unused daif related functions/macros Julien Thierry
2018-11-29 16:26 ` Mark Rutland
2018-11-30 18:03 ` Catalin Marinas
2018-11-12 11:56 ` [PATCH v6 02/24] arm64: cpufeature: Set SYSREG_GIC_CPUIF as a boot system feature Julien Thierry
2018-11-12 18:00 ` Suzuki K Poulose
2018-11-29 16:27 ` Mark Rutland
2018-11-30 18:07 ` Catalin Marinas
2018-11-12 11:56 ` [PATCH v6 03/24] arm64: cpufeature: Add cpufeature for IRQ priority masking Julien Thierry
2018-11-12 18:02 ` Suzuki K Poulose
2018-11-29 17:12 ` Mark Rutland
2018-12-03 10:33 ` Julien Thierry
2018-11-30 18:07 ` Catalin Marinas
2018-11-12 11:56 ` [PATCH v6 04/24] arm/arm64: gic-v3: Add PMR and RPR accessors Julien Thierry
2018-11-29 16:32 ` Mark Rutland
2018-11-30 18:07 ` Catalin Marinas
2018-11-12 11:56 ` [PATCH v6 05/24] irqchip/gic-v3: Switch to PMR masking before calling IRQ handler Julien Thierry
2018-11-29 18:12 ` Mark Rutland
2018-11-30 9:18 ` Julien Thierry
2018-12-04 16:21 ` Catalin Marinas
2018-11-12 11:56 ` [PATCH v6 06/24] arm64: ptrace: Provide definitions for PMR values Julien Thierry
2018-11-29 16:40 ` Mark Rutland
2018-11-30 8:53 ` Julien Thierry
2018-11-30 10:38 ` Daniel Thompson
2018-11-30 11:03 ` Julien Thierry
2018-11-12 11:56 ` [PATCH v6 07/24] arm64: Make PMR part of task context Julien Thierry
2018-11-29 16:46 ` Mark Rutland
2018-11-30 9:25 ` Julien Thierry [this message]
2018-12-04 17:09 ` Catalin Marinas
2018-12-04 17:30 ` Julien Thierry
2018-11-12 11:56 ` [PATCH v6 08/24] arm64: Unmask PMR before going idle Julien Thierry
2018-11-29 17:44 ` Mark Rutland
2018-11-30 10:55 ` Julien Thierry
2018-11-30 13:37 ` Mark Rutland
2018-12-03 10:38 ` Julien Thierry
2018-11-12 11:57 ` [PATCH v6 09/24] arm64: kvm: Unmask PMR before entering guest Julien Thierry
2018-11-12 11:57 ` [PATCH v6 10/24] arm64: irqflags: Use ICC_PMR_EL1 for interrupt masking Julien Thierry
2018-12-04 17:36 ` Catalin Marinas
2018-12-05 16:55 ` Julien Thierry
2018-12-05 18:26 ` Catalin Marinas
2018-12-06 9:50 ` Julien Thierry
2018-12-10 14:39 ` Catalin Marinas
2018-11-12 11:57 ` [PATCH v6 11/24] arm64: daifflags: Include PMR in daifflags restore operations Julien Thierry
2018-11-12 11:57 ` [PATCH v6 12/24] arm64: alternative: Allow alternative status checking per cpufeature Julien Thierry
2018-11-12 11:57 ` [PATCH v6 13/24] arm64: alternative: Apply alternatives early in boot process Julien Thierry
2018-11-12 11:57 ` [PATCH v6 14/24] irqchip/gic-v3: Factor group0 detection into functions Julien Thierry
2018-11-12 11:57 ` [PATCH v6 15/24] arm64: Switch to PMR masking when starting CPUs Julien Thierry
2018-12-04 17:51 ` Catalin Marinas
2018-12-04 18:11 ` Julien Thierry
2018-11-12 11:57 ` [PATCH v6 16/24] arm64: gic-v3: Implement arch support for priority masking Julien Thierry
2018-11-12 11:57 ` [PATCH v6 17/24] irqchip/gic-v3: Detect if GIC can support pseudo-NMIs Julien Thierry
2018-11-12 11:57 ` [PATCH v6 18/24] irqchip/gic-v3: Handle pseudo-NMIs Julien Thierry
2018-11-12 11:57 ` [PATCH v6 19/24] irqchip/gic: Add functions to access irq priorities Julien Thierry
2018-11-12 11:57 ` [PATCH v6 20/24] irqchip/gic-v3: Allow interrupts to be set as pseudo-NMI Julien Thierry
2018-11-12 11:57 ` [PATCH v6 21/24] arm64: Handle serror in NMI context Julien Thierry
2018-12-04 18:09 ` Catalin Marinas
2018-12-05 13:02 ` James Morse
2018-11-12 11:57 ` [PATCH v6 22/24] arm64: Skip preemption when exiting an NMI Julien Thierry
2018-11-12 11:57 ` [PATCH v6 23/24] arm64: Skip irqflags tracing for NMI in IRQs disabled context Julien Thierry
2018-11-12 11:57 ` [PATCH v6 24/24] arm64: Enable the support of pseudo-NMIs Julien Thierry
2018-11-12 12:00 ` [PATCH v6 00/24] arm64: provide pseudo NMI with GICv3 Julien Thierry
2018-11-13 14:43 ` Julien Thierry
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=92b85c6c-029d-d1d6-f299-32129c81009e@arm.com \
--to=julien.thierry@arm.com \
--cc=Dave.Martin@arm.com \
--cc=catalin.marinas@arm.com \
--cc=christoffer.dall@arm.com \
--cc=daniel.thompson@linaro.org \
--cc=james.morse@arm.com \
--cc=joel@joelfernandes.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.zyngier@arm.com \
--cc=mark.rutland@arm.com \
--cc=will.deacon@arm.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;
as well as URLs for NNTP newsgroup(s).