Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1048602iob; Fri, 13 May 2022 21:03:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJ3ysVJDwOMOLWm2GggIj6y7+AsGrxqMORl5MlObcTWjBWGkReHU5mvXE6JpjvE9+mR9q5 X-Received: by 2002:a5d:43d2:0:b0:20c:b986:a337 with SMTP id v18-20020a5d43d2000000b0020cb986a337mr5886051wrr.445.1652501012697; Fri, 13 May 2022 21:03:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652501012; cv=none; d=google.com; s=arc-20160816; b=DEPJc2aK+tBmt30FMJpC/UM+HP35FKGy4QNA/S+/lQ/IncUSPCTgvIZ5NNhdZsMOO6 Ua9M16mm33vxB11rgUT3wce/UeJVB0SxNiY/T4jRgd171GR32snFfTN6bAhzS5RDcmqI je6VRnyK68CsZuSpX848b9XvrE4o1/1NQJ9MagMaKOyZymbVJVWV9Ry0fG+S9RrN6jGC Lp0qjzy5kw/GBahjZQ36bIAKvNhmJOeoofMhLdZ4TYz1V/sxTuUkom3wGqfJ9Pvu9Y3O nZd6lnfoHdHkPKgOl95tRF1Jwd2041BTaZ/etTIhRC2Xmfti1Oa+zoePHS6vizrmrKOh TtjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature; bh=SyY4mEpMFa5F68efRI76ShsKbkWuRwJfr+pFEe31UIc=; b=qwD1PKPcs4xCgvD473mNCwHOSTxTGeaDdLoU7wly/Ye69aaM458Mt8CiGs4PrIkeDR 3fhVvkxPTy69xIVBnKsSszJoNdkZghxPS7el6LSdoqZkx0kjLzOFIF6+nyBnR7jH/N7O y+wh+SF2Tg+ycuYTHlgIazuOAAYAM524YYe3wU0Sahm3nymma7h7DEo/2tYdjk3GB5+e gOaCbn+Y49m94r+7r0qXXWExxMfZawcXlW073Z/P+VLl7Kri7FK/WnGmRoR7KoEs1dyK I4Caegb+ycKzt7YFt/DkMwYPlGXyieVi6B4/Jp/3pgaa49nujUJSbEoFDG+OSFOJoC5u gW0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=tOrn1fTm; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b="A7l/iE3h"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id u13-20020adfdd4d000000b0020c515aaba0si3507752wrm.908.2022.05.13.21.03.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 21:03:32 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=tOrn1fTm; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b="A7l/iE3h"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8EEC7332080; Fri, 13 May 2022 17:34:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378804AbiEMJB5 (ORCPT + 99 others); Fri, 13 May 2022 05:01:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378805AbiEMJBt (ORCPT ); Fri, 13 May 2022 05:01:49 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C73E961291; Fri, 13 May 2022 02:01:45 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4AF0C21AA0; Fri, 13 May 2022 09:01:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1652432504; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SyY4mEpMFa5F68efRI76ShsKbkWuRwJfr+pFEe31UIc=; b=tOrn1fTmPgR4XYhGMsWqyR1oqiwuDphjD/lBoBUskrL+KquiEeR7Gyk2PNNw5rpCPQ1T+7 3lK0nh6Ub+5akOBWp830oyQloyYS4qe3+OJ+xwPVeUnw+AG+huWSERBaaZVPXclDxxhsdF xaupQwxeGjAZ1nbIlW47kana45LJebc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1652432504; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SyY4mEpMFa5F68efRI76ShsKbkWuRwJfr+pFEe31UIc=; b=A7l/iE3h5zsH0F85RE9NINwnO2+9WlnsMl1oxm2z3ZDD2GPRHJC9hoz+HtRwnKf00vYuIs PE2vKhJNXw/z9yAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3C00213446; Fri, 13 May 2022 09:01:44 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id AfOdDngefmJ6bwAAMHmgww (envelope-from ); Fri, 13 May 2022 09:01:44 +0000 Date: Fri, 13 May 2022 11:01:43 +0200 From: Borislav Petkov To: Dionna Amalie Glaze , Michael Roth Cc: Borislav Petkov , "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 , 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 Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org + mroth - brijesh On Thu, May 12, 2022 at 10:34:02PM -0700, Dionna Amalie Glaze wrote: > 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) > -- Regards/Gruss, Boris. SUSE Software Solutions Germany GmbH, GF: Ivo Totev, HRB 36809, AG Nürnberg