Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3404720imm; Tue, 17 Jul 2018 04:25:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdGfU64swOr9nOo++auSm12NkMarBTx1Wup/GTGiPznq5vVOxUkcbq4XOVBDTpzheJbTxTo X-Received: by 2002:a65:4b87:: with SMTP id t7-v6mr1169171pgq.391.1531826707942; Tue, 17 Jul 2018 04:25:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531826707; cv=none; d=google.com; s=arc-20160816; b=ve6OzcY3wsgg8g1VtWuW+/dEGZ/PkbbN6i5tLaIQmvcOf1FZUNXyMz8xKPjGpxWLOH G7MZhkNSdssPQlbzN3AP3Gk55R3Krj+x4iE+8f7ZZGu3iD/KQ4eTRGuGgEKm5O0Rj24M 4NWbar5dYqwDSQ+c3wm7XnY4j3kYxXFxeu8lOulHUoTu1UVYzo1Sfh9gVk7rm7uIk2T+ gsPZ9+KtGel++lySD4mbw4HU2+TN/WbXe17HS/YBPiD+ZhsV54G1pZpeG5wlKDoP/mox uNa1ZjpTMnyhXRka9IrExIZNkH3WCyIM4aBRjMkOWv5POh6ADlFgteEVcytjhAjBqlWu fIRQ== 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=BdA0DU9z5lBsAeQlmDbCWQbQAp7j9iqn9HvxLk1T7cg=; b=x3CDOQS7v5oc21cUbHXWFgZapPvid8P76PI679HLToCexLPaEmjQwwNc+0x0oR9+Z3 p9kXE9ifztKFymOe9Ein4Xketnsq2lTSzDygB3p7vxvVYHmtDYQzT4P5bo5q4KgZlySn ltz9Y3rqaKgfs4hyEbZ9ChqPgYNeyZOcbmYC+tK/kiCIrwswibKiIr4taWOI+1wAB5Pt bhLShME7C/It3suiNNR/5DnOBip9SKGCR3RrITf3FABM3CbZprfK6qQM4xu0i+dw1u4t 0aUM676Bm/ReyldOD3k8KH1unYTD09nkkGOehYNeLR06OJPFvU2B+aZRQHVlHwUFgZE2 lraQ== 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 z2-v6si669201pfb.365.2018.07.17.04.24.53; Tue, 17 Jul 2018 04:25:07 -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 S1731347AbeGQLx5 (ORCPT + 99 others); Tue, 17 Jul 2018 07:53:57 -0400 Received: from mga04.intel.com ([192.55.52.120]:39978 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730839AbeGQLx4 (ORCPT ); Tue, 17 Jul 2018 07:53:56 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2018 04:21:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,365,1526367600"; d="scan'208";a="240943232" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 17 Jul 2018 04:21:42 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id CA24B321; 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 03/19] mm/ksm: Do not merge pages with different KeyIDs Date: Tue, 17 Jul 2018 14:20:13 +0300 Message-Id: <20180717112029.42378-4-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 Pages encrypted with different encryption keys are not allowed to be merged by KSM. Otherwise it would cross security boundary. Signed-off-by: Kirill A. Shutemov --- include/linux/mm.h | 7 +++++++ mm/ksm.c | 3 +++ 2 files changed, 10 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 151d6e6b16e5..a4ce26aa0b65 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1551,6 +1551,13 @@ static inline int vma_keyid(struct vm_area_struct *vma) } #endif +#ifndef page_keyid +static inline int page_keyid(struct page *page) +{ + return 0; +} +#endif + #ifdef CONFIG_SHMEM /* * The vma_is_shmem is not inline because it is used only by slow diff --git a/mm/ksm.c b/mm/ksm.c index a6d43cf9a982..1bd7b9710e29 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1214,6 +1214,9 @@ static int try_to_merge_one_page(struct vm_area_struct *vma, if (!PageAnon(page)) goto out; + if (page_keyid(page) != page_keyid(kpage)) + goto out; + /* * We need the page lock to read a stable PageSwapCache in * write_protect_page(). We use trylock_page() instead of -- 2.18.0