From patchwork Sat Feb 18 21:14:14 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: 59007 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp555475wrn; Sat, 18 Feb 2023 13:21:20 -0800 (PST) X-Google-Smtp-Source: AK7set/d48nj5fkuVgh3yiNJ061MnWBmZYmmgLtlWeqYcZQMBi/Ip37H/UzwuOylgR/mvF6eZOxZ X-Received: by 2002:a17:903:1d1:b0:19a:6b55:a453 with SMTP id e17-20020a17090301d100b0019a6b55a453mr2943820plh.9.1676755279936; Sat, 18 Feb 2023 13:21:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676755279; cv=none; d=google.com; s=arc-20160816; b=ad2VhcDUeqACr4KL0F7tX48Bx2fQBr16eyidgWm3GI2SBeBW9p1k062ULemiB1nTtP AtCrGuNz2YnCTqxa0I8Hu4vK8ZPYLOmsj4dlrdc/sze1C6RkIF60X4InHbFLAp15pl9X JSmOJjCUpJWGuFrQf+7nX4auPreZLqVUydUMyi22Nvyobb1tiZ0MyaEwfsIbUwvdKLux 2E0Ts5WNh3vK2SdYKEj5JfbNyISRNvP4zov/BJdp706IheFBuCp3tq5reK1zjRtLMbVj EtaqkOFa+v1Uhi1geyNXjS7VPiHcuI60DumVMNtsQiglei9Tpvzv80yUdUdGf9ZIp0jr 7FWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=QrUmx8EKept3iSq/eqbQaHrnHicPTWm8RRXXurJvnBo=; b=eCaDUUUvh9ESIuI3Qgd2F9ZoxQYS9HJsNA+Ut6MJXdb5YpfAF0AKYnM+0Pwvw/1tXn S0R9T3TFucoZQCeB0mWS0GBFQlRSPQxJiKnvOh4AjK6OxQrqmzTlxvWerLRhqji4T5yI F/Gjqb4B2R4kemjM/8tXjm9MfPfOSCQ4m2jWiNxciomzBbl+PXvlubG/vJklKM8p515y 7mlu0gBNqmeXXxlFITWXh8U/FSDsJyS18Q8NyGHfrLU1luezQHgpoI8wJqPBCpcRbMa+ 2TeINtAuq1n0yXhdTTsoTwtTlvcbeDvxzI4N2cdXmZ7r2P660yKw4JlsWRlLeq3rVH7r qa3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MX8ZD5O+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s14-20020a170902ea0e00b0019acd30dc69si4399179plg.115.2023.02.18.13.21.06; Sat, 18 Feb 2023 13:21:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MX8ZD5O+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230195AbjBRVUt (ORCPT + 99 others); Sat, 18 Feb 2023 16:20:49 -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> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758205344549920604?= X-GMAIL-MSGID: =?utf-8?q?1758205344549920604?= 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; }