Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4406802ioa; Wed, 27 Apr 2022 03:12:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhUzy2Vd+SLA4wA4XgmqFt8LVBgNq1FOBMAwDemDzcu77/0t+ppdgaXU4g59OvghJ07FAu X-Received: by 2002:a63:2b90:0:b0:3aa:b1df:df69 with SMTP id r138-20020a632b90000000b003aab1dfdf69mr23469290pgr.497.1651054369011; Wed, 27 Apr 2022 03:12:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651054369; cv=none; d=google.com; s=arc-20160816; b=aGgn3DI7yk+KiCE4uK5xC30K9R8/08UX02+jrZ8M2mL1CxatLulVd1+8d94KpHpWn/ 84TD/XntnuNppZDFSEvZ4bW+HWOe8Tugfza4IG2UNMr4IQP7vzo3lLyfe/S3fGE9ZF52 uhWtKE3k2W0GZp/Bt7061IPLw/rfdbQ+5SrV8PqY0l9MWfUSozf9oVLcQ+vjIlawATVS Sq14smoykjNi0+9iZsMXFI8xDU68FqTMKpYVl/+ngBotB4GfhYLhEg+Iv4m4568X3enK ISZCJF7OQKIcI7Hyrm7D9NBUQibqzzTFVsIhVsfXgsFUEMNIzgPUG0NScIbWm8Unfo4Y l5iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:references :in-reply-to:mime-version:dkim-signature; bh=klvWna6aVMmD5xzd2dumZFpFxfWMKshDlMPwR9QCUhU=; b=J7IaeleL+oF9aCGba/9KEEbkIeNdaXruPHBpbtcSGpqu+qDHxBNxVjsQou9mmQeS+J 5+mJSf4mUQJgyyQg5mvnWk58lRGBXTblVCieYsvbTlGUO6/+RATk3IcPnuT9zTDP4znW OKOw7idPgtnckEmGzBn+cWBeN9Z8zTj7mZsH1sZCc29wbq84jt0PzfOcNS07knsKmPEL o2hh8Yebz5yzrRjS5CuVvuvGWJ2f3PZCiXxkdOXEeFIyzIMbqBjEd5E8s3wtqHM0lUkh 6935CqNqLQMHJLJByhQY/eABW1qnPP0nwc3y7xGyMlDBxfxURhOsPGsWYbE/whpIbJke eKCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eclypsium.com header.s=google header.b=Snve9f0K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m22-20020a17090b069600b001d0f203b1ebsi4467678pjz.149.2022.04.27.03.12.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 03:12:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@eclypsium.com header.s=google header.b=Snve9f0K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=eclypsium.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CEFC331E0D4; Wed, 27 Apr 2022 02:34:40 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350619AbiDZNDL (ORCPT + 99 others); Tue, 26 Apr 2022 09:03:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350486AbiDZNCR (ORCPT ); Tue, 26 Apr 2022 09:02:17 -0400 Received: from mail-yb1-xb29.google.com (mail-yb1-xb29.google.com [IPv6:2607:f8b0:4864:20::b29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C59C1815F6 for ; Tue, 26 Apr 2022 05:59:05 -0700 (PDT) Received: by mail-yb1-xb29.google.com with SMTP id w17so1207089ybh.9 for ; Tue, 26 Apr 2022 05:59:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eclypsium.com; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=klvWna6aVMmD5xzd2dumZFpFxfWMKshDlMPwR9QCUhU=; b=Snve9f0KfXixZ+c8vg5EYkQfEnS0VOwMlEfbjzSmmLeKl3CV3QY7OoAEGlUCMMiKpD R3uI1qO6ciPKkLK5vtAtgpjFqwIkNnMkoTIIlq14jZ76GdxyOBwkxciG6k+P3CLvjiiz d+oMOO+GBwo5DcLFG2CBUSHN7gROk7mk7kOsagRBNNw+0te+8pMeTBDhlZ8z6gI8V1nB OwcO7pjnH+wqR7qbdlDmbAwik4TDeQZ2HGgpg4HMQ78iHj0vjE5dn+I5qeu85IiTJdFW vB92ZbAXdrOk8XW/osb3yXoM0AJ/fCZoICH/8pvrXNcyr3lJ561gTCb3ThZOCTE8HCXH NdAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=klvWna6aVMmD5xzd2dumZFpFxfWMKshDlMPwR9QCUhU=; b=GDX7DGHBaDuwD4ZPC82nDDL98nPc7s9EWEXQvfPfN3b8viTFnhgSdEwlOrwT2pad8R AqpGiCZt1unmRYsyXe49wYlTSZUQuoXvhZGKbwz3jBDDXx4FTJx+5qTjG6qAuJJ591Nk c3stg/vIP0FReLDM58iNiaBlWAa+T3/TlPWPE7m88Uy68BXTQRTmoXcFMVdyJbBD7+On Cb0VelPSIWZjgRYrG4Ge8qjk7mYj4vxuno60cvhcKuOs/C1LvKuiGMBSoN27Mlzz2zWj FlaNilop/1YQmvSqtAm6gjH/IrGt904n0w2wAtf6A6Id6rhxRkg3Vh3VcxAGaS0IKW8V V6AQ== X-Gm-Message-State: AOAM530uHbPWS0yjvZ0fLJIH7IRGltGcJKMksrz4U7mXyLsosq2phNoz E1KMkXgdth6XovOT2nki5QzL234YWLr5SkUqfENz0w== X-Received: by 2002:a25:8b03:0:b0:628:8cff:ed6c with SMTP id i3-20020a258b03000000b006288cffed6cmr21036112ybl.513.1650977944764; Tue, 26 Apr 2022 05:59:04 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a81:10a:0:0:0:0:0 with HTTP; Tue, 26 Apr 2022 05:59:04 -0700 (PDT) In-Reply-To: References: <20220425171526.44925-1-martin.fernandez@eclypsium.com> <20220425171526.44925-2-martin.fernandez@eclypsium.com> From: Martin Fernandez Date: Tue, 26 Apr 2022 09:59:04 -0300 Message-ID: Subject: Re: [PATCH v7 1/8] mm/memblock: Tag memblocks with crypto capabilities To: Mike Rapoport Cc: linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-mm@kvack.org, 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, akpm@linux-foundation.org, daniel.gutson@eclypsium.com, hughsient@gmail.com, alex.bazhaniuk@eclypsium.com, alison.schofield@intel.com, keescook@chromium.org Content-Type: text/plain; charset="UTF-8" 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 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 On 4/26/22, Mike Rapoport wrote: > On Mon, Apr 25, 2022 at 02:15:19PM -0300, Martin Fernandez wrote: >> Add the capability to mark regions of the memory memory_type able of >> hardware memory encryption. >> >> Also add the capability to query if all regions of a memory node are >> able to do hardware memory encryption to call it when initializing the >> nodes. Warn the user if a node has both encryptable and >> non-encryptable regions. >> >> Signed-off-by: Martin Fernandez >> --- >> include/linux/memblock.h | 5 ++++ >> mm/memblock.c | 62 ++++++++++++++++++++++++++++++++++++++++ >> 2 files changed, 67 insertions(+) >> >> diff --git a/include/linux/memblock.h b/include/linux/memblock.h >> index 50ad19662a32..00c4f1a20335 100644 >> --- a/include/linux/memblock.h >> +++ b/include/linux/memblock.h >> @@ -40,6 +40,7 @@ extern unsigned long long max_possible_pfn; >> * via a driver, and never indicated in the firmware-provided memory map >> as >> * system RAM. This corresponds to IORESOURCE_SYSRAM_DRIVER_MANAGED in >> the >> * kernel resource tree. >> + * @MEMBLOCK_CRYPTO_CAPABLE: capable of hardware encryption >> */ >> enum memblock_flags { >> MEMBLOCK_NONE = 0x0, /* No special request */ >> @@ -47,6 +48,7 @@ enum memblock_flags { >> MEMBLOCK_MIRROR = 0x2, /* mirrored region */ >> MEMBLOCK_NOMAP = 0x4, /* don't add to kernel direct mapping */ >> MEMBLOCK_DRIVER_MANAGED = 0x8, /* always detected via a driver */ >> + MEMBLOCK_CRYPTO_CAPABLE = 0x10, /* capable of hardware encryption */ >> }; >> >> /** >> @@ -120,6 +122,9 @@ int memblock_physmem_add(phys_addr_t base, phys_addr_t >> size); >> void memblock_trim_memory(phys_addr_t align); >> bool memblock_overlaps_region(struct memblock_type *type, >> phys_addr_t base, phys_addr_t size); >> +bool memblock_node_is_crypto_capable(int nid); >> +int memblock_mark_crypto_capable(phys_addr_t base, phys_addr_t size); >> +int memblock_clear_crypto_capable(phys_addr_t base, phys_addr_t size); >> int memblock_mark_hotplug(phys_addr_t base, phys_addr_t size); >> int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size); >> int memblock_mark_mirror(phys_addr_t base, phys_addr_t size); >> diff --git a/mm/memblock.c b/mm/memblock.c >> index e4f03a6e8e56..fe62f81572e6 100644 >> --- a/mm/memblock.c >> +++ b/mm/memblock.c >> @@ -191,6 +191,40 @@ bool __init_memblock memblock_overlaps_region(struct >> memblock_type *type, >> return i < type->cnt; >> } >> >> +/** >> + * memblock_node_is_crypto_capable - get if whole node is capable >> + * of encryption >> + * @nid: number of node >> + * >> + * Iterate over all memory memblock_type and find if all regions under >> + * node @nid are capable of hardware encryption. >> + * >> + * Return: >> + * true if every region in memory memblock_type is capable of > > I'd s/in memory memblock_type/in @nid > Good, thanks. >> + * encryption, false otherwise. >> + */ >> +bool __init_memblock memblock_node_is_crypto_capable(int nid) >> +{ >> + struct memblock_region *region; >> + int crypto_capables = 0; >> + int not_crypto_capables = 0; >> + >> + for_each_mem_region(region) { >> + if (memblock_get_region_node(region) == nid) { >> + if (region->flags & MEMBLOCK_CRYPTO_CAPABLE) >> + crypto_capables++; >> + else >> + not_crypto_capables++; >> + } >> + } >> + >> + if (crypto_capables > 0 && not_crypto_capables > 0) >> + pr_warn("Node %d has %d regions that are encryptable and %d regions >> that aren't", >> + nid, not_crypto_capables, crypto_capables); >> + >> + return not_crypto_capables == 0; > > This will return true for memoryless nodes as well. Do you mean to consider > them as capable of encryption? > Not really, I didn't think about that to be honest. I don't think it's a good idea to consider them as capable, right?