Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3308020imu; Mon, 19 Nov 2018 13:57:21 -0800 (PST) X-Google-Smtp-Source: AJdET5f0EW0YztWKekvzPE0B6Ae6Rg+ub0BZnFmiePG5ZVlZQRzwauo/D+gTXXjfTrVxkZKUyWgu X-Received: by 2002:a63:c303:: with SMTP id c3mr21795105pgd.268.1542664641580; Mon, 19 Nov 2018 13:57:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542664641; cv=none; d=google.com; s=arc-20160816; b=WkWY1wknUo8O/1U63jst9qQghCLUs0VoJVFD9PfQCWL1FnqDeS7l1swp2ukN+ksrtf AekFRgnIso8U+jLzCT63m8wumDzv63ujXREOjzMagNYu6lH8ICdTERx14NWK07nd7Omw YKT5Rsbbh6vVZ6vVUAJmLgxMhJjGE8zXYgG7S8xOeck2f8QXUqESBMtz1aYPJcNkgz8v 7YuOHmzzdj3ssXTOp7rDVatlMMBaToVr6ZORTpWXAaUXqFbfx0nU177dNQM0E5ES+Fag uEK+WtH9a/8Y2qeTl2vRgTpmwBXrY+eiejVu0rq8d+bP7lEwa3eBNqPvHVFcO4t821dA xt9g== 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; bh=UDsB1X8qrhTibz/44k1UitNwkiMYishcV/n5jBRYRiI=; b=lF5XNxDjCCC44pYIngkNRb0Dp5X7+ASUDMrFr6GktvDiRiHZdnibgLWL4mcuIpi4aT u7QggFVYffsgI5Ew8NBfq23l76/sOhrI4cvJXdPvEShGPvEhog+KGZNhnaOYP1ULKDfZ uhBMio1QEIRLYF+l9sf1cT9UvvHFqJh7PJ7h0QjUjTpxIF4H40ojl6B+ndKYOw/O1QiR uo6ChnBT2GEqWNh0it3uqyA3HhqGUllKm1UAavyDz5/OXGwV2+Tl9iSAXZaPd//Ybhq7 pAghd6oH/R9kbo4Wq179Se7R63nonYLst2gTjfic6c/5ykMoIXQjOlJAd1AIaa1LVytP io9Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n3si2892034pfn.285.2018.11.19.13.57.06; Mon, 19 Nov 2018 13:57:21 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731751AbeKTIUi (ORCPT + 99 others); Tue, 20 Nov 2018 03:20:38 -0500 Received: from mga09.intel.com ([134.134.136.24]:32114 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731707AbeKTIUi (ORCPT ); Tue, 20 Nov 2018 03:20:38 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) && -- 2.17.1