mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	iommu@lists.linux-foundation.org,
	xen-devel <xen-devel@lists.xenproject.org>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	lkml <linux-kernel@vger.kernel.org>,
	stable@vger.kernel.org
Subject: Re: [Xen-devel] [PATCH 1/3] xen/swiotlb: fix condition for calling xen_destroy_contiguous_region()
Date: Thu, 25 Apr 2019 10:55:33 +0200	[thread overview]
Message-ID: <38c2907c-2749-e66c-1279-7d74bc20bc35@suse.com> (raw)

On 25/04/2019 10:53, Jan Beulich wrote:
>>>> On 23.04.19 at 12:54, <jgross@suse.com> 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).

Yes, that is what patch 3 does.


Juergen


             reply	other threads:[~2019-04-25  8:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-25  8:55 Juergen Gross [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-04-25  9:03 Juergen Gross
2019-04-23 10:54 [PATCH 0/3] xen/swiotlb: fix an issue and improve swiotlb-xen Juergen Gross
2019-04-23 10:54 ` [PATCH 1/3] xen/swiotlb: fix condition for calling xen_destroy_contiguous_region() Juergen Gross
2019-04-25  8:53   ` [Xen-devel] " Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=38c2907c-2749-e66c-1279-7d74bc20bc35@suse.com \
    --to=jgross@suse.com \
    --cc=JBeulich@suse.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sstabellini@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®