Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp402426lqs; Thu, 13 Jun 2024 13:28:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX2M09j0H+hKGzMq2Cj/xCY2FpK+PDShLxicZhMuu02dOrmVG3VxZ/hQALXnB+sxJc99KMUHKG6Ngw5yz/X4ZxOs5ccCedJgP3ANXgEnA== X-Google-Smtp-Source: AGHT+IE0DmIC//2slHc5Gj372azJK9Jk5HJuew/9iZ1x3U49bzokASk2nbOu0dc+Alj+Ppx9wjV+ X-Received: by 2002:a05:6a20:1583:b0:1b6:d9fa:8bc with SMTP id adf61e73a8af0-1bae82816a0mr1016725637.42.1718310491477; Thu, 13 Jun 2024 13:28:11 -0700 (PDT) Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f855f07e30si19767315ad.530.2024.06.13.13.28.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 13:28:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213965-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="PghDA9/O"; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-213965-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213965-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 944E3B2623F for ; Thu, 13 Jun 2024 20:05:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E6917132131; Thu, 13 Jun 2024 20:05:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="PghDA9/O" Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2053.outbound.protection.outlook.com [40.107.237.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D76FE57C8D; Thu, 13 Jun 2024 20:05:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.53 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718309116; cv=fail; b=ZeF8HC5xgau8eCkoYCAXinCEZhbEjXxAYUDuvdMXbF6Wfp+zSflRWs7aF68zCpVheh08r2M0wp7NlDsVNSujTFIz2NXfOTrOmMpCmA10f13yizlwkwFqET+2sHaXrEp06D1DIp1cq2GDpGoOHjKj21nR618AD3jTr2Mlbrbg2sU= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718309116; c=relaxed/simple; bh=23rnbrtrzuPGuPvIBEH44MDCrRkXpyebVQfFNtvlX0k=; h=Message-ID:Date:Subject:To:Cc:References:From:In-Reply-To: Content-Type:MIME-Version; b=Re7T0i4c6NkC2lok0hRNqsD8xeHWWnJa7zdD0VYRgdh0VPQFaCqgD07sHGYQwjZ8IRidMvwjkA9W0URxnZLsbY3VxqFBWpZBpndAXF6FlqjTsH2I3CPamCwDJssHZ5pHH9AgVbiOwmbBOMHP7UWTqpyBlcwY3HWLQpXZUBru1wc= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=PghDA9/O; arc=fail smtp.client-ip=40.107.237.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tod4yUKlPeQ3GgKTR0c9BZca6g+zBrBZJVZ+NEJKfq++ItwSkkdfPsj8IND+2W9ThxYuNC+DbfDLHcJp+fXfZn9EU/h0AriskFZ/UTLNwxyz5zHQ2daRc1Trtwf3hWepLywe6OcGCt6rKDMMQQ8SX+/mIbwkHnbDdjxuXntbOnFjivILoXWw7Be6TzHJ6MwexImu8Q6DvMtMCh7T83PT258a4xUCq0g4I6A0dki5oJi2jRHrweP3YAKrOLqe4o3ardQ91X6B8DXWXjgf8JpMJd2yRWiEelhlUjjA74HVCCpXUdVZzXMwYfiEaYIfMZofpnw62eHGLu5zPGIccgS/Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xt3gBoX/eGlvsQEvXqdZgigsnpfdtIPH7ifFz+UdOD4=; b=AFacSkOIYC1pd7NvL/QRhPlMNxoPcip0zHSeeBYFAQuFNV2Ufu21yrHsMZsM9QwqLqDfdOz/MgzVawURuajXahMCsYJ7fxw6uwYzyhX9zwUHeH7ub54FaiUAXcB3EIfTRYKk2fFelmvlzHS7SxkoA+JGsuXtaiIPINCgjGgQynZvlRMJC78lFRBT+qeZEHdnGJEtO9gZtkTP5mHdA2j6whFSsLPld1hwgclR45FnxAh1Krc2yRK9By0bCadlRm83gEOlXQgWLiNIPG3DZ/8BG0QkkqVyXptZi6fKnz8NKB5jJxVAPMgKFatH+SOdpw/NzE+cMfYKvwTh+4P6hRBSpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xt3gBoX/eGlvsQEvXqdZgigsnpfdtIPH7ifFz+UdOD4=; b=PghDA9/O4VRUcKlhceGZ78LO9kPyQBTPzsMJXCkLHWGeYpV/yKJymh3eWkuhRF8r0KmS0vx+6TGDgWkzPDEO2dSu7mZRkPB4nIhZvweW0TuQLi1MVsiavIfeNG4uWLmoX1jICuotK5k+2kNMV7FtENON9nzr9cGeY2T07Bzo/rE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from BYAPR12MB2759.namprd12.prod.outlook.com (2603:10b6:a03:61::32) by MN6PR12MB8543.namprd12.prod.outlook.com (2603:10b6:208:47b::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.24; Thu, 13 Jun 2024 20:05:11 +0000 Received: from BYAPR12MB2759.namprd12.prod.outlook.com ([fe80::10e0:d1f7:5b28:db15]) by BYAPR12MB2759.namprd12.prod.outlook.com ([fe80::10e0:d1f7:5b28:db15%4]) with mapi id 15.20.7633.036; Thu, 13 Jun 2024 20:05:11 +0000 Message-ID: <16131a10-b473-41cc-a96e-d71a4d930353@amd.com> Date: Thu, 13 Jun 2024 15:05:09 -0500 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] x86/efi: Free EFI memory map only when installing a new one. Content-Language: en-US To: Ard Biesheuvel , linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Ard Biesheuvel , Dave Young , Mike Rapoport , Borislav Petkov , Dan Williams References: <20240612135638.298882-2-ardb+git@google.com> From: "Kalra, Ashish" In-Reply-To: <20240612135638.298882-2-ardb+git@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SA9PR13CA0058.namprd13.prod.outlook.com (2603:10b6:806:22::33) To BYAPR12MB2759.namprd12.prod.outlook.com (2603:10b6:a03:61::32) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB2759:EE_|MN6PR12MB8543:EE_ X-MS-Office365-Filtering-Correlation-Id: a971990a-a5a4-40bf-9eed-08dc8be421ce X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230035|376009|1800799019|366011; X-Microsoft-Antispam-Message-Info: =?utf-8?B?MG5tS09WeUhjK0cxSXZ0cDU2Y1JlSGVVc0hrNGdaUVJXVkE5MkpmaHpjMWxJ?= =?utf-8?B?NjMva21pQ2NJMXZEejNrTXA2MEpRTmFZcy91NHZRWk9BVkxrWkxMZlpwS0Fp?= =?utf-8?B?MkdhK2wrU2oxNWFHS3dEZjRUaldnUVo3aUNyaWl5K2VnS3ZHZUwzckhYUkQ4?= =?utf-8?B?M0d2K0RhNWhQQ09lS01xTlBSV3VDQ0d1T2NEUWI0YjFvNmYzZDlPUkVubnZh?= =?utf-8?B?NE1TYlFHZlQyRkFJNFhDUElhRTh3QVU0MWIzeFpzTFNXV01NTGltT2htTGtG?= =?utf-8?B?NzVvRzhYQWx4Zk9GL0k3S25ESmVHZlk5eks1ZDRFdnpVMnlLM1BTOURBbnFP?= =?utf-8?B?WGVyeEswdEhDVm9hVnNIQ2FmYnVRdDhwRXZrTDE4VXBQRkg2aVRuc1RMcFQr?= =?utf-8?B?ZDM3R2ZjV1hTaDdVQXhFZ3B2cHBTQm03bW1w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XBURmNOYXQyL1cwbnRYTitFTWplaitmMWZvM29RdVR2VzRl?= =?utf-8?B?aFNaRFd0RUVwWXZvbTE5Q1Rycm5JYkpkZS8ySE1xOUptWk1qUHI4YThkd1Jh?= =?utf-8?B?ejQvS3hsZ3RYbDlDbk5SckZQUFZGa3pZbExLV0JnbTdWWVprQmZ5eS92bnFH?= =?utf-8?B?ZmJyR3ZJR01nbEJ3aWNydTdPV1ZNZzlwUXQrbEZBY3F1amNTR1VLUDZReUx5?= =?utf-8?B?QjRjZThuUFJEbG1ZTURwdk5kSHU0V2ZiR2NOcHlsZUZ0MCtCeG5mYVRzVXhj?= =?utf-8?B?MUlUeVU1ZysvLzJUTHQ2SThzbHlLYXhHa0xxN1NaV3hIelRhNFk5YklUMG9E?= =?utf-8?B?NUFOblBVa2pWY21PM3RROUNlc0R0by9CZy81SE0rRjBFZjNmUURhb1FnPT0=?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR12MB2759.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230035)(376009)(1800799019)(366011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?WGlvWCtZTDhoWURmeFBCN0lGdkV2cVRoZi8vcFNZV2U0SThJanB6WjdhSGxv?= =?utf-8?B?dWRxOWp4WDhwVjV4Z21KV0ZxaUUwWlBUdjhjUW1TbEViNW5qS1NlbWtrcVFW?= =?utf-8?B?NU83UVBHQllKQThwWEZCTXZta094N2dVUm5xYmxvNUVCdWJhaExQemRwaDBQ?= =?utf-8?B?SnlzdVBzYXV0c05OQTB3Z2FPWk5JR3J4WGVEVFB0cDZ2RmNGQUh3NVJQanZ1?= =?utf-8?B?OXAyN3RIZXdKZzFKZGVZSGRjOUQyK1VWTCtJaWJkNEErR2RZcDcxaVhnOTcv?= =?utf-8?B?c0xEUDlp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2Y2TVhJeE5qeDRvcWF3VTRWZm01R1N6RWdzenhj?= =?utf-8?Q?KnaVNVYEKdRkvK7hSOKMq6EPe?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a971990a-a5a4-40bf-9eed-08dc8be421ce X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB2759.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2024 20:05:11.7180 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: goMpuTxqeWpwITYJuJSesQVNYvQhmYl1aLYtogMjCV00wu/auj8AuYnYC27Q2QmU9AVB9Q5Uwh8ylbBhenRJbQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8543 Hello Ard, On 6/12/2024 8:56 AM, Ard Biesheuvel wrote: > From: Ard Biesheuvel > > The logic in __efi_memmap_init() is shared between two different > execution flows: > - mapping the EFI memory map early or late into the kernel VA space, so > that its entries can be accessed; > - cloning the EFI memory map in order to insert new entries that are > created as a result of creating a memory reservation > (efi_arch_mem_reserve()) > > In the former case, the underlying memory containing the kernel's view > of the EFI memory map (which may be heavily modified by the kernel > itself on x86) is not modified at all, and the only thing that changes > is the virtual mapping of this memory, which is different between early > and late boot. > > In the latter case, an entirely new allocation is created that carries a > new, updated version of the kernel's view of the EFI memory map. When > installing this new version, the old version will no longer be > referenced, and if the memory was allocated by the kernel, it will leak > unless it gets freed. > > The logic that implements this freeing currently lives on the code path > that is shared between these two use cases, but it should only apply to > the latter. So move it to the correct spot. > > While at it, move __efi_memmap_free() into its only caller, and drop the > dummy definition for non-x86 architectures, as that is no longer needed. > > Cc: Ashish Kalra > Cc: Dave Young > Cc: Mike Rapoport > Cc: Borislav Petkov > Cc: Dan Williams > Fixes: f0ef6523475f ("efi: Fix efi_memmap_alloc() leaks") > Link: https://lore.kernel.org/all/36ad5079-4326-45ed-85f6-928ff76483d3@amd.com > Signed-off-by: Ard Biesheuvel > --- > v3: > - don't move __efi_memmap_free() into what turned out not to be its only > caller > - drop another CPP #define related to the dummy definition > > v2: > - free old memory map only after installing the new one succeeded > - move __efi_memmap_free() into its only caller > - drop obsolete dummy declaration from generic code > > arch/x86/include/asm/efi.h | 1 - > arch/x86/platform/efi/memmap.c | 12 +++++++++++- > drivers/firmware/efi/memmap.c | 9 --------- > 3 files changed, 11 insertions(+), 11 deletions(-) > > diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h > index 1dc600fa3ba5..481096177500 100644 > --- a/arch/x86/include/asm/efi.h > +++ b/arch/x86/include/asm/efi.h > @@ -401,7 +401,6 @@ extern int __init efi_memmap_alloc(unsigned int num_entries, > struct efi_memory_map_data *data); > extern void __efi_memmap_free(u64 phys, unsigned long size, > unsigned long flags); > -#define __efi_memmap_free __efi_memmap_free > > extern int __init efi_memmap_install(struct efi_memory_map_data *data); > extern int __init efi_memmap_split_count(efi_memory_desc_t *md, > diff --git a/arch/x86/platform/efi/memmap.c b/arch/x86/platform/efi/memmap.c > index 4ef20b49eb5e..6ed1935504b9 100644 > --- a/arch/x86/platform/efi/memmap.c > +++ b/arch/x86/platform/efi/memmap.c > @@ -92,12 +92,22 @@ int __init efi_memmap_alloc(unsigned int num_entries, > */ > int __init efi_memmap_install(struct efi_memory_map_data *data) > { > + unsigned long size = efi.memmap.desc_size * efi.memmap.nr_map; > + unsigned long flags = efi.memmap.flags; > + u64 phys = efi.memmap.phys_map; > + int ret; > + > efi_memmap_unmap(); > > if (efi_enabled(EFI_PARAVIRT)) > return 0; > > - return __efi_memmap_init(data); > + ret = __efi_memmap_init(data); > + if (ret) > + return ret; > + > + __efi_memmap_free(phys, size, flags); > + return 0; > } > > /** > diff --git a/drivers/firmware/efi/memmap.c b/drivers/firmware/efi/memmap.c > index 3365944f7965..34109fd86c55 100644 > --- a/drivers/firmware/efi/memmap.c > +++ b/drivers/firmware/efi/memmap.c > @@ -15,10 +15,6 @@ > #include > #include > > -#ifndef __efi_memmap_free > -#define __efi_memmap_free(phys, size, flags) do { } while (0) > -#endif > - > /** > * __efi_memmap_init - Common code for mapping the EFI memory map > * @data: EFI memory map data > @@ -51,11 +47,6 @@ int __init __efi_memmap_init(struct efi_memory_map_data *data) > return -ENOMEM; > } > > - if (efi.memmap.flags & (EFI_MEMMAP_MEMBLOCK | EFI_MEMMAP_SLAB)) > - __efi_memmap_free(efi.memmap.phys_map, > - efi.memmap.desc_size * efi.memmap.nr_map, > - efi.memmap.flags); > - > map.phys_map = data->phys_map; > map.nr_map = data->size / data->desc_size; > map.map_end = map.map + data->size; Tested this patch with SNP guest kexec and i do not observe EFI memory map corruption with SNP guest kexec with this patch applied. I have another question related to the discussion on the following email thread: Re: [PATCH v7 1/3] efi/x86: Fix EFI memory map corruption with kexec - Dave Young (kernel.org) Do we still want to create another patch for skipping efi_arch_mem_reserve() when the EFI_MEMORY_RUNTIME bit was set already ? Tested-by: Ashish Kalra