From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D18F77B for ; Tue, 10 May 2022 11:03:58 +0000 (UTC) Received: from zn.tnic (p5de8eeb4.dip0.t-ipconnect.de [93.232.238.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 86E9A1EC06BA; Tue, 10 May 2022 13:03:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1652180632; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=syfkLxHRdwVeg4TDYaeS8+/osqvt2Cc1E/livBnG7OM=; b=SLJxJVy2h1wrhVo+uXYwj0AmoBMCri/tlQceGXhLQMKhuayhE5HkchGtFPZvgpwWJGJj+z XzYKxgfTfHowtHzEj/se8njAdX/JRwhUrxQxY/HBLjWZMbzf+8ZtYy9+9nJrnifV6eiZih 8geRjbWUkJUl3nkh4lqkJQWs4Chq+NM= Date: Tue, 10 May 2022 13:03:56 +0200 From: Borislav Petkov To: "Kirill A. Shutemov" 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: References: <20220425033934.68551-1-kirill.shutemov@linux.intel.com> <20220425033934.68551-7-kirill.shutemov@linux.intel.com> <20220506153013.e6v4q2qhuhqumfiu@box.shutemov.name> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220506153013.e6v4q2qhuhqumfiu@box.shutemov.name> 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