From nobody Tue Jun 30 15:33:48 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29EA7C4332F for ; Thu, 13 Jan 2022 21:30:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235720AbiAMVau (ORCPT ); Thu, 13 Jan 2022 16:30:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235615AbiAMVas (ORCPT ); Thu, 13 Jan 2022 16:30:48 -0500 Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A427AC06173F for ; Thu, 13 Jan 2022 13:30:48 -0800 (PST) Received: by mail-ot1-x32f.google.com with SMTP id a12-20020a0568301dcc00b005919e149b4cso7888446otj.8 for ; Thu, 13 Jan 2022 13:30:48 -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=7RqfR1RKHyt56B3HaINQqKrkUmepffSj3WABI23dqNA=; b=DXOplbCa3rlaTR1lzXo0syR+d0dk0Ki3jfBTsW21qNTvRNb67a7rQFafgRjnsDG0xl IMRYzB1c3zKfRhmQ4H/ZAWy6s7cnRvC7aZSZn2Pv4CNgOjM/N2zri/+3hOHGnv5FBdDE T6EdwD/rbF7IK9lKa0gCFgot6HuowyV2kGQ49C28bv7WWSLmDkXMbIf89xOzCJQfqfsx ukB78kPc4izKs5xECbE7mKdDOAj9JbkAO0IUOhMkikVSrhoW61a4HvH4TTTN0HXr8kwt sqAldQmHRJIB6ys53jbqjMR534CpJY9uOp+L5ed+jr1HukdwMAvLFVNzka/GtcGQpD+b 686Q== 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=7RqfR1RKHyt56B3HaINQqKrkUmepffSj3WABI23dqNA=; b=o9khxdQYMjs6N4EN9BQdz11sAMy5ohCPZLXjwwsBlBSd1ndyCtJPVyJ3Fp86YUBDS9 qZSfHM6AwZ0VimpRUfECWsGEMppIioa6pG2SL6OXQnRy+CtJobChC/8e2FxcrsPtO6qw bHwA3IsPGC9mtJwKGYulmt14hE2f8+cGuss1b9/BFJLWrfoPF6pzKXKNHILKXxBnLIxH WMyPLs4N+HTrEc54WfVX44tAB8GulxKGnQeA10i5+RggiZk089W1jBzFXF35X/8rZF/A 4OhJAZXuCkhN4g+Osh3Q0pFXoPq/WGodg8l9wYd+wP4nMx4ZxnFElfq0lu8hYEe/Ock8 BfYw== X-Gm-Message-State: AOAM532Mbf9i2LpO0rxYmnpd1roFEhSNd2dR4zQNtCzOdIBnFMuZxmI3 LO0Y4S+/4ViGYY/rhijaaS/fz0PTP6t43Q0hI6bPh+u4aIazeF+twQEUO/5YEgPfn4c3uphQj3Y Wz1OnfVt9ocyamgfw7d5vyyHlKFk449hZNt5JtRchJfgOFjFTwBOXnQI3yemsVCcn0qwHjENY92 9zbtxxuqeyCkRCt0tM3gQ= X-Google-Smtp-Source: ABdhPJxohhMZ86BwQjPzKMMIL7CIogMV+YYOB+Qz4+6WClsKEC8ODPW1XtId8mIcWO0OAl/kvVANfg== X-Received: by 2002:a9d:7e84:: with SMTP id m4mr1134058otp.269.1642109447444; Thu, 13 Jan 2022 13:30:47 -0800 (PST) Received: from localhost (115-127-16-190.fibertel.com.ar. [190.16.127.115]) by smtp.gmail.com with ESMTPSA id s124sm971747ooa.1.2022.01.13.13.30.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Jan 2022 13:30:47 -0800 (PST) From: Martin Fernandez To: linux-kernel@vger.kernel.org, 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, 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, Martin Fernandez Subject: [PATCH v5 1/5] mm/memblock: Tag memblocks with crypto capabilities Date: Thu, 13 Jan 2022 18:30:23 -0300 Message-Id: <20220113213027.457282-2-martin.fernandez@eclypsium.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220113213027.457282-1-martin.fernandez@eclypsium.com> References: <20220113213027.457282-1-martin.fernandez@eclypsium.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 9dc7cb239d21..374c03e10b2e 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -41,6 +41,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 =3D 0x0, /* No special request */ @@ -48,6 +49,7 @@ enum memblock_flags { MEMBLOCK_MIRROR =3D 0x2, /* mirrored region */ MEMBLOCK_NOMAP =3D 0x4, /* don't add to kernel direct mapping */ MEMBLOCK_DRIVER_MANAGED =3D 0x8, /* always detected via a driver */ + MEMBLOCK_CRYPTO_CAPABLE =3D 0x10, /* capable of hardware encryption */ }; =20 /** @@ -121,6 +123,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 1018e50566f3..61ec50647469 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -191,6 +191,27 @@ bool __init_memblock memblock_overlaps_region(struct m= emblock_type *type, return i < type->cnt; } =20 +/** + * 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) =3D=3D 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 @@ -885,6 +906,34 @@ static int __init_memblock memblock_setclr_flag(phys_a= ddr_t base, return 0; } =20 +/** + * 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_HOT= PLUG. * @base: the base phys addr of the region --=20 2.30.2 From nobody Tue Jun 30 15:33:48 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C83FC433FE for ; Thu, 13 Jan 2022 21:30:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235805AbiAMVa5 (ORCPT ); Thu, 13 Jan 2022 16:30:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235732AbiAMVaz (ORCPT ); Thu, 13 Jan 2022 16:30:55 -0500 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2738C061574 for ; Thu, 13 Jan 2022 13:30:55 -0800 (PST) Received: by mail-oi1-x236.google.com with SMTP id s22so9629094oie.10 for ; Thu, 13 Jan 2022 13:30:55 -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=dL7Kyw5R5uEJ5iFptCvOaKv8TqVxuhvnFOanF/ug8Oo=; b=hTJNWfpBwWHBXmDAw3gLRIR3djfB+sK2GlFOBYJqrMUl/HiEOQGTQoo9yPe+EWanj8 09iUccyveauB4v3d65kz1O/ho3Hm/bg/9JXoxX/39geyyvUSYl7Inx2ynNhG0bWLzbpn EhhJY776tO9ns0OiI1tOeBENLXIyLkzA684P1WLxGNGqws0uGjPbRBPU5veXOLw9SsuS sn3lT/ZzP9jS25qxkumsln1WApOkQJktI9Dttaw8+F4U2YuMu9KuwzQXeQD5eStbo8be jFu7gWvEVQSC3a7lZHb8H3fUXEgA5MBfzyC3EvB7UVpfZhnFE+7z3A1haLlxBc5tRlw/ 2s0w== 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=dL7Kyw5R5uEJ5iFptCvOaKv8TqVxuhvnFOanF/ug8Oo=; b=GmkODeMB4D4vkW34sn5Zw1u4W6LDNhXYyW4U8vS4x8p5nKnzSsOkTob//L6TXJYoHe +irV/kGHm/QFRge7TwLY7csr8fC8+sjxNfOsgW9pmOIuXRLQ5mN6QhtPvtMOvo0dg5lP T7WYzNV6lPwp3eb5acabM8lb4EDWand0GXqHPpx+v7TAMxuPPdMhr2LCUKCHxEhoB3TW GqKwGod+1eWi5KYi+XVaZh1KEhq22slC0OFXf0otJbDPz7qd4TsUDCCWXjlP3/weVg2v nNG576jcXXbEbLrYmXirMGc62EDo7PBELTLWOxABpmy1U5BnYKHeogtFGsbOQcgTm5uR +2aw== X-Gm-Message-State: AOAM532NJQHZ++qZ4EdK6ALXLfp3N0vgSXuBKXB1HkaaRrLxwjryd8BI 5vd9QXF59GR6XmksGGSaeq6BitUTabKeoUrbz95hh/mjz1XDol7kUmMAuVT2+Vm0LSpBY4WNt7y K0dpYUzB7bpgZea9+Mxwz0w3t6H/e5o7wP0+NHeyr+IZTGTe2UlMWMjt4fMliD4RVZjSlo8n8hP O555l4B0nnbWpv+bJ+8wQ= X-Google-Smtp-Source: ABdhPJzDN1onylDe2EOdadMwtWVnznDi7osDVKOSlKgZ23uvQiFvC/0MpSn76QDva8qLZ5/xZMp8EQ== X-Received: by 2002:aca:a80d:: with SMTP id r13mr8142853oie.21.1642109454826; Thu, 13 Jan 2022 13:30:54 -0800 (PST) Received: from localhost (115-127-16-190.fibertel.com.ar. [190.16.127.115]) by smtp.gmail.com with ESMTPSA id i18sm626212oob.41.2022.01.13.13.30.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Jan 2022 13:30:54 -0800 (PST) From: Martin Fernandez To: linux-kernel@vger.kernel.org, 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, 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, Martin Fernandez Subject: [PATCH v5 2/5] mm/mmzone: Tag pg_data_t with crypto capabilities Date: Thu, 13 Jan 2022 18:30:24 -0300 Message-Id: <20220113213027.457282-3-martin.fernandez@eclypsium.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220113213027.457282-1-martin.fernandez@eclypsium.com> References: <20220113213027.457282-1-martin.fernandez@eclypsium.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a new member in the pg_data_t struct tell whether the node corresponding to that pg_data_t is able to do hardware memory encryption. This will be read from sysfs. Signed-off-by: Martin Fernandez --- include/linux/mmzone.h | 3 +++ mm/page_alloc.c | 1 + 2 files changed, 4 insertions(+) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 936dc0b6c226..cec51e7a01d9 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -871,6 +871,9 @@ typedef struct pglist_data { struct task_struct *kcompactd; bool proactive_compact_trigger; #endif + + bool crypto_capable; + /* * This is a per-node reserve of pages that are not available * to userspace allocations. diff --git a/mm/page_alloc.c b/mm/page_alloc.c index c5952749ad40..8bcbd6fa0089 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7592,6 +7592,7 @@ static void __init free_area_init_node(int nid) pgdat->node_id =3D nid; pgdat->node_start_pfn =3D start_pfn; pgdat->per_cpu_nodestats =3D NULL; + pgdat->crypto_capable =3D memblock_node_is_crypto_capable(nid); =20 pr_info("Initmem setup node %d [mem %#018Lx-%#018Lx]\n", nid, (u64)start_pfn << PAGE_SHIFT, --=20 2.30.2 From nobody Tue Jun 30 15:33:48 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07184C433F5 for ; Thu, 13 Jan 2022 21:31:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235919AbiAMVbG (ORCPT ); Thu, 13 Jan 2022 16:31:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232021AbiAMVbD (ORCPT ); Thu, 13 Jan 2022 16:31:03 -0500 Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41D7AC06173F for ; Thu, 13 Jan 2022 13:31:03 -0800 (PST) Received: by mail-ot1-x32b.google.com with SMTP id c3-20020a9d6c83000000b00590b9c8819aso7894812otr.6 for ; Thu, 13 Jan 2022 13:31:03 -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=VAoRDHUwm1eMqcpMENH9/PXAOANb+EVYwXPhK3cnDlE=; b=WyLcYtkIoEuLzTKFelzWIIRxp2otZLIQNxuK8bOnSYN8hupRQ5twgB0y0nOgm9LYFa LkAoZE1KMLj54jhKyrRJKAQqIJA14pYL74bk98T29Vh+BnfHFUucPEVK4w3iyY7ZdvGK pGjvFfLkY6pwUTtTZtUzLbQ5gMtDz5tIjSoHomVEsuwyR7v2K8XmkZ9C8zVC1fGigot+ 4W8pYmormQTKPOxQmpnBLhCcUUx0NNvVXMqYr2klyHUUjvnr4A7pWc0tPammCG0NePdk FwdYdvLw9/t+tdwWfW+77N9PncJIuQ3Q3L5hWbr//+w2wzULi2HBhfkJE1Wty1NZrfgE bi0g== 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=VAoRDHUwm1eMqcpMENH9/PXAOANb+EVYwXPhK3cnDlE=; b=QjC7GaLa7jOJicLHbf/WM6be2FoqwGMULt/Y27QZat6u8P+PR8xi7Xn5AW3Zr+/SEO 7+umLHbdyaed5shszyMfxI8LdzW/gJ6QCVtSAv2y7sQE/iYjfJVzVhsjCY/i+Pp//bLY n8H/QSl1MCkLlszKeFTf9ugewD4mM2FwB1z5Rr2hCLNZoeKOygfFr1tMk162b3rgmfsF pzZGLZzDWnQWjl27wPMCWKVlLNh0ePOvQ/ESQ9uSMxqPSjXxR4PqUBGhb4CkhiIIhJLc Q1GK/uTC1fBzfzVw7feQily9+UyqQNtClo6vSlTvWHCLCSdafH4evaI4vr7+hhioGuqv ZVVA== X-Gm-Message-State: AOAM530yOFl7ZSQ4Gnf0tWZOgIEz3Ju3YjSVW+xlnhR4mhj+poDS50vY JzdzW3+YTwVam/4IUNtejPCcj0pUFIAQ817tSA3ZqzM1BZMRve5sIJMw1nzLvyexgXVUpwOpEtZ yeqfdcHiLdXEJx760tQqS/3NCM6k+Zn8CDKduAzLNQYs4pvDVhzFiHJ0ORtwC7xXzzEIIaWcowa ypE4853C5L+3lrESZEwZY= X-Google-Smtp-Source: ABdhPJzPsE5o2ZryrBn+0ysWSz+aUIEFzgLWkqw12mZ95CWeEziw/kOfErJzDUXmn2mxu4nyuUtYMg== X-Received: by 2002:a05:6830:2694:: with SMTP id l20mr4819858otu.242.1642109462316; Thu, 13 Jan 2022 13:31:02 -0800 (PST) Received: from localhost (115-127-16-190.fibertel.com.ar. [190.16.127.115]) by smtp.gmail.com with ESMTPSA id i25sm880263otl.8.2022.01.13.13.30.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Jan 2022 13:31:01 -0800 (PST) From: Martin Fernandez To: linux-kernel@vger.kernel.org, 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, 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, Martin Fernandez Subject: [PATCH v5 3/5] x86/e820: Tag e820_entry with crypto capabilities Date: Thu, 13 Jan 2022 18:30:25 -0300 Message-Id: <20220113213027.457282-4-martin.fernandez@eclypsium.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220113213027.457282-1-martin.fernandez@eclypsium.com> References: <20220113213027.457282-1-martin.fernandez@eclypsium.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a new enum for crypto capabilities. Add a new member in e820_entry to hold whether an entry is able to do hardware memory encryption or not. Add a new function __e820__range_update_crypto similar to __e820__range_update but to update crypto capabilities. Change e820__update_table to handle merging and overlap problems taking into account crypto_capable. Add a function to mark a range as crypto, using __e820__range_update_crypto in the background. This will be called when initializing EFI. Signed-off-by: Martin Fernandez --- arch/x86/include/asm/e820/api.h | 1 + arch/x86/include/asm/e820/types.h | 12 +++- arch/x86/kernel/e820.c | 112 ++++++++++++++++++++++++++++-- 3 files changed, 115 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/ap= i.h index e8f58ddd06d9..677dcbabcc8b 100644 --- a/arch/x86/include/asm/e820/api.h +++ b/arch/x86/include/asm/e820/api.h @@ -17,6 +17,7 @@ extern bool e820__mapped_all(u64 start, u64 end, enum e82= 0_type type); extern void e820__range_add (u64 start, u64 size, enum e820_type type); extern u64 e820__range_update(u64 start, u64 size, enum e820_type old_typ= e, enum e820_type new_type); extern u64 e820__range_remove(u64 start, u64 size, enum e820_type old_typ= e, bool check_type); +extern u64 e820__range_mark_as_crypto_capable(u64 start, u64 size); =20 extern void e820__print_table(char *who); extern int e820__update_table(struct e820_table *table); diff --git a/arch/x86/include/asm/e820/types.h b/arch/x86/include/asm/e820/= types.h index 314f75d886d0..aef03c665f5e 100644 --- a/arch/x86/include/asm/e820/types.h +++ b/arch/x86/include/asm/e820/types.h @@ -46,6 +46,11 @@ enum e820_type { E820_TYPE_RESERVED_KERN =3D 128, }; =20 +enum e820_crypto_capabilities { + E820_NOT_CRYPTO_CAPABLE =3D 0, + E820_CRYPTO_CAPABLE =3D 1, +}; + /* * A single E820 map entry, describing a memory range of [addr...addr+size= -1], * of 'type' memory type: @@ -53,9 +58,10 @@ enum e820_type { * (We pack it because there can be thousands of them on large systems.) */ struct e820_entry { - u64 addr; - u64 size; - enum e820_type type; + u64 addr; + u64 size; + enum e820_type type; + enum e820_crypto_capabilities crypto_capable; } __attribute__((packed)); =20 /* diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index bc0657f0deed..bbf67b77bd18 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -163,7 +163,9 @@ int e820__get_entry_type(u64 start, u64 end) /* * Add a memory region to the kernel E820 map. */ -static void __init __e820__range_add(struct e820_table *table, u64 start, = u64 size, enum e820_type type) +static void __init __e820__range_add(struct e820_table *table, u64 start, + u64 size, enum e820_type type, + enum e820_crypto_capabilities crypto_capable) { int x =3D table->nr_entries; =20 @@ -176,12 +178,13 @@ static void __init __e820__range_add(struct e820_tabl= e *table, u64 start, u64 si table->entries[x].addr =3D start; table->entries[x].size =3D size; table->entries[x].type =3D type; + table->entries[x].crypto_capable =3D crypto_capable; table->nr_entries++; } =20 void __init e820__range_add(u64 start, u64 size, enum e820_type type) { - __e820__range_add(e820_table, start, size, type); + __e820__range_add(e820_table, start, size, type, E820_NOT_CRYPTO_CAPABLE); } =20 static void __init e820_print_type(enum e820_type type) @@ -211,6 +214,8 @@ void __init e820__print_table(char *who) e820_table->entries[i].addr + e820_table->entries[i].size - 1); =20 e820_print_type(e820_table->entries[i].type); + if (e820_table->entries[i].crypto_capable =3D=3D E820_CRYPTO_CAPABLE) + pr_cont("; crypto-capable"); pr_cont("\n"); } } @@ -327,6 +332,7 @@ int __init e820__update_table(struct e820_table *table) unsigned long long last_addr; u32 new_nr_entries, overlap_entries; u32 i, chg_idx, chg_nr; + enum e820_crypto_capabilities current_crypto, last_crypto; =20 /* If there's only one memory region, don't bother: */ if (table->nr_entries < 2) @@ -367,6 +373,7 @@ int __init e820__update_table(struct e820_table *table) new_nr_entries =3D 0; /* Index for creating new map entries */ last_type =3D 0; /* Start with undefined memory type */ last_addr =3D 0; /* Start with 0 as last starting address */ + last_crypto =3D E820_NOT_CRYPTO_CAPABLE; =20 /* Loop through change-points, determining effect on the new map: */ for (chg_idx =3D 0; chg_idx < chg_nr; chg_idx++) { @@ -388,13 +395,19 @@ int __init e820__update_table(struct e820_table *tabl= e) * 1=3Dusable, 2,3,4,4+=3Dunusable) */ current_type =3D 0; + current_crypto =3D E820_CRYPTO_CAPABLE; for (i =3D 0; i < overlap_entries; i++) { + if (overlap_list[i]->crypto_capable < current_crypto) + current_crypto =3D overlap_list[i]->crypto_capable; + if (overlap_list[i]->type > current_type) current_type =3D overlap_list[i]->type; } =20 /* Continue building up new map based on this information: */ - if (current_type !=3D last_type || e820_nomerge(current_type)) { + if (current_type !=3D last_type || + current_crypto !=3D last_crypto || + e820_nomerge(current_type)) { if (last_type !=3D 0) { new_entries[new_nr_entries].size =3D change_point[chg_idx]->addr - las= t_addr; /* Move forward only if the new size was non-zero: */ @@ -406,9 +419,12 @@ int __init e820__update_table(struct e820_table *table) if (current_type !=3D 0) { new_entries[new_nr_entries].addr =3D change_point[chg_idx]->addr; new_entries[new_nr_entries].type =3D current_type; + new_entries[new_nr_entries].crypto_capable =3D current_crypto; + last_addr =3D change_point[chg_idx]->addr; } last_type =3D current_type; + last_crypto =3D current_crypto; } } =20 @@ -497,8 +513,80 @@ __e820__range_update(struct e820_table *table, u64 sta= rt, u64 size, enum e820_ty =20 /* New range is completely covered? */ if (entry->addr < start && entry_end > end) { - __e820__range_add(table, start, size, new_type); - __e820__range_add(table, end, entry_end - end, entry->type); + __e820__range_add(table, start, size, new_type, entry->crypto_capable); + __e820__range_add(table, end, entry_end - end, entry->type, entry->cryp= to_capable); + entry->size =3D start - entry->addr; + real_updated_size +=3D size; + continue; + } + + /* Partially covered: */ + final_start =3D max(start, entry->addr); + final_end =3D min(end, entry_end); + if (final_start >=3D final_end) + continue; + + __e820__range_add(table, final_start, final_end - final_start, + new_type, entry->crypto_capable); + + real_updated_size +=3D final_end - final_start; + + /* + * Left range could be head or tail, so need to update + * its size first: + */ + entry->size -=3D final_end - final_start; + if (entry->addr < final_start) + continue; + + entry->addr =3D final_end; + } + return real_updated_size; +} + +/* + * Update crypto capabilities in a range + */ +static u64 __init __e820__range_update_crypto(struct e820_table *table, + u64 start, u64 size, + enum e820_crypto_capabilities crypto_capable) +{ + u64 end; + unsigned int i; + u64 real_updated_size =3D 0; + + if (size > (ULLONG_MAX - start)) + size =3D ULLONG_MAX - start; + + end =3D start + size; + printk(KERN_DEBUG "e820: update crypto capabilities [mem %#018Lx-%#018Lx]= ", start, end - 1); + pr_cont(" =3D=3D> "); + if (crypto_capable =3D=3D E820_CRYPTO_CAPABLE) + pr_cont("crypto capable"); + else + pr_cont("not crypto capable"); + pr_cont("\n"); + + for (i =3D 0; i < table->nr_entries; i++) { + struct e820_entry *entry =3D &table->entries[i]; + u64 final_start, final_end; + u64 entry_end; + enum e820_type type =3D entry->type; + + entry_end =3D entry->addr + entry->size; + + /* Completely covered by new range? */ + if (entry->addr >=3D start && entry_end <=3D end) { + entry->crypto_capable =3D crypto_capable; + real_updated_size +=3D entry->size; + continue; + } + + /* New range is completely covered? */ + if (entry->addr < start && entry_end > end) { + __e820__range_add(table, start, size, type, crypto_capable); + __e820__range_add(table, end, entry_end - end, + type, entry->crypto_capable); entry->size =3D start - entry->addr; real_updated_size +=3D size; continue; @@ -510,7 +598,8 @@ __e820__range_update(struct e820_table *table, u64 star= t, u64 size, enum e820_ty if (final_start >=3D final_end) continue; =20 - __e820__range_add(table, final_start, final_end - final_start, new_type); + __e820__range_add(table, final_start, final_end - final_start, + type, crypto_capable); =20 real_updated_size +=3D final_end - final_start; =20 @@ -527,6 +616,11 @@ __e820__range_update(struct e820_table *table, u64 sta= rt, u64 size, enum e820_ty return real_updated_size; } =20 +u64 __init e820__range_mark_as_crypto_capable(u64 start, u64 size) +{ + return __e820__range_update_crypto(e820_table, start, size, E820_CRYPTO_C= APABLE); +} + u64 __init e820__range_update(u64 start, u64 size, enum e820_type old_type= , enum e820_type new_type) { return __e820__range_update(e820_table, start, size, old_type, new_type); @@ -572,7 +666,9 @@ u64 __init e820__range_remove(u64 start, u64 size, enum= e820_type old_type, bool =20 /* Is the new range completely covered? */ if (entry->addr < start && entry_end > end) { - e820__range_add(end, entry_end - end, entry->type); + __e820__range_add(e820_table, end, entry_end - end, + entry->type, entry->crypto_capable); + entry->size =3D start - entry->addr; real_removed_size +=3D size; continue; @@ -1322,6 +1418,8 @@ void __init e820__memblock_setup(void) continue; =20 memblock_add(entry->addr, entry->size); + if (entry->crypto_capable =3D=3D E820_CRYPTO_CAPABLE) + memblock_mark_crypto_capable(entry->addr, entry->size); } =20 /* Throw away partial pages: */ --=20 2.30.2 From nobody Tue Jun 30 15:33:48 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9030C4332F for ; Thu, 13 Jan 2022 21:31:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235859AbiAMVbN (ORCPT ); Thu, 13 Jan 2022 16:31:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235987AbiAMVbK (ORCPT ); Thu, 13 Jan 2022 16:31:10 -0500 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 717F9C06173E for ; Thu, 13 Jan 2022 13:31:10 -0800 (PST) Received: by mail-oi1-x22e.google.com with SMTP id s22so9630024oie.10 for ; Thu, 13 Jan 2022 13:31:10 -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=AYRnV1Ist1vARSPSnF2rw/yrtuWCrI0ayDUHb4fDzqo=; b=SMckg/nzX83RUT38HDVqXqL/+USSoRNwE2qeb9u2fYcDf+eHn88PcolAkaromVaRG0 X9VARu1HxmUUQ+XnYnc8deAHrPHJMxBP/1z8wreMqEXwVx/hvMJmU06GCgHeA/6VOm2Y dat7Xi9MT9cyH7FmNRqX48xelGVsT2QmygWkut/XwSUtbg3La7lqRzsF+VomJc0W+1ja CsLbpSGOM33Rx28bmwbanQ7ojQNPBvOh4uIVreW2qM+AdaszzP/K5bFlUU6f8JEjuI6c XMeDY4gmsPzxHxeKqh3QO/CCvk8naON6KAe+OyK3/iV/j4dl+Pd8xNw2MeZyWFUfGxOT f4fQ== 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=AYRnV1Ist1vARSPSnF2rw/yrtuWCrI0ayDUHb4fDzqo=; b=U6qp8tD26x5mB4qFWCQ06ofDiHPbfIalbtDqq+uryyBlP39sPcR3R/0K+/f7Z4k3TB wMhj37Q0XO2HMkBU/J9NLqsrdiXWGdXQpb4xaN9pbo+UwYVUZjPoc8ynWUnED+qYul6i D/FWxbcPHGFbLDlL2Ji9dOH87bKgCjKdRWuR0vE44ABehNBnzIuf3B+qvY9cytJ8s8wj EF/D//gYQ4koyIQMmfTt098Hj3yhI1k//Vm+mwoNlMMYSkp2rIp5Ll9nFsHkU3EPi96W t1WPVr9kJEgQsA4611NJe7SrIi/0SCTpLea841DcYv8I25gBL/LdlkRP2joe+CsIDbkZ 0JTw== X-Gm-Message-State: AOAM532b2/KRlP768BrJ22rbQlY+lWvnhHsg/JfduD1X3wEkkPCxeqpk YOK07XFGuwzZuqtj6MY0aaUR8penbN/J42SkiX17AKX1mdmVh03Jt2Pb+Wd96377rkJ2P/GRwRu WhZiFQpz3TrpoJIIX7/VkW3jk3DdUXpOmfIn91qEDjAzasCO6uNcEhrHwSx/L9dxsT1H1HkxWq6 SeV/ORVsSZeI1902zwSNg= X-Google-Smtp-Source: ABdhPJwEYr2CLO1fRtR6rM6IJUk2OdrzSIfOZW8PCuyuo97iz5DyT8grICu19f+pXA46UCcnMK86AQ== X-Received: by 2002:a05:6808:2382:: with SMTP id bp2mr5091455oib.164.1642109469690; Thu, 13 Jan 2022 13:31:09 -0800 (PST) Received: from localhost (115-127-16-190.fibertel.com.ar. [190.16.127.115]) by smtp.gmail.com with ESMTPSA id i7sm908931oot.17.2022.01.13.13.31.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Jan 2022 13:31:09 -0800 (PST) From: Martin Fernandez To: linux-kernel@vger.kernel.org, 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, 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, Martin Fernandez Subject: [PATCH v5 4/5] x86/efi: Tag e820_entries as crypto capable from EFI memmap Date: Thu, 13 Jan 2022 18:30:26 -0300 Message-Id: <20220113213027.457282-5-martin.fernandez@eclypsium.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220113213027.457282-1-martin.fernandez@eclypsium.com> References: <20220113213027.457282-1-martin.fernandez@eclypsium.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Martin Fernandez --- arch/x86/platform/efi/efi.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index 147c30a81f15..ce2f9d38fe36 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -184,6 +184,8 @@ static void __init do_add_efi_memmap(void) } =20 e820__range_add(start, size, e820_type); + if (md->attribute & EFI_MEMORY_CPU_CRYPTO) + e820__range_mark_as_crypto_capable(start, size); } e820__update_table(e820_table); } @@ -441,6 +443,23 @@ static int __init efi_config_init(const efi_config_tab= le_type_t *arch_tables) return ret; } =20 +static void __init efi_mark_e820_regions_as_crypto_capable(void) +{ + efi_memory_desc_t *md; + + for_each_efi_memory_desc(md) { + if (md->attribute & EFI_MEMORY_CPU_CRYPTO) + e820__range_mark_as_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) && @@ -494,6 +513,13 @@ void __init efi_init(void) set_bit(EFI_RUNTIME_SERVICES, &efi.flags); efi_clean_memmap(); =20 + /* + * 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(); } --=20 2.30.2 From nobody Tue Jun 30 15:33:48 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C463C433FE for ; Thu, 13 Jan 2022 21:31:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236112AbiAMVb3 (ORCPT ); Thu, 13 Jan 2022 16:31:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236079AbiAMVbR (ORCPT ); Thu, 13 Jan 2022 16:31:17 -0500 Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DD8CC061574 for ; Thu, 13 Jan 2022 13:31:17 -0800 (PST) Received: by mail-oi1-x229.google.com with SMTP id i9so9675598oih.4 for ; Thu, 13 Jan 2022 13:31:17 -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=yVN27if4TLsRCEMhCF/aqw8r/7THOayqDLYA7IAtavc=; b=cl/0zLZFJiGx8sFR5y9ZQu0me7yAE4sNXzqAJwzAbdsxRpWRMgUShOFWYq8N1hPJY2 48lcCYaUXpUWBAmmXMep3197PfpmGKcgBMTygUt3HNfyP7uOOgBxNz99RILKcZoRYfqs Zt/3R6UjOLJefC5vcjn7sL1MXjc3KjmC+NQjSymVxGXKyYrGFTRPKZcRuLkkEg6NPefk U12lx/o3FRe8+qmMzea5DJ5DLvKXyzTANaRZcV9oVsgPU8w8f/XvJ3Tac1oXIB+RUkGf hwj4x2EZC7kxNZHRPe0QXebw4HB5BaulW7Esu1JdDEw+fpJCtRbhSQoxMNwuGdoSTe3I L08Q== 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=yVN27if4TLsRCEMhCF/aqw8r/7THOayqDLYA7IAtavc=; b=Sh9TdXIx0JAp9V5j9oN4ktJtNOhqhlJcYXnXUYqdeMOQagWA4rJTuYD3tWgK4Zz7AE lJoC9JX/TmcnJ9R0RRlH+gfmK/tckRqY+UNaZyk3uFwEXUwUn6EyDKMXJhxyCtc5hp4c 6+NjETartfN5yPC+7qQFOoQlr9Q2Q2uT++7yzOuperUPB/bfdtuJQcRUcGtXlg757yc7 Oj0WjbVDUNR1XLoy2ew0hefrMk38ZwDm8tr64ztgP+U95WSnifvhsfzPCPMC+j4Y7Z0p Dyrc2tHdheBTCE85NLtzBjc5lhVQiTerAEiRbr4fdtWFcWRW7uitG3cc7mXX/zY8QObP Iw7Q== X-Gm-Message-State: AOAM530SeYyK2z9H79D1Qrzj4eF6QRVtyGMkv2GwrLsE7JAE6g8u3fmy 73/JCVZ6Iav7gKtl14jONHd7CQF6SKkFqjTr3bbIM6/cKxPZE110hc5eMigGR8dK6Km1Nrrsa3E 4jxV/qO0dpsUzmJAUrRJwzcxO6bwr6/Cqgapd9N6oK4dUB7QCz3wJI4NT30pZ6giFY2+zBYEldw 3i1iNg1v+hUkPVcmmnrn8= X-Google-Smtp-Source: ABdhPJxJcXPnlOWnI9M6Jnqh9i6KsB4TBvlTnQrIc/FadDEsjuKYa97ar6lwUiV86vnw2DEkK9FwHA== X-Received: by 2002:a05:6808:1a83:: with SMTP id bm3mr3785579oib.53.1642109476722; Thu, 13 Jan 2022 13:31:16 -0800 (PST) Received: from localhost (115-127-16-190.fibertel.com.ar. [190.16.127.115]) by smtp.gmail.com with ESMTPSA id o130sm1040829oig.26.2022.01.13.13.31.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Jan 2022 13:31:16 -0800 (PST) From: Martin Fernandez To: linux-kernel@vger.kernel.org, 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, 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, Martin Fernandez Subject: [PATCH v5 5/5] drivers/node: Show in sysfs node's crypto capabilities Date: Thu, 13 Jan 2022 18:30:27 -0300 Message-Id: <20220113213027.457282-6-martin.fernandez@eclypsium.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220113213027.457282-1-martin.fernandez@eclypsium.com> References: <20220113213027.457282-1-martin.fernandez@eclypsium.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Show in each node in sysfs if its memory is able to do be encrypted by the CPU, ie. if all its memory is marked with EFI_MEMORY_CPU_CRYPTO in the EFI memory map. Signed-off-by: Martin Fernandez --- Documentation/ABI/testing/sysfs-devices-node | 10 ++++++++++ drivers/base/node.c | 10 ++++++++++ 2 files changed, 20 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-devices-node diff --git a/Documentation/ABI/testing/sysfs-devices-node b/Documentation/A= BI/testing/sysfs-devices-node new file mode 100644 index 000000000000..7c0480580670 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-devices-node @@ -0,0 +1,10 @@ +What: /sys/devices/system/node/nodeX/crypto_capable +Date: January 2022 +Contact: Martin Fernandez +Users: fwupd (https://fwupd.org) +Description: + This value is 1 if all system memory in this node is + marked with EFI_MEMORY_CPU_CRYPTO, indicating that the + system memory is capable of being protected with the + CPU=E2=80=99s memory cryptographic capabilities. It is 0 + otherwise. \ No newline at end of file diff --git a/drivers/base/node.c b/drivers/base/node.c index 87acc47e8951..dabaed997ecd 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -560,11 +560,21 @@ static ssize_t node_read_distance(struct device *dev, } static DEVICE_ATTR(distance, 0444, node_read_distance, NULL); =20 +static ssize_t crypto_capable_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct pglist_data *pgdat =3D NODE_DATA(dev->id); + + return sysfs_emit(buf, "%d\n", pgdat->crypto_capable); +} +static DEVICE_ATTR_RO(crypto_capable); + static struct attribute *node_dev_attrs[] =3D { &dev_attr_meminfo.attr, &dev_attr_numastat.attr, &dev_attr_distance.attr, &dev_attr_vmstat.attr, + &dev_attr_crypto_capable.attr, NULL }; =20 --=20 2.30.2