From nobody Sat Apr 27 04:15:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1565679458; cv=none; d=zoho.com; s=zohoarc; b=FjOnMPyQQAiXxU3fgs5g0Y3qgqryzFXos2zOaVQxpBiw0DbgHqxyIotJPV1iwplgdy1LqQN47K3k29kn3+SO6E7Et3Oo8+7rga1+BW36LYep2+jKWJlIaGzd7FX0j6CETLkS8pOuOjcJH9i0r93+u/T9DPg037OkAVL/KtzTMBM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565679458; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=krxldVBzMpBvl8W+ii85B+vPxUP0wmK+EWJps0ncoSs=; b=XWJog1p0T5MREOFJI/prXGjlaXxdjC58YDSSWecsD88QjaFarB9nXNHRT+O4+KKXJomZp55GR4/y4gGzDoRHFMSq/2WGw8O2tqkS9oo1gI6CdbQh2nRQ8zobEq1+QMzDmn3WPPZjNkLB9EhqMHswm0TUGdwxNWEKrLGFszZCJJs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1565679458019614.9418091928507; Mon, 12 Aug 2019 23:57:38 -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 1hxQjt-0004bI-SK; Tue, 13 Aug 2019 06:57:01 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxQjs-0004Zp-0n for xen-devel@lists.xenproject.org; Tue, 13 Aug 2019 06:57:00 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id e737a8f2-bd29-11e9-9829-e706058a444a; Mon, 12 Aug 2019 17:52:08 +0000 (UTC) X-Inumbo-ID: e737a8f2-bd29-11e9-9829-e706058a444a DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1565632328; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=CvaysdAuP9fY5tgMszP62ebzI1j1AzwADOXDgH3HlRQ=; b=BgJ6X19hKXlhTbMvZOMBPHGCheOMb4sVdfujEv/wsBzOFlY1AKUxA5YQ KEu7IeNwyGQLvTuDRkK8ACS1BZ0DyovNR4rmywypLRgmwSk7OecWZ9Kf3 SvV80T+NAETrGX3dmUgHHq6VaNIozXtFKEp5buxlE8jGT4cusZqkjxm4L A=; Authentication-Results: esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.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=esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: BLs6zp28b5DtWqQEOtH68QGcJYKxrQVtGeWLsAKNkJ2GNr66ojIznLiiqwOBlFZDDUApoBrFFX aE4+2ITOaCsZK3eHuFABzWvhM5kilqXtZwxgEjUMSi8pHryDsDNQpIH42chhPl38Fr5hBxUpCS LuCh1i3HGWN8WK69AcGl85r/9DOUv8OU0gvl7rl1tyYdFjmMVAJc4HEg7ri9oJooHfJCH9jlFm XW/Ift/mjmO3r6g+/F0x0aD88v0HGBKAZuLeDf6xRhBSvI7fL/GBHg0MrEGHwNMzMkv9GcB5L3 Nhs= X-SBRS: 2.7 X-MesageID: 4315423 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,378,1559534400"; d="scan'208";a="4315423" From: Andrew Cooper To: Xen-devel Date: Mon, 12 Aug 2019 18:52:05 +0100 Message-ID: <20190812175205.29143-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] x86/AMD-Vi: Fold exit paths of {enable, disable}_iommu() 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: Jan Beulich , Wei Liu , Andrew Cooper , Suravee Suthikulpanit , Boris Ostrovsky , Brian Woods , =?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" X-ZohoMail-DKIM: fail (Header signature does not verify) ... to avoid having multiple spin_unlock_irqrestore() calls. Signed-off-by: Andrew Cooper Acked-by: Brian Woods --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: Boris Ostrovsky CC: Suravee Suthikulpanit CC: Brian Woods Interestingly GCC 6.3 managed to fold disable_iommu() automatically. There= is some partial folding for enable_iommu() (insofar as there is only a single call to _spin_unlock_irqrestore emitted), but this delta yeilds add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-20 (-20) Function old new delta enable_iommu 1844 1824 -20 Total: Before=3D3340299, After=3D3340279, chg -0.00% which means that something wasn't done automatically. Noticed while investigating the S3 regression. --- xen/drivers/passthrough/amd/iommu_init.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/xen/drivers/passthrough/amd/iommu_init.c b/xen/drivers/passthr= ough/amd/iommu_init.c index bb9f33e264..bb5a3e57c9 100644 --- a/xen/drivers/passthrough/amd/iommu_init.c +++ b/xen/drivers/passthrough/amd/iommu_init.c @@ -899,11 +899,8 @@ static void enable_iommu(struct amd_iommu *iommu) =20 spin_lock_irqsave(&iommu->lock, flags); =20 - if ( iommu->enabled ) - { - spin_unlock_irqrestore(&iommu->lock, flags);=20 - return; - } + if ( unlikely(iommu->enabled) ) + goto out; =20 amd_iommu_erratum_746_workaround(iommu); =20 @@ -957,6 +954,8 @@ static void enable_iommu(struct amd_iommu *iommu) amd_iommu_flush_all_caches(iommu); =20 iommu->enabled =3D 1; + + out: spin_unlock_irqrestore(&iommu->lock, flags); } =20 @@ -966,11 +965,8 @@ static void disable_iommu(struct amd_iommu *iommu) =20 spin_lock_irqsave(&iommu->lock, flags); =20 - if ( !iommu->enabled ) - { - spin_unlock_irqrestore(&iommu->lock, flags); - return; - } + if ( unlikely(!iommu->enabled) ) + goto out; =20 if ( !iommu->ctrl.int_cap_xt_en ) amd_iommu_msi_enable(iommu, IOMMU_CONTROL_DISABLED); @@ -988,6 +984,7 @@ static void disable_iommu(struct amd_iommu *iommu) =20 iommu->enabled =3D 0; =20 + out: spin_unlock_irqrestore(&iommu->lock, flags); } =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel