From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40C6FC433EF for ; Tue, 26 Apr 2022 12:59:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5EB0F6B0073; Tue, 26 Apr 2022 08:59:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 599456B0074; Tue, 26 Apr 2022 08:59:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 460D66B0075; Tue, 26 Apr 2022 08:59:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 34BB36B0073 for ; Tue, 26 Apr 2022 08:59:06 -0400 (EDT) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 04D2A80253 for ; Tue, 26 Apr 2022 12:59:05 +0000 (UTC) X-FDA: 79399035492.31.F36A885 Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) by imf13.hostedemail.com (Postfix) with ESMTP id 6F38120046 for ; Tue, 26 Apr 2022 12:58:59 +0000 (UTC) Received: by mail-yb1-f172.google.com with SMTP id f38so32801191ybi.3 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=ww/axC+Zf+UzrZAVvhFv0Huq9/mgbll0i8hMbCyalX9aCtcsyhl5Hg5oByWQni+qMM OQKJES+epDJkqCVsKGxcDZxllItAHLmfK6kE1SliZEoV+cfAYcal0GqlA5gn+7MoFbMv I9Nlkr44a3bmASl2gGN/AumPN2wXy5Zai7x1PoxSwuVrcpj+QGiN6egRDj7t1Ux+HA1d qbT+rIFBLLZQoKMCz/ymn+zulgrCOa+XSDPQ/3aJ56XPi+qvQeie4eYPhjAGr+eA8lAW BwPEusqgGA4wAh8gAXQGpUVwIHob/twlZ5iAqhaorftICI7V3eL6TEi8bEyWMgVjiiTN P81g== X-Gm-Message-State: AOAM530qairMtSr8UHLD0Keb9D5hPsmN8TkkSoNsqQE1H0Ulup6gAmOe P2P5bFn0tt90yfoNy88XS4nrv8WDSef63OnwrIo6ew== X-Google-Smtp-Source: ABdhPJySiRxTZpBhh3bZw12NdC/YImhj5Q/qK8XHR85blgIx7xY01atU3xGEYkhR1DoyFQ8iXTAaEH22Gry149h26oE= 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-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 6F38120046 X-Stat-Signature: 9349rdktz11z6x7cbi9rygi9mqk1kmxe X-Rspam-User: Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=eclypsium.com header.s=google header.b=Snve9f0K; spf=pass (imf13.hostedemail.com: domain of martin.fernandez@eclypsium.com designates 209.85.219.172 as permitted sender) smtp.mailfrom=martin.fernandez@eclypsium.com; dmarc=pass (policy=quarantine) header.from=eclypsium.com X-HE-Tag: 1650977939-107313 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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?