Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6267756ybi; Wed, 31 Jul 2019 11:13:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFvcqqxqAD6C2texP9ktyVoa7D0YwNlw70B1ZuVLnAB9jwgsMk8OeZnwlhqi+VKfbfFAZH X-Received: by 2002:a17:90a:fa07:: with SMTP id cm7mr4089241pjb.138.1564596812131; Wed, 31 Jul 2019 11:13:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564596812; cv=none; d=google.com; s=arc-20160816; b=moRmQOOGB8WcDyJoRLTp6e9Xwfunvu5idWd6Y1kfElnaweh9WIfAn6HACui5WzNeK+ JouvlIL+ZDqZSPQH69s8sk2P37moRUyCElEGdWhg+5GGkUiOUqxCzF99fupvA0ouhBqF PcgwNqWEkaIja1fjXqmXKo4jNvLuXmLdjLaZc1rCp/Mi+i377v+UI/kTKV9DT+suMpu8 K5zm85Oekec9+ndNXCG0gki3KfOV43zQBn0GXroyyJnQUuKjtk06dwT5n0RsP0Rdns6N MOxoLKP1b1n4MLzUSTQ9pbIMgPBfETttGBfb/ia+aWcCifqACYrFcFIRyEroqT3cOniO DxAg== 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 :dkim-signature; bh=AJU4EYtP5Ndll/OqHeAitrNwzvbF49Nst5sv0orja/w=; b=n4PZOwlQsrHL67YtmYyNieV1hT7mp5XGDiyT02Z4AABnAkqPvAHz8nu+MESHwmVbuA Ql23MzIfJ906SaqGmp6KHpM3GBKVBPyjHdpYV1/WNd17gGiwxrIuWywy4hpPRV2glfvB ZEx4M8i5eSace4oRJcGaHiRjQx1dCF16nCLdFsox/7qyHiDEH0eqn25xI66mZnMbB4hg adpphQIqGL5ILytEinwHSpsfnjbGwbo5XG9biAStEj9PEyVxeAPb9Xt1PqTve6WcLleR YmJby4dJfBIMjhyhFIiU64+MnORIX1cTFbaBosm7UqCscrJFGv5qVt1SYdExAAx9UbsR 1mbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=kKXhGbR2; 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 g15si28501280plo.239.2019.07.31.11.13.16; Wed, 31 Jul 2019 11:13:32 -0700 (PDT) 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; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=kKXhGbR2; 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 S1729048AbfGaPKn (ORCPT + 99 others); Wed, 31 Jul 2019 11:10:43 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:35712 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388453AbfGaPIV (ORCPT ); Wed, 31 Jul 2019 11:08:21 -0400 Received: by mail-ed1-f65.google.com with SMTP id w20so65995150edd.2 for ; Wed, 31 Jul 2019 08:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AJU4EYtP5Ndll/OqHeAitrNwzvbF49Nst5sv0orja/w=; b=kKXhGbR2JDGE9bSyvxgjKsfR1EooQVCxUWsDBiB/ov2JhR22a80ZVWH6hsoT5t60hW ReQlX2VuPnyHZm+ht43QCRrwOTR4FXEx8N9KLDx8PA4ydWKsR2BIUMxIijk5qFFyJWJR 2f083LoqCGdskXIuleu/ah0wA10Rm17n5y2ig4+kPBzijtTL3lkIw8/27JLPaHybuORM pzMd9bI4PnPnmBKajAUKL8D2paFeEh9jjqZZbZStBfag1gDyfG8bBCKhuARqXP5nW2Pq L1ZhDiLr0HWi2NeMxbyWk+wgHvu/5r9izvPURcblDhh/5L3ApkkaOd6gdu9AGvFSIsuM bwfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AJU4EYtP5Ndll/OqHeAitrNwzvbF49Nst5sv0orja/w=; b=tncZ7NQY0EJnonHKzJ8kDJ+tFGp30L3BnMleGafj6hAvRyjgDjh8beUmtTVZWyWaRM WrJPPyja2w9XjFZS5RiKv0E9knXjYTEIfO1PBlLxyLevQfZzgEccuz68xUxcTuF2C8dl w6s9tz990Vtg8qc9dvJSFFu90jrpEZUjfUjYEk5+MYcLvrhNZe731FJLCFHpSd93nFYR y8fFEygTzAEExekc1n7MxjcDr8vhtNJqtMr82KqAq5DC1cLpPivLbDLkSjtwa2POvPJD JUW/o/iIPEYweOWisOtcJ0PWrGy3mWXrU90ue5rsgRD2AZ7+nrU3KQZH6GwpkzIKTwHz FXlg== X-Gm-Message-State: APjAAAUp1AWAB6C39zn7jp/NUc1cUtSbhMgP/qhBYdXrIGK10kXert1W CNMfKi4jPN0gYmaDsRyTDSY= X-Received: by 2002:aa7:da14:: with SMTP id r20mr107154184eds.65.1564585699886; Wed, 31 Jul 2019 08:08:19 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id o22sm17282787edc.37.2019.07.31.08.08.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Jul 2019 08:08:19 -0700 (PDT) From: "Kirill A. Shutemov" X-Google-Original-From: "Kirill A. Shutemov" Received: by box.localdomain (Postfix, from userid 1000) id 17B6310131D; Wed, 31 Jul 2019 18:08:16 +0300 (+03) To: Andrew Morton , x86@kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Borislav Petkov , Peter Zijlstra , Andy Lutomirski , David Howells Cc: Kees Cook , Dave Hansen , Kai Huang , Jacob Pan , Alison Schofield , linux-mm@kvack.org, kvm@vger.kernel.org, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv2 06/59] mm/khugepaged: Handle encrypted pages Date: Wed, 31 Jul 2019 18:07:20 +0300 Message-Id: <20190731150813.26289-7-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190731150813.26289-1-kirill.shutemov@linux.intel.com> References: <20190731150813.26289-1-kirill.shutemov@linux.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 For !NUMA khugepaged allocates page in advance, before we found a VMA for collapse. We don't yet know which KeyID to use for the allocation. The page is allocated with KeyID-0. Once we know that the VMA is suitable for collapsing, we prepare the page for KeyID we need, based on vma_keyid(). Signed-off-by: Kirill A. Shutemov --- mm/khugepaged.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index eaaa21b23215..ae9bd3b18aa1 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1059,6 +1059,16 @@ static void collapse_huge_page(struct mm_struct *mm, */ anon_vma_unlock_write(vma->anon_vma); + /* + * At this point new_page is allocated as non-encrypted. + * If VMA's KeyID is non-zero, we need to prepare it to be encrypted + * before coping data. + */ + if (vma_keyid(vma)) { + prep_encrypted_page(new_page, HPAGE_PMD_ORDER, + vma_keyid(vma), false); + } + __collapse_huge_page_copy(pte, new_page, vma, address, pte_ptl); pte_unmap(pte); __SetPageUptodate(new_page); -- 2.21.0