From nobody Mon May 6 06:55:57 2024 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; 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 Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507290749762622.9564736960389; Fri, 6 Oct 2017 04:52:29 -0700 (PDT) Received: from localhost ([::1]:44247 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0RB2-0006g8-2p for importer@patchew.org; Fri, 06 Oct 2017 07:52:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60355) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0R5a-0002Yx-AP for qemu-devel@nongnu.org; Fri, 06 Oct 2017 07:46:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e0R5Z-00011T-2J for qemu-devel@nongnu.org; Fri, 06 Oct 2017 07:46:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49720) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e0R5Y-00010e-Pt; Fri, 06 Oct 2017 07:46:44 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1D3E85547; Fri, 6 Oct 2017 11:46:43 +0000 (UTC) Received: from max-t460s.redhat.com (ovpn-112-35.ams2.redhat.com [10.36.112.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id A811964431; Fri, 6 Oct 2017 11:46:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C1D3E85547 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=maxime.coquelin@redhat.com From: Maxime Coquelin To: peterx@redhat.com, pbonzini@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Date: Fri, 6 Oct 2017 13:46:23 +0200 Message-Id: <20171006114624.10771-2-maxime.coquelin@redhat.com> In-Reply-To: <20171006114624.10771-1-maxime.coquelin@redhat.com> References: <20171006114624.10771-1-maxime.coquelin@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 06 Oct 2017 11:46:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/2] exec: add page_mask for 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: , Cc: Maxime Coquelin , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Xu The function is originally used for flatview_space_translate() and what we care about most is (xlat, plen) range. However for iotlb requests, we don't really care about "plen", but the size of the page that "xlat" is located on. While, plen cannot really contain this information. A simple example to show why "plen" is not good for IOTLB translations: E.g., for huge pages, it is possible that guest mapped 1G huge page on device side that used this GPA range: 0x100000000 - 0x13fffffff Then let's say we want to translate one IOVA that finally mapped to GPA 0x13ffffe00 (which is located on this 1G huge page). Then here we'll get: (xlat, plen) =3D (0x13fffe00, 0x200) So the IOTLB would be only covering a very small range since from "plen" (which is 0x200 bytes) we cannot tell the size of the page. Actually we can really know that this is a huge page - we just throw the information away in flatview_do_translate(). This patch introduced "page_mask" optional parameter to capture that page mask info. Also, I made "plen" an optional parameter as well, with some comments for the whole function. No functional change yet. Signed-off-by: Peter Xu Signed-off-by: Maxime Coquelin --- exec.c | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/exec.c b/exec.c index 7a80460725..a5f3828445 100644 --- a/exec.c +++ b/exec.c @@ -467,11 +467,29 @@ address_space_translate_internal(AddressSpaceDispatch= *d, hwaddr addr, hwaddr *x return section; } =20 -/* Called from RCU critical section */ +/** + * flatview_do_translate - translate an address in FlatView + * + * @fv: the flat view that we want to translate on + * @addr: the address to be translated in above address space + * @xlat: the translated address offset within memory region. It + * cannot be @NULL. + * @plen_out: valid read/write length of the translated address. It + * can be @NULL when we don't care about it. + * @page_mask_out: page mask for the translated address. This + * should only be meaningful for IOMMU translated + * addresses, since there may be huge pages that this bit + * 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 + * + * This function is called from RCU critical section + */ static MemoryRegionSection flatview_do_translate(FlatView *fv, hwaddr addr, hwaddr *xlat, - hwaddr *plen, + hwaddr *plen_out, + hwaddr *page_mask_out, bool is_write, bool is_mmio, AddressSpace **target_as) @@ -480,11 +498,17 @@ static MemoryRegionSection flatview_do_translate(Flat= View *fv, MemoryRegionSection *section; IOMMUMemoryRegion *iommu_mr; IOMMUMemoryRegionClass *imrc; + hwaddr page_mask =3D ~TARGET_PAGE_MASK; + hwaddr plen =3D (hwaddr)(-1); + + if (plen_out) { + plen =3D *plen_out; + } =20 for (;;) { section =3D address_space_translate_internal( flatview_to_dispatch(fv), addr, &addr, - plen, is_mmio); + &plen, is_mmio); =20 iommu_mr =3D memory_region_get_iommu(section->mr); if (!iommu_mr) { @@ -496,7 +520,8 @@ static MemoryRegionSection flatview_do_translate(FlatVi= ew *fv, IOMMU_WO : IOMMU_RO); addr =3D ((iotlb.translated_addr & ~iotlb.addr_mask) | (addr & iotlb.addr_mask)); - *plen =3D MIN(*plen, (addr | iotlb.addr_mask) - addr + 1); + 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; } @@ -507,6 +532,14 @@ static MemoryRegionSection flatview_do_translate(FlatV= iew *fv, =20 *xlat =3D addr; =20 + if (page_mask_out) { + *page_mask_out =3D page_mask; + } + + if (plen_out) { + *plen_out =3D plen; + } + return *section; =20 translate_fail: @@ -525,7 +558,7 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpac= e *as, hwaddr addr, =20 /* This can never be MMIO. */ section =3D flatview_do_translate(address_space_to_flatview(as), addr, - &xlat, &plen, is_write, false, &as); + &xlat, &plen, NULL, is_write, false, &= as); =20 /* Illegal translation */ if (section.mr =3D=3D &io_mem_unassigned) { @@ -569,7 +602,8 @@ MemoryRegion *flatview_translate(FlatView *fv, hwaddr a= ddr, hwaddr *xlat, AddressSpace *as =3D NULL; =20 /* This can be MMIO, so setup MMIO bit. */ - section =3D flatview_do_translate(fv, addr, xlat, plen, is_write, true= , &as); + section =3D flatview_do_translate(fv, addr, xlat, plen, NULL, + is_write, true, &as); mr =3D section.mr; =20 if (xen_enabled() && memory_access_is_direct(mr, is_write)) { --=20 2.13.6 From nobody Mon May 6 06:55:57 2024 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; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507290653032893.3479057182456; Fri, 6 Oct 2017 04:50:53 -0700 (PDT) Received: from localhost ([::1]:44241 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0R9T-0005NZ-CF for importer@patchew.org; Fri, 06 Oct 2017 07:50:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60371) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0R5c-0002fi-LS for qemu-devel@nongnu.org; Fri, 06 Oct 2017 07:46:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e0R5b-00015f-Ub for qemu-devel@nongnu.org; Fri, 06 Oct 2017 07:46:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57114) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e0R5b-000155-Nn; Fri, 06 Oct 2017 07:46:47 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C115A20B17; Fri, 6 Oct 2017 11:46:46 +0000 (UTC) Received: from max-t460s.redhat.com (ovpn-112-35.ams2.redhat.com [10.36.112.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42E1163F77; Fri, 6 Oct 2017 11:46:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C115A20B17 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=maxime.coquelin@redhat.com From: Maxime Coquelin To: peterx@redhat.com, pbonzini@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Date: Fri, 6 Oct 2017 13:46:24 +0200 Message-Id: <20171006114624.10771-3-maxime.coquelin@redhat.com> In-Reply-To: <20171006114624.10771-1-maxime.coquelin@redhat.com> References: <20171006114624.10771-1-maxime.coquelin@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 06 Oct 2017 11:46:46 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/2] exec: simplify address_space_get_iotlb_entry 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: , Cc: Maxime Coquelin , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Xu This patch let address_space_get_iotlb_entry() to use the newly introduced page_mask parameter in flatview_do_translate(). Then we will be sure the IOTLB can be aligned to page mask, also we should nicely support huge pages now when introducing a764040. Fixes: a764040 ("exec: abstract address_space_do_translate()") Signed-off-by: Peter Xu Signed-off-by: Maxime Coquelin Acked-by: Michael S. Tsirkin --- exec.c | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/exec.c b/exec.c index a5f3828445..f6baa4711e 100644 --- a/exec.c +++ b/exec.c @@ -551,14 +551,14 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSp= ace *as, hwaddr addr, bool is_write) { MemoryRegionSection section; - hwaddr xlat, plen; + hwaddr xlat, page_mask; =20 - /* Try to get maximum page mask during translation. */ - plen =3D (hwaddr)-1; - - /* This can never be MMIO. */ - section =3D flatview_do_translate(address_space_to_flatview(as), addr, - &xlat, &plen, NULL, is_write, false, &= as); + /* + * This can never be MMIO, and we don't really care about plen, + * but page mask. + */ + section =3D flatview_do_translate(address_space_to_flatview(as), addr,= &xlat, + NULL, &page_mask, is_write, false, &as= ); =20 /* Illegal translation */ if (section.mr =3D=3D &io_mem_unassigned) { @@ -569,22 +569,11 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSp= ace *as, hwaddr addr, xlat +=3D section.offset_within_address_space - section.offset_within_region; =20 - if (plen =3D=3D (hwaddr)-1) { - /* - * We use default page size here. Logically it only happens - * for identity mappings. - */ - plen =3D TARGET_PAGE_SIZE; - } - - /* Convert to address mask */ - plen -=3D 1; - return (IOMMUTLBEntry) { .target_as =3D as, - .iova =3D addr & ~plen, - .translated_addr =3D xlat & ~plen, - .addr_mask =3D plen, + .iova =3D addr & ~page_mask, + .translated_addr =3D xlat & ~page_mask, + .addr_mask =3D page_mask, /* IOTLBs are for DMAs, and DMA only allows on RAMs. */ .perm =3D IOMMU_RW, }; --=20 2.13.6