From patchwork Thu Sep 29 22:29:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 12994673 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 1EDD6C433F5 for ; Thu, 29 Sep 2022 22:30:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90B8E8D000D; Thu, 29 Sep 2022 18:30:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 868DB8D000C; Thu, 29 Sep 2022 18:30:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53AC78D000E; Thu, 29 Sep 2022 18:30:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2C0C28D000C for ; Thu, 29 Sep 2022 18:30:27 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id ECEC5813C6 for ; Thu, 29 Sep 2022 22:30:26 +0000 (UTC) X-FDA: 79966568052.08.F35C360 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf10.hostedemail.com (Postfix) with ESMTP id 6AF7CC0005 for ; Thu, 29 Sep 2022 22:30:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664490626; x=1696026626; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=6n6cAgUq+fer3NSIP02jyEcIyWW6Zs7Gr4LVaF52ejw=; b=j9CrzQ5brmPsYwkyPUrGUjgD2PCuR743pkLdtxUnVzhOoiKXFEIBhYaW CsVpkvX8GiJ37CoVFo/49s/rCqAMjoQkasRoF5HpPb6HCxSbUIYhUC357 dl0oAGB710PALNPfeUNqSt0zIP5Yu6PkuUzz3fa4AR5PZk8AKWKiWIXwI gxI3yGYCEPUp+IZgplSn3lb75+85mYwIGFdWDZ5xzfUKHCOdSY8FOA2cu Uzoef9R8OcN6S9D0/lxqtW+jhNNsRMXnGMO88VvApb/jdv3UlYTO3Mney Re9yzeGtcCSj8v5FQYb9puZfiBP6sihRp1u7uqsSnAhxLyGUmTv6b0N20 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="328420486" X-IronPort-AV: E=Sophos;i="5.93,356,1654585200"; d="scan'208";a="328420486" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2022 15:30:24 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="691016248" X-IronPort-AV: E=Sophos;i="5.93,356,1654585200"; d="scan'208";a="691016248" Received: from sergungo-mobl.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.251.25.88]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2022 15:30:22 -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" , joao.moreira@intel.com, John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu Subject: [PATCH v2 19/39] mm/mmap: Add shadow stack pages to memory accounting Date: Thu, 29 Sep 2022 15:29:16 -0700 Message-Id: <20220929222936.14584-20-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220929222936.14584-1-rick.p.edgecombe@intel.com> References: <20220929222936.14584-1-rick.p.edgecombe@intel.com> ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=j9CrzQ5b; spf=pass (imf10.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.88 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=1664490626; a=rsa-sha256; cv=none; b=8Z3tOZxMghnchhPOui9G7yKbmvkvR4DvfO05iBJE6LKZZynkxmyxSrHYFlPG0ASG1iPX1E la5yeGKsyEoVtSMpnbe+QPnlVbH5u5w2hSoztZy2cbb7odmOBgpeU0JrGnZtxWCImzumEN 2QB9erpzaijth4GsLlvFyntAw0F2wxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664490626; 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=GheW5a4Oo9wP4OJZdSYVaVB8bQHZQ3tjnBvRIQx7MBU=; b=l9h8kIHrSqrFry/luaMS6vmZlLrDe/7VwT8q7Ajas/XNI9X+UlEB1M+OmXEssMBti9H1rt a7J13xXIMH3c3TJqaabXut1OXA1E+REdZl0HsO7vcSexNqIL6F9fGcjxFP3RSk3jp4ExxF mfIPgIWgz+ovJNznfcEmk0UoBPnv7K4= Authentication-Results: imf10.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=j9CrzQ5b; spf=pass (imf10.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspam-User: X-Stat-Signature: h77pme9js4wufmt3kj5nmhnn689oizb9 X-Rspamd-Queue-Id: 6AF7CC0005 X-Rspamd-Server: rspam05 X-HE-Tag: 1664490626-361298 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 Account shadow stack pages to stack memory. Signed-off-by: Yu-cheng Yu Co-developed-by: Rick Edgecombe Signed-off-by: Rick Edgecombe Cc: Kees Cook Reviewed-by: Kees Cook --- 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 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index f0d2e9143bd0..8569ef09614c 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1682,6 +1682,9 @@ static inline int accountable_mapping(struct file *file, vm_flags_t vm_flags) if (file && is_file_hugepages(file)) return 0; + if (vm_flags & VM_SHADOW_STACK) + return 1; + return (vm_flags & (VM_NORESERVE | VM_SHARED | VM_WRITE)) == VM_WRITE; } @@ -3289,6 +3292,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; }