From patchwork Tue Sep 2 15:46:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Tseglytskyi X-Patchwork-Id: 36496 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f198.google.com (mail-ig0-f198.google.com [209.85.213.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 87362203BE for ; Tue, 2 Sep 2014 15:47:56 +0000 (UTC) Received: by mail-ig0-f198.google.com with SMTP id h18sf36529498igc.9 for ; Tue, 02 Sep 2014 08:47:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=OhAlrcLmc0aDMBDdieAVJqRIQkZJnWJKu1gIsYQlEJA=; b=LcSyW1qvSvp+ZP5W9LrbkIfaQPzoQPq4jwpk4S91J1OodC491YRUNncOZ5i6ppQD+b asopCCYySh5S6hm8MwPvTGrUFEDCppc0i6LB9BlPYNEMb9lcYxUpIFP2WU/yZDrtIRbn G6U8a2JJXU3aMBN/S100qRKlRPlnkX1u9awLZ0/JqSJYkAzVLufXu6cTFPdwmkHTgzT3 TztqPqn6mOUmuxawEdCK7EM1l017ZLkSta7EYtmT7t5F21TsZ0GIAaol6oEQ/McUgTBT 0rl7aGgsDzNwp+F1xKqfMu9w6uFDVF8MtH6y+z30Y4B62yquF6aEh8R4INz92h7Grti/ xdIQ== X-Gm-Message-State: ALoCoQlomET2crGrhLh2zxqK3Wagr2ptbNPq5MtMEAePKM6okFvYbB5ZI3jT7DYg3cXpxJsGYu4V X-Received: by 10.42.207.5 with SMTP id fw5mr19025242icb.20.1409672876172; Tue, 02 Sep 2014 08:47:56 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.21.50 with SMTP id 47ls2517456qgk.6.gmail; Tue, 02 Sep 2014 08:47:56 -0700 (PDT) X-Received: by 10.220.189.3 with SMTP id dc3mr610131vcb.64.1409672876011; Tue, 02 Sep 2014 08:47:56 -0700 (PDT) Received: from mail-vc0-x22a.google.com (mail-vc0-x22a.google.com [2607:f8b0:400c:c03::22a]) by mx.google.com with ESMTPS id cv1si2493428vdc.22.2014.09.02.08.47.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Sep 2014 08:47:55 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22a as permitted sender) client-ip=2607:f8b0:400c:c03::22a; Received: by mail-vc0-f170.google.com with SMTP id la4so7337602vcb.29 for ; Tue, 02 Sep 2014 08:47:55 -0700 (PDT) X-Received: by 10.220.182.1 with SMTP id ca1mr30488148vcb.21.1409672875930; Tue, 02 Sep 2014 08:47:55 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp548578vcb; Tue, 2 Sep 2014 08:47:55 -0700 (PDT) X-Received: by 10.224.88.3 with SMTP id y3mr56809998qal.65.1409672875437; Tue, 02 Sep 2014 08:47:55 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id d5si5724270qcc.2.2014.09.02.08.47.54 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 02 Sep 2014 08:47:55 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XOqHo-0001TZ-5l; Tue, 02 Sep 2014 15:46:24 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XOqHn-0001TM-1L for xen-devel@lists.xen.org; Tue, 02 Sep 2014 15:46:23 +0000 Received: from [85.158.143.35:62229] by server-1.bemta-4.messagelabs.com id 79/5B-05872-E46E5045; Tue, 02 Sep 2014 15:46:22 +0000 X-Env-Sender: andrii.tseglytskyi@globallogic.com X-Msg-Ref: server-12.tower-21.messagelabs.com!1409672779!13166217!1 X-Originating-IP: [64.18.0.20] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 31028 invoked from network); 2 Sep 2014 15:46:21 -0000 Received: from exprod5og110.obsmtp.com (HELO exprod5og110.obsmtp.com) (64.18.0.20) by server-12.tower-21.messagelabs.com with DHE-RSA-AES256-SHA encrypted SMTP; 2 Sep 2014 15:46:21 -0000 Received: from mail-la0-f49.google.com ([209.85.215.49]) (using TLSv1) by exprod5ob110.postini.com ([64.18.4.12]) with SMTP ID DSNKVAXmSlFuLFfeDsDCaAHwmWltLFLazO/U@postini.com; Tue, 02 Sep 2014 08:46:20 PDT Received: by mail-la0-f49.google.com with SMTP id b17so7891555lan.8 for ; Tue, 02 Sep 2014 08:46:17 -0700 (PDT) X-Received: by 10.112.34.143 with SMTP id z15mr3661020lbi.86.1409672777260; Tue, 02 Sep 2014 08:46:17 -0700 (PDT) X-Received: by 10.112.34.143 with SMTP id z15mr3661010lbi.86.1409672777200; Tue, 02 Sep 2014 08:46:17 -0700 (PDT) Received: from atseglytskyi-HP.synapse.com ([195.238.93.36]) by mx.google.com with ESMTPSA id r6sm5869874lbp.29.2014.09.02.08.46.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Sep 2014 08:46:16 -0700 (PDT) From: Andrii Tseglytskyi To: Ian Campbell , Stefano Stabellini , Julien Grall , xen-devel@lists.xen.org Date: Tue, 2 Sep 2014 18:46:01 +0300 Message-Id: <1409672770-23164-2-git-send-email-andrii.tseglytskyi@globallogic.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1409672770-23164-1-git-send-email-andrii.tseglytskyi@globallogic.com> References: <1409672770-23164-1-git-send-email-andrii.tseglytskyi@globallogic.com> Subject: [Xen-devel] [PATCH v03 01/10] xen: implement guest_physmap_pin_range X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Original-Sender: andrii.tseglytskyi@globallogic.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22a as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@; dmarc=fail (p=NONE dis=NONE) header.from=globallogic.com Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: From: Stefano Stabellini guest_physmap_pin_range pins a range of guest pages so that their p2m mappings won't be changed. guest_physmap_unpin_range unpins the previously pinned pages. The pinning is done using a new count_info flag. Provide empty stubs for x86. Andrii Tseglytskyi : - rebased to latest master branch - added guest_physmap_pinned_range() API - pass mfn instead of gmfn Signed-off-by: Stefano Stabellini Signed-off-by: Andrii Tseglytskyi --- xen/arch/arm/p2m.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/mm.h | 11 +++++++ xen/include/asm-x86/p2m.h | 20 ++++++++++++ 3 files changed, 113 insertions(+) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 46ec01c..b3a16d3 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -214,6 +214,79 @@ err: return maddr; } +int guest_physmap_pin_range(struct domain *d, + xen_pfn_t mfn, + unsigned int order) +{ + int i; + struct page_info *page; + + for ( i = 0; i < (1UL << order); i++ ) + { + if ( !mfn_valid(mfn + i) ) + return -EINVAL; + + page = mfn_to_page(mfn + i); + if ( !page ) + return -EINVAL; + + if ( !get_page_type(page, PGT_writable_page) ) + return -EINVAL; + + if ( test_and_set_bit(_PGC_p2m_pinned, &page->count_info) ) + return -EBUSY; + } + return 0; +} + +int guest_physmap_unpin_range(struct domain *d, + xen_pfn_t mfn, + unsigned int order) +{ + int i; + struct page_info *page; + + for ( i = 0; i < (1UL << order); i++ ) + { + if ( !mfn_valid(mfn + i) ) + return -EINVAL; + + page = mfn_to_page(mfn + i); + if ( !page ) + return -EINVAL; + + if ( !test_and_clear_bit(_PGC_p2m_pinned, &page->count_info) ) + return -EINVAL; + } + return 0; +} + +int guest_physmap_pinned_range(struct domain *d, + xen_pfn_t mfn, + unsigned int order) +{ + int i, pins = 0; + struct page_info *page; + + for ( i = 0; i < (1UL << order); i++ ) + { + if ( !mfn_valid(mfn + i) ) + return 0; + + page = mfn_to_page(mfn + i); + if ( !page ) + return 0; + + if ( test_bit(_PGC_p2m_pinned, &page->count_info) ) + pins++; + } + + if ( i && (i == pins) ) + return 1; + + return 0; +} + int guest_physmap_mark_populate_on_demand(struct domain *d, unsigned long gfn, unsigned int order) @@ -478,10 +551,18 @@ static int apply_one_level(struct domain *d, struct p2m_domain *p2m = &d->arch.p2m; lpae_t pte; const lpae_t orig_pte = *entry; + struct page_info *page = NULL; int rc; BUG_ON(level > 3); + if ( guest_physmap_pinned_range(d, orig_pte.p2m.base, 0) ) + { + gdprintk(XENLOG_WARNING, "cannot change p2m mapping for paddr=%"PRIpaddr + " domid=%d, the page is pinned count_info %lu\n", *addr, d->domain_id, page->count_info); + return -EINVAL; + } + switch ( op ) { case ALLOCATE: @@ -819,6 +900,7 @@ static int apply_p2m_changes(struct domain *d, &addr, &maddr, &flush, mattr, t); if ( ret < 0 ) { rc = ret ; goto out; } + /* L3 had better have done something! We cannot descend any further */ BUG_ON(ret == P2M_ONE_DESCEND); count += ret; diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h index 9fa80a4..f6d9e6b 100644 --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -92,6 +92,10 @@ struct page_info /* Page is Xen heap? */ #define _PGC_xen_heap PG_shift(2) #define PGC_xen_heap PG_mask(1, 2) +/* The page belongs to a guest and it has been pinned. */ +#define _PGC_p2m_pinned PG_shift(3) +#define PGC_p2m_pinned PG_mask(1, 3) + /* ... */ /* Page is broken? */ #define _PGC_broken PG_shift(7) @@ -340,6 +344,13 @@ void free_init_memory(void); int guest_physmap_mark_populate_on_demand(struct domain *d, unsigned long gfn, unsigned int order); +int guest_physmap_pin_range(struct domain *d, paddr_t mfn, + unsigned int order); +int guest_physmap_unpin_range(struct domain *d, paddr_t mfn, + unsigned int order); +int guest_physmap_pinned_range(struct domain *d, paddr_t mfn, + unsigned int order); + extern void put_page_type(struct page_info *page); static inline void put_page_and_type(struct page_info *page) { diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 39f235d..c7f12b1 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -514,6 +514,26 @@ void guest_physmap_remove_page(struct domain *d, int guest_physmap_mark_populate_on_demand(struct domain *d, unsigned long gfn, unsigned int order); +static inline int guest_physmap_pin_range(struct domain *d, + paddr_t mfn, + unsigned int order) +{ + return -ENOSYS; +} +static inline int guest_physmap_unpin_range(struct domain *d, + paddr_t mfn, + unsigned int order) +{ + return -ENOSYS; +} + +static inline int guest_physmap_pinned_range(struct domain *d, + paddr_t mfn, + unsigned int order) +{ + return -ENOSYS; +} + /* Change types across all p2m entries in a domain */ void p2m_change_entry_type_global(struct domain *d, p2m_type_t ot, p2m_type_t nt);