From nobody Sun Apr 28 23:37:04 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) 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 1507223731898701.0145085545744; Thu, 5 Oct 2017 10:15:31 -0700 (PDT) Received: from localhost ([::1]:41069 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e09js-0001kA-Et for importer@patchew.org; Thu, 05 Oct 2017 13:15:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60442) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e09if-000117-JU for qemu-devel@nongnu.org; Thu, 05 Oct 2017 13:13:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e09ib-0002lA-Jm for qemu-devel@nongnu.org; Thu, 05 Oct 2017 13:13:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39536) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e09ib-0002ka-B3; Thu, 05 Oct 2017 13:13:53 -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 7376613A9D; Thu, 5 Oct 2017 17:13:52 +0000 (UTC) Received: from max-t460s.redhat.com (ovpn-112-45.ams2.redhat.com [10.36.112.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B916600C4; Thu, 5 Oct 2017 17:13:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7376613A9D Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.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: Thu, 5 Oct 2017 19:13:08 +0200 Message-Id: <20171005171309.1250-2-maxime.coquelin@redhat.com> In-Reply-To: <20171005171309.1250-1-maxime.coquelin@redhat.com> References: <20171005171309.1250-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.29]); Thu, 05 Oct 2017 17:13:52 +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] [REBASED 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_6 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 Acked-by: Michael S. Tsirkin --- exec.c | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/exec.c b/exec.c index 7a80460725..c5f2752f7d 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 Sun Apr 28 23:37:04 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 1507223813201167.29309885930593; Thu, 5 Oct 2017 10:16:53 -0700 (PDT) Received: from localhost ([::1]:41082 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e09lR-0002oM-Cm for importer@patchew.org; Thu, 05 Oct 2017 13:16:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60441) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e09if-000116-JU for qemu-devel@nongnu.org; Thu, 05 Oct 2017 13:13:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e09id-0002mw-SQ for qemu-devel@nongnu.org; Thu, 05 Oct 2017 13:13:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53068) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e09id-0002mU-Mx; Thu, 05 Oct 2017 13:13:55 -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 D8B8CC04AC4E; Thu, 5 Oct 2017 17:13:54 +0000 (UTC) Received: from max-t460s.redhat.com (ovpn-112-45.ams2.redhat.com [10.36.112.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7970600C4; Thu, 5 Oct 2017 17:13:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D8B8CC04AC4E Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.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: Thu, 5 Oct 2017 19:13:09 +0200 Message-Id: <20171005171309.1250-3-maxime.coquelin@redhat.com> In-Reply-To: <20171005171309.1250-1-maxime.coquelin@redhat.com> References: <20171005171309.1250-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.31]); Thu, 05 Oct 2017 17:13:55 +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] [REBASED 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 c5f2752f7d..39fc96a19e 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