From patchwork Mon Jul 21 15:16:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 33987 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f198.google.com (mail-pd0-f198.google.com [209.85.192.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 534B820672 for ; Mon, 21 Jul 2014 15:37:52 +0000 (UTC) Received: by mail-pd0-f198.google.com with SMTP id fp1sf50805658pdb.9 for ; Mon, 21 Jul 2014 08:37:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=WToV4JxhFSd2+9vTZg2yuvG8XGWr6gs+z0X8ZoIvr1g=; b=GXY2sZZwsQDG5eASazk+b2+o2HZkkTSV8r3iQ87nmsK0tL4hKlU6+BbpQY227IT7lh Yb/0vq7oRQT4vUg7B9glZ0svrrMp6VkI/YBMKp8/MdWtd7ur5SlQkAgumHc4pWa08rY6 LpTsarvdzGLokaLqpb+kBun0HoSVlfxkymCeYRPZ0OwSRgqBVM/cZYz5ysp1z1xa3xIc /GjWMyLonbyQsYhAzSY2RuXiGv7pwH3io2P+7Br+9Kr7eg62/qqcNlSfat4NIBUUBc1h llmRGn4bOoKGwgbaTiRP3GLd8owWAdm4xvAuENeVajM0Byvr2z0GB++rZSBFUrA9mDbX A52Q== X-Gm-Message-State: ALoCoQlaJ3AOX401L1bP1mmpXSvq+fCo4yEZBn/dM64lKiawDYFqH2iOHgfKLCxo2q+7iaTEd1QP X-Received: by 10.68.189.73 with SMTP id gg9mr7680159pbc.4.1405957068890; Mon, 21 Jul 2014 08:37:48 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.93.166 with SMTP id d35ls1997273qge.3.gmail; Mon, 21 Jul 2014 08:37:48 -0700 (PDT) X-Received: by 10.220.81.194 with SMTP id y2mr30344287vck.29.1405957068745; Mon, 21 Jul 2014 08:37:48 -0700 (PDT) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id r6si11635750vei.7.2014.07.21.08.37.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Jul 2014 08:37:45 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id id10so7727437vcb.7 for ; Mon, 21 Jul 2014 08:37:45 -0700 (PDT) X-Received: by 10.220.118.136 with SMTP id v8mr12690845vcq.50.1405957065160; Mon, 21 Jul 2014 08:37:45 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp122512vcb; Mon, 21 Jul 2014 08:37:44 -0700 (PDT) X-Received: by 10.66.251.98 with SMTP id zj2mr4968868pac.115.1405957063190; Mon, 21 Jul 2014 08:37:43 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id mt6si7299500pdb.352.2014.07.21.08.37.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jul 2014 08:37:43 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1X9Fcp-0002P2-Ae; Mon, 21 Jul 2014 15:35:39 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X9Fcn-0002NR-7p for linux-arm-kernel@bombadil.infradead.org; Mon, 21 Jul 2014 15:35:37 +0000 Received: from mail-wg0-f50.google.com ([74.125.82.50]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X9FLX-0003ty-7I for linux-arm-kernel@lists.infradead.org; Mon, 21 Jul 2014 15:17:51 +0000 Received: by mail-wg0-f50.google.com with SMTP id n12so6510464wgh.21 for ; Mon, 21 Jul 2014 08:17:21 -0700 (PDT) X-Received: by 10.194.243.10 with SMTP id wu10mr24104593wjc.44.1405955840753; Mon, 21 Jul 2014 08:17:20 -0700 (PDT) Received: from ards-macbook-pro.local ([212.91.105.246]) by mx.google.com with ESMTPSA id ft17sm38327602wjc.14.2014.07.21.08.17.17 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Jul 2014 08:17:20 -0700 (PDT) From: Ard Biesheuvel To: matt.fleming@intel.com, linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, will.deacon@arm.com, leif.lindholm@linaro.org Subject: [RFC PATCH 08/10] arm64/efi: use LE accessors to access UEFI data Date: Mon, 21 Jul 2014 17:16:23 +0200 Message-Id: <1405955785-13477-9-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1405955785-13477-1-git-send-email-ard.biesheuvel@linaro.org> References: <1405955785-13477-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140721_161747_293991_57F3216E X-CRM114-Status: GOOD ( 23.67 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.4.0 on casper.infradead.org summary: Content analysis details: (-2.6 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [74.125.82.50 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.50 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: roy.franz@linaro.org, victor.kamensky@linaro.org, steve.capper@linaro.org, Ard Biesheuvel , msalter@redhat.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 If we are running a BE kernel, we need to byte reverse all data that UEFI keeps, as UEFI is strictly little endian. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/efi.c | 53 +++++++++++++++++++++++------------------- drivers/firmware/efi/efi.c | 26 ++++++++++++--------- drivers/firmware/efi/efivars.c | 2 +- 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c index e72f3100958f..96df58824189 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -42,7 +42,7 @@ early_param("uefi_debug", uefi_debug_setup); static int __init is_normal_ram(efi_memory_desc_t *md) { - if (md->attribute & EFI_MEMORY_WB) + if (le64_to_cpu(md->attribute) & EFI_MEMORY_WB) return 1; return 0; } @@ -58,10 +58,11 @@ static void __init efi_setup_idmap(void) /* map runtime io spaces */ for_each_efi_memory_desc(&memmap, md) { - if (!(md->attribute & EFI_MEMORY_RUNTIME) || is_normal_ram(md)) + if (!(le64_to_cpu(md->attribute) & EFI_MEMORY_RUNTIME) || + is_normal_ram(md)) continue; - paddr = md->phys_addr; - npages = md->num_pages; + paddr = le64_to_cpu(md->phys_addr); + npages = le64_to_cpu(md->num_pages); memrange_efi_to_native(&paddr, &npages); size = npages << PAGE_SHIFT; create_id_mapping(paddr, size, 1); @@ -87,27 +88,27 @@ static int __init uefi_init(void) /* * Verify the EFI Table */ - if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) { + if (le64_to_cpu(efi.systab->hdr.signature) != EFI_SYSTEM_TABLE_SIGNATURE) { pr_err("System table signature incorrect\n"); return -EINVAL; } - if ((efi.systab->hdr.revision >> 16) < 2) + if ((le32_to_cpu(efi.systab->hdr.revision) >> 16) < 2) pr_warn("Warning: EFI system table version %d.%02d, expected 2.00 or greater\n", efi.systab->hdr.revision >> 16, efi.systab->hdr.revision & 0xffff); /* Show what we know for posterity */ - c16 = early_memremap(efi.systab->fw_vendor, + c16 = early_memremap(le64_to_cpu(efi.systab->fw_vendor), sizeof(vendor)); if (c16) { for (i = 0; i < (int) sizeof(vendor) - 1 && *c16; ++i) - vendor[i] = c16[i]; + vendor[i] = le16_to_cpu(c16[i]); vendor[i] = '\0'; } pr_info("EFI v%u.%.02u by %s\n", - efi.systab->hdr.revision >> 16, - efi.systab->hdr.revision & 0xffff, vendor); + le32_to_cpu(efi.systab->hdr.revision) >> 16, + le32_to_cpu(efi.systab->hdr.revision) & 0xffff, vendor); retval = efi_config_init(NULL); if (retval == 0) @@ -144,11 +145,11 @@ static __init int is_reserve_region(efi_memory_desc_t *md) if (!is_normal_ram(md)) return 0; - if (md->attribute & EFI_MEMORY_RUNTIME) + if (le64_to_cpu(md->attribute) & EFI_MEMORY_RUNTIME) return 1; - if (md->type == EFI_ACPI_RECLAIM_MEMORY || - md->type == EFI_RESERVED_TYPE) + if (le32_to_cpu(md->type) == EFI_ACPI_RECLAIM_MEMORY || + le32_to_cpu(md->type) == EFI_RESERVED_TYPE) return 1; return 0; @@ -163,13 +164,15 @@ static __init void reserve_regions(void) pr_info("Processing EFI memory map:\n"); for_each_efi_memory_desc(&memmap, md) { - paddr = md->phys_addr; - npages = md->num_pages; + u32 md_type = le32_to_cpu(md->type); + + paddr = le64_to_cpu(md->phys_addr); + npages = le64_to_cpu(md->num_pages); if (uefi_debug) pr_info(" 0x%012llx-0x%012llx [%s]", paddr, paddr + (npages << EFI_PAGE_SHIFT) - 1, - memory_type_name[md->type]); + memory_type_name[md_type]); memrange_efi_to_native(&paddr, &npages); size = npages << PAGE_SHIFT; @@ -178,8 +181,8 @@ static __init void reserve_regions(void) early_init_dt_add_memory_arch(paddr, size); if (is_reserve_region(md) || - md->type == EFI_BOOT_SERVICES_CODE || - md->type == EFI_BOOT_SERVICES_DATA) { + md_type == EFI_BOOT_SERVICES_CODE || + md_type == EFI_BOOT_SERVICES_DATA) { memblock_reserve(paddr, size); if (uefi_debug) pr_cont("*"); @@ -258,17 +261,18 @@ static void __init free_boot_services(void) */ if (free_start) { /* adjust free_end then free region */ - if (free_end > md->phys_addr) + if (free_end > le64_to_cpu(md->phys_addr)) free_end -= PAGE_SIZE; total_freed += free_region(free_start, free_end); free_start = 0; } - keep_end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT); + keep_end = le64_to_cpu(md->phys_addr) + + (le64_to_cpu(md->num_pages) << EFI_PAGE_SHIFT); continue; } - if (md->type != EFI_BOOT_SERVICES_CODE && - md->type != EFI_BOOT_SERVICES_DATA) { + if (le32_to_cpu(md->type) != EFI_BOOT_SERVICES_CODE && + le32_to_cpu(md->type) != EFI_BOOT_SERVICES_DATA) { /* no need to free this region */ continue; } @@ -276,8 +280,8 @@ static void __init free_boot_services(void) /* * We want to free memory from this region. */ - paddr = md->phys_addr; - npages = md->num_pages; + paddr = le64_to_cpu(md->phys_addr); + npages = le64_to_cpu(md->num_pages); memrange_efi_to_native(&paddr, &npages); size = npages << PAGE_SHIFT; @@ -475,3 +479,4 @@ err_unmap: return -1; } early_initcall(arm64_enter_virtual_mode); + diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 64ecbb501c50..24cb61b72d06 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -270,18 +270,23 @@ static __init int match_config_table(efi_guid_t *guid, int __init efi_config_init(efi_config_table_type_t *arch_tables) { void *config_tables, *tablep; - int i, sz; + unsigned long __tables; + int i, sz, nr_tables; - if (efi_enabled(EFI_64BIT)) + if (efi_enabled(EFI_64BIT)) { sz = sizeof(efi_config_table_64_t); - else + nr_tables = le64_to_cpu((__force __le64)efi.systab->nr_tables); + __tables = le64_to_cpu((__force __le64)efi.systab->tables); + } else { sz = sizeof(efi_config_table_32_t); + nr_tables = le32_to_cpu((__force __le32)efi.systab->nr_tables); + __tables = le32_to_cpu((__force __le32)efi.systab->tables); + } /* * Let's see what config tables the firmware passed to us. */ - config_tables = early_memremap(efi.systab->tables, - efi.systab->nr_tables * sz); + config_tables = early_memremap(__tables, nr_tables * sz); if (config_tables == NULL) { pr_err("Could not map Configuration table!\n"); return -ENOMEM; @@ -289,21 +294,20 @@ int __init efi_config_init(efi_config_table_type_t *arch_tables) tablep = config_tables; pr_info(""); - for (i = 0; i < efi.systab->nr_tables; i++) { + for (i = 0; i < nr_tables; i++) { efi_guid_t guid; unsigned long table; if (efi_enabled(EFI_64BIT)) { u64 table64; guid = ((efi_config_table_64_t *)tablep)->guid; - table64 = ((efi_config_table_64_t *)tablep)->table; - table = table64; + table = table64 = le64_to_cpu((__force __le64) + ((efi_config_table_64_t *)tablep)->table); #ifndef CONFIG_64BIT if (table64 >> 32) { pr_cont("\n"); pr_err("Table located above 4GB, disabling EFI.\n"); - early_memunmap(config_tables, - efi.systab->nr_tables * sz); + early_memunmap(config_tables, nr_tables * sz); return -EINVAL; } #endif @@ -318,7 +322,7 @@ int __init efi_config_init(efi_config_table_type_t *arch_tables) tablep += sz; } pr_cont("\n"); - early_memunmap(config_tables, efi.systab->nr_tables * sz); + early_memunmap(config_tables, nr_tables * sz); set_bit(EFI_CONFIG_TABLES, &efi.flags); diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c index f256ecd8a176..e33181a779ab 100644 --- a/drivers/firmware/efi/efivars.c +++ b/drivers/firmware/efi/efivars.c @@ -563,7 +563,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var) /* Convert Unicode to normal chars (assume top bits are 0), ala UTF-8 */ for (i=0; i < (int)(variable_name_size / sizeof(efi_char16_t)); i++) { - short_name[i] = variable_name[i] & 0xFF; + short_name[i] = le16_to_cpu((__force __le16)variable_name[i]); } /* This is ugly, but necessary to separate one vendor's private variables from another's. */