From patchwork Thu Mar 8 08:00:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 130967 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp6174804lja; Thu, 8 Mar 2018 00:02:04 -0800 (PST) X-Google-Smtp-Source: AG47ELtKHUlnAHsDT38hjh4TYchSnpYop6sKC4tmLvNyuAq5ya3xW6wznqgvW9Fky9YD9M3xme/4 X-Received: by 2002:a17:902:5984:: with SMTP id p4-v6mr23720952pli.38.1520496124194; Thu, 08 Mar 2018 00:02:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520496124; cv=none; d=google.com; s=arc-20160816; b=szIeMFiMoCvIW6NC9SPg/FXHdSBymC/AKRRet79FREvOWoaEoXVUq/o4XcirG1HqXK /o8AeU4q1u5ShzRxIlXSArvRpj+hvwTolY4EfnpywL2K1cNdbjYeoE0oQU1xzHK2wZ/a wjAFWtMp9cjX+DTfUsFtYgvUUOarpo01Dsdp0sSCk0aOCT/j6lXIpbzRFQLwdZ9S8MCM IW6uj+ManZ25e+ivBHuVeqVTAz/MQcakjBkZQiFKUnnRLnlpJW33/qa6YSQb4o47SW6j kR+sb349qVu13+az1Qb11rs/g29vWTsHtONUy1nSmafsni/hyOwhHZVzTKeGlYWq8fYl Bw9g== 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:arc-authentication-results; bh=a7b3PSNYj8tHT2AB9qUHqW5ltqwjTEi5I9THeAA3O1c=; b=UTuDxQkBXmMMOkquvbph9w1W2XXzx2CFnI3LSvE+I2W9c0Ym2OEjc6IkWfYP72so/R iDkuEIsIPWekfSHZmvOWumX71oB07/ULtnAccwRC0p4WssaDYiwd9mjkYp0Srmz+PEhX Ai9UjqE8ewyQqFaLbjBD+TW1TK3rs9H1jAdf+iiDYI+ng52RJ8l/VR3+pOeovY2S1b/+ ej9m6yraCQiE0qK6VYT2GKlCKpyM1Ug6URrPcxEwDZFQnDsosdfosdMqijm5gvyuOUPB p5WKeGMmXv7jUv1yWANWbP0hQI8CEbntCvO+6tt8aQbteVhL1wfaLaGcsQwwxz4igQsO /NdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W//rEZfl; 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 v2si12662799pgf.530.2018.03.08.00.02.03; Thu, 08 Mar 2018 00:02: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=@linaro.org header.s=google header.b=W//rEZfl; 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 S965058AbeCHIB6 (ORCPT + 28 others); Thu, 8 Mar 2018 03:01:58 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36225 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935358AbeCHIBx (ORCPT ); Thu, 8 Mar 2018 03:01:53 -0500 Received: by mail-wm0-f68.google.com with SMTP id 188so9277034wme.1 for ; Thu, 08 Mar 2018 00:01:53 -0800 (PST) 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=a7b3PSNYj8tHT2AB9qUHqW5ltqwjTEi5I9THeAA3O1c=; b=W//rEZflJewEIGqYimBGW4YEyvXzAlHPpIx7VN86+ZlSs+6be/mlz6enk3JfdlGWrh SI6v+/Cfao5ASnrJveEQ3/70cNvbrJ8eqIynSr6iFhkOKBFSXHZ20vyYsfMpb/IRbjw7 eRnbDVTRpJvliNwXBgngDDAwlgrVICvjP01jI= 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=a7b3PSNYj8tHT2AB9qUHqW5ltqwjTEi5I9THeAA3O1c=; b=pZFQVN4cM/eX1ROrLSEUVq0Q6z+OVBZjJCWmZxj+17zetBa1PxeUK5gzijrTl339SU WanxqVT1Bx8PboX3SxGT3BTDljXsQt2W1DWZ4ijajidf4/oa5lH1jKeEKg/89XiHiCol nzn1xB89Wmvwe/u81nggiuuf77I6/cLn+obFpsmFn2MtVRzCb3ZQrvQapNDDJAqhuvkW 3yrwUS6e2e0GDnc/tayYbmc7LR0B1OrHr3cSG43A7gO5R5u8k3EHfn6qL/mYPjbKU/p7 CSroH0bkKr0dJRN6OYMzt762NY8u0BnT6JiI0sIU8yHdglRO2LNO46qfi65YIZYvVgF/ o8dw== X-Gm-Message-State: AElRT7EokUxrIuAQDgN3WYvpM/SDZeoiUWAzxlQcZwplyTSYC3GLm8aG KPEVuWT9MS6x45UKrAZiFGs03Q== X-Received: by 10.28.20.74 with SMTP id 71mr15315608wmu.71.1520496112526; Thu, 08 Mar 2018 00:01:52 -0800 (PST) Received: from localhost.localdomain ([160.89.73.46]) by smtp.gmail.com with ESMTPSA id e191sm11223361wmg.12.2018.03.08.00.01.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Mar 2018 00:01:51 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Mark Rutland , Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 01/12] efi/arm*: Only register page tables when they exist Date: Thu, 8 Mar 2018 08:00:09 +0000 Message-Id: <20180308080020.22828-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180308080020.22828-1-ard.biesheuvel@linaro.org> References: <20180308080020.22828-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Rutland Currently the arm/arm64 runtime code registers the runtime servies pagetables with ptdump regardless of whether runtime services page tables have been created. As efi_mm.pgd is NULL in these cases, attempting to dump the efi page tables results in a NULL pointer dereference in the ptdump code: /sys/kernel/debug# cat efi_page_tables [ 479.522600] Unable to handle kernel NULL pointer dereference at virtual address 00000000 [ 479.522715] Mem abort info: [ 479.522764] ESR = 0x96000006 [ 479.522850] Exception class = DABT (current EL), IL = 32 bits [ 479.522899] SET = 0, FnV = 0 [ 479.522937] EA = 0, S1PTW = 0 [ 479.528200] Data abort info: [ 479.528230] ISV = 0, ISS = 0x00000006 [ 479.528317] CM = 0, WnR = 0 [ 479.528317] user pgtable: 4k pages, 48-bit VAs, pgd = 0000000064ab0cb0 [ 479.528449] [0000000000000000] *pgd=00000000fbbe4003, *pud=00000000fb66e003, *pmd=0000000000000000 [ 479.528600] Internal error: Oops: 96000006 [#1] PREEMPT SMP [ 479.528664] Modules linked in: [ 479.528699] CPU: 0 PID: 2457 Comm: cat Not tainted 4.15.0-rc3-00065-g2ad2ee7ecb5c-dirty #7 [ 479.528799] Hardware name: FVP Base (DT) [ 479.528899] pstate: 00400009 (nzcv daif +PAN -UAO) [ 479.528941] pc : walk_pgd.isra.1+0x20/0x1d0 [ 479.529011] lr : ptdump_walk_pgd+0x30/0x50 [ 479.529105] sp : ffff00000bf4bc20 [ 479.529185] x29: ffff00000bf4bc20 x28: 0000ffff9d22e000 [ 479.529271] x27: 0000000000020000 x26: ffff80007b4c63c0 [ 479.529358] x25: 00000000014000c0 x24: ffff80007c098900 [ 479.529445] x23: ffff00000bf4beb8 x22: 0000000000000000 [ 479.529532] x21: ffff00000bf4bd70 x20: 0000000000000001 [ 479.529618] x19: ffff00000bf4bcb0 x18: 0000000000000000 [ 479.529760] x17: 000000000041a1c8 x16: ffff0000082139d8 [ 479.529800] x15: 0000ffff9d3c6030 x14: 0000ffff9d2527f4 [ 479.529924] x13: 00000000000003f3 x12: 0000000000000038 [ 479.530000] x11: 0000000000000003 x10: 0101010101010101 [ 479.530099] x9 : 0000000017e94050 x8 : 000000000000003f [ 479.530226] x7 : 0000000000000000 x6 : 0000000000000000 [ 479.530313] x5 : 0000000000000001 x4 : 0000000000000000 [ 479.530416] x3 : ffff000009069fd8 x2 : 0000000000000000 [ 479.530500] x1 : 0000000000000000 x0 : 0000000000000000 [ 479.530599] Process cat (pid: 2457, stack limit = 0x000000005d1b0e6f) [ 479.530660] Call trace: [ 479.530746] walk_pgd.isra.1+0x20/0x1d0 [ 479.530833] ptdump_walk_pgd+0x30/0x50 [ 479.530907] ptdump_show+0x10/0x20 [ 479.530920] seq_read+0xc8/0x470 [ 479.531023] full_proxy_read+0x60/0x90 [ 479.531100] __vfs_read+0x18/0x100 [ 479.531180] vfs_read+0x88/0x160 [ 479.531267] SyS_read+0x48/0xb0 [ 479.531299] el0_svc_naked+0x20/0x24 [ 479.531400] Code: 91400420 f90033a0 a90707a2 f9403fa0 (f9400000) [ 479.531499] ---[ end trace bfe8e28d8acb2b67 ]--- Segmentation fault Let's avoid this problem by only registering the tables after their successful creation, which is also less confusing when EFI runtime services are not in use. Reported-by: Will Deacon Signed-off-by: Mark Rutland Acked-by: Will Deacon Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/arm-runtime.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.15.1 diff --git a/drivers/firmware/efi/arm-runtime.c b/drivers/firmware/efi/arm-runtime.c index 1cc41c3d6315..86a1ad17a32e 100644 --- a/drivers/firmware/efi/arm-runtime.c +++ b/drivers/firmware/efi/arm-runtime.c @@ -54,6 +54,9 @@ static struct ptdump_info efi_ptdump_info = { static int __init ptdump_init(void) { + if (!efi_enabled(EFI_RUNTIME_SERVICES)) + return 0; + return ptdump_debugfs_register(&efi_ptdump_info, "efi_page_tables"); } device_initcall(ptdump_init); From patchwork Thu Mar 8 08:00:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 130969 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp6174876lja; Thu, 8 Mar 2018 00:02:08 -0800 (PST) X-Google-Smtp-Source: AG47ELu0+PD2j5oIO6yo4aDcv+fe0a3mfYTXO7ftTtb7kGeqi93n84wcHfKdxuSjZJG41M1iBYhc X-Received: by 2002:a17:902:6c46:: with SMTP id h6-v6mr13118840pln.333.1520496128302; Thu, 08 Mar 2018 00:02:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520496128; cv=none; d=google.com; s=arc-20160816; b=Pc5DyQtKfagFevDZWM3AsEsNOLV/Ws+iE1XOsDubeu0eOSYgc4WlBM2mzG2WCqN3QA gwBKwYvitVRRFr80ku1XzOKUKP6/7Fx2mksFeRy4A/wpVybAA3suZTYm7I3EsFjeqtwn VYTYn8d7YFsQg5IQboKxiq6VH7xP6NTnZzOnrA3RFMSanhP9GNjbr3SLu0dvvOysVtav gMSRAKA8xrAwtdwCxKN04c5U2+lQNZFvAm1yNO3t/5K2IjzyMQ4a87ncszmxEo/61Osz SiGHNger91aQ0Xb3VAlV+6VphktwtlBJZJzWK+07vQver3Ztz/7gHhp2npiilCHPrIou +k5w== 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:arc-authentication-results; bh=So0SEhBYCIIJRKe2r348eEFdmypztSLIDIuIqX2vRO8=; b=OiEoZhpFpSojW54TpjeSVSop6LmNp57U7AoKOI4UyxdIpvcNDE765vdH6cPhclOBHe ifeUEn+bxh7JIVuxFP2RfQ22PiLLKVFLIaUKcQhBqeCBAxm3ERc3MVXrAP8tzJ9g6Qmk Zv9tnSKQyBfsC+SP8OvTQ8v81FN0tvbajpaVNnaH06tXiO5q3cA40pAQyvLVf63+ygqy AwFwoqPv7XszOdIkjK6eaECAAy/XDknFF1xpAtJf4aMi5sNjI48AyrOlEEMmb3qbiVaU 7r59kWAqCvXQdO+kJBqjUUB+m0gzyMi5C7cOAy6oMNfxwQftpk/mJZ1ITmpeNB8dQQ38 HxHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jgwrPqjW; 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 m75si15282302pfg.64.2018.03.08.00.02.08; Thu, 08 Mar 2018 00:02:08 -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=@linaro.org header.s=google header.b=jgwrPqjW; 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 S965230AbeCHICB (ORCPT + 28 others); Thu, 8 Mar 2018 03:02:01 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:45616 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965050AbeCHIB6 (ORCPT ); Thu, 8 Mar 2018 03:01:58 -0500 Received: by mail-wr0-f195.google.com with SMTP id p104so4651999wrc.12 for ; Thu, 08 Mar 2018 00:01:58 -0800 (PST) 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=So0SEhBYCIIJRKe2r348eEFdmypztSLIDIuIqX2vRO8=; b=jgwrPqjWRN1atN55ydyAMievC46PDpr4ahKIP/dhDWFirtmDZfE6pki509Ds8J8mEf yD+nTFq8XkWlEphflaxDwRfOkyKwGOnDQEXd3XQfLq1uaPoooFO7+bkRvtXfzlGld1rW iQeVThCdST8+sEaGqGD7buzt5bccd1D+Ojswo= 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=So0SEhBYCIIJRKe2r348eEFdmypztSLIDIuIqX2vRO8=; b=Xd2FTJaP0jVqU1QlhlCuDI4ebya2xiZodLQsFrS12DvJmMoEADOam+L++/fdgHIRUb SpvqGqDFIGrKWvwbiVneB4lkGdZa1tsyA+VNG+WGxP8B9Q6pC2KpAPv8Y0gHQoQGstfJ kt6mYauefB6N6GK1qJP0Dw5XGJR2KYZdP1wOcCiSe3eZfAr/0/n5ojRHqXJIoc/0M4rS HQjguEs28PS9xImLEyOCD22DKjpJtl7/HE+jar70Gtyyln3FiKcERTkWf44hnXn674UE sqUUPQHQLs2u+/5hDMxE6Eh1arbyVSUkvFRrcrGmbtO6O8gXHMmSVoAGZbIj7OWgebgf sZvA== X-Gm-Message-State: APf1xPC7zi7oFDvCOetiBOlehYC1zhoIr5U2uxLWX/eJjNYUtpM75jIa g4QEW4GpGH0oaFQcwenTSG+mTQ== X-Received: by 10.223.129.33 with SMTP id 30mr22638468wrm.91.1520496117428; Thu, 08 Mar 2018 00:01:57 -0800 (PST) Received: from localhost.localdomain ([160.89.73.46]) by smtp.gmail.com with ESMTPSA id e191sm11223361wmg.12.2018.03.08.00.01.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Mar 2018 00:01:56 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 03/12] efi/arm*: Stop printing addresses of virtual mappings Date: Thu, 8 Mar 2018 08:00:11 +0000 Message-Id: <20180308080020.22828-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180308080020.22828-1-ard.biesheuvel@linaro.org> References: <20180308080020.22828-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With the recent %p -> %px changes, we now get something like this in the kernel boot log on ARM/arm64 EFI systems: Remapping and enabling EFI services. EFI remap 0x00000087fb830000 => (ptrval) EFI remap 0x00000087fbdb0000 => (ptrval) EFI remap 0x00000087fffc0000 => (ptrval) The physical addresses of the UEFI runtime regions will also be printed when booting with the efi=debug command line option, and the virtual addresses can be inspected via /sys/kernel/debug/efi_page_tables (if enabled). So let's just remove the lines above. Acked-by: Leif Lindholm Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/arm-runtime.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) -- 2.15.1 diff --git a/drivers/firmware/efi/arm-runtime.c b/drivers/firmware/efi/arm-runtime.c index 86a1ad17a32e..13561aeb7396 100644 --- a/drivers/firmware/efi/arm-runtime.c +++ b/drivers/firmware/efi/arm-runtime.c @@ -83,10 +83,7 @@ static bool __init efi_virtmap_init(void) return false; ret = efi_create_mapping(&efi_mm, md); - if (!ret) { - pr_info(" EFI remap %pa => %p\n", - &phys, (void *)(unsigned long)md->virt_addr); - } else { + if (ret) { pr_warn(" EFI remap %pa: failed to create mapping (%d)\n", &phys, ret); return false; From patchwork Thu Mar 8 08:00:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 130977 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp6177432lja; Thu, 8 Mar 2018 00:04:51 -0800 (PST) X-Google-Smtp-Source: AG47ELs5DD4b626YTn4aIDXyXKErJnlhmXbT7w15uQioy5jzTyazSLNh0bQUlgaz3+Xlj7lr4/X1 X-Received: by 2002:a17:902:8541:: with SMTP id d1-v6mr23026395plo.54.1520496291586; Thu, 08 Mar 2018 00:04:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520496291; cv=none; d=google.com; s=arc-20160816; b=Vi9pDdNXu+ZoEVQELO1gs37QZIJFcD+FuF6FjsKjMCwaC+fa/oBEc7gD8pWduDGl0r /GmXtl31mwhy6LKqRIh8S5SFhKzdSqfPLxIqklhSmyOcX2TnyXGkLMv4Dm1YNimdz4X/ Bd2ry6vMQb1px5AgnlKA/5o2EQiVrLBk7wWvoKprUEZMF2qjucyrwEX25hPJEneltWmq mshUD40d9TbCrMLPk0Yg4UPJ7W7JEKnFJz7DGYVgJ9HfVJE2ySXr2VyRb34elVI3nWlg oTa9YWji0zJQhsRs51lOognxQsFu7bCVJBPw6LmNai6vT+dwIRn7oVv64/D3PQQJv241 9euQ== 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:arc-authentication-results; bh=sIYMOnIsHCHadIhT3O2PPHAzaH/6I/c6GgGolR3LAOM=; b=klOojoYEfBDyYVdmFrbsRWCWgpDVBwnWJEsbQh7Q9ODeklmtUpWxQvHmLcmeov6dYd xoO/2amNlybLgnj8E7JbnHmuZ6XaWJ0bLYlR7lDsjljX1UnWgwNYCQq1p/ltFiufMZXp xm9Enumy5hgaeZhXqg+tGjjhNhaBMzi5Qq4mUqoPDZBz+gEYV6uvAd1G61nF8UMhSRv2 XPX0zSal/KmqOGKZgPJBC13rI74T8BrN0lum36LjeSjVdsyhz+L3DnP4ljG4bv3atawX nhDghy59+4mEU2BL8AYj6rtOUxM+1QlrefL1r5o0jq1xawaJukx/HPjsaSZ20uMJBacr iyCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hxPuaaYX; 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 u8-v6si14513041plh.219.2018.03.08.00.04.51; Thu, 08 Mar 2018 00:04:51 -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=@linaro.org header.s=google header.b=hxPuaaYX; 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 S935574AbeCHIEe (ORCPT + 28 others); Thu, 8 Mar 2018 03:04:34 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:34995 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965050AbeCHICE (ORCPT ); Thu, 8 Mar 2018 03:02:04 -0500 Received: by mail-wr0-f193.google.com with SMTP id l43so4677822wrc.2 for ; Thu, 08 Mar 2018 00:02:03 -0800 (PST) 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=sIYMOnIsHCHadIhT3O2PPHAzaH/6I/c6GgGolR3LAOM=; b=hxPuaaYXpwudz13Z0VAL48sUd2ctopgT7lUe5tUF87uzgdJtRkkXen2XxBJgtvrzXY xBVA1FEu4NJ6bjid3bhL4Voat04maSrF2LsctVfzv8htdOSfEzIs76nGVdB/GlufZD0b zMzTr5WveIMTo2twjNpKDBktHp7tkgvCYkh6E= 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=sIYMOnIsHCHadIhT3O2PPHAzaH/6I/c6GgGolR3LAOM=; b=nPsnF3YtWowA4ff4pcwBOBlgvLxFSZ4SybseOfwGmzoSdZn8nHy13UiDGzaV3rko8G WWFPqC4eK8K+7plKYuDmunNFrJ1QIDM1lzmYfOw+5jmNKrFKtmLXDjfJocPnAfQpDrpW qXmvAqgSCFw1+fM5+Ui8VxBX/e1VYahXG0mdtDAt2Bjg2ZdBpJ0O+WsQ1gvsd5Bz3MGq UA/gSqYImjRcQFrxqu6E+lJsJWeNrTDdEj8IsIgkKLIp6SArmEc70Bv5hXRJD692GhCe ppq7nj+Bl0YGe9t1PYD+2Rj2sGnJlNve+dQgl82DzO0G3V/yhwdH8H3154K0p+Dngmjo qr4Q== X-Gm-Message-State: APf1xPAdGGvwpAQ+pKX5gkDV7XyNOoUDw5gpRl2ZhZWlvgHUGqVnFP7S IrsLRGTsl4lDhfbj3d7h4LVl6w== X-Received: by 10.223.189.136 with SMTP id l8mr23373572wrh.69.1520496122416; Thu, 08 Mar 2018 00:02:02 -0800 (PST) Received: from localhost.localdomain ([160.89.73.46]) by smtp.gmail.com with ESMTPSA id e191sm11223361wmg.12.2018.03.08.00.02.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Mar 2018 00:02:01 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 05/12] efi: arm64: Check whether x18 is preserved by runtime services calls Date: Thu, 8 Mar 2018 08:00:13 +0000 Message-Id: <20180308080020.22828-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180308080020.22828-1-ard.biesheuvel@linaro.org> References: <20180308080020.22828-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Whether or not we will ever decide to start using x18 as a platform register in Linux is uncertain, but by that time, we will need to ensure that UEFI runtime services calls don't corrupt it. So let's start issuing warnings now for this, and increase the likelihood that these firmware images have all been replaced by that time. This has been fixed on the EDK2 side in commit 6d73863b5464 ("BaseTools/tools_def AARCH64: mark register x18 as reserved")., dated July 13, 2017. Acked-by: Will Deacon Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/efi.h | 4 +++- arch/arm64/kernel/Makefile | 3 ++- arch/arm64/kernel/efi-rt-wrapper.S | 41 ++++++++++++++++++++++++++++++++++++++ arch/arm64/kernel/efi.c | 6 ++++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 arch/arm64/kernel/efi-rt-wrapper.S -- 2.15.1 diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h index 8389050328bb..192d791f1103 100644 --- a/arch/arm64/include/asm/efi.h +++ b/arch/arm64/include/asm/efi.h @@ -31,7 +31,7 @@ int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md); ({ \ efi_##f##_t *__f; \ __f = p->f; \ - __f(args); \ + __efi_rt_asm_wrapper(__f, #f, args); \ }) #define arch_efi_call_virt_teardown() \ @@ -40,6 +40,8 @@ int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md); efi_virtmap_unload(); \ }) +efi_status_t __efi_rt_asm_wrapper(void *, const char *, ...); + #define ARCH_EFI_IRQ_FLAGS_MASK (PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT) /* arch specific definitions used by the stub code */ diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index b87541360f43..6a4bd80c75bd 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -38,7 +38,8 @@ arm64-obj-$(CONFIG_CPU_PM) += sleep.o suspend.o arm64-obj-$(CONFIG_CPU_IDLE) += cpuidle.o arm64-obj-$(CONFIG_JUMP_LABEL) += jump_label.o arm64-obj-$(CONFIG_KGDB) += kgdb.o -arm64-obj-$(CONFIG_EFI) += efi.o efi-entry.stub.o +arm64-obj-$(CONFIG_EFI) += efi.o efi-entry.stub.o \ + efi-rt-wrapper.o arm64-obj-$(CONFIG_PCI) += pci.o arm64-obj-$(CONFIG_ARMV8_DEPRECATED) += armv8_deprecated.o arm64-obj-$(CONFIG_ACPI) += acpi.o diff --git a/arch/arm64/kernel/efi-rt-wrapper.S b/arch/arm64/kernel/efi-rt-wrapper.S new file mode 100644 index 000000000000..05235ebb336d --- /dev/null +++ b/arch/arm64/kernel/efi-rt-wrapper.S @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2018 Linaro Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include + +ENTRY(__efi_rt_asm_wrapper) + stp x29, x30, [sp, #-32]! + mov x29, sp + + /* + * Register x18 is designated as the 'platform' register by the AAPCS, + * which means firmware running at the same exception level as the OS + * (such as UEFI) should never touch it. + */ + stp x1, x18, [sp, #16] + + /* + * We are lucky enough that no EFI runtime services take more than + * 5 arguments, so all are passed in registers rather than via the + * stack. + */ + mov x8, x0 + mov x0, x2 + mov x1, x3 + mov x2, x4 + mov x3, x5 + mov x4, x6 + blr x8 + + ldp x1, x2, [sp, #16] + cmp x2, x18 + ldp x29, x30, [sp], #32 + b.ne 0f + ret +0: b efi_handle_corrupted_x18 // tail call +ENDPROC(__efi_rt_asm_wrapper) diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c index f85ac58d08a3..fb5b3cd3a1c7 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -126,3 +126,9 @@ bool efi_poweroff_required(void) { return efi_enabled(EFI_RUNTIME_SERVICES); } + +asmlinkage efi_status_t efi_handle_corrupted_x18(efi_status_t s, const char *f) +{ + pr_err_ratelimited(FW_BUG "register x18 corrupted by EFI %s\n", f); + return s; +} From patchwork Thu Mar 8 08:00:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 130970 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp6175012lja; Thu, 8 Mar 2018 00:02:19 -0800 (PST) X-Google-Smtp-Source: AG47ELvp0Nw1NSPwmfwmy5ZSyuZK6gou9BRXXI+VMUgxByu45HRF+45DWRBA1dxn5ii+GjzjdpNu X-Received: by 2002:a17:902:b210:: with SMTP id t16-v6mr23081281plr.373.1520496139139; Thu, 08 Mar 2018 00:02:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520496139; cv=none; d=google.com; s=arc-20160816; b=I+uCIEKVJtayKI+EncWWUTI4dy160kyVOKMgpH6kTJFIjxjJT/4edjYWi5vblV1i/c Oi10l+dpYJy200EWlcpYNeyC8bF3R0wHzzNDJ8BR94sOP3WjEqvPzIblb95qsYrV4a2T DQs5hawVQiSyKesQqHDO4W3SuVFTkkfD+vsArjnsVuU6GCOsaHmJf3naOPzp39+H2pDM qzHOHQqm34Gyr7rGcAG0Lkr+7aVNHgXBafD6+bHoySNKRhzxsjB+M+YFvkSyovuiOshw Fe98ihM0uU8S/Pq/w+wVchBzWoRkaRUKXWUZfUhZLp7z3ra+OOD36PNRoLRhhtfy7Z4b sbaw== 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:arc-authentication-results; bh=uR6XAAs54Wk1jRattopsy687p4Chn7HkmmTWEvFKXUo=; b=zgkWDdcP2sr6A6LSrSNcpiLexy1skq+SmYnmNf3kEdxmGQjuVb/Aen9XQhHQtcw0c2 zaDLKRU1r/kL3d2FkBeAzkwzYpAIaOn+m0JfIH/lRTK5kWEwDoz9GBat0GB2Vn/rb26L k826Xifn2bpwnzTGBmylVTmaz5Ms5CQdGRM+h7l/S4ZPw/tqUVMf/WFDM8/Gfh1mRNcY cW+ZPGMQ5Xc+D9cFRh1escS+4hlSuQ1FHsgmuQ4hRw7Kj0v61oo+OzUXV3uUstJkcrOL ZVYi6Due/QCFAvyJGn8p0Bu54Y39v1Bd3IXSuNI0UnMmagTXjR8no8+YAJjhMAanNNIR gHSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GvnE/6yi; 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 v70si6319449pgb.198.2018.03.08.00.02.18; Thu, 08 Mar 2018 00:02:19 -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=@linaro.org header.s=google header.b=GvnE/6yi; 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 S965504AbeCHICN (ORCPT + 28 others); Thu, 8 Mar 2018 03:02:13 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:53987 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965106AbeCHICJ (ORCPT ); Thu, 8 Mar 2018 03:02:09 -0500 Received: by mail-wm0-f65.google.com with SMTP id e194so9454827wmd.3 for ; Thu, 08 Mar 2018 00:02:09 -0800 (PST) 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=uR6XAAs54Wk1jRattopsy687p4Chn7HkmmTWEvFKXUo=; b=GvnE/6yi6gbrMxvtvtoeEYP7FtnRP6I+Z2E/RirBcrkJ7JHxTWOC93nHS5TvtJZIGf 28erTdKg00zTH72uYrbIGVu4lnkiL6JQ9j5LHpYD7HNqNWsCdUaR4Dd1xC0fn7sTs0DR W8GfW22RrnCVzOfDET1k5PJNgIf+TeVSY1pVY= 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=uR6XAAs54Wk1jRattopsy687p4Chn7HkmmTWEvFKXUo=; b=p4a2IuzLrJqneGFAsAFsv7gCu+8P5tlxvwaHWZMsm7Q/QKUFJv7gs7+KWn2aqtNWnD bcE0YOCeZgatKbxPwB1cKrid+ybEO83Bhqa9QrMfU5kdyLa531uFMx/ock0UfjpIR/IC +FlAhPmHvSS/+KktfOfvgB/9drLOSXPTV4r2n1Oy8gw7G12fGCkzSMyxQN4qhbToRVq4 37aBm9Heuo7a10S+W5w5V3fzBcxEufXr5iHneMsv6qMpuwiNUWrk78u1378UWs2FYf5y YGu8N6ghj34193tDzdh7H82FP22PUeAqLiHyClpLA59we/I6YqBwdp5XLDZS78zPUHTV jgLA== X-Gm-Message-State: AElRT7EP1mQB9ltEzMGhIgJdfkCvZCiEN374KESfx+8bOvBucwFWKb5Q Lt+T6D5v+o9syyaer5u9gRCQhw== X-Received: by 10.28.139.142 with SMTP id n136mr15737343wmd.101.1520496128605; Thu, 08 Mar 2018 00:02:08 -0800 (PST) Received: from localhost.localdomain ([160.89.73.46]) by smtp.gmail.com with ESMTPSA id e191sm11223361wmg.12.2018.03.08.00.02.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Mar 2018 00:02:07 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Sai Praneeth , Ard Biesheuvel , linux-kernel@vger.kernel.org, "Lee, Chun-Yi" , Borislav Petkov , Tony Luck , Andy Lutomirski , "Michael S . Tsirkin" , Ricardo Neri , Ravi Shankar Subject: [PATCH 07/12] efi: Use efi_mm in x86 as well as ARM Date: Thu, 8 Mar 2018 08:00:15 +0000 Message-Id: <20180308080020.22828-8-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180308080020.22828-1-ard.biesheuvel@linaro.org> References: <20180308080020.22828-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sai Praneeth Presently, only ARM uses mm_struct to manage efi page tables and efi runtime region mappings. As this is the preferred approach, let's make this data structure common across architectures. Specially, for x86, using this data structure improves code maintainability and readability. Signed-off-by: Sai Praneeth Prakhya Cc: "Lee, Chun-Yi" Cc: Borislav Petkov Cc: Tony Luck Cc: Andy Lutomirski Cc: Michael S. Tsirkin Cc: Ricardo Neri Cc: Ravi Shankar Tested-by: Bhupesh Sharma Reviewed-by: Matt Fleming Signed-off-by: Ard Biesheuvel --- arch/x86/include/asm/efi.h | 4 ++++ arch/x86/platform/efi/efi_64.c | 3 +++ drivers/firmware/efi/arm-runtime.c | 9 --------- drivers/firmware/efi/efi.c | 9 +++++++++ include/linux/efi.h | 2 ++ 5 files changed, 18 insertions(+), 9 deletions(-) -- 2.15.1 diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h index 85f6ccb80b91..00f977ddd718 100644 --- a/arch/x86/include/asm/efi.h +++ b/arch/x86/include/asm/efi.h @@ -2,10 +2,14 @@ #ifndef _ASM_X86_EFI_H #define _ASM_X86_EFI_H +#include +#include + #include #include #include #include +#include /* * We map the EFI regions needed for runtime services non-contiguously, diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index c310a8284358..0045efe9947b 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c @@ -231,6 +231,9 @@ int __init efi_alloc_page_tables(void) return -ENOMEM; } + mm_init_cpumask(&efi_mm); + init_new_context(NULL, &efi_mm); + return 0; } diff --git a/drivers/firmware/efi/arm-runtime.c b/drivers/firmware/efi/arm-runtime.c index 13561aeb7396..5889cbea60b8 100644 --- a/drivers/firmware/efi/arm-runtime.c +++ b/drivers/firmware/efi/arm-runtime.c @@ -31,15 +31,6 @@ extern u64 efi_system_table; -static struct mm_struct efi_mm = { - .mm_rb = RB_ROOT, - .mm_users = ATOMIC_INIT(2), - .mm_count = ATOMIC_INIT(1), - .mmap_sem = __RWSEM_INITIALIZER(efi_mm.mmap_sem), - .page_table_lock = __SPIN_LOCK_UNLOCKED(efi_mm.page_table_lock), - .mmlist = LIST_HEAD_INIT(efi_mm.mmlist), -}; - #ifdef CONFIG_ARM64_PTDUMP_DEBUGFS #include diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index cd42f66a7c85..c0dda400d22a 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -75,6 +75,15 @@ static unsigned long *efi_tables[] = { &efi.mem_attr_table, }; +struct mm_struct efi_mm = { + .mm_rb = RB_ROOT, + .mm_users = ATOMIC_INIT(2), + .mm_count = ATOMIC_INIT(1), + .mmap_sem = __RWSEM_INITIALIZER(efi_mm.mmap_sem), + .page_table_lock = __SPIN_LOCK_UNLOCKED(efi_mm.page_table_lock), + .mmlist = LIST_HEAD_INIT(efi_mm.mmlist), +}; + static bool disable_runtime; static int __init setup_noefi(char *arg) { diff --git a/include/linux/efi.h b/include/linux/efi.h index f5083aa72eae..f1b7d68ac460 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -966,6 +966,8 @@ extern struct efi { unsigned long flags; } efi; +extern struct mm_struct efi_mm; + static inline int efi_guidcmp (efi_guid_t left, efi_guid_t right) { From patchwork Thu Mar 8 08:00:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 130975 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp6175510lja; Thu, 8 Mar 2018 00:02:51 -0800 (PST) X-Google-Smtp-Source: AG47ELs7teBbk5KarhJH8BtE/PbYgbqzQknMlxkfxIxv0jObIhMvZ+bUymUCRUhBONvL2j6YYR3j X-Received: by 10.99.120.205 with SMTP id t196mr19832591pgc.392.1520496171578; Thu, 08 Mar 2018 00:02:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520496171; cv=none; d=google.com; s=arc-20160816; b=0iwNKuOxmUJdWKhMPXQ0MkXP+rqdk8bmM2pGyOxwFJNgy/Pwzdb0tD18x+gMn/qsz3 RY6oLEkE4z4AWlX/mSaJVRC2Lt8lTEtbUOif/1YLzAtl5iZ/O6aAKgoYn4ivWc3qVKmG 63qUW+zrxTGB2Ux3sBuCLzS5n3WJWfCDlDtsaKcl0FptDVWrDY8TJFpfaDMCMpcOv9z3 dTCOnf29CsUtaqyQPaF1FEaik85TazPrM6zLO0QW4w5/JC6Q6kI7yWm3Zvz6NI2u40Cj z6kQuS94C6nArNf8L7hAUxp03fy10PyPSNaEs8gDH+l8MXGmKEDW1YlPTWVoxm7LIHmp EFpw== 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:arc-authentication-results; bh=UDxa9kNHeQ0iRFqRaV94BS3QESCu7DCrVxxTOZHjGMU=; b=jjcNErV6FpbpYdN1y3fGnaZdquyJPIc5dDoypA2MUGo9Y9yYQinecP+PNYSungCM7L WosmXmsT7Zp0Y9AXdJz6/3yfqUIuALHUhXL1BwVjIpAiJJlrn7RboskBkYLZa3Gs6fBP 9zN5UMSNTP02MmbW3W3dXIF8Ykutprt7HT6n0WcKZYLcliWmB8bpu12NA4QZgkCQZLTb A9t7pKThyb4lyP4EfAs79Lki0TZ0VhnamGO11N/ZSjkVgBcb1b7m/NvCEz6gNyl+FFAd nEsFp7IJ7OpTyQzvXqtQZZYWZnnyCzn12fBHyhTODjBiZNsAvp4MjYU4QNNqBK59is2F 803Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Z5fr8d/m; 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 n22si12729781pgd.564.2018.03.08.00.02.51; Thu, 08 Mar 2018 00:02:51 -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=@linaro.org header.s=google header.b=Z5fr8d/m; 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 S965607AbeCHICU (ORCPT + 28 others); Thu, 8 Mar 2018 03:02:20 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:54759 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965106AbeCHICQ (ORCPT ); Thu, 8 Mar 2018 03:02:16 -0500 Received: by mail-wm0-f66.google.com with SMTP id z81so9457326wmb.4 for ; Thu, 08 Mar 2018 00:02:16 -0800 (PST) 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=UDxa9kNHeQ0iRFqRaV94BS3QESCu7DCrVxxTOZHjGMU=; b=Z5fr8d/m8OoknU2058GS+iJI1hHw+YbnPmgtuKXugPzUS58aGZjswmpvyj8i7KoJ5K URGG2OOchPvjUIhS/at6sN2VkgAbf/vlDteYp5AcdneQabFG7B4RrmHhTX0Zx4K2drof jchQKkrTk9DXm3NYZ5ijRUqp2VfZUaiJd3FHk= 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=UDxa9kNHeQ0iRFqRaV94BS3QESCu7DCrVxxTOZHjGMU=; b=QwPYMdtgPWxxbLvgQ/EbeZrBsff+gUmFP7xbQcg2+045jb+volwlX7WLRue6JOh91F NLxp8/cYvl7d08VYXZ9euKzwqOo7ysKn832sS1sofNUkLoIlCctgCxjRC7BlKi9dYdtr bSb+RulZlGuLiYR5g5b1Z75gMehr1UsWDWVRh4x9LkH+Gw4cEI/AokMNjd+dQ1TT6KZ9 XrsM7v1XuEylhs2nvqKzv12zKbehIcbIkqjercjlhI05SpRn12p0uPVtAybbSp/85OTj 3uv0u9h1L+uzc5Xo3FVK2GUXAr+xDdVgrqVf7FcB1pG5CM7lRw33EBvJSNaB0azj5ATw 1L9A== X-Gm-Message-State: AElRT7GRJNTb4u0YTu8ORVkq4xfrvtxtadMngoBuWfFri1QL7cSq2cYR WZ0buv3AicN95ipVaQnzkWVSnw== X-Received: by 10.28.7.13 with SMTP id 13mr15564749wmh.9.1520496135354; Thu, 08 Mar 2018 00:02:15 -0800 (PST) Received: from localhost.localdomain ([160.89.73.46]) by smtp.gmail.com with ESMTPSA id e191sm11223361wmg.12.2018.03.08.00.02.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Mar 2018 00:02:14 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Sai Praneeth , Ard Biesheuvel , linux-kernel@vger.kernel.org, "Lee, Chun-Yi" , Borislav Petkov , Tony Luck , Andy Lutomirski , "Michael S . Tsirkin" , Bhupesh Sharma , Ricardo Neri , Ravi Shankar Subject: [PATCH 09/12] x86/efi: Use efi_switch_mm() rather than manually twiddling with %cr3 Date: Thu, 8 Mar 2018 08:00:17 +0000 Message-Id: <20180308080020.22828-10-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180308080020.22828-1-ard.biesheuvel@linaro.org> References: <20180308080020.22828-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sai Praneeth Use helper function (efi_switch_mm()) to switch to/from efi_mm. We switch to efi_mm before calling 1. efi_set_virtual_address_map() and 2. Invoking any efi_runtime_service() Likewise, we need to switch back to previous mm (mm context stolen by efi_mm) after the above calls return successfully. We can use efi_switch_mm() helper function only with x86_64 kernel and "efi=old_map" disabled because, x86_32 and efi=old_map doesn't use efi_pgd, rather they use swapper_pg_dir. Signed-off-by: Sai Praneeth Prakhya Cc: "Lee, Chun-Yi" Cc: Borislav Petkov Cc: Tony Luck Cc: Andy Lutomirski Cc: Michael S. Tsirkin Cc: Bhupesh Sharma Cc: Ricardo Neri Cc: Ravi Shankar Tested-by: Bhupesh Sharma Reviewed-by: Matt Fleming Signed-off-by: Ard Biesheuvel --- arch/x86/include/asm/efi.h | 25 +++++++++------------- arch/x86/platform/efi/efi_64.c | 40 +++++++++++++++++++----------------- arch/x86/platform/efi/efi_thunk_64.S | 2 +- 3 files changed, 32 insertions(+), 35 deletions(-) -- 2.15.1 diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h index 00f977ddd718..cda9940bed7a 100644 --- a/arch/x86/include/asm/efi.h +++ b/arch/x86/include/asm/efi.h @@ -62,14 +62,13 @@ extern asmlinkage u64 efi_call(void *fp, ...); #define efi_call_phys(f, args...) efi_call((f), args) /* - * Scratch space used for switching the pagetable in the EFI stub + * struct efi_scratch - Scratch space used while switching to/from efi_mm + * @phys_stack: stack used during EFI Mixed Mode + * @prev_mm: store/restore stolen mm_struct while switching to/from efi_mm */ struct efi_scratch { - u64 r15; - u64 prev_cr3; - pgd_t *efi_pgt; - bool use_pgd; - u64 phys_stack; + u64 phys_stack; + struct mm_struct *prev_mm; } __packed; #define arch_efi_call_virt_setup() \ @@ -78,11 +77,8 @@ struct efi_scratch { preempt_disable(); \ __kernel_fpu_begin(); \ \ - if (efi_scratch.use_pgd) { \ - efi_scratch.prev_cr3 = __read_cr3(); \ - write_cr3((unsigned long)efi_scratch.efi_pgt); \ - __flush_tlb_all(); \ - } \ + if (!efi_enabled(EFI_OLD_MEMMAP)) \ + efi_switch_mm(&efi_mm); \ }) #define arch_efi_call_virt(p, f, args...) \ @@ -90,10 +86,8 @@ struct efi_scratch { #define arch_efi_call_virt_teardown() \ ({ \ - if (efi_scratch.use_pgd) { \ - write_cr3(efi_scratch.prev_cr3); \ - __flush_tlb_all(); \ - } \ + if (!efi_enabled(EFI_OLD_MEMMAP)) \ + efi_switch_mm(efi_scratch.prev_mm); \ \ __kernel_fpu_end(); \ preempt_enable(); \ @@ -135,6 +129,7 @@ extern void __init efi_dump_pagetable(void); extern void __init efi_apply_memmap_quirks(void); extern int __init efi_reuse_config(u64 tables, int nr_tables); extern void efi_delete_dummy_variable(void); +extern void efi_switch_mm(struct mm_struct *mm); struct efi_setup_data { u64 fw_vendor; diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index 8881e601c32d..55c3f623ac49 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c @@ -81,9 +81,8 @@ pgd_t * __init efi_call_phys_prolog(void) int n_pgds, i, j; if (!efi_enabled(EFI_OLD_MEMMAP)) { - save_pgd = (pgd_t *)__read_cr3(); - write_cr3((unsigned long)efi_scratch.efi_pgt); - goto out; + efi_switch_mm(&efi_mm); + return NULL; } early_code_mapping_set_exec(1); @@ -155,8 +154,7 @@ void __init efi_call_phys_epilog(pgd_t *save_pgd) pud_t *pud; if (!efi_enabled(EFI_OLD_MEMMAP)) { - write_cr3((unsigned long)save_pgd); - __flush_tlb_all(); + efi_switch_mm(efi_scratch.prev_mm); return; } @@ -344,13 +342,6 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages) if (efi_enabled(EFI_OLD_MEMMAP)) return 0; - /* - * Since the PGD is encrypted, set the encryption mask so that when - * this value is loaded into cr3 the PGD will be decrypted during - * the pagetable walk. - */ - efi_scratch.efi_pgt = (pgd_t *)__sme_pa(pgd); - /* * It can happen that the physical address of new_memmap lands in memory * which is not mapped in the EFI page table. Therefore we need to go @@ -364,8 +355,6 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages) return 1; } - efi_scratch.use_pgd = true; - /* * Certain firmware versions are way too sentimential and still believe * they are exclusive and unquestionable owners of the first physical page, @@ -624,6 +613,22 @@ void __init efi_dump_pagetable(void) #endif } +/* + * Makes the calling thread switch to/from efi_mm context. Can be used + * for SetVirtualAddressMap() i.e. current->active_mm == init_mm as well + * as during efi runtime calls i.e current->active_mm == current_mm. + * We are not mm_dropping()/mm_grabbing() any mm, because we are not + * losing/creating any references. + */ +void efi_switch_mm(struct mm_struct *mm) +{ + task_lock(current); + efi_scratch.prev_mm = current->active_mm; + current->active_mm = mm; + switch_mm(efi_scratch.prev_mm, mm, NULL); + task_unlock(current); +} + #ifdef CONFIG_EFI_MIXED extern efi_status_t efi64_thunk(u32, ...); @@ -677,16 +682,13 @@ efi_status_t efi_thunk_set_virtual_address_map( efi_sync_low_kernel_mappings(); local_irq_save(flags); - efi_scratch.prev_cr3 = __read_cr3(); - write_cr3((unsigned long)efi_scratch.efi_pgt); - __flush_tlb_all(); + efi_switch_mm(&efi_mm); func = (u32)(unsigned long)phys_set_virtual_address_map; status = efi64_thunk(func, memory_map_size, descriptor_size, descriptor_version, virtual_map); - write_cr3(efi_scratch.prev_cr3); - __flush_tlb_all(); + efi_switch_mm(efi_scratch.prev_mm); local_irq_restore(flags); return status; diff --git a/arch/x86/platform/efi/efi_thunk_64.S b/arch/x86/platform/efi/efi_thunk_64.S index 189b218da87c..46c58b08739c 100644 --- a/arch/x86/platform/efi/efi_thunk_64.S +++ b/arch/x86/platform/efi/efi_thunk_64.S @@ -33,7 +33,7 @@ ENTRY(efi64_thunk) * Switch to 1:1 mapped 32-bit stack pointer. */ movq %rsp, efi_saved_sp(%rip) - movq efi_scratch+25(%rip), %rsp + movq efi_scratch(%rip), %rsp /* * Calculate the physical address of the kernel text. From patchwork Thu Mar 8 08:00:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 130973 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp6175144lja; Thu, 8 Mar 2018 00:02:27 -0800 (PST) X-Google-Smtp-Source: AG47ELtI1PQSgBh6FJ4RHoYIj2EdTJw7d+DhKelqJgbVqpJ86TnicBJ3q8B30mkK6tWb8k8ngs3m X-Received: by 10.98.194.87 with SMTP id l84mr25487383pfg.6.1520496147358; Thu, 08 Mar 2018 00:02:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520496147; cv=none; d=google.com; s=arc-20160816; b=oDgenZNZSZ923LTz+0OLEu+diCw0k85AgtVfKO/6UgI1v3FZStFlh+Lr8v5Fu231l2 rlfmY6csxy9llE2xxuiZDLb/WDfYmwp5TtBtamFvsZxL9tFVZctLTTM3zfRS4PDmh9xI V32PEMFZWOitaJimtxF1rvhcQro1ajWr3pZyNBzcUlPLF+q82PK/4z0GNgCs0TLmvhw6 QAhgW3VFcy54jP8zbi/ZgIMLddTUGB9rgb+gs3iEMMof8NGfGkSg42KKBjGzhXAUGIWu QFurhsR9CsNk0s24Ml4bk2M2Q+9DwFB73P+ypachVu/IIvYugDAGGFH072zcMhWq5w5r 9j9w== 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:arc-authentication-results; bh=4j8lfghSwTxvNEDbImDnVS40a2qU5fMsn6L6OUID690=; b=QGALRJIo42enssU/G5AA0HscOySBbvu54UN65jEKFAvvVR60innFdspH+6CaNEJDaB jAuG18zUdiSU62Kh53PIMcaOZGt6kIni2LPokCuOFTK2QgG+/hJQivZALUqPSCAtrFb+ Ic51kWU4eBd+N+Ddcv95orQ+YC/ojhRqVXV4TsY1NuTf/6Kry6ZaixKvYQ7dqVEgMFl1 4VrDge7FzOGDg8LaDDgTxN5Tubr/oczIVzJFmbLVP4DUUnuKYSxwJ1JexLBFXAa0edSj 5CAFJjdjSoooD+UqTpfi3EMEEdkMprplqVjhEC8LgUfekeajvwOIVrlLH+7wafA2l7kk Sdog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GE3GNpD6; 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 l14si12652173pgc.615.2018.03.08.00.02.27; Thu, 08 Mar 2018 00:02:27 -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=@linaro.org header.s=google header.b=GE3GNpD6; 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 S1755204AbeCHICX (ORCPT + 28 others); Thu, 8 Mar 2018 03:02:23 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:36958 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965528AbeCHICS (ORCPT ); Thu, 8 Mar 2018 03:02:18 -0500 Received: by mail-wm0-f67.google.com with SMTP id 139so9326068wmn.2 for ; Thu, 08 Mar 2018 00:02:18 -0800 (PST) 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=4j8lfghSwTxvNEDbImDnVS40a2qU5fMsn6L6OUID690=; b=GE3GNpD6Tn6CHWR8dpSUsQIyz2UO7POnK7M2qcy2oMVlZ4t4XXdSaAP724rI+DV6U7 i1pZx+THks2+E+YGhhLDcPW4uL/9urbBSsefSVb9xJRWfUibqSxFoEkzKXyR8L0nZdFK e2yz+Lj4yH48W9bmrdrRse8x1j4yX5JsoQoDM= 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=4j8lfghSwTxvNEDbImDnVS40a2qU5fMsn6L6OUID690=; b=nwCbuYgdX88tMIJDNNYusKq4oidxufOGM0GciZujyld/f03j6KJau7z0XM+HkSUsl+ +06AF3vFqfRaw8eTtDTJv1p0mM84dO2bVLaYZot3UnWs74JlLYb3kEZOgyZTLmD2dp+z 18cJ8m6XdNh3ZtPSesRdYH7xA5RK7PimXxz4VhV9Cm+H0TtPboeGsH15/jTx+RoOMItn cKzvpnifcWLuObgZVekwc7EW/3qbobhd7QZ9M+5bDzYnQhzvoeLtm5lAAvKCjPFRjJVI SnG9eu7nSqRBljuah/fbXyk0x6/jdcgZJ/SH3YPZTL1LwMUGQxnfIg5soqH6xNYlyYgq LVsg== X-Gm-Message-State: AElRT7GP4YB12Dqko2UuUp/ihxFt62XStDJM1f0n6b83JG2n7lRSxFFf oNKlvNYDItjcF8H6sUIXiDSDtQ== X-Received: by 10.28.185.83 with SMTP id j80mr17625377wmf.69.1520496137443; Thu, 08 Mar 2018 00:02:17 -0800 (PST) Received: from localhost.localdomain ([160.89.73.46]) by smtp.gmail.com with ESMTPSA id e191sm11223361wmg.12.2018.03.08.00.02.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Mar 2018 00:02:16 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 10/12] efi: reorder pr_notice() with add_device_randomness() call Date: Thu, 8 Mar 2018 08:00:18 +0000 Message-Id: <20180308080020.22828-11-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180308080020.22828-1-ard.biesheuvel@linaro.org> References: <20180308080020.22828-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, when we receive a random seed from the EFI stub, we call add_device_randomness() to incorporate it into the entropy pool, and issue a pr_notice() saying we are about to do that, e.g., [ 0.000000] efi: RNG=0x87ff92cf18 [ 0.000000] random: fast init done [ 0.000000] efi: seeding entropy pool Let's reorder those calls to make the output look less confusing. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.15.1 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index c0dda400d22a..232f4915223b 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -551,9 +551,9 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz, seed = early_memremap(efi.rng_seed, sizeof(*seed) + size); if (seed != NULL) { + pr_notice("seeding entropy pool\n"); add_device_randomness(seed->bits, seed->size); early_memunmap(seed, sizeof(*seed) + size); - pr_notice("seeding entropy pool\n"); } else { pr_err("Could not map UEFI random seed!\n"); }