From patchwork Fri Apr 29 17:42:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamas K Lengyel X-Patchwork-Id: 8984411 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EFC2C9F372 for ; Fri, 29 Apr 2016 17:45:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 094D2201C8 for ; Fri, 29 Apr 2016 17:45:53 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0271A2014A for ; Fri, 29 Apr 2016 17:45:52 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1awCRV-0003ht-MP; Fri, 29 Apr 2016 17:43:05 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1awCRU-0003hn-3i for xen-devel@lists.xenproject.org; Fri, 29 Apr 2016 17:43:04 +0000 Received: from [85.158.137.68] by server-1.bemta-3.messagelabs.com id 3C/6B-07924-72D93275; Fri, 29 Apr 2016 17:43:03 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpkkeJIrShJLcpLzFFi42K5GHp/q67aXOV wg3crtC2+b5nM5MDocfjDFZYAxijWzLyk/IoE1ozrc9awFPyQq7j9eTVLA+M6iS5GLg4hgVmM EjPmf2LqYuTkkBB4xyKxe6M6hB0j0dj6iwXCrpJYfuEHI4gtJKAhcftmIztEcz+TxLaOb2AJN gFtibbXu1hBbBEBJYl7qyYzgRQxC/QxSTRMfgaWEBawkjjz9hjYNhYBVYmfL7eyg9i8As4Sm+ 9OZ4fYJidxefoDtgmMvAsYGVYxqhenFpWlFula6CUVZaZnlOQmZuboGhoY6+WmFhcnpqfmJCY V6yXn525iBAYEAxDsYLzQ7nyIUZKDSUmU96qucrgQX1J+SmVGYnFGfFFpTmrxIUYZDg4lCV72 OUA5waLU9NSKtMwcYGjCpCU4eJREeANB0rzFBYm5xZnpEKlTjMYcW35fW8vEsW3qvbVMQix5+ XmpUuK8+2cDlQqAlGaU5sENgsXMJUZZKWFeRqDThHgKUotyM0tQ5V8xinMwKgnz6oIs5MnMK4 Hb9wroFCagUwQ2KYKcUpKIkJJqYIz5HLjR4VnT1PpTDhMbBE8s7xHN/jnVSfSY/cufmes5Ku5 PWieU5Pa3wsX5dIITS1l1nvPcX9wfkw4x+jlsWHKXaeapgETD08wb768NLInrZzkem8bHpdjz eT1LuPCWzwcY3mjaZJ+9Js2zzFr6NQN3XY7rhwnu6v/PXJVYZft87Q9RpbdpV5RYijMSDbWYi 4oTAQ+5GGiUAgAA X-Env-Sender: tamas.k.lengyel@gmail.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1461951781!37815204!1 X-Originating-IP: [209.85.223.181] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.34; banners=-,-,- X-VirusChecked: Checked Received: (qmail 44104 invoked from network); 29 Apr 2016 17:43:02 -0000 Received: from mail-io0-f181.google.com (HELO mail-io0-f181.google.com) (209.85.223.181) by server-8.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 29 Apr 2016 17:43:02 -0000 Received: by mail-io0-f181.google.com with SMTP id d62so114781910iof.2 for ; Fri, 29 Apr 2016 10:43:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=2azD2pZkR7mvaDKqewiB16HjlwEBLl3JutaaRnzBZ0M=; b=Lr+juLQ7ON0nU1trTT/5p0Q3Bq9nqiqU2LYuSGV2+Kan7orgXi59jsYwECAYpHRb9g fVui7f2CVdzHhVyJQZ+u6qaeBSix61651loVo7lo9dtAl8C8F9Tq4xBzuiBldj3NaQmY jpmXgLgrCRJ3KTSnCz62iYtSdtxuVc7dgwzfr3lMsDUnHnyNQX3SGegTTBH20Si8AxgA exFXEx3SGLdS8dD8ELpPhGhVWTzLDV2FOgbCk3AFxg5h8K9f6Gid+ilLxysbsF8bWEVo /qGHbiWtPXdqy8zjqRVBJvxGsNf0mqg+arhyhggK6u5xeOEvvIxPPO+S1S2HhESVhI8s +rlg== X-Gm-Message-State: AOPr4FUHbLrJpMY+XWtTk50NFvh2H9P+BSUijy8DK2NzsLiqrPRvBZPaSD51Pafna4+seQ== X-Received: by 10.107.50.10 with SMTP id y10mr25082337ioy.144.1461951781263; Fri, 29 Apr 2016 10:43:01 -0700 (PDT) Received: from l1.lan (c-73-14-35-59.hsd1.co.comcast.net. [73.14.35.59]) by smtp.gmail.com with ESMTPSA id s8sm2355228igg.9.2016.04.29.10.42.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Apr 2016 10:42:59 -0700 (PDT) From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Fri, 29 Apr 2016 11:42:56 -0600 Message-Id: <1461951776-25956-1-git-send-email-tamas@tklengyel.com> X-Mailer: git-send-email 2.8.1 Cc: Kevin Tian , Tamas K Lengyel , Keir Fraser , Jan Beulich , George Dunlap , Andrew Cooper , Jun Nakajima Subject: [Xen-devel] [PATCH v3] altp2m: Allow the hostp2m to be shared X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Don't propagate altp2m changes from ept_set_entry for memshare as memshare already has the lock. We call altp2m propagate changes once memshare successfully finishes. Allow the hostp2m entries to be of type p2m_ram_shared when applying mem_access. Also, do not trigger PoD for hostp2m when setting altp2m mem_access to be in-line with non-altp2m mem_access path. Signed-off-by: Tamas K Lengyel --- Cc: George Dunlap Cc: Keir Fraser Cc: Jan Beulich Cc: Andrew Cooper Cc: Jun Nakajima Cc: Kevin Tian v3: Add comment to the unshare routine pointing out where altp2m gets updated v2: Cosmetic fixes and addressing PoD in the commit message --- xen/arch/x86/mm/mem_sharing.c | 11 ++++++++++- xen/arch/x86/mm/p2m-ept.c | 2 +- xen/arch/x86/mm/p2m.c | 5 ++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index a522423..b6c7e33 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include "mm-locks.h" @@ -926,11 +927,12 @@ int mem_sharing_share_pages(struct domain *sd, unsigned long sgfn, shr_handle_t int ret = -EINVAL; mfn_t smfn, cmfn; p2m_type_t smfn_type, cmfn_type; + p2m_access_t cmfn_a; struct two_gfns tg; struct rmap_iterator ri; get_two_gfns(sd, sgfn, &smfn_type, NULL, &smfn, - cd, cgfn, &cmfn_type, NULL, &cmfn, + cd, cgfn, &cmfn_type, &cmfn_a, &cmfn, 0, &tg); /* This tricky business is to avoid two callers deadlocking if @@ -1026,6 +1028,12 @@ int mem_sharing_share_pages(struct domain *sd, unsigned long sgfn, shr_handle_t /* We managed to free a domain page. */ atomic_dec(&nr_shared_mfns); atomic_inc(&nr_saved_mfns); + + /* Save the change to the altp2m tables as well if active */ + if ( altp2m_active(cd) ) + p2m_altp2m_propagate_change(cd, _gfn(cgfn), smfn, PAGE_ORDER_4K, + p2m_ram_shared, cmfn_a); + ret = 0; err_out: @@ -1222,6 +1230,7 @@ int __mem_sharing_unshare_page(struct domain *d, put_page_and_type(old_page); private_page_found: + /* The following will also update the altp2m tables (if any) */ if ( p2m_change_type_one(d, gfn, p2m_ram_shared, p2m_ram_rw) ) { gdprintk(XENLOG_ERR, "Could not change p2m type d %hu gfn %lx.\n", diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c index 1ed5b47..ff84242 100644 --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -847,7 +847,7 @@ out: if ( is_epte_present(&old_entry) ) ept_free_entry(p2m, &old_entry, target); - if ( rc == 0 && p2m_is_hostp2m(p2m) ) + if ( rc == 0 && p2m_is_hostp2m(p2m) && p2mt != p2m_ram_shared ) p2m_altp2m_propagate_change(d, _gfn(gfn), mfn, order, p2mt, p2ma); return rc; diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 6eef2f3..2a42b91 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1765,11 +1765,10 @@ int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m, /* Check host p2m if no valid entry in alternate */ if ( !mfn_valid(mfn) ) { - mfn = hp2m->get_entry(hp2m, gfn_l, &t, &old_a, - P2M_ALLOC | P2M_UNSHARE, &page_order, NULL); + mfn = hp2m->get_entry(hp2m, gfn_l, &t, &old_a, 0, &page_order, NULL); rc = -ESRCH; - if ( !mfn_valid(mfn) || t != p2m_ram_rw ) + if ( !mfn_valid(mfn) || (t != p2m_ram_rw && t != p2m_ram_shared) ) return rc; /* If this is a superpage, copy that first */