From patchwork Thu Jan 19 21:22:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 13108799 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 7F124C004D4 for ; Thu, 19 Jan 2023 21:24:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF0E9900006; Thu, 19 Jan 2023 16:24:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CA0FD900002; Thu, 19 Jan 2023 16:24:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA95E900006; Thu, 19 Jan 2023 16:24:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 881AE900002 for ; Thu, 19 Jan 2023 16:24:01 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 677BF1209E3 for ; Thu, 19 Jan 2023 21:24:01 +0000 (UTC) X-FDA: 80372826282.19.0411C0A Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf27.hostedemail.com (Postfix) with ESMTP id 6277F40003 for ; Thu, 19 Jan 2023 21:23:59 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=U5AkpDuH; spf=pass (imf27.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674163439; 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=uNNpN6cdmenOslkS6PIT2EBjNmLCOw87BxzclT8zLwY=; b=xImAAeZNM89YdVSz3QgkZZMmUEyd/TDCkGWNjBtXUGTIsFi5Z7d7AhxX45YdYmIw53G7MM HjGqabCXsDKPWJH/OzPxLThv8iLNv55mEalTSuE+DpYanxuEesUgvpyxe1NBbnjajvwh4G pvT14Nv9ngmt3664fB2eyPFC12Fzw1s= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=U5AkpDuH; spf=pass (imf27.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.93 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=1674163439; a=rsa-sha256; cv=none; b=fVDC2izhHhNLqyuOW4cfIMQi0p1LOd5FMpMEGeJs8wVM9IvXlknFR6YzOlJ9pQzVXMGsDS sUB8kAW/HAK69Zb+DTt2Udob0YamEmMz1OaLGF9w+lhldwPw9bngmf4QUHN1jo1IR4UxIW ANPvQ27NL9fEnXrkRkT7YH/8jtGldfw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674163439; x=1705699439; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Sqmbg6aViWSIuyH7MnUz0YCJC/oOzGtcIb7+8J/qX00=; b=U5AkpDuHFdbgqDCWy/tse1rrmd5iw7EQBlp7sFFe5BxsrCaxcmow90XS ip5fLyvsbFofK2nU0Nj23h+IUrRq8Ygntlh3aR2Mp/pZ2x/KHMkaUjKR7 T9bm71jUco3Ai4hKptZslwZRM/eOTVjFI2qGNqatL2zDkSTYZLYw1mJOF OP7ScaMJXsW3H9lIDhJwA6nkJGHaiQCGiv7selQ5/NbFec1c87LMxWiQT eIdh1t0QuFDJUiiMoERyhA/QW/gXpBscRXY1T3oWaKLx4C9ZVJw1Fncoo /Drqx5ueOAzL3b9yWMzq1eyv2/Lx97IdmxrpP7xs/gfaaOpL1jgCSHcAt w==; X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="323119664" X-IronPort-AV: E=Sophos;i="5.97,230,1669104000"; d="scan'208";a="323119664" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2023 13:23:58 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="989139099" X-IronPort-AV: E=Sophos;i="5.97,230,1669104000"; d="scan'208";a="989139099" Received: from hossain3-mobl.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.252.128.187]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2023 13:23:57 -0800 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 , 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, Andrew.Cooper3@citrix.com, christina.schimpe@intel.com Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu Subject: [PATCH v5 21/39] mm/mmap: Add shadow stack pages to memory accounting Date: Thu, 19 Jan 2023 13:22:59 -0800 Message-Id: <20230119212317.8324-22-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230119212317.8324-1-rick.p.edgecombe@intel.com> References: <20230119212317.8324-1-rick.p.edgecombe@intel.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 6277F40003 X-Stat-Signature: 17ae7sxcpuo3f6q6gtqo4dqwobyjcd88 X-Rspam-User: X-HE-Tag: 1674163439-950601 X-HE-Meta: U2FsdGVkX191T9n4zu5kdaTWQdaflwAWGa5+kO7BgE0u2mM53Ay0Ae5AtcUs/EW9DsSn+6wS3BC88WCd1bxLia/DOxGf768PcyeynGgOH1/8k23HaFHIDaBxEpTN8zGQu2QzoJ1CKKpqcQ373mZF0oUP+dIG5arKS39NXnfupzJN57UQQt1OUfIM03ZZ/awmGLZUq0Gyw4xvPJbL9yDWaXAxzY0ti5zJJ9dbRLXTshQWNXI8b5VIW5qADHk7hVomVfiNHv8w3PThcOg/yRj7rJvUrUjGZbFtnVhDwbydzHalZdxTwMBpbfflgM+vR5nEV3kSEHDLthVZzIaLVUmZDcU0V3pfwkH4Qc0EF/0N4FxpweVy1zuN5F5y4d/A0iClyreRj7T5NqP6PteM4rBpEahuv4bDAS8kPZoM9t7qW1PtC5AO7CIH+t4Y4cc/ZKMsFqemzzd4b+W/Bei3J+MypaWY3HjRgZZweVfvmCVivc0ZRf1CIQ3X9pvy4Klh5yjFWgEcg9Og/F9A8SEzneBdklDBJsNWPaizY3kqZ96NLynq1OBoQhrJ3uPpEdDL4MRnGfSCtSa4tpRZLOS564qZW0a82QQd8rqwyxGKPARahFnA4bL74GYPOxGhMj7fJ21Gs004JLm+MdflQ/tcmeHmR8SimCSjaERCkTGl/JTFyzsVbSOWdMj1qzh8Rue3+nBW5SJJkz7MQFFS2W1/wtF8rTA1+Kmr8z8y5EYvIX021i1YpTIm1WEzB85mcYPO3RTA897rhSrtIdbZwzl/1ybf30NklwHK+FLERVsckoI83d3xO5oUOMwjuJKWrM7cAjyq9o/epv22xmH7A1sGjlhrI4UXd6bsuxiBw6+LyaoJYGglH1XZdcm9uShjtisk1HsIRZcNfwUANI0Aa/OPAcsr4yPE/zbjV9t5U/8SAgQ+9iZc6mSuedQgy9TwyB99Q/W8VIihPlxtk/yanRrc4Te yWAGtRug igwFhR69WIDhd2dBq/ruULcgnbZF2998P0kAoNyVdWn9Gs7tYZWrXujwbnNZ+vBxi8GQj2QTcunnk9Y9DEdlm1lJ1MZt4kFnk63zfaIaYKjiuZV/zUAkuCCZKXAP1y993DhxTphpipJCppH8Tm4eN+kH3Zct050HHYqz93WEyhoaRukqlyyjZiUSycZiEbe5brAr4efRsAosgAb99sgV3c+1oFz7dwKmQmzJXBJ3/q5WYZbHrhbZEXPxG3s5/1swkZUzYnu/kdo7SBa2Z78GkI6U/owJyw/73E0yU 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. Reviewed-by: Kees Cook 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 425a9349e610..9f85596cce31 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3290,6 +3290,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; }