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=-8.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 47D69C433DB for ; Sat, 23 Jan 2021 02:52:09 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 044DF23B6A for ; Sat, 23 Jan 2021 02:52:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 044DF23B6A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8L26AVOikFjltY26+mc3eJu3LKHW4gfAgJ4G5ji5aRA=; b=RgQ+kX6pYkK1qbHJmf3+D89hI WlzOA7me+2OCILhf/QPmyUnDDJ0fRE5RhK0BgH8LydBMhXIrCXYFfXzV5LgCTC2LbaQRMQEM06wwx JPFuqidVwBDOpg6vMLyrRwB00vinmorfW5NK+Yj8tCp2sn8xkVJK6uNVkQLvshDdbMAk/ngFa1VSc hyiNnzyxqpv62UXUv7f+/+125GDNFM43aW3lMyx1/hUOCyxBLZV1z3wd9KMIh07ixPcOTqyLVvPOr 6MJl51palweIBXqqWK7moai0P5YbA7kHNVx9mMlJs/tYwMWZBG9yCeg+t4mEMFwwpqX90+FLoSyu0 bkgipJgsg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l390Z-0008Ij-PB; Sat, 23 Jan 2021 02:50:39 +0000 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l390V-0008Gj-RG for linux-arm-kernel@lists.infradead.org; Sat, 23 Jan 2021 02:50:37 +0000 Received: by mail-ej1-x631.google.com with SMTP id ke15so10367747ejc.12 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=gF8APLRXY7th60ysd71o+gnPyEEoolfMaAKt1jC/b9+tWJxV5DqX1/s9XwRFUxDL4S hRUPy3bk+LX131Ek9B6ZsWI0U54upoLV+3aYZ2spassDYVafv6imLv/I3zIl5Wd50hC/ Uo+QIcyYAhisPpGYoXQ1Ss5/+7UBEVH3iHoZZVG5a41L8cMuY+hA6NKu8q1BEUbBgbTm o0Cd3swMOL2dBH+iyPIAs+lu7RLExMmfgJ/9Tt3nYNFyIfORrezPMY6ve4nNRxNdQJwR VuAK1Gu9nbaltElsqJf8WqEQV512y1Lc4/UFtkNQ/yV+l8Y52pB5nwIqCOvyX56XMtXx QaxA== X-Gm-Message-State: AOAM533/tSGQAaYNgjrN45bmUicCn7RVfczcnly4eD1YMxLJdMTA9DYP 7unYWPybJyE1uBs6L1yR01vQhk2sIahJEqqk7yKR3A== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210122_215036_203989_6B1A0DC6 X-CRM114-Status: GOOD ( 32.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sasha Levin , Mark Rutland , Vladimir Murzin , Jonathan Corbet , Catalin Marinas , Selin Dag , steve.capper@arm.com, kexec mailing list , LKML , James Morris , linux-mm , rfontana@redhat.com, "Eric W. Biederman" , Marc Zyngier , Matthias Brugger , Thomas Gleixner , Will Deacon , Linux ARM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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)); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel