From nils.goroll at uplex.de Wed Dec 4 12:26:08 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Wed, 4 Dec 2024 12:26:08 +0000 (UTC) Subject: [master] c57f4405a vcc: refactor passing the function's cname to argument expressions Message-ID: <20241204122608.E88D012321F@lists.varnish-cache.org> commit c57f4405a450f89c905da3ef8327b64c1d2fcb8d Author: Nils Goroll Date: Wed Dec 4 13:21:44 2024 +0100 vcc: refactor passing the function's cname to argument expressions We had (ab)used the cname member of struct func_arg to pass the name of the function to have it available for constructing the C name for enum arguments. Make this explicit diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c index 420898120..1e3a6e054 100644 --- a/lib/libvcc/vcc_expr.c +++ b/lib/libvcc/vcc_expr.c @@ -453,20 +453,20 @@ struct func_arg { VTAILQ_ENTRY(func_arg) list; }; -static void -vcc_do_enum(struct vcc *tl, struct func_arg *fa, int len, const char *ptr) +static struct expr * +vcc_do_enum(struct vcc *tl, const char *cfunc, int len, const char *ptr) { const char *r; (void)tl; - r = strchr(fa->cname, '.'); + r = strchr(cfunc, '.'); AN(r); - fa->result = vcc_mk_expr(VOID, "*%.*s.enum_%.*s", - (int)(r - fa->cname), fa->cname, len, ptr); + return (vcc_mk_expr(VOID, "*%.*s.enum_%.*s", + (int)(r - cfunc), cfunc, len, ptr)); } static void -vcc_do_arg(struct vcc *tl, struct func_arg *fa) +vcc_do_arg(struct vcc *tl, const char *cfunc, struct func_arg *fa) { struct expr *e2; struct vjsn_val *vv; @@ -485,7 +485,7 @@ vcc_do_arg(struct vcc *tl, struct func_arg *fa) vcc_ErrWhere(tl, tl->t); return; } - vcc_do_enum(tl, fa, PF(tl->t)); + fa->result = vcc_do_enum(tl, cfunc, PF(tl->t)); SkipToken(tl, ID); } else { if (fa->type == SUB) @@ -551,7 +551,6 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv, assert(vjsn_is_array(vv)); fa = calloc(1, sizeof *fa); AN(fa); - fa->cname = cfunc; VTAILQ_INSERT_TAIL(&head, fa, list); vvp = VTAILQ_FIRST(&vv->children); @@ -594,7 +593,7 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv, if (t1->tok == '=') break; } - vcc_do_arg(tl, fa); + vcc_do_arg(tl, cfunc, fa); if (tl->err) VSB_printf(tl->sb, "Expected argument: %s %s\n\n", fa->type->name, @@ -626,7 +625,7 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv, } vcc_NextToken(tl); SkipToken(tl, '='); - vcc_do_arg(tl, fa); + vcc_do_arg(tl, cfunc, fa); ERRCHK(tl); if (tl->t->tok == ')') break; @@ -649,7 +648,7 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv, e1 = vcc_expr_edit(tl, e1->fmt, ssa, e1, NULL); } if (fa->result == NULL && fa->type == ENUM && fa->val != NULL) - vcc_do_enum(tl, fa, strlen(fa->val), fa->val); + fa->result = vcc_do_enum(tl, cfunc, strlen(fa->val), fa->val); if (fa->result == NULL && fa->val != NULL) fa->result = vcc_mk_expr(fa->type, "%s", fa->val); if (fa->result != NULL && sa != NULL) { From nils.goroll at uplex.de Wed Dec 4 14:55:06 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Wed, 4 Dec 2024 14:55:06 +0000 (UTC) Subject: [master] 311aaf9dc vdef: introduce v_counted_by_(field) Message-ID: <20241204145506.7EA031003EF@lists.varnish-cache.org> commit 311aaf9dca4d22edac9f5308e695a2a727b30c5f Author: Asad Sajjad Ahmed Date: Mon Jan 15 14:29:46 2024 +0100 vdef: introduce v_counted_by_(field) A new attribute can be used for flexible arrays to make the compiler smarter: - https://clang.llvm.org/docs/AttributeReference.html#counted-by - https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628459.html This would improve the array bound sanitizer. Signed-off-by: Asad Sajjad Ahmed diff --git a/include/vdef.h b/include/vdef.h index 95f342cb6..1f3bbec43 100644 --- a/include/vdef.h +++ b/include/vdef.h @@ -247,6 +247,16 @@ int __llvm_gcov_flush(void); # define v_cold_ #endif +#if defined __has_attribute +# if __has_attribute(counted_by) +# define v_counted_by_(field) __attribute__((counted_by(field))) +# endif +#endif + +#ifndef v_counted_by_ +# define v_counted_by_(field) +#endif + /* VTIM API overhaul WIP */ typedef double vtim_mono; typedef double vtim_real; From nils.goroll at uplex.de Wed Dec 4 14:55:06 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Wed, 4 Dec 2024 14:55:06 +0000 (UTC) Subject: [master] 6f374e3d5 tree-wide: apply v_counted_by_(field) Message-ID: <20241204145506.A4DB51003F2@lists.varnish-cache.org> commit 6f374e3d59c6b6ba6dd433ac7270c32651e44bb5 Author: Asad Sajjad Ahmed Date: Mon Jan 15 14:31:49 2024 +0100 tree-wide: apply v_counted_by_(field) Committer edit: Removed one offending case and fixed another, see #4039 Signed-off-by: Asad Sajjad Ahmed diff --git a/bin/varnishd/hpack/vhp_gen_hufdec.c b/bin/varnishd/hpack/vhp_gen_hufdec.c index a69d1df83..121e897d0 100644 --- a/bin/varnishd/hpack/vhp_gen_hufdec.c +++ b/bin/varnishd/hpack/vhp_gen_hufdec.c @@ -72,7 +72,7 @@ struct tbl { unsigned idx; unsigned lvl; unsigned p_idx; - struct cod e[]; + struct cod e[] v_counted_by_(n); }; static struct tbl * diff --git a/bin/varnishd/proxy/cache_proxy_proto.c b/bin/varnishd/proxy/cache_proxy_proto.c index 066be91d3..f8e317a0c 100644 --- a/bin/varnishd/proxy/cache_proxy_proto.c +++ b/bin/varnishd/proxy/cache_proxy_proto.c @@ -52,7 +52,7 @@ struct vpx_tlv { unsigned magic; #define VPX_TLV_MAGIC 0xdeb9a4a5 unsigned len; - char tlv[]; + char tlv[] v_counted_by_(len); }; static inline int diff --git a/include/vsl_priv.h b/include/vsl_priv.h index 500aac584..1d8ae1d28 100644 --- a/include/vsl_priv.h +++ b/include/vsl_priv.h @@ -63,5 +63,5 @@ struct VSL_head { ssize_t segsize; unsigned segment_n; ssize_t offset[VSL_SEGMENTS]; - uint32_t log[]; + uint32_t log[] v_counted_by_(segment_n); }; diff --git a/lib/libvarnish/vte.c b/lib/libvarnish/vte.c index cad557b67..0ceb7d02f 100644 --- a/lib/libvarnish/vte.c +++ b/lib/libvarnish/vte.c @@ -62,7 +62,8 @@ struct vte { int f_sz; /* input field size */ int f_cnt; /* actual number of fields */ int f_maxcnt; /* maximum number of fields */ - int f_maxsz[]; /* maximum size per field */ + int f_maxsz[] + v_counted_by_(f_maxcnt); /* maximum size per field */ }; struct vte * From nils.goroll at uplex.de Thu Dec 5 11:14:10 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Thu, 5 Dec 2024 11:14:10 +0000 (UTC) Subject: [master] a1c26cab8 vmod_debug: Add WS_Alloc() assertions Message-ID: <20241205111410.4D1FB10450A@lists.varnish-cache.org> commit a1c26cab87670d4b6b2deea52505f4dc6626b9c6 Author: Nils Goroll Date: Thu Dec 5 11:56:36 2024 +0100 vmod_debug: Add WS_Alloc() assertions Coverity CIDs 1633177 1633176 diff --git a/vmod/vmod_debug_filters.c b/vmod/vmod_debug_filters.c index 53777996d..464e95458 100644 --- a/vmod/vmod_debug_filters.c +++ b/vmod/vmod_debug_filters.c @@ -585,6 +585,7 @@ static const struct vdp xyzzy_vdp_chkcrc32 = { p->priv = WS_Alloc(ws, sizeof *cfg); \ p->len = sizeof *cfg; \ } \ + AN(p->priv); \ cfg = p->priv; \ INIT_OBJ(cfg, magic); \ if (mode_e == VENUM(log)) \ From dridi.boukelmoune at gmail.com Tue Dec 10 17:54:11 2024 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Tue, 10 Dec 2024 17:54:11 +0000 (UTC) Subject: [master] b825f55f3 vrt_vcl: Avoid retirement of assigned director Message-ID: <20241210175411.4D729124B81@lists.varnish-cache.org> commit b825f55f348595cfc24f5eee92b86ecf2e880924 Author: Dridi Boukelmoune Date: Mon Dec 9 18:43:01 2024 +0100 vrt_vcl: Avoid retirement of assigned director Consider the following VCL statement: set bereq.backend = bereq.backend; The director's refcount will be decremented before it is incremented. If that bereq.backend was holding the last reference of a dynamic backend, the backend is retired before acquiring a new reference. While this scenario is highly unlikely, we cannot discard the risk of assigning a director to a destination that already held a reference to the same director. diff --git a/bin/varnishd/cache/cache_vrt_vcl.c b/bin/varnishd/cache/cache_vrt_vcl.c index 82e6e10a5..33ba68241 100644 --- a/bin/varnishd/cache/cache_vrt_vcl.c +++ b/bin/varnishd/cache/cache_vrt_vcl.c @@ -336,6 +336,8 @@ VRT_Assign_Backend(VCL_BACKEND *dst, VCL_BACKEND src) AN(dst); CHECK_OBJ_ORNULL((*dst), DIRECTOR_MAGIC); CHECK_OBJ_ORNULL(src, DIRECTOR_MAGIC); + if (*dst == src) + return; if (*dst != NULL) { vdir = (*dst)->vdir; CHECK_OBJ_NOTNULL(vdir, VCLDIR_MAGIC); From nils.goroll at uplex.de Fri Dec 13 10:08:12 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Fri, 13 Dec 2024 10:08:12 +0000 (UTC) Subject: [master] 7098d0482 vcl_vrt: When assigning directors, first reference, then dereference Message-ID: <20241213100812.66E26110C41@lists.varnish-cache.org> commit 7098d0482d9508f47935641b9a559644aad27489 Author: Nils Goroll Date: Fri Dec 13 11:04:35 2024 +0100 vcl_vrt: When assigning directors, first reference, then dereference Dridis previous commit b825f55f348595cfc24f5eee92b86ecf2e880924 made me realize that there exists another case with the same effect: *dst could be the director holding the last reference to src (for example, when src is a backend of *dst), so we should reference first, then dereference. diff --git a/bin/varnishd/cache/cache_vrt_vcl.c b/bin/varnishd/cache/cache_vrt_vcl.c index 33ba68241..264ad3446 100644 --- a/bin/varnishd/cache/cache_vrt_vcl.c +++ b/bin/varnishd/cache/cache_vrt_vcl.c @@ -332,18 +332,15 @@ void VRT_Assign_Backend(VCL_BACKEND *dst, VCL_BACKEND src) { struct vcldir *vdir; + VCL_BACKEND tmp; AN(dst); CHECK_OBJ_ORNULL((*dst), DIRECTOR_MAGIC); CHECK_OBJ_ORNULL(src, DIRECTOR_MAGIC); if (*dst == src) return; - if (*dst != NULL) { - vdir = (*dst)->vdir; - CHECK_OBJ_NOTNULL(vdir, VCLDIR_MAGIC); - if (!(vdir->flags & VDIR_FLG_NOREFCNT)) - (void)vcldir_deref(vdir); - } + tmp = *dst; + *dst = src; if (src != NULL) { vdir = src->vdir; CHECK_OBJ_NOTNULL(vdir, VCLDIR_MAGIC); @@ -354,7 +351,12 @@ VRT_Assign_Backend(VCL_BACKEND *dst, VCL_BACKEND src) Lck_Unlock(&vdir->dlck); } } - *dst = src; + if (tmp != NULL) { + vdir = tmp->vdir; + CHECK_OBJ_NOTNULL(vdir, VCLDIR_MAGIC); + if (!(vdir->flags & VDIR_FLG_NOREFCNT)) + (void)vcldir_deref(vdir); + } } void From nils.goroll at uplex.de Fri Dec 13 10:10:06 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Fri, 13 Dec 2024 10:10:06 +0000 (UTC) Subject: [master] 2c761ac79 fix: always wake the new head of the waiting queue Message-ID: <20241213101006.B0158110EC5@lists.varnish-cache.org> commit 2c761ac7952f298f06876e17b99e9da141ecb7c3 Author: Karl von Randow Date: Thu Nov 21 13:44:37 2024 +1300 fix: always wake the new head of the waiting queue Previously multiple threads could signal completion to one waiting queue head, resulting in underuse of available backend connections. diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index d3a98ac56..c4f64f42e 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -246,6 +246,12 @@ vbe_dir_getfd(VRT_CTX, struct worker *wrk, VCL_BACKEND dir, struct backend *bp, } if (cw->cw_state != CW_BE_BUSY) bp->n_conn++; + + if (!VTAILQ_EMPTY(&bp->cw_head) && !BE_BUSY(bp)) { + /* Signal the new head of the waiting queue */ + vbe_connwait_signal_locked(bp); + } + Lck_Unlock(bp->director->mtx); if (cw->cw_state == CW_BE_BUSY) { From nils.goroll at uplex.de Fri Dec 13 10:42:06 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Fri, 13 Dec 2024 10:42:06 +0000 (UTC) Subject: [master] febfce2ad vmod_debug: Fix v1l workspace for reembarking transport demo Message-ID: <20241213104206.66FC81121AB@lists.varnish-cache.org> commit febfce2ad87d218c6345e343fd712442e86b6c15 Author: Nils Goroll Date: Fri Dec 13 11:39:19 2024 +0100 vmod_debug: Fix v1l workspace for reembarking transport demo Clearly the v1l can not live on the worker stack. Noticed thanks to vtest. Ref 0cfd6cd06e186e0a36094a57294124f2f1cf2cfa diff --git a/vmod/vmod_debug_transports.c b/vmod/vmod_debug_transports.c index 90bd0a48b..8a60a5a62 100644 --- a/vmod/vmod_debug_transports.c +++ b/vmod/vmod_debug_transports.c @@ -80,7 +80,7 @@ dbg_deliver(struct req *req, int sendbody) CHECK_OBJ_NOTNULL(req->wrk, WORKER_MAGIC); - v1l = V1L_Open(req->wrk->aws, &req->sp->fd, req->vsl, + v1l = V1L_Open(req->ws, &req->sp->fd, req->vsl, req->t_prev + SESS_TMO(req->sp, send_timeout), cache_param->http1_iovs); From nils.goroll at uplex.de Fri Dec 13 10:52:06 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Fri, 13 Dec 2024 10:52:06 +0000 (UTC) Subject: [master] e3aa61339 vtc: try to stabilize b84 Message-ID: <20241213105206.64F03112814@lists.varnish-cache.org> commit e3aa6133952b898c07098c918585778ee4b4365e Author: Nils Goroll Date: Fri Dec 13 11:50:46 2024 +0100 vtc: try to stabilize b84 from vtest: ** top === process p1 -stop -wait **** dT 1.431 **** p1 Sent signal 15 **** p1 stdout read 0 **** p1 stderr read 0 ** p1 WAIT4 pid=26430 status=0x000f (user 0.004683 sys 0.009366) ... **** top shell_cmd|\ttest ! -f "/root/VT/_vtest_tmp/vtc.26358.31f097e1"/v2/_.secret **** dT 2.455 **** top shell_status = 0x0001 ---- top shell_exit not as expected: got 0x0001 wanted 0x0000 Not exactly sure why we see a status != 0 here, but maybe the kill is too early? diff --git a/bin/varnishtest/tests/b00084.vtc b/bin/varnishtest/tests/b00084.vtc index 6797d28e6..d3d5e17f9 100644 --- a/bin/varnishtest/tests/b00084.vtc +++ b/bin/varnishtest/tests/b00084.vtc @@ -35,6 +35,8 @@ shell -match _.secret { find "${tmpdir}"/v2/_.secret -perm 0640 -size 256c } +shell "varnishadm -n ${tmpdir}/v2 ping" + process p1 -stop -wait shell {