[{"id":1786381,"web_url":"http://patchwork.ozlabs.org/comment/1786381/","msgid":"<20171013153148.dnejsvhxeui6opfw@armageddon.cambridge.arm.com>","list_archive_url":null,"date":"2017-10-13T15:31:48","subject":"Re: [PATCH v3 04/13] arm64: alternatives: use tpidr_el2 on VHE hosts","submitter":{"id":938,"url":"http://patchwork.ozlabs.org/api/people/938/","name":"Catalin Marinas","email":"catalin.marinas@arm.com"},"content":"On Fri, Sep 22, 2017 at 07:26:05PM +0100, James Morse wrote:\n> diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c\n> index cd52d365d1f0..8e4c7da2b126 100644\n> --- a/arch/arm64/kernel/cpufeature.c\n> +++ b/arch/arm64/kernel/cpufeature.c\n> @@ -865,6 +865,7 @@ static const struct arm64_cpu_capabilities arm64_features[] = {\n>  \t\t.capability = ARM64_HAS_VIRT_HOST_EXTN,\n>  \t\t.def_scope = SCOPE_SYSTEM,\n>  \t\t.matches = runs_at_el2,\n> +\t\t.enable = cpu_copy_el2regs,\n>  \t},\n>  \t{\n>  \t\t.desc = \"32-bit EL0 Support\",\n> @@ -1308,3 +1309,25 @@ static int __init enable_mrs_emulation(void)\n>  }\n>  \n>  late_initcall(enable_mrs_emulation);\n> +\n> +int cpu_copy_el2regs(void *__unused)\n> +{\n> +\tint do_copyregs = 0;\n> +\n> +\t/*\n> +\t * Copy register values that aren't redirected by hardware.\n> +\t *\n> +\t * Before code patching, we only set tpidr_el1, all CPUs need to copy\n> +\t * this value to tpidr_el2 before we patch the code. Once we've done\n> +\t * that, freshly-onlined CPUs will set tpidr_el2, so we don't need to\n> +\t * do anything here.\n> +\t */\n> +\tasm volatile(ALTERNATIVE(\"mov %0, #1\", \"mov %0, #0\",\n> +\t\t\t\t ARM64_HAS_VIRT_HOST_EXTN)\n> +\t\t    : \"=r\" (do_copyregs) : : );\n\nCan you just do:\n\n\tif (cpu_have_const_cap(ARM64_HAS_VIRT_HOST_EXTN))\n\t\twrite_sysreg(read_sysreg(tpidr_el1), tpidr_el2);\n\nAt this point the capability bits should be set and the jump labels\nenabled.\n\nOtherwise:\n\nReviewed-by: Catalin Marinas <catalin.marinas@arm.com>\n--\nTo unsubscribe from this list: send the line \"unsubscribe devicetree\" in\nthe body of a message to majordomo@vger.kernel.org\nMore majordomo info at  http://vger.kernel.org/majordomo-info.html","headers":{"Return-Path":"<devicetree-owner@vger.kernel.org>","X-Original-To":"incoming-dt@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming-dt@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=devicetree-owner@vger.kernel.org; receiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3yDBXW18Rlz9t2S\n\tfor <incoming-dt@patchwork.ozlabs.org>;\n\tSat, 14 Oct 2017 02:31:55 +1100 (AEDT)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1753545AbdJMPbx (ORCPT\n\t<rfc822;incoming-dt@patchwork.ozlabs.org>);\n\tFri, 13 Oct 2017 11:31:53 -0400","from foss.arm.com ([217.140.101.70]:35166 \"EHLO foss.arm.com\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1753479AbdJMPbx (ORCPT <rfc822;devicetree@vger.kernel.org>);\n\tFri, 13 Oct 2017 11:31:53 -0400","from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249])\n\tby usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 058741529;\n\tFri, 13 Oct 2017 08:31:53 -0700 (PDT)","from armageddon.cambridge.arm.com (armageddon.cambridge.arm.com\n\t[10.1.206.84])\n\tby usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id\n\t152413F3E1; Fri, 13 Oct 2017 08:31:50 -0700 (PDT)"],"Date":"Fri, 13 Oct 2017 16:31:48 +0100","From":"Catalin Marinas <catalin.marinas@arm.com>","To":"James Morse <james.morse@arm.com>","Cc":"linux-arm-kernel@lists.infradead.org, Mark Rutland <mark.rutland@arm.com>,\n\tdevicetree@vger.kernel.org,\n\tLorenzo Pieralisi <lorenzo.pieralisi@arm.com>, \n\tMarc Zyngier <marc.zyngier@arm.com>, Will Deacon <will.deacon@arm.com>,\n\tRob Herring <robh+dt@kernel.org>, Loc Ho <lho@apm.com>,\n\tkvmarm@lists.cs.columbia.edu,\n\tChristoffer Dall <christoffer.dall@linaro.org>","Subject":"Re: [PATCH v3 04/13] arm64: alternatives: use tpidr_el2 on VHE hosts","Message-ID":"<20171013153148.dnejsvhxeui6opfw@armageddon.cambridge.arm.com>","References":"<20170922182614.27885-1-james.morse@arm.com>\n\t<20170922182614.27885-5-james.morse@arm.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20170922182614.27885-5-james.morse@arm.com>","User-Agent":"NeoMutt/20170113 (1.7.2)","Sender":"devicetree-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<devicetree.vger.kernel.org>","X-Mailing-List":"devicetree@vger.kernel.org"}},{"id":1786390,"web_url":"http://patchwork.ozlabs.org/comment/1786390/","msgid":"<20171013154226.xswo4y2viht22wvk@armageddon.cambridge.arm.com>","list_archive_url":null,"date":"2017-10-13T15:42:26","subject":"Re: [PATCH v3 08/13] arm64: Add vmap_stack header file","submitter":{"id":938,"url":"http://patchwork.ozlabs.org/api/people/938/","name":"Catalin Marinas","email":"catalin.marinas@arm.com"},"content":"On Fri, Sep 22, 2017 at 07:26:09PM +0100, James Morse wrote:\n> diff --git a/arch/arm64/include/asm/vmap_stack.h b/arch/arm64/include/asm/vmap_stack.h\n> new file mode 100644\n> index 000000000000..f41d043cac31\n> --- /dev/null\n> +++ b/arch/arm64/include/asm/vmap_stack.h\n> @@ -0,0 +1,41 @@\n> +/*\n> + * Copyright (C) 2017 ARM Ltd.\n> + *\n> + * This program is free software; you can redistribute it and/or modify\n> + * it under the terms of the GNU General Public License version 2 as\n> + * published by the Free Software Foundation.\n> + *\n> + * This program is distributed in the hope that it will be useful,\n> + * but WITHOUT ANY WARRANTY; without even the implied warranty of\n> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n> + * GNU General Public License for more details.\n> + *\n> + * You should have received a copy of the GNU General Public License\n> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n> + */\n> +#ifndef __ASM_VMAP_STACK_H\n> +#define __ASM_VMAP_STACK_H\n> +\n> +#include <linux/vmalloc.h>\n> +#include <asm/memory.h>\n> +#include <asm/pgtable.h>\n> +#include <asm/thread_info.h>\n> +\n> +#ifdef CONFIG_VMAP_STACK\n> +/*\n> + * To ensure that VMAP'd stack overflow detection works correctly, all VMAP'd\n> + * stacks need to have the same alignment.\n> + */\n> +static inline unsigned long *arch_alloc_vmap_stack(size_t stack_size, int node)\n> +{\n> +\treturn __vmalloc_node_range(stack_size, THREAD_ALIGN,\n> +\t\t\t\t    VMALLOC_START, VMALLOC_END,\n> +\t\t\t\t    THREADINFO_GFP, PAGE_KERNEL, 0, node,\n> +\t\t\t\t    __builtin_return_address(0));\n> +}\n> +\n> +#else\n> +unsigned long *arch_alloc_vmap_stack(size_t stack_size, int node); // link error\n\nDo you actually need this here? The calling site (at least in this\npatch), is surrounded by CONFIG_VMAP_STACK. Removing the dummy\ndeclaration should be fine (I haven't read the rest of the patches yet,\nmaybe it's needed later; would a BUILD_BUG do?).","headers":{"Return-Path":"<devicetree-owner@vger.kernel.org>","X-Original-To":"incoming-dt@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming-dt@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=devicetree-owner@vger.kernel.org; receiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3yDBmn1b0sz9t2S\n\tfor <incoming-dt@patchwork.ozlabs.org>;\n\tSat, 14 Oct 2017 02:42:33 +1100 (AEDT)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1757463AbdJMPmb (ORCPT\n\t<rfc822;incoming-dt@patchwork.ozlabs.org>);\n\tFri, 13 Oct 2017 11:42:31 -0400","from foss.arm.com ([217.140.101.70]:35296 \"EHLO foss.arm.com\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1753366AbdJMPmb (ORCPT <rfc822;devicetree@vger.kernel.org>);\n\tFri, 13 Oct 2017 11:42:31 -0400","from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249])\n\tby usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 263AD1529;\n\tFri, 13 Oct 2017 08:42:31 -0700 (PDT)","from armageddon.cambridge.arm.com (armageddon.cambridge.arm.com\n\t[10.1.206.84])\n\tby usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id\n\t3570B3F3E1; Fri, 13 Oct 2017 08:42:29 -0700 (PDT)"],"Date":"Fri, 13 Oct 2017 16:42:26 +0100","From":"Catalin Marinas <catalin.marinas@arm.com>","To":"James Morse <james.morse@arm.com>","Cc":"linux-arm-kernel@lists.infradead.org, Mark Rutland <mark.rutland@arm.com>,\n\tdevicetree@vger.kernel.org,\n\tLorenzo Pieralisi <lorenzo.pieralisi@arm.com>, \n\tMarc Zyngier <marc.zyngier@arm.com>, Will Deacon <will.deacon@arm.com>,\n\tRob Herring <robh+dt@kernel.org>, Loc Ho <lho@apm.com>,\n\tkvmarm@lists.cs.columbia.edu,\n\tChristoffer Dall <christoffer.dall@linaro.org>","Subject":"Re: [PATCH v3 08/13] arm64: Add vmap_stack header file","Message-ID":"<20171013154226.xswo4y2viht22wvk@armageddon.cambridge.arm.com>","References":"<20170922182614.27885-1-james.morse@arm.com>\n\t<20170922182614.27885-9-james.morse@arm.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20170922182614.27885-9-james.morse@arm.com>","User-Agent":"NeoMutt/20170113 (1.7.2)","Sender":"devicetree-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<devicetree.vger.kernel.org>","X-Mailing-List":"devicetree@vger.kernel.org"}},{"id":1786402,"web_url":"http://patchwork.ozlabs.org/comment/1786402/","msgid":"<20171013154914.ktxecc6zobh7fmr6@armageddon.cambridge.arm.com>","list_archive_url":null,"date":"2017-10-13T15:49:14","subject":"Re: [PATCH v3 07/13] firmware: arm_sdei: Add driver for Software\n\tDelegated Exceptions","submitter":{"id":938,"url":"http://patchwork.ozlabs.org/api/people/938/","name":"Catalin Marinas","email":"catalin.marinas@arm.com"},"content":"On Fri, Sep 22, 2017 at 07:26:08PM +0100, James Morse wrote:\n> The Software Delegated Exception Interface (SDEI) is an ARM standard\n> for registering callbacks from the platform firmware into the OS.\n> This is typically used to implement firmware notifications (such as\n> firmware-first RAS) or promote an IRQ that has been promoted to a\n> firmware-assisted NMI.\n> \n> Add the code for detecting the SDEI version and the framework for\n> registering and unregistering events. Subsequent patches will add the\n> arch-specific backend code and the necessary power management hooks.\n> \n> Only shared events are supported, power management, private events and\n> discovery for ACPI systems will be added by later patches.\n> \n> Signed-off-by: James Morse <james.morse@arm.com>\n> ---\n> Changes since v2:\n>  * Copy the priority into the structure the arch asm handler gets. This\n>    is used for VMAP stacks where we can't know if a critical event interrupted\n>    a normal priority event, thus they need separate stacks.\n> \n> Changes since v1:\n>  * Changed entry point to unsigned long, if we support non-vhe systems this\n>    won't be a valid pointer\n>  * Made invoke_sdei_fn() pass the only register we are interested in, instead\n>    of the whole arm_smccc_res\n>  * Made all the locking WARN_ON()s lockdep_assert_held()s.\n>  * Moved more messages from 'err' to 'warn'.\n>  * Made IS_SDEI_CALL() not depend on whether the config option is selected.\n>  * Made 'event failed' messages rate limited.\n> \n>  drivers/firmware/Kconfig    |   7 +\n>  drivers/firmware/Makefile   |   1 +\n>  drivers/firmware/arm_sdei.c | 616 ++++++++++++++++++++++++++++++++++++++++++++\n>  include/linux/sdei.h        | 100 +++++++\n>  include/uapi/linux/sdei.h   |  91 +++++++\n>  5 files changed, 815 insertions(+)\n>  create mode 100644 drivers/firmware/arm_sdei.c\n>  create mode 100644 include/linux/sdei.h\n>  create mode 100644 include/uapi/linux/sdei.h\n\nI haven't reviewed this patch (yet...). However, I think it's worth\nadding a MAINTAINERS entry with your name on it (unless you really want\nto distance yourself from this code once merged ;)).\n\nThanks.","headers":{"Return-Path":"<devicetree-owner@vger.kernel.org>","X-Original-To":"incoming-dt@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming-dt@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=devicetree-owner@vger.kernel.org; receiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3yDC1v6qyFz9t2W\n\tfor <incoming-dt@patchwork.ozlabs.org>;\n\tSat, 14 Oct 2017 02:53:55 +1100 (AEDT)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1753484AbdJMPxy (ORCPT\n\t<rfc822;incoming-dt@patchwork.ozlabs.org>);\n\tFri, 13 Oct 2017 11:53:54 -0400","from foss.arm.com ([217.140.101.70]:35444 \"EHLO foss.arm.com\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1758507AbdJMPtT (ORCPT <rfc822;devicetree@vger.kernel.org>);\n\tFri, 13 Oct 2017 11:49:19 -0400","from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249])\n\tby usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 19E3B1435;\n\tFri, 13 Oct 2017 08:49:19 -0700 (PDT)","from armageddon.cambridge.arm.com (armageddon.cambridge.arm.com\n\t[10.1.206.84])\n\tby usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id\n\t2A8603F3E1; Fri, 13 Oct 2017 08:49:17 -0700 (PDT)"],"Date":"Fri, 13 Oct 2017 16:49:14 +0100","From":"Catalin Marinas <catalin.marinas@arm.com>","To":"James Morse <james.morse@arm.com>","Cc":"linux-arm-kernel@lists.infradead.org, Mark Rutland <mark.rutland@arm.com>,\n\tdevicetree@vger.kernel.org,\n\tLorenzo Pieralisi <lorenzo.pieralisi@arm.com>, \n\tMarc Zyngier <marc.zyngier@arm.com>, Will Deacon <will.deacon@arm.com>,\n\tRob Herring <robh+dt@kernel.org>, Loc Ho <lho@apm.com>,\n\tkvmarm@lists.cs.columbia.edu,\n\tChristoffer Dall <christoffer.dall@linaro.org>","Subject":"Re: [PATCH v3 07/13] firmware: arm_sdei: Add driver for Software\n\tDelegated Exceptions","Message-ID":"<20171013154914.ktxecc6zobh7fmr6@armageddon.cambridge.arm.com>","References":"<20170922182614.27885-1-james.morse@arm.com>\n\t<20170922182614.27885-8-james.morse@arm.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20170922182614.27885-8-james.morse@arm.com>","User-Agent":"NeoMutt/20170113 (1.7.2)","Sender":"devicetree-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<devicetree.vger.kernel.org>","X-Mailing-List":"devicetree@vger.kernel.org"}},{"id":1786459,"web_url":"http://patchwork.ozlabs.org/comment/1786459/","msgid":"<59E0EEE5.2020208@arm.com>","list_archive_url":null,"date":"2017-10-13T16:50:45","subject":"Re: [PATCH v3 04/13] arm64: alternatives: use tpidr_el2 on VHE hosts","submitter":{"id":66575,"url":"http://patchwork.ozlabs.org/api/people/66575/","name":"James Morse","email":"james.morse@arm.com"},"content":"Hi Catalin,\n\nOn 13/10/17 16:31, Catalin Marinas wrote:\n> On Fri, Sep 22, 2017 at 07:26:05PM +0100, James Morse wrote:\n>> diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c\n>> index cd52d365d1f0..8e4c7da2b126 100644\n>> --- a/arch/arm64/kernel/cpufeature.c\n>> +++ b/arch/arm64/kernel/cpufeature.c\n\n>> @@ -1308,3 +1309,25 @@ static int __init enable_mrs_emulation(void)\n>>  }\n>>  \n>>  late_initcall(enable_mrs_emulation);\n>> +\n>> +int cpu_copy_el2regs(void *__unused)\n>> +{\n>> +\tint do_copyregs = 0;\n>> +\n>> +\t/*\n>> +\t * Copy register values that aren't redirected by hardware.\n>> +\t *\n>> +\t * Before code patching, we only set tpidr_el1, all CPUs need to copy\n>> +\t * this value to tpidr_el2 before we patch the code. Once we've done\n>> +\t * that, freshly-onlined CPUs will set tpidr_el2, so we don't need to\n>> +\t * do anything here.\n>> +\t */\n>> +\tasm volatile(ALTERNATIVE(\"mov %0, #1\", \"mov %0, #0\",\n>> +\t\t\t\t ARM64_HAS_VIRT_HOST_EXTN)\n>> +\t\t    : \"=r\" (do_copyregs) : : );\n> \n> Can you just do:\n> \n> \tif (cpu_have_const_cap(ARM64_HAS_VIRT_HOST_EXTN))\n> \t\twrite_sysreg(read_sysreg(tpidr_el1), tpidr_el2);\n> \n> At this point the capability bits should be set and the jump labels\n> enabled.\n\nThese are enabled too early, we haven't done patching yet.\n\nWe need to copy tpidr_el1 -> tpidr_el2 on all CPUs that are online before code\npatching.\n\nAfter code patching new CPUs set tpidr_el2 when they come online, so we don't\nneed to do the copy... but this enable method is still called. There is nothing\nfor us to do, and tpidr_el1 now contains junk, so the copy\n\n\ncpu_have_const_cap() is great for knowing if we have a feature, here we want to\nknow if we've done the patching for this feature.\n\nI can wrap the ALTERNATIVE() into a helper, something like:\n> arm64_alternatives_applied(ARM64_HAS_VIRT_HOST_EXTN)\n\nwhich should make it clearer.\n\nChristoffer had the same question at connect, so I evidently haven't found the\nright way of describing this yet.\n\n\n> Otherwise:\n> \n> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>\n\nThanks for taking a look, I'll leave this RB until your happy with the\nALTERNATIVE() hackery above.\n\n\nJames\n--\nTo unsubscribe from this list: send the line \"unsubscribe devicetree\" in\nthe body of a message to majordomo@vger.kernel.org\nMore majordomo info at  http://vger.kernel.org/majordomo-info.html","headers":{"Return-Path":"<devicetree-owner@vger.kernel.org>","X-Original-To":"incoming-dt@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming-dt@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=devicetree-owner@vger.kernel.org; receiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3yDDKP4mtWz9sRq\n\tfor <incoming-dt@patchwork.ozlabs.org>;\n\tSat, 14 Oct 2017 03:52:25 +1100 (AEDT)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1752251AbdJMQwZ (ORCPT\n\t<rfc822;incoming-dt@patchwork.ozlabs.org>);\n\tFri, 13 Oct 2017 12:52:25 -0400","from foss.arm.com ([217.140.101.70]:36366 \"EHLO foss.arm.com\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1751817AbdJMQwY (ORCPT <rfc822;devicetree@vger.kernel.org>);\n\tFri, 13 Oct 2017 12:52:24 -0400","from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249])\n\tby usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 23D8D1435;\n\tFri, 13 Oct 2017 09:52:24 -0700 (PDT)","from [10.1.207.55] (melchizedek.cambridge.arm.com [10.1.207.55])\n\tby usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id\n\t524483F236; Fri, 13 Oct 2017 09:52:22 -0700 (PDT)"],"Message-ID":"<59E0EEE5.2020208@arm.com>","Date":"Fri, 13 Oct 2017 17:50:45 +0100","From":"James Morse <james.morse@arm.com>","User-Agent":"Mozilla/5.0 (X11; Linux x86_64;\n\trv:31.0) Gecko/20100101 Icedove/31.6.0","MIME-Version":"1.0","To":"Catalin Marinas <catalin.marinas@arm.com>","CC":"linux-arm-kernel@lists.infradead.org, Mark Rutland <mark.rutland@arm.com>,\n\tdevicetree@vger.kernel.org,\n\tLorenzo Pieralisi <lorenzo.pieralisi@arm.com>, \n\tMarc Zyngier <marc.zyngier@arm.com>, Will Deacon <will.deacon@arm.com>,\n\tRob Herring <robh+dt@kernel.org>, Loc Ho <lho@apm.com>,\n\tkvmarm@lists.cs.columbia.edu,\n\tChristoffer Dall <christoffer.dall@linaro.org>","Subject":"Re: [PATCH v3 04/13] arm64: alternatives: use tpidr_el2 on VHE hosts","References":"<20170922182614.27885-1-james.morse@arm.com>\n\t<20170922182614.27885-5-james.morse@arm.com>\n\t<20171013153148.dnejsvhxeui6opfw@armageddon.cambridge.arm.com>","In-Reply-To":"<20171013153148.dnejsvhxeui6opfw@armageddon.cambridge.arm.com>","Content-Type":"text/plain; charset=windows-1252","Content-Transfer-Encoding":"7bit","Sender":"devicetree-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<devicetree.vger.kernel.org>","X-Mailing-List":"devicetree@vger.kernel.org"}},{"id":1787312,"web_url":"http://patchwork.ozlabs.org/comment/1787312/","msgid":"<20171016101736.fkaikxflyc46zczf@armageddon.cambridge.arm.com>","list_archive_url":null,"date":"2017-10-16T10:17:37","subject":"Re: [PATCH v3 04/13] arm64: alternatives: use tpidr_el2 on VHE hosts","submitter":{"id":938,"url":"http://patchwork.ozlabs.org/api/people/938/","name":"Catalin Marinas","email":"catalin.marinas@arm.com"},"content":"On Fri, Sep 22, 2017 at 07:26:05PM +0100, James Morse wrote:\n> diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h\n> index 29adab8138c3..8f2d0f7d193b 100644\n> --- a/arch/arm64/include/asm/processor.h\n> +++ b/arch/arm64/include/asm/processor.h\n> @@ -193,5 +193,6 @@ static inline void spin_lock_prefetch(const void *ptr)\n>  \n>  int cpu_enable_pan(void *__unused);\n>  int cpu_enable_cache_maint_trap(void *__unused);\n> +int cpu_copy_el2regs(void *__unused);\n>  \n>  #endif /* __ASM_PROCESSOR_H */\n> diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c\n> index cd52d365d1f0..8e4c7da2b126 100644\n> --- a/arch/arm64/kernel/cpufeature.c\n> +++ b/arch/arm64/kernel/cpufeature.c\n[...]\n> +int cpu_copy_el2regs(void *__unused)\n\nCan this be static? I couldn't find it used anywhere else apart from\ncpufeature.c","headers":{"Return-Path":"<devicetree-owner@vger.kernel.org>","X-Original-To":"incoming-dt@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming-dt@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=devicetree-owner@vger.kernel.org; receiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3yFvQc1MDPz9sPk\n\tfor <incoming-dt@patchwork.ozlabs.org>;\n\tMon, 16 Oct 2017 21:17:44 +1100 (AEDT)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1751376AbdJPKRn (ORCPT\n\t<rfc822;incoming-dt@patchwork.ozlabs.org>);\n\tMon, 16 Oct 2017 06:17:43 -0400","from foss.arm.com ([217.140.101.70]:54862 \"EHLO foss.arm.com\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1750914AbdJPKRm (ORCPT <rfc822;devicetree@vger.kernel.org>);\n\tMon, 16 Oct 2017 06:17:42 -0400","from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249])\n\tby usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3A7541435;\n\tMon, 16 Oct 2017 03:17:42 -0700 (PDT)","from armageddon.cambridge.arm.com (armageddon.cambridge.arm.com\n\t[10.1.206.84])\n\tby usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id\n\t4AE6E3F483; Mon, 16 Oct 2017 03:17:40 -0700 (PDT)"],"Date":"Mon, 16 Oct 2017 11:17:37 +0100","From":"Catalin Marinas <catalin.marinas@arm.com>","To":"James Morse <james.morse@arm.com>","Cc":"linux-arm-kernel@lists.infradead.org, Mark Rutland <mark.rutland@arm.com>,\n\tdevicetree@vger.kernel.org,\n\tLorenzo Pieralisi <lorenzo.pieralisi@arm.com>, \n\tMarc Zyngier <marc.zyngier@arm.com>, Will Deacon <will.deacon@arm.com>,\n\tRob Herring <robh+dt@kernel.org>, Loc Ho <lho@apm.com>,\n\tkvmarm@lists.cs.columbia.edu,\n\tChristoffer Dall <christoffer.dall@linaro.org>","Subject":"Re: [PATCH v3 04/13] arm64: alternatives: use tpidr_el2 on VHE hosts","Message-ID":"<20171016101736.fkaikxflyc46zczf@armageddon.cambridge.arm.com>","References":"<20170922182614.27885-1-james.morse@arm.com>\n\t<20170922182614.27885-5-james.morse@arm.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20170922182614.27885-5-james.morse@arm.com>","User-Agent":"NeoMutt/20170113 (1.7.2)","Sender":"devicetree-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<devicetree.vger.kernel.org>","X-Mailing-List":"devicetree@vger.kernel.org"}},{"id":1787437,"web_url":"http://patchwork.ozlabs.org/comment/1787437/","msgid":"<20171016134139.sqe6xabdson2d5rd@armageddon.cambridge.arm.com>","list_archive_url":null,"date":"2017-10-16T13:41:39","subject":"Re: [PATCH v3 09/13] arm64: kernel: Add arch-specific SDEI entry\n\tcode and CPU masking","submitter":{"id":938,"url":"http://patchwork.ozlabs.org/api/people/938/","name":"Catalin Marinas","email":"catalin.marinas@arm.com"},"content":"On Fri, Sep 22, 2017 at 07:26:10PM +0100, James Morse wrote:\n> diff --git a/arch/arm64/include/asm/sdei.h b/arch/arm64/include/asm/sdei.h\n> new file mode 100644\n> index 000000000000..ed329e01a301\n> --- /dev/null\n> +++ b/arch/arm64/include/asm/sdei.h\n> @@ -0,0 +1,63 @@\n> +/*\n> + * Copyright (C) 2017 ARM Ltd.\n> + *\n> + * This program is free software; you can redistribute it and/or modify\n> + * it under the terms of the GNU General Public License version 2 as\n> + * published by the Free Software Foundation.\n> + *\n> + * This program is distributed in the hope that it will be useful,\n> + * but WITHOUT ANY WARRANTY; without even the implied warranty of\n> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n> + * GNU General Public License for more details.\n> + *\n> + * You should have received a copy of the GNU General Public License\n> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n> + */\n> +#ifndef __ASM_SDEI_H\n> +#define __ASM_SDEI_H\n> +\n> +/* Values for sdei_exit_mode */\n> +#define SDEI_EXIT_HVC  0\n> +#define SDEI_EXIT_SMC  1\n> +\n> +#define SDEI_STACK_SIZE\t\tIRQ_STACK_SIZE\n> +\n> +#ifndef __ASSEMBLY__\n> +\n> +#include <linux/linkage.h>\n> +#include <linux/types.h>\n> +\n> +#include <asm/virt.h>\n> +\n> +extern unsigned long sdei_exit_mode;\n> +\n> +/* Software Delegated Exception entry point from firmware*/\n> +asmlinkage void __sdei_asm_handler(unsigned long event_num, unsigned long arg,\n> +\t\t\t\t   unsigned long pc, unsigned long pstate);\n> +\n> +/*\n> + * The above entry point does the minimum to call C code. This function does\n> + * anything else, before calling the driver.\n> + */\n> +struct sdei_registered_event;\n> +asmlinkage unsigned long __sdei_handler(struct pt_regs *regs,\n> +\t\t\t\t\tstruct sdei_registered_event *arg);\n> +\n> +extern unsigned long sdei_arch_get_entry_point(int conduit);\n\nNitpick: drop the \"extern\" here.\n\n> diff --git a/arch/arm64/kernel/sdei-entry.S b/arch/arm64/kernel/sdei-entry.S\n> new file mode 100644\n> index 000000000000..cf12f8da0789\n> --- /dev/null\n> +++ b/arch/arm64/kernel/sdei-entry.S\n> @@ -0,0 +1,122 @@\n> +/*\n> + * Software Delegated Exception entry point from firmware to the kernel.\n> + *\n> + * Copyright (C) 2017 ARM Ltd.\n> + *\n> + * This program is free software; you can redistribute it and/or modify\n> + * it under the terms of the GNU General Public License version 2 as\n> + * published by the Free Software Foundation.\n> + *\n> + * This program is distributed in the hope that it will be useful,\n> + * but WITHOUT ANY WARRANTY; without even the implied warranty of\n> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n> + * GNU General Public License for more details.\n> + *\n> + * You should have received a copy of the GNU General Public License\n> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n> + */\n> +\n> +#include <linux/linkage.h>\n> +\n> +#include <asm/alternative.h>\n> +#include <asm/asm-offsets.h>\n> +#include <asm/assembler.h>\n> +#include <asm/memory.h>\n> +#include <asm/ptrace.h>\n> +#include <asm/sdei.h>\n> +#include <uapi/linux/sdei.h>\n> +\n> +/*\n> + * Software Delegated Exception entry point.\n> + *\n> + * x0: Event number\n\nCurrently the only event number is 0. Shall we plan for having other\nevents in the future or we just ignore this argument?\n\n> + * x1: struct sdei_registered_event argument from registration time.\n> + * x2: interrupted PC\n> + * x3: interrupted PSTATE\n[...]\n> +/*\n> + * __sdei_handler() returns one of:\n> + *  SDEI_EV_HANDLED -  success, return to the interrupted context.\n> + *  SDEI_EV_FAILED  -  failure, return this error code to firmare.\n> + *  virtual-address -  success, return to this address.\n> + */\n> +static __kprobes unsigned long _sdei_handler(struct pt_regs *regs,\n> +\t\t\t\t\t     struct sdei_registered_event *arg)\n> +{\n> +\tu32 mode;\n> +\tint i, err = 0;\n> +\tint clobbered_registers = 4;\n\nMaybe const int here if you want to avoid magic numbers in the 'for'\nloop below. Otherwise it looks like some variable you intend to modify\nin this function.\n\n> +\tu64 elr = read_sysreg(elr_el1);\n> +\tu32 kernel_mode = read_sysreg(CurrentEL) | 1;\t/* +SPSel */\n> +\tunsigned long vbar = read_sysreg(vbar_el1);\n> +\n> +\t/* Retrieve the missing registers values */\n> +\tfor (i = 0; i < clobbered_registers; i++) {\n> +\t\t/* from within the handler, this call always succeeds */\n> +\t\tsdei_api_event_context(i, &regs->regs[i]);\n> +\t}\n> +\n> +\t/*\n> +\t * We didn't take an exception to get here, set PAN. UAO will be cleared\n> +\t * by sdei_event_handler()s set_fs(USER_DS) call.\n> +\t */\n> +\tasm(ALTERNATIVE(\"nop\", SET_PSTATE_PAN(1), ARM64_HAS_PAN,\n> +\t\t\tCONFIG_ARM64_PAN));\n\nCan you use uaccess_disable() directly?\n\n> diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig\n> index d8a9859f6102..1f6633b337aa 100644\n> --- a/drivers/firmware/Kconfig\n> +++ b/drivers/firmware/Kconfig\n> @@ -50,6 +50,7 @@ config ARM_SCPI_POWER_DOMAIN\n>  \n>  config ARM_SDE_INTERFACE\n>  \tbool \"ARM Software Delegated Exception Interface (SDEI)\"\n> +\tdepends on ARM64\n>  \thelp\n>  \t  The Software Delegated Exception Interface (SDEI) is an ARM\n>  \t  standard for registering callbacks from the platform firmware\n> diff --git a/drivers/firmware/arm_sdei.c b/drivers/firmware/arm_sdei.c\n> index 4b3c7fd99c34..3ea6a19ae439 100644\n> --- a/drivers/firmware/arm_sdei.c\n> +++ b/drivers/firmware/arm_sdei.c\n> @@ -154,6 +154,7 @@ int sdei_api_event_context(u32 query, u64 *result)\n>  \treturn invoke_sdei_fn(SDEI_1_0_FN_SDEI_EVENT_CONTEXT, query, 0, 0, 0, 0,\n>  \t\t\t      result);\n>  }\n> +NOKPROBE_SYMBOL(sdei_api_event_context);\n\nShould this be part of the patch introducing arm_sdei.c?\n\n>  \n>  static int sdei_api_event_get_info(u32 event, u32 info, u64 *result)\n>  {\n> diff --git a/include/linux/sdei.h b/include/linux/sdei.h\n> index bb3dd000771e..df3fe6373e32 100644\n> --- a/include/linux/sdei.h\n> +++ b/include/linux/sdei.h\n> @@ -32,6 +32,8 @@ enum sdei_conduit_types {\n>  \tCONDUIT_HVC,\n>  };\n>  \n> +#include <asm/sdei.h>\n> +\n>  /* Arch code should override this to set the entry point from firmware... */\n>  #ifndef sdei_arch_get_entry_point\n>  #define sdei_arch_get_entry_point(conduit)\t(0)\n\nSame here. This should not be built before the Kconfig change anyway.","headers":{"Return-Path":"<devicetree-owner@vger.kernel.org>","X-Original-To":"incoming-dt@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming-dt@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=devicetree-owner@vger.kernel.org; receiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3yFzy243cJz9t3Z\n\tfor <incoming-dt@patchwork.ozlabs.org>;\n\tTue, 17 Oct 2017 00:41:46 +1100 (AEDT)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1752275AbdJPNlp (ORCPT\n\t<rfc822;incoming-dt@patchwork.ozlabs.org>);\n\tMon, 16 Oct 2017 09:41:45 -0400","from foss.arm.com ([217.140.101.70]:57228 \"EHLO foss.arm.com\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1751964AbdJPNlo (ORCPT <rfc822;devicetree@vger.kernel.org>);\n\tMon, 16 Oct 2017 09:41:44 -0400","from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249])\n\tby usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5DC4D1529;\n\tMon, 16 Oct 2017 06:41:44 -0700 (PDT)","from armageddon.cambridge.arm.com (armageddon.cambridge.arm.com\n\t[10.1.206.84])\n\tby usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id\n\t6CEA53F590; Mon, 16 Oct 2017 06:41:42 -0700 (PDT)"],"Date":"Mon, 16 Oct 2017 14:41:39 +0100","From":"Catalin Marinas <catalin.marinas@arm.com>","To":"James Morse <james.morse@arm.com>","Cc":"linux-arm-kernel@lists.infradead.org, Mark Rutland <mark.rutland@arm.com>,\n\tdevicetree@vger.kernel.org,\n\tLorenzo Pieralisi <lorenzo.pieralisi@arm.com>, \n\tMarc Zyngier <marc.zyngier@arm.com>, Will Deacon <will.deacon@arm.com>,\n\tRob Herring <robh+dt@kernel.org>, Loc Ho <lho@apm.com>,\n\tkvmarm@lists.cs.columbia.edu,\n\tChristoffer Dall <christoffer.dall@linaro.org>","Subject":"Re: [PATCH v3 09/13] arm64: kernel: Add arch-specific SDEI entry\n\tcode and CPU masking","Message-ID":"<20171016134139.sqe6xabdson2d5rd@armageddon.cambridge.arm.com>","References":"<20170922182614.27885-1-james.morse@arm.com>\n\t<20170922182614.27885-10-james.morse@arm.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20170922182614.27885-10-james.morse@arm.com>","User-Agent":"NeoMutt/20170113 (1.7.2)","Sender":"devicetree-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<devicetree.vger.kernel.org>","X-Mailing-List":"devicetree@vger.kernel.org"}},{"id":1787447,"web_url":"http://patchwork.ozlabs.org/comment/1787447/","msgid":"<20171016135204.ncz6fzw5gh3gv57c@armageddon.cambridge.arm.com>","list_archive_url":null,"date":"2017-10-16T13:52:05","subject":"Re: [PATCH v3 10/13] firmware: arm_sdei: Add support for CPU and\n\tsystem power states","submitter":{"id":938,"url":"http://patchwork.ozlabs.org/api/people/938/","name":"Catalin Marinas","email":"catalin.marinas@arm.com"},"content":"On Fri, Sep 22, 2017 at 07:26:11PM +0100, James Morse wrote:\n> diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h\n> index f24bfb2b9a2d..466b949474df 100644\n> --- a/include/linux/cpuhotplug.h\n> +++ b/include/linux/cpuhotplug.h\n> @@ -88,6 +88,7 @@ enum cpuhp_state {\n>  \tCPUHP_AP_PERF_XTENSA_STARTING,\n>  \tCPUHP_AP_PERF_METAG_STARTING,\n>  \tCPUHP_AP_MIPS_OP_LOONGSON3_STARTING,\n> +\tCPUHP_AP_SDEI_STARTING,\n\nNitpick: how generic is this as to apply to other architectures?\nProbably not, so shall we prefix this with ARM_?\n\nNot actually a strong preferences but similar question for the\ndefinitions in the sdei.h files (and maybe the filenames themselves).","headers":{"Return-Path":"<devicetree-owner@vger.kernel.org>","X-Original-To":"incoming-dt@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming-dt@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=devicetree-owner@vger.kernel.org; receiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3yG0B32fTQz9t3Z\n\tfor <incoming-dt@patchwork.ozlabs.org>;\n\tTue, 17 Oct 2017 00:52:11 +1100 (AEDT)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1752241AbdJPNwK (ORCPT\n\t<rfc822;incoming-dt@patchwork.ozlabs.org>);\n\tMon, 16 Oct 2017 09:52:10 -0400","from foss.arm.com ([217.140.101.70]:57422 \"EHLO foss.arm.com\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1752133AbdJPNwJ (ORCPT <rfc822;devicetree@vger.kernel.org>);\n\tMon, 16 Oct 2017 09:52:09 -0400","from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249])\n\tby usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 744671529;\n\tMon, 16 Oct 2017 06:52:09 -0700 (PDT)","from armageddon.cambridge.arm.com (armageddon.cambridge.arm.com\n\t[10.1.206.84])\n\tby usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id\n\t858393F590; Mon, 16 Oct 2017 06:52:07 -0700 (PDT)"],"Date":"Mon, 16 Oct 2017 14:52:05 +0100","From":"Catalin Marinas <catalin.marinas@arm.com>","To":"James Morse <james.morse@arm.com>","Cc":"linux-arm-kernel@lists.infradead.org, Mark Rutland <mark.rutland@arm.com>,\n\tdevicetree@vger.kernel.org,\n\tLorenzo Pieralisi <lorenzo.pieralisi@arm.com>, \n\tMarc Zyngier <marc.zyngier@arm.com>, Will Deacon <will.deacon@arm.com>,\n\tRob Herring <robh+dt@kernel.org>, Loc Ho <lho@apm.com>,\n\tkvmarm@lists.cs.columbia.edu,\n\tChristoffer Dall <christoffer.dall@linaro.org>","Subject":"Re: [PATCH v3 10/13] firmware: arm_sdei: Add support for CPU and\n\tsystem power states","Message-ID":"<20171016135204.ncz6fzw5gh3gv57c@armageddon.cambridge.arm.com>","References":"<20170922182614.27885-1-james.morse@arm.com>\n\t<20170922182614.27885-11-james.morse@arm.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20170922182614.27885-11-james.morse@arm.com>","User-Agent":"NeoMutt/20170113 (1.7.2)","Sender":"devicetree-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<devicetree.vger.kernel.org>","X-Mailing-List":"devicetree@vger.kernel.org"}},{"id":1788635,"web_url":"http://patchwork.ozlabs.org/comment/1788635/","msgid":"<59E63105.9080804@arm.com>","list_archive_url":null,"date":"2017-10-17T16:34:13","subject":"Re: [PATCH v3 09/13] arm64: kernel: Add arch-specific SDEI entry\n\tcode and CPU masking","submitter":{"id":66575,"url":"http://patchwork.ozlabs.org/api/people/66575/","name":"James Morse","email":"james.morse@arm.com"},"content":"Hi Catalin,\n\nOn 16/10/17 14:41, Catalin Marinas wrote:\n> On Fri, Sep 22, 2017 at 07:26:10PM +0100, James Morse wrote:\n>> diff --git a/arch/arm64/kernel/sdei-entry.S b/arch/arm64/kernel/sdei-entry.S\n>> new file mode 100644\n>> index 000000000000..cf12f8da0789\n>> --- /dev/null\n>> +++ b/arch/arm64/kernel/sdei-entry.S\n>> @@ -0,0 +1,122 @@\n>> +/*\n>> + * Software Delegated Exception entry point from firmware to the kernel.\n>> + *\n>> + * Copyright (C) 2017 ARM Ltd.\n>> + *\n>> + * This program is free software; you can redistribute it and/or modify\n>> + * it under the terms of the GNU General Public License version 2 as\n>> + * published by the Free Software Foundation.\n>> + *\n>> + * This program is distributed in the hope that it will be useful,\n>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of\n>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n>> + * GNU General Public License for more details.\n>> + *\n>> + * You should have received a copy of the GNU General Public License\n>> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n>> + */\n>> +\n>> +#include <linux/linkage.h>\n>> +\n>> +#include <asm/alternative.h>\n>> +#include <asm/asm-offsets.h>\n>> +#include <asm/assembler.h>\n>> +#include <asm/memory.h>\n>> +#include <asm/ptrace.h>\n>> +#include <asm/sdei.h>\n>> +#include <uapi/linux/sdei.h>\n>> +\n>> +/*\n>> + * Software Delegated Exception entry point.\n>> + *\n>> + * x0: Event number\n> \n> Currently the only event number is 0. Shall we plan for having other\n> events in the future or we just ignore this argument?\n\n'0' is the only event number specified by the SDEI specification. For use with\nRAS the event number is read from the HEST. (and there may me more than one of\nthem).\n\n\n\n>> + * x1: struct sdei_registered_event argument from registration time.\n>> + * x2: interrupted PC\n>> + * x3: interrupted PSTATE\n> [...]\n>> +/*\n>> + * __sdei_handler() returns one of:\n>> + *  SDEI_EV_HANDLED -  success, return to the interrupted context.\n>> + *  SDEI_EV_FAILED  -  failure, return this error code to firmare.\n>> + *  virtual-address -  success, return to this address.\n>> + */\n>> +static __kprobes unsigned long _sdei_handler(struct pt_regs *regs,\n>> +\t\t\t\t\t     struct sdei_registered_event *arg)\n>> +{\n>> +\tu32 mode;\n>> +\tint i, err = 0;\n>> +\tint clobbered_registers = 4;\n\n> Maybe const int here if you want to avoid magic numbers in the 'for'\n> loop below. Otherwise it looks like some variable you intend to modify\n> in this function.\n\nSure.\n\n(this was modified in my various attempts to get this working on non-vhe systems\nwith KVM).\n\n\n>> +\tu64 elr = read_sysreg(elr_el1);\n>> +\tu32 kernel_mode = read_sysreg(CurrentEL) | 1;\t/* +SPSel */\n>> +\tunsigned long vbar = read_sysreg(vbar_el1);\n>> +\n>> +\t/* Retrieve the missing registers values */\n>> +\tfor (i = 0; i < clobbered_registers; i++) {\n>> +\t\t/* from within the handler, this call always succeeds */\n>> +\t\tsdei_api_event_context(i, &regs->regs[i]);\n>> +\t}\n>> +\n>> +\t/*\n>> +\t * We didn't take an exception to get here, set PAN. UAO will be cleared\n>> +\t * by sdei_event_handler()s set_fs(USER_DS) call.\n>> +\t */\n>> +\tasm(ALTERNATIVE(\"nop\", SET_PSTATE_PAN(1), ARM64_HAS_PAN,\n>> +\t\t\tCONFIG_ARM64_PAN));\n\n> Can you use uaccess_disable() directly?\n\nWouldn't this invoke sw-pan's __uaccess_ttbr0_disable():\n> write_sysreg(ttbr, ttbr0_el1);\n\nProbing depends on VHE if booted at EL2, can we guarantee to have PAN (and\ntherefore not-SW-PAN) too?\n\n(otherwise I can add 'depends on !ARM64_SW_TTBR0_PAN' to the Kconfig)\n\n\n>> diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig\n>> index d8a9859f6102..1f6633b337aa 100644\n>> --- a/drivers/firmware/Kconfig\n>> +++ b/drivers/firmware/Kconfig\n>> @@ -50,6 +50,7 @@ config ARM_SCPI_POWER_DOMAIN\n>>  \n>>  config ARM_SDE_INTERFACE\n>>  \tbool \"ARM Software Delegated Exception Interface (SDEI)\"\n>> +\tdepends on ARM64\n>>  \thelp\n>>  \t  The Software Delegated Exception Interface (SDEI) is an ARM\n>>  \t  standard for registering callbacks from the platform firmware\n>> diff --git a/drivers/firmware/arm_sdei.c b/drivers/firmware/arm_sdei.c\n>> index 4b3c7fd99c34..3ea6a19ae439 100644\n>> --- a/drivers/firmware/arm_sdei.c\n>> +++ b/drivers/firmware/arm_sdei.c\n>> @@ -154,6 +154,7 @@ int sdei_api_event_context(u32 query, u64 *result)\n>>  \treturn invoke_sdei_fn(SDEI_1_0_FN_SDEI_EVENT_CONTEXT, query, 0, 0, 0, 0,\n>>  \t\t\t      result);\n>>  }\n>> +NOKPROBE_SYMBOL(sdei_api_event_context);\n\n> Should this be part of the patch introducing arm_sdei.c?\n\nYes.\n\n\n>>  static int sdei_api_event_get_info(u32 event, u32 info, u64 *result)\n>>  {\n>> diff --git a/include/linux/sdei.h b/include/linux/sdei.h\n>> index bb3dd000771e..df3fe6373e32 100644\n>> --- a/include/linux/sdei.h\n>> +++ b/include/linux/sdei.h\n>> @@ -32,6 +32,8 @@ enum sdei_conduit_types {\n>>  \tCONDUIT_HVC,\n>>  };\n>>  \n>> +#include <asm/sdei.h>\n>> +\n>>  /* Arch code should override this to set the entry point from firmware... */\n>>  #ifndef sdei_arch_get_entry_point\n>>  #define sdei_arch_get_entry_point(conduit)\t(0)\n> \n> Same here. This should not be built before the Kconfig change anyway.\n\n(I've been building this on x86 to check I'd not done anything arm64 specific\noutside the arch code...)\n\nSure, I'll move this hunk and the Kconfig create a place holder asm/sdei.h in\nthe earlier patch.\n\n\nThanks,\n\nJames\n\n--\nTo unsubscribe from this list: send the line \"unsubscribe devicetree\" in\nthe body of a message to majordomo@vger.kernel.org\nMore majordomo info at  http://vger.kernel.org/majordomo-info.html","headers":{"Return-Path":"<devicetree-owner@vger.kernel.org>","X-Original-To":"incoming-dt@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming-dt@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=devicetree-owner@vger.kernel.org; receiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3yGgmW4TQyz9t2Z\n\tfor <incoming-dt@patchwork.ozlabs.org>;\n\tWed, 18 Oct 2017 03:35:55 +1100 (AEDT)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1759009AbdJQQfy (ORCPT\n\t<rfc822;incoming-dt@patchwork.ozlabs.org>);\n\tTue, 17 Oct 2017 12:35:54 -0400","from foss.arm.com ([217.140.101.70]:51304 \"EHLO foss.arm.com\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1753784AbdJQQfx (ORCPT <rfc822;devicetree@vger.kernel.org>);\n\tTue, 17 Oct 2017 12:35:53 -0400","from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249])\n\tby usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EA574F;\n\tTue, 17 Oct 2017 09:35:52 -0700 (PDT)","from [10.1.207.55] (melchizedek.cambridge.arm.com [10.1.207.55])\n\tby usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id\n\t28BCF3F590; Tue, 17 Oct 2017 09:35:51 -0700 (PDT)"],"Message-ID":"<59E63105.9080804@arm.com>","Date":"Tue, 17 Oct 2017 17:34:13 +0100","From":"James Morse <james.morse@arm.com>","User-Agent":"Mozilla/5.0 (X11; Linux x86_64;\n\trv:31.0) Gecko/20100101 Icedove/31.6.0","MIME-Version":"1.0","To":"Catalin Marinas <catalin.marinas@arm.com>","CC":"linux-arm-kernel@lists.infradead.org, Mark Rutland <mark.rutland@arm.com>,\n\tdevicetree@vger.kernel.org,\n\tLorenzo Pieralisi <lorenzo.pieralisi@arm.com>, \n\tMarc Zyngier <marc.zyngier@arm.com>, Will Deacon <will.deacon@arm.com>,\n\tRob Herring <robh+dt@kernel.org>, Loc Ho <lho@apm.com>,\n\tkvmarm@lists.cs.columbia.edu,\n\tChristoffer Dall <christoffer.dall@linaro.org>","Subject":"Re: [PATCH v3 09/13] arm64: kernel: Add arch-specific SDEI entry\n\tcode and CPU masking","References":"<20170922182614.27885-1-james.morse@arm.com>\n\t<20170922182614.27885-10-james.morse@arm.com>\n\t<20171016134139.sqe6xabdson2d5rd@armageddon.cambridge.arm.com>","In-Reply-To":"<20171016134139.sqe6xabdson2d5rd@armageddon.cambridge.arm.com>","Content-Type":"text/plain; charset=windows-1252","Content-Transfer-Encoding":"7bit","Sender":"devicetree-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<devicetree.vger.kernel.org>","X-Mailing-List":"devicetree@vger.kernel.org"}},{"id":1788636,"web_url":"http://patchwork.ozlabs.org/comment/1788636/","msgid":"<59E6310E.6080705@arm.com>","list_archive_url":null,"date":"2017-10-17T16:34:22","subject":"Re: [PATCH v3 08/13] arm64: Add vmap_stack header file","submitter":{"id":66575,"url":"http://patchwork.ozlabs.org/api/people/66575/","name":"James Morse","email":"james.morse@arm.com"},"content":"Hi Catalin,\n\nOn 13/10/17 16:42, Catalin Marinas wrote:\n> On Fri, Sep 22, 2017 at 07:26:09PM +0100, James Morse wrote:\n>> diff --git a/arch/arm64/include/asm/vmap_stack.h b/arch/arm64/include/asm/vmap_stack.h\n>> new file mode 100644\n>> index 000000000000..f41d043cac31\n>> --- /dev/null\n>> +++ b/arch/arm64/include/asm/vmap_stack.h\n>> @@ -0,0 +1,41 @@\n\n>> +#ifndef __ASM_VMAP_STACK_H\n>> +#define __ASM_VMAP_STACK_H\n>> +\n>> +#include <linux/vmalloc.h>\n>> +#include <asm/memory.h>\n>> +#include <asm/pgtable.h>\n>> +#include <asm/thread_info.h>\n>> +\n>> +#ifdef CONFIG_VMAP_STACK\n>> +/*\n>> + * To ensure that VMAP'd stack overflow detection works correctly, all VMAP'd\n>> + * stacks need to have the same alignment.\n>> + */\n>> +static inline unsigned long *arch_alloc_vmap_stack(size_t stack_size, int node)\n>> +{\n>> +\treturn __vmalloc_node_range(stack_size, THREAD_ALIGN,\n>> +\t\t\t\t    VMALLOC_START, VMALLOC_END,\n>> +\t\t\t\t    THREADINFO_GFP, PAGE_KERNEL, 0, node,\n>> +\t\t\t\t    __builtin_return_address(0));\n>> +}\n>> +\n>> +#else\n>> +unsigned long *arch_alloc_vmap_stack(size_t stack_size, int node); // link error\n\n> Do you actually need this here? The calling site (at least in this\n> patch), is surrounded by CONFIG_VMAP_STACK. Removing the dummy\n> declaration should be fine (I haven't read the rest of the patches yet,\n> maybe it's needed later;\n\nThis was to avoid having to #ifdef the calling site I add in a later patch.\n\n\n> would a BUILD_BUG do?).\n\nAh, you can put those in header files, yes that would be clearer.\n\n\nThanks,\n\nJames\n\n\n\n\n\n--\nTo unsubscribe from this list: send the line \"unsubscribe devicetree\" in\nthe body of a message to majordomo@vger.kernel.org\nMore majordomo info at  http://vger.kernel.org/majordomo-info.html","headers":{"Return-Path":"<devicetree-owner@vger.kernel.org>","X-Original-To":"incoming-dt@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming-dt@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=devicetree-owner@vger.kernel.org; receiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3yGgmg2852z9t2Z\n\tfor <incoming-dt@patchwork.ozlabs.org>;\n\tWed, 18 Oct 2017 03:36:03 +1100 (AEDT)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1759075AbdJQQgC (ORCPT\n\t<rfc822;incoming-dt@patchwork.ozlabs.org>);\n\tTue, 17 Oct 2017 12:36:02 -0400","from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:51330 \"EHLO\n\tfoss.arm.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1759052AbdJQQgC (ORCPT <rfc822;devicetree@vger.kernel.org>);\n\tTue, 17 Oct 2017 12:36:02 -0400","from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249])\n\tby usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DE8A41529;\n\tTue, 17 Oct 2017 09:36:01 -0700 (PDT)","from [10.1.207.55] (melchizedek.cambridge.arm.com [10.1.207.55])\n\tby usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id\n\t117C43F590; Tue, 17 Oct 2017 09:35:59 -0700 (PDT)"],"Message-ID":"<59E6310E.6080705@arm.com>","Date":"Tue, 17 Oct 2017 17:34:22 +0100","From":"James Morse <james.morse@arm.com>","User-Agent":"Mozilla/5.0 (X11; Linux x86_64;\n\trv:31.0) Gecko/20100101 Icedove/31.6.0","MIME-Version":"1.0","To":"Catalin Marinas <catalin.marinas@arm.com>","CC":"linux-arm-kernel@lists.infradead.org, Mark Rutland <mark.rutland@arm.com>,\n\tdevicetree@vger.kernel.org,\n\tLorenzo Pieralisi <lorenzo.pieralisi@arm.com>, \n\tMarc Zyngier <marc.zyngier@arm.com>, Will Deacon <will.deacon@arm.com>,\n\tRob Herring <robh+dt@kernel.org>, Loc Ho <lho@apm.com>,\n\tkvmarm@lists.cs.columbia.edu,\n\tChristoffer Dall <christoffer.dall@linaro.org>","Subject":"Re: [PATCH v3 08/13] arm64: Add vmap_stack header file","References":"<20170922182614.27885-1-james.morse@arm.com>\n\t<20170922182614.27885-9-james.morse@arm.com>\n\t<20171013154226.xswo4y2viht22wvk@armageddon.cambridge.arm.com>","In-Reply-To":"<20171013154226.xswo4y2viht22wvk@armageddon.cambridge.arm.com>","Content-Type":"text/plain; charset=windows-1252","Content-Transfer-Encoding":"7bit","Sender":"devicetree-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<devicetree.vger.kernel.org>","X-Mailing-List":"devicetree@vger.kernel.org"}},{"id":1788637,"web_url":"http://patchwork.ozlabs.org/comment/1788637/","msgid":"<59E6311E.7030406@arm.com>","list_archive_url":null,"date":"2017-10-17T16:34:38","subject":"Re: [PATCH v3 10/13] firmware: arm_sdei: Add support for CPU and\n\tsystem power states","submitter":{"id":66575,"url":"http://patchwork.ozlabs.org/api/people/66575/","name":"James Morse","email":"james.morse@arm.com"},"content":"Hi Catalin,\n\nOn 16/10/17 14:52, Catalin Marinas wrote:\n> On Fri, Sep 22, 2017 at 07:26:11PM +0100, James Morse wrote:\n>> diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h\n>> index f24bfb2b9a2d..466b949474df 100644\n>> --- a/include/linux/cpuhotplug.h\n>> +++ b/include/linux/cpuhotplug.h\n>> @@ -88,6 +88,7 @@ enum cpuhp_state {\n>>  \tCPUHP_AP_PERF_XTENSA_STARTING,\n>>  \tCPUHP_AP_PERF_METAG_STARTING,\n>>  \tCPUHP_AP_MIPS_OP_LOONGSON3_STARTING,\n>> +\tCPUHP_AP_SDEI_STARTING,\n> \n> Nitpick: how generic is this as to apply to other architectures?\n> Probably not, so shall we prefix this with ARM_?\n\nThis may get used on 32bit ARM. I blindly copied PSCI, which doesn't have a\nprefix. But it makes sense to have one.\n\n\n> Not actually a strong preferences but similar question for the\n> definitions in the sdei.h files (and maybe the filenames themselves).\n\n\nThanks,\n\nJames\n--\nTo unsubscribe from this list: send the line \"unsubscribe devicetree\" in\nthe body of a message to majordomo@vger.kernel.org\nMore majordomo info at  http://vger.kernel.org/majordomo-info.html","headers":{"Return-Path":"<devicetree-owner@vger.kernel.org>","X-Original-To":"incoming-dt@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming-dt@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=devicetree-owner@vger.kernel.org; receiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3yGgmz2m6pz9t2Q\n\tfor <incoming-dt@patchwork.ozlabs.org>;\n\tWed, 18 Oct 2017 03:36:19 +1100 (AEDT)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1759084AbdJQQgS (ORCPT\n\t<rfc822;incoming-dt@patchwork.ozlabs.org>);\n\tTue, 17 Oct 2017 12:36:18 -0400","from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:51336 \"EHLO\n\tfoss.arm.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1759065AbdJQQgS (ORCPT <rfc822;devicetree@vger.kernel.org>);\n\tTue, 17 Oct 2017 12:36:18 -0400","from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249])\n\tby usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0453CF;\n\tTue, 17 Oct 2017 09:36:18 -0700 (PDT)","from [10.1.207.55] (melchizedek.cambridge.arm.com [10.1.207.55])\n\tby usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id\n\t38C993F590; Tue, 17 Oct 2017 09:36:16 -0700 (PDT)"],"Message-ID":"<59E6311E.7030406@arm.com>","Date":"Tue, 17 Oct 2017 17:34:38 +0100","From":"James Morse <james.morse@arm.com>","User-Agent":"Mozilla/5.0 (X11; Linux x86_64;\n\trv:31.0) Gecko/20100101 Icedove/31.6.0","MIME-Version":"1.0","To":"Catalin Marinas <catalin.marinas@arm.com>","CC":"linux-arm-kernel@lists.infradead.org, Mark Rutland <mark.rutland@arm.com>,\n\tdevicetree@vger.kernel.org,\n\tLorenzo Pieralisi <lorenzo.pieralisi@arm.com>, \n\tMarc Zyngier <marc.zyngier@arm.com>, Will Deacon <will.deacon@arm.com>,\n\tRob Herring <robh+dt@kernel.org>, Loc Ho <lho@apm.com>,\n\tkvmarm@lists.cs.columbia.edu,\n\tChristoffer Dall <christoffer.dall@linaro.org>","Subject":"Re: [PATCH v3 10/13] firmware: arm_sdei: Add support for CPU and\n\tsystem power states","References":"<20170922182614.27885-1-james.morse@arm.com>\n\t<20170922182614.27885-11-james.morse@arm.com>\n\t<20171016135204.ncz6fzw5gh3gv57c@armageddon.cambridge.arm.com>","In-Reply-To":"<20171016135204.ncz6fzw5gh3gv57c@armageddon.cambridge.arm.com>","Content-Type":"text/plain; charset=windows-1252","Content-Transfer-Encoding":"7bit","Sender":"devicetree-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<devicetree.vger.kernel.org>","X-Mailing-List":"devicetree@vger.kernel.org"}},{"id":1788641,"web_url":"http://patchwork.ozlabs.org/comment/1788641/","msgid":"<59E63186.4010005@arm.com>","list_archive_url":null,"date":"2017-10-17T16:36:22","subject":"Re: [PATCH v3 04/13] arm64: alternatives: use tpidr_el2 on VHE hosts","submitter":{"id":66575,"url":"http://patchwork.ozlabs.org/api/people/66575/","name":"James Morse","email":"james.morse@arm.com"},"content":"Hi Catalin,\n\nOn 16/10/17 10:58, Catalin Marinas wrote:\n> On Fri, Oct 13, 2017 at 05:50:45PM +0100, James Morse wrote:\n>> On 13/10/17 16:31, Catalin Marinas wrote:\n>>> On Fri, Sep 22, 2017 at 07:26:05PM +0100, James Morse wrote:\n>>>> diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c\n>>>> index cd52d365d1f0..8e4c7da2b126 100644\n>>>> --- a/arch/arm64/kernel/cpufeature.c\n>>>> +++ b/arch/arm64/kernel/cpufeature.c\n>>\n>>>> @@ -1308,3 +1309,25 @@ static int __init enable_mrs_emulation(void)\n>>>>  }\n>>>>  \n>>>>  late_initcall(enable_mrs_emulation);\n>>>> +\n>>>> +int cpu_copy_el2regs(void *__unused)\n>>>> +{\n>>>> +\tint do_copyregs = 0;\n>>>> +\n>>>> +\t/*\n>>>> +\t * Copy register values that aren't redirected by hardware.\n>>>> +\t *\n>>>> +\t * Before code patching, we only set tpidr_el1, all CPUs need to copy\n>>>> +\t * this value to tpidr_el2 before we patch the code. Once we've done\n>>>> +\t * that, freshly-onlined CPUs will set tpidr_el2, so we don't need to\n>>>> +\t * do anything here.\n>>>> +\t */\n>>>> +\tasm volatile(ALTERNATIVE(\"mov %0, #1\", \"mov %0, #0\",\n>>>> +\t\t\t\t ARM64_HAS_VIRT_HOST_EXTN)\n>>>> +\t\t    : \"=r\" (do_copyregs) : : );\n>>>\n>>> Can you just do:\n>>>\n>>> \tif (cpu_have_const_cap(ARM64_HAS_VIRT_HOST_EXTN))\n>>> \t\twrite_sysreg(read_sysreg(tpidr_el1), tpidr_el2);\n>>>\n>>> At this point the capability bits should be set and the jump labels\n>>> enabled.\n>>\n>> These are enabled too early, we haven't done patching yet.\n>>\n>> We need to copy tpidr_el1 -> tpidr_el2 on all CPUs that are online before code\n>> patching.\n>>\n>> After code patching new CPUs set tpidr_el2 when they come online, so we don't\n>> need to do the copy... but this enable method is still called. There is nothing\n>> for us to do, and tpidr_el1 now contains junk, so the copy\n\n> Ah, I get it now (should've read the comment but I usually expect the\n> code to be obvious; it wasn't, at least to me, in this case ;)).\n\n> You could have added the sysreg copying directly in the asm volatile.\n\nI was trying to stick to the sysreg C accessors, and thought there would be more\nregisters that needed copying. (I discovered this VHE doesn't remap all the _ELx\nregisters quite late.)\n\n\n> Anyway, I think it's better if we keep it entirely in C with this hunk\n> (untested):\n\n[...]\n\nYes, that looks much better. I got tangled up in 'which alternative', but you're\nright, they are all applied in one go so it doesn't matter.\n\n\n>\tif (!READ_ONCE(alternatives_applied))\n> \t\twrite_sysreg(read_sysreg(tpidr_el1), tpidr_el2);\n\nI don't think this READ_ONCE() is needed, that only matters within the\nstop_machine()/alternatives-patching code that modifies the value on one CPU.\n\n\nThanks,\n\nJames\n\n--\nTo unsubscribe from this list: send the line \"unsubscribe devicetree\" in\nthe body of a message to majordomo@vger.kernel.org\nMore majordomo info at  http://vger.kernel.org/majordomo-info.html","headers":{"Return-Path":"<devicetree-owner@vger.kernel.org>","X-Original-To":"incoming-dt@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming-dt@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=devicetree-owner@vger.kernel.org; receiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3yGgpz1L9yz9t2Z\n\tfor <incoming-dt@patchwork.ozlabs.org>;\n\tWed, 18 Oct 2017 03:38:03 +1100 (AEDT)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S932519AbdJQQiC (ORCPT <rfc822; incoming-dt@patchwork.ozlabs.org>);\n\tTue, 17 Oct 2017 12:38:02 -0400","from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:51424 \"EHLO\n\tfoss.arm.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S932503AbdJQQiB (ORCPT <rfc822;devicetree@vger.kernel.org>);\n\tTue, 17 Oct 2017 12:38:01 -0400","from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249])\n\tby usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A1523F;\n\tTue, 17 Oct 2017 09:38:01 -0700 (PDT)","from [10.1.207.55] (melchizedek.cambridge.arm.com [10.1.207.55])\n\tby usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id\n\tD4F8C3F590; Tue, 17 Oct 2017 09:37:59 -0700 (PDT)"],"Message-ID":"<59E63186.4010005@arm.com>","Date":"Tue, 17 Oct 2017 17:36:22 +0100","From":"James Morse <james.morse@arm.com>","User-Agent":"Mozilla/5.0 (X11; Linux x86_64;\n\trv:31.0) Gecko/20100101 Icedove/31.6.0","MIME-Version":"1.0","To":"Catalin Marinas <catalin.marinas@arm.com>","CC":"Mark Rutland <mark.rutland@arm.com>, devicetree@vger.kernel.org,\n\tLorenzo Pieralisi <lorenzo.pieralisi@arm.com>,\n\tMarc Zyngier <marc.zyngier@arm.com>, Will Deacon <will.deacon@arm.com>,\n\tChristoffer Dall <christoffer.dall@linaro.org>,\n\tRob Herring <robh+dt@kernel.org>, Loc Ho <lho@apm.com>,\n\tkvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org","Subject":"Re: [PATCH v3 04/13] arm64: alternatives: use tpidr_el2 on VHE hosts","References":"<20170922182614.27885-1-james.morse@arm.com>\n\t<20170922182614.27885-5-james.morse@arm.com>\n\t<20171013153148.dnejsvhxeui6opfw@armageddon.cambridge.arm.com>\n\t<59E0EEE5.2020208@arm.com>\n\t<20171016095845.htg2g4jkyw3nvzub@armageddon.cambridge.arm.com>","In-Reply-To":"<20171016095845.htg2g4jkyw3nvzub@armageddon.cambridge.arm.com>","Content-Type":"text/plain; charset=windows-1252","Content-Transfer-Encoding":"7bit","Sender":"devicetree-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<devicetree.vger.kernel.org>","X-Mailing-List":"devicetree@vger.kernel.org"}},{"id":1789363,"web_url":"http://patchwork.ozlabs.org/comment/1789363/","msgid":"<20171018105422.53lnvivuq37e2oy4@armageddon.cambridge.arm.com>","list_archive_url":null,"date":"2017-10-18T10:54:23","subject":"Re: [PATCH v3 09/13] arm64: kernel: Add arch-specific SDEI entry\n\tcode and CPU masking","submitter":{"id":938,"url":"http://patchwork.ozlabs.org/api/people/938/","name":"Catalin Marinas","email":"catalin.marinas@arm.com"},"content":"On Tue, Oct 17, 2017 at 05:34:13PM +0100, James Morse wrote:\n> On 16/10/17 14:41, Catalin Marinas wrote:\n> > On Fri, Sep 22, 2017 at 07:26:10PM +0100, James Morse wrote:\n> >> +\tu64 elr = read_sysreg(elr_el1);\n> >> +\tu32 kernel_mode = read_sysreg(CurrentEL) | 1;\t/* +SPSel */\n> >> +\tunsigned long vbar = read_sysreg(vbar_el1);\n> >> +\n> >> +\t/* Retrieve the missing registers values */\n> >> +\tfor (i = 0; i < clobbered_registers; i++) {\n> >> +\t\t/* from within the handler, this call always succeeds */\n> >> +\t\tsdei_api_event_context(i, &regs->regs[i]);\n> >> +\t}\n> >> +\n> >> +\t/*\n> >> +\t * We didn't take an exception to get here, set PAN. UAO will be cleared\n> >> +\t * by sdei_event_handler()s set_fs(USER_DS) call.\n> >> +\t */\n> >> +\tasm(ALTERNATIVE(\"nop\", SET_PSTATE_PAN(1), ARM64_HAS_PAN,\n> >> +\t\t\tCONFIG_ARM64_PAN));\n> \n> > Can you use uaccess_disable() directly?\n> \n> Wouldn't this invoke sw-pan's __uaccess_ttbr0_disable():\n> > write_sysreg(ttbr, ttbr0_el1);\n> \n> Probing depends on VHE if booted at EL2, can we guarantee to have PAN (and\n> therefore not-SW-PAN) too?\n> \n> (otherwise I can add 'depends on !ARM64_SW_TTBR0_PAN' to the Kconfig)\n\nWe want the Kconfig to be able to include all features. What you can do\nthough is:\n\n\tselect ARM64_PAN if ARM64_SW_TTBR0_PAN\n\nWith VHE (ARMv8.2) we can guarantee that hardware PAN is around.","headers":{"Return-Path":"<devicetree-owner@vger.kernel.org>","X-Original-To":"incoming-dt@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming-dt@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=devicetree-owner@vger.kernel.org; receiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3yH8851PSPz9t3Z\n\tfor <incoming-dt@patchwork.ozlabs.org>;\n\tWed, 18 Oct 2017 21:54:29 +1100 (AEDT)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1751422AbdJRKy2 (ORCPT\n\t<rfc822;incoming-dt@patchwork.ozlabs.org>);\n\tWed, 18 Oct 2017 06:54:28 -0400","from foss.arm.com ([217.140.101.70]:37684 \"EHLO foss.arm.com\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1751088AbdJRKy1 (ORCPT <rfc822;devicetree@vger.kernel.org>);\n\tWed, 18 Oct 2017 06:54:27 -0400","from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249])\n\tby usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8BF8C1435;\n\tWed, 18 Oct 2017 03:54:27 -0700 (PDT)","from armageddon.cambridge.arm.com (armageddon.cambridge.arm.com\n\t[10.1.206.84])\n\tby usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id\n\t9B8A33F25D; Wed, 18 Oct 2017 03:54:25 -0700 (PDT)"],"Date":"Wed, 18 Oct 2017 11:54:23 +0100","From":"Catalin Marinas <catalin.marinas@arm.com>","To":"James Morse <james.morse@arm.com>","Cc":"Mark Rutland <mark.rutland@arm.com>, devicetree@vger.kernel.org,\n\tLorenzo Pieralisi <lorenzo.pieralisi@arm.com>,\n\tMarc Zyngier <marc.zyngier@arm.com>, Will Deacon <will.deacon@arm.com>,\n\tChristoffer Dall <christoffer.dall@linaro.org>,\n\tRob Herring <robh+dt@kernel.org>, Loc Ho <lho@apm.com>,\n\tkvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org","Subject":"Re: [PATCH v3 09/13] arm64: kernel: Add arch-specific SDEI entry\n\tcode and CPU masking","Message-ID":"<20171018105422.53lnvivuq37e2oy4@armageddon.cambridge.arm.com>","References":"<20170922182614.27885-1-james.morse@arm.com>\n\t<20170922182614.27885-10-james.morse@arm.com>\n\t<20171016134139.sqe6xabdson2d5rd@armageddon.cambridge.arm.com>\n\t<59E63105.9080804@arm.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<59E63105.9080804@arm.com>","User-Agent":"NeoMutt/20170113 (1.7.2)","Sender":"devicetree-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<devicetree.vger.kernel.org>","X-Mailing-List":"devicetree@vger.kernel.org"}}]