Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5429410imm; Tue, 12 Jun 2018 07:45:16 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIFzUp32mpxLrqxRMlYSExxlvP7hsMKsAC5mno1y01bbXiwEve/aQagRZgYNDi5vB8fujeo X-Received: by 2002:a63:3201:: with SMTP id y1-v6mr560585pgy.419.1528814716008; Tue, 12 Jun 2018 07:45:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528814715; cv=none; d=google.com; s=arc-20160816; b=lIB1UsmIfG0HUTwV779xwbZxsQfKenNWQ4aglvyOTnbSThxE1teIL8QE+5ZnaaBD9J H2ZF3EjQCWUNVOPW+JEYdhFyoGzjIvqyrsa8lof1fNYumnPokBKEDhxL+DfMpStdiAnA M3mXGznudZ4G1rZ9QRMTpdeQZm+wVYA8XUX7bBBHEExWjYvuVoulMaGaaB8/NxBag4FX slEtwSxcCvyoIXLC0u9cR8urbjZigzGg3ZKHFL+UjPcSPq9orv+qinXpfuWMaoC/khNW KAD3RbQbPvk5bFy6n0EKbFLfSZOja9Yi4OqFyODCZCmNlLsbI9ptM4pMawZUrSSKm4rq nJKg== 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=r89kyglDCikqEg56tkm9cYkCrF854HvfbX0MlI1g+7M=; b=AkM7G5nJexy131+IcXJAdaEy10d5uRg8pVc7vKRWgr/xIGpgsNuK3aPYc+YmUlnBD/ vEcvRLpEKSbblsaZZrHJsvh6jFLd+Q5Cwkput0AqvG/neZmtARjrfi0IPa3oOpVBbDLf nbdAlqJ1aShiG7VWJLYlj4C9R8dBLaE2K4A3DegHKbUsy2LlhxDuEEMbf/NBbe6E7ZRD iU91sJTbCNfm4ct1dIBLLKMa8XiOPGW7agN5a6Oe1jJ5Yyn2uZKRhCu/1AEueqGSx6m5 Ua68gijtjR/qarJBrGufDNQZhAOSoKRrQ4US0G1pV7GEAg3BGlvSUK3BKj1kw4+3Hj3i +dBg== 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 q18-v6si214718pgt.529.2018.06.12.07.45.01; Tue, 12 Jun 2018 07:45:15 -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 S934198AbeFLOjZ (ORCPT + 99 others); Tue, 12 Jun 2018 10:39:25 -0400 Received: from mga11.intel.com ([192.55.52.93]:20531 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933394AbeFLOjX (ORCPT ); Tue, 12 Jun 2018 10:39:23 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jun 2018 07:39:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,215,1526367600"; d="scan'208";a="66378483" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 12 Jun 2018 07:39:20 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 9DA52166; Tue, 12 Jun 2018 17:39:20 +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: [PATCHv3 03/17] mm/ksm: Do not merge pages with different KeyIDs Date: Tue, 12 Jun 2018 17:39:01 +0300 Message-Id: <20180612143915.68065-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180612143915.68065-1-kirill.shutemov@linux.intel.com> References: <20180612143915.68065-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 subject to KSM merge. 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 435b053c457c..ac1a8480284d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1506,6 +1506,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 7d6558f3bac9..db94bd45fe66 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1201,6 +1201,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.17.1