From patchwork Tue Jul 17 11:20:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A . Shutemov" X-Patchwork-Id: 10529035 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 463A2600F4 for ; Tue, 17 Jul 2018 11:22:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3535D28C0F for ; Tue, 17 Jul 2018 11:22:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 28FB228C30; Tue, 17 Jul 2018 11:22:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDA9328C0F for ; Tue, 17 Jul 2018 11:22:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C5496B0278; Tue, 17 Jul 2018 07:21:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8F2EF6B027A; Tue, 17 Jul 2018 07:21:58 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7235C6B027D; Tue, 17 Jul 2018 07:21:58 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f198.google.com (mail-pf0-f198.google.com [209.85.192.198]) by kanga.kvack.org (Postfix) with ESMTP id 0C9406B027A for ; Tue, 17 Jul 2018 07:21:58 -0400 (EDT) Received: by mail-pf0-f198.google.com with SMTP id a20-v6so403433pfi.1 for ; Tue, 17 Jul 2018 04:21:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=1JfmGhf63B9qVo/Yyw7P7n6ggQFGNCanuLYWxtd4MeE=; b=E99f0g4RZYZPWNtNl9FYGeLFinmMIuYkhxoih1r8WATDD3XXmowWkPBxu0Y1WOsJl6 q/uW1vSueGy+DKyQAaVtwIq+xhNXogDJTHSKNQSHV3+fU8TNb+rDVSDr2vYXAVI/6IaP dxxznRXlbfphfJS8ElJcF7I/lzAQ1yauDX+u6TkX+gq48TvUeQ/swdk8d+MHbQbkXIv9 CqmMBzDGd1xs66bkrXYb4Y69Oj/CFEYNAtWBO2o9Dtilcn9693fXa8eEiX7Mcclmb56F +9rtirhLId64q8calNdRHggrRTXpDV+qbKi3SIB9tnBSEfdHYKGCU/rkOPApdhjloiur vS+w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AOUpUlG0go9+TpCHHjk0b4+hE+cgYkP3RF9OgYZBsAGBu9C9YAkPsBEm Z8AnCg3J0pIETMlI0utsKEE6X4Kof8t0SPwlGmrfUBpeAPVZxwjF1hF+0/Mg1aipsuyn+Dpi7ZE 8ZB7aeIB2CPNaO2QGHHTonOwWtknXM7luFjoLugJfVIsCZ4HOICHvl/HhugbIgncoWQ== X-Received: by 2002:a62:4909:: with SMTP id w9-v6mr283151pfa.154.1531826517758; Tue, 17 Jul 2018 04:21:57 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfnPE8ulUop9oh70e4keDPGpOmhpc26Mn5bjjEA35xf8gW75NW7b/KVjxNqVsaj/S09QlA8 X-Received: by 2002:a62:4909:: with SMTP id w9-v6mr283124pfa.154.1531826517170; Tue, 17 Jul 2018 04:21:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531826517; cv=none; d=google.com; s=arc-20160816; b=DWa4jNWnKFOnFIHL+WnywF/dm1wGpvjPN0LKZtEUFgiJsIvR/06fFzd5FQSYi+e7Eo t1bk0/LDQtpkudU/rm9SI/FgXsTQaiMHLgxIJE5DxJnMUS5Vd8USf4oT+AdYwG1ISgen nV/VWUPn+ZMmUpUQO5AUHpaQI4kZlqIGzclWIqywJYhUtfSMEhWaKiz7J5dgyNarpzo/ rFmXumc/6A7RoKaSiL7MjrUNABLB0Lib1c6M1y69X0PiTk37dMkvOEP4Wvqt33bnhMro fnQVtAEXNhKFrSz+799KsQMfYeGNS3sd3m5HJtNPGI5LXOKvZRNeJn0C2wrSunTjvGu8 H9Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=1JfmGhf63B9qVo/Yyw7P7n6ggQFGNCanuLYWxtd4MeE=; b=rivlsL0wCrJZ060gUYVSAWlVoldlxdSQKGXsX84Obr5+8yAPVURemC4CzGvhPRysv0 /+zFx1NUXqLtEGeRCplpQxXuR5wscZffivq97P3DH/74S+nevE/eUSd18WjfBBDu/XSG PtViuUmx8VKCZNBm4VMBFEkQRyS/aY8oAfsh0zGUKB0rhmxr1G7InaC8uEc6ECMw6IK5 7AGfiwVFlaHOt0K3AYjAgEhPRvXbiW9lCRQdoFM91hgd0OW8pOYIQG9A8CGHhIEUu8Lp LWbTbWr9XNU943mvn0zcvhVtq8EkrpmcUqVXbK3GneO3acStcAmvAUJJCl9sTEVbadDx ZCog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga03.intel.com (mga03.intel.com. [134.134.136.65]) by mx.google.com with ESMTPS id u7-v6si691565pgn.194.2018.07.17.04.21.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 04:21:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.65 as permitted sender) client-ip=134.134.136.65; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.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> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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);