From patchwork Mon Aug 12 17:52:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11091307 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 22AF9912 for ; Tue, 13 Aug 2019 06:57:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 125BF282EC for ; Tue, 13 Aug 2019 06:57:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06A3C28595; Tue, 13 Aug 2019 06:57:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 49A55282EC for ; Tue, 13 Aug 2019 06:57:48 +0000 (UTC) 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 X-Inumbo-ID: e737a8f2-bd29-11e9-9829-e706058a444a 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) 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 (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_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP ... to avoid having multiple spin_unlock_irqrestore() calls. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné 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=3340299, After=3340279, 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/passthrough/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) spin_lock_irqsave(&iommu->lock, flags); - if ( iommu->enabled ) - { - spin_unlock_irqrestore(&iommu->lock, flags); - return; - } + if ( unlikely(iommu->enabled) ) + goto out; amd_iommu_erratum_746_workaround(iommu); @@ -957,6 +954,8 @@ static void enable_iommu(struct amd_iommu *iommu) amd_iommu_flush_all_caches(iommu); iommu->enabled = 1; + + out: spin_unlock_irqrestore(&iommu->lock, flags); } @@ -966,11 +965,8 @@ static void disable_iommu(struct amd_iommu *iommu) spin_lock_irqsave(&iommu->lock, flags); - if ( !iommu->enabled ) - { - spin_unlock_irqrestore(&iommu->lock, flags); - return; - } + if ( unlikely(!iommu->enabled) ) + goto out; 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) iommu->enabled = 0; + out: spin_unlock_irqrestore(&iommu->lock, flags); }