All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Stabellini <sstabellini@kernel.org>
To: Jan Beulich <jbeulich@suse.com>
Cc: Juergen Gross <jgross@suse.com>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	lkml <linux-kernel@vger.kernel.org>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH 03/12] swiotlb-xen: maintain slab count properly
Date: Fri, 10 Sep 2021 16:10:47 -0700 (PDT)	[thread overview]
Message-ID: <alpine.DEB.2.21.2109101610380.10523@sstabellini-ThinkPad-T480s> (raw)
In-Reply-To: <dc054cb0-bec4-4db0-fc06-c9fc957b6e66@suse.com>

On Tue, 7 Sep 2021, Jan Beulich wrote:
> Generic swiotlb code makes sure to keep the slab count a multiple of the
> number of slabs per segment. Yet even without checking whether any such
> assumption is made elsewhere, it is easy to see that xen_swiotlb_fixup()
> might alter unrelated memory when calling xen_create_contiguous_region()
> for the last segment, when that's not a full one - the function acts on
> full order-N regions, not individual pages.
> 
> Align the slab count suitably when halving it for a retry. Add a build
> time check and a runtime one. Replace the no longer useful local
> variable "slabs" by an "order" one calculated just once, outside of the
> loop. Re-use "order" for calculating "dma_bits", and change the type of
> the latter as well as the one of "i" while touching this anyway.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -106,27 +106,26 @@ static int is_xen_swiotlb_buffer(struct
>  
>  static int xen_swiotlb_fixup(void *buf, unsigned long nslabs)
>  {
> -	int i, rc;
> -	int dma_bits;
> +	int rc;
> +	unsigned int order = get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT);
> +	unsigned int i, dma_bits = order + PAGE_SHIFT;
>  	dma_addr_t dma_handle;
>  	phys_addr_t p = virt_to_phys(buf);
>  
> -	dma_bits = get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT) + PAGE_SHIFT;
> +	BUILD_BUG_ON(IO_TLB_SEGSIZE & (IO_TLB_SEGSIZE - 1));
> +	BUG_ON(nslabs % IO_TLB_SEGSIZE);
>  
>  	i = 0;
>  	do {
> -		int slabs = min(nslabs - i, (unsigned long)IO_TLB_SEGSIZE);
> -
>  		do {
>  			rc = xen_create_contiguous_region(
> -				p + (i << IO_TLB_SHIFT),
> -				get_order(slabs << IO_TLB_SHIFT),
> +				p + (i << IO_TLB_SHIFT), order,
>  				dma_bits, &dma_handle);
>  		} while (rc && dma_bits++ < MAX_DMA_BITS);
>  		if (rc)
>  			return rc;
>  
> -		i += slabs;
> +		i += IO_TLB_SEGSIZE;
>  	} while (i < nslabs);
>  	return 0;
>  }
> @@ -210,7 +209,7 @@ retry:
>  error:
>  	if (repeat--) {
>  		/* Min is 2MB */
> -		nslabs = max(1024UL, (nslabs >> 1));
> +		nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
>  		bytes = nslabs << IO_TLB_SHIFT;
>  		pr_info("Lowering to %luMB\n", bytes >> 20);
>  		goto retry;
> @@ -245,7 +244,7 @@ retry:
>  		memblock_free(__pa(start), PAGE_ALIGN(bytes));
>  		if (repeat--) {
>  			/* Min is 2MB */
> -			nslabs = max(1024UL, (nslabs >> 1));
> +			nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
>  			bytes = nslabs << IO_TLB_SHIFT;
>  			pr_info("Lowering to %luMB\n", bytes >> 20);
>  			goto retry;
> 

  parent reply	other threads:[~2021-09-10 23:10 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-07 12:03 [PATCH 00/12] swiotlb-xen: fixes and adjustments Jan Beulich
2021-09-07 12:04 ` [PATCH 01/12] swiotlb-xen: avoid double free Jan Beulich
2021-09-08  6:48   ` Christoph Hellwig
2021-09-10 22:55   ` Stefano Stabellini
2021-09-10 22:55     ` Stefano Stabellini
2021-09-07 12:04 ` [PATCH 02/12] swiotlb-xen: fix late init retry Jan Beulich
2021-09-08  6:50   ` Christoph Hellwig
2021-09-07 12:05 ` [PATCH 03/12] swiotlb-xen: maintain slab count properly Jan Beulich
2021-09-08  6:53   ` Christoph Hellwig
2021-09-10 23:10   ` Stefano Stabellini [this message]
2021-09-10 23:10     ` Stefano Stabellini
2021-09-07 12:05 ` [PATCH 04/12] swiotlb-xen: ensure to issue well-formed XENMEM_exchange requests Jan Beulich
2021-09-08  6:57   ` Christoph Hellwig
2021-09-08  9:16     ` Jan Beulich
2021-09-10 23:14   ` Stefano Stabellini
2021-09-10 23:14     ` Stefano Stabellini
2021-09-13  7:17     ` Jan Beulich
2021-09-13 20:31       ` Stefano Stabellini
2021-09-13 20:31         ` Stefano Stabellini
2021-09-14  9:11         ` Jan Beulich
2021-09-15  1:22           ` Stefano Stabellini
2021-09-15  1:22             ` Stefano Stabellini
2021-09-15  1:54             ` Stefano Stabellini
2021-09-15  1:54               ` Stefano Stabellini
2021-09-15  8:21               ` Jan Beulich
2021-09-07 12:05 ` [PATCH 05/12] swiotlb-xen: suppress certain init retries Jan Beulich
2021-09-08  6:58   ` Christoph Hellwig
2021-09-10 23:18   ` Stefano Stabellini
2021-09-10 23:18     ` Stefano Stabellini
2021-09-07 12:06 ` [PATCH 06/12] swiotlb-xen: limit " Jan Beulich
2021-09-08  7:00   ` Christoph Hellwig
2021-09-10 23:23   ` Stefano Stabellini
2021-09-10 23:23     ` Stefano Stabellini
2021-09-07 12:06 ` [PATCH 07/12] swiotlb-xen: drop leftover __ref Jan Beulich
2021-09-08  7:02   ` Christoph Hellwig
2021-09-10 23:24   ` Stefano Stabellini
2021-09-10 23:24     ` Stefano Stabellini
2021-09-07 12:07 ` [PATCH 08/12] swiotlb-xen: arrange to have buffer info logged Jan Beulich
2021-09-08  7:04   ` Christoph Hellwig
2021-09-10 23:26   ` Stefano Stabellini
2021-09-10 23:26     ` Stefano Stabellini
2021-09-07 12:07 ` [PATCH 09/12] swiotlb-xen: drop DEFAULT_NSLABS Jan Beulich
2021-09-08  7:06   ` Christoph Hellwig
2021-09-10 23:27   ` Stefano Stabellini
2021-09-10 23:27     ` Stefano Stabellini
2021-09-07 12:10 ` [PATCH 10/12] xen-pcifront: this module is PV-only Jan Beulich
2021-09-07 15:30   ` Bjorn Helgaas
2021-09-07 16:14     ` Jan Beulich
2021-09-07 16:38       ` Bjorn Helgaas
2021-09-10 23:34   ` Stefano Stabellini
2021-09-10 23:34     ` Stefano Stabellini
2021-09-07 12:11 ` [PATCH 11/12] xen/pci-swiotlb: reduce visibility of symbols Jan Beulich
2021-09-08  7:08   ` Christoph Hellwig
2021-09-07 12:13 ` [PATCH 12/12] swiotlb-xen: this is PV-only on x86 Jan Beulich
2021-09-08  7:14   ` Christoph Hellwig
2021-09-10 23:48     ` Stefano Stabellini
2021-09-10 23:48       ` Stefano Stabellini
2021-09-13  7:28       ` Jan Beulich
2021-09-13 20:54         ` Stefano Stabellini
2021-09-13 20:54           ` Stefano Stabellini
2021-09-13  7:51       ` Jan Beulich
2021-09-13 20:49         ` Stefano Stabellini
2021-09-13 20:49           ` Stefano Stabellini
2021-09-08 15:18 ` [PATCH 00/12] swiotlb-xen: fixes and adjustments Juergen Gross
2021-09-08 15:18   ` Juergen Gross via iommu
2021-09-14  8:30 ` Juergen Gross

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=alpine.DEB.2.21.2109101610380.10523@sstabellini-ThinkPad-T480s \
    --to=sstabellini@kernel.org \
    --cc=boris.ostrovsky@oracle.com \
    --cc=jbeulich@suse.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.