|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [RFC 10/16] xen/arm: Introduce alternative runtime patching
Hi Konrad, On 13/05/2016 21:26, Konrad Rzeszutek Wilk wrote: On Thu, May 05, 2016 at 05:34:19PM +0100, Julien Grall wrote:Some of the processor erratum will require to modify code sequence. As those modifications may impact the performance, they should only be enabled on affected cores. Furthermore, Xen may also want to take advantage of new hardware features coming up with v8.1 and v8.2. This patch adds an infrastructure to patch Xen during boot time depending on the "features" available on the platform. This code is based on the file arch/arm64/kernel/alternative.c in Linux 4.6-rc3. Any references to arm64 have been dropped to make the code as generic as possible. Furthermore, in Xen the executable sections (.text and .init.text) are always mapped read-only and enforced by SCTLR.WNX. So it is not possible to directly patch Xen.Is it not possible to temporarily 'unenforce' the SCTLR.WNX? The problem is not because of SCTLR.WNX but because the entries are change from read-write to read-only afterwards. The ARM ARM (see D4-1732 in ARM DDI 0487A.i) recommends the use of break-before-make if either the old or new entry is writable when the page table is shared between multiples processor. This is to avoid possible TLB conflicts on platform have aggressive prefetcher. The break-before-make approach requires the following steps: - Replacing the old entry with an invalid entry - Invalidate the entry by flush the TLBs - Write the new entryHowever, with the current approach, secondary CPUs runs at the same, so even with the break-before-make approach it might be possible to hit a data abort if the CPU execute code on an entry that is currently been changed. It would be possible to make the CPUs spinning outside of the executable, but I think this make the code more complicate. Note that you would have the same issue with XSplice. You may wonder why Xen is patched when all the CPUs are online. This is because in big.LITTLE environment, big and little cores will have different errata. The only way to know the list of errata is to probe each CPU, and therefore bring them up. I hope this gives you more insights on why I choose this approach. I can update the commit message with it.
Right, I will change in the next version.
Ok. + endmenu source "common/Kconfig" diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 9122f78..2d330aa 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -4,6 +4,7 @@ subdir-y += platforms subdir-$(CONFIG_ARM_64) += efi subdir-$(CONFIG_ACPI) += acpi +obj-$(CONFIG_ALTERNATIVE) += alternative.oThis probably needs to be alternative.init.o ?obj-y += bootfdt.o obj-y += cpu.o obj-y += cpufeature.o diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c new file mode 100644 index 0000000..0a5d1c8 --- /dev/null +++ b/xen/arch/arm/alternative.c @@ -0,0 +1,217 @@ +/* + * alternative runtime patching + * inspired by the x86 version + * + * Copyright (C) 2014 ARM Ltd.Not 2016? The code has been taken from Linux. I was not sure what to do here. I will update with 2014-2016. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <xen/config.h> +#include <xen/init.h> +#include <xen/types.h> +#include <xen/kernel.h> +#include <xen/mm.h> +#include <xen/vmap.h> +#include <xen/smp.h> +#include <xen/stop_machine.h> +#include <asm/alternative.h> +#include <asm/atomic.h> +#include <asm/byteorder.h> +#include <asm/cpufeature.h> +#include <asm/insn.h> +#include <asm/page.h> + +#define __ALT_PTR(a,f) (u32 *)((void *)&(a)->f + (a)->f) +#define ALT_ORIG_PTR(a) __ALT_PTR(a, orig_offset) +#define ALT_REPL_PTR(a) __ALT_PTR(a, alt_offset) + +extern const struct alt_instr __alt_instructions[], __alt_instructions_end[]; + +struct alt_region { + const struct alt_instr *begin; + const struct alt_instr *end; +}; + +/* + * Check if the target PC is within an alternative block. + */ +static bool_t branch_insn_requires_update(const struct alt_instr *alt,__init? No, xSplice will likely contain some alternatives, which Xen will need to apply. I have in mind invasive errata such as the one implemented in patch #13 and #14. Furthermore, new ARMv8.1 features will requires some to add alternatives in spinlock and atomic helpers.
sure.
The 3rd argument of stop_machine_run is the CPU where the callback will be executed. If NR_CPUS is passed, the callback will be executed on all the CPUs. And I am bit confused. The comment says that 'stop_machine' state machine may be patched, but here you use the stop_machine_run which is part of stop_machine?! Yes, hence the callback __apply_alternatives_multi_stop is executed on every online CPUs. CPU0 will patch the code whilst the other will spin until the code has been patched. + + /* stop_machine_run should never fail at this stage of the boot */ + BUG_ON(ret); +} + +int apply_alternatives(void *start, size_t length)const void *start? Could be.
Yes.
See my answer above. Xen needs to know the list of errata that affect each CPU before patching. Regards, -- Julien Grall _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |