Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1109527ybz; Wed, 29 Apr 2020 15:14:14 -0700 (PDT) X-Google-Smtp-Source: APiQypKkOo/PLIMjoJ2SyDVNnEHpgQf02T9k1BCYIxiigwCpHEgW5M2Xxi4U+iyX77YWfIEWFqbQ X-Received: by 2002:a50:9e2a:: with SMTP id z39mr104118ede.371.1588198454452; Wed, 29 Apr 2020 15:14:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588198454; cv=none; d=google.com; s=arc-20160816; b=Z2I1Flb2tLWslrRy8EXUYnhZYatvnvrZ0A7qq5s20LdU4hRVOEjZkHfcBItXOl5a6u rYlcmLPDPGyPiX0qL2/T96WscdwPS1Tbfszk5Cp9DQlp0QkRcmvxZff14ma8YbGBDGhq SfXJJsNRQy6AMCpWkTJAZ9+nEa80UGxkH9QoOejR1Hw7KT6TQtJkYx3Ke+xXwUZU70tB X6j4kO59tCwRB1ddD/pOERS4ECqJZ0fCjxo8ARR/m5TrYfiA9MHz9yRaz4Eke6hiJZsf NFCqvgGmymNZs+5Fq4O0PodPj4yG6DeuaRc3Eg3Gh1JnxXM6mwq/IUn2Bi1sCeslqPOW mG+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=h8oA3EodQ2vsSFTJZCHCj7Ybn5+ukuugCKLMSZzq7K0=; b=QRV236Jn+1myCpAGHHghLG+VODM7Pbe5a1770OJwQcULcWfNnAk7OYktz7BUmkTGzU UjSB/zfR9CpTynWATvDNO5VxdyLuPfnrzbpicYq+zyISqCS2ml7P7TnDGe2w2su9LQjq oKLyWgGOw8HhaIxQ517w0AGkiqGvos6O3Rnm0dCNSxEKwygnk1gnAH0JofURkKBv1xQI lnjSYovXc6dQ9/vphLk/OeqBEtFoFe+LNg/zC7cAxDlLyVlpaP+GYXAHnJKVOcxIFMnV mMqHs3s2pMGazHMYUCerFhFaFzlv/Eqk/ov0HyZrioWy71vm5SXmPKF/EYIvZzqm5wNU oJdw== 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 ci9si4520793ejc.125.2020.04.29.15.13.51; Wed, 29 Apr 2020 15:14:14 -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 S1728276AbgD2WJy (ORCPT + 99 others); Wed, 29 Apr 2020 18:09:54 -0400 Received: from mga09.intel.com ([134.134.136.24]:61302 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727950AbgD2WIt (ORCPT ); Wed, 29 Apr 2020 18:08:49 -0400 IronPort-SDR: GhThBs38UiYH1SK8Mq8lqsTyJE2qsq3kqr90+uYEyPxREFd8ixNhQPElIg4yAUbpLXfy1cjlHt 7IVG4bD5yvBQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2020 15:08:49 -0700 IronPort-SDR: Qxlpm41s9e3hABYhsoQMLiJrtMgVEIS429u+AeFHDZxyQzsrH5/X3lh9fukI9DQrkktfrtoneu GWZhzr7KNIhA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,333,1583222400"; d="scan'208";a="276308911" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga002.jf.intel.com with ESMTP; 29 Apr 2020 15:08:48 -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 Cc: Yu-cheng Yu Subject: [PATCH v10 17/26] mm/mmap: Add shadow stack pages to memory accounting Date: Wed, 29 Apr 2020 15:07:23 -0700 Message-Id: <20200429220732.31602-18-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200429220732.31602-1-yu-cheng.yu@intel.com> References: <20200429220732.31602-1-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org 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 --- v10: - Use arch_shadow_stack_mapping() to make meaning clear. v8: - Change shadow stake pages from data_vm to stack_vm. arch/x86/mm/pgtable.c | 7 +++++++ include/asm-generic/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 aa4d396ff98d..f384e0314ba7 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -890,3 +890,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/asm-generic/pgtable.h b/include/asm-generic/pgtable.h index 2c3875724809..dbd415ab7dd8 100644 --- a/include/asm-generic/pgtable.h +++ b/include/asm-generic/pgtable.h @@ -1215,6 +1215,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 f609e9ec4a25..70d240b3559c 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1681,6 +1681,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; } @@ -3318,6 +3321,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