From nobody Sun May 5 04:31:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1622114908; cv=none; d=zohomail.com; s=zohoarc; b=gAbgDtQt5tuViLIxTcXL9u5c44bNi+rcOUTmuptB8oINIoFjnectEQxpJh9ELs/azxB+2o9zyXf/C0i6r0G/3McF2jjk/S0D4GSZ6sZpr2a6Xnup5KHAA9hmlXvfgiCKgNz9hsH54+g3VRUermJyiuUneUqTGka0Rm4Uf/V19lc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622114908; 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; bh=b6aTSYEJ4zMIzcsHnssUxQ3Bp2aABIpTEIa3bDkYDGg=; b=LbeZyzWhjRRX1bnr+CMjfTfmFIDdOCpXcVxINAe3KQuf2NiwG7nYbWJAPVuHDe3vS99V/KMkHRIqrWAHAa7/7iNsDNIhGbsN/4Nr153FUBBxq29o6aFNWeduP3wwyN+djLIC7WPx+45OtdSUykl8GXOOH5op0mPWz+5VLH+fR2w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine 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 1622114908514965.4382675016489; Thu, 27 May 2021 04:28:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.133020.248036 (Exim 4.92) (envelope-from ) id 1lmEBS-0000DU-KV; Thu, 27 May 2021 11:28:14 +0000 Received: by outflank-mailman (output) from mailman id 133020.248036; Thu, 27 May 2021 11:28:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lmEBS-0000DN-HZ; Thu, 27 May 2021 11:28:14 +0000 Received: by outflank-mailman (input) for mailman id 133020; Thu, 27 May 2021 11:28:13 +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.92) (envelope-from ) id 1lmEBR-0000DD-6l for xen-devel@lists.xenproject.org; Thu, 27 May 2021 11:28:13 +0000 Received: from smtp-out1.suse.de (unknown [195.135.220.28]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b9f8fd59-2afa-49d5-b336-e0008c844830; Thu, 27 May 2021 11:28:12 +0000 (UTC) Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9829D218DD; Thu, 27 May 2021 11:28:11 +0000 (UTC) Received: from director2.suse.de (director2.suse-dmz.suse.de [192.168.254.72]) by imap.suse.de (Postfix) with ESMTPSA id 6653611A98; Thu, 27 May 2021 11:28:11 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b9f8fd59-2afa-49d5-b336-e0008c844830 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1622114891; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b6aTSYEJ4zMIzcsHnssUxQ3Bp2aABIpTEIa3bDkYDGg=; b=acmKoGYDeHF6DyeYESAaaMb1IsZc3GKsB6z74gGCyYraRgBjoalxJAAq/olGOXV3UARR7v mBckfAt+971c2kTSy84zXDvvaKDqZQRTdWh53ADL6NedLlQ5QeU+yUzG9WWfbP0d8OcZ1h iVArkE/bcz5klrhJAx9n5n8vN5ap8a8= Subject: [PATCH v6 1/3] evtchn: slightly defer lock acquire where possible From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Ian Jackson , Julien Grall , Wei Liu , Stefano Stabellini , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= References: <01bbf3d4-ca6a-e837-91fe-b34aa014564c@suse.com> Message-ID: <5939858e-1c7c-5658-bc2d-0c9024c74040@suse.com> Date: Thu, 27 May 2021 13:28:07 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: <01bbf3d4-ca6a-e837-91fe-b34aa014564c@suse.com> Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" port_is_valid() and evtchn_from_port() are fine to use without holding any locks. Accordingly acquire the per-domain lock slightly later in evtchn_close() and evtchn_bind_vcpu(). Signed-off-by: Jan Beulich Acked-by: Roger Pau Monn=C3=A9 --- v6: Re-base for re-ordering / shrinking of series. v4: New. --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -606,17 +606,14 @@ int evtchn_close(struct domain *d1, int int port2; long rc =3D 0; =20 - again: - spin_lock(&d1->event_lock); - if ( !port_is_valid(d1, port1) ) - { - rc =3D -EINVAL; - goto out; - } + return -EINVAL; =20 chn1 =3D evtchn_from_port(d1, port1); =20 + again: + spin_lock(&d1->event_lock); + /* Guest cannot close a Xen-attached event channel. */ if ( unlikely(consumer_is_xen(chn1)) && guest ) { @@ -1041,16 +1038,13 @@ long evtchn_bind_vcpu(unsigned int port, if ( (v =3D domain_vcpu(d, vcpu_id)) =3D=3D NULL ) return -ENOENT; =20 - spin_lock(&d->event_lock); - if ( !port_is_valid(d, port) ) - { - rc =3D -EINVAL; - goto out; - } + return -EINVAL; =20 chn =3D evtchn_from_port(d, port); =20 + spin_lock(&d->event_lock); + /* Guest cannot re-bind a Xen-attached event channel. */ if ( unlikely(consumer_is_xen(chn)) ) { From nobody Sun May 5 04:31:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1622114932; cv=none; d=zohomail.com; s=zohoarc; b=dUJuwTI+ywKQz7uZywZSMsTjeK3mpAuIzuw+LfiE7BUSf21pNenFBQ9q3rEtg5FdO04GObu6IP0j4TMwmP2NJvqQD5nVQRMTDgUanBA6JRau5c8cBVq/qMo3Y5Vx9aoWVZNi70W/TMZn8tTVGukbUob19SBuD6SFTiKt1aHkpOA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622114932; 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; bh=CyjWzZjN/Vq2WXc19AjsyaFDZn+HLKqQXYu8edCK+Vc=; b=HzGaHTp8E7rek0rSNkre1urtRnY2UdOTf0FVVwbx1Yy19eg6sVRimEdBSxfc69Zj1r3L85feGkhHqycGRrVYnlhGQU/fKaiFIfhAWx9kP6iWU0kGWkHIR/WdFd+q6RF67WTRqjnwTii5AF8c7v9aUZEyGT2GDPM66tRFgU0asQM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine 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 1622114932568711.5166795188596; Thu, 27 May 2021 04:28:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.133022.248047 (Exim 4.92) (envelope-from ) id 1lmEBs-0000le-W9; Thu, 27 May 2021 11:28:40 +0000 Received: by outflank-mailman (output) from mailman id 133022.248047; Thu, 27 May 2021 11:28:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lmEBs-0000lX-SH; Thu, 27 May 2021 11:28:40 +0000 Received: by outflank-mailman (input) for mailman id 133022; Thu, 27 May 2021 11:28:39 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lmEBr-0000lM-OX for xen-devel@lists.xenproject.org; Thu, 27 May 2021 11:28:39 +0000 Received: from smtp-out2.suse.de (unknown [195.135.220.29]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ccfcc1ee-1dbb-455d-bd5f-db6eeff6947e; Thu, 27 May 2021 11:28:38 +0000 (UTC) Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 063A51FD2E; Thu, 27 May 2021 11:28:38 +0000 (UTC) Received: from director2.suse.de (director2.suse-dmz.suse.de [192.168.254.72]) by imap.suse.de (Postfix) with ESMTPSA id CC96211A98; Thu, 27 May 2021 11:28:37 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ccfcc1ee-1dbb-455d-bd5f-db6eeff6947e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1622114918; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CyjWzZjN/Vq2WXc19AjsyaFDZn+HLKqQXYu8edCK+Vc=; b=mvj530uTOp1qx/bWOOlC07BLw+nhdeqY1ck6hybsZwIxQnyejbDdrXT5FUMKG63fsSekXR R8f533asQK2vnvpwpKqIAvJggbkJaIH8j35D1TdHnJKE9kvZZvMzAuz6I54GPWjSZ3VJn5 tW+LPqPLAv/40pBUBG3xHx9UgC0/4Og= Subject: [PATCH v6 2/3] evtchn: add helper for port_is_valid() + evtchn_from_port() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Ian Jackson , Julien Grall , Wei Liu , Stefano Stabellini , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= References: <01bbf3d4-ca6a-e837-91fe-b34aa014564c@suse.com> Message-ID: <76106d2d-6219-bbb1-ee06-601da6f40673@suse.com> Date: Thu, 27 May 2021 13:28:37 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: <01bbf3d4-ca6a-e837-91fe-b34aa014564c@suse.com> Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" The combination is pretty common, so adding a simple local helper seems worthwhile. Make it const- and type-correct, in turn requiring the two called function to also be const-correct (and at this occasion also make them type-correct). Signed-off-by: Jan Beulich Acked-by: Julien Grall --- v6: Re-base, also for re-ordering / shrinking of series. v4: New. --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -147,6 +147,12 @@ static bool virq_is_global(unsigned int return true; } =20 +static struct evtchn *_evtchn_from_port(const struct domain *d, + evtchn_port_t port) +{ + return port_is_valid(d, port) ? evtchn_from_port(d, port) : NULL; +} + static void free_evtchn_bucket(struct domain *d, struct evtchn *bucket) { if ( !bucket ) @@ -319,7 +325,6 @@ static long evtchn_alloc_unbound(evtchn_ return rc; } =20 - static void double_evtchn_lock(struct evtchn *lchn, struct evtchn *rchn) { ASSERT(lchn !=3D rchn); @@ -365,9 +370,9 @@ static long evtchn_bind_interdomain(evtc ERROR_EXIT(lport); lchn =3D evtchn_from_port(ld, lport); =20 - if ( !port_is_valid(rd, rport) ) + rchn =3D _evtchn_from_port(rd, rport); + if ( !rchn ) ERROR_EXIT_DOM(-EINVAL, rd); - rchn =3D evtchn_from_port(rd, rport); if ( (rchn->state !=3D ECS_UNBOUND) || (rchn->u.unbound.remote_domid !=3D ld->domain_id) ) ERROR_EXIT_DOM(-EINVAL, rd); @@ -602,15 +607,12 @@ static long evtchn_bind_pirq(evtchn_bind int evtchn_close(struct domain *d1, int port1, bool guest) { struct domain *d2 =3D NULL; - struct evtchn *chn1, *chn2; - int port2; + struct evtchn *chn1 =3D _evtchn_from_port(d1, port1), *chn2; long rc =3D 0; =20 - if ( !port_is_valid(d1, port1) ) + if ( !chn1 ) return -EINVAL; =20 - chn1 =3D evtchn_from_port(d1, port1); - again: spin_lock(&d1->event_lock); =20 @@ -698,10 +700,8 @@ int evtchn_close(struct domain *d1, int goto out; } =20 - port2 =3D chn1->u.interdomain.remote_port; - BUG_ON(!port_is_valid(d2, port2)); - - chn2 =3D evtchn_from_port(d2, port2); + chn2 =3D _evtchn_from_port(d2, chn1->u.interdomain.remote_port); + BUG_ON(!chn2); BUG_ON(chn2->state !=3D ECS_INTERDOMAIN); BUG_ON(chn2->u.interdomain.remote_dom !=3D d1); =20 @@ -739,15 +739,13 @@ int evtchn_close(struct domain *d1, int =20 int evtchn_send(struct domain *ld, unsigned int lport) { - struct evtchn *lchn, *rchn; + struct evtchn *lchn =3D _evtchn_from_port(ld, lport), *rchn; struct domain *rd; int rport, ret =3D 0; =20 - if ( !port_is_valid(ld, lport) ) + if ( !lchn ) return -EINVAL; =20 - lchn =3D evtchn_from_port(ld, lport); - evtchn_read_lock(lchn); =20 /* Guest cannot send via a Xen-attached event channel. */ @@ -967,15 +965,15 @@ int evtchn_status(evtchn_status_t *statu if ( d =3D=3D NULL ) return -ESRCH; =20 - spin_lock(&d->event_lock); - - if ( !port_is_valid(d, port) ) + chn =3D _evtchn_from_port(d, port); + if ( !chn ) { - rc =3D -EINVAL; - goto out; + rcu_unlock_domain(d); + return -EINVAL; } =20 - chn =3D evtchn_from_port(d, port); + spin_lock(&d->event_lock); + if ( consumer_is_xen(chn) ) { rc =3D -EACCES; @@ -1038,11 +1036,10 @@ long evtchn_bind_vcpu(unsigned int port, if ( (v =3D domain_vcpu(d, vcpu_id)) =3D=3D NULL ) return -ENOENT; =20 - if ( !port_is_valid(d, port) ) + chn =3D _evtchn_from_port(d, port); + if ( !chn ) return -EINVAL; =20 - chn =3D evtchn_from_port(d, port); - spin_lock(&d->event_lock); =20 /* Guest cannot re-bind a Xen-attached event channel. */ @@ -1088,13 +1085,11 @@ long evtchn_bind_vcpu(unsigned int port, int evtchn_unmask(unsigned int port) { struct domain *d =3D current->domain; - struct evtchn *evtchn; + struct evtchn *evtchn =3D _evtchn_from_port(d, port); =20 - if ( unlikely(!port_is_valid(d, port)) ) + if ( unlikely(!evtchn) ) return -EINVAL; =20 - evtchn =3D evtchn_from_port(d, port); - evtchn_read_lock(evtchn); =20 evtchn_port_unmask(d, evtchn); @@ -1177,14 +1172,12 @@ static long evtchn_set_priority(const st { struct domain *d =3D current->domain; unsigned int port =3D set_priority->port; - struct evtchn *chn; + struct evtchn *chn =3D _evtchn_from_port(d, port); long ret; =20 - if ( !port_is_valid(d, port) ) + if ( !chn ) return -EINVAL; =20 - chn =3D evtchn_from_port(d, port); - evtchn_read_lock(chn); =20 ret =3D evtchn_port_set_priority(d, chn, set_priority->priority); @@ -1410,10 +1403,10 @@ void free_xen_event_channel(struct domai =20 void notify_via_xen_event_channel(struct domain *ld, int lport) { - struct evtchn *lchn, *rchn; + struct evtchn *lchn =3D _evtchn_from_port(ld, lport), *rchn; struct domain *rd; =20 - if ( !port_is_valid(ld, lport) ) + if ( !lchn ) { /* * Make sure ->is_dying is read /after/ ->valid_evtchns, pairing @@ -1424,8 +1417,6 @@ void notify_via_xen_event_channel(struct return; } =20 - lchn =3D evtchn_from_port(ld, lport); - if ( !evtchn_read_trylock(lchn) ) return; =20 @@ -1580,12 +1571,14 @@ static void domain_dump_evtchn_info(stru =20 spin_lock(&d->event_lock); =20 - for ( port =3D 1; port_is_valid(d, port); ++port ) + for ( port =3D 1; ; ++port ) { - const struct evtchn *chn; + const struct evtchn *chn =3D _evtchn_from_port(d, port); char *ssid; =20 - chn =3D evtchn_from_port(d, port); + if ( !chn ) + break; + if ( chn->state =3D=3D ECS_FREE ) continue; =20 --- a/xen/include/xen/event.h +++ b/xen/include/xen/event.h @@ -120,7 +120,7 @@ static inline void evtchn_read_unlock(st read_unlock(&evtchn->lock); } =20 -static inline bool_t port_is_valid(struct domain *d, unsigned int p) +static inline bool port_is_valid(const struct domain *d, evtchn_port_t p) { if ( p >=3D read_atomic(&d->valid_evtchns) ) return false; @@ -135,7 +135,8 @@ static inline bool_t port_is_valid(struc return true; } =20 -static inline struct evtchn *evtchn_from_port(struct domain *d, unsigned i= nt p) +static inline struct evtchn *evtchn_from_port(const struct domain *d, + evtchn_port_t p) { if ( p < EVTCHNS_PER_BUCKET ) return &d->evtchn[array_index_nospec(p, EVTCHNS_PER_BUCKET)]; From nobody Sun May 5 04:31:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1622114954; cv=none; d=zohomail.com; s=zohoarc; b=Cf/MXpnDynmbmLpVIb9qRZW4HqiW+q+b5PN6ZpQqjbt+ch1QeoLM7SqJVB53hqawZhmLpnNp5jjK0/h3h4o75z/bi0rBpIPTNh2xGhiMZOc36rkf+KhexshYywnnXhcjnDXx8QojO25kKLI3Dm4qtl4C8fR9nQ8xTvFOxdN0nVQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622114954; 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; bh=Qa0Zu1mlw1DByVU5m9GtwBNK3+ZFmTcifmkaJak5uN8=; b=V94ZzmVmmVD7M+r7pnhuajIRZaW0Lgt92UThivf3VAZuAlIe/jfVOJ0D7BiEjoHD/0Slbh+1j1EH/MoTJdo9CCiUC2fDvyfVEPz1dNsvZsy9vrO12kx8Z1OGpP2qSxxGyMZWJ40h0pLX7La3Q7y9u4RWoE3V4hxWfr8I5y4Tn6Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine 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 1622114954871837.9307442402427; Thu, 27 May 2021 04:29:14 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.133027.248057 (Exim 4.92) (envelope-from ) id 1lmECE-0001Km-8p; Thu, 27 May 2021 11:29:02 +0000 Received: by outflank-mailman (output) from mailman id 133027.248057; Thu, 27 May 2021 11:29:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lmECE-0001Kf-58; Thu, 27 May 2021 11:29:02 +0000 Received: by outflank-mailman (input) for mailman id 133027; Thu, 27 May 2021 11:29:01 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lmECD-0001H9-9o for xen-devel@lists.xenproject.org; Thu, 27 May 2021 11:29:01 +0000 Received: from smtp-out1.suse.de (unknown [195.135.220.28]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ccd41df2-1a00-4c88-b47c-5a3e3295610c; Thu, 27 May 2021 11:29:00 +0000 (UTC) Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B92B2218DD; Thu, 27 May 2021 11:28:59 +0000 (UTC) Received: from director2.suse.de (director2.suse-dmz.suse.de [192.168.254.72]) by imap.suse.de (Postfix) with ESMTPSA id 89EBA11A98; Thu, 27 May 2021 11:28:59 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ccd41df2-1a00-4c88-b47c-5a3e3295610c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1622114939; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qa0Zu1mlw1DByVU5m9GtwBNK3+ZFmTcifmkaJak5uN8=; b=d+b+azCuQyhsO/FD1UhTHtvaamexyHVttDUtgvuCVkKpDRVdJJn1InNe1ALl1V5+1vrRgY Zwg+6cEZjmwGb2H83o+yRriuFsXz1aqqPvBJAUCTFC+w7H1bCRhU1X1G9enZgB3c0jMM1v GTCXDSE2vdFln/wWaohvCRlqP8xvQnk= Subject: [PATCH v6 3/3] evtchn: type adjustments From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Ian Jackson , Julien Grall , Wei Liu , Stefano Stabellini , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= References: <01bbf3d4-ca6a-e837-91fe-b34aa014564c@suse.com> Message-ID: <8f7b57da-cd10-5f96-62fe-1a6e28c8981f@suse.com> Date: Thu, 27 May 2021 13:28:59 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: <01bbf3d4-ca6a-e837-91fe-b34aa014564c@suse.com> Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" First of all avoid "long" when "int" suffices, i.e. in particular when merely conveying error codes. 32-bit values are slightly cheaper to deal with on x86, and their processing is at least no more expensive on Arm. Where possible use evtchn_port_t for port numbers and unsigned int for other unsigned quantities in adjacent code. In evtchn_set_priority() eliminate a local variable altogether instead of changing its type. Signed-off-by: Jan Beulich Acked-by: Roger Pau Monn=C3=A9 --- v6: Re-base for re-ordering / shrinking of series. v4: New. --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -284,13 +284,12 @@ void evtchn_free(struct domain *d, struc xsm_evtchn_close_post(chn); } =20 -static long evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) +static int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) { struct evtchn *chn; struct domain *d; - int port; + int port, rc; domid_t dom =3D alloc->dom; - long rc; =20 d =3D rcu_lock_domain_by_any_id(dom); if ( d =3D=3D NULL ) @@ -342,13 +341,13 @@ static void double_evtchn_unlock(struct evtchn_write_unlock(rchn); } =20 -static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind) +static int evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind) { struct evtchn *lchn, *rchn; struct domain *ld =3D current->domain, *rd; - int lport, rport =3D bind->remote_port; + int lport, rc; + evtchn_port_t rport =3D bind->remote_port; domid_t rdom =3D bind->remote_dom; - long rc; =20 if ( (rd =3D rcu_lock_domain_by_any_id(rdom)) =3D=3D NULL ) return -ESRCH; @@ -484,12 +483,12 @@ int evtchn_bind_virq(evtchn_bind_virq_t } =20 =20 -static long evtchn_bind_ipi(evtchn_bind_ipi_t *bind) +static int evtchn_bind_ipi(evtchn_bind_ipi_t *bind) { struct evtchn *chn; struct domain *d =3D current->domain; - int port, vcpu =3D bind->vcpu; - long rc =3D 0; + int port, rc =3D 0; + unsigned int vcpu =3D bind->vcpu; =20 if ( domain_vcpu(d, vcpu) =3D=3D NULL ) return -ENOENT; @@ -543,16 +542,16 @@ static void unlink_pirq_port(struct evtc } =20 =20 -static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind) +static int evtchn_bind_pirq(evtchn_bind_pirq_t *bind) { struct evtchn *chn; struct domain *d =3D current->domain; struct vcpu *v =3D d->vcpu[0]; struct pirq *info; - int port =3D 0, pirq =3D bind->pirq; - long rc; + int port =3D 0, rc; + unsigned int pirq =3D bind->pirq; =20 - if ( (pirq < 0) || (pirq >=3D d->nr_pirqs) ) + if ( pirq >=3D d->nr_pirqs ) return -EINVAL; =20 if ( !is_hvm_domain(d) && !pirq_access_permitted(d, pirq) ) @@ -608,7 +607,7 @@ int evtchn_close(struct domain *d1, int { struct domain *d2 =3D NULL; struct evtchn *chn1 =3D _evtchn_from_port(d1, port1), *chn2; - long rc =3D 0; + int rc =3D 0; =20 if ( !chn1 ) return -EINVAL; @@ -959,7 +958,7 @@ int evtchn_status(evtchn_status_t *statu domid_t dom =3D status->dom; int port =3D status->port; struct evtchn *chn; - long rc =3D 0; + int rc =3D 0; =20 d =3D rcu_lock_domain_by_any_id(dom); if ( d =3D=3D NULL ) @@ -1025,11 +1024,11 @@ int evtchn_status(evtchn_status_t *statu } =20 =20 -long evtchn_bind_vcpu(unsigned int port, unsigned int vcpu_id) +int evtchn_bind_vcpu(evtchn_port_t port, unsigned int vcpu_id) { struct domain *d =3D current->domain; struct evtchn *chn; - long rc =3D 0; + int rc =3D 0; struct vcpu *v; =20 /* Use the vcpu info to prevent speculative out-of-bound accesses */ @@ -1168,12 +1167,11 @@ int evtchn_reset(struct domain *d, bool return rc; } =20 -static long evtchn_set_priority(const struct evtchn_set_priority *set_prio= rity) +static int evtchn_set_priority(const struct evtchn_set_priority *set_prior= ity) { struct domain *d =3D current->domain; - unsigned int port =3D set_priority->port; - struct evtchn *chn =3D _evtchn_from_port(d, port); - long ret; + struct evtchn *chn =3D _evtchn_from_port(d, set_priority->port); + int ret; =20 if ( !chn ) return -EINVAL; @@ -1189,7 +1187,7 @@ static long evtchn_set_priority(const st =20 long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) { - long rc; + int rc; =20 switch ( cmd ) { --- a/xen/include/xen/event.h +++ b/xen/include/xen/event.h @@ -54,7 +54,7 @@ void send_guest_pirq(struct domain *, co int evtchn_send(struct domain *d, unsigned int lport); =20 /* Bind a local event-channel port to the specified VCPU. */ -long evtchn_bind_vcpu(unsigned int port, unsigned int vcpu_id); +int evtchn_bind_vcpu(evtchn_port_t port, unsigned int vcpu_id); =20 /* Bind a VIRQ. */ int evtchn_bind_virq(evtchn_bind_virq_t *bind, evtchn_port_t port);