From patchwork Thu Sep 27 08:50:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147689 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1726326lji; Thu, 27 Sep 2018 01:51:09 -0700 (PDT) X-Google-Smtp-Source: ACcGV63V64mP70f+GT7JniRwA/ivLV9LQ+tjwwBmM/qtPiGXHzsRZo5QUOinphwy+6G85ExUrkOR X-Received: by 2002:a63:9612:: with SMTP id c18-v6mr8975223pge.21.1538038269119; Thu, 27 Sep 2018 01:51:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538038269; cv=none; d=google.com; s=arc-20160816; b=dcUKzlyCN6FRssbcBtPgDgrXvAik2DPH7w6DvB93Ohb1W+49MeRNnDmhrKw4Vuk5fT i7hoIc0Y43BoT6x2IQurvTSHWyfhceN2OX3tJ1j0B6R3Km62ebwwE1T6D6srlTzuv1CM cocOH9S4iOBMtdyi5YRiFVboSJKyAvPFyOkC+QHyQk1UXeTlTbNxPZHDVNrK41fpZ5VK d2MLII9hXZis3YqxuzBTrLilI4yVClfrAGiZ69AAve+j2fYLSJRacVQcTyS+GqJ3xVkB MrlAeGcoCJ/8woI68bOIvKZ245vyEQ7cLHjdRzAcR9SreMPw4vpvog3IoFV1o2fVdtYs mrUA== 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; bh=8qG3i7EOfW75+1ul/qMJed+W8vBlnWG4DFjga9+cTRI=; b=hrNQiQ3g91s/NOmu+fW1oMsahpZSpjoyaY2bfCUDDHngjJ9mxCXgtiRZWBuFH9vs82 jwMoDROk8Z7aCAl3kSZ7vyFngHZxuAdg+elNeh1YuOxNvZ9ykw2fsE5ZZeJ9TJE5CSR9 OKshgyltUufzhe69u8+KAgTCZbYShttHeGb1WmjJvkJeP49q2KeJMnF50uFMEBj3SvtC qLzzpnYaG2z+lJsWMDtl4bXPy92wW4VSD3NEuUyHrEWgCZLZEJehJMdXEtjtk9I9VApA edW8+JXg+raxNjj+HL6UJ228eiQNs5G8H4flwrSI/pYSovzUHikqbwNUEBeqxXVKlhSv lzqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CTudQxlz; 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=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 l15-v6si1430170pgh.593.2018.09.27.01.51.08; Thu, 27 Sep 2018 01:51: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=pass header.i=@linaro.org header.s=google header.b=CTudQxlz; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727027AbeI0PIP (ORCPT + 3 others); Thu, 27 Sep 2018 11:08:15 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:41815 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727315AbeI0PIP (ORCPT ); Thu, 27 Sep 2018 11:08:15 -0400 Received: by mail-wr1-f65.google.com with SMTP id j15-v6so1647955wrt.8 for ; Thu, 27 Sep 2018 01:51:05 -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=8qG3i7EOfW75+1ul/qMJed+W8vBlnWG4DFjga9+cTRI=; b=CTudQxlzyl1XsS+Y4b5DeSKYBr5h0qMtnEAEWbqW3aHZsDDutmDbVGk0frhXrwe1Ia zQJEgZvV7TL7KSq/VgT14zQFbM8tni0q3Ku3OI9UkL/bkiNtWpdDyfptBlFFVMHn+W26 VwtF2/bUqNkonFF2yk7reykD+QR+JdIDlqXjo= 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=8qG3i7EOfW75+1ul/qMJed+W8vBlnWG4DFjga9+cTRI=; b=bm1iKMjR13H0BiKSS+Dnru0Bc/A44FK8eUiYH6/z7tRTbuwNhB1Iz5P0rchedyb5Yy VS/PBwD0EezrMX/F0xeH44VQXADFgaMBrpJcgI6GpnOCq4j/gTauq0zMBwyN5LbmSJjL RiM3lu87WkOq7xJu87Zqrh8WnwFT4YBlzVKhUT3DKdjDNpT+JEYEI/14zzSTq3gOPOOG DBPrLgVeexm0GKtm3BBkjjM1kOmHqf7x8Pg/b4MgBHh62FVPd+c3qmrCBa/yBCt6+6Yy 3LVibVY9jQgIcGnWY8T2Ds5frdco2nBY6b/5nmXSTewps8zNIqW33Sa+vk5kB5Nsg+WD 5vSg== X-Gm-Message-State: ABuFfohhmkjsI0zqlUqzo7Xvr/bYUE3tjr4u0IpwnGiT0vJqS/yMbuM7 H9i6VfqOcWTTXlUyHQ9FAGFSfA== X-Received: by 2002:adf:fb0e:: with SMTP id c14-v6mr7970479wrr.117.1538038264841; Thu, 27 Sep 2018 01:51:04 -0700 (PDT) Received: from rev03.home ([2a01:cb1d:112:6f00:546e:3c44:5966:2f5e]) by smtp.gmail.com with ESMTPSA id p11-v6sm1304055wrd.74.2018.09.27.01.51.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 01:51:04 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-efi@vger.kernel.org, Aaron Ma , Alistair Strachan , Ben Hutchings , Bhupesh Sharma , Hans de Goede , Ivan Hu , Jeremy Linton , Marc Zyngier , Matt Fleming , Peter Robinson , Sai Praneeth Prakhya , Sebastian Andrzej Siewior , Stefan Agner Subject: [PATCH 06/11] efi: Make efi_rts_work accessible to efi page fault handler Date: Thu, 27 Sep 2018 10:50:33 +0200 Message-Id: <20180927085039.8391-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180927085039.8391-1-ard.biesheuvel@linaro.org> References: <20180927085039.8391-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Sai Praneeth After the kernel has booted, if any accesses by firmware causes a page fault, the efi page fault handler would freeze efi_rts_wq and schedules a new process. To do this, the efi page fault handler needs efi_rts_work. Hence, make it accessible. There will be no race conditions in accessing this structure, because all the calls to efi runtime services are already serialized. Tested-by: Bhupesh Sharma Suggested-by: Matt Fleming Based-on-code-from: Ricardo Neri Signed-off-by: Sai Praneeth Prakhya Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/runtime-wrappers.c | 53 +++++-------------------- include/linux/efi.h | 36 +++++++++++++++++ 2 files changed, 45 insertions(+), 44 deletions(-) -- 2.18.0 diff --git a/drivers/firmware/efi/runtime-wrappers.c b/drivers/firmware/efi/runtime-wrappers.c index aa66cbf23512..b18b2d864c2c 100644 --- a/drivers/firmware/efi/runtime-wrappers.c +++ b/drivers/firmware/efi/runtime-wrappers.c @@ -45,39 +45,7 @@ #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; -}; +struct efi_runtime_work efi_rts_work; /* * efi_queue_work: Queue efi_runtime_service() and wait until it's done @@ -91,7 +59,6 @@ struct efi_runtime_work { */ #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); \ @@ -184,18 +151,16 @@ static DEFINE_SEMAPHORE(efi_runtime_lock); */ 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; + 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) { + 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); @@ -253,8 +218,8 @@ static void efi_call_rts(struct work_struct *work) */ pr_err("Requested executing invalid EFI Runtime Service.\n"); } - efi_rts_work->status = status; - complete(&efi_rts_work->efi_rts_comp); + 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) diff --git a/include/linux/efi.h b/include/linux/efi.h index 22e4de9d3700..a929d2bf41fa 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1662,6 +1662,42 @@ struct linux_efi_tpm_eventlog { extern int efi_tpm_eventlog_init(void); +/* 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; +}; + +extern struct efi_runtime_work efi_rts_work; + /* Workqueue to queue EFI Runtime Services */ extern struct workqueue_struct *efi_rts_wq;