Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4068765pxu; Mon, 12 Oct 2020 08:42:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdAHPILMFk4/OW7tL9iCw093x3ayW8jDrfBIRPAq6mDMbZ42oXcbayDMDIx381a2AmOHjv X-Received: by 2002:a17:906:1a11:: with SMTP id i17mr28091570ejf.381.1602517349129; Mon, 12 Oct 2020 08:42:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602517349; cv=none; d=google.com; s=arc-20160816; b=rzSsVOn+5+U0IaL/a5UMoU1tGLaf7sWctchUg1JFdPq9SMfB47x1uN33x+r36TPVzz fSHwF6tQNLGph3deMIBlABkBluJyZ44wFhXNJyFH99+CuDshS5Y8lUJ5ZbIxfUiLcgd1 dhQg7rGgpL/G+U4qgow8+/vRvW9p1mrMn+MJ9Ib3vY9fXxl75m6oTetcH9/qAxHpZ2Gp unpl0doESBrimgwwliiwnvESPATgyVRXftUV2qNtfse3yDdiF6qtBtdaHpkX6EHgzmQB kxWkYYGHfL9iQjzbvc7jKgQdN/hwdBxUOV6Q3KO0Kj46eDgA6Owdyfvu0dW8TbGYTovZ EaIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=nG+SXQ0ll4ySI3a8X7ev2nfytaKexSyOWNfZ9WjjBxg=; b=thwaBcEk+MwTtdQ2J+g4m9+LrcmSWjjo88lk9eDTVRVZM11bdajSyFJIMzQ7ukuc1O wUZWI4C8LDjH2RDLf471dYumVRQ/Tv+oiiqi6HTjyaymOyKDn0QkS5qi5lr27iiY4WA2 mlFQoCnBTnTNCZF5lcxCB27+pNZREaZoMTJUxLKHMq6tbat5+MfliX2Fz3Gq3082THq2 vFRV4kbTaKK4W9npLjOwPoJdSy65TQfKFJ79f8FcWYbWU+fUK8NdQ8Cxl0AHTulET+N7 NqOK4TtRf+9fZN7a1CwjL52TfmlYQdA62pvnAiSLqQtOHq0pU0FcnrJqdHamRVC+PvM2 pqgg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d20si11334235ejz.615.2020.10.12.08.42.02; Mon, 12 Oct 2020 08:42:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390475AbgJLPk0 (ORCPT + 99 others); Mon, 12 Oct 2020 11:40:26 -0400 Received: from mga05.intel.com ([192.55.52.43]:1310 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390338AbgJLPkH (ORCPT ); Mon, 12 Oct 2020 11:40:07 -0400 IronPort-SDR: LecXeyzgtn32JXVWo0R+Jp0L4xR9qPgs0BgHs5CA6lMPv2hgEBbct0vG7X0tqeHY6Q3SJ5Hc5t SSabJo1lf7eQ== X-IronPort-AV: E=McAfee;i="6000,8403,9772"; a="250452699" X-IronPort-AV: E=Sophos;i="5.77,367,1596524400"; d="scan'208";a="250452699" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2020 08:39:55 -0700 IronPort-SDR: PkpaoOa6r468En+/9cCo9SkQHi6hPO2r0V8t0+PcCg4UOmuctWR3VrgF3ShmczPQkOSSrVKcZA re4fALKKDmKg== X-IronPort-AV: E=Sophos;i="5.77,367,1596524400"; d="scan'208";a="530010886" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2020 08:39:54 -0700 From: Yu-cheng Yu 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" , Vedvyas Shanbhogue , Dave Martin , Weijiang Yang , Pengfei Xu Cc: Yu-cheng Yu Subject: [PATCH v14 17/26] mm/mmap: Add shadow stack pages to memory accounting Date: Mon, 12 Oct 2020 08:38:41 -0700 Message-Id: <20201012153850.26996-18-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20201012153850.26996-1-yu-cheng.yu@intel.com> References: <20201012153850.26996-1-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Account shadow stack pages to stack memory. Signed-off-by: Yu-cheng Yu --- arch/x86/mm/pgtable.c | 7 +++++++ include/linux/pgtable.h | 11 +++++++++++ mm/mmap.c | 5 +++++ 3 files changed, 23 insertions(+) diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c index a9666b64bc05..68e98f70298b 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -893,3 +893,10 @@ int pmd_free_pte_page(pmd_t *pmd, unsigned long addr) #endif /* CONFIG_X86_64 */ #endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */ + +#ifdef CONFIG_ARCH_HAS_SHADOW_STACK +bool arch_shadow_stack_mapping(vm_flags_t vm_flags) +{ + return (vm_flags & VM_SHSTK); +} +#endif diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 157f5e726896..6f2ca5fffd44 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1380,6 +1380,17 @@ static inline pmd_t arch_maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma #endif /* CONFIG_ARCH_MAYBE_MKWRITE */ #endif /* CONFIG_MMU */ +#ifdef CONFIG_MMU +#ifdef CONFIG_ARCH_HAS_SHADOW_STACK +bool arch_shadow_stack_mapping(vm_flags_t vm_flags); +#else +static inline bool arch_shadow_stack_mapping(vm_flags_t vm_flags) +{ + return false; +} +#endif /* CONFIG_ARCH_HAS_SHADOW_STACK */ +#endif /* CONFIG_MMU */ + /* * Architecture PAGE_KERNEL_* fallbacks * diff --git a/mm/mmap.c b/mm/mmap.c index 40248d84ad5f..574b3f273462 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 (arch_shadow_stack_mapping(vm_flags)) + return 1; + return (vm_flags & (VM_NORESERVE | VM_SHARED | VM_WRITE)) == VM_WRITE; } @@ -3352,6 +3355,8 @@ void vm_stat_account(struct mm_struct *mm, vm_flags_t flags, long npages) mm->stack_vm += npages; else if (is_data_mapping(flags)) mm->data_vm += npages; + else if (arch_shadow_stack_mapping(flags)) + mm->stack_vm += npages; } static vm_fault_t special_mapping_fault(struct vm_fault *vmf); -- 2.21.0