Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6999564imu; Thu, 27 Dec 2018 10:15:41 -0800 (PST) X-Google-Smtp-Source: ALg8bN5wR/Y96dg8UpMCqXxt+VEwRDoNfWjecj89WlIHhOxhP1/+bRkHqUY+T5wboPESMm+hfYZP X-Received: by 2002:a17:902:2aaa:: with SMTP id j39mr25118144plb.335.1545934541127; Thu, 27 Dec 2018 10:15:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545934541; cv=none; d=google.com; s=arc-20160816; b=JC9Wg5NQSBErr507dxtBPseomK7LxuhQoT0qGX4Q7eyRGt8UH4LWe96hA2w8PzDc9M uYkgk0BgHXLd1dQsgEqgrto8XLgISOIlU7jp01RA1gAbGPRnAb5t5vlJOenjc7jwPw93 T/ZOk8Bb1Iyntpaoyct11z0speaZKnJT9hLNi4nQ6WZ5uouDmqGb921t9jYhX3nI8sf+ rMoIGeAT3bSJFifQYqafXo10IkHefZMehtapNdlmqMTFNutKvzbpBhuvay3n8USjY2sJ MZakpIpwqN4JnumETb/dzpftWtrkASXFIMTkx1ImZ0bXw3ZJylZ7+BH9oQ93NN7p80JV rdPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=ESQUtg8OvosK7prMVa3+nkOXD7RnKa+w1951in3Ka+A=; b=US5nHaS5mrEwf0gh2zS11jGim3ixW/ucxGxrrR6+Y15p7uRQogW26hSO14M1WKJqJC Mx34MSsVIpYHgtCPexGNwZlHZEEMiDxIGG+0qfKTMKkAj9EFPQA+jp+weuoQi398Q/FK tPq9HYXptIIO9eqB5v9CuDtvQwbrwAijh7HsfaPPwRVL6ABTggoHP6AIeP5A9YHIzrIh u2N0L5/l2D4X8Ch07SlQs5LP+vJAcfIHIfbUQbX1/zo0a6SkOaad0M0MY00qifknPEH/ FSfdI8jkVJWTiB5Z2qnc22ZxWcO9j0oVIQb2wGDNQ2X/E89G3Ji4t3TO+25mRF4w10Ij lfdQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p26si29080958pli.225.2018.12.27.10.15.24; Thu, 27 Dec 2018 10:15:41 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726096AbeL0FHB (ORCPT + 99 others); Thu, 27 Dec 2018 00:07:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43580 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726055AbeL0FHB (ORCPT ); Thu, 27 Dec 2018 00:07:01 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 02A4F1390C; Thu, 27 Dec 2018 05:07:01 +0000 (UTC) Received: from dhcp-128-65.nay.redhat.com (ovpn-12-42.pek2.redhat.com [10.72.12.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 72EC05D781; Thu, 27 Dec 2018 05:06:56 +0000 (UTC) Date: Thu, 27 Dec 2018 13:06:52 +0800 From: Dave Young To: linux-kernel@vger.kernel.org, kexec@lists.infradead.org Cc: AKASHI Takahiro , Andrew Morton , "Eric W. Biederman" , Baoquan He , x86@kernel.org, Ingo Molnar , Borislav Petkov , Thomas Gleixner , Vivek Goyal Subject: [PATCH] x86/kexec: fix a kexec_file_load failure Message-ID: <20181227050652.GA2960@dhcp-128-65.nay.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.5 (2018-04-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 27 Dec 2018 05:07:01 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The code cleanup mentioned in Fixes tag changed the behavior of kexec_locate_mem_hole. The kexec_locate_mem_hole will try to allocate free memory only when kbuf.mem is initialized as zero. But in x86 kexec_file_load implementation there are a few places the kbuf.mem is reused like below: /* kbuf initialized, kbuf.mem = 0 */ ... kexec_add_buffer() ... kexec_add_buffer() The second kexec_add_buffer will reuse previous kbuf but not reinitialize the kbuf.mem. Thus kexec_file_load failed because the sanity check failed. So explictily reset mem = 0 to fix the issue. Fixes: b6664ba42f14 ("s390, kexec_file: drop arch_kexec_mem_walk()") Signed-off-by: Dave Young Cc: --- arch/x86/kernel/crash.c | 1 + arch/x86/kernel/kexec-bzimage64.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c index f631a3f15587..37147509d2c8 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c @@ -469,6 +469,7 @@ int crash_load_segments(struct kimage *image) kbuf.memsz = kbuf.bufsz; kbuf.buf_align = ELF_CORE_HEADER_ALIGN; + kbuf.mem = 0; ret = kexec_add_buffer(&kbuf); if (ret) { vfree((void *)image->arch.elf_headers); diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c index 278cd07228dd..558204bdf412 100644 --- a/arch/x86/kernel/kexec-bzimage64.c +++ b/arch/x86/kernel/kexec-bzimage64.c @@ -434,6 +434,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel, kbuf.memsz = PAGE_ALIGN(header->init_size); kbuf.buf_align = header->kernel_alignment; kbuf.buf_min = MIN_KERNEL_LOAD_ADDR; + kbuf.mem = 0; ret = kexec_add_buffer(&kbuf); if (ret) goto out_free_params; @@ -448,6 +449,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel, kbuf.bufsz = kbuf.memsz = initrd_len; kbuf.buf_align = PAGE_SIZE; kbuf.buf_min = MIN_INITRD_LOAD_ADDR; + kbuf.mem = 0; ret = kexec_add_buffer(&kbuf); if (ret) goto out_free_params; -- 2.17.0