From owner-svn-src-all@freebsd.org Tue Feb 4 20:23:46 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 53DC4233126; Tue, 4 Feb 2020 20:23:46 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-oi1-f195.google.com (mail-oi1-f195.google.com [209.85.167.195]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48Bx3k1Xg6z4Vm0; Tue, 4 Feb 2020 20:23:46 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-oi1-f195.google.com with SMTP id z2so19828752oih.6; Tue, 04 Feb 2020 12:23:46 -0800 (PST) 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:reply-to :from:date:message-id:subject:to:cc; bh=sMHuECfHoBpRD8BM3i0CU+5WY7KxbBwNMAi4gw1wOVQ=; b=c/VqeoXt9yXlQ+G8dpfYiy9tx4PmHIOqsvWAx4SjVazANsEgypaX5DYQjtO/7n+OUu GmVLvKOGqr363hxqI3YSnp3UFu3Oq3REIJKbvF0iYNaEeRCCr7XpLRMH05F767u/uvtK H+/LfofOtkEl2EYHzMI2fjwnX6gI00ttC9Jt3K/K2sSJdL7QgAiSC4W2At1mpPTw6/pt YxPGZ0A/lQC18LQRK1/L79KFQRn6NcwLopMQg+Tu1+SOF2e4vlN3v6omaC4gYatQArG7 g+z4F5ZgGhhbblyqeh7oiay8dtr7vv1Bo8Yha66h0WY530U4ATYHFQmLULFVop0U4h72 pMnA== X-Gm-Message-State: APjAAAXciqFRmPVjAYI8SfRBiAIeKf4IV9ydyXdRFaWs4yn+0lctpEX8 EddUqsPHS01Dvicl6o7ZLlJHnddv X-Google-Smtp-Source: APXvYqz4wH2Ou6nNiBS2yWEUDRZ5PjJR5NfjnoT1tuTrgba2r1DVVUc9tANrnD3Oi2rrmftoi5t9aA== X-Received: by 2002:aca:ab52:: with SMTP id u79mr477798oie.145.1580847824745; Tue, 04 Feb 2020 12:23:44 -0800 (PST) Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com. [209.85.167.180]) by smtp.gmail.com with ESMTPSA id w196sm6470739oia.46.2020.02.04.12.23.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Feb 2020 12:23:44 -0800 (PST) Received: by mail-oi1-f180.google.com with SMTP id i1so19808978oie.8; Tue, 04 Feb 2020 12:23:44 -0800 (PST) X-Received: by 2002:aca:3017:: with SMTP id w23mr514110oiw.152.1580847824231; Tue, 04 Feb 2020 12:23:44 -0800 (PST) MIME-Version: 1.0 References: <202002040525.0145Pppn034466@repo.freebsd.org> In-Reply-To: <202002040525.0145Pppn034466@repo.freebsd.org> Reply-To: cem@freebsd.org From: Conrad Meyer Date: Tue, 4 Feb 2020 12:23:33 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r357492 - in head/sys: kern sys To: Dmitry Chagin Cc: src-committers , svn-src-all , svn-src-head Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 48Bx3k1Xg6z4Vm0 X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-6.00 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-0.997,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; REPLY(-4.00)[]; TAGGED_FROM(0.00)[] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Feb 2020 20:23:46 -0000 Hi Dmitry, This seems to trigger some panics via clock_gettime syscalls (native and 32-bit, reported by Syzkaller): panic: mutex process lock not owned at /syzkaller/managers/main/kernel/sys/kern/kern_time.c:261 cpuid = 0 time = 1580841963 KDB: stack backtrace: db_trace_self_wrapper() at db_trace_self_wrapper+0x47/frame 0xfffffe00244778c0 vpanic() at vpanic+0x1ce/frame 0xfffffe0024477930 panic() at panic+0x43/frame 0xfffffe0024477990 __mtx_assert() at __mtx_assert+0x196/frame 0xfffffe00244779d0 kern_thread_cputime() at kern_thread_cputime+0xaa/frame 0xfffffe0024477a20 kern_clock_gettime() at kern_clock_gettime+0x277/frame 0xfffffe0024477a80 sys_clock_gettime() at sys_clock_gettime+0x25/frame 0xfffffe0024477ab0 amd64_syscall() at amd64_syscall+0x499/frame 0xfffffe0024477bf0 panic: mutex process lock not owned at /syzkaller/managers/i386/kernel/sys/kern/kern_time.c:261 cpuid = 0 time = 1580847200 KDB: stack backtrace: db_trace_self_wrapper() at db_trace_self_wrapper+0x47/frame 0xfffffe00244a68b0 vpanic() at vpanic+0x1ce/frame 0xfffffe00244a6920 panic() at panic+0x43/frame 0xfffffe00244a6980 __mtx_assert() at __mtx_assert+0x196/frame 0xfffffe00244a69c0 kern_thread_cputime() at kern_thread_cputime+0xaa/frame 0xfffffe00244a6a10 kern_clock_gettime() at kern_clock_gettime+0x277/frame 0xfffffe00244a6a70 freebsd32_clock_gettime() at freebsd32_clock_gettime+0x25/frame 0xfffffe00244a6ab0 ia32_syscall() at ia32_syscall+0x48c/frame 0xfffffe00244a6bf0 Best, Conrad On Mon, Feb 3, 2020 at 9:25 PM Dmitry Chagin wrote: > > Author: dchagin > Date: Tue Feb 4 05:25:51 2020 > New Revision: 357492 > URL: https://svnweb.freebsd.org/changeset/base/357492 > > Log: > For code reuse in Linuxulator rename get_proccess_cputime() > and get_thread_cputime() and add prototypes for it to . > > As both functions become a public interface add process lock assert > to ensure that the process is not exiting under it. > > Fix whitespace nit while here. > > Reviewed by: kib > Differential Revision: https://reviews.freebsd.org/D23340 > MFC after 2 weeks > > Modified: > head/sys/kern/kern_time.c > head/sys/sys/syscallsubr.h > > Modified: head/sys/kern/kern_time.c > ============================================================================== > --- head/sys/kern/kern_time.c Tue Feb 4 05:23:34 2020 (r357491) > +++ head/sys/kern/kern_time.c Tue Feb 4 05:25:51 2020 (r357492) > @@ -242,7 +242,7 @@ sys_clock_gettime(struct thread *td, struct clock_gett > return (error); > } > > -static inline void > +static inline void > cputick2timespec(uint64_t runtime, struct timespec *ats) > { > runtime = cputick2usec(runtime); > @@ -250,12 +250,15 @@ cputick2timespec(uint64_t runtime, struct timespec *at > ats->tv_nsec = runtime % 1000000 * 1000; > } > > -static void > -get_thread_cputime(struct thread *targettd, struct timespec *ats) > +void > +kern_thread_cputime(struct thread *targettd, struct timespec *ats) > { > uint64_t runtime, curtime, switchtime; > + struct proc *p; > > if (targettd == NULL) { /* current thread */ > + p = curthread->td_proc; > + PROC_LOCK_ASSERT(p, MA_OWNED); > critical_enter(); > switchtime = PCPU_GET(switchtime); > curtime = cpu_ticks(); > @@ -263,6 +266,8 @@ get_thread_cputime(struct thread *targettd, struct tim > critical_exit(); > runtime += curtime - switchtime; > } else { > + p = targettd->td_proc; > + PROC_LOCK_ASSERT(p, MA_OWNED); > thread_lock(targettd); > runtime = targettd->td_runtime; > thread_unlock(targettd); > @@ -270,12 +275,13 @@ get_thread_cputime(struct thread *targettd, struct tim > cputick2timespec(runtime, ats); > } > > -static void > -get_process_cputime(struct proc *targetp, struct timespec *ats) > +void > +kern_process_cputime(struct proc *targetp, struct timespec *ats) > { > uint64_t runtime; > struct rusage ru; > > + PROC_LOCK_ASSERT(targetp, MA_OWNED); > PROC_STATLOCK(targetp); > rufetch(targetp, &ru); > runtime = targetp->p_rux.rux_runtime; > @@ -300,14 +306,14 @@ get_cputime(struct thread *td, clockid_t clock_id, str > td2 = tdfind(tid, p->p_pid); > if (td2 == NULL) > return (EINVAL); > - get_thread_cputime(td2, ats); > + kern_thread_cputime(td2, ats); > PROC_UNLOCK(td2->td_proc); > } else { > pid = clock_id & CPUCLOCK_ID_MASK; > error = pget(pid, PGET_CANSEE, &p2); > if (error != 0) > return (EINVAL); > - get_process_cputime(p2, ats); > + kern_process_cputime(p2, ats); > PROC_UNLOCK(p2); > } > return (0); > @@ -360,11 +366,11 @@ kern_clock_gettime(struct thread *td, clockid_t clock_ > ats->tv_nsec = 0; > break; > case CLOCK_THREAD_CPUTIME_ID: > - get_thread_cputime(NULL, ats); > + kern_thread_cputime(NULL, ats); > break; > case CLOCK_PROCESS_CPUTIME_ID: > PROC_LOCK(p); > - get_process_cputime(p, ats); > + kern_process_cputime(p, ats); > PROC_UNLOCK(p); > break; > default: > > Modified: head/sys/sys/syscallsubr.h > ============================================================================== > --- head/sys/sys/syscallsubr.h Tue Feb 4 05:23:34 2020 (r357491) > +++ head/sys/sys/syscallsubr.h Tue Feb 4 05:25:51 2020 (r357492) > @@ -91,6 +91,8 @@ int kern_clock_nanosleep(struct thread *td, clockid_t > const struct timespec *rqtp, struct timespec *rmtp); > int kern_clock_settime(struct thread *td, clockid_t clock_id, > struct timespec *ats); > +void kern_thread_cputime(struct thread *targettd, struct timespec *ats); > +void kern_process_cputime(struct proc *targetp, struct timespec *ats); > int kern_close(struct thread *td, int fd); > int kern_connectat(struct thread *td, int dirfd, int fd, > struct sockaddr *sa);