From patchwork Tue Jul 17 11:20:13 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: 10529007 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 5CA65600F4 for ; Tue, 17 Jul 2018 11:21:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39766205A8 for ; Tue, 17 Jul 2018 11:21:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D42F28A8C; Tue, 17 Jul 2018 11:21:59 +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 CACE1205A8 for ; Tue, 17 Jul 2018 11:21:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B8DF46B000E; Tue, 17 Jul 2018 07:21:49 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B3CA26B0010; Tue, 17 Jul 2018 07:21:49 -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 A06046B0266; Tue, 17 Jul 2018 07:21:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id 54E5C6B0010 for ; Tue, 17 Jul 2018 07:21:49 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id q18-v6so464554pll.3 for ; Tue, 17 Jul 2018 04:21:49 -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=BdA0DU9z5lBsAeQlmDbCWQbQAp7j9iqn9HvxLk1T7cg=; b=uCLFISO2o7VofIGeiGUjKSO0Sw8M2342PSWGQO0hcdHiLOitGGy+l+J7/GQcCyNl/D Rm826m2q9uN5FPcQ/BlX/yhPFIVuwtgRGoGBm1UmlFNqqIyz9qFXBdb0yH7lainqmAKw fcnE0shYCJo08gUU6ec2EOLd1Vf9pTDcuZKlAsDsFQtGIYd0m2HXt/1In1v06tOXcOhw tckzCcnCImxxY1zsL/EkCGxoPXPzXkdyuitLWU9k27ikMzKm4Ty5U0Ek8zl6b6vfSHdp 2+n28hYmxCmJcMFR9wUags8W4mWwUYzAUbu6gRfavdwrNekQjRozlCGIkAF5CV9nyInb Za2A== 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.100 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: AOUpUlH6PlJSpqaoeHlIm7LlJDwslxtZLSbE1v5nU0AtJcOLLljBz51j OgjGntersDbodSXbwNSc3UgAyxl1yC3GGLTPAHC+3/cLS+iG/MkAmsq3IATrV3FGWABAglX7IRH YYWqsSR2FhRwr/RM4OdDsPm6mdD0NJv3L/ifdITN4AH/zJ2/aPzrzz325YA4V1D39mw== X-Received: by 2002:a63:5fc1:: with SMTP id t184-v6mr1146620pgb.183.1531826509059; Tue, 17 Jul 2018 04:21:49 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc8o99adB4FtB0jdPYOxQSUVuWm9bfnesKd5b6yTcMYW1qP8NkhZLYZj2/R2liIajzlP0vj X-Received: by 2002:a63:5fc1:: with SMTP id t184-v6mr1146591pgb.183.1531826508437; Tue, 17 Jul 2018 04:21:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531826508; cv=none; d=google.com; s=arc-20160816; b=rmIMKUfdwp3k3cFzdpQi5QOMPKar3zvveDDswpDkNHsjNSUVontErvGYMB3UCfjADE oQo1U0mM5CK9xcP4ikFwYZDbZ1lq/+z3a8P/QQMJbma1KRp8YyCvz/o0ICnJgu9hA6yS GgtiGGviaC4Vj08G2rkOOL+SYyZcG84mdMpSFof4HuZKlkxFjacmsIzQqFbJCTAWrdsJ QRDFEBw1hxtwyZOH7CwAQwJpJyVyhhZpmOXyDbn8sNOfi3ty3KGHBX3hN/TpHikfP1Pg 9OgdwVhwL++rsS+/GD9aD/tVcYORg1tAKTsS4V7ZnJkknQl3nI2GEhNM652gzPAxiuRb Fhpg== 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=BdA0DU9z5lBsAeQlmDbCWQbQAp7j9iqn9HvxLk1T7cg=; b=aZM8BYipoQNwb0UV6C9DJm9j/GHzTL0N6oHvhaQmsE7pc3Prq2BsC2wuayTUVtnT5u xNORRx7FLLGKNfxiAcEJmHvKVK5aie8pBv5N0GFi6O+uUo2YYCeClXXijVYvwbJ/oVvP 6oUGBlXVOFaFUJaUjXO0UOz8D43JzaLC9Q1MR/jU21Pq8bok5yJLM2DzTXDcID6M6mkL M1jEJsHPP43gRJD51/yK/5QStUcwfurMRUvyKotcjWzsxWacS5x3UF2kyu9BY2QRsWYs jIRMyP96A0914fUbGyUDzI0u+z48hje0YnE0s4cTt6BoX6wDOUPC/8p2uqb60fFRmUGs RS8g== 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.100 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga07.intel.com (mga07.intel.com. [134.134.136.100]) by mx.google.com with ESMTPS id 186-v6si752417pff.270.2018.07.17.04.21.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 04:21:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.100 as permitted sender) client-ip=134.134.136.100; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.100 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 orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2018 04:21:47 -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> 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 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