From owner-freebsd-current@freebsd.org Fri Nov 16 14:47:55 2018 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F21881134A61 for ; Fri, 16 Nov 2018 14:47:54 +0000 (UTC) (envelope-from sg@efficientip.com) Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C892D81B7E for ; Fri, 16 Nov 2018 14:47:53 +0000 (UTC) (envelope-from sg@efficientip.com) Received: by mail-ed1-x544.google.com with SMTP id d3so19291750edx.7 for ; Fri, 16 Nov 2018 06:47:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientip.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Py80QWIm8DRpH4q0Fyy8ySd/fDXap63wnITcRabBi3M=; b=kUvME7fJQqaNjbqHIAAwdyojzGfeOaAL/49LwFecSPy3DMNxtATw+ZziQ0mVgDk5K5 ne2UGuLyEHTI511QCrbmRiyKYo8P+9SEhxwt2U66aA8yOQ0mULzKNdEZzw18uG9e8Z+f IYOPXDysk+q/EtkL1BGtCc1YCgBk2UuQShQq8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Py80QWIm8DRpH4q0Fyy8ySd/fDXap63wnITcRabBi3M=; b=TdmJ0S//yL4dWURzrJQMgTe81xA+87F5aPSnttaECTdDitK4lDXfUh9tbpHN9tdzVr BHt1nDf/fQTZ4vjflkknfNmWzV7DxqyM4Ar9BebY19FbbwgpGZubISELC106VF3eCIjs Njg22YjN6vJbGrMKszE3ylPL5cAFq29WIbNG93dTgExc8mucEyjE7r1oa6yILoDftn2m c1+aovEkFHgrvVPbmbFOWeJCaXX5LHS5KvoVkWEXHhgOObN2JEsA+ftGLP3ODooBQ4Ga NqLW8q951dkc5W9Z/et0ytlmVCOD036cpc6vSaaI7lc4n6f6y30bJgd/r/zoUi4gT17q iExQ== X-Gm-Message-State: AGRZ1gJfrOWOmzaC3/0bHCHuxv1uAGTqc3FhUIX9QaMeuChZY60S7g1e 2YxBrcLzK8IBffy+6PxDF4LTeN3K32UjB0Hb2HK/vg== X-Google-Smtp-Source: AJdET5eonWfzRpUgnuZiXTOtSdl5nEYZXO73N4e1jJWDnvWkI4WrOSckFKnNT1+xn9knyiMuygVmkGOasVTvoysosZ8= X-Received: by 2002:a17:906:64cb:: with SMTP id p11-v6mr9007842ejn.181.1542379672571; Fri, 16 Nov 2018 06:47:52 -0800 (PST) MIME-Version: 1.0 References: <20181107043503.GB30861@raichu> <20181115221019.GA2514@raichu> In-Reply-To: <20181115221019.GA2514@raichu> From: Sylvain GALLIANO Date: Fri, 16 Nov 2018 15:47:39 +0100 Message-ID: Subject: Re: Panic on kern_event.c To: markj@freebsd.org Cc: freebsd-current@freebsd.org X-Rspamd-Queue-Id: C892D81B7E X-Spamd-Result: default: False [-3.87 / 40.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; R_DKIM_ALLOW(-0.20)[efficientip.com]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_SHORT(-0.92)[-0.924,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-current@freebsd.org]; TO_DN_NONE(0.00)[]; DMARC_NA(0.00)[efficientip.com]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[efficientip.com:+]; RCPT_COUNT_TWO(0.00)[2]; MIME_BASE64_TEXT(0.10)[]; RCVD_IN_DNSWL_NONE(0.00)[4.4.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.5.4.1.0.0.a.2.list.dnswl.org : 127.0.5.0]; R_SPF_NA(0.00)[]; MX_GOOD(-0.01)[alt1.aspmx.l.google.com,aspmx.l.google.com,aspmx5.googlemail.com,aspmx4.googlemail.com,aspmx3.googlemail.com,alt2.aspmx.l.google.com,aspmx2.googlemail.com]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; IP_SCORE(-0.74)[ip: (0.09), ipnet: 2a00:1450::/32(-1.90), asn: 15169(-1.81), country: US(-0.10)]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; RCVD_COUNT_TWO(0.00)[2] X-Rspamd-Server: mx1.freebsd.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Nov 2018 14:47:55 -0000 Le jeu. 15 nov. 2018 =C3=A0 23:10, Mark Johnston a =C3= =A9crit : > On Thu, Nov 08, 2018 at 05:05:03PM +0100, Sylvain GALLIANO wrote: > > Hi, > > > > I replaced > > << printf("XXX knote %p already in tailq status:%x kq_count:%d [%p %p= ] > > > %u\n",kn,kn->kn_status,kq->kq_count,kn->kn_tqe.tqe_next,kn->kn_tqe.tqe_pr= ev,__LINE__); > > by > > >> panic("XXX knote %p already in tailq status:%x kq_count:%d [%p %p] > > > %u\n",kn,kn->kn_status,kq->kq_count,kn->kn_tqe.tqe_next,kn->kn_tqe.tqe_pr= ev,__LINE__); > > > > Here is the stack during panic: > > panic: XXX knote 0xfffff801e1c6ddc0 already in tailq status:1 kq_count= :2 > > [0 0xfffff8000957a978] 2671 > > > > cpuid =3D 0 > > time =3D 1541688832 > > KDB: stack backtrace: > > db_trace_self_wrapper() at db_trace_self_wrapper+0x2c/frame > > 0xfffffe0412258fd0 > > kdb_backtrace() at kdb_backtrace+0x53/frame 0xfffffe04122590a0 > > vpanic() at vpanic+0x277/frame 0xfffffe0412259170 > > doadump() at doadump/frame 0xfffffe04122591d0 > > knote_enqueue() at knote_enqueue+0xf2/frame 0xfffffe0412259210 > > kqueue_register() at kqueue_register+0xaed/frame 0xfffffe0412259340 > > kqueue_kevent() at kqueue_kevent+0x13c/frame 0xfffffe04122595b0 > > kern_kevent_fp() at kern_kevent_fp+0x66/frame 0xfffffe0412259610 > > kern_kevent() at kern_kevent+0x17f/frame 0xfffffe0412259700 > > kern_kevent_generic() at kern_kevent_generic+0xfe/frame > 0xfffffe0412259780 > > sys_kevent() at sys_kevent+0xaa/frame 0xfffffe0412259810 > > syscallenter() at syscallenter+0x4e3/frame 0xfffffe04122598f0 > > amd64_syscall() at amd64_syscall+0x1b/frame 0xfffffe04122599b0 > > fast_syscall_common() at fast_syscall_common+0x101/frame > 0xfffffe04122599b0 > > --- syscall (560, FreeBSD ELF64, sys_kevent), rip =3D 0x406e3bfa, rsp = =3D > > 0x7fffdf7e9db8, rbp =3D 0x7fffdf7e9e00 --- > > KDB: enter: panic > > > > > > you can get kernel.debug + vmcore at: > > > https://drive.google.com/drive/folders/1MbqJQm12-KOYDbb4-9uNRTnAdsNqLaIP?= usp=3Dsharing > > Could you please give the following patch a try? > > If possible, could you also ktrace one of the active syslog-ng processes > for some time, perhaps 15 seconds, and share the kdump? I have been > trying to reproduce the problem without any luck. > > diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c > index d9c670e29d60..9ef7c53361bf 100644 > --- a/sys/kern/kern_event.c > +++ b/sys/kern/kern_event.c > @@ -224,6 +224,7 @@ SYSCTL_UINT(_kern, OID_AUTO, kq_calloutmax, CTLFLAG_R= W, > #define KQ_LOCK(kq) do { \ > mtx_lock(&(kq)->kq_lock); \ > } while (0) > +#define KQ_LOCKPTR(kq) (&(kq)->kq_lock) > #define KQ_FLUX_WAKEUP(kq) do { > \ > if (((kq)->kq_state & KQ_FLUXWAIT) =3D=3D KQ_FLUXWAIT) { = \ > (kq)->kq_state &=3D ~KQ_FLUXWAIT; = \ > @@ -687,8 +688,11 @@ filt_timerexpire(void *knx) > struct kq_timer_cb_data *kc; > > kn =3D knx; > + KQ_OWNED(kn->kn_kq); > kn->kn_data++; > - KNOTE_ACTIVATE(kn, 0); /* XXX - handle locking */ > + > + if (!kn_in_flux(kn) || (kn->kn_status & KN_SCAN) !=3D 0) > + KNOTE_ACTIVATE(kn, 1); > > if ((kn->kn_flags & EV_ONESHOT) !=3D 0) > return; > @@ -753,7 +757,7 @@ filt_timerattach(struct knote *kn) > kn->kn_flags |=3D EV_CLEAR; /* automatically set */ > kn->kn_status &=3D ~KN_DETACHED; /* knlist_add clears it= */ > kn->kn_ptr.p_v =3D kc =3D malloc(sizeof(*kc), M_KQUEUE, M_WAITOK)= ; > - callout_init(&kc->c, 1); > + callout_init_mtx(&kc->c, KQ_LOCKPTR(kn->kn_kq), 0); > filt_timerstart(kn, to); > > return (0); > @@ -772,8 +776,10 @@ filt_timerstart(struct knote *kn, sbintime_t to) > kc->next =3D to + sbinuptime(); > kc->to =3D to; > } > + KQ_LOCK(kn->kn_kq); > callout_reset_sbt_on(&kc->c, kc->next, 0, filt_timerexpire, kn, > PCPU_GET(cpuid), C_ABSOLUTE); > + KQ_UNLOCK(kn->kn_kq); > } > > static void > @@ -826,7 +832,6 @@ filt_timertouch(struct knote *kn, struct kevent *kev, > u_long type) > KQ_LOCK(kq); > if (kn->kn_status & KN_QUEUED) > knote_dequeue(kn); > - > kn->kn_status &=3D ~KN_ACTIVE; > kn->kn_data =3D 0; > KQ_UNLOCK(kq); > @@ -1843,6 +1848,7 @@ kqueue_scan(struct kqueue *kq, int maxevents, struc= t > kevent_copyops *k_ops, > } > > TAILQ_INSERT_TAIL(&kq->kq_head, marker, kn_tqe); > + marker->kn_status |=3D KN_QUEUED; > influx =3D 0; > while (count) { > KQ_OWNED(kq); > @@ -1861,8 +1867,10 @@ kqueue_scan(struct kqueue *kq, int maxevents, > struct kevent_copyops *k_ops, > } > > TAILQ_REMOVE(&kq->kq_head, kn, kn_tqe); > + KASSERT((kn->kn_status & KN_QUEUED) !=3D 0, > + ("knote %p not queued", kn)); > + kn->kn_status &=3D ~KN_QUEUED; > if ((kn->kn_status & KN_DISABLED) =3D=3D KN_DISABLED) { > - kn->kn_status &=3D ~KN_QUEUED; > kq->kq_count--; > continue; > } > @@ -1876,7 +1884,6 @@ kqueue_scan(struct kqueue *kq, int maxevents, struc= t > kevent_copyops *k_ops, > ("knote %p is unexpectedly in flux", kn)); > > if ((kn->kn_flags & EV_DROP) =3D=3D EV_DROP) { > - kn->kn_status &=3D ~KN_QUEUED; > kn_enter_flux(kn); > kq->kq_count--; > KQ_UNLOCK(kq); > @@ -1888,7 +1895,6 @@ kqueue_scan(struct kqueue *kq, int maxevents, struc= t > kevent_copyops *k_ops, > KQ_LOCK(kq); > continue; > } else if ((kn->kn_flags & EV_ONESHOT) =3D=3D EV_ONESHOT)= { > - kn->kn_status &=3D ~KN_QUEUED; > kn_enter_flux(kn); > kq->kq_count--; > KQ_UNLOCK(kq); > @@ -1910,8 +1916,8 @@ kqueue_scan(struct kqueue *kq, int maxevents, struc= t > kevent_copyops *k_ops, > if (kn->kn_fop->f_event(kn, 0) =3D=3D 0) { > KQ_LOCK(kq); > KQ_GLOBAL_UNLOCK(&kq_global, haskqglobal)= ; > - kn->kn_status &=3D ~(KN_QUEUED | KN_ACTIV= E | > - KN_SCAN); > + /* XXXMJ races with EVFILT_TIMER > activation. */ > + kn->kn_status &=3D ~(KN_ACTIVE | KN_SCAN)= ; > kn_leave_flux(kn); > kq->kq_count--; > kn_list_unlock(knl); > @@ -1937,11 +1943,13 @@ kqueue_scan(struct kqueue *kq, int maxevents, > struct kevent_copyops *k_ops, > } > if (kn->kn_flags & EV_DISPATCH) > kn->kn_status |=3D KN_DISABLED; > - kn->kn_status &=3D ~(KN_QUEUED | KN_ACTIV= E); > + kn->kn_status &=3D ~KN_ACTIVE; > kq->kq_count--; > - } else > + } else if ((kn->kn_status & KN_QUEUED) =3D=3D 0) = { > + kn->kn_status |=3D KN_QUEUED; > TAILQ_INSERT_TAIL(&kq->kq_head, kn, > kn_tqe); > - > + } > + > kn->kn_status &=3D ~KN_SCAN; > kn_leave_flux(kn); > kn_list_unlock(knl); > Unfortunately patched kernel is not stable: - some processes run at 100% CPU (STOP state) and cannot be killed - sometime the system completely freeze (need a hard reboot) I cannot reproduce the issue as soon as syslog-ng is under ktrace (even after 10GB of ktrace file) When I stop ktrace, issue come back after few minutes.