videomode.h: add int hskew member to struct videomode

2016-09-02 Thread Ian Sutton
Some ARM systems have decoupled their display/LCD controllers from their
display transmitters, such as the am335x/beaglebone black whose LCD
controller (on am335x SoC) breaks out to a TDA19988 IC (on PCB). This
sometimes causes sync timing problems in that the timings purported by
the LCD controller do not match the ones coming out of the transmitter,
this hskew int enumerates the value the transmitter must offset its sync
timings by to match what the controller dictates. The extant VID_HSKEW
flag hints at this.

This patch does not break anything, but if devs (understandably) do not
wish to change a MI header to suit a small subset of devices, I can
still fix this issue with the am335x/TDA in a more inelegant way.

Ian


Index: sys/dev/videomode/videomode.h
===
RCS file: /cvs/src/sys/dev/videomode/videomode.h,v
retrieving revision 1.1
diff -u -p -r1.1 videomode.h
--- sys/dev/videomode/videomode.h   8 Oct 2009 20:35:44 -   1.1
+++ sys/dev/videomode/videomode.h   3 Sep 2016 04:26:49 -
@@ -42,6 +42,7 @@ struct videomode {
int vtotal;
int flags;  /* Video mode flags; see below. */
const char *name;
+   int hskew;
 };
 
 /*



if_iwmreg.h enums

2016-09-02 Thread Stefan Sperling
This gets rid of almost all the silly enums in iwm's header file.
Replace them with #define to better match the style of other drivers.

No functional change intended. This conversion was semi-automatic
and additional eyeballing is very much appreciated.

Index: if_iwm.c
===
RCS file: /cvs/src/sys/dev/pci/if_iwm.c,v
retrieving revision 1.104
diff -u -p -r1.104 if_iwm.c
--- if_iwm.c2 Sep 2016 17:10:25 -   1.104
+++ if_iwm.c2 Sep 2016 21:58:40 -
@@ -280,8 +280,8 @@ int iwm_nic_tx_init(struct iwm_softc *);
 intiwm_nic_init(struct iwm_softc *);
 intiwm_enable_txq(struct iwm_softc *, int, int, int);
 intiwm_post_alive(struct iwm_softc *);
-struct iwm_phy_db_entry *iwm_phy_db_get_section(struct iwm_softc *,
-   enum iwm_phy_db_section_type, uint16_t);
+struct iwm_phy_db_entry *iwm_phy_db_get_section(struct iwm_softc *, uint16_t,
+   uint16_t);
 intiwm_phy_db_set_section(struct iwm_softc *,
struct iwm_calib_res_notif_phy_db *);
 intiwm_is_valid_channel(uint16_t);
@@ -292,7 +292,7 @@ int iwm_phy_db_get_section_data(struct i
uint16_t *, uint16_t);
 intiwm_send_phy_db_cmd(struct iwm_softc *, uint16_t, uint16_t, void *);
 intiwm_phy_db_send_all_channel_groups(struct iwm_softc *,
-   enum iwm_phy_db_section_type, uint8_t);
+   uint16_t, uint8_t);
 intiwm_send_phy_db_data(struct iwm_softc *);
 void   iwm_mvm_te_v2_to_v1(const struct iwm_time_event_cmd_v2 *,
struct iwm_time_event_cmd_v1 *);
@@ -449,7 +449,7 @@ int iwm_newstate(struct ieee80211com *, 
 void   iwm_endscan_cb(void *);
 void   iwm_mvm_fill_sf_command(struct iwm_softc *, struct iwm_sf_cfg_cmd *,
struct ieee80211_node *);
-intiwm_mvm_sf_config(struct iwm_softc *, enum iwm_sf_state);
+intiwm_mvm_sf_config(struct iwm_softc *, int);
 intiwm_send_bt_init_conf(struct iwm_softc *);
 intiwm_send_update_mcc_cmd(struct iwm_softc *, const char *);
 void   iwm_mvm_tt_tx_backoff(struct iwm_softc *, uint32_t);
@@ -568,7 +568,7 @@ iwm_read_firmware(struct iwm_softc *sc, 
struct iwm_fw_info *fw = >sc_fw;
struct iwm_tlv_ucode_header *uhdr;
struct iwm_ucode_tlv tlv;
-   enum iwm_ucode_tlv_type tlv_type;
+   uint32_t tlv_type;
uint8_t *data;
int error;
size_t len;
@@ -641,7 +641,7 @@ iwm_read_firmware(struct iwm_softc *sc, 
goto parse_out;
}
 
-   switch ((int)tlv_type) {
+   switch (tlv_type) {
case IWM_UCODE_TLV_PROBE_MAX_LEN:
if (tlv_len < sizeof(uint32_t)) {
error = EINVAL;
@@ -2001,8 +2001,7 @@ iwm_post_alive(struct iwm_softc *sc)
  * type and channel group id.
  */
 struct iwm_phy_db_entry *
-iwm_phy_db_get_section(struct iwm_softc *sc,
-   enum iwm_phy_db_section_type type, uint16_t chg_id)
+iwm_phy_db_get_section(struct iwm_softc *sc, uint16_t type, uint16_t chg_id)
 {
struct iwm_phy_db *phy_db = >sc_phy_db;
 
@@ -2032,7 +2031,7 @@ int
 iwm_phy_db_set_section(struct iwm_softc *sc,
struct iwm_calib_res_notif_phy_db *phy_db_notif)
 {
-   enum iwm_phy_db_section_type type = le16toh(phy_db_notif->type);
+   uint16_t type = le16toh(phy_db_notif->type);
uint16_t size  = le16toh(phy_db_notif->length);
struct iwm_phy_db_entry *entry;
uint16_t chg_id = 0;
@@ -2181,7 +2180,7 @@ iwm_send_phy_db_cmd(struct iwm_softc *sc
 
 int
 iwm_phy_db_send_all_channel_groups(struct iwm_softc *sc,
-   enum iwm_phy_db_section_type type, uint8_t max_ch_groups)
+   uint16_t type, uint8_t max_ch_groups)
 {
uint16_t i;
int err;
@@ -6456,7 +6455,7 @@ iwm_mvm_fill_sf_command(struct iwm_softc
 }
 
 int
-iwm_mvm_sf_config(struct iwm_softc *sc, enum iwm_sf_state new_state)
+iwm_mvm_sf_config(struct iwm_softc *sc, int new_state)
 {
struct ieee80211com *ic = >sc_ic;
struct iwm_sf_cfg_cmd sf_cmd = {
Index: if_iwmreg.h
===
RCS file: /cvs/src/sys/dev/pci/if_iwmreg.h,v
retrieving revision 1.15
diff -u -p -r1.15 if_iwmreg.h
--- if_iwmreg.h 2 Sep 2016 15:46:16 -   1.15
+++ if_iwmreg.h 2 Sep 2016 22:32:59 -
@@ -403,30 +403,25 @@
 
 /* SECURE boot registers */
 #define IWM_CSR_SECURE_BOOT_CONFIG_ADDR(0x100)
-enum iwm_secure_boot_config_reg {
-   IWM_CSR_SECURE_BOOT_CONFIG_INSPECTOR_BURNED_IN_OTP  = 0x0001,
-   IWM_CSR_SECURE_BOOT_CONFIG_INSPECTOR_NOT_REQ= 0x0002,
-};
-
+#define IWM_CSR_SECURE_BOOT_CONFIG_INSPECTOR_BURNED_IN_OTP 0x0001
+#define IWM_CSR_SECURE_BOOT_CONFIG_INSPECTOR_NOT_REQ   0x0002
 #define IWM_CSR_SECURE_BOOT_CPU1_STATUS_ADDR   (0x100)
 #define 

Re: Kernel panic pf.c during halting

2016-09-02 Thread Lampshade
> 
> > The key is really being able to reproduce the problem, Lampshade do you 
> > already know which service or config triggers this panic?  Could you try
> > to figure out by simplifying your setup?
> 
> I don't know.
> Problem is that even with most complicated config it happens a few times
> in a month at most.
> I will try to simplify config.
> From today I don't start Tor clients. I hope crash will happen and then
> I would simplify more.



Remove mention of deprecated flags in ping6.8

2016-09-02 Thread Michal Mazurek
I don't think the -s option is ever ignored now.

OK?

Index: sbin/ping6/ping6.8
===
RCS file: /cvs/src/sbin/ping6/ping6.8,v
retrieving revision 1.60
diff -u -p -r1.60 ping6.8
--- sbin/ping6/ping6.8  25 Oct 2015 14:43:48 -  1.60
+++ sbin/ping6/ping6.8  2 Sep 2016 18:13:18 -
@@ -190,10 +190,6 @@ data bytes when combined
 with the 8 bytes of
 ICMP
 header data.
-.Pp
-This option is ignored if any of the flags
-.Op Fl tWw
-are specified.
 .It Fl V Ar rtable
 Set the routing table to be used for outgoing packets.
 .It Fl v

-- 
Michal Mazurek



Re: send fewer router solicitations

2016-09-02 Thread Florian Obser
On Fri, Sep 02, 2016 at 05:49:22PM +0100, Stuart Henderson wrote:
> On 2016/09/02 10:37, Florian Obser wrote:
> > To stop naddy from pestering me about this at every hackathon (rightly
> > so!), let's base the timeout on the prefixes pltime. ;)
> 
> Just a thought, are we going to need to cap this to the RDNSS time too when
> we start caring about that?
> 

I will not parse the DNS options in the kernel. See CVE-2014-3954 ;)

I imagine when the time comes that we care we have the router
advertisement parsing in userland and solicitations will again be send
from userland, too.

-- 
I'm not entirely sure you are real.



Periodically sync RTC

2016-09-02 Thread Christian Weisgerber
I would like to sync the system time periodically back to the RTC.

Currently we update the RTC
(1) when the time is set with clock_settime() or settimeofday(), which
never happens for a typical ntpd setup;
(2) before suspend;
(3) when the system is properly shut down.

This means if a machine has been running for a few months and it
loses power, it may come back up with the time way off, leading to
all sorts of problems.

Patch below, originally inspired by FreeBSD, and incorporating various
suggestions from kettenis@ when I first proposed this:

* A timeout schedules a task that actually calls resettodr().
* The RTC is synced back every 30 minutes.
* The timeout and task are removed before shutdown and suspend;
  the timeout is started up again on resume.
* Suspend/resume paths: acpi, i386 apm, loongson "apm".

Comments?

Index: arch/i386/i386/apm.c
===
RCS file: /cvs/src/sys/arch/i386/i386/apm.c,v
retrieving revision 1.114
diff -u -p -r1.114 apm.c
--- arch/i386/i386/apm.c28 Sep 2015 18:36:36 -  1.114
+++ arch/i386/i386/apm.c2 Sep 2016 17:28:23 -
@@ -248,6 +248,7 @@ apm_suspend(int state)
 #if NWSDISPLAY > 0
wsdisplay_suspend();
 #endif /* NWSDISPLAY > 0 */
+   stop_periodic_resettodr();
config_suspend_all(DVACT_QUIESCE);
bufq_quiesce();
 
@@ -284,6 +285,7 @@ apm_suspend(int state)
bufq_restart();
 
config_suspend_all(DVACT_WAKEUP);
+   start_periodic_resettodr();
 
 #if NWSDISPLAY > 0
wsdisplay_resume();
Index: arch/loongson/dev/apm.c
===
RCS file: /cvs/src/sys/arch/loongson/dev/apm.c,v
retrieving revision 1.29
diff -u -p -r1.29 apm.c
--- arch/loongson/dev/apm.c 28 Sep 2015 18:36:36 -  1.29
+++ arch/loongson/dev/apm.c 2 Sep 2016 17:28:23 -
@@ -373,6 +373,7 @@ apm_suspend(int state)
wsdisplay_suspend();
 #endif
 
+   stop_periodic_resettodr();
resettodr();
 
config_suspend_all(DVACT_QUIESCE);
@@ -422,6 +423,8 @@ apm_suspend(int state)
bufq_restart();
 
config_suspend_all(DVACT_WAKEUP);
+
+   start_periodic_resettodr();
 
 #if NWSDISPLAY > 0
wsdisplay_resume();
Index: dev/acpi/acpi.c
===
RCS file: /cvs/src/sys/dev/acpi/acpi.c,v
retrieving revision 1.314
diff -u -p -r1.314 acpi.c
--- dev/acpi/acpi.c 31 Aug 2016 15:40:42 -  1.314
+++ dev/acpi/acpi.c 2 Sep 2016 17:28:23 -
@@ -2383,6 +2383,8 @@ acpi_sleep_state(struct acpi_softc *sc, 
rw_enter_write(>sc_lck);
 #endif /* NWSDISPLAY > 0 */
 
+   stop_periodic_resettodr();
+
 #ifdef HIBERNATE
if (state == ACPI_STATE_S4) {
uvmpd_hibernate();
@@ -2482,6 +2484,8 @@ fail_alloc:
hibernate_resume_bufcache();
}
 #endif /* HIBERNATE */
+
+   start_periodic_resettodr();
 
 #if NWSDISPLAY > 0
rw_exit_write(>sc_lck);
Index: kern/init_main.c
===
RCS file: /cvs/src/sys/kern/init_main.c,v
retrieving revision 1.254
diff -u -p -r1.254 init_main.c
--- kern/init_main.c2 Sep 2016 12:17:33 -   1.254
+++ kern/init_main.c2 Sep 2016 17:28:23 -
@@ -551,6 +551,8 @@ main(void *framep)
pool_gc_pages(NULL);
 #endif
 
+   start_periodic_resettodr();
+
 /*
  * proc0: nothing to do, back to sleep
  */
Index: kern/kern_time.c
===
RCS file: /cvs/src/sys/kern/kern_time.c,v
retrieving revision 1.97
diff -u -p -r1.97 kern_time.c
--- kern/kern_time.c28 Apr 2016 20:11:20 -  1.97
+++ kern/kern_time.c2 Sep 2016 17:28:24 -
@@ -41,6 +41,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 
 #include 
@@ -785,3 +787,37 @@ ppsratecheck(struct timeval *lasttime, i
return (rv);
 }
 
+
+#define RESETTODR_PERIOD   1800
+
+void periodic_resettodr(void *);
+void perform_resettodr(void *);
+
+struct timeout resettodr_to = TIMEOUT_INITIALIZER(periodic_resettodr, NULL);
+struct task resettodr_task = TASK_INITIALIZER(perform_resettodr, NULL);
+
+void
+periodic_resettodr(void *arg __unused)
+{
+   task_add(systq, _task);
+}
+
+void
+perform_resettodr(void *arg __unused)
+{
+   resettodr();
+   timeout_add_sec(_to, RESETTODR_PERIOD);
+}
+
+void
+start_periodic_resettodr(void)
+{
+   timeout_add_sec(_to, RESETTODR_PERIOD);
+}
+
+void
+stop_periodic_resettodr(void)
+{
+   timeout_del(_to);
+   task_del(systq, _task);
+}
Index: kern/kern_xxx.c
===
RCS file: /cvs/src/sys/kern/kern_xxx.c,v
retrieving revision 1.29
diff -u -p -r1.29 kern_xxx.c
--- kern/kern_xxx.c 5 Dec 2015 10:11:53 -   1.29
+++ kern/kern_xxx.c 2 Sep 2016 17:28:24 -
@@ -65,6 

Re: Mention the maximum packet size in ping.8

2016-09-02 Thread Sebastian Benoit
Michal Mazurek(akf...@jasminek.net) on 2016.09.02 18:41:27 +0200:
> Index: sbin/ping/ping.8
> ===
> RCS file: /cvs/src/sbin/ping/ping.8,v
> retrieving revision 1.52
> diff -u -p -r1.52 ping.8
> --- sbin/ping/ping.8  24 Mar 2014 11:11:49 -  1.52
> +++ sbin/ping/ping.8  2 Sep 2016 16:35:50 -
> @@ -176,6 +176,7 @@ Specifies the number of data bytes to be
>  The default is 56,
>  which translates into 64 ICMP data bytes
>  when combined with the 8 bytes of ICMP header data.
> +The maximum packet size is 65467.
>  .It Fl T Ar toskeyword
>  Change IPv4 TOS value.
>  .Ar toskeyword
> 
> -- 
> Michal Mazurek
> 

please also check what the limit in ping6 is. florian@ is currently working
on merging ping and ping6 and this just creates more work for him.



Re: Mention the maximum packet size in ping.8

2016-09-02 Thread Ted Unangst
Michal Mazurek wrote:

whee!

> Index: sbin/ping/ping.8
> ===
> RCS file: /cvs/src/sbin/ping/ping.8,v
> retrieving revision 1.52
> diff -u -p -r1.52 ping.8
> --- sbin/ping/ping.8  24 Mar 2014 11:11:49 -  1.52
> +++ sbin/ping/ping.8  2 Sep 2016 16:35:50 -
> @@ -176,6 +176,7 @@ Specifies the number of data bytes to be
>  The default is 56,
>  which translates into 64 ICMP data bytes
>  when combined with the 8 bytes of ICMP header data.
> +The maximum packet size is 65467.
>  .It Fl T Ar toskeyword
>  Change IPv4 TOS value.
>  .Ar toskeyword
> 
> -- 
> Michal Mazurek
> 



Re: mbuf cluster and socket buffer limits

2016-09-02 Thread Karel Gardas
On Fri, Sep 2, 2016 at 6:59 PM, Alexander Bluhm  wrote:
> Hi,
>
> To move our network performance to modern high bandwith and high
> latency characteristics, we have to increase the socket buffer size
> limit.  That also implies more mbuf clusters to avoid running out
> of them.
>
> This diff includes several aspects that somehow belong together.
>
> - Increase the number of mbufs on most architectures.  I have to
>   guess how much memory a typical machine has.  If the value is too
>   high, we may run out of kernel memory.
>   arch/alpha/include/param.h:#defineNMBCLUSTERS (16 * 1026)

Sorry to be clueless, but I'm curious isn't 1026 a typo here and also
in actual param.h?

Thanks,
Karel

> Index: arch/alpha/include/param.h
> ===
> RCS file: /data/mirror/openbsd/cvs/src/sys/arch/alpha/include/param.h,v
> retrieving revision 1.39
> diff -u -p -r1.39 param.h
> --- arch/alpha/include/param.h  26 Mar 2013 05:04:08 -  1.39
> +++ arch/alpha/include/param.h  2 Sep 2016 15:35:35 -
> @@ -63,7 +63,7 @@
>  #defineUSPACE  (UPAGES * PAGE_SIZE)/* total size of 
> u-area */
>  #defineUSPACE_ALIGN0   /* u-area alignment 
> 0-none */
>
> -#defineNMBCLUSTERS 4096/* map size, max 
> cluster allocation */
> +#defineNMBCLUSTERS (16 * 1026) /* max cluster 
> allocation */
>
>  #ifndefMSGBUFSIZE
>  #defineMSGBUFSIZE  (2 * PAGE_SIZE) /* default message 
> buffer size */



Re: mbuf cluster and socket buffer limits

2016-09-02 Thread Landry Breuil
On Fri, Sep 02, 2016 at 06:59:21PM +0200, Alexander Bluhm wrote:
> Hi,
> 
> To move our network performance to modern high bandwith and high
> latency characteristics, we have to increase the socket buffer size
> limit.  That also implies more mbuf clusters to avoid running out
> of them.
> 
> This diff includes several aspects that somehow belong together.
> 
> - Increase the number of mbufs on most architectures.  I have to
>   guess how much memory a typical machine has.  If the value is too
>   high, we may run out of kernel memory.
>   arch/alpha/include/param.h:#define  NMBCLUSTERS (16 * 1026)

1024 ? -^

> ===
> RCS file: /data/mirror/openbsd/cvs/src/sys/arch/alpha/include/param.h,v
> retrieving revision 1.39
> diff -u -p -r1.39 param.h
> --- arch/alpha/include/param.h26 Mar 2013 05:04:08 -  1.39
> +++ arch/alpha/include/param.h2 Sep 2016 15:35:35 -
> @@ -63,7 +63,7 @@
>  #define  USPACE  (UPAGES * PAGE_SIZE)/* total size of u-area 
> */
>  #define  USPACE_ALIGN0   /* u-area alignment 
> 0-none */
>  
> -#define  NMBCLUSTERS 4096/* map size, max 
> cluster allocation */
> +#define  NMBCLUSTERS (16 * 1026) /* max cluster 
> allocation */

ditto



relayd fork+exec

2016-09-02 Thread Reyk Floeter
Hi,

after all the preparation, the following diff adds support for
fork+exec in relayd; based on rzalamena@'s work for httpd.

Notes:
- proc.c is identical to the version that is already in httpd.
- The recvfd pledge in some procs is only needed once, could be
dropped later after receiving IMSG_CTL_PROCFD.
- The socket_rlimit(-1) in the parent is needed because relayd
currently opens n:m fds between all processes which slightly exceeds
the allowed 128 fds.  The problem also exists in httpd and in -current
but the relayd fork+exec diff needs a few more fds and gets over the
limit.  The problem will be reviewed and fixed independently.
- Don't forget to clean and rebuild relayctl.

All regress tests pass, but it needs some more testing.

OK?

Reyk

Index: usr.sbin/relayd/ca.c
===
RCS file: /cvs/src/usr.sbin/relayd/ca.c,v
retrieving revision 1.21
diff -u -p -u -p -r1.21 ca.c
--- usr.sbin/relayd/ca.c2 Sep 2016 14:45:51 -   1.21
+++ usr.sbin/relayd/ca.c2 Sep 2016 16:49:53 -
@@ -73,7 +73,7 @@ ca(struct privsep *ps, struct privsep_pr
 void
 ca_init(struct privsep *ps, struct privsep_proc *p, void *arg)
 {
-   if (pledge("stdio", NULL) == -1)
+   if (pledge("stdio recvfd", NULL) == -1)
fatal("pledge");
 
if (config_init(ps->ps_env) == -1)
Index: usr.sbin/relayd/hce.c
===
RCS file: /cvs/src/usr.sbin/relayd/hce.c,v
retrieving revision 1.74
diff -u -p -u -p -r1.74 hce.c
--- usr.sbin/relayd/hce.c   2 Sep 2016 14:45:51 -   1.74
+++ usr.sbin/relayd/hce.c   2 Sep 2016 16:49:53 -
@@ -70,7 +70,7 @@ hce_init(struct privsep *ps, struct priv
/* Allow maximum available sockets for TCP checks */
socket_rlimit(-1);
 
-   if (pledge("stdio inet", NULL) == -1)
+   if (pledge("stdio recvfd inet", NULL) == -1)
fatal("hce: pledge");
 }
 
Index: usr.sbin/relayd/relayd.c
===
RCS file: /cvs/src/usr.sbin/relayd/relayd.c,v
retrieving revision 1.159
diff -u -p -u -p -r1.159 relayd.c
--- usr.sbin/relayd/relayd.c2 Sep 2016 14:45:51 -   1.159
+++ usr.sbin/relayd/relayd.c2 Sep 2016 16:49:54 -
@@ -121,8 +121,12 @@ main(int argc, char *argv[])
struct relayd   *env;
struct privsep  *ps;
const char  *conffile = CONF_FILE;
+   enum privsep_procid  proc_id = PROC_PARENT;
+   int  proc_instance = 0;
+   const char  *errp, *title = NULL;
+   int  argc0 = argc;
 
-   while ((c = getopt(argc, argv, "dD:nf:v")) != -1) {
+   while ((c = getopt(argc, argv, "dD:nI:P:f:v")) != -1) {
switch (c) {
case 'd':
debug = 2;
@@ -143,6 +147,18 @@ main(int argc, char *argv[])
verbose++;
opts |= RELAYD_OPT_VERBOSE;
break;
+   case 'P':
+   title = optarg;
+   proc_id = proc_getid(procs, nitems(procs), title);
+   if (proc_id == PROC_MAX)
+   fatalx("invalid process name");
+   break;
+   case 'I':
+   proc_instance = strtonum(optarg, 0,
+   PROC_MAX_INSTANCES, );
+   if (errp)
+   fatalx("invalid process instance");
+   break;
default:
usage();
}
@@ -189,19 +205,29 @@ main(int argc, char *argv[])
log_init(debug, LOG_DAEMON);
log_verbose(verbose);
 
-   if (!debug && daemon(1, 0) == -1)
-   err(1, "failed to daemonize");
-
if (env->sc_conf.opts & RELAYD_OPT_NOACTION)
ps->ps_noaction = 1;
-   else
-   log_info("startup");
 
ps->ps_instances[PROC_RELAY] = env->sc_conf.prefork_relay;
ps->ps_instances[PROC_CA] = env->sc_conf.prefork_relay;
+   ps->ps_instance = proc_instance;
+   if (title != NULL)
+   ps->ps_title[proc_id] = title;
+
+   if (proc_id == PROC_PARENT) {
+   /* XXX the parent opens too many fds in proc_open() */
+   socket_rlimit(-1);
+   }
+
+   /* only the parent returns */
+   proc_init(ps, procs, nitems(procs), argc0, argv, proc_id);
 
-   proc_init(ps, procs, nitems(procs));
log_procinit("parent");
+   if (!debug && daemon(1, 0) == -1)
+   err(1, "failed to daemonize");
+
+   if (ps->ps_noaction == 0)
+   log_info("startup");
 
event_init();
 
@@ -217,7 +243,7 @@ main(int argc, char *argv[])
signal_add(>ps_evsigpipe, NULL);
signal_add(>ps_evsigusr1, NULL);
 
-   

Re: NAT-on-enc on iked(8)

2016-09-02 Thread Mike Belopuhov
On 1 September 2016 at 13:35, Vincent Gross  wrote:
> This diff adds the missing bits to support NAT-on-enc in iked(8).
>
> See OUTGOING NETWORK ADDRESS TRANSLATION in iked.conf(5), and also
> http://undeadly.org/cgi?action=article=20090127205841.
>
> Ok ?
>

OK mikeb



mbuf cluster and socket buffer limits

2016-09-02 Thread Alexander Bluhm
Hi,

To move our network performance to modern high bandwith and high
latency characteristics, we have to increase the socket buffer size
limit.  That also implies more mbuf clusters to avoid running out
of them.

This diff includes several aspects that somehow belong together.

- Increase the number of mbufs on most architectures.  I have to
  guess how much memory a typical machine has.  If the value is too
  high, we may run out of kernel memory.
  arch/alpha/include/param.h:#defineNMBCLUSTERS (16 * 1026)
  arch/amd64/include/param.h:#defineNMBCLUSTERS (256 * 1024)
  arch/arm/include/param.h:#define  NMBCLUSTERS (16 * 1024)
  arch/hppa/include/param.h:#define NMBCLUSTERS (4 * 1024)
  arch/i386/include/param.h:#define NMBCLUSTERS (32 * 1024)
  arch/m88k/include/param.h:#define NMBCLUSTERS (4 * 1024)
  arch/mips64/include/param.h:#define   NMBCLUSTERS (8 * 1024)
  arch/powerpc/include/param.h:#define  NMBCLUSTERS (4 * 1024)
  arch/sh/include/param.h:#define   NMBCLUSTERS (4 * 1024)
  arch/sparc64/include/param.h:#define  NMBCLUSTERS (16 * 1024)
- Set size of mclsizes array explicitly to keep it in sync with
  mclpools.
- Limit all mbuf cluster pools to the same memory size.  Having
  limits by number will allow the large clusters using too much
  memory.
- If sosend() cannot allocate a large cluster, try a small one as
  fallback.
- Reduce the factor of the limits derived form NMBCLUSTERS.  We
  want the additional clusters in the socket buffer and not elsewhere.
- Increase the socket buffer size limit from 256 KB to 2 MB.  If the
  value is too high, we may run out of mbufs.

Feel free to comment and ok the parts seperately.

bluhm

Index: arch/alpha/include/param.h
===
RCS file: /data/mirror/openbsd/cvs/src/sys/arch/alpha/include/param.h,v
retrieving revision 1.39
diff -u -p -r1.39 param.h
--- arch/alpha/include/param.h  26 Mar 2013 05:04:08 -  1.39
+++ arch/alpha/include/param.h  2 Sep 2016 15:35:35 -
@@ -63,7 +63,7 @@
 #defineUSPACE  (UPAGES * PAGE_SIZE)/* total size of u-area 
*/
 #defineUSPACE_ALIGN0   /* u-area alignment 
0-none */
 
-#defineNMBCLUSTERS 4096/* map size, max 
cluster allocation */
+#defineNMBCLUSTERS (16 * 1026) /* max cluster 
allocation */
 
 #ifndefMSGBUFSIZE
 #defineMSGBUFSIZE  (2 * PAGE_SIZE) /* default message 
buffer size */
Index: arch/amd64/include/param.h
===
RCS file: /data/mirror/openbsd/cvs/src/sys/arch/amd64/include/param.h,v
retrieving revision 1.22
diff -u -p -r1.22 param.h
--- arch/amd64/include/param.h  26 Mar 2013 05:04:10 -  1.22
+++ arch/amd64/include/param.h  2 Sep 2016 15:58:26 -
@@ -72,7 +72,7 @@
 #defineUSPACE  (UPAGES * PAGE_SIZE)/* total size of u-area 
*/
 #defineUSPACE_ALIGN0   /* u-area alignment 
0-none */
 
-#defineNMBCLUSTERS 6144/* map size, max 
cluster allocation */
+#defineNMBCLUSTERS (256 * 1024)/* max cluster 
allocation */
 
 #ifndefMSGBUFSIZE
 #defineMSGBUFSIZE  (16 * PAGE_SIZE)/* default message 
buffer size */
Index: arch/arm/include/param.h
===
RCS file: /data/mirror/openbsd/cvs/src/sys/arch/arm/include/param.h,v
retrieving revision 1.22
diff -u -p -r1.22 param.h
--- arch/arm/include/param.h20 Aug 2016 19:31:01 -  1.22
+++ arch/arm/include/param.h2 Sep 2016 16:00:12 -
@@ -55,7 +55,7 @@
 #defineUSPACE  (UPAGES * PAGE_SIZE)/* total size of u-area 
*/
 #defineUSPACE_ALIGN0   /* u-area alignment 
0-none */
 
-#defineNMBCLUSTERS 4096/* map size, max 
cluster allocation */
+#defineNMBCLUSTERS (16 * 1024) /* max cluster 
allocation */
 
 /*
  * Maximum size of the kernel malloc arena in PAGE_SIZE-sized
Index: arch/hppa/include/param.h
===
RCS file: /data/mirror/openbsd/cvs/src/sys/arch/hppa/include/param.h,v
retrieving revision 1.45
diff -u -p -r1.45 param.h
--- arch/hppa/include/param.h   26 Mar 2013 05:04:10 -  1.45
+++ arch/hppa/include/param.h   2 Sep 2016 15:39:12 -
@@ -51,7 +51,7 @@
 #defineUSPACE  (UPAGES * PAGE_SIZE)/* total size of u-area 
*/
 #defineUSPACE_ALIGN0   /* u-area alignment 
0-none */
 
-#defineNMBCLUSTERS 4096/* map size, max 
cluster allocation */
+#defineNMBCLUSTERS (4 * 1024)  /* max cluster 
allocation */
 
 #ifndefMSGBUFSIZE
 #defineMSGBUFSIZE  (2 

Re: send fewer router solicitations

2016-09-02 Thread Stuart Henderson
On 2016/09/02 10:37, Florian Obser wrote:
> To stop naddy from pestering me about this at every hackathon (rightly
> so!), let's base the timeout on the prefixes pltime. ;)

Just a thought, are we going to need to cap this to the RDNSS time too when
we start caring about that?



Mention the maximum packet size in ping.8

2016-09-02 Thread Michal Mazurek
Index: sbin/ping/ping.8
===
RCS file: /cvs/src/sbin/ping/ping.8,v
retrieving revision 1.52
diff -u -p -r1.52 ping.8
--- sbin/ping/ping.824 Mar 2014 11:11:49 -  1.52
+++ sbin/ping/ping.82 Sep 2016 16:35:50 -
@@ -176,6 +176,7 @@ Specifies the number of data bytes to be
 The default is 56,
 which translates into 64 ICMP data bytes
 when combined with the 8 bytes of ICMP header data.
+The maximum packet size is 65467.
 .It Fl T Ar toskeyword
 Change IPv4 TOS value.
 .Ar toskeyword

-- 
Michal Mazurek



Re: refactor gzip methods

2016-09-02 Thread Todd C. Miller
On Fri, 02 Sep 2016 12:02:20 -0400, "Ted Unangst" wrote:

> this diff doesn't change any behavior, but creates separate read
> and write open functions (which currently share quite a bit of code)
> that only take the necessary arguments.
> 
> it also deletes a never used zopen function. and removes completely
> unncessary mode checking, because these functions were only ever
> called with fixed strings.

Looks fine, OK millert@

 - todd



new style signing coming soon

2016-09-02 Thread Marc Espie
I've been working on a new way to sign archives, in preparation to a
change to pkg tools, with feedback from Theo and Tedu.

The actual problem happened in FreeBSD. They got a hole in their
gunzip pipeline a few weeks ago (rather subtle one). So if your
workflow is:

1/ fetch data -> 2/ uncompress it -> 3/ check signature -> 4/ process data

you've got TWO steps (1 and 2) that are relatively easy to tamper with, 
with potentially deadly consequences.

The solution is to move the signature outside of the gzip header. New
workflow is
1/ fetch data -> 2/ check signature -> 3/ uncompress -> 4/ process data

Since step 1/ is privsep, as long as step 2 is airtight, 3/ and 4/
are no longer vulnerable.

Just committed some preliminary code into signify that allows that.

Guidelines:
- small, self-contained code to parse simple gzip headers
- signify-style  signature in the gzip comment. Contains checksums of
64K blocks of the compressed archive
- don't even think about passing the original gzip header through
- use as a pipeline step: does not need to download full archive to
use it, and never ever pass any data to the gunzip part before it's been
verified.

Note that afaik we haven't had any hole in our gunzipping process. Well...
waiting for an accident to happen is not how we do things.  Hopefully, this
should prevent future mishaps.

-- 
Marc



Re: Better wording in ping error messages

2016-09-02 Thread Michal Mazurek
On 12:12:11,  2.09.16, Ted Unangst wrote:
> Michal Mazurek wrote:
> > worms(6) does this more concisely:
> > 
> > errx(1, "length (2-1024) is %s: %s", errstr,
> 
> there's multiple schools of thought here, but i've always preferred somewhat
> shorter error messages. we tell the user it's too small or too large already.
> if they need to know the exact bounds, they should consult the manual. maybe
> learn something else too.

The reason for this diff was difficulty in determining the max packet
size, which is 65467 and undocumented. You're saying this should instead
go into the manual page?

-- 
Michal Mazurek



Re: Better wording in ping error messages

2016-09-02 Thread Ted Unangst
Michal Mazurek wrote:
> On 12:12:11,  2.09.16, Ted Unangst wrote:
> > Michal Mazurek wrote:
> > > worms(6) does this more concisely:
> > > 
> > >   errx(1, "length (2-1024) is %s: %s", errstr,
> > 
> > there's multiple schools of thought here, but i've always preferred somewhat
> > shorter error messages. we tell the user it's too small or too large 
> > already.
> > if they need to know the exact bounds, they should consult the manual. maybe
> > learn something else too.
> 
> The reason for this diff was difficulty in determining the max packet
> size, which is 65467 and undocumented. You're saying this should instead
> go into the manual page?

I think that's a much better place to put it. I shouldn't have to run a
command with an absurdly large argument to force it to print the limit.



Re: constify auth functions

2016-09-02 Thread Ted Unangst
Todd C. Miller wrote:
> On Thu, 01 Sep 2016 13:27:49 -0400, "Ted Unangst" wrote:
> 
> > Ted Unangst wrote:
> > > I'm getting annoying warnings because these functions aren't const.
> > 
> > so
> > 
> > turns out several of these functions *do* modify their parameters. which is
> > probably chaos, because i think we sometimes call them with const 
> > parameters.
> 
> I think you'll have to constify login_cap(3) first since the auth
> functions call into login_cap(3).

right, let's start at the beginning.

these functions have the annoying property of unconsting their arguments,
requring the caller to wriggle through hoops. thoughts on changing the
interface to strdup the default argument? but then there's the error string,
which is returned if strdup fails... rugrgrugurgr.



Index: include/login_cap.h
===
RCS file: /cvs/src/include/login_cap.h,v
retrieving revision 1.15
diff -u -p -r1.15 login_cap.h
--- include/login_cap.h 21 Nov 2014 05:13:44 -  1.15
+++ include/login_cap.h 2 Sep 2016 13:46:57 -
@@ -91,14 +91,14 @@ typedef struct login_cap {
 __BEGIN_DECLS
 struct passwd;
 
-login_cap_t *login_getclass(char *);
+login_cap_t *login_getclass(const char *);
 voidlogin_close(login_cap_t *);
-int login_getcapbool(login_cap_t *, char *, unsigned int);
-quad_t  login_getcapnum(login_cap_t *, char *, quad_t, quad_t);
-quad_t  login_getcapsize(login_cap_t *, char *, quad_t, quad_t);
-char   *login_getcapstr(login_cap_t *, char *, char *, char *);
-quad_t  login_getcaptime(login_cap_t *, char *, quad_t, quad_t);
-char   *login_getstyle(login_cap_t *, char *, char *);
+int login_getcapbool(login_cap_t *, const char *, unsigned int);
+quad_t  login_getcapnum(login_cap_t *, const char *, quad_t, quad_t);
+quad_t  login_getcapsize(login_cap_t *, const char *, quad_t, quad_t);
+char   *login_getcapstr(login_cap_t *, const char *, const char *, const char 
*);
+quad_t  login_getcaptime(login_cap_t *, const char *, quad_t, quad_t);
+char   *login_getstyle(login_cap_t *, const char *, const char *);
 
 intsecure_path(char *);
 intsetclasscontext(char *, unsigned int);
Index: lib/libc/gen/login_cap.c
===
RCS file: /cvs/src/lib/libc/gen/login_cap.c,v
retrieving revision 1.34
diff -u -p -r1.34 login_cap.c
--- lib/libc/gen/login_cap.c10 Mar 2016 18:30:53 -  1.34
+++ lib/libc/gen/login_cap.c2 Sep 2016 13:51:16 -
@@ -78,7 +78,7 @@ staticu_quad_t strtosize(char *, char *
 static int gsetrl(login_cap_t *, int, char *, int);
 
 login_cap_t *
-login_getclass(char *class)
+login_getclass(const char *class)
 {
char *classfiles[2] = {NULL, NULL};
login_cap_t *lc;
@@ -149,7 +149,7 @@ login_getclass(char *class)
 DEF_WEAK(login_getclass);
 
 char *
-login_getstyle(login_cap_t *lc, char *style, char *atype)
+login_getstyle(login_cap_t *lc, const char *style, const char *atype)
 {
char **authtypes = _authtypes;
char *auths, *ta;
@@ -210,19 +210,19 @@ login_getstyle(login_cap_t *lc, char *st
 DEF_WEAK(login_getstyle);
 
 char *
-login_getcapstr(login_cap_t *lc, char *cap, char *def, char *e)
+login_getcapstr(login_cap_t *lc, const char *cap, const char *def, const char 
*e)
 {
-   char *res = NULL, *str = e;
+   char *res = NULL, *str = (char *)e;
int stat;
 
errno = 0;
 
if (!lc->lc_cap)
-   return (def);
+   return ((char *)def);
 
switch (stat = cgetstr(lc->lc_cap, cap, )) {
case -1:
-   str = def;
+   str = (char *)def;
break;
case -2:
syslog(LOG_ERR, "%s: getting capability %s: %m",
@@ -245,7 +245,7 @@ login_getcapstr(login_cap_t *lc, char *c
 DEF_WEAK(login_getcapstr);
 
 quad_t
-login_getcaptime(login_cap_t *lc, char *cap, quad_t def, quad_t e)
+login_getcaptime(login_cap_t *lc, const char *cap, quad_t def, quad_t e)
 {
char *ep;
char *res = NULL, *sres;
@@ -330,7 +330,7 @@ invalid:
 DEF_WEAK(login_getcaptime);
 
 quad_t
-login_getcapnum(login_cap_t *lc, char *cap, quad_t def, quad_t e)
+login_getcapnum(login_cap_t *lc, const char *cap, quad_t def, quad_t e)
 {
char *ep;
char *res = NULL;
@@ -384,7 +384,7 @@ login_getcapnum(login_cap_t *lc, char *c
 DEF_WEAK(login_getcapnum);
 
 quad_t
-login_getcapsize(login_cap_t *lc, char *cap, quad_t def, quad_t e)
+login_getcapsize(login_cap_t *lc, const char *cap, quad_t def, quad_t e)
 {
char *ep;
char *res = NULL;
@@ -432,7 +432,7 @@ login_getcapsize(login_cap_t *lc, char *
 DEF_WEAK(login_getcapsize);
 
 int
-login_getcapbool(login_cap_t *lc, char *cap, u_int def)
+login_getcapbool(login_cap_t *lc, const char *cap, u_int def)
 {
if (!lc->lc_cap)
return (def);



Re: Better wording in ping error messages

2016-09-02 Thread Ted Unangst
Michal Mazurek wrote:
> worms(6) does this more concisely:
> 
>   errx(1, "length (2-1024) is %s: %s", errstr,

there's multiple schools of thought here, but i've always preferred somewhat
shorter error messages. we tell the user it's too small or too large already.
if they need to know the exact bounds, they should consult the manual. maybe
learn something else too.

in the case of tos, this message is now too specific because it says that tos
must be a number, but there are many keyword values that are accepted too. the
user would learn this by reading the man page.

>   if (tos < 0 || tos > 255 || errstr || errno)
> - errx(1, "illegal tos value %s", optarg);
> + errx(1, "illegal tos value %s; provide a "
> + "value between 0 and 255 inclusive",
> + optarg);



Better wording in ping error messages

2016-09-02 Thread Michal Mazurek
worms(6) does this more concisely:

errx(1, "length (2-1024) is %s: %s", errstr,


Index: ping.c
===
RCS file: /cvs/src/sbin/ping/ping.c,v
retrieving revision 1.142
diff -u -p -r1.142 ping.c
--- ping.c  30 Aug 2016 14:28:31 -  1.142
+++ ping.c  2 Sep 2016 16:01:53 -
@@ -295,8 +295,9 @@ main(int argc, char *argv[])
case 's':   /* size of packet to send */
datalen = strtonum(optarg, 0, MAXPAYLOAD, );
if (errstr)
-   errx(1, "packet size is %s: %s", errstr,
-   optarg);
+   errx(1, "packet size is %s: %s; provide a "
+   "value between 0 and %d inclusive", errstr,
+   optarg, MAXPAYLOAD);
break;
 #ifndef SMALL
case 'T':
@@ -311,20 +312,25 @@ main(int argc, char *argv[])
else
tos = strtonum(optarg, 0, 255, );
if (tos < 0 || tos > 255 || errstr || errno)
-   errx(1, "illegal tos value %s", optarg);
+   errx(1, "illegal tos value %s; provide a "
+   "value between 0 and 255 inclusive",
+   optarg);
break;
 #endif /* SMALL */
case 't':
options |= F_TTL;
ttl = strtonum(optarg, 0, MAXTTL, );
if (errstr)
-   errx(1, "ttl value is %s: %s", errstr, optarg);
+   errx(1, "ttl value is %s: %s; provide a "
+   "value between 0 and %d inclusive",
+   errstr, optarg, MAXTTL);
break;
case 'V':
rtableid = strtonum(optarg, 0, RT_TABLEID_MAX, );
if (errstr)
-   errx(1, "rtable value is %s: %s", errstr,
-   optarg);
+   errx(1, "rtable value is %s: %s; provide a "
+   "value between 0 and %d inclusive", errstr,
+   optarg, RT_TABLEID_MAX);
if (setsockopt(s, SOL_SOCKET, SO_RTABLE, ,
sizeof(rtableid)) == -1)
err(1, "setsockopt SO_RTABLE");

-- 
Michal Mazurek



refactor gzip methods

2016-09-02 Thread Ted Unangst
the code in gzip uses a function pointer abstraction but tries to shove too
much code into the same functions. this is impeding work to refactor the code
to fork + pledge helper processes.

in many cases, the duplication results absurd code like this:

error = (decomp ? dodecompress : docompress)
(infile, outfile, method, bits, entry->fts_statp);

what? why are we passing bits to a decompressor? because somebody was a little
too enamored with ?: operations.

this diff doesn't change any behavior, but creates separate read and write
open functions (which currently share quite a bit of code) that only take the
necessary arguments.

it also deletes a never used zopen function. and removes completely unncessary
mode checking, because these functions were only ever called with fixed
strings.


Index: compress.h
===
RCS file: /cvs/src/usr.bin/compress/compress.h,v
retrieving revision 1.12
diff -u -p -r1.12 compress.h
--- compress.h  22 Sep 2011 10:41:04 -  1.12
+++ compress.h  2 Sep 2016 15:53:55 -
@@ -58,26 +58,23 @@ enum program_mode {
 
 extern char null_magic[];
 
-extern void *z_open(int, const char *, char *, int, u_int32_t, int);
+extern void *z_ropen(int, char *, int);
+extern void *z_wopen(int, char *, int, u_int32_t);
 extern FILE *zopen(const char *, const char *,int);
 extern int zread(void *, char *, int);
 extern int zwrite(void *, const char *, int);
 extern int z_close(void *, struct z_info *, const char *, struct stat *);
 
 
-extern void *gz_open(int, const char *, char *, int, u_int32_t, int);
+extern void *gz_ropen(int, char *, int);
+extern void *gz_wopen(int, char *, int, u_int32_t);
 extern int gz_read(void *, char *, int);
 extern int gz_write(void *, const char *, int);
 extern int gz_close(void *, struct z_info *, const char *, struct stat *);
 extern int gz_flush(void *, int);
 
-extern void *lzh_open(int, const char *, char *, int, u_int32_t, int);
-extern int lzh_read(void *, char *, int);
-extern int lzh_write(void *, const char *, int);
-extern int lzh_close(void *, struct z_info *);
-extern int lzh_flush(void *, int);
-
-extern void *null_open(int, const char *, char *, int, u_int32_t, int);
+extern void *null_ropen(int, char *, int);
+extern void *null_wopen(int, char *, int, u_int32_t);
 extern int null_read(void *, char *, int);
 extern int null_write(void *, const char *, int);
 extern int null_close(void *, struct z_info *, const char *, struct stat *);
Index: gzopen.c
===
RCS file: /cvs/src/usr.bin/compress/gzopen.c,v
retrieving revision 1.32
diff -u -p -r1.32 gzopen.c
--- gzopen.c17 Aug 2016 12:02:38 -  1.32
+++ gzopen.c2 Sep 2016 15:57:39 -
@@ -103,16 +103,14 @@ static int put_header(gz_stream *, char 
 static int get_byte(gz_stream *);
 
 void *
-gz_open(int fd, const char *mode, char *name, int bits,
-u_int32_t mtime, int gotmagic)
+gz_wopen(int fd, char *name, int bits, u_int32_t mtime)
 {
gz_stream *s;
 
-   if (fd < 0 || !mode)
+   if (fd < 0)
return NULL;
 
-   if ((mode[0] != 'r' && mode[0] != 'w') || mode[1] != '\0' ||
-   bits < 0 || bits > Z_BEST_COMPRESSION) {
+   if (bits < 0 || bits > Z_BEST_COMPRESSION) {
errno = EINVAL;
return NULL;
}
@@ -132,45 +130,74 @@ gz_open(int fd, const char *mode, char *
s->z_total_in = 0;
s->z_total_out = 0;
s->z_crc = crc32(0L, Z_NULL, 0);
-   s->z_mode = mode[0];
+   s->z_mode = 'w';
 
-   if (s->z_mode == 'w') {
 #ifndef SMALL
-   /* windowBits is passed < 0 to suppress zlib header */
-   if (deflateInit2(&(s->z_stream), bits, Z_DEFLATED,
--MAX_WBITS, DEF_MEM_LEVEL, 0) != Z_OK) {
-   free (s);
-   return NULL;
-   }
-   s->z_stream.next_out = s->z_buf;
+   /* windowBits is passed < 0 to suppress zlib header */
+   if (deflateInit2(&(s->z_stream), bits, Z_DEFLATED,
+-MAX_WBITS, DEF_MEM_LEVEL, 0) != Z_OK) {
+   free (s);
+   return NULL;
+   }
+   s->z_stream.next_out = s->z_buf;
 #else
-   free(s);
-   return (NULL);
+   free(s);
+   return (NULL);
 #endif
-   } else {
-   if (inflateInit2(&(s->z_stream), -MAX_WBITS) != Z_OK) {
-   free (s);
-   return NULL;
-   }
-   s->z_stream.next_in = s->z_buf;
+   s->z_stream.avail_out = Z_BUFSIZE;
+
+   errno = 0;
+   s->z_fd = fd;
+
+   /* write the .gz header */
+   if (put_header(s, name, mtime, bits) != 0) {
+   gz_close(s, NULL, NULL, NULL);
+   s = NULL;
+   }
+
+   return s;
+}
+
+void *
+gz_ropen(int fd, char *name, int gotmagic)
+{
+

acpixtu: Intel Extreme Tuning driver

2016-09-02 Thread Paul Irofti
Hi,

Here is a work-in-progress driver for the Intel eXtreme Tuning Utility.
The main purpose is to add more sensors to the existing pool.

I am very interested in tests on recent Intel K- and X-series processors!
None the less, please test on all Intel cpus and if you see acpixtu
attaching please send me a private mail with the dmesg and acpidump.


I initially implemented it for the x260, but there is a mysterious XTUS
AML external method that seems to be blocking it on my machine. I tried
overwritting it with hacks in dsdt.c but failed.

After seeing a few more acpidumps (that don't have the blocking XTUS
method) I decided to send it here for wider tests.


Thank you,
Paul


Index: arch/amd64/amd64/locore.S
===
RCS file: /cvs/src/sys/arch/amd64/amd64/locore.S,v
retrieving revision 1.82
diff -u -p -u -p -r1.82 locore.S
--- arch/amd64/amd64/locore.S   16 Jul 2016 06:04:29 -  1.82
+++ arch/amd64/amd64/locore.S   2 Sep 2016 15:05:06 -
@@ -1202,3 +1202,18 @@ _C_LABEL(xen_hypercall_page):
 _C_LABEL(hv_hypercall_page):
.skip   0x1000, 0xcc
 #endif /* NXEN > 0 */
+
+/* acpixtu_smi_read(sc->sc_fadt->smi_cmd, xtu_port, _addr) */
+ENTRY(acpixtu_smi_read)
+   /* Read BIOS Settings Command */
+   xorl%ecx,%ecx
+   /* 32-bit Physical Memory Data Location */
+   movl%edx, %ebx
+   /* Write the SW SMI Command Value to the SW SMI Port */
+   movq%rdi, %rdx
+   movq%rsi, %rax
+   outb%al, %dx
+   /* Return Value in EBX */
+   xorq%rax, %rax
+   movl%ebx, %eax
+   ret
Index: arch/amd64/conf/GENERIC
===
RCS file: /cvs/src/sys/arch/amd64/conf/GENERIC,v
retrieving revision 1.430
diff -u -p -u -p -r1.430 GENERIC
--- arch/amd64/conf/GENERIC 1 Sep 2016 10:04:51 -   1.430
+++ arch/amd64/conf/GENERIC 2 Sep 2016 15:05:07 -
@@ -67,6 +67,7 @@ sdhc* at acpi?
 acpicbkbd* at acpi?
 acpials*   at acpi?
 tpm*   at acpi?
+acpixtu*   at acpi?
 
 mpbios0at bios0
 
Index: dev/acpi/acpireg.h
===
RCS file: /cvs/src/sys/dev/acpi/acpireg.h,v
retrieving revision 1.36
diff -u -p -u -p -r1.36 acpireg.h
--- dev/acpi/acpireg.h  10 Jul 2016 20:36:41 -  1.36
+++ dev/acpi/acpireg.h  2 Sep 2016 15:05:07 -
@@ -778,4 +778,7 @@ struct acpi_ivrs {
 #define ACPI_DEV_DWIIC4"INT3433"
 #define ACPI_DEV_DWIIC5"80860F41"
 
+/* Intel Extreme Tuning Utility */
+#define ACPI_DEV_XTU "INT3394"
+
 #endif /* !_DEV_ACPI_ACPIREG_H_ */
Index: dev/acpi/acpixtu.c
===
RCS file: dev/acpi/acpixtu.c
diff -N dev/acpi/acpixtu.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ dev/acpi/acpixtu.c  2 Sep 2016 15:05:07 -
@@ -0,0 +1,252 @@
+/* $OpenBSD$   */
+/*
+ * Copyright (c) 2016 Paul Irofti 
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+struct acpixtu_softc {
+   struct device sc_dev;
+
+   struct acpi_softc *sc_acpi;
+   struct aml_node *sc_devnode;
+
+   int sc_tsdd;
+   int sc_vsdd;
+   int sc_fsdd;
+};
+
+intacpixtu_match(struct device *, void *, void *);
+void   acpixtu_attach(struct device *, struct device *, void *);
+intacpixtu_notify(struct aml_node *, int, void *);
+
+struct cfattach acpixtu_ca = {
+   sizeof(struct acpixtu_softc), acpixtu_match, acpixtu_attach
+};
+
+struct cfdriver acpixtu_cd = {
+   NULL, "acpixtu", DV_DULL
+};
+
+static const char *acpixtu_hids[] = { ACPI_DEV_XTU, 0 };
+uint32_t acpixtu_smi_read(int, int, uint8_t *);
+
+static int
+acpixtu_get_data(struct acpixtu_softc *sc, char *method)
+{
+   struct aml_value res;
+   int i;
+
+   if (aml_evalname(sc->sc_acpi, sc->sc_devnode, method, 0, NULL, )) {
+   printf("%s: %s method is absent\n", DEVNAME(sc), method);
+   return 1;
+   }
+   printf("%s: %s(%s) AML dump\n", DEVNAME(sc), __func__, method);
+   aml_showvalue();
+   if (res.type == 

Re: mg(1) Initialize stack variables to zero before memmove()

2016-09-02 Thread Todd C. Miller
On Fri, 02 Sep 2016 07:10:38 -, Mark Lumsden wrote:

> Source Joachim Nilsson:
> 
> Coverity Scan reported these two stack variables as uninitialized, in
> particular the .r_lineno struct member was uninitialized.  This patch
> clears the 'struct region' rather than setting .r_lineno because if
> any more struct members are added in the future the clear will cover
> them too.
> 
> I think Joachim's approach is sensible. ok?

OK millert@

 - todd



Re: Diff: Fix wrong bzero call in snmpd

2016-09-02 Thread Mike Belopuhov
On Fri, Sep 02, 2016 at 16:56 +0200, Jan Klemkow wrote:
> Hi,
> 
> When a new IP address shows up on an interface, the function
> if_newaddr() save this IP address and its mask and boardcast address
> into a data structure.  If the corresponding IP mask or broad cast
> address is not set, their data fields in this structure are bzero()-ed.
> 
> But, the code wipes the mask field if the broadcast address is not set
> an leave the broadcast field untouched.
> 
> The diff below should fix this problem.
>

Yes, looks like a pasto to me.  OK mikeb

> bye,
> Jan
> 
> Index: kroute.c
> ===
> RCS file: /mount/openbsd/cvs/src/usr.sbin/snmpd/kroute.c,v
> retrieving revision 1.32
> diff -u -p -r1.32 kroute.c
> --- kroute.c  3 Nov 2015 07:48:03 -   1.32
> +++ kroute.c  2 Sep 2016 13:51:59 -
> @@ -1127,7 +1127,7 @@ if_newaddr(u_short if_index, struct sock
>   if (brd)
>   bcopy(brd, >dstbrd.sa, brd->sa_len);
>   else
> - bzero(>mask, sizeof(ka->mask));
> + bzero(>dstbrd, sizeof(ka->dstbrd));
>  
>  }
> 



Diff: Fix wrong bzero call in snmpd

2016-09-02 Thread Jan Klemkow
Hi,

When a new IP address shows up on an interface, the function
if_newaddr() save this IP address and its mask and boardcast address
into a data structure.  If the corresponding IP mask or broad cast
address is not set, their data fields in this structure are bzero()-ed.

But, the code wipes the mask field if the broadcast address is not set
an leave the broadcast field untouched.

The diff below should fix this problem.

bye,
Jan

Index: kroute.c
===
RCS file: /mount/openbsd/cvs/src/usr.sbin/snmpd/kroute.c,v
retrieving revision 1.32
diff -u -p -r1.32 kroute.c
--- kroute.c3 Nov 2015 07:48:03 -   1.32
+++ kroute.c2 Sep 2016 13:51:59 -
@@ -1127,7 +1127,7 @@ if_newaddr(u_short if_index, struct sock
if (brd)
bcopy(brd, >dstbrd.sa, brd->sa_len);
else
-   bzero(>mask, sizeof(ka->mask));
+   bzero(>dstbrd, sizeof(ka->dstbrd));
 
 }



Re: switch the cubie miniroot to cubieboard2

2016-09-02 Thread sid77
- Original Message -
> si...@slackware.it [si...@slackware.it] wrote:
> > Speaking as a Cubieboard owner here ;-)
> > Would it be too much hassle to provide both images? (and a pony!)
> > 
> 
> It's fairly easy to take a miniroot image for a similar board, and
> adapt it to your board.

Thanks for the tutorial!

> 
> Since both the Cubieboard and Cubieboard2 are Allwinner based,
> the miniroot's general structure does not change.
> 
> 1. Install u-boot-2016.07p1 from ports/packages (packages if you don't
> want to wait all day)
> 
> 2. Examine /usr/src/distrib/armv7/ramdisk/install.md and find
> a similar board (same or similar chipset).
> 
> 3. Find the proper u-boot/dtb stuff in /usr/local/share/u-boot
> 
> 4. Download the miniroot image for a board that has the same
> or similar chipset to your board
> 
> 5. vnconfig vnd0 miniroot.fs
> 
> 6. Install proper u-boot image to the miniroot image. The install.md
> file tells you how to copy the proper u-boot/dtb over. For instance,
> Cubieboard is Allwinner A10/A20, and my Lime is A20.
> 
> install.md says:
> 
>   cubie)
> dd if=$_mdec/u-boot-sunxi-with-spl.bin of=${_disk}c \
> bs=1024 seek=8 >/dev/null 2>&1
> 
> So, to get my Lime or Lime2 working, I do this:
> 
> dd if=/usr/local/share/u-boot/A20-OLinuXino-Lime2/u-boot-sunxi-with-spl.bin
> of=/dev/rvnd0c bs=1024 seek=8
> 
> (Note: Lime and lime2 bootloaders will appear to work on both boards,
> but if you don't use the right one, the Realtek ethernet PHY will
> not be properly initialized.)
> 
> 7. vnconfig -u vnd0
> 
> 8. Write miniroot.fs to your SD card
> 
> You don't have to use vnd, but this is conceptually simpler
> and less error prone than trying to chop it up with dd.
> 
> Chris
> 

-- 
Marco Bonetti



Re: Futexes for OpenBSD

2016-09-02 Thread Amit Kulkarni
The new files should have the ISC/OpenBSD license inserted at the top.

IMHO, the ticket changes are a separate diff and you will be able to commit
that part first.

Also, replacing struct _spinlock with int is also a separate diff.

Those changes don't clash with futexes, so less chance of being reverted.

Thanks


On Fri, Sep 2, 2016 at 8:36 AM, Michal Mazurek  wrote:

> Here is a working futex implementation for OpenBSD. This diff touches
> the kernel and librthread.
>
> * get rid of tickets from rthreads, they were getting in the way and are
> unused anyway
> * replace all struct _spinlock with int
> * use futexes instead of spinlocks everywhere within librthread
> * librthread no longer calls sched_yield(), nor does it spin
>
> Any comments?
>
> Index: lib/librthread/Makefile
> ===
> RCS file: /cvs/src/lib/librthread/Makefile,v
> retrieving revision 1.43
> diff -u -p -r1.43 Makefile
> --- lib/librthread/Makefile 1 Jun 2016 04:34:18 -   1.43
> +++ lib/librthread/Makefile 2 Sep 2016 13:09:44 -
> @@ -18,7 +18,8 @@ CFLAGS+=-DNO_PIC
>  VERSION_SCRIPT= ${.CURDIR}/Symbols.map
>
>  .PATH: ${.CURDIR}/arch/${MACHINE_CPU}
> -SRCS=  rthread.c \
> +SRCS=  futex.c \
> +   rthread.c \
> rthread_attr.c \
> rthread_barrier.c \
> rthread_barrier_attr.c \
> Index: lib/librthread/futex.c
> ===
> RCS file: lib/librthread/futex.c
> diff -N lib/librthread/futex.c
> --- /dev/null   1 Jan 1970 00:00:00 -
> +++ lib/librthread/futex.c  2 Sep 2016 13:09:44 -
> @@ -0,0 +1,41 @@
> +#include 
> +
> +#include 
> +#include "thread_private.h"
> +#include "rthread.h"
> +
> +inline int
> +futex_lock(volatile int *val)
> +{
> +   int c;
> +
> +   if ((c = __sync_val_compare_and_swap(val, 0, 1)) != 0) {
> +   do {
> +   if (c == 2 || __sync_val_compare_and_swap(val, 1,
> 2) != 0) {
> +   futex(val, FUTEX_WAIT, 2, NULL, NULL, 0);
> +   }
> +   } while ((c = __sync_val_compare_and_swap(val, 0, 2)) !=
> 0);
> +   }
> +
> +   return 0;
> +}
> +
> +inline int
> +futex_trylock(volatile int *val)
> +{
> +   if ((__sync_val_compare_and_swap(val, 0, 1)) != 0)
> +   return 1;
> +
> +   return 0;
> +}
> +
> +inline int
> +futex_unlock(volatile int *val)
> +{
> +   if (__sync_sub_and_fetch(val, 1) != 0) {
> +   *val = 0;
> +   futex(val, FUTEX_WAKE, 1, NULL, NULL, 0);
> +   }
> +
> +   return 0;
> +}
> Index: lib/librthread/rthread.c
> ===
> RCS file: /cvs/src/lib/librthread/rthread.c,v
> retrieving revision 1.92
> diff -u -p -r1.92 rthread.c
> --- lib/librthread/rthread.c1 Sep 2016 10:41:02 -   1.92
> +++ lib/librthread/rthread.c2 Sep 2016 13:09:44 -
> @@ -63,15 +63,15 @@ REDIRECT_SYSCALL(thrkill);
>
>  static int concurrency_level;  /* not used */
>
> -struct _spinlock _SPINLOCK_UNLOCKED_ASSIGN = _SPINLOCK_UNLOCKED;
> +int _SPINLOCK_UNLOCKED_ASSIGN = _SPINLOCK_UNLOCKED;
>
>  int _threads_ready;
>  size_t _thread_pagesize;
>  struct listhead _thread_list = LIST_HEAD_INITIALIZER(_thread_list);
> -struct _spinlock _thread_lock = _SPINLOCK_UNLOCKED;
> +int _thread_lock = 0;
>  static struct pthread_queue _thread_gc_list
>  = TAILQ_HEAD_INITIALIZER(_thread_gc_list);
> -static struct _spinlock _thread_gc_lock = _SPINLOCK_UNLOCKED;
> +int _thread_gc_lock = 0;
>  static struct pthread _initial_thread;
>
>  struct pthread_attr _rthread_attr_default = {
> @@ -88,23 +88,22 @@ struct pthread_attr _rthread_attr_defaul
>  /*
>   * internal support functions
>   */
> -void
> -_spinlock(volatile struct _spinlock *lock)
> +inline void
> +_spinlock(volatile int *lock)
>  {
> -   while (_atomic_lock(>ticket))
> -   sched_yield();
> +   futex_lock(lock);
>  }
>
> -int
> -_spinlocktry(volatile struct _spinlock *lock)
> +inline int
> +_spinlocktry(volatile int *lock)
>  {
> -   return 0 == _atomic_lock(>ticket);
> +   return 0 == futex_trylock(lock);
>  }
>
> -void
> -_spinunlock(volatile struct _spinlock *lock)
> +inline void
> +_spinunlock(volatile int *lock)
>  {
> -   lock->ticket = _ATOMIC_LOCK_UNLOCKED;
> +   futex_unlock(lock);
>  }
>
>  static void
> @@ -643,7 +642,7 @@ _thread_dump_info(void)
>  void
>  _rthread_dl_lock(int what)
>  {
> -   static struct _spinlock lock = _SPINLOCK_UNLOCKED;
> +   static int lock = _SPINLOCK_UNLOCKED;
> static pthread_t owner = NULL;
> static struct pthread_queue lockers =
> TAILQ_HEAD_INITIALIZER(lockers);
> static int count = 0;
> @@ -658,8 +657,7 @@ _rthread_dl_lock(int what)
> } else if (owner != self) {
> TAILQ_INSERT_TAIL(, self, waiting);
>

acpi: remove unused argument in aml_showvalue()

2016-09-02 Thread Paul Irofti
Hi,

This diff removes the second argument of aml_showvalue which was
probably supposed to set the verbosity level through dnprintf() but in
fact it does nothing.

OK?


Index: acpicpu.c
===
RCS file: /cvs/src/sys/dev/acpi/acpicpu.c,v
retrieving revision 1.75
diff -u -p -u -p -r1.75 acpicpu.c
--- acpicpu.c   28 Jul 2016 21:57:56 -  1.75
+++ acpicpu.c   2 Sep 2016 13:44:42 -
@@ -368,7 +368,7 @@ acpicpu_add_cstatepkg(struct aml_value *
int state, method, flags;
 
 #if defined(ACPI_DEBUG) && !defined(SMALL_KERNEL)
-   aml_showvalue(val, 0);
+   aml_showvalue(val);
 #endif
if (val->type != AML_OBJTYPE_PACKAGE || val->length != 4)
return;
@@ -468,7 +468,7 @@ void
 acpicpu_add_cdeppkg(struct aml_value *val, void *arg)
 {
 #if 1 || defined(ACPI_DEBUG) && !defined(SMALL_KERNEL)
-   aml_showvalue(val, 0);
+   aml_showvalue(val);
 #endif
if (val->type != AML_OBJTYPE_PACKAGE || val->length < 6 ||
val->length != val->v_package[0]->v_integer) {
Index: dsdt.c
===
RCS file: /cvs/src/sys/dev/acpi/dsdt.c,v
retrieving revision 1.223
diff -u -p -u -p -r1.223 dsdt.c
--- dsdt.c  8 May 2016 11:08:01 -   1.223
+++ dsdt.c  2 Sep 2016 13:44:45 -
@@ -289,14 +289,14 @@ _aml_die(const char *fn, int line, const
sp = aml_getstack(root, AMLOP_ARG0+idx);
if (sp && sp->type) {
printf("  arg%d: ", idx);
-   aml_showvalue(sp, 0);
+   aml_showvalue(sp);
}
}
for (idx = 0; idx < AML_MAX_LOCAL; idx++) {
sp = aml_getstack(root, AMLOP_LOCAL0+idx);
if (sp && sp->type) {
printf("  local%d: ", idx);
-   aml_showvalue(sp, 0);
+   aml_showvalue(sp);
}
}
}
@@ -786,7 +786,7 @@ aml_unlockfield(struct aml_scope *scope,
 
 #ifndef SMALL_KERNEL
 void
-aml_showvalue(struct aml_value *val, int lvl)
+aml_showvalue(struct aml_value *val)
 {
int idx;
 
@@ -809,7 +809,7 @@ aml_showvalue(struct aml_value *val, int
case AML_OBJTYPE_PACKAGE:
printf(" package: %.2x\n", val->length);
for (idx = 0; idx < val->length; idx++)
-   aml_showvalue(val->v_package[idx], lvl);
+   aml_showvalue(val->v_package[idx]);
break;
case AML_OBJTYPE_BUFFER:
printf(" buffer: %.2x {", val->length);
@@ -862,7 +862,7 @@ aml_showvalue(struct aml_value *val, int
case AML_OBJTYPE_OBJREF:
printf(" objref: %p index:%x opcode:%s\n", val->v_objref.ref,
val->v_objref.index, aml_mnem(val->v_objref.type, 0));
-   aml_showvalue(val->v_objref.ref, lvl);
+   aml_showvalue(val->v_objref.ref);
break;
default:
printf(" !!type: %x\n", val->type);
@@ -1855,14 +1855,14 @@ aml_showstack(struct aml_scope *scope)
sp = aml_getstack(scope, AMLOP_ARG0+idx);
if (sp && sp->type) {
dnprintf(10," Arg%d: ", idx);
-   aml_showvalue(sp, 10);
+   aml_showvalue(sp);
}
}
for (idx=0; scope->locals && idx<8; idx++) {
sp = aml_getstack(scope, AMLOP_LOCAL0+idx);
if (sp && sp->type) {
dnprintf(10," Local%d: ", idx);
-   aml_showvalue(sp, 10);
+   aml_showvalue(sp);
}
}
 }
@@ -2070,7 +2070,7 @@ aml_convert(struct aml_value *a, int cty
}
if (c == NULL) {
 #ifndef SMALL_KERNEL
-   aml_showvalue(a, 0);
+   aml_showvalue(a);
 #endif
aml_die("Could not convert %x to %x\n", a->type, ctype);
}
@@ -3174,7 +3174,7 @@ aml_eval(struct aml_scope *scope, struct
dnprintf(10,"\n--==Finished evaluating method: %s %c\n",
aml_nodename(tmp->node), ret_type);
 #ifdef ACPI_DEBUG
-   aml_showvalue(my_ret, 0);
+   aml_showvalue(my_ret);
aml_showstack(ms);
 #endif
aml_popscope(ms);
@@ -3189,7 +3189,7 @@ aml_eval(struct aml_scope *scope, struct
}
if (ret_type == 'i' && my_ret && my_ret->type != AML_OBJTYPE_INTEGER) {
 #ifndef SMALL_KERNEL
-   aml_showvalue(my_ret, 8-100);
+   aml_showvalue(my_ret);
 #endif
aml_die("Not Integer");
}
@@ -3725,7 +3725,7 @@ aml_parse(struct aml_scope *scope, int r
idx = opargs[1]->v_integer;
if (idx >= 

Futexes for OpenBSD

2016-09-02 Thread Michal Mazurek
Here is a working futex implementation for OpenBSD. This diff touches
the kernel and librthread.

* get rid of tickets from rthreads, they were getting in the way and are
unused anyway
* replace all struct _spinlock with int
* use futexes instead of spinlocks everywhere within librthread
* librthread no longer calls sched_yield(), nor does it spin

Any comments?

Index: lib/librthread/Makefile
===
RCS file: /cvs/src/lib/librthread/Makefile,v
retrieving revision 1.43
diff -u -p -r1.43 Makefile
--- lib/librthread/Makefile 1 Jun 2016 04:34:18 -   1.43
+++ lib/librthread/Makefile 2 Sep 2016 13:09:44 -
@@ -18,7 +18,8 @@ CFLAGS+=-DNO_PIC
 VERSION_SCRIPT= ${.CURDIR}/Symbols.map
 
 .PATH: ${.CURDIR}/arch/${MACHINE_CPU}
-SRCS=  rthread.c \
+SRCS=  futex.c \
+   rthread.c \
rthread_attr.c \
rthread_barrier.c \
rthread_barrier_attr.c \
Index: lib/librthread/futex.c
===
RCS file: lib/librthread/futex.c
diff -N lib/librthread/futex.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ lib/librthread/futex.c  2 Sep 2016 13:09:44 -
@@ -0,0 +1,41 @@
+#include 
+
+#include 
+#include "thread_private.h"
+#include "rthread.h"
+
+inline int
+futex_lock(volatile int *val)
+{
+   int c;
+
+   if ((c = __sync_val_compare_and_swap(val, 0, 1)) != 0) {
+   do {
+   if (c == 2 || __sync_val_compare_and_swap(val, 1, 2) != 
0) {
+   futex(val, FUTEX_WAIT, 2, NULL, NULL, 0);
+   }
+   } while ((c = __sync_val_compare_and_swap(val, 0, 2)) != 0);
+   }
+
+   return 0;
+}
+
+inline int
+futex_trylock(volatile int *val)
+{
+   if ((__sync_val_compare_and_swap(val, 0, 1)) != 0)
+   return 1;
+
+   return 0;
+}
+
+inline int
+futex_unlock(volatile int *val)
+{
+   if (__sync_sub_and_fetch(val, 1) != 0) {
+   *val = 0;
+   futex(val, FUTEX_WAKE, 1, NULL, NULL, 0);
+   }
+
+   return 0;
+}
Index: lib/librthread/rthread.c
===
RCS file: /cvs/src/lib/librthread/rthread.c,v
retrieving revision 1.92
diff -u -p -r1.92 rthread.c
--- lib/librthread/rthread.c1 Sep 2016 10:41:02 -   1.92
+++ lib/librthread/rthread.c2 Sep 2016 13:09:44 -
@@ -63,15 +63,15 @@ REDIRECT_SYSCALL(thrkill);
 
 static int concurrency_level;  /* not used */
 
-struct _spinlock _SPINLOCK_UNLOCKED_ASSIGN = _SPINLOCK_UNLOCKED;
+int _SPINLOCK_UNLOCKED_ASSIGN = _SPINLOCK_UNLOCKED;
 
 int _threads_ready;
 size_t _thread_pagesize;
 struct listhead _thread_list = LIST_HEAD_INITIALIZER(_thread_list);
-struct _spinlock _thread_lock = _SPINLOCK_UNLOCKED;
+int _thread_lock = 0;
 static struct pthread_queue _thread_gc_list
 = TAILQ_HEAD_INITIALIZER(_thread_gc_list);
-static struct _spinlock _thread_gc_lock = _SPINLOCK_UNLOCKED;
+int _thread_gc_lock = 0;
 static struct pthread _initial_thread;
 
 struct pthread_attr _rthread_attr_default = {
@@ -88,23 +88,22 @@ struct pthread_attr _rthread_attr_defaul
 /*
  * internal support functions
  */
-void
-_spinlock(volatile struct _spinlock *lock)
+inline void
+_spinlock(volatile int *lock)
 {
-   while (_atomic_lock(>ticket))
-   sched_yield();
+   futex_lock(lock);
 }
 
-int
-_spinlocktry(volatile struct _spinlock *lock)
+inline int
+_spinlocktry(volatile int *lock)
 {
-   return 0 == _atomic_lock(>ticket);
+   return 0 == futex_trylock(lock);
 }
 
-void
-_spinunlock(volatile struct _spinlock *lock)
+inline void
+_spinunlock(volatile int *lock)
 {
-   lock->ticket = _ATOMIC_LOCK_UNLOCKED;
+   futex_unlock(lock);
 }
 
 static void
@@ -643,7 +642,7 @@ _thread_dump_info(void)
 void
 _rthread_dl_lock(int what)
 {
-   static struct _spinlock lock = _SPINLOCK_UNLOCKED;
+   static int lock = _SPINLOCK_UNLOCKED;
static pthread_t owner = NULL;
static struct pthread_queue lockers = TAILQ_HEAD_INITIALIZER(lockers);
static int count = 0;
@@ -658,8 +657,7 @@ _rthread_dl_lock(int what)
} else if (owner != self) {
TAILQ_INSERT_TAIL(, self, waiting);
while (owner != self) {
-   __thrsleep(self, 0 | _USING_TICKETS, NULL,
-   , NULL);
+   __thrsleep(self, 0, NULL, , NULL);
_spinlock();
}
}
Index: lib/librthread/rthread.h
===
RCS file: /cvs/src/lib/librthread/rthread.h,v
retrieving revision 1.58
diff -u -p -r1.58 rthread.h
--- lib/librthread/rthread.h7 May 2016 19:05:22 -   1.58
+++ lib/librthread/rthread.h2 Sep 2016 13:09:44 -
@@ -37,18 +37,8 @@
 #define 

trade the rb tree in pools for subr_tree code

2016-09-02 Thread David Gwynne
its not quite an even trade, we lose some bytes still cos the
subr_tree code is a bit bigger than what RB_GENERATE produced. we'll
be ahead after the next conversion though.

ok?

Index: conf/files
===
RCS file: /cvs/src/sys/conf/files,v
retrieving revision 1.624
diff -u -p -r1.624 files
--- conf/files  13 Aug 2016 20:35:57 -  1.624
+++ conf/files  2 Sep 2016 13:36:22 -
@@ -694,6 +694,7 @@ file kern/subr_hibernate.c  hibernate
 file kern/subr_log.c
 file kern/subr_poison.cdiagnostic
 file kern/subr_pool.c
+file kern/subr_tree.c
 file kern/dma_alloc.c
 file kern/subr_prf.c
 file kern/subr_prof.c
Index: sys/tree.h
===
RCS file: /cvs/src/sys/sys/tree.h,v
retrieving revision 1.15
diff -u -p -r1.15 tree.h
--- sys/tree.h  2 Sep 2016 11:17:14 -   1.15
+++ sys/tree.h  2 Sep 2016 13:36:22 -
@@ -745,7 +745,7 @@ name##_RB_MINMAX(struct name *head, int 
((x) != NULL) && ((y) = name##_RB_PREV(x), 1);  \
 (x) = (y))
 
-#if 0 && defined(_KERNEL)
+#ifdef _KERNEL
 
 /*
  * Copyright (c) 2016 David Gwynne 
Index: sys/pool.h
===
RCS file: /cvs/src/sys/sys/pool.h,v
retrieving revision 1.59
diff -u -p -r1.59 pool.h
--- sys/pool.h  21 Apr 2016 04:09:28 -  1.59
+++ sys/pool.h  2 Sep 2016 13:36:22 -
@@ -121,7 +121,7 @@ struct pool {
 
int pr_ipl;
 
-   RB_HEAD(phtree, pool_item_header)
+   RBT_HEAD(phtree, pool_item_header)
pr_phtree;
 
u_int   pr_align;
Index: kern/subr_pool.c
===
RCS file: /cvs/src/sys/kern/subr_pool.c,v
retrieving revision 1.194
diff -u -p -r1.194 subr_pool.c
--- kern/subr_pool.c15 Jan 2016 11:21:58 -  1.194
+++ kern/subr_pool.c2 Sep 2016 13:36:23 -
@@ -79,7 +79,7 @@ struct pool_item_header {
TAILQ_ENTRY(pool_item_header)
ph_pagelist;/* pool page list */
XSIMPLEQ_HEAD(,pool_item) ph_itemlist;  /* chunk list for this page */
-   RB_ENTRY(pool_item_header)
+   RBT_ENTRY(pool_item_header)
ph_node;/* Off-page page headers */
int ph_nmissing;/* # of chunks in use */
caddr_t ph_page;/* this page's address */
@@ -165,8 +165,11 @@ struct task pool_gc_task = TASK_INITIALI
 int pool_wait_free = 1;
 int pool_wait_gc = 8;
 
+RBT_PROTOTYPE(phtree, pool_item_header, ph_node, phtree_compare);
+
 static inline int
-phtree_compare(struct pool_item_header *a, struct pool_item_header *b)
+phtree_compare(const struct pool_item_header *a,
+const struct pool_item_header *b)
 {
vaddr_t va = (vaddr_t)a->ph_page;
vaddr_t vb = (vaddr_t)b->ph_page;
@@ -180,8 +183,7 @@ phtree_compare(struct pool_item_header *
return (0);
 }
 
-RB_PROTOTYPE(phtree, pool_item_header, ph_node, phtree_compare);
-RB_GENERATE(phtree, pool_item_header, ph_node, phtree_compare);
+RBT_GENERATE(phtree, pool_item_header, ph_node, phtree_compare);
 
 /*
  * Return the pool page header based on page address.
@@ -200,7 +202,7 @@ pr_find_pagehead(struct pool *pp, void *
}
 
key.ph_page = v;
-   ph = RB_NFIND(phtree, >pr_phtree, );
+   ph = RBT_NFIND(phtree, >pr_phtree, );
if (ph == NULL)
panic("%s: %s: page header missing", __func__, pp->pr_wchan);
 
@@ -292,7 +294,7 @@ pool_init(struct pool *pp, size_t size, 
pp->pr_hardlimit_ratecap.tv_usec = 0;
pp->pr_hardlimit_warning_last.tv_sec = 0;
pp->pr_hardlimit_warning_last.tv_usec = 0;
-   RB_INIT(>pr_phtree);
+   RBT_INIT(phtree, >pr_phtree);
 
/*
 * Use the space between the chunks and the page header
@@ -847,7 +849,7 @@ pool_p_insert(struct pool *pp, struct po
 
TAILQ_INSERT_TAIL(>pr_emptypages, ph, ph_pagelist);
if (!POOL_INPGHDR(pp))
-   RB_INSERT(phtree, >pr_phtree, ph);
+   RBT_INSERT(phtree, >pr_phtree, ph);
 
pp->pr_nitems += pp->pr_itemsperpage;
pp->pr_nidle++;
@@ -868,7 +870,7 @@ pool_p_remove(struct pool *pp, struct po
pp->pr_nitems -= pp->pr_itemsperpage;
 
if (!POOL_INPGHDR(pp))
-   RB_REMOVE(phtree, >pr_phtree, ph);
+   RBT_REMOVE(phtree, >pr_phtree, ph);
TAILQ_REMOVE(>pr_emptypages, ph, ph_pagelist);
 
pool_update_curpage(pp);



Re: send fewer router solicitations

2016-09-02 Thread Stuart Henderson
On 2016/09/02 10:37, Florian Obser wrote:
> Our kernel based rtsol code is like this little child.  We bring up
> the interface, send our first solicitation and get an advertisment
> back with a pltime of a week or so.
> 
> We lean back, quite happy that we can do v6 now, but after 60 seconds
> we wake up, oh shit, better check if that prefix is still valid. and
> so on and on.
> 
> This is particularly annoying if you try to debug ICMPv6 with tcpdump
> in a network with a lot of openbsd machines.
> 
> To stop naddy from pestering me about this at every hackathon (rightly
> so!), let's base the timeout on the prefixes pltime. ;)
> 
> OK?

I agree with doing this, but I think this makes it more important
that we do something to expire old prefixes when changing networks (i.e.
change of link state).



Re: installer: do proper checks for MBR/GPT and OpenBSD area

2016-09-02 Thread Alexander Hall
On Fri, Sep 02, 2016 at 01:57:21PM +0300, Paul Irofti wrote:
> Hi,
> 
> While reinstalling OpenBSD on the x260 I saw a weird message when
> selecting the disk (that had a valid MBR)
> 
> 'No valid MBR or GPT'
> 
> which lead to the following installer diff.
> 
> The idea is to do two checks (similar to i386): first see if there's an
> MBR or GPT present on the disk, and if there is then check for the
> OpenBSD area.
> 
> The current code is too strict and checks for an OpenBSD area inside an
> MBR or GPT and if it fails to find one reports that there's no valid MBR
> or GPT (which is misleading).
> 
> OK?
> 
> 
> Index: install.md
> ===
> RCS file: /cvs/src/distrib/amd64/common/install.md,v
> retrieving revision 1.51
> diff -u -p -u -p -r1.51 install.md
> --- install.md8 Feb 2016 17:28:08 -   1.51
> +++ install.md2 Sep 2016 10:51:42 -
> @@ -59,10 +59,12 @@ md_prep_fdisk() {
>  
>   [[ $MDEFI == y ]] && _d=gpt
>  
> - if disk_has $_disk mbr openbsd || disk_has $_disk gpt openbsd; 
> then
> - _q="$_q, (O)penBSD area"
> - _d=OpenBSD
> + if disk_has $_disk mbr || disk_has $_disk gpt; then
>   fdisk $_disk

> + if disk_has $_disk mbr openbsd || disk_has $_disk gpt 
> openbsd; then

Can you wrap this please? It was already too long before. :)

if disk_has $_disk mbr openbsd ||
disk_has $_disk gpt openbsd; then

> + _q="$_q, (O)penBSD area"
> + _d=OpenBSD
> + fi
>   else
>   echo "No valid MBR or GPT."
>   fi

I've never touched a GPT, but it certainly looks right(er). ok halex@



installer: do proper checks for MBR/GPT and OpenBSD area

2016-09-02 Thread Paul Irofti
Hi,

While reinstalling OpenBSD on the x260 I saw a weird message when
selecting the disk (that had a valid MBR)

'No valid MBR or GPT'

which lead to the following installer diff.

The idea is to do two checks (similar to i386): first see if there's an
MBR or GPT present on the disk, and if there is then check for the
OpenBSD area.

The current code is too strict and checks for an OpenBSD area inside an
MBR or GPT and if it fails to find one reports that there's no valid MBR
or GPT (which is misleading).

OK?


Index: install.md
===
RCS file: /cvs/src/distrib/amd64/common/install.md,v
retrieving revision 1.51
diff -u -p -u -p -r1.51 install.md
--- install.md  8 Feb 2016 17:28:08 -   1.51
+++ install.md  2 Sep 2016 10:51:42 -
@@ -59,10 +59,12 @@ md_prep_fdisk() {
 
[[ $MDEFI == y ]] && _d=gpt
 
-   if disk_has $_disk mbr openbsd || disk_has $_disk gpt openbsd; 
then
-   _q="$_q, (O)penBSD area"
-   _d=OpenBSD
+   if disk_has $_disk mbr || disk_has $_disk gpt; then
fdisk $_disk
+   if disk_has $_disk mbr openbsd || disk_has $_disk gpt 
openbsd; then
+   _q="$_q, (O)penBSD area"
+   _d=OpenBSD
+   fi
else
echo "No valid MBR or GPT."
fi



Re: Kernel panic pf.c during halting

2016-09-02 Thread Lampshade
Another crash.
I should note that this kernel is build by me with patches
to GENERIC (HZ from 100 to 300), pci and acpi files.
Both previous reports were from
official kernel builds (snapshots).
Source code is based on:
cvs -d$CVSROOT up -D  "2016-08-26 12:45" -Pd

As always with this panic I issued command:
sudo halt -p

Stopped at Debugger+0x9: leave
TID  PID   UID PRFLAGS
51607 51607  53   0x10
PFLAGS  CPU  COMMAND
01  unbound

main message from debugger is the same as previous
panic()
__assert()
pf_state_key_unref()
pf_pkt_unlink_state_key()
and so on as previous

machine ddbcpu 1  - slightly changed,
but still the same 3 function calls before crash

x86_ipi_handler() at x86_ipi_handler+0x76
Xresume_lapic_ipi() at Xresume_lapic_ipi+0x1c
---interrupt---
__mp_lock() at __mp_lock+0x48
syscall() at syscall+0x2e5
---syscall (number 73) ---
end of kernel
end trace from



Re: in6_selectroute should never get AF_INET filled struct route *

2016-09-02 Thread Florian Obser
OK florian@

On Fri, Sep 02, 2016 at 11:21:33AM +0200, Vincent Gross wrote:
> in6_selectroute() checks whether the struct route it received contains
> a valid route whose AF is not AF_INET6, "in case the cache is shared".
> Well, is this cache shared or not ?
> 
> There's only two ways to get to in6_selectroute()
> 1) in6_pcbselsrc() -> in6_selectif() -> in6_selectroute()
> It is trivial to check that only inet6 is handled here, and that any
> other AF is obviously an error.
> 
> 2) ip6_output() -> in6_selectroute()
>   a. If the struct route * arg of ip6_output() is NULL, then
> ip6_output() zeroes a struct route from the stack, it will never
> be valid thus there is no need to check its AF.
>   b. If the struct route * arg is not NULL, it is passed to
> ip6_output().
> 
> ip6_output() is called with a non-NULL struct route * in 5 places only:
> 
> netinet/tcp_output.c:1124:  error = ip6_output(m, 
> tp->t_inpcb->inp_outputopts6,
> netinet/tcp_output.c-1125->t_inpcb->inp_route6,
> netinet/tcp_output.c-1126-0, NULL, tp->t_inpcb);
> 
> netinet/tcp_subr.c:399: ip6_output(m, tp ? 
> tp->t_inpcb->inp_outputopts6 : NULL,
> netinet/tcp_subr.c-400- tp ? >t_inpcb->inp_route6 : NULL,
> netinet/tcp_subr.c-401- 0, NULL,
> netinet/tcp_subr.c-402- tp ? tp->t_inpcb : NULL);
> 
> netinet/tcp_input.c:4386:   error = ip6_output(m, NULL /*XXX*/, 
> >sc_route6, 0,
> netinet/tcp_input.c-4387-   NULL, NULL);
> 
> netinet6/ip6_divert.c:167:  error = ip6_output(m, NULL, 
> >inp_route6,
> netinet6/ip6_divert.c-168-  IP_ALLOWBROADCAST | IP_RAWOUTPUT, 
> NULL, NULL);
> 
> netinet6/raw_ip6.c:457: error = ip6_output(m, optp, >inp_route6, flags,
> netinet6/raw_ip6.c-458- in6p->inp_moptions6, in6p);
> 
> Each time, the struct route is only used in an inet6 context.
> 
> I think it is safe to add this KASSERT() to in6_selectroute(). A few
> other things can be tightened, they will be addressed later.
> 
> Ok ?
> 
> 
> Index: netinet6/in6_src.c
> ===
> RCS file: /cvs/src/sys/netinet6/in6_src.c,v
> retrieving revision 1.79
> diff -u -p -r1.79 in6_src.c
> --- netinet6/in6_src.c4 Aug 2016 20:46:24 -   1.79
> +++ netinet6/in6_src.c2 Sep 2016 09:17:10 -
> @@ -302,13 +302,13 @@ in6_selectroute(struct sockaddr_in6 *dst
>  
>   /*
>* Use a cached route if it exists and is valid, else try to allocate
> -  * a new one.  Note that we should check the address family of the
> -  * cached destination, in case of sharing the cache with IPv4.
> +  * a new one.
>*/
>   if (ro) {
> + if (rtisvalid(ro->ro_rt))
> + KASSERT(sin6tosa(>ro_dst)->sa_family == AF_INET6);
>   if (!rtisvalid(ro->ro_rt) ||
> -  sin6tosa(>ro_dst)->sa_family != AF_INET6 ||
> -  !IN6_ARE_ADDR_EQUAL(>ro_dst.sin6_addr, dst)) {
> + !IN6_ARE_ADDR_EQUAL(>ro_dst.sin6_addr, dst)) {
>   rtfree(ro->ro_rt);
>   ro->ro_rt = NULL;
>   }
> 

-- 
I'm not entirely sure you are real.



send fewer router solicitations

2016-09-02 Thread Florian Obser
Our kernel based rtsol code is like this little child.  We bring up
the interface, send our first solicitation and get an advertisment
back with a pltime of a week or so.

We lean back, quite happy that we can do v6 now, but after 60 seconds
we wake up, oh shit, better check if that prefix is still valid. and
so on and on.

This is particularly annoying if you try to debug ICMPv6 with tcpdump
in a network with a lot of openbsd machines.

To stop naddy from pestering me about this at every hackathon (rightly
so!), let's base the timeout on the prefixes pltime. ;)

OK?

diff --git nd6_rtr.c nd6_rtr.c
index 6ca25f0..4ac978f 100644
--- nd6_rtr.c
+++ nd6_rtr.c
@@ -75,6 +75,7 @@ int rt6_deleteroute(struct rtentry *, void *, unsigned int);
 void nd6_addr_add(void *);
 
 void nd6_rs_output_timo(void *);
+u_int32_t nd6_rs_next_pltime_timo(struct ifnet *);
 void nd6_rs_output_set_timo(int);
 void nd6_rs_output(struct ifnet *, struct in6_ifaddr *);
 void nd6_rs_dev_state(void *);
@@ -283,30 +284,63 @@ nd6_rs_output_set_timo(int timeout)
timeout_add_sec(_rs_output_timer, nd6_rs_output_timeout);
 }
 
+u_int32_t
+nd6_rs_next_pltime_timo(struct ifnet *ifp)
+{
+   struct ifaddr *ifa;
+   struct in6_ifaddr *ia6;
+   u_int32_t pltime_expires = ND6_INFINITE_LIFETIME;
+
+   TAILQ_FOREACH(ifa, >if_addrlist, ifa_list) {
+   if (ifa->ifa_addr->sa_family != AF_INET6)
+   continue;
+
+   ia6 = ifatoia6(ifa);
+   if (ia6->ia6_lifetime.ia6t_pltime == ND6_INFINITE_LIFETIME ||
+   IFA6_IS_DEPRECATED(ia6) || IFA6_IS_INVALID(ia6))
+   continue;
+
+   pltime_expires = MIN(pltime_expires,
+   ia6->ia6_lifetime.ia6t_pltime);
+   }
+
+   return pltime_expires;
+}
+
 void
 nd6_rs_output_timo(void *ignored_arg)
 {
struct ifnet *ifp;
struct in6_ifaddr *ia6;
+   u_int32_t pltime_expire = ND6_INFINITE_LIFETIME, t;
+   int timeout = ND6_RS_OUTPUT_INTERVAL;
 
if (nd6_rs_timeout_count == 0)
return;
 
if (nd6_rs_output_timeout < ND6_RS_OUTPUT_INTERVAL)
/* exponential backoff if running quick timeouts */
-   nd6_rs_output_timeout *= 2;
-   if (nd6_rs_output_timeout > ND6_RS_OUTPUT_INTERVAL)
-   nd6_rs_output_timeout = ND6_RS_OUTPUT_INTERVAL;
+   timeout = nd6_rs_output_timeout * 2;
 
TAILQ_FOREACH(ifp, , if_list) {
if (ISSET(ifp->if_flags, IFF_RUNNING) &&
ISSET(ifp->if_xflags, IFXF_AUTOCONF6)) {
-   ia6 = in6ifa_ifpforlinklocal(ifp, IN6_IFF_TENTATIVE);
-   if (ia6 != NULL)
-   nd6_rs_output(ifp, ia6);
+   t = nd6_rs_next_pltime_timo(ifp);
+   if (t == ND6_INFINITE_LIFETIME || t <
+   ND6_RS_OUTPUT_INTERVAL) {
+   ia6 = in6ifa_ifpforlinklocal(ifp,
+   IN6_IFF_TENTATIVE);
+   if (ia6 != NULL)
+   nd6_rs_output(ifp, ia6);
+   }
+
+   pltime_expire = MIN(pltime_expire, t);
}
}
-   nd6_rs_output_set_timo(nd6_rs_output_timeout);
+   if (pltime_expire != ND6_INFINITE_LIFETIME)
+   timeout = MAX(timeout, pltime_expire / 2);
+
+   nd6_rs_output_set_timo(timeout);
 }
 
 void


-- 
I'm not entirely sure you are real.



Re: Let iked specify its source address when sending

2016-09-02 Thread Reyk Floeter
On Wed, Aug 31, 2016 at 03:57:45PM +0200, Vincent Gross wrote:
> On Wed, 31 Aug 2016 15:26:53 +0200
> Vincent Gross  wrote:
> 
> > On Thu, 11 Aug 2016 16:57:27 +0100
> > Stuart Henderson  wrote:
> > 
> > > On 2016/06/27 13:00, J?r?mie Courr?ges-Anglas wrote:  
> > [...]  
> > > > 
> > > > I also gave my ok to vgross by IM.
> > > > 
> > > > I know that some concerns have been exposed privately, I was not
> > > > Cc'd, thus I have no idea what is the current status of that
> > > > discussion.  To the people concerned, please keep me / us updated
> > > > about that discussion and Cc us.
> > > 
> > > How are things looking with IN_SENDSRCADDR now, are there any
> > > remaining concerns that need fixing before it could be committed?
> > > (Also if anyone has a share-able diff to use this with iked it
> > > would be quite handy..)
> > >   
> > 
> > Tested locally with two iked on two distinct rdomains plus a bit of
> > LD_PRELOAD goop. Unfortunately I couldn't ping from one rdom to the
> > other, but I also have this problem without my patch, so I am
> > confident this ping problem is unrelated.
> > 
> > I would be very grateful if someone could test this.
> >
> 
> Take two, unmangled version :
> 

lovely.

Comments below, otherwise OK

> Index: sbin/iked/iked.h
> ===
> RCS file: /cvs/src/sbin/iked/iked.h,v
> retrieving revision 1.96
> diff -u -p -r1.96 iked.h
> --- sbin/iked/iked.h  1 Jun 2016 11:16:41 -   1.96
> +++ sbin/iked/iked.h  31 Aug 2016 13:19:10 -
> @@ -898,6 +898,8 @@ intsocket_setport(struct sockaddr *, i
>  int   socket_getaddr(int, struct sockaddr_storage *);
>  int   socket_bypass(int, struct sockaddr *);
>  int   udp_bind(struct sockaddr *, in_port_t);
> +ssize_t   sendtofrom(int, void *, size_t, int, struct sockaddr *,
> + socklen_t, struct sockaddr *, socklen_t);
>  ssize_t   recvfromto(int, void *, size_t, int, struct sockaddr *,
>   socklen_t *, struct sockaddr *, socklen_t *);
>  const char *
> Index: sbin/iked/ikev2_msg.c
> ===
> RCS file: /cvs/src/sbin/iked/ikev2_msg.c,v
> retrieving revision 1.45
> diff -u -p -r1.45 ikev2_msg.c
> --- sbin/iked/ikev2_msg.c 19 Oct 2015 11:25:35 -  1.45
> +++ sbin/iked/ikev2_msg.c 31 Aug 2016 13:19:10 -
> @@ -319,9 +319,11 @@ ikev2_msg_send(struct iked *env, struct 
>   msg->msg_offset += sizeof(natt);
>   }
>  
> - if ((sendto(msg->msg_fd, ibuf_data(buf), ibuf_size(buf), 0,
> - (struct sockaddr *)>msg_peer, msg->msg_peerlen)) == -1) {
> - log_warn("%s: sendto", __func__);
> + if (sendtofrom(msg->msg_fd, ibuf_data(buf), ibuf_size(buf), 0,
> + (struct sockaddr *)>msg_peer, msg->msg_peerlen,
> + (struct sockaddr *)>msg_local, msg->msg_locallen) <
> + ibuf_size(buf)) {

I think checking for -1 is more appropriate here as DGRAM is atomic
and the sendmsg return value is usually checked as -1 (or sometimes <= 0).

> + log_warn("%s: sendtofrom", __func__);
>   return (-1);
>   }
>  
> @@ -969,10 +971,12 @@ int
>  ikev2_msg_retransmit_response(struct iked *env, struct iked_sa *sa,
>  struct iked_message *msg)
>  {
> - if ((sendto(msg->msg_fd, ibuf_data(msg->msg_data),
> - ibuf_size(msg->msg_data), 0, (struct sockaddr *)>msg_peer,
> - msg->msg_peerlen)) == -1) {
> - log_warn("%s: sendto", __func__);
> + if (sendtofrom(msg->msg_fd, ibuf_data(msg->msg_data),
> + ibuf_size(msg->msg_data), 0,
> + (struct sockaddr *)>msg_peer, msg->msg_peerlen,
> + (struct sockaddr *)>msg_local, msg->msg_locallen) < 

Same here.

> + ibuf_size(msg->msg_data)) {
> + log_warn("%s: sendtofrom", __func__);
>   return (-1);
>   }
>  
> @@ -996,11 +1000,12 @@ ikev2_msg_retransmit_timeout(struct iked
>   struct iked_sa  *sa = msg->msg_sa;
>  
>   if (msg->msg_tries < IKED_RETRANSMIT_TRIES) {
> - if ((sendto(msg->msg_fd, ibuf_data(msg->msg_data),
> + if (sendtofrom(msg->msg_fd, ibuf_data(msg->msg_data),
>   ibuf_size(msg->msg_data), 0,
> - (struct sockaddr *)>msg_peer,
> - msg->msg_peerlen)) == -1) {
> - log_warn("%s: sendto", __func__);
> + (struct sockaddr *)>msg_peer, msg->msg_peerlen,
> + (struct sockaddr *)>msg_local, msg->msg_locallen) <

And here.

> + ibuf_size(msg->msg_data)) {
> + log_warn("%s: sendtofrom", __func__);
>   sa_free(env, sa);
>   return;
>   }
> Index: sbin/iked/util.c
> ===
> RCS file: /cvs/src/sbin/iked/util.c,v
> retrieving revision 1.30
> diff -u -p 

in6_selectroute should never get AF_INET filled struct route *

2016-09-02 Thread Vincent Gross
in6_selectroute() checks whether the struct route it received contains
a valid route whose AF is not AF_INET6, "in case the cache is shared".
Well, is this cache shared or not ?

There's only two ways to get to in6_selectroute()
1) in6_pcbselsrc() -> in6_selectif() -> in6_selectroute()
It is trivial to check that only inet6 is handled here, and that any
other AF is obviously an error.

2) ip6_output() -> in6_selectroute()
  a. If the struct route * arg of ip6_output() is NULL, then
ip6_output() zeroes a struct route from the stack, it will never
be valid thus there is no need to check its AF.
  b. If the struct route * arg is not NULL, it is passed to
ip6_output().

ip6_output() is called with a non-NULL struct route * in 5 places only:

netinet/tcp_output.c:1124:  error = ip6_output(m, 
tp->t_inpcb->inp_outputopts6,
netinet/tcp_output.c-1125->t_inpcb->inp_route6,
netinet/tcp_output.c-1126-0, NULL, tp->t_inpcb);

netinet/tcp_subr.c:399: ip6_output(m, tp ? tp->t_inpcb->inp_outputopts6 
: NULL,
netinet/tcp_subr.c-400- tp ? >t_inpcb->inp_route6 : NULL,
netinet/tcp_subr.c-401- 0, NULL,
netinet/tcp_subr.c-402- tp ? tp->t_inpcb : NULL);

netinet/tcp_input.c:4386:   error = ip6_output(m, NULL /*XXX*/, 
>sc_route6, 0,
netinet/tcp_input.c-4387-   NULL, NULL);

netinet6/ip6_divert.c:167:  error = ip6_output(m, NULL, 
>inp_route6,
netinet6/ip6_divert.c-168-  IP_ALLOWBROADCAST | IP_RAWOUTPUT, 
NULL, NULL);

netinet6/raw_ip6.c:457: error = ip6_output(m, optp, >inp_route6, flags,
netinet6/raw_ip6.c-458- in6p->inp_moptions6, in6p);

Each time, the struct route is only used in an inet6 context.

I think it is safe to add this KASSERT() to in6_selectroute(). A few
other things can be tightened, they will be addressed later.

Ok ?


Index: netinet6/in6_src.c
===
RCS file: /cvs/src/sys/netinet6/in6_src.c,v
retrieving revision 1.79
diff -u -p -r1.79 in6_src.c
--- netinet6/in6_src.c  4 Aug 2016 20:46:24 -   1.79
+++ netinet6/in6_src.c  2 Sep 2016 09:17:10 -
@@ -302,13 +302,13 @@ in6_selectroute(struct sockaddr_in6 *dst
 
/*
 * Use a cached route if it exists and is valid, else try to allocate
-* a new one.  Note that we should check the address family of the
-* cached destination, in case of sharing the cache with IPv4.
+* a new one.
 */
if (ro) {
+   if (rtisvalid(ro->ro_rt))
+   KASSERT(sin6tosa(>ro_dst)->sa_family == AF_INET6);
if (!rtisvalid(ro->ro_rt) ||
-sin6tosa(>ro_dst)->sa_family != AF_INET6 ||
-!IN6_ARE_ADDR_EQUAL(>ro_dst.sin6_addr, dst)) {
+   !IN6_ARE_ADDR_EQUAL(>ro_dst.sin6_addr, dst)) {
rtfree(ro->ro_rt);
ro->ro_rt = NULL;
}



Re: Drop IPSec traffic that should be encapsulated but is not

2016-09-02 Thread Mike Belopuhov
On 1 September 2016 at 10:31, Vincent Gross  wrote:
> Our IPSec stack rejects UDP-encapsulated traffic using a non
> encapsulating SA, but not the other way around. This diff adds
> the missing check and the corresponding stat counter.
>
> Ok ?
>

Go for it.  OK mikeb



Re: Let iked specify its source address when sending

2016-09-02 Thread Vincent Gross
Objections anyone ?

On Wed, 31 Aug 2016 15:57:45 +0200
Vincent Gross  wrote:

> On Wed, 31 Aug 2016 15:26:53 +0200
> Vincent Gross  wrote:
> 
> > On Thu, 11 Aug 2016 16:57:27 +0100
> > Stuart Henderson  wrote:
> >   
> > > On 2016/06/27 13:00, Jérémie Courrèges-Anglas wrote:
> > [...]
> > > > 
> > > > I also gave my ok to vgross by IM.
> > > > 
> > > > I know that some concerns have been exposed privately, I was not
> > > > Cc'd, thus I have no idea what is the current status of that
> > > > discussion.  To the people concerned, please keep me / us
> > > > updated about that discussion and Cc us.  
> > > 
> > > How are things looking with IN_SENDSRCADDR now, are there any
> > > remaining concerns that need fixing before it could be committed?
> > > (Also if anyone has a share-able diff to use this with iked it
> > > would be quite handy..)
> > > 
> > 
> > Tested locally with two iked on two distinct rdomains plus a bit of
> > LD_PRELOAD goop. Unfortunately I couldn't ping from one rdom to the
> > other, but I also have this problem without my patch, so I am
> > confident this ping problem is unrelated.
> > 
> > I would be very grateful if someone could test this.
> >  
> 
> Take two, unmangled version :
> 
> Index: sbin/iked/iked.h
> ===
> RCS file: /cvs/src/sbin/iked/iked.h,v
> retrieving revision 1.96
> diff -u -p -r1.96 iked.h
> --- sbin/iked/iked.h  1 Jun 2016 11:16:41 -   1.96
> +++ sbin/iked/iked.h  31 Aug 2016 13:19:10 -
> @@ -898,6 +898,8 @@ intsocket_setport(struct sockaddr *, i
>  int   socket_getaddr(int, struct sockaddr_storage *);
>  int   socket_bypass(int, struct sockaddr *);
>  int   udp_bind(struct sockaddr *, in_port_t);
> +ssize_t   sendtofrom(int, void *, size_t, int, struct sockaddr
> *,
> + socklen_t, struct sockaddr *, socklen_t);
>  ssize_t   recvfromto(int, void *, size_t, int, struct sockaddr
> *, socklen_t *, struct sockaddr *, socklen_t *);
>  const char *
> Index: sbin/iked/ikev2_msg.c
> ===
> RCS file: /cvs/src/sbin/iked/ikev2_msg.c,v
> retrieving revision 1.45
> diff -u -p -r1.45 ikev2_msg.c
> --- sbin/iked/ikev2_msg.c 19 Oct 2015 11:25:35 -
> 1.45 +++ sbin/iked/ikev2_msg.c31 Aug 2016 13:19:10 -
> @@ -319,9 +319,11 @@ ikev2_msg_send(struct iked *env, struct 
>   msg->msg_offset += sizeof(natt);
>   }
>  
> - if ((sendto(msg->msg_fd, ibuf_data(buf), ibuf_size(buf), 0,
> - (struct sockaddr *)>msg_peer, msg->msg_peerlen)) ==
> -1) {
> - log_warn("%s: sendto", __func__);
> + if (sendtofrom(msg->msg_fd, ibuf_data(buf), ibuf_size(buf),
> 0,
> + (struct sockaddr *)>msg_peer, msg->msg_peerlen,
> + (struct sockaddr *)>msg_local, msg->msg_locallen) <
> + ibuf_size(buf)) {
> + log_warn("%s: sendtofrom", __func__);
>   return (-1);
>   }
>  
> @@ -969,10 +971,12 @@ int
>  ikev2_msg_retransmit_response(struct iked *env, struct iked_sa *sa,
>  struct iked_message *msg)
>  {
> - if ((sendto(msg->msg_fd, ibuf_data(msg->msg_data),
> - ibuf_size(msg->msg_data), 0, (struct sockaddr
> *)>msg_peer,
> - msg->msg_peerlen)) == -1) {
> - log_warn("%s: sendto", __func__);
> + if (sendtofrom(msg->msg_fd, ibuf_data(msg->msg_data),
> + ibuf_size(msg->msg_data), 0,
> + (struct sockaddr *)>msg_peer, msg->msg_peerlen,
> + (struct sockaddr *)>msg_local, msg->msg_locallen) < 
> + ibuf_size(msg->msg_data)) {
> + log_warn("%s: sendtofrom", __func__);
>   return (-1);
>   }
>  
> @@ -996,11 +1000,12 @@ ikev2_msg_retransmit_timeout(struct iked
>   struct iked_sa  *sa = msg->msg_sa;
>  
>   if (msg->msg_tries < IKED_RETRANSMIT_TRIES) {
> - if ((sendto(msg->msg_fd, ibuf_data(msg->msg_data),
> + if (sendtofrom(msg->msg_fd, ibuf_data(msg->msg_data),
>   ibuf_size(msg->msg_data), 0,
> - (struct sockaddr *)>msg_peer,
> - msg->msg_peerlen)) == -1) {
> - log_warn("%s: sendto", __func__);
> + (struct sockaddr *)>msg_peer,
> msg->msg_peerlen,
> + (struct sockaddr *)>msg_local,
> msg->msg_locallen) <
> + ibuf_size(msg->msg_data)) {
> + log_warn("%s: sendtofrom", __func__);
>   sa_free(env, sa);
>   return;
>   }
> Index: sbin/iked/util.c
> ===
> RCS file: /cvs/src/sbin/iked/util.c,v
> retrieving revision 1.30
> diff -u -p -r1.30 util.c
> --- sbin/iked/util.c  23 Nov 2015 19:28:34 -  1.30
> +++ sbin/iked/util.c  31 Aug 2016 13:19:10 -
> @@ -287,6 +287,57 @@ 

Re: arm: store curcpu pointer in thread id register

2016-09-02 Thread Jonathan Gray
On Sat, Feb 27, 2016 at 05:03:46PM +0100, Patrick Wildt wrote:
> On Fri, Feb 26, 2016 at 08:59:41PM -0800, Philip Guenther wrote:
> > On Sat, Feb 20, 2016 at 1:49 PM, Patrick Wildt  wrote:
> > > since ARMv6 the coprocessor provides special registers to store software
> > > defined values.  Those registers are:
> > >
> > >   * TPIDRURW -> kernel RW, user RW
> > >   * TPIDRURO -> kernel RW, user RO
> > >   * TPIDRPRW -> kernel RW
> > >
> > > TPIDRPRW is typically used to store the pointer to the curcpu struct,
> > > while TPIDRURO is used to point to the TCB.
> > >
> > > The following diff implements using TPIDRPRW to store and retrieve the
> > > curcpu struct pointer.  This will especially be helpful in future MP
> > > efforts.  I have guarded it for ARMv7 only, as that's the only hardware
> > > I have that supports it and I was able to test on.
> > 
> > I don't know arm, but of those choices that makes sense.
> > 
> > 
> > > If TCB_GET()'s only user is libpthread, then it could make sense to
> > > store the TCB pointer in TPIDRURO.  If it's possible that it's also
> > > used in ports, then the arm packages won't be compatible to
> > > armish/zaurus anymore.  But the TCB stuff is not part of this diff.
> > 
> > The userland bits in  should match the platform's ABI
> > for the thread register.  The last time I tried to figure this out
> > from the arm ABI docs I wanted to stab someone, but I was hopefully
> > just looking at the wrong docs.  Looking at the bits in FreeBSD I see
> > 
> > static inline void
> > set_tls(void *tls)
> > {
> > __asm __volatile("mcr p15, 0, %0, c13, c0, 3" : : "r" (tls));
> > }
> > 
> > so, uh, whichever register that sets is presumably the correct one for 
> > userland.
> 
> Yep, that's TPIDRURO.  It's not a lot of work to use this register, but
> it might just not work out as zaurus and armv7 use the same packages.

Time to revisit this and switch to the armv7 path in
lib/librthread/arch/arm/_atomic_lock.c ?



Re: sxidog hang

2016-09-02 Thread Mark Kettenis
> Date: Fri, 2 Sep 2016 08:31:20 +0200
> From: Marcus Glocker 
> 
> Trying to disable the watchdog on the allwinner,sun5i-r8 breaks the
> reboot ('reboot failed; spinning').  Can we change this back at least
> for the A10?

Sorry for dropping the ball here.  But does it work if instead of
WDOG_EN, you enable/disable WDOG_RST_EN based on the period being >0
or not?

> Index: sxidog.c
> ===
> RCS file: /cvs/src/sys/arch/armv7/sunxi/sxidog.c,v
> retrieving revision 1.9
> diff -u -p -r1.9 sxidog.c
> --- sxidog.c  27 Aug 2016 14:13:14 -  1.9
> +++ sxidog.c  2 Sep 2016 06:27:21 -
> @@ -148,9 +148,8 @@ sxidog_callback(void *arg, int period)
>  
>   switch (sc->sc_type) {
>   case SXIDOG_A10:
> - enable = (period > 0) ? WDOG_EN : 0;
>   SXIWRITE4(sc, WDOG_MODE_REG,
> - enable | WDOG_RST_EN | WDOG_INTV_VALUE(period));
> + WDOG_EN | WDOG_RST_EN | WDOG_INTV_VALUE(period));
>   SXIWRITE4(sc, WDOG_CTRL_REG, WDOG_KEY | WDOG_RSTART);
>   break;
>   case SXIDOG_A31:
> 
> 



mg(1) Initialize stack variables to zero before memmove()

2016-09-02 Thread Mark Lumsden
Source Joachim Nilsson:

Coverity Scan reported these two stack variables as uninitialized, in
particular the .r_lineno struct member was uninitialized.  This patch
clears the 'struct region' rather than setting .r_lineno because if
any more struct members are added in the future the clear will cover
them too.

I think Joachim's approach is sensible. ok?

-lum

Index: undo.c
===
RCS file: /cvs/src/usr.bin/mg/undo.c,v
retrieving revision 1.57
diff -u -p -u -p -r1.57 undo.c
--- undo.c  11 Dec 2015 20:21:23 -  1.57
+++ undo.c  2 Sep 2016 07:02:18 -
@@ -269,6 +269,8 @@ undo_add_insert(struct line *lp, int off
 
if (!undo_enable_flag)
return (TRUE);
+
+   memset(, 0, sizeof(reg));
reg.r_linep = lp;
reg.r_offset = offset;
reg.r_size = size;
@@ -315,6 +317,7 @@ undo_add_delete(struct line *lp, int off
if (!undo_enable_flag)
return (TRUE);
 
+   memset(, 0, sizeof(reg));
reg.r_linep = lp;
reg.r_offset = offset;
reg.r_size = size;



sxidog hang

2016-09-02 Thread Marcus Glocker
Trying to disable the watchdog on the allwinner,sun5i-r8 breaks the
reboot ('reboot failed; spinning').  Can we change this back at least
for the A10?


Index: sxidog.c
===
RCS file: /cvs/src/sys/arch/armv7/sunxi/sxidog.c,v
retrieving revision 1.9
diff -u -p -r1.9 sxidog.c
--- sxidog.c27 Aug 2016 14:13:14 -  1.9
+++ sxidog.c2 Sep 2016 06:27:21 -
@@ -148,9 +148,8 @@ sxidog_callback(void *arg, int period)
 
switch (sc->sc_type) {
case SXIDOG_A10:
-   enable = (period > 0) ? WDOG_EN : 0;
SXIWRITE4(sc, WDOG_MODE_REG,
-   enable | WDOG_RST_EN | WDOG_INTV_VALUE(period));
+   WDOG_EN | WDOG_RST_EN | WDOG_INTV_VALUE(period));
SXIWRITE4(sc, WDOG_CTRL_REG, WDOG_KEY | WDOG_RSTART);
break;
case SXIDOG_A31: