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 1F113C433F5 for ; Fri, 13 May 2022 05:34:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD54B6B0073; Fri, 13 May 2022 01:34:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A85348D0005; Fri, 13 May 2022 01:34:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9732A8D0003; Fri, 13 May 2022 01:34:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8B1C06B0073 for ; Fri, 13 May 2022 01:34:14 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 57A8720EFB for ; Fri, 13 May 2022 05:34:14 +0000 (UTC) X-FDA: 79459604028.06.3A16C04 Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) by imf17.hostedemail.com (Postfix) with ESMTP id 9C133400B7 for ; Fri, 13 May 2022 05:33:53 +0000 (UTC) Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-2f7d7e3b5bfso79234627b3.5 for ; Thu, 12 May 2022 22:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MzuLZkvGtBtGQw1pDL6vVc7H+kdQt/J9TPee+0oSim0=; b=aJUNIyh0bt3QZBpNiFdkambzLl3faJNTEzhdur1OgekhYmVwx4JYk0LTXQcg+OFwzx tgWk34RcWG8/Y4/7fPJJ1tzImbyE1MXVgT1f/btb2jmoOI03bWLr3qJsQbJ0poQdQQph eQvRtlvKAdyr82raWhu+JQi2JNaKpAbyuZYMA4jCcoXxv3sHPJpenbeWg2gOCUq8QR7l Id3os4GVb0FoGWuliBiz4c2TXNY1sV5sApK6JdyfvfH2WSD/RIT+54qt4Yd7/Z7Phj20 04xEmautD+SZxJB9aakX8kR52XAMIniucHIOgzuPJYUXP/RRj1fxItIHfNvmlh+TXQ0Y dVjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MzuLZkvGtBtGQw1pDL6vVc7H+kdQt/J9TPee+0oSim0=; b=uoqC7pT4wPqkkpNrprDEqV1O/WpWDChJ3WS30Ugwi6kOr7UAk/+qoKauuBpuY8dx9J bm+gGSkfgHdZJmFOjluId2vHytih2/qT3jEEKOba9fEwZlLdtL4sgZDZArBsRoFkPBqU ftemUZIoIGxleJWaVU04LsNj4C1mwOik3SF6IeoD1jRzsE5CtHu6NEtUO5MRH2pqrvpL X/bHf84z+il+VFsJMmyU9zf78nE9Btq/jRtm4lOlE0Z1+HHT+sM+0wJd6XzT6fAQOEBd A92XhwMAC2cwhiPx2EzMWCatIPVDWCIlAn1ZqgLR6MvYx9n4ll3W4r0wxHcjXSmUUqgE Xwsg== X-Gm-Message-State: AOAM531L7xVMUJ9+4ZWlWl0FT2/s2SX41RaGxRK8tS9h+tBLF6aO4Fg6 dFZn/N5EiIcZn3jeD3S0OL3chl3b7Qc2w0eBv/8pYQ== X-Google-Smtp-Source: ABdhPJzbvJITAyF9pezasvdbf9Ebv/WVdiqeWUMVoaO1Sw2Z4IgmSKbjl1gIk4rgrnQk4UVM1yDalurYFkxnnMGZV0c= X-Received: by 2002:a0d:db43:0:b0:2f8:9a:8c1d with SMTP id d64-20020a0ddb43000000b002f8009a8c1dmr3941612ywe.72.1652420052877; Thu, 12 May 2022 22:34:12 -0700 (PDT) MIME-Version: 1.0 References: <20220425033934.68551-1-kirill.shutemov@linux.intel.com> <20220425033934.68551-7-kirill.shutemov@linux.intel.com> <20220506153013.e6v4q2qhuhqumfiu@box.shutemov.name> In-Reply-To: From: Dionna Amalie Glaze Date: Thu, 12 May 2022 22:34:02 -0700 Message-ID: Subject: Re: [PATCHv5 06/12] x86/boot/compressed: Handle unaccepted memory To: Borislav Petkov Cc: "Kirill A. Shutemov" , "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 Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=aJUNIyh0; spf=pass (imf17.hostedemail.com: domain of dionnaglaze@google.com designates 209.85.128.182 as permitted sender) smtp.mailfrom=dionnaglaze@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9C133400B7 X-Stat-Signature: 5xoi91cb1t89o93f9utxw89c6obx1ypx X-HE-Tag: 1652420033-720934 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: Kirill, I've been tracking these changes to see if we can handle the unaccepted memory type for SEV-SNP, but testing has been an issue. The proposed patch in Ovmf to introduce unaccepted memory seems to have stalled out last September (https://www.mail-archive.com/devel@edk2.groups.io/msg35842.html) and is particularly difficult to adapt to SEV-SNP since it doesn't follow the TDVF way of initializing all memory. Is there a different development I might have missed so that we might test these cases? Without the UEFI introducing EFI_UNACCEPTED_MEMORY type, any kernel uses are essentially dead code. Thanks, -Dionna (apologies for repost in text mode) On Tue, May 10, 2022 at 4:04 AM Borislav Petkov wrote: > > On Fri, May 06, 2022 at 06:30:13PM +0300, Kirill A. Shutemov wrote: > > I find it harder to follow. > > If in doubt, always consider using a helper function: > > --- > > diff --git a/arch/x86/boot/compressed/efi.h b/arch/x86/boot/compressed/efi.h > index 7db2f41b54cd..cf475243b6d5 100644 > --- a/arch/x86/boot/compressed/efi.h > +++ b/arch/x86/boot/compressed/efi.h > @@ -32,6 +32,7 @@ typedef struct { > } efi_table_hdr_t; > > #define EFI_CONVENTIONAL_MEMORY 7 > +#define EFI_UNACCEPTED_MEMORY 15 > > #define EFI_MEMORY_MORE_RELIABLE \ > ((u64)0x0000000000010000ULL) /* higher reliability */ > diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c > index 28b91df9d31e..39bb4c319dfc 100644 > --- a/arch/x86/boot/compressed/kaslr.c > +++ b/arch/x86/boot/compressed/kaslr.c > @@ -671,6 +671,23 @@ static bool process_mem_region(struct mem_vector *region, > } > > #ifdef CONFIG_EFI > + > +/* > + * Only EFI_CONVENTIONAL_MEMORY and EFI_UNACCEPTED_MEMORY (if supported) are guaranteed > + * to be free. > + */ > +static inline bool memory_type_is_free(efi_memory_desc_t *md) > +{ > + if (md->type == EFI_CONVENTIONAL_MEMORY) > + return true; > + > + if (IS_ENABLED(CONFIG_UNACCEPTED_MEMORY)) > + if (md->type == EFI_UNACCEPTED_MEMORY) > + return true; > + > + return false; > +} > + > /* > * Returns true if we processed the EFI memmap, which we prefer over the E820 > * table if it is available. > @@ -723,21 +740,9 @@ process_efi_entries(unsigned long minimum, unsigned long image_size) > * free memory and thus available to place the kernel image into, > * but in practice there's firmware where using that memory leads > * to crashes. > - * > - * Only EFI_CONVENTIONAL_MEMORY and EFI_UNACCEPTED_MEMORY (if > - * supported) are guaranteed to be free. > */ > - > - switch (md->type) { > - case EFI_CONVENTIONAL_MEMORY: > - break; > - case EFI_UNACCEPTED_MEMORY: > - if (IS_ENABLED(CONFIG_UNACCEPTED_MEMORY)) > - break; > + if (!memory_type_is_free(md)) > continue; > - default: > - continue; > - } > > if (efi_soft_reserve_enabled() && > (md->attribute & EFI_MEMORY_SP)) > -- > Regards/Gruss, > Boris. > > https://people.kernel.org/tglx/notes-about-netiquette -- -Dionna Glaze, PhD (she/her)