armv7: unused/useless residue

2018-03-04 Thread Artturi Alm
Hi,

these should still belong to history.

-Artturi


diff --git sys/arch/arm/arm/bus_dma.c sys/arch/arm/arm/bus_dma.c
index 231951c7262..14f643b7697 100644
--- sys/arch/arm/arm/bus_dma.c
+++ sys/arch/arm/arm/bus_dma.c
@@ -751,8 +751,7 @@ _bus_dmamap_sync(bus_dma_tag_t t, bus_dmamap_t map, 
bus_addr_t offset,
 * vmspace has not been active since the last time a full
 * cache flush was performed, we don't need to do anything.
 */
-   if (__predict_false(map->_dm_proc != NULL &&
-   map->_dm_proc->p_vmspace->vm_map.pmap->pm_cstate.cs_cache_d == 0))
+   if (__predict_false(map->_dm_proc != NULL))
return;
 
switch (map->_dm_buftype) {
diff --git sys/arch/arm/arm/genassym.cf sys/arch/arm/arm/genassym.cf
index 3937b930c39..c6f6d097476 100644
--- sys/arch/arm/arm/genassym.cf
+++ sys/arch/arm/arm/genassym.cf
@@ -61,7 +61,6 @@ define__ARM_FIQ_INDIRECT  1
 endif
 
 export DOMAIN_CLIENT
-export PMAP_DOMAIN_KERNEL
 
 ifdef PMAP_INCLUDE_PTE_SYNC
 define PMAP_INCLUDE_PTE_SYNC   1
@@ -86,8 +85,6 @@ memberpcb_tf
 member pcb_pagedir
 member pcb_pl1vec
 member pcb_l1vec
-member pcb_dacr
-member pcb_cstate
 member pcb_flags
 member PCB_R8  pcb_un.un_32.pcb32_r8
 member PCB_R9  pcb_un.un_32.pcb32_r9
@@ -112,18 +109,6 @@ struct vmspace
 member vm_map
 member VM_PMAP vm_map.pmap
 
-union  pmap_cache_state
-member cs_tlb_id
-member cs_tlb_d
-member cs_tlb
-member cs_cache_id
-member cs_cache_d
-member cs_cache
-member cs_all
-
-struct pmap
-member PMAP_CSTATE pm_cstate
-
 struct uprof
 member pr_base
 member pr_size
diff --git sys/arch/arm/include/pcb.h sys/arch/arm/include/pcb.h
index fc43b1c9a21..ffef2fb59d8 100644
--- sys/arch/arm/include/pcb.h
+++ sys/arch/arm/include/pcb.h
@@ -48,8 +48,6 @@ struct pcb_arm32 {
paddr_t pcb32_pagedir;  /* PT hooks */
pd_entry_t *pcb32_pl1vec;   /* PTR to vector_base L1 entry*/
pd_entry_t pcb32_l1vec; /* Value to stuff on ctx sw */
-   u_int   pcb32_dacr; /* Domain Access Control Reg */
-   void*pcb32_cstate;  /* >pm_cstate */
/*
 * WARNING!
 * cpuswitch.S relies on pcb32_r8 being quad-aligned in struct pcb
@@ -68,8 +66,6 @@ struct pcb_arm32 {
 #definepcb_pagedir pcb_un.un_32.pcb32_pagedir
 #definepcb_pl1vec  pcb_un.un_32.pcb32_pl1vec
 #definepcb_l1vec   pcb_un.un_32.pcb32_l1vec
-#definepcb_dacrpcb_un.un_32.pcb32_dacr
-#definepcb_cstate  pcb_un.un_32.pcb32_cstate
 
 /*
  * WARNING!
diff --git sys/arch/arm/include/pmap.h sys/arch/arm/include/pmap.h
index 83c3395f710..162f0a45835 100644
--- sys/arch/arm/include/pmap.h
+++ sys/arch/arm/include/pmap.h
@@ -124,55 +124,11 @@
 struct l1_ttable;
 struct l2_dtable;
 
-/*
- * Track cache/tlb occupancy using the following structure
- */
-union pmap_cache_state {
-   struct {
-   union {
-   u_int8_t csu_cache_b[2];
-   u_int16_t csu_cache;
-   } cs_cache_u;
-
-   union {
-   u_int8_t csu_tlb_b[2];
-   u_int16_t csu_tlb;
-   } cs_tlb_u;
-   } cs_s;
-   u_int32_t cs_all;
-};
-#definecs_cache_id cs_s.cs_cache_u.csu_cache_b[0]
-#definecs_cache_d  cs_s.cs_cache_u.csu_cache_b[1]
-#definecs_cachecs_s.cs_cache_u.csu_cache
-#definecs_tlb_id   cs_s.cs_tlb_u.csu_tlb_b[0]
-#definecs_tlb_dcs_s.cs_tlb_u.csu_tlb_b[1]
-#definecs_tlb  cs_s.cs_tlb_u.csu_tlb
-
-/*
- * Assigned to cs_all to force cacheops to work for a particular pmap
- */
-#definePMAP_CACHE_STATE_ALL0xu
-
-/*
- * This structure is used by machine-dependent code to describe
- * static mappings of devices, created at bootstrap time.
- */
-struct pmap_devmap {
-   vaddr_t pd_va;  /* virtual address */
-   paddr_t pd_pa;  /* physical address */
-   psize_t pd_size;/* size of region */
-   vm_prot_t   pd_prot;/* protection code */
-   int pd_cache;   /* cache attributes */
-};
-
 /*
  * The pmap structure itself
  */
 struct pmap {
-   u_int8_tpm_domain;
-   boolean_t   pm_remove_all;
struct l1_ttable*pm_l1;
-   union pmap_cache_state  pm_cstate;
u_int   pm_refs;
struct l2_dtable*pm_l2[L2_SIZE];
struct pmap_statistics  pm_stats;
@@ -274,16 +230,11 @@ void  vector_page_setprot(int);
 /* XXX */
 void pmap_kenter_cache(vaddr_t va, paddr_t pa, vm_prot_t prot, int cacheable);
 
-const struct pmap_devmap *pmap_devmap_find_pa(paddr_t, psize_t);
-const struct pmap_devmap *pmap_devmap_find_va(vaddr_t, vsize_t);
-
 /* Bootstrapping 

Allow syspatch to use ftp

2018-03-04 Thread Andrew Marks
The below allows "ftp://; url in /etc/installurl.

Now the discussion part, there are at least three utilities I know of
which use /etc/installurl to find OpenBSD "sources"
1. syspatch
2. pkg_add
3. installation (I don't know the exact name)

There may be others which are all
1. verifiying that /etc/installurl is valid
2. fetching things
3. verifying checksums

Which may be cause to consolidate those things into a single utility?

Any thoughts?

--- syspatch.sh 29 Dec 2017 18:56:36 -  1.134
+++ syspatch.sh 4 Mar 2018 17:41:41 -
@@ -264,7 +264,7 @@ _OSrev=${_KERNV[0]%.*}${_KERNV[0]#*.}
 
 _MIRROR=$(while read _line; do _line=${_line%%#*}; [[ -n ${_line} ]] &&
print -r -- "${_line}"; done /dev/null
-[[ ${_MIRROR} == @(file|http|https)://* ]] ||
+[[ ${_MIRROR} == @(ftp|file|http|https)://* ]] ||
sp_err "${0##*/}: invalid URL configured in /etc/installurl"
 _MIRROR="${_MIRROR}/syspatch/${_KERNV[0]}/$(machine)"
 



Another fix for /usr/games/hack

2018-03-04 Thread tonypony76
I recently wrote a patch that makes /usr/games/hack playable again.

 http://marc.info/?l=openbsd-tech=151986187422137

But now I've noticed that hack crashes with a segmentation fault when
the user requests the inventory list while playing a previously-saved
game.  I've discovered that when hack saves a game, it saves pointers to
addresses inside the executable, under the assumption that those
pointers will always be the same "as long as we use only one version of
Hack".  In OpenBSD, this assumption is not valid, and it causes a
segmentation fault when one process attempts to use a pointer that was
saved by another process.

A patch that fixes this problem is included below.


--- games/hack/hack.o_init.c.orig   Sat Jan  9 21:54:11 2016
+++ games/hack/hack.o_init.cSun Mar  4 20:20:19 2018
@@ -173,18 +173,29 @@
 {
int i;
unsigned len;
+   unsigned zero = 0;
 
bwrite(fd, bases, sizeof bases);
bwrite(fd, objects, sizeof objects);
-   /* as long as we use only one version of Hack/Quest we
-  need not save oc_name and oc_descr, but we must save
-  oc_uname for all objects */
for(i=0; i < SIZE(objects); i++) {
+   if(objects[i].oc_name) {
+   len = strlen(objects[i].oc_name)+1;
+   bwrite(fd, , sizeof len);
+   bwrite(fd, objects[i].oc_name, len);
+   } else
+   bwrite(fd, , sizeof len);
+   if(objects[i].oc_descr) {
+   len = strlen(objects[i].oc_descr)+1;
+   bwrite(fd, , sizeof len);
+   bwrite(fd, objects[i].oc_descr, len);
+   } else
+   bwrite(fd, , sizeof len);
if(objects[i].oc_uname) {
len = strlen(objects[i].oc_uname)+1;
bwrite(fd, , sizeof len);
bwrite(fd, objects[i].oc_uname, len);
-   }
+   } else
+   bwrite(fd, , sizeof len);
}
 }
 
@@ -196,10 +207,25 @@
 
mread(fd, (char *) bases, sizeof bases);
mread(fd, (char *) objects, sizeof objects);
-   for(i=0; i < SIZE(objects); i++) if(objects[i].oc_uname) {
+   for(i=0; i < SIZE(objects); i++) {
mread(fd, (char *) , sizeof len);
-   objects[i].oc_uname = (char *) alloc(len);
-   mread(fd, objects[i].oc_uname, len);
+   if(len) {
+   objects[i].oc_name = (char *) alloc(len);
+   mread(fd, objects[i].oc_name, len);
+   } else
+   objects[i].oc_name = 0;
+   mread(fd, (char *) , sizeof len);
+   if(len) {
+   objects[i].oc_descr = (char *) alloc(len);
+   mread(fd, objects[i].oc_descr, len);
+   } else 
+   objects[i].oc_descr = 0;
+   mread(fd, (char *) , sizeof len);
+   if(len) {
+   objects[i].oc_uname = (char *) alloc(len);
+   mread(fd, objects[i].oc_uname, len);
+   } else 
+   objects[i].oc_uname = 0;
}
 }
 



sparc64 softraid boot: workaround for memory leak

2018-03-04 Thread Stefan Sperling
On my T5220 LDOM guests cannot boot from softraid because ofwboot
crashes with a "Fast Data Access MMU Miss" while loading the kernel:

>> OpenBSD BOOT 1.9   
ERROR: /iscsi-hba: No iscsi-network-bootpath property  
sr0*
Passphrase:   
Booting sr0:a/bsd   
8480888@0x100
ERROR: Last Trap: Fast Data Access MMU Miss 

I've tracked down the failure to a crash in OF_open() called in sr_strategy().
There is no missing OF_close() call. So it seems a memory/resource leak
of some kind is happening in firmware during OF_open()/OF_close().

Affected firmware version info:

SP firmware 3.0.12.8.a
SP firmware build number: 108523
SP firmware date: Fri Mar 11 07:19:16 PST 2016
SP filesystem version: 0.1.22

hypervisor_version = Hypervisor 1.10.7.h 2016/03/11 07:13
obp_version = OpenBoot 4.33.6.g 2016/03/11 06:05
post_version = POST 4.33.6.g 2016/03/11 06:15
status = OpenBSD running
sysfw_version = Sun System Firmware 7.4.10.a 2016/03/11 07:45

The diff below allows a guest to boot from softraid on this machine.

ok?

Index: disk.h
===
RCS file: /cvs/src/sys/arch/sparc64/stand/ofwboot/disk.h,v
retrieving revision 1.1
diff -u -p -r1.1 disk.h
--- disk.h  26 Nov 2014 20:30:41 -  1.1
+++ disk.h  4 Mar 2018 15:56:59 -
@@ -37,6 +37,9 @@ struct diskinfo {
char path[256];
struct disklabel disklabel;
struct sr_boot_volume *sr_vol;
+   int ihandle;
+   int flags;
+#define DISKINFO_FLAG_OPEN 0x1
 
TAILQ_ENTRY(diskinfo) list;
 };
Index: ofdev.c
===
RCS file: /cvs/src/sys/arch/sparc64/stand/ofwboot/ofdev.c,v
retrieving revision 1.25
diff -u -p -r1.25 ofdev.c
--- ofdev.c 1 Oct 2015 16:08:20 -   1.25
+++ ofdev.c 4 Mar 2018 15:56:59 -
@@ -165,6 +165,7 @@ devclose(struct open_file *of)
 #endif
 #ifdef SOFTRAID
if (op->type == OFDEV_SOFTRAID) {
+   sr_close_volume(bootdev_dip->sr_vol);
op->handle = -1;
return 0;
}
Index: softraid_sparc64.c
===
RCS file: /cvs/src/sys/arch/sparc64/stand/ofwboot/softraid_sparc64.c,v
retrieving revision 1.2
diff -u -p -r1.2 softraid_sparc64.c
--- softraid_sparc64.c  11 Sep 2016 17:53:26 -  1.2
+++ softraid_sparc64.c  4 Mar 2018 15:56:59 -
@@ -306,6 +306,22 @@ srprobe(void)
free(md, SR_META_SIZE * DEV_BSIZE);
 }
 
+/* 
+ * Cache ihandle to work around memory leaks in firmware
+ * with repeated OF_open/OF_close calls.
+ */
+int
+sr_open_disk(struct diskinfo *dip)
+{
+   if ((dip->flags & DISKINFO_FLAG_OPEN) == 0) {
+   dip->ihandle = OF_open(dip->path);
+   if (dip->ihandle != -1)
+   dip->flags |= DISKINFO_FLAG_OPEN;
+   }
+
+   return dip->ihandle;
+}
+
 int
 sr_strategy(struct sr_boot_volume *bv, int rw, daddr32_t blk, size_t size,
 void *buf, size_t *rsize)
@@ -347,7 +363,7 @@ sr_strategy(struct sr_boot_volume *bv, i
blk += bv->sbv_data_blkno;
 
/* XXX - If I/O failed we should try another chunk... */
-   ihandle = OF_open(dip->path);
+   ihandle = sr_open_disk(dip);
if (ihandle == -1)
return EIO;
bzero(, sizeof(ofdev));
@@ -356,7 +372,6 @@ sr_strategy(struct sr_boot_volume *bv, i
ofdev.bsize = DEV_BSIZE;
ofdev.partoff = DL_GETPOFFSET(pp);
err = strategy(, rw, blk, size, buf, rsize);
-   OF_close(ihandle);
return err;
 
} else if (bv->sbv_level == 'C') {
@@ -371,7 +386,7 @@ sr_strategy(struct sr_boot_volume *bv, i
dip = (struct diskinfo *)bc->sbc_diskinfo;
pp = >disklabel.d_partitions[bc->sbc_part - 'a'];
 
-   ihandle = OF_open(dip->path);
+   ihandle = sr_open_disk(dip);
if (ihandle == -1)
return EIO;
bzero(, sizeof(ofdev));
@@ -395,7 +410,6 @@ sr_strategy(struct sr_boot_volume *bv, i
printf("Read from crypto volume failed "
"(read %d bytes): %s\n", *rsize,
strerror(err));
-   OF_close(ihandle);
return err;
}
bcopy(, iv, sizeof(blkno));
@@ -404,11 +418,30 @@ sr_strategy(struct sr_boot_volume *bv, i
aes_xts_decrypt(, bp + j);
}
*rsize = nsect * DEV_BSIZE;
-   OF_close(ihandle);
return err;