From patchwork Tue Jul 10 22:26:35 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: 10518189 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 2BC846032A for ; Tue, 10 Jul 2018 22:32:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E8391FF7E for ; Tue, 10 Jul 2018 22:32:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 127EC212D6; Tue, 10 Jul 2018 22:32:14 +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=unavailable 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 AEBBB1FF7E for ; Tue, 10 Jul 2018 22:32:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 57A8A6B0272; Tue, 10 Jul 2018 18:31:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 42A8F6B0277; Tue, 10 Jul 2018 18:31:20 -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 0FA166B0274; Tue, 10 Jul 2018 18:31:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f71.google.com (mail-pl0-f71.google.com [209.85.160.71]) by kanga.kvack.org (Postfix) with ESMTP id B1EBC6B0270 for ; Tue, 10 Jul 2018 18:31:19 -0400 (EDT) Received: by mail-pl0-f71.google.com with SMTP id 31-v6so13407715plf.19 for ; Tue, 10 Jul 2018 15:31:19 -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=wMOelUBk/4VNj8u8kphigUP3R/YB9e4JY4ubq6J1Fbg=; b=G4mY45X+xm40H4ErukCI+ivOQpB3szq+KbP8HkZfulf795AgCUo+oFdZbSCdOYGoGY +2pf5HyQUvlgJRiAosd45Xma1bSd6WhJOGUF+XDk+NdycbAB5cm+OKh7ePYcpISozcJX KR5bt/EGPRU+9gVM2VkQRzRod/1zUwSIQIH5EJcS5pyN6D2mz3LLJs5uAJRI22kq/nYg izSSGCLmdevZaTMbMRJ5jMFD+t3lkMgTTlXE3C4sA4XF1fRcrx5k8tJgUagBGc9IGWKm 6EfNDyz3zrd4WZCXSxYsfohslEbrsz7ylWEV18bBwSBIty34j1HkkfgNrLrYwP+Pg577 KJJw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.136 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: APt69E0sZ/vulS9QlK2w5AqVGMHmwadqW4kmfHT6OkJJhhRIeWsOKxGw ngwa3p5Q3/y4XAXeiM0xUpPJUNcMAlxHL7+fsHGsZcY9txdWPHXk6FptkWVhqSBqR+h4079lBlc HO/PlrRpHQwCS0/xeBbyxiU718GevVd9qe1CnTDmIUpUxLUC9Hcq796ayZiEccwe/VQ== X-Received: by 2002:a17:902:b586:: with SMTP id a6-v6mr26213016pls.174.1531261879421; Tue, 10 Jul 2018 15:31:19 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc8W9d5muDxm4atCtaJx3//XE0NcTBRRd3pRK+iAAOohWrAZ6hVzHk35D7K35ugF1FmkV+J X-Received: by 2002:a17:902:b586:: with SMTP id a6-v6mr26212984pls.174.1531261878706; Tue, 10 Jul 2018 15:31:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531261878; cv=none; d=google.com; s=arc-20160816; b=hXhjNbalB/PxABJgJwbJaimXToDYSy5grx+kmewvOGAHhlYzoryHAV5ww7/0gVk047 +FDSZf9/vnzFv3O3ZtSDc/3/wum893/wAm8ITUGT6Hn2unhQ0aKKHElmO8j+MyyntvSe jIIIOF99LmmyA2vPuWLcEF13DXPBUpFxfjL/qxchzIVCr3Z1AmicZiEkBm/TyFfEMJFp Wd1OoQW2bCbdQiOjcRKXqVHyafrPIbRZxsf48636DG0KTVR82oCriSaFRFELJqBHQpfY qdMPyNKgrsEuL7FuBdOytri3H9/x3qMAOqwUxWKKGyQS3TVYYMZcvivi+hJDwdszADJz mSNQ== 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 :arc-authentication-results; bh=wMOelUBk/4VNj8u8kphigUP3R/YB9e4JY4ubq6J1Fbg=; b=uL429o4OOelMe8uYO4ZZ9s+MsUlRwbYVM6CbGuIr5P+LPPFBHaxbtyRJnPBFATEf8D 5Elimz5Jhs+OWli64dOyO+nwzhqoetwE/v2UZ4F5M6oo53wAfcAEg6kKw+HUVigbTKf7 7c4kIR5YDMgk9URC2CQDxzIsTiSAKBDiOYGx2CIMmxB9gXHQx4hXJ03IoMQBDk6VByNO gBPfHP4DWGvcdwKyGC/pm3ooASVpwPOx8FfFNr8iykVKIVhnhovzRwWcCwG4oy9Oq8Wi Rt2fuhSUHaYc7FoUYtXf93mAs9gcOT9EjtB/DSLnzC6pOpvrCaUnufeAuKboa1TkxA7I cSEA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=yu-cheng.yu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga12.intel.com (mga12.intel.com. [192.55.52.136]) by mx.google.com with ESMTPS id h1-v6si16605731pgs.221.2018.07.10.15.31.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Jul 2018 15:31:18 -0700 (PDT) Received-SPF: pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.136 as permitted sender) client-ip=192.55.52.136; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.136 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 fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jul 2018 15:31:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,335,1526367600"; d="scan'208";a="70305451" Received: from 2b52.sc.intel.com ([143.183.136.52]) by fmsmga004.fm.intel.com with ESMTP; 10 Jul 2018 15:31:16 -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 , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , "Ravi V. Shankar" , Vedvyas Shanbhogue Cc: Yu-cheng Yu Subject: [RFC PATCH v2 23/27] mm/mmap: Add IBT bitmap size to address space limit check Date: Tue, 10 Jul 2018 15:26:35 -0700 Message-Id: <20180710222639.8241-24-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180710222639.8241-1-yu-cheng.yu@intel.com> References: <20180710222639.8241-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/uapi/asm/resource.h | 5 +++++ include/uapi/asm-generic/resource.h | 3 +++ mm/mmap.c | 12 +++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/uapi/asm/resource.h b/arch/x86/include/uapi/asm/resource.h index 04bc4db8921b..0741b2a6101a 100644 --- a/arch/x86/include/uapi/asm/resource.h +++ b/arch/x86/include/uapi/asm/resource.h @@ -1 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +#ifdef CONFIG_X86_INTEL_CET +#define rlimit_as_extra() current->thread.cet.ibt_bitmap_size +#endif + #include diff --git a/include/uapi/asm-generic/resource.h b/include/uapi/asm-generic/resource.h index f12db7a0da64..8a7608a09700 100644 --- a/include/uapi/asm-generic/resource.h +++ b/include/uapi/asm-generic/resource.h @@ -58,5 +58,8 @@ # define RLIM_INFINITY (~0UL) #endif +#ifndef rlimit_as_extra +#define rlimit_as_extra() 0 +#endif #endif /* _UAPI_ASM_GENERIC_RESOURCE_H */ diff --git a/mm/mmap.c b/mm/mmap.c index d1eb87ef4b1a..fad41b291ae1 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3242,7 +3242,17 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, */ 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 + rlimit_as_extra(); + + /* 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) &&