libc/regex: constify more data

2020-12-29 Thread Miod Vallat
The following diff constifies the strings in cnames[]. No functional
change.

Index: cname.h
===
RCS file: /OpenBSD/src/lib/libc/regex/cname.h,v
retrieving revision 1.5
diff -u -p -r1.5 cname.h
--- cname.h 2 Jun 2003 20:18:36 -   1.5
+++ cname.h 29 Dec 2020 09:30:53 -
@@ -36,8 +36,8 @@
  */
 
 /* character-name table */
-static struct cname {
-   char *name;
+static const struct cname {
+   const char *name;
char code;
 } cnames[] = {
{ "NUL",'\0' },
Index: regcomp.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regcomp.c,v
retrieving revision 1.35
diff -u -p -r1.35 regcomp.c
--- regcomp.c   13 Oct 2020 04:42:28 -  1.35
+++ regcomp.c   29 Dec 2020 09:30:53 -
@@ -826,7 +815,7 @@ p_b_coll_elem(struct parse *p,
 int endc)  /* name ended by endc,']' */
 {
char *sp = p->next;
-   struct cname *cp;
+   const struct cname *cp;
size_t len;
 
while (MORE() && !SEETWO(endc, ']'))



libc/regex: remove dead code

2020-12-29 Thread Miod Vallat
cclasses[] multis field is always an empty string. Remove it and code
dealing with it. This code was incomplete anyway.

Index: cclass.h
===
RCS file: /OpenBSD/src/lib/libc/regex/cclass.h,v
retrieving revision 1.6
diff -u -p -r1.6 cclass.h
--- cclass.h13 Oct 2020 04:42:28 -  1.6
+++ cclass.h29 Dec 2020 09:30:53 -
@@ -39,30 +39,22 @@
 static const struct cclass {
const char *name;
const char *chars;
-   const char *multis;
 } cclasses[] = {
{ "alnum",  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
-0123456789",   ""} ,
-   { "alpha",  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
-   ""} ,
-   { "blank",  " \t",  ""} ,
+0123456789" },
+   { "alpha",  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" 
},
+   { "blank",  " \t" },
{ "cntrl",  "\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\
-\25\26\27\30\31\32\33\34\35\36\37\177",""} ,
-   { "digit",  "0123456789",   ""} ,
+\25\26\27\30\31\32\33\34\35\36\37\177" },
+   { "digit",  "0123456789" },
{ "graph",  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
-0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
-   ""} ,
-   { "lower",  "abcdefghijklmnopqrstuvwxyz",
-   ""} ,
+0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" },
+   { "lower",  "abcdefghijklmnopqrstuvwxyz" },
{ "print",  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
-0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ",
-   ""} ,
-   { "punct",  "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
-   ""} ,
-   { "space",  "\t\n\v\f\r ",  ""} ,
-   { "upper",  "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
-   ""} ,
-   { "xdigit", "0123456789ABCDEFabcdef",
-   ""} ,
-   { NULL, 0,  "" }
+0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ " },
+   { "punct",  "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" },
+   { "space",  "\t\n\v\f\r " },
+   { "upper",  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" },
+   { "xdigit", "0123456789ABCDEFabcdef" },
+   { NULL, 0 }
 };
Index: regcomp.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regcomp.c,v
retrieving revision 1.35
diff -u -p -r1.35 regcomp.c
--- regcomp.c   13 Oct 2020 04:42:28 -  1.35
+++ regcomp.c   29 Dec 2020 09:30:53 -
@@ -90,9 +90,6 @@ static void freeset(struct parse *, cset
 static int freezeset(struct parse *, cset *);
 static int firstch(struct parse *, cset *);
 static int nch(struct parse *, cset *);
-static void mcadd(struct parse *, cset *, const char *);
-static void mcinvert(struct parse *, cset *);
-static void mccase(struct parse *, cset *);
 static int isinsets(struct re_guts *, int);
 static int samesets(struct re_guts *, int, int);
 static void categorize(struct parse *, struct re_guts *);
@@ -666,8 +663,6 @@ p_bracket(struct parse *p)
if (ci != i)
CHadd(cs, ci);
}
-   if (cs->multis != NULL)
-   mccase(p, cs);
}
if (invert) {
int i;
@@ -679,12 +674,8 @@ p_bracket(struct parse *p)
CHadd(cs, i);
if (p->g->cflags®_NEWLINE)
CHsub(cs, '\n');
-   if (cs->multis != NULL)
-   mcinvert(p, cs);
}
 
-   assert(cs->multis == NULL); /* xxx */
-
if (nch(p, cs) == 1) {  /* optimize singleton sets */
ordinary(p, firstch(p, cs));
freeset(p, cs);
@@ -782,8 +773,6 @@ p_b_cclass(struct parse *p, cset *cs)
u = cp->chars;
while ((c = *u++) != '\0')
CHadd(cs, c);
-   for (u = cp->multis; *u != '\0'; u += strlen(u) + 1)
-   MCadd(p, cs, u);
 }
 
 /*
@@ -1073,8 +1062,6 @@ allocset(struct parse *p)
cs->ptr = p->g->setbits + css*((no)/CHAR_BIT);
cs->mask = 1 << ((no) % CHAR_BIT);
cs->hash = 0;
-   cs->smultis = 0;
-   cs->multis = NULL;
 
return(cs);
 nomem:
@@ -1171,52 +1158,6 @@ nch(struct parse *p, cset *cs)
if (CHIN(cs, i))
n++;
return(n);
-}
-
-/*
- - mcadd - add a collating element to a cset
- */
-static void
-mcadd( struct parse *p, cset *cs, const char *cp)
-{
-   size_t oldend = cs->smultis;
-   void *np;
-
-   cs->smultis += strlen(cp) + 1;
-   np = realloc(cs->multis, cs->smultis);
-   if (np == NULL) {
-   free(cs-

libc/regex: regerror minor tweaks

2020-12-29 Thread Miod Vallat
The following diff constifies the strings in regerror.c and also makes
use of the strlcpy() return value to avoid a redundant strlen() call.

Index: regerror.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regerror.c,v
retrieving revision 1.14
diff -u -p -r1.14 regerror.c
--- regerror.c  1 Nov 2015 03:45:29 -   1.14
+++ regerror.c  29 Dec 2020 10:24:18 -
@@ -44,12 +44,12 @@
 
 #include "utils.h"
 
-static char *regatoi(const regex_t *, char *, int);
+static const char *regatoi(const regex_t *, char *, int);
 
-static struct rerr {
+static const struct rerr {
int code;
-   char *name;
-   char *explain;
+   const char *name;
+   const char *explain;
 } rerrs[] = {
{ REG_NOMATCH,  "REG_NOMATCH",  "regexec() failed to match" },
{ REG_BADPAT,   "REG_BADPAT",   "invalid regular expression" },
@@ -77,10 +77,10 @@ static struct rerr {
 size_t
 regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
 {
-   struct rerr *r;
+   const struct rerr *r;
size_t len;
int target = errcode &~ REG_ITOA;
-   char *s;
+   const char *s;
char convbuf[50];
 
if (errcode == REG_ATOI)
@@ -102,21 +102,21 @@ regerror(int errcode, const regex_t *pre
s = r->explain;
}
 
-   len = strlen(s) + 1;
-   if (errbuf_size > 0) {
-   strlcpy(errbuf, s, errbuf_size);
-   }
+   if (errbuf_size != 0)
+   len = strlcpy(errbuf, s, errbuf_size);
+   else
+   len = strlen(s);
 
-   return(len);
+   return len + 1;
 }
 
 /*
  - regatoi - internal routine to implement REG_ATOI
  */
-static char *
+static const char *
 regatoi(const regex_t *preg, char *localbuf, int localbufsize)
 {
-   struct rerr *r;
+   const struct rerr *r;
 
for (r = rerrs; r->code != 0; r++)
if (strcmp(r->name, preg->re_endp) == 0)



libc/regex: safer pointer arithmetic

2020-12-29 Thread Miod Vallat
regcomp.c uses the "start + count < end" idiom to check that there are
"count" bytes available in an array of char "start" and "end" both point
to.

This is fine, unless "start + count" goes beyond the last element of the
array. In this case, pedantic interpretation of the C standard makes
the comparison of such a pointer against "end" undefined, and optimizers
from hell will happily remove as much code as possible because of this.

An example of this occurs in regcomp.c's bothcases(), which defines
bracket[3], sets "next" to "bracket" and "end" to "bracket + 2". Then it
invokes p_bracket(), which starts with "if (p->next + 5 < p->end)"...

Because bothcases() and p_bracket() are static functions in regcomp.c,
there is a real risk of miscompilation if aggressive inlining happens.

The following diff rewrites the "start + count < end" constructs into
"end - start > count". Assuming "end" and "start" are always pointing in
the array (such as "bracket[3]" above), "end - start" is well-defined
and can be compared without trouble.

As a bonus, MORE2() implies MORE() therefore SEETWO() can be simplified
a bit.

Index: regcomp.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regcomp.c,v
retrieving revision 1.35
diff -u -p -r1.35 regcomp.c
--- regcomp.c   13 Oct 2020 04:42:28 -  1.35
+++ regcomp.c   29 Dec 2020 10:24:18 -
@@ -113,10 +110,10 @@ static char nuls[10]; /* place to point
  */
 #definePEEK()  (*p->next)
 #definePEEK2() (*(p->next+1))
-#defineMORE()  (p->next < p->end)
-#defineMORE2() (p->next+1 < p->end)
+#defineMORE()  (p->end - p->next > 0)
+#defineMORE2() (p->end - p->next > 1)
 #defineSEE(c)  (MORE() && PEEK() == (c))
-#defineSEETWO(a, b)(MORE() && MORE2() && PEEK() == (a) && PEEK2() 
== (b))
+#defineSEETWO(a, b)(MORE2() && PEEK() == (a) && PEEK2() == (b))
 #defineEAT(c)  ((SEE(c)) ? (NEXT(), 1) : 0)
 #defineEATTWO(a, b)((SEETWO(a, b)) ? (NEXT2(), 1) : 0)
 #defineNEXT()  (p->next++)
@@ -623,15 +620,17 @@ p_bracket(struct parse *p)
int invert = 0;
 
/* Dept of Truly Sickening Special-Case Kludges */
-   if (p->next + 5 < p->end && strncmp(p->next, "[:<:]]", 6) == 0) {
-   EMIT(OBOW, 0);
-   NEXTn(6);
-   return;
-   }
-   if (p->next + 5 < p->end && strncmp(p->next, "[:>:]]", 6) == 0) {
-   EMIT(OEOW, 0);
-   NEXTn(6);
-   return;
+   if (p->end - p->next > 5) {
+   if (strncmp(p->next, "[:<:]]", 6) == 0) {
+   EMIT(OBOW, 0);
+   NEXTn(6);
+   return;
+   }
+   if (strncmp(p->next, "[:>:]]", 6) == 0) {
+   EMIT(OEOW, 0);
+   NEXTn(6);
+   return;
+   }
}
 
if ((cs = allocset(p)) == NULL) {



compress sparc64 bsd.rd

2020-12-30 Thread Miod Vallat
Up until 6.5, sparc64 bsd.rd were gzipped kernels. This got lost during
the Great Installation Media Unification of the 6.6 release cycle, and
since then bsd.rd are uncompressed.

The following diff ought to fix this and bring back sparc64 netboot
times down to acceptable times.

Index: miniroot/Makefile
===
RCS file: /OpenBSD/src/distrib/sparc64/miniroot/Makefile,v
retrieving revision 1.23
diff -u -p -r1.23 Makefile
--- miniroot/Makefile   18 May 2020 06:20:44 -  1.23
+++ miniroot/Makefile   30 Dec 2020 20:35:55 -
@@ -100,7 +100,7 @@ unconfig:
 
 .ifdef RELEASEDIR
 install:
-   cp bsd.rd ${RELEASEDIR}/bsd.rd
+   cp bsd.gz ${RELEASEDIR}/bsd.rd
chmod a+r ${RELEASEDIR}/bsd.rd
cp ${FS} ${RELEASEDIR}
cp ${CDROM} ${RELEASEDIR}



libc/regex: const'r'us

2020-12-30 Thread Miod Vallat
Spencer's code was written before const was a thing, but we can do
better. Neither regcomp(3) nor regex(3) modify the strings they are
being passed, so we can keep internal pointers as const as well and
avoid {dub,spur}ious casts.

While there, the temporary array in nonnewline() can be made static
const as well rather than recreated every time.

Index: regcomp.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regcomp.c,v
retrieving revision 1.38
diff -u -p -r1.38 regcomp.c
--- regcomp.c   30 Dec 2020 08:59:17 -  1.38
+++ regcomp.c   31 Dec 2020 07:21:31 -
@@ -53,8 +53,8 @@
  * other clumsinesses
  */
 struct parse {
-   char *next; /* next character in RE */
-   char *end;  /* end of string (-> NUL normally) */
+   const char *next;   /* next character in RE */
+   const char *end;/* end of string (-> NUL normally) */
int error;  /* has an error been seen? */
sop *strip; /* malloced strip */
sopno ssize;/* malloced strip size (allocated) */
@@ -179,7 +178,7 @@ regcomp(regex_t *preg, const char *patte
 
/* set things up */
p->g = g;
-   p->next = (char *)pattern;  /* convenience; we do not modify it */
+   p->next = pattern;
p->end = p->next + len;
p->error = 0;
p->ncsalloc = 0;
@@ -754,7 +749,7 @@ p_b_term(struct parse *p, cset *cs)
 static void
 p_b_cclass(struct parse *p, cset *cs)
 {
-   char *sp = p->next;
+   const char *sp = p->next;
const struct cclass *cp;
size_t len;
const char *u;
@@ -816,7 +811,7 @@ static char /* value of collating elem
 p_b_coll_elem(struct parse *p,
 int endc)  /* name ended by endc,']' */
 {
-   char *sp = p->next;
+   const char *sp = p->next;
const struct cname *cp;
size_t len;
 
@@ -860,8 +855,8 @@ othercase(int ch)
 static void
 bothcases(struct parse *p, int ch)
 {
-   char *oldnext = p->next;
-   char *oldend = p->end;
+   const char *oldnext = p->next;
+   const char *oldend = p->end;
char bracket[3];
 
ch = (uch)ch;
@@ -921,16 +911,12 @@ backslash(struct parse *p, int ch)
 static void
 nonnewline(struct parse *p)
 {
-   char *oldnext = p->next;
-   char *oldend = p->end;
-   char bracket[4];
+   const char *oldnext = p->next;
+   const char *oldend = p->end;
+   static const char bracket[4] = { '^', '\n', ']', '\0' };
 
p->next = bracket;
p->end = bracket+3;
-   bracket[0] = '^';
-   bracket[1] = '\n';
-   bracket[2] = ']';
-   bracket[3] = '\0';
p_bracket(p);
assert(p->next == bracket+3);
p->next = oldnext;



libc/regex: drop more unused data

2020-12-30 Thread Miod Vallat
re_guts catspace[] is only written to (via categories[]), and never used
for anything, so don't bother keeping that.

Index: lib/libc/regex/regcomp.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regcomp.c,v
retrieving revision 1.38
diff -u -p -r1.38 regcomp.c
--- lib/libc/regex/regcomp.c30 Dec 2020 08:59:17 -  1.38
+++ lib/libc/regex/regcomp.c31 Dec 2020 07:20:39 -
@@ -92,7 +92,6 @@ static int firstch(struct parse *, cset 
 static int nch(struct parse *, cset *);
 static int isinsets(struct re_guts *, int);
 static int samesets(struct re_guts *, int, int);
-static void categorize(struct parse *, struct re_guts *);
 static sopno dupl(struct parse *, sopno, sopno);
 static void doemit(struct parse *, sop, size_t);
 static void doinsert(struct parse *, sop, size_t, sopno);
@@ -198,9 +197,6 @@ regcomp(regex_t *preg, const char *patte
g->must = NULL;
g->mlen = 0;
g->nsub = 0;
-   g->ncategories = 1; /* category 0 is "everything else" */
-   g->categories = &g->catspace[-(CHAR_MIN)];
-   memset(g->catspace, 0, sizeof(g->catspace));
g->backrefs = 0;
 
/* do it */
@@ -216,7 +212,6 @@ regcomp(regex_t *preg, const char *patte
g->laststate = THERE();
 
/* tidy up loose ends and fill things in */
-   categorize(p, g);
stripsnug(p, g);
findmust(p, g);
g->nplus = pluscount(p, g);
@@ -883,15 +878,10 @@ bothcases(struct parse *p, int ch)
 static void
 ordinary(struct parse *p, int ch)
 {
-   cat_t *cap = p->g->categories;
-
if ((p->g->cflags®_ICASE) && isalpha((uch)ch) && othercase(ch) != ch)
bothcases(p, ch);
-   else {
+   else
EMIT(OCHAR, (uch)ch);
-   if (cap[ch] == 0)
-   cap[ch] = p->g->ncategories++;
-   }
 }
 
 /*
@@ -1195,31 +1180,6 @@ samesets(struct re_guts *g, int c1, int 
if (col[uc1] != col[uc2])
return(0);
return(1);
-}
-
-/*
- - categorize - sort out character categories
- */
-static void
-categorize(struct parse *p, struct re_guts *g)
-{
-   cat_t *cats = g->categories;
-   int c;
-   int c2;
-   cat_t cat;
-
-   /* avoid making error situations worse */
-   if (p->error != 0)
-   return;
-
-   for (c = CHAR_MIN; c <= CHAR_MAX; c++)
-   if (cats[c] == 0 && isinsets(g, c)) {
-   cat = g->ncategories++;
-   cats[c] = cat;
-   for (c2 = c+1; c2 <= CHAR_MAX; c2++)
-   if (cats[c2] == 0 && samesets(g, c, c2))
-   cats[c2] = cat;
-   }
 }
 
 /*
Index: lib/libc/regex/regex2.h
===
RCS file: /OpenBSD/src/lib/libc/regex/regex2.h,v
retrieving revision 1.9
diff -u -p -r1.9 regex2.h
--- lib/libc/regex/regex2.h 30 Dec 2020 08:54:42 -  1.9
+++ lib/libc/regex/regex2.h 31 Dec 2020 07:20:39 -
@@ -112,9 +112,6 @@ typedef struct {
 #defineCHsub(cs, c)((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash 
-= (c))
 #defineCHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask)
 
-/* stuff for character categories */
-typedef unsigned char cat_t;
-
 /*
  * main compiled-expression structure
  */
@@ -136,15 +133,11 @@ struct re_guts {
 #  define  BAD 04  /* something wrong */
int nbol;   /* number of ^ used */
int neol;   /* number of $ used */
-   int ncategories;/* how many character categories */
-   cat_t *categories;  /* ->catspace[-CHAR_MIN] */
char *must; /* match must contain this string */
int mlen;   /* length of must */
size_t nsub;/* copy of re_nsub */
int backrefs;   /* does it use back references? */
sopno nplus;/* how deep does it nest +s? */
-   /* catspace must be last */
-   cat_t catspace[NC]; /* actually [NC] */
 };
 
 /* misc utilities */
Index: regress/lib/libc/regex/debug.c
===
RCS file: /OpenBSD/src/regress/lib/libc/regex/debug.c,v
retrieving revision 1.4
diff -u -p -r1.4 debug.c
--- regress/lib/libc/regex/debug.c  31 Jul 2003 21:48:03 -  1.4
+++ regress/lib/libc/regex/debug.c  31 Dec 2020 07:20:39 -
@@ -26,10 +26,8 @@ FILE *d;
register int i;
register int c;
register int last;
-   int nincat[NC];
 
-   fprintf(d, "%ld states, %d categories", (long)g->nstates,
-   g->ncategories);
+   fprintf(d, "%ld states", (long)g->nstates);
fprintf(d, ", first %ld last %ld", (long)g->firststate,
(long)g->laststate);
   

libc/regex: more regular error handling

2020-12-30 Thread Miod Vallat
The REQUIRE macro is used to check for a condition, and set an error in
the parse struct if it is not satisfied.

This changes it from ((condition) || function call) to a, IMHO more
readable, if() test.

Index: regcomp.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regcomp.c,v
retrieving revision 1.38
diff -u -p -r1.38 regcomp.c
--- regcomp.c   30 Dec 2020 08:59:17 -  1.38
+++ regcomp.c   31 Dec 2020 07:21:31 -
@@ -84,7 +84,7 @@ static void ordinary(struct parse *, int
 static void backslash(struct parse *, int);
 static void nonnewline(struct parse *);
 static void repeat(struct parse *, sopno, int, int);
-static int seterr(struct parse *, int);
+static void seterr(struct parse *, int);
 static cset *allocset(struct parse *);
 static void freeset(struct parse *, cset *);
 static int freezeset(struct parse *, cset *);
@@ -121,7 +120,7 @@ static char nuls[10];   /* place to point
 #defineNEXTn(n)(p->next += (n))
 #defineGETNEXT()   (*p->next++)
 #defineSETERROR(e) seterr(p, (e))
-#defineREQUIRE(co, e)  (void) ((co) || SETERROR(e))
+#defineREQUIRE(co, e)  do { if (!(co)) SETERROR(e); } while (0)
 #defineEMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd))
 #defineINSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos)
 #defineAHEAD(pos)  dofwd(p, pos, HERE()-(pos))
@@ -1010,14 +996,13 @@ repeat(struct parse *p,
 /*
  - seterr - set an error condition
  */
-static int /* useless but makes type checking happy */
+static void
 seterr(struct parse *p, int e)
 {
if (p->error == 0)  /* keep earliest error condition */
p->error = e;
p->next = nuls; /* try to bring things to a halt */
p->end = nuls;
-   return(0);  /* make the return value well-defined */
 }
 
 /*



libc/regex: turn unsafe macros to inline functions

2021-01-02 Thread Miod Vallat
That code was written before inline functions were supported by
compilers; now that they are even part of the language standard, turn
macros into inline functions so that there is no need to document in
comments that they will evaluate their arguments multiple times.

(one may consider switching their names to lowercase now that these are
no longer macros.)

Index: regex2.h
===
RCS file: /OpenBSD/src/lib/libc/regex/regex2.h,v
retrieving revision 1.10
diff -u -p -r1.10 regex2.h
--- regex2.h31 Dec 2020 17:20:19 -  1.10
+++ regex2.h2 Jan 2021 15:59:51 -
@@ -107,10 +107,24 @@ typedef struct {
uch mask;   /* bit within array */
uch hash;   /* hash code */
 } cset;
-/* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */
-#defineCHadd(cs, c)((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash 
+= (c))
-#defineCHsub(cs, c)((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash 
-= (c))
-#defineCHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask)
+
+static inline void
+CHadd(cset *cs, char c)
+{
+   cs->ptr[(uch)c] |= cs->mask;
+   cs->hash += c;
+}
+static inline void
+CHsub(cset *cs, char c)
+{
+   cs->ptr[(uch)c] &= ~cs->mask;
+   cs->hash -= c;
+}
+static inline uch
+CHIN(const cset *cs, char c)
+{
+   return cs->ptr[(uch)c] & cs->mask;
+}
 
 /*
  * main compiled-expression structure



libc/regex: more dead code

2021-01-02 Thread Miod Vallat
The removal of the categories code made these two functions unused, so
remove them as well.

Index: regcomp.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regcomp.c,v
retrieving revision 1.41
diff -u -p -r1.41 regcomp.c
--- regcomp.c   31 Dec 2020 17:24:05 -  1.41
+++ regcomp.c   2 Jan 2021 15:59:51 -
@@ -90,8 +90,6 @@ static void freeset(struct parse *, cset
 static int freezeset(struct parse *, cset *);
 static int firstch(struct parse *, cset *);
 static int nch(struct parse *, cset *);
-static int isinsets(struct re_guts *, int);
-static int samesets(struct re_guts *, int, int);
 static sopno dupl(struct parse *, sopno, sopno);
 static void doemit(struct parse *, sop, size_t);
 static void doinsert(struct parse *, sop, size_t, sopno);
@@ -1148,41 +1146,6 @@ nch(struct parse *p, cset *cs)
 }
 
 /*
- - isinsets - is this character in any sets?
- */
-static int /* predicate */
-isinsets(struct re_guts *g, int c)
-{
-   uch *col;
-   int i;
-   int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT;
-   unsigned uc = (uch)c;
-
-   for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize)
-   if (col[uc] != 0)
-   return(1);
-   return(0);
-}
-
-/*
- - samesets - are these two characters in exactly the same sets?
- */
-static int /* predicate */
-samesets(struct re_guts *g, int c1, int c2)
-{
-   uch *col;
-   int i;
-   int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT;
-   unsigned uc1 = (uch)c1;
-   unsigned uc2 = (uch)c2;
-
-   for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize)
-   if (col[uc1] != col[uc2])
-   return(0);
-   return(1);
-}
-
-/*
  - dupl - emit a duplicate of a bunch of sops
  */
 static sopno   /* start of duplicate */
@@ -1394,7 +1357,7 @@ findmust(struct parse *p, struct re_guts
*cp++ = (char)OPND(s);
}
assert(cp == g->must + g->mlen);
-   *cp++ = '\0';   /* just on general principles */
+   *cp = '\0'; /* just on general principles */
 }
 
 /*



Re: libc/regex: turn unsafe macros to inline functions

2021-01-03 Thread Miod Vallat
> Is there a reason not to do
> 
>   return (cs->ptr[(uch)c] & cs->mask) != 0;
> 
> This would allow us to get rid of the !! construct in regcomp.c

Why not. What about that?

Index: regcomp.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regcomp.c,v
retrieving revision 1.41
diff -u -p -r1.41 regcomp.c
--- regcomp.c   31 Dec 2020 17:24:05 -  1.41
+++ regcomp.c   3 Jan 2021 16:43:50 -
@@ -1101,7 +1099,7 @@ freezeset(struct parse *p, cset *cs)
if (cs2->hash == h && cs2 != cs) {
/* maybe */
for (i = 0; i < css; i++)
-   if (!!CHIN(cs2, i) != !!CHIN(cs, i))
+   if (CHIN(cs2, i) != CHIN(cs, i))
break;  /* no */
if (i == css)
break;  /* yes */
Index: regex2.h
===
RCS file: /OpenBSD/src/lib/libc/regex/regex2.h,v
retrieving revision 1.10
diff -u -p -r1.10 regex2.h
--- regex2.h31 Dec 2020 17:20:19 -  1.10
+++ regex2.h3 Jan 2021 16:43:50 -
@@ -107,10 +107,26 @@ typedef struct {
uch mask;   /* bit within array */
uch hash;   /* hash code */
 } cset;
-/* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */
-#defineCHadd(cs, c)((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash 
+= (c))
-#defineCHsub(cs, c)((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash 
-= (c))
-#defineCHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask)
+
+static inline void
+CHadd(cset *cs, char c)
+{
+   cs->ptr[(uch)c] |= cs->mask;
+   cs->hash += c;
+}
+
+static inline void
+CHsub(cset *cs, char c)
+{
+   cs->ptr[(uch)c] &= ~cs->mask;
+   cs->hash -= c;
+}
+
+static inline int
+CHIN(const cset *cs, char c)
+{
+   return (cs->ptr[(uch)c] & cs->mask) != 0;
+}
 
 /*
  * main compiled-expression structure



libc/regex: drop debug helpers

2021-01-03 Thread Miod Vallat
regex(3) documents non-standard extensions REG_ITOA and REG_ATOI to
regerror(). In the OpenBSD tree, the only use of them is by the regress
test, so why not move that specific code to the regress test and shrink
libc a bit - remember that this code is present in the installation
media through grep(1).

Assuming there are no objections against this, it would be worth trying
a ports build with this diff to confirm there are no 3rd-party users of
these extensions.

Index: include/regex.h
===
RCS file: /OpenBSD/src/include/regex.h,v
retrieving revision 1.7
diff -u -p -r1.7 regex.h
--- include/regex.h 5 Dec 2012 23:19:57 -   1.7
+++ include/regex.h 3 Jan 2021 17:48:03 -
@@ -83,8 +83,6 @@ typedef struct {
 #defineREG_EMPTY   14
 #defineREG_ASSERT  15
 #defineREG_INVARG  16
-#defineREG_ATOI255 /* convert name to number (!) */
-#defineREG_ITOA0400/* convert number to name (!) */
 
 /* regexec() flags */
 #defineREG_NOTBOL  1
Index: lib/libc/regex/regerror.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regerror.c,v
retrieving revision 1.15
diff -u -p -r1.15 regerror.c
--- lib/libc/regex/regerror.c   30 Dec 2020 08:56:38 -  1.15
+++ lib/libc/regex/regerror.c   3 Jan 2021 17:48:03 -
@@ -48,26 +48,25 @@ static const char *regatoi(const regex_t
 
 static const struct rerr {
int code;
-   const char *name;
const char *explain;
 } rerrs[] = {
-   { REG_NOMATCH,  "REG_NOMATCH",  "regexec() failed to match" },
-   { REG_BADPAT,   "REG_BADPAT",   "invalid regular expression" },
-   { REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element" },
-   { REG_ECTYPE,   "REG_ECTYPE",   "invalid character class" },
-   { REG_EESCAPE,  "REG_EESCAPE",  "trailing backslash (\\)" },
-   { REG_ESUBREG,  "REG_ESUBREG",  "invalid backreference number" },
-   { REG_EBRACK,   "REG_EBRACK",   "brackets ([ ]) not balanced" },
-   { REG_EPAREN,   "REG_EPAREN",   "parentheses not balanced" },
-   { REG_EBRACE,   "REG_EBRACE",   "braces not balanced" },
-   { REG_BADBR,"REG_BADBR","invalid repetition count(s)" },
-   { REG_ERANGE,   "REG_ERANGE",   "invalid character range" },
-   { REG_ESPACE,   "REG_ESPACE",   "out of memory" },
-   { REG_BADRPT,   "REG_BADRPT",   "repetition-operator operand invalid" },
-   { REG_EMPTY,"REG_EMPTY","empty (sub)expression" },
-   { REG_ASSERT,   "REG_ASSERT",   "\"can't happen\" -- you found a bug" },
-   { REG_INVARG,   "REG_INVARG",   "invalid argument to regex routine" },
-   { 0,"", "*** unknown regexp error code ***" }
+   { REG_NOMATCH,  "regexec() failed to match" },
+   { REG_BADPAT,   "invalid regular expression" },
+   { REG_ECOLLATE, "invalid collating element" },
+   { REG_ECTYPE,   "invalid character class" },
+   { REG_EESCAPE,  "trailing backslash (\\)" },
+   { REG_ESUBREG,  "invalid backreference number" },
+   { REG_EBRACK,   "brackets ([ ]) not balanced" },
+   { REG_EPAREN,   "parentheses not balanced" },
+   { REG_EBRACE,   "braces not balanced" },
+   { REG_BADBR,"invalid repetition count(s)" },
+   { REG_ERANGE,   "invalid character range" },
+   { REG_ESPACE,   "out of memory" },
+   { REG_BADRPT,   "repetition-operator operand invalid" },
+   { REG_EMPTY,"empty (sub)expression" },
+   { REG_ASSERT,   "\"can't happen\" -- you found a bug" },
+   { REG_INVARG,   "invalid argument to regex routine" },
+   { 0,"unknown regexp error code ***" }
 };
 
 /*
@@ -79,51 +78,15 @@ regerror(int errcode, const regex_t *pre
 {
const struct rerr *r;
size_t len;
-   int target = errcode &~ REG_ITOA;
-   const char *s;
-   char convbuf[50];
 
-   if (errcode == REG_ATOI)
-   s = regatoi(preg, convbuf, sizeof convbuf);
-   else {
-   for (r = rerrs; r->code != 0; r++)
-   if (r->code == target)
-   break;
-   
-   if (errcode®_ITOA) {
-   if (r->code != 0) {
-   assert(strlen(r->name) < sizeof(convbuf));
-   (void) strlcpy(convbuf, r->name, sizeof 
convbuf);
-   } else
-   (void)snprintf(convbuf, sizeof convbuf,
-   "REG_0x%x", target);
-   s = convbuf;
-   } else
-   s = r->explain;
-   }
+   for (r = rerrs; r->code != 0; r++)
+   if (r->code == errcode)
+   break;
 
if (errbuf_size != 0)
-   len = strlcpy(errbuf, s, errbuf_size);
+   len = strlcpy(err

Re: compress sparc64 bsd.rd

2021-01-03 Thread Miod Vallat
> Since this change went in, bsd.rd doesn't boot unless I uncompress it first.
> 
> upgrade detected: switching to /bsd.upgrade
> Trying /bsd.upgrade...
> NOTE: random seed is being reused.
> Booting /pci@400/pci@2/pci@0/pci@c/nvme@0/disk@1:a/bsd.upgrade
> 4246528@0x100+5120@0x140cc00+3248796@0x1c0+945508@0x1f1929c 
> OF_map_phys(ff84,8192,fee5,-1) failed
> no space for symbol table
> Program terminated

What machine and OpenBoot version are you using?

gzipped kernels work here (as they used to) on:

Sun Ultra 1 UPA/SBus (UltraSPARC 167MHz), No Keyboard
OpenBoot 3.1, 128 MB memory installed, Serial #8592590.
Ethernet address 8:0:20:83:1c:ce, Host ID: 80831cce.



Rebooting with command: boot bsd.rd.gz   
Boot device: /sbus/SUNW,fas@e,880/sd@0,0  File and args: bsd.rd.gz
OpenBSD IEEE 1275 Bootblock 2.1
..>> OpenBSD BOOT 1.21
Booting /sbus@1f,0/SUNW,fas@e,880/sd@0,0:a/bsd.rd.gz
4249968@0x100+1680@0x140d970+3249820@0x1c0+944484@0x1f1969c 
symbols @ 0xffe88400 249148+165+369384+224195 start=0x100
console is /sbus@1f,0/zs@f,110:a
Copyright (c) 1982, 1986, 1989, 1991, 1993
The Regents of the University of California.  All rights reserved.
Copyright (c) 1995-2020 OpenBSD. All rights reserved.  https://www.OpenBSD.org
(etc, etc)



Re: compress sparc64 bsd.rd

2021-01-03 Thread Miod Vallat
> > Rebooting with command: boot bsd.rd.gz   
> 
> This is interesting. The change has it just being named bsd.rd, without the
> .gz.

That's just me testing a compressed bsd.rd.



Re: libc/regex: safer pointer arithmetic

2021-01-03 Thread Miod Vallat


> regcomp.c uses the "start + count < end" idiom to check that there are
> "count" bytes available in an array of char "start" and "end" both point
> to.
>
> This is fine, unless "start + count" goes beyond the last element of the
> array. In this case, pedantic interpretation of the C standard makes
> the comparison of such a pointer against "end" undefined, and optimizers
> from hell will happily remove as much code as possible because of this.

I am only noticing now that llvm contains a copy of OpenBSD's libc regex
code (with an llvm_ prefix to the public interfaces) in its llvmSupport
library.

I am thus surprised that one of their sanitizers did not expose that
wrong construct already. I'll report this to the llvm project tomorrow.

In the meantime, under OpenBSD, it might be worth investigating shutting
that copy and having llvm_re* aliases of libc's re* functions, if only
to make the code smaller.



Re: all platforms: isolate hardclock(9) from statclock()

2021-01-14 Thread Miod Vallat
> My understanding is that HZ=100 was a practical choice because the
> machines of the day could not reliably drive a faster clock interrupt.

The VAX architecture defines a 100Hz timer, which is the only timer you
can be sure will be available to the kernel. A few of the later models
(VAXstation 4000 comes to mind) have a so-called diagnostic timer with a
better precision.

Thus when BSD was ported to VAX, there was no choice but have HZ=100.
And when it was ported to other platforms (such as hp300), that value
was kept because there was no good reason to change it.

The value of hz became adjustable because some hardware came with clocks
which required a power-of-two divider, such as the 4.4BSD pmax port
which had HZ=64. And of course, later, alpha was architected to have a
1024Hz timer, so HZ=1024 on these systems as well.



hppa: terminate backtrace of secondary processors

2021-02-07 Thread Miod Vallat
When asking for the backtrace of a secondary processor in ddb, if that
backtrace reaches the secondary cpu startup code before the
switch_trampoline call, it will trust uninitialized stack data and is
likely to panic with an unaligned access at db_stack_trace_print+0x1d0.
(this was found the hard way by landry@ many years ago due to another
bug which got quickly fixed)

The following diff makes sure the secondary processor stack is correctly
set up to hint the backtrace code that it should not attempt to go
further.

Index: locore.S
===
RCS file: /OpenBSD/src/sys/arch/hppa/hppa/locore.S,v
retrieving revision 1.193
diff -u -p -r1.193 locore.S
--- locore.S23 Oct 2014 16:57:45 -  1.193
+++ locore.S2 Feb 2021 17:08:57 -
@@ -2970,6 +2970,9 @@ ENTRY(hw_cpu_spinup_trampoline, 0)
stw r0, HPPA_FRAME_CRP(sp)
stw r0, HPPA_FRAME_PSP(sp)
 
+   ldilL%TFF_LAST, t1
+   stw t1, TF_FLAGS-TRAPFRAME_SIZEOF(sp)
+
/* Provide CPU with page tables. */
ldilL%hppa_vtop, t1
ldw R%hppa_vtop(t1), t1



Re: occasional SSIGSEGV on C++ exception handling

2021-02-22 Thread Miod Vallat


> No problem, real-life often takes precedence.

No way! operator(7) would need an update!



harmonize maxusers on 64-bit platforms

2021-02-28 Thread Miod Vallat
The following diff causes all 64-bit platforms to use the same maxusers
settings. (which in turn affects the maxprocess, maxthread, maxfiles and
initialvnodes kernel variables)

Index: sys/arch/alpha/conf/files.alpha
===
RCS file: /OpenBSD/src/sys/arch/alpha/conf/files.alpha,v
retrieving revision 1.107
diff -u -p -r1.107 files.alpha
--- sys/arch/alpha/conf/files.alpha 14 Feb 2018 23:51:49 -  1.107
+++ sys/arch/alpha/conf/files.alpha 28 Feb 2021 17:36:45 -
@@ -6,7 +6,7 @@
 # maxpartitions must be first item in files.${ARCH}
 maxpartitions 16
 
-maxusers 2 8 128
+maxusers 2 16 128
 
 # this loses, but there's no way to define attributes which have attributes
 define alpha_shared_intr
Index: sys/arch/arm64/conf/files.arm64
===
RCS file: /OpenBSD/src/sys/arch/arm64/conf/files.arm64,v
retrieving revision 1.32
diff -u -p -r1.32 files.arm64
--- sys/arch/arm64/conf/files.arm64 25 Jul 2020 12:26:09 -  1.32
+++ sys/arch/arm64/conf/files.arm64 28 Feb 2021 17:36:45 -
@@ -1,7 +1,7 @@
 # $OpenBSD: files.arm64,v 1.32 2020/07/25 12:26:09 tobhe Exp $
 
 maxpartitions  16
-maxusers   2 8 128
+maxusers   2 16 128
 
 major  {wd = 16}
 major  {sd = 24}
Index: sys/arch/loongson/conf/GENERIC
===
RCS file: /OpenBSD/src/sys/arch/loongson/conf/GENERIC,v
retrieving revision 1.64
diff -u -p -r1.64 GENERIC
--- sys/arch/loongson/conf/GENERIC  4 Feb 2021 16:25:39 -   1.64
+++ sys/arch/loongson/conf/GENERIC  28 Feb 2021 17:36:45 -
@@ -11,7 +11,7 @@
 
 machineloongson mips64
 include"../../../conf/GENERIC"
-maxusers   32
+maxusers   80
 
 option CPU_LOONGSON2
 option CPU_LOONGSON3
Index: sys/arch/loongson/conf/files.loongson
===
RCS file: /OpenBSD/src/sys/arch/loongson/conf/files.loongson,v
retrieving revision 1.26
diff -u -p -r1.26 files.loongson
--- sys/arch/loongson/conf/files.loongson   30 Sep 2020 22:23:41 -  
1.26
+++ sys/arch/loongson/conf/files.loongson   28 Feb 2021 17:36:45 -
@@ -2,7 +2,7 @@
 
 # Standard stanzas config(8) can't run without
 maxpartitions 16
-maxusers 2 8 64
+maxusers 2 16 128
 
 # Major number for block devices, for ``root on'' lines
 major  { sd = 0 }
Index: sys/arch/octeon/conf/GENERIC
===
RCS file: /OpenBSD/src/sys/arch/octeon/conf/GENERIC,v
retrieving revision 1.58
diff -u -p -r1.58 GENERIC
--- sys/arch/octeon/conf/GENERIC4 Feb 2021 16:25:39 -   1.58
+++ sys/arch/octeon/conf/GENERIC28 Feb 2021 17:36:45 -
@@ -11,7 +11,7 @@
 
 machineocteon mips64
 include"../../../conf/GENERIC"
-maxusers   32
+maxusers   80
 
 option CPU_MIPS64R2
 option CPU_OCTEON
Index: sys/arch/octeon/conf/files.octeon
===
RCS file: /OpenBSD/src/sys/arch/octeon/conf/files.octeon,v
retrieving revision 1.58
diff -u -p -r1.58 files.octeon
--- sys/arch/octeon/conf/files.octeon   25 Oct 2020 10:31:33 -  1.58
+++ sys/arch/octeon/conf/files.octeon   28 Feb 2021 17:36:45 -
@@ -2,7 +2,7 @@
 
 # Standard stanzas config(8) can't run without
 maxpartitions 16
-maxusers 2 8 64
+maxusers 2 16 128
 
 # Major number for block devices, for ``root on'' lines
 major  { sd = 0 }
Index: sys/arch/powerpc64/conf/files.powerpc64
===
RCS file: /OpenBSD/src/sys/arch/powerpc64/conf/files.powerpc64,v
retrieving revision 1.26
diff -u -p -r1.26 files.powerpc64
--- sys/arch/powerpc64/conf/files.powerpc64 23 Jan 2021 12:10:08 -  
1.26
+++ sys/arch/powerpc64/conf/files.powerpc64 28 Feb 2021 17:36:45 -
@@ -1,7 +1,7 @@
 # $OpenBSD: files.powerpc64,v 1.26 2021/01/23 12:10:08 kettenis Exp $
 
 maxpartitions  16
-maxusers   2 8 128
+maxusers   2 16 128
 
 major  {rd = 2}
 major  {sd = 3}
Index: sys/arch/sgi/conf/GENERIC-IP22
===
RCS file: /OpenBSD/src/sys/arch/sgi/conf/GENERIC-IP22,v
retrieving revision 1.18
diff -u -p -r1.18 GENERIC-IP22
--- sys/arch/sgi/conf/GENERIC-IP22  14 Feb 2018 23:51:49 -  1.18
+++ sys/arch/sgi/conf/GENERIC-IP22  28 Feb 2021 17:36:45 -
@@ -13,7 +13,7 @@
 
 machinesgi mips64
 include"../../../conf/GENERIC"
-maxusers   32  # Estimated number of users
+maxusers   80  # Estimated number of users
 
 # Make options
 makeoption LINK_ADDRESS="0x8880"
Index: sys/arch/sgi/conf/GENERIC-IP26
===
RCS file: /OpenBSD/src/sys/arch/sgi/conf/G

safer sigcode page filling

2021-03-08 Thread Miod Vallat
The code responsible for filling a page with repeated copies of the
signal trampoline code assumes that PAGE_SIZE % sigfillsz == 0.

While this is true on all currently supported OpenBSD platforms, this
might not be the case in the future (and isn't the case on some
no-longer official platforms).

The following diff makes sure that we don't try to write more than
PAGE_SIZE bytes in this page. Another possibility would be to assert
that PAGE_SIZE % sigfillsz == 0 and only apply this diff once it becomes
truly needed.

Index: sys/kern/kern_exec.c
===
RCS file: /OpenBSD/src/sys/kern/kern_exec.c,v
retrieving revision 1.208
diff -u -p -r1.208 kern_exec.c
--- sys/kern/kern_exec.c2 Aug 2019 02:17:35 -   1.208
+++ sys/kern/kern_exec.c25 Nov 2019 10:09:48 -
@@ -832,7 +832,7 @@ exec_sigcode_map(struct process *pr, str
if (e->e_sigobject == NULL) {
extern int sigfillsiz;
extern u_char sigfill[];
-   size_t off;
+   size_t off, left;
vaddr_t va;
int r;
 
@@ -846,8 +846,12 @@ exec_sigcode_map(struct process *pr, str
return (ENOMEM);
}
 
-   for (off = 0; off < round_page(sz); off += sigfillsiz)
-   memcpy((caddr_t)va + off, sigfill, sigfillsiz);
+   for (off = 0, left = round_page(sz); left != 0;
+   off += sigfillsiz) {
+   size_t chunk = ulmin(left, sigfillsiz);
+   memcpy((caddr_t)va + off, sigfill, chunk);
+   left -= chunk;
+   }
memcpy((caddr_t)va, e->e_sigcode, sz);
uvm_unmap(kernel_map, va, va + round_page(sz));
}



Re: safer sigcode page filling

2021-03-08 Thread Miod Vallat
> I guess the rest of the page contains 0?

No, it contains a truncated copy of the sigcode.

> It would be better if it contained "trap" instructions.  We still don't
> have an ideal way of doing that tho.

That would work, but that would make the code a bit more complicated.
And I'm not sure it's worth doing anyway. Running into an unmapped page
will segfault anyway.



no ptys on ramdisk filesystems

2021-03-29 Thread Miod Vallat
A few platforms create pty nodes in /dev in the installation media
filesystem. That wastes 2x62 inodes on an tight filesystem.

The following diff removes these useless (since installation media
kernels lack the pty pseudo-device) /dev entries.

Miod

PS: while there, one might want to unify the creation of pty nodes in
the `all' target, as most platforms build one set of 62 ptys, but a few
(loongson, octeon, sgi) build three.

Index: etc.hppa/MAKEDEV.md
===
RCS file: /OpenBSD/src/etc/etc.hppa/MAKEDEV.md,v
retrieving revision 1.66
diff -u -p -r1.66 MAKEDEV.md
--- etc.hppa/MAKEDEV.md 23 Jan 2021 05:08:33 -  1.66
+++ etc.hppa/MAKEDEV.md 29 Mar 2021 20:02:02 -
@@ -85,7 +85,7 @@ divert(__mddivert)dnl
 dnl
 ramdisk)
_recurse std fd st0 st1 sd0 sd1 sd2 sd3 rd0 random
-   _recurse pty0 bpf bio diskmap
+   _recurse bpf bio diskmap
;;
 
 _std(1, 2, 25, 6)
@@ -110,5 +110,3 @@ target(all, cd, 0, 1)dnl
 target(all, sd, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)dnl
 target(all, vnd, 0, 1, 2, 3)dnl
 target(all, switch, 0, 1, 2, 3)dnl
-target(ramd, pty, 0)dnl
-target(ramd, hil)dnl
Index: etc.loongson/MAKEDEV.md
===
RCS file: /OpenBSD/src/etc/etc.loongson/MAKEDEV.md,v
retrieving revision 1.34
diff -u -p -r1.34 MAKEDEV.md
--- etc.loongson/MAKEDEV.md 12 Feb 2021 10:26:34 -  1.34
+++ etc.loongson/MAKEDEV.md 29 Mar 2021 20:02:02 -
@@ -113,7 +113,6 @@ target(all, vnd, 0, 1, 2, 3)dnl
 target(all, switch, 0, 1, 2, 3)dnl
 target(all, dri)dnl
 target(all, drm, 0, 1, 2, 3)dnl
-target(ramd, pty, 0)dnl
 target(ramd, bio)dnl
 target(ramd, diskmap)dnl
 target(ramd, random)dnl
Index: etc.luna88k/MAKEDEV.md
===
RCS file: /OpenBSD/src/etc/etc.luna88k/MAKEDEV.md,v
retrieving revision 1.35
diff -u -p -r1.35 MAKEDEV.md
--- etc.luna88k/MAKEDEV.md  6 Jul 2020 06:11:27 -   1.35
+++ etc.luna88k/MAKEDEV.md  29 Mar 2021 20:02:02 -
@@ -65,7 +65,6 @@ dnl
 dnl ramdisk)
 dnl
 twrget(ramd, sio, tty, a)dnl
-target(ramd, pty, 0)dnl
 target(ramd, bio)dnl
 target(ramd, diskmap)dnl
 target(ramd, random)dnl
Index: etc.macppc/MAKEDEV.md
===
RCS file: /OpenBSD/src/etc/etc.macppc/MAKEDEV.md,v
retrieving revision 1.77
diff -u -p -r1.77 MAKEDEV.md
--- etc.macppc/MAKEDEV.md   12 Feb 2021 10:26:34 -  1.77
+++ etc.macppc/MAKEDEV.md   29 Mar 2021 20:02:02 -
@@ -136,7 +136,6 @@ target(all, drm, 0, 1, 2, 3)dnl
 target(all, switch, 0, 1, 2, 3)dnl
 target(ramd, ttya, 0, 1)dnl
 target(ramd, ttyb, 0, 1)dnl
-target(ramd, pty, 0)dnl
 target(ramd, bio)dnl
 target(ramd, diskmap)dnl
 target(ramd, random)dnl
Index: etc.octeon/MAKEDEV.md
===
RCS file: /OpenBSD/src/etc/etc.octeon/MAKEDEV.md,v
retrieving revision 1.20
diff -u -p -r1.20 MAKEDEV.md
--- etc.octeon/MAKEDEV.md   23 Jan 2021 05:08:33 -  1.20
+++ etc.octeon/MAKEDEV.md   29 Mar 2021 20:02:02 -
@@ -116,7 +116,6 @@ target(all, sd, 0, 1, 2, 3, 4, 5, 6, 7, 
 target(all, vnd, 0, 1, 2, 3)dnl
 target(all, octcf, 0)dnl
 target(all, switch, 0, 1, 2, 3)dnl
-target(ramd, pty, 0)dnl
 target(ramd, bio)dnl
 target(ramd, diskmap)dnl
 target(ramd, random)dnl
Index: etc.sgi/MAKEDEV.md
===
RCS file: /OpenBSD/src/etc/etc.sgi/MAKEDEV.md,v
retrieving revision 1.55
diff -u -p -r1.55 MAKEDEV.md
--- etc.sgi/MAKEDEV.md  23 Jan 2021 05:08:33 -  1.55
+++ etc.sgi/MAKEDEV.md  29 Mar 2021 20:02:02 -
@@ -118,7 +118,6 @@ twrget(all, zs, tty, a, b)dnl
 twrget(wscons, wscons, ttyD, cfg, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b)dnl
 twrget(wscons, wscons, ttyE, cfg, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b)dnl
 twrget(wscons, wscons, ttyF, cfg, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b)dnl
-target(ramd, pty, 0)dnl
 target(ramd, bio)dnl
 target(ramd, diskmap)dnl
 target(ramd, random)dnl



more MAKEDEV cleanup

2021-04-05 Thread Miod Vallat
The following diff attempts to clean up a few loose ends in the current
MAKEDEV files:

- remove no-longer applicable device definitions (MSCP and SMD disks,
  this kind of thing).
- makes sure all platforms use the same `ramdisk' target for
  installation media devices, rather than a mix of `ramd' and `ramdisk'.
- moves as many `ramdisk' devices to MI land (bio, diskmap, random,
  etc).
- reduces the number of block devices in `ramdisk' targets to only one
  per device, since the installer script will invoke MAKEDEV by itself
  for the devices it needs to use.
- sort device names in `all' and `ramdisk' MI lists to make maintainence
  easier. This causes some ordering change in the `all' target in the
  generated MAKEDEVs.

Index: MAKEDEV.common
===
RCS file: /OpenBSD/src/etc/MAKEDEV.common,v
retrieving revision 1.113
diff -u -p -r1.113 MAKEDEV.common
--- MAKEDEV.common  12 Feb 2021 10:26:33 -  1.113
+++ MAKEDEV.common  5 Apr 2021 09:18:49 -
@@ -114,7 +114,7 @@ dnl make a 'disktgt' macro that automati
 dnl disktgt(rd, {-rd-})
 dnl
 dnltarget(all,rd,0)
-dnltarget(ramd,rd,0)
+dnltarget(ramdisk,rd,0)
 dnldisk_q(rd)
 dnl__devitem(rd, {-rd*-}, {-rd-})dnl
 dnl
@@ -122,62 +122,60 @@ dnl  Note: not all devices are generated
 dnlits own extra list.
 dnl
 divert(1)dnl
+target(all, acpi)dnl
+target(all, apm)dnl
+target(all, bio)dnl
+target(all, bpf)dnl
+twrget(all, com, tty0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b)dnl
+twrget(all, czs, cua, a, b, c, d)dnl
+target(all, diskmap)dnl
+target(all, dt)dnl
 twrget(all, fdesc, fd)dnl
-target(all, st, 0, 1)dnl
-target(all, std)dnl
-target(all, ra, 0, 1, 2, 3)dnl
-target(all, rx, 0, 1)dnl
-target(all, wd, 0, 1, 2, 3)dnl
-target(all, xd, 0, 1, 2, 3)dnl
+target(all, fuse)dnl
+target(all, hotplug)dnl
+target(all, joy, 0, 1)dnl
+target(all, kcov)dnl
+target(all, kstat)dnl
+target(all, local)dnl
+target(all, lpt, 0, 1, 2)dnl
+twrget(all, lpt, lpa, 0, 1, 2)dnl
+target(all, par, 0)dnl
+target(all, pci, 0, 1, 2, 3)dnl
 target(all, pctr)dnl
 target(all, pctr0)dnl
 target(all, pf)dnl
-target(all, apm)dnl
-target(all, acpi)dnl
+target(all, pppac)dnl
+target(all, pppx)dnl
+target(all, ptm)dnl
+target(all, pty, 0)dnl
+target(all, pvbus, 0, 1)dnl
+target(all, radio, 0)dnl
+target(all, rmidi, 0, 1, 2, 3, 4, 5, 6, 7)dnl
+twrget(all, rnd, random)dnl
+twrget(all, speak, speaker)dnl
+target(all, st, 0, 1)dnl
+target(all, std)dnl
+target(all, switch, 0, 1, 2, 3)dnl
+target(all, tap, 0, 1, 2, 3)dnl
 twrget(all, tth, ttyh, 0, 1)dnl
 target(all, ttyA, 0, 1)dnl
-twrget(all, mac_tty0, tty0, 0, 1)dnl
-twrget(all, tzs, tty, a, b, c, d)dnl
-twrget(all, czs, cua, a, b, c, d)dnl
 target(all, ttyc, 0, 1, 2, 3, 4, 5, 6, 7)dnl
-twrget(all, com, tty0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b)dnl
-twrget(all, mmcl, mmclock)dnl
-target(all, lpt, 0, 1, 2)dnl
-twrget(all, lpt, lpa, 0, 1, 2)dnl
-target(all, joy, 0, 1)dnl
-twrget(all, rnd, random)dnl
-target(all, uk, 0)dnl
-twrget(all, vi, video, 0, 1)dnl
-twrget(all, speak, speaker)dnl
-target(all, asc, 0)dnl
-target(all, radio, 0)dnl
+target(all, tun, 0, 1, 2, 3)dnl
 target(all, tuner, 0)dnl
-target(all, rmidi, 0, 1, 2, 3, 4, 5, 6, 7)dnl
+twrget(all, tzs, tty, a, b, c, d)dnl
 target(all, uall)dnl
-target(all, pci, 0, 1, 2, 3)dnl
-twrget(all, wsmouse, wscons)dnl
-target(all, par, 0)dnl
-target(all, apci, 0)dnl
-target(all, local)dnl
-target(all, ptm)dnl
-target(all, hotplug)dnl
-target(all, pppx)dnl
-target(all, pppac)dnl
-target(all, fuse)dnl
+target(all, uk, 0)dnl
+twrget(all, vi, video, 0, 1)dnl
 target(all, vmm)dnl
-target(all, pvbus, 0, 1)dnl
-target(all, bpf)dnl
-target(all, kcov)dnl
-target(all, dt)dnl
-target(all, kstat)dnl
+target(all, vnd, 0, 1, 2, 3)dnl
+target(all, vscsi, 0)dnl
+target(all, wd, 0, 1, 2, 3)dnl
+twrget(all, wsmouse, wscons)dnl
 dnl
 _mkdev(all, {-all-}, {-dnl
 show_target(all)dnl
 -})dnl
 dnl
-dnl XXX some arches use ramd, others ramdisk - needs to be fixed eventually
-__devitem(ramdisk, ramdisk, Ramdisk kernel devices,nothing)dnl
-dnl
 target(usb, usb, 0, 1, 2, 3, 4, 5, 6, 7)dnl
 target(usb, uhid, 0, 1, 2, 3, 4, 5, 6, 7)dnl
 twrget(usb, fido, fido)dnl
@@ -208,26 +206,26 @@ __devitem(ch, {-ch*-}, SCSI media change
 _mcdev(ch, ch*, ch, {-major_ch_c-}, 660, operator)dnl
 __devitem(uk, uk*, Unknown SCSI devices)dnl
 _mcdev(uk, uk*, uk, {-major_uk_c-}, 640, operator)dnl
-dnl XXX see ramdisk above
-__devitem(ramd, ramdisk, Ramdisk kernel devices,nothing)dnl
 dnl
-_mkdev(ramd, ramdisk, {-dnl
-show_target(ramd)dnl
+__devitem(ramdisk, ramdisk, Ramdisk kernel devices,nothing)dnl
+_mkdev(ramdisk, ramdisk, {-dnl
+show_target(ramdisk)dnl
 -})dnl
 dnl
-target(ramd, std)dnl
-target(ramd, bpf)dnl
-twrget(ramd, com, tty0, 0, 1)dnl
-target(ramd, sd, 0, 1, 2, 3, 4)dnl
-target(ramd, wd, 0, 1, 2, 3, 4)dnl
-target(ramd, st, 0, 1)dnl
-target(ramd, cd, 0, 1)dnl
-target(ramd, rd, 0)dnl
+target(ramdisk, bio)dnl
+target(ramdisk, bpf)dnl
+target(ramdisk, cd, 0)dnl

libc/yp internals mop up

2022-07-22 Thread Miod Vallat
Following the switch to ypconnect(), several fields in the dom_binding
struct used internally are no longer needed. The following diff removes
them.

Index: yp/ypinternal.h
===
RCS file: /OpenBSD/src/lib/libc/yp/ypinternal.h,v
retrieving revision 1.13
diff -u -p -r1.13 ypinternal.h
--- yp/ypinternal.h 17 Jul 2022 03:08:58 -  1.13
+++ yp/ypinternal.h 22 Jul 2022 06:43:15 -
@@ -31,14 +31,9 @@
  * yp_prot.h and yp.h.
  */
 struct dom_binding {
-   struct dom_binding *dom_pnext;
-   char dom_domain[YPMAXDOMAIN + 1];
struct sockaddr_in dom_server_addr;
-   u_short dom_server_port;
int dom_socket;
CLIENT *dom_client;
-   u_short dom_local_port;
-   long dom_vers;
 };
 
 #define BINDINGDIR "/var/yp/binding"
Index: yp/yp_first.c
===
RCS file: /OpenBSD/src/lib/libc/yp/yp_first.c,v
retrieving revision 1.11
diff -u -p -r1.11 yp_first.c
--- yp/yp_first.c   13 Sep 2015 20:57:28 -  1.11
+++ yp/yp_first.c   22 Jul 2022 06:43:15 -
@@ -69,7 +69,6 @@ again:
if (r != RPC_SUCCESS) {
if (tries++)
clnt_perror(ysd->dom_client, "yp_first: clnt_call");
-   ysd->dom_vers = -1;
goto again;
}
if (!(r = ypprot_err(yprkv.stat))) {
Index: yp/yp_maplist.c
===
RCS file: /OpenBSD/src/lib/libc/yp/yp_maplist.c,v
retrieving revision 1.9
diff -u -p -r1.9 yp_maplist.c
--- yp/yp_maplist.c 16 Jan 2015 16:48:51 -  1.9
+++ yp/yp_maplist.c 22 Jul 2022 06:43:15 -
@@ -56,7 +56,6 @@ again:
if (r != RPC_SUCCESS) {
if (tries++)
clnt_perror(ysd->dom_client, "yp_maplist: clnt_call");
-   ysd->dom_vers = -1;
goto again;
}
*outmaplist = ypml.maps;
Index: yp/yp_master.c
===
RCS file: /OpenBSD/src/lib/libc/yp/yp_master.c,v
retrieving revision 1.9
diff -u -p -r1.9 yp_master.c
--- yp/yp_master.c  16 Jan 2015 16:48:51 -  1.9
+++ yp/yp_master.c  22 Jul 2022 06:43:15 -
@@ -65,7 +65,6 @@ again:
if (r != RPC_SUCCESS) {
if (tries++)
clnt_perror(ysd->dom_client, "yp_master: clnt_call");
-   ysd->dom_vers = -1;
goto again;
}
if (!(r = ypprot_err(yprm.stat))) {
Index: yp/yp_order.c
===
RCS file: /OpenBSD/src/lib/libc/yp/yp_order.c,v
retrieving revision 1.10
diff -u -p -r1.10 yp_order.c
--- yp/yp_order.c   16 Jan 2015 16:48:51 -  1.10
+++ yp/yp_order.c   22 Jul 2022 06:43:15 -
@@ -72,7 +72,6 @@ again:
}
if (r != RPC_SUCCESS) {
clnt_perror(ysd->dom_client, "yp_order: clnt_call");
-   ysd->dom_vers = -1;
goto again;
}
*outorder = ypro.ordernum;
Index: yp/ypmatch_cache.c
===
RCS file: /OpenBSD/src/lib/libc/yp/ypmatch_cache.c,v
retrieving revision 1.17
diff -u -p -r1.17 ypmatch_cache.c
--- yp/ypmatch_cache.c  13 Sep 2015 20:57:28 -  1.17
+++ yp/ypmatch_cache.c  22 Jul 2022 06:43:15 -
@@ -187,7 +187,6 @@ again:
if (r != RPC_SUCCESS) {
if (tries++)
clnt_perror(ysd->dom_client, "yp_match: clnt_call");
-   ysd->dom_vers = -1;
goto again;
}
if (!(r = ypprot_err(yprv.stat))) {
@@ -248,7 +247,6 @@ again:
if (r != RPC_SUCCESS) {
if (tries++)
clnt_perror(ysd->dom_client, "yp_next: clnt_call");
-   ysd->dom_vers = -1;
goto again;
}
if (!(r = ypprot_err(yprkv.stat))) {



Re: mips64: trigger deferred timer interrupt from splx(9)

2022-08-09 Thread Miod Vallat
> Do those machines not have Coprocessor 0?  If they do, why would you
> prefer glxclk over CP0?

cop0 only provides one timer, from which both the scheduling clock and
statclk are derived. glxclk allows two timers to be used, and thus can
provide a more reliable statclk (see the Torek paper, etc - it is even
mentioned in the glxclk manual page).



Re: mips64: trigger deferred timer interrupt from splx(9)

2022-08-09 Thread Miod Vallat
> Other platforms (architectures?) (powerpc, powerpc64, arm64, riscv64)
> multiplex their singular interrupt clock to schedule both a
> fixed-period hardclock and a pseudorandom statclock.
> 
> This is the direction I intend to take every platform, mips64
> included, after the next release.
> 
> In that context, would there be any reason to prefer glxclk to
> CP0.count?

No. The cop0 timer is supposed to be the most reliable timer available.
(although one may argue that, on sgi, the xbow timer on some systems is
even better quality)



alpha: remove misaligned access emulation code

2022-08-09 Thread Miod Vallat
The alpha part contains code in the kernel to handle unaligned memory
accesses from userland programs, to prevent them from dying in horrible
SIGBUS.

This made sense in the '90s, but since then people have learned to work
with strict-alignment architectures, and this code has been less and
less triggered - in my own experience I don't remember seeing it
triggered in the last 20 years.

I think it's time to send it to the Attic for a well-deserved
retirement, and let these ill-behaved userland programs catch the SIGBUS
they deserve.

Index: etc/etc.alpha/sysctl.conf
===
RCS file: /OpenBSD/src/etc/etc.alpha/sysctl.conf,v
retrieving revision 1.8
diff -u -p -r1.8 sysctl.conf
--- etc/etc.alpha/sysctl.conf   2 Mar 2013 22:53:10 -   1.8
+++ etc/etc.alpha/sysctl.conf   9 Aug 2022 06:16:34 -
@@ -1,5 +1,2 @@
-#machdep.unaligned_print=0 # 0 - disable printing of unaligned access
-#machdep.unaligned_fix=0   # 0 - disable fixup of unaligned access
-#machdep.unaligned_sigbus=0# 0 - don't sigbus on unaligned access
 #machdep.allowaperture=1   # see xf86(4)
 #machdep.led_blink=1   # blink chassis leds on DEC 3000
Index: sys/arch/alpha/alpha/machdep.c
===
RCS file: /OpenBSD/src/sys/arch/alpha/alpha/machdep.c,v
retrieving revision 1.196
diff -u -p -r1.196 machdep.c
--- sys/arch/alpha/alpha/machdep.c  6 Oct 2021 15:46:03 -   1.196
+++ sys/arch/alpha/alpha/machdep.c  9 Aug 2022 06:16:34 -
@@ -180,9 +180,6 @@ u_int8_tdec_3000_scsiid[2], dec_3000_sc
 struct platform platform;
 
 /* for cpu_sysctl() */
-intalpha_unaligned_print = 1;  /* warn about unaligned accesses */
-intalpha_unaligned_fix = 1;/* fix up unaligned accesses */
-intalpha_unaligned_sigbus = 1; /* SIGBUS on fixed-up accesses */
 #ifndef NO_IEEE
 intalpha_fp_sync_complete = 0; /* fp fixup if sync even without /s */
 #endif
@@ -1555,18 +1552,6 @@ cpu_sysctl(int *name, u_int namelen, voi
sizeof consdev));
 
 #ifndef SMALL_KERNEL
-   case CPU_UNALIGNED_PRINT:
-   return (sysctl_int(oldp, oldlenp, newp, newlen,
-   &alpha_unaligned_print));
-
-   case CPU_UNALIGNED_FIX:
-   return (sysctl_int(oldp, oldlenp, newp, newlen,
-   &alpha_unaligned_fix));
-
-   case CPU_UNALIGNED_SIGBUS:
-   return (sysctl_int(oldp, oldlenp, newp, newlen,
-   &alpha_unaligned_sigbus));
-
case CPU_BOOTED_KERNEL:
return (sysctl_rdstring(oldp, oldlenp, newp,
bootinfo.booted_kernel));
Index: sys/arch/alpha/alpha/trap.c
===
RCS file: /OpenBSD/src/sys/arch/alpha/alpha/trap.c,v
retrieving revision 1.100
diff -u -p -r1.100 trap.c
--- sys/arch/alpha/alpha/trap.c 9 Dec 2021 00:26:11 -   1.100
+++ sys/arch/alpha/alpha/trap.c 9 Aug 2022 06:16:35 -
@@ -110,21 +110,6 @@
 #endif
 #include 
 
-#ifndef SMALL_KERNEL
-
-unsigned long  Sfloat_to_reg(unsigned int);
-unsigned int   reg_to_Sfloat(unsigned long);
-unsigned long  Tfloat_reg_cvt(unsigned long);
-#ifdef FIX_UNALIGNED_VAX_FP
-unsigned long  Ffloat_to_reg(unsigned int);
-unsigned int   reg_to_Ffloat(unsigned long);
-unsigned long  Gfloat_reg_cvt(unsigned long);
-#endif
-
-intunaligned_fixup(unsigned long, unsigned long,
-   unsigned long, struct proc *);
-#endif /* SMALL_KERNEL */
-
 inthandle_opdec(struct proc *p, u_int64_t *ucodep);
 
 #ifndef NO_IEEE
@@ -249,19 +234,10 @@ trap(a0, a1, a2, entry, framep)
switch (entry) {
case ALPHA_KENTRY_UNA:
/*
-* If user-land, do whatever fixups, printing, and
-* signalling is appropriate (based on system-wide
-* and per-process unaligned-access-handling flags).
+* If user-land, deliver SIGBUS unconditionally.
 */
if (user) {
-#ifndef SMALL_KERNEL
-   KERNEL_LOCK();
-   i = unaligned_fixup(a0, a1, a2, p);
-   KERNEL_UNLOCK();
-   if (i == 0)
-   goto out;
-#endif
-
+   i = SIGBUS;
ucode = ILL_ILLADR;
v = (caddr_t)a0;
break;
@@ -716,11 +692,6 @@ ast(framep)
userret(p);
 }
 
-/*
- * Unaligned access handler.  It's not clear that this can get much slower...
- *
- */
-
 const static int reg_to_framereg[32] = {
FRAME_V0,   FRAME_T0,   FRAME_T1,   FRAME_T2,
FRAME_T3,   FRAME_T4,   FRAME_T5,   FRAME_T6,
@@ -736,356 +707,6 @@ const static int reg_to_framereg[32] = {
((reg_to_framereg[(reg)] == -1) ? NULL :\
&(p)->p_m

Re: Race in disk_attach_callback?

2022-08-16 Thread Miod Vallat
> after a prompt from stsp@ and florian@, reporting that newfs_msdos
> fails when given an $duid.i argument, I set down to see what could be
> going on. My test using an USB stick failed to reprdouce the problem.
> Then I started using a vnd, and that shows the issue (once in a
> while). The feeling is that any disk devcied created on the fly might
> show this issue.

Moments ago kn@ stumbled upon this as well.

It turns out that, at least in the vnd case, there is indeed a race
between the scheduling of the task running disk_attach_callback and the
first access to the vnd device, which will cause the label to get read.

While vnd(4) has logic to read a label on-demand, disk_attach_callback
assumes it runs at a point where the label can safely be obtained, and
will not retry (because it sets DKF_OPENED, which never gets unset).

The following shell script will demonstrate the issue:

cat << EOF > test.sh
#! /bin/sh
set -e

dd if=/dev/zero of=img.bin bs=1m count=4 >/dev/null
iter=1
while [ $iter -lt 1000 ]; do
vnconfig vnd0 img.bin
fdisk -iy vnd0 > /dev/null
disklabel -Aw vnd0 > /dev/null
duid=$(sysctl hw.disknames|sed 's,.*vnd0:,,')
disklabel $duid > /dev/null
vnconfig -u vnd0
iter=$((iter + 1))
done
EOF

(don't forget to vnconfig -u vnd0 if it fails).

The following diff makes vnd attempt to read a label as soon as the
VNDIOCSET ioctl is issued. However it will not fix softraid if it has a
similar problem, so a rework of the disk_attach operation might be a
better idea.

Index: vnd.c
===
RCS file: /OpenBSD/src/sys/dev/vnd.c,v
retrieving revision 1.177
diff -u -p -r1.177 vnd.c
--- vnd.c   23 Dec 2021 10:09:16 -  1.177
+++ vnd.c   16 Aug 2022 21:02:23 -
@@ -536,6 +536,9 @@ fail:
sc->sc_dk.dk_name = sc->sc_dev.dv_xname;
disk_attach(&sc->sc_dev, &sc->sc_dk);
 
+   sc->sc_flags |= VNF_HAVELABEL;
+   vndgetdisklabel(dev, sc, sc->sc_dk.dk_label, 0);
+
disk_unlock(&sc->sc_dk);
 
break;



Re: Race in disk_attach_callback?

2022-08-16 Thread Miod Vallat
Come to think further about it, I think it is better for diskmap to
always trust disk drivers to either :
- not have any label (dk_label == NULL, or points to zeroed memory)
or
- have a valid label (duid is not zeroes).

The following diff thus relaxes the logic to always trust
dk_label->d_uid, unless it is zero. This passes the vnd test I mailed
yesterday, without the need for a dev/vnd.c change.

Index: sys/dev/softraid.c
===
RCS file: /OpenBSD/src/sys/dev/softraid.c,v
retrieving revision 1.425
diff -u -p -u -p -r1.425 softraid.c
--- sys/dev/softraid.c  16 Apr 2022 19:19:58 -  1.425
+++ sys/dev/softraid.c  17 Aug 2022 05:20:51 -
@@ -3685,13 +3685,11 @@ sr_ioctl_installboot(struct sr_softc *sc
}
}
 
-   bzero(duid, sizeof(duid));
TAILQ_FOREACH(dk, &disklist,  dk_link)
if (!strncmp(dk->dk_name, bb->bb_dev, sizeof(bb->bb_dev)))
break;
if (dk == NULL || dk->dk_label == NULL ||
-   (dk->dk_flags & DKF_LABELVALID) == 0 ||
-   bcmp(dk->dk_label->d_uid, &duid, sizeof(duid)) == 0) {
+   duid_iszero(dk->dk_label->d_uid)) {
sr_error(sc, "failed to get DUID for softraid volume");
goto done;
}
Index: sys/kern/subr_disk.c
===
RCS file: /OpenBSD/src/sys/kern/subr_disk.c,v
retrieving revision 1.253
diff -u -p -u -p -r1.253 subr_disk.c
--- sys/kern/subr_disk.c14 Aug 2022 01:58:27 -  1.253
+++ sys/kern/subr_disk.c17 Aug 2022 05:20:51 -
@@ -1121,7 +1121,6 @@ disk_attach_callback(void *xdat)
/* Read disklabel. */
if (disk_readlabel(&dl, dk->dk_devno, errbuf, sizeof(errbuf)) == NULL) {
enqueue_randomness(dl.d_checksum);
-   dk->dk_flags |= DKF_LABELVALID;
}
 
 done:
@@ -1440,14 +1439,14 @@ setroot(struct device *bootdv, int part,
TAILQ_FOREACH(dk, &disklist, dk_link)
if (dk->dk_device == bootdv)
break;
-   if (dk && (dk->dk_flags & DKF_LABELVALID))
+   if (dk)
bcopy(dk->dk_label->d_uid, bootduid, sizeof(bootduid));
} else if (bootdv == NULL) {
/* Locate boot disk based on the provided DUID. */
TAILQ_FOREACH(dk, &disklist, dk_link)
if (duid_equal(dk->dk_label->d_uid, bootduid))
break;
-   if (dk && (dk->dk_flags & DKF_LABELVALID))
+   if (dk)
bootdv = dk->dk_device;
}
bcopy(bootduid, rootduid, sizeof(rootduid));
@@ -1561,8 +1560,7 @@ gotswap:
if (bootdv->dv_class == DV_DISK) {
if (!duid_iszero(rootduid)) {
TAILQ_FOREACH(dk, &disklist, dk_link)
-   if ((dk->dk_flags & DKF_LABELVALID) &&
-   dk->dk_label && duid_equal(
+   if (dk->dk_label && duid_equal(
dk->dk_label->d_uid, rootduid))
break;
if (dk == NULL)
@@ -1788,7 +1786,8 @@ disk_map(char *path, char *mappath, int 
 
mdk = NULL;
TAILQ_FOREACH(dk, &disklist, dk_link) {
-   if ((dk->dk_flags & DKF_LABELVALID) && dk->dk_label &&
+   if (dk->dk_label &&
+   !duid_iszero(dk->dk_label->d_uid) &&
memcmp(dk->dk_label->d_uid, uid,
sizeof(dk->dk_label->d_uid)) == 0) {
/* Fail if there are duplicate UIDs! */
Index: sys/sys/disk.h
===
RCS file: /OpenBSD/src/sys/sys/disk.h,v
retrieving revision 1.36
diff -u -p -u -p -r1.36 disk.h
--- sys/sys/disk.h  4 May 2017 22:47:27 -   1.36
+++ sys/sys/disk.h  17 Aug 2022 05:20:51 -
@@ -83,7 +83,6 @@ struct disk {
 #define DKF_CONSTRUCTED0x0001
 #define DKF_OPENED 0x0002
 #define DKF_NOLABELREAD0x0004
-#define DKF_LABELVALID 0x0008
 
/*
 * Metrics data; note that some metrics may have no meaning



Re: Race in disk_attach_callback?

2022-08-17 Thread Miod Vallat
> What is the result if root runs disklabel, and forces it to all zeros?

If the root duid is all zeroes, then the only way to refer to the root
disk is to use its /dev/{s,w}d* device name, as zero duids are ignored.

If you set a zero duid in disklabel(8), setdisklabel() in the kernel
will compute a new, non-zero value.



Re: mips64: trigger deferred timer interrupt from splx(9)

2022-08-18 Thread Miod Vallat
> After about 92 hours, one machine showed cp0_raise_calls=622486 and
> another 695892. cp0_raise_miss was zero on both of them. On two other
> machines I had forgotten to allow ddb access from console and could
> not check the values.

Put kern.allowkmem=1 in /etc/sysctl.conf, and then you can do fetch the
values with pstat -d.



Re: installer: zap fdisk.8.gz and disklabel.8.gz

2022-08-25 Thread Miod Vallat
> Well, something tells me the inclusion of the manual pages for fdisk
> and disklabel is deliberate.  Makes some sense as these are complex
> utilities and their interactive use is documented in those pages.

The ability to be able to read the manual pages from the binaries
themselves, when running is interactive mode, is an intentional feature
and the reason they embed a gzipped version of the formatted manpage.



Re: installer: zap fdisk.8.gz and disklabel.8.gz

2022-08-25 Thread Miod Vallat
> > The ability to be able to read the manual pages from the binaries
> > themselves, when running is interactive mode, is an intentional feature
> > and the reason they embed a gzipped version of the formatted manpage.
> 
> Even in the installer?

Especially in the installer, because you might not have another machine
nearby to access documentation. (and there were no smartphones when this
was introduced close to 25 years ago)

> The manual feature is handy, but I don't think it's worth having in
> install media.

This feature is *especially* intended for installation media.



Re: Race in disk_attach_callback?

2022-08-29 Thread Miod Vallat
> What's the status on this diff?

I'm waiting for review from at least one of the softraid suspects prior
to putting this in, in case there are further cinematics to address.



Re: all architectures: put clockframe definition in frame.h?

2022-08-30 Thread Miod Vallat
> So we would get rid of all the 32-bit compat stuff from arch/sparc64?

Yes, but this has never been used, so no worries about it.

> Index: include/cpu.h
> ===
> RCS file: /cvs/src/sys/arch/sparc64/include/cpu.h,v
> retrieving revision 1.98
> diff -u -p -r1.98 cpu.h
> --- include/cpu.h 6 Jul 2021 09:34:07 -   1.98
> +++ include/cpu.h 29 Aug 2022 18:44:50 -
> @@ -144,7 +144,7 @@ struct cpu_info {
>   paddr_t ci_paddr;   /* Phys addr of this structure. 
> */
>  
>  #ifdef SUN4V
> - struct rwindow64ci_rw;
> + struct rwindow  ci_rw;

Note that struct rwindow* used to be defined in ; if you
move it to  then cpu.h needs to include it now. And
since  also gets included from assembler code, the struct
definitions you have moved there need to be protected with #ifndef
_LOCORE.


> Index: sparc64/machdep.c

> @@ -872,36 +872,24 @@ trapdump(tf)
>  void
>  stackdump(void)
>  {
> - struct frame32 *fp = (struct frame32 *)getfp(), *sfp;
> - struct frame64 *fp64;
> + struct frame *fp64 = getfp(), *sfp;
>  
> - sfp = fp;
> - printf("Frame pointer is at %p\n", fp);
> + sfp = fp64;
> + printf("Frame pointer is at %p\n", fp64);
>   printf("Call traceback:\n");
> - while (fp && ((u_long)fp >> PGSHIFT) == ((u_long)sfp >> PGSHIFT)) {
> - if( ((long)fp) & 1 ) {
> - fp64 = (struct frame64*)(((char *)fp)+BIAS);
> - /* 64-bit frame */
> - printf("%llx(%llx, %llx, %llx, %llx, %llx, %llx, %llx) "
> - "fp = %llx\n",
> -(unsigned long long)fp64->fr_pc,
> -(unsigned long long)fp64->fr_arg[0],
> -(unsigned long long)fp64->fr_arg[1],
> -(unsigned long long)fp64->fr_arg[2],
> -(unsigned long long)fp64->fr_arg[3],
> -(unsigned long long)fp64->fr_arg[4],
> -(unsigned long long)fp64->fr_arg[5], 
> -(unsigned long long)fp64->fr_arg[6],
> -(unsigned long long)fp64->fr_fp);
> - fp = (struct frame32 *)(u_long)fp64->fr_fp;
> - } else {
> - /* 32-bit frame */
> - printf("  pc = %x  args = (%x, %x, %x, %x, %x, %x) "
> - "fp = %x\n", fp->fr_pc, fp->fr_arg[0],
> - fp->fr_arg[1], fp->fr_arg[2], fp->fr_arg[3],
> - fp->fr_arg[4], fp->fr_arg[5], fp->fr_fp);
> - fp = (struct frame32*)(u_long)(u_short)fp->fr_fp;
> - }
> + while (fp64 && ((u_long)fp64 >> PGSHIFT) == ((u_long)sfp >> PGSHIFT)) {
> + printf("%llx(%llx, %llx, %llx, %llx, %llx, %llx, %llx) "
> + "fp = %llx\n",
> +(unsigned long long)fp64->fr_pc,
> +(unsigned long long)fp64->fr_arg[0],
> +(unsigned long long)fp64->fr_arg[1],
> +(unsigned long long)fp64->fr_arg[2],
> +(unsigned long long)fp64->fr_arg[3],
> +(unsigned long long)fp64->fr_arg[4],
> +(unsigned long long)fp64->fr_arg[5], 
> +(unsigned long long)fp64->fr_arg[6],
> +(unsigned long long)fp64->fr_fp);
> + fp64 = v9next_frame(fp64);

This chunk is wrong. The 64-bit stack pointer is always odd (biased by
BIAS), so you need add something similar to
fp64 = (struct frame*)(((char *)fp64) + BIAS);
prior to the printf call. Also the next statement is incorrectly
indented.

Last, the removal of CCFSZ exposes a bug in locore.S where it is still
used instead of CC64FSZ (in an "everything went wrong" shouldn't-happen
scenario), so it should be replaced in there.



libelf: disable ident strings

2022-08-31 Thread Miod Vallat
The general policy in OpenBSD is to not embed ident(1) strings in
libraries. However, libelf is currently compiled with ident strings, and
thus /usr/lib/libelf* are the only files in /usr/lib sporting ident
strings.

The following diff disables them.

Index: _elftc.h
===
RCS file: /OpenBSD/src/lib/libelf/_elftc.h,v
retrieving revision 1.2
diff -u -p -r1.2 _elftc.h
--- _elftc.h2 Sep 2021 21:12:09 -   1.2
+++ _elftc.h31 Aug 2022 18:55:31 -
@@ -316,11 +316,7 @@ struct name {  
\
 #endif
 
 #if defined(__OpenBSD__)
-#if defined(__GNUC__)
-#defineELFTC_VCSID(ID) __asm__(".ident\t\"" ID "\"")
-#else
-#defineELFTC_VCSID(ID) /**/
-#endif /* __GNUC__ */
+#defineELFTC_VCSID(ID) /* intentionally disabled */
 #endif
 
 #endif /* ELFTC_VCSID */



some more kernel const

2022-09-02 Thread Miod Vallat
Constify nam2blk[] and chrtoblktbl[], these are never modified at
runtime. Plus an octeon bonus: devmap[].

Index: sys/arch/alpha/alpha/autoconf.c
===
RCS file: /OpenBSD/src/sys/arch/alpha/alpha/autoconf.c,v
retrieving revision 1.38
diff -u -p -u -p -r1.38 autoconf.c
--- sys/arch/alpha/alpha/autoconf.c 27 Jan 2018 22:55:23 -  1.38
+++ sys/arch/alpha/alpha/autoconf.c 2 Sep 2022 14:39:45 -
@@ -220,7 +220,7 @@ device_register(dev, aux)
(*platform.device_register)(dev, aux);
 }
 
-struct nam2blk nam2blk[] = {
+const struct nam2blk nam2blk[] = {
{ "wd", 0 },
{ "cd", 3 },
{ "fd", 4 },
Index: sys/arch/alpha/alpha/conf.c
===
RCS file: /OpenBSD/src/sys/arch/alpha/alpha/conf.c,v
retrieving revision 1.90
diff -u -p -u -p -r1.90 conf.c
--- sys/arch/alpha/alpha/conf.c 11 Nov 2021 10:03:08 -  1.90
+++ sys/arch/alpha/alpha/conf.c 2 Sep 2022 14:39:45 -
@@ -252,7 +252,7 @@ getnulldev()
return makedev(mem_no, 2);
 }
 
-int chrtoblktbl[] = {
+const int chrtoblktbl[] = {
/*VCHR*//*VBLK*/
/*  0 */NODEV,
/*  1 */NODEV,
@@ -293,4 +293,4 @@ int chrtoblktbl[] = {
/* 36 */0,
/* 37 */4,  /* fd */
 };
-int nchrtoblktbl = nitems(chrtoblktbl);
+const int nchrtoblktbl = nitems(chrtoblktbl);
Index: sys/arch/amd64/amd64/autoconf.c
===
RCS file: /OpenBSD/src/sys/arch/amd64/amd64/autoconf.c,v
retrieving revision 1.53
diff -u -p -u -p -r1.53 autoconf.c
--- sys/arch/amd64/amd64/autoconf.c 11 Jan 2019 06:25:06 -  1.53
+++ sys/arch/amd64/amd64/autoconf.c 2 Sep 2022 14:39:45 -
@@ -223,7 +223,7 @@ diskconf(void)
 #endif /* HIBERNATE */
 }
 
-struct nam2blk nam2blk[] = {
+const struct nam2blk nam2blk[] = {
{ "wd", 0 },
{ "fd", 2 },
{ "sd", 4 },
Index: sys/arch/amd64/amd64/conf.c
===
RCS file: /OpenBSD/src/sys/arch/amd64/amd64/conf.c,v
retrieving revision 1.75
diff -u -p -u -p -r1.75 conf.c
--- sys/arch/amd64/amd64/conf.c 28 Jun 2022 14:43:50 -  1.75
+++ sys/arch/amd64/amd64/conf.c 2 Sep 2022 14:39:45 -
@@ -331,7 +331,7 @@ getnulldev(void)
return makedev(mem_no, 2);
 }
 
-int chrtoblktbl[] = {
+const int chrtoblktbl[] = {
/*VCHR*//*VBLK*/
/*  0 */NODEV,
/*  1 */NODEV,
@@ -383,7 +383,7 @@ int chrtoblktbl[] = {
/* 47 */17, /* rd */
 };
 
-int nchrtoblktbl = nitems(chrtoblktbl);
+const int nchrtoblktbl = nitems(chrtoblktbl);
 
 /*
  * In order to map BSD bdev numbers of disks to their BIOS equivalents
Index: sys/arch/arm/arm/conf.c
===
RCS file: /OpenBSD/src/sys/arch/arm/arm/conf.c,v
retrieving revision 1.58
diff -u -p -u -p -r1.58 conf.c
--- sys/arch/arm/arm/conf.c 11 Nov 2021 10:03:08 -  1.58
+++ sys/arch/arm/arm/conf.c 2 Sep 2022 14:39:45 -
@@ -415,7 +415,7 @@ iszerodev(dev_t dev)
 }
 
 
-int chrtoblktbl[] = {
+const int chrtoblktbl[] = {
 /*VCHR*//*VBLK*/
 /*  0 */NODEV,
 /*  1 */NODEV,
@@ -445,7 +445,7 @@ int chrtoblktbl[] = {
 /* 25 */NODEV,
 /* 26 */26,/* cd */
 };
-int nchrtoblktbl = nitems(chrtoblktbl);
+const int nchrtoblktbl = nitems(chrtoblktbl);
 
 dev_t
 getnulldev(void)
Index: sys/arch/arm64/arm64/autoconf.c
===
RCS file: /OpenBSD/src/sys/arch/arm64/arm64/autoconf.c,v
retrieving revision 1.12
diff -u -p -u -p -r1.12 autoconf.c
--- sys/arch/arm64/arm64/autoconf.c 21 Feb 2021 14:55:16 -  1.12
+++ sys/arch/arm64/arm64/autoconf.c 2 Sep 2022 14:39:45 -
@@ -109,7 +109,7 @@ device_register(struct device *dev, void
 {
 }
 
-struct nam2blk nam2blk[] = {
+const struct nam2blk nam2blk[] = {
{ "wd",  0 },
{ "sd",  4 },
{ "cd",  6 },
Index: sys/arch/arm64/arm64/conf.c
===
RCS file: /OpenBSD/src/sys/arch/arm64/arm64/conf.c,v
retrieving revision 1.19
diff -u -p -u -p -r1.19 conf.c
--- sys/arch/arm64/arm64/conf.c 11 Nov 2021 10:03:08 -  1.19
+++ sys/arch/arm64/arm64/conf.c 2 Sep 2022 14:39:45 -
@@ -273,7 +273,7 @@ getnulldev(void)
return makedev(CMAJ_MM, 2);
 }
 
-int chrtoblktbl[] = {
+const int chrtoblktbl[] = {
/*VCHR*//*VBLK*/
/*  0 */NODEV,
/*  1 */NODEV,
@@ -325,7 +325,7 @@ int chrtoblktbl[] = {
/* 47 */17, /* rd */
 };
 
-int nchrtoblktbl = nitems(chrtoblktbl);
+const int nchrtoblktbl = nitems(chrt

pmap_collect and the page daemon

2022-09-10 Thread Miod Vallat
When the kernel is low on memory, the pagedaemon thread will try various
strategies to free memory.

One of those is to ask the pmap layer to free some memory. This is done
in uvm_swapout_threads(), which is roughly a wrapper around the
invocation of pmap_collect() on behalf of all processes.

However, most pmap layers do not implement pmap_collect() and only
provide a stub which does nothing. It doesn't make much sense to iterate
over the process list, only to invoke a function which does absolutely
nothing.

The following diff makes pmap_collect() an optional interface, with
pmaps implementing it defining __HAVE_PMAP_COLLECT. This feature macro
is used to completely omit uvm_swapout_threads() when pmap_collect() is
not available.

Index: arch/alpha/include/pmap.h
===
RCS file: /OpenBSD/src/sys/arch/alpha/include/pmap.h,v
retrieving revision 1.40
diff -u -p -r1.40 pmap.h
--- arch/alpha/include/pmap.h   20 Apr 2016 05:24:18 -  1.40
+++ arch/alpha/include/pmap.h   10 Sep 2022 08:00:10 -
@@ -197,6 +197,8 @@ extern  pt_entry_t *VPT;/* Virtual Page
 
 paddr_t vtophys(vaddr_t);
 
+#define__HAVE_PMAP_COLLECT
+
 /* Machine-specific functions. */
 void   pmap_bootstrap(paddr_t ptaddr, u_int maxasn, u_long ncpuids);
 intpmap_emulate_reference(struct proc *p, vaddr_t v, int user, int type);
Index: arch/amd64/amd64/pmap.c
===
RCS file: /OpenBSD/src/sys/arch/amd64/amd64/pmap.c,v
retrieving revision 1.153
diff -u -p -r1.153 pmap.c
--- arch/amd64/amd64/pmap.c 30 Jun 2022 13:51:24 -  1.153
+++ arch/amd64/amd64/pmap.c 10 Sep 2022 08:00:10 -
@@ -2206,6 +2206,7 @@ pmap_unwire(struct pmap *pmap, vaddr_t v
 #endif
 }
 
+#if 0
 /*
  * pmap_collect: free resources held by a pmap
  *
@@ -2221,10 +,10 @@ pmap_collect(struct pmap *pmap)
 * for its entire address space.
 */
 
-/* pmap_do_remove(pmap, VM_MIN_ADDRESS, VM_MAX_ADDRESS,
+   pmap_do_remove(pmap, VM_MIN_ADDRESS, VM_MAX_ADDRESS,
PMAP_REMOVE_SKIPWIRED);
-*/
 }
+#endif
 
 /*
  * pmap_copy: copy mappings from one pmap to another
Index: arch/arm/arm/pmap7.c
===
RCS file: /OpenBSD/src/sys/arch/arm/arm/pmap7.c,v
retrieving revision 1.63
diff -u -p -r1.63 pmap7.c
--- arch/arm/arm/pmap7.c21 Feb 2022 19:15:58 -  1.63
+++ arch/arm/arm/pmap7.c10 Sep 2022 08:00:10 -
@@ -1743,21 +1743,6 @@ dab_access(trapframe_t *tf, u_int fsr, u
 }
 
 /*
- * pmap_collect: free resources held by a pmap
- *
- * => optional function.
- * => called when a process is swapped out to free memory.
- */
-void
-pmap_collect(pmap_t pm)
-{
-   /*
-* Nothing to do.
-* We don't even need to free-up the process' L1.
-*/
-}
-
-/*
  * Routine:pmap_proc_iflush
  *
  * Function:
Index: arch/arm64/arm64/pmap.c
===
RCS file: /OpenBSD/src/sys/arch/arm64/arm64/pmap.c,v
retrieving revision 1.84
diff -u -p -r1.84 pmap.c
--- arch/arm64/arm64/pmap.c 10 Jan 2022 09:20:27 -  1.84
+++ arch/arm64/arm64/pmap.c 10 Sep 2022 08:00:10 -
@@ -856,24 +856,6 @@ pmap_fill_pte(pmap_t pm, vaddr_t va, pad
 }
 
 /*
- * Garbage collects the physical map system for pages which are
- * no longer used. Success need not be guaranteed -- that is, there
- * may well be pages which are not referenced, but others may be collected
- * Called by the pageout daemon when pages are scarce.
- */
-void
-pmap_collect(pmap_t pm)
-{
-   /* This could return unused v->p table layers which
-* are empty.
-* could malicious programs allocate memory and eat
-* these wired pages? These are allocated via pool.
-* Are there pool functions which could be called
-* to lower the pool usage here?
-*/
-}
-
-/*
  * Fill the given physical page with zeros.
  */
 void
Index: arch/hppa/hppa/pmap.c
===
RCS file: /OpenBSD/src/sys/arch/hppa/hppa/pmap.c,v
retrieving revision 1.177
diff -u -p -r1.177 pmap.c
--- arch/hppa/hppa/pmap.c   14 Sep 2021 16:16:51 -  1.177
+++ arch/hppa/hppa/pmap.c   10 Sep 2022 08:00:10 -
@@ -734,13 +734,6 @@ pmap_reference(struct pmap *pmap)
atomic_inc_int(&pmap->pm_obj.uo_refs);
 }
 
-void
-pmap_collect(struct pmap *pmap)
-{
-   DPRINTF(PDB_FOLLOW|PDB_PMAP, ("pmap_collect(%p)\n", pmap));
-   /* nothing yet */
-}
-
 int
 pmap_enter(struct pmap *pmap, vaddr_t va, paddr_t pa, vm_prot_t prot, int 
flags)
 {
Index: arch/hppa/include/param.h
===
RCS file: /OpenBSD/src/sys/arch/hppa/include/param.h,v
retrieving revision 1.47
diff -u -p -r1.47 param.h
--- arch/hppa/include/param.h   14 Sep 2018 13:58:20 -  1.47
+++

Re: apldckbd(4): add fn key combose for Page Up/Down

2022-09-14 Thread Miod Vallat
> Hey,
> 
> the diff below adds FN key combos for Page Up, Page Down and some more
> on the M2 keyboard.  Most of the logic was copied from ukbd.

This means most of the munging logic should move from ukbd into hidkbd,
but that can be done later.

If you don't want to do this yet, you need to address two points:
- the result of the hid_locate() call should be checked.
- because of this, invocation of apldckbd_munge() should only happen if
  that call had succeeded.



Re: apldckbd(4): add fn key combose for Page Up/Down

2022-09-16 Thread Miod Vallat
> Index: dev/hid/hidkbdtrans.h

> +static const struct hidkbd_translation apple_fn_trans[] = {

No effing way. Every file including this header will embed its own copy
of these tables.

Better keep the tables in their original locations. The munge interfaces
already take a pointer to a table and its number of elements, there is
no need to gather all these tables in one particular location.



Re: apldckbd(4): add fn key combose for Page Up/Down

2022-09-16 Thread Miod Vallat
> On 16/09/22 12:20 +0000, Miod Vallat wrote:
> > > Index: dev/hid/hidkbdtrans.h
> > 
> > > +static const struct hidkbd_translation apple_fn_trans[] = {
> > 
> > No effing way. Every file including this header will embed its own copy
> > of these tables.
> > 
> > Better keep the tables in their original locations. The munge interfaces
> > already take a pointer to a table and its number of elements, there is
> > no need to gather all these tables in one particular location.
> 
> yeah was quiet stupid of me.. new diff here. i've also put the whole
> thing inside !SMALL_KERNEL

That's better.

However:
- I see no reason for this to be wrapped within !SMALL_KERNEL, having a
  working keyboard within the installer is always a good thing.
- there is also no reason to move the Gdium-specific (loongson) bits
  away from ukbd.c. They will never appear on any other kind of
  keyboard. As long as there is a prototype for hidkbd_translate()
  somewhere, it will keep working.



Re: apldckbd(4): add fn key combose for Page Up/Down

2022-09-16 Thread Miod Vallat
> rev3:

Almost there! Minor nits below, then ok.

> Index: dev/hid/hidkbd.c

> +static const struct hidkbd_translation apple_iso_trans[] = {
> + { 53, 100 },/* less -> grave */
> + { 100, 53 }
> +};
> +
> +static const struct hidkbd_translation apple_iso_mba_trans[] = {
> + { 53, 100 },/* less -> grave */
> + { 100, 53 }
> +};

No need for two copies of that table. Keep the first one (shortest
name) and update hidkbd_apple_mba_munge() accordingly.

> Index: dev/hid/hidkbdsc.h

> @@ -67,6 +67,7 @@ struct hidkbd {
>   struct hid_location sc_capsloc;
>   struct hid_location sc_scroloc;
>   struct hid_location sc_compose;
> + struct hid_location sc_fn;

Since the name is generic, consider adding a comment, for example
/* optional extra input source used by sc_munge below */



Re: apldckbd(4): add fn key combose for Page Up/Down

2022-09-16 Thread Miod Vallat
> I've also removed the hidkbd_apple_mba_iso_munge() function as it is
> the same as hidkbd_apple_iso_munge() so this also cleans up the switch
> in ukbd.c

Oh no, it isn't.

See, you are in a maze of twisty little functions, all alike.

The current state of ukbd has four apple munge routines:

- "apple": invoke hid_get_data to get extra keys, then applies table
- "apple_mba": invoke hid_get_data to get extra keys, then applies a
  different table
- "apple_iso": applies small iso table, then invokes "apple" munge
- "apple_iso_mba": applies small iso table, then invokes "apple_mba"
  munge.

Because the tables used by "apple" and "apple_mba" differ, their iso
flavours need to be kept separate.



Re: Fwd: ukbd.c diff

2022-10-04 Thread Miod Vallat
> Found that the reason is that 'sc_apple_fn' inside 'ukbd_softc' is not
> being assigned to
> newly created 'sc_fn' inside 'hidkbd'

Argh, sorry about that.

Does the following diff fix the problem on your machine?

Index: ukbd.c
===
RCS file: /OpenBSD/src/sys/dev/usb/ukbd.c,v
retrieving revision 1.87
diff -u -p -r1.87 ukbd.c
--- ukbd.c  16 Sep 2022 16:30:10 -  1.87
+++ ukbd.c  4 Oct 2022 18:27:49 -
@@ -131,7 +131,6 @@ struct ukbd_softc {
 
struct hidkbd   sc_kbd;
int sc_spl;
-   struct hid_location sc_apple_fn;
 
 #ifdef DDB
struct timeout  sc_ddb; /* for entering DDB */
@@ -242,7 +241,7 @@ ukbd_attach(struct device *parent, struc
 
if (uha->uaa->vendor == USB_VENDOR_APPLE) {
if (hid_locate(desc, dlen, HID_USAGE2(HUP_APPLE, HUG_FN_KEY),
-   uha->reportid, hid_input, &sc->sc_apple_fn, &qflags)) {
+   uha->reportid, hid_input, &kbd->sc_fn, &qflags)) {
if (qflags & HIO_VARIABLE) {
switch (uha->uaa->product) {
case USB_PRODUCT_APPLE_FOUNTAIN_ISO:



Re: fix libz regress on gcc archs

2022-10-31 Thread Miod Vallat
> +.if (${COMPILER_VERSION:L} != "clang" && ! exists(/usr/local/bin/eg++))
> +regress:
> + @echo 'Run "pkg_add g++" to run unittests on GCC architectures'
> + @echo SKIPPED

Or the C++ test could be downgraded to C++98 so that it may be used on
all supported platforms:

Index: utils_unittest.cc
===
RCS file: /OpenBSD/src/regress/lib/libz/utils_unittest.cc,v
retrieving revision 1.3
diff -u -p -r1.3 utils_unittest.cc
--- utils_unittest.cc   4 Apr 2022 11:42:12 -   1.3
+++ utils_unittest.cc   31 Oct 2022 07:44:08 -
@@ -108,7 +108,7 @@ TEST(ZlibTest, CRCHashBitsCollision) {
   // of hash bits must be set higher, regardless of the memlevel parameter, 
when
   // using CRC32c hashing for string matching. See https://crbug.com/1113596
 
-  std::vector src = {
+  const uint8_t srcdata[] = {
   // Random byte; zlib doesn't match at offset 0.
   123,
 
@@ -131,10 +131,13 @@ TEST(ZlibTest, CRCHashBitsCollision) {
   0x14,
   0x15,
   };
+  std::vector src;
+  for (int i = 0; i < sizeof(srcdata) / sizeof(srcdata[0]); ++i)
+src.push_back(srcdata[i]);
 
   z_stream stream;
-  stream.zalloc = nullptr;
-  stream.zfree = nullptr;
+  stream.zalloc = Z_NULL;
+  stream.zfree = Z_NULL;
 
   // Using a low memlevel to try to reduce the number of hash bits. Negative
   // windowbits means raw deflate, i.e. without the zlib header.
@@ -174,7 +177,7 @@ TEST(ZlibTest, CRCHashAssert) {
   // other four bytes also mismatch. This tests that zlib's assert handles this
   // case.
 
-  std::vector src = {
+  const uint8_t srcdata[] = {
   // Random byte; zlib doesn't match at offset 0.
   123,
 
@@ -202,10 +205,13 @@ TEST(ZlibTest, CRCHashAssert) {
   0x12,
   0x34,
   };
+  std::vector src;
+  for (int i = 0; i < sizeof(srcdata) / sizeof(srcdata[0]); ++i)
+src.push_back(srcdata[i]);
 
   z_stream stream;
-  stream.zalloc = nullptr;
-  stream.zfree = nullptr;
+  stream.zalloc = Z_NULL;
+  stream.zfree = Z_NULL;
 
   int ret = deflateInit2(&stream, /*comp level*/ 5, /*method*/ Z_DEFLATED,
  /*windowbits*/ -15, /*memlevel*/ 8,
@@ -331,8 +337,8 @@ static const uint8_t checkMatchCrashData
 TEST(ZlibTest, CheckMatchCrash) {
   // See https://crbug.com/1113142.
   z_stream stream;
-  stream.zalloc = nullptr;
-  stream.zfree = nullptr;
+  stream.zalloc = Z_NULL;
+  stream.zfree = Z_NULL;
 
   // Low windowbits to hit window sliding also with a relatively small input.
   int ret = deflateInit2(&stream, /*comp level*/ 5, /*method*/ Z_DEFLATED,
@@ -352,7 +358,7 @@ TEST(ZlibTest, CheckMatchCrash) {
 ASSERT_EQ(ret, Z_OK);
   }
 
-  stream.next_in = nullptr;
+  stream.next_in = NULL;
   stream.avail_in = 0;
   ASSERT_GT(stream.avail_out, 0U);
   ret = deflate(&stream, Z_FINISH);
@@ -385,7 +391,7 @@ TEST(ZlibTest, DeflateRLEUninitUse) {
   int windowBits = 9;
   int memLevel = 8;
   int strategy = Z_RLE;
-  const std::vector src{
+  const uint8_t srcdata[] = {
   0x31, 0x64, 0x38, 0x32, 0x30, 0x32, 0x30, 0x36, 0x65, 0x35, 0x38, 0x35,
   0x32, 0x61, 0x30, 0x36, 0x65, 0x35, 0x32, 0x66, 0x30, 0x34, 0x38, 0x37,
   0x61, 0x31, 0x38, 0x36, 0x37, 0x37, 0x31, 0x39, 0x0a, 0x65, 0x62, 0x00,
@@ -451,6 +457,9 @@ TEST(ZlibTest, DeflateRLEUninitUse) {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
   };
+  std::vector src;
+  for (int i = 0; i < sizeof(srcdata) / sizeof(srcdata[0]); ++i)
+src.push_back(srcdata[i]);
 
   z_stream stream;
   stream.zalloc = Z_NULL;
@@ -463,7 +472,8 @@ TEST(ZlibTest, DeflateRLEUninitUse) {
   std::vector compressed(src.size() * 2 + 1000);
   stream.next_out = compressed.data();
   stream.avail_out = compressed.size();
-  for (uint8_t b : src) {
+  for (std::vector::size_type i = 0; i < src.size(); ++i) {
+uint8_t b = src[i];
 stream.next_in = &b;
 stream.avail_in = 1;
 ret = deflate(&stream, Z_NO_FLUSH);



Re: sparc64: switch to clockintr(9)

2022-11-07 Thread Miod Vallat
> This patch switches sparc64 to clockintr(9).

[...]

> Testing on the UltraSPARC IIe ("Hummingbird") would also be helpful.
> Apparently it has %SYS_TICK and %SYS_TICK_COMPARE, but in an unusual
> hardware configuration.  I imagine this machine is a bit rare, though.

All Sun Blade 100 and 150 are IIe, so they're actually quite common.

Fixed diff which compiles below.

Index: include/_types.h
===
RCS file: /OpenBSD/src/sys/arch/sparc64/include/_types.h,v
retrieving revision 1.23
diff -u -p -r1.23 _types.h
--- include/_types.h5 Mar 2018 01:15:25 -   1.23
+++ include/_types.h7 Nov 2022 16:10:08 -
@@ -35,6 +35,8 @@
 #ifndef _MACHINE__TYPES_H_
 #define _MACHINE__TYPES_H_
 
+#define__HAVE_CLOCKINTR
+
 #if defined(_KERNEL)
 typedef struct label_t {
long val[2];
Index: include/cpu.h
===
RCS file: /OpenBSD/src/sys/arch/sparc64/include/cpu.h,v
retrieving revision 1.100
diff -u -p -r1.100 cpu.h
--- include/cpu.h   22 Oct 2022 20:09:41 -  1.100
+++ include/cpu.h   7 Nov 2022 16:10:08 -
@@ -78,6 +78,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 
@@ -129,7 +130,7 @@ struct cpu_info {
int ci_want_resched;
int ci_handled_intr_level;
void*ci_intrpending[16][8];
-   u_int64_t   ci_tick;
+   struct clockintr_queue  ci_queue;
struct intrhand ci_tickintr;
 
volatile intci_ddb_paused;
Index: sparc64/clock.c
===
RCS file: /OpenBSD/src/sys/arch/sparc64/sparc64/clock.c,v
retrieving revision 1.71
diff -u -p -r1.71 clock.c
--- sparc64/clock.c 24 Oct 2021 17:05:04 -  1.71
+++ sparc64/clock.c 7 Nov 2022 16:10:08 -
@@ -65,6 +65,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -74,6 +75,7 @@
 #include 
 #endif
 #include 
+#include 
 #include 
 #include 
 
@@ -132,19 +134,35 @@ struct timecounter sys_tick_timecounter 
.tc_user = TC_SYS_TICK,
 };
 
-/*
- * Statistics clock interval and variance, in usec.  Variance must be a
- * power of two.  Since this gives us an even number, not an odd number,
- * we discard one case and compensate.  That is, a variance of 1024 would
- * give us offsets in [0..1023].  Instead, we take offsets in [1..1023].
- * This is symmetric about the point 512, or statvar/2, and thus averages
- * to that value (assuming uniform random numbers).
- */
-/* XXX fix comment to match value */
-int statvar = 8192;
-int statmin;   /* statclock interval - 1/2*variance */
+uint64_t tick_nsec_cycle_ratio;
+uint64_t tick_nsec_max;
+
+void tick_rearm(void *, uint64_t);
+void tick_trigger(void *);
+
+const struct intrclock tick_intrclock = {
+   .ic_rearm = tick_rearm,
+   .ic_trigger = tick_trigger
+};
+
+uint64_t sys_tick_nsec_cycle_ratio;
+uint64_t sys_tick_nsec_max;
 
-static long tick_increment;
+void sys_tick_rearm(void *, uint64_t);
+void sys_tick_trigger(void *);
+
+const struct intrclock sys_tick_intrclock = {
+   .ic_rearm = sys_tick_rearm,
+   .ic_trigger = sys_tick_trigger
+};
+
+void stick_rearm(void *, uint64_t);
+void stick_trigger(void *);
+
+const struct intrclock stick_intrclock = {
+   .ic_rearm = stick_rearm,
+   .ic_trigger = stick_trigger
+};
 
 void   tick_start(void);
 void   sys_tick_start(void);
@@ -153,12 +171,8 @@ void   stick_start(void);
 inttickintr(void *);
 intsys_tickintr(void *);
 intstickintr(void *);
-intschedintr(void *);
 
-static struct intrhand level10 = { clockintr };
 static struct intrhand level0 = { tickintr };
-static struct intrhand level14 = { statintr };
-static struct intrhand schedint = { schedintr };
 
 /*
  * clock (eeprom) attaches at the sbus or the ebus (PCI)
@@ -473,21 +487,7 @@ timerattach(struct device *parent, struc
timerreg_4u.t_clrintr = (int64_t *)(u_long)va[1];
timerreg_4u.t_mapintr = (int64_t *)(u_long)va[2];
 
-   /* Install the appropriate interrupt vector here */
-   level10.ih_number = INTVEC(ma->ma_interrupts[0]);
-   level10.ih_clr = (void *)&timerreg_4u.t_clrintr[0];
-   level10.ih_map = (void *)&timerreg_4u.t_mapintr[0];
-   strlcpy(level10.ih_name, "clock", sizeof(level10.ih_name));
-   intr_establish(10, &level10);
-
-   level14.ih_number = INTVEC(ma->ma_interrupts[1]);
-   level14.ih_clr = (void *)&timerreg_4u.t_clrintr[1];
-   level14.ih_map = (void *)&timerreg_4u.t_mapintr[1];
-   strlcpy(level14.ih_name, "prof", sizeof(level14.ih_name));
-   intr_establish(14, &level14);
-
-   printf(" ivec 0x%llx, 0x%llx\n", INTVEC(level10.ih_number),
-   INTVEC(level14.ih_number));
+   printf(" ivec (none)\n");
 }
 
 void
@@ -538,7 +538,7 @@ myetheraddr(u_char *cp)
 void
 cpu_i

remove eeprom(8) sun4 leftovers

2022-11-08 Thread Miod Vallat
The following diff removes the last mentions of the sun4 old style
eeprom behaviour in the eeprom(8) manual page, as well as options
specific to it.

Index: eeprom.8
===
RCS file: /OpenBSD/src/usr.sbin/eeprom/eeprom.8,v
retrieving revision 1.22
diff -u -p -r1.22 eeprom.8
--- eeprom.88 Jan 2020 14:45:36 -   1.22
+++ eeprom.88 Nov 2022 15:42:12 -
@@ -33,12 +33,11 @@
 .Os
 .Sh NAME
 .Nm eeprom
-.Nd display or modify contents of the EEPROM or OpenPROM
+.Nd display or modify contents of the OpenPROM
 .Sh SYNOPSIS
 .Nm eeprom
-.Op Fl cipv
+.Op Fl pv
 .Op Fl f Ar device
-.Op Fl N Ar system
 .Oo
 .Ar field Ns Op = Ns Ar value
 .Ar ...
@@ -46,7 +45,7 @@
 .Sh DESCRIPTION
 .Nm eeprom
 provides an interface for displaying and changing the contents of the
-EEPROM or OpenPROM.
+OpenPROM.
 Without any arguments,
 .Nm eeprom
 will list all of the known fields and their corresponding values.
@@ -55,145 +54,26 @@ When given the name of a specific field,
 will display that value or set it if the field name is followed by
 .Sq =
 and a value.
-Only the superuser may modify the contents of the EEPROM or OpenPROM.
+Only the superuser may modify the contents of the OpenPROM.
 .Pp
 The options are as follows:
 .Bl -tag -width Ds
 .It Fl
 Commands are taken from stdin and displayed on stdout.
-.It Fl c
-.Nm eeprom
-will fix incorrect checksum values and exit.
-This flag is quietly ignored on systems with an OpenPROM.
 .It Fl f Ar device
-On systems with an EEPROM, use
-.Ar device
-instead of the default
-.Pa /dev/eeprom .
-On systems with an OpenPROM, use
+Use
 .Ar device
 instead of the default
 .Pa /dev/openprom .
-.It Fl i
-If checksum values are incorrect,
-.Nm eeprom
-will ignore them and continue after displaying a warning.
-This flag is quietly ignored on systems with an OpenPROM.
-.It Fl N Ar system
-Use the system image
-.Ar system
-instead of the default
-.Pa /bsd .
 .It Fl p
-On systems with an OpenPROM, display the tree derived from it and exit.
-This flag is quietly ignored on systems with an EEPROM.
+Display the tree derived from the OpenPROM and exit.
 .It Fl v
-On systems with an OpenPROM, be verbose when setting a value.
-Systems with an EEPROM are always verbose.
+Be verbose when setting a value.
 .El
 .Sh FIELDS AND VALUES
-The following fields and values are for systems with an EEPROM:
-.Bl -tag -width "watchdog_reboot  "
-.It Ar hwupdate
-A valid date, such as
-.Dq 7/12/95 .
-The strings
-.Dq today
-and
-.Dq now
-are also acceptable.
-.It Ar memsize
-How much memory, in megabytes, is installed in the system.
-.It Ar memtest
-How much memory, in megabytes, is to be tested upon power-up.
-.It Ar scrsize
-The size of the screen.
-Acceptable values are
-.Dq 1024x1024 ,
-.Dq 1152x900 ,
-.Dq 1600x1280 ,
-and
-.Dq 1440x1440 .
-.It Ar watchdog_reboot
-If true, the system will reboot upon reset.
-Otherwise, the system will fall into the monitor.
-.It Ar default_boot
-If true, the system will use the boot device stored in
-.Ar bootdev .
-.It Ar bootdev
-Specifies the default boot device in the form cc(x,x,x), where
-.Dq cc
-is a combination of two letters such as
-.Dq sd
-or
-.Dq le
-and each
-.Dq x
-is a hexadecimal number between 0 and ff, less the prepending
-.Dq 0x .
-.It Ar kbdtype
-This value is
-.Dq 0
-for all Sun keyboards.
-.It Ar console
-Specifies the console type.
-Valid values are
-.Dq b&w ,
-.Dq ttya ,
-.Dq ttyb ,
-.Dq color ,
-and
-.Dq p4opt .
-.It Ar keyclick
-If true, the keys click annoyingly.
-.It Ar diagdev
-This is a string very similar to that used by
-.Ar bootdev .
-It specifies the default boot device when the diagnostic switch is
-turned on.
-.It Ar diagpath
-A 40-character, NULL-terminated string specifying the kernel or stand-alone
-program to load when the diagnostic switch is turned on.
-.It Ar columns
-An 8-bit integer specifying the number of columns on the console.
-.It Ar rows
-An 8-bit integer specifying the number of rows on the console.
-.It Ar ttya_use_baud
-Use the baud rate stored in
-.Ar ttya_baud
-instead of the default 9600.
-.It Ar ttya_baud
-A 16-bit integer specifying the baud rate to use on ttya.
-.It Ar ttya_no_rtsdtr
-If true, disables RTS/DTR.
-.It Ar ttyb_use_baud
-Similar to
-.Ar ttya_use_baud ,
-but for ttyb.
-.It Ar ttyb_baud
-Similar to
-.Ar ttya_baud ,
-but for ttyb.
-.It Ar ttyb_no_rtsdtr
-Similar to
-.Ar ttya_no_rtsdtr ,
-but for ttyb.
-.It Ar banner
-An 80-character, NULL-terminated string to use at power-up instead
-of the default Sun banner.
-.El
-.Pp
-Note that the
-.Ar secure ,
-.Ar bad_login ,
-and
-.Ar password
-fields are not currently supported.
-.Pp
 Since the OpenPROM is designed such that the field names are arbitrary,
 explaining them here is dubious.
-Below are field names and values that
-one is likely to see on a system with an OpenPROM.
+Below are field names and values that one is likely to see.
 NOTE: this list
 may be incomplete or incorrect due to differences b

Re: arm64 pwmbl(4): simplify ramp case

2022-11-10 Thread Miod Vallat
> This actually breaks my machine.  malloc() is saying allocation too
> large.  OF_getproplen will return -1 on that.  Is it possible that
> len is treated as uint64_t as it is an int and sizeof is effectively
> uint64_t?

Ah, yes; size_t is unsigned and wider than int on 64-bit platforms,
therefore int is converted to unsigned for the comparison. Casting
sizeof to int will do.

> Might be easier to have a check like:
> 
>   if (sc->sc_channels == NULL)
>   return level < sc->sc_nlevels ? level : sc->sc_nlevels - 1;
> 
> Then you don't need to indent the whole block.  Makes the diff smaller
> and a bit easier to understand?

Sure; what about this new version, then?

Index: pwmbl.c
===
RCS file: /OpenBSD/src/sys/dev/fdt/pwmbl.c,v
retrieving revision 1.6
diff -u -p -r1.6 pwmbl.c
--- pwmbl.c 24 Oct 2021 17:52:26 -  1.6
+++ pwmbl.c 11 Nov 2022 06:46:41 -
@@ -35,7 +35,7 @@ struct pwmbl_softc {
struct device   sc_dev;
uint32_t*sc_pwm;
int sc_pwm_len;
-   uint32_t*sc_levels;
+   uint32_t*sc_levels; /* NULL if simple ramp */
int sc_nlevels;
uint32_tsc_max_level;
uint32_tsc_def_level;
@@ -73,7 +73,7 @@ pwmbl_attach(struct device *parent, stru
struct pwmbl_softc *sc = (struct pwmbl_softc *)self;
struct fdt_attach_args *faa = aux;
uint32_t *gpios;
-   int i, len;
+   int len;
 
len = OF_getproplen(faa->fa_node, "pwms");
if (len < 0) {
@@ -95,7 +95,7 @@ pwmbl_attach(struct device *parent, stru
}
 
len = OF_getproplen(faa->fa_node, "brightness-levels");
-   if (len > 0) {
+   if (len >= (int)sizeof(uint32_t)) {
sc->sc_levels = malloc(len, M_DEVBUF, M_WAITOK);
OF_getpropintarray(faa->fa_node, "brightness-levels",
sc->sc_levels, len);
@@ -107,13 +107,9 @@ pwmbl_attach(struct device *parent, stru
sc->sc_def_level = sc->sc_nlevels - 1;
sc->sc_def_level = sc->sc_levels[sc->sc_def_level];
} else {
+   /* No levels, assume a simple 0..255 ramp. */
sc->sc_nlevels = 256;
-   sc->sc_levels = mallocarray(sc->sc_nlevels,
-   sizeof(uint32_t), M_DEVBUF, M_WAITOK);
-   for (i = 0; i < sc->sc_nlevels; i++)
-   sc->sc_levels[i] = i;
-   sc->sc_max_level = sc->sc_levels[sc->sc_nlevels - 1];
-   sc->sc_def_level = sc->sc_levels[sc->sc_nlevels - 1];
+   sc->sc_max_level = sc->sc_def_level = sc->sc_nlevels - 1;
}
 
printf("\n");
@@ -143,6 +139,9 @@ pwmbl_find_brightness(struct pwmbl_softc
 {
uint32_t mid;
int i;
+
+   if (sc->sc_levels == NULL)
+   return level < sc->sc_nlevels ? level : sc->sc_nlevels - 1;
 
for (i = 0; i < sc->sc_nlevels - 1; i++) {
mid = (sc->sc_levels[i] + sc->sc_levels[i + 1]) / 2;



Re: lladdr support for netstart/hostname.if (was: Re: Locking network card configuration)

2022-11-22 Thread Miod Vallat
I'm a bit late to the thread, but whatever its outcome, things have to
work correctly on older sparc64 hardware, where the default behaviour
for on-board and Sun-branded expansion card interfaces is to use the
same MAC address.

This hints that hostname. should have priority over
hoshname. for the latter will be ambiguous on these
systems.



Re: Get rid of UVM_VNODE_CANPERSIST

2022-11-22 Thread Miod Vallat
> Here is a diff.  Maybe bluhm@ can try this on the macppc machine that
> triggered the original "vref used where vget required" problem?

On a similar machine it panics after a few hours with:

panic: uvn_flush: PGO_SYNCIO return 'try again' error (impossible)

The trace (transcribed by hand) is
uvn_flush+0x820
uvm_vnp_terminate+0x79
vclean+0xdc
vgonel+0x70
getnewvnode+0x240
ffs_vget+0xcc
ffs_inode_alloc+0x13c
ufs_makeinode+0x94
ufs_create+0x58
VOP_CREATE+0x48
vn_open+0x188
doopenat+0x1b4



Re: m2: add suspend keyboard shortcut

2023-07-08 Thread Miod Vallat
> Now that we have request_sleep() we can add a new internal KS_Cmd_Sleep
> keycode, map it into the macbook keyboard, catch in wskbd and go to sleep.
> 
> ok?

> --- sys/dev/usb/ukbdmap.c
> +++ sys/dev/usb/ukbdmap.c
> @@ -176,6 +176,7 @@ static const keysym_t ukbd_keydesc_us[] = {
>  KC(127), KS_AudioMute,
>  KC(128), KS_AudioRaise,
>  KC(129), KS_AudioLower,
> +KC(130), KS_Cmd_Sleep,
>  KC(224), KS_Cmd1,KS_Control_L,
>  KC(225), KS_Shift_L,
>  KC(226), KS_Cmd2,KS_Alt_L,

This file is generated, so the changes would be lost eventually.

You should add this in makemap.awk in the block starting at line 330.
Also, that block mentions the use of keysym 102 for suspend, rather than
130 (which you probably picked randomly), so I would prefer if you
would use 102, this would allow this feature to also work on more
systems.

> --- sys/dev/wscons/wskbd.c
> +++ sys/dev/wscons/wskbd.c
> @@ -1513,6 +1513,11 @@ internal_command(struct wskbd_softc *sc, u_int *type, 
>   if (*type != WSCONS_EVENT_KEY_DOWN)
>   return (0);
>  
> +#ifdef SUSPEND
> + if (ksym == KS_Cmd_Sleep)
> + return request_sleep(SLEEP_SUSPEND);
> +#endif

I think you should return 1 regardless of the result of request_sleep().



Re: [PATCH] Support PS2 keyboard on chrromebook

2023-07-26 Thread Miod Vallat
> On, at least, some Chromebook PS/2 protocol is implemented by EC rather
> than a real PS/2 controller. It works fine except for 2 things:
> * Unusual layout like multimedia keys instead of F*
> * Reset command returns garbage (usually last key)
> This patch attempts to handle later as it stops keyboard from being
> recognized at all. It works by checking getid if reset fails.

I was not aware of the reset behaviour.

I suppose your logic makes sense. However, only Chromebook or other crap
hardware would hit that "send a getid command" path, so I think we
should only check for a 0xab/0x83 answer to that command, rather than
six possible values for the first byte and ignoring the second byte.

Have you checked that the Chromebook EC 8042 emulation returns 0xab/0x83
to the 0xf2 command?

Miod



Re: Diff for evaluation (WACOM tablet driver)

2023-08-12 Thread Miod Vallat
I have had a look at your diff and I think it's decent enough to go in
after some polishing.

Can Wacom tablet users try this cleaned up diff?

Index: dev/hid/hid.c
===
RCS file: /OpenBSD/src/sys/dev/hid/hid.c,v
retrieving revision 1.5
diff -u -p -r1.5 hid.c
--- dev/hid/hid.c   20 May 2022 05:03:45 -  1.5
+++ dev/hid/hid.c   12 Aug 2023 07:59:14 -
@@ -657,3 +657,52 @@ hid_is_collection(const void *desc, int 
hid_end_parse(hd);
return (0);
 }
+
+struct hid_data *
+hid_get_collection_data(const void *desc, int size, int32_t usage,
+uint32_t collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: usage=0x%x\n", __func__, usage);
+   while (hid_get_item(hd, &hi)) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage) {
+   DPRINTF("%s: found\n", __func__);
+   return hd;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return NULL;
+}
+
+int
+hid_get_id_of_collection(const void *desc, int size, int32_t usage,
+uint32_t collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: id=%d usage=0x%x\n", __func__, id, usage);
+   while (hid_get_item(hd, &hi)) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage) {
+   DPRINTF("%s: found\n", __func__);
+   hid_end_parse(hd);
+   return hi.report_ID;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return 0;
+}
Index: dev/hid/hid.h
===
RCS file: /OpenBSD/src/sys/dev/hid/hid.h,v
retrieving revision 1.10
diff -u -p -r1.10 hid.h
--- dev/hid/hid.h   20 May 2022 05:03:45 -  1.10
+++ dev/hid/hid.h   12 Aug 2023 07:59:14 -
@@ -93,6 +93,10 @@ int  hid_locate(const void *, int, int32_
 int32_thid_get_data(const uint8_t *buf, int, struct hid_location *);
 uint32_t hid_get_udata(const uint8_t *buf, int, struct hid_location *);
 inthid_is_collection(const void *, int, uint8_t, int32_t);
+struct hid_data *  hid_get_collection_data(const void *, int, int32_t, 
+   uint32_t);
+inthid_get_id_of_collection(const void *desc, int size, int32_t usage, 
+   uint32_t collection);
 
 #endif /* _KERNEL */
 
@@ -353,6 +357,7 @@ int hid_is_collection(const void *, int,
 #define HUD_TOUCHSCREEN0x0004
 #define HUD_TOUCHPAD   0x0005
 #define HUD_CONFIG 0x000e
+#define HUD_STYLUS 0x0020
 #define HUD_FINGER 0x0022
 #define HUD_TIP_PRESSURE   0x0030
 #define HUD_BARREL_PRESSURE0x0031
@@ -387,6 +392,12 @@ inthid_is_collection(const void *, int,
 #define HUD_CONTACT_MAX0x0055
 #define HUD_SCAN_TIME  0x0056
 #define HUD_BUTTON_TYPE0x0059
+#define HUD_SECONDARY_BARREL_SWITCH0x005A
+#define HUD_WACOM_X0x0130
+#define HUD_WACOM_Y0x0131
+#define HUD_WACOM_DISTANCE 0x0132
+#define HUD_WACOM_PAD_BUTTONS000x0910
+#define HUD_WACOM_BATTERY  0x1013
 
 /* Usages, LED */
 #define HUL_NUM_LOCK   0x0001
Index: dev/hid/hidms.c
===
RCS file: /OpenBSD/src/sys/dev/hid/hidms.c,v
retrieving revision 1.9
diff -u -p -r1.9 hidms.c
--- dev/hid/hidms.c 16 Jun 2022 20:52:38 -  1.9
+++ dev/hid/hidms.c 12 Aug 2023 07:59:14 -
@@ -61,6 +61,188 @@ int hidmsdebug = 0;
 #define MOUSE_FLAGS_MASK   (HIO_CONST | HIO_RELATIVE)
 #define NOTMOUSE(f)(((f) & MOUSE_FLAGS_MASK) != HIO_RELATIVE)
 
+void
+hidms_stylus_hid_parse(struct hidms *ms, struct hid_data *d,
+struct hid_location *loc_stylus_btn)
+{
+   struct hid_item h;
+
+   while (hid_get_item(d, &h)) {
+   if (h.kind == hid_endcollection)
+   break;
+   if (h.kind != hid_input || (h.flags & HIO_CONST) != 0)
+   continue;
+   /* All the possible stylus reported usages go here */
+#ifdef HIDMS_DEBUG
+   printf("stylus usage: 0x%x\n", h.usage);
+#endif
+   switch (h.usage) {
+   /* Buttons */
+   case HID_USAGE2(HUP_WACOM | HUP_DIGIT

Re: Diff for evaluation (WACOM tablet driver)

2023-08-12 Thread Miod Vallat
> On Sat, Aug 12, 2023 at 08:00:48AM +0000, Miod Vallat wrote:
> > I have had a look at your diff and I think it's decent enough to go in
> > after some polishing.
> > 
> > Can Wacom tablet users try this cleaned up diff?
> 
> Hi,
> 
> My WACOM tablet stopped working with this, here is a dmesg with the patch and
> usbdevs -v output.  Let me know if there is any new patches I can test.
> 
> As you can see it doesn't even attach like it should (from the dmesg).

Thanks for reporting this. The changes in uhidev have been a bit too
aggressive indeed.

Does this new version of the diff help? Only uhidev.c differs.

Index: dev/hid/hid.c
===
RCS file: /OpenBSD/src/sys/dev/hid/hid.c,v
retrieving revision 1.5
diff -u -p -r1.5 hid.c
--- dev/hid/hid.c   20 May 2022 05:03:45 -  1.5
+++ dev/hid/hid.c   12 Aug 2023 13:11:22 -
@@ -657,3 +657,52 @@ hid_is_collection(const void *desc, int 
hid_end_parse(hd);
return (0);
 }
+
+struct hid_data *
+hid_get_collection_data(const void *desc, int size, int32_t usage,
+uint32_t collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: usage=0x%x\n", __func__, usage);
+   while (hid_get_item(hd, &hi)) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage) {
+   DPRINTF("%s: found\n", __func__);
+   return hd;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return NULL;
+}
+
+int
+hid_get_id_of_collection(const void *desc, int size, int32_t usage,
+uint32_t collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: id=%d usage=0x%x\n", __func__, id, usage);
+   while (hid_get_item(hd, &hi)) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage) {
+   DPRINTF("%s: found\n", __func__);
+   hid_end_parse(hd);
+   return hi.report_ID;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return 0;
+}
Index: dev/hid/hid.h
===
RCS file: /OpenBSD/src/sys/dev/hid/hid.h,v
retrieving revision 1.10
diff -u -p -r1.10 hid.h
--- dev/hid/hid.h   20 May 2022 05:03:45 -  1.10
+++ dev/hid/hid.h   12 Aug 2023 13:11:22 -
@@ -93,6 +93,10 @@ int  hid_locate(const void *, int, int32_
 int32_thid_get_data(const uint8_t *buf, int, struct hid_location *);
 uint32_t hid_get_udata(const uint8_t *buf, int, struct hid_location *);
 inthid_is_collection(const void *, int, uint8_t, int32_t);
+struct hid_data *  hid_get_collection_data(const void *, int, int32_t, 
+   uint32_t);
+inthid_get_id_of_collection(const void *desc, int size, int32_t usage, 
+   uint32_t collection);
 
 #endif /* _KERNEL */
 
@@ -353,6 +357,7 @@ int hid_is_collection(const void *, int,
 #define HUD_TOUCHSCREEN0x0004
 #define HUD_TOUCHPAD   0x0005
 #define HUD_CONFIG 0x000e
+#define HUD_STYLUS 0x0020
 #define HUD_FINGER 0x0022
 #define HUD_TIP_PRESSURE   0x0030
 #define HUD_BARREL_PRESSURE0x0031
@@ -387,6 +392,12 @@ inthid_is_collection(const void *, int,
 #define HUD_CONTACT_MAX0x0055
 #define HUD_SCAN_TIME  0x0056
 #define HUD_BUTTON_TYPE0x0059
+#define HUD_SECONDARY_BARREL_SWITCH0x005A
+#define HUD_WACOM_X0x0130
+#define HUD_WACOM_Y0x0131
+#define HUD_WACOM_DISTANCE 0x0132
+#define HUD_WACOM_PAD_BUTTONS000x0910
+#define HUD_WACOM_BATTERY  0x1013
 
 /* Usages, LED */
 #define HUL_NUM_LOCK   0x0001
Index: dev/hid/hidms.c
===
RCS file: /OpenBSD/src/sys/dev/hid/hidms.c,v
retrieving revision 1.9
diff -u -p -r1.9 hidms.c
--- dev/hid/hidms.c 16 Jun 2022 20:52:38 -  1.9
+++ dev/hid/hidms.c 12 Aug 2023 13:11:22 -
@@ -61,6 +61,188 @@ int hidmsdebug = 0;
 #define MOUSE_FLAGS_MASK   (HIO_CONST | HIO_RELATIVE)
 #define NOTMOUSE(f)(((f) & MOUSE_FLAG

Re: Diff for evaluation (WACOM tablet driver)

2023-08-12 Thread Miod Vallat
Third time's (hopefully) the charm. How about that diff? Too much things
have been removed in uwacom.

Index: dev/hid/hid.c
===
RCS file: /OpenBSD/src/sys/dev/hid/hid.c,v
retrieving revision 1.5
diff -u -p -r1.5 hid.c
--- dev/hid/hid.c   20 May 2022 05:03:45 -  1.5
+++ dev/hid/hid.c   12 Aug 2023 14:24:53 -
@@ -657,3 +657,52 @@ hid_is_collection(const void *desc, int 
hid_end_parse(hd);
return (0);
 }
+
+struct hid_data *
+hid_get_collection_data(const void *desc, int size, int32_t usage,
+uint32_t collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: usage=0x%x\n", __func__, usage);
+   while (hid_get_item(hd, &hi)) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage) {
+   DPRINTF("%s: found\n", __func__);
+   return hd;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return NULL;
+}
+
+int
+hid_get_id_of_collection(const void *desc, int size, int32_t usage,
+uint32_t collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: id=%d usage=0x%x\n", __func__, id, usage);
+   while (hid_get_item(hd, &hi)) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage) {
+   DPRINTF("%s: found\n", __func__);
+   hid_end_parse(hd);
+   return hi.report_ID;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return 0;
+}
Index: dev/hid/hid.h
===
RCS file: /OpenBSD/src/sys/dev/hid/hid.h,v
retrieving revision 1.10
diff -u -p -r1.10 hid.h
--- dev/hid/hid.h   20 May 2022 05:03:45 -  1.10
+++ dev/hid/hid.h   12 Aug 2023 14:24:53 -
@@ -93,6 +93,10 @@ int  hid_locate(const void *, int, int32_
 int32_thid_get_data(const uint8_t *buf, int, struct hid_location *);
 uint32_t hid_get_udata(const uint8_t *buf, int, struct hid_location *);
 inthid_is_collection(const void *, int, uint8_t, int32_t);
+struct hid_data *  hid_get_collection_data(const void *, int, int32_t, 
+   uint32_t);
+inthid_get_id_of_collection(const void *desc, int size, int32_t usage, 
+   uint32_t collection);
 
 #endif /* _KERNEL */
 
@@ -353,6 +357,7 @@ int hid_is_collection(const void *, int,
 #define HUD_TOUCHSCREEN0x0004
 #define HUD_TOUCHPAD   0x0005
 #define HUD_CONFIG 0x000e
+#define HUD_STYLUS 0x0020
 #define HUD_FINGER 0x0022
 #define HUD_TIP_PRESSURE   0x0030
 #define HUD_BARREL_PRESSURE0x0031
@@ -387,6 +392,12 @@ inthid_is_collection(const void *, int,
 #define HUD_CONTACT_MAX0x0055
 #define HUD_SCAN_TIME  0x0056
 #define HUD_BUTTON_TYPE0x0059
+#define HUD_SECONDARY_BARREL_SWITCH0x005A
+#define HUD_WACOM_X0x0130
+#define HUD_WACOM_Y0x0131
+#define HUD_WACOM_DISTANCE 0x0132
+#define HUD_WACOM_PAD_BUTTONS000x0910
+#define HUD_WACOM_BATTERY  0x1013
 
 /* Usages, LED */
 #define HUL_NUM_LOCK   0x0001
Index: dev/hid/hidms.c
===
RCS file: /OpenBSD/src/sys/dev/hid/hidms.c,v
retrieving revision 1.9
diff -u -p -r1.9 hidms.c
--- dev/hid/hidms.c 16 Jun 2022 20:52:38 -  1.9
+++ dev/hid/hidms.c 12 Aug 2023 14:24:53 -
@@ -61,6 +61,188 @@ int hidmsdebug = 0;
 #define MOUSE_FLAGS_MASK   (HIO_CONST | HIO_RELATIVE)
 #define NOTMOUSE(f)(((f) & MOUSE_FLAGS_MASK) != HIO_RELATIVE)
 
+void
+hidms_stylus_hid_parse(struct hidms *ms, struct hid_data *d,
+struct hid_location *loc_stylus_btn)
+{
+   struct hid_item h;
+
+   while (hid_get_item(d, &h)) {
+   if (h.kind == hid_endcollection)
+   break;
+   if (h.kind != hid_input || (h.flags & HIO_CONST) != 0)
+   continue;
+   /* All the possible stylus reported usages go here */
+#ifdef HIDMS_DEBUG
+   printf("stylus usage: 0x%x\n", h.usage);
+#endif
+   switch (h.usage) {
+   /* Buttons */
+   case HID_USAGE2(HUP_WACOM | HUP_DIGITIZERS, HUD_TIP_SWITCH):
+

Re: Diff for evaluation (WACOM tablet driver)

2023-08-12 Thread Miod Vallat
> On Sat, Aug 12, 2023 at 02:27:13PM +0000, Miod Vallat wrote:
> > Third time's (hopefully) the charm. How about that diff? Too much things
> > have been removed in uwacom.
> 
> partial success!  The wacom driver is recognized, no panics this time.  But
> the input is all over the place when I try to draw anything in gimp.  It opens
> windows and stuff that I didn't open.

I think it was a mistake to try and have the wacom interrupt code
cover the "new" models as well as the existing ones, so I've split it
in two flavours.

New diff below.

Index: dev/hid/hid.c
===
RCS file: /OpenBSD/src/sys/dev/hid/hid.c,v
retrieving revision 1.5
diff -u -p -r1.5 hid.c
--- dev/hid/hid.c   20 May 2022 05:03:45 -  1.5
+++ dev/hid/hid.c   12 Aug 2023 15:51:13 -
@@ -657,3 +657,52 @@ hid_is_collection(const void *desc, int 
hid_end_parse(hd);
return (0);
 }
+
+struct hid_data *
+hid_get_collection_data(const void *desc, int size, int32_t usage,
+uint32_t collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: usage=0x%x\n", __func__, usage);
+   while (hid_get_item(hd, &hi)) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage) {
+   DPRINTF("%s: found\n", __func__);
+   return hd;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return NULL;
+}
+
+int
+hid_get_id_of_collection(const void *desc, int size, int32_t usage,
+uint32_t collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: id=%d usage=0x%x\n", __func__, id, usage);
+   while (hid_get_item(hd, &hi)) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage) {
+   DPRINTF("%s: found\n", __func__);
+   hid_end_parse(hd);
+   return hi.report_ID;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return -1;
+}
Index: dev/hid/hid.h
===
RCS file: /OpenBSD/src/sys/dev/hid/hid.h,v
retrieving revision 1.10
diff -u -p -r1.10 hid.h
--- dev/hid/hid.h   20 May 2022 05:03:45 -  1.10
+++ dev/hid/hid.h   12 Aug 2023 15:51:13 -
@@ -93,6 +93,10 @@ int  hid_locate(const void *, int, int32_
 int32_thid_get_data(const uint8_t *buf, int, struct hid_location *);
 uint32_t hid_get_udata(const uint8_t *buf, int, struct hid_location *);
 inthid_is_collection(const void *, int, uint8_t, int32_t);
+struct hid_data *  hid_get_collection_data(const void *, int, int32_t, 
+   uint32_t);
+inthid_get_id_of_collection(const void *desc, int size, int32_t usage, 
+   uint32_t collection);
 
 #endif /* _KERNEL */
 
@@ -353,6 +357,7 @@ int hid_is_collection(const void *, int,
 #define HUD_TOUCHSCREEN0x0004
 #define HUD_TOUCHPAD   0x0005
 #define HUD_CONFIG 0x000e
+#define HUD_STYLUS 0x0020
 #define HUD_FINGER 0x0022
 #define HUD_TIP_PRESSURE   0x0030
 #define HUD_BARREL_PRESSURE0x0031
@@ -387,6 +392,12 @@ inthid_is_collection(const void *, int,
 #define HUD_CONTACT_MAX0x0055
 #define HUD_SCAN_TIME  0x0056
 #define HUD_BUTTON_TYPE0x0059
+#define HUD_SECONDARY_BARREL_SWITCH0x005A
+#define HUD_WACOM_X0x0130
+#define HUD_WACOM_Y0x0131
+#define HUD_WACOM_DISTANCE 0x0132
+#define HUD_WACOM_PAD_BUTTONS000x0910
+#define HUD_WACOM_BATTERY  0x1013
 
 /* Usages, LED */
 #define HUL_NUM_LOCK   0x0001
Index: dev/hid/hidms.c
===
RCS file: /OpenBSD/src/sys/dev/hid/hidms.c,v
retrieving revision 1.9
diff -u -p -r1.9 hidms.c
--- dev/hid/hidms.c 16 Jun 2022 20:52:38 -  1.9
+++ dev/hid/hidms.c 12 Aug 2023 15:51:13 -
@@ -61,6 +61,188 @@ int hidmsdebug = 0;
 #define MOUSE_FLAGS_MASK   (HIO_CONST | HIO_RELATIVE)
 #define NOTMOUSE(f)(((f) & MOUSE_FLAGS_MASK) != HIO_RELATIVE)
 
+void
+hidms_stylus_hid_parse(struct hidms *ms, str

Re: [PATCH] Support PS2 keyboard on chrromebook

2023-08-13 Thread Miod Vallat
> CC'ed back the mailing list.

Oops, I thought I had replied to the list as well, my bad.

> Tested your patch. It works on my Chromebook.

Excellent. It's in!

Thanks,
Miod



Re: __predict_{true,false} is this right?

2023-08-22 Thread Miod Vallat
> lines 195 and 196.  Now my question, does this not sorta look wrong?
> 
> Shouldn't these values be a little more unique?  As in not the same?

No, these are correct. These lines are used when the compiler does not
support __predict_false and __predict_true, so __predict_whaterver(x)
has to behave as a boolean evaluation of (x).

Miod



dwge(4): don't panic on truncated input packet

2023-10-18 Thread Miod Vallat
I had the misfortune of hitting a KASSERT in dwge:

panic: kernel diagnostic assertion "len > 0" failed: file "/usr/src/sys/dev/fdt
/if_dwge.c", line 1102
Stopped at  panic+0x106:addia0,zero,256TIDPIDUID PR
FLAGS PFLAGS  CPU  COMMAND
*405136  98879   1500 0x3  00  git
 301471  67731  0 0x14000  0x2001  softnet0
panic() at panic+0x106
panic() at panic
dwge_rx_proc() at dwge_rx_proc+0x1d4
dwge_intr() at dwge_intr+0x4e
plic_irq_dispatch() at plic_irq_dispatch+0xec
plic_irq_handler() at plic_irq_handler+0x56
riscv_cpu_intr() at riscv_cpu_intr+0x22
cpu_exception_handler_supervisor() at cpu_exception_handler_supervisor+0x7a
pmap_copy_page() at pmap_copy_page+0x94
uvm_pagerealloc_multi() at uvm_pagerealloc_multi+0x24e
buf_realloc_pages() at buf_realloc_pages+0xa0
buf_flip_high() at buf_flip_high+0x64
bufcache_recover_dmapages() at bufcache_recover_dmapages+0x13a
buf_get() at buf_get+0xec
end trace frame: 0xffc04d9ac870, count: 0

The following diff should count the error and skirt the panic.

Index: if_dwge.c
===
RCS file: /OpenBSD/src/sys/dev/fdt/if_dwge.c,v
retrieving revision 1.19
diff -u -p -r1.19 if_dwge.c
--- if_dwge.c   15 Aug 2023 08:27:30 -  1.19
+++ if_dwge.c   18 Oct 2023 16:37:59 -
@@ -1099,13 +1101,15 @@ dwge_rx_proc(struct dwge_softc *sc)
 
/* Strip off CRC. */
len -= ETHER_CRC_LEN;
-   KASSERT(len > 0);
-
-   m = rxb->tb_m;
-   rxb->tb_m = NULL;
-   m->m_pkthdr.len = m->m_len = len;
+   if (len <= 0) {
+   ifp->if_ierrors++;
+   } else {
+   m = rxb->tb_m;
+   rxb->tb_m = NULL;
+   m->m_pkthdr.len = m->m_len = len;
 
-   ml_enqueue(&ml, m);
+   ml_enqueue(&ml, m);
+   }
 
put++;
if (sc->sc_rx_cons == (DWGE_NRXDESC - 1))



Re: Prevent off-by-one accounting hang in out-of-swap situations

2023-10-21 Thread Miod Vallat
> Stuart, Miod, I wonder if this also help for the off-by-one issue you
> are seeing.  It might not.

It makes the aforementioned issue disappear on the affected machine.

> Comments, ok?

> diff --git sys/uvm/uvm_pdaemon.c sys/uvm/uvm_pdaemon.c
> index 284211d226c..a26a776df67 100644
> --- sys/uvm/uvm_pdaemon.c
> +++ sys/uvm/uvm_pdaemon.c

> @@ -917,9 +914,7 @@ uvmpd_scan(struct uvm_pmalloc *pma, struct 
> uvm_constraint_range *constraint)
>*/
>   free = uvmexp.free - BUFPAGES_DEFICIT;
>   swap_shortage = 0;
> - if (free < uvmexp.freetarg &&
> - uvmexp.swpginuse == uvmexp.swpages &&
> - !uvm_swapisfull() &&
> + if (free < uvmexp.freetarg && uvm_swapisfilled() && !uvm_swapisfull() &&
>   pages_freed == 0) {
>   swap_shortage = uvmexp.freetarg - free;
>   }

It's unfortunate that you now invoke two uvm_swapisxxx() routines, which
will both acquire a mutex. Maybe a third uvm_swapisxxx routine could be
introduced to compute the swapisfilled && !swapisfull condition at once?



Re: Prevent off-by-one accounting hang in out-of-swap situations

2023-10-22 Thread Miod Vallat
> On 21/10/23(Sat) 14:28, Miod Vallat wrote:
> > > Stuart, Miod, I wonder if this also help for the off-by-one issue you
> > > are seeing.  It might not.
> > 
> > It makes the aforementioned issue disappear on the affected machine.
> 
> Thanks at lot for testing!

Spoke too soon. I have just hit

panic: kernel diagnostic assertion "uvmexp.swpgonly > 0" failed: file 
"/usr/src/sys/uvm/uvm_anon.c", line 121
Stopped at  db_enter+0x8:   add #0x4, r14
TIDPIDUID PRFLAGS PFLAGS  CPU  COMMAND
*235984  11904  0 0x14000  0x2000  reaper
db_enter() at db_enter+0x8
panic() at panic+0x74
__assert() at __assert+0x1c
uvm_anfree_list() at uvm_anfree_list+0x156
amap_wipeout() at amap_wipeout+0xe6
uvm_unmap_detach() at uvm_unmap_detach+0x42
uvm_map_teardown() at uvm_map_teardown+0x104
uvmspace_free() at uvmspace_free+0x2a
reaper() at reaper+0x86
ddb> show uvmexp
Current UVM status:
  pagesize=4096 (0x1000), pagemask=0xfff, pageshift=12
  14875 VM pages: 376 active, 2076 inactive, 1 wired, 7418 free (924
zero)
  min  10% (25) anon, 10% (25) vnode, 5% (12) vtext
  freemin=495, free-target=660, inactive-target=2809, wired-max=4958
  faults=73331603, traps=39755714, intrs=33863551, ctxswitch=11641480
fpuswitch
=0
  softint=15742561, syscalls=39755712, kmapent=11
  fault counts:
noram=1, noanon=0, noamap=0, pgwait=1629, pgrele=0
ok relocks(total)=1523991(1524022), anget(retries)=23905247(950233),
amapco
py=9049749
neighbor anon/obj pg=12025732/40041442,
gets(lock/unlock)=12859247/574102
cases: anon=20680175, anoncow=3225049, obj=11467884, prcopy=1391019,
przero
=36545783
  daemon and swap counts:
woke=6868, revs=6246, scans=3525644, obscans=511526, anscans=2930634
busy=0, freed=1973275, reactivate=83484, deactivate=3941988
pageouts=94506, pending=94506, nswget=949421
nswapdev=1
swpages=4194415, swpginuse=621, swpgonly=0 paging=0
  kernel pointers:
objs(kern)=0x8c3ca94c



Re: Prevent off-by-one accounting hang in out-of-swap situations

2023-10-26 Thread Miod Vallat
> I wonder if the diff below makes a difference.  It's hard to debug and it
> might be worth adding a counter for bad swap slots.

It did not help (but your diff is probably correct).

> Index: uvm/uvm_anon.c
> ===
> RCS file: /cvs/src/sys/uvm/uvm_anon.c,v
> retrieving revision 1.56
> diff -u -p -r1.56 uvm_anon.c
> --- uvm/uvm_anon.c2 Sep 2023 08:24:40 -   1.56
> +++ uvm/uvm_anon.c22 Oct 2023 21:27:42 -
> @@ -116,7 +116,7 @@ uvm_anfree_list(struct vm_anon *anon, st
>   uvm_unlock_pageq(); /* free the daemon */
>   }
>   } else {
> - if (anon->an_swslot != 0) {
> + if (anon->an_swslot != 0 && anon->an_swslot != SWSLOT_BAD) {
>   /* This page is no longer only in swap. */
>   KASSERT(uvmexp.swpgonly > 0);
>   atomic_dec_int(&uvmexp.swpgonly);



ld.so and ldconfig manpage nits

2020-05-08 Thread Miod Vallat
This ensures consistent spelling of set-{user,group}-ID, and also
mentions LD_DEBUG is ignored by ld.so for such binaries.

Index: ld.so.1
===
RCS file: /OpenBSD/src/libexec/ld.so/ld.so.1,v
retrieving revision 1.23
diff -u -p -r1.23 ld.so.1
--- ld.so.1 14 Feb 2019 07:26:31 -  1.23
+++ ld.so.1 8 May 2020 09:11:30 -
@@ -161,6 +161,7 @@ are recognised and have their usual mean
 When set, be verbose about what
 .Nm
 does.
+This variable is ignored for set-user-ID and set-group-ID executables.
 .El
 .Sh FILES
 .Bl -tag -width /var/run/ld.so.hintsXXX -compact
Index: ldconfig/ldconfig.8
===
RCS file: /OpenBSD/src/libexec/ld.so/ldconfig/ldconfig.8,v
retrieving revision 1.29
diff -u -p -r1.29 ldconfig.8
--- ldconfig/ldconfig.8 4 Jul 2016 20:56:50 -   1.29
+++ ldconfig/ldconfig.8 8 May 2020 09:11:30 -
@@ -120,9 +120,7 @@ Switch on verbose mode.
 .El
 .Sh SECURITY
 Special care must be taken when loading shared libraries into the address
-space of
-.Ev set-user-Id
-programs.
+space of set-user-ID and set-group-ID programs.
 Whenever such a program is run,
 .Xr ld.so 1
 will only load shared libraries from the
@@ -141,7 +139,7 @@ It is presumed that the set of directori
 .Nm
 are under control of the system's administrator.
 .Xr ld.so 1
-further assists set-user-Id programs by erasing the
+further assists set-user-ID and set-group-ID programs by erasing the
 .Ev LD_LIBRARY_PATH
 from the environment.
 .Sh ENVIRONMENT



Re: Code changes for clarity

2020-05-18 Thread Miod Vallat


> For instance, in the wsdisplay_emulops structure, there are:
>
> int   (*alloc_attr)(void *c, int fg, int bg, int flags, long *attrp);
> void  (*unpack_attr)(void *c, long attr, int *fg, int *bg, int *ul);
>
> And at the end of the structure is this comment, showing that at
> least someone (other than me) was confused by it:
>   /* XXX need a free_attr() ??? */

`alloc_attr' was named that way because there was a theoretical
possibility that drivers would actually need to allocate storage for
attribute-related information (which is why attributes are longs rather
than uint32_t). A `free_attr' routine would then make sense, except that
there is no clear lifetime for attributes (e.g. the kernel messages
attribute has to survive free_screen).

Since in practice, no driver actually allocates anything and all
attributes fit in either 8 bits (vga text mode) or 32 bits (rasops), it
would make sense to rename this function to `compute_attr' or
`pack_attr' and narrow the attribute type from `long' to `uint32_t'.

$.02

Miod



Re: Increase default number of devices created for LDOMs on sparc64

2020-05-18 Thread Miod Vallat


> Learning how LDOMs work on this T4-1 and we only create 8 devices
> (each /dev/ldom* and /dev/ttyV*) by default. The now-commonly-available
> T4-1 machines can do far more than that pretty easily, so bump up the
> number created by default from 8 to 16.
>
> ok?

MAKEDEV is a generated file. Edit the second-to-last line of MAKEDEV.md
to add the extra 8 nodes.



tcpdump gtp bugfix

2020-05-19 Thread Miod Vallat
There seems to be a logic error in tcpdump's print-gtp.c.

The code is printing some values by passing a pointer to the array of
strings, and the index within the array, and the routine uses
sizeof(array) / sizeof(array[0]) to figure out the bound.

But since the caller is passing a pointer, sizeof returns the size of
the pointer and not of the array itself (and clang will rightfully warn
about this).

The right fix is to have the caller pass the upper bound.

Suggested fix below.

Index: print-gtp.c
===
RCS file: /OpenBSD/src/usr.sbin/tcpdump/print-gtp.c,v
retrieving revision 1.11
diff -u -p -r1.11 print-gtp.c
--- print-gtp.c 22 Oct 2018 16:12:45 -  1.11
+++ print-gtp.c 1 May 2020 09:37:58 -
@@ -57,12 +57,16 @@
 #include "interface.h"
 #include "gtp.h"
 
+#ifndef nitems
+#define nitems(_a)  (sizeof((_a)) / sizeof((_a)[0]))
+#endif
+
 void   gtp_print(const u_char *, u_int, u_short, u_short);
 void   gtp_decode_ie(const u_char *, u_short, int);
 void   gtp_print_tbcd(const u_char *, u_int);
 void   gtp_print_user_address(const u_char *, u_int);
 void   gtp_print_apn(const u_char *, u_int);
-void   gtp_print_str(const char **, u_int);
+void   gtp_print_str(const char **, u_int, u_int);
 
 void   gtp_v0_print(const u_char *, u_int, u_short, u_short);
 void   gtp_v0_print_prime(const u_char *);
@@ -466,10 +470,9 @@ gtp_print_apn(const u_char *cp, u_int le
 
 /* Print string from array. */
 void
-gtp_print_str(const char **strs, u_int index)
+gtp_print_str(const char **strs, u_int bound, u_int index)
 {
-
-   if (index >= (sizeof(*strs) / sizeof(*strs[0])))
+   if (index >= bound)
printf(": %u", index);
else if (strs[index] != NULL)
printf(": %s", strs[index]);
@@ -727,7 +730,8 @@ gtp_v0_print_tv(const u_char *cp, u_int 
/* 12.15 7.3.4.5.3 - Packet Transfer Command. */
TCHECK2(cp[0], GTPV0_TV_PACKET_XFER_CMD_LENGTH - 1);
printf("Packet Transfer Command");
-   gtp_print_str(gtp_packet_xfer_cmd, cp[0]);
+   gtp_print_str(gtp_packet_xfer_cmd, nitems(gtp_packet_xfer_cmd),
+   cp[0]);
ielen = GTPV0_TV_PACKET_XFER_CMD_LENGTH;
break;

@@ -1315,7 +1319,8 @@ gtp_v1_print_tv(const u_char *cp, u_int 
/* 32.295 6.2.4.5.2 - Packet Transfer Command. */
TCHECK2(cp[0], GTPV1_TV_PACKET_XFER_CMD_LENGTH - 1);
printf("Packet Transfer Command");
-   gtp_print_str(gtp_packet_xfer_cmd, cp[0]);
+   gtp_print_str(gtp_packet_xfer_cmd, nitems(gtp_packet_xfer_cmd),
+   cp[0]);
ielen = GTPV1_TV_PACKET_XFER_CMD_LENGTH;
break;
 
@@ -1515,7 +1520,7 @@ gtp_v1_print_tlv(const u_char *cp, u_int
 
/* 29.060 7.7.50 - RAT Type. */
printf("RAT");
-   gtp_print_str(gtp_rat_type, cp[0]);
+   gtp_print_str(gtp_rat_type, nitems(gtp_rat_type), cp[0]);
break;
 
case GTPV1_TLV_USER_LOCATION_INFO:
@@ -1607,7 +1612,8 @@ gtp_v1_print_tlv(const u_char *cp, u_int
 
/* 29.060 7.7.66 - MBMS 2G/3G Indicator. */
printf("MBMS 2G/3G Indicator");
-   gtp_print_str(mbms_2g3g_indicator, cp[0]);
+   gtp_print_str(mbms_2g3g_indicator, nitems(mbms_2g3g_indicator),
+   cp[0]);
break;
 
case GTPV1_TLV_ENHANCED_NSAPI:
@@ -1697,7 +1703,8 @@ gtp_v1_print_tlv(const u_char *cp, u_int
 
/* 29.060 7.7.80 - MS Info Change Reporting. */
printf("MS Info Change Reporting");
-   gtp_print_str(ms_info_change_rpt, cp[0]);
+   gtp_print_str(ms_info_change_rpt, nitems(ms_info_change_rpt),
+   cp[0]);
break;
 
case GTPV1_TLV_DIRECT_TUNNEL_FLAGS:



Re: sparc64 boot issue on qemu

2020-05-30 Thread Miod Vallat
Yet another case where the emulator does not match the real hardware.

Why bother with them?

Get qemu to fix their shit so that the frame buffer metrics variable are
aligned on 64-bit boundaries. There might not be a written specification
for this requirement, but that's the way real hardware behaves, and it
makes complete sense (the variables are OFW cells, which are 64-bit
values and 64-bit aligned).

If you really want to accomodate their broken firmware, you can avoid
using memcpy by relying upon sparc64 being big-endian and do something
like:

-   *fontwidth = (int)*(uint64_t *)romwidth;
-   *fontheight = (int)*(uint64_t *)romheight;
-   *wtop = (int)*(uint64_t *)windowtop;
-   *wleft = (int)*(uint64_t *)windowleft;
+   *fontwidth = *(uint32_t *)(romwidth + 4);
+   *fontheight = *(uint32_t *)(romheight + 4);
+   *wtop = *(uint32_t *)(windowtop + 4);
+   *wleft = *(uint32_t *)(windowleft + 4);

Miod



Re: powerpc64: ldbrx/stdbrx for endian.h?

2020-06-08 Thread Miod Vallat


> There is an interest in supporting PowerPC 970 ("G5").  That would
> allow people to use more than 2G of RAM on the last generations of
> Apple PowerMac machines.  Otherwise I don't think we are interested in
> anything before POWER8.

Years ago, a decision was made to ditch 64-bit PA-RISC (mostly because
toolchain limitations for 64-bit userland) and keep running a 32-bit
kernels on 64-bit PA-RISC systems with a 32-bit PDC.

Before that, mickey@ was adamant that earlier hppa64 systems (pre-astro)
with 32-bit PCI busses and no way to have more than 2GB of memory (such
as C240) were not worth supporting in 64-bit mode.

At about the same time, it was also decided that G5 systems with more
than 2 or 3 GB of memory were rare enough not to be worth supporting in
64-bit mode.

Given the current "3GHz and gobs of ram or dust" party's line those days,
I don't see a point in attempting to support G5 systems in 64-bit mode,
if this seriously impacts support for sexier^Wmore modern designs.



Re: symmetric toeplitz hashing

2020-06-14 Thread Miod Vallat


>> Others have pointed out off-list that one can use __builtin_popcount(),
>> but __builtin_parity() is exactly what I want. Is it available on all
>> architectures?
>
> I don't think it is available on gcc 3.x for m88k but someone with
> an m88k should confirm.

__builtin_popcount() does not exist in gcc 3.



dead clock functions

2021-04-21 Thread Miod Vallat
The todr_handle struct contains two unused function pointers, which are
either not implemented or with clones of eopnotsupp(). The following
diff removes this waste of kernel text.

Index: arch/sparc64/dev/rtc.c
===
RCS file: /OpenBSD/src/sys/arch/sparc64/dev/rtc.c,v
retrieving revision 1.10
diff -u -p -r1.10 rtc.c
--- arch/sparc64/dev/rtc.c  11 Jul 2014 08:18:31 -  1.10
+++ arch/sparc64/dev/rtc.c  21 Apr 2021 19:24:32 -
@@ -119,8 +119,6 @@ int rtc_gettime(todr_chip_handle_t, stru
 int rtc_settime(todr_chip_handle_t, struct timeval *);
 int rtc_bq4802_gettime(todr_chip_handle_t, struct timeval *);
 int rtc_bq4802_settime(todr_chip_handle_t, struct timeval *);
-int rtc_getcal(todr_chip_handle_t, int *);
-int rtc_setcal(todr_chip_handle_t, int);
 
 int
 rtc_match(struct device *parent, void *cf, void *aux)
@@ -166,8 +164,6 @@ rtc_attach(struct device *parent, struct
handle->cookie = sc;
handle->todr_gettime = rtc_gettime;
handle->todr_settime = rtc_settime;
-   handle->todr_getcal = rtc_getcal;
-   handle->todr_setcal = rtc_setcal;
 
handle->bus_cookie = NULL;
handle->todr_setwen = NULL;
@@ -403,16 +399,4 @@ rtc_bq4802_settime(todr_chip_handle_t ha
csr &= ~BQ4802_UTI;
bus_space_write_1(iot, ioh, BQ4802_CTRL, csr);
return (0);
-}
-
-int
-rtc_getcal(todr_chip_handle_t handle, int *vp)
-{
-   return (EOPNOTSUPP);
-}
-
-int
-rtc_setcal(todr_chip_handle_t handle, int v)
-{
-   return (EOPNOTSUPP);
 }
Index: dev/clock_subr.h
===
RCS file: /OpenBSD/src/sys/dev/clock_subr.h,v
retrieving revision 1.6
diff -u -p -r1.6 clock_subr.h
--- dev/clock_subr.h17 May 2020 13:21:20 -  1.6
+++ dev/clock_subr.h21 Apr 2021 19:24:32 -
@@ -35,8 +35,6 @@
  *
  * todr_gettime: convert time-of-day clock into a `struct timeval'
  * todr_settime: set time-of-day clock from a `struct timeval'
- * todr_getcal: get current TOD clock calibration value in ppm
- * todr_setcal: set calibration value in ppm in TOD clock
  *
  * (this is probably not so useful:)
  * todr_setwen: provide a machine-dependent TOD clock write-enable callback
@@ -49,16 +47,12 @@ struct todr_chip_handle {
 
int (*todr_gettime)(struct todr_chip_handle *, struct timeval *);
int (*todr_settime)(struct todr_chip_handle *, struct timeval *);
-   int (*todr_getcal)(struct todr_chip_handle *, int *);
-   int (*todr_setcal)(struct todr_chip_handle *, int);
int (*todr_setwen)(struct todr_chip_handle *, int);
 };
 typedef struct todr_chip_handle *todr_chip_handle_t;
 
 #define todr_gettime(ct, t)((*(ct)->todr_gettime)(ct, t))
 #define todr_settime(ct, t)((*(ct)->todr_settime)(ct, t))
-#define todr_getcal(ct, vp)((*(ct)->todr_gettime)(ct, vp))
-#define todr_setcal(ct, v) ((*(ct)->todr_settime)(ct, v))
 #define todr_wenable(ct, v)if ((ct)->todr_setwen) \
((*(ct)->todr_setwen)(ct, v))
 
Index: dev/fdt/sxirtc.c
===
RCS file: /OpenBSD/src/sys/dev/fdt/sxirtc.c,v
retrieving revision 1.4
diff -u -p -r1.4 sxirtc.c
--- dev/fdt/sxirtc.c11 Aug 2019 14:46:18 -  1.4
+++ dev/fdt/sxirtc.c21 Apr 2021 19:24:32 -
@@ -146,8 +146,6 @@ sxirtc_attach(struct device *parent, str
handle->cookie = self;
handle->todr_gettime = sxirtc_gettime;
handle->todr_settime = sxirtc_settime;
-   handle->todr_getcal = NULL;
-   handle->todr_setcal = NULL;
handle->bus_cookie = NULL;
handle->todr_setwen = NULL;
todr_handle = handle;
Index: dev/i2c/ds1307.c
===
RCS file: /OpenBSD/src/sys/dev/i2c/ds1307.c,v
retrieving revision 1.2
diff -u -p -r1.2 ds1307.c
--- dev/i2c/ds1307.c27 Apr 2020 12:41:44 -  1.2
+++ dev/i2c/ds1307.c21 Apr 2021 19:24:32 -
@@ -72,8 +72,6 @@ int   maxrtc_enable_osc(struct maxrtc_soft
 intmaxrtc_set_24h_mode(struct maxrtc_softc *);
 intmaxrtc_gettime(struct todr_chip_handle *, struct timeval *);
 intmaxrtc_settime(struct todr_chip_handle *, struct timeval *);
-intmaxrtc_getcal(struct todr_chip_handle *, int *);
-intmaxrtc_setcal(struct todr_chip_handle *, int);
 
 /*
  * Driver glue structures.
@@ -114,8 +112,6 @@ maxrtc_attach(struct device *parent, str
sc->sc_todr.cookie = sc;
sc->sc_todr.todr_gettime = maxrtc_gettime;
sc->sc_todr.todr_settime = maxrtc_settime;
-   sc->sc_todr.todr_getcal = maxrtc_getcal;
-   sc->sc_todr.todr_setcal = maxrtc_setcal;
sc->sc_todr.todr_setwen = NULL;
 
if (maxrtc_enable_osc(sc) == -1)
@@ -275,16 +271,4 @@ maxrtc_settime(struct todr_chip_handle *
}
 
return (0);
-}
-
-int
-maxrtc_getcal(struct todr_chip_handle *ch, 

remove gccism from com(4)

2021-05-06 Thread Miod Vallat
`return f()' when f is a void function is not allowed by the C standard
but is a gcc extension.

Index: com.c
===
RCS file: /OpenBSD/src/sys/dev/ic/com.c,v
retrieving revision 1.173
diff -u -p -r1.173 com.c
--- com.c   14 Aug 2020 18:14:11 -  1.173
+++ com.c   6 May 2021 19:55:13 -
@@ -1609,9 +1609,9 @@ com_write_reg(struct com_softc *sc, bus_
reg <<= sc->sc_reg_shift;
 
if (sc->sc_reg_width == 4)
-   return bus_space_write_4(sc->sc_iot, sc->sc_ioh, reg, value);
+   bus_space_write_4(sc->sc_iot, sc->sc_ioh, reg, value);
else
-   return bus_space_write_1(sc->sc_iot, sc->sc_ioh, reg, value);
+   bus_space_write_1(sc->sc_iot, sc->sc_ioh, reg, value);
 }
 
 #ifdef COM_CONSOLE
@@ -1636,9 +1636,9 @@ comcn_write_reg(bus_size_t reg, uint8_t 
reg <<= comcons_reg_shift;
 
if (comcons_reg_width == 4)
-   return bus_space_write_4(comconsiot, comconsioh, reg, value);
+   bus_space_write_4(comconsiot, comconsioh, reg, value);
else
-   return bus_space_write_1(comconsiot, comconsioh, reg, value);
+   bus_space_write_1(comconsiot, comconsioh, reg, value);
 }
 
 #endif



fix isascii(3) manpage

2021-06-11 Thread Miod Vallat
All the is*() ctype.h functions take an int as argument, but valid
values are only EOF, and the range of values of `unsigned char'.

All, but one: the XPG4 isascii(), which has no such restriction.
Quoting https://pubs.opengroup.org/onlinepubs/9699919799/ :
``The isascii() function is defined on all integer values.''

Hence the following diff.

Index: isascii.3
===
RCS file: /OpenBSD/src/lib/libc/gen/isascii.3,v
retrieving revision 1.13
diff -u -p -r1.13 isascii.3
--- isascii.3   17 Jul 2013 05:42:11 -  1.13
+++ isascii.3   11 Jun 2021 09:54:13 -
@@ -77,11 +77,3 @@ The
 .Fn isascii
 function first appeared in
 .At v7 .
-.Sh CAVEATS
-The argument to
-.Fn isascii
-must be
-.Dv EOF
-or representable as an
-.Li unsigned char ;
-otherwise, the result is undefined.



[sparc64] dead code in emul.c

2018-08-07 Thread Miod Vallat
emul.c r1.19 removed a bunch of code, but not enough, and left dead code
around.

Index: emul.c
===
RCS file: /OpenBSD/src/sys/arch/sparc64/sparc64/emul.c,v
retrieving revision 1.23
diff -u -p -r1.23 emul.c
--- emul.c  16 Nov 2014 12:30:59 -  1.23
+++ emul.c  6 Aug 2018 20:11:00 -
@@ -49,13 +49,9 @@
 
 #define GPR(tf, i) ((int32_t *)(u_long)&tf->tf_global)[i]
 #define IPR(tf, i) ((int32_t *)(u_long)tf->tf_out[6])[i - 16]
-#define FPR(p, i)  ((int32_t) p->p_md.md_fpstate->fs_regs[i])
-#define FPRSET(p, i, v)p->p_md.md_fpstate->fs_regs[i] = (v)
 
 static __inline int readgpreg(struct trapframe64 *, int, void *);
-static __inline int readfpreg(struct proc *, int, void *);
 static __inline int writegpreg(struct trapframe64 *, int, const void *);
-static __inline int writefpreg(struct proc *, int, const void *);
 static __inline int decodeaddr(struct trapframe64 *, union instr *, void *);
 static int muldiv(struct trapframe64 *, union instr *, int32_t *, int32_t *,
 int32_t *);
@@ -81,7 +77,6 @@ readgpreg(tf, i, val)
return error;
 }
 
-   
 static __inline int
 writegpreg(tf, i, val)
struct trapframe64 *tf;
@@ -99,28 +94,6 @@ writegpreg(tf, i, val)
error = copyout((caddr_t) val, &IPR(tf, i), sizeof(int32_t));
 
return error;
-}
-   
-
-static __inline int
-readfpreg(p, i, val)
-   struct proc *p;
-   int i;
-   void *val;
-{
-   *(int32_t *) val = FPR(p, i);
-   return 0;
-}
-
-   
-static __inline int
-writefpreg(p, i, val)
-   struct proc *p;
-   int i;
-   const void *val;
-{
-   FPRSET(p, i, *(const int32_t *) val);
-   return 0;
 }
 
 static __inline int



Re: re-enable -Wshadow for openssl(1)?

2018-08-23 Thread Miod Vallat


> The -Wshadow warning was briefly enabled, but it turned out to break vax
> builds with gcc3. Among other things, this warning helps catching stupid
> mistakes in refactoring early, so I was wondering whether we could
> re-enable it. The commit that disabled it also mentions gcc3, so I'm
> unsure whether luna88k would be affected by this.

gcc3 will warn like this:

  In file included from /usr/src/usr.bin/openssl/apps.h:117,
   from /usr/src/usr.bin/openssl/apps.c:138:
  /usr/include/openssl/bio.h:342: warning: declaration of `write' shadows a 
global declaration
  /usr/include/unistd.h:374: warning: shadowed declaration is here

This is caused by the BIO_meth_*() prototypes using formal parameters
nawed `read', `puts', etc.

Alternatively, you may choose to enable -Wshadow only if building with a
non-gcc3 toolchain.



Remove debug options in hppa GENERIC

2018-11-03 Thread Miod Vallat
The hppa GENERIC kernel contains various debug options for pcmcia and
cardbus code. None of the other platforms enables these options in
GENERIC.

Index: sys/arch/hppa/conf/GENERIC
===
RCS file: /OpenBSD/src/sys/arch/hppa/conf/GENERIC,v
retrieving revision 1.177
diff -u -p -u -p -r1.177 GENERIC
--- sys/arch/hppa/conf/GENERIC  22 Aug 2018 15:38:46 -  1.177
+++ sys/arch/hppa/conf/GENERIC  3 Nov 2018 13:54:34 -
@@ -78,9 +78,8 @@ lpt0  at ssio?
 # CardBus bus support
 cbb*   at pci?
 cardslot*  at cbb?
-option CARDBUS_DEBUG,CARDSLOT_DEBUG,CARDBUS_MAP_DEBUG
 cardbus*   at cardslot?
-option PCMCIADEBUG,PCMCIAVERBOSE
+option PCMCIAVERBOSE
 pcmcia*at cardslot?
 
 # PCI USB Controllers



hppa minor cleanup

2018-11-15 Thread Miod Vallat
In the never ending story of "encoding of diag instructions is hard,
let's go shopping" (as shown by at least rev 1.65, 1.66 and 1.189 of
hppa locore.S), the following diff attempts to clean and fix things for
good:
  - macros get a cpu-family suffix, since encoding differ accross
processor families.
  - source of the information, when known, is mentioned.
  - two unused routines get removed.

This does not change anything in the object code, as the remaining wrong
encodings were only used in pbtlb_l which has not been used for ages.

Index: hppa/locore.S
===
RCS file: /OpenBSD/src/sys/arch/hppa/hppa/locore.S,v
retrieving revision 1.199
diff -u -p -r1.199 locore.S
--- hppa/locore.S   16 Jul 2017 22:47:37 -  1.199
+++ hppa/locore.S   15 Nov 2018 20:25:21 -
@@ -76,16 +76,23 @@
 #include "assym.h"
 
 /*
- * hv-specific instructions
+ * hw-specific instructions
  */
-#defineDR_PAGE0.word   0x14001200
-#defineDR_PAGE1.word   0x14001240
-#defineMTCPU_T(x,t).word   0x14001600 | ((t) << 21) | ((x) << 16)
-#defineMFCPU_T(r,x).word   0x14001a00 | ((r) << 21) | ((x) << 16)
-#defineMTCPU_C(x,t).word   0x14000240 | ((t) << 21) | ((x) << 16)
-#defineMFCPU_C(r,x).word   0x14000600 | ((r) << 21) | ((x) << 16)
-#defineMFCPU_U(r,x).word   0x140008a0 | ((r) << 21) | ((x))
-#defineMTCPU_U(x,r).word   0x14001840 | ((r) << 21) | ((x) << 16)
+
+/* source: mklinux cache.s */
+#defineMFCPU_C_PCXST(r,x)  .word   0x14001a00 | ((r) << 21) | ((x) 
<< 16)
+#defineMTCPU_PCXST(x,r).word   0x14001600 | ((r) << 21) | ((x) 
<< 16)
+
+/* source: PCXL and PCXL2 ERS */
+/* Use MFCPU_C for DR0-8; MFCPU_T for DR25,27,28,29 */
+#defineMFCPU_C_PCXL(r,x)   .word   0x14000600 | ((r) << 21) | ((x) 
<< 16)
+#defineMFCPU_T_PCXL(r,x)   .word   0x14001800 | ((r) << 21) | ((x))
+#defineMTCPU_PCXL(x,r) .word   0x14000240 | ((r) << 21) | ((x) 
<< 16)
+#defineDR_PAGE0_PCXL   .word   0x14000e00
+#defineDR_PAGE1_PCXL   .word   0x14000e40
+
+#defineMFCPU_PCXU(r,x) .word   0x140008a0 | ((r) << 21) | ((x))
+#defineMTCPU_PCXU(x,r) .word   0x14001840 | ((r) << 21) | ((x) 
<< 16)
 
.import $global$, data
.import pdc, data
@@ -1646,8 +1653,8 @@ EXIT(TLABEL(all))
  */
 LEAF_ENTRY(desidhash_s)
sync
-   MFCPU_T(DR_CPUCFG,22)   /* t1 */
-   MFCPU_T(DR_CPUCFG,22)
+   MFCPU_C_PCXST(DR_CPUCFG,22) /* t1 */
+   MFCPU_C_PCXST(DR_CPUCFG,22)
nop
nop
depi0, DR0_PCXS_DHE, 3, t1  /* 3: DR0_PCXS_DOMAIN|DR0_PCXS_IHE */
@@ -1656,8 +1663,8 @@ LEAF_ENTRY(desidhash_s)
depi0, DR0_PCXS_DHPMC, 1, t1
depi0, DR0_PCXS_ILPMC, 1, t1
sync
-   MTCPU_T(22,DR_CPUCFG)
-   MTCPU_T(22,DR_CPUCFG)
+   MTCPU_PCXST(22,DR_CPUCFG)
+   MTCPU_PCXST(22,DR_CPUCFG)
nop
nop
bv  0(rp)
@@ -1671,8 +1678,8 @@ EXIT(desidhash_s)
  */
 LEAF_ENTRY(desidhash_t)
sync
-   MFCPU_T(DR_CPUCFG,22)   /* t1 */
-   MFCPU_T(DR_CPUCFG,22)
+   MFCPU_C_PCXST(DR_CPUCFG,22) /* t1 */
+   MFCPU_C_PCXST(DR_CPUCFG,22)
nop
nop
depi0, DR0_PCXT_IHE, 1, t1
@@ -1681,8 +1688,8 @@ LEAF_ENTRY(desidhash_t)
depi0, DR0_PCXT_DHPMC, 1, t1
depi0, DR0_PCXT_ILPMC, 1, t1
sync
-   MTCPU_T(22,DR_CPUCFG)
-   MTCPU_T(22,DR_CPUCFG)
+   MTCPU_PCXST(22,DR_CPUCFG)
+   MTCPU_PCXST(22,DR_CPUCFG)
nop
nop
bv  0(rp)
@@ -1697,7 +1704,7 @@ LEAF_ENTRY(eaio_l2)
ldilL%eaio_l2_mask, t2
ldw R%eaio_l2_mask(t2), t1
or  t1, arg0, t1
-   MTCPU_C(22, DR0_PCXL2_ACCEL_IO)
+   MTCPU_PCXL(22, DR0_PCXL2_ACCEL_IO)
nop
nop
bv  0(rp)
@@ -1719,54 +1726,11 @@ LEAF_ENTRY(ibtlb_l)
mtsmt4
 EXIT(ibtlb_l)
 
-/* hpti_l(addr,size) */
-LEAF_ENTRY(hpti_l)
-   ldo -1(arg1), arg1
-   depi0, 31, 12, arg1
-   ldi 0x1c0, t1   /* cache size assumed 128k XXX */
-   or  arg0, t1, arg0
-   sync
-   MTCPU_C(26,DR0_PCXL2_HTLB_ADDR)
-   MTCPU_C(25,DR0_PCXL2_HTLB_CFG)
-   nop
-   nop
-   bv,nr0(rp)
-   nop
-EXIT(hpti_l)
-
-/*
- * int
- * pbtlb_l(int i)
- */
-LEAF_ENTRY(pbtlb_l)
-   ; DR_PAGE0
-   rsm (PSL_R|PSL_I), t4
-   nop ! nop ! nop ! nop
-   ldilL%0xc041, t1
-   ldo R%0xc041(t1), t1
-   dep arg0, 30, 3, t1
-   sync
-   MTCPU_T(22,DR_DTLB) /* t1 */
-   nop
-   nop
-   mtspr0, sr1
-   idtlba  r0,(sr1,r0)
-   idtlbp  r0,(sr1,r0)
-   zdepi   -1, 18, 1, t1
-   nop
-   sync
-   MTCPU_T(22,DR_DTLB)
-   nop
-   nop
-   bv  0(rp)
-   mtsmt4
-EXIT(pbtlb_l

SGI O2 mec(4) cold boot issue (and workaround)

2018-12-08 Thread Miod Vallat
I have noticed, for a while, that my O2 systems were horribly slow
during installs or upgrades, when fetching sets from the network (28
*minutes* to fetch base64.tgz).

At first, I thought this was a bsd.rd specific bug, but couldn't find
anything obvious. After gathering enough data, I found out that the
problem only occurs on a cold boot. After a reboot, the network
performance is as good as it can be. That would explain why I would only
notice it during upgrades.

I also noticed that, on a warm boot, the dmesg would show:

mec0 at macebus0 base 0x0028 irq 3: MAC-110 rev 1, address 08:00:69:0e:bf:a1
nsphy0 at mec0 phy 8: DP83840 10/100 PHY, rev. 1

but on cold boots, it would show:

mec0 at macebus0 base 0x0028 irq 3: MAC-110 rev 1, address 08:00:69:0e:bf:a1
nsphy0 at mec0 phy 10: DP83840 10/100 PHY, rev. 1

Note that, in these cases, the phy seems to attach to a different
address. In these cases, after booting, "ifconfig mec0" would show:

mec0: flags=8843 mtu 1500
lladdr 08:00:69:0e:bf:a1
llprio 3
media: Ethernet autoselect
status: active
inet 10.0.1.193 netmask 0xff00 broadcast 10.255.255.255

while one would expect the "media" line to be similar to:

media: Ethernet autoselect (100baseTX full-duplex)

Investigating further, it seems that, after a cold boot, the MII bus
takes some time to initialize; the phy does not answer to address 8 but
to a larger address (10 or 11), then, after being reset, to its correct
address of 8.

So the kernel would discover the phy at a wrong address, attach it, and
after it gets reset, reading from the phy at the wrong address would
return either all bits clear or all bits set, confusing the link speed
logic without any way to recover.

What I tried but did not work:
- invoking mii_attach() twice in the mec driver. This would attach nsphy
  twice, once at the wrong address, then once at the correct address,
  but the first (wrong) attachment would be preferred.
- adding a one second delay between the Ethernet interface reset and
  mii_attach(). This would work most of the time, but not always.

What I tried and works:
- the first time the interface is reset, the mii bus is walked and all
  phys found on it are reset. Thus, by the time mii_attach() runs and
  walks the bus again, the phy will answer at the right address.

The diff below implements this (last chunk of if_mec.c), and also cleans
the mii read/write routines a bit (all the other chunks).

Tested on three different R5K family O2 systems, which have all been
exposing that problem on cold boot.

Index: dev/if_mec.c
===
RCS file: /OpenBSD/src/sys/arch/sgi/dev/if_mec.c,v
retrieving revision 1.37
diff -u -p -r1.37 if_mec.c
--- dev/if_mec.c22 Jan 2017 10:17:37 -  1.37
+++ dev/if_mec.c8 Dec 2018 15:00:04 -
@@ -264,7 +264,6 @@ struct mec_softc {
bus_dma_tag_t sc_dmat;  /* bus_dma tag. */
 
struct mii_data sc_mii; /* MII/media information. */
-   int sc_phyaddr; /* MII address. */
struct timeout sc_tick_ch;  /* Tick timeout. */
 
bus_dmamap_t sc_cddmamap;   /* bus_dma map for control data. */
@@ -329,7 +328,7 @@ voidmec_start(struct ifnet *);
 void   mec_watchdog(struct ifnet *);
 void   mec_tick(void *);
 intmec_ioctl(struct ifnet *, u_long, caddr_t);
-void   mec_reset(struct mec_softc *);
+void   mec_reset(struct mec_softc *, int);
 void   mec_iff(struct mec_softc *);
 intmec_intr(void *arg);
 void   mec_stop(struct ifnet *);
@@ -422,7 +421,7 @@ mec_attach(struct device *parent, struct
enaddr_aton(bios_enaddr, sc->sc_ac.ac_enaddr);
 
/* Reset device. */
-   mec_reset(sc);
+   mec_reset(sc, 1);
 
command = bus_space_read_8(sc->sc_st, sc->sc_sh, MEC_MAC_CONTROL);
 
@@ -451,7 +450,6 @@ mec_attach(struct device *parent, struct
ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER | IFM_MANUAL);
} else {
ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER | IFM_AUTO);
-   sc->sc_phyaddr = child->mii_phy;
}
 
bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
@@ -499,21 +497,19 @@ mec_mii_readreg(struct device *self, int
struct mec_softc *sc = (void *)self;
bus_space_tag_t st = sc->sc_st;
bus_space_handle_t sh = sc->sc_sh;
-   uint32_t val;
+   uint64_t val;
int i;
 
if (mec_mii_wait(sc) != 0)
return 0;
 
-   bus_space_write_4(st, sh, MEC_PHY_ADDRESS,
+   bus_space_write_8(st, sh, MEC_PHY_ADDRESS,
(phy << MEC_PHY_ADDR_DEVSHIFT) | (reg & MEC_PHY_ADDR_REGISTER));
bus_space_write_8(st, sh, MEC_PHY_READ_INITIATE, 1);
-   delay(25);
 
for (i = 0; i < 20; i++) {
-   delay(30);
-
-   val = bus_space_read_4(st, sh, MEC_PHY_DATA);
+   delay(25);
+   val = bu

Re: kubsan tcp timer shift

2022-01-20 Thread Miod Vallat
> An unsinged TF_TIMER does not create that problem.

Why don't you simply append an U suffix to TF_TMR_REXMT?



Re: kubsan tcp timer shift

2022-01-21 Thread Miod Vallat
> Sounds like a call for the huge U change.

Since none of these #define seem to be used by .S files, go for it. We
don't really want to bring Mach's U() macro back.



in4_cksum changes, step 1

2022-01-25 Thread Miod Vallat
in4_cksum(), used to compute packet checksums for the legacy internet
protocol, has been hand-optimized for speed on most elderly platforms,
with the most recent pieces of silicon using a portable C
implementation.

Most of these implementations, in a not-so-uncommon case, need to
checksum an extra (``overlay'') header, and invoke memset or bzero on
such an overlay, prior to initializing it and checksumming it.

However, except for one byte, the zeroed parts are useless since they
will not change the checksum, so that memset/bzero call can be removed,
and the sum can omit the first 8 bytes which will always be zero.

The following diff implements that idea. Plus on sparc64 you get one
useless assembly instruction removed, for free, isn't that awesome?

Affected platforms: alpha, amd64, arm64, hppa, landisk, luna88k, macppc,
octeon, powerpc64, riscv64, sparc64. No need to test on armv7 and i386.

Index: sys/arch/alpha/alpha/in_cksum.c
===
RCS file: /OpenBSD/src/sys/arch/alpha/alpha/in_cksum.c,v
retrieving revision 1.9
diff -u -p -r1.9 in_cksum.c
--- sys/arch/alpha/alpha/in_cksum.c 21 Aug 2014 14:24:08 -  1.9
+++ sys/arch/alpha/alpha/in_cksum.c 25 Jan 2022 20:21:06 -
@@ -212,14 +212,13 @@ in4_cksum(struct mbuf *m, u_int8_t nxt, 
panic("in4_cksum: bad mbuf chain");
 #endif
 
-   memset(&ipov, 0, sizeof(ipov));
-
-   ipov.ih_len = htons(len);
+   ipov.ih_x1[8] = 0;
ipov.ih_pr = nxt;
+   ipov.ih_len = htons(len);
ipov.ih_src = mtod(m, struct ip *)->ip_src;
ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
 
-   sum += in_cksumdata((caddr_t) &ipov, sizeof(ipov));
+   sum += in_cksumdata((caddr_t) &ipov + 8, sizeof(ipov) - 8);
}
 
/* skip over unnecessary part */
Index: sys/arch/m88k/m88k/in_cksum.c
===
RCS file: /OpenBSD/src/sys/arch/m88k/m88k/in_cksum.c,v
retrieving revision 1.4
diff -u -p -r1.4 in_cksum.c
--- sys/arch/m88k/m88k/in_cksum.c   21 Aug 2014 14:24:08 -  1.4
+++ sys/arch/m88k/m88k/in_cksum.c   25 Jan 2022 20:21:07 -
@@ -95,19 +95,22 @@ in4_cksum(struct mbuf *m, uint8_t nxt, i
 {
u_int16_t *w;
u_int sum = 0;
-   struct ipovly ipov;
+   union {
+   struct ipovly ipov;
+   u_int16_t w[10];
+   } u;
 
if (nxt != 0) {
/* pseudo header */
-   bzero(&ipov, sizeof(ipov));
-   ipov.ih_len = htons(len);
-   ipov.ih_pr = nxt; 
-   ipov.ih_src = mtod(m, struct ip *)->ip_src; 
-   ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
-   w = (u_int16_t *)&ipov;
-   /* assumes sizeof(ipov) == 20 */
-   sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3]; sum += w[4];
-   sum += w[5]; sum += w[6]; sum += w[7]; sum += w[8]; sum += w[9];
+   u.ipov.ih_x1[8] = 0; 
+   u.ipov.ih_pr = nxt; 
+   u.ipov.ih_len = htons(len);
+   u.ipov.ih_src = mtod(m, struct ip *)->ip_src; 
+   u.ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
+   w = u.w;
+   /* assumes sizeof(ipov) == 20 and first 8 bytes are zeroes */
+   sum += w[4]; sum += w[5]; sum += w[6];
+   sum += w[7]; sum += w[8]; sum += w[9];
}
 
/* skip unnecessary part */
Index: sys/arch/powerpc/powerpc/in_cksum.c
===
RCS file: /OpenBSD/src/sys/arch/powerpc/powerpc/in_cksum.c,v
retrieving revision 1.10
diff -u -p -r1.10 in_cksum.c
--- sys/arch/powerpc/powerpc/in_cksum.c 22 Jul 2014 10:35:35 -  1.10
+++ sys/arch/powerpc/powerpc/in_cksum.c 25 Jan 2022 20:21:07 -
@@ -254,15 +254,15 @@ in4_cksum(struct mbuf *m, uint8_t nxt, i
 
if (nxt != 0) {
/* pseudo header */
-   memset(&u.ipov, 0, sizeof(u.ipov));
-   u.ipov.ih_len = htons(len);
+   u.ipov.ih_x1[8] = 0;
u.ipov.ih_pr = nxt; 
+   u.ipov.ih_len = htons(len);
u.ipov.ih_src = mtod(m, struct ip *)->ip_src; 
u.ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
w = u.w;
-   /* assumes sizeof(ipov) == 20 */
-   sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3]; sum += w[4];
-   sum += w[5]; sum += w[6]; sum += w[7]; sum += w[8]; sum += w[9];
+   /* assumes sizeof(ipov) == 20 and first 8 bytes are zeroes */
+   sum += w[4]; sum += w[5]; sum += w[6];
+   sum += w[7]; sum += w[8]; sum += w[9];
}
 
/* skip unnecessary part */
Index: sys/arch/sparc64/sparc64/in4_cksum.c
===
RCS file

Re: passwd(1) does not need librpcsvc

2022-01-27 Thread Miod Vallat
> Hi,
> 
> linking with librpcsvc should be superfluous now.

Then you should also update DPADD to remove $(LIBRPCSVC}...

> Index: Makefile
> ===
> RCS file: /var/cvs/src/usr.bin/passwd/Makefile,v
> retrieving revision 1.41
> diff -u -p -r1.41 Makefile
> --- Makefile  26 Nov 2015 19:01:47 -  1.41
> +++ Makefile  27 Jan 2022 14:59:09 -
> @@ -7,7 +7,7 @@ SRCS= local_passwd.c passwd.c getpwent.c
>   pwd_check.c
>  .PATH:  ${.CURDIR}/../../lib/libc/gen
>  DPADD+= ${LIBRPCSVC} ${LIBUTIL}
> -LDADD+= -lrpcsvc -lutil
> +LDADD+= -lutil
>  CFLAGS+= -I${.CURDIR}
>  
>  CFLAGS+=-I${.CURDIR}/../../lib/libc/include
> 
> --
> Greetings Ben
> 



Re: in4_cksum changes, step 1

2022-01-30 Thread Miod Vallat
> > -   sum += in_cksumdata((caddr_t) &ipov, sizeof(ipov));
> > +   sum += in_cksumdata((caddr_t) &ipov + 8, sizeof(ipov) - 8);
> 
> I think this would be clearer with a comment.

Sure, added one.

> Please remove the trailing space that some of the changed lines have.

Ok. Updated patch below.

> > Index: sys/arch/sparc64/sparc64/in4_cksum.c

> > +   __asm volatile(
> > +   " lduw [%5 + 12], %1; "
> > +   " lduw [%5 + 16], %2; "
> > " mov -1, %3; add %0, %1, %0; "
> > " srl %3, 0, %3; add %0, %2, %0; "
> > -   " srlx %0, 32, %2; and %0, %3, %1; "
> > +   " srlx %0, 32, %2; "
> > " add %0, %2, %0; "
> > : "=r" (sum), "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3)
> > -   : "0" (sum), "r" (w));
> > +   : "0" (sum), "r" (&ipov));
> 
> I might be missing something, but is the temporary register %3 needed
> at all?

Yes, it is set to -1 and used for shifts, at the moment.

Miod

Index: sys/arch/alpha/alpha/in_cksum.c
===
RCS file: /OpenBSD/src/sys/arch/alpha/alpha/in_cksum.c,v
retrieving revision 1.9
diff -u -p -r1.9 in_cksum.c
--- sys/arch/alpha/alpha/in_cksum.c 21 Aug 2014 14:24:08 -  1.9
+++ sys/arch/alpha/alpha/in_cksum.c 30 Jan 2022 18:35:18 -
@@ -200,7 +200,7 @@ in4_cksum(struct mbuf *m, u_int8_t nxt, 
int clen = 0;
caddr_t addr;
union q_util q_util;
-   union l_util l_util; 
+   union l_util l_util;
struct ipovly ipov;
 
if (nxt != 0) {
@@ -212,14 +212,14 @@ in4_cksum(struct mbuf *m, u_int8_t nxt, 
panic("in4_cksum: bad mbuf chain");
 #endif
 
-   memset(&ipov, 0, sizeof(ipov));
-
-   ipov.ih_len = htons(len);
+   ipov.ih_x1[8] = 0;
ipov.ih_pr = nxt;
+   ipov.ih_len = htons(len);
ipov.ih_src = mtod(m, struct ip *)->ip_src;
ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
 
-   sum += in_cksumdata((caddr_t) &ipov, sizeof(ipov));
+   /* first 8 bytes are zeroes */
+   sum += in_cksumdata((caddr_t) &ipov + 8, sizeof(ipov) - 8);
}
 
/* skip over unnecessary part */
@@ -241,7 +241,7 @@ in4_cksum(struct mbuf *m, u_int8_t nxt, 
sum += in_cksumdata(addr, mlen) << 8;
else
sum += in_cksumdata(addr, mlen);
- 
+
clen += mlen;
len -= mlen;
}
Index: sys/arch/m88k/m88k/in_cksum.c
===
RCS file: /OpenBSD/src/sys/arch/m88k/m88k/in_cksum.c,v
retrieving revision 1.4
diff -u -p -r1.4 in_cksum.c
--- sys/arch/m88k/m88k/in_cksum.c   21 Aug 2014 14:24:08 -  1.4
+++ sys/arch/m88k/m88k/in_cksum.c   30 Jan 2022 18:35:18 -
@@ -95,19 +95,22 @@ in4_cksum(struct mbuf *m, uint8_t nxt, i
 {
u_int16_t *w;
u_int sum = 0;
-   struct ipovly ipov;
+   union {
+   struct ipovly ipov;
+   u_int16_t w[10];
+   } u;
 
if (nxt != 0) {
/* pseudo header */
-   bzero(&ipov, sizeof(ipov));
-   ipov.ih_len = htons(len);
-   ipov.ih_pr = nxt; 
-   ipov.ih_src = mtod(m, struct ip *)->ip_src; 
-   ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
-   w = (u_int16_t *)&ipov;
-   /* assumes sizeof(ipov) == 20 */
-   sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3]; sum += w[4];
-   sum += w[5]; sum += w[6]; sum += w[7]; sum += w[8]; sum += w[9];
+   u.ipov.ih_x1[8] = 0;
+   u.ipov.ih_pr = nxt;
+   u.ipov.ih_len = htons(len);
+   u.ipov.ih_src = mtod(m, struct ip *)->ip_src;
+   u.ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
+   w = u.w;
+   /* assumes sizeof(ipov) == 20 and first 8 bytes are zeroes */
+   sum += w[4]; sum += w[5]; sum += w[6];
+   sum += w[7]; sum += w[8]; sum += w[9];
}
 
/* skip unnecessary part */
Index: sys/arch/powerpc/powerpc/in_cksum.c
===
RCS file: /OpenBSD/src/sys/arch/powerpc/powerpc/in_cksum.c,v
retrieving revision 1.10
diff -u -p -r1.10 in_cksum.c
--- sys/arch/powerpc/powerpc/in_cksum.c 22 Jul 2014 10:35:35 -  1.10
+++ sys/arch/powerpc/powerpc/in_cksum.c 30 Jan 2022 18:35:18 -
@@ -87,7 +87,7 @@ in_cksum_internal(struct mbuf *m, int of
 * of a word spanning between this mbuf and the
 * last mbuf.
 *
-* s_util.c[0] is already saved when scanning previous 
+* s_util.c[0] is

Re: in4_cksum changes, step 1

2022-01-31 Thread Miod Vallat
> The register is set to -1, all bits set, and then its upper half
> is cleared. Now that the "and" has been removed, the value seems
> unused. The result of the removed "and" seemed unused too.

Oh, indeed, you're right, that makes things even simpler.

New diff:

Index: sys/arch/alpha/alpha/in_cksum.c
===
RCS file: /OpenBSD/src/sys/arch/alpha/alpha/in_cksum.c,v
retrieving revision 1.9
diff -u -p -r1.9 in_cksum.c
--- sys/arch/alpha/alpha/in_cksum.c 21 Aug 2014 14:24:08 -  1.9
+++ sys/arch/alpha/alpha/in_cksum.c 31 Jan 2022 19:39:56 -
@@ -200,7 +200,7 @@ in4_cksum(struct mbuf *m, u_int8_t nxt, 
int clen = 0;
caddr_t addr;
union q_util q_util;
-   union l_util l_util; 
+   union l_util l_util;
struct ipovly ipov;
 
if (nxt != 0) {
@@ -212,14 +212,14 @@ in4_cksum(struct mbuf *m, u_int8_t nxt, 
panic("in4_cksum: bad mbuf chain");
 #endif
 
-   memset(&ipov, 0, sizeof(ipov));
-
-   ipov.ih_len = htons(len);
+   ipov.ih_x1[8] = 0;
ipov.ih_pr = nxt;
+   ipov.ih_len = htons(len);
ipov.ih_src = mtod(m, struct ip *)->ip_src;
ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
 
-   sum += in_cksumdata((caddr_t) &ipov, sizeof(ipov));
+   /* first 8 bytes are zeroes */
+   sum += in_cksumdata((caddr_t) &ipov + 8, sizeof(ipov) - 8);
}
 
/* skip over unnecessary part */
@@ -241,7 +241,7 @@ in4_cksum(struct mbuf *m, u_int8_t nxt, 
sum += in_cksumdata(addr, mlen) << 8;
else
sum += in_cksumdata(addr, mlen);
- 
+
clen += mlen;
len -= mlen;
}
Index: sys/arch/m88k/m88k/in_cksum.c
===
RCS file: /OpenBSD/src/sys/arch/m88k/m88k/in_cksum.c,v
retrieving revision 1.4
diff -u -p -r1.4 in_cksum.c
--- sys/arch/m88k/m88k/in_cksum.c   21 Aug 2014 14:24:08 -  1.4
+++ sys/arch/m88k/m88k/in_cksum.c   31 Jan 2022 19:39:56 -
@@ -95,19 +95,22 @@ in4_cksum(struct mbuf *m, uint8_t nxt, i
 {
u_int16_t *w;
u_int sum = 0;
-   struct ipovly ipov;
+   union {
+   struct ipovly ipov;
+   u_int16_t w[10];
+   } u;
 
if (nxt != 0) {
/* pseudo header */
-   bzero(&ipov, sizeof(ipov));
-   ipov.ih_len = htons(len);
-   ipov.ih_pr = nxt; 
-   ipov.ih_src = mtod(m, struct ip *)->ip_src; 
-   ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
-   w = (u_int16_t *)&ipov;
-   /* assumes sizeof(ipov) == 20 */
-   sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3]; sum += w[4];
-   sum += w[5]; sum += w[6]; sum += w[7]; sum += w[8]; sum += w[9];
+   u.ipov.ih_x1[8] = 0;
+   u.ipov.ih_pr = nxt;
+   u.ipov.ih_len = htons(len);
+   u.ipov.ih_src = mtod(m, struct ip *)->ip_src;
+   u.ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
+   w = u.w;
+   /* assumes sizeof(ipov) == 20 and first 8 bytes are zeroes */
+   sum += w[4]; sum += w[5]; sum += w[6];
+   sum += w[7]; sum += w[8]; sum += w[9];
}
 
/* skip unnecessary part */
Index: sys/arch/powerpc/powerpc/in_cksum.c
===
RCS file: /OpenBSD/src/sys/arch/powerpc/powerpc/in_cksum.c,v
retrieving revision 1.10
diff -u -p -r1.10 in_cksum.c
--- sys/arch/powerpc/powerpc/in_cksum.c 22 Jul 2014 10:35:35 -  1.10
+++ sys/arch/powerpc/powerpc/in_cksum.c 31 Jan 2022 19:39:56 -
@@ -87,7 +87,7 @@ in_cksum_internal(struct mbuf *m, int of
 * of a word spanning between this mbuf and the
 * last mbuf.
 *
-* s_util.c[0] is already saved when scanning previous 
+* s_util.c[0] is already saved when scanning previous
 * mbuf.
 */
s_util.c[1] = *w++;
@@ -254,15 +254,15 @@ in4_cksum(struct mbuf *m, uint8_t nxt, i
 
if (nxt != 0) {
/* pseudo header */
-   memset(&u.ipov, 0, sizeof(u.ipov));
+   u.ipov.ih_x1[8] = 0;
+   u.ipov.ih_pr = nxt;
u.ipov.ih_len = htons(len);
-   u.ipov.ih_pr = nxt; 
-   u.ipov.ih_src = mtod(m, struct ip *)->ip_src; 
+   u.ipov.ih_src = mtod(m, struct ip *)->ip_src;
u.ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
w = u.w;
-   /* assumes sizeof(ipov) == 20 */
-   sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3]; sum += w[4];

[macppc] mpcpcibr buglet

2022-02-02 Thread Miod Vallat
On PowerMac11,2 systems, the PCIe bus attaches as:

mpcpcibr0 at mainbus0 pci: u4-pcie
pci0 at mpcpcibr0 bus 0

However none of the devices attached to pci0 will appear in pcidump.

This is caused by an incorrect bus number during attachment of the
pci(4) subdevice. The following diff queries the `bus-range' property in
order to use the correct number (and also contains a bunch of whitespace
and KNF fixes).

With the diff below applied, the attachment becomes:

mpcpcibr0 at mainbus0 pci: u4-pcie
pci0 at mpcpcibr0 bus 10

and pci0 devices will appear in the pcidump output.

Index: mpcpcibus.c
===
RCS file: /OpenBSD/src/sys/arch/macppc/pci/mpcpcibus.c,v
retrieving revision 1.47
diff -u -p -r1.47 mpcpcibus.c
--- mpcpcibus.c 3 Jun 2015 08:41:43 -   1.47
+++ mpcpcibus.c 2 Feb 2022 10:40:48 -
@@ -168,7 +168,7 @@ mpcpcibus_find_ranges_32(struct pcibr_so
sc->sc_iobus_space.bus_size = prange[found].size_lo;
}
 
-   /* the mem space ranges 
+   /* the mem space ranges
 * apple openfirmware always puts full
 * addresses in config information,
 * it is not necessary to have correct bus
@@ -185,12 +185,12 @@ mpcpcibus_find_ranges_32(struct pcibr_so
prange[i].size_lo);
 #endif
if (base != 0) {
-   if ((base + size) == prange[i].phys)   
+   if ((base + size) == prange[i].phys)
size += prange[i].size_lo;
else {
base = prange[i].phys;
size = prange[i].size_lo;
-   } 
+   }
} else {
base = prange[i].phys;
size = prange[i].size_lo;
@@ -263,7 +263,7 @@ mpcpcibus_find_ranges_64(struct pcibr_so
sc->sc_iobus_space.bus_size = prange[found].size_lo;
}
 
-   /* the mem space ranges 
+   /* the mem space ranges
 * apple openfirmware always puts full
 * addresses in config information,
 * it is not necessary to have correct bus
@@ -307,7 +307,6 @@ mpcpcibrattach(struct device *parent, st
struct confargs *ca = aux;
struct pcibr_config *lcp;
struct pcibus_attach_args pba;
-   int of_node = 0;
char compat[32];
u_int32_t addr_offset;
u_int32_t data_offset;
@@ -315,41 +314,39 @@ mpcpcibrattach(struct device *parent, st
int len;
int rangesize;
u_int32_t range_store[32];
+   int busrange[2];
 
if (ca->ca_node == 0) {
printf("invalid node on mpcpcibr config\n");
return;
}
-   len=OF_getprop(ca->ca_node, "name", compat, sizeof (compat));
+   len = OF_getprop(ca->ca_node, "name", compat, sizeof(compat));
compat[len] = '\0';
if (len > 0)
printf(" %s", compat);
 
-   len=OF_getprop(ca->ca_node, "compatible", compat,
-   sizeof (compat));
-   if (len <= 0 ) {
-   len=OF_getprop(ca->ca_node, "name", compat,
-   sizeof (compat));
+   len = OF_getprop(ca->ca_node, "compatible", compat, sizeof(compat));
+   if (len <= 0) {
+   len = OF_getprop(ca->ca_node, "name", compat, sizeof(compat));
if (len <= 0) {
printf(" compatible and name not found\n");
return;
}
-   compat[len] = 0; 
-   if (strcmp (compat, "bandit") != 0) {
+   compat[len] = 0;
+   if (strcmp(compat, "bandit") != 0) {
printf(" compatible not found and name %s found\n",
compat);
return;
}
}
-   compat[len] = 0; 
+   compat[len] = 0;
if ((rangesize = OF_getprop(ca->ca_node, "ranges",
range_store, sizeof (range_store))) <= 0) {
if (strcmp(compat, "u3-ht") == 0) {
range_store[0] = 0xabb10113; /* appl U3; */
-   } else 
+   } else
printf("range lookup failed, node %x\n", ca->ca_node);
}
-   /* translate byte(s) into item count*/
 
lcp = &sc->pcibr_config;
 
@@ -363,16 +360,16 @@ mpcpcibrattach(struct device *parent, st
M_DEVBUF, NULL, 0, EX_NOWAIT | EX_FILLED);
 
if (ppc_proc_is_64b)
-   mpcpcibus_find_ranges_64 (sc, range_store, rangesize);
+   mpcpcibus_find_ranges_64(sc, range_store, rangesize);
else
-   mpcpcibus_find_ranges_32 (sc, range_store, rangesize);
+   mpcpcibus_find_ranges_32(sc, range_store, rangesize);
 
addr_offset = 0;

Re: Use installboot(8) in install.md of riscv64

2022-02-02 Thread Miod Vallat
> Index: usr.sbin/installboot/armv7_installboot.c
> ===
> RCS file: src/usr.sbin/installboot/armv7_installboot.c,v
> retrieving revision 1.11
> diff -u -p -r1.11 armv7_installboot.c
> --- usr.sbin/installboot/armv7_installboot.c  20 Jul 2021 14:51:56 -  
> 1.11
> +++ usr.sbin/installboot/armv7_installboot.c  2 Feb 2022 14:11:08 -
> @@ -55,6 +55,19 @@
>  
>  #include "installboot.h"
>  
> +#if defined(__aarch64__)
> +#define BOOTEFI_SRC  "BOOTAA64.EFI"
> +#define BOOTEFI_DST  "bootaa64.efi"
> +#elif defined(__arm__)
> +#define BOOTEFI_SRC  "BOOTARM.EFI"
> +#define BOOTEFI_DST  "bootarm.efi"
> +#elif defined(__riscv)
> +#define BOOTEFI_SRC  "BOOTRISCV64.EFI"
> +#define BOOTEFI_DST  "bootriscv64.efi"
> +#else
> +#error "unhandled architecture"
> +#endif

Wouldn't these defines better set at the Makefile level, since there is
already logic to pick different files depending upon the architecture?



Re: sigabort(), p_sigmask & p_siglist

2020-09-15 Thread Miod Vallat


> Diff below introduces an helper for sending an uncatchable SIGABRT and
> annotate that `p_siglist' and `p_sigmask' are updated using atomic
> operations.

Why not use sigexit(p, SIGABRT); for that purpose?



Re: sigabort(), p_sigmask & p_siglist

2020-09-16 Thread Miod Vallat
> Something doesn't feel right.
> 
> db_kill_cmd finds a process, called p, then kills it.  In your new diff
> calling sigexit, take note of the comment at the top:
> 
>  * Force the current process to exit with the specified signal, dumping core
> 
> current process?  Doesn't look like it, it looks like it kills p.  But then
> it calls exit1?

Ah, yes, sigexit() ends up with a context switch. This is not a good
idea for the places where Martin wants to use it, his first diff was
better. Sorry for the noise.



fix eeprom(8) on macppc

2020-09-20 Thread Miod Vallat
I had noticed for years that eeprom(8) always reported failure when
attempting to change OpenFirmware environment variables on macppc.

Upon further examination, it doesn't - the variables get changed, but
error is reported. This is caused by a difference in implementation
behaviour between Apple's OpenFirmware and Sun's.

Suggested diff below; clue from NetBSD.

Before:
# eeprom boot-command
boot-command=mac-boot
# eeprom boot-command=boot
eeprom: invalid keyword: boot-command
# eeprom boot-command
boot-command=boot   <-- yet the value has been changed

After:
# eeprom boot-command
boot-command=mac-boot
# eeprom boot-command=boot
# eeprom boot-command
boot-command=boot


Index: openprom.c
===
RCS file: /OpenBSD/src/sys/arch/macppc/macppc/openprom.c,v
retrieving revision 1.4
diff -u -p -r1.4 openprom.c
--- openprom.c  19 Sep 2015 21:07:04 -  1.4
+++ openprom.c  20 Sep 2020 17:56:35 -
@@ -186,7 +186,11 @@ openpromioctl(dev_t dev, u_long cmd, cad
strlcpy(buf, name, 32); /* XXX */
len = OF_setprop(node, buf, value, op->op_buflen + 1);
splx(s);
-   if (len != op->op_buflen)
+   /*
+* For string properties, the Apple OpenFirmware implementation
+* returns the buffer length including the trailing NUL.
+*/
+   if (len != op->op_buflen && len != op->op_buflen + 1)
error = EINVAL;
break;
 



Re: fix eeprom(8) on macppc

2020-09-20 Thread Miod Vallat
> > Suggested diff below; clue from NetBSD.
> I looked for openprom code there but only found it for SPARC, can you
> point me to where you got the "clue" from exactly?

http://bxr.su/NetBSD/sys/dev/ofw/openfirmio.c#205



Re: uvm_map_inentry() checks in trap()

2020-09-24 Thread Miod Vallat
> Repeating diffs from i386, amd64, sh.  Improve alpha diff to handle an
> additional fault case.  Adding diffs for powerpc, powerc64, and m88k.

The m88k diff is incomplete:
- changes need to be done in both m88100_trap() and m88110_trap().
- the uvm_map_inentry() check should be put after the user_fault and
  m88110_user_fault labels, which implies the KERNEL_LOCK must be moved
  after these labels and removed from the two code paths jumping to
  these labels.



missing trap.c code for m88k

2019-06-17 Thread Miod Vallat
Exception handling code on superH and m88k does not check for a valid
stack pointer, like other platforms do.

The following (mechanical) diff addresses the m88k case, and has been
tested to work on 88100 and 88110 processors.

Index: sys/arch/m88k/m88k/trap.c
===
RCS file: /OpenBSD/src/sys/arch/m88k/m88k/trap.c,v
retrieving revision 1.107
diff -u -p -u -p -r1.107 trap.c
--- sys/arch/m88k/m88k/trap.c   8 Sep 2017 05:36:52 -   1.107
+++ sys/arch/m88k/m88k/trap.c   17 Jun 2019 17:54:48 -
@@ -239,6 +239,9 @@ m88100_trap(u_int type, struct trapframe
type += T_USER;
p->p_md.md_tf = frame;  /* for ptrace/signals */
refreshcreds(p);
+   if (!uvm_map_inentry(p, &p->p_spinentry, PROC_STACK(p), "sp",
+   uvm_map_inentry_sp, p->p_vmspace->vm_map.sserial))
+   return;
}
fault_type = SI_NOINFO;
fault_code = 0;
@@ -679,6 +682,9 @@ m88110_trap(u_int type, struct trapframe
type += T_USER;
p->p_md.md_tf = frame;  /* for ptrace/signals */
refreshcreds(p);
+   if (!uvm_map_inentry(p, &p->p_spinentry, PROC_STACK(p), "sp",
+   uvm_map_inentry_sp, p->p_vmspace->vm_map.sserial))
+   return;
}
 
if (sig != 0)



unused sparc64 extern

2019-06-29 Thread Miod Vallat
The following declaration has actually never been used, for `ver' is a
local in cpuattach() and locore does rdpr %ver every time it needs the
value.

Index: include/psl.h
===
RCS file: /OpenBSD/src/sys/arch/sparc64/include/psl.h,v
retrieving revision 1.34
diff -u -p -r1.34 psl.h
--- include/psl.h   20 Aug 2018 15:02:07 -  1.34
+++ include/psl.h   29 Jun 2019 10:35:40 -
@@ -227,8 +227,6 @@
 
 #if defined(_KERNEL) && !defined(_LOCORE)
 
-extern u_int64_t ver;  /* Copy of v9 version register.  We need to read this 
only once, in locore.s. */
-
 #ifdef DIAGNOSTIC
 /*
  * Although this function is implemented in MI code, it must be in this MD



missing splnet in network drivers

2019-07-02 Thread Miod Vallat
The recent mii_tick diff made me ponder whether the mii tick timeout
could be put in the mii_data struct rather than each driver softc (not
that a good idea, actually).

While looking at this, I noticed that two drivers may end up invoking
mii_tick() while not being at IPL_NET.

bnx: bnx_tick() can get invoked either from the interrupt handler, or
from a timeout.

sk: on some boards, sk_tick() gets invoked from timeout, but may end up
invoking sk_intr_bcom() which is intended to run at IPL_NET.

This diff has only been compile-tested, for lack of such hardware.

Index: if_bnx.c
===
RCS file: /OpenBSD/src/sys/dev/pci/if_bnx.c,v
retrieving revision 1.125
diff -u -p -r1.125 if_bnx.c
--- if_bnx.c10 Mar 2018 10:51:46 -  1.125
+++ if_bnx.c3 Jul 2019 06:40:47 -
@@ -5457,6 +5457,9 @@ bnx_tick(void *xsc)
struct ifnet*ifp = &sc->arpcom.ac_if;
struct mii_data *mii = NULL;
u_int32_t   msg;
+   int s;
+
+   s = splnet();
 
/* Tell the firmware that the driver is still running. */
 #ifdef BNX_DEBUG
@@ -5489,7 +5492,7 @@ bnx_tick(void *xsc)
}
 
 bnx_tick_exit:
-   return;
+   splx(s);
 }
 
 //
Index: if_sk.c
===
RCS file: /OpenBSD/src/sys/dev/pci/if_sk.c,v
retrieving revision 1.189
diff -u -p -r1.189 if_sk.c
--- if_sk.c 4 Jun 2017 04:29:23 -   1.189
+++ if_sk.c 3 Jul 2019 06:40:47 -
@@ -1703,15 +1703,20 @@ sk_tick(void *xsc_if)
struct sk_if_softc *sc_if = xsc_if;
struct mii_data *mii = &sc_if->sk_mii;
struct ifnet *ifp = &sc_if->arpcom.ac_if;
-   int i;
+   int i, s;
 
DPRINTFN(2, ("sk_tick\n"));
 
-   if (!(ifp->if_flags & IFF_UP))
+   s = splnet();
+
+   if (!(ifp->if_flags & IFF_UP)) {
+   splx(s);
return;
+   }
 
if (sc_if->sk_phytype == SK_PHYTYPE_BCOM) {
sk_intr_bcom(sc_if);
+   splx(s);
return;
}
 
@@ -1729,6 +1734,7 @@ sk_tick(void *xsc_if)
 
if (i != 3) {
timeout_add_sec(&sc_if->sk_tick_ch, 1);
+   splx(s);
return;
}
 
@@ -1736,6 +1742,7 @@ sk_tick(void *xsc_if)
SK_XM_CLRBIT_2(sc_if, XM_IMR, XM_IMR_GP0_SET);
SK_XM_READ_2(sc_if, XM_ISR);
mii_tick(mii);
+   splx(s);
timeout_del(&sc_if->sk_tick_ch);
 }
 



minor INSTALL.loongson tweaks

2019-08-10 Thread Miod Vallat
Hello,

  I have noticed a few inaccuracies in the installation notes. The
following diff fixes them.

Index: hardware
===
RCS file: /OpenBSD/src/distrib/notes/loongson/hardware,v
retrieving revision 1.10
diff -u -p -r1.10 hardware
--- hardware27 Feb 2014 18:48:15 -  1.10
+++ hardware10 Aug 2019 16:43:12 -
@@ -21,5 +21,4 @@ The following machines are supported by 
  all onboard devices (keyboard, trackpad, display, SD card reader,
  USB ports, Ethernet adapter, wireless network adapter,
  battery information) are supported except for the audio controller;
- suspend/resume is not supported yet; keyboard actions involving
- the `Fn' key are not working either at the moment.
+ suspend/resume is not supported yet.
Index: install
===
RCS file: /OpenBSD/src/distrib/notes/loongson/install,v
retrieving revision 1.14
diff -u -p -r1.14 install
--- install 19 Mar 2014 01:59:48 -  1.14
+++ install 10 Aug 2019 16:43:12 -
@@ -35,9 +35,12 @@ dnl you can boot the kernel from an usb 
 dnl 
 dnlPMON> boot /dev/fs/fat@usb0:/bsd.rd
 
-Netbooting the installation kernel can be done as well:
+Netbooting the installation kernel can be done as well. First, check the name
+of the PMON device for the onboard interface using the ``devls'' command.
+This is likely to be either rtl0 (on Yeeloong) or rtk0 (on Fuloong). Then,
+assign it an address and fetch the installation kernel from a tftp server:
 
-PMON> ifaddr rtl0 
+PMON> ifaddr  
 PMON> boot -k tftp:///bsd.rd
 
 OpenBSDInstallPart2



Re: minor INSTALL.loongson tweaks

2019-08-13 Thread Miod Vallat


> Is suspend-resume not working on the lemote anymore?

It works (or used to work) on the Yeeloong, not on the Gdium (different
battery controller chip).



Re: ppppoe octeon kernel panic .6.6

2019-10-23 Thread Miod Vallat


> The system has a trap 2, which I looked up as:
>
> #define T_TLB_LD_MISS   2   /* TLB miss on load or ifetch */
>
> what happens before this patch, I think, is that there is a varargs size_t 
> (which is size 8 in mips64), that gets promoted (I think) in varargs to int 
> (which would likely be size 4).  Then what happens is the char * that is 
> va_arg'ed after that is somehow corrupted on length 1, bcopy would trap #2 
> on this.

Try changing all the final 0 in sppp_auth_send() to 0UL and this ought
to work. This function needs __attribute__((__sentinel__)) as well to
prevent such mistakes from occurring again.



Re: ppppoe octeon kernel panic .6.6

2019-10-23 Thread Miod Vallat


> Try changing all the final 0 in sppp_auth_send() to 0UL and this ought
> to work. This function needs __attribute__((__sentinel__)) as well to
> prevent such mistakes from occurring again.

The sentinel attribute wants a pointer, not a zero size_t,
unfortunately.

Please try this diff.

Index: if_spppsubr.c
===
RCS file: /OpenBSD/src/sys/net/if_spppsubr.c,v
retrieving revision 1.179
diff -u -p -r1.179 if_spppsubr.c
--- if_spppsubr.c   24 Jun 2019 21:36:53 -  1.179
+++ if_spppsubr.c   23 Oct 2019 17:12:53 -
@@ -3340,7 +3340,7 @@ sppp_chap_input(struct sppp *sp, struct 
   sizeof digest, digest,
   strlen(sp->myauth.name),
   sp->myauth.name,
-  0);
+  0UL);
break;
 
case CHAP_SUCCESS:
@@ -3460,7 +3460,7 @@ sppp_chap_input(struct sppp *sp, struct 
/* action scn, tld */
sppp_auth_send(&chap, sp, CHAP_FAILURE, h->ident,
   sizeof(FAILMSG) - 1, (u_char *)FAILMSG,
-  0);
+  0UL);
chap.tld(sp);
break;
}
@@ -3469,7 +3469,7 @@ sppp_chap_input(struct sppp *sp, struct 
sp->state[IDX_CHAP] == STATE_OPENED)
sppp_auth_send(&chap, sp, CHAP_SUCCESS, h->ident,
   sizeof(SUCCMSG) - 1, (u_char *)SUCCMSG,
-  0);
+  0UL);
if (sp->state[IDX_CHAP] == STATE_REQ_SENT) {
sppp_cp_change_state(&chap, sp, STATE_OPENED);
chap.tlu(sp);
@@ -3647,7 +3647,7 @@ sppp_chap_scr(struct sppp *sp)
   (size_t)AUTHCHALEN, sp->chap_challenge,
   strlen(sp->myauth.name),
   sp->myauth.name,
-  0);
+  0UL);
 }
 /*
  *--*
@@ -3726,7 +3726,7 @@ sppp_pap_input(struct sppp *sp, struct m
sppp_auth_send(&pap, sp, PAP_NAK, h->ident,
   sizeof mlen, (const char *)&mlen,
   sizeof(FAILMSG) - 1, (u_char *)FAILMSG,
-  0);
+  0UL);
pap.tld(sp);
break;
}
@@ -3737,7 +3737,7 @@ sppp_pap_input(struct sppp *sp, struct m
sppp_auth_send(&pap, sp, PAP_ACK, h->ident,
   sizeof mlen, (const char *)&mlen,
   sizeof(SUCCMSG) - 1, (u_char *)SUCCMSG,
-  0);
+  0UL);
}
if (sp->state[IDX_PAP] == STATE_REQ_SENT) {
sppp_cp_change_state(&pap, sp, STATE_OPENED);
@@ -3952,7 +3952,7 @@ sppp_pap_scr(struct sppp *sp)
   (size_t)idlen, sp->myauth.name,
   sizeof pwdlen, (const char *)&pwdlen,
   (size_t)pwdlen, sp->myauth.secret,
-  0);
+  0UL);
 }
 /*
  * Random miscellaneous functions.



Re: more MAKEDEV cleanup

2022-02-10 Thread Miod Vallat
> What happened to this?

I need to split this into orthogonal diffs, and also since this will
expose an issue in makefs(8), I need to polish and send a fix for makefs
first...



makefs, inodes, the universe and everything

2022-02-25 Thread Miod Vallat
As you may vaguely remember, I have plans to clean up MAKEDEV a bit,
which have the side effect of removing many unneeded device nodes from
the ramdisk target, used on the installation media.

Doing this will in turn expose a slight difference in filesystem
creation between the pre-makefs(8) world order (using newfs and
populating a vnd) and the current usage of makefs: while newfs will
create a fixed number of inodes, based upon the geometry parameters (one
inode per four fragments), makefs is lazier and will only build "enough"
inodes, where "enough" means that the number of available inodes will be
rounded to the number of inodes in a cylinder group.

tl;dr: by removing unneeded MAKEDEV entries, some platforms will end up
with makefs creating a file system with 256 inodes, of which about 250
are used, and installation will misbehave in interesting ways due to the
lack of free inodes.

There are two ways to address this:
1. fix makefs to initialize inodes in all cylinder groups.
2. let the `-f' option of makefs, used to specify a given number of free
   inodes, be accepted even when using a fixed geometry.

The following diff implements choice #2 (which is the easiest to do),
and adds `-f 100' to require 100 free inodes, in every installation
media.

The advantage, IMHO, of going this way, is that if the geometry does not
allow for enough free inodes, building installation media will fail, and
this will get noticed quickly.

Case in point: at the moment, the alpha bsd.rd uses a geometry
providing up to 384 inodes, of which 277 are used. Building with -f 100,
requiring thus 377 inodes, completes, while trying -f 120 will fail:

  makefs -o disklabel=rdroot,minfree=0,density=8192 -f 120 mr.fs mr.fs.d
  Calculated size of `mr.fs': 2940928 bytes, 397 inodes
  Extent size set to 8192
  mr.fs: 2.8MB (5744 sectors) block size 8192, fragment size 1024
  using 1 cylinder groups of 2.80MB, 359 blks, 384 inodes.
  super-block backups (for fsck -b #) at:
   32,
  makefs: Image file `mr.fs' has 384 free inodes; 397 are required.
  makefs: Image file `mr.fs' not created.
  *** Error 1 in /usr/src/distrib/alpha/miniroot (Makefile:89 'mr.fs')

I have not been able to test that diff on all platforms, therefore I
don't know which platforms will require tweaks to their miniroot
filesystem geometry to build with that "100 free inodes" requirement.
Maybe the amount can be adjusted on legacy platforms. Also, the makefs
diff can go in and installation media changes applied later on a
tested-platform basis.

In any case, keep in mind that I have upcoming changes which will free
a bunch of inodes from every miniroot.

Index: usr.sbin/makefs/ffs.c
===
RCS file: /OpenBSD/src/usr.sbin/makefs/ffs.c,v
retrieving revision 1.36
diff -u -p -r1.36 ffs.c
--- usr.sbin/makefs/ffs.c   11 Jan 2022 05:34:32 -  1.36
+++ usr.sbin/makefs/ffs.c   25 Feb 2022 16:47:17 -
@@ -324,10 +324,9 @@ ffs_validate(const char *dir, fsnode *ro
if (pp->p_fragblock == 0)
errx(1, "fragment size missing in disktab");
if (fsopts->freeblocks != 0 || fsopts->freeblockpc != 0 ||
-   fsopts->freefiles != 0 || fsopts->freefilepc != 0 ||
fsopts->minsize != 0 || fsopts->maxsize != 0 ||
fsopts->sectorsize != -1 || fsopts->size != 0)
-   errx(1, "-bfMmSs and disklabel are mutually exclusive");
+   errx(1, "-bMmSs and disklabel are mutually exclusive");
if (ffs_opts->fsize != -1 || ffs_opts->bsize != -1)
errx(1, "b/fsize and disklabel are mutually exclusive");
 
Index: distrib/alpha/miniroot/Makefile
===
RCS file: /OpenBSD/src/distrib/alpha/miniroot/Makefile,v
retrieving revision 1.23
diff -u -p -r1.23 Makefile
--- distrib/alpha/miniroot/Makefile 26 Jul 2021 12:47:44 -  1.23
+++ distrib/alpha/miniroot/Makefile 25 Feb 2022 16:47:17 -
@@ -12,7 +12,7 @@ LISTS=${.CURDIR}/list
 UTILS= ${.CURDIR}/../../miniroot
 
 MRDISKTYPE=rdroot
-MRMAKEFSARGS=  -o disklabel=${MRDISKTYPE},minfree=0,density=8192
+MRMAKEFSARGS=  -o disklabel=${MRDISKTYPE},minfree=0,density=8192 -f 100
 
 all: ${FS} ${CDROM}
 
Index: distrib/amd64/ramdiskA/Makefile
===
RCS file: /OpenBSD/src/distrib/amd64/ramdiskA/Makefile,v
retrieving revision 1.16
diff -u -p -r1.16 Makefile
--- distrib/amd64/ramdiskA/Makefile 26 Jul 2021 12:47:44 -  1.16
+++ distrib/amd64/ramdiskA/Makefile 25 Feb 2022 16:47:17 -
@@ -30,7 +30,7 @@ ${FS}: bsd.gz
rm -f vnd
 
 MRDISKTYPE=rdroot
-MRMAKEFSARGS=  -o disklabel=${MRDISKTYPE},minfree=0,density=4096
+MRMAKEFSARGS=  -o disklabel=${MRDISKTYPE},minfree=0,density=4096 -f 100
 
 bsd.gz: bsd.rd
objcopy -S -

Re: makefs, inodes, the universe and everything

2022-02-25 Thread Miod Vallat
> Should the default for makefs not be changed, rather than requiring an
> argument?

I'm not fond of that idea, but why not, as long as it gets documented.

> 100 seem extremely small.  Imagine a person installing a machine with 5
> drives.  Our installer lets people iterate over all their drives. MAKEDEV
> will create 32 inodes per drive.   For 5 drives, that 160 inodes, plus the
> 10 or so /tmp files created during build... it is way more than the 100 you
> propose as being satisfactory.  Even a person with two drives will use 64
> inodes, leaving 36 for the script, but if someone had 3 drives it will blow
> up.

100 was a starting point to start the discussion. Using a larger value
will probably cause more miniroot geometries to be updated, but that's a
once-in-10-years kind of change anyway.

> I guess this went quietly off the rails when we switched to using
> makefs.  This "minimalism" decision it makes is not really compatible
> with our wish to make disk device nodes on the fly.

Indeed.

> So should it be -f 200, or 250, and/or should the minimum default built-in
> be changed?  Basically 100% of makefs use is for our install media, is it not
> right to change the default?

Well it would be interesting to hear from people using makefs for other
purposes. Are there any?



  1   2   3   4   5   >