From owner-svn-src-head@freebsd.org Thu Jul 2 10:42:58 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 EAF9F351664; Thu, 2 Jul 2020 10:42:58 +0000 (UTC) (envelope-from kib@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 49yF6p5yv6z4fL2; Thu, 2 Jul 2020 10:42:58 +0000 (UTC) (envelope-from kib@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 9673119903; Thu, 2 Jul 2020 10:42:58 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 062AgwVe007275; Thu, 2 Jul 2020 10:42:58 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 062AgwhG007274; Thu, 2 Jul 2020 10:42:58 GMT (envelope-from kib@FreeBSD.org) Message-Id: <202007021042.062AgwhG007274@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Thu, 2 Jul 2020 10:42:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r362886 - head/sys/compat/linuxkpi/common/src X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: head/sys/compat/linuxkpi/common/src X-SVN-Commit-Revision: 362886 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, 02 Jul 2020 10:42:59 -0000 Author: kib Date: Thu Jul 2 10:42:58 2020 New Revision: 362886 URL: https://svnweb.freebsd.org/changeset/base/362886 Log: linuxkpi: improvements for linux_pid_task() and linux_get_pid_task(). Unify functions bodies. Do not call tdfind() if pid is passed, and do not call pfind() if tid is supplied. Reviewed by: hselasky Sponsored by: Mellanox Technologies MFC after: 1 week Differential revision: https://reviews.freebsd.org/D25534 Modified: head/sys/compat/linuxkpi/common/src/linux_current.c Modified: head/sys/compat/linuxkpi/common/src/linux_current.c ============================================================================== --- head/sys/compat/linuxkpi/common/src/linux_current.c Thu Jul 2 10:40:47 2020 (r362885) +++ head/sys/compat/linuxkpi/common/src/linux_current.c Thu Jul 2 10:42:58 2020 (r362886) @@ -155,65 +155,52 @@ linuxkpi_thread_dtor(void *arg __unused, struct thread put_task_struct(ts); } -struct task_struct * -linux_pid_task(pid_t pid) +static struct task_struct * +linux_get_pid_task_int(pid_t pid, const bool do_get) { struct thread *td; struct proc *p; + struct task_struct *ts; - /* try to find corresponding thread */ - td = tdfind(pid, -1); - if (td != NULL) { - struct task_struct *ts = td->td_lkpi_task; - PROC_UNLOCK(td->td_proc); - return (ts); - } - - /* try to find corresponding procedure */ - p = pfind(pid); - if (p != NULL) { - FOREACH_THREAD_IN_PROC(p, td) { - struct task_struct *ts = td->td_lkpi_task; - if (ts != NULL) { - PROC_UNLOCK(p); - return (ts); + if (pid > PID_MAX) { + /* try to find corresponding thread */ + td = tdfind(pid, -1); + if (td != NULL) { + ts = td->td_lkpi_task; + if (do_get && ts != NULL) + get_task_struct(ts); + PROC_UNLOCK(td->td_proc); + return (ts); + } + } else { + /* try to find corresponding procedure */ + p = pfind(pid); + if (p != NULL) { + FOREACH_THREAD_IN_PROC(p, td) { + ts = td->td_lkpi_task; + if (ts != NULL) { + if (do_get) + get_task_struct(ts); + PROC_UNLOCK(p); + return (ts); + } } + PROC_UNLOCK(p); } - PROC_UNLOCK(p); } return (NULL); } struct task_struct * -linux_get_pid_task(pid_t pid) +linux_pid_task(pid_t pid) { - struct thread *td; - struct proc *p; + return (linux_get_pid_task_int(pid, false)); +} - /* try to find corresponding thread */ - td = tdfind(pid, -1); - if (td != NULL) { - struct task_struct *ts = td->td_lkpi_task; - if (ts != NULL) - get_task_struct(ts); - PROC_UNLOCK(td->td_proc); - return (ts); - } - - /* try to find corresponding procedure */ - p = pfind(pid); - if (p != NULL) { - FOREACH_THREAD_IN_PROC(p, td) { - struct task_struct *ts = td->td_lkpi_task; - if (ts != NULL) { - get_task_struct(ts); - PROC_UNLOCK(p); - return (ts); - } - } - PROC_UNLOCK(p); - } - return (NULL); +struct task_struct * +linux_get_pid_task(pid_t pid) +{ + return (linux_get_pid_task_int(pid, true)); } bool