From patchwork Thu Jul 12 12:21:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141821 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1445767ljj; Thu, 12 Jul 2018 05:22:02 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf5yAwRiUmQto4/AaOMg6t079qMFCZJDJJ/Lb1vw8m02TXcFN5zY1cHwER2e8LF0DanIqg4 X-Received: by 2002:a65:6109:: with SMTP id z9-v6mr1910309pgu.243.1531398122830; Thu, 12 Jul 2018 05:22:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531398122; cv=none; d=google.com; s=arc-20160816; b=C9OlewSrPiMnfNnmJ9acynrPYHTHAPSddeiUO/OmUZ9+iv32wHwVolULjgSjhlG3Ob DcP3B7suFSBkR2LRcX6dTrZoGhTbC4l7a22uRoYy1On1DioZRGhAL+ZlGBr2o1GWdzpu q2ktPtAKpXttUf2shG4rpuDSrjKvAuAdjH9PujFh5E0TseDcZ0I4GoJJ9Xa0EXm2T8br u0TthkROK0tNAV7yGQjKqrfihWF60pvGO6EmFXk7ntJfyVWu3Am2zOSh2FcMwUPkgQBj 9STDaOaBJyFKnnL8oGwKly/Fxs77N7HXhH1e3TwJiteRvvNE/tnO3zyNTyTtPl0LjiJa Cxew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Mee1R2d7xL/SbP1sOTkeEF/1zDfZ4V0g6F7w6qTNs94=; b=ezahEzawV3gbWBZ1Drb7zZaGkgw2pNV+5JoBKdtejS/1gGsXJ9ythO7h1RrnkjiDba 7iskLrRSPNi5P6Yc1fZ0RGGGhob59Q5kQUqs9rQyxW+ShKGqyyehFFmzRCj7kxPGREzZ 6H6dS8om170pXV/okvVquDwjigrsgEyzNqZWCONhVKonT8GblZAapUif5DLb4Le15hoo cykv8Vgi9uzsBIgWwrvtP/a6qYcV7y9aXLFaYT36kgpOtxtsOFRkcZ3xXpnkZk81GwKK PrmB0uYtAInsI1cjg6Fg2HSzs4pWfBjAGGUmw6QGCY//03mJ4qqzpPpYL1IBvraGUOvj yeZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=TpE5neAd; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v8-v6si7016131pff.248.2018.07.12.05.22.02; Thu, 12 Jul 2018 05:22:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=TpE5neAd; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726818AbeGLMbV (ORCPT + 3 others); Thu, 12 Jul 2018 08:31:21 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:33135 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726650AbeGLMbV (ORCPT ); Thu, 12 Jul 2018 08:31:21 -0400 Received: by mail-wr1-f68.google.com with SMTP id g6-v6so12584546wrp.0 for ; Thu, 12 Jul 2018 05:22:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IM/cMUjTpL3xiwbZmg4o2pagF/mxE1L0krGAJOO1eMw=; b=TpE5neAdgQ4UrVhq91Bre57ykH6u0JCMS31b3Onn2Rcq1WgLLx5p18RrQyfb6Mg5wP HfT8ZPjFO+70vRq4YJaQyNevltC10oqonKlPJBNMWt4OPjInKgeBT5fvq8JUokpc0h5W FAfmjNschnCchkO9hiRLSblWtnGcF+kG7xPuU= 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:in-reply-to :references; bh=IM/cMUjTpL3xiwbZmg4o2pagF/mxE1L0krGAJOO1eMw=; b=GtdANLEqSb66/YvmulDYW+rvmNYYTqoxP69REnUZjTDfm5t55Qx5RbgdSGky89/yqV 34+1wry3e78QhgX6LMcGMVrGxTEmnfA5AlDoslo518vzwGg+h2t2d5BX2nOd0kFr57zE RqOB3c/yJvzDZNGvvABWVq2toUwM7aOB6eeARZivP8ZzJ9aJNddsA1y9ZmqhD8LHWS0b XiDcgm+xo179fIxheqflQpvv+mczU7BAGGTPlj4fD51Hyf/iH15pilLE1kQpa3bhPFf4 2bQrG4xWTrN/ROR8CF9TpDugK8VoFgwMmiJ6iVs9jN+2791BU2DAtVZP4+wAq9iunNmZ MKDQ== X-Gm-Message-State: AOUpUlHG7zRTRHaVXK7zZzyEPsHXsPCeYTT3gwaHc0ENQDY6rM5/3QDs VjNN42cLb6V16Qc7+XmK/sa6N+29M4g= X-Received: by 2002:adf:fa45:: with SMTP id y5-v6mr1754136wrr.138.1531398119638; Thu, 12 Jul 2018 05:21:59 -0700 (PDT) Received: from localhost.localdomain (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id y3-v6sm3551246wmd.24.2018.07.12.05.21.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jul 2018 05:21:58 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: sai.praneeth.prakhya@intel.com, mingo@kernel.org, hdegoede@redhat.com, lukas@wunner.de, Ard Biesheuvel Subject: [PATCH 1/6] efi/x86: prevent reentrant firmware calls in mixed mode Date: Thu, 12 Jul 2018 14:21:49 +0200 Message-Id: <20180712122154.13819-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180712122154.13819-1-ard.biesheuvel@linaro.org> References: <20180712122154.13819-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The UEFI spec does not permit runtime services to be called reentrantly, and so it is up to the OS to provide proper locking around such calls. For the native case, this was fixed a long time ago, but for the mixed mode case, no locking is done whatsoever. Note that the calls are made with preemption and interrupts disabled, so only SMP configurations are affected by this issue. So add a spinlock and grab it when invoking a UEFI runtime service in mixed mode. We will also need to provide non-blocking versions of SetVariable() and QueryVariableInfo(), so add those as well. Signed-off-by: Ard Biesheuvel --- arch/x86/platform/efi/efi_64.c | 101 +++++++++++++++++++- 1 file changed, 98 insertions(+), 3 deletions(-) -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index e01f7ceb9e7a..24f1231a9278 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c @@ -636,6 +636,8 @@ void efi_switch_mm(struct mm_struct *mm) #ifdef CONFIG_EFI_MIXED extern efi_status_t efi64_thunk(u32, ...); +static DEFINE_SPINLOCK(efi_runtime_lock); + #define runtime_service32(func) \ ({ \ u32 table = (u32)(unsigned long)efi.systab; \ @@ -657,17 +659,14 @@ extern efi_status_t efi64_thunk(u32, ...); #define efi_thunk(f, ...) \ ({ \ efi_status_t __s; \ - unsigned long __flags; \ u32 __func; \ \ - local_irq_save(__flags); \ arch_efi_call_virt_setup(); \ \ __func = runtime_service32(f); \ __s = efi64_thunk(__func, __VA_ARGS__); \ \ arch_efi_call_virt_teardown(); \ - local_irq_restore(__flags); \ \ __s; \ }) @@ -702,14 +701,17 @@ static efi_status_t efi_thunk_get_time(efi_time_t *tm, efi_time_cap_t *tc) { efi_status_t status; u32 phys_tm, phys_tc; + unsigned long flags; spin_lock(&rtc_lock); + spin_lock_irqsave(&efi_runtime_lock, flags); phys_tm = virt_to_phys_or_null(tm); phys_tc = virt_to_phys_or_null(tc); status = efi_thunk(get_time, phys_tm, phys_tc); + spin_unlock_irqrestore(&efi_runtime_lock, flags); spin_unlock(&rtc_lock); return status; @@ -719,13 +721,16 @@ static efi_status_t efi_thunk_set_time(efi_time_t *tm) { efi_status_t status; u32 phys_tm; + unsigned long flags; spin_lock(&rtc_lock); + spin_lock_irqsave(&efi_runtime_lock, flags); phys_tm = virt_to_phys_or_null(tm); status = efi_thunk(set_time, phys_tm); + spin_unlock_irqrestore(&efi_runtime_lock, flags); spin_unlock(&rtc_lock); return status; @@ -737,8 +742,10 @@ efi_thunk_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending, { efi_status_t status; u32 phys_enabled, phys_pending, phys_tm; + unsigned long flags; spin_lock(&rtc_lock); + spin_lock_irqsave(&efi_runtime_lock, flags); phys_enabled = virt_to_phys_or_null(enabled); phys_pending = virt_to_phys_or_null(pending); @@ -747,6 +754,7 @@ efi_thunk_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending, status = efi_thunk(get_wakeup_time, phys_enabled, phys_pending, phys_tm); + spin_unlock_irqrestore(&efi_runtime_lock, flags); spin_unlock(&rtc_lock); return status; @@ -757,13 +765,16 @@ efi_thunk_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm) { efi_status_t status; u32 phys_tm; + unsigned long flags; spin_lock(&rtc_lock); + spin_lock_irqsave(&efi_runtime_lock, flags); phys_tm = virt_to_phys_or_null(tm); status = efi_thunk(set_wakeup_time, enabled, phys_tm); + spin_unlock_irqrestore(&efi_runtime_lock, flags); spin_unlock(&rtc_lock); return status; @@ -781,6 +792,9 @@ efi_thunk_get_variable(efi_char16_t *name, efi_guid_t *vendor, efi_status_t status; u32 phys_name, phys_vendor, phys_attr; u32 phys_data_size, phys_data; + unsigned long flags; + + spin_lock_irqsave(&efi_runtime_lock, flags); phys_data_size = virt_to_phys_or_null(data_size); phys_vendor = virt_to_phys_or_null(vendor); @@ -791,6 +805,8 @@ efi_thunk_get_variable(efi_char16_t *name, efi_guid_t *vendor, status = efi_thunk(get_variable, phys_name, phys_vendor, phys_attr, phys_data_size, phys_data); + spin_unlock_irqrestore(&efi_runtime_lock, flags); + return status; } @@ -800,6 +816,34 @@ efi_thunk_set_variable(efi_char16_t *name, efi_guid_t *vendor, { u32 phys_name, phys_vendor, phys_data; efi_status_t status; + unsigned long flags; + + spin_lock_irqsave(&efi_runtime_lock, flags); + + phys_name = virt_to_phys_or_null_size(name, efi_name_size(name)); + phys_vendor = virt_to_phys_or_null(vendor); + phys_data = virt_to_phys_or_null_size(data, data_size); + + /* If data_size is > sizeof(u32) we've got problems */ + status = efi_thunk(set_variable, phys_name, phys_vendor, + attr, data_size, phys_data); + + spin_unlock_irqrestore(&efi_runtime_lock, flags); + + return status; +} + +static efi_status_t +efi_thunk_set_variable_nonblocking(efi_char16_t *name, efi_guid_t *vendor, + u32 attr, unsigned long data_size, + void *data) +{ + u32 phys_name, phys_vendor, phys_data; + efi_status_t status; + unsigned long flags; + + if (!spin_trylock_irqsave(&efi_runtime_lock, flags)) + return EFI_NOT_READY; phys_name = virt_to_phys_or_null_size(name, efi_name_size(name)); phys_vendor = virt_to_phys_or_null(vendor); @@ -809,6 +853,8 @@ efi_thunk_set_variable(efi_char16_t *name, efi_guid_t *vendor, status = efi_thunk(set_variable, phys_name, phys_vendor, attr, data_size, phys_data); + spin_unlock_irqrestore(&efi_runtime_lock, flags); + return status; } @@ -819,6 +865,9 @@ efi_thunk_get_next_variable(unsigned long *name_size, { efi_status_t status; u32 phys_name_size, phys_name, phys_vendor; + unsigned long flags; + + spin_lock_irqsave(&efi_runtime_lock, flags); phys_name_size = virt_to_phys_or_null(name_size); phys_vendor = virt_to_phys_or_null(vendor); @@ -827,6 +876,8 @@ efi_thunk_get_next_variable(unsigned long *name_size, status = efi_thunk(get_next_variable, phys_name_size, phys_name, phys_vendor); + spin_unlock_irqrestore(&efi_runtime_lock, flags); + return status; } @@ -835,10 +886,15 @@ efi_thunk_get_next_high_mono_count(u32 *count) { efi_status_t status; u32 phys_count; + unsigned long flags; + + spin_lock_irqsave(&efi_runtime_lock, flags); phys_count = virt_to_phys_or_null(count); status = efi_thunk(get_next_high_mono_count, phys_count); + spin_unlock_irqrestore(&efi_runtime_lock, flags); + return status; } @@ -847,10 +903,15 @@ efi_thunk_reset_system(int reset_type, efi_status_t status, unsigned long data_size, efi_char16_t *data) { u32 phys_data; + unsigned long flags; + + spin_lock_irqsave(&efi_runtime_lock, flags); phys_data = virt_to_phys_or_null_size(data, data_size); efi_thunk(reset_system, reset_type, status, data_size, phys_data); + + spin_unlock_irqrestore(&efi_runtime_lock, flags); } static efi_status_t @@ -872,10 +933,13 @@ efi_thunk_query_variable_info(u32 attr, u64 *storage_space, { efi_status_t status; u32 phys_storage, phys_remaining, phys_max; + unsigned long flags; if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION) return EFI_UNSUPPORTED; + spin_lock_irqsave(&efi_runtime_lock, flags); + phys_storage = virt_to_phys_or_null(storage_space); phys_remaining = virt_to_phys_or_null(remaining_space); phys_max = virt_to_phys_or_null(max_variable_size); @@ -883,6 +947,35 @@ efi_thunk_query_variable_info(u32 attr, u64 *storage_space, status = efi_thunk(query_variable_info, attr, phys_storage, phys_remaining, phys_max); + spin_unlock_irqrestore(&efi_runtime_lock, flags); + + return status; +} + +static efi_status_t +efi_thunk_query_variable_info_nonblocking(u32 attr, u64 *storage_space, + u64 *remaining_space, + u64 *max_variable_size) +{ + efi_status_t status; + u32 phys_storage, phys_remaining, phys_max; + unsigned long flags; + + if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION) + return EFI_UNSUPPORTED; + + if (!spin_trylock_irqsave(&efi_runtime_lock, flags)) + return EFI_NOT_READY; + + phys_storage = virt_to_phys_or_null(storage_space); + phys_remaining = virt_to_phys_or_null(remaining_space); + phys_max = virt_to_phys_or_null(max_variable_size); + + status = efi_thunk(query_variable_info, attr, phys_storage, + phys_remaining, phys_max); + + spin_unlock_irqrestore(&efi_runtime_lock, flags); + return status; } @@ -908,9 +1001,11 @@ void efi_thunk_runtime_setup(void) efi.get_variable = efi_thunk_get_variable; efi.get_next_variable = efi_thunk_get_next_variable; efi.set_variable = efi_thunk_set_variable; + efi.set_variable_nonblocking = efi_thunk_set_variable_nonblocking; efi.get_next_high_mono_count = efi_thunk_get_next_high_mono_count; efi.reset_system = efi_thunk_reset_system; efi.query_variable_info = efi_thunk_query_variable_info; + efi.query_variable_info_nonblocking = efi_thunk_query_variable_info_nonblocking; efi.update_capsule = efi_thunk_update_capsule; efi.query_capsule_caps = efi_thunk_query_capsule_caps; } From patchwork Thu Jul 12 12:21:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141822 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1445792ljj; Thu, 12 Jul 2018 05:22:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe5KMH4KdFojPdsyfUe3NAk1iq+7M3yvrjsuYxG+CxKSw6om0Ujci5urmeDJ+EGFMVcn0BU X-Received: by 2002:a17:902:9b98:: with SMTP id y24-v6mr1962367plp.177.1531398124437; Thu, 12 Jul 2018 05:22:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531398124; cv=none; d=google.com; s=arc-20160816; b=joq1Pj1Ll9MdD1n8wzCwfIHh50hQwbrQOrE5HQmeNuVgHg+2hr/LPzIsqdWxbLaqSG +VxIpPh7tmBW7mjjflPEYA832bVv7xa1N0enLSVglAmNNZQQp+L21woJ5NcN/bV6t71J bhEUU7a/bo11Rdbvg/+1UPBXmV4Wy7iQ9KtjqAbI1F7QJHJcF2clfD6Cm/gVmLjK0+iW u22lSGK3ngh/l1rOMkXk4D09ghwhaEBN+aMmZxTBp4t1pmLNNtv7PY25LWslUnbrW1l7 dgfbnT6pQQGeEkwbtBaAEmglggpTwbyQlXEc7d3apP0EHw/G4U+//JGt31rhoBb17/tE lBbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=NqoWVwjs0IbWWkpdr1chW4dwGJvYj1cdlKjgIf8FBj8=; b=a5h9svBTe90HrWgXbUFTAl15+wQM8Y4JagWHYHpYOhHNK39cGyRU+8YRsQVmHeSfi1 O2/X1aGCnUOvbpCQJw34DNYo6bnCAQrtDKSdx1u8pp8XYZplQWfU4eX5xhn4FLOE4gS2 Wvt+7F+YEv6MyJgDOsblmRbHtgV8cHfzqDaHVwkQuK9Q7WFIjNqbZBLv5lyP3ht4lEgi HEECSV28iOj6L3HQQXEjeRDuzdajNYG7sKFREGo4f/OxXwmG6jzXfvcKslcOLt5epaVk FnfM0CYN+NHVTWPCE8BjeNYcOP8r8p+VYkDbK6wPL+arqBadclisgDswmUzn+0/ONTZM +V1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=idQA+CXG; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v8-v6si7016131pff.248.2018.07.12.05.22.04; Thu, 12 Jul 2018 05:22:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=idQA+CXG; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726888AbeGLMbX (ORCPT + 3 others); Thu, 12 Jul 2018 08:31:23 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:39839 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726810AbeGLMbW (ORCPT ); Thu, 12 Jul 2018 08:31:22 -0400 Received: by mail-wr1-f66.google.com with SMTP id h10-v6so21489846wre.6 for ; Thu, 12 Jul 2018 05:22:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Xa1oCOxGi3VGiwj5bciKhIoLsDEFyyT+8HAJdmSrulo=; b=idQA+CXGEeUU7C5in6fpLahqDhdvdTza1+G8iGsi/i0mz6kBPc93RcqJCc5ygeHGNY arWEEyUTqR5EG4fXqVO8LEBc+SCdJxCFF8ho661PrtDMxexjaud4G+auSBp8E4T/MaxO kALP1mOyknc6rUQ0zmdgYFgCw5pmrLdtHkJmw= 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:in-reply-to :references; bh=Xa1oCOxGi3VGiwj5bciKhIoLsDEFyyT+8HAJdmSrulo=; b=pNkyhtRk5l0L3hIaO3HDBOvADWiiRtk1ps4e4l5d3VjSwZZYgMiDFio0SuYtFQ8HTb JkiOG7f7pBMAuxIyMUN4QwMWW2hARUfUJGv6FjU9Y1YIBBr71LfEIjx/aSK/7gmojFhK Mmp/Ar57XQvICLjJQkbwCfFw9zQWJKmiUJN2hAzVcWWc3A0i4qlSyYLvuKZFNeMiJxM+ YJ43IlY+x3x4D5H2lRqnlZj1YTE3yDEKY8eVRH3qKQSGuQPIOc8256DLJEz9gKsG+8Lu kiNrCGJGNSdg5+O/ydgp9o6NlffD0Go50B+nNBRg0nNHHS9EQUbVBCifVNmy2NWAWEgH zLMg== X-Gm-Message-State: AOUpUlEDYonA4PQ+vgL1PJATMz7i3JNUrgkl6AnFkEXd0KIjBfSMhw6/ 35JLnZdiQwwklm/hxm2EdvHNbrEFT48= X-Received: by 2002:a5d:48cd:: with SMTP id p13-v6mr1762616wrs.0.1531398121102; Thu, 12 Jul 2018 05:22:01 -0700 (PDT) Received: from localhost.localdomain (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id y3-v6sm3551246wmd.24.2018.07.12.05.21.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jul 2018 05:22:00 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: sai.praneeth.prakhya@intel.com, mingo@kernel.org, hdegoede@redhat.com, lukas@wunner.de, Ard Biesheuvel Subject: [PATCH 2/6] efi/x86: merge setup_efi_pci32 and setup_efi_pci64 routines Date: Thu, 12 Jul 2018 14:21:50 +0200 Message-Id: <20180712122154.13819-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180712122154.13819-1-ard.biesheuvel@linaro.org> References: <20180712122154.13819-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org After merging the 32-bit and 64-bit versions of the code that invokes the PCI I/O protocol methods to preserve PCI ROM images in commit 2c3625cb9fa2 ("efi/x86: Fold __setup_efi_pci32() and __setup_efi_pci64() ...") there are still separate code paths for 32-bit and 64-bit, where the only difference is the size of a EFI_HANDLE. So let's parameterize a single implementation for that difference only, and get rid of the two copies of the code. While at it, rename __setup_efi_pci() to preserve_pci_rom_image() to better reflect its purpose. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/eboot.c | 123 +++++--------------- 1 file changed, 32 insertions(+), 91 deletions(-) -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index 9f6813493945..c72550783c16 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -111,7 +111,7 @@ void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str) } static efi_status_t -__setup_efi_pci(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom) +preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom) { struct pci_setup_rom *rom = NULL; efi_status_t status; @@ -181,92 +181,6 @@ __setup_efi_pci(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom) return status; } -static void -setup_efi_pci32(struct boot_params *params, void **pci_handle, unsigned long size) -{ - efi_pci_io_protocol_t *pci = NULL; - efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; - u32 *handles = (u32 *)(unsigned long)pci_handle; - efi_status_t status; - unsigned long nr_pci; - struct setup_data *data; - int i; - - data = (struct setup_data *)(unsigned long)params->hdr.setup_data; - - while (data && data->next) - data = (struct setup_data *)(unsigned long)data->next; - - nr_pci = size / sizeof(u32); - for (i = 0; i < nr_pci; i++) { - struct pci_setup_rom *rom = NULL; - u32 h = handles[i]; - - status = efi_call_early(handle_protocol, h, - &pci_proto, (void **)&pci); - - if (status != EFI_SUCCESS) - continue; - - if (!pci) - continue; - - status = __setup_efi_pci(pci, &rom); - if (status != EFI_SUCCESS) - continue; - - if (data) - data->next = (unsigned long)rom; - else - params->hdr.setup_data = (unsigned long)rom; - - data = (struct setup_data *)rom; - } -} - -static void -setup_efi_pci64(struct boot_params *params, void **pci_handle, unsigned long size) -{ - efi_pci_io_protocol_t *pci = NULL; - efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; - u64 *handles = (u64 *)(unsigned long)pci_handle; - efi_status_t status; - unsigned long nr_pci; - struct setup_data *data; - int i; - - data = (struct setup_data *)(unsigned long)params->hdr.setup_data; - - while (data && data->next) - data = (struct setup_data *)(unsigned long)data->next; - - nr_pci = size / sizeof(u64); - for (i = 0; i < nr_pci; i++) { - struct pci_setup_rom *rom = NULL; - u64 h = handles[i]; - - status = efi_call_early(handle_protocol, h, - &pci_proto, (void **)&pci); - - if (status != EFI_SUCCESS) - continue; - - if (!pci) - continue; - - status = __setup_efi_pci(pci, &rom); - if (status != EFI_SUCCESS) - continue; - - if (data) - data->next = (unsigned long)rom; - else - params->hdr.setup_data = (unsigned long)rom; - - data = (struct setup_data *)rom; - } -} - /* * There's no way to return an informative status from this function, * because any analysis (and printing of error messages) needs to be @@ -282,6 +196,9 @@ static void setup_efi_pci(struct boot_params *params) void **pci_handle = NULL; efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; unsigned long size = 0; + unsigned long nr_pci; + struct setup_data *data; + int i; status = efi_call_early(locate_handle, EFI_LOCATE_BY_PROTOCOL, @@ -305,10 +222,34 @@ static void setup_efi_pci(struct boot_params *params) if (status != EFI_SUCCESS) goto free_handle; - if (efi_early->is64) - setup_efi_pci64(params, pci_handle, size); - else - setup_efi_pci32(params, pci_handle, size); + data = (struct setup_data *)(unsigned long)params->hdr.setup_data; + + while (data && data->next) + data = (struct setup_data *)(unsigned long)data->next; + + nr_pci = size / (efi_is_64bit() ? sizeof(u64) : sizeof(u32)); + for (i = 0; i < nr_pci; i++) { + efi_pci_io_protocol_t *pci = NULL; + struct pci_setup_rom *rom; + + status = efi_call_early(handle_protocol, + efi_is_64bit() ? ((u64 *)pci_handle)[i] + : ((u32 *)pci_handle)[i], + &pci_proto, (void **)&pci); + if (status != EFI_SUCCESS || !pci) + continue; + + status = preserve_pci_rom_image(pci, &rom); + if (status != EFI_SUCCESS) + continue; + + if (data) + data->next = (unsigned long)rom; + else + params->hdr.setup_data = (unsigned long)rom; + + data = (struct setup_data *)rom; + } free_handle: efi_call_early(free_pool, pci_handle); From patchwork Thu Jul 12 12:21:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141823 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1445811ljj; Thu, 12 Jul 2018 05:22:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdqqd8k1rZAf2p/PB+wqtznk4UmqBrmZnxIeJCBcsP+h7Rvs9fbAyF+RCDra871c5irFOZ/ X-Received: by 2002:a17:902:8a87:: with SMTP id p7-v6mr1957436plo.281.1531398125065; Thu, 12 Jul 2018 05:22:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531398125; cv=none; d=google.com; s=arc-20160816; b=ieaawAWACP+4KBzb9nc4GBrcrWGfhXD27/wui2KnQf5JVphdvP2cwkoiHdKCAPxOeg 9vKdSr2sR6SxPVwOl4HV2wEfySF162OQj+oHUlNA18P/9tOH4BWpV9nPjWtIJYrPXO1G oHLUlKGBmAoARDjSG+Q8S17satKo6+KRp0USnTFNbJZYbg6udVMf899DGxanjzEc0D6Y jXsTheGTul/+9KknN83R1OijpcgXuaz7NikbygR2JV/17BrT6tk36HvI/8s3AeWaPywl v3xMyW9qR9GtJHnEKTl+KbQnqnzvy+yJ/4tB9Gmhq5nFrgAQkHHe+kckqh3FBvEfdvFA B0Pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=JV1uVoUDq/3jhH69BLaIYv9CzyL9eJOVly68vFzBSMw=; b=xxCWmygIzmnRnmHjLQa0m3Ukdiq0lQWXwMcW4zhI1cq6VHpNK2v9EWdevyuTRP2C66 FTbZ9LLdEQf0HCvJWUhENhxEoRyuayo2map5Mcn4pAdWJ/FI25KAWIZkgMPsatIqtGor zjc/Q3D2Mgd2jQdgEx2JYrQ4MZe9hWnPyHkWAAtzyE2V5+aNE8pRVB+NbzLegbAAoYUW bh65u6kW9fBGl+U3U572F/YKG6P7LNnfBTsyK9vHlyHL04h+wNmPykyaSf6pvlUIDKvS oRbE8B0UboBhU5Yyafq0X4M0/5sVKBlWVH4Z9OV3lJPqo3O4u5Ceh81RmqqoTfczwAQ5 112w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=FFDl+jlz; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v8-v6si7016131pff.248.2018.07.12.05.22.04; Thu, 12 Jul 2018 05:22:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=FFDl+jlz; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726810AbeGLMbX (ORCPT + 3 others); Thu, 12 Jul 2018 08:31:23 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:43136 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726650AbeGLMbX (ORCPT ); Thu, 12 Jul 2018 08:31:23 -0400 Received: by mail-wr1-f66.google.com with SMTP id b15-v6so21527448wrv.10 for ; Thu, 12 Jul 2018 05:22:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lXByrcLbJy+t9KQq8NWgJSOFOA/CgZkdv1BMwsVKOaA=; b=FFDl+jlzEMwdWGdLSEc56EbVwCUoiQftcAN/IGo4AhOdZ+6XJdkPX+B2cQl0Mi+84i H0S4ztDPKgh6z32WrKC3HpSPjTzr7SvlgNuw98RQKB1DDjlkQHntYdoyxOhcjbOArNpB aSgC2fiVy6+unpHWvJHfYvtlqMOweZw05vwlE= 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:in-reply-to :references; bh=lXByrcLbJy+t9KQq8NWgJSOFOA/CgZkdv1BMwsVKOaA=; b=Eis3bGY91yvHgKZmzz7FtuNAkHRAMBaGGXCfezL/gB1BGB9ZxYGJliky3no3WoFMC5 pPGSLGcz6gTadleQqZd/We6LTMw0U7f3ZgqlDsTZwy7cuKaM+/whspCqyboAKrw2/QZ6 3TGJiNV07jRYNENvSev/JL8boWr7vDDomf08YEmXICDXodNv9viVW6D5m+kpZNRp7b/D sQfkr2BmFwtNu76mi3KE77Y13feRe6zRohro6ogtcUeqtM1zI/xbGjg67Vv6cfZKyvyY RGElmplOaGfUT1duPjGZL0iadvi2CI5rNmMr5e3605DLyMCJbyXDnreXt5rYuqb9yxfe /VDQ== X-Gm-Message-State: AOUpUlFPnOJKXvR3Fn/mV/Bc9cZTUeVJpsn1GQ3sNkEoCEjmOXMNNqtO P6FT6sdw49dO5vj9uK/O3gpQjI5dpss= X-Received: by 2002:adf:ef03:: with SMTP id e3-v6mr1517049wro.182.1531398122531; Thu, 12 Jul 2018 05:22:02 -0700 (PDT) Received: from localhost.localdomain (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id y3-v6sm3551246wmd.24.2018.07.12.05.22.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jul 2018 05:22:01 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: sai.praneeth.prakhya@intel.com, mingo@kernel.org, hdegoede@redhat.com, lukas@wunner.de, Ard Biesheuvel Subject: [PATCH 3/6] efi/x86: align efi_uga_draw_protocol typedef names to convention Date: Thu, 12 Jul 2018 14:21:51 +0200 Message-Id: <20180712122154.13819-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180712122154.13819-1-ard.biesheuvel@linaro.org> References: <20180712122154.13819-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The linux-efi subsystem uses typedefs with the _t suffix to declare data structures that originate in the UEFI spec. Our type mangling for mixed mode depends on this convention, so rename the UGA drawing protocols to allow efi_call_proto() to be used with them in a subsequent patch. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/eboot.c | 4 ++-- arch/x86/boot/compressed/eboot.h | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index c72550783c16..011d5c289449 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -321,7 +321,7 @@ static void setup_quirks(struct boot_params *boot_params) static efi_status_t setup_uga32(void **uga_handle, unsigned long size, u32 *width, u32 *height) { - struct efi_uga_draw_protocol *uga = NULL, *first_uga; + efi_uga_draw_protocol_t *uga = NULL, *first_uga; efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID; unsigned long nr_ugas; u32 *handles = (u32 *)uga_handle; @@ -366,7 +366,7 @@ setup_uga32(void **uga_handle, unsigned long size, u32 *width, u32 *height) static efi_status_t setup_uga64(void **uga_handle, unsigned long size, u32 *width, u32 *height) { - struct efi_uga_draw_protocol *uga = NULL, *first_uga; + efi_uga_draw_protocol_t *uga = NULL, *first_uga; efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID; unsigned long nr_ugas; u64 *handles = (u64 *)uga_handle; diff --git a/arch/x86/boot/compressed/eboot.h b/arch/x86/boot/compressed/eboot.h index e799dc5c6448..8297387c4676 100644 --- a/arch/x86/boot/compressed/eboot.h +++ b/arch/x86/boot/compressed/eboot.h @@ -12,22 +12,22 @@ #define DESC_TYPE_CODE_DATA (1 << 0) -struct efi_uga_draw_protocol_32 { +typedef struct { u32 get_mode; u32 set_mode; u32 blt; -}; +} efi_uga_draw_protocol_32_t; -struct efi_uga_draw_protocol_64 { +typedef struct { u64 get_mode; u64 set_mode; u64 blt; -}; +} efi_uga_draw_protocol_64_t; -struct efi_uga_draw_protocol { +typedef struct { void *get_mode; void *set_mode; void *blt; -}; +} efi_uga_draw_protocol_t; #endif /* BOOT_COMPRESSED_EBOOT_H */ From patchwork Thu Jul 12 12:21:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141824 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1445841ljj; Thu, 12 Jul 2018 05:22:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdwd7wQfU9MUiiAgqtEY2MyQie8kHnOOUeE6w2e4an5C8/MfOSyu+F7epKqQHxD6mCLY9QF X-Received: by 2002:a62:d94a:: with SMTP id s71-v6mr2176218pfg.164.1531398126996; Thu, 12 Jul 2018 05:22:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531398126; cv=none; d=google.com; s=arc-20160816; b=qo24hjIdIDJfwUoaJ5b1da1Bakvs20h+GpXQWKz88UMHRq+JX0PZXugDl7+TETvijl 7SK1Zew4/ZQqaXcw5gSmDGlqLtXcUNE2UcQSxMT+KsehMkr9kOAl9m0D3MxFnbqAntKh fpIJfqeMj7hK1Wfu/y83tZ5y3548a7a+efCkBtAHUivDIqN9NAQTMjp3/jrL2VeyNGn0 mjYdKVxWwbTc9KimIQ9Y1Or5pErYFV8Hu7fhnQ1SK9KewUWSSgebt3ZKdsONvDZH5FF3 5LUawx51dqrEEIeIph6wLX7jRDNivoD/atUqHbe/TcidEdrse3AiA6v7j0seI6HvuEZB aWAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=k66eypQ+gfJy5GrB9k7glPT9ORuRPAOBLRyQCO9oMvg=; b=bISIFYNQcXop1Dtzu3RhR5fVDEw+o5LryVeCaFG5pMX5426PDTJpicOf75dUcPf5tc JSww9Y+ZLgy9MZP0iJWRLosheDOTlGcksvGBIU5CKnxN+wE7b+5/si0YzSXjwU/hhhKP cDFM53d9R+LWOJHT2X/xjvfQRPMdwBQwoRV7CnqOZ+aQpveAZxm1czPVqnBnZ8+9ioNv mpbHjexQOePAvPn3Q7GHHeU/6wzPn8kfLDmnPQprDzwRJyCL12dIofzubI7rPwyfpCWp ApQUpY0gvJCge334+iuDlSxZuEbbP+u3ozsi7LflF6HHppVwuqzg6zvOLogv7AxAu1Xf 7aGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=GIuG+7xG; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v8-v6si7016131pff.248.2018.07.12.05.22.06; Thu, 12 Jul 2018 05:22:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=GIuG+7xG; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727077AbeGLMbZ (ORCPT + 3 others); Thu, 12 Jul 2018 08:31:25 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43138 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726650AbeGLMbZ (ORCPT ); Thu, 12 Jul 2018 08:31:25 -0400 Received: by mail-wr1-f67.google.com with SMTP id b15-v6so21527528wrv.10 for ; Thu, 12 Jul 2018 05:22:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fLEKaKaGvUJrSkn8yTm6nFj1/boi+MXs0KsskJ0gQQ0=; b=GIuG+7xGDC0YUo1dge3NJTY74+QNzzq9F/grskaNFj3s+5jvb0yHQiOwHDFU/WhgjU XAuF5COPDFF7M32vLfJ0GmJ5+YF/a+mgHjjhECWnr9MzPQ9K+ntVameYPTftv/G7uEAW 6WEsjri7wNcTge9j7UUuM8Y4oLgumlOWlRkhY= 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:in-reply-to :references; bh=fLEKaKaGvUJrSkn8yTm6nFj1/boi+MXs0KsskJ0gQQ0=; b=D4TiNNZ5rlDIiaSQwWtgPZYGWjxHPalD7U3asYadoQVrmCk37fxi3kiiaZVXbP+fMX jO2r/T5bD+rIfDH/xYqyLuCKUnkQQivPPMv4zkKL4tQQGqpVFZHfKKKSI/pQJyJAG6O6 vQUUmgTHlbimiKAbciR5zA2Nr6SgIBVgpESs0++hL6NvE/hVOf4VLgfhsxgF4VDg8Ysp mSoJUCJY6AdrmRU/3vLoqahKCG15lWhLnl8Xvv06zkCnEWUHO848tbSsYtBynWspvsUy CyAmPlcIeSYWqMxmZ2ld5WdU+HQoEELOaGYQ2FYN7+u8r9FxU7LU0WRR0Fw9gLC3Jlpm 0kyw== X-Gm-Message-State: AOUpUlEb7mRKzBVqxs8N2W+r6+ARuTXBxui8fkcEFW4jRd9E0h1cIHW8 OxAf/jwdiKKoGml6FiQSD9lxYHabTxI= X-Received: by 2002:adf:8466:: with SMTP id 93-v6mr1228353wrf.274.1531398123930; Thu, 12 Jul 2018 05:22:03 -0700 (PDT) Received: from localhost.localdomain (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id y3-v6sm3551246wmd.24.2018.07.12.05.22.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jul 2018 05:22:03 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: sai.praneeth.prakhya@intel.com, mingo@kernel.org, hdegoede@redhat.com, lukas@wunner.de, Ard Biesheuvel Subject: [PATCH 4/6] efi/x86: merge 32-bit and 64-bit UGA draw protocol setup routines Date: Thu, 12 Jul 2018 14:21:52 +0200 Message-Id: <20180712122154.13819-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180712122154.13819-1-ard.biesheuvel@linaro.org> References: <20180712122154.13819-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The two versions of setup_uga##() are mostly identical, with the exception of the size of EFI_HANDLE. So let's merge the two, and pull the implementation into the calling function setup_uga(). Note that the 64-bit version was only mixed-mode safe by accident: it only calls the get_mode() method of the UGA draw protocol, which happens to be the first member, and so truncating that value at offset 0 to 32 bits happens to produce the correct value. But let's not rely on that, and use the proper API instead. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/eboot.c | 111 +++++--------------- 1 file changed, 26 insertions(+), 85 deletions(-) -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index 011d5c289449..ac8e442db71f 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -318,81 +318,54 @@ static void setup_quirks(struct boot_params *boot_params) } } +/* + * See if we have Universal Graphics Adapter (UGA) protocol + */ static efi_status_t -setup_uga32(void **uga_handle, unsigned long size, u32 *width, u32 *height) +setup_uga(struct screen_info *si, efi_guid_t *uga_proto, unsigned long size) { + efi_status_t status; + u32 width, height; + void **uga_handle = NULL; efi_uga_draw_protocol_t *uga = NULL, *first_uga; - efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID; unsigned long nr_ugas; - u32 *handles = (u32 *)uga_handle; - efi_status_t status = EFI_INVALID_PARAMETER; int i; - first_uga = NULL; - nr_ugas = size / sizeof(u32); - for (i = 0; i < nr_ugas; i++) { - efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID; - u32 w, h, depth, refresh; - void *pciio; - u32 handle = handles[i]; - - status = efi_call_early(handle_protocol, handle, - &uga_proto, (void **)&uga); - if (status != EFI_SUCCESS) - continue; - - efi_call_early(handle_protocol, handle, &pciio_proto, &pciio); - - status = efi_early->call((unsigned long)uga->get_mode, uga, - &w, &h, &depth, &refresh); - if (status == EFI_SUCCESS && (!first_uga || pciio)) { - *width = w; - *height = h; - - /* - * Once we've found a UGA supporting PCIIO, - * don't bother looking any further. - */ - if (pciio) - break; - - first_uga = uga; - } - } + status = efi_call_early(allocate_pool, EFI_LOADER_DATA, + size, (void **)&uga_handle); + if (status != EFI_SUCCESS) + return status; - return status; -} + status = efi_call_early(locate_handle, + EFI_LOCATE_BY_PROTOCOL, + uga_proto, NULL, &size, uga_handle); + if (status != EFI_SUCCESS) + goto free_handle; -static efi_status_t -setup_uga64(void **uga_handle, unsigned long size, u32 *width, u32 *height) -{ - efi_uga_draw_protocol_t *uga = NULL, *first_uga; - efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID; - unsigned long nr_ugas; - u64 *handles = (u64 *)uga_handle; - efi_status_t status = EFI_INVALID_PARAMETER; - int i; + height = 0; + width = 0; first_uga = NULL; - nr_ugas = size / sizeof(u64); + nr_ugas = size / (efi_is_64bit() ? sizeof(u64) : sizeof(u32)); for (i = 0; i < nr_ugas; i++) { efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID; u32 w, h, depth, refresh; void *pciio; - u64 handle = handles[i]; + unsigned long handle = efi_is_64bit() ? ((u64 *)uga_handle)[i] + : ((u32 *)uga_handle)[i]; status = efi_call_early(handle_protocol, handle, - &uga_proto, (void **)&uga); + uga_proto, (void **)&uga); if (status != EFI_SUCCESS) continue; efi_call_early(handle_protocol, handle, &pciio_proto, &pciio); - status = efi_early->call((unsigned long)uga->get_mode, uga, - &w, &h, &depth, &refresh); + status = efi_call_proto(efi_uga_draw_protocol, get_mode, uga, + &w, &h, &depth, &refresh); if (status == EFI_SUCCESS && (!first_uga || pciio)) { - *width = w; - *height = h; + width = w; + height = h; /* * Once we've found a UGA supporting PCIIO, @@ -405,38 +378,6 @@ setup_uga64(void **uga_handle, unsigned long size, u32 *width, u32 *height) } } - return status; -} - -/* - * See if we have Universal Graphics Adapter (UGA) protocol - */ -static efi_status_t -setup_uga(struct screen_info *si, efi_guid_t *uga_proto, unsigned long size) -{ - efi_status_t status; - u32 width, height; - void **uga_handle = NULL; - - status = efi_call_early(allocate_pool, EFI_LOADER_DATA, - size, (void **)&uga_handle); - if (status != EFI_SUCCESS) - return status; - - status = efi_call_early(locate_handle, - EFI_LOCATE_BY_PROTOCOL, - uga_proto, NULL, &size, uga_handle); - if (status != EFI_SUCCESS) - goto free_handle; - - height = 0; - width = 0; - - if (efi_early->is64) - status = setup_uga64(uga_handle, size, &width, &height); - else - status = setup_uga32(uga_handle, size, &width, &height); - if (!width && !height) goto free_handle; From patchwork Thu Jul 12 12:21:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141825 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1445863ljj; Thu, 12 Jul 2018 05:22:08 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcb8qVVOdNl4Yvqhnofa/0yL2zN+8kZqevHX7PgaBNDCI+0h4n5ZpY3mWTq/jnQ6B1XaUYI X-Received: by 2002:a62:8d84:: with SMTP id p4-v6mr2199477pfk.251.1531398127900; Thu, 12 Jul 2018 05:22:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531398127; cv=none; d=google.com; s=arc-20160816; b=i4W/bVbiLayfmtqzOA4cYrbjmt/5nyLx/thdyojNl8AI0qi7JJz0NPCypRcIL9/Ru1 Oz76pG/dfK2jZA44SKI+AhKvNSwRy7KicTJLeIOg+onWDVJsDGpYWmyOrZ+cHqGwB2VW jHR816i1mWkEvP8E0KSVUGSxy8T8rTBQgEkHV/J/Ifv0aY+/hvAKUWcSCaC+ARB0hY3x UtOnzGeNf2naoRHm2TQsDq/Mol2AxxXL4FO2Ujs2Lt6EAxUs8RA9XlRinhROixw8RNcY aGl4NZ6vuOxrKcNtkkJkdVwkMyojdfqc+SCmiYLogkgA21xazJ5FQylSawkWRfv62Dkz +Law== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=25wg7I0bdUlC4DIeHZFJ0xU9n0s9AKthURt+JptmIew=; b=zo1AwKtjUiItQWgkrC8EZeHV1oKWfXyKrHez6MYar5kNxpyFZv/3yr9yQ6hIp78V8H rd+/dTx9IEwcnIg0Jg3op8FrlRHwvOMn2wMPU4eG757a03sozM87sgG44gUbVT3lTvp9 ba+Sl1jzzqrszgcvWykeFjt5MfPMpH/kn3mD5J/M6Pbgp3YDJ58hfJBvK/HujTkQQKOc DUpl6hnkLzWgrUu+3n1LDXq7p9cpvLMW6C249zmKsxKktILYK+IExBMyD7avqE59MnZR U1h+j1SEamtDb0GWScU44ytoqCIDL4JGqiR5NYPlkKLGgI9RNwRfNkcgt6cmkuiAlqFK gb9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=K5bA4r6s; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v8-v6si7016131pff.248.2018.07.12.05.22.07; Thu, 12 Jul 2018 05:22:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=K5bA4r6s; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726650AbeGLMb0 (ORCPT + 3 others); Thu, 12 Jul 2018 08:31:26 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:34733 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727006AbeGLMb0 (ORCPT ); Thu, 12 Jul 2018 08:31:26 -0400 Received: by mail-wr1-f65.google.com with SMTP id c13-v6so21460348wrt.1 for ; Thu, 12 Jul 2018 05:22:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zwFKNtIGwJIp24L0NIpBT5xt9rkuDsOvqBjuvChMS0w=; b=K5bA4r6s3sm89jMMXjH9vGTaQW8BSayXkMKAeDp1Gx0Y/T2tdfXw8eIE2MB+al+D4M 5zutWwv8Q4hAgceNrvJdOtzdzcessiLY0K8J+I7sBQkLqalKsvB1oyBmw8Oq3i8L1AH4 9czJW2FoYtIKxFfQM4KSD0zxZFG9apfkKqer0= 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:in-reply-to :references; bh=zwFKNtIGwJIp24L0NIpBT5xt9rkuDsOvqBjuvChMS0w=; b=UtFTcPXhEbCOj3Rxkiuv0QbrfQG8fnzBEdUxJeWUl6+chnaNQIhsR1iGj5YwUp5aNl KwgQRNM5FJjl+0PGlNvBBFQWQjfoXw5NmYoa0dKbLjPS60r8bXoE3RJKPt4Bu+HEr50o WeN7AqkXlYZy2gQooYVioRXZ+gm+gZmcdCQzUSGi6wIt/5NYJMwfWRh/UuSUrb+KfzM3 SLs+abcxr66iYlrVdZlnVBEDxnWGghra7+ExQUEzjXHi3i3Of6wJV1+2IrgDGFagI+AC kNSGZoAXIm12iayD+7R5PevZtisuZjEEr3v47sv9N/fhCoKUMZ3rG4p0X0+hO3MfzZ5e p05Q== X-Gm-Message-State: AOUpUlFQy5pu3wb7Oxs3wvOe3pP6EEW6IIiP9hZaUS9DgbWBBmaQTDhA ENIyG/f4v8RPi8EfFNFgUV/BLr46G5A= X-Received: by 2002:adf:a815:: with SMTP id l21-v6mr1469459wrc.281.1531398125349; Thu, 12 Jul 2018 05:22:05 -0700 (PDT) Received: from localhost.localdomain (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id y3-v6sm3551246wmd.24.2018.07.12.05.22.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jul 2018 05:22:04 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: sai.praneeth.prakhya@intel.com, mingo@kernel.org, hdegoede@redhat.com, lukas@wunner.de, Ard Biesheuvel Subject: [PATCH 5/6] efi/x86: add missing NULL initialization in UGA draw protocol discovery Date: Thu, 12 Jul 2018 14:21:53 +0200 Message-Id: <20180712122154.13819-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180712122154.13819-1-ard.biesheuvel@linaro.org> References: <20180712122154.13819-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The UGA draw protocol discovery routine looks for a EFI handle that has both the UGA draw protocol and the PCI I/O protocol installed. It checks for the latter by calling handle_protocol() and pass it a PCI I/O protocol pointer variable by reference, but fails to initialize it to NULL, which means the non-NULL check later on in the code could produce false positives, given that the return code of the handle_protocol() call is ignored entirely. So add the missing initialization. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/eboot.c | 1 + 1 file changed, 1 insertion(+) -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index ac8e442db71f..92b573fd239c 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -359,6 +359,7 @@ setup_uga(struct screen_info *si, efi_guid_t *uga_proto, unsigned long size) if (status != EFI_SUCCESS) continue; + pciio = NULL; efi_call_early(handle_protocol, handle, &pciio_proto, &pciio); status = efi_call_proto(efi_uga_draw_protocol, get_mode, uga, From patchwork Thu Jul 12 12:21:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141826 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1445893ljj; Thu, 12 Jul 2018 05:22:09 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfwGw8Q0htd+t52nnKzIKzRaftLUBY2Rkal35EXSPAKWHKRneayxMWHwG4NyGmernZsjy01 X-Received: by 2002:a62:d39b:: with SMTP id z27-v6mr2230825pfk.182.1531398129418; Thu, 12 Jul 2018 05:22:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531398129; cv=none; d=google.com; s=arc-20160816; b=ev9xLPoXoon8drYhcoTO+a32O6Po9U2n6G20lZ1fDrfGcOXIw1CjO/PDFDivBIX5Sb qE47GD/8TGY6yeHqc9lug+3WUf03t9C/sTSBi3Ii9JfVM7jja0rqE9bUwiVcun/X2vzn v2VmagfIVI+Ks+O6kyntB2ipotWo26ytXJuEg2EQHQVSXsT8YSlPDxlrZmy0Lu+UbJIY 7VxWRn7Wb+rc50mYkRWm8EvAoeNGHIyQtzppyrTs4DSUfJF6uMcSzVoFO3HR/hGcqd8/ QMqiipxXBxE0Asedo+gCAHVuH90+57CMFTeIPJ5ETDzvsJD/mOCcXYm1ZdHP/q4tmXJG iXfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=8TxoZuggYj8RZ7qKULFIbQsL5pAiRJVxLYlaN7L14JM=; b=mXwgXjcSZwygOtKTT2Xh82gtEOAPtsZmpcSmpAyKoTu3WxTEA48MLq0AM+ce3UPu4p gJ/MnwkoWwLo3ARdXzLziDVbAQfcayhFpVSa+OZONCawLRNrkx5g+oiBHSw1oG1fH3FH 12N9VdaZWjM02qJTDEJv6h5XnXTSOHYyvL5GcncbM1DPp0KGvbLH0pllCxJ4N3836lTq rVldvcczbeRDhQQB32fMgH+Ur4NghokB5lE1cLmOCnrBB0DSMtaWlnN2oauW4GBLszSP NZSIaCTrvXEY0ng3kCrF8DK1UKGtpQnpM8DImwP6hbBNcxFXfC2+v0UocX6gMacNzqTW ajeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=jy3Afy41; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v8-v6si7016131pff.248.2018.07.12.05.22.09; Thu, 12 Jul 2018 05:22:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=jy3Afy41; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727092AbeGLMb2 (ORCPT + 3 others); Thu, 12 Jul 2018 08:31:28 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:46323 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727006AbeGLMb1 (ORCPT ); Thu, 12 Jul 2018 08:31:27 -0400 Received: by mail-wr1-f66.google.com with SMTP id s11-v6so21492017wra.13 for ; Thu, 12 Jul 2018 05:22:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cVyQ/JUzlmp8ewnQhL+UUUcp7O1/aplvmkaHEWVk55s=; b=jy3Afy41Ir6Ehy2fLVB3GihNTfrQ9Ir6cbnM9t28oqWuDsRp4ivTcp22OUAj8YiGsJ 5ojLF8OGjmFmOPAk594hf1OR95Y7DPBEgVXSmf2rZBOlLidXytJIYYSn60wrYj69qUgn sU45AH0UTK1NZ+44nKXbIm1KuUeeJrmKW2f10= 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:in-reply-to :references; bh=cVyQ/JUzlmp8ewnQhL+UUUcp7O1/aplvmkaHEWVk55s=; b=XFj+gx52fnCm+bk0/AF/Qchug4nMV8oDrttz1Yqc7UQQb/BSyBnnDxIvB+B9C4Yyud 2akTm8EhNY7EW1DClCggfq8677d+JNMrJ0QClcdgAsMcTTmGnfMlNl5MStgSKiO3miJj WLyYL55EEjDczejEV6ADwVspN67FNeO3lAzfwiO9X2MH0KZQceu3k9S2n+JUzUyFjQnW ECh0989PRvGNL/f7TWQJWBwoORH4GgD1RbgaWLmOstPuCGdga4Rfk6prmYi2dSuUd7DX iWmRxACpjDA7PlPw+J9vOcVeF5EvPm6kyjBFpjV9xyzKHTLTwFmKgPolcTMfX9ohStjc zYow== X-Gm-Message-State: AOUpUlHDjkZp7/Y92Uq9CfF9g4u4dqrT7AS4Zdb2r2XBlTAwb8N4f2jW C1yLx48VtGtfGNiO+uem/jWgXOol7mg= X-Received: by 2002:adf:ee4e:: with SMTP id w14-v6mr1684413wro.63.1531398126723; Thu, 12 Jul 2018 05:22:06 -0700 (PDT) Received: from localhost.localdomain (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id y3-v6sm3551246wmd.24.2018.07.12.05.22.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jul 2018 05:22:06 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: sai.praneeth.prakhya@intel.com, mingo@kernel.org, hdegoede@redhat.com, lukas@wunner.de, Ard Biesheuvel Subject: [PATCH 6/6] efi/x86: replace references to efi_early->is64 with efi_is_64bit() Date: Thu, 12 Jul 2018 14:21:54 +0200 Message-Id: <20180712122154.13819-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180712122154.13819-1-ard.biesheuvel@linaro.org> References: <20180712122154.13819-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org There are a couple of places in the x86 EFI stub code where we select between 32-bit and 64-bit versions of the support routines based on the value of efi_early->is64. Referencing that field directly is a bad idea, since it prevents the compiler from inferring that this field can never be true on a 32-bit build, and can only become false on a 64-bit build if support for mixed mode is compiled in. This results in dead code to be retained in the uncompressed part of the kernel image, which is wasteful. So switch to the efi_is_64bit() helper, which will resolve to a constant boolean unless building for 64-bit with mixed mode support. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/eboot.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index 92b573fd239c..b492fba230ea 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -98,7 +98,7 @@ static inline efi_status_t __open_volume64(void *__image, void **__fh) efi_status_t efi_open_volume(efi_system_table_t *sys_table, void *__image, void **__fh) { - if (efi_early->is64) + if (efi_is_64bit()) return __open_volume64(__image, __fh); return __open_volume32(__image, __fh); @@ -467,7 +467,7 @@ struct boot_params *make_boot_params(struct efi_config *c) if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) return NULL; - if (efi_early->is64) + if (efi_is_64bit()) setup_boot_services64(efi_early); else setup_boot_services32(efi_early); @@ -746,8 +746,7 @@ static efi_status_t exit_boot_func(efi_system_table_t *sys_table_arg, return EFI_SUCCESS; } -static efi_status_t exit_boot(struct boot_params *boot_params, - void *handle, bool is64) +static efi_status_t exit_boot(struct boot_params *boot_params, void *handle) { unsigned long map_sz, key, desc_size, buff_size; efi_memory_desc_t *mem_map; @@ -768,7 +767,7 @@ static efi_status_t exit_boot(struct boot_params *boot_params, priv.efi = &boot_params->efi_info; priv.e820ext = NULL; priv.e820ext_size = 0; - priv.is64 = is64; + priv.is64 = efi_is_64bit(); /* Might as well exit boot services now */ status = efi_exit_boot_services(sys_table, handle, &map, &priv, @@ -803,13 +802,11 @@ efi_main(struct efi_config *c, struct boot_params *boot_params) struct desc_struct *desc; void *handle; efi_system_table_t *_table; - bool is64; efi_early = c; _table = (efi_system_table_t *)(unsigned long)efi_early->table; handle = (void *)(unsigned long)efi_early->image_handle; - is64 = efi_early->is64; sys_table = _table; @@ -817,7 +814,7 @@ efi_main(struct efi_config *c, struct boot_params *boot_params) if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) goto fail; - if (is64) + if (efi_is_64bit()) setup_boot_services64(efi_early); else setup_boot_services32(efi_early); @@ -873,7 +870,7 @@ efi_main(struct efi_config *c, struct boot_params *boot_params) hdr->code32_start = bzimage_addr; } - status = exit_boot(boot_params, handle, is64); + status = exit_boot(boot_params, handle); if (status != EFI_SUCCESS) { efi_printk(sys_table, "exit_boot() failed!\n"); goto fail;