lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1450741676-5865-80-git-send-email-viro@ZenIV.linux.org.uk>
Date:	Mon, 21 Dec 2015 23:47:53 +0000
From:	Al Viro <viro@...IV.linux.org.uk>
To:	linux-kernel@...r.kernel.org
Cc:	Linus Torvalds <torvalds@...ux-foundation.org>
Subject: [POC][PATCH 80/83] [sun3] try to sort dvma types out

From: Al Viro <viro@...iv.linux.org.uk>

[I've pretty much zero confidence in that one - if anything, it would need
to be split]

Signed-off-by: Al Viro <viro@...iv.linux.org.uk>
---
 arch/m68k/include/asm/dvma.h             | 21 +++++--------
 arch/m68k/sun3/dvma.c                    | 31 ++++++++-----------
 arch/m68k/sun3/sun3dvma.c                | 52 ++++++++++++++------------------
 arch/m68k/sun3x/dvma.c                   | 15 +++------
 drivers/net/ethernet/i825xx/sun3_82586.c | 13 ++++----
 drivers/scsi/sun3_scsi.c                 | 23 ++++++--------
 6 files changed, 64 insertions(+), 91 deletions(-)

diff --git a/arch/m68k/include/asm/dvma.h b/arch/m68k/include/asm/dvma.h
index 890bbf7..1fa85e5 100644
--- a/arch/m68k/include/asm/dvma.h
+++ b/arch/m68k/include/asm/dvma.h
@@ -16,18 +16,16 @@
 #define DVMA_PAGE_ALIGN(addr)	ALIGN(addr, DVMA_PAGE_SIZE)
 
 extern void dvma_init(void);
-extern int dvma_map_iommu(unsigned long kaddr, unsigned long baddr,
-			  int len);
+extern int dvma_map_iommu(void *kaddr, unsigned long baddr, int len);
 
 #define dvma_malloc(x) dvma_malloc_align(x, 0)
 #define dvma_map(x, y) dvma_map_align(x, y, 0)
 #define dvma_map_vme(x, y) (dvma_map(x, y) & 0xfffff)
 #define dvma_map_align_vme(x, y, z) (dvma_map_align (x, y, z) & 0xfffff)
-extern unsigned long dvma_map_align(unsigned long kaddr, int len,
-			    int align);
+extern unsigned long dvma_map_align(void *kaddr, int len, int align);
 extern void *dvma_malloc_align(unsigned long len, unsigned long align);
 
-extern void dvma_unmap(void *baddr);
+extern void dvma_unmap(unsigned long);
 extern void dvma_free(void *vaddr);
 
 
@@ -51,14 +49,13 @@ extern void dvma_free(void *vaddr);
 
 /* virt <-> phys conversions */
 #define dvma_vtop(x) ((unsigned long)(x) & 0xffffff)
-#define dvma_ptov(x) ((unsigned long)(x) | 0xf000000)
+#define dvma_ptov(x) ((void *)((unsigned long)(x) | 0xf000000))
 #define dvma_vtovme(x) ((unsigned long)(x) & 0x00fffff)
-#define dvma_vmetov(x) ((unsigned long)(x) | 0xff00000)
+#define dvma_vmetov(x) ((void*)((unsigned long)(x) | 0xff00000))
 #define dvma_vtob(x) dvma_vtop(x)
 #define dvma_btov(x) dvma_ptov(x)
 
-static inline int dvma_map_cpu(unsigned long kaddr, unsigned long vaddr,
-			       int len)
+static inline int dvma_map_cpu(void *kaddr, void *vaddr, int len)
 {
 	return 0;
 }
@@ -75,11 +72,9 @@ static inline int dvma_map_cpu(unsigned long kaddr, unsigned long vaddr,
 #define IOMMU_ENTRIES              (IOMMU_TOTAL_ENTRIES - 0x80)
 
 #define dvma_vtob(x) ((unsigned long)(x) & 0x00ffffff)
-#define dvma_btov(x) ((unsigned long)(x) | 0xff000000)
-
-extern int dvma_map_cpu(unsigned long kaddr, unsigned long vaddr, int len);
-
+#define dvma_btov(x) ((void *)((unsigned long)(x) | 0xff000000))
 
+extern int dvma_map_cpu(void *kaddr, void *vaddr, int len);
 
 /* everything below this line is specific to dma used for the onboard
    ESP scsi on sun3x */
diff --git a/arch/m68k/sun3/dvma.c b/arch/m68k/sun3/dvma.c
index d95506e..0b0d352 100644
--- a/arch/m68k/sun3/dvma.c
+++ b/arch/m68k/sun3/dvma.c
@@ -20,47 +20,42 @@
 
 static unsigned long ptelist[120];
 
-static unsigned long dvma_page(unsigned long kaddr, unsigned long vaddr)
+static void *dvma_page(void *kaddr, void *vaddr)
 {
 	unsigned long pte;
 	unsigned long j;
 	pte_t ptep;
+	int idx;
 
 	j = *(volatile unsigned long *)kaddr;
 	*(volatile unsigned long *)kaddr = j;
 
 	ptep = pfn_pte(virt_to_pfn(kaddr), PAGE_KERNEL);
 	pte = pte_val(ptep);
-//		printk("dvma_remap: addr %lx -> %lx pte %08lx len %x\n",
+//		printk("dvma_remap: addr %p -> %lx pte %08lx len %x\n",
 //		       kaddr, vaddr, pte, len);
-	if(ptelist[(vaddr & 0xff000) >> PAGE_SHIFT] != pte) {
-		sun3_put_pte(vaddr, pte);
-		ptelist[(vaddr & 0xff000) >> PAGE_SHIFT] = pte;
-	}
+	idx = ((unsigned long)vaddr & 0xff000) >> PAGE_SHIFT;
 
-	return (vaddr + (kaddr & ~PAGE_MASK));
+	if (ptelist[idx] != pte) {
+		sun3_put_pte((unsigned long)vaddr, pte);
+		ptelist[idx] = pte;
+	}
 
+	return vaddr + offset_in_page(kaddr);
 }
 
-int dvma_map_iommu(unsigned long kaddr, unsigned long baddr,
-			      int len)
+int dvma_map_iommu(void *kaddr, unsigned long baddr, int len)
 {
+	void *vaddr = dvma_btov(baddr);
+	void *end = vaddr + len;
 
-	unsigned long end;
-	unsigned long vaddr;
-
-	vaddr = dvma_btov(baddr);
-
-	end = vaddr + len;
-
-	while(vaddr < end) {
+	while (vaddr < end) {
 		dvma_page(kaddr, vaddr);
 		kaddr += PAGE_SIZE;
 		vaddr += PAGE_SIZE;
 	}
 
 	return 0;
-
 }
 
 void __init sun3_dvma_init(void)
diff --git a/arch/m68k/sun3/sun3dvma.c b/arch/m68k/sun3/sun3dvma.c
index fdc4900..68eefa4 100644
--- a/arch/m68k/sun3/sun3dvma.c
+++ b/arch/m68k/sun3/sun3dvma.c
@@ -277,7 +277,7 @@ void __init dvma_init(void)
 
 }
 
-unsigned long dvma_map_align(unsigned long kaddr, int len, int align)
+unsigned long dvma_map_align(void *kaddr, int len, int align)
 {
 
 	unsigned long baddr;
@@ -287,58 +287,52 @@ unsigned long dvma_map_align(unsigned long kaddr, int len, int align)
 		len = 0x800;
 
 	if(!kaddr || !len) {
-//		printk("error: kaddr %lx len %x\n", kaddr, len);
+//		printk("error: kaddr %p len %x\n", kaddr, len);
 //		*(int *)4 = 0;
 		return 0;
 	}
 
 #ifdef DEBUG
-	printk("dvma_map request %08lx bytes from %08lx\n",
+	printk("dvma_map request %08lx bytes from %p\n",
 	       len, kaddr);
 #endif
-	off = kaddr & ~DVMA_PAGE_MASK;
-	kaddr &= PAGE_MASK;
+	off = (unsigned long)kaddr % DVMA_PAGE_SIZE;
+	kaddr -= off;
 	len += off;
-	len = ((len + (DVMA_PAGE_SIZE-1)) & DVMA_PAGE_MASK);
+	len = ALIGN(len, DVMA_PAGE_SIZE);
 
 	if(align == 0)
 		align = DVMA_PAGE_SIZE;
 	else
-		align = ((align + (DVMA_PAGE_SIZE-1)) & DVMA_PAGE_MASK);
+		align = ALIGN(align, DVMA_PAGE_SIZE);
 
 	baddr = get_baddr(len, align);
 //	printk("using baddr %lx\n", baddr);
 
-	if(!dvma_map_iommu(kaddr, baddr, len))
+	if (!dvma_map_iommu(kaddr, baddr, len))
 		return (baddr + off);
 
-	printk("dvma_map failed kaddr %lx baddr %lx len %x\n", kaddr, baddr, len);
+	printk("dvma_map failed kaddr %p baddr %lx len %x\n", kaddr, baddr, len);
 	BUG();
 	return 0;
 }
 EXPORT_SYMBOL(dvma_map_align);
 
-void dvma_unmap(void *baddr)
+void dvma_unmap(unsigned long baddr)
 {
-	unsigned long addr;
-
-	addr = (unsigned long)baddr;
 	/* check if this is a vme mapping */
-	if(!(addr & 0x00f00000))
-		addr |= 0xf00000;
-
-	free_baddr(addr);
-
-	return;
+	if (!(baddr & 0x00f00000))
+		baddr |= 0xf00000;
 
+	free_baddr(baddr);
 }
 EXPORT_SYMBOL(dvma_unmap);
 
 void *dvma_malloc_align(unsigned long len, unsigned long align)
 {
-	unsigned long kaddr;
+	void *kaddr;
 	unsigned long baddr;
-	unsigned long vaddr;
+	void *vaddr;
 
 	if(!len)
 		return NULL;
@@ -348,28 +342,28 @@ void *dvma_malloc_align(unsigned long len, unsigned long align)
 #endif
 	len = ((len + (DVMA_PAGE_SIZE-1)) & DVMA_PAGE_MASK);
 
-        if((kaddr = __get_free_pages(GFP_ATOMIC, get_order(len))) == 0)
+        if((kaddr = get_free_pages(GFP_ATOMIC, get_order(len))) == NULL)
 		return NULL;
 
-	if((baddr = (unsigned long)dvma_map_align(kaddr, len, align)) == 0) {
-		free_pages((void *)kaddr, get_order(len));
+	if((baddr = dvma_map_align(kaddr, len, align)) == 0) {
+		free_pages(kaddr, get_order(len));
 		return NULL;
 	}
 
 	vaddr = dvma_btov(baddr);
 
-	if(dvma_map_cpu(kaddr, vaddr, len) < 0) {
-		dvma_unmap((void *)baddr);
-		free_pages((void *)kaddr, get_order(len));
+	if (dvma_map_cpu(kaddr, vaddr, len) < 0) {
+		dvma_unmap(baddr);
+		free_pages(kaddr, get_order(len));
 		return NULL;
 	}
 
 #ifdef DEBUG
-	printk("mapped %08lx bytes %08lx kern -> %08lx bus\n",
+	printk("mapped %08lx bytes %p kern -> %08lx bus\n",
 	       len, kaddr, baddr);
 #endif
 
-	return (void *)vaddr;
+	return vaddr;
 
 }
 EXPORT_SYMBOL(dvma_malloc_align);
diff --git a/arch/m68k/sun3x/dvma.c b/arch/m68k/sun3x/dvma.c
index d5ddcda..a85faa5 100644
--- a/arch/m68k/sun3x/dvma.c
+++ b/arch/m68k/sun3x/dvma.c
@@ -79,18 +79,14 @@ void dvma_print (unsigned long dvma_addr)
 
 /* create a virtual mapping for a page assigned within the IOMMU
    so that the cpu can reach it easily */
-inline int dvma_map_cpu(unsigned long kaddr,
-			       unsigned long vaddr, int len)
+int dvma_map_cpu(void *k, void *v, int len)
 {
 	pgd_t *pgd;
-	unsigned long end;
+	unsigned long kaddr = (unsigned long)k & PAGE_MASK;
+	unsigned long vaddr = (unsigned long)v & PAGE_MASK;
+	unsigned long end = PAGE_ALIGN(vaddr + len);
 	int ret = 0;
 
-	kaddr &= PAGE_MASK;
-	vaddr &= PAGE_MASK;
-
-	end = PAGE_ALIGN(vaddr + len);
-
 #ifdef DEBUG
 	printk("dvma: mapping kern %08lx to virt %08lx\n",
 	       kaddr, vaddr);
@@ -148,8 +144,7 @@ inline int dvma_map_cpu(unsigned long kaddr,
 }
 
 
-inline int dvma_map_iommu(unsigned long kaddr, unsigned long baddr,
-				 int len)
+int dvma_map_iommu(void *kaddr, unsigned long baddr, int len)
 {
 	unsigned long end, index;
 
diff --git a/drivers/net/ethernet/i825xx/sun3_82586.c b/drivers/net/ethernet/i825xx/sun3_82586.c
index 353f57f6..a9a279f 100644
--- a/drivers/net/ethernet/i825xx/sun3_82586.c
+++ b/drivers/net/ethernet/i825xx/sun3_82586.c
@@ -131,7 +131,7 @@ static void    sun3_82586_dump(struct net_device *,void *);
 
 /* helper-functions */
 static int     init586(struct net_device *dev);
-static int     check586(struct net_device *dev,char *where,unsigned size);
+static int     check586(struct net_device *dev,unsigned long where,unsigned size);
 static void    alloc586(struct net_device *dev);
 static void    startrecv586(struct net_device *dev);
 static void   *alloc_rfa(struct net_device *dev,void *ptr);
@@ -203,7 +203,7 @@ static int sun3_82586_open(struct net_device *dev)
 /**********************************************
  * Check to see if there's an 82586 out there.
  */
-static int check586(struct net_device *dev,char *where,unsigned size)
+static int check586(struct net_device *dev,unsigned long where,unsigned size)
 {
 	struct priv pb;
 	struct priv *p = &pb;
@@ -211,7 +211,7 @@ static int check586(struct net_device *dev,char *where,unsigned size)
 	int i;
 
 	p->base = (unsigned long) dvma_btov(0);
-	p->memtop = (char *)dvma_btov((unsigned long)where);
+	p->memtop = dvma_btov(where);
 	p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS);
 	memset((char *)p->scp,0, sizeof(struct scp_struct));
 	for(i=0;i<sizeof(struct scp_struct);i++) /* memory was writeable? */
@@ -221,7 +221,7 @@ static int check586(struct net_device *dev,char *where,unsigned size)
 	if(p->scp->sysbus != SYSBUSVAL)
 		return 0;
 
-	iscp_addr = (char *)dvma_btov((unsigned long)where);
+	iscp_addr = dvma_btov(where);
 
 	p->iscp = (struct iscp_struct *) iscp_addr;
 	memset((char *)p->iscp,0, sizeof(struct iscp_struct));
@@ -366,14 +366,13 @@ static int __init sun3_82586_probe1(struct net_device *dev,int ioaddr)
 		retval = -ENODEV;
 		goto out;
 	}
-	if(!check586(dev,(char *) dev->mem_start,size)) {
+	if(!check586(dev, dev->mem_start,size)) {
 		printk("?memcheck, Can't find memory at 0x%lx with size %d!\n",dev->mem_start,size);
 		retval = -ENODEV;
 		goto out;
 	}
 
-	((struct priv *)netdev_priv(dev))->memtop =
-					(char *)dvma_btov(dev->mem_start);
+	((struct priv *)netdev_priv(dev))->memtop = dvma_btov(dev->mem_start);
 	((struct priv *)netdev_priv(dev))->base = (unsigned long) dvma_btov(0);
 	alloc586(dev);
 
diff --git a/drivers/scsi/sun3_scsi.c b/drivers/scsi/sun3_scsi.c
index 22a4283..5cfc634 100644
--- a/drivers/scsi/sun3_scsi.c
+++ b/drivers/scsi/sun3_scsi.c
@@ -100,7 +100,7 @@ static struct scsi_cmnd *sun3_dma_setup_done;
 static unsigned char *sun3_scsi_regp;
 static volatile struct sun3_dma_regs *dregs;
 static struct sun3_udc_regs *udc_regs;
-static unsigned char *sun3_dma_orig_addr = NULL;
+static unsigned long sun3_dma_orig_addr;
 static unsigned long sun3_dma_orig_count = 0;
 static int sun3_dma_active = 0;
 static unsigned long last_residual = 0;
@@ -237,15 +237,15 @@ void sun3_sun3_debug (void)
 /* sun3scsi_dma_setup() -- initialize the dma controller for a read/write */
 static unsigned long sun3scsi_dma_setup(void *data, unsigned long count, int write_flag)
 {
-	void *addr;
+	unsigned long addr;
 
-	if(sun3_dma_orig_addr != NULL)
+	if (sun3_dma_orig_addr)
 		dvma_unmap(sun3_dma_orig_addr);
 
 #ifdef SUN3_SCSI_VME
-	addr = (void *)dvma_map_vme((unsigned long) data, count);
+	addr = dvma_map_vme(data, count);
 #else
-	addr = (void *)dvma_map((unsigned long) data, count);
+	addr = dvma_map(data, count);
 #endif
 		
 	sun3_dma_orig_addr = addr;
@@ -399,9 +399,7 @@ static int sun3scsi_dma_finish(int write_flag)
 	last_residual = fifo;
 	/* empty bytes from the fifo which didn't make it */
 	if ((!write_flag) && (dregs->csr & CSR_LEFT)) {
-		unsigned char *vaddr;
-
-		vaddr = (unsigned char *)dvma_vmetov(sun3_dma_orig_addr);
+		unsigned char *vaddr = dvma_vmetov(sun3_dma_orig_addr);
 
 		vaddr += (sun3_dma_orig_count - fifo);
 		vaddr--;
@@ -444,11 +442,8 @@ static int sun3scsi_dma_finish(int write_flag)
 
 	/* empty bytes from the fifo which didn't make it */
 	if((!write_flag) && (count - fifo) == 2) {
-		unsigned short data;
-		unsigned char *vaddr;
-
-		data = dregs->fifo_data;
-		vaddr = (unsigned char *)dvma_btov(sun3_dma_orig_addr);
+		unsigned short data = dregs->fifo_data;
+		unsigned char *vaddr = dvma_btov(sun3_dma_orig_addr);
 		
 		vaddr += (sun3_dma_orig_count - fifo);
 
@@ -458,7 +453,7 @@ static int sun3scsi_dma_finish(int write_flag)
 #endif
 
 	dvma_unmap(sun3_dma_orig_addr);
-	sun3_dma_orig_addr = NULL;
+	sun3_dma_orig_addr = 0;
 
 #ifdef SUN3_SCSI_VME
 	dregs->dma_addr_hi = 0;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ