From patchwork Fri Nov 4 22:35:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rick Edgecombe X-Patchwork-Id: 13032657 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA388C43217 for ; Fri, 4 Nov 2022 22:39:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A4698E000D; Fri, 4 Nov 2022 18:39:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 12F188E0007; Fri, 4 Nov 2022 18:39:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF3558E000E; Fri, 4 Nov 2022 18:39:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id AE4138E000D for ; Fri, 4 Nov 2022 18:39:41 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7D811C14E1 for ; Fri, 4 Nov 2022 22:39:41 +0000 (UTC) X-FDA: 80097228162.16.E9FB762 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf14.hostedemail.com (Postfix) with ESMTP id F3AC6100009 for ; Fri, 4 Nov 2022 22:39:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667601581; x=1699137581; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=QCRYLxuft9By+ea93NBBljihOI4kEYqg35nP/V5qBtI=; b=ilFen3K6cuDOkiDrrFKHCDFyVzOlmgdrroPAxxM89KFD7YZefHAuAcTW Db7SCJNsgxqQ2CnJmmss9Fg5EgdAwUJMLU2I9HdKnZolFg/z6mtbCUS+x uYd3z/VgbrvM25cGEl8TXyXnCGUuv0gWKJP5DumipyFr72KnnaFDgexcg foyJQ9ANX5xi2NdJa/9BnqjLXGLJRw2VOZMVc0GLsLM9nysqrPSqhmYOD vFUmsEumlh3c+MKchbUttluGpWaBMdkXqEELQIyStD6ueDMn+J/5/8Yde mllJ/RARnTG87DmqOgmr3XqT7FYFAM7/NeE+Zg1GQ9cvo1YEhqpLl2RN3 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10521"; a="297559660" X-IronPort-AV: E=Sophos;i="5.96,138,1665471600"; d="scan'208";a="297559660" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2022 15:39:39 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10521"; a="668514085" X-IronPort-AV: E=Sophos;i="5.96,138,1665471600"; d="scan'208";a="668514085" Received: from adhjerms-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.212.227.68]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2022 15:39:38 -0700 From: Rick Edgecombe 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 , Borislav Petkov , 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" , Weijiang Yang , "Kirill A . Shutemov" , John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu Subject: [PATCH v3 19/37] mm/mmap: Add shadow stack pages to memory accounting Date: Fri, 4 Nov 2022 15:35:46 -0700 Message-Id: <20221104223604.29615-20-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221104223604.29615-1-rick.p.edgecombe@intel.com> References: <20221104223604.29615-1-rick.p.edgecombe@intel.com> ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=ilFen3K6; spf=pass (imf14.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667601581; a=rsa-sha256; cv=none; b=QBkww8MGkREheba008fHa6WFMRSG12lZhtD8N4CWKQs1BF56sXK+k3y2OTqeZJ/fdm4OU6 X7NAs1aO3R8YQYurQF06hX9548EfshUfZXtNiAgYgmY0M+QRRf7v97yDZ/kVMDaCxbmoHB 1yrhoD2bKNLNcT0oVaLXUBmfn2Pzjoo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667601581; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=OS38q1UI76P3zo2mEE1/FuGGSmIk3DJz+B+bAUpkUYk=; b=lLlb5I3u5R483eOp4MTyuBx4RQx5u1PGW2d3W3JPH5LCQe9hVnnaGqtS4sCLaekd77ters 0bMy484L8gniYf7ZOij+XBD7wBDYQfxUKqJFNqU4fMa8EwGN3056ylRgrZjw5zxTSAqO61 ImudXq5uN2Iwb80K+vMpRwx1HugcrWg= X-Stat-Signature: q4wtp664kxe6opwkqhkicf8h9xh7g4fn X-Rspamd-Queue-Id: F3AC6100009 Authentication-Results: imf14.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=ilFen3K6; spf=pass (imf14.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1667601580-228632 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: From: Yu-cheng Yu The x86 Control-flow Enforcement Technology (CET) feature includes a new type of memory called shadow stack. This shadow stack memory has some unusual properties, which requires some core mm changes to function properly. Account shadow stack pages to stack memory. Tested-by: Pengfei Xu Tested-by: John Allen Signed-off-by: Yu-cheng Yu Co-developed-by: Rick Edgecombe Signed-off-by: Rick Edgecombe Cc: Kees Cook --- v3: - Remove unneeded VM_SHADOW_STACK check in accountable_mapping() (Kirill) v2: - Remove is_shadow_stack_mapping() and just change it to directly bitwise and VM_SHADOW_STACK. Yu-cheng v26: - Remove redundant #ifdef CONFIG_MMU. Yu-cheng v25: - Remove #ifdef CONFIG_ARCH_HAS_SHADOW_STACK for is_shadow_stack_mapping(). mm/mmap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index f67606fbc464..4dc157869b34 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3298,6 +3298,8 @@ void vm_stat_account(struct mm_struct *mm, vm_flags_t flags, long npages) mm->exec_vm += npages; else if (is_stack_mapping(flags)) mm->stack_vm += npages; + else if (flags & VM_SHADOW_STACK) + mm->stack_vm += npages; else if (is_data_mapping(flags)) mm->data_vm += npages; }