Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp7260827imm; Tue, 28 Aug 2018 08:57:21 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdabk4x3k4D6ju73en+t5Dei4+HMT3SPpwRAgoF9qbiJLupEwpD31Ur/JoFX8eUao9bSITgI X-Received: by 2002:a65:5c83:: with SMTP id a3-v6mr2190089pgt.164.1535471841779; Tue, 28 Aug 2018 08:57:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535471841; cv=none; d=google.com; s=arc-20160816; b=jQUzrPozUKMKs9xf08fEXKwm9wOpRKy/UkrCC2rWOCf7kWrKiuDN8Z1cVwMLP90v/N lWWhrNjOXP1nzU796htQ9E6GyX5pozyqYbjYlJZ3zMNvV1K+8XNSQB/V0JtbTSAKy2EH ld6tOXGm0BhttCwuJ07qYVdnAgq6nFkcAl2iFIflaVvkAuHwl5R4vvQzcfWrMRP5PwrH hqMdS1KaGvqqcyrWkH2zhHUK0nFdoXxvXBcLmJWYQX0W/pDpVQAbWsf21IICdX6jWort mgH7wtvHJ8H9RSE/V0++VibFxI06CjbsyUsYy6DWWWXbt4AJYDaLEg7npaeTjnGGgVuh fylQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=hQwSNgZOqhzX9OWL0mBU+hABU7lel7fLyWv3BU//UqE=; b=TKyED1RAIjMgMf8Wr/fWfjGPhmt2f5te5cyD6yExkF8BUHFq0L6sfk7+OqoKMMYCZr LyESpZgccLNURUh75WfjQ1Q8bOdQxk0qViZzkbtipWfuLLelC3yozenc+MoLChCXDDni MVcDPP7WnZcaPZdGRI1Efdg6CT9NV5UysR6xJnOMKAQBV01UbZxaVv21SHukoltHgsmC z2QQOTpj9i4GO4SCQvlSvyFmHALbbIZEE/SfA98FHjFCNkQuSISoTITRsBF6MhL5uO1y Sg4utpSl9Q6vDdZydr3pW4X8W3mJVtjyS9mjAlselSnxgA/bP6PvK/3Fdq40m3KtX/L7 rPtg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 72-v6si1356191pfq.6.2018.08.28.08.57.06; Tue, 28 Aug 2018 08:57:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727608AbeH1Toc (ORCPT + 99 others); Tue, 28 Aug 2018 15:44:32 -0400 Received: from foss.arm.com ([217.140.101.70]:41018 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726383AbeH1Toa (ORCPT ); Tue, 28 Aug 2018 15:44:30 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 705EE80D; Tue, 28 Aug 2018 08:52:14 -0700 (PDT) Received: from e112298-lin.Emea.Arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 322193F557; Tue, 28 Aug 2018 08:52:12 -0700 (PDT) From: Julien Thierry To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, daniel.thompson@linaro.org, joel@joelfernandes.org, marc.zyngier@arm.com, mark.rutland@arm.com, christoffer.dall@arm.com, james.morse@arm.com, catalin.marinas@arm.com, will.deacon@arm.com, Julien Thierry , Oleg Nesterov , Dave Martin Subject: [PATCH v5 11/27] arm64: Make PMR part of task context Date: Tue, 28 Aug 2018 16:51:21 +0100 Message-Id: <1535471497-38854-12-git-send-email-julien.thierry@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1535471497-38854-1-git-send-email-julien.thierry@arm.com> References: <1535471497-38854-1-git-send-email-julien.thierry@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Tested-by: Daniel Thompson Signed-off-by: Julien Thierry Cc: Catalin Marinas Cc: Will Deacon Cc: Oleg Nesterov Cc: Dave Martin --- arch/arm64/include/asm/processor.h | 1 + arch/arm64/include/asm/ptrace.h | 5 ++++- arch/arm64/kernel/asm-offsets.c | 1 + arch/arm64/kernel/entry.S | 16 ++++++++++++++++ arch/arm64/kernel/process.c | 2 ++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index 79657ad..45a2e08 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -167,6 +167,7 @@ static inline void start_thread_common(struct pt_regs *regs, unsigned long pc) memset(regs, 0, sizeof(*regs)); forget_syscall(regs); regs->pc = pc; + regs->pmr_save = ICC_PMR_EL1_UNMASKED; } 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 177b851..29ec217 100644 --- a/arch/arm64/include/asm/ptrace.h +++ b/arch/arm64/include/asm/ptrace.h @@ -25,6 +25,9 @@ #define CurrentEL_EL1 (1 << 2) #define CurrentEL_EL2 (2 << 2) +/* PMR value use to unmask interrupts */ +#define ICC_PMR_EL1_UNMASKED 0xf0 + /* AArch32-specific ptrace requests */ #define COMPAT_PTRACE_GETREGS 12 #define COMPAT_PTRACE_SETREGS 13 @@ -163,7 +166,7 @@ struct pt_regs { #endif u64 orig_addr_limit; - u64 unused; // maintain 16 byte alignment + u64 pmr_save; u64 stackframe[2]; }; 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 85ce06ac..79b06af 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -249,6 +249,15 @@ 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 +alternative_else + /* Keep a sane value in the task context */ + mov x20, ICC_PMR_EL1_UNMASKED +alternative_endif + str x20, [sp, #S_PMR_SAVE] + /* * Registers that may be useful after this macro is invoked: * @@ -269,6 +278,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 7f1628e..1f6a4d5 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -230,6 +230,7 @@ void __show_regs(struct pt_regs *regs) } printk("sp : %016llx\n", sp); + printk("pmr_save: %08llx\n", regs->pmr_save); i = top_reg; @@ -355,6 +356,7 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start, } else { memset(childregs, 0, sizeof(struct pt_regs)); childregs->pstate = PSR_MODE_EL1h; + childregs->pmr_save = ICC_PMR_EL1_UNMASKED; if (IS_ENABLED(CONFIG_ARM64_UAO) && cpus_have_const_cap(ARM64_HAS_UAO)) childregs->pstate |= PSR_UAO_BIT; -- 1.9.1