From patchwork Sat Jun 22 08:51:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 167477 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1734088ilk; Sat, 22 Jun 2019 01:51:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqwuOSJapgIrEeYFgA9V5dV4WsIq9w3lev/0/u+tpC3A9NC5wsAArmT6FCUUogUcL89UDtZn X-Received: by 2002:a17:902:2aa8:: with SMTP id j37mr91644603plb.316.1561193477898; Sat, 22 Jun 2019 01:51:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561193477; cv=none; d=google.com; s=arc-20160816; b=NbyX4kEGXg2peC62MTBhryn5A2WJ3TJ+9OfvM01qLy6BA/pVbrFkhH+XfX9zpw43PB 3UvpFwmRHXvQPs1o3zDoAfhppnQ9JisWejachwKAudLgSPpst+1TVVHRdPOAt6s5dGQL VSLIEZ+kbzNfUw08+qaGa4E7cJbxTCHGDpcJdx3QVD1ME7Sm0olGygGDPFlpTEPSRW3P qdH0HyyHeTT585Pf92RwTMf9uHGVGpeiivIpnXJ/lutgvi/dwedd69qRSl1UhZa+I5El q+xEahXit4gcO+WhJjzvPDbPjWU6Wzh0z8qLF3lVK+XmfcPkPiqopf2XYoaPBHyXYU6p A3+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HO4NlEgMlVr7RQNzUTkiZe3whDgA7iGbSEYeXfsjzfo=; b=ABC9RSxdjC82Hyb3/WVI73+LPeWVMTI43KEI2yMPgykO7e6Y6Yjd9vQVoNDmQMKUQY fIutdKpQD8qqFWjknB1YfUSYPbxyIqe0wIzNrtYwwGWGv3rzODSAl5JkMcJYUaMOcfWB s1TFrZHQyo+xSEtoFqImrDm9CDPEjRFKsLGbVf69OxY6fuxCB7qeaz/ZFOBIMjrXk03g IUG33n9FyxcdrQzFrS7Q09LTNheFZKFH64X3PmNq762NI8jdSaWwotezN6AeTPaGfac6 ZlJshYZDCJ/LUY9V6KpF97Jw+avTYX4mboM2cTmofedsefhFVdOgoAntOVlJQQDbl9oq tHcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iz2Wh5lK; 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 b5si4917528pfd.273.2019.06.22.01.51.17; Sat, 22 Jun 2019 01:51:17 -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=iz2Wh5lK; 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 S1726416AbfFVIvQ (ORCPT + 30 others); Sat, 22 Jun 2019 04:51:16 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:51836 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726308AbfFVIvO (ORCPT ); Sat, 22 Jun 2019 04:51:14 -0400 Received: by mail-wm1-f65.google.com with SMTP id 207so8287019wma.1 for ; Sat, 22 Jun 2019 01:51:13 -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 :mime-version:content-transfer-encoding; bh=HO4NlEgMlVr7RQNzUTkiZe3whDgA7iGbSEYeXfsjzfo=; b=iz2Wh5lKIKrtIT+GilYCiOborf/BB+0KAnXOBgcowZHsTrFSpVUgXEsP8RADKbgcjA AiNEbMFDsQHqYVnWhYpACbjywEFmgTQHxJbOZh0qTYuoixUa9GwiPPPJ7c9Pohwgpt+k usZtN0O+w4JAQj2x3sfCJefE7RL8k9GJwvaw6Q4C065/h9Z0VFvC/r/CllXb4R5ZPrDV +a49/gi4z3nP3UUHtSONU1xhrt+djS34PKGvVpsc4yihqBsw7ULFsoBJS4VNLegoUAqE kYjdwP3jxhffTl7ROUZHCgTdMj8VgCtkkMDZcwxIueXwu5dCXzu3BIFp6fCTwkKb+fym LquA== 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:mime-version:content-transfer-encoding; bh=HO4NlEgMlVr7RQNzUTkiZe3whDgA7iGbSEYeXfsjzfo=; b=Nenr8ADncjCOBt5g3EUhGFQSNzJYZjGTVOS7ZEDhceWGt5Jd98wVrllic/lbsN3juZ baCDEMqWPmuYvODVuvr859gr19dGirVSo49Pis8RAc4OrQu6+tBSjM9umaXvN3KGu8Cu R0bb+RmRI3lj3lrq3ZoXOD37ISgKIuJNrzCxsehvCK6rVaItsznJ8O45wgferexUCKd6 BCCRY5qKGpDbuRqVOJXQdhezsttxFRB/SOQcSSNQCzuCl0pxGu2eVtsyeIIESyPpPvoc F6kMNSr6uY+pdmxl4Jqryj4L1evD4EqJdjTVnTGCyE6+Rzy3CB8Zi+yyMi0qeK8tyP5C OTHA== X-Gm-Message-State: APjAAAUAHM6ayM2u9S85FFW27L6XXFLjiT5BdpfkX5vf+Zyh194/lq1K I9OZlAJUK4Rh9M8ZnzuajDVzew== X-Received: by 2002:a7b:c450:: with SMTP id l16mr7720525wmi.0.1561193472725; Sat, 22 Jun 2019 01:51:12 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:4bd:3f91:4ef8:ae7e]) by smtp.gmail.com with ESMTPSA id v15sm4863589wrt.25.2019.06.22.01.51.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Jun 2019 01:51:12 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Hans de Goede , Jonathan Richardson , Luo XinanX , "Prakhya, Sai Praneeth" , Qian Cai , Tian Baofeng Subject: [PATCH 1/4] efi/memreserve: deal with memreserve entries in unmapped memory Date: Sat, 22 Jun 2019 10:51:03 +0200 Message-Id: <20190622085106.24859-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190622085106.24859-1-ard.biesheuvel@linaro.org> References: <20190622085106.24859-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ensure that the EFI memreserve entries can be accessed, even if they are located in memory that the kernel (e.g., a crashkernel) omits from the linear map. Fixes: 80424b02d42b ("efi: Reduce the amount of memblock reservations ...") Cc: # 5.0+ Reported-by: Jonathan Richardson Reviewed-by: Jonathan Richardson Tested-by: Jonathan Richardson Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efi.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) -- 2.20.1 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 16b2137d117c..4b7cf7bc0ded 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -1009,14 +1009,16 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size) /* first try to find a slot in an existing linked list entry */ for (prsv = efi_memreserve_root->next; prsv; prsv = rsv->next) { - rsv = __va(prsv); + rsv = memremap(prsv, sizeof(*rsv), MEMREMAP_WB); index = atomic_fetch_add_unless(&rsv->count, 1, rsv->size); if (index < rsv->size) { rsv->entry[index].base = addr; rsv->entry[index].size = size; + memunmap(rsv); return 0; } + memunmap(rsv); } /* no slot found - allocate a new linked list entry */ @@ -1024,7 +1026,13 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size) if (!rsv) return -ENOMEM; - rsv->size = EFI_MEMRESERVE_COUNT(PAGE_SIZE); + /* + * The memremap() call above assumes that a linux_efi_memreserve entry + * never crosses a page boundary, so let's ensure that this remains true + * even when kexec'ing a 4k pages kernel from a >4k pages kernel, by + * using SZ_4K explicitly in the size calculation below. + */ + rsv->size = EFI_MEMRESERVE_COUNT(SZ_4K); atomic_set(&rsv->count, 1); rsv->entry[0].base = addr; rsv->entry[0].size = size; From patchwork Sat Jun 22 08:51:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 167480 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1734188ilk; Sat, 22 Jun 2019 01:51:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqwg7NPtitV0yz2WeL/RlLWBjUc9DbJ2yE6LWZXC86u07k/QfILgWXRSVXVUQyYGIrN3zRAx X-Received: by 2002:a63:6b46:: with SMTP id g67mr14912066pgc.45.1561193486709; Sat, 22 Jun 2019 01:51:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561193486; cv=none; d=google.com; s=arc-20160816; b=hp/NSeTj85KtItsmurK0l3mn7A3x1+4uA6tiO5UXDYEyY5s2QvBPPFHktHNwmUxqOs LuY3l6rm4jIVLxxQjicJVRG9NDPmFCmObcJ/LB5nKPqIDA4zcJIvBBTm0rOd9DpmHSJt XjMmgIETxsTWI654od/QCDJZNhwK/MDxJUiVWV5eFPRn+WgjBqsO0CXoBQHub1k52i2u oLTdO9cvTxh9Wp/1hoMJqOEfdhUtNZszCN0VaePRALuNFuCtgpJEVWFguzbTvzp6O8cC 16GH+V9ZJ9NZUP0q2wih3cfZ1SDOKjJqOLi+OgRcUHiq7m/3v8p3aKQxhnGHpFCkIs0W 4DVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qiN85MY5YnTwB3nQ80pJ/FSY8JMCGoluMGY1yE5pzt8=; b=XUS50EUcppjchedzBHRjj6FHbdCYChjgxc7QTO6Y8j13ZOi7a0ku5lDtfpM5aF3Tuv Yf5+hfL2peIODaC0pyYlzIT2nOJFmeOTdG/hnmlgWNpa/rW2pVETL+x3yRX+PJTher/Z ODjaYGllDTwuvTc6hNsI9Z5FB9jqAccS82ZdKmCgoiv73+ZvWQn4b36ZaFN6WOJcYmze aDFYPucPHThyLKJlvslYOem8IkGPY/hXq9h0J5aefRWFavAHLYkUxZs8mCl9b8fCwSU4 lP6zRb58WoX1Eptsqb9+4iVxemQx2p+KDHlzcLv/LO9/CnY2KfImDujmafdin93gdD// 9nkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="H/p1qP5U"; 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 f16si5357664pjg.50.2019.06.22.01.51.26; Sat, 22 Jun 2019 01:51: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="H/p1qP5U"; 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 S1726465AbfFVIvX (ORCPT + 30 others); Sat, 22 Jun 2019 04:51:23 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:45516 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726419AbfFVIvS (ORCPT ); Sat, 22 Jun 2019 04:51:18 -0400 Received: by mail-wr1-f67.google.com with SMTP id f9so8687554wre.12 for ; Sat, 22 Jun 2019 01:51:17 -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 :mime-version:content-transfer-encoding; bh=qiN85MY5YnTwB3nQ80pJ/FSY8JMCGoluMGY1yE5pzt8=; b=H/p1qP5UKrqbgx62rex5GvcEiP0tumRfLfdHFtTeGXRVnhy+Bc0wSAjxZkpJI2kT6U vQUfAVCPe9SfCqgFiRYWiEmlDFWx07zJylvpNpmMiWu8esFrF0nsSylVV71EWkolD9xQ S6t6QfIx1p643HMzcCMzaomCgLCtYVoT4th99SnrRo5wcclGgqXgD2Mkx7M81nBh7D8c FHSNPRsklt3XRZV1fmkYW6h+38Z1j8NhVaQ1GreT6T/aI81iqlGF30NUrqPj0xQozNpg HEyFXAK7Eufqhn0jAVrL7bYli/+XrGKo5PABFeIFVThkD2OuAz7cbiOlxuXxWaFMaFBO ZJyA== 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:mime-version:content-transfer-encoding; bh=qiN85MY5YnTwB3nQ80pJ/FSY8JMCGoluMGY1yE5pzt8=; b=UqUxfZxJ3LDSVbBMYTj+zDaUIRJxBertwxVyp4N/I3zUYlGYaWmzkhYudJ3W60IhoV s6tfkgJNa0L+80lp2XHBJn1Gz6NjXQWb9+6dGtgQRw+5Wl3Re9M+d9+3pRRNyoxSRRC8 P7lW7dEtinoXt9FluuhIme1yivxq9zrDiZHDYJpHYSM3BPbL1pksKWkna93ma9JfLtyt o4Olq7SUTjIeid/YtbsROl3lubS5kLTnvD7L4ckHAU8yrCWIpfofGbwY4r7E1IyNcfuS KlwQqGRluuqncQcu36bcn0u6ESUEBPuz0nqhi2G+fMQd+NImZcr26tCZe6V8IvxIL2Hc +jQg== X-Gm-Message-State: APjAAAU3wgEeFbw9MTF/ltaP83qq1h0u/KJUXbmi/g6QFeIiZb+JvADX qnNiSvJekrm3ch/WL6TZc5hpgQ== X-Received: by 2002:adf:f591:: with SMTP id f17mr2519691wro.119.1561193476680; Sat, 22 Jun 2019 01:51:16 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:4bd:3f91:4ef8:ae7e]) by smtp.gmail.com with ESMTPSA id v15sm4863589wrt.25.2019.06.22.01.51.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Jun 2019 01:51:16 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Hans de Goede , Jonathan Richardson , Luo XinanX , "Prakhya, Sai Praneeth" , Qian Cai , Tian Baofeng Subject: [PATCH 4/4] efibc: Replace variable set function in notifier call Date: Sat, 22 Jun 2019 10:51:06 +0200 Message-Id: <20190622085106.24859-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190622085106.24859-1-ard.biesheuvel@linaro.org> References: <20190622085106.24859-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tian Baofeng Replace the variable set function from "efivar_entry_set" to "efivar_entry_set_safe" in efibc panic notifier. In safe function parameter "block" will set to false and will call "efivar_entry_set_nonblocking"to set efi variables. efivar_entry_set_nonblocking is guaranteed to not block and is suitable for calling from crash/panic handlers. In UEFI android platform, when warm reset happens, with this change, efibc will not block the reboot process. Otherwise, set variable will call queue work and send to other offlined cpus then cause another panic, finally will cause reboot failure. Signed-off-by: Tian Baofeng Signed-off-by: Luo XinanX Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efibc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) -- 2.20.1 diff --git a/drivers/firmware/efi/efibc.c b/drivers/firmware/efi/efibc.c index 61e099826cbb..35dccc88ac0a 100644 --- a/drivers/firmware/efi/efibc.c +++ b/drivers/firmware/efi/efibc.c @@ -43,11 +43,13 @@ static int efibc_set_variable(const char *name, const char *value) efibc_str_to_str16(value, (efi_char16_t *)entry->var.Data); memcpy(&entry->var.VendorGuid, &guid, sizeof(guid)); - ret = efivar_entry_set(entry, - EFI_VARIABLE_NON_VOLATILE - | EFI_VARIABLE_BOOTSERVICE_ACCESS - | EFI_VARIABLE_RUNTIME_ACCESS, - size, entry->var.Data, NULL); + ret = efivar_entry_set_safe(entry->var.VariableName, + entry->var.VendorGuid, + EFI_VARIABLE_NON_VOLATILE + | EFI_VARIABLE_BOOTSERVICE_ACCESS + | EFI_VARIABLE_RUNTIME_ACCESS, + false, size, entry->var.Data); + if (ret) pr_err("failed to set %s EFI variable: 0x%x\n", name, ret);