Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2805541rwb; Thu, 29 Sep 2022 15:34:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5N0pMDk8xO7dRha3wHSdGMNwgjol2yfspA1PqoTzPAGnYZ3emcZ8g9nN/T1Q9UOcSsY0fu X-Received: by 2002:aa7:838a:0:b0:550:5e4a:ab55 with SMTP id u10-20020aa7838a000000b005505e4aab55mr5703830pfm.10.1664490861019; Thu, 29 Sep 2022 15:34:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664490861; cv=none; d=google.com; s=arc-20160816; b=Xsh8S6BGh7L9AWNtlmCDhMksT+O2kOq4x7TzEB4RpJ7ZOEigVMM+Q+NVG2lMxbpL/j 5QWXpvqc3r2WIdNmV85Ged0kPeOby5qHiNvtuRxknUFN6nFxCeVl5jAe3ghuvQBO3vlg qb4tycI4ckkZ8ZyhbFzO6qG96H7WL6ZlK/rhQ8tgzhN8BjoDQ2WBnPKbGZX/Q5rchkLU xWrjaQXJZ6HhmfwS4ieoS0WS+zMn57y8EF0go3F4aZfCvRcvBoaPxiDb7Z3vlDARHHd4 336+1/rcCV8oWZVe5XXxZf8qEhjZPaIHlHFt80OWvJ/VZY2tYLYtetms009b3W6KMAX+ Btvw== 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=GheW5a4Oo9wP4OJZdSYVaVB8bQHZQ3tjnBvRIQx7MBU=; b=EVNt4qHwBbzt6ylP1gPyBjgLBr/riheo9dXLS3gcBq5FEoqGSm8MbXAU0XmEWHKtab 1Z772oCmB+4VjAG/QHCvZqqGyTnd8A9sfDM5ge224omxW4g2HYA5uthlCvvDZjAeAysC KeKWfow2JSUynthT6a+p/FESch7z8TETAmX8aSIO+gTHfehVXvgUsuqS6AHVSoA9wA1U JcMaUDgszIf8Fh+z61uONujwwcYpEYEtSit1pJ4v1p9GcLapbatgAoqLVhVfqvclIHi9 zce+afPav9WUsi+eW0NiW2O6v/Iiohvc1ukBIF8pNcsZW6CmePsO1cKMPF3NW6mnjR1b iJRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ai8qVhrC; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nn18-20020a17090b38d200b00200bbb9027asi45684pjb.77.2022.09.29.15.34.08; Thu, 29 Sep 2022 15:34:21 -0700 (PDT) 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=Ai8qVhrC; 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 S229998AbiI2WdY (ORCPT + 99 others); Thu, 29 Sep 2022 18:33:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229945AbiI2Wce (ORCPT ); Thu, 29 Sep 2022 18:32:34 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93C3E9568D; Thu, 29 Sep 2022 15:30:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664490654; x=1696026654; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=6n6cAgUq+fer3NSIP02jyEcIyWW6Zs7Gr4LVaF52ejw=; b=Ai8qVhrCek3zGUrt/fiaC7Zx0jGN/H32g6r/TuMLg5enzHFcrG0rTb3C IFwpgvCOUf3/gYmBEKrLXtldwGYX9vKeoak9MEXN0C9F7wmWC9FkqJrxJ IDnBqoq/P2DGHaHf7cJjY18FrpA3NC/yXSXl8I4CSc5kMxWKip04hP6QJ uK4kCJIlyV0G9i+DICF3JKfuV1sNrAc7XB2P1Zi8JkyhAjiw/tlHQh3ak FbvnIA7nSverimBPxJumKnLYrhzmcLcUybgz3kg02N1q6cd8ddkH4FnJq oRHJ8vN1OJr5Ed0iwcJNwAL65gFMCKlH1vufjagqbv+QUvJEqCv+fCvj3 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="285181979" X-IronPort-AV: E=Sophos;i="5.93,356,1654585200"; d="scan'208";a="285181979" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2022 15:30:25 -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> X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 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 --- 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; } -- 2.17.1