From patchwork Tue Jul 17 11:20:12 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: 10528993 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 9C414600F4 for ; Tue, 17 Jul 2018 11:21:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A87028C34 for ; Tue, 17 Jul 2018 11:21:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EC4028CB4; Tue, 17 Jul 2018 11:21:48 +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=ham 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 10D9328D0D for ; Tue, 17 Jul 2018 11:21:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0427C6B0007; Tue, 17 Jul 2018 07:21:47 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 026B66B0008; Tue, 17 Jul 2018 07:21:46 -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 E52A76B0008; Tue, 17 Jul 2018 07:21:46 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f70.google.com (mail-pl0-f70.google.com [209.85.160.70]) by kanga.kvack.org (Postfix) with ESMTP id A38016B0006 for ; Tue, 17 Jul 2018 07:21:46 -0400 (EDT) Received: by mail-pl0-f70.google.com with SMTP id 39-v6so459247ple.6 for ; Tue, 17 Jul 2018 04:21:46 -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=rQaO/JVc0AS/aRRbgD9fSDKHD3P+GEP7QoyaRik/99g=; b=WZn2iNF2tDY3U3kCZ44z7AP0q5+TaAw/5Eo9izGLJGd/ff1hbsAiLiEJsFw7+4V0XV 0NRykDeyDYxmJOWlRaY9w8gFj50FtXpWsNbfmr/OXDh6cbLDJWGhhwbPB9m1P5wUm6/u 8NrXdDpBotmYPKHZd7/Wb3fch2kZaZiqJj19ehX1DGXNfJnAMN8qYsmCgKf0V8CRPFyW agYy+XYtp50XoETBFm/3m/6hVTdr5LszXrwQyJWt3gup2bi9W6uB6FRRYw6vFZxLvGeB VpI6fZes/EyO4ucy4WFJSoMbWpBUxOj/faCo+yO73P/xzf9/zX+QXnNqYwOMxk0j7+9F sDhA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.151 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: AOUpUlGu64LBe7aUwr4ar5+yzpE9cSJcOhyelRKGq3n9vtWnkNxnqMEY +UthUeG06OEHuZ/VrGFEcH6yYePtVMyk/eaW7SsHCD7Wuupz8D5TIEtgagHllLtbt0y3CrxMAfQ T7RBP2QQbjXvgBIWsB0ev+vJiLxqle63crUzXyvWLOp3egNuNEgN3lHDoBHa4q3FMng== X-Received: by 2002:a17:902:7888:: with SMTP id q8-v6mr1238688pll.79.1531826506350; Tue, 17 Jul 2018 04:21:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdfGGX8rabVGG+DsC4cCVdaCuEzhY3yrllj3rbIuiECXgq1cy/JsOV9pSqRR06NaLuQjSmD X-Received: by 2002:a17:902:7888:: with SMTP id q8-v6mr1238646pll.79.1531826505552; Tue, 17 Jul 2018 04:21:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531826505; cv=none; d=google.com; s=arc-20160816; b=k/SAHbueaPO2bSA+ziwP6dIcUtZQRTyV4C6Mqfisi90vh4FsdBRQPHy9msD1++jqba 6HbJtLmYMTqKGcZfd4x5JkrN0MTNTPgwvSYkkBFJDZV3BjRxHFuFAF7xiIufYSpwSlx/ MfBW6O8lJihqR8p8lInvEECgk1YBa0XmiaXlF5bs5HqOCQ81lD4qCMlEU+iCLnO/fqy0 QviBiGpQXFBPwSA/si+fJyQb4yKWcMEFakXya7E22rEYwvDsNgyyqoVTJQ5MY9Xl1BAK /S+8hI1FE39rsTGNTXiOxrrm5vJVr78QLzy6GRwXVMlbMogx6WoyCqcO9Xg/lS6dhuzK I32g== 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=rQaO/JVc0AS/aRRbgD9fSDKHD3P+GEP7QoyaRik/99g=; b=djlm1rzQYBq0WBYI8Nzalfp7T4qDv/imTMXZv8291d+2L4o0Axwtgjba3ZY0W8Y2Bc EtGgeaj0RS5SwusukeM+sUC9jUFEO5d8pfTljd1n5yZ+SeLGhtxC8OYubgU1J+HJrhQd mT+HLFcbWfvtq69ssI7TEkj2tKj7AuycXaCNk8SCh0YFQmWJlg5jsIPYlsRWRpPO9bKI /iRZY3eUEuV+jyC+qC1Y3NBlnyjkMZMQGUm3/RDmhs4bA8nR9BenqC/CGqxeaxe1+I+s HgRBBNHeNWQlvuAnz9wn9hiBCGZ7+7HjSlL3HHcU1kPVCxx6n1N1Wmt9ZLNRufVMnd33 PGpg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga17.intel.com (mga17.intel.com. [192.55.52.151]) by mx.google.com with ESMTPS id f62-v6si697286pfg.165.2018.07.17.04.21.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 04:21:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.151 as permitted sender) client-ip=192.55.52.151; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.151 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 orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2018 04:21:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,365,1526367600"; d="scan'208";a="57138270" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga007.jf.intel.com with ESMTP; 17 Jul 2018 04:21:42 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id BA0A9309; 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 02/19] mm: Do not use zero page in encrypted pages Date: Tue, 17 Jul 2018 14:20:12 +0300 Message-Id: <20180717112029.42378-3-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 Zero page is not encrypted and putting it into encrypted VMA produces garbage. We can map zero page with KeyID-0 into an encrypted VMA, but this would be violation security boundary between encryption domains. Forbid zero pages in encrypted VMAs. Signed-off-by: Kirill A. Shutemov --- arch/s390/include/asm/pgtable.h | 2 +- include/linux/mm.h | 4 ++-- mm/huge_memory.c | 3 +-- mm/memory.c | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h index 5ab636089c60..2e8658962aae 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -505,7 +505,7 @@ static inline int mm_alloc_pgste(struct mm_struct *mm) * In the case that a guest uses storage keys * faults should no longer be backed by zero pages */ -#define mm_forbids_zeropage mm_has_pgste +#define vma_forbids_zeropage(vma) mm_has_pgste(vma->vm_mm) static inline int mm_uses_skeys(struct mm_struct *mm) { #ifdef CONFIG_PGSTE diff --git a/include/linux/mm.h b/include/linux/mm.h index c8780c5835ad..151d6e6b16e5 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -92,8 +92,8 @@ extern int mmap_rnd_compat_bits __read_mostly; * s390 does this to prevent multiplexing of hardware bits * related to the physical page in case of virtualization. */ -#ifndef mm_forbids_zeropage -#define mm_forbids_zeropage(X) (0) +#ifndef vma_forbids_zeropage +#define vma_forbids_zeropage(vma) vma_keyid(vma) #endif /* diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 1cd7c1a57a14..83f096c7299b 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -676,8 +676,7 @@ int do_huge_pmd_anonymous_page(struct vm_fault *vmf) return VM_FAULT_OOM; if (unlikely(khugepaged_enter(vma, vma->vm_flags))) return VM_FAULT_OOM; - if (!(vmf->flags & FAULT_FLAG_WRITE) && - !mm_forbids_zeropage(vma->vm_mm) && + if (!(vmf->flags & FAULT_FLAG_WRITE) && !vma_forbids_zeropage(vma) && transparent_hugepage_use_zero_page()) { pgtable_t pgtable; struct page *zero_page; diff --git a/mm/memory.c b/mm/memory.c index 02fbef2bd024..a705637d2ded 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3139,8 +3139,7 @@ static int do_anonymous_page(struct vm_fault *vmf) return 0; /* Use the zero-page for reads */ - if (!(vmf->flags & FAULT_FLAG_WRITE) && - !mm_forbids_zeropage(vma->vm_mm)) { + if (!(vmf->flags & FAULT_FLAG_WRITE) && !vma_forbids_zeropage(vma)) { entry = pte_mkspecial(pfn_pte(my_zero_pfn(vmf->address), vma->vm_page_prot)); vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd,