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 166CDC433F5 for ; Tue, 26 Apr 2022 13:25:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 976476B0073; Tue, 26 Apr 2022 09:25:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FDB36B0074; Tue, 26 Apr 2022 09:25:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 778E06B0075; Tue, 26 Apr 2022 09:25:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 656DB6B0073 for ; Tue, 26 Apr 2022 09:25:57 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 3FF21604BE for ; Tue, 26 Apr 2022 13:25:57 +0000 (UTC) X-FDA: 79399103154.09.9F5CFE2 Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) by imf15.hostedemail.com (Postfix) with ESMTP id 2CA4BA0042 for ; Tue, 26 Apr 2022 13:25:52 +0000 (UTC) Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-2f7ca2ce255so82525587b3.7 for ; Tue, 26 Apr 2022 06:25:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eclypsium.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hXo185h+kObSXkmQZMr8a8mrf64dnncRTNIlAM3h4k0=; b=XhtPv0riXJD4oHpkFiEGvmxAh+OpkTuZqJNaNstrZ+03xWz4+eDhyxgf4+khWCQbOR Q2FF4wcYRcJCHhrpWxTZmaVNfpXgVtNo+IPasqov4enVnqa7Yyul0b+fWNDyrUOCCQNE DI+kns+Cp/Gut1CGsEAnh+HysYx0PipRwICaAIjbUW9alp60ozvNXxTOU50PgJI4pvuG HwWNpwWhqgpFS8X40+4VFVPQLwJDJR3cAWTLzGtACGPi2Ur6Ui1yH1N4nEPk38pF+ZeH DrZA/75cxP0cqsZpfjn/mfb6QxGqr+xYAFUlKLlearwimmc4MJv4zbwK5DkiNDeFYSRp xKcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hXo185h+kObSXkmQZMr8a8mrf64dnncRTNIlAM3h4k0=; b=MbE3+qYaqXl6rcouCa04QUEDmHf5f0wcFj0x+zZ4H+IQA36EeajXCJV6BugTL7EBKy qr0JRLXeKaCimXq0S3grT2LkiES7lC5jRYBaA4d7Z7MVts74mwKuHYCVUQ/9g5szAmBM hTsJpBOhfgTZw3RghVQ8oaQCqb5QgDoxDFHapNvk0fwcAox36WDOW9uKai39UXvS63xf tr8T5LoMCRAZPLrgl0RiXpRIttCFQmt5+o10oHiszoziJYC5cp1bHkU6hax9ngeHOI3P rn9Me2wtFY+bfDvsoOGX7Jzr19Py0SoWYf6hdgiNj+V3tTBanDzoA+Rw4phvLrsCARbW WzMA== X-Gm-Message-State: AOAM530eOgcZ8/1o+DWcNDy6hutjN4XjfQROHEcjt/P5ZIE1mPVFkW69 lZVnqMIli9eMhonmiOSwy6w1HrgLd4RU9Dv510MLlw== X-Google-Smtp-Source: ABdhPJyeUmVpGb8SXBarAcmmHFvinXgebrIrvNFeIufykRJ4H//aeaz5HNCbHAftyJ7CTjQF/0WXHFIa0gYB6LJ9lms= X-Received: by 2002:a81:7895:0:b0:2f1:6933:3b66 with SMTP id t143-20020a817895000000b002f169333b66mr21694519ywc.239.1650979555989; Tue, 26 Apr 2022 06:25:55 -0700 (PDT) MIME-Version: 1.0 References: <20220425171526.44925-1-martin.fernandez@eclypsium.com> <20220425171526.44925-2-martin.fernandez@eclypsium.com> In-Reply-To: From: Daniel Gutson Date: Tue, 26 Apr 2022 10:25:45 -0300 Message-ID: Subject: Re: [PATCH v7 1/8] mm/memblock: Tag memblocks with crypto capabilities To: Mike Rapoport Cc: Martin Fernandez , linux-kernel , linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-mm@kvack.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , ardb@kernel.org, dvhart@infradead.org, andy@infradead.org, Greg Kroah-Hartman , rafael@kernel.org, akpm@linux-foundation.org, Richard Hughes , Alex Bazhaniuk , Alison Schofield , Kees Cook Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: iprw5iwgza3oatk859a7t5hriujct4w7 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2CA4BA0042 X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=eclypsium.com header.s=google header.b=XhtPv0ri; dmarc=pass (policy=quarantine) header.from=eclypsium.com; spf=pass (imf15.hostedemail.com: domain of daniel.gutson@eclypsium.com designates 209.85.128.181 as permitted sender) smtp.mailfrom=daniel.gutson@eclypsium.com X-HE-Tag: 1650979552-532825 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 Tue, Apr 26, 2022 at 10:21 AM Mike Rapoport wrote: > > On Tue, Apr 26, 2022 at 09:59:04AM -0300, Martin Fernandez wrote: > > 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? > > I think capable of encryption would mean > > crypto_capables && !not_crypto_capables Since these operands were evaluated above with comparison ops, I would say crypto_capables > 0 && not_crypto_capables == 0 to improve readability and be explicit that they are numbers rather than booleans. > > -- > Sincerely yours, > Mike.