Received: by 10.223.185.116 with SMTP id b49csp2779128wrg; Mon, 5 Mar 2018 08:33:07 -0800 (PST) X-Google-Smtp-Source: AG47ELthjGAOe4xuGPcCVKtu2mQE+ePA9g44xEpCZ09yZk2ge3Zu/4jxPgRnIeW6EmODZw1vqU5x X-Received: by 10.101.82.70 with SMTP id q6mr12482204pgp.67.1520267586998; Mon, 05 Mar 2018 08:33:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520267586; cv=none; d=google.com; s=arc-20160816; b=TcHW4Nbqr6O8P8p85NToPoh2+kB6fKXC4NF4mnXl7Ygz69W2xOfvUVhz+Amt9yVd7F 45z/k10QlEVCHazzyG+4GbzWv5FrmWQQGRm/UtJ/ZXKXv6ycTEZ77EAty7MoleBgN+42 36qAVWULwsBS8+7898F+5FpRv+56m8VM3UzQLBJu5n9/thojIknZKN5SbGZzLqI4wBY5 uIn2EAo/tjDfYaWo9s4dalSIaVRtWaxlhnggeVMOrK2SUSwS6XueYz3zcug5AZUN8ysb zlXGEbE6bDrEnZr1zYR44rc6/AXv0PlyUAmm1ydF0PefgysF+bW7Nmp9aj1ORicUw+nu B5zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Y/Nwjwnd/xHIeAJwsCISg9x06LuoiHuwABxi5qwG2GU=; b=h8j7LZgrGPF9Orwx06Ea7ESlRo75p3VuHVRVKm89V55QPfP3wPBbuBUdIFuhyb3q7i EzfjwxgCd/mf0bQ++6s9SxkB1kNFuOjsY65PPdo5Tp3WxpzdPZcHZOzYhrs4twSD1Wd2 hQUA/ZGFEp6swnBEh8A20AG9HtiAEnOElTXQWu0295yd0TPtxZ3ArMYbnpYfnSl0iBjX LLz1zXqe3aHnhCrnUK6wgUhXtS5AhXGJdfcuuts/omfgu+yO7KRTw9iwWHH/ZKtHKzes bG3GuKtHbZ1STQqSJ3FQyY9rGTCYXwI1PdCFlNAi9tBTHalAiRNbmcJLqo83EEtuAh18 yyXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q3si8548922pgp.632.2018.03.05.08.32.52; Mon, 05 Mar 2018 08:33:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753101AbeCEQaz (ORCPT + 99 others); Mon, 5 Mar 2018 11:30:55 -0500 Received: from mga05.intel.com ([192.55.52.43]:31633 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752319AbeCEQ01 (ORCPT ); Mon, 5 Mar 2018 11:26:27 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2018 08:26:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,427,1515484800"; d="scan'208";a="25328713" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 05 Mar 2018 08:26:24 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 621864F8; Mon, 5 Mar 2018 18:26:20 +0200 (EET) From: "Kirill A. Shutemov" To: Ingo Molnar , x86@kernel.org, Thomas Gleixner , "H. Peter Anvin" , Tom Lendacky Cc: Dave Hansen , Kai Huang , linux-kernel@vger.kernel.org, linux-mm@kvack.org, "Kirill A. Shutemov" Subject: [RFC, PATCH 11/22] mm: Use __GFP_ENCRYPT for pages in encrypted VMAs Date: Mon, 5 Mar 2018 19:25:59 +0300 Message-Id: <20180305162610.37510-12-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180305162610.37510-1-kirill.shutemov@linux.intel.com> References: <20180305162610.37510-1-kirill.shutemov@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Change page allocation path to pass __GFP_ENCRYPT on allocation pages for encrypted VMAs. There are two different path where __GFP_ENCRYPT has to be set. One for kernel compiled with CONFIG_NUMA enabled and the second for kernel without NUMA support. Signed-off-by: Kirill A. Shutemov --- include/linux/gfp.h | 17 +++++++++++------ include/linux/mm.h | 7 +++++++ mm/mempolicy.c | 3 +++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 43a93ca11c3c..c2e6f99a7fc6 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -506,21 +506,26 @@ alloc_pages(gfp_t gfp_mask, unsigned int order) extern struct page *alloc_pages_vma(gfp_t gfp_mask, int order, struct vm_area_struct *vma, unsigned long addr, int node, bool hugepage); -#define alloc_hugepage_vma(gfp_mask, vma, addr, order) \ - alloc_pages_vma(gfp_mask, order, vma, addr, numa_node_id(), true) #else #define alloc_pages(gfp_mask, order) \ alloc_pages_node(numa_node_id(), gfp_mask, order) -#define alloc_pages_vma(gfp_mask, order, vma, addr, node, false)\ - alloc_pages(gfp_mask, order) -#define alloc_hugepage_vma(gfp_mask, vma, addr, order) \ - alloc_pages(gfp_mask, order) + +static inline struct page *alloc_pages_vma(gfp_t gfp_mask, int order, + struct vm_area_struct *vma, unsigned long addr, + int node, bool hugepage) +{ + if (vma_is_encrypted(vma)) + gfp_mask |= __GFP_ENCRYPT; + return alloc_pages(gfp_mask, order); +} #endif #define alloc_page(gfp_mask) alloc_pages(gfp_mask, 0) #define alloc_page_vma(gfp_mask, vma, addr) \ alloc_pages_vma(gfp_mask, 0, vma, addr, numa_node_id(), false) #define alloc_page_vma_node(gfp_mask, vma, addr, node) \ alloc_pages_vma(gfp_mask, 0, vma, addr, node, false) +#define alloc_hugepage_vma(gfp_mask, vma, addr, order) \ + alloc_pages_vma(gfp_mask, order, vma, addr, numa_node_id(), true) extern unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order); extern unsigned long get_zeroed_page(gfp_t gfp_mask); diff --git a/include/linux/mm.h b/include/linux/mm.h index 6791eccdb740..bc7b32d0189b 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1479,6 +1479,13 @@ static inline bool vma_is_anonymous(struct vm_area_struct *vma) return !vma->vm_ops; } +#ifndef vma_is_encrypted +static inline bool vma_is_encrypted(struct vm_area_struct *vma) +{ + return false; +} +#endif + #ifdef CONFIG_SHMEM /* * The vma_is_shmem is not inline because it is used only by slow diff --git a/mm/mempolicy.c b/mm/mempolicy.c index d879f1d8a44a..da989273de40 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1977,6 +1977,9 @@ alloc_pages_vma(gfp_t gfp, int order, struct vm_area_struct *vma, int preferred_nid; nodemask_t *nmask; + if (vma_is_encrypted(vma)) + gfp |= __GFP_ENCRYPT; + pol = get_vma_policy(vma, addr); if (pol->mode == MPOL_INTERLEAVE) { -- 2.16.1