From nobody Tue Nov 11 08:32:43 2025 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1569426662; cv=none; d=zoho.com; s=zohoarc; b=Fkv4C32qKTscLgt34574xFn77zkJPV49IFl5UpTeUSyqt4rhwnDZbNnDM8yPxXJvg8/n0axWjAguI2YX23E21H7dKr2L4pcURaEEIFT6dXkTguW2kvWP/TaPFWmzKthufhbTKm3EovxUxRl+I1OA1jELKg7bvybjd2mtREEm0SQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569426662; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=2MkzNmzu06lKFaYNSPpBjcjUDRl9uVGunwStJ5t3Hvc=; b=JmOO6RzgPkccY7tIpaCckA1SbU/BIWM66aM+2ELPK1OxZTFhxXmmFSzbVrM8bZOz98nvOsWHRrVke4BmELvcJm/o2LYX9QCNpvXGD37soRyOhaWMOACizp5+257dnmrRdszlMX6qbji20I2EactmkhdQB5YUiSN3Ffx+IgoObYs= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1569426662295568.5655802029128; Wed, 25 Sep 2019 08:51:02 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iD9Y3-0000uz-OC; Wed, 25 Sep 2019 15:49:47 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iD9Y2-0000uM-N4 for xen-devel@lists.xenproject.org; Wed, 25 Sep 2019 15:49:46 +0000 Received: from mga12.intel.com (unknown [192.55.52.136]) by localhost (Halon) with ESMTPS id 114983be-dfac-11e9-8628-bc764e2007e4; Wed, 25 Sep 2019 15:49:33 +0000 (UTC) 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:30 -0700 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:30 -0700 X-Inumbo-ID: 114983be-dfac-11e9-8628-bc764e2007e4 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,548,1559545200"; d="scan'208";a="193812645" From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Wed, 25 Sep 2019 08:48:43 -0700 Message-Id: <6dcafecd884999e288eeab0347c7814808b137e2.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 05/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=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 --- 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 8ad6cf3850..df308a75cd 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -954,7 +954,7 @@ static int share_pages(struct domain *sd, gfn_t sgfn, s= hr_handle_t sh, unsigned long put_count =3D 0; =20 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); =20 /* * This tricky business is to avoid two callers deadlocking if @@ -1068,7 +1068,7 @@ err_out: } =20 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 =3D -EINVAL; @@ -1080,7 +1080,7 @@ int mem_sharing_add_to_physmap(struct domain *sd, uns= igned long sgfn, shr_handle struct two_gfns tg; =20 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); =20 /* Get the source shared page, check and lock */ ret =3D XENMEM_SHARING_OP_S_HANDLE_INVALID; @@ -1155,7 +1155,8 @@ int mem_sharing_add_to_physmap(struct domain *sd, uns= igned 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; } =20 @@ -1574,7 +1575,7 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_= sharing_op_t) arg) sh =3D mso.u.share.source_handle; cgfn =3D mso.u.share.client_gfn; =20 - rc =3D mem_sharing_add_to_physmap(d, sgfn, sh, cd, cgfn); + rc =3D mem_sharing_add_to_physmap(d, sgfn, sh, cd, cgfn, true); =20 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 =20 /* Now do the gets */ - *first_mfn =3D get_gfn_type_access(p2m_get_hostp2m(rval->first_domain= ), - gfn_x(rval->first_gfn), first_t, fir= st_a, q, NULL); - *second_mfn =3D get_gfn_type_access(p2m_get_hostp2m(rval->second_domai= n), - gfn_x(rval->second_gfn), second_t, s= econd_a, q, NULL); + *first_mfn =3D __get_gfn_type_access(p2m_get_hostp2m(rval->first_doma= in), + gfn_x(rval->first_gfn), first_t, f= irst_a, q, NULL, lock); + *second_mfn =3D __get_gfn_type_access(p2m_get_hostp2m(rval->second_dom= ain), + gfn_x(rval->second_gfn), second_t,= second_a, q, NULL, lock); } =20 static inline void put_two_gfns(struct two_gfns *arg) --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel