Re: pipex(4) fix: check session existence before creation

2020-04-06 Thread Claudio Jeker
On Mon, Apr 06, 2020 at 07:54:20PM +0300, Vitaliy Makkoveev wrote:
> Deny to create pipex_session which is already exist. Newly created
> session will be placed to list head so the caller of
> pipex_*_lookup_session() will receive wrong session.

I think in the pppx(4) case the code is already doing this check in the
RBT_FIND() on line 835. Still I think this is a good thing to add.
OK claudio@

 
> Index: sys/net/if_pppx.c
> ===
> RCS file: /cvs/src/sys/net/if_pppx.c,v
> retrieving revision 1.79
> diff -u -p -r1.79 if_pppx.c
> --- sys/net/if_pppx.c 6 Apr 2020 12:31:30 -   1.79
> +++ sys/net/if_pppx.c 6 Apr 2020 13:47:26 -
> @@ -719,6 +719,11 @@ pppx_add_session(struct pppx_dev *pxd, s
>   return (EPROTONOSUPPORT);
>   }
>  
> + session = pipex_lookup_by_session_id(req->pr_protocol,
> + req->pr_session_id);
> + if (session)
> + return (EEXIST);
> +
>   pxi = pool_get(pppx_if_pl, PR_WAITOK | PR_ZERO);
>   if (pxi == NULL)
>   return (ENOMEM);
> Index: sys/net/pipex.c
> ===
> RCS file: /cvs/src/sys/net/pipex.c,v
> retrieving revision 1.112
> diff -u -p -r1.112 pipex.c
> --- sys/net/pipex.c   6 Apr 2020 13:14:04 -   1.112
> +++ sys/net/pipex.c   6 Apr 2020 13:47:33 -
> @@ -312,6 +312,11 @@ pipex_add_session(struct pipex_session_r
>   return (EPROTONOSUPPORT);
>   }
>  
> + session = pipex_lookup_by_session_id(req->pr_protocol,
> + req->pr_session_id);
> + if (session)
> + return (EEXIST);
> +
>   /* prepare a new session */
>   session = pool_get(_session_pool, PR_WAITOK | PR_ZERO);
>   session->state = PIPEX_STATE_OPENED;
> 

-- 
:wq Claudio



[PATCH v2] gostr341001: support unwrapped private keys support

2020-04-06 Thread Dmitry Baryshkov
GOST private keys can be wrapped in OCTET STRING, INTEGER or come
unwrapped. Support the latter format.

Sponsored by ROSA Linux

Signed-off-by: Dmitry Baryshkov 
---
 src/lib/libcrypto/gost/gost_asn1.c |  52 ++
 src/lib/libcrypto/gost/gost_asn1.h |  11 ++
 src/lib/libcrypto/gost/gostr341001_ameth.c | 115 +++--
 3 files changed, 169 insertions(+), 9 deletions(-)

diff --git a/src/lib/libcrypto/gost/gost_asn1.c 
b/src/lib/libcrypto/gost/gost_asn1.c
index 703d64070449..bfd81faa1ee2 100644
--- a/src/lib/libcrypto/gost/gost_asn1.c
+++ b/src/lib/libcrypto/gost/gost_asn1.c
@@ -17,6 +17,58 @@
 #include "gost_locl.h"
 #include "gost_asn1.h"
 
+static const ASN1_TEMPLATE MASKED_GOST_KEY_seq_tt[] = {
+   {
+   .flags = 0,
+   .tag = 0,
+   .offset = offsetof(MASKED_GOST_KEY, masked_priv_key),
+   .field_name = "masked_priv_key",
+   .item = _OCTET_STRING_it,
+   },
+   {
+   .flags = 0,
+   .tag = 0,
+   .offset = offsetof(MASKED_GOST_KEY, public_key),
+   .field_name = "public_key",
+   .item = _OCTET_STRING_it,
+   },
+};
+
+const ASN1_ITEM MASKED_GOST_KEY_it = {
+   .itype = ASN1_ITYPE_NDEF_SEQUENCE,
+   .utype = V_ASN1_SEQUENCE,
+   .templates = MASKED_GOST_KEY_seq_tt,
+   .tcount = sizeof(MASKED_GOST_KEY_seq_tt) / sizeof(ASN1_TEMPLATE),
+   .funcs = NULL,
+   .size = sizeof(MASKED_GOST_KEY),
+   .sname = "MASKED_GOST_KEY",
+};
+
+MASKED_GOST_KEY *
+d2i_MASKED_GOST_KEY(MASKED_GOST_KEY **a, const unsigned char **in, long len)
+{
+   return (MASKED_GOST_KEY *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
+   _GOST_KEY_it);
+}
+
+int
+i2d_MASKED_GOST_KEY(MASKED_GOST_KEY *a, unsigned char **out)
+{
+   return ASN1_item_i2d((ASN1_VALUE *)a, out, _GOST_KEY_it);
+}
+
+MASKED_GOST_KEY *
+MASKED_GOST_KEY_new(void)
+{
+   return (MASKED_GOST_KEY *)ASN1_item_new(_GOST_KEY_it);
+}
+
+void
+MASKED_GOST_KEY_free(MASKED_GOST_KEY *a)
+{
+   ASN1_item_free((ASN1_VALUE *)a, _GOST_KEY_it);
+}
+
 static const ASN1_TEMPLATE GOST_KEY_TRANSPORT_seq_tt[] = {
{
.flags = 0,
diff --git a/src/lib/libcrypto/gost/gost_asn1.h 
b/src/lib/libcrypto/gost/gost_asn1.h
index 7cabfc79c965..cdbda7b98b67 100644
--- a/src/lib/libcrypto/gost/gost_asn1.h
+++ b/src/lib/libcrypto/gost/gost_asn1.h
@@ -56,6 +56,17 @@
 
 __BEGIN_HIDDEN_DECLS
 
+typedef struct {
+   ASN1_OCTET_STRING *masked_priv_key;
+   ASN1_OCTET_STRING *public_key;
+} MASKED_GOST_KEY;
+
+MASKED_GOST_KEY *MASKED_GOST_KEY_new(void);
+void MASKED_GOST_KEY_free(MASKED_GOST_KEY *a);
+MASKED_GOST_KEY *d2i_MASKED_GOST_KEY(MASKED_GOST_KEY **a, const unsigned char 
**in, long len);
+int i2d_MASKED_GOST_KEY(MASKED_GOST_KEY *a, unsigned char **out);
+extern const ASN1_ITEM MASKED_GOST_KEY_it;
+
 typedef struct {
ASN1_OCTET_STRING *encrypted_key;
ASN1_OCTET_STRING *imit;
diff --git a/src/lib/libcrypto/gost/gostr341001_ameth.c 
b/src/lib/libcrypto/gost/gostr341001_ameth.c
index 49eec7a31d70..da354d0fe66d 100644
--- a/src/lib/libcrypto/gost/gostr341001_ameth.c
+++ b/src/lib/libcrypto/gost/gostr341001_ameth.c
@@ -437,6 +437,70 @@ priv_print_gost01(BIO *out, const EVP_PKEY *pkey, int 
indent, ASN1_PCTX *pctx)
return pub_print_gost01(out, pkey, indent, pctx);
 }
 
+static BIGNUM *unmask_priv_key(EVP_PKEY *pk,
+   const unsigned char *buf, int len, int num_masks)
+{
+   BIGNUM *pknum_masked = NULL, *q, *mask;
+   const GOST_KEY *key_ptr = pk->pkey.gost;
+   const EC_GROUP *group = GOST_KEY_get0_group(key_ptr);
+   const unsigned char *p = buf + num_masks * len;
+   BN_CTX *ctx;
+
+   pknum_masked = GOST_le2bn(buf, len, NULL);
+   if (!pknum_masked) {
+   GOSTerror(ERR_R_MALLOC_FAILURE);
+   return NULL;
+   }
+
+   if (num_masks == 0)
+   return pknum_masked;
+
+   ctx = BN_CTX_new();
+   if (ctx == NULL) {
+   GOSTerror(ERR_R_MALLOC_FAILURE);
+   goto err;
+   }
+
+   BN_CTX_start(ctx);
+
+   q = BN_CTX_get(ctx);
+   if (!q) {
+   GOSTerror(ERR_R_MALLOC_FAILURE);
+   goto err;
+   }
+
+   mask = BN_CTX_get(ctx);
+   if (!mask) {
+   GOSTerror(ERR_R_MALLOC_FAILURE);
+   goto err;
+   }
+
+   if (EC_GROUP_get_order(group, q, NULL) <= 0) {
+   GOSTerror(ERR_R_EC_LIB);
+   goto err;
+   }
+
+   for (; p != buf; p -= len) {
+   if (GOST_le2bn(p, len, mask) == NULL ||
+   !BN_mod_mul(pknum_masked, pknum_masked, mask, q, ctx)) {
+   GOSTerror(ERR_R_BN_LIB);
+   goto err;
+   }
+   }
+
+   BN_CTX_end(ctx);
+   BN_CTX_free(ctx);
+
+   return pknum_masked;
+
+err:
+   BN_CTX_end(ctx);
+   BN_CTX_free(ctx);
+
+   

pipex(4) fix: check session existence before creation

2020-04-06 Thread Vitaliy Makkoveev
Deny to create pipex_session which is already exist. Newly created
session will be placed to list head so the caller of
pipex_*_lookup_session() will receive wrong session.

Index: sys/net/if_pppx.c
===
RCS file: /cvs/src/sys/net/if_pppx.c,v
retrieving revision 1.79
diff -u -p -r1.79 if_pppx.c
--- sys/net/if_pppx.c   6 Apr 2020 12:31:30 -   1.79
+++ sys/net/if_pppx.c   6 Apr 2020 13:47:26 -
@@ -719,6 +719,11 @@ pppx_add_session(struct pppx_dev *pxd, s
return (EPROTONOSUPPORT);
}
 
+   session = pipex_lookup_by_session_id(req->pr_protocol,
+   req->pr_session_id);
+   if (session)
+   return (EEXIST);
+
pxi = pool_get(pppx_if_pl, PR_WAITOK | PR_ZERO);
if (pxi == NULL)
return (ENOMEM);
Index: sys/net/pipex.c
===
RCS file: /cvs/src/sys/net/pipex.c,v
retrieving revision 1.112
diff -u -p -r1.112 pipex.c
--- sys/net/pipex.c 6 Apr 2020 13:14:04 -   1.112
+++ sys/net/pipex.c 6 Apr 2020 13:47:33 -
@@ -312,6 +312,11 @@ pipex_add_session(struct pipex_session_r
return (EPROTONOSUPPORT);
}
 
+   session = pipex_lookup_by_session_id(req->pr_protocol,
+   req->pr_session_id);
+   if (session)
+   return (EEXIST);
+
/* prepare a new session */
session = pool_get(_session_pool, PR_WAITOK | PR_ZERO);
session->state = PIPEX_STATE_OPENED;



Re: pipex(4) fix: check session existence before creation

2020-04-06 Thread Vitaliy Makkoveev



> On 6 Apr 2020, at 17:37, Claudio Jeker  wrote:
> 
> On Mon, Apr 06, 2020 at 07:54:20PM +0300, Vitaliy Makkoveev wrote:
>> Deny to create pipex_session which is already exist. Newly created
>> session will be placed to list head so the caller of
>> pipex_*_lookup_session() will receive wrong session.
> 
> I think in the pppx(4) case the code is already doing this check in the
> RBT_FIND() on line 835. Still I think this is a good thing to add.
> OK claudio@
> 

In pppx(4) layer not in pipex(4). Without this check pppx(4) can override 
pppac(4) owned session.

> 
>> Index: sys/net/if_pppx.c
>> ===
>> RCS file: /cvs/src/sys/net/if_pppx.c,v
>> retrieving revision 1.79
>> diff -u -p -r1.79 if_pppx.c
>> --- sys/net/if_pppx.c6 Apr 2020 12:31:30 -   1.79
>> +++ sys/net/if_pppx.c6 Apr 2020 13:47:26 -
>> @@ -719,6 +719,11 @@ pppx_add_session(struct pppx_dev *pxd, s
>>  return (EPROTONOSUPPORT);
>>  }
>> 
>> +session = pipex_lookup_by_session_id(req->pr_protocol,
>> +req->pr_session_id);
>> +if (session)
>> +return (EEXIST);
>> +
>>  pxi = pool_get(pppx_if_pl, PR_WAITOK | PR_ZERO);
>>  if (pxi == NULL)
>>  return (ENOMEM);
>> Index: sys/net/pipex.c
>> ===
>> RCS file: /cvs/src/sys/net/pipex.c,v
>> retrieving revision 1.112
>> diff -u -p -r1.112 pipex.c
>> --- sys/net/pipex.c  6 Apr 2020 13:14:04 -   1.112
>> +++ sys/net/pipex.c  6 Apr 2020 13:47:33 -
>> @@ -312,6 +312,11 @@ pipex_add_session(struct pipex_session_r
>>  return (EPROTONOSUPPORT);
>>  }
>> 
>> +session = pipex_lookup_by_session_id(req->pr_protocol,
>> +req->pr_session_id);
>> +if (session)
>> +return (EEXIST);
>> +
>>  /* prepare a new session */
>>  session = pool_get(_session_pool, PR_WAITOK | PR_ZERO);
>>  session->state = PIPEX_STATE_OPENED;
>> 
> 
> -- 
> :wq Claudio



Re: iwn: fix tx result reporting

2020-04-06 Thread Stefan Sperling
On Mon, Apr 06, 2020 at 05:02:00PM +0200, Stefan Sperling wrote:
> On Thu, Apr 02, 2020 at 03:52:11PM +0200, Stefan Sperling wrote:
> > While working on iwm Tx aggregation and revisiting some parts of MiRA,
> > I have noticed a rate-control problem in iwm and iwx (this also affects
> > iwn, but I am leaving that for later since iwn already does Tx aggregation
> > and requires a more elaborate fix).
> 
> Here is the corresponding diff for iwn(4).
> 
> Fixes an automatic Tx rate control issue in iwn(4).
> Same change as for iwm(4) and iwx(4), but also accounts for block ack.
> 
> Also fix this driver's handling of ic_fixed_mcs.

Block ack is hard :(
The previous diff had a bug in evaluating the block ack bitmap.

We must align our own block ack window with the current window used by
firmware before looking at bits in the ACK bitmap provided by firmware.
Otherwise ACK/non-ACK status could be associated with the wrong frames.

Fixed in this version.

diff refs/heads/master refs/heads/iwn
blob - 72e19d7e35646822faaed4f2ebd157297a8ec907
blob + b50cd5642bd70be70e8d6d70f70e665208c0
--- sys/dev/pci/if_iwn.c
+++ sys/dev/pci/if_iwn.c
@@ -166,8 +166,8 @@ voidiwn_rx_statistics(struct iwn_softc *, 
struct iwn
 void   iwn_ampdu_txq_advance(struct iwn_softc *, struct iwn_tx_ring *,
int, int);
 void   iwn_ampdu_tx_done(struct iwn_softc *, struct iwn_tx_ring *,
-   struct iwn_rx_desc *, uint16_t, struct iwn_txagg_status *,
-   int, uint32_t);
+   struct iwn_rx_desc *, uint16_t, uint8_t, uint8_t, uint8_t,
+   int, uint32_t, struct iwn_txagg_status *);
 void   iwn4965_tx_done(struct iwn_softc *, struct iwn_rx_desc *,
struct iwn_rx_data *);
 void   iwn5000_tx_done(struct iwn_softc *, struct iwn_rx_desc *,
@@ -176,7 +176,7 @@ voidiwn_tx_done_free_txdata(struct 
iwn_softc *,
struct iwn_tx_data *);
 void   iwn_clear_oactive(struct iwn_softc *, struct iwn_tx_ring *);
 void   iwn_tx_done(struct iwn_softc *, struct iwn_rx_desc *,
-   uint8_t, int, int, uint16_t);
+   uint8_t, uint8_t, int, int, uint16_t);
 void   iwn_cmd_done(struct iwn_softc *, struct iwn_rx_desc *);
 void   iwn_notif_intr(struct iwn_softc *);
 void   iwn_wakeup_intr(struct iwn_softc *);
@@ -2259,6 +2259,7 @@ void
 iwn_rx_compressed_ba(struct iwn_softc *sc, struct iwn_rx_desc *desc,
 struct iwn_rx_data *data)
 {
+   struct iwn_ops *ops = >ops;
struct iwn_compressed_ba *cba = (struct iwn_compressed_ba *)(desc + 1);
struct ieee80211com *ic = >sc_ic;
struct ieee80211_node *ni;
@@ -2268,6 +2269,9 @@ iwn_rx_compressed_ba(struct iwn_softc *sc, struct iwn_
uint16_t ssn, idx;
int qid;
 
+   if (ic->ic_state != IEEE80211_S_RUN)
+   return;
+
bus_dmamap_sync(sc->sc_dmat, data->map, sizeof (*desc), sizeof (*cba),
BUS_DMASYNC_POSTREAD);
 
@@ -2282,47 +2286,76 @@ iwn_rx_compressed_ba(struct iwn_softc *sc, struct iwn_
return;
 
txq = >txq[qid];
-   ssn = le16toh(cba->ssn); /* BA window starting sequence number */
-   idx = IWN_AGG_SSN_TO_TXQ_IDX(ssn);
 
/* Protect against a firmware bug where the queue/TID are off. */
if (qid != sc->first_agg_txq + cba->tid)
return;
-   /*
-* Update Tx rate statistics.
-*/
-   if (ic->ic_state == IEEE80211_S_RUN && cba->nframes_sent > 0) {
-   uint8_t nframes = cba->nframes_sent;
-   int read = txq->read;
-   wn->mn.agglen = 0;
-   wn->mn.ampdu_size = 0;
-   /* Add up the lengths of all frames before the window. */
-   while (nframes && read != idx) {
-   struct iwn_tx_data *txdata = >data[read];
-   wn->mn.agglen++;
-   wn->mn.ampdu_size += txdata->totlen + IEEE80211_CRC_LEN;
-   read = (read + 1) % IWN_TX_RING_COUNT;
-   nframes--;
-   }
-   wn->mn.frames += cba->nframes_sent;
-   /* If firmware reports a bogus ACK counter, fix it up. */
-   if (cba->nframes_acked > cba->nframes_sent)
-   cba->nframes_acked = cba->nframes_sent;
-   wn->mn.retries += cba->nframes_sent - cba->nframes_acked;
-   if (wn->mn.txfail > wn->mn.frames)
-   wn->mn.txfail = wn->mn.frames;
-   if (wn->mn.ampdu_size > 0)
-   ieee80211_mira_choose(>mn, ic, ni);
-   }
 
ba = >ni_tx_ba[cba->tid];
+   if (ba->ba_state != IEEE80211_BA_AGREED)
+   return;
 
+   ssn = le16toh(cba->ssn); /* BA window starting sequence number */
if (!SEQ_LT(ssn, ba->ba_winstart)) {

iwn: fix tx result reporting

2020-04-06 Thread Stefan Sperling
On Thu, Apr 02, 2020 at 03:52:11PM +0200, Stefan Sperling wrote:
> While working on iwm Tx aggregation and revisiting some parts of MiRA,
> I have noticed a rate-control problem in iwm and iwx (this also affects
> iwn, but I am leaving that for later since iwn already does Tx aggregation
> and requires a more elaborate fix).

Here is the corresponding diff for iwn(4).

Fixes an automatic Tx rate control issue in iwn(4).
Same change as for iwm(4) and iwx(4), but also accounts for block ack.

Also fix this driver's handling of ic_fixed_mcs.
 
diff 5c2ccc6893e39ccee38b5e7e6ecf6487be392b1e 
efc01515a309caa279d79c1a251c73cdbcc68bba
blob - 72e19d7e35646822faaed4f2ebd157297a8ec907
blob + 30a936bedb20e7958f73ee789e9aced79626e580
--- sys/dev/pci/if_iwn.c
+++ sys/dev/pci/if_iwn.c
@@ -166,8 +166,8 @@ voidiwn_rx_statistics(struct iwn_softc *, 
struct iwn
 void   iwn_ampdu_txq_advance(struct iwn_softc *, struct iwn_tx_ring *,
int, int);
 void   iwn_ampdu_tx_done(struct iwn_softc *, struct iwn_tx_ring *,
-   struct iwn_rx_desc *, uint16_t, struct iwn_txagg_status *,
-   int, uint32_t);
+   struct iwn_rx_desc *, uint16_t, uint8_t, uint8_t, uint8_t,
+   int, uint32_t, struct iwn_txagg_status *);
 void   iwn4965_tx_done(struct iwn_softc *, struct iwn_rx_desc *,
struct iwn_rx_data *);
 void   iwn5000_tx_done(struct iwn_softc *, struct iwn_rx_desc *,
@@ -176,7 +176,7 @@ voidiwn_tx_done_free_txdata(struct 
iwn_softc *,
struct iwn_tx_data *);
 void   iwn_clear_oactive(struct iwn_softc *, struct iwn_tx_ring *);
 void   iwn_tx_done(struct iwn_softc *, struct iwn_rx_desc *,
-   uint8_t, int, int, uint16_t);
+   uint8_t, uint8_t, int, int, uint16_t);
 void   iwn_cmd_done(struct iwn_softc *, struct iwn_rx_desc *);
 void   iwn_notif_intr(struct iwn_softc *);
 void   iwn_wakeup_intr(struct iwn_softc *);
@@ -2259,6 +2259,7 @@ void
 iwn_rx_compressed_ba(struct iwn_softc *sc, struct iwn_rx_desc *desc,
 struct iwn_rx_data *data)
 {
+   struct iwn_ops *ops = >ops;
struct iwn_compressed_ba *cba = (struct iwn_compressed_ba *)(desc + 1);
struct ieee80211com *ic = >sc_ic;
struct ieee80211_node *ni;
@@ -2268,6 +2269,9 @@ iwn_rx_compressed_ba(struct iwn_softc *sc, struct iwn_
uint16_t ssn, idx;
int qid;
 
+   if (ic->ic_state != IEEE80211_S_RUN)
+   return;
+
bus_dmamap_sync(sc->sc_dmat, data->map, sizeof (*desc), sizeof (*cba),
BUS_DMASYNC_POSTREAD);
 
@@ -2282,41 +2286,66 @@ iwn_rx_compressed_ba(struct iwn_softc *sc, struct iwn_
return;
 
txq = >txq[qid];
-   ssn = le16toh(cba->ssn); /* BA window starting sequence number */
-   idx = IWN_AGG_SSN_TO_TXQ_IDX(ssn);
 
/* Protect against a firmware bug where the queue/TID are off. */
if (qid != sc->first_agg_txq + cba->tid)
return;
+
+   ba = >ni_tx_ba[cba->tid];
+   if (ba->ba_state != IEEE80211_BA_AGREED)
+   return;
+
/*
 * Update Tx rate statistics.
+* Skip rate control if our Tx rate is fixed.
 */
-   if (ic->ic_state == IEEE80211_S_RUN && cba->nframes_sent > 0) {
-   uint8_t nframes = cba->nframes_sent;
-   int read = txq->read;
+   if (ic->ic_fixed_mcs == -1 && cba->nframes_sent > 0) {
+   int end_idx = IWN_AGG_SSN_TO_TXQ_IDX(ba->ba_winend);
+   int bit = 0, nsent = cba->nframes_sent;
+
wn->mn.agglen = 0;
wn->mn.ampdu_size = 0;
-   /* Add up the lengths of all frames before the window. */
-   while (nframes && read != idx) {
-   struct iwn_tx_data *txdata = >data[read];
-   wn->mn.agglen++;
-   wn->mn.ampdu_size += txdata->totlen + IEEE80211_CRC_LEN;
-   read = (read + 1) % IWN_TX_RING_COUNT;
-   nframes--;
+
+   ssn = le16toh(ba->ba_winstart);
+   idx = IWN_AGG_SSN_TO_TXQ_IDX(ssn);
+   while (nsent && idx != end_idx) {
+   struct iwn_tx_data *txdata = >data[idx];
+   int have_ack = (le64toh(cba->bitmap) & (1 << bit++));
+
+   if (txdata->m != NULL) {
+   /*
+* Don't report frames to MiRA which were sent
+* at a different Tx rate than ni->ni_txmcs.
+*/
+   if (txdata->actual_txmcs == ni->ni_txmcs) {
+   wn->mn.frames++;
+   wn->mn.agglen++;
+   wn->mn.ampdu_size += txdata->totlen +

Re: wi(4): tsleep(9) -> tsleep_nsec(9)

2020-04-06 Thread Stefan Sperling
On Mon, Apr 06, 2020 at 02:03:36PM -0500, Scott Cheloha wrote:
> Ticks to seconds.  Trivial.
> 
> ok?

ok stsp@

> Index: if_wi.c
> ===
> RCS file: /cvs/src/sys/dev/ic/if_wi.c,v
> retrieving revision 1.171
> diff -u -p -r1.171 if_wi.c
> --- if_wi.c   31 Dec 2019 10:05:32 -  1.171
> +++ if_wi.c   6 Apr 2020 18:29:33 -
> @@ -1865,8 +1865,8 @@ wi_ioctl(struct ifnet *ifp, u_long comma
>   timeout_add(>wi_scan_timeout, len);
>  
>   /* Let the userspace process wait for completion */
> - error = tsleep(>wi_scan_lock, PCATCH, "wiscan",
> - hz * IEEE80211_SCAN_TIMEOUT);
> + error = tsleep_nsec(>wi_scan_lock, PCATCH, "wiscan",
> + SEC_TO_NSEC(IEEE80211_SCAN_TIMEOUT));
>   break;
>   case SIOCG80211ALLNODES:
>   {
> 



Re: pipex(4) fix: check session existence before creation

2020-04-06 Thread Claudio Jeker
On Mon, Apr 06, 2020 at 06:32:01PM +0300, Vitaliy Makkoveev wrote:
> 
> 
> > On 6 Apr 2020, at 17:37, Claudio Jeker  wrote:
> > 
> > On Mon, Apr 06, 2020 at 07:54:20PM +0300, Vitaliy Makkoveev wrote:
> >> Deny to create pipex_session which is already exist. Newly created
> >> session will be placed to list head so the caller of
> >> pipex_*_lookup_session() will receive wrong session.
> > 
> > I think in the pppx(4) case the code is already doing this check in the
> > RBT_FIND() on line 835. Still I think this is a good thing to add.
> > OK claudio@
> > 
> 
> In pppx(4) layer not in pipex(4). Without this check pppx(4) can
> override pppac(4) owned session.

Yes, the pppac(4) version does not do the check. I'm not sure sure if it is
valid to use both pppx and pppac at the same time. In the end doing the
check feels right.
 
> > 
> >> Index: sys/net/if_pppx.c
> >> ===
> >> RCS file: /cvs/src/sys/net/if_pppx.c,v
> >> retrieving revision 1.79
> >> diff -u -p -r1.79 if_pppx.c
> >> --- sys/net/if_pppx.c  6 Apr 2020 12:31:30 -   1.79
> >> +++ sys/net/if_pppx.c  6 Apr 2020 13:47:26 -
> >> @@ -719,6 +719,11 @@ pppx_add_session(struct pppx_dev *pxd, s
> >>return (EPROTONOSUPPORT);
> >>}
> >> 
> >> +  session = pipex_lookup_by_session_id(req->pr_protocol,
> >> +  req->pr_session_id);
> >> +  if (session)
> >> +  return (EEXIST);
> >> +
> >>pxi = pool_get(pppx_if_pl, PR_WAITOK | PR_ZERO);
> >>if (pxi == NULL)
> >>return (ENOMEM);
> >> Index: sys/net/pipex.c
> >> ===
> >> RCS file: /cvs/src/sys/net/pipex.c,v
> >> retrieving revision 1.112
> >> diff -u -p -r1.112 pipex.c
> >> --- sys/net/pipex.c6 Apr 2020 13:14:04 -   1.112
> >> +++ sys/net/pipex.c6 Apr 2020 13:47:33 -
> >> @@ -312,6 +312,11 @@ pipex_add_session(struct pipex_session_r
> >>return (EPROTONOSUPPORT);
> >>}
> >> 
> >> +  session = pipex_lookup_by_session_id(req->pr_protocol,
> >> +  req->pr_session_id);
> >> +  if (session)
> >> +  return (EEXIST);
> >> +
> >>/* prepare a new session */
> >>session = pool_get(_session_pool, PR_WAITOK | PR_ZERO);
> >>session->state = PIPEX_STATE_OPENED;
> >> 
> > 
> > -- 
> > :wq Claudio
> 

-- 
:wq Claudio



wi(4): tsleep(9) -> tsleep_nsec(9)

2020-04-06 Thread Scott Cheloha
Ticks to seconds.  Trivial.

ok?

Index: if_wi.c
===
RCS file: /cvs/src/sys/dev/ic/if_wi.c,v
retrieving revision 1.171
diff -u -p -r1.171 if_wi.c
--- if_wi.c 31 Dec 2019 10:05:32 -  1.171
+++ if_wi.c 6 Apr 2020 18:29:33 -
@@ -1865,8 +1865,8 @@ wi_ioctl(struct ifnet *ifp, u_long comma
timeout_add(>wi_scan_timeout, len);
 
/* Let the userspace process wait for completion */
-   error = tsleep(>wi_scan_lock, PCATCH, "wiscan",
-   hz * IEEE80211_SCAN_TIMEOUT);
+   error = tsleep_nsec(>wi_scan_lock, PCATCH, "wiscan",
+   SEC_TO_NSEC(IEEE80211_SCAN_TIMEOUT));
break;
case SIOCG80211ALLNODES:
{



pppx(4): kill needless check

2020-04-06 Thread Vitaliy Makkoveev
Just quick cleanup.

Index: sys/net/if_pppx.c
===
RCS file: /cvs/src/sys/net/if_pppx.c,v
retrieving revision 1.79
diff -u -p -r1.79 if_pppx.c
--- sys/net/if_pppx.c   6 Apr 2020 12:31:30 -   1.79
+++ sys/net/if_pppx.c   6 Apr 2020 19:22:13 -
@@ -720,8 +720,6 @@ pppx_add_session(struct pppx_dev *pxd, s
}
 
pxi = pool_get(pppx_if_pl, PR_WAITOK | PR_ZERO);
-   if (pxi == NULL)
-   return (ENOMEM);
 
session = >pxi_session;
ifp = >pxi_if;



Re: [PLEASE TEST] acpi(4): acpi_sleep(): tsleep(9) -> tsleep_nsec(9)

2020-04-06 Thread Scott Cheloha
On Tue, Mar 24, 2020 at 09:02:38PM +0100, Mark Kettenis wrote:
> > Date: Tue, 24 Mar 2020 12:52:55 -0500
> > From: Scott Cheloha 
> > 
> > On Tue, Mar 24, 2020 at 09:17:34AM +0100, Mark Kettenis wrote:
> > > > Date: Mon, 23 Mar 2020 21:57:46 -0500
> > > > From: Scott Cheloha 
> > > > 
> > > > On Sun, Mar 15, 2020 at 09:55:53PM -0500, Scott Cheloha wrote:
> > > > > 
> > > > > [...]
> > > > > 
> > > > > This is a straightforward ticks-to-milliseconds conversion, but IIRC
> > > > > pirofti@ wanted me to get some tests before committing it.
> > > > > 
> > > > > The only users of acpi_sleep() are (a) acpitz(4) and (b) any AML code
> > > > > that uses AMLOP_SLEEP.  AMLOP_SLEEP seems to trigger just before a
> > > > > suspend.  I don't know when else it is used.
> > > > > 
> > > > > If you have an acpi(4) laptop with suspend/resume support, please
> > > > > apply this patch and let me know if anything doesn't work,
> > > > > particularly with suspend/resume.
> > > > > 
> > > > > [...]
> > > > 
> > > > 1 week bump.
> > > > 
> > > > I have one test report.  I'm hoping for a few more.
> > > > 
> > > > I think acpi(4) machines with suspend/resume support should be
> > > > somewhat common amongst tech@ readers.
> > > 
> > > AMLOP_SLEEP can occur anywhere when executing AML code.
> > 
> > Oh, good to know.
> > 
> > > The current code tries to protect against negative timeouts, but
> > > your new code doesn't?
> > 
> > What would a negative value here actually mean?  A firmware bug?
> > Should we log that?  Or panic?
> > 
> > The simplest thing would be to just MAX it up to 1.  Which I have
> > done in this patch.
> > 
> > But it looks like there are other "what if we get a negative value
> > from the firmware" problems in this file.  I dunno if you want to
> > address all of them.
> > 
> > Related:
> > 
> > I'm looking around at these functions accepting .v_integer as
> > argument: acpi_stall, acpi_sleep(), acpi_event_wait().  They all take
> > ints, but aml_value.v_integer is an int64_t.  So there's implicit
> > type-casting.
> > 
> > Should we change these functions to handle 64-bit integers?  Or should
> > we clamp .v_integer to within [INT_MIN, INT_MAX]?
> 
> The ACPI code isn't the best code in our tree I fear.  One issue here
> is that ACPI 1.0 had 32-bit integers, which became 640-bit in ACPI
> 2.0.  Treating all integers as 64-bit numbers seems to work fine
> though.  So acpi_sleep() should really accept a 64-bit integer as an
> argument.  And ACPI says that integers are unsigned, so the sign
> problem should never occur and our codebase is just plain doing it
> wrong...
> 
> Here is the description of the operation lifted form the ACPI 6.3 spec:
> 
>   19.6.125 Sleep (Milliseconds Sleep)
> 
>   Syntax
> 
> Sleep (MilliSeconds)
> 
>   Arguments
> 
> The Sleep term is used to implement long-term timing
> requirements. Execution is delayed for at least the required
> number of milliseconds.
> 
>   Description
> 
> The implementation of Sleep is to round the request up to the
> closest sleep time supported by the OS and relinquish the
> processor.

That sounds like a much deeper problem.

The following diff converts the tsleep(9) to tsleep_nsec(9) without
changing the current behavior.  I have left a note about the larger
problem.

I have several successful test reports.

Is anyone OK with this?

Index: dsdt.c
===
RCS file: /cvs/src/sys/dev/acpi/dsdt.c,v
retrieving revision 1.249
diff -u -p -r1.249 dsdt.c
--- dsdt.c  16 Oct 2019 01:43:50 -  1.249
+++ dsdt.c  6 Apr 2020 20:29:51 -
@@ -465,15 +465,14 @@ void
 acpi_sleep(int ms, char *reason)
 {
static int acpinowait;
-   int to = ms * hz / 1000;
+
+   /* XXX ACPI integers are supposed to be unsigned. */
+   ms = MAX(1, ms);
 
if (cold)
delay(ms * 1000);
-   else {
-   if (to <= 0)
-   to = 1;
-   tsleep(, PWAIT, reason, to);
-   }
+   else
+   tsleep_nsec(, PWAIT, reason, MSEC_TO_NSEC(ms));
 }
 
 void



Re: [PLEASE TEST] acpi(4): acpi_sleep(): tsleep(9) -> tsleep_nsec(9)

2020-04-06 Thread Mark Kettenis
> Date: Mon, 6 Apr 2020 15:32:09 -0500
> From: Scott Cheloha 
> 
> On Tue, Mar 24, 2020 at 09:02:38PM +0100, Mark Kettenis wrote:
> > > Date: Tue, 24 Mar 2020 12:52:55 -0500
> > > From: Scott Cheloha 
> > > 
> > > On Tue, Mar 24, 2020 at 09:17:34AM +0100, Mark Kettenis wrote:
> > > > > Date: Mon, 23 Mar 2020 21:57:46 -0500
> > > > > From: Scott Cheloha 
> > > > > 
> > > > > On Sun, Mar 15, 2020 at 09:55:53PM -0500, Scott Cheloha wrote:
> > > > > > 
> > > > > > [...]
> > > > > > 
> > > > > > This is a straightforward ticks-to-milliseconds conversion, but IIRC
> > > > > > pirofti@ wanted me to get some tests before committing it.
> > > > > > 
> > > > > > The only users of acpi_sleep() are (a) acpitz(4) and (b) any AML 
> > > > > > code
> > > > > > that uses AMLOP_SLEEP.  AMLOP_SLEEP seems to trigger just before a
> > > > > > suspend.  I don't know when else it is used.
> > > > > > 
> > > > > > If you have an acpi(4) laptop with suspend/resume support, please
> > > > > > apply this patch and let me know if anything doesn't work,
> > > > > > particularly with suspend/resume.
> > > > > > 
> > > > > > [...]
> > > > > 
> > > > > 1 week bump.
> > > > > 
> > > > > I have one test report.  I'm hoping for a few more.
> > > > > 
> > > > > I think acpi(4) machines with suspend/resume support should be
> > > > > somewhat common amongst tech@ readers.
> > > > 
> > > > AMLOP_SLEEP can occur anywhere when executing AML code.
> > > 
> > > Oh, good to know.
> > > 
> > > > The current code tries to protect against negative timeouts, but
> > > > your new code doesn't?
> > > 
> > > What would a negative value here actually mean?  A firmware bug?
> > > Should we log that?  Or panic?
> > > 
> > > The simplest thing would be to just MAX it up to 1.  Which I have
> > > done in this patch.
> > > 
> > > But it looks like there are other "what if we get a negative value
> > > from the firmware" problems in this file.  I dunno if you want to
> > > address all of them.
> > > 
> > > Related:
> > > 
> > > I'm looking around at these functions accepting .v_integer as
> > > argument: acpi_stall, acpi_sleep(), acpi_event_wait().  They all take
> > > ints, but aml_value.v_integer is an int64_t.  So there's implicit
> > > type-casting.
> > > 
> > > Should we change these functions to handle 64-bit integers?  Or should
> > > we clamp .v_integer to within [INT_MIN, INT_MAX]?
> > 
> > The ACPI code isn't the best code in our tree I fear.  One issue here
> > is that ACPI 1.0 had 32-bit integers, which became 640-bit in ACPI
> > 2.0.  Treating all integers as 64-bit numbers seems to work fine
> > though.  So acpi_sleep() should really accept a 64-bit integer as an
> > argument.  And ACPI says that integers are unsigned, so the sign
> > problem should never occur and our codebase is just plain doing it
> > wrong...
> > 
> > Here is the description of the operation lifted form the ACPI 6.3 spec:
> > 
> >   19.6.125 Sleep (Milliseconds Sleep)
> > 
> >   Syntax
> > 
> > Sleep (MilliSeconds)
> > 
> >   Arguments
> > 
> > The Sleep term is used to implement long-term timing
> > requirements. Execution is delayed for at least the required
> > number of milliseconds.
> > 
> >   Description
> > 
> > The implementation of Sleep is to round the request up to the
> > closest sleep time supported by the OS and relinquish the
> > processor.
> 
> That sounds like a much deeper problem.
> 
> The following diff converts the tsleep(9) to tsleep_nsec(9) without
> changing the current behavior.  I have left a note about the larger
> problem.
> 
> I have several successful test reports.
> 
> Is anyone OK with this?

ok kettenis@

> Index: dsdt.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/dsdt.c,v
> retrieving revision 1.249
> diff -u -p -r1.249 dsdt.c
> --- dsdt.c16 Oct 2019 01:43:50 -  1.249
> +++ dsdt.c6 Apr 2020 20:29:51 -
> @@ -465,15 +465,14 @@ void
>  acpi_sleep(int ms, char *reason)
>  {
>   static int acpinowait;
> - int to = ms * hz / 1000;
> +
> + /* XXX ACPI integers are supposed to be unsigned. */
> + ms = MAX(1, ms);
>  
>   if (cold)
>   delay(ms * 1000);
> - else {
> - if (to <= 0)
> - to = 1;
> - tsleep(, PWAIT, reason, to);
> - }
> + else
> + tsleep_nsec(, PWAIT, reason, MSEC_TO_NSEC(ms));
>  }
>  
>  void
> 



sysupgrade: add BUILDINFO file to fetched files

2020-04-06 Thread Mikolaj Kucharski
Hi,

When I'm upgrading my machines, I find it useful to have BUILDINFO
file around. Tested on RPi3.

Please carbon-copy me in any replies. Thank you.

openbsd-rpi# sysupgrade -s -n
Fetching from https://cdn.openbsd.org/pub/OpenBSD/snapshots/arm64/
SHA256.sig   100% |**|  1453   00:00
Signature Verified
Verifying old sets.
BUILDINFO100% |**|54   00:00
Verifying sets.
Fetching updated firmware.
Will upgrade on next reboot

openbsd-rpi# reboot
... [successfull upgrade]
openbsd-rpi# ls -1A /home/_sysupgrade/ | wc -l
   0


OpenBSD 6.6-current (GENERIC.MP) #513: Wed Mar 18 16:41:35 MDT 2020
dera...@arm64.openbsd.org:/usr/src/sys/arch/arm64/compile/GENERIC.MP


Index: sysupgrade.sh
===
RCS file: /cvs/src/usr.sbin/sysupgrade/sysupgrade.sh,v
retrieving revision 1.37
diff -u -p -u -r1.37 sysupgrade.sh
--- sysupgrade.sh   26 Jan 2020 22:08:36 -  1.37
+++ sysupgrade.sh   20 Mar 2020 06:30:51 -
@@ -152,9 +152,9 @@ if cmp -s /var/db/installed.SHA256 SHA25
exit 0
 fi
 
-# INSTALL.*, bsd*, *.tgz
+# BUILDINFO, INSTALL.*, bsd*, *.tgz
 SETS=$(sed -n -e 's/^SHA256 (\(.*\)) .*/\1/' \
--e '/^INSTALL\./p;/^bsd/p;/\.tgz$/p' SHA256)
+-e '/^BUILDINFO$/p;/^INSTALL\./p;/^bsd/p;/\.tgz$/p' SHA256)
 
 OLD_FILES=$(ls)
 OLD_FILES=$(rmel SHA256 $OLD_FILES)

-- 
Regards,
 Mikolaj



pipex(4) cleanup: use LIST_FOERACH_SAFE() instead of manual rolling

2020-04-06 Thread Vitaliy Makkoveev
Index: sys/net/pipex.c
===
RCS file: /cvs/src/sys/net/pipex.c,v
retrieving revision 1.111
diff -u -p -r1.111 pipex.c
--- sys/net/pipex.c 6 Apr 2020 12:31:30 -   1.111
+++ sys/net/pipex.c 6 Apr 2020 12:58:31 -
@@ -177,17 +177,15 @@ pipex_iface_start(struct pipex_iface_con
 Static void
 pipex_iface_stop(struct pipex_iface_context *pipex_iface)
 {
-   struct pipex_session *session;
-   struct pipex_session *session_next;
+   struct pipex_session *session, *session_tmp;
 
pipex_iface->pipexmode = 0;
/*
 * traversal all pipex sessions.
 * it will become heavy if the number of pppac devices bocomes large.
 */
-   for (session = LIST_FIRST(_session_list);
-   session; session = session_next) {
-   session_next = LIST_NEXT(session, session_list);
+   LIST_FOREACH_SAFE(session, _session_list, session_list,
+   session_tmp) {
if (session->pipex_iface == pipex_iface)
pipex_destroy_session(session);
}
@@ -555,13 +553,12 @@ Static int
 pipex_get_closed(struct pipex_session_list_req *req,
 struct pipex_iface_context *iface)
 {
-   struct pipex_session *session, *session_next;
+   struct pipex_session *session, *session_tmp;
 
NET_ASSERT_LOCKED();
bzero(req, sizeof(*req));
-   for (session = LIST_FIRST(_close_wait_list);
-   session; session = session_next) {
-   session_next = LIST_NEXT(session, state_list);
+   LIST_FOREACH_SAFE(session, _close_wait_list, state_list,
+   session_tmp) {
if (session->pipex_iface != iface)
continue;
req->plr_ppp_id[req->plr_ppp_id_count++] = session->ppp_id;
@@ -763,16 +760,14 @@ pipex_timer_stop(void)
 Static void
 pipex_timer(void *ignored_arg)
 {
-   struct pipex_session *session;
-   struct pipex_session *session_next;
+   struct pipex_session *session, *session_tmp;
 
timeout_add_sec(_timer_ch, pipex_prune);
 
NET_LOCK();
/* walk through */
-   for (session = LIST_FIRST(_session_list); session;
-   session = session_next) {
-   session_next = LIST_NEXT(session, session_list);
+   LIST_FOREACH_SAFE(session, _session_list, session_list,
+   session_tmp) {
switch (session->state) {
case PIPEX_STATE_OPENED:
if (session->timeout_sec == 0)



Re: Fix pipex(4) pipex_ioctl() access to not owned sessions (kernel crash too)

2020-04-06 Thread Claudio Jeker
On Thu, Apr 02, 2020 at 01:44:50PM +0300, Vitaliy Makkoveev wrote:
> pipex(4) has pipex_ioctl() interface for pipex_session related routines.
> pipex_ioctl() calls should be done with pipex_iface_contex, so any
> operations should be done with pipex_sessions owned by passed
> pipex_iface_contex. pipex_session check ownership is missing within
> pipex_ioctl() so anybody can do pipex_ioctl() commands PIPEXDSESSION,
> PIPEXCSESSION, PIPEXGSTAT and PIPEXGCLOSED on any pipex_session.
> PIPEXDSESSION on foreign pppx(4) owned pipex_session will crash kernel.
> Code to reproduce and screenshot attached below. Diffs below add
> pipes_session ownrship check to pipex_ioctl() internals.
> 

...

> This diff add ownership checks to the rest pipex_ioctl() commands. A few
> words about pppx_get_closed(): since in-kernel timeout feature was
> disabled for pppx(4) related pipex_sessions, closed pipex_sessions can't
> exist in system, so this function is dummy. I have an idea how to
> reenable this disabled timeout, but some reafactoring requited, and fair
> pipex_ioctl(PIPEXGCLOSED) call will be restored.

One minor comment below:
 
>  cut begin
> diff --git sys/net/if_pppx.c sys/net/if_pppx.c
> index 37a6af0..6c4977d 100644
> --- sys/net/if_pppx.c
> +++ sys/net/if_pppx.c
> @@ -175,6 +175,12 @@ int  pppx_add_session(struct pppx_dev *,
>   struct pipex_session_req *);
>  int  pppx_del_session(struct pppx_dev *,
>   struct pipex_session_close_req *);
> +int  pppx_config_session(struct pppx_dev *,
> + struct pipex_session_config_req *);
> +int  pppx_get_stat(struct pppx_dev *,
> + struct pipex_session_stat_req *);
> +int  pppx_get_closed(struct pppx_dev *,
> + struct pipex_session_list_req *);
>  int  pppx_set_session_descr(struct pppx_dev *,
>   struct pipex_session_descr_req *);
>  
> @@ -451,16 +457,18 @@ pppxioctl(dev_t dev, u_long cmd, caddr_t addr, int 
> flags, struct proc *p)
>   break;
>  
>   case PIPEXCSESSION:
> - error = pipex_config_session(
> + error = pppx_config_session(pxd,
>   (struct pipex_session_config_req *)addr);
>   break;
>  
>   case PIPEXGSTAT:
> - error = pipex_get_stat((struct pipex_session_stat_req *)addr);
> + error = pppx_get_stat(pxd,
> + (struct pipex_session_stat_req *)addr);
>   break;
>  
>   case PIPEXGCLOSED:
> - error = pipex_get_closed((struct pipex_session_list_req *)addr);
> + error = pppx_get_closed(pxd,
> + (struct pipex_session_list_req *)addr);
>   break;
>  
>   case PIPEXSIFDESCR:
> @@ -947,6 +955,40 @@ pppx_del_session(struct pppx_dev *pxd, struct 
> pipex_session_close_req *req)
>   return (0);
>  }
>  
> +int
> +pppx_config_session(struct pppx_dev *pxd,
> +struct pipex_session_config_req *req)
> +{
> + struct pppx_if *pxi;
> +
> + pxi = pppx_if_find(pxd, req->pcr_session_id, req->pcr_protocol);
> + if (pxi == NULL)
> + return (EINVAL);
> +
> + return pipex_config_session(req, >pxi_ifcontext);
> +}
> +
> +int
> +pppx_get_stat(struct pppx_dev *pxd, struct pipex_session_stat_req *req)
> +{
> + struct pppx_if *pxi;
> +
> + pxi = pppx_if_find(pxd, req->psr_session_id, req->psr_protocol);
> + if (pxi == NULL)
> + return (EINVAL);
> +
> + return pipex_get_stat(req, >pxi_ifcontext);
> +}
> +
> +int
> +pppx_get_closed(struct pppx_dev *pxd, struct pipex_session_list_req *req)
> +{
> + /* XXX: Only opened sessions exist for pppx(4) */
> + memset(req, 0, sizeof(*req));
> +
> + return 0;
> +}
> +
>  int
>  pppx_set_session_descr(struct pppx_dev *pxd,
>  struct pipex_session_descr_req *req)
> diff --git sys/net/pipex.c sys/net/pipex.c
> index 22edce3..219e18d 100644
> --- sys/net/pipex.c
> +++ sys/net/pipex.c
> @@ -235,15 +235,17 @@ pipex_ioctl(struct pipex_iface_context *pipex_iface, 
> u_long cmd, caddr_t data)
>  
>   case PIPEXCSESSION:
>   ret = pipex_config_session(
> - (struct pipex_session_config_req *)data);
> + (struct pipex_session_config_req *)data, pipex_iface);
>   break;
>  
>   case PIPEXGSTAT:
> - ret = pipex_get_stat((struct pipex_session_stat_req *)data);
> + ret = pipex_get_stat((struct pipex_session_stat_req *)data,
> + pipex_iface);
>   break;
>  
>   case PIPEXGCLOSED:
> - ret = pipex_get_closed((struct pipex_session_list_req *)data);
> + ret = pipex_get_closed((struct pipex_session_list_req *)data,
> + pipex_iface);
>   break;
>  
>   default:
> @@ -514,7 +516,8 @@ pipex_close_session(struct pipex_session_close_req *req,
>  }
>  
>  Static int
> -pipex_config_session(struct 

[patch] ps.c mark usage() as __dead

2020-04-06 Thread Martin Vahlensieck
Hi

I'm not sure this is worth a diff, but here it is anyway.

Best,

Martin

Index: ps.c
===
RCS file: /cvs/src/bin/ps/ps.c,v
retrieving revision 1.76
diff -u -p -r1.76 ps.c
--- ps.c16 Dec 2019 19:21:16 -  1.76
+++ ps.c6 Apr 2020 09:54:47 -
@@ -69,10 +69,10 @@ int needcomm, needenv, neednlist, comman
 
 enum sort { DEFAULT, SORTMEM, SORTCPU } sortby = DEFAULT;
 
-static char*kludge_oldps_options(char *);
-static int  pscomp(const void *, const void *);
-static void scanvars(void);
-static void usage(void);
+static char*kludge_oldps_options(char *);
+static int  pscomp(const void *, const void *);
+static void scanvars(void);
+static void __dead  usage(void);
 
 char dfmt[] = "pid tt state time command";
 char tfmt[] = "pid tid tt state time command";
@@ -482,7 +482,7 @@ kludge_oldps_options(char *s)
return (newopts);
 }
 
-static void
+static void __dead
 usage(void)
 {
(void)fprintf(stderr,



SMR_TAILQ implementation

2020-04-06 Thread Claudio Jeker
To make signal delivery not require the kernel lock I need a basic TAILQ
implementation that is SMR safe. This diff implements this TAILQ.
Without the write lock only SMR_TAILQ_FOREACH() (including SMR_TAIL_FIRST and
SMR_TAILQ_NEXT) can be used. No other traversals are supported.
For the locked version the one function I need is
SMR_TAILQ_INSERT_TAIL_LOCKED() the other functions are more or less
adapted copies of the SMR_LIST version (with the usual TAILQ extra
checks).

Please review. I tried to ensure that smr_tqh_first and smr_tqe_next are
updates last after the membar to ensure that the list can always be
traversed.
-- 
:wq Claudio

Index: sys/smr.h
===
RCS file: /cvs/src/sys/sys/smr.h,v
retrieving revision 1.4
diff -u -p -r1.4 smr.h
--- sys/smr.h   3 Apr 2020 03:36:57 -   1.4
+++ sys/smr.h   6 Apr 2020 10:25:04 -
@@ -318,6 +318,115 @@ struct {  
\
 * any concurrent readers to proceed iteration. */  \
 } while (0)
 
+/*
+ * Tail queue definitions.
+ */
+#defineSMR_TAILQ_HEAD(name, type)  
\
+struct name {  \
+   struct type *smr_tqh_first; /* first element, SMR-protected */\
+   struct type **smr_tqh_last; /* last element, SMR-protected */\
+}
+
+#defineSMR_TAILQ_HEAD_INITIALIZER(head)
\
+   { .smr_tqh_first = NULL, .smr_tqh_last = &(head).smr_tqh_first }
+
+#defineSMR_TAILQ_ENTRY(type)   
\
+struct {   \
+   struct type *smr_tqe_next;  /* next element, SMR-protected */\
+   struct type **smr_tqe_prev; /* address of previous next element */\
+}
+
+/*
+ * Tail queue access methods.
+ */
+#defineSMR_TAILQ_END(head) NULL
+
+#defineSMR_TAILQ_FIRST(head) \
+   SMR_PTR_GET(&(head)->smr_tqh_first)
+#defineSMR_TAILQ_NEXT(elm, field) \
+   SMR_PTR_GET(&(elm)->field.smr_tqe_next)
+
+#defineSMR_TAILQ_FIRST_LOCKED(head)((head)->smr_tqh_first)
+#defineSMR_TAILQ_NEXT_LOCKED(elm, field)   
((elm)->field.smr_tqe_next)
+#defineSMR_TAILQ_LAST_LOCKED(head, headname) \
+   (*(((struct headname *)((head)->smr_tqh_last))->smr_tqh_last))
+#defineSMR_TAILQ_EMPTY_LOCKED(head) \
+   (SMR_TAILQ_FIRST_LOCKED(head) == SMR_TAILQ_END(head))
+
+#defineSMR_TAILQ_FOREACH(var, head, field) 
\
+   for((var) = SMR_TAILQ_FIRST(head);  \
+   (var)!= SMR_TAILQ_END(head);\
+   (var) = SMR_TAILQ_NEXT(var, field))
+
+#defineSMR_TAILQ_FOREACH_LOCKED(var, head, field)  
\
+   for((var) = SMR_TAILQ_FIRST_LOCKED(head);   \
+   (var)!= SMR_TAILQ_END(head);\
+   (var) = SMR_TAILQ_NEXT_LOCKED(var, field))
+
+#defineSMR_TAILQ_FOREACH_SAFE_LOCKED(var, head, field, tvar)   
\
+   for ((var) = SMR_TAILQ_FIRST_LOCKED(head);  \
+   (var) && ((tvar) = SMR_TAILQ_NEXT_LOCKED(var, field), 1);   \
+   (var) = (tvar))
+
+/*
+ * Tail queue functions.
+ */
+#defineSMR_TAILQ_INIT(head) do {   
\
+   (head)->smr_tqh_first = TAILQ_END(head);\
+   (head)->smr_tqh_last = &(head)->smr_tqh_first;  \
+} while (0)
+
+#defineSMR_TAILQ_INSERT_AFTER_LOCKED(head, listelm, elm, field) do {   
\
+   (elm)->field.smr_tqe_next = (listelm)->field.smr_tqe_next;  \
+   if ((listelm)->field.smr_tqe_next != NULL)  \
+   (listelm)->field.smr_tqe_next->field.smr_tqe_prev = \
+   &(elm)->field.smr_tqe_next; \
+   else\
+   (head)->smr_tqh_last = &(elm)->field.smr_tqe_next;  \
+   (elm)->field.smr_tqe_prev = &(listelm)->field.smr_tqe_next; \
+   membar_producer();  \
+   (listelm)->field.smr_tqe_next = (elm);  \
+} while (0)
+
+#defineSMR_TAILQ_INSERT_BEFORE_LOCKED(listelm, elm, field) do {
\
+   (elm)->field.smr_tqe_prev = (listelm)->field.smr_tqe_prev;  \
+   (elm)->field.smr_tqe_next = (listelm);  \
+   membar_producer();  \
+   *(listelm)->field.smr_tqe_prev = (elm); \
+   (listelm)->field.smr_tqe_prev = &(elm)->field.smr_tqe_next; \
+} while (0)
+
+#defineSMR_TAILQ_INSERT_HEAD_LOCKED(head, elm, field) do {