From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 13B047BB12 for ; Tue, 19 Mar 2024 04:00:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710820837; cv=none; b=KSD8prRKlEM8CbGpK2dca7TcXWt5CIX5hL+Qf3jgJFhBuQeZs8dqSTq6wbHfQncvF4IQzfRb0hbCIOXFOzTN1LDffwVi04ZEnjtDPQplV/24KmaBhr0WuEsSGnMfmJt7rIWHZsLzX1nVi/5FXZAY8/FiHDGYvM0f4Ve97TmP5KE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710820837; c=relaxed/simple; bh=em1tayWATecsjQCbVE06v1UJF8h/Yfzd2A6qPpmeTQE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=StvbVynR0z64IZoe4HcuCpXvjnTUtXT/UBTJQERcxzFRh/Lmvu9A57a0wl++5SbaD4T6Q2JNyTGQ/vj6vS7eKsYPyXZjSu4L44aC3H7GGXKx0xKJzkyrOk/iLhyWVEGQas46t7S3hXV/rpEupE8gCbWSiaI2uTvipVOuxA9robQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=hqHL56Jq; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hqHL56Jq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710820835; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=VCuT+KF0CFKXEteYACtgcd0bLY6/wFRR3VLA/HmQm5k=; b=hqHL56Jqicv3KCrs7a8X/ztyhDrw+Rzwt4Hkzm6hIOXpSimcShzMHCka9Ii4VyDT3VyYuI O3c+2RgcgEGsEjB5Cw2/3ql8yA88dYfadqiLWxe+4flkP+ES7DihH4+UOkjj/iMS7tIK3e ONBWeDCW9z8O6Hw4QNEsxrMuxiOGecg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-608-uhYCHd1lOYC1LAIgkUewmA-1; Tue, 19 Mar 2024 00:00:30 -0400 X-MC-Unique: uhYCHd1lOYC1LAIgkUewmA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 565D3852002; Tue, 19 Mar 2024 04:00:28 +0000 (UTC) Received: from darkstar.users.ipa.redhat.com (unknown [10.72.116.87]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 859973C20; Tue, 19 Mar 2024 04:00:16 +0000 (UTC) Date: Tue, 19 Mar 2024 12:00:15 +0800 From: Dave Young To: Ashish Kalra Cc: tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, rafael@kernel.org, peterz@infradead.org, adrian.hunter@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, elena.reshetova@intel.com, jun.nakajima@intel.com, rick.p.edgecombe@intel.com, thomas.lendacky@amd.com, seanjc@google.com, michael.roth@amd.com, kai.huang@intel.com, bhe@redhat.com, kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, kirill.shutemov@linux.intel.com, bdas@redhat.com, vkuznets@redhat.com, dionnaglaze@google.com, anisinha@redhat.com, jroedel@suse.de, Ard Biesheuvel Subject: Re: [PATCH v2 1/3] efi/x86: skip efi_arch_mem_reserve() in case of kexec. Message-ID: References: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> <7c2e6ae663da2e5eb41527f0d854f59a56b91ecd.1710744412.git.ashish.kalra@amd.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7c2e6ae663da2e5eb41527f0d854f59a56b91ecd.1710744412.git.ashish.kalra@amd.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 Hi, Added Ard in cc. On 03/18/24 at 07:02am, Ashish Kalra wrote: > From: Ashish Kalra > > For kexec use case, need to use and stick to the EFI memmap passed > from the first kernel via boot-params/setup data, hence, > skip efi_arch_mem_reserve() during kexec. > > Additionally during SNP guest kexec testing discovered that EFI memmap > is corrupted during chained kexec. kexec_enter_virtual_mode() during > late init will remap the efi_memmap physical pages allocated in > efi_arch_mem_reserve() via memboot & then subsequently cause random > EFI memmap corruption once memblock is freed/teared-down. > > Signed-off-by: Ashish Kalra > --- > arch/x86/platform/efi/quirks.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c > index f0cc00032751..d4562d074371 100644 > --- a/arch/x86/platform/efi/quirks.c > +++ b/arch/x86/platform/efi/quirks.c > @@ -258,6 +258,16 @@ void __init efi_arch_mem_reserve(phys_addr_t addr, u64 size) > int num_entries; > void *new; > > + /* > + * For kexec use case, we need to use the EFI memmap passed from the first > + * kernel via setup data, so we need to skip this. > + * Additionally kexec_enter_virtual_mode() during late init will remap > + * the efi_memmap physical pages allocated here via memboot & then > + * subsequently cause random EFI memmap corruption once memblock is freed. Can you elaborate a bit about the corruption, is it reproducible without SNP? > + */ > + if (efi_setup) > + return; > + How about checking the md attribute instead of checking the efi_setup, personally I feel it a bit better, something like below: diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c index f0cc00032751..699332b075bb 100644 --- a/arch/x86/platform/efi/quirks.c +++ b/arch/x86/platform/efi/quirks.c @@ -255,15 +255,24 @@ void __init efi_arch_mem_reserve(phys_addr_t addr, u64 size) struct efi_memory_map_data data = { 0 }; struct efi_mem_range mr; efi_memory_desc_t md; - int num_entries; + int num_entries, ret; void *new; - if (efi_mem_desc_lookup(addr, &md) || - md.type != EFI_BOOT_SERVICES_DATA) { + ret = efi_mem_desc_lookup(addr, &md); + if (ret) { pr_err("Failed to lookup EFI memory descriptor for %pa\n", &addr); return; } + if (md.type != EFI_BOOT_SERVICES_DATA) { + pr_err("Skil reserving non EFI Boot Service Data memory for %pa\n", &addr); + return; + } + + /* Kexec copied the efi memmap from the 1st kernel, thus skip the case. */ + if (md.attribute & EFI_MEMORY_RUNTIME) + return; + if (addr + size > md.phys_addr + (md.num_pages << EFI_PAGE_SHIFT)) { pr_err("Region spans EFI memory descriptors, %pa\n", &addr); return;