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 1F9DC2FB3 for ; Tue, 3 May 2022 14:13:08 +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 D04111EC0258; Tue, 3 May 2022 16:12:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1651587176; 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=x202iZNl5Y0R60gL0lXqXi/nN/reLshg7nG0X1MPp9g=; b=K6cLKFCQeaOKb+YdQBpE/BYk6yBSDBhZn8S12WAdaU3UXW/1JfqkoKxWUb1CzNMDt8pwsD o2p3YV5EUQK839YcBccjLUx/DkpbVlEk2mM0JKUkjCPn7tYPRf2kzP2C6fmxWLqEVr4fa8 06usPfyoNJfP8ot3Amzhq67J/n8PEt4= Date: Tue, 3 May 2022 16:12:55 +0200 From: Borislav Petkov To: "Kirill A. Shutemov" Cc: 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> 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: <20220425033934.68551-7-kirill.shutemov@linux.intel.com> On Mon, Apr 25, 2022 at 06:39:28AM +0300, Kirill A. Shutemov wrote: > 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: > + if (IS_ENABLED(CONFIG_UNACCEPTED_MEMORY)) > + break; > continue; > + default: > + continue; > + } Is there any special reason for this to be a switch-case or can it simply be a compound conditional if (bla...) ? > @@ -66,3 +69,21 @@ void process_unaccepted_memory(struct boot_params *params, u64 start, u64 end) > bitmap_set((unsigned long *)params->unaccepted_memory, > start / PMD_SIZE, (end - start) / PMD_SIZE); > } > + > +void accept_memory(phys_addr_t start, phys_addr_t end) > +{ > + unsigned long range_start, range_end; > + unsigned long *unaccepted_memory; Please shorten that name so that you don't have to break the lines below. > + unsigned long bitmap_size; > + > + unaccepted_memory = (unsigned long *)boot_params->unaccepted_memory; > + range_start = start / PMD_SIZE; > + bitmap_size = DIV_ROUND_UP(end, PMD_SIZE); > + > + for_each_set_bitrange_from(range_start, range_end, > + unaccepted_memory, bitmap_size) { > + __accept_memory(range_start * PMD_SIZE, range_end * PMD_SIZE); > + bitmap_clear(unaccepted_memory, > + range_start, range_end - range_start); > + } > +} > diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c > index fa8969fad011..285b37e28074 100644 > --- a/arch/x86/boot/compressed/misc.c > +++ b/arch/x86/boot/compressed/misc.c > @@ -18,6 +18,7 @@ > #include "../string.h" > #include "../voffset.h" > #include > +#include > > /* > * WARNING!! > @@ -451,6 +452,14 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap, > #endif > > debug_putstr("\nDecompressing Linux... "); > + > +#ifdef CONFIG_UNACCEPTED_MEMORY IS_ENABLED() perhaps? > + if (boot_params->unaccepted_memory) { Also, that ->unaccepted_memory will be set only when ACONFIG_UNACCEPTED_MEMORY is set, FAICT. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette