Skip to contentSkip to conversation

hypersparc dvma aliasing

DISCUSSION Bob Breuer 4 participants 10 messages Nov 17, 2004 – Nov 24, 2004 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore

Bob Breuer

author
#0 lore raw

After further testing, it certainly seems that hypersparcs have aliasing issues between dvma and physical addresses.

Here are some results that I get using a minimum of cache flushing with 512K of cache, and all dvma areas are cacheable:

iommu_get_one -- cache(va) = cache(pa):
va 0xf0777000, pa 0x00777000, dvma 0xf0010000 -- fails va 0xf0777000, pa 0x00777000, dvma 0xf0777000 -- works

iommu_map_dma_area -- cache(va) != cache(addr):
va 0xfbd66000, addr 0xfff0e000, pba 0xf0066000 -- fails va 0xfbd80000, addr 0xfff00000, pba 0xf0000000 -- works va 0xfbd66000, addr 0xfff0e000, pba 0xf010e000 -- works

I've got some additional changes that allocate dvma addresses with the right cache color and allow for less cache flushing. I will post a patch shortly.

Bob

author
#1 lore raw

Here's the preliminary patch. This time around, both the hme and esp drivers are working for me. This replaces my previous patch and is against the vanilla 2.6.9 kernel. I've tried to reduce the amount of unnecessary cache flushing, therefore this will need some testing on non-hypersparc cpus also. It needs some cleanup yet, and will be rediffed against a later kernel. I'm looking for comments and feedback.

Bob

include/asm-sparc/bitext.h renamed from include/asm-sparc/bitext.h.orig +1 -0
@@ -17,6 +17,7 @@ struct bit_map {
  	int last_off;
  	int last_size;
  	int first_free;
+	int num_colors;
  };
 
  extern int bit_map_string_get(struct bit_map *t, int len, int align);
arch/sparc/mm/iommu.c renamed from arch/sparc/mm/iommu.c.orig +59 -18

153 lines not on this page · raw message

arch/sparc/mm/srmmu.c renamed from arch/sparc/mm/srmmu.c.orig +2 -5
@@ -90,8 +90,6 @@ ctxd_t *srmmu_context_table;
  int viking_mxcc_present;
  static spinlock_t srmmu_context_spinlock = SPIN_LOCK_UNLOCKED;
 
-int is_hypersparc;
-
  /*
   * In general all page table modifications should use the V8 atomic
   * swap instruction.  This insures the mmu and the cpu are in sync
@@ -565,7 +563,7 @@ static void srmmu_switch_mm(struct mm_st
  		srmmu_ctxd_set(&srmmu_context_table[mm->context], mm->pgd);
  	}
 
-	if (is_hypersparc)
+	if (srmmu_modtype = HyperSparc)
  		hyper_flush_whole_icache();
 
  	srmmu_set_context(mm->context);
@@ -1463,11 +1461,10 @@ static void __init poke_hypersparc(void)
  static void __init init_hypersparc(void)
  {
  	srmmu_name = "ROSS HyperSparc";
+	srmmu_modtype = HyperSparc;
 
  	init_vac_layout();
 
-	is_hypersparc = 1;
-
  	BTFIXUPSET_CALL(pte_clear, srmmu_pte_clear, BTFIXUPCALL_NORM);
  	BTFIXUPSET_CALL(pmd_clear, srmmu_pmd_clear, BTFIXUPCALL_NORM);
  	BTFIXUPSET_CALL(pgd_clear, srmmu_pgd_clear, BTFIXUPCALL_NORM);
arch/sparc/lib/bitext.c renamed from arch/sparc/lib/bitext.c.orig +17 -6
@@ -29,10 +29,17 @@ int bit_map_string_get(struct bit_map *t
  	int offset, count;	/* siamese twins */
  	int off_new;
  	int align1;
-	int i;
+	int i, color;
 
-	if (align = 0)
-		align = 1;
+	if (t->num_colors) {
+		/* align is overloaded to be the page color */
+		color = align;
+		align = t->num_colors;
+	} else {
+		color = 0;
+		if (align = 0)
+			align = 1;
+	}
  	align1 = align - 1;
  	if ((align & align1) != 0)
  		BUG();
@@ -40,6 +47,7 @@ int bit_map_string_get(struct bit_map *t
  		BUG();
  	if (len <= 0 || len > t->size)
  		BUG();
+	color &= align1;
 
  	spin_lock(&t->lock);
  	if (len < t->last_size)
@@ -49,7 +57,7 @@ int bit_map_string_get(struct bit_map *t
  	count = 0;
  	for (;;) {
  		off_new = find_next_zero_bit(t->map, t->size, offset);
-		off_new = (off_new + align1) & ~align1;
+		off_new = ((off_new + align1) & ~align1) + color;
  		count += off_new - offset;
  		offset = off_new;
  		if (offset >= t->size)
@@ -69,6 +77,7 @@ int bit_map_string_get(struct bit_map *t
  		}
 
  		i = 0;
+		/* try using find_next_bit(t->map, len+1, offset) */
  		while (test_bit(offset + i, t->map) = 0) {
  			i++;
  			if (i = len) {
@@ -121,6 +130,8 @@ void bit_map_init(struct bit_map *t, uns
  	spin_lock_init(&t->lock);
  	t->map = map;
  	t->size = size;
-	t->last_size = 0;
-	t->first_free = 0;
+
+	// redundent, zeroed above
+	//t->last_size = 0;
+	//t->first_free = 0;
  }
#2 lore raw
In reply to Bob Breuer
Quoted 7 lines · Bob Breuer

Here's the preliminary patch. This time around, both the hme and esp drivers are working for me. This replaces my previous patch and is against the vanilla 2.6.9 kernel. I've tried to reduce the amount of unnecessary cache flushing, therefore this will need some testing on non-hypersparc cpus also. It needs some cleanup yet, and will be rediffed against a later kernel. I'm looking for comments and feedback.

I'll spin this up on some sparc32 boxen.

-- wli

maintainer
#3 lore raw
In reply to Bob Breuer
Quoted 6 lines · On Tue, 16 Nov 2004 20:28:18 -0600 Bob Breuer <[email protected]> wrote:

After further testing, it certainly seems that hypersparcs have aliasing issues between dvma and physical addresses.

Here are some results that I get using a minimum of cache flushing with 512K of cache, and all dvma areas are cacheable:

Quoted 8 lines

iommu_get_one -- cache(va) = cache(pa):
va 0xf0777000, pa 0x00777000, dvma 0xf0010000 -- fails va 0xf0777000, pa 0x00777000, dvma 0xf0777000 -- works

iommu_map_dma_area -- cache(va) != cache(addr):
va 0xfbd66000, addr 0xfff0e000, pba 0xf0066000 -- fails va 0xfbd80000, addr 0xfff00000, pba 0xf0000000 -- works va 0xfbd66000, addr 0xfff0e000, pba 0xf010e000 -- works

You've certainly disproven all the theories in my previous email on this topic :-) Good work Bob!

author
#4 lore raw
In reply to Bob Breuer

Hmmm, no reports on whether the previous patch works or not for anyone. Well, I'll report my status. Using Aurora 1.92, runlevel 2 works without any major problems, but with runlevel 3 it looks like nfs is causing problems, but I'm not certain. I would like to know if it's just me, or if it happens only with hypersparcs or any sparc32 machine.

In the meantime, I've revised the last patch. This is against 2.6.10-rc2 and is just enough to fix the hypersparc dvma problems. The other changes can be looked at later.

If anyone has a more elegant solution than my overloading of the align argument to bit_map_string_get(), let me know. The alignment for page coloring is known ahead of time, so we only need to pass either the alignment or the page color hint.

Then when setting up the number of colors, where can I get the proper cache size from? I've only enabled the page coloring for hypersparcs, should we do the coloring for the rest as well?

Bob

include/asm-sparc/bitext.h +1 -0
diff -X dontdiff -urp linux-2.6.10-rc2-clean/include/asm-sparc/bitext.h linux-2.6.10-rc2/include/asm-sparc/bitext.h
@@ -17,6 +17,7 @@ struct bit_map {
  	int last_off;
  	int last_size;
  	int first_free;
+	int num_colors;
  };
 
  extern int bit_map_string_get(struct bit_map *t, int len, int align);
arch/sparc/lib/bitext.c +12 -6
diff -X dontdiff -urp linux-2.6.10-rc2-clean/arch/sparc/lib/bitext.c linux-2.6.10-rc2/arch/sparc/lib/bitext.c
@@ -29,10 +29,17 @@ int bit_map_string_get(struct bit_map *t
  	int offset, count;	/* siamese twins */
  	int off_new;
  	int align1;
-	int i;
+	int i, color;
 
-	if (align = 0)
-		align = 1;
+	if (t->num_colors) {
+		/* align is overloaded to be the page color */
+		color = align;
+		align = t->num_colors;
+	} else {
+		color = 0;
+		if (align = 0)
+			align = 1;
+	}
  	align1 = align - 1;
  	if ((align & align1) != 0)
  		BUG();
@@ -40,6 +47,7 @@ int bit_map_string_get(struct bit_map *t
  		BUG();
  	if (len <= 0 || len > t->size)
  		BUG();
+	color &= align1;
 
  	spin_lock(&t->lock);
  	if (len < t->last_size)
@@ -49,7 +57,7 @@ int bit_map_string_get(struct bit_map *t
  	count = 0;
  	for (;;) {
  		off_new = find_next_zero_bit(t->map, t->size, offset);
-		off_new = (off_new + align1) & ~align1;
+		off_new = ((off_new + align1) & ~align1) + color;
  		count += off_new - offset;
  		offset = off_new;
  		if (offset >= t->size)
@@ -121,6 +129,4 @@ void bit_map_init(struct bit_map *t, uns
  	spin_lock_init(&t->lock);
  	t->map = map;
  	t->size = size;
-	t->last_size = 0;
-	t->first_free = 0;
  }
arch/sparc/mm/iommu.c +23 -6
diff -X dontdiff -urp linux-2.6.10-rc2-clean/arch/sparc/mm/iommu.c linux-2.6.10-rc2/arch/sparc/mm/iommu.c
@@ -119,6 +119,14 @@ iommu_init(int iommund, struct sbus_bus
  		prom_halt();
  	}
  	bit_map_init(&iommu->usemap, bitmap, IOMMU_NPTES);
+	/* To be coherent on HyperSparc, the page color of DVMA
+	 * and physical addresses must match.
+	 */
+	if (srmmu_modtype = HyperSparc)
+		/* XXX Use real cache size */
+		iommu->usemap.num_colors = (1<<20) >> PAGE_SHIFT;
+	else
+		iommu->usemap.num_colors = 1;
 
  	printk("IOMMU: impl %d vers %d table 0x%p[%d B] map [%d b]\n",
  	    impl, vers, iommu->page_table,
@@ -128,7 +136,9 @@ iommu_init(int iommund, struct sbus_bus
  }
 
  /* This begs to be btfixup-ed by srmmu. */
-static void iommu_viking_flush_iotlb(iopte_t *iopte, unsigned int niopte)
+/* Flush the iotlb entries to ram. */
+/* This could be better if we didn't have to flush whole pages. */
+static void iommu_flush_iotlb(iopte_t *iopte, unsigned int niopte)
  {
  	unsigned long start;
  	unsigned long end;
@@ -145,6 +155,11 @@ static void iommu_viking_flush_iotlb(iop
  			viking_flush_page(start);
  			start += PAGE_SIZE;
  		}
+	} else {
+		while(start < end) {
+			__flush_page_to_ram(start);
+			start += PAGE_SIZE;
+		}
  	}
  }
 
@@ -156,7 +171,8 @@ static u32 iommu_get_one(struct page *pa
  	unsigned int busa, busa0;
  	int i;
 
-	ioptex = bit_map_string_get(&iommu->usemap, npages, 1);
+	/* page color = pfn of page */
+	ioptex = bit_map_string_get(&iommu->usemap, npages, page_to_pfn(page));
  	if (ioptex < 0)
  		panic("iommu out");
  	busa0 = iommu->start + (ioptex << PAGE_SHIFT);
@@ -172,8 +188,7 @@ static u32 iommu_get_one(struct page *pa
  		page++;
  	}
 
-	iommu_viking_flush_iotlb(iopte0, npages);
-	flush_cache_all(); // hack to fix dma errors with hypersparc
+	iommu_flush_iotlb(iopte0, npages);
 
  	return busa0;
  }
@@ -328,7 +343,9 @@ static int iommu_map_dma_area(dma_addr_t
  	if ((addr & ~PAGE_MASK) != 0) BUG();
  	if ((len & ~PAGE_MASK) != 0) BUG();
 
-	ioptex = bit_map_string_get(&iommu->usemap, len >> PAGE_SHIFT, 1);
+	/* page color = physical address */
+	ioptex = bit_map_string_get(&iommu->usemap, len >> PAGE_SHIFT,
+		addr >> PAGE_SHIFT);
  	if (ioptex < 0)
  		panic("iommu out");
 
@@ -372,7 +389,7 @@ static int iommu_map_dma_area(dma_addr_t
  	 *        to handle the latter case as well.
  	 */
  	flush_cache_all();
-	iommu_viking_flush_iotlb(first, len >> PAGE_SHIFT);
+	iommu_flush_iotlb(first, len >> PAGE_SHIFT);
  	flush_tlb_all();
  	iommu_invalidate(iommu->regs);
 
maintainer
#5 lore raw
In reply to Bob Breuer
Quoted 3 lines · On Tue, 23 Nov 2004 00:18:48 -0600 Bob Breuer <[email protected]> wrote:

Then when setting up the number of colors, where can I get the proper cache size from? I've only enabled the page coloring for hypersparcs, should we do the coloring for the rest as well?

Use vac_cache_size on srmmu.

#6 lore raw
In reply to Bob Breuer
Quoted 1 line · Bob Breuer

Hmmm, no reports on whether the previous patch works or

not for anyone.

Quoted 1 line

diff -X dontdiff -urp linux-2.6.10-rc2-clean

Bob are you using 2.6.10-rc2 from ftp://ftp.kernel.org/pub/linux/kernel/v2.6/testing/
or linux-2.6.9 patched with your fixes?
Need a good start point. Both my Ross hypersparc 150 smp ss20 and supersparc 75 smp ss20 have Aurora build 1.0 installed. They are ready to go.

--
Stan Benoit<[email protected]>

author
#7 lore raw
In reply to Bob Breuer
Quoted 8 lines · Stan Benoit
Quoted 4 lines · Bob Breuer

Hmmm, no reports on whether the previous patch works or not for anyone.

diff -X dontdiff -urp linux-2.6.10-rc2-clean

Quoted 7 lines

Bob are you using 2.6.10-rc2 from ftp://ftp.kernel.org/pub/linux/kernel/v2.6/testing/
or linux-2.6.9 patched with your fixes?
Need a good start point. Both my Ross hypersparc 150 smp ss20 and supersparc 75 smp ss20 have Aurora build 1.0 installed. They are ready to go.

I've tried both kernels. The previous 2 line fix made it into 2.6.10-rc2, so that is what I'm basing any future diffs off of.

I'd recommend upgrading Aurora to 1.92 because 1.0 may not support a 2.6 kernel (see the aurora-sparc-user list archives for help). Be sure to keep a 2.4 kernel around to fall back to.

If it will help anyone with testing, I may be able to provide an already compiled kernel and modules.

Bob

#8 lore raw
In reply to Bob Breuer
Quoted 4 lines · Bob Breuer

If it will help anyone with testing, I may be able to provide an already compiled kernel and modules.

Bob

That looks like a good idea, that should sync everything up real nice.

Signature · 2 lines
Stan Benoit<[email protected]>
Mondo Testing	http://troff.nakedsoul.org
#9 lore raw
In reply to Bob Breuer
Quoted 6 lines · Stan Benoit
Quoted 6 lines

Bob are you using 2.6.10-rc2 from ftp://ftp.kernel.org/pub/linux/kernel/v2.6/testing/
or linux-2.6.9 patched with your fixes?
Need a good start point. Both my Ross hypersparc 150 smp ss20 and supersparc 75 smp ss20 have Aurora build 1.0 installed. They are ready to go.

Quoted 7 lines · Bob Breuer

I've tried both kernels. The previous 2 line fix made it into 2.6.10-rc2, so that is what I'm basing any future diffs off of. I'd recommend upgrading Aurora to 1.92 because 1.0 may not support a 2.6 kernel (see the aurora-sparc-user list archives for help). Be sure to keep a 2.4 kernel around to fall back to.
If it will help anyone with testing, I may be able to provide an already compiled kernel and modules.

I didn't forget about this. The results on 2.6.10-rc2-mm3 were so catastrophic I'm still trying to debug them.

-- wli