From owner-svn-src-head@freebsd.org Thu Jul 23 17:26:54 2020 Return-Path: Delivered-To: svn-src-head@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 988C335CDC0; Thu, 23 Jul 2020 17:26:54 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BCK5B3R7Hz3b6P; Thu, 23 Jul 2020 17:26:54 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5A1731C5F7; Thu, 23 Jul 2020 17:26:54 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 06NHQsLQ027178; Thu, 23 Jul 2020 17:26:54 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 06NHQrZH027174; Thu, 23 Jul 2020 17:26:53 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <202007231726.06NHQrZH027174@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Thu, 23 Jul 2020 17:26:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r363451 - in head/sys: kern sys X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: in head/sys: kern sys X-SVN-Commit-Revision: 363451 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jul 2020 17:26:54 -0000 Author: mjg Date: Thu Jul 23 17:26:53 2020 New Revision: 363451 URL: https://svnweb.freebsd.org/changeset/base/363451 Log: locks: fix a long standing bug for primitives with kdtrace but without spinning In such a case the second argument to lock_delay_arg_init was NULL which was immediately causing a null pointer deref. Since the sructure is only used for spin count, provide a dedicate routine initializing it. Reported by: andrew Modified: head/sys/kern/kern_mutex.c head/sys/kern/kern_rwlock.c head/sys/kern/kern_sx.c head/sys/sys/lock.h Modified: head/sys/kern/kern_mutex.c ============================================================================== --- head/sys/kern/kern_mutex.c Thu Jul 23 17:16:20 2020 (r363450) +++ head/sys/kern/kern_mutex.c Thu Jul 23 17:26:53 2020 (r363451) @@ -538,7 +538,7 @@ __mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v) #if defined(ADAPTIVE_MUTEXES) lock_delay_arg_init(&lda, &mtx_delay); #elif defined(KDTRACE_HOOKS) - lock_delay_arg_init(&lda, NULL); + lock_delay_arg_init_noadapt(&lda); #endif if (__predict_false(v == MTX_UNOWNED)) Modified: head/sys/kern/kern_rwlock.c ============================================================================== --- head/sys/kern/kern_rwlock.c Thu Jul 23 17:16:20 2020 (r363450) +++ head/sys/kern/kern_rwlock.c Thu Jul 23 17:26:53 2020 (r363451) @@ -475,7 +475,7 @@ __rw_rlock_hard(struct rwlock *rw, struct thread *td, #if defined(ADAPTIVE_RWLOCKS) lock_delay_arg_init(&lda, &rw_delay); #elif defined(KDTRACE_HOOKS) - lock_delay_arg_init(&lda, NULL); + lock_delay_arg_init_noadapt(&lda); #endif #ifdef HWPMC_HOOKS @@ -951,7 +951,7 @@ __rw_wlock_hard(volatile uintptr_t *c, uintptr_t v LOC #if defined(ADAPTIVE_RWLOCKS) lock_delay_arg_init(&lda, &rw_delay); #elif defined(KDTRACE_HOOKS) - lock_delay_arg_init(&lda, NULL); + lock_delay_arg_init_noadapt(&lda); #endif if (__predict_false(v == RW_UNLOCKED)) v = RW_READ_VALUE(rw); Modified: head/sys/kern/kern_sx.c ============================================================================== --- head/sys/kern/kern_sx.c Thu Jul 23 17:16:20 2020 (r363450) +++ head/sys/kern/kern_sx.c Thu Jul 23 17:26:53 2020 (r363451) @@ -623,7 +623,7 @@ _sx_xlock_hard(struct sx *sx, uintptr_t x, int opts LO #if defined(ADAPTIVE_SX) lock_delay_arg_init(&lda, &sx_delay); #elif defined(KDTRACE_HOOKS) - lock_delay_arg_init(&lda, NULL); + lock_delay_arg_init_noadapt(&lda); #endif if (__predict_false(x == SX_LOCK_UNLOCKED)) @@ -1063,7 +1063,7 @@ _sx_slock_hard(struct sx *sx, int opts, uintptr_t x LO #if defined(ADAPTIVE_SX) lock_delay_arg_init(&lda, &sx_delay); #elif defined(KDTRACE_HOOKS) - lock_delay_arg_init(&lda, NULL); + lock_delay_arg_init_noadapt(&lda); #endif #ifdef HWPMC_HOOKS Modified: head/sys/sys/lock.h ============================================================================== --- head/sys/sys/lock.h Thu Jul 23 17:16:20 2020 (r363450) +++ head/sys/sys/lock.h Thu Jul 23 17:26:53 2020 (r363451) @@ -195,6 +195,13 @@ lock_delay_arg_init(struct lock_delay_arg *la, struct la->spin_cnt = 0; } +static inline void +lock_delay_arg_init_noadapt(struct lock_delay_arg *la) +{ + la->delay = 0; + la->spin_cnt = 0; +} + #define lock_delay_spin(n) do { \ u_int _i; \ \