From patchwork Mon Dec 30 16:11:27 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: 11313357 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 54FE9159A for ; Mon, 30 Dec 2019 16:13:19 +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 3B9CA206CB for ; Mon, 30 Dec 2019 16:13:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B9CA206CB 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 1ilxeK-000288-MN; Mon, 30 Dec 2019 16:12:08 +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 1ilxeK-00027v-45 for xen-devel@lists.xenproject.org; Mon, 30 Dec 2019 16:12:08 +0000 X-Inumbo-ID: 17bd9fbf-2b1f-11ea-a04b-12813bfff9fa Received: from mga14.intel.com (unknown [192.55.52.115]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 17bd9fbf-2b1f-11ea-a04b-12813bfff9fa; Mon, 30 Dec 2019 16:11:53 +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:11:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,375,1571727600"; d="scan'208";a="221167313" 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:11:51 -0800 From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Mon, 30 Dec 2019 08:11:27 -0800 Message-Id: <398477e2e5ef5e0003e3dc4e2f9f2d5252ed6dc4.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 03/18] x86/mem_sharing: make get_two_gfns take locks conditionally 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" During VM forking the client lock will already be taken. Signed-off-by: Tamas K Lengyel Acked-by: Andrew Coopers --- xen/arch/x86/mm/mem_sharing.c | 11 ++++++----- xen/include/asm-x86/p2m.h | 10 +++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index ddf1f0f9f9..f6187403a0 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -955,7 +955,7 @@ static int share_pages(struct domain *sd, gfn_t sgfn, shr_handle_t sh, unsigned long put_count = 0; get_two_gfns(sd, sgfn, &smfn_type, NULL, &smfn, - cd, cgfn, &cmfn_type, NULL, &cmfn, 0, &tg); + cd, cgfn, &cmfn_type, NULL, &cmfn, 0, &tg, true); /* * This tricky business is to avoid two callers deadlocking if @@ -1073,7 +1073,7 @@ err_out: } int mem_sharing_add_to_physmap(struct domain *sd, unsigned long sgfn, shr_handle_t sh, - struct domain *cd, unsigned long cgfn) + struct domain *cd, unsigned long cgfn, bool lock) { struct page_info *spage; int ret = -EINVAL; @@ -1085,7 +1085,7 @@ int mem_sharing_add_to_physmap(struct domain *sd, unsigned long sgfn, shr_handle struct two_gfns tg; get_two_gfns(sd, _gfn(sgfn), &smfn_type, NULL, &smfn, - cd, _gfn(cgfn), &cmfn_type, &a, &cmfn, 0, &tg); + cd, _gfn(cgfn), &cmfn_type, &a, &cmfn, 0, &tg, lock); /* Get the source shared page, check and lock */ ret = XENMEM_SHARING_OP_S_HANDLE_INVALID; @@ -1162,7 +1162,8 @@ int mem_sharing_add_to_physmap(struct domain *sd, unsigned long sgfn, shr_handle err_unlock: mem_sharing_page_unlock(spage); err_out: - put_two_gfns(&tg); + if ( lock ) + put_two_gfns(&tg); return ret; } @@ -1583,7 +1584,7 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) sh = mso.u.share.source_handle; cgfn = mso.u.share.client_gfn; - rc = mem_sharing_add_to_physmap(d, sgfn, sh, cd, cgfn); + rc = mem_sharing_add_to_physmap(d, sgfn, sh, cd, cgfn, true); rcu_unlock_domain(cd); } diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 94285db1b4..7399c4a897 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -539,7 +539,7 @@ struct two_gfns { static inline void get_two_gfns(struct domain *rd, gfn_t rgfn, p2m_type_t *rt, p2m_access_t *ra, mfn_t *rmfn, struct domain *ld, gfn_t lgfn, p2m_type_t *lt, p2m_access_t *la, mfn_t *lmfn, - p2m_query_t q, struct two_gfns *rval) + p2m_query_t q, struct two_gfns *rval, bool lock) { mfn_t *first_mfn, *second_mfn, scratch_mfn; p2m_access_t *first_a, *second_a, scratch_a; @@ -569,10 +569,10 @@ do { \ #undef assign_pointers /* Now do the gets */ - *first_mfn = get_gfn_type_access(p2m_get_hostp2m(rval->first_domain), - gfn_x(rval->first_gfn), first_t, first_a, q, NULL); - *second_mfn = get_gfn_type_access(p2m_get_hostp2m(rval->second_domain), - gfn_x(rval->second_gfn), second_t, second_a, q, NULL); + *first_mfn = __get_gfn_type_access(p2m_get_hostp2m(rval->first_domain), + gfn_x(rval->first_gfn), first_t, first_a, q, NULL, lock); + *second_mfn = __get_gfn_type_access(p2m_get_hostp2m(rval->second_domain), + gfn_x(rval->second_gfn), second_t, second_a, q, NULL, lock); } static inline void put_two_gfns(struct two_gfns *arg)