From patchwork Thu Sep 26 09:46:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11162213 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 4F11513B1 for ; Thu, 26 Sep 2019 09:52:32 +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 2B6392053B for ; Thu, 26 Sep 2019 09:52:32 +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="ZNXcGJTg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2B6392053B 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 1iDQR8-0002q3-N5; Thu, 26 Sep 2019 09:51:46 +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 1iDQR7-0002nx-Bn for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 09:51:45 +0000 X-Inumbo-ID: 3d71c8d9-e043-11e9-964d-12813bfff9fa Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by localhost (Halon) with ESMTPS id 3d71c8d9-e043-11e9-964d-12813bfff9fa; Thu, 26 Sep 2019 09:51:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1569491502; x=1601027502; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=gUmQxE1/9r+oWcjOQYQcyyS1mWBwuNCjdmshVcZJotg=; b=ZNXcGJTg5oQelB9faY9mTIi6pA/ByJUR6Q5opV9f48GUtZRxtzEsIlwn i/nh7Fjgo58xNbPCmveCHIlgP8r8bWMn+U6GmwgE/pMn4YEooTw7ZXdcm jeVrKOD7XvZ6zK2EIT/AVJt5YcNUj14sDg7Zk4uSWkTlpBpFTvD7TwNRg k=; X-IronPort-AV: E=Sophos;i="5.64,551,1559520000"; d="scan'208";a="836989166" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-1a-e34f1ddc.us-east-1.amazon.com) ([10.47.22.34]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 26 Sep 2019 09:49:54 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1a-e34f1ddc.us-east-1.amazon.com (Postfix) with ESMTPS id B9086A26A7; Thu, 26 Sep 2019 09:49:41 +0000 (UTC) Received: from EX13D28EUB004.ant.amazon.com (10.43.166.176) 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:22 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX13D28EUB004.ant.amazon.com (10.43.166.176) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 26 Sep 2019 09:49:21 +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:17 +0000 From: To: Date: Thu, 26 Sep 2019 10:46:32 +0100 Message-ID: <71e585138508d7d46c5349f72e1dfd3df8f2b595.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 69/84] page_alloc: comments on (un)mapping pages in xenheap allocations. 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 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 4ec6299ba8..a00db4c0d9 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -2212,6 +2212,10 @@ void *alloc_xenheap_pages(unsigned int order, unsigned int memflags) pg[i].count_info |= PGC_xen_heap; ret = page_to_virt(pg); + /* + * The direct map is not always mapped now. We need to populate the direct + * map region on demand for security. + */ map_pages_to_xen((unsigned long)ret, page_to_mfn(pg), 1UL << order, PAGE_HYPERVISOR); @@ -2234,6 +2238,7 @@ void free_xenheap_pages(void *v, unsigned int order) pg[i].count_info &= ~PGC_xen_heap; ASSERT((unsigned long)v >= DIRECTMAP_VIRT_START); + /* Tear down the 1:1 mapping in this region for memory safety. */ map_pages_to_xen((unsigned long)v, INVALID_MFN, 1UL << order, _PAGE_NONE); free_heap_pages(pg, order, true);