From patchwork Mon Dec 30 16:11:38 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: 11313349 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 23D97139A for ; Mon, 30 Dec 2019 16:13:13 +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 09EC820722 for ; Mon, 30 Dec 2019 16:13:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 09EC820722 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 1ilxej-0002RQ-07; Mon, 30 Dec 2019 16:12:33 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ilxeg-0002PY-U1 for xen-devel@lists.xenproject.org; Mon, 30 Dec 2019 16:12:30 +0000 X-Inumbo-ID: 1c8738b6-2b1f-11ea-a914-bc764e2007e4 Received: from mga14.intel.com (unknown [192.55.52.115]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1c8738b6-2b1f-11ea-a914-bc764e2007e4; Mon, 30 Dec 2019 16:12:02 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Dec 2019 08:12:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,375,1571727600"; d="scan'208";a="221167363" Received: from tlengyel-mobl2.amr.corp.intel.com (HELO localhost.localdomain) ([10.254.94.206]) by orsmga003.jf.intel.com with ESMTP; 30 Dec 2019 08:12:00 -0800 From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Mon, 30 Dec 2019 08:11:38 -0800 Message-Id: <0f92c0ee2861775e682fd6e89202c80315ff2ac3.1577721845.git.tamas.lengyel@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 14/18] x86/mem_sharing: check page type count earlier 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 | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index baa3e35ded..ecbe40545d 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -652,19 +652,18 @@ static int page_make_sharable(struct domain *d, return -EBUSY; } - /* Change page type and count atomically */ - if ( !get_page_and_type(page, d, PGT_shared_page) ) + /* Check if page is already typed and bail early if it is */ + if ( (page->u.inuse.type_info & PGT_count_mask) != 1 ) { spin_unlock(&d->page_alloc_lock); - return -EINVAL; + return -EEXIST; } - /* Check it wasn't already sharable and undo if it was */ - if ( (page->u.inuse.type_info & PGT_count_mask) != 1 ) + /* Change page type and count atomically */ + if ( !get_page_and_type(page, d, PGT_shared_page) ) { spin_unlock(&d->page_alloc_lock); - put_page_and_type(page); - return -EEXIST; + return -EINVAL; } /*