From patchwork Wed Nov 24 20:34:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Fernandez X-Patchwork-Id: 12637761 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 BDD6FC433F5 for ; Wed, 24 Nov 2021 20:36:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E025D6B0078; Wed, 24 Nov 2021 15:35:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DB1C16B007B; Wed, 24 Nov 2021 15:35:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA2376B007D; Wed, 24 Nov 2021 15:35:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0060.hostedemail.com [216.40.44.60]) by kanga.kvack.org (Postfix) with ESMTP id BDE7D6B0078 for ; Wed, 24 Nov 2021 15:35:49 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 88A068D8DA for ; Wed, 24 Nov 2021 20:35:39 +0000 (UTC) X-FDA: 78844979556.24.E2528ED Received: from mail-ua1-f50.google.com (mail-ua1-f50.google.com [209.85.222.50]) by imf24.hostedemail.com (Postfix) with ESMTP id B15FBB0000A9 for ; Wed, 24 Nov 2021 20:35:35 +0000 (UTC) Received: by mail-ua1-f50.google.com with SMTP id i6so7737325uae.6 for ; Wed, 24 Nov 2021 12:35:39 -0800 (PST) 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=A1xzUXa5x5Bog8pkez/HAfQHT5aX9xfLkxwoJiQMbWc=; b=R/VkjXX7MeaPnAJhsMccTmDjScX+FGCDi/gWTGbEyxNzjTrosEp2TMkxq4Q8QqnWX3 EiR05kKzaCua2T5uLpS4x+98C9oM8i3LlhzcnBDeRGC24fGAoyeFvA1KVSV9AgEjeOVJ vH7np4lUkKx+qQHlPlhpJygvWwD869+WYK43+cFJ/C7Kd8v7ndmK5JMhk/uy9VzFsPCQ wXZsTrxo7Zt8TLdrpr5Nd9gnOKty6EwrQFR9x1l78oU9y4enfAPISe4cwYbaeioZHn+f mM5vGVQEMpumW+1F5JNtvk+ktfsQXcogAWs82IlNpm/nQEFmqB/in2eVlF72g+x7Orjp vNdw== 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=A1xzUXa5x5Bog8pkez/HAfQHT5aX9xfLkxwoJiQMbWc=; b=4oupBKO9sR9yTqHYAxVPfN8besIx645DKg91Y1E/gln4Kz2REStb6dedDjbQ/OdATO 1+606vcsBwBaMgVEIdN0qGJzToheOHnZcMMYhIo8M75MXez8feHFUT2NZacKmgSXAP3L N3/nIpkKvaOEHBHvkIaMlG6Kv0qdEOA/bLMj8FPBKKTuXiHXrgTfUZsaE5f8UlAdRg5B LRncf3Xj7vYDd2cBzg2F1LTmPTfpcwuSCLCLoeUnTtbiUe4CtXVgDans6vnHSBjSMSPC fNU/fSh/4dlucQp/28xMzFXJIt4YDRWw6p7ZRcgpnTgM3wF6ibq8LwwF0/FLEwaNNd8t QFOw== X-Gm-Message-State: AOAM5326tgNAmtku6rlOP9j5+3DCykdxQG50glPKK2OeY/djRZgN3vJ8 83ovw5dT+1hm8IgPIRmki4w31Q== X-Google-Smtp-Source: ABdhPJxrY7iEnE3QEj+1+FKnOjeDBmxUb2vIP8O2gzcsmt6jFXU8jIdP3ReeX+H4CHRVT1yoUpuYTQ== X-Received: by 2002:a67:bc16:: with SMTP id t22mr27805377vsn.10.1637786138632; Wed, 24 Nov 2021 12:35:38 -0800 (PST) Received: from localhost (7-153-16-190.fibertel.com.ar. [190.16.153.7]) by smtp.gmail.com with ESMTPSA id t11sm479278vkt.34.2021.11.24.12.35.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Nov 2021 12:35:38 -0800 (PST) From: Martin Fernandez To: linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-mm@kvack.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, ardb@kernel.org, dvhart@infradead.org, andy@infradead.org, gregkh@linuxfoundation.org, rafael@kernel.org, daniel.gutson@eclypsium.com, hughsient@gmail.com, alison.schofield@intel.com, Martin Fernandez Subject: [PATCH v2 1/5] mm/memblock: Tag memblocks with crypto capabilities Date: Wed, 24 Nov 2021 17:34:55 -0300 Message-Id: <20211124203459.4578-2-martin.fernandez@eclypsium.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211124203459.4578-1-martin.fernandez@eclypsium.com> References: <20211124203459.4578-1-martin.fernandez@eclypsium.com> MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: B15FBB0000A9 X-Stat-Signature: iupc1acw91bqcmkp7kre7dspgjkje39s Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=eclypsium.com header.s=google header.b="R/VkjXX7"; spf=pass (imf24.hostedemail.com: domain of martin.fernandez@eclypsium.com designates 209.85.222.50 as permitted sender) smtp.mailfrom=martin.fernandez@eclypsium.com; dmarc=pass (policy=quarantine) header.from=eclypsium.com X-HE-Tag: 1637786135-733610 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: 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. Signed-off-by: Martin Fernandez --- include/linux/memblock.h | 5 ++++ mm/memblock.c | 49 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 34de69b3b8ba..a54665863f80 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -31,6 +31,7 @@ extern unsigned long long max_possible_pfn; * @MEMBLOCK_HOTPLUG: hotpluggable region * @MEMBLOCK_MIRROR: mirrored region * @MEMBLOCK_NOMAP: don't add to kernel direct mapping and treat as + * @MEMBLOCK_CRYPTO_CAPABLE: capable of hardware encryption * reserved in the memory map; refer to memblock_mark_nomap() description * for further details */ @@ -39,6 +40,7 @@ enum memblock_flags { MEMBLOCK_HOTPLUG = 0x1, /* hotpluggable region */ MEMBLOCK_MIRROR = 0x2, /* mirrored region */ MEMBLOCK_NOMAP = 0x4, /* don't add to kernel direct mapping */ + MEMBLOCK_CRYPTO_CAPABLE = 0x8, /* capable of hardware encryption */ }; /** @@ -111,6 +113,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 5096500b2647..cd5553c3df5a 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -191,6 +191,27 @@ 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. + */ +bool __init_memblock memblock_node_is_crypto_capable(int nid) +{ + struct memblock_region *region; + + for_each_mem_region(region) { + if ((memblock_get_region_node(region) == nid) && + !(region->flags & MEMBLOCK_CRYPTO_CAPABLE)) + return false; + } + + return true; +} + /** * __memblock_find_range_bottom_up - find free area utility in bottom-up * @start: start of candidate range @@ -884,6 +905,34 @@ static int __init_memblock memblock_setclr_flag(phys_addr_t base, return 0; } +/** + * memblock_mark_crypto_capable - Mark memory regions capable of hardware + * encryption with flag MEMBLOCK_CRYPTO_CAPABLE. + * @base: the base phys addr of the region + * @size: the size of the region + * + * Return: 0 on success, -errno on failure. + */ +int __init_memblock memblock_mark_crypto_capable(phys_addr_t base, + phys_addr_t size) +{ + return memblock_setclr_flag(base, size, 1, MEMBLOCK_CRYPTO_CAPABLE); +} + +/** + * memblock_clear_crypto_capable - Clear flag MEMBLOCK_CRYPTO for a + * specified region. + * @base: the base phys addr of the region + * @size: the size of the region + * + * Return: 0 on success, -errno on failure. + */ +int __init_memblock memblock_clear_crypto_capable(phys_addr_t base, + phys_addr_t size) +{ + return memblock_setclr_flag(base, size, 0, MEMBLOCK_CRYPTO_CAPABLE); +} + /** * memblock_mark_hotplug - Mark hotpluggable memory with flag MEMBLOCK_HOTPLUG. * @base: the base phys addr of the region