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 6F95DC433F5 for ; Tue, 10 May 2022 11:10:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB3416B0072; Tue, 10 May 2022 07:10:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E3AB46B0073; Tue, 10 May 2022 07:10:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB4916B0074; Tue, 10 May 2022 07:10:50 -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 B4B266B0072 for ; Tue, 10 May 2022 07:10:50 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 88BCA31A5A for ; Tue, 10 May 2022 11:10:50 +0000 (UTC) X-FDA: 79449565860.15.FC52844 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) by imf15.hostedemail.com (Postfix) with ESMTP id 3DF94A0076 for ; Tue, 10 May 2022 11:10:36 +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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220506153013.e6v4q2qhuhqumfiu@box.shutemov.name> X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3DF94A0076 X-Stat-Signature: krru9tx3w1jp1qww3wnh6yj4tgh9pdqf X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=alien8.de header.s=dkim header.b=SLJxJVy2; spf=pass (imf15.hostedemail.com: domain of bp@alien8.de designates 5.9.137.197 as permitted sender) smtp.mailfrom=bp@alien8.de; dmarc=pass (policy=none) header.from=alien8.de X-HE-Tag: 1652181036-325425 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 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