Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3837704ybz; Tue, 28 Apr 2020 01:04:48 -0700 (PDT) X-Google-Smtp-Source: APiQypKzkEThktCgXVq7r4GB+u5JrXSXLGEhOJYoXomxXf96O7ZuGcxZ40ncCrtFWJ9OuheY5tz/ X-Received: by 2002:a17:906:fcaf:: with SMTP id qw15mr23161974ejb.236.1588061088414; Tue, 28 Apr 2020 01:04:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588061088; cv=none; d=google.com; s=arc-20160816; b=Kf3NmkNR6LTcrdxlcw/h5pm7xhtKeyvdXG5DSDCur8OpXSTUeFaCPW/ab03ttFPokP haFf2SQnTB9lDX8BGbWJPJuEFSnAZKbGjVt/AHRet39RG5QjzGAcTgl2n/rGaJLFoHys SVF2wlprhb1CTeyPn37tqmzai4ft7l/I+338YaSXqN0JHKuwHGVRnF9XsrshpT63uTpj 0MH3R36P7n+2l9gv6ABSZHee39rAs3yRWzjErSHcahmbFiEDnQo8OE5J4fU9AO+n5ng5 eWeJyQLtEcJbe0vjafez17UC1Z+V7zip2VhlKV+4mocMPaDH1XR2khcWOf1MszX4OMVG 0VkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=0Gc8wiZaH5vxzoL7Y4RD61mnokWImM3/OUm105M5x4Q=; b=y+6DwY9PaMw8uQXaaUIp/CiSm7HNCZ9BX0LsvyhvwlhZY38y0BFo2t+P0PVbr9mtwu tHkV+auJPASxkzy11i/twmVr7BeMoesylBj3ZJL+CFqBHo/DWqbz1JimwjcSFprXmgTn omIChytFnKVh8dB2Q/h+fW1gLhwLKv+vrMlQ+CTi3wxMT8h7MXuiAQlTOBBD+dZhzRqP uPLGxx3hlECV62BnU0JEP+z+mcJipaB55k7Fr/Vsix113HSXWo/Rd+xQS2bVDvzJ0mrH 7u2QUkrtHRTgs2sIZsD8Vf91UzQCQBVgWhXbM63XFG/rJGAU1xvNf98va8LwsFZKeB2T 5Gow== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=AkRzSgUB; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e22si1372765eje.203.2020.04.28.01.04.25; Tue, 28 Apr 2020 01:04:48 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=AkRzSgUB; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726775AbgD1ICU (ORCPT + 99 others); Tue, 28 Apr 2020 04:02:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726637AbgD1ICP (ORCPT ); Tue, 28 Apr 2020 04:02:15 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74E0BC03C1A9 for ; Tue, 28 Apr 2020 01:02:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=0Gc8wiZaH5vxzoL7Y4RD61mnokWImM3/OUm105M5x4Q=; b=AkRzSgUBS3spTGGb1FU2ZdnFp4 7BKimlNU77GlBbuUM/8B5MPQQ/E6pQxNnqbGv+7iaZdB1yzXSBR4E6U5GIwvyG6VLpIOzmZt8b+Af FhXp4/msJvZ5wc9Q/RiSGYZjj5WugzIgMCgyvRtTHLiMoRI/isejvWR1rP9hHQqpa9qWD+mUpziT9 uaVqa13Hhc/t59XAU11bOMVnUb4ynS0/3sHmfE672BTSnYmRzfdf+63SFCOFf2DKOM2/lg8NAzimF fD0PTuRTAIjTIr+c2X26hXxC4p/Xa5P+lwbVfvO9LSTlCL0fe8zEy86Odd6yWyhlALdnxCk28aydq KqW8hdGw==; Received: from hch by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jTLBy-0000XO-Ed; Tue, 28 Apr 2020 08:02:10 +0000 Date: Tue, 28 Apr 2020 01:02:10 -0700 From: Christoph Hellwig To: peng.fan@nxp.com Cc: konrad.wilk@oracle.com, boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, xen-devel@lists.xenproject.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-imx@nxp.com Subject: Re: [PATCH] xen/swiotlb: correct the check for xen_destroy_contiguous_region Message-ID: <20200428080210.GA25643@infradead.org> References: <1588059225-11245-1-git-send-email-peng.fan@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1588059225-11245-1-git-send-email-peng.fan@nxp.com> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html 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 03:33:45PM +0800, peng.fan@nxp.com wrote: > > In xen_swiotlb_alloc_coherent, if !(dev_addr + size - 1 <= dma_mask) or > range_straddles_page_boundary(phys, size) are true, it will > create contiguous region. So when free, we need to free contiguous > region use upper check condition. > > Signed-off-by: Peng Fan > --- > drivers/xen/swiotlb-xen.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > 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 *hwdev, size_t size, void *vaddr, > /* Convert the size to actually allocated. */ > size = 1UL << (order + XEN_PAGE_SHIFT); > > - 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))) No need for the inner braces. But more importantly please factor our a helper that can be used by alloc and free to make sure that they always stay in sync. Something like: static inline bool xen_swiotlb_need_contiguous_region(struct device *dev, phys_addr_t phys, size_t size) { return xen_phys_to_bus(phys) + size - 1 > dev->coherent_dma_mask || range_straddles_page_boundary(phys, size)) }