Received: by 10.223.185.116 with SMTP id b49csp3209988wrg; Mon, 5 Mar 2018 16:36:42 -0800 (PST) X-Google-Smtp-Source: AG47ELvyDUrmRdICnQoSSSVKGUyxURFAiCapcLRmiy58sDHdCbtasU/E9p1YoGAunAcQKvLwGHNn X-Received: by 2002:a17:902:3383:: with SMTP id b3-v6mr15138873plc.224.1520296602627; Mon, 05 Mar 2018 16:36:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520296602; cv=none; d=google.com; s=arc-20160816; b=h+loIvQ00h5iTG7CqA4htdMLeHlVb+VnKZ/WVZEqm/1nDDXoh1UzDBYL07llMK1g9q P3Hh568WxBKnZUOsVsG4Pslcc6YdwmcfFpoWuhVcOXuP082VSoglZjuESSbrhrkdOMfi ir3dsI6oL1EBCdCn3VytHsrphZ2ffWYXxr22FAVOZNEMLQqOplFncsO1FD1sX2rycGC0 8+fHhxL7+mDTdj2DuOtEOzkQFkxxfjDszpmqgsAe4GV8hw9sAtshHH3QeFVgCN6OwdlE EFSDv708AfuQHy6k8FYLg6zxHZCrbV5qVUI6X7HpGbiTMp3xYnOUTXhSrQJVUYoYFRXG p8HQ== 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:to:from:dkim-signature:arc-authentication-results; bh=XAY3/a1hjoDu3QqCa+Dsmj71oh5kp9BSMf+BCRpg918=; b=CIJCSEobNroklx+W53x1Yc63tEaj4CZmrOO719NRrYYXMqM2jdOf45f0DCz7FceGgr BBFJcqZZL0knt+e9+oJgvUo5FDQzMYqDgFX2GA+PtVnNfebW1lDEsC++D3gj3Gqe9DuE DTUOVRH5A/RMqHAMtJqP2mLQpEiENaDSM9qrrcbapOeJ36Z4MUxEnHom6ZJNa4JzXhI7 OLvvJzHcF0nuq0gL3zkGF5nRXzHHm17p1iwMpVw5jFZJQGc5S2pJsC7mCY7eBZL3+RxP OI1P53gURppoQnsCNZaIgD9NvCgy9dcvRwLw+d60SktTduIfwLGqBN933D2mWKaIm4/T HFyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=jj9JAs1R; 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=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l91-v6si10127236plb.345.2018.03.05.16.36.28; Mon, 05 Mar 2018 16:36:42 -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=@oracle.com header.s=corp-2017-10-26 header.b=jj9JAs1R; 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=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933278AbeCFA0g (ORCPT + 99 others); Mon, 5 Mar 2018 19:26:36 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:40704 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933101AbeCFA0a (ORCPT ); Mon, 5 Mar 2018 19:26:30 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w260LdCZ187395; Tue, 6 Mar 2018 00:26:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=XAY3/a1hjoDu3QqCa+Dsmj71oh5kp9BSMf+BCRpg918=; b=jj9JAs1RFl1rkfYEN8NgqI8zbXHh9Jx3ArRvd9pcO1YaiZbCMXje1USeGEOxM0FaJA/k jQeIBBIW+rGKGj6W0tcummUW8l9hbFg6BT0ZYefsHbmWfv4NFpK4+vmpgFkfMkem1MFy 141CCxCC4NEd1DUWpcnb2mFtQEL/++Y9Fxiy7EZ94YPSWmcTlxlLMzGOFLqxabpVquvk Uf8xII56/sPTBGu0p9qq9h6j04Nfq1ZjaEF1m+B5nPPbadRax4crkWmBjNC/VlFVsEEg F8YXMlEPLg4nU/3COxXAG5ZJgDl8MekTDT3XzyP5VPaXpP76XMXq4Lx9FUG0tt1SbvGu eg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2ghdxf8jr2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 06 Mar 2018 00:26:25 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w260QOLw025588 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 6 Mar 2018 00:26:24 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w260QOZs025090; Tue, 6 Mar 2018 00:26:24 GMT Received: from localhost.localdomain (/98.216.35.41) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 05 Mar 2018 16:26:24 -0800 From: Pavel Tatashin To: steven.sistare@oracle.com, daniel.m.jordan@oracle.com, linux-kernel@vger.kernel.org, Alexander.Levin@microsoft.com, dan.j.williams@intel.com, sathyanarayanan.kuppuswamy@intel.com, pankaj.laxminarayan.bharadiya@intel.com, akuster@mvista.com, cminyard@mvista.com, pasha.tatashin@oracle.com, gregkh@linuxfoundation.org, stable@vger.kernel.org Subject: [PATCH 4.1 29/65] kaiser: stack map PAGE_SIZE at THREAD_SIZE-PAGE_SIZE Date: Mon, 5 Mar 2018 19:25:02 -0500 Message-Id: <20180306002538.1761-30-pasha.tatashin@oracle.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180306002538.1761-1-pasha.tatashin@oracle.com> References: <20180306002538.1761-1-pasha.tatashin@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8823 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=995 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1803060003 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hugh Dickins Kaiser only needs to map one page of the stack; and kernel/fork.c did not build on powerpc (no __PAGE_KERNEL). It's all cleaner if linux/kaiser.h provides kaiser_map_thread_stack() and kaiser_unmap_thread_stack() wrappers around asm/kaiser.h's kaiser_add_mapping() and kaiser_remove_mapping(). And use linux/kaiser.h in init/main.c to avoid the #ifdefs there. Signed-off-by: Hugh Dickins Acked-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 003e476716906afa135faf605ae0a5c3598c0293) Signed-off-by: Pavel Tatashin Conflicts: init/main.c --- include/linux/kaiser.h | 40 +++++++++++++++++++++++++++++++++------- init/main.c | 6 +----- kernel/fork.c | 7 ++----- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/include/linux/kaiser.h b/include/linux/kaiser.h index 9db5433c2284..4a4d6d911a14 100644 --- a/include/linux/kaiser.h +++ b/include/linux/kaiser.h @@ -1,26 +1,52 @@ -#ifndef _INCLUDE_KAISER_H -#define _INCLUDE_KAISER_H +#ifndef _LINUX_KAISER_H +#define _LINUX_KAISER_H #ifdef CONFIG_KAISER #include + +static inline int kaiser_map_thread_stack(void *stack) +{ + /* + * Map that page of kernel stack on which we enter from user context. + */ + return kaiser_add_mapping((unsigned long)stack + + THREAD_SIZE - PAGE_SIZE, PAGE_SIZE, __PAGE_KERNEL); +} + +static inline void kaiser_unmap_thread_stack(void *stack) +{ + /* + * Note: may be called even when kaiser_map_thread_stack() failed. + */ + kaiser_remove_mapping((unsigned long)stack + + THREAD_SIZE - PAGE_SIZE, PAGE_SIZE); +} #else /* * These stubs are used whenever CONFIG_KAISER is off, which - * includes architectures that support KAISER, but have it - * disabled. + * includes architectures that support KAISER, but have it disabled. */ static inline void kaiser_init(void) { } -static inline void kaiser_remove_mapping(unsigned long start, unsigned long size) +static inline int kaiser_add_mapping(unsigned long addr, + unsigned long size, unsigned long flags) +{ + return 0; +} +static inline void kaiser_remove_mapping(unsigned long start, + unsigned long size) { } -static inline int kaiser_add_mapping(unsigned long addr, unsigned long size, unsigned long flags) +static inline int kaiser_map_thread_stack(void *stack) { return 0; } +static inline void kaiser_unmap_thread_stack(void *stack) +{ +} #endif /* !CONFIG_KAISER */ -#endif /* _INCLUDE_KAISER_H */ +#endif /* _LINUX_KAISER_H */ diff --git a/init/main.c b/init/main.c index de1951eaf1cc..c8d3596a721f 100644 --- a/init/main.c +++ b/init/main.c @@ -81,15 +81,13 @@ #include #include #include +#include #include #include #include #include #include -#ifdef CONFIG_KAISER -#include -#endif static int kernel_init(void *); @@ -490,9 +488,7 @@ static void __init mm_init(void) pgtable_init(); vmalloc_init(); ioremap_huge_init(); -#ifdef CONFIG_KAISER kaiser_init(); -#endif } asmlinkage __visible void __init start_kernel(void) diff --git a/kernel/fork.c b/kernel/fork.c index eb1ca74c48ce..823bcff9b047 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -168,12 +168,9 @@ static struct thread_info *alloc_thread_info_node(struct task_struct *tsk, return page ? page_address(page) : NULL; } -extern void kaiser_remove_mapping(unsigned long start_addr, unsigned long size); static inline void free_thread_info(struct thread_info *ti) { -#ifdef CONFIG_KAISER - kaiser_remove_mapping((unsigned long)ti, THREAD_SIZE); -#endif + kaiser_unmap_thread_stack(ti); free_kmem_pages((unsigned long)ti, THREAD_SIZE_ORDER); } # else @@ -351,7 +348,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig) tsk->stack = ti; - err= kaiser_add_mapping((unsigned long)tsk->stack, THREAD_SIZE, __PAGE_KERNEL); + err = kaiser_map_thread_stack(tsk->stack); if (err) goto free_ti; #ifdef CONFIG_SECCOMP -- 2.16.2