From patchwork Mon Jul 8 21:15:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 11035797 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3C48314E5 for ; Mon, 8 Jul 2019 21:16:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29C7D2837D for ; Mon, 8 Jul 2019 21:16:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B3F8283BB; Mon, 8 Jul 2019 21:16:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A03912837D for ; Mon, 8 Jul 2019 21:16:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MqmJpv5BWDDEzyI0eBgpQuJdP7w/dkNeEj9pXJB5wv0=; b=oU4U/bDYUACCgj sVcA+JsppEyvcyjzfiZi0oy06hVhcdfRK08FAPZrOOcrwQ5X8Btp5huNdxEm3i5B1FrINwjk7J7Sw BLi5qf+yubdsO+n9m7QWF+rEhEMoFygWF+FixcScHbrGdleIt2c1gezqrEDzPT4gQ5OdEwInrXUxP +r2EmaBUw7ovqn6+NWsqyty4d84V/FkVmHOqZAJb2zEz0nKNsvvjo5QJ+iIFAHx/wODIUTGgHQJXU FSjQezvYM247Y0bVQyWztSg6lB3eTcFp0hHRKs9otC+YGoyC2qfl1b99hcE+OoyCZPFIbcX46U9oF XXjC3wYcXb8d6wcaxBAQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hkazg-0001wo-1J; Mon, 08 Jul 2019 21:16:16 +0000 Received: from mail-qk1-x742.google.com ([2607:f8b0:4864:20::742]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hkaz3-0001Ri-Ex for linux-arm-kernel@lists.infradead.org; Mon, 08 Jul 2019 21:15:40 +0000 Received: by mail-qk1-x742.google.com with SMTP id r6so14483573qkc.0 for ; Mon, 08 Jul 2019 14:15:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=0AMQxB8fjID6n1nIoBRP/bexLOV4+LcL9MqYB3dLbp0=; b=nh2063uICAObAjvkowsMusqQTntBkHqsfDRkCKAaQr6mTjmZpjHeQbbJETBcCobAji gGycJV8JxvYKKHhTrBKhzzaa/0oync9yQY22DTAt6Lasb8/KgeCIV1yTfKJfPA4bSP5H XNkKsLyMvQkV72jCjE85v0IoPLvyvhY4i8NIB/SQAT6Sg+vdWDdAa0pNLjGlyZob2RKu KSMLCm5gq949sNAsKLj2ma2oXyJx/ugj3A9fd9byhxVX/hy78ZWLeWfWUB5DKxh9l9tB ExkSwi1sOivngEa7rGmXpr701XcGlSIKddV+gNESh946PsgUjHAjZJ6S9ZUhcy+8ia+V ucWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0AMQxB8fjID6n1nIoBRP/bexLOV4+LcL9MqYB3dLbp0=; b=qQy8GoWdOPU3eglOozcsRCA926Bn3L3/7h3Y77wVC+3jxmmRfpy47aDmNIdOoHeYnE +9qXfSGKdcsmHmfus/XUEICb69IFRBZgBY5rbdnR5vGO5emzZ2eolj9QWKsxQipwCosh 9J1MMPJQ7kjw3ypD396MoGvuhAvO9uW1uq8UFc7o5yN0iUvMppof5LozWl2jcInXjXAJ y2Pe35s3KlhiWvpxW9sbV3f1Pdnp1xeFAroz5aceWG5B7YuurHJI1J8EiHGboGs5MJms nhlfYxYnAiAfjkI00N5qyfVUK9s+t01p0bN4AcM8AmhxB0Ym7Q93QKypX6aXpY1MgQV9 RR0Q== X-Gm-Message-State: APjAAAUuo4AyZzSpDfONl3NG33QxvZKWQ1tjjqVljYT07sL7mzLzJ25m CDea9pkK9vdQ1nnoJ9SnpFaJEQ== X-Google-Smtp-Source: APXvYqxil68FzEbaqfS3VsZ9U/3z7w3WmWgrJNx8pulJ4mSV3A2nSrAQIOKvet23G/V3Ph6Itu0yLw== X-Received: by 2002:ae9:f303:: with SMTP id p3mr15620551qkg.320.1562620536253; Mon, 08 Jul 2019 14:15:36 -0700 (PDT) Received: from localhost.localdomain (c-73-69-118-222.hsd1.nh.comcast.net. [73.69.118.222]) by smtp.gmail.com with ESMTPSA id b67sm8335620qkd.82.2019.07.08.14.15.35 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 08 Jul 2019 14:15:35 -0700 (PDT) From: Pavel Tatashin To: pasha.tatashin@soleen.com, 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-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [v1 4/5] kexec: use reserved memory for normal kexec reboot Date: Mon, 8 Jul 2019 17:15:27 -0400 Message-Id: <20190708211528.12392-5-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708211528.12392-1-pasha.tatashin@soleen.com> References: <20190708211528.12392-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190708_141537_755339_B1154217 X-CRM114-Status: GOOD ( 15.04 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP If memory was reserved for the given segment use it directly instead of allocating on per-page bases. This will avoid relocating this segment to final destination when machine is rebooted. This is done on a per segment bases because user might decide to always load kernel segments at the given address (i.e. non-relocatable kernel), but load initramfs at reserved address, and thus save reboot time on copying initramfs if it is large, and reduces reboot performance. Signed-off-by: Pavel Tatashin --- kernel/kexec_core.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index 932feadbeb3a..2a8d8746e0a1 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -154,6 +154,18 @@ static struct page *kimage_alloc_page(struct kimage *image, gfp_t gfp_mask, unsigned long dest); +/* Check whether this segment is fully within the resource */ +static bool segment_is_reserved(struct kexec_segment *seg, struct resource *res) +{ + unsigned long mstart = seg->mem; + unsigned long mend = mstart + seg->memsz - 1; + + if (mstart < phys_to_boot_phys(res->start) || + mend > phys_to_boot_phys(res->end)) + return false; + return true; +} + int sanity_check_segment_list(struct kimage *image) { int i; @@ -246,13 +258,9 @@ int sanity_check_segment_list(struct kimage *image) if (image->type == KEXEC_TYPE_CRASH) { for (i = 0; i < nr_segments; i++) { - unsigned long mstart, mend; - - mstart = image->segment[i].mem; - mend = mstart + image->segment[i].memsz - 1; /* Ensure we are within the crash kernel limits */ - if ((mstart < phys_to_boot_phys(crashk_res.start)) || - (mend > phys_to_boot_phys(crashk_res.end))) + if (!segment_is_reserved(&image->segment[i], + &crashk_res)) return -EADDRNOTAVAIL; } } @@ -848,12 +856,13 @@ static int kimage_load_normal_segment(struct kimage *image, return result; } -static int kimage_load_crash_segment(struct kimage *image, - struct kexec_segment *segment) +static int kimage_load_crash_or_reserved_segment(struct kimage *image, + struct kexec_segment *segment) { - /* For crash dumps kernels we simply copy the data from - * user space to it's destination. - * We do things a page at a time for the sake of kmap. + /* + * For crash dumps and kexec-reserved kernels we simply copy the data + * from user space to it's destination. We do things a page at a time + * for the sake of kmap. */ unsigned long maddr; size_t ubytes, mbytes; @@ -923,10 +932,14 @@ int kimage_load_segment(struct kimage *image, switch (image->type) { case KEXEC_TYPE_DEFAULT: - result = kimage_load_normal_segment(image, segment); + if (segment_is_reserved(segment, &kexeck_res)) + result = kimage_load_crash_or_reserved_segment(image, + segment); + else + result = kimage_load_normal_segment(image, segment); break; case KEXEC_TYPE_CRASH: - result = kimage_load_crash_segment(image, segment); + result = kimage_load_crash_or_reserved_segment(image, segment); break; }