From nobody Thu Apr 25 01:15:29 2024 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=1561109875; cv=none; d=zoho.com; s=zohoarc; b=ebpEVi6sbmGlpgmdlrAPXo6TUVAuZcuouktDvpnf0NCg+RsGgDGTD2eOzqbvnTSq/LtZui3TBM3zJtb8Q1BBeH7xHln1omrJ7Ci6OxqG+epRBYfrzNcUYWL1yjiVEF68tsASiYbUqh6P1YnZ/MxoQR/B8V22Z0Sq/Y0zeekPD1Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561109875; 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=p2lgN5wvPHbflOJbCkyOhI2JjWNrQqcQ0UR59Ns6Dso=; b=FrXJ1gE+XSMViRM63JppEGZEAKqqVwS+H1r9TFOB4b0VPES0UwGE8lo3hS8NTvxD8DNKpDx4ppqQBhZgAzJLLjuztsTUYJ1faQR3P+lqmB4eyhuLCqD0yjrS0/ns5KDL6hYfMJVTDWPjgWrPMyKHkmIEWLheyOfsKJozoC7BcaQ= 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 1561109875563920.3371461777314; Fri, 21 Jun 2019 02:37:55 -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 1heFyR-0007aN-1j; Fri, 21 Jun 2019 09:36:47 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1heFyP-0007a8-QH for xen-devel@lists.xenproject.org; Fri, 21 Jun 2019 09:36:45 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 14bfd50c-9408-11e9-8980-bc764e045a96; Fri, 21 Jun 2019 09:36:44 +0000 (UTC) X-Inumbo-ID: 14bfd50c-9408-11e9-8980-bc764e045a96 Authentication-Results: esa1.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@mail.citrix.com 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 (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.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:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 7163l8iTHCmy0+N2/twP80czhKbNZzTecOXN7Uy7gbWgp7Ta/bop3HWbqYlnpJtu+rqSkAT1l2 MqJZbV5/IIAzDgtzync9wotBThkpWtQEkWl4G/xd22N6seHBiJ08LLZZ6ekiO7dBoHwPkb5oHo 6922zbEYnrHmy0SW6P9wbyK0XcNlW7NR2DqRKStZjvDK5s79uvOkHdNdN8n0GV1+RUHcktAIf5 5sAbU9zihGgparQTSt4UA9xZCCIG+JRQVcF1GCcfS0ww+AW8y1olBXrdv5yvg37TRw7zZF3Muh EkQ= X-SBRS: 2.7 X-MesageID: 2060658 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.63,399,1557201600"; d="scan'208";a="2060658" From: Andrew Cooper To: Xen-devel Date: Fri, 21 Jun 2019 10:36:34 +0100 Message-ID: <1561109798-8744-2-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1561109798-8744-1-git-send-email-andrew.cooper3@citrix.com> References: <1561109798-8744-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 1/5] xen/gnttab: Reduce complexity when reading grant_entry_header_t 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: Stefano Stabellini , Wei Liu , George Dunlap , Andrew Cooper , Julien Grall , 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" _set_status_v{1,2}() and gnttab_prepare_for_transfer() read the shared head= er by always casting to u32. Despite grant_entry_header_t only having an alignment of 2, this is actually safe because of the grant table ABI itself. Switch to using an explicit uint32_t *, which removes all subsequent castin= g. Furthermore, switch to using ACCESS_ONCE() for the read. There is nothing = in the _set_status_v1() and gnttab_prepare_for_transfer() which prevents the compiler from issuing multiple memory reads and creating a TOCTOU race arou= nd the sanity checks, although the worst that can happen is Xen stamping a sta= tus flag over a bad grant entry if the guest is misbehaving. _set_status_v2() does use barrier() to try avoid multiple reads, but this is overkill. All that matters is that the shared header gets read in one go, = and this allows the compiler more room to optimise. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: Stefano Stabellini CC: Julien Grall CC: George Dunlap Dropping the barrier() in _set_status_v2() allows the optimiser to notice t= hat initialiser for flags/id are redundant memory reads. This is fixed in the following patch. --- xen/common/grant_table.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 2bbde5c..e5d585f 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -679,6 +679,7 @@ static int _set_status_v1(const grant_entry_header_t *s= hah, domid_t ldomid) { int rc =3D GNTST_okay; + uint32_t *raw_shah =3D (uint32_t *)shah; union grant_combo scombo, prev_scombo, new_scombo; uint16_t mask =3D GTF_type_mask; =20 @@ -697,7 +698,7 @@ static int _set_status_v1(const grant_entry_header_t *s= hah, if ( mapflag ) mask |=3D GTF_sub_page; =20 - scombo.word =3D *(u32 *)shah; + scombo.word =3D ACCESS_ONCE(*raw_shah); =20 /* * This loop attempts to set the access (reading/writing) flags @@ -728,7 +729,7 @@ static int _set_status_v1(const grant_entry_header_t *s= hah, "Attempt to write-pin a r/o grant entry\n"); } =20 - prev_scombo.word =3D guest_cmpxchg(rd, (u32 *)shah, + prev_scombo.word =3D guest_cmpxchg(rd, raw_shah, scombo.word, new_scombo.word); if ( likely(prev_scombo.word =3D=3D scombo.word) ) break; @@ -753,17 +754,13 @@ static int _set_status_v2(const grant_entry_header_t = *shah, domid_t ldomid) { int rc =3D GNTST_okay; + uint32_t *raw_shah =3D (uint32_t *)shah; union grant_combo scombo; uint16_t flags =3D shah->flags; domid_t id =3D shah->domid; uint16_t mask =3D GTF_type_mask; =20 - /* we read flags and domid in a single memory access. - this avoids the need for another memory barrier to - ensure access to these fields are not reordered */ - scombo.word =3D *(u32 *)shah; - barrier(); /* but we still need to stop the compiler from turning - it back into two reads */ + scombo.word =3D ACCESS_ONCE(*raw_shah); flags =3D scombo.shorts.flags; id =3D scombo.shorts.domid; =20 @@ -797,8 +794,7 @@ static int _set_status_v2(const grant_entry_header_t *s= hah, still valid */ smp_mb(); =20 - scombo.word =3D *(u32 *)shah; - barrier(); + scombo.word =3D ACCESS_ONCE(*raw_shah); flags =3D scombo.shorts.flags; id =3D scombo.shorts.domid; =20 @@ -2041,7 +2037,7 @@ gnttab_prepare_for_transfer( struct domain *rd, struct domain *ld, grant_ref_t ref) { struct grant_table *rgt =3D rd->grant_table; - grant_entry_header_t *sha; + uint32_t *raw_shah; union grant_combo scombo, prev_scombo, new_scombo; int retries =3D 0; =20 @@ -2055,9 +2051,8 @@ gnttab_prepare_for_transfer( goto fail; } =20 - sha =3D shared_entry_header(rgt, ref); - - scombo.word =3D *(u32 *)&sha->flags; + raw_shah =3D (uint32_t *)shared_entry_header(rgt, ref); + scombo.word =3D ACCESS_ONCE(*raw_shah); =20 for ( ; ; ) { @@ -2074,7 +2069,7 @@ gnttab_prepare_for_transfer( new_scombo =3D scombo; new_scombo.shorts.flags |=3D GTF_transfer_committed; =20 - prev_scombo.word =3D guest_cmpxchg(rd, (u32 *)&sha->flags, + prev_scombo.word =3D guest_cmpxchg(rd, raw_shah, scombo.word, new_scombo.word); if ( likely(prev_scombo.word =3D=3D scombo.word) ) break; --=20 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu Apr 25 01:15:29 2024 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=1561109898; cv=none; d=zoho.com; s=zohoarc; b=ljgRSajzIBO6SQafzwIH38qJ/A4AqAXvF01JNzX05x3E5YyskUkv4/4wEBUCkCLwuMQk8pj2aRMYe80BWLXRAoGCzvxS60frGjb9Gk/du7LuGgcd+TfkT0UKqQ2OJu19N3vOkTXq5A8lQzgQwdkIHYdzPHdnZNohAg3bZ6K0AzA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561109898; 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=suFADwfFyzOJbWSYw+nwnjiq856Lh4nzW0xVoBRf3F4=; b=Y4ONQmm3I5yZF9MulUdzB64QRmZY5LGc7zHqLAZUAUdoISSMtyogPjG2Gokt3794B+V3e3rIgwWyzSXNwtvDWN4euLU5vxEf5Jej2kTTpGtO9M5e4pDIJsiCvEY0J3+OrxlblaR+iVVWAmiZriO2yLfZpfHobpA9wjPkqEzIRYk= 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 1561109898866128.59868521722774; Fri, 21 Jun 2019 02:38:18 -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 1heFyW-0007dr-Dq; Fri, 21 Jun 2019 09:36:52 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1heFyV-0007d6-5M for xen-devel@lists.xenproject.org; Fri, 21 Jun 2019 09:36:51 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 179222cf-9408-11e9-8980-bc764e045a96; Fri, 21 Jun 2019 09:36:48 +0000 (UTC) X-Inumbo-ID: 179222cf-9408-11e9-8980-bc764e045a96 Authentication-Results: esa4.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@mail.citrix.com 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 (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.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:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 3QsXQ6UzxZ/RsFpDjPTRe2PUn5cTdhX1EEzut9HBlL95JtYSfIkKhdGiuXC43NDldRLzDrz3FW Gye4FySDBB7WLH+FCc5E4rw78koryUxtV4jmr5i+JMFphnSVCiRK+oq7C4gn39rbfHcHNVVV9+ g+FWRIgQhDSnCFCXYoFqlGvoTxCrVSwFPz21TLrHOVIFX1UuOAMo4W1dmUUjIsqNGHD155386n bl1ayci2B6AyZszy+10iphFG0PGqXnUaWMZnsRAa0FxWnf5jQCEjR2fZeEpYCeUV1oo+aYU2IE hZ0= X-SBRS: 2.7 X-MesageID: 2072494 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.63,399,1557201600"; d="scan'208";a="2072494" From: Andrew Cooper To: Xen-devel Date: Fri, 21 Jun 2019 10:36:35 +0100 Message-ID: <1561109798-8744-3-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1561109798-8744-1-git-send-email-andrew.cooper3@citrix.com> References: <1561109798-8744-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 2/5] xen/gnttab: Reduce code volume when using union grant_combo 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: Stefano Stabellini , Wei Liu , George Dunlap , Andrew Cooper , Julien Grall , 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" There is no need for 'struct { ... } shorts' to be named. Convert it to be= ing an anonymous struct, and rename 'word' to the more common 'raw'. For _set_status_v1() and gnttab_prepare_for_transfer() which use a bounded cmpxchg loop, rename {prev,new}_scombo to {prev,new} and reduce their scope= to within the loop. For _set_status_v2(), the flags and id variables are completely unnecessary. Drop them. No functional change. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: Stefano Stabellini CC: Julien Grall CC: George Dunlap --- xen/common/grant_table.c | 91 ++++++++++++++++++++++----------------------= ---- 1 file changed, 41 insertions(+), 50 deletions(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index e5d585f..6d8f17d 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -144,11 +144,11 @@ custom_param("gnttab", parse_gnttab); * The following union allows that to happen in an endian-neutral fashion. */ union grant_combo { - uint32_t word; + uint32_t raw; struct { uint16_t flags; domid_t domid; - } shorts; + }; }; =20 /* Used to share code between unmap_grant_ref and unmap_and_replace. */ @@ -680,7 +680,7 @@ static int _set_status_v1(const grant_entry_header_t *s= hah, { int rc =3D GNTST_okay; uint32_t *raw_shah =3D (uint32_t *)shah; - union grant_combo scombo, prev_scombo, new_scombo; + union grant_combo scombo; uint16_t mask =3D GTF_type_mask; =20 /* @@ -698,7 +698,7 @@ static int _set_status_v1(const grant_entry_header_t *s= hah, if ( mapflag ) mask |=3D GTF_sub_page; =20 - scombo.word =3D ACCESS_ONCE(*raw_shah); + scombo.raw =3D ACCESS_ONCE(*raw_shah); =20 /* * This loop attempts to set the access (reading/writing) flags @@ -708,37 +708,35 @@ static int _set_status_v1(const grant_entry_header_t = *shah, */ for ( ; ; ) { + union grant_combo prev, new; + /* If not already pinned, check the grant domid and type. */ - if ( !act->pin && - (((scombo.shorts.flags & mask) !=3D - GTF_permit_access) || - (scombo.shorts.domid !=3D ldomid)) ) + if ( !act->pin && (((scombo.flags & mask) !=3D GTF_permit_access) = || + (scombo.domid !=3D ldomid)) ) PIN_FAIL(done, GNTST_general_error, "Bad flags (%x) or dom (%d); expected d%d\n", - scombo.shorts.flags, scombo.shorts.domid, - ldomid); + scombo.flags, scombo.domid, ldomid); =20 - new_scombo =3D scombo; - new_scombo.shorts.flags |=3D GTF_reading; + new =3D scombo; + new.flags |=3D GTF_reading; =20 if ( !readonly ) { - new_scombo.shorts.flags |=3D GTF_writing; - if ( unlikely(scombo.shorts.flags & GTF_readonly) ) + new.flags |=3D GTF_writing; + if ( unlikely(scombo.flags & GTF_readonly) ) PIN_FAIL(done, GNTST_general_error, "Attempt to write-pin a r/o grant entry\n"); } =20 - prev_scombo.word =3D guest_cmpxchg(rd, raw_shah, - scombo.word, new_scombo.word); - if ( likely(prev_scombo.word =3D=3D scombo.word) ) + prev.raw =3D guest_cmpxchg(rd, raw_shah, scombo.raw, new.raw); + if ( likely(prev.raw =3D=3D scombo.raw) ) break; =20 if ( retries++ =3D=3D 4 ) PIN_FAIL(done, GNTST_general_error, "Shared grant entry is unstable\n"); =20 - scombo =3D prev_scombo; + scombo =3D prev; } =20 done: @@ -756,13 +754,9 @@ static int _set_status_v2(const grant_entry_header_t *= shah, int rc =3D GNTST_okay; uint32_t *raw_shah =3D (uint32_t *)shah; union grant_combo scombo; - uint16_t flags =3D shah->flags; - domid_t id =3D shah->domid; uint16_t mask =3D GTF_type_mask; =20 - scombo.word =3D ACCESS_ONCE(*raw_shah); - flags =3D scombo.shorts.flags; - id =3D scombo.shorts.domid; + scombo.raw =3D ACCESS_ONCE(*raw_shah); =20 /* if this is a grant mapping operation we should ensure GTF_sub_page is not set */ @@ -770,13 +764,12 @@ static int _set_status_v2(const grant_entry_header_t = *shah, mask |=3D GTF_sub_page; =20 /* If not already pinned, check the grant domid and type. */ - if ( !act->pin && - ( (((flags & mask) !=3D GTF_permit_access) && - ((flags & mask) !=3D GTF_transitive)) || - (id !=3D ldomid)) ) + if ( !act->pin && ((((scombo.flags & mask) !=3D GTF_permit_access) && + ((scombo.flags & mask) !=3D GTF_transitive)) || + (scombo.domid !=3D ldomid)) ) PIN_FAIL(done, GNTST_general_error, "Bad flags (%x) or dom (%d); expected d%d, flags %x\n", - flags, id, ldomid, mask); + scombo.flags, scombo.domid, ldomid, mask); =20 if ( readonly ) { @@ -784,7 +777,7 @@ static int _set_status_v2(const grant_entry_header_t *s= hah, } else { - if ( unlikely(flags & GTF_readonly) ) + if ( unlikely(scombo.flags & GTF_readonly) ) PIN_FAIL(done, GNTST_general_error, "Attempt to write-pin a r/o grant entry\n"); *status |=3D GTF_reading | GTF_writing; @@ -794,27 +787,25 @@ static int _set_status_v2(const grant_entry_header_t = *shah, still valid */ smp_mb(); =20 - scombo.word =3D ACCESS_ONCE(*raw_shah); - flags =3D scombo.shorts.flags; - id =3D scombo.shorts.domid; + scombo.raw =3D ACCESS_ONCE(*raw_shah); =20 if ( !act->pin ) { - if ( (((flags & mask) !=3D GTF_permit_access) && - ((flags & mask) !=3D GTF_transitive)) || - (id !=3D ldomid) || - (!readonly && (flags & GTF_readonly)) ) + if ( (((scombo.flags & mask) !=3D GTF_permit_access) && + ((scombo.flags & mask) !=3D GTF_transitive)) || + (scombo.domid !=3D ldomid) || + (!readonly && (scombo.flags & GTF_readonly)) ) { gnttab_clear_flag(rd, _GTF_writing, status); gnttab_clear_flag(rd, _GTF_reading, status); PIN_FAIL(done, GNTST_general_error, "Unstable flags (%x) or dom (%d); expected d%d (r/w: = %d)\n", - flags, id, ldomid, !readonly); + scombo.flags, scombo.domid, ldomid, !readonly); } } else { - if ( unlikely(flags & GTF_readonly) ) + if ( unlikely(scombo.flags & GTF_readonly) ) { gnttab_clear_flag(rd, _GTF_writing, status); PIN_FAIL(done, GNTST_general_error, @@ -2038,7 +2029,7 @@ gnttab_prepare_for_transfer( { struct grant_table *rgt =3D rd->grant_table; uint32_t *raw_shah; - union grant_combo scombo, prev_scombo, new_scombo; + union grant_combo scombo; int retries =3D 0; =20 grant_read_lock(rgt); @@ -2052,26 +2043,26 @@ gnttab_prepare_for_transfer( } =20 raw_shah =3D (uint32_t *)shared_entry_header(rgt, ref); - scombo.word =3D ACCESS_ONCE(*raw_shah); + scombo.raw =3D ACCESS_ONCE(*raw_shah); =20 for ( ; ; ) { - if ( unlikely(scombo.shorts.flags !=3D GTF_accept_transfer) || - unlikely(scombo.shorts.domid !=3D ld->domain_id) ) + union grant_combo prev, new; + + if ( unlikely(scombo.flags !=3D GTF_accept_transfer) || + unlikely(scombo.domid !=3D ld->domain_id) ) { gdprintk(XENLOG_INFO, "Bad flags (%x) or dom (%d); expected d%d\n", - scombo.shorts.flags, scombo.shorts.domid, - ld->domain_id); + scombo.flags, scombo.domid, ld->domain_id); goto fail; } =20 - new_scombo =3D scombo; - new_scombo.shorts.flags |=3D GTF_transfer_committed; + new =3D scombo; + new.flags |=3D GTF_transfer_committed; =20 - prev_scombo.word =3D guest_cmpxchg(rd, raw_shah, - scombo.word, new_scombo.word); - if ( likely(prev_scombo.word =3D=3D scombo.word) ) + prev.raw =3D guest_cmpxchg(rd, raw_shah, scombo.raw, new.raw); + if ( likely(prev.raw =3D=3D scombo.raw) ) break; =20 if ( retries++ =3D=3D 4 ) @@ -2080,7 +2071,7 @@ gnttab_prepare_for_transfer( goto fail; } =20 - scombo =3D prev_scombo; + scombo =3D prev; } =20 grant_read_unlock(rgt); --=20 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu Apr 25 01:15:29 2024 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=1561109873; cv=none; d=zoho.com; s=zohoarc; b=A4oce9YK3MMtFg8KPLOQLfueJE4hi/ghicRh4Ie1Lmoo2c9G2d8AYs2Ek4KU+i2jhK8UXKePPyUp0o1W55ZYrmI5sj0xmySchziypjrJ2sEwoSByN6aGIEa/cj6euR+VPTCjT/2Nbre++E9YWLo33/XJfG53Qc3NK+lTeTcmElQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561109873; 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=MDBn0cfEesJ9mFAACtzkxAhGiWQJ/6e+uvnW6TwEFKE=; b=QFf2wSoqy4yprjdZgL4ZKdwl3Jues0iUl7wk1058HpJe5eEZ6hYE6qgihtsXA3nY0DrfCdyaFiDuRrpukYekOQo51+32YWl2Z7vAvNLyYdrumg4Byv4IVrT27L3RkT9yw+t9oxxCQ1vvSM1esmfffTw/eBnJ6NGC9aBVU5o1hVE= 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 1561109873082831.8340325921297; Fri, 21 Jun 2019 02:37:53 -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 1heFyR-0007aY-BH; Fri, 21 Jun 2019 09:36:47 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1heFyP-0007a9-QI for xen-devel@lists.xenproject.org; Fri, 21 Jun 2019 09:36:45 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 152d0e33-9408-11e9-8980-bc764e045a96; Fri, 21 Jun 2019 09:36:44 +0000 (UTC) X-Inumbo-ID: 152d0e33-9408-11e9-8980-bc764e045a96 Authentication-Results: esa1.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@mail.citrix.com 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 (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.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:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: pJBqWnN1+Zomj8YcpNMobkrhTT26oNYxj6+fwFmgCGNca26V+TRBk9BNwD0Xq1upyfT3pZwqct H3vNTM+CbqEwOThyqzFgaPr3OMnNSd7g6ihEd8KYfEE9cvCYfMu2joQD8Zy+sI5BW5X4LDwccd YZWrpreQ6NyWJp8GiZnR+eH/nymFelEKr8tAjaaj0LXwahK17ASE4jwSWpxnqRa0EciIo6aSVE HywicuF133pwCzD2RXbUo6ljFkb6Zq3fuXJwgr5iOigqQx6cUOGDUmnVXpRl9xQNCaarbPdnZ2 5ts= X-SBRS: 2.7 X-MesageID: 2060661 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.63,399,1557201600"; d="scan'208";a="2060661" From: Andrew Cooper To: Xen-devel Date: Fri, 21 Jun 2019 10:36:36 +0100 Message-ID: <1561109798-8744-4-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1561109798-8744-1-git-send-email-andrew.cooper3@citrix.com> References: <1561109798-8744-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 3/5] arm/gnttab: Implement stub helpers as static inlines 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: Andrew Cooper , Julien Grall , Stefano Stabellini Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" It is inefficient to call into a different translation unit for a stub function, when a static inline will work fine. Replace an open-coded printk_once() while moving it. No functional change. Signed-off-by: Andrew Cooper Acked-by: Julien Grall --- CC: Stefano Stabellini CC: Julien Grall --- xen/arch/arm/mm.c | 16 ---------------- xen/include/asm-arm/grant_table.h | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 35dc1f7..44258ad 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -41,7 +41,6 @@ #include #include =20 -#include #include =20 /* Override macros from asm/page.h to make them work with mfn_t */ @@ -1532,21 +1531,6 @@ void put_page_type(struct page_info *page) return; } =20 -void gnttab_clear_flag(struct domain *d, unsigned long nr, uint16_t *addr) -{ - guest_clear_mask16(d, BIT(nr, UL), addr); -} - -void gnttab_mark_dirty(struct domain *d, mfn_t mfn) -{ - /* XXX: mark dirty */ - static int warning; - if (!warning) { - gdprintk(XENLOG_WARNING, "gnttab_mark_dirty not implemented yet\n"= ); - warning =3D 1; - } -} - int create_grant_host_mapping(unsigned long addr, mfn_t frame, unsigned int flags, unsigned int cache_flags) { diff --git a/xen/include/asm-arm/grant_table.h b/xen/include/asm-arm/grant_= table.h index 1ed0aef..b0d673b 100644 --- a/xen/include/asm-arm/grant_table.h +++ b/xen/include/asm-arm/grant_table.h @@ -6,6 +6,8 @@ #include #include =20 +#include + #define INITIAL_NR_GRANT_FRAMES 1U #define GNTTAB_MAX_VERSION 1 =20 @@ -14,13 +16,24 @@ struct grant_table_arch { gfn_t *status_gfn; }; =20 -void gnttab_clear_flag(struct domain *d, unsigned long nr, uint16_t *addr); +static inline void gnttab_clear_flag(struct domain *d, + unsigned long nr, uint16_t *addr) +{ + guest_clear_mask16(d, BIT(nr, UL), addr); +} + +static inline void gnttab_mark_dirty(struct domain *d, mfn_t mfn) +{ +#ifndef NDEBUG + printk_once(XENLOG_G_WARNING "gnttab_mark_dirty not implemented yet\n"= ); +#endif +} + int create_grant_host_mapping(unsigned long gpaddr, mfn_t mfn, unsigned int flags, unsigned int cache_flags= ); #define gnttab_host_mapping_get_page_type(ro, ld, rd) (0) int replace_grant_host_mapping(unsigned long gpaddr, mfn_t mfn, unsigned long new_gpaddr, unsigned int flag= s); -void gnttab_mark_dirty(struct domain *d, mfn_t mfn); #define gnttab_release_host_mappings(domain) 1 =20 /* --=20 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu Apr 25 01:15:29 2024 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=1561109875; cv=none; d=zoho.com; s=zohoarc; b=JRdIFlDC2N/7hCWaUBWYE66OpYzE/OERbVnzjh6sGvv416MZDGT34Y5BncO9PWgeJNchySsXiwDlVjXeijcKs3qnQdftp7si0LHaMIzmWg8jA4apT6KtUxMSQ88PdbxX+T0/nJehz/DVHmcYYXAB2y2P3zoa1/qi+Ac5q2zSJmM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561109875; 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=u6PP9sDMgbcAjklApZXwlQSEOuOdeksqLB01gZlqfoc=; b=b/eZchnvR/4Y3WUVT4C4yWDGR8s9e5YRLEiHqQUKEc6SCHPo4SF0LLmSsRpMNgrabyn0ioBBRuo05wFaWOmGtGgjj5+R1qjMEeIDbxcdX2zMpktloRDiWgtKz7fgW9v0SPWE3SRWde1VDxVSgmEVMuKy7oqLU1FYZpZ7CEkuKt8= 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 1561109875753735.9205864867815; Fri, 21 Jun 2019 02:37:55 -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 1heFyR-0007au-QH; Fri, 21 Jun 2019 09:36:47 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1heFyR-0007aP-4k for xen-devel@lists.xenproject.org; Fri, 21 Jun 2019 09:36:47 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 158a9716-9408-11e9-8980-bc764e045a96; Fri, 21 Jun 2019 09:36:45 +0000 (UTC) X-Inumbo-ID: 158a9716-9408-11e9-8980-bc764e045a96 Authentication-Results: esa1.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@mail.citrix.com 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 (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.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:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: yNk+spgbSIUyPpMJ3Bv1VgpP3fQ1ysjF1u6loCb+D51o+6dAli79oJ8rdBfcLU/N3DNIxNjXSf Z93NL2Suv9Cuw6Ki8/jMGap1R78DxxuSXutlX6LcJ/0eaSlg74oMUc0ZiQPRAW+NMAr8OoL7oi 60KhuxFu2YjQRXzwBqb8FIiXzDT0hSF+S1MFzE10wmhJaZ0tdBhgD+eVLMy3jChqgVAmAQDRbD Uvfc69iEqG5civg9U6DxobS1gpV2ZHgsNfBvPsH326+xW2cLkLsfryQpuGH1Jw41AVyLrC1rUP Oiw= X-SBRS: 2.7 X-MesageID: 2060662 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.63,399,1557201600"; d="scan'208";a="2060662" From: Andrew Cooper To: Xen-devel Date: Fri, 21 Jun 2019 10:36:37 +0100 Message-ID: <1561109798-8744-5-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1561109798-8744-1-git-send-email-andrew.cooper3@citrix.com> References: <1561109798-8744-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 4/5] xen/gnttab: Refactor gnttab_clear_flag() to be gnttab_clear_flags() 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: Stefano Stabellini , Wei Liu , George Dunlap , Andrew Cooper , Julien Grall , 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" To allow for further improvements, it is useful to be able to clear more th= an a single flag at once. Rework gnttab_clear_flag() into gnttab_clear_flags() which takes a bitmask rather than a bit number. No practical change yet. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: Stefano Stabellini CC: Julien Grall CC: George Dunlap --- xen/common/grant_table.c | 30 +++++++++++++++--------------- xen/include/asm-arm/grant_table.h | 6 +++--- xen/include/asm-x86/grant_table.h | 11 ++++------- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 6d8f17d..4bd5777 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -796,8 +796,8 @@ static int _set_status_v2(const grant_entry_header_t *s= hah, (scombo.domid !=3D ldomid) || (!readonly && (scombo.flags & GTF_readonly)) ) { - gnttab_clear_flag(rd, _GTF_writing, status); - gnttab_clear_flag(rd, _GTF_reading, status); + gnttab_clear_flags(rd, GTF_writing, status); + gnttab_clear_flags(rd, GTF_reading, status); PIN_FAIL(done, GNTST_general_error, "Unstable flags (%x) or dom (%d); expected d%d (r/w: = %d)\n", scombo.flags, scombo.domid, ldomid, !readonly); @@ -807,7 +807,7 @@ static int _set_status_v2(const grant_entry_header_t *s= hah, { if ( unlikely(scombo.flags & GTF_readonly) ) { - gnttab_clear_flag(rd, _GTF_writing, status); + gnttab_clear_flags(rd, GTF_writing, status); PIN_FAIL(done, GNTST_general_error, "Unstable grant readonly flag\n"); } @@ -1220,10 +1220,10 @@ map_grant_ref( unlock_out_clear: if ( !(op->flags & GNTMAP_readonly) && !(act->pin & (GNTPIN_hstw_mask|GNTPIN_devw_mask)) ) - gnttab_clear_flag(rd, _GTF_writing, status); + gnttab_clear_flags(rd, GTF_writing, status); =20 if ( !act->pin ) - gnttab_clear_flag(rd, _GTF_reading, status); + gnttab_clear_flags(rd, GTF_reading, status); =20 act_release_out: active_entry_release(act); @@ -1493,10 +1493,10 @@ unmap_common_complete(struct gnttab_unmap_common *o= p) =20 if ( ((act->pin & (GNTPIN_devw_mask|GNTPIN_hstw_mask)) =3D=3D 0) && !(op->done & GNTMAP_readonly) ) - gnttab_clear_flag(rd, _GTF_writing, status); + gnttab_clear_flags(rd, GTF_writing, status); =20 if ( act->pin =3D=3D 0 ) - gnttab_clear_flag(rd, _GTF_reading, status); + gnttab_clear_flags(rd, GTF_reading, status); =20 active_entry_release(act); grant_read_unlock(rgt); @@ -2354,11 +2354,11 @@ release_grant_for_copy( =20 act->pin -=3D GNTPIN_hstw_inc; if ( !(act->pin & (GNTPIN_devw_mask|GNTPIN_hstw_mask)) ) - gnttab_clear_flag(rd, _GTF_writing, status); + gnttab_clear_flags(rd, GTF_writing, status); } =20 if ( !act->pin ) - gnttab_clear_flag(rd, _GTF_reading, status); + gnttab_clear_flags(rd, GTF_reading, status); =20 active_entry_release(act); grant_read_unlock(rgt); @@ -2385,10 +2385,10 @@ static void fixup_status_for_copy_pin(struct domain= *rd, uint16_t *status) { if ( !(act->pin & (GNTPIN_hstw_mask | GNTPIN_devw_mask)) ) - gnttab_clear_flag(rd, _GTF_writing, status); + gnttab_clear_flags(rd, GTF_writing, status); =20 if ( !act->pin ) - gnttab_clear_flag(rd, _GTF_reading, status); + gnttab_clear_flags(rd, GTF_reading, status); } =20 /* @@ -2639,10 +2639,10 @@ acquire_grant_for_copy( unlock_out_clear: if ( !(readonly) && !(act->pin & (GNTPIN_hstw_mask | GNTPIN_devw_mask)) ) - gnttab_clear_flag(rd, _GTF_writing, status); + gnttab_clear_flags(rd, GTF_writing, status); =20 if ( !act->pin ) - gnttab_clear_flag(rd, _GTF_reading, status); + gnttab_clear_flags(rd, GTF_reading, status); =20 unlock_out: active_entry_release(act); @@ -3677,11 +3677,11 @@ gnttab_release_mappings( } =20 if ( (act->pin & (GNTPIN_devw_mask|GNTPIN_hstw_mask)) =3D=3D 0= ) - gnttab_clear_flag(rd, _GTF_writing, status); + gnttab_clear_flags(rd, GTF_writing, status); } =20 if ( act->pin =3D=3D 0 ) - gnttab_clear_flag(rd, _GTF_reading, status); + gnttab_clear_flags(rd, GTF_reading, status); =20 active_entry_release(act); grant_read_unlock(rgt); diff --git a/xen/include/asm-arm/grant_table.h b/xen/include/asm-arm/grant_= table.h index b0d673b..8ccad69 100644 --- a/xen/include/asm-arm/grant_table.h +++ b/xen/include/asm-arm/grant_table.h @@ -16,10 +16,10 @@ struct grant_table_arch { gfn_t *status_gfn; }; =20 -static inline void gnttab_clear_flag(struct domain *d, - unsigned long nr, uint16_t *addr) +static inline void gnttab_clear_flags(struct domain *d, + uint16_t mask, uint16_t *addr) { - guest_clear_mask16(d, BIT(nr, UL), addr); + guest_clear_mask16(d, mask, addr); } =20 static inline void gnttab_mark_dirty(struct domain *d, mfn_t mfn) diff --git a/xen/include/asm-x86/grant_table.h b/xen/include/asm-x86/grant_= table.h index 121b33d..4691258 100644 --- a/xen/include/asm-x86/grant_table.h +++ b/xen/include/asm-x86/grant_table.h @@ -60,14 +60,11 @@ static inline int replace_grant_host_mapping(uint64_t a= ddr, mfn_t frame, =20 #define gnttab_mark_dirty(d, f) paging_mark_dirty(d, f) =20 -static inline void gnttab_clear_flag(struct domain *d, unsigned int nr, - uint16_t *st) +static inline void gnttab_clear_flags(struct domain *d, + uint16_t mask, uint16_t *addr) { - /* - * Note that this cannot be clear_bit(), as the access must be - * confined to the specified 2 bytes. - */ - asm volatile ("lock btrw %w1,%0" : "+m" (*st) : "Ir" (nr)); + /* Access must be confined to the specified 2 bytes. */ + asm volatile ("lock andw %w1,%0" : "+m" (*addr) : "Ir" (~mask)); } =20 /* Foreign mappings of HVM-guest pages do not modify the type count. */ --=20 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu Apr 25 01:15:29 2024 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=1561109877; cv=none; d=zoho.com; s=zohoarc; b=hmRosLcd6fdth2pQCBvl5WQhBCAZ2WWdxkXSj7xOYIPUAYr/gLkFw5BsGLgZhYG2lEr8X41/YzLrUQQq8Oyy9a5IAGSluP2m0zeoi+OFg7SPbgNNfWtY1CaU/Yk0eebc+5C0xC7g703aNH+r6HMcuI/RHZrgxGy4VZ50IDrGO10= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561109877; 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=ZSHKwqgqbi9aav1VrVrV/LdYWWIPY6yXBs5Ej1cKRqg=; b=bu62IoUDCAR5SMKQOhhCZbgLkoK7arMJ4ZwwwRGLFoKsqW6YqZ6o2peRxIIKmtsCXu4OgYQ+7JJwNrSs7mUcOQdeYs+aohBjpD6CQfHRkg13m6YEUoE+k3tgezDe0H8wW4cN9f2ty66nZxkO1//aVJ4DDi/f/T0v/4dEZYvDcQU= 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 1561109877342488.3414584322903; Fri, 21 Jun 2019 02:37:57 -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 1heFyU-0007cH-4b; Fri, 21 Jun 2019 09:36:50 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1heFyS-0007bG-Ei for xen-devel@lists.xenproject.org; Fri, 21 Jun 2019 09:36:48 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 160e3fd5-9408-11e9-8980-bc764e045a96; Fri, 21 Jun 2019 09:36:46 +0000 (UTC) X-Inumbo-ID: 160e3fd5-9408-11e9-8980-bc764e045a96 Authentication-Results: esa2.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@mail.citrix.com 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 (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa2.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:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: N9ySbi1gz7TGtob0AL3JnQ+p1SMNIMgK6tKK9ujZ06jhgI699k6O367Pb1etQml4CaA9rgUikM FN1spb/pEixIAYwIWH5lRrwloavQAh3TpOBc9B6tM020QZBY8aX0hFfxBzJKxD1vCfkqIQj2GV ABhORl/M1dTAs6oopIWZEtSYz/J4zq+jtQNynFi3skAji/sO92iSdUhiVl2aboNRCufrWXz//r G1B9ncaz+XY1a5G0G7uqudF65OD0pXqymgBhOoCqz4Bul5jVrTSqvTt5Rmx1nI4S1zlKG2D/n3 1yg= X-SBRS: 2.7 X-MesageID: 2039644 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.63,399,1557201600"; d="scan'208";a="2039644" From: Andrew Cooper To: Xen-devel Date: Fri, 21 Jun 2019 10:36:38 +0100 Message-ID: <1561109798-8744-6-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1561109798-8744-1-git-send-email-andrew.cooper3@citrix.com> References: <1561109798-8744-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 5/5] xen/gnttab: Fold adjacent calls to gnttab_clear_flags() 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: Stefano Stabellini , Wei Liu , George Dunlap , Andrew Cooper , Julien Grall , 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" Atomic operations are expensive to use, especially following XSA-295 for AR= M. It is wasteful to use two of them back-to-back when one will do. Especially for a misbehaving guest on ARM, this will reduce the system disruption required to complete the grant operations. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: Stefano Stabellini CC: Julien Grall CC: George Dunlap --- xen/common/grant_table.c | 54 ++++++++++++++++++++++++++++++++++----------= ---- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 4bd5777..e6a0f30 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -796,8 +796,7 @@ static int _set_status_v2(const grant_entry_header_t *s= hah, (scombo.domid !=3D ldomid) || (!readonly && (scombo.flags & GTF_readonly)) ) { - gnttab_clear_flags(rd, GTF_writing, status); - gnttab_clear_flags(rd, GTF_reading, status); + gnttab_clear_flags(rd, GTF_writing | GTF_reading, status); PIN_FAIL(done, GNTST_general_error, "Unstable flags (%x) or dom (%d); expected d%d (r/w: = %d)\n", scombo.flags, scombo.domid, ldomid, !readonly); @@ -919,7 +918,7 @@ map_grant_ref( int rc =3D GNTST_okay; u32 old_pin; u32 act_pin; - unsigned int cache_flags, refcnt =3D 0, typecnt =3D 0; + unsigned int cache_flags, clear_flags =3D 0, refcnt =3D 0, typecnt = =3D 0; bool host_map_created =3D false; struct active_grant_entry *act =3D NULL; struct grant_mapping *mt; @@ -1220,10 +1219,13 @@ map_grant_ref( unlock_out_clear: if ( !(op->flags & GNTMAP_readonly) && !(act->pin & (GNTPIN_hstw_mask|GNTPIN_devw_mask)) ) - gnttab_clear_flags(rd, GTF_writing, status); + clear_flags |=3D GTF_writing; =20 if ( !act->pin ) - gnttab_clear_flags(rd, GTF_reading, status); + clear_flags |=3D GTF_reading; + + if ( clear_flags ) + gnttab_clear_flags(rd, clear_flags, status); =20 act_release_out: active_entry_release(act); @@ -1433,6 +1435,7 @@ unmap_common_complete(struct gnttab_unmap_common *op) grant_entry_header_t *sha; struct page_info *pg; uint16_t *status; + unsigned int clear_flags =3D 0; =20 if ( !op->done ) { @@ -1493,10 +1496,13 @@ unmap_common_complete(struct gnttab_unmap_common *o= p) =20 if ( ((act->pin & (GNTPIN_devw_mask|GNTPIN_hstw_mask)) =3D=3D 0) && !(op->done & GNTMAP_readonly) ) - gnttab_clear_flags(rd, GTF_writing, status); + clear_flags |=3D GTF_writing; =20 if ( act->pin =3D=3D 0 ) - gnttab_clear_flags(rd, GTF_reading, status); + clear_flags |=3D GTF_reading; + + if ( clear_flags ) + gnttab_clear_flags(rd, clear_flags, status); =20 active_entry_release(act); grant_read_unlock(rgt); @@ -2324,6 +2330,7 @@ release_grant_for_copy( uint16_t *status; grant_ref_t trans_gref; struct domain *td; + unsigned int clear_flags =3D 0; =20 grant_read_lock(rgt); =20 @@ -2354,11 +2361,14 @@ release_grant_for_copy( =20 act->pin -=3D GNTPIN_hstw_inc; if ( !(act->pin & (GNTPIN_devw_mask|GNTPIN_hstw_mask)) ) - gnttab_clear_flags(rd, GTF_writing, status); + clear_flags |=3D GTF_writing; } =20 if ( !act->pin ) - gnttab_clear_flags(rd, GTF_reading, status); + clear_flags |=3D GTF_reading; + + if ( clear_flags ) + gnttab_clear_flags(rd, clear_flags, status); =20 active_entry_release(act); grant_read_unlock(rgt); @@ -2384,11 +2394,16 @@ static void fixup_status_for_copy_pin(struct domain= *rd, const struct active_grant_entry *act, uint16_t *status) { + unsigned int clear_flags =3D 0; + if ( !(act->pin & (GNTPIN_hstw_mask | GNTPIN_devw_mask)) ) - gnttab_clear_flags(rd, GTF_writing, status); + clear_flags |=3D GTF_writing; =20 if ( !act->pin ) - gnttab_clear_flags(rd, GTF_reading, status); + clear_flags |=3D GTF_reading; + + if ( clear_flags ) + gnttab_clear_flags(rd, clear_flags, status); } =20 /* @@ -2417,6 +2432,7 @@ acquire_grant_for_copy( uint16_t trans_length; bool is_sub_page; s16 rc =3D GNTST_okay; + unsigned int clear_flags =3D 0; =20 *page =3D NULL; =20 @@ -2639,10 +2655,13 @@ acquire_grant_for_copy( unlock_out_clear: if ( !(readonly) && !(act->pin & (GNTPIN_hstw_mask | GNTPIN_devw_mask)) ) - gnttab_clear_flags(rd, GTF_writing, status); + clear_flags |=3D GTF_writing; =20 if ( !act->pin ) - gnttab_clear_flags(rd, GTF_reading, status); + clear_flags |=3D GTF_reading; + + if ( clear_flags ) + gnttab_clear_flags(rd, clear_flags, status); =20 unlock_out: active_entry_release(act); @@ -3603,6 +3622,8 @@ gnttab_release_mappings( =20 for ( handle =3D 0; handle < gt->maptrack_limit; handle++ ) { + unsigned int clear_flags =3D 0; + map =3D &maptrack_entry(gt, handle); if ( !(map->flags & (GNTMAP_device_map|GNTMAP_host_map)) ) continue; @@ -3677,11 +3698,14 @@ gnttab_release_mappings( } =20 if ( (act->pin & (GNTPIN_devw_mask|GNTPIN_hstw_mask)) =3D=3D 0= ) - gnttab_clear_flags(rd, GTF_writing, status); + clear_flags |=3D GTF_writing; } =20 if ( act->pin =3D=3D 0 ) - gnttab_clear_flags(rd, GTF_reading, status); + clear_flags |=3D GTF_reading; + + if ( clear_flags ) + gnttab_clear_flags(rd, clear_flags, status); =20 active_entry_release(act); grant_read_unlock(rgt); --=20 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel