All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dov Murik <dovmurik@linux.ibm.com>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: linux-efi@vger.kernel.org, Borislav Petkov <bp@suse.de>,
	Ashish Kalra <ashish.kalra@amd.com>,
	Brijesh Singh <brijesh.singh@amd.com>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	Ard Biesheuvel <ardb@kernel.org>,
	James Morris <jmorris@namei.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	Andi Kleen <ak@linux.intel.com>, Andrew Scull <ascull@google.com>,
	Dave Hansen <dave.hansen@intel.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	James Bottomley <jejb@linux.ibm.com>,
	Tobin Feldman-Fitzthum <tobin@linux.ibm.com>,
	Jim Cadden <jcadden@ibm.com>,
	Daniele Buono <dbuono@linux.vnet.ibm.com>,
	linux-coco@lists.linux.dev,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org, Dov Murik <dovmurik@linux.ibm.com>
Subject: Re: [PATCH v4 2/3] efi: Reserve confidential computing secret area
Date: Wed, 20 Oct 2021 11:19:42 +0300	[thread overview]
Message-ID: <1d79190a-f023-a83c-b197-62b0514dc769@linux.ibm.com> (raw)
In-Reply-To: <YW+55YcXqUtrw4/T@kroah.com>



On 20/10/2021 9:40, Greg KH wrote:
> On Wed, Oct 20, 2021 at 06:14:07AM +0000, Dov Murik wrote:
>> When efi-stub copies an EFI-provided confidential computing (coco)
>> secret area, reserve that memory block for future use within the kernel.
>>
>> Signed-off-by: Dov Murik <dovmurik@linux.ibm.com>
>> ---
>>  arch/x86/platform/efi/efi.c   |  3 +++
>>  drivers/firmware/efi/Makefile |  1 +
>>  drivers/firmware/efi/coco.c   | 41 +++++++++++++++++++++++++++++++++++
>>  drivers/firmware/efi/efi.c    |  8 +++++++
>>  include/linux/efi.h           | 10 +++++++++
>>  5 files changed, 63 insertions(+)
>>  create mode 100644 drivers/firmware/efi/coco.c
>>
>> diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
>> index 147c30a81f15..1591d67e0bcd 100644
>> --- a/arch/x86/platform/efi/efi.c
>> +++ b/arch/x86/platform/efi/efi.c
>> @@ -93,6 +93,9 @@ static const unsigned long * const efi_tables[] = {
>>  #ifdef CONFIG_LOAD_UEFI_KEYS
>>  	&efi.mokvar_table,
>>  #endif
>> +#ifdef CONFIG_EFI_COCO_SECRET
>> +	&efi.coco_secret,
>> +#endif
>>  };
>>  
>>  u64 efi_setup;		/* efi setup_data physical address */
>> diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile
>> index c02ff25dd477..49c4a8c0bfc4 100644
>> --- a/drivers/firmware/efi/Makefile
>> +++ b/drivers/firmware/efi/Makefile
>> @@ -32,6 +32,7 @@ obj-$(CONFIG_APPLE_PROPERTIES)		+= apple-properties.o
>>  obj-$(CONFIG_EFI_RCI2_TABLE)		+= rci2-table.o
>>  obj-$(CONFIG_EFI_EMBEDDED_FIRMWARE)	+= embedded-firmware.o
>>  obj-$(CONFIG_LOAD_UEFI_KEYS)		+= mokvar-table.o
>> +obj-$(CONFIG_EFI_COCO_SECRET)		+= coco.o
>>  
>>  fake_map-y				+= fake_mem.o
>>  fake_map-$(CONFIG_X86)			+= x86_fake_mem.o
>> diff --git a/drivers/firmware/efi/coco.c b/drivers/firmware/efi/coco.c
>> new file mode 100644
>> index 000000000000..42f477d6188c
>> --- /dev/null
>> +++ b/drivers/firmware/efi/coco.c
>> @@ -0,0 +1,41 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Confidential computing (coco) secret area handling
>> + *
>> + * Copyright (C) 2021 IBM Corporation
>> + * Author: Dov Murik <dovmurik@linux.ibm.com>
>> + */
>> +
>> +#define pr_fmt(fmt) "efi: " fmt
>> +
>> +#include <linux/efi.h>
>> +#include <linux/init.h>
>> +#include <linux/memblock.h>
>> +#include <asm/early_ioremap.h>
>> +
>> +/*
>> + * Reserve the confidential computing secret area memory
>> + */
>> +int __init efi_coco_secret_area_reserve(void)
>> +{
>> +	struct linux_efi_coco_secret_area *secret_area;
>> +	unsigned long secret_area_size;
>> +
>> +	if (efi.coco_secret == EFI_INVALID_TABLE_ADDR)
>> +		return 0;
>> +
>> +	secret_area = early_memremap(efi.coco_secret, sizeof(*secret_area));
>> +	if (!secret_area) {
>> +		pr_err("Failed to map confidential computing secret area\n");
>> +		efi.coco_secret = EFI_INVALID_TABLE_ADDR;
>> +		return -ENOMEM;
>> +	}
>> +
>> +	secret_area_size = sizeof(*secret_area) + secret_area->size;
>> +	memblock_reserve(efi.coco_secret, secret_area_size);
>> +
>> +	pr_info("Reserved memory of EFI-provided confidential computing secret area");
> 
> When kernel code works properly, it is quiet.  Why do you need to print
> this out at every boot?
> 

My kernel is not so quiet at the info loglevel; specifically from efi I 
see these prints (third log line added by this patch):

[    0.000000] efi: EFI v2.70 by EDK II
[    0.000000] efi: SMBIOS=0x7f541000 ACPI=0x7f77e000 ACPI 2.0=0x7f77e014 MEMATTR=0x7ea0c018 CocoSecret=0x7ea0b018
[    0.000000] efi: Reserved memory of EFI-provided confidential computing secret area

This print is useful to understand that both OVMF (EFI) and kernel support
the confidential computing secret area.



>> +
>> +	early_memunmap(secret_area, sizeof(*secret_area));
>> +	return 0;
>> +}
> 
> And again, when is this memory freed when shutting down?
> 

It is currently not freed.  I tried to look for such memory freeing of
other EFI-provided memory areas (such as efi.tpm_final_log) and couldn't
find them.  Can you please share pointers/examples of how to do that?

Thanks,
-Dov

  reply	other threads:[~2021-10-20  8:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-20  6:14 [PATCH v4 0/3] Allow guest access to EFI confidential computing secret area Dov Murik
2021-10-20  6:14 ` [PATCH v4 1/3] efi/libstub: Copy " Dov Murik
2021-10-20  6:39   ` Greg KH
2021-10-20  7:02     ` Ard Biesheuvel
2021-10-20  8:02     ` Dov Murik
2021-10-20 12:00     ` James Bottomley
2021-10-20 12:11       ` Greg KH
2021-10-20 12:52         ` Dov Murik
2021-10-20 13:59           ` Greg KH
2021-10-20  6:14 ` [PATCH v4 2/3] efi: Reserve " Dov Murik
2021-10-20  6:40   ` Greg KH
2021-10-20  8:19     ` Dov Murik [this message]
2021-10-20  6:14 ` [PATCH v4 3/3] virt: Add efi_secret module to expose confidential computing secrets Dov Murik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1d79190a-f023-a83c-b197-62b0514dc769@linux.ibm.com \
    --to=dovmurik@linux.ibm.com \
    --cc=ak@linux.intel.com \
    --cc=ardb@kernel.org \
    --cc=ascull@google.com \
    --cc=ashish.kalra@amd.com \
    --cc=bp@suse.de \
    --cc=brijesh.singh@amd.com \
    --cc=dave.hansen@intel.com \
    --cc=dbuono@linux.vnet.ibm.com \
    --cc=dgilbert@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jcadden@ibm.com \
    --cc=jejb@linux.ibm.com \
    --cc=jmorris@namei.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=serge@hallyn.com \
    --cc=thomas.lendacky@amd.com \
    --cc=tobin@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.