Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp833932pxb; Tue, 8 Feb 2022 03:38:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJwr9DGSqAj0jneHlFwoBvop7snEjGdGcY4TC4AI1i/bpEG4LNYmJyVQpWGm+J/BDfGad/Me X-Received: by 2002:a17:90a:7844:: with SMTP id y4mr887849pjl.13.1644320319213; Tue, 08 Feb 2022 03:38:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644320319; cv=none; d=google.com; s=arc-20160816; b=MM7jKSejdREqgVyT3o5HpZ8mMWHCxBCJoGXVkA8HAu/79Nr+nhzTCe/MU/iLuKubcK xG0+LfBBLW/yPflls6+XHI1M/3MHdVz3V7oreSP2ulEP/i5s/2wSRBytmarOg/qLFo54 HylVk0UmlwOKUWx+o2JEUDzVPpAShbwkusU2RjKT6H2iHD5aNzCD2weczZMBYwwWOq0O xDbJA6LlJ3Nk7ynzIyCZynmIKj3VHxtCenc1AttcB3MV7GlKNBpbmKZ18l/te4w9g1b5 uDkha5XD6Enr/u06/G6miEsmMn+ooBTHRwS+GkmNItcA1IWaH/WK8izixJlrxnKSzCuZ gRXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=tHxa2zKVaHBcu/brPJMMDCzteRvMa8lCYhxJZN7g04o=; b=kPEuGbtLB6rGrASANLcHzK2s+GF/RstONqcCM+zIXo3IkdFK78pzDLw/iNzTMxwimP iWQxCEm/luAuJcVA4d0JfSQxHb9oC+ZQp6ZRgT8X5WOjbd1NaoRPvhS3DCCTzVFe8Xsx VF171rK394yK9moF8kEHOlAzE2WZMLwj7UWhowo89jdpeoSI0Lpz60FYRPA3DCHAhIO6 Jfnwb3an9HBVUkeJBkD/NhUPZAtxQzTpBud9qOS9y3aJWAxPsuGRrcNs8/FRte+Pcio1 1Fv5bQpQLtcFTM4aa8Rvsjyywq0r3lkjdbYvyaHsypbQI4CzvD8T8MbKCsZEI10pEhfU EC6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=I3T0MgX3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y7si11135720plh.421.2022.02.08.03.38.22; Tue, 08 Feb 2022 03:38:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=I3T0MgX3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243237AbiBGV4T (ORCPT + 99 others); Mon, 7 Feb 2022 16:56:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242051AbiBGV4Q (ORCPT ); Mon, 7 Feb 2022 16:56:16 -0500 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5C45C061A73 for ; Mon, 7 Feb 2022 13:56:15 -0800 (PST) Received: by mail-pf1-x42c.google.com with SMTP id y5so14428428pfe.4 for ; Mon, 07 Feb 2022 13:56:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=tHxa2zKVaHBcu/brPJMMDCzteRvMa8lCYhxJZN7g04o=; b=I3T0MgX3KD3D8din9AD4VmFgX5xNMlWkCITEwL0yWT4rotEFC5G/eY54wJX+04On6C CHr+Fk8wpO7RGMsRViMvJA3/won/IUNX8Ak9LBq8aIS1CJfPR5C6w46zR1Z8O+YPMarK I3WWGlNHdYu4PYfMgfgnwpeTxftKTY5LuLmhc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=tHxa2zKVaHBcu/brPJMMDCzteRvMa8lCYhxJZN7g04o=; b=nFDNXCY/5ExJzazeY6MwMEujiQwU2UQLHCjObqeVYgCE5LErj8KUJOnWkRijo5vLmX nSJkJprMWuw1wmfF83DvT4cuGCYlevMUC+HqsYYQI6CUU3wFZfgUyX44wh5s30mWSFtD MZykWdjM+xXbRQ7kaTOMgqWk1Orberta8t2XlZKO3bkv8W2RePgSrPTT19Lh4gXcuiRf msxO8BCDXh2H6/vtX/T2GFxg4a75dVFkm9SF3GTEWM21pZh4GCpvXkDZJ2f6hO1YEu8K MSPG9TrCCkDwyEtNvlVHrAaIUWJb7vnryjCraf+RBTaqXRaGz1BXWsJ7csQZQgJR8d6P tiGg== X-Gm-Message-State: AOAM532F9rMeBqUM4P75gSJbOjMu0QOqh4sBfOASNjH48vTypw4Z1Lt+ AbypvazrFqtCkijZ4U9FM0/N0Q== X-Received: by 2002:a63:4f4f:: with SMTP id p15mr1109735pgl.452.1644270975192; Mon, 07 Feb 2022 13:56:15 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 6sm9348292pgx.36.2022.02.07.13.56.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 13:56:14 -0800 (PST) Date: Mon, 7 Feb 2022 13:56:14 -0800 From: Kees Cook To: Martin Fernandez 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, rppt@kernel.org, akpm@linux-foundation.org, daniel.gutson@eclypsium.com, hughsient@gmail.com, alex.bazhaniuk@eclypsium.com, alison.schofield@intel.com Subject: Re: [PATCH v6 4/6] x86/e820: Tag e820_entry with crypto capabilities Message-ID: <202202071351.AEEEA92@keescook> References: <20220203164328.203629-1-martin.fernandez@eclypsium.com> <20220203164328.203629-5-martin.fernandez@eclypsium.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220203164328.203629-5-martin.fernandez@eclypsium.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Thu, Feb 03, 2022 at 01:43:26PM -0300, Martin Fernandez wrote: > 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_set_crypto_capable to mark all the > entries in a range of addresses as encryptable. This will be called > when initializing EFI. > > Change e820__update_table to handle merging and overlap problems > taking into account crypto_capable. > > 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 | 114 ++++++++++++++++++++++++++++-- > 3 files changed, 119 insertions(+), 8 deletions(-) > > diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h > index e8f58ddd06d9..4b3b01fafdd1 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 e820_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_type, enum e820_type new_type); > extern u64 e820__range_remove(u64 start, u64 size, enum e820_type old_type, bool check_type); > +extern u64 e820__range_set_crypto_capable(u64 start, u64 size); > > 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 = 128, > }; > > +enum e820_crypto_capabilities { > + E820_NOT_CRYPTO_CAPABLE = 0, > + E820_CRYPTO_CAPABLE = 1, > +}; Is this expected to grow beyond a bool? > + > /* > * 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)); Is there any concern about growing this structure? The "thousands" note in the comment is likely rare. FWIW, this seems fine to me, but I thought I'd mention it. -- Kees Cook