From nobody Tue Feb 10 06:43:08 2026 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 ARC-Seal: i=1; a=rsa-sha256; t=1599464450; cv=none; d=zohomail.com; s=zohoarc; b=IGQ0w7Wx1Q5r1C0+gf1SpSODYEcU7/g8t3wswAN8sw+CpCbC1axD4yAaA8jwswFmFLSz3CUYJ4iFLN2kouYo6zMmrB6OA98K/U6WLq9MSHNm7Uu36u8jIGeRBMSIYp3SIy3atHn3DlbeLYtOFN11SaPbOZdE93aYoMX5AwuwTeA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599464450; h=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=bcXYSziQEVYnJt2FcTKxwvzJvDf1bktnUlerxuTET0c=; b=AD+bX9SedTuF9WLqzbtseOE7IcjNl+qknbTcd/+n0Sp6dbKFk7OTJxaz3vsQvC1t0bscdFS2oYm1Rut40T3fioJZWjUempLY6zngptjQZa3ZeaH+3Bsk0xWy7OPYhkJKEJkoxdwP6min5Rk0Fs3TZxzIsTPajvSip93hxKVICVw= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1599464450012862.0384703292972; Mon, 7 Sep 2020 00:40:50 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kFBlQ-0003Bb-Ki; Mon, 07 Sep 2020 07:40:32 +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 1kFBlP-0003B9-1d for xen-devel@lists.xenproject.org; Mon, 07 Sep 2020 07:40:31 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5a4bef6d-d5f6-45b0-aa12-87804f4abd64; Mon, 07 Sep 2020 07:40:29 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kFBlN-0000ry-4c; Mon, 07 Sep 2020 07:40:29 +0000 Received: from host86-176-94-160.range86-176.btcentralplus.com ([86.176.94.160] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kFBlM-0008Cf-SD; Mon, 07 Sep 2020 07:40:29 +0000 X-Inumbo-ID: 5a4bef6d-d5f6-45b0-aa12-87804f4abd64 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=bcXYSziQEVYnJt2FcTKxwvzJvDf1bktnUlerxuTET0c=; b=S48bY3xNU86MaV7pOhWN2st8z+ fuJ7YTU2yckWUNYkWjZfO761J3Sdz5u+hEQ7ziwjj/JQ826PvtZjdhuF6zJMH44o13ZLpk8VnDboW 0TqCyo8UuoieGPrVZYKxGg4cBbUtPhjBJBqHx8XRhyGgQwl7t0ZP7kQh+VEnyGBm2qBY=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Jan Beulich Subject: [PATCH v5 3/8] iommu: flush I/O TLB if iommu_map() or iommu_unmap() fail Date: Mon, 7 Sep 2020 08:40:18 +0100 Message-Id: <20200907074023.1392-4-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200907074023.1392-1-paul@xen.org> References: <20200907074023.1392-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @xen.org) Content-Type: text/plain; charset="utf-8" From: Paul Durrant This patch adds a full I/O TLB flush to the error paths of iommu_map() and iommu_unmap(). Without this change callers need constructs such as: rc =3D iommu_map/unmap(...) err =3D iommu_flush(...) if ( !rc ) rc =3D err; With this change, it can be simplified to: rc =3D iommu_map/unmap(...) if ( !rc ) rc =3D iommu_flush(...) because, if the map or unmap fails the flush will be unnecessary. This saves a stack variable and generally makes the call sites tidier. Signed-off-by: Paul Durrant Reviewed-by: Jan Beulich --- Cc: Jan Beulich v5: - Avoid unnecessary flushing if 'page_order' is 0 - Add missing indirection on 'flush_flags' v2: - New in v2 --- xen/drivers/passthrough/iommu.c | 34 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iomm= u.c index 660dc5deb2..f27facd52d 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -274,6 +274,13 @@ int iommu_map(struct domain *d, dfn_t dfn, mfn_t mfn, break; } =20 + /* + * Something went wrong so, if we were dealing with more than a single + * page, flush everything and clear flush flags. + */ + if ( page_order && unlikely(rc) && !iommu_iotlb_flush_all(d, *flush_fl= ags) ) + *flush_flags =3D 0; + return rc; } =20 @@ -283,14 +290,8 @@ int iommu_legacy_map(struct domain *d, dfn_t dfn, mfn_= t mfn, unsigned int flush_flags =3D 0; int rc =3D iommu_map(d, dfn, mfn, page_order, flags, &flush_flags); =20 - if ( !this_cpu(iommu_dont_flush_iotlb) ) - { - int err =3D iommu_iotlb_flush(d, dfn, (1u << page_order), - flush_flags); - - if ( !rc ) - rc =3D err; - } + if ( !this_cpu(iommu_dont_flush_iotlb) && !rc ) + rc =3D iommu_iotlb_flush(d, dfn, (1u << page_order), flush_flags); =20 return rc; } @@ -330,6 +331,13 @@ int iommu_unmap(struct domain *d, dfn_t dfn, unsigned = int page_order, } } =20 + /* + * Something went wrong so, if we were dealing with more than a single + * page, flush everything and clear flush flags. + */ + if ( page_order && unlikely(rc) && !iommu_iotlb_flush_all(d, *flush_fl= ags) ) + *flush_flags =3D 0; + return rc; } =20 @@ -338,14 +346,8 @@ int iommu_legacy_unmap(struct domain *d, dfn_t dfn, un= signed int page_order) unsigned int flush_flags =3D 0; int rc =3D iommu_unmap(d, dfn, page_order, &flush_flags); =20 - if ( !this_cpu(iommu_dont_flush_iotlb) ) - { - int err =3D iommu_iotlb_flush(d, dfn, (1u << page_order), - flush_flags); - - if ( !rc ) - rc =3D err; - } + if ( !this_cpu(iommu_dont_flush_iotlb) && ! rc ) + rc =3D iommu_iotlb_flush(d, dfn, (1u << page_order), flush_flags); =20 return rc; } --=20 2.20.1