From nobody Thu Oct 30 15:31:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525818008850700.7093081895194; Tue, 8 May 2018 15:20:08 -0700 (PDT) Received: from localhost ([::1]:53530 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGAxs-0007JT-3D for importer@patchew.org; Tue, 08 May 2018 18:20:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGAsy-0002x6-RM for qemu-devel@nongnu.org; Tue, 08 May 2018 18:15:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGAsv-0001Lt-Nz for qemu-devel@nongnu.org; Tue, 08 May 2018 18:15:04 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:35365) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGAsv-0001LO-Ic for qemu-devel@nongnu.org; Tue, 08 May 2018 18:15:01 -0400 Received: by mail-wm0-x241.google.com with SMTP id o78-v6so24237797wmg.0 for ; Tue, 08 May 2018 15:15:01 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-189-60.clienti.tiscali.it. [78.12.189.60]) by smtp.gmail.com with ESMTPSA id c15-v6sm14020129edr.78.2018.05.08.15.14.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 15:14:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=MSp40CTpss7IVoVC6Hne8/lZ2KCLOlSvefVxhHPqTN0=; b=a0efE84Ne47Ux/CnKVGcpbffqklaRcgqFum58LsFylEgo0tCy+sNs5tTnpymr8Yy9S F8m8HkMGhx1R2CotphhCsmcu0U5DL07x9Eg2wx7ewZym6FoLnEjsOEoz9MHUVnbOuWnx C/Z6b7LA+DKb1gLNmZuawYCUI3EviHSBdRFsiZo3nPXOVoLP3ucbMQ8qVIqsy5tYrBfP 08JFknjQtm/niHdgBYgy09rVVqrYYXmIvBNqUTVctpzZ/Qk3KBbsh2mDy9I/fUfsANxh mIZVgS038NbR7d8yppHMzgCWjtxu8Qbbds17Vvz1DNWRRIlvFrJgSGnxqg7bd0xw+FXm e1uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=MSp40CTpss7IVoVC6Hne8/lZ2KCLOlSvefVxhHPqTN0=; b=VNUCEJh69nUTa8No+x6/d3VCPwyUv1XM8LZyqR3xwUmJZB/mD44XpM5PoLS+JWW4t7 fV3OJz38Cc7bL+8Mds1BlXggF9UbXNKAoKF1qJtQ2EwUHLil9QHHNhdKBB+9OfU2dHfF p4p9UXhELkTSdv/SQexXQysKlmJzr7J1sO9SVnDIn7AHh0neZHLOcph9Oy82Kz84LJ1g 8F27FyX2u5ivlfLpb4nsukP5mbMhLjdTlapRB/gKTjkT74CbQ1huh31KhhcLICCiMMXj 6e7DedoYLfcAfARQxqnxDLZbFzvPfIZvaud49EeHUZ5G4r5eUKdO/Jfgr0/jEEx33KZY 0stw== X-Gm-Message-State: ALQs6tCX32bhwf7eEkBcAhHFjfgZPWPx930koLnyu6Rk0CpcHK6X8aX0 XYxioL1GPg4itwUOav85IGfRNYuj X-Google-Smtp-Source: AB8JxZpAWspj6Bw34co6DFHPx9Z6OZadSSKt0dKEOZkeqa9cEFFsaiZqXC3iS0D5kCu+1Dt+sKO+TA== X-Received: by 2002:a50:8ecf:: with SMTP id x15-v6mr56769268edx.128.1525817700336; Tue, 08 May 2018 15:15:00 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 9 May 2018 00:14:25 +0200 Message-Id: <1525817687-34620-9-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1525817687-34620-1-git-send-email-pbonzini@redhat.com> References: <1525817687-34620-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PULL 08/30] exec: small changes to flatview_do_translate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Prepare for extracting the IOMMU part to a separate function. Mostly cosmetic; the only semantic change is that, if there is more than one cascaded IOMMU and the second one fails to translate, *plen_out is now adjusted according to the page mask of the first IOMMU. Reviewed-by: Peter Xu Signed-off-by: Paolo Bonzini --- exec.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/exec.c b/exec.c index c7fcefa..8354cdc 100644 --- a/exec.c +++ b/exec.c @@ -476,6 +476,7 @@ address_space_translate_internal(AddressSpaceDispatch *= d, hwaddr addr, hwaddr *x * would tell. It can be @NULL if we don't care about it. * @is_write: whether the translation operation is for write * @is_mmio: whether this can be MMIO, set true if it can + * @target_as: the address space targeted by the IOMMU * * This function is called from RCU critical section */ @@ -495,14 +496,14 @@ static MemoryRegionSection flatview_do_translate(Flat= View *fv, hwaddr page_mask =3D (hwaddr)(-1); hwaddr plen =3D (hwaddr)(-1); =20 - if (plen_out) { - plen =3D *plen_out; + if (!plen_out) { + plen_out =3D &plen; } =20 for (;;) { section =3D address_space_translate_internal( - flatview_to_dispatch(fv), addr, &addr, - &plen, is_mmio); + flatview_to_dispatch(fv), addr, xlat, + plen_out, is_mmio); =20 iommu_mr =3D memory_region_get_iommu(section->mr); if (!iommu_mr) { @@ -510,35 +511,29 @@ static MemoryRegionSection flatview_do_translate(Flat= View *fv, } imrc =3D memory_region_get_iommu_class_nocheck(iommu_mr); =20 + addr =3D *xlat; iotlb =3D imrc->translate(iommu_mr, addr, is_write ? IOMMU_WO : IOMMU_RO); - addr =3D ((iotlb.translated_addr & ~iotlb.addr_mask) - | (addr & iotlb.addr_mask)); - page_mask &=3D iotlb.addr_mask; - plen =3D MIN(plen, (addr | iotlb.addr_mask) - addr + 1); if (!(iotlb.perm & (1 << is_write))) { goto translate_fail; } =20 + addr =3D ((iotlb.translated_addr & ~iotlb.addr_mask) + | (addr & iotlb.addr_mask)); + page_mask &=3D iotlb.addr_mask; + *plen_out =3D MIN(*plen_out, (addr | iotlb.addr_mask) - addr + 1); fv =3D address_space_to_flatview(iotlb.target_as); *target_as =3D iotlb.target_as; } =20 - *xlat =3D addr; - - if (page_mask =3D=3D (hwaddr)(-1)) { - /* Not behind an IOMMU, use default page size. */ - page_mask =3D ~TARGET_PAGE_MASK; - } - if (page_mask_out) { + if (page_mask =3D=3D (hwaddr)(-1)) { + /* Not behind an IOMMU, use default page size. */ + page_mask =3D ~TARGET_PAGE_MASK; + } *page_mask_out =3D page_mask; } =20 - if (plen_out) { - *plen_out =3D plen; - } - return *section; =20 translate_fail: --=20 1.8.3.1