Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1066581rwd; Tue, 16 May 2023 11:14:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6auVaJbGrbDI9BdYkU+zVvaxtlef+MP8AxRsI7qZpYHUgLON21XIvYoOFgPNFH8UtJiZ+2 X-Received: by 2002:a05:6a00:4305:b0:64a:e8a2:bb26 with SMTP id cb5-20020a056a00430500b0064ae8a2bb26mr17108738pfb.0.1684260893389; Tue, 16 May 2023 11:14:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684260893; cv=none; d=google.com; s=arc-20160816; b=GnBxD75YRw3kcZztf5xNOnK65dRFY2+H3NNgXd/SX6UtPStF+XmFjTAaYQQryqR24u cD7l2wR6mEodROKi1dG4v+KWP9pPljEUMgS/RQH5MACkRKf7c251jOtegUNkqi4I073p MAOx64gxR2JTKaL6nWCxEjnoFr9FM27yIj8OfNmopL578zKp3kPKEVhy+eRYIvrD9E1v VCY/xYmAbJfTfCgXa3mLaAMKy7vrIhg+lELlEAfp9tFltoVUe+ErNnP8HXMr8VOU31RM IAds6R6i1UazY9ng+He+z9qD1UWXN2pnBsoT7sv/XSnWXgGz7GvJIKJ/DVUR9khijdBk yE+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=/p6R+68FwabHdgtBStGenvDElp3UiSkTl9PQWfq1E0k=; b=XCy5oDHPzPyGWc/iSKwMWSiW9Dvw8ruTp7aM4rwmfO0a0TediD0TDGXEsHdu+uYC/T uedyzWMTQrZGBonqbiPqpQcl+kAT9aNmvg+Y+52giJajFXNHx75R+GbqJU/+9CeSA7Bj kHgdJyZZ0EpXT0a8DOLrZI80S81EOaFhFzq3jp7oH/FdFrcx7QkEcW4nyvcspHOxY/rn 32gg7Vg3pu6tTG4hPY75BclpP2VRT05pn38gyp3KUHqMYL1B2YG8nv81p1ORueI8m9EF t74JGonHx7yPwvTkbSasnTZbl6EEgx/CiimP6DH2buH5bo1o2kTnjNcC5yKApQUoh/Gl xUzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RlotsGFN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 123-20020a620481000000b006466cd0dfffsi19376028pfe.158.2023.05.16.11.14.28; Tue, 16 May 2023 11:14:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RlotsGFN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229809AbjEPSBz (ORCPT + 99 others); Tue, 16 May 2023 14:01:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229522AbjEPSBy (ORCPT ); Tue, 16 May 2023 14:01:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A9AC3A81; Tue, 16 May 2023 11:01:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9C21963D7A; Tue, 16 May 2023 18:01:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 008BFC433AE; Tue, 16 May 2023 18:01:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684260112; bh=fTMeSN7AzVHCiTkT+f9pmwZrYPpPz9puMnicx/1cTkI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=RlotsGFNhRhoLtH8XEDeUgZi0A9QysXGzNW8uROo+1oL6hMQNZvWQDrnhux+u4kuL rBR59dmF/PkfieVlBNIH1U1SIcpn0efnUOGY3QnJJtnJ4UrDjHDcH5D9BhjF4kBaZ8 bBRiBA/tSfue4MAsveruziEiuKBZXaGVBbBHbJo7QB4ByWcpqPORiEgRXW3lfSlaZe vhxpodHCgI5iUhqpiYlCygt5y6dfBbI0TX3fSEyE2Fu1uRkyevrX1u4p12epe/aDh2 E8lkieM74b5CRgpImmOljoSHYCgGLLGVIGkWnZfUVCItCqyIIOLcoTGf6Igll8FGOP HDcxizFz2RvQQ== Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-4f00d41df22so5965380e87.1; Tue, 16 May 2023 11:01:51 -0700 (PDT) X-Gm-Message-State: AC+VfDz/3ocs2lhoWG4IBLPTMn6f5yEqLPkKQgzdX/Gxdj9OVZkKOae8 V7p1ulzO7YeX0vvdhGgyZL5TC5RoqUXb8m3ZXi8= X-Received: by 2002:a05:651c:1728:b0:2a9:f9e0:a820 with SMTP id be40-20020a05651c172800b002a9f9e0a820mr7846949ljb.11.1684260109821; Tue, 16 May 2023 11:01:49 -0700 (PDT) MIME-Version: 1.0 References: <20230513220418.19357-1-kirill.shutemov@linux.intel.com> <20230513220418.19357-4-kirill.shutemov@linux.intel.com> <9549d984-e581-048d-95a3-7c54acd70fb8@redhat.com> <20230514211324.fymzoa263wx2hs2p@box.shutemov.name> In-Reply-To: <20230514211324.fymzoa263wx2hs2p@box.shutemov.name> From: Ard Biesheuvel Date: Tue, 16 May 2023 20:01:38 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCHv11 3/9] efi/libstub: Implement support for unaccepted memory To: "Kirill A. Shutemov" Cc: =?UTF-8?Q?Mika_Penttil=C3=A4?= , "Kirill A. Shutemov" , Borislav Petkov , Andy Lutomirski , Dave Hansen , Sean Christopherson , Andrew Morton , Joerg Roedel , Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Dario Faggioli , Mike Rapoport , David Hildenbrand , Mel Gorman , marcelo.cerri@canonical.com, tim.gardner@canonical.com, khalid.elmously@canonical.com, philip.cox@canonical.com, aarcange@redhat.com, peterx@redhat.com, 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" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 On Sun, 14 May 2023 at 23:13, Kirill A. Shutemov wro= te: > > On Sun, May 14, 2023 at 08:08:07AM +0300, Mika Penttil=C3=A4 wrote: > > > + status =3D efi_bs_call(allocate_pool, EFI_LOADER_DATA, > > > + sizeof(*unaccepted_table) + bitmap_size, > > > + (void **)&unaccepted_table); > > > > > > Wonder if EFI_LOADER_DATA guarantees bitmap not to be freed, or should = some > > more persistent type be used. If EFI_LOADER_DATA is enough, maybe a com= ment > > why it is safe could be added. > > Ughh.. I've lost the hunk that reserves the memory explicitly while > folding in the patch we discussed with Ard. See below. > > But the question is solid. > > Ard, do we want to allocate the memory as EFI_RUNTIME_SERVICES_DATA (or > something else?) that got reserved automatically without additional steps= ? > EFI loader data should be fine here, as long as we reserve it. EFI runtime services data is intended for allocations that have significance to the firmware itself, so it gets mapped into the EFI runtime page tables and on some architectures, it gets removed from the direct map as well. The unaccepted bitmap is only accessed by the OS itself, so runtime services data is really not the right choice. We just have to ensure the bitmap gets reserved in memblock sufficiently early. > diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c > index e15a2005ed93..d817e7afd266 100644 > --- a/drivers/firmware/efi/efi.c > +++ b/drivers/firmware/efi/efi.c > @@ -765,6 +765,25 @@ int __init efi_config_parse_tables(const efi_config_= table_t *config_tables, > } > } > > + if (IS_ENABLED(CONFIG_UNACCEPTED_MEMORY) && > + efi.unaccepted !=3D EFI_INVALID_TABLE_ADDR) { > + struct efi_unaccepted_memory *unaccepted; > + > + unaccepted =3D early_memremap(efi.unaccepted, sizeof(*una= ccepted)); > + if (unaccepted) { > + unsigned long size; > + > + if (unaccepted->version =3D=3D 1) { > + size =3D sizeof(*unaccepted) + unaccepted= ->size; > + memblock_reserve(efi.unaccepted, size); > + } else { > + efi.unaccepted =3D EFI_INVALID_TABLE_ADDR= ; > + } > + > + early_memunmap(unaccepted, sizeof(*unaccepted)); > + } > + } > + > return 0; > } > > -- > Kiryl Shutsemau / Kirill A. Shutemov