From patchwork Mon Mar 12 08:44:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 131373 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp477417ljb; Mon, 12 Mar 2018 01:45:44 -0700 (PDT) X-Google-Smtp-Source: AG47ELsF7K7ou4p3Q4Va62FwP4gi/wdMyGELCIwhhKVDGq+bSETSR7r3tYnswLS/9NQxRbEJh8QI X-Received: by 10.99.137.65 with SMTP id v62mr5970824pgd.90.1520844344652; Mon, 12 Mar 2018 01:45:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520844344; cv=none; d=google.com; s=arc-20160816; b=tTyhNyjztR1M67qgHtdjtL3M9eBxfa5xbOt5j3dTrvPcjJZ76JK2JAMlbK8c1frbud oXGCGF+HieYaM4rrTy7z0lEGMxZi7Ql5+KYtbNN2273DoI5tSZO8bbc0/RCIQpdx92fa QIrrgU8oZyPA0DHLa7h+VKg94ma82RjMYKiJN9uVQUCPnFp2X/LuYRCySoWTlVaDBFx7 oQtGGH6XYowkraL9w0DjZdj+j+OVkm0miZaV11tERrWPLd94lA8Z3BTA/gd7nSbrJjmJ VRtOk5qEBKaqhlk40zzYgFzX4Xndd2bjIPwDmf+9KtKyEnMqrdAJXJHoKsbUs7mGkt+A eOMQ== 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=p5jjkCO9QcXGzG+Iy5/VqD/giTUNaJPTbSz5nwGqEfM=; b=hHcRC+I5Hkb7I+3v9J9LlworBalXEG+MH4KwmA46HADK4pdFvSrzjQEgpELVgQbeCg TMNkb281zqLhKDwK8mFoZz7IJC7TOVz2l1BA59aBN0f+38i8ZPJZrAupU01fxIJSJXSr IkirQuez0epnQHg6VXtfvF2v+xbOkKWR7cKTPWEA67gTs2xNVLu1NjoOCElAbLXIHtYo ZRemoipPUqj0d7zvyO+hNmUy2Su+pzni9erX4Rw1CyHJeBnq6BbknRkB7zQPQIRuibiJ h5jE1vq5M4pHgHVZZZ+nehAFXaEQpWFNsnXpG1uC5Jqf0UALin94Of5q6UHvLYSw9epp nSnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OGI5Xabf; 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 h9si1657339pgn.230.2018.03.12.01.45.44; Mon, 12 Mar 2018 01:45:44 -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=OGI5Xabf; 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 S1752539AbeCLIpk (ORCPT + 28 others); Mon, 12 Mar 2018 04:45:40 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:37841 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751849AbeCLIpa (ORCPT ); Mon, 12 Mar 2018 04:45:30 -0400 Received: by mail-wr0-f193.google.com with SMTP id z12so14757248wrg.4 for ; Mon, 12 Mar 2018 01:45:29 -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=p5jjkCO9QcXGzG+Iy5/VqD/giTUNaJPTbSz5nwGqEfM=; b=OGI5XabfXISXvDdlmu46gWqyV18IjR3naKQB+OVt8npzpwjt04aTEDPg+vTKYO1Z0Q MEKJEuK8PMIJoUrQOEmzbpwfb255O0OpK1VDS7+kqaj3R4cq62YkQBaO/GR4qRReIHt+ uS62TJtPZaGzHgUkC+2jg68atChZr8oGiKUK0= 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=p5jjkCO9QcXGzG+Iy5/VqD/giTUNaJPTbSz5nwGqEfM=; b=qHCRlU5kPoAveESOepk6R85MxqAqGiAPgyxh8fKnjDweESZ/agQ+iSeQjR9BVr3nSa cm20kyG7ysBGPO2Y6rb0WHb5hpN61cEPTqccxI5SOy/4z7LGIjLJq+fiM9gv6P2Bmbvu 66ua8Sz2N++UniuBxyGWItEXZ6tAFXcEewCEEPkPoENgM9vb9b0MoquVRp1gOzMQNo3k N7FxPM2LRxO0Jd85JODR9H9UPB51A20/jfECpgtk5zXDtGMiqilj4Fz/I5l4nPNJrdtF DkRv8f9HPbIQue5FrqdHO9ugeZk/FqndDdUWxj+R0SmRAS9zVs0vVeJAsdYVIIxKT3ao V1jw== X-Gm-Message-State: AElRT7HCHBJeHDbxk5gpRs05Fomo7kUq1pvP/dUm/QbBLLU9TOsrxGXd +jZFlT3ad1Ka42mha4BwVUHdIA== X-Received: by 10.223.176.77 with SMTP id g13mr5861889wra.21.1520844329173; Mon, 12 Mar 2018 01:45:29 -0700 (PDT) Received: from localhost.localdomain ([105.148.128.186]) by smtp.gmail.com with ESMTPSA id c1sm6544788wre.27.2018.03.12.01.45.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Mar 2018 01:45:28 -0700 (PDT) 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 1/5] efi: Use efi_mm in x86 as well as ARM Date: Mon, 12 Mar 2018 08:44:56 +0000 Message-Id: <20180312084500.10764-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180312084500.10764-1-ard.biesheuvel@linaro.org> References: <20180312084500.10764-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 [ardb: don't #include the world to get a declaration of struct mm_struct] Signed-off-by: Ard Biesheuvel --- arch/x86/include/asm/efi.h | 1 + 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, 15 insertions(+), 9 deletions(-) -- 2.15.1 diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h index a399c1ebf6f0..c62443fa7d0a 100644 --- a/arch/x86/include/asm/efi.h +++ b/arch/x86/include/asm/efi.h @@ -7,6 +7,7 @@ #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 92b9e79e5da9..232f4915223b 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) {