From patchwork Mon Nov 19 21:49:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-cheng Yu X-Patchwork-Id: 10689575 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1FADA1923 for ; Mon, 19 Nov 2018 21:55:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12D7B2A583 for ; Mon, 19 Nov 2018 21:55:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 05F2A2A6EE; Mon, 19 Nov 2018 21:55:45 +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 975C92A583 for ; Mon, 19 Nov 2018 21:55:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B0FF76B1CB2; Mon, 19 Nov 2018 16:54:59 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9FEB36B1CB4; Mon, 19 Nov 2018 16:54:59 -0500 (EST) 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 803EE6B1CB5; Mon, 19 Nov 2018 16:54:59 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id 3BDE06B1CB2 for ; Mon, 19 Nov 2018 16:54:59 -0500 (EST) Received: by mail-pf1-f199.google.com with SMTP id s14so4876845pfk.16 for ; Mon, 19 Nov 2018 13:54:59 -0800 (PST) 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:from:to:cc :subject:date:message-id:in-reply-to:references; bh=UDsB1X8qrhTibz/44k1UitNwkiMYishcV/n5jBRYRiI=; b=fWZ9m/dzUjcUXcOxos0vO1GkWZxlb7pP9aq5hq++LOjNsbKbhisvx7DF1rytfFuAK7 B8SgkeMWAoV2nJ/vCdTuhTom11w8x3Qe4g0PbgHXD5z2szBUBmFOFbIrxWktAiStGnhi YObVgudl0SswFZtuMVDYQQ0IdbMpuAHYUweQxfSQeGmsSyrKKTKLV6NzzYFbhapknhNb xlTMTTQBhBBJVPNYqQ8/gXqzkG9powHWylpSRosVKFhhpR7d1yH6Isy5XYAHZlQE/x9G eKxEsOV/KDp2k85jyiwPQwaVVlcKmSWYdYLvAPffUUUOBu7QPS/98TyxhHBMJemLIyy+ 4ipw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=yu-cheng.yu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AGRZ1gIzJUMj+7TSYGrfMR6Le9dwPi12rGPKprHXnSuWVEnXH+ANLEZ8 6gwco6YCefY/ISHf4iVTwtspaY8Lo+HvLtnDI8Lu/q4tCyroEOAJZn6wImjyy09hLndtrwaVh0V g5jxnDKiOASMjM21LkZkcmFoA82iiCp1cBgnFZMBSBsT4qx5oo318Xb6MsTvfJjBWZA== X-Received: by 2002:a62:178c:: with SMTP id 134-v6mr25302455pfx.29.1542664498943; Mon, 19 Nov 2018 13:54:58 -0800 (PST) X-Google-Smtp-Source: AJdET5cQAsO+8bVSLFv1pEGeTeukbt5l1gLDoQI//GJ+LoIg39fVrmRtW/3HFacAf9LhrjG8QMlO X-Received: by 2002:a62:178c:: with SMTP id 134-v6mr25302432pfx.29.1542664498322; Mon, 19 Nov 2018 13:54:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542664498; cv=none; d=google.com; s=arc-20160816; b=ng26eojhZNDt8D4XqHSIldSCS0rmZXD/2ZEddu1jSlwDIOfYHNOUgtynxVVOIWBLKX 5ur1RCyFk8jEXTfjMxuKh2GDvE1euPUGI3OZ3S/BlzBhqjNCabb4L1YRdwWch870EDJp F8DmxcR16ngKYOaMBCGYho1aRHvccRBgEPYlVbrbXmqsfRslBl18xLuwi0rKvpnJE/YL ubKg7CyXp1/Rw+ehplD+JiLb6eaiR5fy8EtfsdceD90A2KtkaospGTRPBEtmTYn/m+i8 Ar4Bc3xdM99gG2MyROxES2tvtu+W2x4ndCxdZV0bLnI1JZGwQxGj2J6+vyZBkban3ka5 QvCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=UDsB1X8qrhTibz/44k1UitNwkiMYishcV/n5jBRYRiI=; b=NzTwMw013GcKdhZvvSMc+gxMT/DwErBZTvxaY/oMi4mmE0C1y6vOJfJizPL6k9td5S F7iFVglgDtGQBc20NW360O7jP86Hv5VIGGaiGJh8bT45y/Q22f2J0ooPgGdNn93x0fXS IjIj9PAT8hL2L0eGBkXc6ykiVqVDdxkEjMM9uYx5x9LP/fHmrslvU/9dLIysbefxb068 TKXXxs0H7ozdiIZkH3oaDpo17WebHYCdGSNxWnNC9sVpHVqAtf4CHTu19fUv0lfBaHre xUCK7mY5L4Es3hWBTIKRYpDmpmi631V7CKtJQfWK7tWJiEIopIfP4N5iUs/e54PHSMVN tpLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=yu-cheng.yu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga11.intel.com (mga11.intel.com. [192.55.52.93]) by mx.google.com with ESMTPS id s8si4586261plq.345.2018.11.19.13.54.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Nov 2018 13:54:58 -0800 (PST) Received-SPF: pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.93 as permitted sender) client-ip=192.55.52.93; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=yu-cheng.yu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Nov 2018 13:54:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,254,1539673200"; d="scan'208";a="92423896" Received: from yyu32-desk1.sc.intel.com ([143.183.136.147]) by orsmga006.jf.intel.com with ESMTP; 19 Nov 2018 13:54:56 -0800 From: Yu-cheng Yu To: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue Cc: Yu-cheng Yu Subject: [RFC PATCH v6 04/11] mm/mmap: Add IBT bitmap size to address space limit check Date: Mon, 19 Nov 2018 13:49:27 -0800 Message-Id: <20181119214934.6174-5-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181119214934.6174-1-yu-cheng.yu@intel.com> References: <20181119214934.6174-1-yu-cheng.yu@intel.com> 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 The indirect branch tracking legacy bitmap takes a large address space. This causes may_expand_vm() failure on the address limit check. For a IBT-enabled task, add the bitmap size to the address limit. Signed-off-by: Yu-cheng Yu --- arch/x86/include/asm/mmu_context.h | 10 ++++++++++ mm/mmap.c | 19 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h index 57c1f6c42bef..97a101267dd5 100644 --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -341,4 +341,14 @@ static inline unsigned long __get_current_cr3_fast(void) return cr3; } +#ifdef CONFIG_X86_INTEL_BRANCH_TRACKING_USER +static inline unsigned long arch_as_limit(void) +{ + if (current->thread.cet.ibt_enabled) + return current->thread.cet.ibt_bitmap_size; + else + return 0; +} +#endif + #endif /* _ASM_X86_MMU_CONTEXT_H */ diff --git a/mm/mmap.c b/mm/mmap.c index 9560d69fa08c..3de023f3e565 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3283,13 +3283,30 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, return NULL; } +#ifndef CONFIG_ARCH_HAS_AS_LIMIT +static inline unsigned long arch_as_limit(void) +{ + return 0; +} +#endif + /* * Return true if the calling process may expand its vm space by the passed * number of pages */ bool may_expand_vm(struct mm_struct *mm, vm_flags_t flags, unsigned long npages) { - if (mm->total_vm + npages > rlimit(RLIMIT_AS) >> PAGE_SHIFT) + unsigned long as_limit = rlimit(RLIMIT_AS); + unsigned long as_limit_plus = as_limit + arch_as_limit(); + + /* as_limit_plus overflowed */ + if (as_limit_plus < as_limit) + as_limit_plus = RLIM_INFINITY; + + if (as_limit_plus > as_limit) + as_limit = as_limit_plus; + + if (mm->total_vm + npages > as_limit >> PAGE_SHIFT) return false; if (is_data_mapping(flags) &&