Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1802662ybn; Thu, 26 Sep 2019 02:25:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZfpmwY73Ba+bH1ZkdD0ll989hqGwJM+8sZ4HIPXVeEfSzJR+/WMXoniRgawufcCLOaxAg X-Received: by 2002:a50:a57d:: with SMTP id z58mr2429500edb.115.1569489931992; Thu, 26 Sep 2019 02:25:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569489931; cv=none; d=google.com; s=arc-20160816; b=Wezz/AMwgCZonzYInIU3PNXr8FN6wbY6ksJ6PwnrfMbWHLG1UQ87t7eZ8WV+OjHHLb ZZ9riEaRSgqG3V0wULa2ypKiKQCqeZQOqDWlNjMlbT1CzBMitwf7soFZU9TB7ohI7D2Q +Xlsg1GDTAqYFeBXDGZyMzXRh4gDuNGONbqhMvE2EPr5LhPneKWkJm+Jc2VjFbbT0R4i hMFAWnodwg6s+X/X+2Dn465UvSPzxxsZes0KEU+V3VRZxQhOQiRW6JMoo2wOXrsj6K0T 9Dpc6SP2kU+EqRsfu4UzCjc/VTsurSJhB+c70VOYrws7CpQz8ClU4/bU4rPSltNJOOn3 ZfOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=nwufxU1fA5zK4/D9cIrul2uTjAS7x2oBdlB6/fuCBjk=; b=LOexpXscePEzKiwQsnkzUj867Jq14RJtvH4XwfY6YXbWswZim41Coj9GxhJ1y5K72u WH05fzIUYTmYf73taPbwmwhP/fCYJL3o122TmVBTmecN7qs7gqZvmLUJ1QNsfCQgfgDs lvEcqw9IqnwXugi8nNFXIev33sgO+TrgzDiEQha3LapSXIzLBiIhqKgXLxNAgiU1m1uy prMX2aiHHoMrVR3yhchmlLjXMLqZR/2acSbe7hr4NbVtTMPMq1ardBoCyg4lf2KSk/4Q 0+eu53VMRy+9MipCsr9KO7bMAfoNxMU1F8VvVVawcezen+j+sdlzYW8P6gcF+W1wIkly TrkQ== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o32si937215edb.63.2019.09.26.02.25.08; Thu, 26 Sep 2019 02:25:31 -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; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729820AbfIYJvY (ORCPT + 99 others); Wed, 25 Sep 2019 05:51:24 -0400 Received: from mga12.intel.com ([192.55.52.136]:32918 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726363AbfIYJvX (ORCPT ); Wed, 25 Sep 2019 05:51:23 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Sep 2019 02:51:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,547,1559545200"; d="scan'208";a="191290854" Received: from dariusvo-mobl.ger.corp.intel.com (HELO localhost) ([10.249.39.150]) by orsmga003.jf.intel.com with ESMTP; 25 Sep 2019 02:51:17 -0700 Date: Wed, 25 Sep 2019 12:51:14 +0300 From: Jarkko Sakkinen To: Kairui Song Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Matthew Garrett , Baoquan He , Dave Young , x86@kernel.org, linux-efi@vger.kernel.org Subject: Re: [PATCH v2] x86, efi: never relocate kernel below lowest acceptable address Message-ID: <20190925095114.GB5173@linux.intel.com> References: <20190919160521.13820-1-kasong@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190919160521.13820-1-kasong@redhat.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 20, 2019 at 12:05:21AM +0800, Kairui Song wrote: > Currently, kernel fails to boot on some HyperV VMs when using EFI. > And it's a potential issue on all platforms. > > It's caused a broken kernel relocation on EFI systems, when below three > conditions are met: > > 1. Kernel image is not loaded to the default address (LOAD_PHYSICAL_ADDR) > by the loader. > 2. There isn't enough room to contain the kernel, starting from the > default load address (eg. something else occupied part the region). > 3. In the memmap provided by EFI firmware, there is a memory region > starts below LOAD_PHYSICAL_ADDR, and suitable for containing the > kernel. > > Efi stub will perform a kernel relocation when condition 1 is met. But > due to condition 2, efi stub can't relocate kernel to the preferred > address, so it fallback to query and alloc from EFI firmware for lowest > usable memory region. > > It's incorrect to use the lowest memory address. In later stage, kernel > will assume LOAD_PHYSICAL_ADDR as the minimal acceptable relocate address, > but efi stub will end up relocating kernel below it. > > Then before the kernel decompressing. Kernel will do another relocation > to address not lower than LOAD_PHYSICAL_ADDR, this time the relocate will > over write the blockage at the default load address, which efi stub tried > to avoid, and lead to unexpected behavior. Beside, the memory region it > writes to is not allocated from EFI firmware, which is also wrong. > > To fix it, just don't let efi stub relocate the kernel to any address > lower than lowest acceptable address. > > Signed-off-by: Kairui Song Acked-by: /Jarkko