Received: by 10.223.185.116 with SMTP id b49csp2225815wrg; Sat, 24 Feb 2018 14:18:25 -0800 (PST) X-Google-Smtp-Source: AG47ELvDR+l5eMoXI6DXdQAmoXgmSru/O9csD8Wkvv9X4a/tKTdwMtO7W3bXUxJBXH9WUpmi0l+S X-Received: by 10.98.35.68 with SMTP id j65mr1488835pfj.5.1519510704920; Sat, 24 Feb 2018 14:18:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519510704; cv=none; d=google.com; s=arc-20160816; b=RV2MkwXWRhW0y36oILIYNFU4lQjdjwuq4Grj9gISmjs9jo+S6kezmwayjOKu7WvCEI GpAYEz9bvFiBeQjrBE1MrBaIl2AVuONuMXF95ai6cCPH6VkNBj8gVc83/W0mTJVOhtOF Sf/FsK5Z/8QD3GJOzLxwsnH41R+aPXW4sgYhy43nE65N/rRFe5pO3J63ZDVt8zB6npAH qrS4QWoEkzIc8C+Ca/F6u9ThcWldxFzZt/eZ4Ombp/2aaD6q/FvUFR0POiXKHnyx++Jv zSV9xLzJJdzXb3O6fDr0kccERcxYv+I5aB6BJOfX3E6Xq2PULOWo8RRh7lQiPHiGos9X 9uvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=zeOJgzgeR8c0BCPF/UQrjDqDn9YeS9aLUGPVHKUomC8=; b=y4dUI5rPGSwbnivZFtAuf/TYO4G11bbK0amzQ+9qLtv4Z91s6XFPMzll01r0gs/Ptm cj8QNi26g+qNnnUQVMkiXmUsEcV2jPL/j1DmElu0T4LPJf7HDs7BNrTnpTgUEFY8k1yn oD2ti+pbtMBIq67Ttu7LYVLAxOgXZQcMYdXPdE8LGgSE/PiJZZox6ziGC1Fz7mdnB2LV BfjqSGWIO/vs4p3dowaPLpNgKEiXUeAJwEMjv5VbCmaAK5bQ/51+naFb9hKa1xKTc3nv t7w4Zc/yG96dQSI2/Amoif5Y3tz0VkkNXa/tilRXw0XG7Cd2JwkjSuKZJQj2a8Gr6QSb YpUg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o12-v6si4103019plg.607.2018.02.24.14.18.10; Sat, 24 Feb 2018 14:18:24 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751531AbeBXWR2 (ORCPT + 99 others); Sat, 24 Feb 2018 17:17:28 -0500 Received: from mga04.intel.com ([192.55.52.120]:23057 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751399AbeBXWR0 (ORCPT ); Sat, 24 Feb 2018 17:17:26 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Feb 2018 14:17:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,389,1515484800"; d="scan'208";a="20564903" Received: from saipraneeth.sc.intel.com ([143.183.140.145]) by orsmga008.jf.intel.com with ESMTP; 24 Feb 2018 14:17:25 -0800 From: Sai Praneeth Prakhya To: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Sai Praneeth , "Lee, Chun-Yi" , Borislav Petkov , Tony Luck , Will Deacon , Dave Hansen , Mark Rutland , Bhupesh Sharma , Ricardo Neri , Ravi Shankar , Matt Fleming , Peter Zijlstra , Ard Biesheuvel , Dan Williams Subject: [PATCH V1 0/3] Use efi_rts_workqueue to invoke EFI Runtime Services Date: Sat, 24 Feb 2018 14:10:46 -0800 Message-Id: <1519510249-31447-1-git-send-email-sai.praneeth.prakhya@intel.com> X-Mailer: git-send-email 2.1.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sai Praneeth This patch set is an outcome of the discussion at https://lkml.org/lkml/2017/8/21/607 Presently, efi_runtime_services() are executed by firmware in process context. To execute efi_runtime_service(), kernel switches the page directory from swapper_pgd to efi_pgd. However, efi_pgd doesn't have any user space mappings. A potential issue could be, for instance, an NMI interrupt (like perf) trying to profile some user data while in efi_pgd. A solution for this issue could be to use kthread to run efi_runtime_service(). When a user/kernel thread requests to execute efi_runtime_service(), kernel off-loads this work to kthread which in turn uses efi_pgd. Anything that tries to touch user space addresses while in kthread is terminally broken. This patch set adds support to the efi subsystem to handle all calls to efi_runtime_services() using a work queue (which in turn uses kthread). Implementation summary: ----------------------- 1. When a user/kernel thread requests to execute efi_runtime_service(), enqueue work to a work queue, efi_rts_workqueue. 2. The caller thread waits until the work is finished because it's dependent on the return status of efi_runtime_service() and, in specific cases, the arguments populated by efi_runtime_service(). Some efi_runtime_services() takes a pointer to buffer as an argument and fills up the buffer with requested data. For instance, efi_get_variable() and efi_get_next_variable(). Hence, the caller process cannot just post the work and get going, it has to wait for results from firmware. Caveat: efi_rts_workqueue to run efi_runtime_services() shouldn't be used while in atomic, because caller thread might sleep. Presently, pstore code doesn't use efi_rts_workqueue. Tested using LUV (Linux UEFI Validation) for x86_64 and x86_32. Builds fine for arm and arm64. Will appreciate the effort if someone could test the patches on ARM (although I was able to boot with LUV for ARM). LUV: https://01.org/linux-uefi-validation Thanks to Ricardo and Dan for initial reviews and suggestions. Please feel free to pour in your comments and concerns. Note: Patches are based on Linus's kernel v4.16-rc2 Sai Praneeth (3): x86/efi: Call efi_delete_dummy_variable() during efi subsystem initialization efi: Introduce efi_rts_workqueue and necessary infrastructure to invoke all efi_runtime_services() efi: Use efi_rts_workqueue to invoke EFI Runtime Services arch/x86/include/asm/efi.h | 1 - arch/x86/platform/efi/efi.c | 6 - drivers/firmware/efi/efi.c | 18 +++ drivers/firmware/efi/runtime-wrappers.c | 229 +++++++++++++++++++++++++++++--- include/linux/efi.h | 26 ++++ 5 files changed, 253 insertions(+), 27 deletions(-) Signed-off-by: Sai Praneeth Prakhya Suggested-by: Andy Lutomirski Cc: Lee, Chun-Yi Cc: Borislav Petkov Cc: Tony Luck Cc: Will Deacon Cc: Dave Hansen Cc: Mark Rutland Cc: Bhupesh Sharma Cc: Ricardo Neri Cc: Ravi Shankar Cc: Matt Fleming Cc: Peter Zijlstra Cc: Ard Biesheuvel Cc: Dan Williams -- 2.1.4