From patchwork Sat Jul 14 20:53:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugeniu Rosca X-Patchwork-Id: 944004 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Pp6m7Iau"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41ShlY3CxDz9rxx for ; Sun, 15 Jul 2018 06:55:37 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 1CE3BC21FA3; Sat, 14 Jul 2018 20:55:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 0DD7AC21DFB; Sat, 14 Jul 2018 20:55:30 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 275A1C21DFB; Sat, 14 Jul 2018 20:55:28 +0000 (UTC) Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by lists.denx.de (Postfix) with ESMTPS id 008ACC21DD9 for ; Sat, 14 Jul 2018 20:55:26 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id c13-v6so28174333wrt.1 for ; Sat, 14 Jul 2018 13:55:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=JqL8R7mTl4wFikA3iSrrROnJYDGSTxYMMXG4yYv7sRA=; b=Pp6m7IauahOye6yz12DbEgihY0+y8ukmwJnPDlaI10QQY+8xFrCe7xRLs8CZ/A9Eiy nPiLdOzsMvqbYfqH+aHKcS+fQ7ZBxoaI/L0NOIcLorWVvJu7tbZtQPiM3A/B6iB4GvV9 KpmnXXNY5bkr/8W8Fy5/O3K88THpDPS7sxV4cBo12xbIn/gAE2n7tQkBOQ8gfzWrXqwn gavMr1GTD++clx/CJ+t80DpX0q7FQG4Ck9NY0x16KPT3PdUP7DGoKnRINof1pwxXPFOb GN7Rf053j/7i8LMv26vRzqk9O949ycPkCJgi8E1IyT/PbdgxnweR7t3gSUKe+pQmJTxq kgHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=JqL8R7mTl4wFikA3iSrrROnJYDGSTxYMMXG4yYv7sRA=; b=FyawAH9rJ6uhVSqHQ5xx6gVccHwQ8JFxDhrH1J/dkUFPox/SrFxhNog6FeXYu/U0cX Mb+F6UE4EwxiOePFIewt8YYYev0jwY88paSXVFQ4J+xPub9AzWjqgOdhbfu3pXZ7M46W 0tLKQ1CzEuYq6X2vwcyyOcaMsfmdJcGNA3bUos9Bf4HKfl48c5frYQA3tn/+rEAMsoAZ 6Uor/MsltQmRjW7C1e+qdBPQTcJju6te+MeW55nbVaJNUxKMgC4HBAinGbY8ifytILYp ew2Yu5dwoKgZUE9g9mHcp6nU1GluKON2XPyOtkdkRBc9/C3ufO1mPjDQ/WUqc1P/kvDS JoTA== X-Gm-Message-State: AOUpUlGyJGKu2kWkNr1eQcKsaF66G6rX6fknfPNK+V7ALp7dJuJex7Az huSysLR8e9jT/P3GqoN2URo= X-Google-Smtp-Source: AAOMgpcTSR7sX+NHLX09aFD0r7o/9DJNh+8K1fY5zobULzUcQhhBGX6YelwV9JjFL3lvqRyeFgnUuA== X-Received: by 2002:a5d:5088:: with SMTP id a8-v6mr8562402wrt.37.1531601726647; Sat, 14 Jul 2018 13:55:26 -0700 (PDT) Received: from localhost.localdomain (ipb218f4bb.dynamic.kabel-deutschland.de. [178.24.244.187]) by smtp.gmail.com with ESMTPSA id j6-v6sm5518889wro.13.2018.07.14.13.55.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 14 Jul 2018 13:55:26 -0700 (PDT) From: Eugeniu Rosca X-Google-Original-From: Eugeniu Rosca To: Heinrich Schuchardt , Simon Glass , Alexander Graf , Bin Meng , Rob Clark , u-boot@lists.denx.de Date: Sat, 14 Jul 2018 22:53:30 +0200 Message-Id: <20180714205332.17709-1-erosca@de.adit-jv.com> X-Mailer: git-send-email 2.18.0 Cc: Eugeniu Rosca Subject: [U-Boot] [PATCH v2 1/3] efi: Fix truncation of constant value X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Starting with commit 867a6ac86dd8 ("efi: Add start-up library code"), sparse constantly complains about truncated constant value in efi.h: include/efi.h:176:35: warning: cast truncates bits from constant value (8000000000000000 becomes 0) This can get quite noisy, preventing real issues to be noticed: $ make defconfig *** Default configuration is based on 'sandbox_defconfig' $ make C=2 -j12 2>&1 | grep truncates | wc -l 441 After the patch is applied: $ make C=2 -j12 2>&1 | grep truncates | wc -l 0 $ sparse --version v0.5.2 Following the suggestion of Heinrich Schuchardt, instead of only fixing the root-cause, I replaced the whole enum of _SHIFT values by ULL defines. This matches both the UEFI 2.7 spec and the Linux kernel implementation. Some ELF size comparison before and after the patch (gcc 7.3.0): efi-x86_payload64_defconfig: text data bss dec hex filename 407174 29432 278676 715282 aea12 u-boot.old 407152 29464 278676 715292 aea1c u-boot.new -22 +32 0 +10 efi-x86_payload32_defconfig: text data bss dec hex filename 447075 30308 280076 757459 b8ed3 u-boot.old 447053 30340 280076 757469 b8edd u-boot.new -22 +32 0 +10 Fixes: 867a6ac86dd8 ("efi: Add start-up library code") Suggested-by: Heinrich Schuchardt Signed-off-by: Eugeniu Rosca Reviewed-by: Heinrich Schuchardt Reviewed-by: Heinrich Schuchardt --- v2: - Replace _SHIFT enum values by ULL defines to match UEFI 2.7 spec - Add ELF size comparison to patch description cmd/efi.c | 22 +++++++++++----------- include/efi.h | 24 ++++++++++-------------- lib/efi_loader/efi_memory.c | 7 +++---- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/cmd/efi.c b/cmd/efi.c index 6c1eb88424be..92a565f71373 100644 --- a/cmd/efi.c +++ b/cmd/efi.c @@ -28,18 +28,18 @@ static const char *const type_name[] = { }; static struct attr_info { - int shift; + u64 val; const char *name; } mem_attr[] = { - { EFI_MEMORY_UC_SHIFT, "uncached" }, - { EFI_MEMORY_WC_SHIFT, "write-coalescing" }, - { EFI_MEMORY_WT_SHIFT, "write-through" }, - { EFI_MEMORY_WB_SHIFT, "write-back" }, - { EFI_MEMORY_UCE_SHIFT, "uncached & exported" }, - { EFI_MEMORY_WP_SHIFT, "write-protect" }, - { EFI_MEMORY_RP_SHIFT, "read-protect" }, - { EFI_MEMORY_XP_SHIFT, "execute-protect" }, - { EFI_MEMORY_RUNTIME_SHIFT, "needs runtime mapping" } + { EFI_MEMORY_UC, "uncached" }, + { EFI_MEMORY_WC, "write-coalescing" }, + { EFI_MEMORY_WT, "write-through" }, + { EFI_MEMORY_WB, "write-back" }, + { EFI_MEMORY_UCE, "uncached & exported" }, + { EFI_MEMORY_WP, "write-protect" }, + { EFI_MEMORY_RP, "read-protect" }, + { EFI_MEMORY_XP, "execute-protect" }, + { EFI_MEMORY_RUNTIME, "needs runtime mapping" } }; /* Maximum different attribute values we can track */ @@ -173,7 +173,7 @@ static void efi_print_mem_table(struct efi_entry_memmap *map, printf("%c%llx: ", attr & EFI_MEMORY_RUNTIME ? 'r' : ' ', attr & ~EFI_MEMORY_RUNTIME); for (j = 0, first = true; j < ARRAY_SIZE(mem_attr); j++) { - if (attr & (1ULL << mem_attr[j].shift)) { + if (attr & mem_attr[j].val) { if (first) first = false; else diff --git a/include/efi.h b/include/efi.h index 0fe15e65c06c..eb2a569fe010 100644 --- a/include/efi.h +++ b/include/efi.h @@ -162,20 +162,16 @@ enum efi_mem_type { }; /* Attribute values */ -enum { - EFI_MEMORY_UC_SHIFT = 0, /* uncached */ - EFI_MEMORY_WC_SHIFT = 1, /* write-coalescing */ - EFI_MEMORY_WT_SHIFT = 2, /* write-through */ - EFI_MEMORY_WB_SHIFT = 3, /* write-back */ - EFI_MEMORY_UCE_SHIFT = 4, /* uncached, exported */ - EFI_MEMORY_WP_SHIFT = 12, /* write-protect */ - EFI_MEMORY_RP_SHIFT = 13, /* read-protect */ - EFI_MEMORY_XP_SHIFT = 14, /* execute-protect */ - EFI_MEMORY_RUNTIME_SHIFT = 63, /* range requires runtime mapping */ - - EFI_MEMORY_RUNTIME = 1ULL << EFI_MEMORY_RUNTIME_SHIFT, - EFI_MEM_DESC_VERSION = 1, -}; +#define EFI_MEMORY_UC ((u64)0x0000000000000001ULL) /* uncached */ +#define EFI_MEMORY_WC ((u64)0x0000000000000002ULL) /* write-coalescing */ +#define EFI_MEMORY_WT ((u64)0x0000000000000004ULL) /* write-through */ +#define EFI_MEMORY_WB ((u64)0x0000000000000008ULL) /* write-back */ +#define EFI_MEMORY_UCE ((u64)0x0000000000000010ULL) /* uncached, exported */ +#define EFI_MEMORY_WP ((u64)0x0000000000001000ULL) /* write-protect */ +#define EFI_MEMORY_RP ((u64)0x0000000000002000ULL) /* read-protect */ +#define EFI_MEMORY_XP ((u64)0x0000000000004000ULL) /* execute-protect */ +#define EFI_MEMORY_RUNTIME ((u64)0x8000000000000000ULL) /* range requires runtime mapping */ +#define EFI_MEM_DESC_VERSION 1 #define EFI_PAGE_SHIFT 12 #define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT) diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index ec66af98ea8f..233333bf6b18 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -171,14 +171,13 @@ uint64_t efi_add_memory_map(uint64_t start, uint64_t pages, int memory_type, switch (memory_type) { case EFI_RUNTIME_SERVICES_CODE: case EFI_RUNTIME_SERVICES_DATA: - newlist->desc.attribute = (1 << EFI_MEMORY_WB_SHIFT) | - (1ULL << EFI_MEMORY_RUNTIME_SHIFT); + newlist->desc.attribute = EFI_MEMORY_WB | EFI_MEMORY_RUNTIME; break; case EFI_MMAP_IO: - newlist->desc.attribute = 1ULL << EFI_MEMORY_RUNTIME_SHIFT; + newlist->desc.attribute = EFI_MEMORY_RUNTIME; break; default: - newlist->desc.attribute = 1 << EFI_MEMORY_WB_SHIFT; + newlist->desc.attribute = EFI_MEMORY_WB; break; }