From patchwork Wed Sep 25 15:48:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamas K Lengyel X-Patchwork-Id: 11160989 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 C765717D4 for ; Wed, 25 Sep 2019 15:51:14 +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 ADA5121D7A for ; Wed, 25 Sep 2019 15:51:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ADA5121D7A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.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 1iD9Yd-00023J-6M; Wed, 25 Sep 2019 15:50:23 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iD9Yb-000220-Op for xen-devel@lists.xenproject.org; Wed, 25 Sep 2019 15:50:21 +0000 X-Inumbo-ID: 13934be6-dfac-11e9-8628-bc764e2007e4 Received: from mga12.intel.com (unknown [192.55.52.136]) by localhost (Halon) with ESMTPS id 13934be6-dfac-11e9-8628-bc764e2007e4; Wed, 25 Sep 2019 15:49:36 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Sep 2019 08:49:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,548,1559545200"; d="scan'208";a="193812688" Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.252.129.153]) by orsmga006.jf.intel.com with ESMTP; 25 Sep 2019 08:49:35 -0700 From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 25 Sep 2019 08:48:51 -0700 Message-Id: <92649106a0d6651ebc8cf42a381418a9c1c8890c.1569425745.git.tamas.lengyel@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [RFC PATCH for-next 13/18] x86/mem_sharing: ASSERT that p2m_set_entry succeeds X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Tamas K Lengyel , Tamas K Lengyel , Wei Liu , George Dunlap , Andrew Cooper , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Signed-off-by: Tamas K Lengyel --- xen/arch/x86/mm/mem_sharing.c | 46 +++++++++++++++++------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index a7b9665c8b..99f24fcf6c 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -1113,39 +1113,37 @@ int add_to_physmap(struct domain *sd, unsigned long sgfn, shr_handle_t sh, goto err_unlock; } + /* + * Must succeed, we just read the entry and hold the p2m lock + * via get_two_gfns. + */ ret = p2m_set_entry(p2m, _gfn(cgfn), smfn, PAGE_ORDER_4K, p2m_ram_shared, a); + ASSERT(!ret); - /* Tempted to turn this into an assert */ - if ( ret ) + /* + * There is a chance we're plugging a hole where a paged out + * page was. + */ + if ( p2m_is_paging(cmfn_type) && (cmfn_type != p2m_ram_paging_out) ) { - mem_sharing_gfn_destroy(spage, cd, gfn_info); - put_page_and_type(spage); - } else { + atomic_dec(&cd->paged_pages); /* - * There is a chance we're plugging a hole where a paged out - * page was. + * Further, there is a chance this was a valid page. + * Don't leak it. */ - if ( p2m_is_paging(cmfn_type) && (cmfn_type != p2m_ram_paging_out) ) + if ( mfn_valid(cmfn) ) { - atomic_dec(&cd->paged_pages); - /* - * Further, there is a chance this was a valid page. - * Don't leak it. - */ - if ( mfn_valid(cmfn) ) - { - struct page_info *cpage = mfn_to_page(cmfn); + struct page_info *cpage = mfn_to_page(cmfn); - if ( !get_page(cpage, cd) ) - { - domain_crash(cd); - ret = -EOVERFLOW; - goto err_unlock; - } - put_page_alloc_ref(cpage); - put_page(cpage); + if ( !get_page(cpage, cd) ) + { + domain_crash(cd); + ret = -EOVERFLOW; + goto err_unlock; } + put_page_alloc_ref(cpage); + put_page(cpage); } }