From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50294) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a6bhA-00012L-Dy for qemu-devel@nongnu.org; Wed, 09 Dec 2015 05:10:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a6bh5-0006qr-QI for qemu-devel@nongnu.org; Wed, 09 Dec 2015 05:10:00 -0500 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]:32891) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a6bh5-0006qg-Hq for qemu-devel@nongnu.org; Wed, 09 Dec 2015 05:09:55 -0500 Received: by wmec201 with SMTP id c201so251962339wme.0 for ; Wed, 09 Dec 2015 02:09:55 -0800 (PST) References: <00fe01d1210c$1be12880$53a37980$@samsung.com> <1447884282.4697.111.camel@redhat.com> <013101d122b5$240ef500$6c2cdf00$@samsung.com> From: Alex =?utf-8?Q?Benn=C3=A9e?= In-reply-to: <013101d122b5$240ef500$6c2cdf00$@samsung.com> Date: Wed, 09 Dec 2015 10:09:53 +0000 Message-ID: <87oae0orv2.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] vfio: Align iova also to IOMMU page size List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Pavel Fedin Cc: 'Peter Maydell' , 'Alex Williamson' , qemu-devel@nongnu.org Pavel Fedin writes: > Hello! > >> > On some architectures TARGET_PAGE_ALIGN() is not enough to get the rig= ht >> > alignment. For example on ARM TARGET_PAGE_BITS is 10 because some old = CPUs >> > support 1K page size, while minimum SMMU page size is 4K. >> > >> > This fixes problems like: >> > >> > 2015-11-17T07:37:42.892265Z qemu-system-aarch64: VFIO_MAP_DMA: -22 >> > 2015-11-17T07:37:42.892309Z qemu-system-aarch64: vfio_dma_map(0x223da2= 30, 0x80002f0400, >> 0x10fc00, 0x7f89b40400) =3D -22 (Invalid >> > argument) >> > qemu: hardware error: vfio: DMA mapping failed, unable to continue > > [skip] > >> I don't understand how this is supposed to work, if we align to a larger >> size than the processor, then there are processor size pages of RAM than >> could be handed out as DMA targets for devices, but we can't map them >> through the IOMMU. Thus if the guest tries to use them, we get IOMMU >> faults in the host and likely memory corruption in the guest because the >> device can't read or write to the page it's supposed to. This doesn't >> seem like the right solution. > > Well, this was my first try on the problem. I've got your idea. But i gu= ess we should discuss the proper solution then. > So, i've got this problem on ARM64. On ARM64 we actually can never have = 1K pages. This page size was supported only by old 32-bit ARM CPUs, up to A= RMv5 IIRC, then it was dropped. Linux OS never even used it. > But, since qemu can emulate those ancient CPUs, TARGET_PAGE_BITS is defi= ned to 10 for ARM. And, ARM64 and ARM32 is actually the same target for qem= u, so this is why we still get it. > Perhaps, TARGET_PAGE_BITS should be a variable for ARM, and we should > set it according to the actual used CPU. Then this IOMMU alignment > problem would disappear automatically. What do you think? Yes it should be. For one thing we pay a fairly high performance penalty for using these smaller pages for no reason. What the best way to do this remains to be seen as I think there a lot of fixed sized arrays currently in the system based on various derivations of TARGET_PAGE_BITS. > Cc'ed Peter since he is the main ARM guy here. > > Kind regards, > Pavel Fedin > Expert Engineer > Samsung Electronics Research center Russia -- Alex Benn=C3=A9e