svn commit: r367715 - head/sys/dev/mlx5/mlx5_ib

2020-11-16 Thread Hans Petter Selasky
Author: hselasky
Date: Mon Nov 16 10:00:21 2020
New Revision: 367715
URL: https://svnweb.freebsd.org/changeset/base/367715

Log:
  Fix error handling order in create_kernel_qp in mlx5ib.
  
  Make sure order of cleanup is exactly the opposite of initialization.
  
  Linux commit:
  f4044dac63e952ac1137b6df02b233d37696e2f5
  
  MFC after:1 week
  Sponsored by: Mellanox Technologies // NVIDIA Networking

Modified:
  head/sys/dev/mlx5/mlx5_ib/mlx5_ib_qp.c

Modified: head/sys/dev/mlx5/mlx5_ib/mlx5_ib_qp.c
==
--- head/sys/dev/mlx5/mlx5_ib/mlx5_ib_qp.c  Mon Nov 16 03:12:21 2020
(r367714)
+++ head/sys/dev/mlx5/mlx5_ib/mlx5_ib_qp.c  Mon Nov 16 10:00:21 2020
(r367715)
@@ -987,12 +987,12 @@ static int create_kernel_qp(struct mlx5_ib_dev *dev,
return 0;
 
 err_wrid:
-   mlx5_db_free(dev->mdev, &qp->db);
kfree(qp->sq.wqe_head);
kfree(qp->sq.w_list);
kfree(qp->sq.wrid);
kfree(qp->sq.wr_data);
kfree(qp->rq.wrid);
+   mlx5_db_free(dev->mdev, &qp->db);
 
 err_free:
kvfree(*in);
@@ -1007,12 +1007,12 @@ err_uuar:
 
 static void destroy_qp_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp)
 {
-   mlx5_db_free(dev->mdev, &qp->db);
kfree(qp->sq.wqe_head);
kfree(qp->sq.w_list);
kfree(qp->sq.wrid);
kfree(qp->sq.wr_data);
kfree(qp->rq.wrid);
+   mlx5_db_free(dev->mdev, &qp->db);
mlx5_buf_free(dev->mdev, &qp->buf);
free_uuar(&dev->mdev->priv.uuari, qp->bf->uuarn);
 }
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367716 - in head/sys/dev/mlx5: . mlx5_core

2020-11-16 Thread Hans Petter Selasky
Author: hselasky
Date: Mon Nov 16 10:03:18 2020
New Revision: 367716
URL: https://svnweb.freebsd.org/changeset/base/367716

Log:
  Use mlx5core to create/destroy all Dynamically Connected Targets, DCTs.
  
  To prevent a hardware memory leak when a DEVX DCT object is destroyed
  without calling drain DCT before, (e.g. under cleanup flow), need to
  manage its creation and destruction via mlx5 core.
  
  Linux commit:
  c5ae1954c47d3fd8815bd5a592aba18702c93f33
  
  MFC after:1 week
  Sponsored by: Mellanox Technologies // NVIDIA Networking

Modified:
  head/sys/dev/mlx5/mlx5_core/mlx5_qp.c
  head/sys/dev/mlx5/qp.h

Modified: head/sys/dev/mlx5/mlx5_core/mlx5_qp.c
==
--- head/sys/dev/mlx5/mlx5_core/mlx5_qp.c   Mon Nov 16 10:00:21 2020
(r367715)
+++ head/sys/dev/mlx5/mlx5_core/mlx5_qp.c   Mon Nov 16 10:03:18 2020
(r367716)
@@ -349,19 +349,18 @@ EXPORT_SYMBOL_GPL(mlx5_core_xrcd_dealloc);
 
 int mlx5_core_create_dct(struct mlx5_core_dev *dev,
 struct mlx5_core_dct *dct,
-u32 *in)
+u32 *in, int inlen,
+u32 *out, int outlen)
 {
struct mlx5_qp_table *table = &dev->priv.qp_table;
-   u32 out[MLX5_ST_SZ_DW(create_dct_out)]   = {0};
u32 dout[MLX5_ST_SZ_DW(destroy_dct_out)] = {0};
u32 din[MLX5_ST_SZ_DW(destroy_dct_in)]   = {0};
-   int inlen = MLX5_ST_SZ_BYTES(create_dct_in);
int err;
 
init_completion(&dct->drained);
MLX5_SET(create_dct_in, in, opcode, MLX5_CMD_OP_CREATE_DCT);
 
-   err = mlx5_cmd_exec(dev, in, inlen, &out, sizeof(out));
+   err = mlx5_cmd_exec(dev, in, inlen, out, outlen);
if (err) {
mlx5_core_warn(dev, "create DCT failed, ret %d", err);
return err;
@@ -387,7 +386,7 @@ int mlx5_core_create_dct(struct mlx5_core_dev *dev,
 err_cmd:
MLX5_SET(destroy_dct_in, din, opcode, MLX5_CMD_OP_DESTROY_DCT);
MLX5_SET(destroy_dct_in, din, dctn, dct->dctn);
-   mlx5_cmd_exec(dev, &din, sizeof(din), &out, sizeof(dout));
+   mlx5_cmd_exec(dev, &din, sizeof(din), dout, sizeof(dout));
 
return err;
 }

Modified: head/sys/dev/mlx5/qp.h
==
--- head/sys/dev/mlx5/qp.h  Mon Nov 16 10:00:21 2020(r367715)
+++ head/sys/dev/mlx5/qp.h  Mon Nov 16 10:03:18 2020(r367716)
@@ -586,7 +586,8 @@ int mlx5_core_xrcd_alloc(struct mlx5_core_dev *dev, u3
 int mlx5_core_xrcd_dealloc(struct mlx5_core_dev *dev, u32 xrcdn);
 int mlx5_core_create_dct(struct mlx5_core_dev *dev,
 struct mlx5_core_dct *dct,
-u32 *in);
+u32 *in, int inlen,
+u32 *out, int outlen);
 int mlx5_core_destroy_dct(struct mlx5_core_dev *dev,
  struct mlx5_core_dct *dct);
 int mlx5_core_create_rq_tracked(struct mlx5_core_dev *dev, u32 *in, int inlen,
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367717 - in head/sys/dev/mlx5: . mlx5_core mlx5_en mlx5_ib

2020-11-16 Thread Hans Petter Selasky
Author: hselasky
Date: Mon Nov 16 10:06:10 2020
New Revision: 367717
URL: https://svnweb.freebsd.org/changeset/base/367717

Log:
  Enhance the mlx5_core_create_cq() function in mlx5core.
  
  Enhance mlx5_core_create_cq() to get the command out buffer from the
  callers to let them use the output.
  
  Linux commit:
  38164b771947be9baf06e78ffdfb650f8f3e908e
  
  MFC after:1 week
  Sponsored by: Mellanox Technologies // NVIDIA Networking

Modified:
  head/sys/dev/mlx5/cq.h
  head/sys/dev/mlx5/mlx5_core/mlx5_cq.c
  head/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
  head/sys/dev/mlx5/mlx5_ib/mlx5_ib_cq.c

Modified: head/sys/dev/mlx5/cq.h
==
--- head/sys/dev/mlx5/cq.h  Mon Nov 16 10:03:18 2020(r367716)
+++ head/sys/dev/mlx5/cq.h  Mon Nov 16 10:06:10 2020(r367717)
@@ -155,7 +155,7 @@ static inline void mlx5_cq_arm(struct mlx5_core_cq *cq
 int mlx5_init_cq_table(struct mlx5_core_dev *dev);
 void mlx5_cleanup_cq_table(struct mlx5_core_dev *dev);
 int mlx5_core_create_cq(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq,
-   u32 *in, int inlen);
+   u32 *in, int inlen, u32 *out, int outlen);
 int mlx5_core_destroy_cq(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq);
 int mlx5_core_query_cq(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq,
   u32 *out, int outlen);

Modified: head/sys/dev/mlx5/mlx5_core/mlx5_cq.c
==
--- head/sys/dev/mlx5/mlx5_core/mlx5_cq.c   Mon Nov 16 10:03:18 2020
(r367716)
+++ head/sys/dev/mlx5/mlx5_core/mlx5_cq.c   Mon Nov 16 10:06:10 2020
(r367717)
@@ -119,16 +119,16 @@ void mlx5_cq_event(struct mlx5_core_dev *dev, u32 cqn,
 }
 
 int mlx5_core_create_cq(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq,
-   u32 *in, int inlen)
+   u32 *in, int inlen, u32 *out, int outlen)
 {
struct mlx5_cq_table *table = &dev->priv.cq_table;
-   u32 out[MLX5_ST_SZ_DW(create_cq_out)] = {0};
u32 din[MLX5_ST_SZ_DW(destroy_cq_in)] = {0};
u32 dout[MLX5_ST_SZ_DW(destroy_cq_out)] = {0};
int err;
 
+   memset(out, 0, outlen);
MLX5_SET(create_cq_in, in, opcode, MLX5_CMD_OP_CREATE_CQ);
-   err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
+   err = mlx5_cmd_exec(dev, in, inlen, out, outlen);
if (err)
return err;
 

Modified: head/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
==
--- head/sys/dev/mlx5/mlx5_en/mlx5_en_main.cMon Nov 16 10:03:18 2020
(r367716)
+++ head/sys/dev/mlx5/mlx5_en/mlx5_en_main.cMon Nov 16 10:06:10 2020
(r367717)
@@ -1989,6 +1989,7 @@ static int
 mlx5e_enable_cq(struct mlx5e_cq *cq, struct mlx5e_cq_param *param, int eq_ix)
 {
struct mlx5_core_cq *mcq = &cq->mcq;
+   u32 out[MLX5_ST_SZ_DW(create_cq_out)];
void *in;
void *cqc;
int inlen;
@@ -2017,7 +2018,7 @@ mlx5e_enable_cq(struct mlx5e_cq *cq, struct mlx5e_cq_p
PAGE_SHIFT);
MLX5_SET64(cqc, cqc, dbr_addr, cq->wq_ctrl.db.dma);
 
-   err = mlx5_core_create_cq(cq->priv->mdev, mcq, in, inlen);
+   err = mlx5_core_create_cq(cq->priv->mdev, mcq, in, inlen, out, 
sizeof(out));
 
kvfree(in);
 

Modified: head/sys/dev/mlx5/mlx5_ib/mlx5_ib_cq.c
==
--- head/sys/dev/mlx5/mlx5_ib/mlx5_ib_cq.c  Mon Nov 16 10:03:18 2020
(r367716)
+++ head/sys/dev/mlx5/mlx5_ib/mlx5_ib_cq.c  Mon Nov 16 10:06:10 2020
(r367717)
@@ -905,6 +905,7 @@ struct ib_cq *mlx5_ib_create_cq(struct ib_device *ibde
int entries = attr->cqe;
int vector = attr->comp_vector;
struct mlx5_ib_dev *dev = to_mdev(ibdev);
+   u32 out[MLX5_ST_SZ_DW(create_cq_out)];
struct mlx5_ib_cq *cq;
int uninitialized_var(index);
int uninitialized_var(inlen);
@@ -969,7 +970,7 @@ struct ib_cq *mlx5_ib_create_cq(struct ib_device *ibde
if (cq->create_flags & IB_CQ_FLAGS_IGNORE_OVERRUN)
MLX5_SET(cqc, cqc, oi, 1);
 
-   err = mlx5_core_create_cq(dev->mdev, &cq->mcq, cqb, inlen);
+   err = mlx5_core_create_cq(dev->mdev, &cq->mcq, cqb, inlen, out, 
sizeof(out));
if (err)
goto err_cqb;
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367718 - in head/sys/dev/mlx5: . mlx5_core mlx5_en mlx5_ib

2020-11-16 Thread Hans Petter Selasky
Author: hselasky
Date: Mon Nov 16 10:10:53 2020
New Revision: 367718
URL: https://svnweb.freebsd.org/changeset/base/367718

Log:
  Report EQE data upon CQ completion in mlx5core.
  
  Report EQE data upon CQ completion to let upper layers use this data.
  
  Linux commit:
  4e0e2ea1886afe8c001971ff767f6670312a9b04
  
  MFC after:1 week
  Sponsored by: Mellanox Technologies // NVIDIA Networking

Modified:
  head/sys/dev/mlx5/cq.h
  head/sys/dev/mlx5/driver.h
  head/sys/dev/mlx5/mlx5_core/mlx5_cq.c
  head/sys/dev/mlx5/mlx5_core/mlx5_eq.c
  head/sys/dev/mlx5/mlx5_en/en.h
  head/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
  head/sys/dev/mlx5/mlx5_en/mlx5_en_rl.c
  head/sys/dev/mlx5/mlx5_en/mlx5_en_rx.c
  head/sys/dev/mlx5/mlx5_en/mlx5_en_tx.c
  head/sys/dev/mlx5/mlx5_ib/mlx5_ib_cq.c
  head/sys/dev/mlx5/mlx5_ib/mlx5_ib_main.c

Modified: head/sys/dev/mlx5/cq.h
==
--- head/sys/dev/mlx5/cq.h  Mon Nov 16 10:06:10 2020(r367717)
+++ head/sys/dev/mlx5/cq.h  Mon Nov 16 10:10:53 2020(r367718)
@@ -32,7 +32,7 @@
 #include 
 #include 
 
-
+struct mlx5_eqe;
 struct mlx5_core_cq {
u32 cqn;
int cqe_sz;
@@ -40,7 +40,7 @@ struct mlx5_core_cq {
__be32 *arm_db;
unsignedvector;
int irqn;
-   void (*comp)(struct mlx5_core_cq *);
+   void (*comp)(struct mlx5_core_cq *, struct mlx5_eqe *);
void (*event)   (struct mlx5_core_cq *, int);
struct mlx5_uar*uar;
u32 cons_index;

Modified: head/sys/dev/mlx5/driver.h
==
--- head/sys/dev/mlx5/driver.h  Mon Nov 16 10:06:10 2020(r367717)
+++ head/sys/dev/mlx5/driver.h  Mon Nov 16 10:10:53 2020(r367718)
@@ -1021,7 +1021,7 @@ void mlx5_unregister_debugfs(void);
 int mlx5_eq_init(struct mlx5_core_dev *dev);
 void mlx5_eq_cleanup(struct mlx5_core_dev *dev);
 void mlx5_fill_page_array(struct mlx5_buf *buf, __be64 *pas);
-void mlx5_cq_completion(struct mlx5_core_dev *dev, u32 cqn);
+void mlx5_cq_completion(struct mlx5_core_dev *dev, struct mlx5_eqe *eqe);
 void mlx5_rsc_event(struct mlx5_core_dev *dev, u32 rsn, int event_type);
 void mlx5_srq_event(struct mlx5_core_dev *dev, u32 srqn, int event_type);
 struct mlx5_core_srq *mlx5_core_get_srq(struct mlx5_core_dev *dev, u32 srqn);

Modified: head/sys/dev/mlx5/mlx5_core/mlx5_cq.c
==
--- head/sys/dev/mlx5/mlx5_core/mlx5_cq.c   Mon Nov 16 10:06:10 2020
(r367717)
+++ head/sys/dev/mlx5/mlx5_core/mlx5_cq.c   Mon Nov 16 10:10:53 2020
(r367718)
@@ -55,13 +55,16 @@ mlx5_cq_table_write_unlock(struct mlx5_cq_table *table
NET_EPOCH_WAIT();
 }
 
-void mlx5_cq_completion(struct mlx5_core_dev *dev, u32 cqn)
+void mlx5_cq_completion(struct mlx5_core_dev *dev, struct mlx5_eqe *eqe)
 {
struct mlx5_cq_table *table = &dev->priv.cq_table;
struct mlx5_core_cq *cq;
struct epoch_tracker et;
+   u32 cqn;
bool do_lock;
 
+   cqn = be32_to_cpu(eqe->data.comp.cqn) & 0xff;
+
NET_EPOCH_ENTER(et);
 
do_lock = atomic_read(&table->writercount) != 0;
@@ -78,7 +81,7 @@ void mlx5_cq_completion(struct mlx5_core_dev *dev, u32
 
if (likely(cq != NULL)) {
++cq->arm_sn;
-   cq->comp(cq);
+   cq->comp(cq, eqe);
} else {
mlx5_core_warn(dev,
"Completion event for bogus CQ 0x%x\n", cqn);

Modified: head/sys/dev/mlx5/mlx5_core/mlx5_eq.c
==
--- head/sys/dev/mlx5/mlx5_core/mlx5_eq.c   Mon Nov 16 10:06:10 2020
(r367717)
+++ head/sys/dev/mlx5/mlx5_core/mlx5_eq.c   Mon Nov 16 10:10:53 2020
(r367718)
@@ -246,8 +246,7 @@ static int mlx5_eq_int(struct mlx5_core_dev *dev, stru
  eq->eqn, eqe_type_str(eqe->type));
switch (eqe->type) {
case MLX5_EVENT_TYPE_COMP:
-   cqn = be32_to_cpu(eqe->data.comp.cqn) & 0xff;
-   mlx5_cq_completion(dev, cqn);
+   mlx5_cq_completion(dev, eqe);
break;
 
case MLX5_EVENT_TYPE_PATH_MIG:

Modified: head/sys/dev/mlx5/mlx5_en/en.h
==
--- head/sys/dev/mlx5/mlx5_en/en.h  Mon Nov 16 10:06:10 2020
(r367717)
+++ head/sys/dev/mlx5/mlx5_en/en.h  Mon Nov 16 10:10:53 2020
(r367718)
@@ -149,7 +149,7 @@ MALLOC_DECLARE(M_MLX5EN);
 struct mlx5_core_dev;
 struct mlx5e_cq;
 
-typedef void (mlx5e_cq_comp_t)(struct mlx5_core_cq *);
+typedef void (mlx5e_cq_comp_t)(struct mlx5_core_cq

svn commit: r367719 - in head/sys/dev/mlx5: . mlx5_core mlx5_ib

2020-11-16 Thread Hans Petter Selasky
Author: hselasky
Date: Mon Nov 16 10:15:03 2020
New Revision: 367719
URL: https://svnweb.freebsd.org/changeset/base/367719

Log:
  Make mlx5_cmd_exec_cb() a safe API in mlx5core.
  
  APIs that have deferred callbacks should have some kind of cleanup
  function that callers can use to fence the callbacks. Otherwise things
  like module unloading can lead to dangling function pointers, or worse.
  
  The IB MR code is the only place that calls this function and had a
  really poor attempt at creating this fence. Provide a good version in
  the core code as future patches will add more places that need this
  fence.
  
  Linux commit:
  e355477ed9e4f401e3931043df97325d38552d54
  
  MFC after:1 week
  Sponsored by: Mellanox Technologies // NVIDIA Networking

Modified:
  head/sys/dev/mlx5/driver.h
  head/sys/dev/mlx5/mlx5_core/mlx5_cmd.c
  head/sys/dev/mlx5/mlx5_core/mlx5_mr.c
  head/sys/dev/mlx5/mlx5_ib/mlx5_ib.h
  head/sys/dev/mlx5/mlx5_ib/mlx5_ib_mr.c

Modified: head/sys/dev/mlx5/driver.h
==
--- head/sys/dev/mlx5/driver.h  Mon Nov 16 10:10:53 2020(r367718)
+++ head/sys/dev/mlx5/driver.h  Mon Nov 16 10:15:03 2020(r367719)
@@ -41,6 +41,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -947,11 +948,30 @@ void mlx5_cmd_use_events(struct mlx5_core_dev *dev);
 void mlx5_cmd_use_polling(struct mlx5_core_dev *dev);
 void mlx5_cmd_mbox_status(void *out, u8 *status, u32 *syndrome);
 int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type);
+
+struct mlx5_async_ctx {
+   struct mlx5_core_dev *dev;
+   atomic_t num_inflight;
+   struct wait_queue_head wait;
+};
+
+struct mlx5_async_work;
+
+typedef void (*mlx5_async_cbk_t)(int status, struct mlx5_async_work *context);
+
+struct mlx5_async_work {
+   struct mlx5_async_ctx *ctx;
+   mlx5_async_cbk_t user_callback;
+};
+
+void mlx5_cmd_init_async_ctx(struct mlx5_core_dev *dev,
+struct mlx5_async_ctx *ctx);
+void mlx5_cmd_cleanup_async_ctx(struct mlx5_async_ctx *ctx);
+int mlx5_cmd_exec_cb(struct mlx5_async_ctx *ctx, void *in, int in_size,
+void *out, int out_size, mlx5_async_cbk_t callback,
+struct mlx5_async_work *work);
 int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
  int out_size);
-int mlx5_cmd_exec_cb(struct mlx5_core_dev *dev, void *in, int in_size,
-void *out, int out_size, mlx5_cmd_cbk_t callback,
-void *context);
 int mlx5_cmd_exec_polling(struct mlx5_core_dev *dev, void *in, int in_size,
  void *out, int out_size);
 int mlx5_cmd_alloc_uar(struct mlx5_core_dev *dev, u32 *uarn);
@@ -986,9 +1006,10 @@ void mlx5_init_mr_table(struct mlx5_core_dev *dev);
 void mlx5_cleanup_mr_table(struct mlx5_core_dev *dev);
 int mlx5_core_create_mkey_cb(struct mlx5_core_dev *dev,
 struct mlx5_core_mr *mkey,
-u32 *in, int inlen,
-u32 *out, int outlen,
-mlx5_cmd_cbk_t callback, void *context);
+struct mlx5_async_ctx *async_ctx, u32 *in,
+int inlen, u32 *out, int outlen,
+mlx5_async_cbk_t callback,
+struct mlx5_async_work *context);
 int mlx5_core_create_mkey(struct mlx5_core_dev *dev,
  struct mlx5_core_mr *mr,
  u32 *in, int inlen);

Modified: head/sys/dev/mlx5/mlx5_core/mlx5_cmd.c
==
--- head/sys/dev/mlx5/mlx5_core/mlx5_cmd.c  Mon Nov 16 10:10:53 2020
(r367718)
+++ head/sys/dev/mlx5/mlx5_core/mlx5_cmd.c  Mon Nov 16 10:15:03 2020
(r367719)
@@ -1353,11 +1353,57 @@ int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in,
 }
 EXPORT_SYMBOL(mlx5_cmd_exec);
 
-int mlx5_cmd_exec_cb(struct mlx5_core_dev *dev, void *in, int in_size,
-void *out, int out_size, mlx5_cmd_cbk_t callback,
-void *context)
+void mlx5_cmd_init_async_ctx(struct mlx5_core_dev *dev,
+struct mlx5_async_ctx *ctx)
 {
-   return cmd_exec_helper(dev, in, in_size, out, out_size, callback, 
context, false);
+   ctx->dev = dev;
+   /* Starts at 1 to avoid doing wake_up if we are not cleaning up */
+   atomic_set(&ctx->num_inflight, 1);
+   init_waitqueue_head(&ctx->wait);
+}
+EXPORT_SYMBOL(mlx5_cmd_init_async_ctx);
+
+/**
+ * mlx5_cmd_cleanup_async_ctx - Clean up an async_ctx
+ * @ctx: The ctx to clean
+ *
+ * Upon return all callbacks given to mlx5_cmd_exec_cb() have been called. The
+ * caller must ensure that mlx5_cmd_exec_cb() is not called during or after
+ * the call mlx5_cleanup_async_ctx().
+ */
+void mlx5_cmd_cleanup_async_ctx(str

svn commit: r367720 - head/tools/build

2020-11-16 Thread Alex Richardson
Author: arichardson
Date: Mon Nov 16 11:38:51 2020
New Revision: 367720
URL: https://svnweb.freebsd.org/changeset/base/367720

Log:
  Revert "When building on Ubuntu bootstrap bmake with bash as the default 
shell"
  
  This reverts r365950 since the latest bmake update includes fixes for the test
  failures that prompted the change.

Modified:
  head/tools/build/make.py

Modified: head/tools/build/make.py
==
--- head/tools/build/make.pyMon Nov 16 10:15:03 2020(r367719)
+++ head/tools/build/make.pyMon Nov 16 11:38:51 2020(r367720)
@@ -81,14 +81,6 @@ def bootstrap_bmake(source_root, objdir_prefix):
 "--with-default-sys-path=" + str(bmake_install_dir / "share/mk"),
 "--with-machine=amd64",  # TODO? "--with-machine-arch=amd64",
 "--without-filemon", "--prefix=" + str(bmake_install_dir)]
-
-if Path("/bin/sh").resolve().name == "dash":
-# Note: we have to avoid using dash as the default shell since it
-# filters out variables containing characters such as '-' and that
-# breaks the bmake bootstrap tests.
-# TODO: remove this when the bootstrap tests have been fixed.
-configure_args.append("--with-defshell=/bin/bash")
-
 run(["sh", bmake_source_dir / "boot-strap"] + configure_args,
 cwd=str(bmake_build_dir), env=env)
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367721 - head/sys/dev/mmc/host

2020-11-16 Thread Emmanuel Vadot
Author: manu
Date: Mon Nov 16 11:53:36 2020
New Revision: 367721
URL: https://svnweb.freebsd.org/changeset/base/367721

Log:
  dwmmc: dwmmc_switch_vccq is only used in MMCCAM kernel
  
  Silence the build for non MMCCAM kernel

Modified:
  head/sys/dev/mmc/host/dwmmc.c

Modified: head/sys/dev/mmc/host/dwmmc.c
==
--- head/sys/dev/mmc/host/dwmmc.c   Mon Nov 16 11:38:51 2020
(r367720)
+++ head/sys/dev/mmc/host/dwmmc.c   Mon Nov 16 11:53:36 2020
(r367721)
@@ -143,8 +143,8 @@ static int dma_stop(struct dwmmc_softc *);
 static void pio_read(struct dwmmc_softc *, struct mmc_command *);
 static void pio_write(struct dwmmc_softc *, struct mmc_command *);
 static void dwmmc_handle_card_present(struct dwmmc_softc *sc, bool is_present);
-static int dwmmc_switch_vccq(device_t, device_t);
 #ifdef MMCCAM
+static int dwmmc_switch_vccq(device_t, device_t);
 static void dwmmc_cam_action(struct cam_sim *, union ccb *);
 static void dwmmc_cam_poll(struct cam_sim *);
 static int dwmmc_cam_settran_settings(struct dwmmc_softc *, union ccb *);
@@ -1418,6 +1418,7 @@ dwmmc_write_ivar(device_t bus, device_t child, int whi
return (0);
 }
 
+#ifdef MMCCAM
 /* Note: this function likely belongs to the specific driver impl */
 static int
 dwmmc_switch_vccq(device_t dev, device_t child)
@@ -1426,7 +1427,6 @@ dwmmc_switch_vccq(device_t dev, device_t child)
return EINVAL;
 }
 
-#ifdef MMCCAM
 static void
 dwmmc_cam_handle_mmcio(struct cam_sim *sim, union ccb *ccb)
 {
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367722 - head/sys/arm64/freescale/imx

2020-11-16 Thread Emmanuel Vadot
Author: manu
Date: Mon Nov 16 11:54:38 2020
New Revision: 367722
URL: https://svnweb.freebsd.org/changeset/base/367722

Log:
  imx7gpc: Remove unused functions

Modified:
  head/sys/arm64/freescale/imx/imx7gpc.c

Modified: head/sys/arm64/freescale/imx/imx7gpc.c
==
--- head/sys/arm64/freescale/imx/imx7gpc.c  Mon Nov 16 11:53:36 2020
(r367721)
+++ head/sys/arm64/freescale/imx/imx7gpc.c  Mon Nov 16 11:54:38 2020
(r367722)
@@ -59,20 +59,6 @@ static struct ofw_compat_data compat_data[] = {
{ NULL, 0}
 };
 
-static inline uint32_t
-imx7gpc_read_4(struct imx7gpc_softc *sc, int reg)
-{
-
-   return (bus_read_4(sc->memres, reg));
-}
-
-static inline void
-imx7gpc_write_4(struct imx7gpc_softc *sc, int reg, uint32_t val)
-{
-
-bus_write_4(sc->memres, reg, val);
-}
-
 static int
 imx7gpc_activate_intr(device_t dev, struct intr_irqsrc *isrc,
 struct resource *res, struct intr_map_data *data)
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367725 - in head/sys: dev/iommu x86/iommu

2020-11-16 Thread Ruslan Bukin
Author: br
Date: Mon Nov 16 15:29:52 2020
New Revision: 367725
URL: https://svnweb.freebsd.org/changeset/base/367725

Log:
  Add device_t member to struct iommu.
  
  This is needed on arm64 for the interface between iommu framework
  and iommu controller drivers.
  
  Reviewed by:  kib
  Sponsored by: Innovate DSbD
  Differential Revision:https://reviews.freebsd.org/D27229

Modified:
  head/sys/dev/iommu/iommu.h
  head/sys/x86/iommu/intel_drv.c

Modified: head/sys/dev/iommu/iommu.h
==
--- head/sys/dev/iommu/iommu.h  Mon Nov 16 11:58:22 2020(r367724)
+++ head/sys/dev/iommu/iommu.h  Mon Nov 16 15:29:52 2020(r367725)
@@ -67,6 +67,7 @@ struct iommu_map_entry {
 
 struct iommu_unit {
struct mtx lock;
+   device_t dev;
int unit;
 
int dma_enabled;

Modified: head/sys/x86/iommu/intel_drv.c
==
--- head/sys/x86/iommu/intel_drv.c  Mon Nov 16 11:58:22 2020
(r367724)
+++ head/sys/x86/iommu/intel_drv.c  Mon Nov 16 15:29:52 2020
(r367725)
@@ -411,6 +411,7 @@ dmar_attach(device_t dev)
unit = device_get_softc(dev);
unit->dev = dev;
unit->iommu.unit = device_get_unit(dev);
+   unit->iommu.dev = dev;
dmaru = dmar_find_by_index(unit->iommu.unit);
if (dmaru == NULL)
return (EINVAL);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367726 - head/sys/dev/iommu

2020-11-16 Thread Ruslan Bukin
Author: br
Date: Mon Nov 16 15:37:09 2020
New Revision: 367726
URL: https://svnweb.freebsd.org/changeset/base/367726

Log:
  Fix a bug in assertion: entry flags also includes IOMMU_MAP_ENTRY_UNMAPPED.
  The entry->flags field is initialized in iommu_gas_init_domain().
  
  Reviewed by:  kib
  Sponsored by: Innovate DSbD
  Differential Revision:https://reviews.freebsd.org/D27235

Modified:
  head/sys/dev/iommu/iommu_gas.c

Modified: head/sys/dev/iommu/iommu_gas.c
==
--- head/sys/dev/iommu/iommu_gas.c  Mon Nov 16 15:29:52 2020
(r367725)
+++ head/sys/dev/iommu/iommu_gas.c  Mon Nov 16 15:37:09 2020
(r367726)
@@ -258,7 +258,8 @@ iommu_gas_fini_domain(struct iommu_domain *domain)
entry = RB_MIN(iommu_gas_entries_tree, &domain->rb_root);
KASSERT(entry->start == 0, ("start entry start %p", domain));
KASSERT(entry->end == IOMMU_PAGE_SIZE, ("start entry end %p", domain));
-   KASSERT(entry->flags == IOMMU_MAP_ENTRY_PLACE,
+   KASSERT(entry->flags ==
+   (IOMMU_MAP_ENTRY_PLACE | IOMMU_MAP_ENTRY_UNMAPPED),
("start entry flags %p", domain));
RB_REMOVE(iommu_gas_entries_tree, &domain->rb_root, entry);
iommu_gas_free_entry(domain, entry);
@@ -266,7 +267,8 @@ iommu_gas_fini_domain(struct iommu_domain *domain)
entry = RB_MAX(iommu_gas_entries_tree, &domain->rb_root);
KASSERT(entry->start == domain->end, ("end entry start %p", domain));
KASSERT(entry->end == domain->end, ("end entry end %p", domain));
-   KASSERT(entry->flags == IOMMU_MAP_ENTRY_PLACE,
+   KASSERT(entry->flags ==
+   (IOMMU_MAP_ENTRY_PLACE | IOMMU_MAP_ENTRY_UNMAPPED),
("end entry flags %p", domain));
RB_REMOVE(iommu_gas_entries_tree, &domain->rb_root, entry);
iommu_gas_free_entry(domain, entry);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367728 - in head: cddl/usr.bin/ztest usr.sbin/praudit

2020-11-16 Thread Brooks Davis
Author: brooks
Date: Mon Nov 16 17:20:35 2020
New Revision: 367728
URL: https://svnweb.freebsd.org/changeset/base/367728

Log:
  Add missing includes of src.opts.mk
  
  Without this "SUBDIR.${MK_TESTS}=tests" would always expand to
  "SUBDIR.=tests" resulting in the tests not being built.
  
  Sponsored by: DARPA

Modified:
  head/cddl/usr.bin/ztest/Makefile
  head/usr.sbin/praudit/Makefile

Modified: head/cddl/usr.bin/ztest/Makefile
==
--- head/cddl/usr.bin/ztest/MakefileMon Nov 16 16:53:46 2020
(r367727)
+++ head/cddl/usr.bin/ztest/MakefileMon Nov 16 17:20:35 2020
(r367728)
@@ -1,5 +1,7 @@
 # $FreeBSD$
 
+.include 
+
 ZFSTOP=${SRCTOP}/sys/contrib/openzfs
 
 .PATH: ${ZFSTOP}/cmd/ztest

Modified: head/usr.sbin/praudit/Makefile
==
--- head/usr.sbin/praudit/Makefile  Mon Nov 16 16:53:46 2020
(r367727)
+++ head/usr.sbin/praudit/Makefile  Mon Nov 16 17:20:35 2020
(r367728)
@@ -2,6 +2,8 @@
 # $FreeBSD$
 #
 
+.include 
+
 OPENBSMDIR=${SRCTOP}/contrib/openbsm
 .PATH: ${OPENBSMDIR}/bin/praudit
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367733 - head/sys/kern

2020-11-16 Thread Mateusz Guzik
Author: mjg
Date: Mon Nov 16 17:56:58 2020
New Revision: 367733
URL: https://svnweb.freebsd.org/changeset/base/367733

Log:
  malloc: make malloc_large closer to standalone
  
  This moves entire large alloc handling out of all consumers, apart from
  deciding to go there.
  
  This is a step towards creating a fast path.
  
  Reviewed by:  markj
  Differential Revision:https://reviews.freebsd.org/D27198

Modified:
  head/sys/kern/kern_malloc.c

Modified: head/sys/kern/kern_malloc.c
==
--- head/sys/kern/kern_malloc.c Mon Nov 16 17:45:42 2020(r367732)
+++ head/sys/kern/kern_malloc.c Mon Nov 16 17:56:58 2020(r367733)
@@ -110,6 +110,14 @@ dtrace_malloc_probe_func_t __read_mostly   dtrace_malloc
 #defineMALLOC_DEBUG1
 #endif
 
+#ifdef DEBUG_REDZONE
+#defineDEBUG_REDZONE_ARG_DEF   , unsigned long osize
+#defineDEBUG_REDZONE_ARG   , osize
+#else
+#defineDEBUG_REDZONE_ARG_DEF
+#defineDEBUG_REDZONE_ARG
+#endif
+
 /*
  * When realloc() is called, if the new size is sufficiently smaller than
  * the old size, realloc() will allocate a new, smaller block to avoid
@@ -574,21 +582,33 @@ malloc_large_size(uma_slab_t slab)
return (va >> 1);
 }
 
-static caddr_t
-malloc_large(size_t *size, struct domainset *policy, int flags)
+static caddr_t __noinline
+malloc_large(size_t *size, struct malloc_type *mtp, struct domainset *policy,
+int flags DEBUG_REDZONE_ARG_DEF)
 {
-   vm_offset_t va;
+   vm_offset_t kva;
+   caddr_t va;
size_t sz;
 
sz = roundup(*size, PAGE_SIZE);
-   va = kmem_malloc_domainset(policy, sz, flags);
-   if (va != 0) {
+   kva = kmem_malloc_domainset(policy, sz, flags);
+   if (kva != 0) {
/* The low bit is unused for slab pointers. */
-   vsetzoneslab(va, NULL, (void *)((sz << 1) | 1));
+   vsetzoneslab(kva, NULL, (void *)((sz << 1) | 1));
uma_total_inc(sz);
*size = sz;
}
-   return ((caddr_t)va);
+   va = (caddr_t)kva;
+   malloc_type_allocated(mtp, va == NULL ? 0 : sz);
+   if (__predict_false(va == NULL)) {
+   KASSERT((flags & M_WAITOK) == 0,
+   ("malloc(M_WAITOK) returned NULL"));
+   }
+#ifdef DEBUG_REDZONE
+   if (va != NULL)
+   va = redzone_setup(va, osize);
+#endif
+   return (va);
 }
 
 static void
@@ -613,30 +633,30 @@ void *
int indx;
caddr_t va;
uma_zone_t zone;
-#if defined(DEBUG_REDZONE)
+#ifdef DEBUG_REDZONE
unsigned long osize = size;
 #endif
 
MPASS((flags & M_EXEC) == 0);
+
 #ifdef MALLOC_DEBUG
va = NULL;
if (malloc_dbg(&va, &size, mtp, flags) != 0)
return (va);
 #endif
 
-   if (size <= kmem_zmax) {
-   if (size & KMEM_ZMASK)
-   size = (size & ~KMEM_ZMASK) + KMEM_ZBASE;
-   indx = kmemsize[size >> KMEM_ZSHIFT];
-   zone = kmemzones[indx].kz_zone[mtp_get_subzone(mtp)];
-   va = uma_zalloc(zone, flags);
-   if (va != NULL)
-   size = zone->uz_size;
-   malloc_type_zone_allocated(mtp, va == NULL ? 0 : size, indx);
-   } else {
-   va = malloc_large(&size, DOMAINSET_RR(), flags);
-   malloc_type_allocated(mtp, va == NULL ? 0 : size);
-   }
+   if (__predict_false(size > kmem_zmax))
+   return (malloc_large(&size, mtp, DOMAINSET_RR(), flags
+   DEBUG_REDZONE_ARG));
+
+   if (size & KMEM_ZMASK)
+   size = (size & ~KMEM_ZMASK) + KMEM_ZBASE;
+   indx = kmemsize[size >> KMEM_ZSHIFT];
+   zone = kmemzones[indx].kz_zone[mtp_get_subzone(mtp)];
+   va = uma_zalloc(zone, flags);
+   if (va != NULL)
+   size = zone->uz_size;
+   malloc_type_zone_allocated(mtp, va == NULL ? 0 : size, indx);
if (__predict_false(va == NULL)) {
KASSERT((flags & M_WAITOK) == 0,
("malloc(M_WAITOK) returned NULL"));
@@ -679,28 +699,27 @@ malloc_domainset(size_t size, struct malloc_type *mtp,
caddr_t va;
int domain;
int indx;
-
-#if defined(DEBUG_REDZONE)
+#ifdef DEBUG_REDZONE
unsigned long osize = size;
 #endif
+
MPASS((flags & M_EXEC) == 0);
+
 #ifdef MALLOC_DEBUG
va = NULL;
if (malloc_dbg(&va, &size, mtp, flags) != 0)
return (va);
 #endif
-   if (size <= kmem_zmax) {
-   vm_domainset_iter_policy_init(&di, ds, &domain, &flags);
-   do {
-   va = malloc_domain(&size, &indx, mtp, domain, flags);
-   } while (va == NULL &&
-   vm_domainset_iter_policy(&di, &domain) == 0);
-   malloc_type_zone_allocated(mtp, va == NULL ? 0 : size, indx);
-   } else {
-   /* Policy is h

svn commit: r367734 - head/usr.bin/bsdiff/bsdiff

2020-11-16 Thread Mitchell Horne
Author: mhorne
Date: Mon Nov 16 18:41:49 2020
New Revision: 367734
URL: https://svnweb.freebsd.org/changeset/base/367734

Log:
  bsdiff: fix off-by-one error
  
  The program reads oldsize bytes from oldfile, and proceeds to initialize
  a suffix array of oldsize elements using divsufsort(). As per the
  function's API [1], array indices 0 through n-1 are initialized.
  
  Later, search() is called, but with index bounds [0, n]. Depending on
  the contents of the malloc'd buffer, accessing this uninitialized index
  at the end of can result in a segmentation fault. Fix this by passing
  oldsize-1 to search(), limiting the search bounds to [0, n-1].
  
  This bug is a result of r303285, which introduced divsufsort() as an
  alternate suffix sorting function to the existing qsufsort(). It seems
  that qsufsort() did initialize the final empty element, meaning it could
  be safely accessed. This difference in the implementations was missed at
  the time.
  
  [1] https://github.com/y-256/libdivsufsort
  
  Discussed with:   cperciva
  MFC after:1 week
  Sponsored by: The FreeBSD Foundation
  Differential Revision:https://reviews.freebsd.org/D26911

Modified:
  head/usr.bin/bsdiff/bsdiff/bsdiff.c

Modified: head/usr.bin/bsdiff/bsdiff/bsdiff.c
==
--- head/usr.bin/bsdiff/bsdiff/bsdiff.c Mon Nov 16 17:56:58 2020
(r367733)
+++ head/usr.bin/bsdiff/bsdiff/bsdiff.c Mon Nov 16 18:41:49 2020
(r367734)
@@ -212,7 +212,7 @@ int main(int argc,char *argv[])
 
for(scsc=scan+=len;scanhttps://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367735 - head/share/mk

2020-11-16 Thread Brooks Davis
Author: brooks
Date: Mon Nov 16 19:15:11 2020
New Revision: 367735
URL: https://svnweb.freebsd.org/changeset/base/367735

Log:
  Add a guard for broken SUBDIR.${MK_FOO} use
  
  Check for the variable SUBDIR. and error as it usually means someone
  forgot to include src.opts.mk.
  
  This guard from CheriBSD found the bugs in r367655 and r367728.
  
  Reviewed by:  bdrewery, arichardson
  Obtained from:CheriBSD
  Sponsored by: DARPA
  Differential Revision:https://reviews.freebsd.org/D27211

Modified:
  head/share/mk/bsd.subdir.mk

Modified: head/share/mk/bsd.subdir.mk
==
--- head/share/mk/bsd.subdir.mk Mon Nov 16 18:41:49 2020(r367734)
+++ head/share/mk/bsd.subdir.mk Mon Nov 16 19:15:11 2020(r367735)
@@ -127,6 +127,12 @@ SUBDIR:=${SUBDIR} ${SUBDIR.yes} ${SUBDIR.yes.yes}
 SUBDIR:=${SUBDIR:u}
 .endif
 
+.if defined(SUBDIR.)
+.error ${.CURDIR}: Found variable SUBDIR. with value "${SUBDIR.}". This was \
+probably caused by using SUBDIR.$${MK_FOO} without including \
+ or by using an invalid $${MK_FOO} option.
+.endif
+
 # Subdir code shared among 'make ', 'make ' and 
SUBDIR_PARALLEL.
 _SUBDIR_SH=\
if test -d ${.CURDIR}/$${dir}.${MACHINE_ARCH}; then \
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367736 - in head/sys: arm64/include arm64/iommu conf

2020-11-16 Thread Ruslan Bukin
Author: br
Date: Mon Nov 16 21:55:52 2020
New Revision: 367736
URL: https://svnweb.freebsd.org/changeset/base/367736

Log:
  Introduce IOMMU support for arm64 platform.
  
  This adds an arm64 iommu interface and a driver for Arm System Memory
  Management Unit version 3.2 (ARM SMMU v3.2) specified in ARM IHI 0070C
  document.
  
  Hardware overview is provided in the header of smmu.c file.
  
  The support is disabled by default. To enable add 'options IOMMU' to your
  kernel configuration file.
  
  The support was developed on Arm Neoverse N1 System Development Platform
  (ARM N1SDP), kindly provided by ARM Ltd.
  
  Currently, PCI-based devices and ACPI platforms are supported only.
  The support was tested on IOMMU-enabled Marvell SATA controller,
  Realtek Ethernet controller and a TI xHCI USB controller with a low to
  medium load only.
  
  Many thanks to Konstantin Belousov for help forming the generic IOMMU
  framework that is vital for this project; to Andrew Turner for adding
  IOMMU support to MSI interrupt code; to Mark Johnston for help with SMMU
  page management; to John Baldwin for explaining various IOMMU bits.
  
  Reviewed by:  mmel
  Relnotes: yes
  Sponsored by: DARPA / AFRL
  Sponsored by: Innovate UK (Digital Security by Design programme)
  Differential Revision:https://reviews.freebsd.org/D24618

Added:
  head/sys/arm64/include/iommu.h   (contents, props changed)
  head/sys/arm64/iommu/
  head/sys/arm64/iommu/iommu.c   (contents, props changed)
  head/sys/arm64/iommu/iommu.h   (contents, props changed)
  head/sys/arm64/iommu/iommu_if.m   (contents, props changed)
  head/sys/arm64/iommu/smmu.c   (contents, props changed)
  head/sys/arm64/iommu/smmu_acpi.c   (contents, props changed)
  head/sys/arm64/iommu/smmu_quirks.c   (contents, props changed)
  head/sys/arm64/iommu/smmureg.h   (contents, props changed)
  head/sys/arm64/iommu/smmuvar.h   (contents, props changed)
Modified:
  head/sys/conf/files.arm64

Added: head/sys/arm64/include/iommu.h
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/arm64/include/iommu.h  Mon Nov 16 21:55:52 2020
(r367736)
@@ -0,0 +1,11 @@
+/*-
+ * This file is in the public domain.
+ */
+/* $FreeBSD$ */
+
+#ifndef_MACHINE_IOMMU_H_
+#define_MACHINE_IOMMU_H_
+
+#include 
+
+#endif /* !_MACHINE_IOMMU_H_ */

Added: head/sys/arm64/iommu/iommu.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/arm64/iommu/iommu.cMon Nov 16 21:55:52 2020
(r367736)
@@ -0,0 +1,397 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2020 Ruslan Bukin 
+ *
+ * This software was developed by SRI International and the University of
+ * Cambridge Computer Laboratory (Department of Computer Science and
+ * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the
+ * DARPA SSITH research programme.
+ *
+ * Portions of this work was supported by Innovate UK project 105694,
+ * "Digital Security by Design (DSbD) Technology Platform Prototype".
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "opt_platform.h"
+
+#include 
+__FBSDID("$FreeBSD$");
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "iommu.h"
+#include "iommu_if.h"
+
+static MALLOC_DEFINE(M_IOMMU, "IOMMU", "IOMMU framework");
+
+#defineIOMMU_LIST_LOCK()   mtx_lock(&iommu_mtx)
+#defineIOMMU_LIST_UNLOC

svn commit: r367737 - head/sys/kern

2020-11-16 Thread Mateusz Guzik
Author: mjg
Date: Tue Nov 17 00:04:05 2020
New Revision: 367737
URL: https://svnweb.freebsd.org/changeset/base/367737

Log:
  cpuset: refcount-clean

Modified:
  head/sys/kern/kern_cpuset.c

Modified: head/sys/kern/kern_cpuset.c
==
--- head/sys/kern/kern_cpuset.c Mon Nov 16 21:55:52 2020(r367736)
+++ head/sys/kern/kern_cpuset.c Tue Nov 17 00:04:05 2020(r367737)
@@ -1482,7 +1482,7 @@ cpuset_thread0(void)
CPU_COPY(&all_cpus, &set->cs_mask);
LIST_INIT(&set->cs_children);
LIST_INSERT_HEAD(&cpuset_ids, set, cs_link);
-   set->cs_ref = 1;
+   refcount_init(&set->cs_ref, 1);
set->cs_flags = CPU_SET_ROOT | CPU_SET_RDONLY;
set->cs_domain = &domainset0;
cpuset_zero = set;
@@ -2281,7 +2281,7 @@ DB_SHOW_COMMAND(cpusets, db_show_cpusets)
 
LIST_FOREACH(set, &cpuset_ids, cs_link) {
db_printf("set=%p id=%-6u ref=%-6d flags=0x%04x parent id=%d\n",
-   set, set->cs_id, set->cs_ref, set->cs_flags,
+   set, set->cs_id, refcount_load(&set->cs_ref), set->cs_flags,
(set->cs_parent != NULL) ? set->cs_parent->cs_id : 0);
db_printf("  cpu mask=");
ddb_display_cpuset(&set->cs_mask);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367738 - head/sys/sys

2020-11-16 Thread Mateusz Guzik
Author: mjg
Date: Tue Nov 17 00:04:30 2020
New Revision: 367738
URL: https://svnweb.freebsd.org/changeset/base/367738

Log:
  cpuset: reorder so that cs_mask does not share cacheline with cs_ref

Modified:
  head/sys/sys/cpuset.h

Modified: head/sys/sys/cpuset.h
==
--- head/sys/sys/cpuset.h   Tue Nov 17 00:04:05 2020(r367737)
+++ head/sys/sys/cpuset.h   Tue Nov 17 00:04:30 2020(r367738)
@@ -111,15 +111,15 @@ LIST_HEAD(setlist, cpuset);
  * to deal with inconsistent results.
  */
 struct cpuset {
-   cpuset_tcs_mask;/* bitmask of valid cpus. */
-   struct domainset*cs_domain; /* (c) NUMA policy. */
volatile u_int  cs_ref; /* (a) Reference count. */
int cs_flags;   /* (s) Flags from below. */
-   cpusetid_t  cs_id;  /* (s) Id or INVALID. */
-   struct cpuset   *cs_parent; /* (s) Pointer to our parent. */
LIST_ENTRY(cpuset)  cs_link;/* (c) All identified sets. */
LIST_ENTRY(cpuset)  cs_siblings;/* (c) Sibling set link. */
struct setlist  cs_children;/* (c) List of children. */
+   struct domainset*cs_domain; /* (c) NUMA policy. */
+   cpusetid_t  cs_id;  /* (s) Id or INVALID. */
+   struct cpuset   *cs_parent; /* (s) Pointer to our parent. */
+   cpuset_tcs_mask;/* bitmask of valid cpus. */
 };
 
 #define CPU_SET_ROOT0x0001  /* Set is a root set. */
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r367713 - head/sys/kern

2020-11-16 Thread Konstantin Belousov
On Mon, Nov 16, 2020 at 03:09:19AM +, Mateusz Guzik wrote:
> Author: mjg
> Date: Mon Nov 16 03:09:18 2020
> New Revision: 367713
> URL: https://svnweb.freebsd.org/changeset/base/367713
> 
> Log:
>   select: replace reference counting with memory barriers in selfd
>   
>   Refcounting was added to combat a race between selfdfree and doselwakup,
>   but it adds avoidable overhead.
>   
>   selfdfree detects it can free the object by ->sf_si == NULL, thus we can
>   ensure that the condition only holds after all accesses are completed.
> 
> Modified:
>   head/sys/kern/sys_generic.c
> 
> Modified: head/sys/kern/sys_generic.c
> ==
> --- head/sys/kern/sys_generic.c   Sun Nov 15 22:49:28 2020
> (r367712)
> +++ head/sys/kern/sys_generic.c   Mon Nov 16 03:09:18 2020
> (r367713)
> @@ -156,7 +156,6 @@ struct selfd {
>   struct mtx  *sf_mtx;/* Pointer to selinfo mtx. */
>   struct seltd*sf_td; /* (k) owning seltd. */
>   void*sf_cookie; /* (k) fd or pollfd. */
> - u_int   sf_refs;
>  };
>  
>  MALLOC_DEFINE(M_SELFD, "selfd", "selfd");
> @@ -1704,16 +1703,17 @@ static void
>  selfdfree(struct seltd *stp, struct selfd *sfp)
>  {
>   STAILQ_REMOVE(&stp->st_selq, sfp, selfd, sf_link);
> - if (sfp->sf_si != NULL) {
> + /*
> +  * Paired with doselwakeup.
> +  */
> + if (atomic_load_acq_ptr((uintptr_t *)&sfp->sf_si) != (uintptr_t)NULL) {
This could be != 0.

>   mtx_lock(sfp->sf_mtx);
>   if (sfp->sf_si != NULL) {
>   TAILQ_REMOVE(&sfp->sf_si->si_tdlist, sfp, sf_threads);
> - refcount_release(&sfp->sf_refs);
>   }
>   mtx_unlock(sfp->sf_mtx);
>   }
> - if (refcount_release(&sfp->sf_refs))
> - free(sfp, M_SELFD);
> + free(sfp, M_SELFD);
What guarantees that doselwakeup() finished with sfp ?

>  }
>  
>  /* Drain the waiters tied to all the selfd belonging the specified selinfo. 
> */
> @@ -1766,7 +1766,6 @@ selrecord(struct thread *selector, struct selinfo *sip
>*/
>   sfp->sf_si = sip;
>   sfp->sf_mtx = mtxp;
> - refcount_init(&sfp->sf_refs, 2);
>   STAILQ_INSERT_TAIL(&stp->st_selq, sfp, sf_link);
>   /*
>* Now that we've locked the sip, check for initialization.
> @@ -1820,14 +1819,15 @@ doselwakeup(struct selinfo *sip, int pri)
>* sf_si seltdclear will know to ignore this si.
>*/
>   TAILQ_REMOVE(&sip->si_tdlist, sfp, sf_threads);
> - sfp->sf_si = NULL;
>   stp = sfp->sf_td;
> + /*
> +  * Paired with selfdfree.
> +  */
> + atomic_store_rel_ptr((uintptr_t *)&sfp->sf_si, (uintptr_t)NULL);
>   mtx_lock(&stp->st_mtx);
>   stp->st_flags |= SELTD_PENDING;
>   cv_broadcastpri(&stp->st_wait, pri);
>   mtx_unlock(&stp->st_mtx);
> - if (refcount_release(&sfp->sf_refs))
> - free(sfp, M_SELFD);
>   }
>   mtx_unlock(sip->si_mtx);
>  }
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367741 - head/sys/kern

2020-11-16 Thread Konstantin Belousov
Author: kib
Date: Tue Nov 17 02:18:34 2020
New Revision: 367741
URL: https://svnweb.freebsd.org/changeset/base/367741

Log:
  vmem: trivial warning and style fixes.
  
  Add __unused to some args.
  Change type of the iterator variables to match loop control.
  Remove excessive {}.
  
  Reviewed by:  markj
  Sponsored by: The FreeBSD Foundation
  MFC after:1 week
  Differential revision:https://reviews.freebsd.org/D27220

Modified:
  head/sys/kern/subr_vmem.c

Modified: head/sys/kern/subr_vmem.c
==
--- head/sys/kern/subr_vmem.c   Tue Nov 17 01:02:00 2020(r367740)
+++ head/sys/kern/subr_vmem.c   Tue Nov 17 02:18:34 2020(r367741)
@@ -521,7 +521,7 @@ bt_insseg_tail(vmem_t *vm, bt_t *bt)
 }
 
 static void
-bt_remfree(vmem_t *vm, bt_t *bt)
+bt_remfree(vmem_t *vm __unused, bt_t *bt)
 {
 
MPASS(bt->bt_type == BT_TYPE_FREE);
@@ -734,10 +734,9 @@ static int
 vmem_rehash(vmem_t *vm, vmem_size_t newhashsize)
 {
bt_t *bt;
-   int i;
struct vmem_hashlist *newhashlist;
struct vmem_hashlist *oldhashlist;
-   vmem_size_t oldhashsize;
+   vmem_size_t i, oldhashsize;
 
MPASS(newhashsize > 0);
 
@@ -766,9 +765,8 @@ vmem_rehash(vmem_t *vm, vmem_size_t newhashsize)
}
VMEM_UNLOCK(vm);
 
-   if (oldhashlist != vm->vm_hash0) {
+   if (oldhashlist != vm->vm_hash0)
free(oldhashlist, M_VMEM);
-   }
 
return 0;
 }
@@ -1242,7 +1240,7 @@ vmem_t *
 vmem_init(vmem_t *vm, const char *name, vmem_addr_t base, vmem_size_t size,
 vmem_size_t quantum, vmem_size_t qcache_max, int flags)
 {
-   int i;
+   vmem_size_t i;
 
MPASS(quantum > 0);
MPASS((quantum & (quantum - 1)) == 0);
@@ -1483,7 +1481,7 @@ vmem_free(vmem_t *vm, vmem_addr_t addr, vmem_size_t si
 }
 
 void
-vmem_xfree(vmem_t *vm, vmem_addr_t addr, vmem_size_t size)
+vmem_xfree(vmem_t *vm, vmem_addr_t addr, vmem_size_t size __unused)
 {
bt_t *bt;
bt_t *t;
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r367713 - head/sys/kern

2020-11-16 Thread Mateusz Guzik
On 11/17/20, Konstantin Belousov  wrote:
> On Mon, Nov 16, 2020 at 03:09:19AM +, Mateusz Guzik wrote:
>> Author: mjg
>> Date: Mon Nov 16 03:09:18 2020
>> New Revision: 367713
>> URL: https://svnweb.freebsd.org/changeset/base/367713
>>
>> Log:
>>   select: replace reference counting with memory barriers in selfd
>>
>>   Refcounting was added to combat a race between selfdfree and
>> doselwakup,
>>   but it adds avoidable overhead.
>>
>>   selfdfree detects it can free the object by ->sf_si == NULL, thus we
>> can
>>   ensure that the condition only holds after all accesses are completed.
>>
>> Modified:
>>   head/sys/kern/sys_generic.c
>>
>> Modified: head/sys/kern/sys_generic.c
>> ==
>> --- head/sys/kern/sys_generic.c  Sun Nov 15 22:49:28 2020
>> (r367712)
>> +++ head/sys/kern/sys_generic.c  Mon Nov 16 03:09:18 2020
>> (r367713)
>> @@ -156,7 +156,6 @@ struct selfd {
>>  struct mtx  *sf_mtx;/* Pointer to selinfo mtx. */
>>  struct seltd*sf_td; /* (k) owning seltd. */
>>  void*sf_cookie; /* (k) fd or pollfd. */
>> -u_int   sf_refs;
>>  };
>>
>>  MALLOC_DEFINE(M_SELFD, "selfd", "selfd");
>> @@ -1704,16 +1703,17 @@ static void
>>  selfdfree(struct seltd *stp, struct selfd *sfp)
>>  {
>>  STAILQ_REMOVE(&stp->st_selq, sfp, selfd, sf_link);
>> -if (sfp->sf_si != NULL) {
>> +/*
>> + * Paired with doselwakeup.
>> + */
>> +if (atomic_load_acq_ptr((uintptr_t *)&sfp->sf_si) != (uintptr_t)NULL) {
> This could be != 0.
>
>>  mtx_lock(sfp->sf_mtx);
>>  if (sfp->sf_si != NULL) {
>>  TAILQ_REMOVE(&sfp->sf_si->si_tdlist, sfp, sf_threads);
>> -refcount_release(&sfp->sf_refs);
>>  }
>>  mtx_unlock(sfp->sf_mtx);
>>  }
>> -if (refcount_release(&sfp->sf_refs))
>> -free(sfp, M_SELFD);
>> +free(sfp, M_SELFD);
> What guarantees that doselwakeup() finished with sfp ?
>

Release semantics provided by atomic_store_rel_ptr -- it means the
NULL store is the last access, neither CPU nor the compiler are going
to reorder preceding loads/stores past it.

-- 
Mateusz Guzik 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r367713 - head/sys/kern

2020-11-16 Thread Konstantin Belousov
On Tue, Nov 17, 2020 at 04:15:12AM +0100, Mateusz Guzik wrote:
> On 11/17/20, Konstantin Belousov  wrote:
> > On Mon, Nov 16, 2020 at 03:09:19AM +, Mateusz Guzik wrote:
> >> Author: mjg
> >> Date: Mon Nov 16 03:09:18 2020
> >> New Revision: 367713
> >> URL: https://svnweb.freebsd.org/changeset/base/367713
> >>
> >> Log:
> >>   select: replace reference counting with memory barriers in selfd
> >>
> >>   Refcounting was added to combat a race between selfdfree and
> >> doselwakup,
> >>   but it adds avoidable overhead.
> >>
> >>   selfdfree detects it can free the object by ->sf_si == NULL, thus we
> >> can
> >>   ensure that the condition only holds after all accesses are completed.
> >>
> >> Modified:
> >>   head/sys/kern/sys_generic.c
> >>
> >> Modified: head/sys/kern/sys_generic.c
> >> ==
> >> --- head/sys/kern/sys_generic.cSun Nov 15 22:49:28 2020
> >> (r367712)
> >> +++ head/sys/kern/sys_generic.cMon Nov 16 03:09:18 2020
> >> (r367713)
> >> @@ -156,7 +156,6 @@ struct selfd {
> >>struct mtx  *sf_mtx;/* Pointer to selinfo mtx. */
> >>struct seltd*sf_td; /* (k) owning seltd. */
> >>void*sf_cookie; /* (k) fd or pollfd. */
> >> -  u_int   sf_refs;
> >>  };
> >>
> >>  MALLOC_DEFINE(M_SELFD, "selfd", "selfd");
> >> @@ -1704,16 +1703,17 @@ static void
> >>  selfdfree(struct seltd *stp, struct selfd *sfp)
> >>  {
> >>STAILQ_REMOVE(&stp->st_selq, sfp, selfd, sf_link);
> >> -  if (sfp->sf_si != NULL) {
> >> +  /*
> >> +   * Paired with doselwakeup.
> >> +   */
> >> +  if (atomic_load_acq_ptr((uintptr_t *)&sfp->sf_si) != (uintptr_t)NULL) {
> > This could be != 0.
> >
> >>mtx_lock(sfp->sf_mtx);
> >>if (sfp->sf_si != NULL) {
> >>TAILQ_REMOVE(&sfp->sf_si->si_tdlist, sfp, sf_threads);
> >> -  refcount_release(&sfp->sf_refs);
> >>}
> >>mtx_unlock(sfp->sf_mtx);
> >>}
> >> -  if (refcount_release(&sfp->sf_refs))
> >> -  free(sfp, M_SELFD);
> >> +  free(sfp, M_SELFD);
> > What guarantees that doselwakeup() finished with sfp ?
> >
> 
> Release semantics provided by atomic_store_rel_ptr -- it means the
> NULL store is the last access, neither CPU nor the compiler are going
> to reorder preceding loads/stores past it.
It only guarantees that if we observed NULL as the result of load.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367742 - head/lib/libc/sys

2020-11-16 Thread Kyle Evans
Author: kevans
Date: Tue Nov 17 03:26:56 2020
New Revision: 367742
URL: https://svnweb.freebsd.org/changeset/base/367742

Log:
  _umtx_op: document UMTX_OP_SEM2_WAIT copyout behavior
  
  This clever technique to get a time remaining back was added to support 
sem_clockwait_np.
  
  Reviewed by:  kib, vangyzen
  MFC after:1 week
  Differential Revision:https://reviews.freebsd.org/D27160

Modified:
  head/lib/libc/sys/_umtx_op.2

Modified: head/lib/libc/sys/_umtx_op.2
==
--- head/lib/libc/sys/_umtx_op.2Tue Nov 17 02:18:34 2020
(r367741)
+++ head/lib/libc/sys/_umtx_op.2Tue Nov 17 03:26:56 2020
(r367742)
@@ -28,7 +28,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd November 13, 2017
+.Dd November 16, 2020
 .Dt _UMTX_OP 2
 .Os
 .Sh NAME
@@ -1101,6 +1101,15 @@ The arguments to the request are:
 .It Fa obj
 Pointer to the semaphore (of type
 .Vt struct _usem2 ) .
+.It Fa uaddr
+Size of the memory passed in via the
+.Fa uaddr2
+argument.
+.It Fa uaddr2
+Optional pointer to a structure of type
+.Vt struct _umtx_time ,
+which may be followed by a structure of type
+.Vt struct timespec .
 .El
 .Pp
 Put the requesting thread onto a sleep queue if the semaphore counter
@@ -1124,6 +1133,18 @@ An unblocked signal delivered during such wait results
 interruption and
 .Er EINTR
 error.
+.Pp
+If
+.Dv UMTX_ABSTIME
+was not set, and the operation was interrupted and the caller passed in a
+.Fa uaddr2
+large enough to hold a
+.Vt struct timespec
+following the initial
+.Vt struct _umtx_time ,
+then the
+.Vt struct timespec
+is updated to contain the unslept amount.
 .It Dv UMTX_OP_SEM2_WAKE
 Wake up waiters on semaphore lock.
 The arguments to the request are:
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367743 - in head: lib/libthr/tests sys/kern

2020-11-16 Thread Kyle Evans
Author: kevans
Date: Tue Nov 17 03:34:01 2020
New Revision: 367743
URL: https://svnweb.freebsd.org/changeset/base/367743

Log:
  _umtx_op: fix a compat32 bug in UMTX_OP_NWAKE_PRIVATE
  
  Specifically, if we're waking up some value n > BATCH_SIZE, then the
  copyin(9) is wrong on the second iteration due to upp being the wrong type.
  upp is currently a uint32_t**, so upp + pos advances it by twice as many
  elements as it should (host pointer size vs. compat32 pointer size).
  
  Fix it by just making upp a uint32_t*; it's still technically a double
  pointer, but the distinction doesn't matter all that much here since we're
  just doing arithmetic on it.
  
  Add a test case that demonstrates the problem, placed with the libthr tests
  since one messing with _umtx_op should be running these tests. Running under
  compat32, the new test case will hang as threads after the first 128 get
  missed in the wake. it's not immediately clear how to hit it in practice,
  since pthread_cond_broadcast() uses a smaller (sleepq batch?) size observed
  to be around ~50 -- I did not spend much time digging into it.
  
  The uintptr_t change makes no functional difference, but i've tossed it in
  since it's more accurate (semantically).
  
  Reported by:  Andrew Gierth (andrew_tao173.riddles.org.uk, inspection)
  Reviewed by:  kib
  MFC after:1 week
  Differential Revision:https://reviews.freebsd.org/D27231

Added:
  head/lib/libthr/tests/umtx_op_test.c   (contents, props changed)
Modified:
  head/lib/libthr/tests/Makefile
  head/sys/kern/kern_umtx.c

Modified: head/lib/libthr/tests/Makefile
==
--- head/lib/libthr/tests/Makefile  Tue Nov 17 03:26:56 2020
(r367742)
+++ head/lib/libthr/tests/Makefile  Tue Nov 17 03:34:01 2020
(r367743)
@@ -35,6 +35,8 @@ NETBSD_ATF_TESTS_SH+= cancel_test
 NETBSD_ATF_TESTS_SH+=  exit_test
 NETBSD_ATF_TESTS_SH+=  resolv_test
 
+ATF_TESTS_C+=  umtx_op_test
+
 LIBADD+=   pthread
 LIBADD.fpu_test+=  m
 LIBADD.sem_test+=  rt

Added: head/lib/libthr/tests/umtx_op_test.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/lib/libthr/tests/umtx_op_test.cTue Nov 17 03:34:01 2020
(r367743)
@@ -0,0 +1,108 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2020 Kyle Evans 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include 
+__FBSDID("$FreeBSD$");
+
+#include 
+#include 
+
+#include 
+
+#include 
+
+/*
+ * This is an implementation detail of _umtx_op(2), pulled from
+ * sys/kern/kern_umtx.c.  The relevant bug observed that requests above the
+ * batch side would not function as intended, so it's important that this
+ * reflects the BATCH_SIZE configured there.
+ */
+#defineUMTX_OP_BATCH_SIZE  128
+#define THREAD_COUNT   ((UMTX_OP_BATCH_SIZE * 3) / 2)
+
+static pthread_mutex_t static_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+static int batched_waiting;
+
+static void *
+batching_threadfunc(void *arg)
+{
+
+   pthread_mutex_lock(&static_mutex);
+   ++batched_waiting;
+   pthread_mutex_unlock(&static_mutex);
+   _umtx_op(arg, UMTX_OP_WAIT_UINT_PRIVATE, 0, NULL, NULL);
+
+   return (NULL);
+}
+
+ATF_TC(batching);
+ATF_TC_HEAD(batching, tc)
+{
+   atf_tc_set_md_var(tc, "descr",
+   "Checks batching of UMTX_OP_NWAKE_PRIVATE");
+}
+ATF_TC_BODY(batching, tc)
+{
+   uintptr_t addrs[THREAD_COUNT];
+   uint32_t vals[THREAD_COUNT];
+   pthread_t threads[THREAD_COUNT];
+
+   for (int i = 0; i < THREAD_COUNT; i++) {
+   

svn commit: r367744 - in head/sys: compat/freebsd32 kern sys

2020-11-16 Thread Kyle Evans
Author: kevans
Date: Tue Nov 17 03:36:58 2020
New Revision: 367744
URL: https://svnweb.freebsd.org/changeset/base/367744

Log:
  umtx_op: reduce redundancy required for compat32
  
  All of the compat32 variants are substantially the same, save for
  copyin/copyout (mostly). Apply the same kind of technique used with kevent
  here by having the syscall routines supply a umtx_copyops describing the
  operations needed.
  
  umtx_copyops carries the bare minimum needed- size of timespec and
  _umtx_time are used for determining if copyout is needed in the sem2_wait
  case.
  
  Reviewed by:  kib
  MFC after:1 week
  Differential Revision:https://reviews.freebsd.org/D27222

Modified:
  head/sys/compat/freebsd32/freebsd32.h
  head/sys/compat/freebsd32/freebsd32_misc.c
  head/sys/kern/kern_umtx.c
  head/sys/sys/proc.h
  head/sys/sys/syscallsubr.h
  head/sys/sys/umtx.h

Modified: head/sys/compat/freebsd32/freebsd32.h
==
--- head/sys/compat/freebsd32/freebsd32.h   Tue Nov 17 03:34:01 2020
(r367743)
+++ head/sys/compat/freebsd32/freebsd32.h   Tue Nov 17 03:36:58 2020
(r367744)
@@ -94,6 +94,27 @@ struct itimerval32 {
struct timeval32 it_value;
 };
 
+struct umtx_time32 {
+   struct  timespec32  _timeout;
+   uint32_t_flags;
+   uint32_t_clockid;
+};
+
+struct umtx_robust_lists_params_compat32 {
+   uint32_trobust_list_offset;
+   uint32_trobust_priv_list_offset;
+   uint32_trobust_inact_offset;
+};
+
+struct umutex32 {
+   volatile __lwpid_t  m_owner;/* Owner of the mutex */
+   __uint32_t  m_flags;/* Flags of the mutex */
+   __uint32_t  m_ceilings[2];  /* Priority protect ceiling */
+   __uint32_t  m_rb_lnk;   /* Robust linkage */
+   __uint32_t  m_pad;
+   __uint32_t  m_spare[2];
+};
+
 #define FREEBSD4_MFSNAMELEN16
 #define FREEBSD4_MNAMELEN  (88 - 2 * sizeof(int32_t))
 

Modified: head/sys/compat/freebsd32/freebsd32_misc.c
==
--- head/sys/compat/freebsd32/freebsd32_misc.c  Tue Nov 17 03:34:01 2020
(r367743)
+++ head/sys/compat/freebsd32/freebsd32_misc.c  Tue Nov 17 03:36:58 2020
(r367744)
@@ -84,6 +84,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -3764,4 +3765,12 @@ freebsd32_sched_rr_get_interval(struct thread *td,
error = copyout(&ts32, uap->interval, sizeof(ts32));
}
return (error);
+}
+
+int
+freebsd32__umtx_op(struct thread *td, struct freebsd32__umtx_op_args *uap)
+{
+
+   return (kern__umtx_op(td, uap->obj, uap->op, uap->val, uap->uaddr,
+   uap->uaddr2, &umtx_native_ops32));
 }

Modified: head/sys/kern/kern_umtx.c
==
--- head/sys/kern/kern_umtx.c   Tue Nov 17 03:34:01 2020(r367743)
+++ head/sys/kern/kern_umtx.c   Tue Nov 17 03:36:58 2020(r367744)
@@ -219,20 +219,9 @@ struct abs_timeout {
struct timespec end;
 };
 
-#ifdef COMPAT_FREEBSD32
-struct umutex32 {
-   volatile __lwpid_t  m_owner;/* Owner of the mutex */
-   __uint32_t  m_flags;/* Flags of the mutex */
-   __uint32_t  m_ceilings[2];  /* Priority protect ceiling */
-   __uint32_t  m_rb_lnk;   /* Robust linkage */
-   __uint32_t  m_pad;
-   __uint32_t  m_spare[2];
-};
-
 _Static_assert(sizeof(struct umutex) == sizeof(struct umutex32), "umutex32");
 _Static_assert(__offsetof(struct umutex, m_spare[0]) ==
 __offsetof(struct umutex32, m_spare[0]), "m_spare32");
-#endif
 
 int umtx_shm_vnobj_persistent = 0;
 SYSCTL_INT(_kern_ipc, OID_AUTO, umtx_vnode_persistent, CTLFLAG_RWTUN,
@@ -3400,11 +3389,11 @@ do_sem2_wake(struct thread *td, struct _usem2 *sem)
 }
 
 inline int
-umtx_copyin_timeout(const void *addr, struct timespec *tsp)
+umtx_copyin_timeout(const void *uaddr, struct timespec *tsp)
 {
int error;
 
-   error = copyin(addr, tsp, sizeof(struct timespec));
+   error = copyin(uaddr, tsp, sizeof(*tsp));
if (error == 0) {
if (tsp->tv_sec < 0 ||
tsp->tv_nsec >= 10 ||
@@ -3415,16 +3404,16 @@ umtx_copyin_timeout(const void *addr, struct timespec 
 }
 
 static inline int
-umtx_copyin_umtx_time(const void *addr, size_t size, struct _umtx_time *tp)
+umtx_copyin_umtx_time(const void *uaddr, size_t size, struct _umtx_time *tp)
 {
int error;
 
-   if (size <= sizeof(struct timespec)) {
+   if (size <= sizeof(tp->_timeout)) {
tp->_clockid = CLOCK_REALTIME;
tp->_flags = 0;
-   error = copyin(addr, &tp->_timeout, sizeof

svn commit: r367745 - head/sys/sys

2020-11-16 Thread Kyle Evans
Author: kevans
Date: Tue Nov 17 04:06:35 2020
New Revision: 367745
URL: https://svnweb.freebsd.org/changeset/base/367745

Log:
  sys/proc.h: improve comment for new TDP2 flag
  
  This was suggested by kib and integrated locally, but somehow did not make
  it into the committed version.

Modified:
  head/sys/sys/proc.h

Modified: head/sys/sys/proc.h
==
--- head/sys/sys/proc.h Tue Nov 17 03:36:58 2020(r367744)
+++ head/sys/sys/proc.h Tue Nov 17 04:06:35 2020(r367745)
@@ -519,7 +519,7 @@ do {
\
 #defineTDP_SIGFASTPENDING 0x8000 /* Pending signal due to 
sigfastblock */
 
 #defineTDP2_SBPAGES0x0001 /* Owns sbusy on some pages */
-#defineTDP2_COMPAT32RB 0x0002 /* compat32 robust lists */
+#defineTDP2_COMPAT32RB 0x0002 /* compat32 ABI for robust lists */
 
 /*
  * Reasons that the current thread can not be run yet.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367746 - head/sys/kern

2020-11-16 Thread Kyle Evans
Author: kevans
Date: Tue Nov 17 04:22:10 2020
New Revision: 367746
URL: https://svnweb.freebsd.org/changeset/base/367746

Log:
  Fix !COMPAT_FREEBSD32 kernel build
  
  One of the last shifts inadvertently moved these static assertions out of a
  COMPAT_FREEBSD32 block, which the relevant definitions are limited to.
  
  Fix it.
  
  Pointy hat:   kevans

Modified:
  head/sys/kern/kern_umtx.c

Modified: head/sys/kern/kern_umtx.c
==
--- head/sys/kern/kern_umtx.c   Tue Nov 17 04:06:35 2020(r367745)
+++ head/sys/kern/kern_umtx.c   Tue Nov 17 04:22:10 2020(r367746)
@@ -219,9 +219,11 @@ struct abs_timeout {
struct timespec end;
 };
 
+#ifdef COMPAT_FREEBSD32
 _Static_assert(sizeof(struct umutex) == sizeof(struct umutex32), "umutex32");
 _Static_assert(__offsetof(struct umutex, m_spare[0]) ==
 __offsetof(struct umutex32, m_spare[0]), "m_spare32");
+#endif
 
 int umtx_shm_vnobj_persistent = 0;
 SYSCTL_INT(_kern_ipc, OID_AUTO, umtx_vnode_persistent, CTLFLAG_RWTUN,
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"