Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp165573imw; Mon, 4 Jul 2022 07:05:06 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t5jI1qHVEWV63ZTWH1WoEDdbbnAK0UAG4D/342pHfvdrxzCuYeC7xep9U/NHyXCpqC8g4S X-Received: by 2002:a05:6402:42d5:b0:433:1727:b31c with SMTP id i21-20020a05640242d500b004331727b31cmr30891054edc.9.1656943506125; Mon, 04 Jul 2022 07:05:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656943506; cv=none; d=google.com; s=arc-20160816; b=YsjCvPgAT65bh6iMM9YjhBNWfnPLUumZp9WC5ewZjhfT7QNHO0sug5k9P2DeAEG0gb Tq3442CugtE455gkex3wDtCq0Otx0pmTwQYIhzblnOg9v7hwBTM5DWjY8VZVIJfplDjm nEJoAq6j5E3XpFzEVadnJ2sXN32KjjJZXoXXKYh64b2t+uENO5pCtc9fKxfI4zW7IxcJ R80v82jXfGWwcjNjwcjizru51a9qXtusf1ej4fZfngi6GMX4IQRrEdKuMwYK5+iQMpwj 6MUJE7Y7qPhxxltTJGU7X3jTG/rsgiUOJ+hPkzwL+7NtVXoLx9t0KMzjMh7v87NZcIbH mB8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PFcwfz9YjnTwBY53CZ26/cKSWQCH95fLXQHITYfVqQs=; b=uEthcAQOcyRbzn0RuBVysGQlQtcb1mpxOjl7BQ9pzpZ0C2TINegdy+0BdkXkNgDKlS Iyzaf/6dMl13q8eDCzK0T0HjwWY7pziUmSpcdfPhD5zV8EdaOYbjYXby7rew+Mo76m/Z k4H+50/3VJHUXVoeKAbE2qRG0tMwc1hV/hSMPBzVGzZ+X+KNvNIHC+vkuVKE2yfVJqcW xW1WXJKPQJynoqUPad7s7jQ5ZtLzXp7gEKYVvxTnpCmedCQXAX+EL6Bgh4CBzS8Ta1SD ALrVyQ7vO2aopLPT+2hhkzPHnpK1Y4vI69LikofRjKFO2iy/8d24LU51iSZOU6XxBBge ygqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eclypsium.com header.s=google header.b=CQTNFByZ; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=eclypsium.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g8-20020a056402090800b0043a7080a79csi951188edz.508.2022.07.04.07.04.40; Mon, 04 Jul 2022 07:05:06 -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=@eclypsium.com header.s=google header.b=CQTNFByZ; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=eclypsium.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230017AbiGDOAU (ORCPT + 99 others); Mon, 4 Jul 2022 10:00:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232209AbiGDN76 (ORCPT ); Mon, 4 Jul 2022 09:59:58 -0400 Received: from mail-vs1-xe34.google.com (mail-vs1-xe34.google.com [IPv6:2607:f8b0:4864:20::e34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7AB1DFD0 for ; Mon, 4 Jul 2022 06:59:42 -0700 (PDT) Received: by mail-vs1-xe34.google.com with SMTP id a184so8283vsa.1 for ; Mon, 04 Jul 2022 06:59:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eclypsium.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PFcwfz9YjnTwBY53CZ26/cKSWQCH95fLXQHITYfVqQs=; b=CQTNFByZSPbcjp+kBGJxruUIiefylatXkTKZ4UXWXph7ZtNVp8T6HpEfD1XKzuncEy y3FR1f6yAyetwOtLdPHa0NQDBeJgn7zQpIarid63VNYuSxz4OGxt1VLadB3LAfdvW+aw JwrhslRX3sESXzTPsm5dzaMQdQKd1ykl1P4YJXXYlQn3Wb8Q0Ro2q8KdWxdfb1ke5HU5 cTmyxBSvuFbDFi2x49F91NFcxUqn/XPns/cqItahB3rYnpS0VgEsz46iamTD1IvZni3+ s4yfyUsSiGmDTuIfozuuX80v86m2Q/l0Op6AZ+KtMUA/qUrt2196D1PPf4BMGWhUuzJG gU0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PFcwfz9YjnTwBY53CZ26/cKSWQCH95fLXQHITYfVqQs=; b=0YvwPggETAu8nJVplQ6NOY7LOGCvYjifRxCYV6s5Pwy/1JbEYOk3vXUGeS5L530aiZ POMpyD6EaBJjU+8/8b7kbwXSBN0esiAQRAeaC6nhdIngJcm93kK/WfQcLdPbcBUQi4UM hhXIYrZLuODd37v2hoWlWPum6fFOOlMaGy6vBKOdJGs3zMCu07kvRPqik0WxdRYCBXDL M4Kz+/HeKLk4Q0n2JbM1/xq8Ys4BhxibLTc+nFUpU0Oa7EHQc9L7I650uDVO7W0BZlOC HzrYIy8P14oKlzTTA2t4JNHRMvDMzn6BxWKA+PPDaZEzdAlTfE/ralmA1fm0VUXTbnq+ E/MA== X-Gm-Message-State: AJIora/vAF8Kq7X7yLb0o1xXCE+EJfNFv/djT7SOPr4UslyRjHSP/ymx NFiS0BEnwps3f3aBTcRp88Y4KW+Z5K0sJLkXoO61sgRlX7Tuc7z02HuqDolRHKkYcmn+mxRLhtA HL2QXFA8iczlsML8Dt0pOCYSYfApELYlt9O7GG4uGlUlhhP3qA62c6wjCgyGAtqm+MIF2CkqVKp D96K2LLFkwVYb8XwvD X-Received: by 2002:a05:6102:4410:b0:356:f108:157b with SMTP id df16-20020a056102441000b00356f108157bmr272236vsb.66.1656943181405; Mon, 04 Jul 2022 06:59:41 -0700 (PDT) Received: from localhost ([181.97.174.128]) by smtp.gmail.com with ESMTPSA id q192-20020a1f5cc9000000b00356d8a0fbb2sm4413105vkb.51.2022.07.04.06.59.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Jul 2022 06:59:41 -0700 (PDT) From: Martin Fernandez To: linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-mm@kvack.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, ardb@kernel.org, dvhart@infradead.org, andy@infradead.org, gregkh@linuxfoundation.org, rafael@kernel.org, rppt@kernel.org, akpm@linux-foundation.org, daniel.gutson@eclypsium.com, hughsient@gmail.com, alex.bazhaniuk@eclypsium.com, alison.schofield@intel.com, keescook@chromium.org, Martin Fernandez Subject: [PATCH v9 8/9] x86/efi: Mark e820_entries as crypto capable from EFI memmap Date: Mon, 4 Jul 2022 10:58:32 -0300 Message-Id: <20220704135833.1496303-9-martin.fernandez@eclypsium.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220704135833.1496303-1-martin.fernandez@eclypsium.com> References: <20220704135833.1496303-1-martin.fernandez@eclypsium.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Add a function to iterate over the EFI Memory Map and mark the regions tagged with EFI_MEMORY_CPU_CRYPTO in the e820_table; and call it from efi_init if add_efi_memmap is disabled. Also modify do_add_efi_memmap to mark the regions there. If add_efi_memmap is false, also check that the e820_table has enough size to (possibly) store also the EFI memmap. Signed-off-by: Martin Fernandez --- arch/x86/platform/efi/efi.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index 1591d67e0bcd..397d5e54d65e 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -187,6 +187,8 @@ static void __init do_add_efi_memmap(void) } e820__range_add(start, size, e820_type); + if (md->attribute & EFI_MEMORY_CPU_CRYPTO) + e820__range_set_crypto_capable(start, size); } e820__update_table(e820_table); } @@ -444,6 +446,34 @@ static int __init efi_config_init(const efi_config_table_type_t *arch_tables) return ret; } +static void __init efi_mark_e820_regions_as_crypto_capable(void) +{ + efi_memory_desc_t *md; + + /* + * Calling e820__range_set_crypto_capable several times + * creates a bunch of entries in the E820 table. They probably + * will get merged when calling update_table but we need the + * space there anyway + */ + if (efi.memmap.nr_map + e820_table->nr_entries >= E820_MAX_ENTRIES) { + pr_err_once("E820 table is not large enough to fit EFI memmap; not marking entries as crypto capable\n"); + return; + } + + for_each_efi_memory_desc(md) { + if (md->attribute & EFI_MEMORY_CPU_CRYPTO) + e820__range_set_crypto_capable(md->phys_addr, + md->num_pages << EFI_PAGE_SHIFT); + } + + /* + * We added and modified regions so it's good to update the + * table to merge/sort + */ + e820__update_table(e820_table); +} + void __init efi_init(void) { if (IS_ENABLED(CONFIG_X86_32) && @@ -497,6 +527,13 @@ void __init efi_init(void) set_bit(EFI_RUNTIME_SERVICES, &efi.flags); efi_clean_memmap(); + /* + * If add_efi_memmap then there is no need to mark the regions + * again + */ + if (!add_efi_memmap) + efi_mark_e820_regions_as_crypto_capable(); + if (efi_enabled(EFI_DBG)) efi_print_memmap(); } -- 2.30.2