From patchwork Sun Mar 19 00:15:17 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: 13180150 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 8D967C7618A for ; Sun, 19 Mar 2023 00:16:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C593A280014; Sat, 18 Mar 2023 20:16:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BE4F0280001; Sat, 18 Mar 2023 20:16:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0EBE280014; Sat, 18 Mar 2023 20:16:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8BC48280001 for ; Sat, 18 Mar 2023 20:16:34 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 66684120C46 for ; Sun, 19 Mar 2023 00:16:34 +0000 (UTC) X-FDA: 80583731508.13.189FA0B Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf11.hostedemail.com (Postfix) with ESMTP id 5164A40007 for ; Sun, 19 Mar 2023 00:16:32 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=YMeMjMog; spf=pass (imf11.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.115 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=1679184992; 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=85mBto0Sll7IRfEByhCC7vuZskZGVCPWl8XWWuDZvdA=; b=IrzysuwqA6K1U1u9qJ9hGVpUp/QIq40C+4sCuLMoFUbxkoElVMQusSmQkv/VfR/Bmpm0zO s4i87pFOFiQr9hnmYx8PAW6nKJsBFeulrkae+4WrphVK9JQxX8lE5IbI/pCqmqKLRAl1G7 OkFPpaTNRU4qpkkWtOg+hXfoqn2ZPvs= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=YMeMjMog; spf=pass (imf11.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.115 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=1679184992; a=rsa-sha256; cv=none; b=Ry4yRlOOhpJotiGTv7jwlyzh2/UaEn4pRXYfqIWhVXo+D8+x3aKG05rh9KJQgkrJHEU7+H VUDki2v1oLqFJie29MmiqrZZVLV4Rxqoxw+/ILBGG00LgQlewdhlS0J/zMTsbUTCmw2x6p 3HDFbFkVLxdwBktg+bTcPFEJti2s4WQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679184992; x=1710720992; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Y8Z54H+73n2LbfSOdI84l/ZPS4qK7Tl7I0RpDbdZ/iA=; b=YMeMjMogXdCSFJzDxbpEZvcwjDIqz43r0l641NQ0r7Cm5s+sDWBFaQSK naiFRA4LfV5nZiimXwquLW5CaH/5WwgM9YjHpiNld6gIVCrV7Y4EU7Nif nv5Du4/ohJrxMPceNwDvsI5JioitkDcALrowe1zSVpi2HOzE9uGQBVVZr w3/UqNPr/EhnPryURFue8pQrG7YStJg+A3xKR8J38wrFMMxzzKty3Ln/q AsgmqCI7Rnd/7Ni33ZgB1zWVOiltUVRcLLcWzR33yikkbqw41hWvTYWx5 6Pq9mH35zZlPGcad0sWCIbpVaEP93pReVdNJyT8m6Haeh7vDmXlCSPp34 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10653"; a="338491221" X-IronPort-AV: E=Sophos;i="5.98,272,1673942400"; d="scan'208";a="338491221" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2023 17:16:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10653"; a="749672869" X-IronPort-AV: E=Sophos;i="5.98,272,1673942400"; d="scan'208";a="749672869" Received: from bmahatwo-mobl1.gar.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.135.34.5]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2023 17:16:30 -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 , 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, david@redhat.com, debug@rivosinc.com, szabolcs.nagy@arm.com Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu Subject: [PATCH v8 22/40] mm/mmap: Add shadow stack pages to memory accounting Date: Sat, 18 Mar 2023 17:15:17 -0700 Message-Id: <20230319001535.23210-23-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230319001535.23210-1-rick.p.edgecombe@intel.com> References: <20230319001535.23210-1-rick.p.edgecombe@intel.com> X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5164A40007 X-Rspam-User: X-Stat-Signature: kzj8zwmsgfdf6wtrabthxw33wdwpzjjf X-HE-Tag: 1679184992-925483 X-HE-Meta: U2FsdGVkX19CZ39Qg/aQEpG1qm1GStoroNKKSzBhYHjhf/uVEIXTzFzcTCB2rO0SsLOjWqiU0M5FeGkQP1Uu+xtTzY1hiHczD7E1E4Auv245cLSDxJsukJWWpDm3XVlWeL6QoGs+NOrTP48rGt+p779B3v0dTHJdtJ78G3ycWpKkDR/9mVCIzelxN6rZK1O71pIRJhDQ7z1RinUvK/urY9Dhf8BybxHgKrdv4gCHOnFp9W6wFluMHduiXqIkatTj7guV+WAsDCK283whh8uo9SFI7tpwL1ZVthFmQpa53ebH5JjH1wsNnZkyiZ4ca92JGP/FnidsognQZHv56mUrEZFSYhzneEs8IcmqHdhe2fBi7zGwsX9pAfbY8+GJASmlJCZNDyy4d/0Rl8naexZQsKJqxC87DZamdgwNEuTzqFzYxczeomlai/Jqd+NMCSzjSXEX6y/6lvEotuvs90Ob2l7LUu4oMJoSwLIUkQaW0rtVXfm8sEW759yBs5wce/eVmP3MN1nOiD+tjmtYWUgdV5qQopWAyp6cMPntZzOIOAQ+YwmeoQNqBuslxMhTpFwFguha4j3OlBclYFwF8Aro5ifVML3OUdNKKE5w2nU6hnZAZYRtYFM9lRO22I5UHZzW+JLaaVN8ZFHxk8u9gAksU7CTL/O/N5k2uZC7537EbRjnrpu/rWvi4hzo6/LgPJmKOBidc6FCcy9CDl24YWs6w3xN7Fd+Q3eynElAARZxu0ejGFzfq1G81LBqRE+u3ZWo9xihfbA1S+2l/z1PqRWjfcGyhNhOEKkmdoW0KhDUXUTpw4hDdh5RU7ZHvRkY5TL4QuyZBijShWLGoGeNbRnGO7BlfiffYqRejDA1hs84XX3PqGn2eRFfszcOplTsyu/BOpUtZF+D20qCDOl6ap5cIZpksBHE0PZzx8soiveoygW+NQTQopuvsvMGC72DWEv1E9Cv3wM/Geb9Nd83XvJ dKTF8GM0 9lP3Cji+c4AWKabOuW5on5u4j/d3BLMup3MJYANn/vcGg33iTug5kwY+4qB3OXUcpjJVhEew7P76xJ9L+JToOn6cOvLrQpGzul+qBhd/keCyqjvnEDuGbRGg+0FdOXz3qUGNpPRp3WargOsT6IDD31tbdpI4ZET3Ovqx2wuQlw2yiNQ5LhDg79+uc/n0Xj9SpC0ZYjuj04G9RFfbI994zXhoXu1g6rgqT77QbOkxYDl+oV//XbbX8mfEJwTgA/f/Bq/CmEEdE19+ZMgkzBvz4xYVk+vMXlNxhVQz3FMSQoIxDU2I4TXaT65cRHYSpmMuo+d8Fx1OUwu5rsr0RqLGlZogxQ2+mL5IHHm+N9EEM1oDdTNbQ3XoC2kVOyg== 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: 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. Co-developed-by: Yu-cheng Yu Signed-off-by: Yu-cheng Yu Signed-off-by: Rick Edgecombe Reviewed-by: Kees Cook Acked-by: Mike Rapoport (IBM) Acked-by: David Hildenbrand Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook --- v8: - Update commit log verbaige (Boris) - Update comment around is_stack_mapping() (David Hildenbrand) v7: - Change is_stack_mapping() to know about VM_SHADOW_STACK so the additions in vm_stat_account() can be dropped. (David Hildenbrand) 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. --- mm/internal.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 7920a8b7982e..2e9f313fcf67 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -491,14 +491,14 @@ static inline bool is_exec_mapping(vm_flags_t flags) } /* - * Stack area - automatically grows in one direction + * Stack area (including shadow stacks) * * VM_GROWSUP / VM_GROWSDOWN VMAs are always private anonymous: * do_mmap() forbids all other combinations. */ static inline bool is_stack_mapping(vm_flags_t flags) { - return (flags & VM_STACK) == VM_STACK; + return ((flags & VM_STACK) == VM_STACK) || (flags & VM_SHADOW_STACK); } /*