Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp675437pxb; Wed, 3 Feb 2021 15:04:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjweuDBTW9tDePv7epkJG0OA4AYO7qrR/QRtPXHXKI+WPaJtt+PT+ClXMchsogWKA4HMlv X-Received: by 2002:aa7:d1d7:: with SMTP id g23mr5483472edp.6.1612393460235; Wed, 03 Feb 2021 15:04:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612393460; cv=none; d=google.com; s=arc-20160816; b=giuna93rtbpSoYr5elgGGRoArD0d590D1KjyoKszLsKIwkf6fxkO8lvdD7WwFalhYm Ut48vDFC4HrL1YVggZqvsePZIxZhDGNDhJnpn7uxT/xl/sGOo53ef7R3RoMwhpXtqHLH YWUGuq83LwcHsHIhafquv7+2ibLuaY6+1Bhq+Wm4UlA6ct/uQHJxH4wa2YNl7sCUgqB6 3b6WeE3qVE+ICaUsnoezrJGZCf9nsoMU1qx8Rtq15TVq1gUHSb3XnxRZwlbfCwDPFm1G fExcW1tEoNko0oIY8N3tzEbAJRBiwvzgePgm+NoC7pk2hR2jSK1hx5KjKtKnqO6Qewk0 4gxQ== 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=uIp3WzndLhiWRVYCVkhpmO4Y6PgLxVZ3AAf9jvQZS2w=; b=wp+eUJYI9J/BLNrILNQwFRNGceyCakwQ/L2WW3dnQ8u0WrOeJ2kLSZhas89Uh7L4G9 mtpRLU2bFkdsaF0QfHzCGKOhLjc7SFSIb471ur1JgV3DQEF41wLtIj8CdamICUGxSY9F P1FWR1Cz7WVNPNxzhbjdMjv4PKHfAibfRVI6RFI/3+Pimj/RMPOjXlPVdk2BSB0mCSzT 537BxPIdbkfy9+FuNqP+bCurlClpt40hEuAhKVvPGp8bB7EL1bk0FOXiMHquwhYL4wl9 hd7KZN19q8HO5CErT9VAq9q6pF0X0fnQxoYLUlU5abR199Zi88Gju3QJUUU8PsgJNRg0 95Bw== 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 jx12si2224414ejb.247.2021.02.03.15.03.54; Wed, 03 Feb 2021 15:04:20 -0800 (PST) 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 S233456AbhBCXAB (ORCPT + 99 others); Wed, 3 Feb 2021 18:00:01 -0500 Received: from mga06.intel.com ([134.134.136.31]:30220 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233279AbhBCW6X (ORCPT ); Wed, 3 Feb 2021 17:58:23 -0500 IronPort-SDR: gDKMlVdKaZ44cPtqcDPj49iToHVa+KvfJcUgVlHo3VmBiP9WhIdzxdeHQZfMQ9PRLsP9E0HRTH 1AwWVOpiTMuA== X-IronPort-AV: E=McAfee;i="6000,8403,9884"; a="242642368" X-IronPort-AV: E=Sophos;i="5.79,399,1602572400"; d="scan'208";a="242642368" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2021 14:56:30 -0800 IronPort-SDR: /P3+zoAooPPO21LpBKqZxbbNDY0Hv2qqeWX+ft85gpDVQ18Bh31UYjOTSYed3padk+4DNanueb 8AzSzjKi0laQ== X-IronPort-AV: E=Sophos;i="5.79,399,1602572400"; d="scan'208";a="507921135" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2021 14:56:29 -0800 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 v19 17/25] mm/mmap: Add shadow stack pages to memory accounting Date: Wed, 3 Feb 2021 14:55:39 -0800 Message-Id: <20210203225547.32221-18-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210203225547.32221-1-yu-cheng.yu@intel.com> References: <20210203225547.32221-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 0f4fbf51a9fc..948d28c29964 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -895,3 +895,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 d8452218d09b..b888b246b8b1 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1463,6 +1463,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 dc7206032387..51200b821898 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1720,6 +1720,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; } @@ -3389,6 +3392,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