From patchwork Thu Aug 24 08:18:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 110885 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp5317871qge; Thu, 24 Aug 2017 01:21:36 -0700 (PDT) X-Received: by 10.98.152.77 with SMTP id q74mr5651855pfd.40.1503562896171; Thu, 24 Aug 2017 01:21:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503562896; cv=none; d=google.com; s=arc-20160816; b=oFiDKF74fk2eOHCCxZPLh+++bGcTtS/zPxrjmDKHNm0rM3b+jVXftDnobov3jtfXSG HBxPpa+IHTxilSrisy9gUQDRHYp0Jhc2OoqYTsdbBzue+fsViXbeYjR38AoxPmZCxKCr F/Z/Zs5ybJt8rpaHYDxmWzyYl8vzLhTO5TyRitjSxJXGTclQwesDoeTNNxttH4O6TOdF 4F6CYQUSjbuGcdOtJ4PcWW6FMqE2Rn4UsK7gokSmJ/d/k1YUews32Pjq9mIF56Flc2ah dvEov8UTGxeSgaP/Pmjse8WByf9PM2PTtjcJ1/clB4hhnIcq0d72XtDrEOyetXtXD4wL 13IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=l/Cr37RnrKeUy/7oVwyiQ7k3V/jjYM1O6XUt3JP3jVg=; b=IA6C9BLvyMbdQiSGnIrZ3aV0cBS9YV5TrIJ9Fowd71nsoy/KmqZ3OCOrNXOKTza1D0 4w7Rrb0Fxuygslb5mcsr3NIm9/F7kDAeKcUmNziPvAoim4oPgvjm4udnKbsrV62gDYAR XiL546wp0qxiXGDUj+Ni3Uk978gsLf3q/AN+1rDiXGp4qfPeS3b985uY3VzQTBnqfqug LFjcKvCHpUfS+MFog3GqmbKjSNOdlZSrJR2uxsQ3wbFtWvoFNDF49SX6xAIaNOUeMjVk rS+QYQ/kLX5HDpneuaZ4cokgHr7ZucGEoS1qyINKE92JkrG1PP+CTbs522qSOQMUhMYE HWEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BkIqPASS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j23si2739677pli.275.2017.08.24.01.21.35; Thu, 24 Aug 2017 01:21:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BkIqPASS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751858AbdHXITM (ORCPT + 26 others); Thu, 24 Aug 2017 04:19:12 -0400 Received: from mail-pg0-f48.google.com ([74.125.83.48]:33838 "EHLO mail-pg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751253AbdHXISg (ORCPT ); Thu, 24 Aug 2017 04:18:36 -0400 Received: by mail-pg0-f48.google.com with SMTP id s14so13470727pgs.1 for ; Thu, 24 Aug 2017 01:18:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=l/Cr37RnrKeUy/7oVwyiQ7k3V/jjYM1O6XUt3JP3jVg=; b=BkIqPASSps5+FI55sagFyNSywIgqshk98g0+zITac8XY+2K1X8fKvrZ1Pe6yHlS8qq XsZ+5zGk5nWSc05fYf0gprP0/s3hHcnjjRc+hcfNeb2fzp6U18sn05RIey4oa8qTPGd5 4lKrjudL4+TFQf+NZwwHeYE4gUEd48snwXwqo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=l/Cr37RnrKeUy/7oVwyiQ7k3V/jjYM1O6XUt3JP3jVg=; b=CpoAYgTocnnPSdnO8OudS9MiyAx1A1eT7oEfvbQhdF2JTTQczAkXxB0jHIGcPNMEs4 oRy1e+x5Oy/F//43kKxhTGsqpsMVDJ7G2RDGMrVFRYKnPbejlbVOlGJEXZOwxById3VZ mylisiNuWlYxsIH1jBjQmwAJIpDn8XTNoUYqkZEpCojUBoSbPmamZXBPg6Rz6She/y+W niMjlPvzX+ZfT0OiqxZZp3p5f+2J1sSSuou+OHu9NtJuyVDPb9AI7dxpe/hSRS6/VsPk 6e+0/b3PPhu0t9ejZGwe+ItTBN7nDKQ7Yn7Djp6+0pyH153tb2mUXxF5txrcQ1Ra5cwQ hHEg== X-Gm-Message-State: AHYfb5jZ0+FzayWSxveqRp16AIoGz+CO84f58Mqxf4kdRYbQDaMoyn1S wtEkNzYBDec/E6Th X-Received: by 10.99.120.200 with SMTP id t191mr5598289pgc.191.1503562715830; Thu, 24 Aug 2017 01:18:35 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id o25sm6481038pfj.117.2017.08.24.01.18.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Aug 2017 01:18:35 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH 06/14] kexec_file: add kexec_add_segment() Date: Thu, 24 Aug 2017 17:18:03 +0900 Message-Id: <20170824081811.19299-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170824081811.19299-1-takahiro.akashi@linaro.org> References: <20170824081811.19299-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In contrast to kexec_add_buffer(), this function assumes that kbuf->mem is already assigned by caller. This type of allocation is commonly used in kexec-tools. This function will be used on arm64 in loading vmlinux(elf) binary. Signed-off-by: AKASHI Takahiro Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- include/linux/kexec.h | 1 + kernel/kexec_file.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) -- 2.14.1 diff --git a/include/linux/kexec.h b/include/linux/kexec.h index acaecd72b134..be5e99afaf77 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -162,6 +162,7 @@ struct kexec_buf { int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, int (*func)(u64, u64, void *)); extern int kexec_add_buffer(struct kexec_buf *kbuf); +extern int kexec_add_segment(struct kexec_buf *kbuf); int kexec_locate_mem_hole(struct kexec_buf *kbuf); #ifdef CONFIG_CRASH_CORE extern int prepare_elf_headers(struct kimage *image, void **addr, diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 9f48f4412297..d898dec37816 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -519,6 +519,53 @@ int kexec_add_buffer(struct kexec_buf *kbuf) return 0; } +/** + * kexec_add_segment - place a buffer in a kexec segment + * @kbuf: Buffer contents and memory parameters. + * + * In contrast to kexec_add_buffer(), this function assumes + * that kbuf->mem is already assigned by caller. + * + * Return: 0 on success, negative errno on error. + */ +int kexec_add_segment(struct kexec_buf *kbuf) +{ + + struct kexec_segment *ksegment; + + /* Currently adding segment this way is allowed only in file mode */ + if (!kbuf->image->file_mode) + return -EINVAL; + + if (kbuf->image->nr_segments >= KEXEC_SEGMENT_MAX) + return -EINVAL; + + /* + * Make sure we are not trying to add buffer after allocating + * control pages. All segments need to be placed first before + * any control pages are allocated. As control page allocation + * logic goes through list of segments to make sure there are + * no destination overlaps. + */ + if (!list_empty(&kbuf->image->control_pages)) { + WARN_ON(1); + return -EINVAL; + } + + /* Ensure minimum alignment needed for segments. */ + kbuf->memsz = ALIGN(kbuf->memsz, PAGE_SIZE); + + /* Found a suitable memory range */ + ksegment = &kbuf->image->segment[kbuf->image->nr_segments]; + ksegment->kbuf = kbuf->buffer; + ksegment->bufsz = kbuf->bufsz; + ksegment->mem = kbuf->mem; + ksegment->memsz = kbuf->memsz; + kbuf->image->nr_segments++; + + return 0; +} + /* Calculate and store the digest of segments */ static int kexec_calculate_store_digests(struct kimage *image) {