From patchwork Sat Jul 14 09:31:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Srivatsa S. Bhat" X-Patchwork-Id: 10524653 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CC55B60388 for ; Sat, 14 Jul 2018 09:32:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B65D127BA5 for ; Sat, 14 Jul 2018 09:32:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6CE629123; Sat, 14 Jul 2018 09:32:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BF7727BA5 for ; Sat, 14 Jul 2018 09:32:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17BD96B000A; Sat, 14 Jul 2018 05:32:05 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 129796B000C; Sat, 14 Jul 2018 05:32:05 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F32FF6B000D; Sat, 14 Jul 2018 05:32:04 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk0-f199.google.com (mail-qk0-f199.google.com [209.85.220.199]) by kanga.kvack.org (Postfix) with ESMTP id C5E496B000A for ; Sat, 14 Jul 2018 05:32:04 -0400 (EDT) Received: by mail-qk0-f199.google.com with SMTP id u68-v6so25052815qku.5 for ; Sat, 14 Jul 2018 02:32:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:subject:from :to:cc:date:message-id:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=LGwM6XnM9jxKCLYR1NnsI3KDDYwT+x6hebUTdeExgAY=; b=PNpTRO9+7gRCdeJ7ouHOL3Vuqkv+9hFP/39uRzcsWKI/zF2PYW1Rv//Qlb560/rs+J OiwomYtPu/O0IksquiZelc/JuOcW/5ltCgj7unwTBTQUFRW15V9vi9zLlth4vJtk0mvI T06WEL+w1IruVbCPAljAh2s6WibsxLPo9Uo9EzAmpoUBvj3Cau4U2Z5Zm1DAQRJaYJjv dJDAfbEwOAyr7jvCr/bM5OSar3EC/0j7wyh3K8g+49pxwHBWdJGwmdlWLjQokrWIvL9z DGEDHxGdPpha2c4ubxLhUn6qhyYp/92EZ23hpl9le1y20GORNm1IjiNkFpyBpEuJj11R O1ww== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of srivatsa@csail.mit.edu designates 128.30.2.210 as permitted sender) smtp.mailfrom=srivatsa@csail.mit.edu; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=csail.mit.edu X-Gm-Message-State: AOUpUlGzhA8vkPepL55l3lsUZEyJJyTPwKBNIrRTTnh2bG13AljqxX8V QFAokoUVKxFbABy+ca6uGBnPJCdGZKF8ilFQSCjqzbn5fYmBIyDdqHcqfjcKt2qJoDizBHN8iK5 mQcjAM5/p/KNlaLtxJ+UeaRPzA/IHwGXB25P1K/z/zxSd0QXUOfHT1GWbvSX6yBgQOA== X-Received: by 2002:a37:188c:: with SMTP id 12-v6mr8248066qky.72.1531560724563; Sat, 14 Jul 2018 02:32:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe/ZhPRNVNPcFDrIInCa3RzARnTXgBgoY/oaNMWx0AuUQGVgo8LfUhr9igRqnsKnRHXkIuc X-Received: by 2002:a37:188c:: with SMTP id 12-v6mr8248034qky.72.1531560723531; Sat, 14 Jul 2018 02:32:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531560723; cv=none; d=google.com; s=arc-20160816; b=r6877jiEc9vwLCEuqx1g+ngY7LI9yZDtww0Jx04j08f3f47f+D4MEoUYpqPRtZXR6P Lpza3bnZe8/jITIYHUCyTuiAukG7T+CG2EM9oIWSQUr650CEXDoc8trSJBPyDOzdCAYY oZf4zH7H7LAijpnDZ/DJGp5YYeXiHANb0YQJxra2d3whK/sItF0XcS17YxvaJe3OBvcS eX04BQ8xIPwc5qlpfh1Y/vTrd7Pkfi8YBbeEeiE3l6OqhDiJbkPv38qXyIYGmFnIwy8T xHfRYQ7mUSez1HBiy6T+DX7b8clw4XzOPEBkL2gqhhNOLNoeozisRDe+ODQZNpkVTYwY x6wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject :arc-authentication-results; bh=LGwM6XnM9jxKCLYR1NnsI3KDDYwT+x6hebUTdeExgAY=; b=spW5AR5RYbTNZJH7Y0+Ri8b15sXZRHLn3cklW3An3bDKnv7d/q161+mXFK8xFazV2p FRgcXazufLdEEHRS1408agHTwfx9jj+be375EBW5D4XQszncYs7uIaDKYx37zETqrsqC g6FybcgPzndRmyO7uW5RY7UXQpF9b+MEZEgylu1/l1E4hynrjdptYirNapotjMDswSHM uAu61Pd99pkRRSBrDDcR9FQOMTlMd0vWQShf6HwZV6mTdljx0cWK0oQMXShiDktr/BY5 euf8lKNRjZVNpR4h1pTTWSLxtpuKDc7kIf9/wabMXS0RZgZ7uWKPCYyKsanV+K9WdJDG oN2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of srivatsa@csail.mit.edu designates 128.30.2.210 as permitted sender) smtp.mailfrom=srivatsa@csail.mit.edu; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=csail.mit.edu Received: from outgoing-stata.csail.mit.edu (outgoing-stata.csail.mit.edu. [128.30.2.210]) by mx.google.com with ESMTP id j2-v6si4663489qtp.300.2018.07.14.02.32.03 for ; Sat, 14 Jul 2018 02:32:03 -0700 (PDT) Received-SPF: pass (google.com: domain of srivatsa@csail.mit.edu designates 128.30.2.210 as permitted sender) client-ip=128.30.2.210; Authentication-Results: mx.google.com; spf=pass (google.com: domain of srivatsa@csail.mit.edu designates 128.30.2.210 as permitted sender) smtp.mailfrom=srivatsa@csail.mit.edu; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=csail.mit.edu Received: from c-71-231-194-96.hsd1.wa.comcast.net ([71.231.194.96] helo=[127.0.1.1]) by outgoing-stata.csail.mit.edu with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1feGuH-000ZYX-HF; Sat, 14 Jul 2018 05:32:01 -0400 Subject: [PATCH 4.4.y 041/101] x86/mm: Factor out LDT init from context init From: "Srivatsa S. Bhat" To: gregkh@linuxfoundation.org, stable@vger.kernel.org Cc: Dave Hansen , Thomas Gleixner , Andrew Morton , Andy Lutomirski , Borislav Petkov , Brian Gerst , Dave Hansen , Denys Vlasenko , "H. Peter Anvin" , Linus Torvalds , Peter Zijlstra , Rik van Riel , linux-mm@kvack.org, Ingo Molnar , "Matt Helsley \(VMware\)" , Alexey Makhalov , Bo Gan , matt.helsley@gmail.com, rostedt@goodmis.org, amakhalov@vmware.com, ganb@vmware.com, srivatsa@csail.mit.edu, srivatsab@vmware.com Date: Sat, 14 Jul 2018 02:31:57 -0700 Message-ID: <153156071778.10043.13239124304280929230.stgit@srivatsa-ubuntu> In-Reply-To: <153156030832.10043.13438231886571087086.stgit@srivatsa-ubuntu> References: <153156030832.10043.13438231886571087086.stgit@srivatsa-ubuntu> User-Agent: StGit/0.18 MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Dave Hansen commit 39a0526fb3f7d93433d146304278477eb463f8af upstream The arch-specific mm_context_t is a great place to put protection-key allocation state. But, we need to initialize the allocation state because pkey 0 is always "allocated". All of the runtime initialization of mm_context_t is done in *_ldt() manipulation functions. This renames the existing LDT functions like this: init_new_context() -> init_new_context_ldt() destroy_context() -> destroy_context_ldt() and makes init_new_context() and destroy_context() available for generic use. Signed-off-by: Dave Hansen Reviewed-by: Thomas Gleixner Cc: Andrew Morton Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Dave Hansen Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Rik van Riel Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/20160212210234.DB34FCC5@viggo.jf.intel.com Signed-off-by: Ingo Molnar Signed-off-by: Srivatsa S. Bhat Reviewed-by: Matt Helsley (VMware) Reviewed-by: Alexey Makhalov Reviewed-by: Bo Gan --- arch/x86/include/asm/mmu_context.h | 21 ++++++++++++++++----- arch/x86/kernel/ldt.c | 4 ++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h index 9bfc5fd..1c4794f 100644 --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -52,15 +52,15 @@ struct ldt_struct { /* * Used for LDT copy/destruction. */ -int init_new_context(struct task_struct *tsk, struct mm_struct *mm); -void destroy_context(struct mm_struct *mm); +int init_new_context_ldt(struct task_struct *tsk, struct mm_struct *mm); +void destroy_context_ldt(struct mm_struct *mm); #else /* CONFIG_MODIFY_LDT_SYSCALL */ -static inline int init_new_context(struct task_struct *tsk, - struct mm_struct *mm) +static inline int init_new_context_ldt(struct task_struct *tsk, + struct mm_struct *mm) { return 0; } -static inline void destroy_context(struct mm_struct *mm) {} +static inline void destroy_context_ldt(struct mm_struct *mm) {} #endif static inline void load_mm_ldt(struct mm_struct *mm) @@ -102,6 +102,17 @@ static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk) this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY); } +static inline int init_new_context(struct task_struct *tsk, + struct mm_struct *mm) +{ + init_new_context_ldt(tsk, mm); + return 0; +} +static inline void destroy_context(struct mm_struct *mm) +{ + destroy_context_ldt(mm); +} + extern void switch_mm(struct mm_struct *prev, struct mm_struct *next, struct task_struct *tsk); diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c index bc42936..8bc68cf 100644 --- a/arch/x86/kernel/ldt.c +++ b/arch/x86/kernel/ldt.c @@ -119,7 +119,7 @@ static void free_ldt_struct(struct ldt_struct *ldt) * we do not have to muck with descriptors here, that is * done in switch_mm() as needed. */ -int init_new_context(struct task_struct *tsk, struct mm_struct *mm) +int init_new_context_ldt(struct task_struct *tsk, struct mm_struct *mm) { struct ldt_struct *new_ldt; struct mm_struct *old_mm; @@ -160,7 +160,7 @@ out_unlock: * * 64bit: Don't touch the LDT register - we're already in the next thread. */ -void destroy_context(struct mm_struct *mm) +void destroy_context_ldt(struct mm_struct *mm) { free_ldt_struct(mm->context.ldt); mm->context.ldt = NULL;