Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3402690imm; Tue, 17 Jul 2018 04:22:50 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcwaDtExuVjCA2p9ZIqjtsiyUaNMoWwJd7sEdi2sXGfOU4jK/OoAEdYjyGeqL6Y5TU9OEIX X-Received: by 2002:a63:790b:: with SMTP id u11-v6mr1186579pgc.111.1531826570768; Tue, 17 Jul 2018 04:22:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531826570; cv=none; d=google.com; s=arc-20160816; b=aruOMyQkWVnGZEtOPBFmkfKkFKKaYaOXE4OdVSOAgDkF6yj4ZP6qgoVsyMWwKaKSN1 VODFAmLV2Dw+0kA+BCy8Dq5vt0plCAACyl0P0ReQVYdSZaTCWvKIczm3m1JXTlBqRbCb dTQ8pZ7ssdG33Zx6bTLa6bgc3lS6HYqicd6iId9K2CTC5bVB/5ZQiMd2k43+eLiTNm1s ZYZkDKeYny6HN8QUN9RRBGLipE2ul7MRLGzugK72QSaI3SXmTMKXajtIX8MWpJ9pDM1z MNWA/NzhQ4EhXE+kUOmOp4bH9Hwzo2T2wZBlHhyGHwn4zZqz2oUa6+ekFKDnMIk3/mFW 42Nw== 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=1JfmGhf63B9qVo/Yyw7P7n6ggQFGNCanuLYWxtd4MeE=; b=Bk4jcQC5udVcmxB5BQQVQ+vpYQ+n9HYjywiZMh3WimnVgJ18qcpTB+KDO6QN8r6STw 3HVD+zJqA59uOsIiiSQV+dTiwTWHInQseoYVGbwSX7fTsfEmY5ZpvLtgffzCb4NXdebB 7a1Xv7ffVUqbmwEyXD5T8rrBfns5HWsyKj332jTq/RcrJEjoJUUFvIKenZfO/6oENY9J +gMhy6M+0WedaP+gblvDNbuhtfJO0pxvTVjIMBHq5Wc2AgAeydlF33Zd4qenXULTZvnO mRIv4Va50EOyhJYpqXB185fFO4jiXYgsAjjXDSouEzjfFGc/H87tQPULdCmkDTJXciUj sj4Q== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r3-v6si652459pgg.201.2018.07.17.04.22.35; Tue, 17 Jul 2018 04:22:50 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731586AbeGQLyF (ORCPT + 99 others); Tue, 17 Jul 2018 07:54:05 -0400 Received: from mga14.intel.com ([192.55.52.115]:5664 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731468AbeGQLyF (ORCPT ); Tue, 17 Jul 2018 07:54:05 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2018 04:21:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,365,1526367600"; d="scan'208";a="55628002" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga008.fm.intel.com with ESMTP; 17 Jul 2018 04:21:45 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id ED3753BF; Tue, 17 Jul 2018 14:21:48 +0300 (EEST) From: "Kirill A. Shutemov" To: Ingo Molnar , x86@kernel.org, Thomas Gleixner , "H. Peter Anvin" , Tom Lendacky Cc: Dave Hansen , Kai Huang , Jacob Pan , linux-kernel@vger.kernel.org, linux-mm@kvack.org, "Kirill A. Shutemov" Subject: [PATCHv5 06/19] mm/khugepaged: Handle encrypted pages Date: Tue, 17 Jul 2018 14:20:16 +0300 Message-Id: <20180717112029.42378-7-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180717112029.42378-1-kirill.shutemov@linux.intel.com> References: <20180717112029.42378-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 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 5ae34097aed1..d116f4ebb622 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1056,6 +1056,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.18.0