Received: by 10.223.185.116 with SMTP id b49csp3188552wrg; Mon, 5 Mar 2018 16:07:04 -0800 (PST) X-Google-Smtp-Source: AG47ELvB1NneZNMkp9e2oFtmnKNqcoGvZmGCAIM31aOcLmX+aHEUqbNag5+xRp39RNnRtYF19GIV X-Received: by 10.101.82.198 with SMTP id z6mr13462633pgp.41.1520294824121; Mon, 05 Mar 2018 16:07:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520294824; cv=none; d=google.com; s=arc-20160816; b=B8Cw7BHC5EVTLu3ZeYaj58yjbdOYPOvNG+rb9JwhVZZXfVXn9GfU7NjvhQIU+sunKk 825WVFFkck8gbuGkcQOd+UFs+67NmiFUGbYEhzBD5/EvxOS5ju9F30DRGYypsWITqFU8 FR7bN0WmaWfRhvnZ3t5arPVPh0S1q54O6bLa4Frnlknma73YOddLBbK4MsGzf5qCm5Vt mu8etUy74crGc5/z+9EuRVJSHG7aH1vh/4cG+eHdjqtmG5kJRxvTU0aoQys0WiCNbEwf J3LCcx5XxrJxk9g3GmVA1VfEonrhZmOl07AhtqgTEGJ433lDXEOwvwzzMH52ibKs9bYT c4Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=EfIsYGNPHKunM+YiqQCSkFik0Wd8dEm2PxEB/39zPXo=; b=EipjHejnSnk8sbdVX9Mo/g8KBgnwF1x2ZoT6O5srPQYrBw8PCrHrnvyooF54omtEOL v8zI/dlp2ND8AjRGv7Y5FAHqhyAOxarlJ1T0HoU0qUvT2SSV2fQRhTr6XoFuyq9Li059 DRc5SYmbT57JBfB04bjmIIEX2T4jT5GqNnnBuEV63J7EG4XrE6f7F22A8YMtqF5Emk5q ADlD8WefhZn3VZao1erl+O0bRA1WbTwXE1ccGtf7xq344yd+nr5mS7sQx2uPOGzL9aT8 nQFTxWpT+CtUTuCb7J1mJhTMifSHvd16SsqJVSLer0xWjUlT0C679yM+ZJR6gUgUBslz tE5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=Trh2Iw+R; 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 w17-v6si5453806plp.561.2018.03.05.16.06.50; Mon, 05 Mar 2018 16:07:04 -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; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=Trh2Iw+R; 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 S932847AbeCFAFg (ORCPT + 99 others); Mon, 5 Mar 2018 19:05:36 -0500 Received: from mail-ot0-f196.google.com ([74.125.82.196]:45875 "EHLO mail-ot0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932395AbeCFAFe (ORCPT ); Mon, 5 Mar 2018 19:05:34 -0500 Received: by mail-ot0-f196.google.com with SMTP id f11so16717141otj.12 for ; Mon, 05 Mar 2018 16:05:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=EfIsYGNPHKunM+YiqQCSkFik0Wd8dEm2PxEB/39zPXo=; b=Trh2Iw+RN87ynxH9k3ab9qPgA4Td2ijoUqSMr17dp61vpamvOztXnroJRDKdKSkwlG 1vznMgXEzPlm5a9OA+vOvifiIrX73d8Nx5Z6shaqLPqzblCm1nrcbB+SvakIUG9G3JG1 rl3cRCqdnQQBwYPK8CS5MINysCWQ3oeImtsgZmbQaZEMYhEw/j05cq9KlY8PMutkVyEH FKNgRn384N7VndW9XkfjXIL543zQvrLTMfrNs2dhzZ+oy3SHINvv4ViVuEVK1tVfMxOa SBUfFd4SykfxIEr0yhVHgfhhtdoj1hnXflW2ycXerNIWYEZ5aY7+BNlRXsfAhuV6Yeqk pN3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=EfIsYGNPHKunM+YiqQCSkFik0Wd8dEm2PxEB/39zPXo=; b=MgUqlob/TbgNmI8G5al/o8v9pXS8LxYu5rjVMnjYOvXLP/fDQtdD8FyPmWd785wMpo /6syyq0mMiJLGpaKYHDaQ9teJ0EK3slcJw3nXhmdaFyvFG/ojuc046RId/SGwQ+EzkZH F8rXYWMN4mGArt89PYic0TjZ9Pj7B6rz3PSGTcPVTH43vPNXq/mgmJDq6ikhYmPUOgfZ 2U/pl8ukVKvVu/DVPunKJoOOjA49kXWPXG7tl3cbBCEzQT1YT9yz6lpdoT2cIO8Wpdfm imjKfgSrT8O66UcXvLyukvr5mhTE/wbSXY9AUjbmw3f3DZmb0vc7bKODa/Q3bC17kmeR ZHnQ== X-Gm-Message-State: AElRT7E8NepCsYLJVD6vZBU0iJuZ/14F8gsuzO9fktuPcgfRI29t6Dio mtsJJhOXVKuVf9WgvI9Lq4loN40w6SYAb+arXE3FPw== X-Received: by 10.157.23.34 with SMTP id i34mr12542428ota.210.1520294733682; Mon, 05 Mar 2018 16:05:33 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.81.137 with HTTP; Mon, 5 Mar 2018 16:05:33 -0800 (PST) In-Reply-To: <1520292190-5027-4-git-send-email-sai.praneeth.prakhya@intel.com> References: <1520292190-5027-1-git-send-email-sai.praneeth.prakhya@intel.com> <1520292190-5027-4-git-send-email-sai.praneeth.prakhya@intel.com> From: Dan Williams Date: Mon, 5 Mar 2018 16:05:33 -0800 Message-ID: Subject: Re: [PATCH V2 3/3] efi: Use efi_rts_workqueue to invoke EFI Runtime Services To: Sai Praneeth Prakhya Cc: linux-efi@vger.kernel.org, Linux Kernel Mailing List , Chun-Yi , Borislav Petkov , Tony Luck , Will Deacon , Dave Hansen , Mark Rutland , Bhupesh Sharma , Ricardo Neri , Ravi Shankar , Matt Fleming , Peter Zijlstra , Ard Biesheuvel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 5, 2018 at 3:23 PM, Sai Praneeth Prakhya wrote: > From: Sai Praneeth > > 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 adds support to efi > subsystem to handle all calls to efi_runtime_services() using a work > queue (which in turn uses kthread). > > Implementation summary: > ----------------------- > 1. When user/kernel thread requests to execute efi_runtime_service(), > enqueue work to efi_rts_workqueue. > 2. Caller thread waits until the work is finished because it's dependent > on the return status of efi_runtime_service(). > > Semantics to pack arguments in efi_runtime_work (has void pointers): > 1. If argument is a pointer (of any type), pass it as is. > 2. If argument is a value (of any type), address of the value is > passed. > > Introduce a handler function (called efi_call_rts()) that > a. understands efi_runtime_work and > b. invokes 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. > > pstore writes could potentially be invoked in interrupt context and it > uses set_variable<>() and query_variable_info<>() to store logs. If we > invoke efi_runtime_services() through efi_rts_wq while in atomic() > kernel issues a warning ("scheduling wile in atomic") and prints stack > trace. One way to overcome this is to not make the caller process wait > for the worker thread to finish. This approach breaks pstore i.e. the > log messages aren't written to efi variables. Hence, pstore calls > efi_runtime_services() without using efi_rts_wq or in other words > efi_rts_wq will be used unconditionally for all the > efi_runtime_services() except set_variable<>() and > query_variable_info<>() Is there a place in the system reboot path where we can try to flush these asynchronous pstore writes from interrupt context? It seems unfortunate that we need to have this wide exception for all set_variable() calls. Either that or switch to an explicit "emergency mode" where we stop caring about protecting the system from EFI runtime code because we're already crashing.