Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4392151ybz; Tue, 28 Apr 2020 10:29:16 -0700 (PDT) X-Google-Smtp-Source: APiQypJ8K1SOV8CRQ5mJpN53cDH/3VSNJAT6WI+lGLLIAa+SYJwsZ4v03HmDhLZfnpFuse0X/+Lm X-Received: by 2002:a50:a285:: with SMTP id 5mr23014122edm.360.1588094956063; Tue, 28 Apr 2020 10:29:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588094956; cv=none; d=google.com; s=arc-20160816; b=Vdv7VDpRADVidoKKgtfpDKrtrvfrukbyrwVKeZhY+k2W6VN3TOizQlqRQdFrRU3IZs KF6WaK7Ajviv86a7OZgbbUClHyYdqvRhs5fB3KlTDlIcHRGehZAESijZ0gnLeCSCEsVr dly2W344OsWsdTm9iHhCCYBuLoNCtF/CIGonS4hngOTNTW2r+qPjFLTqISJEPyBtxu8J 9BJ59Tw5Nfnvc7fDEpMpl0XSyzKfIXQgpoVHgJgM9DOEOjjubMT1LHzDLP6Lsa3B1C9b Hka7cH19w5jbJBg+o2yO2uHf/LrNVeIk0URLjrwV+4IHPKD07jqdozS42V41CtbQvOCF GY6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:user-agent :in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:dkim-signature; bh=a1DRwVeeZI8m8zRrIZSIlkJajtV66/ligL8DUqPAkjE=; b=Y2QW4GsrL+3gcyGoogCR0FcPIFLvxVFLnikw3xWwpSiQBO644ff+JXhVW8FbMRcEsl ffCwMRIujeqIeBqOtZi8wcerov1iUnBHJmPAh16L1SrIkJL46d754OMKURzumWO16Zz1 DGyob1xeOCGJ7ScdLfosXdQpYCdSivkL7VYmlqb0GuaIOUzlZ7HUkXIghYc6Mw3dFawu mb+6E73xeAyHzwplhgy+yn42NQLZnkZsImDGvbNSoK30r1834ShvHPzty6HPhsRO/iUm dOVdj2IMlVWCQJWHT0x9g61EJ1djLfELRtcppDjT26M/wmbgCu+V8zwXAroUOgVWsD5p Dfsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=aJO9db+u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y4si1947335edi.166.2020.04.28.10.28.51; Tue, 28 Apr 2020 10:29:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=aJO9db+u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728365AbgD1RZG (ORCPT + 99 others); Tue, 28 Apr 2020 13:25:06 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:57646 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728022AbgD1RZF (ORCPT ); Tue, 28 Apr 2020 13:25:05 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 03SHMjTX035908; Tue, 28 Apr 2020 17:24:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to : content-transfer-encoding; s=corp-2020-01-29; bh=a1DRwVeeZI8m8zRrIZSIlkJajtV66/ligL8DUqPAkjE=; b=aJO9db+uOkB7e+WYGZXpXPaUytTt5+432QDnBzrkB9IFcDAm8NdTKrnhgbvT90fu5xwA ZfS/N++Pru08Hu4sTwXFhs3NaEABtCV42M4IZQuMuD2W3Xh3GaaAYYYOStSePUOT7hV9 X2IVRvEYZq+fIT+cLXn5Tzc5LR6tq0EOUUBG8ye13FKmxtE4HhmB8ifs7ueHYkXhU0CF j8EF6v8Nsr9DTn9Nu70LDxzl/C9xSaTsCawSc7q4yo1AyQF+vT+jhOtOfOfKiuAD1qSl 0ca+4QpA2ZUocSNimSYRkVjffZRD5BnfNYy8KXGOidf4Ya6FwUWZ+oN3DnEkBmTVRRzF 3w== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 30nucg1bx6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 28 Apr 2020 17:24:54 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 03SHMxng050675; Tue, 28 Apr 2020 17:24:53 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 30my0dseh2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 28 Apr 2020 17:24:53 +0000 Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 03SHOpMO019149; Tue, 28 Apr 2020 17:24:52 GMT Received: from char.us.oracle.com (/10.152.32.25) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 28 Apr 2020 10:24:51 -0700 Received: by char.us.oracle.com (Postfix, from userid 1000) id BC1D26A011D; Tue, 28 Apr 2020 13:25:14 -0400 (EDT) Date: Tue, 28 Apr 2020 13:25:14 -0400 From: Konrad Rzeszutek Wilk To: =?iso-8859-1?Q?J=FCrgen_Gro=DF?= , joe.jin@oracle.com Cc: Peng Fan , "boris.ostrovsky@oracle.com" , "sstabellini@kernel.org" , "xen-devel@lists.xenproject.org" , "iommu@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" , dl-linux-imx Subject: Re: [PATCH] xen/swiotlb: correct the check for xen_destroy_contiguous_region Message-ID: <20200428172514.GA24178@char.us.oracle.com> References: <1588059225-11245-1-git-send-email-peng.fan@nxp.com> <1c01e97a-adcd-a703-55b5-8975b4ce4d2c@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9605 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 spamscore=0 suspectscore=2 adultscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004280137 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9605 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1011 priorityscore=1501 mlxlogscore=999 impostorscore=0 suspectscore=2 malwarescore=0 lowpriorityscore=0 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004280137 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 28, 2020 at 12:19:41PM +0200, J=FCrgen Gro=DF wrote: > On 28.04.20 10:25, Peng Fan wrote: Adding Joe Jin. Joe, didn't you have some ideas on how this could be implemented? > > > Subject: Re: [PATCH] xen/swiotlb: correct the check for > > > xen_destroy_contiguous_region > > >=20 > > > On 28.04.20 09:33, peng.fan@nxp.com wrote: > > > > From: Peng Fan > > > >=20 > > > > When booting xen on i.MX8QM, met: > > > > " > > > > [ 3.602128] Unable to handle kernel paging request at virtual = address > > > 0000000000272d40 > > > > [ 3.610804] Mem abort info: > > > > [ 3.613905] ESR =3D 0x96000004 > > > > [ 3.617332] EC =3D 0x25: DABT (current EL), IL =3D 32 bits > > > > [ 3.623211] SET =3D 0, FnV =3D 0 > > > > [ 3.626628] EA =3D 0, S1PTW =3D 0 > > > > [ 3.630128] Data abort info: > > > > [ 3.633362] ISV =3D 0, ISS =3D 0x00000004 > > > > [ 3.637630] CM =3D 0, WnR =3D 0 > > > > [ 3.640955] [0000000000272d40] user address but active_mm is > > > swapper > > > > [ 3.647983] Internal error: Oops: 96000004 [#1] PREEMPT SMP > > > > [ 3.654137] Modules linked in: > > > > [ 3.677285] Hardware name: Freescale i.MX8QM MEK (DT) > > > > [ 3.677302] Workqueue: events deferred_probe_work_func > > > > [ 3.684253] imx6q-pcie 5f000000.pcie: PCI host bridge to bus 0= 000:00 > > > > [ 3.688297] pstate: 60000005 (nZCv daif -PAN -UAO) > > > > [ 3.688310] pc : xen_swiotlb_free_coherent+0x180/0x1c0 > > > > [ 3.693993] pci_bus 0000:00: root bus resource [bus 00-ff] > > > > [ 3.701002] lr : xen_swiotlb_free_coherent+0x44/0x1c0 > > > > " > > > >=20 > > > > In xen_swiotlb_alloc_coherent, if !(dev_addr + size - 1 <=3D dma_= mask) > > > > or range_straddles_page_boundary(phys, size) are true, it will cr= eate > > > > contiguous region. So when free, we need to free contiguous regio= n use > > > > upper check condition. > > >=20 > > > No, this will break PV guests on x86. > >=20 > > Could you share more details why alloc and free not matching for the = check? >=20 > xen_create_contiguous_region() is needed only in case: >=20 > - the bus address is not within dma_mask, or > - the memory region is not physically contiguous (can happen only for > PV guests) >=20 > In any case it should arrange for the memory to be suitable for the > DMA operation, so to be contiguous and within dma_mask afterwards. So > xen_destroy_contiguous_region() should only ever called for areas > which match above criteria, as otherwise we can be sure > xen_create_contiguous_region() was not used for making the area DMA-abl= e > in the beginning. >=20 > And this is very important in the PV case, as in those guests the page > tables are containing the host-PFNs, not the guest-PFNS, and > xen_create_contiguous_region() will fiddle with host- vs. guest-PFN > arrangements, and xen_destroy_contiguous_region() is reverting this > fiddling. Any call of xen_destroy_contiguous_region() for an area it > was not intended to be called for might swap physical pages beneath > random virtual addresses, which was the reason for this test to be > added by me. >=20 >=20 > Juergen >=20 > >=20 > > Thanks, > > Peng. > >=20 > > >=20 > > > I think there is something wrong with your setup in combination wit= h the ARM > > > xen_create_contiguous_region() implementation. > > >=20 > > > Stefano? > > >=20 > > >=20 > > > Juergen > > >=20 > > > >=20 > > > > Signed-off-by: Peng Fan > > > > --- > > > > drivers/xen/swiotlb-xen.c | 4 ++-- > > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > >=20 > > > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.= c > > > > index b6d27762c6f8..ab96e468584f 100644 > > > > --- a/drivers/xen/swiotlb-xen.c > > > > +++ b/drivers/xen/swiotlb-xen.c > > > > @@ -346,8 +346,8 @@ xen_swiotlb_free_coherent(struct device *hwde= v, > > > size_t size, void *vaddr, > > > > /* Convert the size to actually allocated. */ > > > > size =3D 1UL << (order + XEN_PAGE_SHIFT); > > > >=20 > > > > - if (!WARN_ON((dev_addr + size - 1 > dma_mask) || > > > > - range_straddles_page_boundary(phys, size)) && > > > > + if (((dev_addr + size - 1 > dma_mask) || > > > > + range_straddles_page_boundary(phys, size)) && > > > > TestClearPageXenRemapped(virt_to_page(vaddr))) > > > > xen_destroy_contiguous_region(phys, order); > > > >=20 > > > >=20 > >=20 >=20