svn commit: r367410 - head/sys/opencrypto

2020-11-05 Thread John Baldwin
Author: jhb
Date: Fri Nov  6 00:15:52 2020
New Revision: 367410
URL: https://svnweb.freebsd.org/changeset/base/367410

Log:
  Move cryptof_ioctl() below the routines it calls.
  
  Reviewed by:  markj
  Sponsored by: Chelsio Communications
  Differential Revision:https://reviews.freebsd.org/D27069

Modified:
  head/sys/opencrypto/cryptodev.c

Modified: head/sys/opencrypto/cryptodev.c
==
--- head/sys/opencrypto/cryptodev.c Fri Nov  6 00:10:58 2020
(r367409)
+++ head/sys/opencrypto/cryptodev.c Fri Nov  6 00:15:52 2020
(r367410)
@@ -381,13 +381,6 @@ static struct csession *csecreate(struct fcrypt *, cry
 struct auth_hash *, void *);
 static void csefree(struct csession *);
 
-static int cryptodev_op(struct csession *, const struct crypt_op *,
-struct ucred *, struct thread *);
-static int cryptodev_aead(struct csession *, struct crypt_aead *,
-struct ucred *, struct thread *);
-static int cryptodev_key(struct crypt_kop *);
-static int cryptodev_find(struct crypt_find_op *);
-
 /*
  * Check a crypto identifier to see if it requested
  * a software device/driver.  This can be done either
@@ -713,194 +706,6 @@ bail:
return (error);
 }
 
-/* ARGSUSED */
-static int
-cryptof_ioctl(struct file *fp, u_long cmd, void *data,
-struct ucred *active_cred, struct thread *td)
-{
-   static struct timeval keywarn, featwarn;
-   struct fcrypt *fcr = fp->f_data;
-   struct csession *cse;
-   struct session2_op *sop;
-   struct crypt_op *cop;
-   struct crypt_aead *caead;
-   struct crypt_kop *kop;
-   uint32_t ses;
-   int error = 0;
-   union {
-   struct session2_op sopc;
-#ifdef COMPAT_FREEBSD32
-   struct crypt_op copc;
-   struct crypt_aead aeadc;
-   struct crypt_kop kopc;
-#endif
-   } thunk;
-#ifdef COMPAT_FREEBSD32
-   u_long cmd32;
-   void *data32;
-
-   cmd32 = 0;
-   data32 = NULL;
-   switch (cmd) {
-   case CIOCGSESSION32:
-   cmd32 = cmd;
-   data32 = data;
-   cmd = CIOCGSESSION;
-   data = 
-   session_op_from_32((struct session_op32 *)data32, );
-   break;
-   case CIOCGSESSION232:
-   cmd32 = cmd;
-   data32 = data;
-   cmd = CIOCGSESSION2;
-   data = 
-   session2_op_from_32((struct session2_op32 *)data32,
-   );
-   break;
-   case CIOCCRYPT32:
-   cmd32 = cmd;
-   data32 = data;
-   cmd = CIOCCRYPT;
-   data = 
-   crypt_op_from_32((struct crypt_op32 *)data32, );
-   break;
-   case CIOCCRYPTAEAD32:
-   cmd32 = cmd;
-   data32 = data;
-   cmd = CIOCCRYPTAEAD;
-   data = 
-   crypt_aead_from_32((struct crypt_aead32 *)data32, );
-   break;
-   case CIOCKEY32:
-   case CIOCKEY232:
-   cmd32 = cmd;
-   data32 = data;
-   if (cmd == CIOCKEY32)
-   cmd = CIOCKEY;
-   else
-   cmd = CIOCKEY2;
-   data = 
-   crypt_kop_from_32((struct crypt_kop32 *)data32, );
-   break;
-   }
-#endif
-
-   switch (cmd) {
-   case CIOCGSESSION:
-   case CIOCGSESSION2:
-   if (cmd == CIOCGSESSION) {
-   session2_op_from_op(data, );
-   sop = 
-   } else
-   sop = (struct session2_op *)data;
-
-   error = cryptodev_create_session(fcr, sop);
-   if (cmd == CIOCGSESSION && error == 0)
-   session2_op_to_op(sop, data);
-   break;
-   case CIOCFSESSION:
-   ses = *(uint32_t *)data;
-   if (!csedelete(fcr, ses)) {
-   SDT_PROBE1(opencrypto, dev, ioctl, error, __LINE__);
-   return (EINVAL);
-   }
-   break;
-   case CIOCCRYPT:
-   cop = (struct crypt_op *)data;
-   cse = csefind(fcr, cop->ses);
-   if (cse == NULL) {
-   SDT_PROBE1(opencrypto, dev, ioctl, error, __LINE__);
-   return (EINVAL);
-   }
-   error = cryptodev_op(cse, cop, active_cred, td);
-   csefree(cse);
-   break;
-   case CIOCKEY:
-   case CIOCKEY2:
-   if (ratecheck(, ))
-   gone_in(14,
-   "Asymmetric crypto operations via /dev/crypto");
-
-   if (!crypto_userasymcrypto) {
-   SDT_PROBE1(opencrypto, dev, ioctl, error, __LINE__);
-   return (EPERM); /* XXX compat? */
-   }
- 

svn commit: r367409 - head/sys/opencrypto

2020-11-05 Thread John Baldwin
Author: jhb
Date: Fri Nov  6 00:10:58 2020
New Revision: 367409
URL: https://svnweb.freebsd.org/changeset/base/367409

Log:
  Split logic to create new sessions into a separate function.
  
  This simplifies cryptof_ioctl as it now a wrapper around functions that
  contain the bulk of the per-ioctl logic.
  
  Reviewed by:  markj
  Sponsored by: Chelsio Communications
  Differential Revision:https://reviews.freebsd.org/D27068

Modified:
  head/sys/opencrypto/cryptodev.c

Modified: head/sys/opencrypto/cryptodev.c
==
--- head/sys/opencrypto/cryptodev.c Fri Nov  6 00:07:46 2020
(r367408)
+++ head/sys/opencrypto/cryptodev.c Fri Nov  6 00:10:58 2020
(r367409)
@@ -415,26 +415,318 @@ checkforsoftware(int *cridp)
return 0;
 }
 
+static int
+cryptodev_create_session(struct fcrypt *fcr, struct session2_op *sop)
+{
+   struct crypto_session_params csp;
+   struct csession *cse;
+   struct enc_xform *txform;
+   struct auth_hash *thash;
+   void *key = NULL;
+   void *mackey = NULL;
+   crypto_session_t cses;
+   int crid, error;
+
+   switch (sop->cipher) {
+   case 0:
+   txform = NULL;
+   break;
+   case CRYPTO_AES_CBC:
+   txform = _xform_rijndael128;
+   break;
+   case CRYPTO_AES_XTS:
+   txform = _xform_aes_xts;
+   break;
+   case CRYPTO_NULL_CBC:
+   txform = _xform_null;
+   break;
+   case CRYPTO_CAMELLIA_CBC:
+   txform = _xform_camellia;
+   break;
+   case CRYPTO_AES_ICM:
+   txform = _xform_aes_icm;
+   break;
+   case CRYPTO_AES_NIST_GCM_16:
+   txform = _xform_aes_nist_gcm;
+   break;
+   case CRYPTO_CHACHA20:
+   txform = _xform_chacha20;
+   break;
+   case CRYPTO_AES_CCM_16:
+   txform = _xform_ccm;
+   break;
+   default:
+   CRYPTDEB("invalid cipher");
+   SDT_PROBE1(opencrypto, dev, ioctl, error, __LINE__);
+   return (EINVAL);
+   }
+
+   switch (sop->mac) {
+   case 0:
+   thash = NULL;
+   break;
+   case CRYPTO_POLY1305:
+   thash = _hash_poly1305;
+   break;
+   case CRYPTO_SHA1_HMAC:
+   thash = _hash_hmac_sha1;
+   break;
+   case CRYPTO_SHA2_224_HMAC:
+   thash = _hash_hmac_sha2_224;
+   break;
+   case CRYPTO_SHA2_256_HMAC:
+   thash = _hash_hmac_sha2_256;
+   break;
+   case CRYPTO_SHA2_384_HMAC:
+   thash = _hash_hmac_sha2_384;
+   break;
+   case CRYPTO_SHA2_512_HMAC:
+   thash = _hash_hmac_sha2_512;
+   break;
+   case CRYPTO_RIPEMD160_HMAC:
+   thash = _hash_hmac_ripemd_160;
+   break;
+#ifdef COMPAT_FREEBSD12
+   case CRYPTO_AES_128_NIST_GMAC:
+   case CRYPTO_AES_192_NIST_GMAC:
+   case CRYPTO_AES_256_NIST_GMAC:
+   /* Should always be paired with GCM. */
+   if (sop->cipher != CRYPTO_AES_NIST_GCM_16) {
+   CRYPTDEB("GMAC without GCM");
+   SDT_PROBE1(opencrypto, dev, ioctl, error, __LINE__);
+   return (EINVAL);
+   }
+   break;
+#endif
+   case CRYPTO_AES_NIST_GMAC:
+   switch (sop->mackeylen * 8) {
+   case 128:
+   thash = _hash_nist_gmac_aes_128;
+   break;
+   case 192:
+   thash = _hash_nist_gmac_aes_192;
+   break;
+   case 256:
+   thash = _hash_nist_gmac_aes_256;
+   break;
+   default:
+   CRYPTDEB("invalid GMAC key length");
+   SDT_PROBE1(opencrypto, dev, ioctl, error, __LINE__);
+   return (EINVAL);
+   }
+   break;
+   case CRYPTO_AES_CCM_CBC_MAC:
+   switch (sop->mackeylen) {
+   case 16:
+   thash = _hash_ccm_cbc_mac_128;
+   break;
+   case 24:
+   thash = _hash_ccm_cbc_mac_192;
+   break;
+   case 32:
+   thash = _hash_ccm_cbc_mac_256;
+   break;
+   default:
+   CRYPTDEB("Invalid CBC MAC key size %d", sop->keylen);
+   SDT_PROBE1(opencrypto, dev, ioctl, error, __LINE__);
+   return (EINVAL);
+   }
+   break;
+   case CRYPTO_SHA1:
+   thash = _hash_sha1;
+   break;
+   case CRYPTO_SHA2_224:
+   thash = 

svn commit: r367407 - head/sys/opencrypto

2020-11-05 Thread John Baldwin
Author: jhb
Date: Thu Nov  5 23:42:36 2020
New Revision: 367407
URL: https://svnweb.freebsd.org/changeset/base/367407

Log:
  Move cryptodev_cb earlier before it is used.
  
  This is consistent with cryptodevkey_cb being defined before it is used
  and removes a prototype in the middle of the file.
  
  Reviewed by:  markj
  Sponsored by: Chelsio Communications
  Differential Revision:https://reviews.freebsd.org/D27067

Modified:
  head/sys/opencrypto/cryptodev.c

Modified: head/sys/opencrypto/cryptodev.c
==
--- head/sys/opencrypto/cryptodev.c Thu Nov  5 23:31:58 2020
(r367406)
+++ head/sys/opencrypto/cryptodev.c Thu Nov  5 23:42:36 2020
(r367407)
@@ -904,8 +904,6 @@ bail:
return (error);
 }
 
-static int cryptodev_cb(struct cryptop *);
-
 static struct cryptop_data *
 cod_alloc(struct csession *cse, size_t aad_len, size_t len, struct thread *td)
 {
@@ -936,6 +934,23 @@ cod_free(struct cryptop_data *cod)
 }
 
 static int
+cryptodev_cb(struct cryptop *crp)
+{
+   struct cryptop_data *cod = crp->crp_opaque;
+
+   /*
+* Lock to ensure the wakeup() is not missed by the loops
+* waiting on cod->done in cryptodev_op() and
+* cryptodev_aead().
+*/
+   mtx_lock(>cse->lock);
+   cod->done = true;
+   mtx_unlock(>cse->lock);
+   wakeup(cod);
+   return (0);
+}
+
+static int
 cryptodev_op(struct csession *cse, const struct crypt_op *cop,
 struct ucred *active_cred, struct thread *td)
 {
@@ -1338,23 +1353,6 @@ bail:
cod_free(cod);
 
return (error);
-}
-
-static int
-cryptodev_cb(struct cryptop *crp)
-{
-   struct cryptop_data *cod = crp->crp_opaque;
-
-   /*
-* Lock to ensure the wakeup() is not missed by the loops
-* waiting on cod->done in cryptodev_op() and
-* cryptodev_aead().
-*/
-   mtx_lock(>cse->lock);
-   cod->done = true;
-   mtx_unlock(>cse->lock);
-   wakeup(cod);
-   return (0);
 }
 
 static void
___
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: r367406 - head/sys/crypto/aesni

2020-11-05 Thread John Baldwin
Author: jhb
Date: Thu Nov  5 23:31:58 2020
New Revision: 367406
URL: https://svnweb.freebsd.org/changeset/base/367406

Log:
  Check cipher key lengths during probesession.
  
  OCF drivers in general should perform as many session parameter checks
  as possible during probesession rather than when creating a new
  session.  I got this wrong for aesni(4) in r359374.  In addition,
  aesni(4) was performing the check for digest-only requests and failing
  to create digest-only sessions as a result.
  
  Reported by:  jkim
  Tested by:jkim
  Sponsored by: Chelsio Communications

Modified:
  head/sys/crypto/aesni/aesni.c

Modified: head/sys/crypto/aesni/aesni.c
==
--- head/sys/crypto/aesni/aesni.c   Thu Nov  5 23:28:46 2020
(r367405)
+++ head/sys/crypto/aesni/aesni.c   Thu Nov  5 23:31:58 2020
(r367406)
@@ -237,16 +237,35 @@ aesni_cipher_supported(struct aesni_softc *sc,
switch (csp->csp_cipher_alg) {
case CRYPTO_AES_CBC:
case CRYPTO_AES_ICM:
+   switch (csp->csp_cipher_klen * 8) {
+   case 128:
+   case 192:
+   case 256:
+   break;
+   default:
+   CRYPTDEB("invalid CBC/ICM key length");
+   return (false);
+   }
if (csp->csp_ivlen != AES_BLOCK_LEN)
return (false);
-   return (sc->has_aes);
+   break;
case CRYPTO_AES_XTS:
+   switch (csp->csp_cipher_klen * 8) {
+   case 256:
+   case 512:
+   break;
+   default:
+   CRYPTDEB("invalid XTS key length");
+   return (false);
+   }
if (csp->csp_ivlen != AES_XTS_IV_LEN)
return (false);
-   return (sc->has_aes);
+   break;
default:
return (false);
}
+
+   return (true);
 }
 
 #define SUPPORTED_SES (CSP_F_SEPARATE_OUTPUT | CSP_F_SEPARATE_AAD | CSP_F_ESN)
@@ -271,6 +290,15 @@ aesni_probesession(device_t dev, const struct crypto_s
case CSP_MODE_AEAD:
switch (csp->csp_cipher_alg) {
case CRYPTO_AES_NIST_GCM_16:
+   switch (csp->csp_cipher_klen * 8) {
+   case 128:
+   case 192:
+   case 256:
+   break;
+   default:
+   CRYPTDEB("invalid GCM key length");
+   return (EINVAL);
+   }
if (csp->csp_auth_mlen != 0 &&
csp->csp_auth_mlen != GMAC_DIGEST_LEN)
return (EINVAL);
@@ -279,6 +307,15 @@ aesni_probesession(device_t dev, const struct crypto_s
return (EINVAL);
break;
case CRYPTO_AES_CCM_16:
+   switch (csp->csp_cipher_klen * 8) {
+   case 128:
+   case 192:
+   case 256:
+   break;
+   default:
+   CRYPTDEB("invalid CCM key length");
+   return (EINVAL);
+   }
if (csp->csp_auth_mlen != 0 &&
csp->csp_auth_mlen != AES_CBC_MAC_HASH_LEN)
return (EINVAL);
@@ -519,41 +556,6 @@ aesni_authprepare(struct aesni_session *ses, int klen)
 }
 
 static int
-aesni_cipherprepare(const struct crypto_session_params *csp)
-{
-
-   switch (csp->csp_cipher_alg) {
-   case CRYPTO_AES_ICM:
-   case CRYPTO_AES_NIST_GCM_16:
-   case CRYPTO_AES_CCM_16:
-   case CRYPTO_AES_CBC:
-   switch (csp->csp_cipher_klen * 8) {
-   case 128:
-   case 192:
-   case 256:
-   break;
-   default:
-   CRYPTDEB("invalid CBC/ICM/GCM key length");
-   return (EINVAL);
-   }
-   break;
-   case CRYPTO_AES_XTS:
-   switch (csp->csp_cipher_klen * 8) {
-   case 256:
-   case 512:
-   break;
-   default:
-   CRYPTDEB("invalid XTS key length");
-   return (EINVAL);
-   }
-   break;
-   default:
-   return (EINVAL);
-   }
-   return (0);
-}
-
-static int
 aesni_cipher_setup(struct aesni_session *ses,
 const struct crypto_session_params *csp)
 {
@@ -600,10 +602,6 @@ aesni_cipher_setup(struct aesni_session *ses,
if (error != 0)
return (error);

svn commit: r367404 - head/sys/opencrypto

2020-11-05 Thread John Baldwin
Author: jhb
Date: Thu Nov  5 23:28:05 2020
New Revision: 367404
URL: https://svnweb.freebsd.org/changeset/base/367404

Log:
  Style fixes for function prototypes and definitions.
  
  Reviewed by:  markj
  Sponsored by: Chelsio Communications
  Differential Revision:https://reviews.freebsd.org/D27066

Modified:
  head/sys/opencrypto/crypto.c
  head/sys/opencrypto/cryptodev.c

Modified: head/sys/opencrypto/crypto.c
==
--- head/sys/opencrypto/crypto.cThu Nov  5 23:26:02 2020
(r367403)
+++ head/sys/opencrypto/crypto.cThu Nov  5 23:28:05 2020
(r367404)
@@ -286,7 +286,9 @@ keybuf_init(void)
 }
 
 /* It'd be nice if we could store these in some kind of secure memory... */
-struct keybuf * get_keybuf(void) {
+struct keybuf *
+get_keybuf(void)
+{
 
 return (keybuf);
 }

Modified: head/sys/opencrypto/cryptodev.c
==
--- head/sys/opencrypto/cryptodev.c Thu Nov  5 23:26:02 2020
(r367403)
+++ head/sys/opencrypto/cryptodev.c Thu Nov  5 23:28:05 2020
(r367404)
@@ -351,13 +351,13 @@ SYSCTL_TIMEVAL_SEC(_kern, OID_AUTO, cryptodev_warn_int
 ,
 "Delay in seconds between warnings of deprecated /dev/crypto algorithms");
 
-static int cryptof_ioctl(struct file *, u_long, void *,
-   struct ucred *, struct thread *);
-static int cryptof_stat(struct file *, struct stat *,
-   struct ucred *, struct thread *);
-static int cryptof_close(struct file *, struct thread *);
-static int cryptof_fill_kinfo(struct file *, struct kinfo_file *,
-   struct filedesc *);
+static int cryptof_ioctl(struct file *, u_long, void *, struct ucred *,
+struct thread *);
+static int cryptof_stat(struct file *, struct stat *, struct ucred *,
+struct thread *);
+static int cryptof_close(struct file *, struct thread *);
+static int cryptof_fill_kinfo(struct file *, struct kinfo_file *,
+struct filedesc *);
 
 static struct fileops cryptofops = {
 .fo_read = invfo_rdwr,
@@ -381,12 +381,12 @@ static struct csession *csecreate(struct fcrypt *, cry
 struct auth_hash *, void *);
 static void csefree(struct csession *);
 
-static int cryptodev_op(struct csession *, const struct crypt_op *,
-   struct ucred *, struct thread *td);
-static int cryptodev_aead(struct csession *, struct crypt_aead *,
-   struct ucred *, struct thread *);
-static int cryptodev_key(struct crypt_kop *);
-static int cryptodev_find(struct crypt_find_op *);
+static int cryptodev_op(struct csession *, const struct crypt_op *,
+struct ucred *, struct thread *);
+static int cryptodev_aead(struct csession *, struct crypt_aead *,
+struct ucred *, struct thread *);
+static int cryptodev_key(struct crypt_kop *);
+static int cryptodev_find(struct crypt_find_op *);
 
 /*
  * Check a crypto identifier to see if it requested
@@ -417,12 +417,8 @@ checkforsoftware(int *cridp)
 
 /* ARGSUSED */
 static int
-cryptof_ioctl(
-   struct file *fp,
-   u_long cmd,
-   void *data,
-   struct ucred *active_cred,
-   struct thread *td)
+cryptof_ioctl(struct file *fp, u_long cmd, void *data,
+struct ucred *active_cred, struct thread *td)
 {
static struct timeval keywarn, featwarn;
struct crypto_session_params csp;
@@ -940,11 +936,8 @@ cod_free(struct cryptop_data *cod)
 }
 
 static int
-cryptodev_op(
-   struct csession *cse,
-   const struct crypt_op *cop,
-   struct ucred *active_cred,
-   struct thread *td)
+cryptodev_op(struct csession *cse, const struct crypt_op *cop,
+struct ucred *active_cred, struct thread *td)
 {
struct cryptop_data *cod = NULL;
struct cryptop *crp = NULL;
@@ -1154,11 +1147,8 @@ bail:
 }
 
 static int
-cryptodev_aead(
-   struct csession *cse,
-   struct crypt_aead *caead,
-   struct ucred *active_cred,
-   struct thread *td)
+cryptodev_aead(struct csession *cse, struct crypt_aead *caead,
+struct ucred *active_cred, struct thread *td)
 {
struct cryptop_data *cod = NULL;
struct cryptop *crp = NULL;
@@ -1515,11 +1505,8 @@ cryptodev_find(struct crypt_find_op *find)
 
 /* ARGSUSED */
 static int
-cryptof_stat(
-   struct file *fp,
-   struct stat *sb,
-   struct ucred *active_cred,
-   struct thread *td)
+cryptof_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
+struct thread *td)
 {
 
return (EOPNOTSUPP);
@@ -1545,7 +1532,8 @@ cryptof_close(struct file *fp, struct thread *td)
 }
 
 static int
-cryptof_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc 
*fdp)
+cryptof_fill_kinfo(struct file *fp, struct kinfo_file *kif,
+struct filedesc *fdp)
 {
 
kif->kf_type = KF_TYPE_CRYPTO;
@@ -1634,7 +1622,8 @@ csefree(struct csession *cse)
 }
 
 static int
-cryptoioctl(struct cdev 

svn commit: r367403 - head/sys/opencrypto

2020-11-05 Thread John Baldwin
Author: jhb
Date: Thu Nov  5 23:26:02 2020
New Revision: 367403
URL: https://svnweb.freebsd.org/changeset/base/367403

Log:
  Don't modify the destination pointer in ioctl requests.
  
  This breaks the case where the original pointer was NULL but an
  in-line IV was used.
  
  Reviewed by:  markj
  Sponsored by: Chelsio Communications
  Differential Revision:https://reviews.freebsd.org/D27064

Modified:
  head/sys/opencrypto/cryptodev.c

Modified: head/sys/opencrypto/cryptodev.c
==
--- head/sys/opencrypto/cryptodev.c Thu Nov  5 22:41:54 2020
(r367402)
+++ head/sys/opencrypto/cryptodev.c Thu Nov  5 23:26:02 2020
(r367403)
@@ -381,7 +381,7 @@ static struct csession *csecreate(struct fcrypt *, cry
 struct auth_hash *, void *);
 static void csefree(struct csession *);
 
-static int cryptodev_op(struct csession *, struct crypt_op *,
+static int cryptodev_op(struct csession *, const struct crypt_op *,
struct ucred *, struct thread *td);
 static int cryptodev_aead(struct csession *, struct crypt_aead *,
struct ucred *, struct thread *);
@@ -942,12 +942,13 @@ cod_free(struct cryptop_data *cod)
 static int
 cryptodev_op(
struct csession *cse,
-   struct crypt_op *cop,
+   const struct crypt_op *cop,
struct ucred *active_cred,
struct thread *td)
 {
struct cryptop_data *cod = NULL;
struct cryptop *crp = NULL;
+   char *dst;
int error;
 
if (cop->len > 256*1024-4) {
@@ -980,6 +981,7 @@ cryptodev_op(
}
 
cod = cod_alloc(cse, 0, cop->len + cse->hashsize, td);
+   dst = cop->dst;
 
crp = crypto_getreq(cse->cses, M_WAITOK);
 
@@ -1082,7 +1084,7 @@ cryptodev_op(
crp->crp_iv_start = 0;
crp->crp_payload_start += cse->ivsize;
crp->crp_payload_length -= cse->ivsize;
-   cop->dst += cse->ivsize;
+   dst += cse->ivsize;
}
 
if (cop->mac != NULL && crp->crp_op & CRYPTO_OP_VERIFY_DIGEST) {
@@ -1127,7 +1129,7 @@ again:
 
if (cop->dst != NULL) {
error = copyout(cod->obuf != NULL ? cod->obuf :
-   cod->buf + crp->crp_payload_start, cop->dst,
+   cod->buf + crp->crp_payload_start, dst,
crp->crp_payload_length);
if (error) {
SDT_PROBE1(opencrypto, dev, ioctl, error, __LINE__);
@@ -1160,6 +1162,7 @@ cryptodev_aead(
 {
struct cryptop_data *cod = NULL;
struct cryptop *crp = NULL;
+   char *dst;
int error;
 
if (caead->len > 256*1024-4 || caead->aadlen > 256*1024-4) {
@@ -1186,6 +1189,7 @@ cryptodev_aead(
}
 
cod = cod_alloc(cse, caead->aadlen, caead->len + cse->hashsize, td);
+   dst = caead->dst;
 
crp = crypto_getreq(cse->cses, M_WAITOK);
 
@@ -1277,7 +1281,7 @@ cryptodev_aead(
crp->crp_iv_start = crp->crp_payload_start;
crp->crp_payload_start += cse->ivsize;
crp->crp_payload_length -= cse->ivsize;
-   caead->dst += cse->ivsize;
+   dst += cse->ivsize;
}
 
if (crp->crp_op & CRYPTO_OP_VERIFY_DIGEST) {
@@ -1322,7 +1326,7 @@ again:
 
if (caead->dst != NULL) {
error = copyout(cod->obuf != NULL ? cod->obuf :
-   cod->buf + crp->crp_payload_start, caead->dst,
+   cod->buf + crp->crp_payload_start, dst,
crp->crp_payload_length);
if (error) {
SDT_PROBE1(opencrypto, dev, ioctl, error, __LINE__);
___
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: r367400 - head/sys/dev/nvme

2020-11-05 Thread Mateusz Guzik
Author: mjg
Date: Thu Nov  5 21:44:58 2020
New Revision: 367400
URL: https://svnweb.freebsd.org/changeset/base/367400

Log:
  nvme: change namei_request_zone into a malloc type
  
  Both the size (128 bytes) and ephemeral nature of allocations make it a great
  fit for malloc.
  
  A dedicated zone unnecessarily avoids sharing buckets with 128-byte objects.
  
  Reviewed by:  imp
  Differential Revision:https://reviews.freebsd.org/D27103

Modified:
  head/sys/dev/nvme/nvme.c
  head/sys/dev/nvme/nvme_private.h

Modified: head/sys/dev/nvme/nvme.c
==
--- head/sys/dev/nvme/nvme.cThu Nov  5 21:37:24 2020(r367399)
+++ head/sys/dev/nvme/nvme.cThu Nov  5 21:44:58 2020(r367400)
@@ -49,7 +49,6 @@ struct nvme_consumer {
 struct nvme_consumer nvme_consumer[NVME_MAX_CONSUMERS];
 #defineINVALID_CONSUMER_ID 0x
 
-uma_zone_t nvme_request_zone;
 int32_tnvme_retry_count;
 
 MALLOC_DEFINE(M_NVME, "nvme", "nvme(4) memory allocations");
@@ -61,9 +60,6 @@ nvme_init(void)
 {
uint32_ti;
 
-   nvme_request_zone = uma_zcreate("nvme_request",
-   sizeof(struct nvme_request), NULL, NULL, NULL, NULL, 0, 0);
-
for (i = 0; i < NVME_MAX_CONSUMERS; i++)
nvme_consumer[i].id = INVALID_CONSUMER_ID;
 }
@@ -73,7 +69,6 @@ SYSINIT(nvme_register, SI_SUB_DRIVERS, SI_ORDER_SECOND
 static void
 nvme_uninit(void)
 {
-   uma_zdestroy(nvme_request_zone);
 }
 
 SYSUNINIT(nvme_unregister, SI_SUB_DRIVERS, SI_ORDER_SECOND, nvme_uninit, NULL);

Modified: head/sys/dev/nvme/nvme_private.h
==
--- head/sys/dev/nvme/nvme_private.hThu Nov  5 21:37:24 2020
(r367399)
+++ head/sys/dev/nvme/nvme_private.hThu Nov  5 21:44:58 2020
(r367400)
@@ -113,7 +113,6 @@ MALLOC_DECLARE(M_NVME);
 #define CACHE_LINE_SIZE(64)
 #endif
 
-extern uma_zone_t  nvme_request_zone;
 extern int32_t nvme_retry_count;
 extern boolnvme_verbose_cmd_dump;
 
@@ -489,7 +488,7 @@ _nvme_allocate_request(nvme_cb_fn_t cb_fn, void *cb_ar
 {
struct nvme_request *req;
 
-   req = uma_zalloc(nvme_request_zone, M_NOWAIT | M_ZERO);
+   req = malloc(sizeof(*req), M_NVME, M_NOWAIT | M_ZERO);
if (req != NULL) {
req->cb_fn = cb_fn;
req->cb_arg = cb_arg;
@@ -551,7 +550,7 @@ nvme_allocate_request_ccb(union ccb *ccb, nvme_cb_fn_t
return (req);
 }
 
-#define nvme_free_request(req) uma_zfree(nvme_request_zone, req)
+#define nvme_free_request(req) free(req, M_NVME)
 
 void   nvme_notify_async_consumers(struct nvme_controller *ctrlr,
const struct nvme_completion *async_cpl,
___
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: r367399 - head/contrib/bsnmp/snmpd

2020-11-05 Thread Enji Cooper
Author: ngie
Date: Thu Nov  5 21:37:24 2020
New Revision: 367399
URL: https://svnweb.freebsd.org/changeset/base/367399

Log:
  snmpmod(3): fix typo under the COMMUNITIES section
  
  "recipte" should be spelled like "receipt".
  
  .Dd is intentionally not being bumped for the change.
  
  MFC after:1 week
  Sponsored by: DellEMC

Modified:
  head/contrib/bsnmp/snmpd/snmpmod.3

Modified: head/contrib/bsnmp/snmpd/snmpmod.3
==
--- head/contrib/bsnmp/snmpd/snmpmod.3  Thu Nov  5 20:52:49 2020
(r367398)
+++ head/contrib/bsnmp/snmpd/snmpmod.3  Thu Nov  5 21:37:24 2020
(r367399)
@@ -577,7 +577,7 @@ struct systemg {
 .Ed
 .Ss COMMUNITIES
 The SNMP daemon implements a community table.
-On recipte of a request message
+On receipt of a request message
 the community string in that message is compared to each of the community
 strings in that table, if a match is found, the global variable
 .Va community
___
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: r367398 - in head/sys: dev/acpica dev/xen/control kern sys

2020-11-05 Thread Konstantin Belousov
Author: kib
Date: Thu Nov  5 20:52:49 2020
New Revision: 367398
URL: https://svnweb.freebsd.org/changeset/base/367398

Log:
  Suspend all writeable local filesystems on power suspend.
  
  This ensures that no writes are pending in memory, either metadata or
  user data, but not including dirty pages not yet converted to fs writes.
  
  Only filesystems declared local are suspended.
  
  Note that this does not guarantee absence of the metadata errors or
  leaks if resume is not done: for instance, on UFS unlinked but opened
  inodes are leaked and require fsck to gc.
  
  Reviewed by:  markj
  Discussed with:   imp
  Tested by:imp (previous version), pho
  Sponsored by: The FreeBSD Foundation
  MFC after:2 weeks
  Differential revision:https://reviews.freebsd.org/D27054

Modified:
  head/sys/dev/acpica/acpi.c
  head/sys/dev/xen/control/control.c
  head/sys/kern/vfs_mount.c
  head/sys/sys/mount.h

Modified: head/sys/dev/acpica/acpi.c
==
--- head/sys/dev/acpica/acpi.c  Thu Nov  5 20:18:00 2020(r367397)
+++ head/sys/dev/acpica/acpi.c  Thu Nov  5 20:52:49 2020(r367398)
@@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -3081,6 +3082,7 @@ acpi_EnterSleepState(struct acpi_softc *sc, int state)
 
 EVENTHANDLER_INVOKE(power_suspend_early);
 stop_all_proc();
+suspend_all_fs();
 EVENTHANDLER_INVOKE(power_suspend);
 
 #ifdef EARLY_AP_STARTUP
@@ -3240,6 +3242,7 @@ backout:
 }
 #endif
 
+resume_all_fs();
 resume_all_proc();
 
 EVENTHANDLER_INVOKE(power_resume);

Modified: head/sys/dev/xen/control/control.c
==
--- head/sys/dev/xen/control/control.c  Thu Nov  5 20:18:00 2020
(r367397)
+++ head/sys/dev/xen/control/control.c  Thu Nov  5 20:52:49 2020
(r367398)
@@ -113,6 +113,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -204,6 +205,7 @@ xctrl_suspend()
xs_lock();
stop_all_proc();
xs_unlock();
+   suspend_all_fs();
EVENTHANDLER_INVOKE(power_suspend);
 
 #ifdef EARLY_AP_STARTUP
@@ -317,6 +319,7 @@ xctrl_suspend()
}
 #endif
 
+   resume_all_fs();
resume_all_proc();
 
EVENTHANDLER_INVOKE(power_resume);

Modified: head/sys/kern/vfs_mount.c
==
--- head/sys/kern/vfs_mount.c   Thu Nov  5 20:18:00 2020(r367397)
+++ head/sys/kern/vfs_mount.c   Thu Nov  5 20:52:49 2020(r367398)
@@ -2507,3 +2507,67 @@ mount_devctl_event(const char *type, struct mount *mp,
sbuf_delete();
free(buf, M_MOUNT);
 }
+
+/*
+ * Suspend write operations on all local writeable filesystems.  Does
+ * full sync of them in the process.
+ *
+ * Iterate over the mount points in reverse order, suspending most
+ * recently mounted filesystems first.  It handles a case where a
+ * filesystem mounted from a md(4) vnode-backed device should be
+ * suspended before the filesystem that owns the vnode.
+ */
+void
+suspend_all_fs(void)
+{
+   struct mount *mp;
+   int error;
+
+   mtx_lock(_mtx);
+   TAILQ_FOREACH_REVERSE(mp, , mntlist, mnt_list) {
+   error = vfs_busy(mp, MBF_MNTLSTLOCK | MBF_NOWAIT);
+   if (error != 0)
+   continue;
+   if ((mp->mnt_flag & (MNT_RDONLY | MNT_LOCAL)) != MNT_LOCAL ||
+   (mp->mnt_kern_flag & MNTK_SUSPEND) != 0) {
+   mtx_lock(_mtx);
+   vfs_unbusy(mp);
+   continue;
+   }
+   error = vfs_write_suspend(mp, 0);
+   if (error == 0) {
+   MNT_ILOCK(mp);
+   MPASS((mp->mnt_kern_flag & MNTK_SUSPEND_ALL) == 0);
+   mp->mnt_kern_flag |= MNTK_SUSPEND_ALL;
+   MNT_IUNLOCK(mp);
+   mtx_lock(_mtx);
+   } else {
+   printf("suspend of %s failed, error %d\n",
+   mp->mnt_stat.f_mntonname, error);
+   mtx_lock(_mtx);
+   vfs_unbusy(mp);
+   }
+   }
+   mtx_unlock(_mtx);
+}
+
+void
+resume_all_fs(void)
+{
+   struct mount *mp;
+
+   mtx_lock(_mtx);
+   TAILQ_FOREACH(mp, , mnt_list) {
+   if ((mp->mnt_kern_flag & MNTK_SUSPEND_ALL) == 0)
+   continue;
+   mtx_unlock(_mtx);
+   MNT_ILOCK(mp);
+   MPASS((mp->mnt_kern_flag & MNTK_SUSPEND) != 0);
+   mp->mnt_kern_flag &= ~MNTK_SUSPEND_ALL;
+   MNT_IUNLOCK(mp);
+   vfs_write_resume(mp, 0);
+   mtx_lock(_mtx);
+   vfs_unbusy(mp);
+   }
+   

svn commit: r367397 - head/sys/powerpc/include

2020-11-05 Thread Leandro Lupori
Author: luporl
Date: Thu Nov  5 20:18:00 2020
New Revision: 367397
URL: https://svnweb.freebsd.org/changeset/base/367397

Log:
  Fix powerpc and powerpcspe builds
  
  This change fixes 32-bit PowerPC builds, that r367390 broke
  (shift count >= width of type).

Modified:
  head/sys/powerpc/include/spr.h

Modified: head/sys/powerpc/include/spr.h
==
--- head/sys/powerpc/include/spr.h  Thu Nov  5 19:37:56 2020
(r367396)
+++ head/sys/powerpc/include/spr.h  Thu Nov  5 20:18:00 2020
(r367397)
@@ -492,13 +492,13 @@
 
 #defineSPR_MMCR2   0x311
 #define  SPR_MMCR2_CNBIT(n, bit) ((bit) << (((5 - (n)) * 9) + 10))
-#define  SPR_MMCR2_FCNS(n)   SPR_MMCR2_CNBIT(n, 0x100UL)
-#define  SPR_MMCR2_FCNP0(n)  SPR_MMCR2_CNBIT(n, 0x080UL)
-#define  SPR_MMCR2_FCNP1(n)  SPR_MMCR2_CNBIT(n, 0x040UL)
-#define  SPR_MMCR2_FCNM1(n)  SPR_MMCR2_CNBIT(n, 0x020UL)
-#define  SPR_MMCR2_FCNM0(n)  SPR_MMCR2_CNBIT(n, 0x010UL)
-#define  SPR_MMCR2_FCNWAIT(n)SPR_MMCR2_CNBIT(n, 0x008UL)
-#define  SPR_MMCR2_FCNH(n)   SPR_MMCR2_CNBIT(n, 0x004UL)
+#define  SPR_MMCR2_FCNS(n)   SPR_MMCR2_CNBIT(n, 0x100ULL)
+#define  SPR_MMCR2_FCNP0(n)  SPR_MMCR2_CNBIT(n, 0x080ULL)
+#define  SPR_MMCR2_FCNP1(n)  SPR_MMCR2_CNBIT(n, 0x040ULL)
+#define  SPR_MMCR2_FCNM1(n)  SPR_MMCR2_CNBIT(n, 0x020ULL)
+#define  SPR_MMCR2_FCNM0(n)  SPR_MMCR2_CNBIT(n, 0x010ULL)
+#define  SPR_MMCR2_FCNWAIT(n)SPR_MMCR2_CNBIT(n, 0x008ULL)
+#define  SPR_MMCR2_FCNH(n)   SPR_MMCR2_CNBIT(n, 0x004ULL)
 /* Freeze Counter N in Hypervisor/Supervisor/Problem states */
 #define  SPR_MMCR2_FCNHSP(n)   \
(SPR_MMCR2_FCNS(n) | SPR_MMCR2_FCNP0(n) |   \
___
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: r367395 - in head/sys: amd64/linux amd64/linux32 arm64/linux compat/linux conf i386/linux modules/linux modules/linux64 modules/linux_common x86/linux

2020-11-05 Thread Conrad Meyer
Author: cem
Date: Thu Nov  5 19:30:31 2020
New Revision: 367395
URL: https://svnweb.freebsd.org/changeset/base/367395

Log:
  linux(4): Deduplicate unimpl/dummy syscall handlers
  
  No functional change.
  
  Reviewed by:  emaste, trasz
  Differential Revision:https://reviews.freebsd.org/D27099

Added:
  head/sys/amd64/linux/linux_dummy_machdep.c
 - copied, changed from r367394, head/sys/amd64/linux/linux_dummy.c
  head/sys/arm64/linux/linux_dummy_machdep.c
 - copied, changed from r367394, head/sys/arm64/linux/linux_dummy.c
  head/sys/compat/linux/linux_dummy.c
 - copied, changed from r367393, head/sys/arm64/linux/linux_dummy.c
  head/sys/i386/linux/linux_dummy_machdep.c
 - copied, changed from r367394, head/sys/i386/linux/linux_dummy.c
  head/sys/x86/linux/
  head/sys/x86/linux/linux_dummy_x86.c   (contents, props changed)
 - copied, changed from r367393, head/sys/amd64/linux/linux_dummy.c
Deleted:
  head/sys/amd64/linux/linux_dummy.c
  head/sys/arm64/linux/linux_dummy.c
  head/sys/i386/linux/linux_dummy.c
Modified:
  head/sys/amd64/linux32/linux32_dummy.c
  head/sys/conf/files.amd64
  head/sys/conf/files.i386
  head/sys/modules/linux/Makefile
  head/sys/modules/linux64/Makefile
  head/sys/modules/linux_common/Makefile

Copied and modified: head/sys/amd64/linux/linux_dummy_machdep.c (from r367394, 
head/sys/amd64/linux/linux_dummy.c)
==
--- head/sys/amd64/linux/linux_dummy.c  Thu Nov  5 18:10:03 2020
(r367394, copy source)
+++ head/sys/amd64/linux/linux_dummy_machdep.c  Thu Nov  5 19:30:31 2020
(r367395)
@@ -43,146 +43,32 @@ __FBSDID("$FreeBSD$");
 /* DTrace init */
 LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE);
 
-UNIMPLEMENTED(afs_syscall);
-UNIMPLEMENTED(create_module);  /* Added in Linux 1.0 removed in 2.6. */
-UNIMPLEMENTED(epoll_ctl_old);
-UNIMPLEMENTED(epoll_wait_old);
-UNIMPLEMENTED(get_kernel_syms);/* Added in Linux 1.0 removed in 2.6. */
+/*
+ * Before adding new stubs to this file, please check if a stub can be added to
+ * the machine-independent code in sys/compat/linux/linux_dummy.c (or
+ * sys/x86/linux/linux_dummy_x86.c).
+ */
+
 UNIMPLEMENTED(get_thread_area);
-UNIMPLEMENTED(getpmsg);
-UNIMPLEMENTED(nfsservctl); /* Added in Linux 2.2 removed in 3.1. */
-UNIMPLEMENTED(putpmsg);
-UNIMPLEMENTED(query_module);   /* Added in Linux 2.2 removed in 2.6. */
-UNIMPLEMENTED(tuxcall);
-UNIMPLEMENTED(security);
 UNIMPLEMENTED(set_thread_area);
 UNIMPLEMENTED(uselib);
-UNIMPLEMENTED(vserver);
 
-DUMMY(setfsuid);
-DUMMY(setfsgid);
-DUMMY(sysfs);
-DUMMY(vhangup);
 DUMMY(modify_ldt);
-DUMMY(pivot_root);
-DUMMY(adjtimex);
-DUMMY(swapoff);
-DUMMY(init_module);
+
 DUMMY(ioperm);
-DUMMY(delete_module);
-DUMMY(quotactl);
-DUMMY(readahead);
 DUMMY(io_setup);
 DUMMY(io_destroy);
 DUMMY(io_getevents);
 DUMMY(io_submit);
 DUMMY(io_cancel);
-DUMMY(lookup_dcookie);
-DUMMY(remap_file_pages);
-DUMMY(restart_syscall);
-DUMMY(semtimedop);
-DUMMY(mbind);
-DUMMY(get_mempolicy);
-DUMMY(set_mempolicy);
 DUMMY(mq_open);
 DUMMY(mq_unlink);
 DUMMY(mq_timedsend);
 DUMMY(mq_timedreceive);
 DUMMY(mq_notify);
 DUMMY(mq_getsetattr);
-DUMMY(kexec_load);
-/* Linux 2.6.11: */
-DUMMY(add_key);
-DUMMY(request_key);
-DUMMY(keyctl);
-/* Linux 2.6.13: */
-DUMMY(ioprio_set);
-DUMMY(ioprio_get);
-DUMMY(inotify_init);
-DUMMY(inotify_add_watch);
-DUMMY(inotify_rm_watch);
-/* Linux 2.6.16: */
-DUMMY(migrate_pages);
-DUMMY(unshare);
-/* Linux 2.6.17: */
-DUMMY(tee);
-DUMMY(vmsplice);
-/* Linux 2.6.18: */
-DUMMY(move_pages);
-/* Linux 2.6.22: */
-DUMMY(signalfd);
-/* Linux 2.6.27: */
-DUMMY(signalfd4);
-DUMMY(inotify_init1);
-/* Linux 2.6.31: */
-DUMMY(perf_event_open);
-/* Linux 2.6.36: */
-DUMMY(fanotify_init);
-DUMMY(fanotify_mark);
-/* Linux 2.6.39: */
-DUMMY(name_to_handle_at);
-DUMMY(open_by_handle_at);
-DUMMY(clock_adjtime);
-/* Linux 3.0: */
-DUMMY(setns);
-/* Linux 3.2: */
-DUMMY(process_vm_readv);
-DUMMY(process_vm_writev);
-/* Linux 3.5: */
-DUMMY(kcmp);
-/* Linux 3.8: */
-DUMMY(finit_module);
-DUMMY(sched_setattr);
-DUMMY(sched_getattr);
+DUMMY(readahead);
+DUMMY(restart_syscall);
+DUMMY(semtimedop);
 /* Linux 3.15: */
 DUMMY(kexec_file_load);
-/* Linux 3.17: */
-DUMMY(seccomp);
-/* Linux 3.18: */
-DUMMY(bpf);
-/* Linux 3.19: */
-DUMMY(execveat);
-/* Linux 4.2: */
-DUMMY(userfaultfd);
-/* Linux 4.3: */
-DUMMY(membarrier);
-/* Linux 4.4: */
-DUMMY(mlock2);
-/* Linux 4.6: */
-DUMMY(preadv2);
-DUMMY(pwritev2);
-/* Linux 4.8: */
-DUMMY(pkey_mprotect);
-DUMMY(pkey_alloc);
-DUMMY(pkey_free);
-/* Linux 4.11: */
-DUMMY(statx);
-/* Linux 4.18: */
-DUMMY(io_pgetevents);
-DUMMY(rseq);
-/* Linux 5.0: */
-DUMMY(pidfd_send_signal);
-DUMMY(io_uring_setup);
-DUMMY(io_uring_enter);
-DUMMY(io_uring_register);
-
-#define DUMMY_XATTR(s) \
-int\
-linux_ ## s ## xattr(  \
-struct thread 

svn commit: r367394 - in head/sys/arm: arm include

2020-11-05 Thread Edward Tomasz Napierala
Author: trasz
Date: Thu Nov  5 18:10:03 2020
New Revision: 367394
URL: https://svnweb.freebsd.org/changeset/base/367394

Log:
  Remove the 'nap' field from ARM's 'struct syscall_args', to bring it
  in sync with (most) other architectures.  No functional changes.
  
  Reviewed by:  manu
  Tested by:mmel
  MFC after:2 weeks
  Sponsored by: EPSRC
  Differential Revision:https://reviews.freebsd.org/D26604

Modified:
  head/sys/arm/arm/syscall.c
  head/sys/arm/include/proc.h

Modified: head/sys/arm/arm/syscall.c
==
--- head/sys/arm/arm/syscall.c  Thu Nov  5 17:10:14 2020(r367393)
+++ head/sys/arm/arm/syscall.c  Thu Nov  5 18:10:03 2020(r367394)
@@ -102,17 +102,19 @@ cpu_fetch_syscall_args(struct thread *td)
struct proc *p;
register_t *ap;
struct syscall_args *sa;
+   u_int nap;
int error;
 
+   nap = 4;
sa = >td_sa;
sa->code = td->td_frame->tf_r7;
ap = >td_frame->tf_r0;
if (sa->code == SYS_syscall) {
sa->code = *ap++;
-   sa->nap--;
+   nap--;
} else if (sa->code == SYS___syscall) {
sa->code = ap[_QUAD_LOWWORD];
-   sa->nap -= 2;
+   nap -= 2;
ap += 2;
}
p = td->td_proc;
@@ -121,11 +123,10 @@ cpu_fetch_syscall_args(struct thread *td)
else
sa->callp = >p_sysent->sv_table[sa->code];
error = 0;
-   memcpy(sa->args, ap, sa->nap * sizeof(register_t));
-   if (sa->callp->sy_narg > sa->nap) {
+   memcpy(sa->args, ap, nap * sizeof(register_t));
+   if (sa->callp->sy_narg > nap) {
error = copyin((void *)td->td_frame->tf_usr_sp, sa->args +
-   sa->nap, (sa->callp->sy_narg - sa->nap) *
-   sizeof(register_t));
+   nap, (sa->callp->sy_narg - nap) * sizeof(register_t));
}
if (error == 0) {
td->td_retval[0] = 0;
@@ -140,7 +141,6 @@ static void
 syscall(struct thread *td, struct trapframe *frame)
 {
 
-   td->td_sa.nap = 4;
syscallenter(td);
syscallret(td);
 }

Modified: head/sys/arm/include/proc.h
==
--- head/sys/arm/include/proc.h Thu Nov  5 17:10:14 2020(r367393)
+++ head/sys/arm/include/proc.h Thu Nov  5 18:10:03 2020(r367394)
@@ -82,7 +82,6 @@ struct syscall_args {
u_int code;
struct sysent *callp;
register_t args[MAXARGS];
-   u_int nap;
 } __aligned(8);
 
 #endif /* !_MACHINE_PROC_H_ */
___
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: r367393 - head/usr.sbin/bhyve

2020-11-05 Thread Allan Jude
Author: allanjude
Date: Thu Nov  5 17:10:14 2020
New Revision: 367393
URL: https://svnweb.freebsd.org/changeset/base/367393

Log:
  VirtIO: Make sure the guest knows the TRIM alignment requirements
  
  If bhyve is used to emulate 512e access in guest OS, then discard addresses 
should be properly aligned.
  Otherwise ioctl DIOCGDELETE fails for 512b requires on devices with 4K sector 
size.
  see g_dev_ioctl() in sys/geom/geom_dev.c
  
  Submitted by: Vitaliy Gusev 
  MFC after:1 week
  Sponsored by: vStack.com
  Differential Revision:https://reviews.freebsd.org/D27075

Modified:
  head/usr.sbin/bhyve/pci_virtio_block.c

Modified: head/usr.sbin/bhyve/pci_virtio_block.c
==
--- head/usr.sbin/bhyve/pci_virtio_block.c  Thu Nov  5 16:47:23 2020
(r367392)
+++ head/usr.sbin/bhyve/pci_virtio_block.c  Thu Nov  5 17:10:14 2020
(r367393)
@@ -523,7 +523,7 @@ pci_vtblk_init(struct vmctx *ctx, struct pci_devinst *
sc->vbsc_cfg.vbc_writeback = 0;
sc->vbsc_cfg.max_discard_sectors = VTBLK_MAX_DISCARD_SECT;
sc->vbsc_cfg.max_discard_seg = VTBLK_MAX_DISCARD_SEG;
-   sc->vbsc_cfg.discard_sector_alignment = sectsz / VTBLK_BSIZE;
+   sc->vbsc_cfg.discard_sector_alignment = MAX(sectsz, sts) / VTBLK_BSIZE;
 
/*
 * Should we move some of this into virtio.c?  Could
___
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: r367392 - head/lib/libpmcstat

2020-11-05 Thread Leandro Lupori
Author: luporl
Date: Thu Nov  5 16:47:23 2020
New Revision: 367392
URL: https://svnweb.freebsd.org/changeset/base/367392

Log:
  pmcstat: fix PPC kernel symbol resolution
  
  PowerPC kernel is of DYN type and it has a base address where it is
  initially loaded, before being relocated. As the start address passed to
  pmcstat_image_link() is where the kernel was relocated to, but the symbols
  always use the original base address, we need to subtract it to get the
  correct offset.
  
  Reviewed by:  jhibbits
  Sponsored by: Eldorado Research Institute (eldorado.org.br)
  Differential Revision:https://reviews.freebsd.org/D26114

Modified:
  head/lib/libpmcstat/libpmcstat_image.c

Modified: head/lib/libpmcstat/libpmcstat_image.c
==
--- head/lib/libpmcstat/libpmcstat_image.c  Thu Nov  5 16:41:28 2020
(r367391)
+++ head/lib/libpmcstat/libpmcstat_image.c  Thu Nov  5 16:47:23 2020
(r367392)
@@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -176,12 +177,36 @@ pmcstat_image_link(struct pmcstat_process *pp, struct 
 {
struct pmcstat_pcmap *pcm, *pcmnew;
uintfptr_t offset;
+#ifdef __powerpc__
+   unsigned long kernbase;
+   size_t kernbase_len;
+#endif
 
assert(image->pi_type != PMCSTAT_IMAGE_UNKNOWN &&
image->pi_type != PMCSTAT_IMAGE_INDETERMINABLE);
 
if ((pcmnew = malloc(sizeof(*pcmnew))) == NULL)
err(EX_OSERR, "ERROR: Cannot create a map entry");
+
+   /*
+* PowerPC kernel is of DYN type and it has a base address
+* where it is initially loaded, before being relocated.
+* As the address in 'start' is where the kernel was relocated to,
+* but the symbols always use the original base address, we need to
+* subtract it to get the correct offset.
+*/
+#ifdef __powerpc__
+   if (pp->pp_pid == -1) {
+   kernbase = 0;
+   kernbase_len = sizeof(kernbase);
+   if (sysctlbyname("kern.base_address", , _len,
+   NULL, 0) == -1)
+   warnx(
+   "WARNING: Could not retrieve kernel base address");
+   else
+   start -= kernbase;
+   }
+#endif
 
/*
 * Adjust the map entry to only cover the text portion
___
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: r367391 - head/lib/libpmc

2020-11-05 Thread Leandro Lupori
Author: luporl
Date: Thu Nov  5 16:41:28 2020
New Revision: 367391
URL: https://svnweb.freebsd.org/changeset/base/367391

Log:
  libpmc: add support for POWER8/9 PMCs
  
  This change adds support for POWER8/9 performance counters.
  
  Reviewed by:  jhibbits
  Sponsored by: Eldorado Research Institute (eldorado.org.br)
  Differential Revision:https://reviews.freebsd.org/D26113

Modified:
  head/lib/libpmc/libpmc.c

Modified: head/lib/libpmc/libpmc.c
==
--- head/lib/libpmc/libpmc.cThu Nov  5 16:36:39 2020(r367390)
+++ head/lib/libpmc/libpmc.cThu Nov  5 16:41:28 2020(r367391)
@@ -149,6 +149,7 @@ PMC_CLASSDEP_TABLE(mips74k, MIPS74K);
 PMC_CLASSDEP_TABLE(octeon, OCTEON);
 PMC_CLASSDEP_TABLE(ppc7450, PPC7450);
 PMC_CLASSDEP_TABLE(ppc970, PPC970);
+PMC_CLASSDEP_TABLE(power8, POWER8);
 PMC_CLASSDEP_TABLE(e500, E500);
 
 static struct pmc_event_descr soft_event_table[PMC_EV_DYN_COUNT];
@@ -204,6 +205,7 @@ PMC_MDEP_TABLE(mips74k, MIPS74K, PMC_CLASS_SOFT, PMC_C
 PMC_MDEP_TABLE(octeon, OCTEON, PMC_CLASS_SOFT, PMC_CLASS_OCTEON);
 PMC_MDEP_TABLE(ppc7450, PPC7450, PMC_CLASS_SOFT, PMC_CLASS_PPC7450, 
PMC_CLASS_TSC);
 PMC_MDEP_TABLE(ppc970, PPC970, PMC_CLASS_SOFT, PMC_CLASS_PPC970, 
PMC_CLASS_TSC);
+PMC_MDEP_TABLE(power8, POWER8, PMC_CLASS_SOFT, PMC_CLASS_POWER8, 
PMC_CLASS_TSC);
 PMC_MDEP_TABLE(e500, E500, PMC_CLASS_SOFT, PMC_CLASS_E500, PMC_CLASS_TSC);
 PMC_MDEP_TABLE(generic, SOFT, PMC_CLASS_SOFT);
 
@@ -252,6 +254,7 @@ PMC_CLASS_TABLE_DESC(octeon, OCTEON, octeon, mips);
 #if defined(__powerpc__)
 PMC_CLASS_TABLE_DESC(ppc7450, PPC7450, ppc7450, powerpc);
 PMC_CLASS_TABLE_DESC(ppc970, PPC970, ppc970, powerpc);
+PMC_CLASS_TABLE_DESC(power8, POWER8, power8, powerpc);
 PMC_CLASS_TABLE_DESC(e500, E500, e500, powerpc);
 #endif
 
@@ -913,6 +916,12 @@ static struct pmc_event_alias ppc970_aliases[] = {
EV_ALIAS(NULL, NULL)
 };
 
+static struct pmc_event_alias power8_aliases[] = {
+   EV_ALIAS("instructions", "INSTR_COMPLETED"),
+   EV_ALIAS("cycles",   "CYCLES"),
+   EV_ALIAS(NULL, NULL)
+};
+
 static struct pmc_event_alias e500_aliases[] = {
EV_ALIAS("instructions", "INSTR_COMPLETED"),
EV_ALIAS("cycles",   "CYCLES"),
@@ -1313,6 +1322,10 @@ pmc_event_names_of_class(enum pmc_class cl, const char
ev = ppc970_event_table;
count = PMC_EVENT_TABLE_SIZE(ppc970);
break;
+   case PMC_CLASS_POWER8:
+   ev = power8_event_table;
+   count = PMC_EVENT_TABLE_SIZE(power8);
+   break;
case PMC_CLASS_E500:
ev = e500_event_table;
count = PMC_EVENT_TABLE_SIZE(e500);
@@ -1564,6 +1577,10 @@ pmc_init(void)
PMC_MDEP_INIT(ppc970);
pmc_class_table[n] = _class_table_descr;
break;
+   case PMC_CPU_PPC_POWER8:
+   PMC_MDEP_INIT(power8);
+   pmc_class_table[n] = _class_table_descr;
+   break;
case PMC_CPU_PPC_E500:
PMC_MDEP_INIT(e500);
pmc_class_table[n] = _class_table_descr;
@@ -1701,6 +1718,9 @@ _pmc_name_of_event(enum pmc_event pe, enum pmc_cputype
} else if (pe >= PMC_EV_PPC970_FIRST && pe <= PMC_EV_PPC970_LAST) {
ev = ppc970_event_table;
evfence = ppc970_event_table + PMC_EVENT_TABLE_SIZE(ppc970);
+   } else if (pe >= PMC_EV_POWER8_FIRST && pe <= PMC_EV_POWER8_LAST) {
+   ev = power8_event_table;
+   evfence = power8_event_table + PMC_EVENT_TABLE_SIZE(power8);
} else if (pe >= PMC_EV_E500_FIRST && pe <= PMC_EV_E500_LAST) {
ev = e500_event_table;
evfence = e500_event_table + PMC_EVENT_TABLE_SIZE(e500);
___
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: r367390 - in head/sys: dev/hwpmc modules/hwpmc powerpc/include sys

2020-11-05 Thread Leandro Lupori
Author: luporl
Date: Thu Nov  5 16:36:39 2020
New Revision: 367390
URL: https://svnweb.freebsd.org/changeset/base/367390

Log:
  [PowerPC] hwpmc: add support for POWER8/9 PMCs
  
  This change adds support for POWER8 and POWER9 PMCs (bare metal and
  pseries).
  All PowerISA 2.07B non-random events are supported.
  
  Implementation was based on that of PPC970.
  
  Reviewed by:  jhibbits
  Sponsored by: Eldorado Research Institute (eldorado.org.br)
  Differential Revision:https://reviews.freebsd.org/D26110

Added:
  head/sys/dev/hwpmc/hwpmc_power8.c   (contents, props changed)
Modified:
  head/sys/dev/hwpmc/hwpmc_e500.c
  head/sys/dev/hwpmc/hwpmc_mpc7xxx.c
  head/sys/dev/hwpmc/hwpmc_powerpc.c
  head/sys/dev/hwpmc/hwpmc_powerpc.h
  head/sys/dev/hwpmc/hwpmc_ppc970.c
  head/sys/dev/hwpmc/pmc_events.h
  head/sys/modules/hwpmc/Makefile
  head/sys/powerpc/include/pmc_mdep.h
  head/sys/sys/pmc.h

Modified: head/sys/dev/hwpmc/hwpmc_e500.c
==
--- head/sys/dev/hwpmc/hwpmc_e500.c Thu Nov  5 16:21:21 2020
(r367389)
+++ head/sys/dev/hwpmc/hwpmc_e500.c Thu Nov  5 16:36:39 2020
(r367390)
@@ -41,14 +41,6 @@ __FBSDID("$FreeBSD$");
 
 #include "hwpmc_powerpc.h"
 
-#definePOWERPC_PMC_CAPS(PMC_CAP_INTERRUPT | PMC_CAP_USER | 
\
-PMC_CAP_SYSTEM | PMC_CAP_EDGE |\
-PMC_CAP_THRESHOLD | PMC_CAP_READ | \
-PMC_CAP_WRITE | PMC_CAP_INVERT |   \
-PMC_CAP_QUALIFIER)
-
-#define E500_PMC_HAS_OVERFLOWED(x) (e500_pmcn_read(x) & (0x1 << 31))
-
 struct e500_event_code_map {
enum pmc_event  pe_ev;   /* enum value */
uint8_t pe_counter_mask;  /* Which counter this can be counted 
in. */
@@ -246,20 +238,16 @@ static pmc_value_t
 e500_pmcn_read(unsigned int pmc)
 {
switch (pmc) {
-   case 0:
-   return mfpmr(PMR_PMC0);
-   break;
-   case 1:
-   return mfpmr(PMR_PMC1);
-   break;
-   case 2:
-   return mfpmr(PMR_PMC2);
-   break;
-   case 3:
-   return mfpmr(PMR_PMC3);
-   break;
-   default:
-   panic("Invalid PMC number: %d\n", pmc);
+   case 0:
+   return (mfpmr(PMR_PMC0));
+   case 1:
+   return (mfpmr(PMR_PMC1));
+   case 2:
+   return (mfpmr(PMR_PMC2));
+   case 3:
+   return (mfpmr(PMR_PMC3));
+   default:
+   panic("Invalid PMC number: %d\n", pmc);
}
 }
 
@@ -267,206 +255,98 @@ static void
 e500_pmcn_write(unsigned int pmc, uint32_t val)
 {
switch (pmc) {
-   case 0:
-   mtpmr(PMR_PMC0, val);
-   break;
-   case 1:
-   mtpmr(PMR_PMC1, val);
-   break;
-   case 2:
-   mtpmr(PMR_PMC2, val);
-   break;
-   case 3:
-   mtpmr(PMR_PMC3, val);
-   break;
-   default:
-   panic("Invalid PMC number: %d\n", pmc);
-   }
-}
-
-static int
-e500_read_pmc(int cpu, int ri, pmc_value_t *v)
-{
-   struct pmc *pm;
-   pmc_value_t tmp;
-
-   KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
-   ("[powerpc,%d] illegal CPU value %d", __LINE__, cpu));
-   KASSERT(ri >= 0 && ri < E500_MAX_PMCS,
-   ("[powerpc,%d] illegal row index %d", __LINE__, ri));
-
-   pm  = powerpc_pcpu[cpu]->pc_ppcpmcs[ri].phw_pmc;
-   KASSERT(pm,
-   ("[core,%d] cpu %d ri %d pmc not configured", __LINE__, cpu,
-   ri));
-
-   tmp = e500_pmcn_read(ri);
-   PMCDBG2(MDP,REA,2,"ppc-read id=%d -> %jd", ri, tmp);
-   if (PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm)))
-   *v = POWERPC_PERFCTR_VALUE_TO_RELOAD_COUNT(tmp);
-   else
-   *v = tmp;
-
-   return 0;
-}
-
-static int
-e500_write_pmc(int cpu, int ri, pmc_value_t v)
-{
-   struct pmc *pm;
-
-   KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
-   ("[powerpc,%d] illegal CPU value %d", __LINE__, cpu));
-   KASSERT(ri >= 0 && ri < E500_MAX_PMCS,
-   ("[powerpc,%d] illegal row-index %d", __LINE__, ri));
-
-   pm  = powerpc_pcpu[cpu]->pc_ppcpmcs[ri].phw_pmc;
-
-   if (PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm)))
-   v = POWERPC_RELOAD_COUNT_TO_PERFCTR_VALUE(v);
-   
-   PMCDBG3(MDP,WRI,1,"powerpc-write cpu=%d ri=%d v=%jx", cpu, ri, v);
-
-   e500_pmcn_write(ri, v);
-
-   return 0;
-}
-
-static int
-e500_config_pmc(int cpu, int ri, struct pmc *pm)
-{
-   struct pmc_hw *phw;
-
-   PMCDBG3(MDP,CFG,1, "cpu=%d ri=%d pm=%p", cpu, ri, 

svn commit: r367389 - in head/sys: kern sys

2020-11-05 Thread Mateusz Guzik
Author: mjg
Date: Thu Nov  5 16:21:21 2020
New Revision: 367389
URL: https://svnweb.freebsd.org/changeset/base/367389

Log:
  malloc: add a helper returning size allocated for given request
  
  Sample usage: kernel modules can decide whether to stick to malloc or
  create their own zone.
  
  Reviewed by:  markj
  Differential Revision:https://reviews.freebsd.org/D27097

Modified:
  head/sys/kern/kern_malloc.c
  head/sys/sys/malloc.h

Modified: head/sys/kern/kern_malloc.c
==
--- head/sys/kern/kern_malloc.c Thu Nov  5 16:00:57 2020(r367388)
+++ head/sys/kern/kern_malloc.c Thu Nov  5 16:21:21 2020(r367389)
@@ -1031,6 +1031,23 @@ reallocf(void *addr, size_t size, struct malloc_type *
 }
 
 /*
+ * malloc_size: returns the number of bytes allocated for a request of the
+ *  specified size
+ */
+size_t
+malloc_size(size_t size)
+{
+   int indx;
+
+   if (size > kmem_zmax)
+   return (0);
+   if (size & KMEM_ZMASK)
+   size = (size & ~KMEM_ZMASK) + KMEM_ZBASE;
+   indx = kmemsize[size >> KMEM_ZSHIFT];
+   return (kmemzones[indx].kz_size);
+}
+
+/*
  * malloc_usable_size: returns the usable size of the allocation.
  */
 size_t

Modified: head/sys/sys/malloc.h
==
--- head/sys/sys/malloc.h   Thu Nov  5 16:00:57 2020(r367388)
+++ head/sys/sys/malloc.h   Thu Nov  5 16:21:21 2020(r367389)
@@ -250,6 +250,7 @@ voidmalloc_type_allocated(struct malloc_type *type, 
u
 void   malloc_type_freed(struct malloc_type *type, unsigned long size);
 void   malloc_type_list(malloc_type_list_func_t *, void *);
 void   malloc_uninit(void *);
+size_t malloc_size(size_t);
 size_t malloc_usable_size(const void *);
 void   *realloc(void *addr, size_t size, struct malloc_type *type, int flags)
__result_use_check __alloc_size(2);
___
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: r367388 - head/tests/sys/opencrypto

2020-11-05 Thread Mark Johnston
Author: markj
Date: Thu Nov  5 16:00:57 2020
New Revision: 367388
URL: https://svnweb.freebsd.org/changeset/base/367388

Log:
  cryptotest: Add qat(4) coverage
  
  MFC after:3 days
  Sponsored by: Rubicon Communications, LLC (Netgate)

Modified:
  head/tests/sys/opencrypto/cryptotest.py

Modified: head/tests/sys/opencrypto/cryptotest.py
==
--- head/tests/sys/opencrypto/cryptotest.py Thu Nov  5 16:00:30 2020
(r367387)
+++ head/tests/sys/opencrypto/cryptotest.py Thu Nov  5 16:00:57 2020
(r367388)
@@ -50,8 +50,8 @@ def katg(base, glob):
 raise unittest.SkipTest("Missing %s test vectors" % (base))
 return iglob(os.path.join(katdir, base, glob))
 
-aesmodules = [ 'cryptosoft0', 'aesni0', 'armv8crypto0', 'ccr0', 'ccp0', 
'safexcel0' ]
-shamodules = [ 'cryptosoft0', 'aesni0', 'armv8crypto0', 'ccr0', 'ccp0', 
'ossl0', 'safexcel0' ]
+aesmodules = [ 'cryptosoft0', 'aesni0', 'armv8crypto0', 'ccr0', 'ccp0', 
'safexcel0', 'qat0' ]
+shamodules = [ 'cryptosoft0', 'aesni0', 'armv8crypto0', 'ccr0', 'ccp0', 
'ossl0', 'safexcel0', 'qat0' ]
 
 def GenTestCase(cname):
 try:
@@ -458,6 +458,7 @@ ccr = GenTestCase('ccr0')
 ccp = GenTestCase('ccp0')
 ossl = GenTestCase('ossl0')
 safexcel = GenTestCase('safexcel0')
+qat = GenTestCase('qat0')
 
 if __name__ == '__main__':
 unittest.main()
___
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: r367387 - in head/sys: contrib/dev/qat modules modules/qatfw modules/qatfw/qat_c2xxx modules/qatfw/qat_c3xxx modules/qatfw/qat_c62x modules/qatfw/qat_d15xx modules/qatfw/qat_dh895xcc

2020-11-05 Thread Mark Johnston
Author: markj
Date: Thu Nov  5 16:00:30 2020
New Revision: 367387
URL: https://svnweb.freebsd.org/changeset/base/367387

Log:
  Add firmware modules for qat(4)
  
  MFC after:3 days
  Sponsored by: Rubicon Communications, LLC (Netgate)

Added:
  head/sys/contrib/dev/qat/
  head/sys/contrib/dev/qat/LICENSE
  head/sys/contrib/dev/qat/mmp_firmware_c2xxx.bin
  head/sys/contrib/dev/qat/mof_firmware_c2xxx.bin
  head/sys/contrib/dev/qat/qat_895xcc.bin
  head/sys/contrib/dev/qat/qat_895xcc_mmp.bin
  head/sys/contrib/dev/qat/qat_c3xxx.bin
  head/sys/contrib/dev/qat/qat_c3xxx_mmp.bin
  head/sys/contrib/dev/qat/qat_c62x.bin
  head/sys/contrib/dev/qat/qat_c62x_mmp.bin
  head/sys/contrib/dev/qat/qat_d15xx.bin
  head/sys/contrib/dev/qat/qat_d15xx_mmp.bin
  head/sys/modules/qatfw/
  head/sys/modules/qatfw/Makefile   (contents, props changed)
  head/sys/modules/qatfw/qat_c2xxx/
  head/sys/modules/qatfw/qat_c2xxx/Makefile   (contents, props changed)
  head/sys/modules/qatfw/qat_c3xxx/
  head/sys/modules/qatfw/qat_c3xxx/Makefile   (contents, props changed)
  head/sys/modules/qatfw/qat_c62x/
  head/sys/modules/qatfw/qat_c62x/Makefile   (contents, props changed)
  head/sys/modules/qatfw/qat_d15xx/
  head/sys/modules/qatfw/qat_d15xx/Makefile   (contents, props changed)
  head/sys/modules/qatfw/qat_dh895xcc/
  head/sys/modules/qatfw/qat_dh895xcc/Makefile   (contents, props changed)
Modified:
  head/sys/modules/Makefile

Added: head/sys/contrib/dev/qat/LICENSE
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/contrib/dev/qat/LICENSEThu Nov  5 16:00:30 2020
(r367387)
@@ -0,0 +1,11 @@
+Copyright (c) 2007-2016 Intel Corporation.
+All rights reserved.
+Redistribution.  Redistribution and use in binary form, without modification, 
are permitted provided that the following conditions are met:
+
+   Redistributions must reproduce the above copyright notice and the 
following disclaimer in the documentation and/or other materials provided with 
the distribution. 
+   Neither the name of Intel Corporation nor the names of its suppliers 
may be used to endorse or promote products derived from this software without 
specific prior written permission. 
+   No reverse engineering, decompilation, or disassembly of this software 
is permitted.
+   
+Limited patent license.  Intel Corporation grants a world-wide, royalty-free, 
non-exclusive license under patents it now or hereafter owns or controls to 
make, have made, use, import, offer to sell and sell ("Utilize") this software, 
but solely to the extent that any such patent is necessary to Utilize the 
software alone.  The patent license shall not apply to any combinations which 
include this software.  No hardware per se is licensed hereunder.
+
+DISCLAIMER.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.

Added: head/sys/contrib/dev/qat/mmp_firmware_c2xxx.bin
==

Added: head/sys/contrib/dev/qat/mof_firmware_c2xxx.bin
==

Added: head/sys/contrib/dev/qat/qat_895xcc.bin
==

Added: head/sys/contrib/dev/qat/qat_895xcc_mmp.bin
==

Added: head/sys/contrib/dev/qat/qat_c3xxx.bin
==

Added: head/sys/contrib/dev/qat/qat_c3xxx_mmp.bin
==

Added: head/sys/contrib/dev/qat/qat_c62x.bin
==

Added: head/sys/contrib/dev/qat/qat_c62x_mmp.bin
==

Added: head/sys/contrib/dev/qat/qat_d15xx.bin
==

Added: head/sys/contrib/dev/qat/qat_d15xx_mmp.bin
==

Modified: head/sys/modules/Makefile

svn commit: r367386 - in head: share/man/man4 sys/amd64/conf sys/conf sys/dev/qat sys/modules sys/modules/qat

2020-11-05 Thread Mark Johnston
Author: markj
Date: Thu Nov  5 15:55:23 2020
New Revision: 367386
URL: https://svnweb.freebsd.org/changeset/base/367386

Log:
  Add qat(4)
  
  This provides an OpenCrypto driver for Intel QuickAssist devices.  The
  driver was initially ported from NetBSD and comes with a few
  improvements:
  - support for GMAC/AES-GCM, AES-CTR and AES-XTS, and support for
SHA/HMAC-authenticated encryption
  - support for detaching the driver
  - various bug fixes
  - DH895X support
  
  Discussed with:   jhb
  MFC after:3 days
  Sponsored by: Rubicon Communications, LLC (Netgate)
  Differential Revision:https://reviews.freebsd.org/D26963

Added:
  head/share/man/man4/qat.4   (contents, props changed)
  head/sys/dev/qat/
  head/sys/dev/qat/qat.c   (contents, props changed)
  head/sys/dev/qat/qat_ae.c   (contents, props changed)
  head/sys/dev/qat/qat_aevar.h   (contents, props changed)
  head/sys/dev/qat/qat_c2xxx.c   (contents, props changed)
  head/sys/dev/qat/qat_c2xxxreg.h   (contents, props changed)
  head/sys/dev/qat/qat_c3xxx.c   (contents, props changed)
  head/sys/dev/qat/qat_c3xxxreg.h   (contents, props changed)
  head/sys/dev/qat/qat_c62x.c   (contents, props changed)
  head/sys/dev/qat/qat_c62xreg.h   (contents, props changed)
  head/sys/dev/qat/qat_d15xx.c   (contents, props changed)
  head/sys/dev/qat/qat_d15xxreg.h   (contents, props changed)
  head/sys/dev/qat/qat_dh895xcc.c   (contents, props changed)
  head/sys/dev/qat/qat_dh895xccreg.h   (contents, props changed)
  head/sys/dev/qat/qat_hw15.c   (contents, props changed)
  head/sys/dev/qat/qat_hw15reg.h   (contents, props changed)
  head/sys/dev/qat/qat_hw15var.h   (contents, props changed)
  head/sys/dev/qat/qat_hw17.c   (contents, props changed)
  head/sys/dev/qat/qat_hw17reg.h   (contents, props changed)
  head/sys/dev/qat/qat_hw17var.h   (contents, props changed)
  head/sys/dev/qat/qatreg.h   (contents, props changed)
  head/sys/dev/qat/qatvar.h   (contents, props changed)
  head/sys/modules/qat/
  head/sys/modules/qat/Makefile   (contents, props changed)
Modified:
  head/share/man/man4/Makefile
  head/sys/amd64/conf/NOTES
  head/sys/conf/files.x86
  head/sys/modules/Makefile

Modified: head/share/man/man4/Makefile
==
--- head/share/man/man4/MakefileThu Nov  5 15:27:38 2020
(r367385)
+++ head/share/man/man4/MakefileThu Nov  5 15:55:23 2020
(r367386)
@@ -431,6 +431,7 @@ MAN=aac.4 \
pty.4 \
puc.4 \
pwmc.4 \
+   ${_qat.4} \
${_qlxge.4} \
${_qlxgb.4} \
${_qlxgbe.4} \
@@ -823,6 +824,7 @@ _nvram.4=   nvram.4
 _ossl.4=   ossl.4
 _padlock.4=padlock.4
 _pchtherm.4=   pchtherm.4
+_qat.4=qat.4
 _rr232x.4= rr232x.4
 _speaker.4=speaker.4
 _spkr.4=   spkr.4

Added: head/share/man/man4/qat.4
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/share/man/man4/qat.4   Thu Nov  5 15:55:23 2020(r367386)
@@ -0,0 +1,99 @@
+.\"-
+.\" Copyright (c) 2020 Rubicon Communications, LLC (Netgate)
+.\"
+.\" 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd November 5, 2020
+.Dt QAT 4
+.Os
+.Sh NAME
+.Nm qat
+.Nd Intel QuickAssist Technology (QAT) driver
+.Sh SYNOPSIS
+To compile this driver into the kernel,
+place the following lines in your
+kernel configuration file:
+.Bd -ragged -offset indent
+.Cd "device crypto"
+.Cd "device cryptodev"
+.Cd "device qat"
+.Ed
+.Pp
+Alternatively, to load the driver as a
+module at boot time, place the following lines in
+.Xr loader.conf 

svn commit: r367384 - in head/sys: kern sys vm

2020-11-05 Thread Mateusz Guzik
Author: mjg
Date: Thu Nov  5 15:08:56 2020
New Revision: 367384
URL: https://svnweb.freebsd.org/changeset/base/367384

Log:
  Rationalize per-cpu zones.
  
  The 2 provided zones had inconsistent naming between each other
  ("int" and "64") and other allocator zones (which use bytes).
  
  Follow malloc by naming them "pcpu-" + size in bytes.
  
  This is a step towards replacing ad-hoc per-cpu zones with
  general slabs.

Modified:
  head/sys/kern/kern_rmlock.c
  head/sys/kern/subr_counter.c
  head/sys/kern/subr_pcpu.c
  head/sys/kern/vfs_mount.c
  head/sys/sys/param.h
  head/sys/vm/uma.h

Modified: head/sys/kern/kern_rmlock.c
==
--- head/sys/kern/kern_rmlock.c Thu Nov  5 14:15:50 2020(r367383)
+++ head/sys/kern/kern_rmlock.c Thu Nov  5 15:08:56 2020(r367384)
@@ -890,8 +890,8 @@ rms_init(struct rmslock *rms, const char *name)
rms->writers = 0;
rms->readers = 0;
mtx_init(>mtx, name, NULL, MTX_DEF | MTX_NEW);
-   rms->readers_pcpu = uma_zalloc_pcpu(pcpu_zone_int, M_WAITOK | M_ZERO);
-   rms->readers_influx = uma_zalloc_pcpu(pcpu_zone_int, M_WAITOK | M_ZERO);
+   rms->readers_pcpu = uma_zalloc_pcpu(pcpu_zone_4, M_WAITOK | M_ZERO);
+   rms->readers_influx = uma_zalloc_pcpu(pcpu_zone_4, M_WAITOK | M_ZERO);
 }
 
 void
@@ -901,8 +901,8 @@ rms_destroy(struct rmslock *rms)
MPASS(rms->writers == 0);
MPASS(rms->readers == 0);
mtx_destroy(>mtx);
-   uma_zfree_pcpu(pcpu_zone_int, rms->readers_pcpu);
-   uma_zfree_pcpu(pcpu_zone_int, rms->readers_influx);
+   uma_zfree_pcpu(pcpu_zone_4, rms->readers_pcpu);
+   uma_zfree_pcpu(pcpu_zone_4, rms->readers_influx);
 }
 
 static void __noinline

Modified: head/sys/kern/subr_counter.c
==
--- head/sys/kern/subr_counter.cThu Nov  5 14:15:50 2020
(r367383)
+++ head/sys/kern/subr_counter.cThu Nov  5 15:08:56 2020
(r367384)
@@ -61,14 +61,14 @@ counter_u64_t
 counter_u64_alloc(int flags)
 {
 
-   return (uma_zalloc_pcpu(pcpu_zone_64, flags | M_ZERO));
+   return (uma_zalloc_pcpu(pcpu_zone_8, flags | M_ZERO));
 }
 
 void
 counter_u64_free(counter_u64_t c)
 {
 
-   uma_zfree_pcpu(pcpu_zone_64, c);
+   uma_zfree_pcpu(pcpu_zone_8, c);
 }
 
 int

Modified: head/sys/kern/subr_pcpu.c
==
--- head/sys/kern/subr_pcpu.c   Thu Nov  5 14:15:50 2020(r367383)
+++ head/sys/kern/subr_pcpu.c   Thu Nov  5 15:08:56 2020(r367384)
@@ -131,21 +131,19 @@ dpcpu_startup(void *dummy __unused)
 SYSINIT(dpcpu, SI_SUB_KLD, SI_ORDER_FIRST, dpcpu_startup, NULL);
 
 /*
- * UMA_PCPU_ZONE zones, that are available for all kernel
- * consumers. Right now 64 bit zone is used for counter(9)
- * and int zone is used for mount point counters.
+ * UMA_ZONE_PCPU zones for general kernel use.
  */
 
-uma_zone_t pcpu_zone_int;
-uma_zone_t pcpu_zone_64;
+uma_zone_t pcpu_zone_4;
+uma_zone_t pcpu_zone_8;
 
 static void
 pcpu_zones_startup(void)
 {
 
-   pcpu_zone_int = uma_zcreate("int pcpu", sizeof(int),
+   pcpu_zone_4 = uma_zcreate("pcpu-4", sizeof(uint32_t),
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_PCPU);
-   pcpu_zone_64 = uma_zcreate("64 pcpu", sizeof(uint64_t),
+   pcpu_zone_8 = uma_zcreate("pcpu-8", sizeof(uint64_t),
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_PCPU);
 }
 SYSINIT(pcpu_zones, SI_SUB_COUNTER, SI_ORDER_FIRST, pcpu_zones_startup, NULL);

Modified: head/sys/kern/vfs_mount.c
==
--- head/sys/kern/vfs_mount.c   Thu Nov  5 14:15:50 2020(r367383)
+++ head/sys/kern/vfs_mount.c   Thu Nov  5 15:08:56 2020(r367384)
@@ -127,13 +127,13 @@ mount_init(void *mem, int size, int flags)
mtx_init(>mnt_mtx, "struct mount mtx", NULL, MTX_DEF);
mtx_init(>mnt_listmtx, "struct mount vlist mtx", NULL, MTX_DEF);
lockinit(>mnt_explock, PVFS, "explock", 0, 0);
-   mp->mnt_thread_in_ops_pcpu = uma_zalloc_pcpu(pcpu_zone_int,
+   mp->mnt_thread_in_ops_pcpu = uma_zalloc_pcpu(pcpu_zone_4,
M_WAITOK | M_ZERO);
-   mp->mnt_ref_pcpu = uma_zalloc_pcpu(pcpu_zone_int,
+   mp->mnt_ref_pcpu = uma_zalloc_pcpu(pcpu_zone_4,
M_WAITOK | M_ZERO);
-   mp->mnt_lockref_pcpu = uma_zalloc_pcpu(pcpu_zone_int,
+   mp->mnt_lockref_pcpu = uma_zalloc_pcpu(pcpu_zone_4,
M_WAITOK | M_ZERO);
-   mp->mnt_writeopcount_pcpu = uma_zalloc_pcpu(pcpu_zone_int,
+   mp->mnt_writeopcount_pcpu = uma_zalloc_pcpu(pcpu_zone_4,
M_WAITOK | M_ZERO);
mp->mnt_ref = 0;
mp->mnt_vfs_ops = 1;
@@ -147,10 +147,10 @@ mount_fini(void *mem, int size)
struct mount *mp;
 
mp = (struct mount *)mem;
-   uma_zfree_pcpu(pcpu_zone_int, 

svn commit: r367383 - in head/sys: dev/hwpmc powerpc/include powerpc/powerpc

2020-11-05 Thread Leandro Lupori
Author: luporl
Date: Thu Nov  5 14:15:50 2020
New Revision: 367383
URL: https://svnweb.freebsd.org/changeset/base/367383

Log:
  [PowerPC] Make PPC 970 PMC SPRs the standard ones
  
  And add a _74XX suffix to 74XX SPRs.
  
  This is a preparation for adding support to POWER8/9 PMCs, which have most
  SPRs equal to 970 ones.
  
  Reviewed by:  jhibbits
  Sponsored by: Eldorado Research Institute (eldorado.org.br)
  Differential Revision:https://reviews.freebsd.org/D26532

Modified:
  head/sys/dev/hwpmc/hwpmc_mpc7xxx.c
  head/sys/dev/hwpmc/hwpmc_ppc970.c
  head/sys/powerpc/include/spr.h
  head/sys/powerpc/powerpc/cpu.c

Modified: head/sys/dev/hwpmc/hwpmc_mpc7xxx.c
==
--- head/sys/dev/hwpmc/hwpmc_mpc7xxx.c  Thu Nov  5 13:45:26 2020
(r367382)
+++ head/sys/dev/hwpmc/hwpmc_mpc7xxx.c  Thu Nov  5 14:15:50 2020
(r367383)
@@ -48,12 +48,15 @@ __FBSDID("$FreeBSD$");
 PMC_CAP_WRITE | PMC_CAP_INVERT |   \
 PMC_CAP_QUALIFIER)
 
-#define PPC_SET_PMC1SEL(r, x)  ((r & ~(SPR_MMCR0_PMC1SEL(0x3f))) | 
SPR_MMCR0_PMC1SEL(x))
-#define PPC_SET_PMC2SEL(r, x)  ((r & ~(SPR_MMCR0_PMC2SEL(0x3f))) | 
SPR_MMCR0_PMC2SEL(x))
+#define PPC_SET_PMC1SEL(r, x)  ((r & ~(SPR_MMCR0_74XX_PMC1SEL(0x3f))) | \
+   SPR_MMCR0_74XX_PMC1SEL(x))
+#define PPC_SET_PMC2SEL(r, x)  ((r & ~(SPR_MMCR0_74XX_PMC2SEL(0x3f))) | \
+   SPR_MMCR0_74XX_PMC2SEL(x))
 #define PPC_SET_PMC3SEL(r, x)  ((r & ~(SPR_MMCR1_PMC3SEL(0x1f))) | 
SPR_MMCR1_PMC3SEL(x))
 #define PPC_SET_PMC4SEL(r, x)  ((r & ~(SPR_MMCR1_PMC4SEL(0x1f))) | 
SPR_MMCR1_PMC4SEL(x))
 #define PPC_SET_PMC5SEL(r, x)  ((r & ~(SPR_MMCR1_PMC5SEL(0x1f))) | 
SPR_MMCR1_PMC5SEL(x))
-#define PPC_SET_PMC6SEL(r, x)  ((r & ~(SPR_MMCR1_PMC6SEL(0x3f))) | 
SPR_MMCR1_PMC6SEL(x))
+#define PPC_SET_PMC6SEL(r, x)  ((r & ~(SPR_MMCR1_74XX_PMC6SEL(0x3f))) | \
+   SPR_MMCR1_74XX_PMC6SEL(x))
 
 /* Change this when we support more than just the 7450. */
 #define MPC7XXX_MAX_PMCS   6
@@ -318,22 +321,22 @@ mpc7xxx_pmcn_read(unsigned int pmc)
 {
switch (pmc) {
case 0:
-   return mfspr(SPR_PMC1);
+   return mfspr(SPR_PMC1_74XX);
break;
case 1:
-   return mfspr(SPR_PMC2);
+   return mfspr(SPR_PMC2_74XX);
break;
case 2:
-   return mfspr(SPR_PMC3);
+   return mfspr(SPR_PMC3_74XX);
break;
case 3:
-   return mfspr(SPR_PMC4);
+   return mfspr(SPR_PMC4_74XX);
break;
case 4:
-   return mfspr(SPR_PMC5);
+   return mfspr(SPR_PMC5_74XX);
break;
case 5:
-   return mfspr(SPR_PMC6);
+   return mfspr(SPR_PMC6_74XX);
default:
panic("Invalid PMC number: %d\n", pmc);
}
@@ -344,22 +347,22 @@ mpc7xxx_pmcn_write(unsigned int pmc, uint32_t val)
 {
switch (pmc) {
case 0:
-   mtspr(SPR_PMC1, val);
+   mtspr(SPR_PMC1_74XX, val);
break;
case 1:
-   mtspr(SPR_PMC2, val);
+   mtspr(SPR_PMC2_74XX, val);
break;
case 2:
-   mtspr(SPR_PMC3, val);
+   mtspr(SPR_PMC3_74XX, val);
break;
case 3:
-   mtspr(SPR_PMC4, val);
+   mtspr(SPR_PMC4_74XX, val);
break;
case 4:
-   mtspr(SPR_PMC5, val);
+   mtspr(SPR_PMC5_74XX, val);
break;
case 5:
-   mtspr(SPR_PMC6, val);
+   mtspr(SPR_PMC6_74XX, val);
break;
default:
panic("Invalid PMC number: %d\n", pmc);
@@ -452,34 +455,34 @@ mpc7xxx_start_pmc(int cpu, int ri)
/* Enable the PMC. */
switch (ri) {
case 0:
-   pmc_mmcr = mfspr(SPR_MMCR0);
+   pmc_mmcr = mfspr(SPR_MMCR0_74XX);
pmc_mmcr = PPC_SET_PMC1SEL(pmc_mmcr, config);
-   mtspr(SPR_MMCR0, pmc_mmcr);
+   mtspr(SPR_MMCR0_74XX, pmc_mmcr);
break;
case 1:
-   pmc_mmcr = mfspr(SPR_MMCR0);
+   pmc_mmcr = mfspr(SPR_MMCR0_74XX);
pmc_mmcr = PPC_SET_PMC2SEL(pmc_mmcr, config);
-   mtspr(SPR_MMCR0, pmc_mmcr);
+   mtspr(SPR_MMCR0_74XX, pmc_mmcr);
   

svn commit: r367379 - head/sys/kern

2020-11-05 Thread Mateusz Guzik
Author: mjg
Date: Thu Nov  5 12:24:37 2020
New Revision: 367379
URL: https://svnweb.freebsd.org/changeset/base/367379

Log:
  poll/select: change selfd_zone into a malloc type
  
  On a sample box vmstat -z shows:
  
  ITEM   SIZE  LIMIT USED FREE  REQ
  64:  64,  0, 1043784, 4367538,3698187229
  selfd:   64,  0,1520,   13726,182729008
  
  But at the same time:
  vm.uma.selfd.keg.domain.1.pages: 121
  vm.uma.selfd.keg.domain.0.pages: 121
  
  Thus 242 pages got pulled even though the malloc zone would likely accomodate
  the load without using extra memory.

Modified:
  head/sys/kern/sys_generic.c

Modified: head/sys/kern/sys_generic.c
==
--- head/sys/kern/sys_generic.c Thu Nov  5 12:17:50 2020(r367378)
+++ head/sys/kern/sys_generic.c Thu Nov  5 12:24:37 2020(r367379)
@@ -159,7 +159,7 @@ struct selfd {
u_int   sf_refs;
 };
 
-static uma_zone_t selfd_zone;
+MALLOC_DEFINE(M_SELFD, "selfd", "selfd");
 static struct mtx_pool *mtxpool_select;
 
 #ifdef __LP64__
@@ -1691,11 +1691,11 @@ selfdalloc(struct thread *td, void *cookie)
 
stp = td->td_sel;
if (stp->st_free1 == NULL)
-   stp->st_free1 = uma_zalloc(selfd_zone, M_WAITOK|M_ZERO);
+   stp->st_free1 = malloc(sizeof(*stp->st_free1), M_SELFD, 
M_WAITOK|M_ZERO);
stp->st_free1->sf_td = stp;
stp->st_free1->sf_cookie = cookie;
if (stp->st_free2 == NULL)
-   stp->st_free2 = uma_zalloc(selfd_zone, M_WAITOK|M_ZERO);
+   stp->st_free2 = malloc(sizeof(*stp->st_free2), M_SELFD, 
M_WAITOK|M_ZERO);
stp->st_free2->sf_td = stp;
stp->st_free2->sf_cookie = cookie;
 }
@@ -1713,7 +1713,7 @@ selfdfree(struct seltd *stp, struct selfd *sfp)
mtx_unlock(sfp->sf_mtx);
}
if (refcount_release(>sf_refs))
-   uma_zfree(selfd_zone, sfp);
+   free(sfp, M_SELFD);
 }
 
 /* Drain the waiters tied to all the selfd belonging the specified selinfo. */
@@ -1827,7 +1827,7 @@ doselwakeup(struct selinfo *sip, int pri)
cv_broadcastpri(>st_wait, pri);
mtx_unlock(>st_mtx);
if (refcount_release(>sf_refs))
-   uma_zfree(selfd_zone, sfp);
+   free(sfp, M_SELFD);
}
mtx_unlock(sip->si_mtx);
 }
@@ -1888,9 +1888,9 @@ seltdfini(struct thread *td)
if (stp == NULL)
return;
if (stp->st_free1)
-   uma_zfree(selfd_zone, stp->st_free1);
+   free(stp->st_free1, M_SELFD);
if (stp->st_free2)
-   uma_zfree(selfd_zone, stp->st_free2);
+   free(stp->st_free2, M_SELFD);
td->td_sel = NULL;
cv_destroy(>st_wait);
mtx_destroy(>st_mtx);
@@ -1920,8 +1920,6 @@ static void
 selectinit(void *dummy __unused)
 {
 
-   selfd_zone = uma_zcreate("selfd", sizeof(struct selfd), NULL, NULL,
-   NULL, NULL, UMA_ALIGN_PTR, 0);
mtxpool_select = mtx_pool_create("select mtxpool", 128, MTX_DEF);
 }
 
___
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: r367343 - in head/sys/contrib/openzfs/include/os: freebsd/zfs/sys linux/zfs/sys

2020-11-05 Thread Mateusz Guzik
On 11/5/20, Alexey Dokuchaev  wrote:
> On Wed, Nov 04, 2020 at 09:18:52PM +, Mateusz Guzik wrote:
>> New Revision: 367343
>> URL: https://svnweb.freebsd.org/changeset/base/367343
>>
>> Log:
>>   zfs: add branch prediction to ZFS_ENTER and ZFS_VERIFY_ZP macros
>>
>>   They are expected to fail only in corner cases.
>>
>> Modified:
>>   head/sys/contrib/openzfs/include/os/freebsd/zfs/sys/zfs_znode_impl.h
>>   head/sys/contrib/openzfs/include/os/linux/zfs/sys/zfs_znode_impl.h
>
> Since my earlier email was ignored, I'd take this chance to ask again:
> why Linux-specific bits present in the head and had to be updated like
> in this commit?  They shouldn't have made past the vendor branch, no?
>

I don't know the reasoning for putting these files here. I suspect
this is to make merging easier. fwiw I don't think they are a problem.

The patch at hand modified them as it was based on the work against
the upstream repo and followed suit

-- 
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"


svn commit: r367372 - head/sys/kern

2020-11-05 Thread Mateusz Guzik
Author: mjg
Date: Thu Nov  5 12:06:50 2020
New Revision: 367372
URL: https://svnweb.freebsd.org/changeset/base/367372

Log:
  vfs: change nt_zone into a malloc type
  
  Elements are small in size and allocated for short periods.

Modified:
  head/sys/kern/vfs_lookup.c

Modified: head/sys/kern/vfs_lookup.c
==
--- head/sys/kern/vfs_lookup.c  Thu Nov  5 11:56:49 2020(r367371)
+++ head/sys/kern/vfs_lookup.c  Thu Nov  5 12:06:50 2020(r367372)
@@ -149,7 +149,7 @@ struct nameicap_tracker {
 };
 
 /* Zone for cap mode tracker elements used for dotdot capability checks. */
-static uma_zone_t nt_zone;
+MALLOC_DEFINE(M_NAMEITRACKER, "namei_tracker", "namei tracking for dotdot");
 
 static void
 nameiinit(void *dummy __unused)
@@ -157,8 +157,6 @@ nameiinit(void *dummy __unused)
 
namei_zone = uma_zcreate("NAMEI", MAXPATHLEN, NULL, NULL, NULL, NULL,
UMA_ALIGN_PTR, 0);
-   nt_zone = uma_zcreate("rentr", sizeof(struct nameicap_tracker),
-   NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
vfs_vector_op_register(_vnodeops);
getnewvnode("crossmp", NULL, _vnodeops, _crossmp);
 }
@@ -190,7 +188,7 @@ nameicap_tracker_add(struct nameidata *ndp, struct vno
return;
ndp->ni_lcf |= NI_LCF_BENEATH_LATCHED;
}
-   nt = uma_zalloc(nt_zone, M_WAITOK);
+   nt = malloc(sizeof(*nt), M_NAMEITRACKER, M_WAITOK);
vhold(dp);
nt->dp = dp;
TAILQ_INSERT_TAIL(>ni_cap_tracker, nt, nm_link);
@@ -206,7 +204,7 @@ nameicap_cleanup(struct nameidata *ndp, bool clean_lat
TAILQ_FOREACH_SAFE(nt, >ni_cap_tracker, nm_link, nt1) {
TAILQ_REMOVE(>ni_cap_tracker, nt, nm_link);
vdrop(nt->dp);
-   uma_zfree(nt_zone, nt);
+   free(nt, M_NAMEITRACKER);
}
if (clean_latch && (ndp->ni_lcf & NI_LCF_LATCH) != 0) {
ndp->ni_lcf &= ~NI_LCF_LATCH;
___
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: r367280 - head/lib/libc/gen

2020-11-05 Thread Stefan Esser

Am 04.11.20 um 20:49 schrieb Konstantin Belousov:

On Mon, Nov 02, 2020 at 11:51:12PM +0100, Stefan Esser wrote:

Am 02.11.20 um 23:10 schrieb Konstantin Belousov:

On Mon, Nov 02, 2020 at 10:49:07PM +0100, Emmanuel Vadot wrote:

   I think that the first question we want to ask is : Do we want to
support LOCALBASE being different than /usr/local
   I honestly don't see any advantages of making it !=/usr/local/ and
before we start putting a lot of new/useless(for I guess 99% of our
user base) in the tree we should here why people are using /usr/pkg or
whatever weird location.
   If they have some good argument, then we should proceed further.


I would be delighted to be able to install _and use_ two independent
set of packages from the same base system install.  Without recursing
to jails, X forwarding, etc.


I understand the use case, and I agree this may be appropriate for
a development system.

But on a production system I'd never want to have a non-constant and
not generally applied LOCALBASE, at least not on a system that gives
a CLI to unprivileged users. Those could build their own copy of the
LOCALBASE tree (e.g. sym-linking all sub-trees that are to be kept
unmodified, replacing config files that policies that restrict the
user).

So how this makes attitude to the feature different ?  For me, dev machine
is my production box because what I do is development.  And for user that
need to run an old binary-only 32bit app which requires X libs, for instance,
it also would be a production.


Maybe I'm using the term in a too strict sense, but it has been
consistently used in this way in all the environments I have worked
in during the last few decades:

The term "production server" is generally applied to systems that
are operated by e.g. an admin team (e.g. ITIL operations processes).

You may consider your development work productive ;-), but that does
not make your development system a production system as found e.g.
in a server farm providing internal or public services.

One difference between test vs. production systems is
that development systems are generally operated under less tight
security obligations. You are in full control of the system and
could damage its integrity at will. It does not contain any data
you are not authorized to access.

The opposite is true of most "production systems", which need to
be protected against attacks on confidentiality, integrity, and
availability.


And if LOCALBASE is not compiled into binaries but somehow obtained
at run-time, there are a number of attacks I can imagine (e.g. by
LD_PRELOAD replace the sysctl() call in libc by your own version).

If somebody can LD_PRELOAD their into your process, it makes no sense to talk
about 'security'.


Yes, it takes some effort, but you could e.g. intercept fopen() calls
and manipulate the file name argument.

One of the suggested methods to make programs use a non-default
LOCALBASE was by means of an environment variable, and that makes it
trivial to have programs use an attacker-controlled value compare to
a LD_PRELOAD attack, though. This is acceptable on a development
system, but not on a production system, IMHO.

I'm afraid that sysctl() could be intercepted, if it was used to
determine a run-time value for LOCALBASE, but intercepting fopen()
could accomplish the same result even for hard-coded paths ...


In fact I would like to use /usr/local and e.g /usr/local-i386 on amd64
machine.  I am fine with me building both of them in my instance of
poudriere.


This is a use-case for architecture dependent path definitions (which
I have used some 30 years ago on HP-UX which supported 68k and HP-PA
on a single file system that way). Such a feature has been discussed
in FreeBSD multiple times over the decades ...


Ok, let replace /usr/local-i386 by /usr/local-11.4, if you so inclined.


Well, how about /compat/11.4-i386 then?

The HP-UX implementation used e.g. /usr/bin/@hppa/ ... and when a file
name lookup for /usr/bin/somefile did not find it in /usr/bin, it would
try /usr/bin/@ARCH (with ARCH = hppa or 68k, IIRC).

This is not exactly what you asked for, but our Linux emulation might
already contain everything required to allow a 32 bit environment to
exist on a 64 bit system. And by that I mean not the ability to execute
32 bin binaries that we already have, but e.g. to make path lookups by
such binaries consider the compat prefix first.

Ports built in the 32 bit environment should then find all their include
files, libraries ... under the appropriate /compat sub-tree.

That still leaves a few aspects undefined though, e.g. whether config
files in /etc or $LOCALBASE/etc will be different in the "emulation", or
shared with the base system. The same applies to /usr/share, which ought
to be architecture independent.

This could be an alternative layout to e.g. having 32 bit libraries in
/usr/lib32 (with both supported for backwards compatibility).

Regards, STefan


OpenPGP_signature
Description: OpenPGP 

svn commit: r367368 - head/sys/fs/tmpfs

2020-11-05 Thread Mateusz Guzik
Author: mjg
Date: Thu Nov  5 11:24:45 2020
New Revision: 367368
URL: https://svnweb.freebsd.org/changeset/base/367368

Log:
  tmpfs: reorder struct tmpfs_node to shrink it by 8 bytes
  
  The reduction (232 -> 224 bytes) allows UMA to fit one more item (17 -> 18)
  per slab as reported in vm.uma.TMPFS_node.keg.ipers.

Modified:
  head/sys/fs/tmpfs/tmpfs.h

Modified: head/sys/fs/tmpfs/tmpfs.h
==
--- head/sys/fs/tmpfs/tmpfs.h   Thu Nov  5 11:19:31 2020(r367367)
+++ head/sys/fs/tmpfs/tmpfs.h   Thu Nov  5 11:24:45 2020(r367368)
@@ -156,8 +156,10 @@ struct tmpfs_node {
 * when the node is removed from list and unlocked.
 */
LIST_ENTRY(tmpfs_node)  tn_entries; /* (m) */
-   booltn_attached;/* (m) */
 
+   /* Node identifier. */
+   ino_t   tn_id;  /* (c) */
+
/*
 * The node's type.  Any of 'VBLK', 'VCHR', 'VDIR', 'VFIFO',
 * 'VLNK', 'VREG' and 'VSOCK' is allowed.  The usage of vnode
@@ -166,8 +168,10 @@ struct tmpfs_node {
 */
enum vtype  tn_type;/* (c) */
 
-   /* Node identifier. */
-   ino_t   tn_id;  /* (c) */
+   /*
+* See the top comment. Reordered here to fill LP64 hole.
+*/
+   booltn_attached;/* (m) */
 
/*
 * Node's internal status.  This is used by several file system
___
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: r367280 - head/lib/libc/gen

2020-11-05 Thread Stefan Esser

Am 04.11.20 um 20:40 schrieb Baptiste Daroussin:

On Wed, Nov 04, 2020 at 11:04:37AM -0800, Rodney W. Grimes wrote:

For 25 years PREFIX has been rigidly a part of the ports infustructure,
why is it that the BASE system has been allowed to de-evolve from this
concept as documented and REQUIRED by:

https://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/porting-prefix.html


I again assert at one time the base system was clean of this,
it has regressed and needs to be fixed.  That fix should restore
the independence of PREFIX.  If 30k ported pieces of software can
do it why can't the base system do it?

Those ports do not require a recompile, why should the base system?


I am just reacting on that phrase, you do really think the ports do not require
a rebuild to be able to relocate from a PREFIX to another? this is a myth!

ports support being built with another prefix than localbase but that is all it
supports.

There has been a flase claim for years that relocating work, but beside the
tools proposing the feature it never worked, or to be fait only on some very
specific port.

But it is just an impossible goal to achieve otherwise as for example all the
path which gets hardcoded at build time depending on the prefix will end up in
the binary looking for resources in a hardcoded prefix at runtime and so fail if
you relocate the package, for example its datadir.


Adding to Baptiste's reply:

While ports have often contained hard-coded dependencies on the PREFIX
used at build time, the changes currently being applied to the base 
system would actually ease having ports that adapt to a different prefix

at run-time.

See Scott Longs proposed getlocalbase() function (D27022), which could
be used by ports to derive at run-time the (currently hard-coded) path
in a standardized way (with fall-back to _PATH_LOCALBASE or /usr/local).

There are potential security issues with a run-time configured PREFIX
though, e.g. if it is used to locate files that contain an admin-
configured policy meant to restrict unprivileged users. Only hard-coded
paths in the respective binaries protect against attacks that manipulate
a dynamic prefix at run-time in such a szenario.

But as long as not all supported versions of FreeBSD support the
getlocalbase() function, it cannot be assumed to be generally available
for use in ports.

And since it will take some time for the currently supported releases to
reach EoL, ports could only conditionally include such a feature when
built on and for a system known to have getlocalbase().

We are in the process of creating the infrastructure that may one day
allow ports to automatically adapt to the PREFIX in use on the system
they are installed on, but we are not there, yet.

Regards, STefan


OpenPGP_signature
Description: OpenPGP digital signature


svn commit: r367365 - head/sys/arm64/arm64

2020-11-05 Thread Andrew Turner
Author: andrew
Date: Thu Nov  5 09:55:55 2020
New Revision: 367365
URL: https://svnweb.freebsd.org/changeset/base/367365

Log:
  Stop trying to bounce in memory allocated by bus dma
  
  Memory allocated by bus_dmamem_alloc will take into account any alignment
  requirements of the CPU it's running on. Stop trying to bounce in this case
  as there is no bounce zone allocated.
  
  Reported by:  manu, tuexen
  Tested by:manu
  Sponsored by: Innovate UK

Modified:
  head/sys/arm64/arm64/busdma_bounce.c

Modified: head/sys/arm64/arm64/busdma_bounce.c
==
--- head/sys/arm64/arm64/busdma_bounce.cThu Nov  5 08:58:21 2020
(r367364)
+++ head/sys/arm64/arm64/busdma_bounce.cThu Nov  5 09:55:55 2020
(r367365)
@@ -206,6 +206,10 @@ might_bounce(bus_dma_tag_t dmat, bus_dmamap_t map, bus
 bus_size_t size)
 {
 
+   /* Memory allocated by bounce_bus_dmamem_alloc won't bounce */
+   if ((map->flags & DMAMAP_FROM_DMAMEM) != 0)
+   return (false);
+
if ((dmat->bounce_flags & BF_COULD_BOUNCE) != 0)
return (true);
 
___
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: r367364 - head/usr.bin/calendar

2020-11-05 Thread Stefan Eßer
Author: se
Date: Thu Nov  5 08:58:21 2020
New Revision: 367364
URL: https://svnweb.freebsd.org/changeset/base/367364

Log:
  Restrict locale settings to the file they occur in
  
  This prevents LANG= in an included file from affecting the interpretation
  of month and day names in the including file.
  
  Make the internal pre-processor accept white space between the "#" at
  the start of the line and the keyword for better compatibility with cpp.
  
  Add support for the cpp keywords #warning and #error.
  
  MFC after:3 days

Modified:
  head/usr.bin/calendar/calendar.1
  head/usr.bin/calendar/calendar.h
  head/usr.bin/calendar/events.c
  head/usr.bin/calendar/io.c

Modified: head/usr.bin/calendar/calendar.1
==
--- head/usr.bin/calendar/calendar.1Thu Nov  5 07:59:05 2020
(r367363)
+++ head/usr.bin/calendar/calendar.1Thu Nov  5 08:58:21 2020
(r367364)
@@ -28,7 +28,7 @@
 .\" @(#)calendar.1  8.1 (Berkeley) 6/29/93
 .\" $FreeBSD$
 .\"
-.Dd November 4, 2020
+.Dd November 5, 2020
 .Dt CALENDAR 1
 .Os
 .Sh NAME
@@ -199,13 +199,14 @@ file is preprocessed by a limited subset of
 internally, allowing the inclusion of shared files such as
 lists of company holidays or meetings.
 This limited subset consists of \fB#include\fR, \fB#define\fR,
-\fB#undef\fR, \fB#ifdef\fR, \fB#ifndef\fR, and \fB#else\fR.
+\fB#undef\fR, \fB#ifdef\fR, \fB#ifndef\fR, \fB#else\fR, \fB#warning\fR,
+and \fB#error\fR.
 .Pp
 Conditions can be nested and the consistency of opening and closing
 instructions is checked.
 Only the first word after #define is used as the name of the
 condition variable being defined.
-More than word following #ifdef, #ifndef, or #undef is a ayntax
+More than word following #ifdef, #ifndef, or #undef is considered a syntax
 error, since names cannot include white-space.
 Included files are parsed in a global scope with regard to the condition
 variables being defined or tested therein.

Modified: head/usr.bin/calendar/calendar.h
==
--- head/usr.bin/calendar/calendar.hThu Nov  5 07:59:05 2020
(r367363)
+++ head/usr.bin/calendar/calendar.hThu Nov  5 08:58:21 2020
(r367364)
@@ -130,7 +130,6 @@ struct event {
int month;
int day;
int var;
-   char*date;
char*text;
char*extra;
struct event *next;

Modified: head/usr.bin/calendar/events.c
==
--- head/usr.bin/calendar/events.c  Thu Nov  5 07:59:05 2020
(r367363)
+++ head/usr.bin/calendar/events.c  Thu Nov  5 08:58:21 2020
(r367364)
@@ -39,7 +39,6 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
-#include 
 
 static iconv_t conv = (iconv_t)-1;
 static char *currentEncoding = NULL;
@@ -204,13 +203,7 @@ event_print_all(FILE *fp)
struct tm tm;
char dbuf[80];
static int d_first;
-   const char *lang;
 
-   lang = getenv("LANG");
-   if (lang == NULL)
-   lang = "C";
-   if (setlocale(LC_ALL, lang) == NULL)
-   (void)setlocale(LC_ALL, "C");
d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
 
while (walkthrough_dates() != 0) {

Modified: head/usr.bin/calendar/io.c
==
--- head/usr.bin/calendar/io.c  Thu Nov  5 07:59:05 2020(r367363)
+++ head/usr.bin/calendar/io.c  Thu Nov  5 08:58:21 2020(r367364)
@@ -172,6 +172,16 @@ cal_path(void)
 #defineWARN1(format, arg1)\
warnx(format " in %s line %d", arg1, cal_path(), cal_line)
 
+static char*
+cmptoken(char *line, const char* token)
+{
+   char len = strlen(token);
+
+   if (strncmp(line, token, len) != 0)
+   return NULL;
+   return (line + len);
+}
+
 static int
 token(char *line, FILE *out, int *skip, int *unskip)
 {
@@ -181,7 +191,10 @@ token(char *line, FILE *out, int *skip, int *unskip)
const char *this_cal_file;
int this_cal_line;
 
-   if (strncmp(line, "endif", 5) == 0) {
+   while (isspace(*line))
+   line++;
+
+   if (cmptoken(line, "endif")) {
if (*skip + *unskip == 0) {
WARN0("#endif without prior #ifdef or #ifndef");
return (T_ERR);
@@ -194,8 +207,8 @@ token(char *line, FILE *out, int *skip, int *unskip)
return (T_OK);
}
 
-   if (strncmp(line, "ifdef", 5) == 0) {
-   walk = line + 5;
+   walk = cmptoken(line, "ifdef");
+   if (walk != NULL) {
sep = trimlr();
 
if (*walk == '\0') {
@@ -217,8 +230,8 @@ token(char *line, FILE *out, int *skip, int *unskip)
return (T_OK);
}
 
-   if (strncmp(line, "ifndef", 6) ==