From patchwork Wed Nov 25 18:36:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Borzenkov X-Patchwork-Id: 7702091 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 552B89F1BE for ; Wed, 25 Nov 2015 18:36:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 715E320877 for ; Wed, 25 Nov 2015 18:36:58 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 929B120867 for ; Wed, 25 Nov 2015 18:36:57 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 6AE6A1A2029; Wed, 25 Nov 2015 10:36:57 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mail-lf0-x235.google.com (mail-lf0-x235.google.com [IPv6:2a00:1450:4010:c07::235]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 324C41A2029 for ; Wed, 25 Nov 2015 10:36:56 -0800 (PST) Received: by lfdl133 with SMTP id l133so70921407lfd.2 for ; Wed, 25 Nov 2015 10:36:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type; bh=HZgLuIfjc43fJpVgQmJnaQw/iDS6QwibmcvDBG3uxLI=; b=XzOJp8jJUQNAl6+njmdiw5AILA9vCaBWEHV232sEhO+PedT+3yN5cMS7DinxHM1RNX i/mw68jyedNUEcmfZvJhphzdWiZUKSqSDuVA1g0acCLT6xNNqVjbJsrwwuX1EzOaR8R1 HEB6bExWnAStFX05dhfJnxaQRc3l7UuheOlx7SN4hRY8AbtBOTZb96TD39YJdpX0AV4y zKkYiCbV+bkVYota/aUpHvkOZ67S3M4Ax7OLU1zs4zujoAA5RwwR2MeAApKOS8g3M+iK B6QwFYeyLGBZoWgM4J6gspm+bIJEtrcTMtGoqjcX3SI5zDjPSmZ3r0Lp31XeNInRcLJp HPqA== X-Received: by 10.112.36.130 with SMTP id q2mr16213233lbj.24.1448476614001; Wed, 25 Nov 2015 10:36:54 -0800 (PST) Received: from [192.168.1.41] (ppp91-76-25-247.pppoe.mtu-net.ru. [91.76.25.247]) by smtp.gmail.com with ESMTPSA id aa4sm3144128lbc.10.2015.11.25.10.36.52 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 25 Nov 2015 10:36:53 -0800 (PST) Subject: Re: grub causing NVDIMMs to be treated as normal memory To: The development of GNU GRUB , "dan.j.williams@intel.com" , "linux-nvdimm@lists.01.org" References: <94D0CD8314A33A4D9D801C0FE68B40295BE539AF@G9W0745.americas.hpqcorp.net> From: Andrei Borzenkov Message-ID: <5655FFC3.9030603@gmail.com> Date: Wed, 25 Nov 2015 21:36:51 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <94D0CD8314A33A4D9D801C0FE68B40295BE539AF@G9W0745.americas.hpqcorp.net> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 25.11.2015 02:52, Elliott, Robert (Persistent Memory) ?????: > We've noticed that some combinations of grub and old linux kernels > > end up interpreting the UEFI memory map EfiPersistentMemory type 14 > > (formerly a reserved value) as regular memory in the linux e820 > > table, causing silent data corruption on the NVDIMMs. That occurs > > even though grub prints this message suggesting everything is safe: > > Unknown memory type 14, considering reserved > > > > In broken versions of grub, the code parsing the UEFI memory map > > has a "default" case that falls through to the > > GRUB_EFI_BOOT_SERVICES_DATA case, which marks the memory range > > as GRUB_MEMORY_AVAILABLE and ends up in e820 as regular memory. > Could you test if attached patch works for you (compile tested)? From: Andrei Borzenkov Subject: [PATCH] efi: really mark memory of unknown type as reserved 9be4c45dbe3c877d1f4856e99ee15133c6cd2261 added switch case between fall through cases, causing all memory regions of unknown type to be marked as available. Move default case into its own block and add explicit FALLTHROUGH annotation. Reported by Elliott, Robert (Persistent Memory) --- grub-core/mmap/efi/mmap.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/grub-core/mmap/efi/mmap.c b/grub-core/mmap/efi/mmap.c index a77efe8..6b5f5d8 100644 --- a/grub-core/mmap/efi/mmap.c +++ b/grub-core/mmap/efi/mmap.c @@ -73,6 +73,7 @@ grub_efi_mmap_iterate (grub_memory_hook_t hook, void *hook_data, GRUB_MEMORY_AVAILABLE, hook_data); break; } + /* FALLTHROUGH */ case GRUB_EFI_RUNTIME_SERVICES_CODE: hook (desc->physical_start, desc->num_pages * 4096, GRUB_MEMORY_CODE, hook_data); @@ -83,10 +84,6 @@ grub_efi_mmap_iterate (grub_memory_hook_t hook, void *hook_data, GRUB_MEMORY_BADRAM, hook_data); break; - default: - grub_printf ("Unknown memory type %d, considering reserved\n", - desc->type); - case GRUB_EFI_BOOT_SERVICES_DATA: if (!avoid_efi_boot_services) { @@ -94,6 +91,7 @@ grub_efi_mmap_iterate (grub_memory_hook_t hook, void *hook_data, GRUB_MEMORY_AVAILABLE, hook_data); break; } + /* FALLTHROUGH */ case GRUB_EFI_RESERVED_MEMORY_TYPE: case GRUB_EFI_RUNTIME_SERVICES_DATA: case GRUB_EFI_MEMORY_MAPPED_IO: @@ -119,6 +117,13 @@ grub_efi_mmap_iterate (grub_memory_hook_t hook, void *hook_data, hook (desc->physical_start, desc->num_pages * 4096, GRUB_MEMORY_NVS, hook_data); break; + default: + grub_printf ("Unknown memory type %d, considering reserved\n", + desc->type); + hook (desc->physical_start, desc->num_pages * 4096, + GRUB_MEMORY_RESERVED, hook_data); + break; + } } -- tg: (f9d1b44..) u/efi-unknown-memory-type (depends on: master)