linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yinghai Lu <yinghai@kernel.org>
To: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: mingo@elte.hu, hpa@zytor.com, tglx@linutronix.de,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86: fix gart iommu using for amd 64 bit system
Date: Tue, 24 Nov 2009 10:48:32 -0800	[thread overview]
Message-ID: <4B0C2A80.5090609@kernel.org> (raw)
In-Reply-To: <20091124225000H.fujita.tomonori@lab.ntt.co.jp>

FUJITA Tomonori wrote:
> On Tue, 24 Nov 2009 02:42:26 -0800
> Yinghai Lu <yinghai@kernel.org> wrote:
> 
>> at GART iommu workaround : it is not rare. a lot of systems have this problem.
>> and that workaround works well for several years.
> 
> swiotlb has worked too.
> 
> 
>> don't think user will like to use SWIOTLB instead of swiotlb.
> 
> I doubt that users care about a way to fix their problems.
> 
> 
>> that gart iommu hardware is not broken, just those BIOS guys just forget to program it.
>>
>> here intel vt-d is different, it seems can not make it work just program some hardware register...
> 
> Because BIOS is broken, IIRC. Both cases are pretty similar.
> 
>> please check my v2 patch, to see if it breaks your setup.
> 
> As I said, adding another trick only for GART is not good. And using
> force_iommu in pci-dma.c is confusing since force_iommu should be used
> only in X86_64.
> 
> The following patch works for you?
> 
> 
> diff --git a/arch/x86/include/asm/swiotlb.h b/arch/x86/include/asm/swiotlb.h
> index 87ffcb1..8085277 100644
> --- a/arch/x86/include/asm/swiotlb.h
> +++ b/arch/x86/include/asm/swiotlb.h
> @@ -5,13 +5,17 @@
>  
>  #ifdef CONFIG_SWIOTLB
>  extern int swiotlb;
> -extern int pci_swiotlb_init(void);
> +extern int __init pci_swiotlb_detect(void);
> +extern void __init pci_swiotlb_init(void);
>  #else
>  #define swiotlb 0
> -static inline int pci_swiotlb_init(void)
> +static inline int pci_swiotlb_detect(void)
>  {
>  	return 0;
>  }
> +static inline void pci_swiotlb_init(void)
> +{
> +}
>  #endif
>  
>  static inline void dma_mark_clean(void *addr, size_t size) {}
> diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
> index e0dfb68..750dd8d 100644
> --- a/arch/x86/kernel/aperture_64.c
> +++ b/arch/x86/kernel/aperture_64.c
> @@ -401,6 +401,7 @@ void __init gart_iommu_hole_init(void)
>  
>  			iommu_detected = 1;
>  			gart_iommu_aperture = 1;
> +			swiotlb = 0;
>  			x86_init.iommu.iommu_init = gart_iommu_init;
>  
>  			aper_order = (read_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL) >> 1) & 7;
> @@ -458,7 +459,7 @@ out:
>  
>  	if (aper_alloc) {
>  		/* Got the aperture from the AGP bridge */
> -	} else if (!valid_agp) {
> +	} else if (swiotlb && !valid_agp) {
>  		/* Do nothing */

still have some problem here.
because you set swiotlb to 0 before. it will break
iommu=soft

when amd 64bit system, ram > 4g, and no AGP bridge, and BIOS doesn't set gart.
if the user set iommu=soft.
old way, kernel will use swiotlb.

so instead set swiotlb before, it seems you should restore
 			iommu_detected
 			gart_iommu_aperture
			swiotlb = 0;
 			x86_init.iommu.iommu_init
to make swiotlb happy later.

>  	} else if ((!no_iommu && max_pfn > MAX_DMA32_PFN) ||
>  		   force_iommu ||
> diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
> index afcc58b..75e14e2 100644
> --- a/arch/x86/kernel/pci-dma.c
> +++ b/arch/x86/kernel/pci-dma.c
> @@ -124,8 +124,8 @@ void __init pci_iommu_alloc(void)
>  	/* free the range so iommu could get some range less than 4G */
>  	dma32_free_bootmem();
>  #endif
> -	if (pci_swiotlb_init())
> -		return;
> +	if (pci_swiotlb_detect())
> +		goto out;
>  
>  	gart_iommu_hole_init();
>  
> @@ -135,6 +135,8 @@ void __init pci_iommu_alloc(void)
>  
>  	/* needs to be called after gart_iommu_hole_init */
>  	amd_iommu_detect();
> +out:
> +	pci_swiotlb_init();
>  }
>  
>  void *dma_generic_alloc_coherent(struct device *dev, size_t size,
> diff --git a/arch/x86/kernel/pci-gart_64.c b/arch/x86/kernel/pci-gart_64.c
> index e6a0d40..2358409 100644
> --- a/arch/x86/kernel/pci-gart_64.c
> +++ b/arch/x86/kernel/pci-gart_64.c
> @@ -847,7 +847,6 @@ int __init gart_iommu_init(void)
>  	flush_gart();
>  	dma_ops = &gart_dma_ops;
>  	x86_platform.iommu_shutdown = gart_iommu_shutdown;
> -	swiotlb = 0;
>  
>  	return 0;
>  }
> diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
> index e36e71d..6971ba5 100644
> --- a/arch/x86/kernel/pci-swiotlb.c
> +++ b/arch/x86/kernel/pci-swiotlb.c
> @@ -43,12 +43,12 @@ static struct dma_map_ops swiotlb_dma_ops = {
>  };
>  
>  /*
> - * pci_swiotlb_init - initialize swiotlb if necessary
> + * pci_swiotlb_init - set swiotlb to 1 if necessary

pci_swiotlb_detect ?

YH

  parent reply	other threads:[~2009-11-24 18:51 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-10 10:46 [PATCH v2 0/9] x86: handle HW IOMMU initialization failure gracefully FUJITA Tomonori
2009-11-10 10:46 ` [PATCH -v2 1/9] add iommu_init to x86_init_ops FUJITA Tomonori
2009-11-10 13:22   ` [tip:core/iommu] x86: Add " tip-bot for FUJITA Tomonori
2009-11-10 13:42   ` [tip:core/iommu] x86: Add iommu_init to x86_init_ops, fix build tip-bot for Ingo Molnar
2009-11-10 10:46 ` [PATCH -v2 2/9] Calgary: convert detect_calgary to use iommu_init hook FUJITA Tomonori
2009-11-10 13:22   ` [tip:core/iommu] x86: Calgary: Convert detect_calgary() " tip-bot for FUJITA Tomonori
2009-11-10 10:46 ` [PATCH -v2 3/9] GART: convert gart_iommu_hole_init " FUJITA Tomonori
2009-11-10 13:23   ` [tip:core/iommu] x86: GART: Convert gart_iommu_hole_init() " tip-bot for FUJITA Tomonori
2009-11-10 10:46 ` [PATCH -v2 4/9] amd_iommu: convert amd_iommu_detect " FUJITA Tomonori
2009-11-10 13:23   ` [tip:core/iommu] x86: amd_iommu: Convert amd_iommu_detect() " tip-bot for FUJITA Tomonori
2009-11-10 10:46 ` [PATCH -v2 5/9] intel-iommu: convert detect_intel_iommu " FUJITA Tomonori
2009-11-10 11:12   ` Ingo Molnar
2009-11-10 13:23   ` [tip:core/iommu] x86: intel-iommu: Convert " tip-bot for FUJITA Tomonori
2009-11-10 10:46 ` [PATCH -v2 6/9] bootmem: add free_bootmem_late FUJITA Tomonori
2009-11-10 12:00   ` Johannes Weiner
2009-11-14 12:50     ` FUJITA Tomonori
2009-11-10 13:23   ` [tip:core/iommu] bootmem: Add free_bootmem_late() tip-bot for FUJITA Tomonori
2009-11-11 23:56   ` [PATCH -v2 6/9] bootmem: add free_bootmem_late Andrew Morton
2009-11-12  7:47     ` Ingo Molnar
2009-11-10 10:46 ` [PATCH -v2 7/9] swiotlb: add swiotlb_free function FUJITA Tomonori
2009-11-10 11:27   ` Ingo Molnar
2009-11-10 13:24   ` [tip:core/iommu] swiotlb: Add swiotlb_free() function tip-bot for FUJITA Tomonori
2009-11-10 10:46 ` [PATCH -v2 8/9] swiotlb: export swiotlb_print_info FUJITA Tomonori
2009-11-10 13:24   ` [tip:core/iommu] swiotlb: Defer swiotlb init printing, export swiotlb_print_info() tip-bot for FUJITA Tomonori
2009-11-10 10:46 ` [PATCH -v2 9/9] x86: handle HW IOMMU initialization failure gracely FUJITA Tomonori
2009-11-10 11:27   ` Ingo Molnar
2009-11-10 13:24   ` [tip:core/iommu] x86: Handle HW IOMMU initialization failure gracefully tip-bot for FUJITA Tomonori
2009-11-22  4:24     ` [PATCH] x86: fix gart iommu using for amd 64 bit system Yinghai Lu
2009-11-22  5:19       ` [PATCH] x86: fix gart iommu using for amd 64 bit system -v2 Yinghai Lu
2009-11-24  8:46       ` [PATCH] x86: fix gart iommu using for amd 64 bit system FUJITA Tomonori
2009-11-24  9:19         ` Yinghai Lu
2009-11-24  9:35           ` FUJITA Tomonori
2009-11-24  9:48             ` Yinghai Lu
2009-11-24 10:31               ` FUJITA Tomonori
2009-11-24 10:42                 ` Yinghai Lu
2009-11-24 13:50                   ` FUJITA Tomonori
2009-11-24 15:26                     ` Ingo Molnar
2009-11-24 18:28                       ` Yinghai Lu
2009-11-24 23:57                       ` FUJITA Tomonori
2009-11-25  7:25                         ` Ingo Molnar
2009-11-25  7:56                           ` FUJITA Tomonori
2009-11-24 18:48                     ` Yinghai Lu [this message]
2009-11-24 23:48                       ` FUJITA Tomonori
2009-11-10 11:19 ` [PATCH v2 0/9] x86: handle HW IOMMU initialization failure gracefully Ingo Molnar
2009-11-10 11:55   ` Ingo Molnar
2009-11-10 12:35     ` FUJITA Tomonori
2009-11-22  3:17   ` Yinghai Lu

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=4B0C2A80.5090609@kernel.org \
    --to=yinghai@kernel.org \
    --cc=fujita.tomonori@lab.ntt.co.jp \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).