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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 E537DC433DB for ; Sat, 23 Jan 2021 02:50:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6061823B6A for ; Sat, 23 Jan 2021 02:50:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6061823B6A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C30906B0005; Fri, 22 Jan 2021 21:50:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BBADA6B0007; Fri, 22 Jan 2021 21:50:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A819B6B0008; Fri, 22 Jan 2021 21:50:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0203.hostedemail.com [216.40.44.203]) by kanga.kvack.org (Postfix) with ESMTP id 8C4E96B0005 for ; Fri, 22 Jan 2021 21:50:36 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 43A373651 for ; Sat, 23 Jan 2021 02:50:36 +0000 (UTC) X-FDA: 77735511672.17.legs48_5808ef927571 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 2AA78180D0184 for ; Sat, 23 Jan 2021 02:50:36 +0000 (UTC) X-HE-Tag: legs48_5808ef927571 X-Filterd-Recvd-Size: 6750 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Sat, 23 Jan 2021 02:50:35 +0000 (UTC) Received: by mail-ej1-f51.google.com with SMTP id gx5so10399473ejb.7 for ; Fri, 22 Jan 2021 18:50:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PPa2PKSw/waauVA8Bx+VsfrrtqVIeZc1qOYap+f8/h8=; b=lutH7D9nJBgo4rbYtUSB6hS+9wfbtY+nEM4MMtgPn44Qrhheaq58MP3jffbYUNQID9 NajApLWOWDmfOGeyKaVnO9OvAnscmk5XUqQP0hrK9vgSeVNNES6YxoSSbKGRchjr5ntA L/2MxKQYSAtIXmsa1DUYNfo/bc9+FjxA7prFCXDZweGvetHM5T/QiGg1cr41Lb8e3GjV xiRp1GWPV01w6+ez8xXyvFvM6tEtR1nBqYAcZh6//lkLm778fmAjr4GDlEXsJ8L5d+Ua Mn+qbazSZTrixLw2ecrQ4kDxuPJNEYvPz3i50NO4rdbC044G5hI7h6SdlN7iCfyWYIni Y1+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PPa2PKSw/waauVA8Bx+VsfrrtqVIeZc1qOYap+f8/h8=; b=nFR65pLqS3Z8zYKcX2qx933mU8J9J58kjNWFk0ag0iFTPnhHxSFuksTKMDIkvmyX4E rUtkLf2pmGpk6XmsJ3I9xEpcJis+qMdlqGD+bhZStX3pxgVwL3Vu2Jh0gaFbVGvKJQ/M CqWYjqiOCxrU2ucVAqRJve1cli9oH3nmOonRcTZtYFqkTgxXNr/NRSEHCQ4Ryfk1zc8f GqOvLcQqBzcRFUdkffHGyW2AT+QyHdzceZmUqOKaICBS582BWcyFwippE7ScnQ3Cw4z0 HKa55/b2m5Squg4alpxKJO7cU6kAA2aMoJbuXWtM1OExGsoMfZFwAfpAxGKnRAwUaXiz Tyww== X-Gm-Message-State: AOAM532W90jQcnGDysvV6+D+jmelR1jP5XtwDc7A12QUqhcIdqM3zQTA FcVJ92iTnah2gz11AhZeuUsv3sbX3CksdipgOfQCBw== X-Google-Smtp-Source: ABdhPJzYbgP11gnR687aBiDmT2sYOj5RkCXjsB8OhUTh383zDdb2dojruAGaljGsy3DoeTHwIarikIOs15J8u56JxZw= X-Received: by 2002:a17:907:96a5:: with SMTP id hd37mr1187066ejc.541.1611370234300; Fri, 22 Jan 2021 18:50:34 -0800 (PST) MIME-Version: 1.0 References: <20200326032420.27220-1-pasha.tatashin@soleen.com> <20200326032420.27220-14-pasha.tatashin@soleen.com> <012e19d9-97d6-805a-bfec-8c6e7104f852@arm.com> In-Reply-To: <012e19d9-97d6-805a-bfec-8c6e7104f852@arm.com> From: Pavel Tatashin Date: Fri, 22 Jan 2021 21:49:58 -0500 Message-ID: Subject: Re: [PATCH v9 13/18] arm64: kexec: add expandable argument to relocation function To: James Morse Cc: James Morris , Sasha Levin , "Eric W. Biederman" , kexec mailing list , LKML , Jonathan Corbet , Catalin Marinas , Will Deacon , Linux ARM , Marc Zyngier , Vladimir Murzin , Matthias Brugger , linux-mm , Mark Rutland , steve.capper@arm.com, rfontana@redhat.com, Thomas Gleixner , Selin Dag Content-Type: text/plain; charset="UTF-8" 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: On Thu, May 7, 2020 at 12:22 PM James Morse wrote: > > 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. Yes, this is a hypervisor abi limitation. I will improve the commit log to state it clearly. > > 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. Thank you for catching this, I added: __flush_dcache_area(kern_reloc_arg, sizeof (struct kern_reloc_arg));