Received: by 10.223.185.116 with SMTP id b49csp2774030wrg; Mon, 5 Mar 2018 08:28:54 -0800 (PST) X-Google-Smtp-Source: AG47ELtbTBvl22nDI4lmgj8n0ukCSTF9b2v2H6ABHLSET9gpq/VmxP9bSy4qNpmBfle7OR9lhN4r X-Received: by 10.167.129.195 with SMTP id c3mr15830199pfn.14.1520267334440; Mon, 05 Mar 2018 08:28:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520267334; cv=none; d=google.com; s=arc-20160816; b=LNtcLyYtUBxV5XocCvp3mBHdFWQjFbGidL7dCbF7OrPO/1JexWgCC00SFGu9LsSwdR thvbK539P2zHI22caKy4EJmjUq6T2dw6n2cHyT0Bie0EQAKNBOs40BG22XYwcEyFpLoM xLxSu9gDSfCwKyxXK5KEvtHFtNXYCrbQChFHXdiW3vH8jqhMPZ0M3xjgQ497VgttRf9P e9f5cTLoXsItdXae+KOI/rlMPf7HaqxInTHpbcWc5wlrvjniI4O0fK0O/3LOQLIOAk1k q24OGR+Iysd94eIYHVpj/tQbI+C5yl1/ze9aN3b6xZFeFghGHiiSToF6Ukh0im5qTty9 2neA== 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=w90H/L+vNT2KEhpYGugcRG9X4/OZLBbf32tGNVk1/vQ=; b=u5XpQ+lPQitAIoboYxxoGPb/xxrisVm+4Qydqhu7W0jUig8PBKgXcP67BRhVXa3hpu qMC7EDMvkpaiIfd+HzzZO8CqsR3f0PcEKL5baxYLqBEgYIGloWj2tUEiGi26Ed6+q1t6 1mTYNH5hTON067reYS6WEyNuG7ITxugQuCqsjqDx/fhTLfxOeRMLAAcM0btGHaLD3RjN PMq0R+ZenBPiepetwEe5b+N/Sflp3LfYdZU3jZlnxfp8I5//PmigbAUeBL+LZIegqENE /WnA/mx2+Lbidwya2Up0iQqxaaVy+M7qXN3LjTo5eoYDxjIHAI9L4v1M7Q4Nq29BkXNW k9OQ== 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 g86si2338979pfk.94.2018.03.05.08.28.40; Mon, 05 Mar 2018 08:28:54 -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 S1752786AbeCEQ1K (ORCPT + 99 others); Mon, 5 Mar 2018 11:27:10 -0500 Received: from mga07.intel.com ([134.134.136.100]:9033 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752674AbeCEQ0c (ORCPT ); Mon, 5 Mar 2018 11:26:32 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2018 08:26:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,427,1515484800"; d="scan'208";a="39349304" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 05 Mar 2018 08:26:27 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id BD7EE6EC; 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 19/22] x86/mm: Implement free_encrypt_page() Date: Mon, 5 Mar 2018 19:26:07 +0300 Message-Id: <20180305162610.37510-20-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 As on allocation of encrypted page, we need to flush cache before returning page to free pool. Failing to do this may lead to data corruption. Signed-off-by: Kirill A. Shutemov --- arch/x86/mm/mktme.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/x86/mm/mktme.c b/arch/x86/mm/mktme.c index 1129ad25b22a..ef0eb1eb8d6e 100644 --- a/arch/x86/mm/mktme.c +++ b/arch/x86/mm/mktme.c @@ -45,6 +45,19 @@ void prep_encrypt_page(struct page *page, gfp_t gfp, unsigned int order) WARN_ONCE(gfp & __GFP_ZERO, "__GFP_ZERO is useless for encrypted pages"); } +void free_encrypt_page(struct page *page, int keyid, unsigned int order) +{ + int i; + void *v; + + for (i = 0; i < (1 << order); i++) { + v = kmap_atomic_keyid(page, keyid + i); + /* See comment in prep_encrypt_page() */ + clflush_cache_range(v, PAGE_SIZE); + kunmap_atomic(v); + } +} + struct page *__alloc_zeroed_encrypted_user_highpage(gfp_t gfp, struct vm_area_struct *vma, unsigned long vaddr) { -- 2.16.1