Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1158089ybt; Fri, 26 Jun 2020 23:32:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQOxgukgNv3BTRplU81oLJnZa+SSLR3AF1h6KtxG7U9M+FCEq88k98+HTlv0LShurBeAvG X-Received: by 2002:a17:906:9387:: with SMTP id l7mr5458681ejx.274.1593239521288; Fri, 26 Jun 2020 23:32:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593239521; cv=none; d=google.com; s=arc-20160816; b=nXjObqhVfdm6YYH0ueDdeabaIFbfFqKSeVBmefYEsDQ9Y8TgIcJvJ19nJpzlCZmFfP zslhqzzkEq9mK+1bhehTOrCZmfkiFFgowIkQADLB1PTDTzjukXpi1Ti27CsMNMod3NRb /cp5UrkEaoSivUpChAvfWE7NqnF6TY+Qty9229OEISsYna9T9kQbw5QFZQP3CFvzksG2 gXs/8gGGROxpTWKYBcW1x5cg6xzkslGO67i77Q6hZOXcLDCsYQLlLFNHO3ZjYQGrTI4h ReEnsfbBz9GM+uHirOpN2cUFgYmd/tS++yq5QRSR7exNGUO1/pcFW9yrXS0jI/RTWp2/ SU3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=keOa5E2f+RZ6HO7Q2x56556XnY3nanz3ZR34YhCXQmI=; b=SDVNZuCVmfvP6iAPZnj89AHjKcPeZRmGj+evK1yMwPcbSMYt1eeNjjb3xMcgyRBS79 XiQwpXA9/iKabbpwSoL1UBcNqWeVVYLmLlA/sb2gAQYcljh+Q4wXhO7ON++c6z6koOUy s+xeF5B2kxU46nRmYfS8/3aBNrb2M7JC1Jswym1TiC/Z/I59gbbjMQBM2TtJpK7yghXQ shVZ9i9U/E/OpBTY/42FCyT/ve3O2tO683bzFZGiv2HPTED4EVusnR7Y3EiXA8FwS8lM saxHF/OXxSSJ4LKbMDBWONq+Z8EvMZ1BL2ZtaIoiF6xnS1jPZ45cFZap14G+lHyrtUCx b2Kw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c3si1491633edr.308.2020.06.26.23.31.37; Fri, 26 Jun 2020 23:32:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725980AbgF0Ga0 (ORCPT + 99 others); Sat, 27 Jun 2020 02:30:26 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:63218 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725861AbgF0GaZ (ORCPT ); Sat, 27 Jun 2020 02:30:25 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 49v3ld5TcGz9v021; Sat, 27 Jun 2020 08:30:21 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id tCD-gMIER6eu; Sat, 27 Jun 2020 08:30:21 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 49v3ld3tDjz9v01x; Sat, 27 Jun 2020 08:30:21 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 89E108B772; Sat, 27 Jun 2020 08:30:22 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id XpRoYDrHEWkv; Sat, 27 Jun 2020 08:30:22 +0200 (CEST) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 688C18B75B; Sat, 27 Jun 2020 08:30:21 +0200 (CEST) Subject: Re: [PATCH 01/11] kexec_file: allow archs to handle special regions while locating memory hole To: Hari Bathini , Michael Ellerman , Andrew Morton Cc: Pingfan Liu , Kexec-ml , Petr Tesarik , Mahesh J Salgaonkar , Sourabh Jain , lkml , linuxppc-dev , Mimi Zohar , Vivek Goyal , Dave Young , Thiago Jung Bauermann , Eric Biederman References: <159319825403.16351.7253978047621755765.stgit@hbathini.in.ibm.com> <159319828304.16351.6990340111766605842.stgit@hbathini.in.ibm.com> From: Christophe Leroy Message-ID: <9a976370-caef-1beb-d172-bcb0b17e9b78@csgroup.eu> Date: Sat, 27 Jun 2020 08:30:22 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <159319828304.16351.6990340111766605842.stgit@hbathini.in.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 26/06/2020 à 21:04, Hari Bathini a écrit : > Some archs can have special memory regions, within the given memory > range, which can't be used for the buffer in a kexec segment. As > kexec_add_buffer() function is being called from generic code as well, > add weak arch_kexec_add_buffer definition for archs to override & take > care of special regions before trying to locate a memory hole. > > Signed-off-by: Hari Bathini > --- > include/linux/kexec.h | 5 +++++ > kernel/kexec_file.c | 37 +++++++++++++++++++++++++++++++++---- > 2 files changed, 38 insertions(+), 4 deletions(-) > > diff --git a/include/linux/kexec.h b/include/linux/kexec.h > index 1776eb2..1237682 100644 > --- a/include/linux/kexec.h > +++ b/include/linux/kexec.h > @@ -195,6 +195,11 @@ int __weak arch_kexec_apply_relocations(struct purgatory_info *pi, > const Elf_Shdr *relsec, > const Elf_Shdr *symtab); > > +extern int arch_kexec_add_buffer(struct kexec_buf *kbuf); > + extern keywork is useless here, please remove (checkpatch also complains about it usually). > +/* arch_kexec_add_buffer calls this when it is ready */ > +extern int __kexec_add_buffer(struct kexec_buf *kbuf); > + same > extern int kexec_add_buffer(struct kexec_buf *kbuf); > int kexec_locate_mem_hole(struct kexec_buf *kbuf); > > diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c > index bb05fd5..a0b4f7f 100644 > --- a/kernel/kexec_file.c > +++ b/kernel/kexec_file.c > @@ -669,10 +669,6 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf) > */ > int kexec_add_buffer(struct kexec_buf *kbuf) > { > - > - struct kexec_segment *ksegment; > - int ret; > - > /* Currently adding segment this way is allowed only in file mode */ > if (!kbuf->image->file_mode) > return -EINVAL; > @@ -696,6 +692,25 @@ int kexec_add_buffer(struct kexec_buf *kbuf) > kbuf->memsz = ALIGN(kbuf->memsz, PAGE_SIZE); > kbuf->buf_align = max(kbuf->buf_align, PAGE_SIZE); > > + return arch_kexec_add_buffer(kbuf); > +} > + > +/** > + * __kexec_add_buffer - arch_kexec_add_buffer would call this function after > + * updating kbuf, to place a buffer in a kexec segment. > + * @kbuf: Buffer contents and memory parameters. > + * > + * This function assumes that kexec_mutex is held. > + * On successful return, @kbuf->mem will have the physical address of > + * the buffer in memory. > + * > + * Return: 0 on success, negative errno on error. > + */ > +int __kexec_add_buffer(struct kexec_buf *kbuf) > +{ > + struct kexec_segment *ksegment; > + int ret; > + > /* Walk the RAM ranges and allocate a suitable range for the buffer */ > ret = kexec_locate_mem_hole(kbuf); > if (ret) > @@ -711,6 +726,20 @@ int kexec_add_buffer(struct kexec_buf *kbuf) > return 0; > } > > +/** > + * arch_kexec_add_buffer - Some archs have memory regions within the given > + * range that can't be used to place a kexec segment. > + * Such archs can override this function to take care > + * of them before trying to locate the memory hole. > + * @kbuf: Buffer contents and memory parameters. > + * > + * Return: 0 on success, negative errno on error. > + */ > +int __weak arch_kexec_add_buffer(struct kexec_buf *kbuf) > +{ > + return __kexec_add_buffer(kbuf); > +} > + > /* Calculate and store the digest of segments */ > static int kexec_calculate_store_digests(struct kimage *image) > { > Christophe