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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0F14C64ED9 for ; Sat, 18 Feb 2023 21:20:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229938AbjBRVUv (ORCPT ); Sat, 18 Feb 2023 16:20:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230206AbjBRVTz (ORCPT ); Sat, 18 Feb 2023 16:19:55 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3DAA1ABD5; Sat, 18 Feb 2023 13:17:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676755066; x=1708291066; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=h1Ina/ZMuUJfFdTiWzdv2FLDw2HpwpjMUTBFM0iRihw=; b=MX8ZD5O+Q7gsaO8Dkdzu+pRrj5sYGgksEM2HH4uCA8rvuePuwFVgEJLI oEKk/b2bn6CxihvijkQHDpAlSYfk6MYI59UAsXz6JN6BLbDiPoEcVlfbb idcB8IovK3Q6ph7K7F6VQKY83lLLMLQ1K/zNZ2Gn7JsqBv1OGUjRmkyRj 2ksGPdzOEmfMD0sDhBzET4BIOCwqpmaArsmoiKybPtBUrVDIT/vNYnF53 D5upXvtl4yhMwFyyVM2uep5RPSbY3kVRYZ0ixWqIL1EFQ4nH6tvAMPzgW DX8McvE2liKgsPwngxwc4D+AzIc1XShK+fQxUDmB3d5Nh0jOwG1kL9uy7 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10625"; a="418427576" X-IronPort-AV: E=Sophos;i="5.97,309,1669104000"; d="scan'208";a="418427576" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2023 13:16:15 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10625"; a="664241677" X-IronPort-AV: E=Sophos;i="5.97,309,1669104000"; d="scan'208";a="664241677" Received: from adityava-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.209.80.223]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2023 13:16:14 -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, david@redhat.com, debug@rivosinc.com Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu Subject: [PATCH v6 22/41] mm/mmap: Add shadow stack pages to memory accounting Date: Sat, 18 Feb 2023 13:14:14 -0800 Message-Id: <20230218211433.26859-23-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230218211433.26859-1-rick.p.edgecombe@intel.com> References: <20230218211433.26859-1-rick.p.edgecombe@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.17.1