From patchwork Tue Jun 12 14:39:01 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: 10460489 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 A45D3602A0 for ; Tue, 12 Jun 2018 14:39:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84685287AB for ; Tue, 12 Jun 2018 14:39:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73F4C287E3; Tue, 12 Jun 2018 14:39: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=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 99FF6287AB for ; Tue, 12 Jun 2018 14:39:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7665B6B0005; Tue, 12 Jun 2018 10:39:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 745486B0008; Tue, 12 Jun 2018 10:39:25 -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 62C9C6B000A; Tue, 12 Jun 2018 10:39:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f72.google.com (mail-pl0-f72.google.com [209.85.160.72]) by kanga.kvack.org (Postfix) with ESMTP id 25B246B0005 for ; Tue, 12 Jun 2018 10:39:25 -0400 (EDT) Received: by mail-pl0-f72.google.com with SMTP id q18-v6so9397921pll.3 for ; Tue, 12 Jun 2018 07:39:25 -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=r89kyglDCikqEg56tkm9cYkCrF854HvfbX0MlI1g+7M=; b=OS5ohj92r31JN65MDxs5bAWNBC+PQbBXQBhfC3hneqtWQZ7KXgTYVpkotk7HqV/pYb 1PU2OsWF9vxe+Z1EpFkXut4bZl6sCBKqy1mpYPTqs59l9EPhX1XvujLg5AsMDFvrkyeG EsQfTnoZ8oE2jKJ0rBYHH8wqaASMUchu0yFhp8Me9TkRzAKqTER8jPWVvUhB9QsVCmfm xcveWGc1dGH5XBhEPtPcXtLGTSoxjIF0qjUh3JmUXHHmRMbv6z5yCuor8hNXwOMqS/XC o8LY+gsHW1NuKh5XHjs9WD8lpErpXHiwAtyhTMkuVC23Olex92fBkkd0621QHSqVdgSW gwIA== 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.126 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: APt69E27sf2mGo/opWwHgTm78JiA5z1A7/rJanlgltmgaHrlVKgVYDxj klfQBLkgDOgfqcuiGu6vFNE7vSjP+ZgO+LwAePLE5uy6+UqrpXgI+Vw1bx7BEf220o1aCUSrsCZ 7W4FRLx8GqrlEiQN2pZx3STCKRpUT4vZIX63cDrRkn7E2rT0/gcCbx74KF7BIeri/fQ== X-Received: by 2002:a17:902:b28c:: with SMTP id u12-v6mr750521plr.68.1528814364844; Tue, 12 Jun 2018 07:39:24 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI8oEqjpbegg1zsDVKA3vLGmu1n3twta7xKZkbxdDrNb/uNAt/8/dO8Poz8eR3OSTKp1meA X-Received: by 2002:a17:902:b28c:: with SMTP id u12-v6mr750476plr.68.1528814364018; Tue, 12 Jun 2018 07:39:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528814363; cv=none; d=google.com; s=arc-20160816; b=0EXK/9G1uRsA7E89VtyDhmAHAlBiy9gwvvW44dT7g3QrK1LnTqtAnUXOyBSWPM1Ps8 PJD8DD5ewuKurFi2f74GQktAsdhsnQbZmW+98RZHApaHGQsAB+55ZT9d/krgENw82BLB UIaHS9n2KqvvILaZ2SJKhZXarPJ7UMZwYm3AxF9AFJeSS3hHX03Lru294v/i0j/1Gx1U ZKgvpCXanCiHPZAEaL9Irgo5yyQWYVHJ/fDInzpz8AYvrRnXGAUvKWVqgZo+QRLkGtyh L8rI8Phz4tsIPqwGzP+FhIoCZO0xHpkKAO+6BZPGPIOgUoj6P/roLXXfZEmKbXmEwTmb CqHw== 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=r89kyglDCikqEg56tkm9cYkCrF854HvfbX0MlI1g+7M=; b=D3EqZiigHz7kntQq57HbA6Y/RB1zmC95bX/G/EJ4X0TNVXy+vpzjxXavY6J51iGHFY KiYJSENaxPWNt36xLzb8tjp1tm2BuD3cPp00ghVQypG+oH24i1aqF8h/CssC0vGnm7bU z5TrF+z+Z9HnRSr4q0ITcfIBkOSPlbHY3PxX77K177S+FlFMvCUkH/rTzX9sjPEg0s+2 9ss2M2yjUDU49dSMCikEF4jedMrEulGI4InfwnOEanwpuMxPg2uj6NgTEFHTPR1bJ72U 7tGGDWOt/2WPSHBYf1Gq7rXOptC14gpNR0/qgmswf+jki0LesuB+5WCqjQwld/Ln+wJb FRfA== 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.126 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga18.intel.com (mga18.intel.com. [134.134.136.126]) by mx.google.com with ESMTPS id w1-v6si242590pgp.10.2018.06.12.07.39.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jun 2018 07:39:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.126 as permitted sender) client-ip=134.134.136.126; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.126 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 orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.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> 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 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