From patchwork Thu Oct 11 15:16:47 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: 10636911 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 D1E4B17E1 for ; Thu, 11 Oct 2018 15:22:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0E0F2BA47 for ; Thu, 11 Oct 2018 15:22:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3CB42BA42; Thu, 11 Oct 2018 15:22:53 +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 4E10F2BA3B for ; Thu, 11 Oct 2018 15:22:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9CEE66B029D; Thu, 11 Oct 2018 11:22:07 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9601B6B02A0; Thu, 11 Oct 2018 11:22:07 -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 73F446B02A1; Thu, 11 Oct 2018 11:22:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by kanga.kvack.org (Postfix) with ESMTP id 258776B029D for ; Thu, 11 Oct 2018 11:22:07 -0400 (EDT) Received: by mail-pg1-f199.google.com with SMTP id x2-v6so6208296pgr.8 for ; Thu, 11 Oct 2018 08:22:07 -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:from:to:cc :subject:date:message-id:in-reply-to:references; bh=d1q+L6xRd38r++1iYXaTRxHM6bzgrxeKrLjB3l6Upgw=; b=rjonCIlbhIgRvsviQjbRJR9NZC7g9Zx/hUFSX9GFsIHZwCXZFb5KSsVGcCz4WL6Ues 56AqxywQasYdOvyleHmvkPB1dUnFi9DnDItvABEpVnnxEAnzmCANRvmleJGL9KySB517 x+AT+/k4SlDL26sERADZLjy3UrLHzjfhWafV/ScOTR1YXm9NcSnpYzVNdk2Y8ENu3q9H 9T/IZXUpbMs7piBNxd3RAJetQP1jL10Oge7hLjIJVM2FxDlDO8h02mcYerg2t4/Jk93R R2wIOPLaQcDDX3q/9b6/RWF7VRqCO7Q+q0ljRddNlblD5yvD6kCB3Wtb4ImapJlvCLQY unTw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.115 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: ABuFfogjVRkOq8e8jTNGrTXp0+zmIzm6rs7JRIJUeUJXZ58vn5Wjhcuy 4Tf2p/hvfrKcr9P95JR8TNdNXQPuBhkXpLTMuMm+H3n2OSA5Xc6uKu0GMynMTsAlYD6ud8m5RTt sG+u4v8ug9IXOZZFgjDa34eXnGnS+t6GnLtHN/egdbxuqhnoclU1nuCUWbmRGhZOG2w== X-Received: by 2002:a63:d048:: with SMTP id s8-v6mr1788912pgi.311.1539271326830; Thu, 11 Oct 2018 08:22:06 -0700 (PDT) X-Google-Smtp-Source: ACcGV60PHGQKgCXHwCfgMLxVfU1zD8R9b63n3Dge/1GC4E0Af1PbB96jr9GrdxP2B+kJf5XoenAC X-Received: by 2002:a63:d048:: with SMTP id s8-v6mr1788878pgi.311.1539271326143; Thu, 11 Oct 2018 08:22:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539271326; cv=none; d=google.com; s=arc-20160816; b=hq9XjyvMPJmq1h5zv6Aljf/0Slx4iJa7REjZW+Fh1d9yQpWdAJNLoHVkaPeb0eTIKm snC5PIU7KjXHXCW+BzyOtEpj2COM6M2ZtXZbphQCHr7ytlU04uz7pQkmlR4RI9mD1CT2 jCDtWaaQ2TQg0ljc/R6/KHA3+KrVGk+ub0fzx5RmDR1TwcKYcDwnTSdHDbuzjVWEO/b+ d46NaDy31nIlIPGZsCVyMkTy7kwU/pJQ0ZgdiDTPqwfFd9OG5PFNZ6tiK2wz7rJdiAec IK7orbJPmon9aVbAlNPbO5s+W3X18Rn/4TRBTdYaTlaBpzwrPADkAytO9rzzXDuM43F2 wQDA== 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=d1q+L6xRd38r++1iYXaTRxHM6bzgrxeKrLjB3l6Upgw=; b=XZSK1/tsQL8dEhVRvOwIs0RntgsOh6QdUbuEjz4CxJ7/R7NDbPA0ephpY2ZUSuihRs ef3s28/kZN5HPhXC9PMK/3YCPS4TuNSJoacH8XqsEEAf7Ex+nvi+6eStY7RrnlBPFE3X Bv4dpYGp3mMxjJNlmaUYl9XwLZSx58w22VK2Z5cFs/17AKBXodDNsz/3CdmsyH9KL2kO BO6UKTjUsMqszU9kTf282d0KYtp/OLj7WBa4ljHu7J+4cugqq/oTr56OO+15biyYO+ro OgVFvk8mnNBTWeD/hfmnQP1TDXu3jwtYFxhh8vIYWH+JVB+M6zOazywN5mLHrjxzuhFM TZOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=yu-cheng.yu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga14.intel.com (mga14.intel.com. [192.55.52.115]) by mx.google.com with ESMTPS id 33-v6si28541073plh.50.2018.10.11.08.22.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 08:22:06 -0700 (PDT) Received-SPF: pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.115 as permitted sender) client-ip=192.55.52.115; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.115 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 fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Oct 2018 08:22:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,368,1534834800"; d="scan'208";a="77271627" Received: from 2b52.sc.intel.com ([143.183.136.147]) by fmsmga007.fm.intel.com with ESMTP; 11 Oct 2018 08:21:44 -0700 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: [PATCH v5 04/11] mm/mmap: Add IBT bitmap size to address space limit check Date: Thu, 11 Oct 2018 08:16:47 -0700 Message-Id: <20181011151654.27221-5-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181011151654.27221-1-yu-cheng.yu@intel.com> References: <20181011151654.27221-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 | 7 +++++++ mm/mmap.c | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h index 8da7c999b7ee..9c726171e5c5 100644 --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -341,4 +341,11 @@ 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) +{ + return current->thread.cet.ibt_bitmap_size; +} +#endif + #endif /* _ASM_X86_MMU_CONTEXT_H */ diff --git a/mm/mmap.c b/mm/mmap.c index fa581ced3f56..62b3045af005 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3231,13 +3231,30 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, return NULL; } +#ifndef CONFIG_ARCH_HAS_AS_LIMIT +static inline int 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) &&