From patchwork Wed Jul 11 09:40:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141713 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp70479ljj; Wed, 11 Jul 2018 02:41:45 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcPxDN6WDSgMrTO2qW4BxNSO+EHAUR5zq/mW8JpybGgPRbOlu2uFkHIxOIFScqFOiMpGqPV X-Received: by 2002:a62:fc4b:: with SMTP id e72-v6mr14898208pfh.168.1531302105708; Wed, 11 Jul 2018 02:41:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531302105; cv=none; d=google.com; s=arc-20160816; b=wHloYmGe9O7LnyY7vjwyKC1Flumr8XSuZtUfS0w0MTBvcWBQSsgEUvhd2nxqTx0Rzp phhITyCdLCyrBWDRDqmXVcOTNqatkuTcQ/opWuMjnHQBplzT3dGnQVAqCJspOMbC26OJ 6PQlLZRwSoPglN1x7qNvvoHznYwIbtPpY76RPGjNc0kYpEPonwPL0hM4NO0ZSsETyldk wLcZhLfcFRV1lM5FIsPr3dhwv+XmlB+bgv8NR+hW4qiYrvC29Jh7mLEpprMzQmjTNkRm 9f8KbP2E9EyqTLKJ9GYukm8zYCTo7teC7bDZwANxOVjVcIUPUdU8GuLmsQvwAu0lk5Ay 40Dw== 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=/q/sznLHl7/eGa0nIgn7Rl1zB0oOPHdHKcT0/DG3mmI=; b=XSyd/LyOcjV+TSnPGpPjYUmzDbpMpNOGFDowhYncDvD6rhipjG99eG1dwT7044Bj6/ ydic7Bxq27cNBLfyq3bQyebsYP4LdfUG7UhseL4c+GEQreY/xRK7LBtGLB/l8nr+jgo4 Gw06zveX6jL4MCtN+OlGT6GdmIkA0XTDNDmJlkZXiI6PFq/MC9MY3856vTL+3+GhdZE+ AEIyl/938gXbDmvVFezLc13/UGtqnM25c41ojDrtHyhbdksvdpj1O6dgoIApB/86TM7G d34JdHDairXR8KKPxGkJhC+awRRwvL4ZY6H4D6ASZ+1yD1vq59iFhAGfl5TE7eo4zdh9 Qi4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NxGCGonp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (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 o5-v6si18429675plk.25.2018.07.11.02.41.45; Wed, 11 Jul 2018 02:41:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NxGCGonp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732631AbeGKJoU (ORCPT + 22 others); Wed, 11 Jul 2018 05:44:20 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:38573 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726477AbeGKJoU (ORCPT ); Wed, 11 Jul 2018 05:44:20 -0400 Received: by mail-wm0-f68.google.com with SMTP id 69-v6so1814093wmf.3 for ; Wed, 11 Jul 2018 02:40:52 -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=/q/sznLHl7/eGa0nIgn7Rl1zB0oOPHdHKcT0/DG3mmI=; b=NxGCGonpLZkmEeIDuPLeFHFtG5j80zMXTsEdiu3XivE5TKiuVWSIUI1ib2zjAkHu8d o+UZKoVk7w28ELVveptunwB0A2QHj7W4En5PRKSdi+ZY4VcPdxrnKPliS2KPYKfxcTZQ /LAGI59Nup92sQrs/86h4c7DbjHbT35EBHPUA= 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=/q/sznLHl7/eGa0nIgn7Rl1zB0oOPHdHKcT0/DG3mmI=; b=YcGv02nAA/rvAvQttJP00RHSPQo4ZWWlUie/k2dOIJ0lkgRMIk+6AP78T4MiChrQaF vSJj5NFN5BoE2pEDOwBzlSeVWsgBo/uiUC23NpaXY0F5zGkUwwKEWJruaU5TduouU+E/ N6d68WpgrmQdQr5XS3+XHpGoOI9bUrWzHheqUcmqpPpSsvzdeplQcE0u/DlWE16DDpIS 9CGfc39rE2g3OfyC572l1ixoO9RRCcPbcIB2gSOIOtcYcEkGWKMSArH6X3U9C18O9ejt 1/9Pk0vP+N61lumkOhZgPXZxgi7lYm9G7Njj9PdSlmmBFVLUiZW6TI0deIwEYrtINVPD wpMg== X-Gm-Message-State: APt69E3EA6+IFo66GdyseJk+yre8Wg8t9a4RP9tvo8tzimgrSkKPBUTf T8wRvTg8MbZQa3TyC3NRBb1a8aMbpOQ= X-Received: by 2002:a1c:c14:: with SMTP id 20-v6mr18591887wmm.117.1531302051627; Wed, 11 Jul 2018 02:40:51 -0700 (PDT) Received: from localhost.localdomain (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id t124-v6sm1641311wmt.29.2018.07.11.02.40.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 02:40:50 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Sai Praneeth , Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 2/8] efi/x86: Use non-blocking SetVariable() for efi_delete_dummy_variable() Date: Wed, 11 Jul 2018 11:40:34 +0200 Message-Id: <20180711094040.12506-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180711094040.12506-1-ard.biesheuvel@linaro.org> References: <20180711094040.12506-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sai Praneeth Presently, efi_delete_dummy_variable() uses set_variable() which might block and hence kernel prints stack trace with a warning "bad: scheduling from the idle thread!". So, make efi_delete_dummy_variable() use set_variable_nonblocking(), which, as the name suggests doesn't block. Signed-off-by: Sai Praneeth Prakhya Signed-off-by: Ard Biesheuvel --- arch/x86/platform/efi/quirks.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) -- 2.17.1 diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c index 36c1f8b9f7e0..6af39dc40325 100644 --- a/arch/x86/platform/efi/quirks.c +++ b/arch/x86/platform/efi/quirks.c @@ -105,12 +105,11 @@ early_param("efi_no_storage_paranoia", setup_storage_paranoia); */ void efi_delete_dummy_variable(void) { - efi.set_variable((efi_char16_t *)efi_dummy_name, - &EFI_DUMMY_GUID, - EFI_VARIABLE_NON_VOLATILE | - EFI_VARIABLE_BOOTSERVICE_ACCESS | - EFI_VARIABLE_RUNTIME_ACCESS, - 0, NULL); + efi.set_variable_nonblocking((efi_char16_t *)efi_dummy_name, + &EFI_DUMMY_GUID, + EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, 0, NULL); } /* From patchwork Wed Jul 11 09:40:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141711 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp70162ljj; Wed, 11 Jul 2018 02:41:26 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcaYzbht5tlmJFV1uSM0jihiXYuTn1M8aL2IhdazwCl9xf/W0SL6bUbulKp0e24CeVP7Xbq X-Received: by 2002:a17:902:b586:: with SMTP id a6-v6mr27885336pls.174.1531302086621; Wed, 11 Jul 2018 02:41:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531302086; cv=none; d=google.com; s=arc-20160816; b=TPegNvX/E76sg6wxWkAvPgVDJrvlmdgbWIPJgIOc4TscuhNE6da0g3FQoI8/EeCRsK PtBhP0kVFUXb3P1ghxu1KhIqF6TIiPdRqKGr4huJcn9gtBScjUTXvzCYNQ0YpXD6RWYH I+F0q4mlxBqTZ4n+z5aeOFIAkYdJmqey9iLu1ZbwxKtmm9Z1fZYJcSLFHXfSUfDw/YM+ Mthu2YgmdN/zHX+yvgDr5nwMlNcipkS7L5tEa0DHhIrtipoVYbd0fm3kLCOridcLrYab UR4Wjdf5SQ41Eu68ZFJsIMj5J+GxXzX7uDKAY4uxW/wga/iNiYpOPatwE526mSC0VanV dQug== 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=T/pQ2dXw0S7li09NwH2n2zx6kGdi0vZ92wbsvuy9tB4=; b=MB2zINfRLEF/2ugNpJyVy7kPHFGGQ2yCubwoKPKmMel9+zBmTFRqK2tL19Q7RWxGLq lKcpzusuFLH8vTl9aY5OYJN4XqBM2F+ofSZOwA7h7T+YdSfIVoIbEWa8dssN/S0d4FDG 4NfjfvhFiAdEI2dAFRTsodaRxUDhWdV04dGvHOSw/HzwrI3x1M9JcrtdztOYFo9f+4gu w0uXXmBiSJxvmrD6AIveL4xMHdktsD9p28+8YNVa88S9KTGYO4B00ua92kRpu6kwSIKo n7FOBN9EvFngLyF9jDoea8qp8baTFEERqawLTnTJuoKOlOkCmr28OaoCLq9Wt9LOnShC QH4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WMGkT3i5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (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 r192-v6si18709462pgr.634.2018.07.11.02.41.26; Wed, 11 Jul 2018 02:41:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WMGkT3i5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732678AbeGKJoX (ORCPT + 22 others); Wed, 11 Jul 2018 05:44:23 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:37038 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732628AbeGKJoV (ORCPT ); Wed, 11 Jul 2018 05:44:21 -0400 Received: by mail-wr1-f65.google.com with SMTP id q10-v6so17452048wrd.4 for ; Wed, 11 Jul 2018 02:40:53 -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=T/pQ2dXw0S7li09NwH2n2zx6kGdi0vZ92wbsvuy9tB4=; b=WMGkT3i5Ecxd+CLP9yAqlMj4YNerH76u3qOzzf0F9yABhUU6ZWNUxU8UwswFoYwP7k Hl42EVLLpCn8MOXR2Ox2T/EL+DZzss0EBy++3zeBYSoaT3rRkWq37mDVaNG3tkR3g45A g3KPrUcjSL3AnkZwhLD91hP5mu9zzhJpciAhI= 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=T/pQ2dXw0S7li09NwH2n2zx6kGdi0vZ92wbsvuy9tB4=; b=TS3Whch0TN6Hb8VM2MO94AWkZExSdZGdCa83IHsS3J6CVQz0jlqDAcgNiSM1j6Bs0u oDC+j2q8ZWHzZKYjPt+RmpgjNq3Mcck3MBGxO0ko6vRIiW0MqAGwA34hp7fb6hEmFQ9B nAsMUcKrOsGg2QDzdHr8VdoOYgngGlGkHVOq7BjzLnQ2sE/0n19fDqxBDenY8LgQgHw1 kIM6cIHjF2r5XYaQjRtweqD0yHoxL/Zg48ah/xLIP78iIa4YuMRmVu8cnaVrrP5Y54Ih e5BDh07izPQaM5XNKwTJXypm2MZ7aFpRzGXx7IU6t46L6RU6gUzu+Wnbet0qMmzkLUrE WVvQ== X-Gm-Message-State: AOUpUlHqT8cap+kr2VGUDfd6pfY8GO2nqaDyZsuUncPovlUGcLkCdLAd TaQGIkd2JHCb9GFJxHikL6Ubdw== X-Received: by 2002:adf:e34d:: with SMTP id n13-v6mr12741331wrj.158.1531302053227; Wed, 11 Jul 2018 02:40:53 -0700 (PDT) Received: from localhost.localdomain (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id t124-v6sm1641311wmt.29.2018.07.11.02.40.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 02:40:52 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Sai Praneeth , Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 3/8] efi: Use a work queue to invoke EFI Runtime Services Date: Wed, 11 Jul 2018 11:40:35 +0200 Message-Id: <20180711094040.12506-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180711094040.12506-1-ard.biesheuvel@linaro.org> References: <20180711094040.12506-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sai Praneeth Presently, when a user process requests the kernel to execute any UEFI runtime service, the kernel temporarily switches to a separate set of page tables that describe the virtual mapping of the UEFI runtime services regions in memory. Since UEFI runtime services are typically invoked with interrupts enabled, any code that may be called during this time, will have an incorrect view of the process's address space. Although it is unusual for code running in interrupt context to make assumptions about the process context it runs in, there are cases (such as the perf subsystem taking samples) where this causes problems. So let's set up a work queue for calling UEFI runtime services, so that the actual calls are made when the work queue items are dispatched by a work queue worker running in a separate kernel thread. Such threads are not expected to have userland mappings in the first place, and so the additional mappings created for the UEFI runtime services can never clash with any. The ResetSystem() runtime service is not covered by the work queue handling, since it is not expected to return, and may be called at a time when the kernel is torn down to the point where we cannot expect work queues to still be operational. The non-blocking variants of SetVariable() and QueryVariableInfo() are also excluded: these are intended to be used from atomic context, which obviously rules out waiting for a completion to be signalled by another thread. Note that these variants are currently only used for UEFI runtime services calls that occur very early in the boot, and for ones that occur in critical conditions, e.g., to flush kernel logs to UEFI variables via efi-pstore. Suggested-by: Andy Lutomirski Signed-off-by: Sai Praneeth Prakhya [ardb: exclude ResetSystem() from the workqueue treatment merge from 2 separate patches and rewrite commit log] Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efi.c | 14 ++ drivers/firmware/efi/runtime-wrappers.c | 202 ++++++++++++++++++++++-- include/linux/efi.h | 3 + 3 files changed, 204 insertions(+), 15 deletions(-) -- 2.17.1 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 232f4915223b..1379a375dfa8 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -84,6 +84,8 @@ struct mm_struct efi_mm = { .mmlist = LIST_HEAD_INIT(efi_mm.mmlist), }; +struct workqueue_struct *efi_rts_wq; + static bool disable_runtime; static int __init setup_noefi(char *arg) { @@ -337,6 +339,18 @@ static int __init efisubsys_init(void) if (!efi_enabled(EFI_BOOT)) return 0; + /* + * Since we process only one efi_runtime_service() at a time, an + * ordered workqueue (which creates only one execution context) + * should suffice all our needs. + */ + efi_rts_wq = alloc_ordered_workqueue("efi_rts_wq", 0); + if (!efi_rts_wq) { + pr_err("Creating efi_rts_wq failed, EFI runtime services disabled.\n"); + clear_bit(EFI_RUNTIME_SERVICES, &efi.flags); + return 0; + } + /* We register the efi directory at /sys/firmware/efi */ efi_kobj = kobject_create_and_add("efi", firmware_kobj); if (!efi_kobj) { diff --git a/drivers/firmware/efi/runtime-wrappers.c b/drivers/firmware/efi/runtime-wrappers.c index ae54870b2788..aa66cbf23512 100644 --- a/drivers/firmware/efi/runtime-wrappers.c +++ b/drivers/firmware/efi/runtime-wrappers.c @@ -1,6 +1,15 @@ /* * runtime-wrappers.c - Runtime Services function call wrappers * + * Implementation summary: + * ----------------------- + * 1. When user/kernel thread requests to execute efi_runtime_service(), + * enqueue work to efi_rts_wq. + * 2. Caller thread waits for completion until the work is finished + * because it's dependent on the return status and execution of + * efi_runtime_service(). + * For instance, get_variable() and get_next_variable(). + * * Copyright (C) 2014 Linaro Ltd. * * Split off from arch/x86/platform/efi/efi.c @@ -22,6 +31,9 @@ #include #include #include +#include +#include + #include /* @@ -33,6 +45,76 @@ #define __efi_call_virt(f, args...) \ __efi_call_virt_pointer(efi.systab->runtime, f, args) +/* efi_runtime_service() function identifiers */ +enum efi_rts_ids { + GET_TIME, + SET_TIME, + GET_WAKEUP_TIME, + SET_WAKEUP_TIME, + GET_VARIABLE, + GET_NEXT_VARIABLE, + SET_VARIABLE, + QUERY_VARIABLE_INFO, + GET_NEXT_HIGH_MONO_COUNT, + UPDATE_CAPSULE, + QUERY_CAPSULE_CAPS, +}; + +/* + * efi_runtime_work: Details of EFI Runtime Service work + * @arg<1-5>: EFI Runtime Service function arguments + * @status: Status of executing EFI Runtime Service + * @efi_rts_id: EFI Runtime Service function identifier + * @efi_rts_comp: Struct used for handling completions + */ +struct efi_runtime_work { + void *arg1; + void *arg2; + void *arg3; + void *arg4; + void *arg5; + efi_status_t status; + struct work_struct work; + enum efi_rts_ids efi_rts_id; + struct completion efi_rts_comp; +}; + +/* + * efi_queue_work: Queue efi_runtime_service() and wait until it's done + * @rts: efi_runtime_service() function identifier + * @rts_arg<1-5>: efi_runtime_service() function arguments + * + * Accesses to efi_runtime_services() are serialized by a binary + * semaphore (efi_runtime_lock) and caller waits until the work is + * finished, hence _only_ one work is queued at a time and the caller + * thread waits for completion. + */ +#define efi_queue_work(_rts, _arg1, _arg2, _arg3, _arg4, _arg5) \ +({ \ + struct efi_runtime_work efi_rts_work; \ + efi_rts_work.status = EFI_ABORTED; \ + \ + init_completion(&efi_rts_work.efi_rts_comp); \ + INIT_WORK_ONSTACK(&efi_rts_work.work, efi_call_rts); \ + efi_rts_work.arg1 = _arg1; \ + efi_rts_work.arg2 = _arg2; \ + efi_rts_work.arg3 = _arg3; \ + efi_rts_work.arg4 = _arg4; \ + efi_rts_work.arg5 = _arg5; \ + efi_rts_work.efi_rts_id = _rts; \ + \ + /* \ + * queue_work() returns 0 if work was already on queue, \ + * _ideally_ this should never happen. \ + */ \ + if (queue_work(efi_rts_wq, &efi_rts_work.work)) \ + wait_for_completion(&efi_rts_work.efi_rts_comp); \ + else \ + pr_err("Failed to queue work to efi_rts_wq.\n"); \ + \ + efi_rts_work.status; \ +}) + void efi_call_virt_check_flags(unsigned long flags, const char *call) { unsigned long cur_flags, mismatch; @@ -90,13 +172,98 @@ void efi_call_virt_check_flags(unsigned long flags, const char *call) */ static DEFINE_SEMAPHORE(efi_runtime_lock); +/* + * Calls the appropriate efi_runtime_service() with the appropriate + * arguments. + * + * Semantics followed by efi_call_rts() to understand efi_runtime_work: + * 1. If argument was a pointer, recast it from void pointer to original + * pointer type. + * 2. If argument was a value, recast it from void pointer to original + * pointer type and dereference it. + */ +static void efi_call_rts(struct work_struct *work) +{ + struct efi_runtime_work *efi_rts_work; + void *arg1, *arg2, *arg3, *arg4, *arg5; + efi_status_t status = EFI_NOT_FOUND; + + efi_rts_work = container_of(work, struct efi_runtime_work, work); + arg1 = efi_rts_work->arg1; + arg2 = efi_rts_work->arg2; + arg3 = efi_rts_work->arg3; + arg4 = efi_rts_work->arg4; + arg5 = efi_rts_work->arg5; + + switch (efi_rts_work->efi_rts_id) { + case GET_TIME: + status = efi_call_virt(get_time, (efi_time_t *)arg1, + (efi_time_cap_t *)arg2); + break; + case SET_TIME: + status = efi_call_virt(set_time, (efi_time_t *)arg1); + break; + case GET_WAKEUP_TIME: + status = efi_call_virt(get_wakeup_time, (efi_bool_t *)arg1, + (efi_bool_t *)arg2, (efi_time_t *)arg3); + break; + case SET_WAKEUP_TIME: + status = efi_call_virt(set_wakeup_time, *(efi_bool_t *)arg1, + (efi_time_t *)arg2); + break; + case GET_VARIABLE: + status = efi_call_virt(get_variable, (efi_char16_t *)arg1, + (efi_guid_t *)arg2, (u32 *)arg3, + (unsigned long *)arg4, (void *)arg5); + break; + case GET_NEXT_VARIABLE: + status = efi_call_virt(get_next_variable, (unsigned long *)arg1, + (efi_char16_t *)arg2, + (efi_guid_t *)arg3); + break; + case SET_VARIABLE: + status = efi_call_virt(set_variable, (efi_char16_t *)arg1, + (efi_guid_t *)arg2, *(u32 *)arg3, + *(unsigned long *)arg4, (void *)arg5); + break; + case QUERY_VARIABLE_INFO: + status = efi_call_virt(query_variable_info, *(u32 *)arg1, + (u64 *)arg2, (u64 *)arg3, (u64 *)arg4); + break; + case GET_NEXT_HIGH_MONO_COUNT: + status = efi_call_virt(get_next_high_mono_count, (u32 *)arg1); + break; + case UPDATE_CAPSULE: + status = efi_call_virt(update_capsule, + (efi_capsule_header_t **)arg1, + *(unsigned long *)arg2, + *(unsigned long *)arg3); + break; + case QUERY_CAPSULE_CAPS: + status = efi_call_virt(query_capsule_caps, + (efi_capsule_header_t **)arg1, + *(unsigned long *)arg2, (u64 *)arg3, + (int *)arg4); + break; + default: + /* + * Ideally, we should never reach here because a caller of this + * function should have put the right efi_runtime_service() + * function identifier into efi_rts_work->efi_rts_id + */ + pr_err("Requested executing invalid EFI Runtime Service.\n"); + } + efi_rts_work->status = status; + complete(&efi_rts_work->efi_rts_comp); +} + static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc) { efi_status_t status; if (down_interruptible(&efi_runtime_lock)) return EFI_ABORTED; - status = efi_call_virt(get_time, tm, tc); + status = efi_queue_work(GET_TIME, tm, tc, NULL, NULL, NULL); up(&efi_runtime_lock); return status; } @@ -107,7 +274,7 @@ static efi_status_t virt_efi_set_time(efi_time_t *tm) if (down_interruptible(&efi_runtime_lock)) return EFI_ABORTED; - status = efi_call_virt(set_time, tm); + status = efi_queue_work(SET_TIME, tm, NULL, NULL, NULL, NULL); up(&efi_runtime_lock); return status; } @@ -120,7 +287,8 @@ static efi_status_t virt_efi_get_wakeup_time(efi_bool_t *enabled, if (down_interruptible(&efi_runtime_lock)) return EFI_ABORTED; - status = efi_call_virt(get_wakeup_time, enabled, pending, tm); + status = efi_queue_work(GET_WAKEUP_TIME, enabled, pending, tm, NULL, + NULL); up(&efi_runtime_lock); return status; } @@ -131,7 +299,8 @@ static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm) if (down_interruptible(&efi_runtime_lock)) return EFI_ABORTED; - status = efi_call_virt(set_wakeup_time, enabled, tm); + status = efi_queue_work(SET_WAKEUP_TIME, &enabled, tm, NULL, NULL, + NULL); up(&efi_runtime_lock); return status; } @@ -146,8 +315,8 @@ static efi_status_t virt_efi_get_variable(efi_char16_t *name, if (down_interruptible(&efi_runtime_lock)) return EFI_ABORTED; - status = efi_call_virt(get_variable, name, vendor, attr, data_size, - data); + status = efi_queue_work(GET_VARIABLE, name, vendor, attr, data_size, + data); up(&efi_runtime_lock); return status; } @@ -160,7 +329,8 @@ static efi_status_t virt_efi_get_next_variable(unsigned long *name_size, if (down_interruptible(&efi_runtime_lock)) return EFI_ABORTED; - status = efi_call_virt(get_next_variable, name_size, name, vendor); + status = efi_queue_work(GET_NEXT_VARIABLE, name_size, name, vendor, + NULL, NULL); up(&efi_runtime_lock); return status; } @@ -175,8 +345,8 @@ static efi_status_t virt_efi_set_variable(efi_char16_t *name, if (down_interruptible(&efi_runtime_lock)) return EFI_ABORTED; - status = efi_call_virt(set_variable, name, vendor, attr, data_size, - data); + status = efi_queue_work(SET_VARIABLE, name, vendor, &attr, &data_size, + data); up(&efi_runtime_lock); return status; } @@ -210,8 +380,8 @@ static efi_status_t virt_efi_query_variable_info(u32 attr, if (down_interruptible(&efi_runtime_lock)) return EFI_ABORTED; - status = efi_call_virt(query_variable_info, attr, storage_space, - remaining_space, max_variable_size); + status = efi_queue_work(QUERY_VARIABLE_INFO, &attr, storage_space, + remaining_space, max_variable_size, NULL); up(&efi_runtime_lock); return status; } @@ -242,7 +412,8 @@ static efi_status_t virt_efi_get_next_high_mono_count(u32 *count) if (down_interruptible(&efi_runtime_lock)) return EFI_ABORTED; - status = efi_call_virt(get_next_high_mono_count, count); + status = efi_queue_work(GET_NEXT_HIGH_MONO_COUNT, count, NULL, NULL, + NULL, NULL); up(&efi_runtime_lock); return status; } @@ -272,7 +443,8 @@ static efi_status_t virt_efi_update_capsule(efi_capsule_header_t **capsules, if (down_interruptible(&efi_runtime_lock)) return EFI_ABORTED; - status = efi_call_virt(update_capsule, capsules, count, sg_list); + status = efi_queue_work(UPDATE_CAPSULE, capsules, &count, &sg_list, + NULL, NULL); up(&efi_runtime_lock); return status; } @@ -289,8 +461,8 @@ static efi_status_t virt_efi_query_capsule_caps(efi_capsule_header_t **capsules, if (down_interruptible(&efi_runtime_lock)) return EFI_ABORTED; - status = efi_call_virt(query_capsule_caps, capsules, count, max_size, - reset_type); + status = efi_queue_work(QUERY_CAPSULE_CAPS, capsules, &count, + max_size, reset_type, NULL); up(&efi_runtime_lock); return status; } diff --git a/include/linux/efi.h b/include/linux/efi.h index 56add823f190..8ba0cdd244b2 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1651,4 +1651,7 @@ struct linux_efi_tpm_eventlog { extern int efi_tpm_eventlog_init(void); +/* Workqueue to queue EFI Runtime Services */ +extern struct workqueue_struct *efi_rts_wq; + #endif /* _LINUX_EFI_H */ From patchwork Wed Jul 11 09:40:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141712 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp70239ljj; Wed, 11 Jul 2018 02:41:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdaCTKQbPkpklEDcGeGy4jK3vbFzaOSWYh3SQMdBOiWNGLQg5jnK2ffQDcHSztvbKswCp9Z X-Received: by 2002:a63:4951:: with SMTP id y17-v6mr26327680pgk.32.1531302091895; Wed, 11 Jul 2018 02:41:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531302091; cv=none; d=google.com; s=arc-20160816; b=SYCqu/l6dsHPDSiRga512gTezMQgJkyOEvopQUJfM+ObbfauIupPreysAuqxfdU07t VAep1Th1HK/GwgCIlZKa2lJhykVJsjog4UC5ZoerImRAsFdwFRK5LvShgULdH8KB2ukC yPwrL8ycLLi6A4epNjnhovynbrjnSBUFpiyNih3xomonie1KU7zFfGhTS8w8rpkBuWjU 3+sYZTlHi+OnFaDubadmGoGtT71WlrSFs2KHtUMHRmxoUM5MRosatWjQbBFGZHtT07Tg kHo+8NRRZxTLwRY46G9khuxdqSzCJ31PIOd+9P+4K8SdFfG4qtRYwNtVC1Zur8WNpP4O s/KQ== 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=sA0x4vnqsHOfjf2tc9OZ1sVTXlxbVufq2Bf9Pecho2U=; b=fcxxUpmE97gOaF5b47qNGrolsKlP9epyYhhJJkNYs4HA/EtOB0lcRCwAtIyKH/42AJ oqz0i6l/hsP6/9GxZzUVlKyAT3jZNEW/BfWDyABrV1uUPEA+P0/tCk6E6l1NsQtaX5FK C0kgalmm1tu1pNFVy2GRTX5dSCzI1hS/nsIbbinkuyFEziBKHXfHXK/zwdfccwwPW0+Q 3ygp9NtBLJOHRD9oMga4AgD624hR8vhRS7WBKB/netryD43IQ4qLRkDDq6NzghqLWK9i 3AiVXeeoYkzLl7Ld3Elg7vTbY1D2/rJhcKEP7TdF980GfjJJc1lNp+h4cP4BF9RTEFaL ym1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GnRSApHQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (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 a10-v6si18942535pli.122.2018.07.11.02.41.31; Wed, 11 Jul 2018 02:41:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GnRSApHQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732665AbeGKJoX (ORCPT + 22 others); Wed, 11 Jul 2018 05:44:23 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:40032 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726490AbeGKJoW (ORCPT ); Wed, 11 Jul 2018 05:44:22 -0400 Received: by mail-wr1-f68.google.com with SMTP id t6-v6so17452709wrn.7 for ; Wed, 11 Jul 2018 02:40:55 -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=sA0x4vnqsHOfjf2tc9OZ1sVTXlxbVufq2Bf9Pecho2U=; b=GnRSApHQiDH25jpATv9Hy+YfcdUmFoLZmSkR5RQxzvJvMbWjA3RmDby27bcyBy1RUz Oof0Qm/nHboGrcB+Ntm1+mzwKeIshCj+rPnL9jEvINjnPA+sH0QEo1S6uiAkA9XFMFBZ 6nsv0PbzDLsyqQlxlXhS4hl4MgNW/7ekODA5o= 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=sA0x4vnqsHOfjf2tc9OZ1sVTXlxbVufq2Bf9Pecho2U=; b=ftiLps/lxaR6ImrAPPFCsJGGTTWW5CLd+99sXPOHqLJItRZDDxF3IVPFWoP4tybcT+ MQ8DzEJOSFVKMUs9WHzKZsJNF413gEwO9vEHUjO0sRkUcIbE5SABgJipqiHfmdLXvr81 ky+K1tLbkSbGBPFPPxO/wKKrkpFscvV5vMduE/1dOuGmuXz3Fga9MmZQRpdtS5LSTsp1 aldlb01EfzYzpSoZB1OHq3IZT2AWHMKF3pa04ywGMYas6Wr1RR5/ZAvu5qRbjlMx4Sqh Dw9cJECJnFBJ2F5A1uc/m01XrVe06XZnYbGxTb4zfCoTc4LjL2PkKJmkN9E2QMDVVnF6 zS6Q== X-Gm-Message-State: APt69E2ZKPo/1oBGeLdkqcwiVmKv9NBhbdn9n2Mq1aaXBqiSua1vy7w/ pCX9oE+xgKKK0lHoJtJQUvIbWw== X-Received: by 2002:adf:b3d4:: with SMTP id x20-v6mr21143810wrd.272.1531302054562; Wed, 11 Jul 2018 02:40:54 -0700 (PDT) Received: from localhost.localdomain (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id t124-v6sm1641311wmt.29.2018.07.11.02.40.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 02:40:53 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Arnd Bergmann , Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 4/8] efi: cper: avoid using get_seconds() Date: Wed, 11 Jul 2018 11:40:36 +0200 Message-Id: <20180711094040.12506-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180711094040.12506-1-ard.biesheuvel@linaro.org> References: <20180711094040.12506-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnd Bergmann get_seconds() is deprecated because of the 32-bit time overflow in y2038/y2106 on 32-bit architectures. The way it is used in cper_next_record_id() causes an overflow in 2106 when unsigned UTC seconds overflow, even on 64-bit architectures. This starts using ktime_get_real_seconds() to give us more than 32 bits of timestamp on all architectures, and then changes the algorithm to use 39 bits for the timestamp after the y2038 wrap date, plus an always-1 bit at the top. This gives us another 127 epochs of 136 years, with strictly monotonically increasing sequence numbers across boots. This is almost certainly overkill, but seems better than just extending the deadline from 2038 to 2106. Signed-off-by: Arnd Bergmann Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/cper.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c index 3bf0dca378a6..b73fc4cab083 100644 --- a/drivers/firmware/efi/cper.c +++ b/drivers/firmware/efi/cper.c @@ -48,8 +48,21 @@ u64 cper_next_record_id(void) { static atomic64_t seq; - if (!atomic64_read(&seq)) - atomic64_set(&seq, ((u64)get_seconds()) << 32); + if (!atomic64_read(&seq)) { + time64_t time = ktime_get_real_seconds(); + + /* + * This code is unlikely to still be needed in year 2106, + * but just in case, let's use a few more bits for timestamps + * after y2038 to be sure they keep increasing monotonically + * for the next few hundred years... + */ + if (time < 0x80000000) + atomic64_set(&seq, (ktime_get_real_seconds()) << 32); + else + atomic64_set(&seq, 0x8000000000000000ull | + ktime_get_real_seconds() << 24); + } return atomic64_inc_return(&seq); } From patchwork Wed Jul 11 09:40:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141707 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp69771ljj; Wed, 11 Jul 2018 02:41:00 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc8f3KUAsGTi8fPwSdX6sdDWa642kdJwrvuT6dmz4Gw/QXACmsV5ZzEuTJwlBm9Bl4Wd2Kh X-Received: by 2002:a63:4857:: with SMTP id x23-v6mr20374014pgk.30.1531302059941; Wed, 11 Jul 2018 02:40:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531302059; cv=none; d=google.com; s=arc-20160816; b=STK3PkSvEfebpQbbVEjk+wkd72xpBLTf5O5/ECWJkeIHL05ncO69Q5Be9TdccXcISd 0MX4PQrplwsH4PgeuI4cHHdyK8ZWPuHUN5TiH5RAKk/lh+gS+x+unpAiiURZL4ODBO0d Bg4oXY9wyxrS/gcgAi/+MR0r3yJ/wcA+bcFroopAK3hw93D2VX2326HkMX6y/bkYQHTH ShgPbnQJr5M5jlD+LnXqfUz64wCs3AidAzq0MmSoGsnvUIWKRjmtGyIW3A7cFDLrqmxY ARFwemnLQKHAl9EVBmVYqNkUezyO/qtwSr6e7865SCx3/ooNFt7ssBKZC3Zx4ZPyiFRb eGsg== 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=ZqeNzGml4afcm1ZwxUqSeHEL0c5jVKB8hlqShvm+ZHg=; b=yOXmaSlxECsDCYCqJHmIN77PRI19q0MBFp4lb7qimKTBJZkU4+YjmjBne4DE84iUVS h+/Uy+uVWMUfFSb4NG2jv6O5c34g/p+9X9BtGKAid35t/BN1HOzRHKzbNM8C7tUgBqaH 5ILHebAIovSR073KI83ISLLFJxwN/IBs3w51bzpjKMymjHuEol3+/741PUGne6ZVkUIo XZ8zfpWLRAyCJYW+D4wjXh/ZLXxd+E10dyhVJ8WezIg0lWnWSrDYoDiWqv/0J9+RiMQ9 8xvyZdWMkkNUNImkw4UGyE9eMxN+mFMc6bfLqPrGxlmA8ZUSpsuHpfXILsK32IN8unbM k2IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Tcv2EhEE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (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 f17-v6si17367412pgv.383.2018.07.11.02.40.59; Wed, 11 Jul 2018 02:40:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Tcv2EhEE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732693AbeGKJoY (ORCPT + 22 others); Wed, 11 Jul 2018 05:44:24 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:45399 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732649AbeGKJoX (ORCPT ); Wed, 11 Jul 2018 05:44:23 -0400 Received: by mail-wr1-f68.google.com with SMTP id c4-v6so4782333wrs.12 for ; Wed, 11 Jul 2018 02:40:56 -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=ZqeNzGml4afcm1ZwxUqSeHEL0c5jVKB8hlqShvm+ZHg=; b=Tcv2EhEEOtrXUYNV09XvwqVSoCBg//nX/8XAtsntwXu2BZ5E53pgKDFOOvodUN+Vz9 2NuIHbzOFyrs+i9vTuaSGUqbHHNtOKZgRKPzxhSYO/fpXlvM4emXy7+wvOkUbPXle5Yk 92f3gmWOfPyoc8YAcxPJG5Qvwj/ksOzSIKXQU= 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=ZqeNzGml4afcm1ZwxUqSeHEL0c5jVKB8hlqShvm+ZHg=; b=YO3iaIW1qQzs7WLZNRHOVssDQLjqMarJ6iA6xHZn2Xhyab17USfX3yPYK7gCo42vIv sNX3slAEXZCFLF6roHhOe0R6/p01FxqfDjERfJnV0jDP4Nud3zS68q4GjTDazfXByicA u7Myls9+HQHBz64pJlhL8ToFYXWAIj6jxvFl8b0qWMg1v0yFMJZTl/Pt0XlbdNKG4Kko BvWZddheu9uL5E6Bd5ZSvoSZZ6VTABYjgdT+GRqDIvx33QXmnArzUcnxeVqJFFaloPYE EILDYCBX9ddF9RZAxGSdF3dt/FKZrbUrgoN3irdnw0ZHGcZ8S4kBLcYi6CaLBzu2GqGM /e8w== X-Gm-Message-State: APt69E0I4NhoX0nb3K2LwhlrFV3LsdKuAme2Gw674T+2sXv5A8Tl815l Db7h+ZQnI2upcxCk8gr2XTMFFg== X-Received: by 2002:adf:c321:: with SMTP id n30-v6mr19899750wrf.235.1531302055747; Wed, 11 Jul 2018 02:40:55 -0700 (PDT) Received: from localhost.localdomain (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id t124-v6sm1641311wmt.29.2018.07.11.02.40.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 02:40:55 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Sai Praneeth , Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 5/8] efi: Remove the declaration of efi_late_init() as the function is unused Date: Wed, 11 Jul 2018 11:40:37 +0200 Message-Id: <20180711094040.12506-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180711094040.12506-1-ard.biesheuvel@linaro.org> References: <20180711094040.12506-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sai Praneeth Commit 7b0a911478c74 (efi/x86: Move the EFI BGRT init code to early init code), removed the implementation and all the references to efi_late_init() but the function is still declared at include/linux/efi.h. Hence, remove the unnecessary declaration. Signed-off-by: Sai Praneeth Prakhya Signed-off-by: Ard Biesheuvel --- include/linux/efi.h | 2 -- 1 file changed, 2 deletions(-) -- 2.17.1 diff --git a/include/linux/efi.h b/include/linux/efi.h index 8ba0cdd244b2..e190652f5ef9 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -988,14 +988,12 @@ extern void efi_memmap_walk (efi_freemem_callback_t callback, void *arg); extern void efi_gettimeofday (struct timespec64 *ts); extern void efi_enter_virtual_mode (void); /* switch EFI to virtual mode, if possible */ #ifdef CONFIG_X86 -extern void efi_late_init(void); extern void efi_free_boot_services(void); extern efi_status_t efi_query_variable_store(u32 attributes, unsigned long size, bool nonblocking); extern void efi_find_mirror(void); #else -static inline void efi_late_init(void) {} static inline void efi_free_boot_services(void) {} static inline efi_status_t efi_query_variable_store(u32 attributes, From patchwork Wed Jul 11 09:40:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141708 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp69804ljj; Wed, 11 Jul 2018 02:41:02 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf44YGcKoH2tJhC+38V+2MOpQ1ICYeSK4L0w3vdfQNDBAW6OfKGNBrhWhanWnkkPXjTXoXl X-Received: by 2002:a17:902:264:: with SMTP id 91-v6mr27433692plc.341.1531302062119; Wed, 11 Jul 2018 02:41:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531302062; cv=none; d=google.com; s=arc-20160816; b=LSz9ZfWxCTI8IfiwWoN68llsXgogTgOxCCx4cRVIW0j4OW31irhoaaPrywKZQeDm3d WMS5LO8EuituJNGJz8FEQ31M0l19yDl+w8jKstyva0s8c7gi07WJ9VsgqYVj+WLZ2+Zr BWyreGOB9VDeUW6bCjCTqgU/ux4WouQNSsZP0uQXXk9Co4hCq3Ox4oeJw6Hw1KzId0Lu pNg6sMp3xWpuW+fFv9projXdcekTFeE7epkhzZ4ZlOcCdyEAvIk3NRT7RMbq1JIqg7ZN QmkPc0swZZRVnykDgjkZzO8wZyiqJvenYYnWDdTk2zWFSUbuui6VBXL3oks9Brd+Di7w drbQ== 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=semFZDZ5nZhcHHAbVFoDCVNYOqmDtPeCRsqInWmd32A=; b=KIyRAs0ESGhE0RqlF1C8ZyfCGvz1r7Xy4KHt5c+J9UvT3ZCelmCu2XB2omIm0CP8ph o+dO3jgGNyus8WUpX74NuD454C295ZVZKSIvqoDCOYD8GuKnH55GZiYu/OK127lYfZlO AO9V0XP5j/ioSw8A9m916bt+8GKrjTCh4Kwo7SaTnGKsTrAt4MF5VxFQe7/jNt3+eN8w Bgv3pqkNls3I+m2jWd0pZF93vQoW0S/bGxQcAeJk/T5fbem9ZCx/N6br4drDcmIX4UZO 3pyfsxDKzt0jucL0IuB1eYSJoFLKG+P4rjccQwi/onQmhzUqjRZ/qIT5AgADF25KOgBH bY7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="BWjg/fqT"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (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 o1-v6si18610527plb.279.2018.07.11.02.41.01; Wed, 11 Jul 2018 02:41:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="BWjg/fqT"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732708AbeGKJoZ (ORCPT + 22 others); Wed, 11 Jul 2018 05:44:25 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:35790 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732628AbeGKJoY (ORCPT ); Wed, 11 Jul 2018 05:44:24 -0400 Received: by mail-wm0-f66.google.com with SMTP id v3-v6so1840740wmh.0 for ; Wed, 11 Jul 2018 02:40:57 -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=semFZDZ5nZhcHHAbVFoDCVNYOqmDtPeCRsqInWmd32A=; b=BWjg/fqTgl5cNpg7yim7h3iQMkc7YJV61kg5WOiBg59yZZtM5yxShPo9dWI5gdVMD3 2PIpjqvI9zVgj/I4osdj8UDv5ayb9uYhnRhy631Lam2Mlw/9V3SQWlF7R0B4f1E4+iNU a0AxXPVMWUvChd3jRy3/0Tnq3yXEEBFqN/Ui0= 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=semFZDZ5nZhcHHAbVFoDCVNYOqmDtPeCRsqInWmd32A=; b=nFYFjxLdvXGcikh6rM7C0QQmGeVTT8OdkppEHSbSqa/iz+A4QqqRRmkMsYnbDzwkd+ sM0JrF3lxiYzZSswaYwnd5A/XRV7AH6SmxN9lXs+950yosE3lHCiHkrO9Uf7OmpEQ1Zb t7FVcV1jISz9Z0nAI26Jtz8ReUDdC9kVjzR6MP+NM9VqbeK2wewlFpmuN9aGy91JYUj9 SYFoNBaBbMKqIvIgqM79PmHVJAS+adGEs9wc98XXD1vOvPidZln/O6E73Sm2AYKc4zgl dhoC56p9tKrn4kluOwI5Aeojb4LwqmqEqH15T8ZJUPD7Shu2kqmj2bpW4pUhW50qmT/X bCFw== X-Gm-Message-State: APt69E3Y7DB/H3LP9y7MR1mW3DGIp1SFSqFjcPA/Flm4zB78rgvX1w7n XiRFFmVdVVilEYNCCWpMvb1ozw== X-Received: by 2002:a1c:8d0a:: with SMTP id p10-v6mr17760280wmd.121.1531302056988; Wed, 11 Jul 2018 02:40:56 -0700 (PDT) Received: from localhost.localdomain (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id t124-v6sm1641311wmt.29.2018.07.11.02.40.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 02:40:56 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 6/8] efi/libstub/arm: add opt-in Kconfig option for the DTB loader Date: Wed, 11 Jul 2018 11:40:38 +0200 Message-Id: <20180711094040.12506-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180711094040.12506-1-ard.biesheuvel@linaro.org> References: <20180711094040.12506-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are various ways a platform can provide a device tree binary to the kernel, with different levels of sophistication: - ideally, the UEFI firmware, which is tightly coupled with the platform, provides a device tree image directly as a UEFI configuration table, and typically permits the contents to be manipulated either via menu options or via UEFI environment variables that specify a replacement image, - GRUB for ARM has a 'devicetree' directive which allows a device tree image to be loaded from any location accessible to GRUB, and supersede the one provided by the firmware, - the EFI stub implements a dtb= command line option that allows a device tree image to be loaded from a file residing in the same file system as the one the kernel image was loaded from. The dtb= command line option was never intended to be more than a development feature, to allow the other options to be implemented in parallel. So let's make it an opt-in feature that is disabled by default, but can be re-enabled at will. Note that we already disable the dtb= command line option when we detect that we are running with UEFI Secure Boot enabled. Acked-by: Leif Lindholm Reviewed-by: Alexander Graf Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/Kconfig | 12 ++++++++++++ drivers/firmware/efi/libstub/arm-stub.c | 7 ++++--- 2 files changed, 16 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig index 781a4a337557..fc1cb2961d5b 100644 --- a/drivers/firmware/efi/Kconfig +++ b/drivers/firmware/efi/Kconfig @@ -87,6 +87,18 @@ config EFI_RUNTIME_WRAPPERS config EFI_ARMSTUB bool +config EFI_ARMSTUB_DTB_LOADER + bool "Enable the DTB loader" + depends on EFI_ARMSTUB + help + Select this config option to add support for the dtb= command + line parameter, allowing a device tree blob to be loaded into + memory from the EFI System Partition by the stub. + + The device tree is typically provided by the platform or by + the bootloader, and so this option is mostly for development + purposes only. + config EFI_BOOTLOADER_CONTROL tristate "EFI Bootloader Control" depends on EFI_VARS diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c index 01a9d78ee415..c98b1856fc3d 100644 --- a/drivers/firmware/efi/libstub/arm-stub.c +++ b/drivers/firmware/efi/libstub/arm-stub.c @@ -202,9 +202,10 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table, * 'dtb=' unless UEFI Secure Boot is disabled. We assume that secure * boot is enabled if we can't determine its state. */ - if (secure_boot != efi_secureboot_mode_disabled && - strstr(cmdline_ptr, "dtb=")) { - pr_efi(sys_table, "Ignoring DTB from command line.\n"); + if (!IS_ENABLED(CONFIG_EFI_ARMSTUB_DTB_LOADER) || + secure_boot != efi_secureboot_mode_disabled) { + if (strstr(cmdline_ptr, "dtb=")) + pr_efi(sys_table, "Ignoring DTB from command line.\n"); } else { status = handle_cmdline_files(sys_table, image, cmdline_ptr, "dtb=", From patchwork Wed Jul 11 09:40:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141709 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp69831ljj; Wed, 11 Jul 2018 02:41:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd6gjSkuY2LqRmjCJDX+jf5r6Oe1+jAEbGAIUI9IaJ8UFgBZURUaCB0zlFJz8/lURwAzIQw X-Received: by 2002:a62:464f:: with SMTP id t76-v6mr29467876pfa.118.1531302064236; Wed, 11 Jul 2018 02:41:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531302064; cv=none; d=google.com; s=arc-20160816; b=dqV3S4tH5UNZ4hLSQVQxprsMb9pzobKL9JMtFcPdGb5C13R6s0g2rNHB1VykyWkLq0 2xgrJrIJ1a+duNS02UlK2SSZYIHgpdC+v7v7u6BEeKE0rYS4zMSlI0GnFRn+gIA1zCWo VmoaUSmEbzJjQ0ANTFfv3CZPW7+tIQSu2dcV7BrVQFRYxD0ieSMaDUX9zKR/UE6TNS/t avo/I8WMIwAkpaia3yY2iY5ua4js06TuDQ3G3Yn7ixgIRF71v3MCzilu0w0GSHEYYxJ5 gzz9bUlDyMwCZxBn2QHZdiJ2yioKj4xnHDnvJTVmilV19CyO5pMvQpbK9MrsjVWQKdz/ zbng== 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=K6onjEFl2BD59yiPdC7EvEbLejow6UKfjhclEvp4LkA=; b=nBhWjv8euejiDUSxoKWI3pOxRUeGiM/hAbXm66TM1Edorh+bit0U/KkfxOc03j2AzG bRxHqiQVyAf2vAWOgV2Sv5Lw8ITE4uHSlCDTd4fi4oo0ioX8VDepHrQCyPoW6Y2cPhNy Mb0ArqaeVUqTv8y03yylTmtcIQltaZ9ttb4WowzmF6Njx2/IjUFfQ77Amt57hOiDrsjd 5U3Gil+de6GEHCZs6CDgV0no9+tVlJL3nfE+BGtP64lhwj55fsx+OEPXFYnwl31hztBq GsgX+CPXkp2m5XdWkdKUckDPqUwUCPOAsf8hPr/w8LGY7I348nCKNEte+dltSfzPcJBa NIQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FAIjelsb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (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 y8-v6si126141pfe.269.2018.07.11.02.41.04; Wed, 11 Jul 2018 02:41:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FAIjelsb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732724AbeGKJo2 (ORCPT + 22 others); Wed, 11 Jul 2018 05:44:28 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:40341 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732649AbeGKJo0 (ORCPT ); Wed, 11 Jul 2018 05:44:26 -0400 Received: by mail-wm0-f65.google.com with SMTP id z13-v6so1821984wma.5 for ; Wed, 11 Jul 2018 02:40:59 -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=K6onjEFl2BD59yiPdC7EvEbLejow6UKfjhclEvp4LkA=; b=FAIjelsbktZKTdXOlDgXx8BIdZLA3mpzvc/qBvRBbuHHBgjgSpxQWUxUCdtKCeoo90 9EKDY2skViyPH/ng/v1zuQDPGWw4qJluEZl/JY9pAJmpQ3bxcnrTADN+o/5TNkPCTPZq Hh2KJ5KsyyBdSiZ2oKe3DPaG8UdGaerdscnN8= 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=K6onjEFl2BD59yiPdC7EvEbLejow6UKfjhclEvp4LkA=; b=kwGS9ddl1Hl4ZW9vgz1AGMNZ6zx5EG2Ph5jNYxiIe0uYOyMYCJBmlGZeUgfHvVfh6M xX4hAyKKNHeWIMrCJhdOjjrlTPGfyUIzSZEtSA0Z4hEjfWuP5nUUS3dGm2LHFiie/9Ul EmLboymqZ+n8UTXc81g/DLJNpuO8bDBK8y7fskyZ2rqo4Sz4DW10No2SABauN7OQYih3 ttPAe/wytvW736wyqr98AKsmCZBiW8HAKt7RyBojdMRFV+cuC4rvPEykMYFzLjza+chN yc3gxd5/wu7wf5U18Z/iFybCdszZkD/NY+Fhxv0PjJwX8jbmn6sznBbaiQyWgaBa267i MQaA== X-Gm-Message-State: APt69E3IrTNh+HGX6DUlGeLn/IbHWp1nVjmcywkhZCpHGg+t7FtumRwM 8+6Uueyn/KKRYwaO7K1m3o/rEFWkyYE= X-Received: by 2002:a1c:894f:: with SMTP id l76-v6mr16495795wmd.103.1531302058259; Wed, 11 Jul 2018 02:40:58 -0700 (PDT) Received: from localhost.localdomain (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id t124-v6sm1641311wmt.29.2018.07.11.02.40.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 02:40:57 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Peter Jones Subject: [PATCH 7/8] efi: drop type and attribute checks in efi_mem_desc_lookup() Date: Wed, 11 Jul 2018 11:40:39 +0200 Message-Id: <20180711094040.12506-8-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180711094040.12506-1-ard.biesheuvel@linaro.org> References: <20180711094040.12506-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current implementation of efi_mem_desc_lookup() includes the following check on the memory descriptor it returns: if (!(md->attribute & EFI_MEMORY_RUNTIME) && md->type != EFI_BOOT_SERVICES_DATA && md->type != EFI_RUNTIME_SERVICES_DATA) { continue; } This means that only EfiBootServicesData or EfiRuntimeServicesData regions are considered, or any other region type provided that it has the EFI_MEMORY_RUNTIME attribute set. Given what the name of the function implies, and the fact that any physical address can be described in the UEFI memory map only a single time, it does not make sense to impose this condition in the body of the loop, but instead, should be imposed by the caller depending on the value that is returned to it. Two such callers exist at the moment: - The BGRT code when running on x86, via efi_mem_reserve() and efi_arch_mem_reserve(). In this case, the region is already known to be EfiBootServicesData, and so the check is redundant. - The ESRT handling code which introduced this function, which calls it both directly from efi_esrt_init() and again via efi_mem_reserve() and efi_arch_mem_reserve() [on x86]. So let's move this check into the callers instead. This preserves the current behavior both for BGRT and ESRT handling, and allows the lookup routine to be reused by other [upcoming] users that don't have this limitation. In the ESRT case, keep the entire condition, so that platforms that deviate from the UEFI spec and use something other than EfiBootServicesData for the ESRT table will keep working as before. For x86's efi_arch_mem_reserve() implementation, limit the type to EfiBootServicesData, since it is the only type the reservation code expects to operate on in the first place. While we're at it, drop the __init annotation so that drivers can use it as well. Cc: Peter Jones Tested-by: Laszlo Ersek Signed-off-by: Ard Biesheuvel --- arch/x86/platform/efi/quirks.c | 3 ++- drivers/firmware/efi/efi.c | 8 +------- drivers/firmware/efi/esrt.c | 5 ++++- 3 files changed, 7 insertions(+), 9 deletions(-) -- 2.17.1 diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c index 6af39dc40325..844d31cb8a0c 100644 --- a/arch/x86/platform/efi/quirks.c +++ b/arch/x86/platform/efi/quirks.c @@ -248,7 +248,8 @@ void __init efi_arch_mem_reserve(phys_addr_t addr, u64 size) int num_entries; void *new; - if (efi_mem_desc_lookup(addr, &md)) { + if (efi_mem_desc_lookup(addr, &md) || + md.type != EFI_BOOT_SERVICES_DATA) { pr_err("Failed to lookup EFI memory descriptor for %pa\n", &addr); return; } diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 1379a375dfa8..d8a33a781a57 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -402,7 +402,7 @@ subsys_initcall(efisubsys_init); * and if so, populate the supplied memory descriptor with the appropriate * data. */ -int __init efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md) +int efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md) { efi_memory_desc_t *md; @@ -420,12 +420,6 @@ int __init efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md) u64 size; u64 end; - if (!(md->attribute & EFI_MEMORY_RUNTIME) && - md->type != EFI_BOOT_SERVICES_DATA && - md->type != EFI_RUNTIME_SERVICES_DATA) { - continue; - } - size = md->num_pages << EFI_PAGE_SHIFT; end = md->phys_addr + size; if (phys_addr >= md->phys_addr && phys_addr < end) { diff --git a/drivers/firmware/efi/esrt.c b/drivers/firmware/efi/esrt.c index 1ab80e06e7c5..375a77c1c6e5 100644 --- a/drivers/firmware/efi/esrt.c +++ b/drivers/firmware/efi/esrt.c @@ -250,7 +250,10 @@ void __init efi_esrt_init(void) return; rc = efi_mem_desc_lookup(efi.esrt, &md); - if (rc < 0) { + if (rc < 0 || + (!(md.attribute & EFI_MEMORY_RUNTIME) && + md.type != EFI_BOOT_SERVICES_DATA && + md.type != EFI_RUNTIME_SERVICES_DATA)) { pr_warn("ESRT header is not in the memory map.\n"); return; } From patchwork Wed Jul 11 09:40:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141710 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp69877ljj; Wed, 11 Jul 2018 02:41:06 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdBUj7uKlfSf+fY4XcXL9k9j9YHox/pTaB96cJ4tTsYxCkbyvGbHtBaxhv5gQrJREeRH1lT X-Received: by 2002:a65:510c:: with SMTP id f12-v6mr25250391pgq.288.1531302066804; Wed, 11 Jul 2018 02:41:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531302066; cv=none; d=google.com; s=arc-20160816; b=U47h65TPMOqXaT4aeb0vP9PfU7YmZsyiScnV+Revj2HHPPqn/gzotPVohrmT4J2Ts3 eE/i8ol6T7uCZhPqvsy48kPUgbZYhllFVH0dlUPoZhHTaftJ3MzocGRPA4UdJeZz1vfA Boa0idGFmg5LAVNUHNSOwezycouaEI+FMf70t9LsW/u+Up2gqMMyO0ip1wHQFgVxAzrN y4m4V5clsO945OTuI2z+9+L9KCL7ELphY4I8vUjwlUUOfwRevNXKB/yLv4XbW03uMGF6 yMtUZ6Epax8IlLhbjOSEGCAsfYa4fFgd97kvkQRiXX2N2NSy6oWZ9Q9DyBJoga+RnI16 3IZg== 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=hSmuPT04ey1U4iYRelgasoauscoIOrW4wwIqOVRaXYw=; b=N/xZ7BgEftaVEUQkfUPaZqLru1wmalnntL18YI8pjXcg3SL/dcmEBAX7eq0xtrqKbz UtJIKCCvMm8bfUxWVx2EJxcoEuJnq75zmLXEGWtGPHVEvUqN11IRNZW4HFOCogbJZXA2 +nA08jVzSS8Ddj81fHxwc0Nsp53yZitC6Ax9o72CbQFnaKCZBM1Vpq9cwAsUnIVeXOsw cfiNyoGMDRaFFwnEiouHvzvf2xiXaI9i5OKOgCvcIycPWeIPXsVImrGBXN6o/r/cz74O U/OFICT+QBzQ9q/YJTzkQTsrVHhuhOxd4AIH9JZCM339QZpGworPGs/vFnM8XTUAfCm5 cgcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q20FrrOF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (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 f24-v6si18118741pgh.287.2018.07.11.02.41.06; Wed, 11 Jul 2018 02:41:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q20FrrOF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732735AbeGKJoa (ORCPT + 22 others); Wed, 11 Jul 2018 05:44:30 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:54354 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732628AbeGKJo2 (ORCPT ); Wed, 11 Jul 2018 05:44:28 -0400 Received: by mail-wm0-f67.google.com with SMTP id i139-v6so1759584wmf.4 for ; Wed, 11 Jul 2018 02:41: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=hSmuPT04ey1U4iYRelgasoauscoIOrW4wwIqOVRaXYw=; b=Q20FrrOF3D6KVUv22rSGpOLhLgdfVwqIrbtC9ntFxoDFenik7SaJZNVQZcXjROjvDg q9H6aMg9yVilfL+PuHfJPZTIQB1TzV3ZVOVQqIawF/45T+7YX6jo+PUINA2a8oLq+Nst qTu5b9DHY+FxulTxAYRb+6Dd/O4HbBMYAWTsA= 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=hSmuPT04ey1U4iYRelgasoauscoIOrW4wwIqOVRaXYw=; b=kK7vG14BcI6gfnLn3GWSunuJaKihMjmqeuKL4j+d/LZh3NKKewoxnXVJzVOPSy6Ey3 YQaFIHhvOwpONzzx+aXqD7q/cbAynL0H4UClB7TCb/Az+TUX4jEXPbB/QWjpz8/OIL1W I6xOHTsZxz+pwNe/rmzqeozKfWRaRr+GKJiELgrfNltHX7oC6sweOqg6vylvqeF9r9dG nEk7zT+RYzxJpVKbIalGr1vP+aVERs8Xq8E0x7qA1+su9aYIZNnlJ2bXncQ2tSZtF/CL o8XeJOwbZKRn4n/qiDys4k26H/1qpJGRlY7AT+a7NZ1jsd21FZKodDDh0nlhxMG10axK pY4Q== X-Gm-Message-State: APt69E26LIkxTJ1HuhySfApZero7JesofwNZ6ye8pWhdEuNg0/Q2vRgp xfK9p+4YvB+y/9X0fC6v/wHhwA== X-Received: by 2002:a1c:9809:: with SMTP id a9-v6mr11999792wme.15.1531302059628; Wed, 11 Jul 2018 02:40: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 t124-v6sm1641311wmt.29.2018.07.11.02.40.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 02:40:58 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Peter Jones Subject: [PATCH 8/8] fbdev/efifb: honour UEFI memory map attributes when mapping the fb Date: Wed, 11 Jul 2018 11:40:40 +0200 Message-Id: <20180711094040.12506-9-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180711094040.12506-1-ard.biesheuvel@linaro.org> References: <20180711094040.12506-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the framebuffer address provided by the Graphics Output Protocol (GOP) is covered by the UEFI memory map, it will tell us which memory attributes are permitted when mapping this region. In some cases, (KVM guest on ARM), violating this will result in loss of coherency, which means that updates sent to the framebuffer by the guest will not be observeable by the host, and the emulated display simply does not work. So if the memory map contains such a description, take the attributes field into account, and add support for creating WT or WB mappings of the framebuffer region. Cc: Peter Jones Tested-by: Laszlo Ersek Acked-by: Bartlomiej Zolnierkiewicz Signed-off-by: Ard Biesheuvel --- drivers/video/fbdev/efifb.c | 51 +++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 10 deletions(-) -- 2.17.1 diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c index 46a4484e3da7..c6f78d27947b 100644 --- a/drivers/video/fbdev/efifb.c +++ b/drivers/video/fbdev/efifb.c @@ -20,7 +20,7 @@ #include /* For DRM_MODE_PANEL_ORIENTATION_* */ static bool request_mem_succeeded = false; -static bool nowc = false; +static u64 mem_flags = EFI_MEMORY_WC | EFI_MEMORY_UC; static struct fb_var_screeninfo efifb_defined = { .activate = FB_ACTIVATE_NOW, @@ -68,8 +68,12 @@ static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green, static void efifb_destroy(struct fb_info *info) { - if (info->screen_base) - iounmap(info->screen_base); + if (info->screen_base) { + if (mem_flags & (EFI_MEMORY_UC | EFI_MEMORY_WC)) + iounmap(info->screen_base); + else + memunmap(info->screen_base); + } if (request_mem_succeeded) release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size); @@ -104,7 +108,7 @@ static int efifb_setup(char *options) else if (!strncmp(this_opt, "width:", 6)) screen_info.lfb_width = simple_strtoul(this_opt+6, NULL, 0); else if (!strcmp(this_opt, "nowc")) - nowc = true; + mem_flags &= ~EFI_MEMORY_WC; } } @@ -164,6 +168,7 @@ static int efifb_probe(struct platform_device *dev) unsigned int size_remap; unsigned int size_total; char *option = NULL; + efi_memory_desc_t md; if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI || pci_dev_disabled) return -ENODEV; @@ -272,12 +277,35 @@ static int efifb_probe(struct platform_device *dev) info->apertures->ranges[0].base = efifb_fix.smem_start; info->apertures->ranges[0].size = size_remap; - if (nowc) - info->screen_base = ioremap(efifb_fix.smem_start, efifb_fix.smem_len); - else - info->screen_base = ioremap_wc(efifb_fix.smem_start, efifb_fix.smem_len); + if (!efi_mem_desc_lookup(efifb_fix.smem_start, &md)) { + if ((efifb_fix.smem_start + efifb_fix.smem_len) > + (md.phys_addr + (md.num_pages << EFI_PAGE_SHIFT))) { + pr_err("efifb: video memory @ 0x%lx spans multiple EFI memory regions\n", + efifb_fix.smem_start); + err = -EIO; + goto err_release_fb; + } + /* + * If the UEFI memory map covers the efifb region, we may only + * remap it using the attributes the memory map prescribes. + */ + mem_flags |= EFI_MEMORY_WT | EFI_MEMORY_WB; + mem_flags &= md.attribute; + } + if (mem_flags & EFI_MEMORY_WC) + info->screen_base = ioremap_wc(efifb_fix.smem_start, + efifb_fix.smem_len); + else if (mem_flags & EFI_MEMORY_UC) + info->screen_base = ioremap(efifb_fix.smem_start, + efifb_fix.smem_len); + else if (mem_flags & EFI_MEMORY_WT) + info->screen_base = memremap(efifb_fix.smem_start, + efifb_fix.smem_len, MEMREMAP_WT); + else if (mem_flags & EFI_MEMORY_WB) + info->screen_base = memremap(efifb_fix.smem_start, + efifb_fix.smem_len, MEMREMAP_WB); if (!info->screen_base) { - pr_err("efifb: abort, cannot ioremap video memory 0x%x @ 0x%lx\n", + pr_err("efifb: abort, cannot remap video memory 0x%x @ 0x%lx\n", efifb_fix.smem_len, efifb_fix.smem_start); err = -EIO; goto err_release_fb; @@ -371,7 +399,10 @@ static int efifb_probe(struct platform_device *dev) err_groups: sysfs_remove_groups(&dev->dev.kobj, efifb_groups); err_unmap: - iounmap(info->screen_base); + if (mem_flags & (EFI_MEMORY_UC | EFI_MEMORY_WC)) + iounmap(info->screen_base); + else + memunmap(info->screen_base); err_release_fb: framebuffer_release(info); err_release_mem: