From patchwork Thu Sep 26 09:46:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11162217 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF32413B1 for ; Thu, 26 Sep 2019 09:52:48 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AA1DB2053B for ; Thu, 26 Sep 2019 09:52:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="klB5hPvP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AA1DB2053B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDQRP-0003Cy-L9; Thu, 26 Sep 2019 09:52:03 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDQRP-0003C3-0u for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 09:52:03 +0000 X-Inumbo-ID: 49a35e3d-e043-11e9-964d-12813bfff9fa Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by localhost (Halon) with ESMTPS id 49a35e3d-e043-11e9-964d-12813bfff9fa; Thu, 26 Sep 2019 09:52:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1569491522; x=1601027522; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=0ZRTMVyTxhD3UAeSMOjD2jf6Xx+XUFYSwEDGxF69GA4=; b=klB5hPvPOZyF0u6evgDbtwEM+jan6klo47etBMPz5hJAi/hGWTOv8lTt nvlnUstQZEQTAaj6MVHvtfsTxqEY7f8bz/wShi8aHiONpExUj0PXJS5HQ GHCrE1CxYMCewjoSSLSYfIJHSjFaz7LfU0FgR8yloQ5Wk+4+DCHGC84S8 Q=; X-IronPort-AV: E=Sophos;i="5.64,551,1559520000"; d="scan'208";a="704637566" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-1e-62350142.us-east-1.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 26 Sep 2019 09:49:54 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1e-62350142.us-east-1.amazon.com (Postfix) with ESMTPS id 75CDEA21D2; Thu, 26 Sep 2019 09:49:38 +0000 (UTC) Received: from EX13D28EUB003.ant.amazon.com (10.43.166.124) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 26 Sep 2019 09:49:17 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX13D28EUB003.ant.amazon.com (10.43.166.124) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 26 Sep 2019 09:49:16 +0000 Received: from u9d785c4ba99158.ant.amazon.com (10.125.106.58) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Thu, 26 Sep 2019 09:49:13 +0000 From: To: Date: Thu, 26 Sep 2019 10:46:31 +0100 Message-ID: <30e7ab0c4eff006d752ecd004cd1f0130ef52536.1569489002.git.hongyax@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [RFC PATCH 68/84] page_alloc: actually do the mapping and unmapping on xenheap. X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Hongyan Xia , George Dunlap , Andrew Cooper , Konrad Rzeszutek Wilk , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Hongyan Xia Signed-off-by: Hongyan Xia --- xen/common/page_alloc.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 7cb1bd368b..4ec6299ba8 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -2143,6 +2143,7 @@ void init_xenheap_pages(paddr_t ps, paddr_t pe) void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) { struct page_info *pg; + void *ret; ASSERT(!in_irq()); @@ -2151,7 +2152,10 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) if ( unlikely(pg == NULL) ) return NULL; - memguard_unguard_range(page_to_virt(pg), 1 << (order + PAGE_SHIFT)); + ret = page_to_virt(pg); + memguard_unguard_range(ret, 1 << (order + PAGE_SHIFT)); + map_pages_to_xen((unsigned long)ret, page_to_mfn(pg), + 1UL << order, PAGE_HYPERVISOR); return page_to_virt(pg); } @@ -2165,6 +2169,8 @@ void free_xenheap_pages(void *v, unsigned int order) return; memguard_guard_range(v, 1 << (order + PAGE_SHIFT)); + ASSERT((unsigned long)v >= DIRECTMAP_VIRT_START); + map_pages_to_xen((unsigned long)v, INVALID_MFN, 1UL << order, _PAGE_NONE); free_heap_pages(virt_to_page(v), order, false); } @@ -2189,6 +2195,7 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) { struct page_info *pg; unsigned int i; + void *ret; ASSERT(!in_irq()); @@ -2204,7 +2211,11 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) for ( i = 0; i < (1u << order); i++ ) pg[i].count_info |= PGC_xen_heap; - return page_to_virt(pg); + ret = page_to_virt(pg); + map_pages_to_xen((unsigned long)ret, page_to_mfn(pg), + 1UL << order, PAGE_HYPERVISOR); + + return ret; } void free_xenheap_pages(void *v, unsigned int order) @@ -2222,6 +2233,9 @@ void free_xenheap_pages(void *v, unsigned int order) for ( i = 0; i < (1u << order); i++ ) pg[i].count_info &= ~PGC_xen_heap; + ASSERT((unsigned long)v >= DIRECTMAP_VIRT_START); + map_pages_to_xen((unsigned long)v, INVALID_MFN, 1UL << order, _PAGE_NONE); + free_heap_pages(pg, order, true); }