From nobody Mon Feb 9 13:38:16 2026 Delivered-To: importer@patchew.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 ARC-Seal: i=1; a=rsa-sha256; t=1559564919; cv=none; d=zoho.com; s=zohoarc; b=L8pHRIyYbixJ9G8vEB21x/qUEd18ypKSPficvrw+iqnr+Fq8V2THtbfwpUOuQ/LS18KFE3nyYrowAzxGtzLPXsxx7owOWyLHQ6QGSYWlUrJj/EUxkaBObEgYcxEFm9M6/rPkRK9WD/aZgaQ9qTmRKiJaL0N4sEC10kWqmavVH/g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559564919; 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=Wna5cMvyDn2STU+ltszQtuBHWpVAgdNetjcjByBrvIU=; b=eoFSiERjkqKxMOiIvMejyiuWw3ajLg4N6CV0bpbX5LI7EMDYa75TBoI1R4QZNFIAsyLFs0GZc3YGiaYDtLaiFH8902BTCACV3W2ucQ31QHaB+dP5VOoCBoD6aJPmsy6iLOfsZKz1uSWMjTEYPJlH+Y9+XOVpsqAW9fW+k8qxDCw= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1559564919303948.2907575352335; Mon, 3 Jun 2019 05:28:39 -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 1hXm3f-0002iA-HV; Mon, 03 Jun 2019 12:27:23 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXm3e-0002hz-9W for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 12:27:22 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id ee9cd0cd-85fa-11e9-8980-bc764e045a96; Mon, 03 Jun 2019 12:27:20 +0000 (UTC) X-Inumbo-ID: ee9cd0cd-85fa-11e9-8980-bc764e045a96 Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@MIAPEX02MSOL01.citrite.net 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; Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=23.29.105.83; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 23.29.105.83 as permitted sender) identity=mailfrom; client-ip=23.29.105.83; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:23.29.105.83 ip4:162.221.156.50 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@MIAPEX02MSOL01.citrite.net) identity=helo; client-ip=23.29.105.83; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@MIAPEX02MSOL01.citrite.net"; x-conformance=sidf_compatible IronPort-SDR: mFpd0BHq41rqUkknaawpmlgst8b43wtM2rGYzHUVKlX3x4UWFP0B8p6BdLHDCXipGDJ8PlBgMK hjY6m1Yx4I0TUAYyu/6YTwKZEfAkWWkFVjqv5jfNPe06KaxzE1QA+4q9Y/s8w7V1yCPNXx1kOU KfW4PH9rZGEQkXWiRQHrV1Oea5BD0eIu5ltlAbyRdLHvyIRLu/MU1bkdKxATprhmFNXQXVMKSq ecogSu31C0ZH58itwtbENSJ2A/JZwueKmjnKO3w55vCyl5h0sdg8pb38EEimgYeNWkqUtbFxAe qLY= X-SBRS: 2.7 X-MesageID: 1206003 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 23.29.105.83 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.60,546,1549947600"; d="scan'208";a="1206003" From: Andrew Cooper To: Xen-devel Date: Mon, 3 Jun 2019 13:25:25 +0100 Message-ID: <1559564728-17167-3-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1559564728-17167-1-git-send-email-andrew.cooper3@citrix.com> References: <1559564728-17167-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 2/5] xen/vm-event: Expand vm_event_* spinlock macros and rename the lock 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: Petre Pircalabu , Andrew Cooper , Tamas K Lengyel , Razvan Cojocaru Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" These serve no purpose, but to add to the congnitive load of following the code. Remove the level of indirection. Furthermore, the lock protects all data in vm_event_domain, making ring_lock a poor choice of name. For vm_event_get_response() and vm_event_grab_slot(), fold the exit paths to have a single unlock, as the compiler can't make this optimisation itself. No functional change. Signed-off-by: Andrew Cooper Acked-by: Razvan Cojocaru --- CC: Razvan Cojocaru CC: Tamas K Lengyel CC: Petre Pircalabu --- xen/common/vm_event.c | 58 ++++++++++++++++++++++++---------------------= ---- xen/include/xen/sched.h | 3 +-- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/xen/common/vm_event.c b/xen/common/vm_event.c index 902e152..db975e9 100644 --- a/xen/common/vm_event.c +++ b/xen/common/vm_event.c @@ -35,10 +35,6 @@ #define xen_rmb() smp_rmb() #define xen_wmb() smp_wmb() =20 -#define vm_event_ring_lock_init(_ved) spin_lock_init(&(_ved)->ring_lock) -#define vm_event_ring_lock(_ved) spin_lock(&(_ved)->ring_lock) -#define vm_event_ring_unlock(_ved) spin_unlock(&(_ved)->ring_lock) - static int vm_event_enable( struct domain *d, struct xen_domctl_vm_event_op *vec, @@ -66,8 +62,8 @@ static int vm_event_enable( if ( ring_gfn =3D=3D 0 ) return -EOPNOTSUPP; =20 - vm_event_ring_lock_init(*ved); - vm_event_ring_lock(*ved); + spin_lock_init(&(*ved)->lock); + spin_lock(&(*ved)->lock); =20 rc =3D vm_event_init_domain(d); =20 @@ -101,13 +97,13 @@ static int vm_event_enable( /* Initialize the last-chance wait queue. */ init_waitqueue_head(&(*ved)->wq); =20 - vm_event_ring_unlock(*ved); + spin_unlock(&(*ved)->lock); return 0; =20 err: destroy_ring_for_helper(&(*ved)->ring_page, (*ved)->ring_pg_struct); - vm_event_ring_unlock(*ved); + spin_unlock(&(*ved)->lock); xfree(*ved); *ved =3D NULL; =20 @@ -200,11 +196,11 @@ static int vm_event_disable(struct domain *d, struct = vm_event_domain **ved) { struct vcpu *v; =20 - vm_event_ring_lock(*ved); + spin_lock(&(*ved)->lock); =20 if ( !list_empty(&(*ved)->wq.list) ) { - vm_event_ring_unlock(*ved); + spin_unlock(&(*ved)->lock); return -EBUSY; } =20 @@ -226,7 +222,7 @@ static int vm_event_disable(struct domain *d, struct vm= _event_domain **ved) =20 vm_event_cleanup_domain(d); =20 - vm_event_ring_unlock(*ved); + spin_unlock(&(*ved)->lock); } =20 xfree(*ved); @@ -292,7 +288,7 @@ void vm_event_put_request(struct domain *d, =20 req->version =3D VM_EVENT_INTERFACE_VERSION; =20 - vm_event_ring_lock(ved); + spin_lock(&ved->lock); =20 /* Due to the reservations, this step must succeed. */ front_ring =3D &ved->front_ring; @@ -319,7 +315,7 @@ void vm_event_put_request(struct domain *d, !atomic_read(&curr->vm_event_pause_count) ) vm_event_mark_and_pause(curr, ved); =20 - vm_event_ring_unlock(ved); + spin_unlock(&ved->lock); =20 notify_via_xen_event_channel(d, ved->xen_port); } @@ -329,17 +325,15 @@ static int vm_event_get_response(struct domain *d, st= ruct vm_event_domain *ved, { vm_event_front_ring_t *front_ring; RING_IDX rsp_cons; + int rc =3D 0; =20 - vm_event_ring_lock(ved); + spin_lock(&ved->lock); =20 front_ring =3D &ved->front_ring; rsp_cons =3D front_ring->rsp_cons; =20 if ( !RING_HAS_UNCONSUMED_RESPONSES(front_ring) ) - { - vm_event_ring_unlock(ved); - return 0; - } + goto out; =20 /* Copy response */ memcpy(rsp, RING_GET_RESPONSE(front_ring, rsp_cons), sizeof(*rsp)); @@ -353,9 +347,12 @@ static int vm_event_get_response(struct domain *d, str= uct vm_event_domain *ved, * there may be additional space available in the ring. */ vm_event_wake(d, ved); =20 - vm_event_ring_unlock(ved); + rc =3D 1; =20 - return 1; + out: + spin_unlock(&ved->lock); + + return rc; } =20 /* @@ -455,35 +452,38 @@ void vm_event_cancel_slot(struct domain *d, struct vm= _event_domain *ved) if( !vm_event_check_ring(ved) ) return; =20 - vm_event_ring_lock(ved); + spin_lock(&ved->lock); vm_event_release_slot(d, ved); - vm_event_ring_unlock(ved); + spin_unlock(&ved->lock); } =20 static int vm_event_grab_slot(struct vm_event_domain *ved, int foreign) { unsigned int avail_req; + int rc; =20 if ( !ved->ring_page ) return -EOPNOTSUPP; =20 - vm_event_ring_lock(ved); + spin_lock(&ved->lock); =20 avail_req =3D vm_event_ring_available(ved); + + rc =3D -EBUSY; if ( avail_req =3D=3D 0 ) - { - vm_event_ring_unlock(ved); - return -EBUSY; - } + goto out; =20 if ( !foreign ) ved->target_producers++; else ved->foreign_producers++; =20 - vm_event_ring_unlock(ved); + rc =3D 0; =20 - return 0; + out: + spin_unlock(&ved->lock); + + return rc; } =20 /* Simple try_grab wrapper for use in the wait_event() macro. */ diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 2201fac..b9691fc 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -282,8 +282,7 @@ struct vcpu /* VM event */ struct vm_event_domain { - /* ring lock */ - spinlock_t ring_lock; + spinlock_t lock; /* The ring has 64 entries */ unsigned char foreign_producers; unsigned char target_producers; --=20 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel