Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1047696imm; Mon, 21 May 2018 20:15:24 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqenTN+pBK3sYSeBO7mt+wzSdxe+LC41CGXsQXz9RzpJGFW4W55evi8AwLAa6EoQ6dSsDmA X-Received: by 2002:a63:7043:: with SMTP id a3-v6mr17575228pgn.206.1526958924923; Mon, 21 May 2018 20:15:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526958924; cv=none; d=google.com; s=arc-20160816; b=d4cyGByHDzHzTB7bwh0La6a9WzCbaiFdHmhQ7nv+3eKvdeshNsXvMURhdC2j/HsD0L 7KQCmcQ9Ub8jx9QusZlAj8Mzyu6Hle2aJfHcqHbYV4HSZ7Of0PPyj0OaNFq9ZY3UOqoM 8o9BUCLeU3HTMSP5VttDZ+JVdW2T91JpCuxj5DuWO37P+JoNfG0TJZqL5YVzaKFHtUAP 3R0HxM/uSfFkWexE6FwzFxxI7lt6BMwwgvS8kaYrQIwiuPNo7RZ3Gd6Pie7MD2Bu4ry9 HQeQ0QJJCHkVFQoKC0y+BkpupacFjwmUeBMb7Na9MGFpq3KmwDisFIHEAydnsgSe6jeb cdWw== 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:arc-authentication-results; bh=kQ3MmWcHfKhnLgtsDc20aBniO8sIq4SuQ7JIdXB8irg=; b=bUSwUTBOv1f7T+Xk/ZGloBZClcCSET0f85FMtxY2naZBomr7Nb7OwFAWcn5QBM766t VRt4wTBxtKbPtN/RuasmkdKmqEJa5sNtLyqWfDA6QMLgoD8UKrDMweJ5V4U0AUbsrirI 6ixcr6KH8bLGWyERxMo6DfbiDUeft3V0Lf6OtOFqrkdsOG9QPlBS6SI1QPO91dkVxm5K OAeQ+orFZy+0jdSm21o6QgFmY3CgmXAcEecSILnjVw2Y8s+njV9VyLc0CshUtfOvSLr7 HhGL3poh4hKLRqhsZUSo5n9/w7QeOlQ0vOWPb5imUJIcBvjpSt465X2kK+ir/xgBwWkA DjMQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n10-v6si11787582pgq.472.2018.05.21.20.15.09; Mon, 21 May 2018 20:15:24 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752695AbeEVDNv (ORCPT + 99 others); Mon, 21 May 2018 23:13:51 -0400 Received: from mga06.intel.com ([134.134.136.31]:55066 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751967AbeEVDNP (ORCPT ); Mon, 21 May 2018 23:13:15 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 May 2018 20:13:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,428,1520924400"; d="scan'208";a="41795477" Received: from sai-dev-mach.sc.intel.com ([143.183.140.145]) by fmsmga008.fm.intel.com with ESMTP; 21 May 2018 20:13:14 -0700 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 , Naresh Bhat , Ricardo Neri , Peter Zijlstra , Ravi Shankar , Matt Fleming , Dan Williams , Ard Biesheuvel , Miguel Ojeda Subject: [PATCH V3 1/3] x86/efi: Call efi_delete_dummy_variable() after creating efi_rts_wq Date: Mon, 21 May 2018 20:13:02 -0700 Message-Id: <1526958784-14688-2-git-send-email-sai.praneeth.prakhya@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526958784-14688-1-git-send-email-sai.praneeth.prakhya@intel.com> References: <1526958784-14688-1-git-send-email-sai.praneeth.prakhya@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sai Praneeth Create a workqueue named efi_rts_wq (efi runtime services workqueue), so that all efi_runtime_services() are executed in kthread context. Invoking efi_runtime_services() through efi_rts_wq means all accesses to efi_runtime_services() should be done after efi_rts_wq has been created. efi_delete_dummy_variable() calls set_variable(), hence efi_delete_dummy_variable() should be called after efi_rts_wq has been created. 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: Naresh Bhat Cc: Ricardo Neri Cc: Peter Zijlstra Cc: Ravi Shankar Cc: Matt Fleming Cc: Dan Williams Cc: Ard Biesheuvel Cc: Miguel Ojeda --- arch/x86/platform/efi/efi.c | 15 +++++++++------ drivers/firmware/efi/arm-runtime.c | 3 +++ drivers/firmware/efi/efi.c | 25 +++++++++++++++++++++++++ include/linux/efi.h | 4 ++++ 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index 9061babfbc83..adcc55cd25ce 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -893,9 +893,6 @@ static void __init kexec_enter_virtual_mode(void) if (efi_enabled(EFI_OLD_MEMMAP) && (__supported_pte_mask & _PAGE_NX)) runtime_code_page_mkexec(); - - /* clean DUMMY object */ - efi_delete_dummy_variable(); #endif } @@ -1015,9 +1012,6 @@ static void __init __efi_enter_virtual_mode(void) * necessary relocation fixups for the new virtual addresses. */ efi_runtime_update_mappings(); - - /* clean DUMMY object */ - efi_delete_dummy_variable(); } void __init efi_enter_virtual_mode(void) @@ -1031,6 +1025,15 @@ void __init efi_enter_virtual_mode(void) __efi_enter_virtual_mode(); efi_dump_pagetable(); + + if (!efi_create_rts_wq()) + return; + + /* + * Clean DUMMY object calls EFI Runtime Service, set_variable(), so + * it should be invoked only after efi_rts_wq is ready. + */ + efi_delete_dummy_variable(); } static int __init arch_parse_efi_cmdline(char *str) diff --git a/drivers/firmware/efi/arm-runtime.c b/drivers/firmware/efi/arm-runtime.c index 5889cbea60b8..6fb06130b53f 100644 --- a/drivers/firmware/efi/arm-runtime.c +++ b/drivers/firmware/efi/arm-runtime.c @@ -139,6 +139,9 @@ static int __init arm_enable_runtime_services(void) return -ENOMEM; } + if (!efi_create_rts_wq()) + return 0; + /* Set up runtime services function pointers */ efi_native_runtime_setup(); set_bit(EFI_RUNTIME_SERVICES, &efi.flags); diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 232f4915223b..b9103caa03b4 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,13 @@ static int __init efisubsys_init(void) if (!efi_enabled(EFI_BOOT)) return 0; + /* + * If we failed to create efi_rts_wq, EFI_RUNTIME_SERVICES would + * have been be cleared, check for that condition. + */ + if (!efi_enabled(EFI_RUNTIME_SERVICES)) + return 0; + /* We register the efi directory at /sys/firmware/efi */ efi_kobj = kobject_create_and_add("efi", firmware_kobj); if (!efi_kobj) { @@ -971,3 +980,19 @@ static int register_update_efi_random_seed(void) } late_initcall(register_update_efi_random_seed); #endif + +bool __init efi_create_rts_wq(void) +{ + /* + * 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 false; + } + return true; +} diff --git a/include/linux/efi.h b/include/linux/efi.h index 3016d8c456bc..565955010b18 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -987,6 +987,7 @@ extern void efi_map_pal_code (void); 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 */ +extern bool __init efi_create_rts_wq(void); #ifdef CONFIG_X86 extern void efi_late_init(void); extern void efi_free_boot_services(void); @@ -1651,4 +1652,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 */ -- 2.7.4