From nobody Tue Dec 07 23:38:41 2021 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id CEC8518D4303; Tue, 7 Dec 2021 23:38:41 +0000 (UTC) (envelope-from git@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4J7xZT3brNz4TBm; Tue, 7 Dec 2021 23:38:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5C160577; Tue, 7 Dec 2021 23:38:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1B7Ncfk7075960; Tue, 7 Dec 2021 23:38:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B7Ncfk7075959; Tue, 7 Dec 2021 23:38:41 GMT (envelope-from git) Date: Tue, 7 Dec 2021 23:38:41 GMT Message-Id: <202112072338.1B7Ncfk7075959@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 8099a354469a - main - libkvm: Fix kvm_getloadavg() on modern kernel vmcores List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8099a354469a012512d9850302edaa0e27c75fd7 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638920321; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QsACFbCXQtVgZRzNxcfDh+sG27VtveMrnrXerDfWnm8=; b=sKZtcDk09lh5Ov7p5PZIagxTY/4KndFJQtAUUHRE+07DHOPZV4VHIIx9DZTLRcR4cQgwSs 7wQfnJZX4MFmZ36nwIkdHOzey7Zn3+Uruzfuhg3bitkuv3HbLGCftpszLfiX1awSSpr9jO YXSJnuXq1mTjluAcUDOtAimDa+TIrZuc2Daa2RBP2kkkdHX+KwSsHsyDkk+Utbj7VQ/7uD ALNrtvMAH0pu3vBpO8izI0u14ybUI0WjhV46kwk2ADLLKLg9+tQ+enXY+p4QT4N3IBgX3t 7/+kJU//WGB1fA7EEesbBzTwArCUgxafHt5/vj5IrJhOLQR73Os472ulEbKwkw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638920321; a=rsa-sha256; cv=none; b=HBeIJBylyzAHedul7sByhY5iBLHivcKtwxTVoyq7QSPFNFXTuQDK/S7/0FpU7eA3N5jWAM DjtaTU7roUztG3Ha3bZut6ql4mvvXdGG338wBnvOsNo59dKYNcRZ+mOegRWilKWgWY/R7u 7ebBR4PEifAGw7jUbiyMG4stEl9yUKwuqLWfZ4Np2YQANXSI95QP4JMtSApuVAi9VAroy2 dXWrj6CN7l+HCNJrlqiji6mvmJ9P2QbgFz45270myO87K+2ltbDfjk4NBt/nfm765HXNLA TASpOiR4kxXuBB/pU4+9MOr9wkNorijlq5Mq8ADGS5TyzysnFzQM36XLzJkXzw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=8099a354469a012512d9850302edaa0e27c75fd7 commit 8099a354469a012512d9850302edaa0e27c75fd7 Author: Michał Górny AuthorDate: 2021-11-07 21:11:52 +0000 Commit: John Baldwin CommitDate: 2021-12-07 23:36:34 +0000 libkvm: Fix kvm_getloadavg() on modern kernel vmcores Fix kvm_getloadavg() to work correctly on vmcores for modern kernel versions. The kernels no longer include the `_fscale` symbol causing the kvm_nlist() invocation to fail. The code seemed to already assume that `_fscale` could be missing but the early kvm_nlist() result check has caused the function to fail if any symbol were missing. Modify it to only treat `_averunnable` as obligatory, and handle missing `_fscale` gracefully. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D32884 --- lib/libkvm/kvm_getloadavg.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/libkvm/kvm_getloadavg.c b/lib/libkvm/kvm_getloadavg.c index 0f2a5f69bcf0..f94b1d844663 100644 --- a/lib/libkvm/kvm_getloadavg.c +++ b/lib/libkvm/kvm_getloadavg.c @@ -62,7 +62,6 @@ int kvm_getloadavg(kvm_t *kd, double loadavg[], int nelem) { struct loadavg loadinfo; - struct nlist *p; int fscale, i; if (ISALIVE(kd)) @@ -74,10 +73,9 @@ kvm_getloadavg(kvm_t *kd, double loadavg[], int nelem) return (-1); } - if (kvm_nlist(kd, nl) != 0) { - for (p = nl; p->n_type != 0; ++p); + if (kvm_nlist(kd, nl) != 0 && nl[X_AVERUNNABLE].n_type == 0) { _kvm_err(kd, kd->program, - "%s: no such symbol", p->n_name); + "%s: no such symbol", nl[X_AVERUNNABLE].n_name); return (-1); } @@ -92,7 +90,8 @@ kvm_getloadavg(kvm_t *kd, double loadavg[], int nelem) * Old kernels have fscale separately; if not found assume * running new format. */ - if (!KREAD(kd, nl[X_FSCALE].n_value, &fscale)) + if (nl[X_FSCALE].n_type != 0 && + !KREAD(kd, nl[X_FSCALE].n_value, &fscale)) loadinfo.fscale = fscale; nelem = MIN(nelem, (int)(sizeof(loadinfo.ldavg) / sizeof(fixpt_t)));