Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7748136imu; Fri, 28 Dec 2018 04:17:18 -0800 (PST) X-Google-Smtp-Source: ALg8bN7v5BdY4hhuLH9uPvCpiXKQqUrwLvo2tAUqJXKq2hSQqxoyhNlUVdKisueTcJ3mJ2ceV/3E X-Received: by 2002:a17:902:714c:: with SMTP id u12mr27056562plm.234.1545999437946; Fri, 28 Dec 2018 04:17:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545999437; cv=none; d=google.com; s=arc-20160816; b=a3xlC4AJPo2Y7j3t3S7jOpRZSW//Bv8pemRN+GgEhz3VX5uqtCfDxFWv2/elISPJTq mvHQCkZdwmlpU9hrQgLf+Dikg8ffPar81qVS9M8fJnIRFqrKfDZjN91rnqvl99rBHFwY aheRZ4PRTU1C5k5V4wvBtfPu8Ct6yaK1gRTbvydSq3zoJDas7jLBOIHsNavzuqgC+AHb u21LmtjRm6zHJWVc9NB43MWQ6plxS3gNYIwQsPHxpPPTnb8qe/B9qefH8vGLTe2VqF3R i8lnIova1QrO444cqmJ9OSNLf+Y9/VEWHKZ45Ai9uw5UVASvopysFoV52E6Z+xWNVIzG PXKQ== 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=rUQ8Y2Pkix4PKKATClUHMcnULdxYIEx/k78QiDlLF8Q=; b=G4QWqjtttuhiywLUNZjNkNFqeNSXma9qusqp7Z+BdEDW5+NF0e8QBOEJ02O5XM694V HuSYzU18v2d29LswAPDKemuiM0s+oG685lGKHiuVYk8N+rlCXkg7dm21745mrkXg2quT +Vcq1fuYXNhgzUwHj5WL2Klf1UNn4K3U/jw/Q99Zr3iBcRnlbQu6TX91DKzgo9oW9JsA DUXa3h+I8cIDGqkGLjQLkNYAAJ3wOEePRGg9ilmiP7Zk2EKqEVwzpiOcKkDjjt8r/oUZ 4nuGvpW0AYGhXAjVWJMGiyJHFOT1F9dKeN5zBgq8d4WAq5GTjAcyypvk8GiazJTtPNbm EEbQ== 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 27si38088473pgu.421.2018.12.28.04.17.02; Fri, 28 Dec 2018 04:17:17 -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 S1727693AbeL1BM4 (ORCPT + 99 others); Thu, 27 Dec 2018 20:12:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49148 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727207AbeL1BMz (ORCPT ); Thu, 27 Dec 2018 20:12:55 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6B7987AEAB; Fri, 28 Dec 2018 01:12:55 +0000 (UTC) Received: from dhcp-128-65.nay.redhat.com (ovpn-12-71.pek2.redhat.com [10.72.12.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3740D19742; Fri, 28 Dec 2018 01:12:50 +0000 (UTC) Date: Fri, 28 Dec 2018 09:12:47 +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 V2] x86/kexec: fix a kexec_file_load failure Message-ID: <20181228011247.GA9999@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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 28 Dec 2018 01:12:55 +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 kbuf.mem to fix the issue. Fixes: b6664ba42f14 ("s390, kexec_file: drop arch_kexec_mem_walk()") Signed-off-by: Dave Young Cc: --- V1 -> V2: use KEXEC_BUF_MEM_UNKNOWN in code. 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..6b7890c7889b 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 = KEXEC_BUF_MEM_UNKNOWN; 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..0d5efa34f359 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 = KEXEC_BUF_MEM_UNKNOWN; 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 = KEXEC_BUF_MEM_UNKNOWN; ret = kexec_add_buffer(&kbuf); if (ret) goto out_free_params; -- 2.17.0