From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76E0BC433F5 for ; Wed, 27 Apr 2022 14:17:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE6B76B0071; Wed, 27 Apr 2022 10:17:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B961B6B0072; Wed, 27 Apr 2022 10:17:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9EA7A6B0073; Wed, 27 Apr 2022 10:17:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 894E96B0071 for ; Wed, 27 Apr 2022 10:17:36 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 4E5C012116E for ; Wed, 27 Apr 2022 14:17:36 +0000 (UTC) X-FDA: 79402862112.03.5AA3734 Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) by imf20.hostedemail.com (Postfix) with ESMTP id 2E22D1C0064 for ; Wed, 27 Apr 2022 14:17:32 +0000 (UTC) Received: by mail-lj1-f176.google.com with SMTP id bn33so2829523ljb.6 for ; Wed, 27 Apr 2022 07:17:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=x/04ExZsssyHqK3ybhx4YVkpwU+WO3WPNrqX7DTqXG4=; b=KcoQA4RUPwVoun+6cZl/pmYQbIgxcoqRYDMq1MFkIwR5zf/Z/nxThQRqsAXpO6fHl8 KIomzfKhTflfdyS3w9NrdfMQKGTVAnQBz25Pe3HQItAotLqhUfYkS1qxfbzk3sUS9duR BFHXvCs1zMAiB27DkIhE0/vCtJMXpOFFAamo/+d1lmWh492Ftkv8Pm986gpCZzvuSn4y ERQB0kCCij3s2rkuRuKB+Bc3jQrBnKaKTc5O6mddoYlQo+M5eKoU2+gi1W9epBhTqajZ w6bW9WYrXOrScM6YsoZwQGiinAiJsHOebdQqSSZIfkdfg5JzYK5Qmpp4pvfSJhW+zZsP iZZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=x/04ExZsssyHqK3ybhx4YVkpwU+WO3WPNrqX7DTqXG4=; b=5JmXgAzkgaG92B7PX4xZ0KqO0tKxR0noNlOJ6BuMt/Bxr6pNWUNGJKqCFF+af3J9rJ yEB/J7bye9e4JopFm4Rvs7KHFb3S+lZNvph0f+QLvOHFhjTy+eYgIrEenD30gYWzRyJ0 CqEUDNB+zdUEfNkg5ABzbbU1xdTFos3u46RW2bqE50ioMbLylUQNvqK6qRujaQ/VSa+T Gqow+WfNEUN4gUDp3Ttr4bDK12/wmOpE3HTHw+lRRIIfsuYcq+rti4SO84sDBCLv6NzF 2sfvutn7yDGGYXKwnmJFs6sK/Kt513qpCq/t8lup4Q0WatSIdpqJml18phejLOlDRSYU q2fQ== X-Gm-Message-State: AOAM530cDumGOKLCGvGrcKc+Ba//OfGrTUctfXgOkCHL4a5s3bqgvFgg 3pZkGiKmsoMPnRyvP2ZcxbSEjQ== X-Google-Smtp-Source: ABdhPJxVjTj0vQFFkI6C0mpp7oyTSf4B40Jzv5S29tPlaFcLkO/RSz/P1O/faKPD1SWNzxgEvPAecQ== X-Received: by 2002:a05:651c:887:b0:247:f630:d069 with SMTP id d7-20020a05651c088700b00247f630d069mr18602831ljq.514.1651069053766; Wed, 27 Apr 2022 07:17:33 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id t17-20020a192d51000000b0047212cead69sm633986lft.253.2022.04.27.07.17.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 07:17:32 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 4FE48103716; Wed, 27 Apr 2022 17:19:14 +0300 (+03) Date: Wed, 27 Apr 2022 17:19:14 +0300 From: "Kirill A. Shutemov" To: Michael Roth , Borislav Petkov Cc: "Kirill A. Shutemov" , Andy Lutomirski , Sean Christopherson , Andrew Morton , Joerg Roedel , Ard Biesheuvel , Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Varad Gautam , Dario Faggioli , Dave Hansen , Brijesh Singh , Mike Rapoport , David Hildenbrand , x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCHv5 06/12] x86/boot/compressed: Handle unaccepted memory Message-ID: <20220427141914.s7y7lhlaau473mu7@box.shutemov.name> References: <20220425033934.68551-1-kirill.shutemov@linux.intel.com> <20220425033934.68551-7-kirill.shutemov@linux.intel.com> <20220427001756.xefhkwwc7uhxuusk@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220427001756.xefhkwwc7uhxuusk@amd.com> X-Stat-Signature: rm7rr7mr3w4e7qsta6d586p3poxs1d3g Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=shutemov-name.20210112.gappssmtp.com header.s=20210112 header.b=KcoQA4RU; spf=none (imf20.hostedemail.com: domain of kirill@shutemov.name has no SPF policy when checking 209.85.208.176) smtp.mailfrom=kirill@shutemov.name; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 2E22D1C0064 X-HE-Tag: 1651069052-101132 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Apr 26, 2022 at 07:17:56PM -0500, Michael Roth wrote: > On Mon, Apr 25, 2022 at 06:39:28AM +0300, Kirill A. Shutemov wrote: > > The firmware will pre-accept the memory used to run the stub. But, the > > stub is responsible for accepting the memory into which it decompresses > > the main kernel. Accept memory just before decompression starts. > > > > The stub is also responsible for choosing a physical address in which to > > place the decompressed kernel image. The KASLR mechanism will randomize > > this physical address. Since the unaccepted memory region is relatively > > small, KASLR would be quite ineffective if it only used the pre-accepted > > area (EFI_CONVENTIONAL_MEMORY). Ensure that KASLR randomizes among the > > entire physical address space by also including EFI_UNACCEPTED_MEMOR > > > > Signed-off-by: Kirill A. Shutemov > > --- > > arch/x86/boot/compressed/Makefile | 2 +- > > arch/x86/boot/compressed/kaslr.c | 14 ++++++++++++-- > > arch/x86/boot/compressed/mem.c | 21 +++++++++++++++++++++ > > arch/x86/boot/compressed/misc.c | 9 +++++++++ > > arch/x86/include/asm/unaccepted_memory.h | 2 ++ > > 5 files changed, 45 insertions(+), 3 deletions(-) > > > > diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile > > index 7f672f7e2fea..b59007e57cbf 100644 > > --- a/arch/x86/boot/compressed/Makefile > > +++ b/arch/x86/boot/compressed/Makefile > > @@ -102,7 +102,7 @@ endif > > > > vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o > > vmlinux-objs-$(CONFIG_INTEL_TDX_GUEST) += $(obj)/tdx.o $(obj)/tdcall.o > > -vmlinux-objs-$(CONFIG_UNACCEPTED_MEMORY) += $(obj)/bitmap.o $(obj)/mem.o > > +vmlinux-objs-$(CONFIG_UNACCEPTED_MEMORY) += $(obj)/bitmap.o $(obj)/find.o $(obj)/mem.o > > Since it's possible to have CONFIG_UNACCEPTED_MEMORY=y while > CONFIG_INTEL_TDX_GUEST=n (e.g. for SNP-only guest kernels), this can > result in mem.o reporting linker errors due to tdx_accept_memory() not > being defined. I think it needs a stub for !CONFIG_INTEL_TDX_GUEST, or > something along that line. Fair enough. This would do the trick: diff --git a/arch/x86/boot/compressed/mem.c b/arch/x86/boot/compressed/mem.c index 539fff27de49..4a49a2438180 100644 --- a/arch/x86/boot/compressed/mem.c +++ b/arch/x86/boot/compressed/mem.c @@ -19,6 +19,9 @@ static bool is_tdx_guest(void) static bool once; static bool is_tdx; + if (!IS_ENABLED(CONFIG_INTEL_TDX_GUEST)) + return false; + if (!once) { u32 eax, sig[3]; > > vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o > > efi-obj-$(CONFIG_EFI_STUB) = $(objtree)/drivers/firmware/efi/libstub/lib.a > > diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c > > index 411b268bc0a2..59db90626042 100644 > > --- a/arch/x86/boot/compressed/kaslr.c > > +++ b/arch/x86/boot/compressed/kaslr.c > > @@ -725,10 +725,20 @@ process_efi_entries(unsigned long minimum, unsigned long image_size) > > * but in practice there's firmware where using that memory leads > > * to crashes. > > * > > - * Only EFI_CONVENTIONAL_MEMORY is guaranteed to be free. > > + * Only EFI_CONVENTIONAL_MEMORY and EFI_UNACCEPTED_MEMORY (if > > + * supported) are guaranteed to be free. > > */ > > - if (md->type != EFI_CONVENTIONAL_MEMORY) > > + > > + switch (md->type) { > > + case EFI_CONVENTIONAL_MEMORY: > > + break; > > + case EFI_UNACCEPTED_MEMORY: > > Just FYI, but with latest tip boot/compressed now relies on a separate header > in arch/x86/boot/compressed/efi.h where this need to be defined again. Right. Borislav, how do you want to handle this? Do you want me to rebase the tree to a specific branch? -- Kirill A. Shutemov