Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1579614yba; Thu, 25 Apr 2019 02:07:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqzPsHqyGSqXJ69xAy4vC2Tvl594hahHXGmEZKEQ8EOWCOIqllelsxgbiXvKyRfL1WpqXHAp X-Received: by 2002:a63:2c4a:: with SMTP id s71mr35663488pgs.373.1556183235491; Thu, 25 Apr 2019 02:07:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556183235; cv=none; d=google.com; s=arc-20160816; b=SzDLY5v65Z8DW98Ebt6fP6aqCZKrkMYrUBS7tVo4qbh6miOirDUXJiN6dE0tqaM0LB jQ5J2w35u+zEZiurV9JBroPrPUbe200+clmXLy16yhSoFyBcotnb99RYVxPwpCKmGwbU X0eeAM3gAocmOInHCYm7wPnOS1vJx145Oonz4vu2wviPIlp8Hvh9//SGMRis/jgIIiv9 Sl7c17DRDmXlW/ysbMNbo5V6og/rL75sdThKn3LuEzYttqlgK1kZCcwG0fUApee7g3C1 icbr0LYnCK9mjYaaAMhawjmqkyqOWsLh7ekXHWJ4iccqRyKlzQaBUhpozrAFNe3zhmrs WQlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:in-reply-to:references :subject:cc:to:from:date:message-id; bh=rRU94DAsw1BOHjKs2X/I1YAT09qqprMrn+CDKye82lg=; b=iXvpVYbAcK9vLUXuCiV7l1+fDVNOiYGolGP7zTnhjrrXEuiHRSIN9MNBAqFmSNPrwO oltk9vcN+JjcSW6fTkSoWIqO+zgUBqXdQAK7PXAo7nFUHnk6okb0dBfvVKKOjJPKkzpo yF2hfntPkKNiLdnls/cvK0SixMk8cfZ3aXHNG4XEbkK/Pbp3AdrSImV36ufEsnTCWzd1 qskuXI9mWuj5fp5nbM+fOQnEXepl9hQjLapIUlTKOSHdAII4GAy9uRXXXiTwnfTHFD58 f8UVMDz2oaYtwsEAd7i+gmhmwjW3MJisGwkRA8EhVeXbELipqO2R59JzlhREeV69ykaB TNXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j184si23231593pfb.106.2019.04.25.02.06.58; Thu, 25 Apr 2019 02:07:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727485AbfDYIxp convert rfc822-to-8bit (ORCPT + 99 others); Thu, 25 Apr 2019 04:53:45 -0400 Received: from prv1-mh.provo.novell.com ([137.65.248.33]:52852 "EHLO prv1-mh.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726150AbfDYIxp (ORCPT ); Thu, 25 Apr 2019 04:53:45 -0400 Received: from INET-PRV1-MTA by prv1-mh.provo.novell.com with Novell_GroupWise; Thu, 25 Apr 2019 02:53:44 -0600 Message-Id: <5CC175950200007800228E80@prv1-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 18.1.0 Date: Thu, 25 Apr 2019 02:53:41 -0600 From: "Jan Beulich" To: "Juergen Gross" Cc: "Stefano Stabellini" , , "xen-devel" , "Boris Ostrovsky" , "Konrad Rzeszutek Wilk" , , Subject: Re: [Xen-devel] [PATCH 1/3] xen/swiotlb: fix condition for calling xen_destroy_contiguous_region() References: <20190423105457.17502-1-jgross@suse.com> <20190423105457.17502-2-jgross@suse.com> In-Reply-To: <20190423105457.17502-2-jgross@suse.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8BIT Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org >>> On 23.04.19 at 12:54, wrote: > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -360,8 +360,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 (((dev_addr + size - 1 <= dma_mask)) || > - range_straddles_page_boundary(phys, size)) > + if ((dev_addr + size - 1 <= dma_mask) && > + !WARN_ON(range_straddles_page_boundary(phys, size))) > xen_destroy_contiguous_region(phys, order); On the allocation side we have if (((dev_addr + size - 1 <= dma_mask)) && !range_straddles_page_boundary(phys, size)) *dma_handle = dev_addr; else { if (xen_create_contiguous_region(phys, order, fls64(dma_mask), dma_handle) != 0) { xen_free_coherent_pages(hwdev, size, ret, (dma_addr_t)phys, attrs); return NULL; } } which is (as far as the function call is concerned) if ((dev_addr + size - 1 > dma_mask) || range_straddles_page_boundary(phys, size)) xen_create_contiguous_region(...); So I don't think your transformation is correct. Even worse, both parts of the condition in xen_swiotlb_free_coherent() act on an address that is the _result_ of the prior xen_create_contiguous_region(), i.e. the address should always match _both_ criteria anyway. Whereas what you really want is undo the xen_create_contiguous_region() only when it actually was called. Otherwise you also shatter contiguous allocations that were contiguous already for other reasons (perhaps just luck). Jan