From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B55EC38A24 for ; Thu, 7 May 2020 16:22:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2728C2053B for ; Thu, 7 May 2020 16:22:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2728C2053B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C5E67900006; Thu, 7 May 2020 12:22:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C0E4A900002; Thu, 7 May 2020 12:22:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AFC18900006; Thu, 7 May 2020 12:22:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0217.hostedemail.com [216.40.44.217]) by kanga.kvack.org (Postfix) with ESMTP id 98A7C900002 for ; Thu, 7 May 2020 12:22:22 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 5DF7682499B9 for ; Thu, 7 May 2020 16:22:22 +0000 (UTC) X-FDA: 76790440524.04.cave15_4edf4df8a034d X-HE-Tag: cave15_4edf4df8a034d X-Filterd-Recvd-Size: 4783 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Thu, 7 May 2020 16:22:21 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 03F271045; Thu, 7 May 2020 09:22:21 -0700 (PDT) Received: from [192.168.0.14] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 58EBD3F71F; Thu, 7 May 2020 09:22:18 -0700 (PDT) Subject: Re: [PATCH v9 13/18] arm64: kexec: add expandable argument to relocation function To: Pavel Tatashin References: <20200326032420.27220-1-pasha.tatashin@soleen.com> <20200326032420.27220-14-pasha.tatashin@soleen.com> From: James Morse Cc: jmorris@namei.org, sashal@kernel.org, ebiederm@xmission.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, corbet@lwn.net, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, maz@kernel.org, vladimir.murzin@arm.com, matthias.bgg@gmail.com, bhsharma@redhat.com, linux-mm@kvack.org, mark.rutland@arm.com, steve.capper@arm.com, rfontana@redhat.com, tglx@linutronix.de, selindag@gmail.com Message-ID: <012e19d9-97d6-805a-bfec-8c6e7104f852@arm.com> Date: Thu, 7 May 2020 17:22:17 +0100 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20200326032420.27220-14-pasha.tatashin@soleen.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi Pavel, On 26/03/2020 03:24, Pavel Tatashin wrote: > Currently, kexec relocation function (arm64_relocate_new_kernel) accepts > the following arguments: > > head: start of array that contains relocation information. > entry: entry point for new kernel or purgatory. > dtb_mem: first and only argument to entry. > The number of arguments cannot be easily expended, because this > function is also called from HVC_SOFT_RESTART, which preserves only > three arguments. And, also arm64_relocate_new_kernel is written in > assembly but called without stack, thus no place to move extra > arguments to free registers. > > Soon, we will need to pass more arguments: once we enable MMU we > will need to pass information about page tables. > Another benefit of allowing this function to accept more arguments, is that > kernel can actually accept up to 4 arguments (x0-x3), however currently > only one is used, but if in the future we will need for more (for example, > pass information about when previous kernel exited to have a precise > measurement in time spent in purgatory), we won't be easilty do that > if arm64_relocate_new_kernel can't accept more arguments. This is a niche debug hack. We really don't want an ABI with purgatory. I think the register values it gets were added early for compatibility with kexec_file_load(). > So, add a new struct: kern_reloc_arg, and place it in kexec safe page (i.e > memory that is not overwritten during relocation). > Thus, make arm64_relocate_new_kernel to only take one argument, that > contains all the needed information. Do we really not have enough registers? The PCS[0] gives you 8 arguments. In this patch you use 6. If this is really about the hyp-stub abi, please state that. > diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c > index cee3be586384..b1122eea627e 100644 > --- a/arch/arm64/kernel/machine_kexec.c > +++ b/arch/arm64/kernel/machine_kexec.c > @@ -59,13 +60,35 @@ void machine_kexec_cleanup(struct kimage *kimage) > int machine_kexec_post_load(struct kimage *kimage) > { > void *reloc_code = page_to_virt(kimage->control_code_page); > + struct kern_reloc_arg *kern_reloc_arg = kexec_page_alloc(kimage); > + > + if (!kern_reloc_arg) > + return -ENOMEM; > > memcpy(reloc_code, arm64_relocate_new_kernel, > arm64_relocate_new_kernel_size); > kimage->arch.kern_reloc = __pa(reloc_code); > + kimage->arch.kern_reloc_arg = __pa(kern_reloc_arg); > + kern_reloc_arg->head = kimage->head; > + kern_reloc_arg->entry_addr = kimage->start; > + kern_reloc_arg->kern_arg0 = kimage->arch.dtb_mem; These kern_reloc_arg values are written via the cacheable linear map. They are read in arm64_relocate_new_kernel() where the MMU is disabled an all memory access are non-cacheable. To ensure you read the values you wrote, you must clean kern_reloc_arg to the PoC. > kexec_image_info(kimage); > > return 0;Thanks, James [0] https://developer.arm.com/docs/ihi0055/d/procedure-call-standard-for-the-arm-64-bit-architecture