From nobody Tue Apr 05 18:35:11 2022 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 81E321A81BCC; Tue, 5 Apr 2022 18:35:12 +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 4KXxCN1dVJz3p5l; Tue, 5 Apr 2022 18:35:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649183712; 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=zkqWfH0p5RddvLBKtd9gonFKVfUw1ZjraEslA1KkZ6M=; b=VsxPX7pzxIvgMznQjgVsbZGNC72uXCvDvNRvlGTz7PMwSf/AyG8ULqZhogWOSlbsIxNgOb gkBMQ4KpXdr0jo0wPAlbTG2PCVnFzK/par13gz9A90N401qHq3+zOyJLiCCqjuNF/Bv9zz c1qR8tI82bCpjLZi9WTsdYs0T5ETIYtEhWINSAri9UzTCg91cFEm5agg5ztskAtm2oAn4T sFLOgnFiPwJdq31oAdiyYxlR2DNi7QGAk5O5Izjhx61NBqMoFwDYeHbKgeDkkzry+gbJK5 LyNd9dozTyI3pQdk8fK7+QNxmLQkuOr9q4aDmTsqTaryzkcjhofxtcHVICLOwA== 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 F295F3C43; Tue, 5 Apr 2022 18:35:11 +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 235IZBhq044146; Tue, 5 Apr 2022 18:35:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 235IZB6j044145; Tue, 5 Apr 2022 18:35:11 GMT (envelope-from git) Date: Tue, 5 Apr 2022 18:35:11 GMT Message-Id: <202204051835.235IZB6j044145@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 59c27ea18c32 - main - Split out dumper allocation from list insertion 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: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 59c27ea18c32f5db2c2f9e8213b3ed4219e70704 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649183712; 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=zkqWfH0p5RddvLBKtd9gonFKVfUw1ZjraEslA1KkZ6M=; b=UDxCnn3lpXYr1IQ6pWtZ4hlhgh98C8XqNga5Rk4M6+DhvEsVZMWNFgRQUuswr0KWYAIyav 6DLTTyR68ggpS9ERGdmsru2dVAYSTR/An0eHFZElXe/i4K+zAbEQcHZ98CIzMKnG3LDuVM R/wJP6Z7iXfEs9A8X58J69FGn08yvzprbdFdTOF7rnXOxl0W/xqeqrNMf79X+gv0mQj9Kl s7aGLNmy6kyr22j5BK6/u1FEOYB6JMgMddEidwTD7ebkTpYCExBxSA59AjKLZU8nXYaXw5 bmtHLgok32g0xLGH4tHf3+c8nZtqgdIap7aF+LFnXkOWHlJEF0Bf/VeuytGtSg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649183712; a=rsa-sha256; cv=none; b=rV5Qna9usuSKr7Jf4yNOJkEREx269QbKqXSloIVbMRksHFelzXFRi4L3JUBSikeAbJt13I K+PO1fcyE2fa8PPnsKIYlv1fUnJTxu4CteeZqur7AmjUxHL1xoxgvowfPRr9P95Iea9WXK VYcTfuwcY44iCnKyvTmxx1MzLOsgBfUPAz/mrQEGZApP2Gsb4aax2x5QfvfN/qiUgzXqLh Wm5jmvpkaLKjtRqPrkJlTjuzlfO6N9CvGNWTOUAMq5wtKfVaF3qEEGRPIaj3ypbAzXCEC2 F2h5Nbj/pRULS+XCZYjQ2FGekw+Gh4NiZsFN0j/SYnbNjwUPtPgHHgrg9u9FUg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=59c27ea18c32f5db2c2f9e8213b3ed4219e70704 commit 59c27ea18c32f5db2c2f9e8213b3ed4219e70704 Author: Mitchell Horne AuthorDate: 2021-08-09 17:21:07 +0000 Commit: Mitchell Horne CommitDate: 2022-04-05 18:35:05 +0000 Split out dumper allocation from list insertion Add a new function, dumper_create(), to allocate a dumper. dumper_insert() will call this function and retains the existing behaviour. This is desirable for performing live dumps of the system. Here, there is a need to allocate and configure a dumper structure that is invoked outside of the typical debugger context. Therefore, it should be excluded from the list of panic-time dumpers. free_single_dumper() is made public and renamed to dumper_destroy(). Reviewed by: kib, markj MFC after: 1 week Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D34068 --- sys/kern/kern_shutdown.c | 79 +++++++++++++++++++++++++++++++----------------- sys/sys/conf.h | 3 ++ 2 files changed, 54 insertions(+), 28 deletions(-) diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c index c92ac1902b08..7d0f913961cb 100644 --- a/sys/kern/kern_shutdown.c +++ b/sys/kern/kern_shutdown.c @@ -1212,45 +1212,39 @@ kerneldumpcomp_destroy(struct dumperinfo *di) } /* - * Must not be present on global list. + * Free a dumper. Must not be present on global list. */ -static void -free_single_dumper(struct dumperinfo *di) +void +dumper_destroy(struct dumperinfo *di) { if (di == NULL) return; zfree(di->blockbuf, M_DUMPER); - kerneldumpcomp_destroy(di); - #ifdef EKCD zfree(di->kdcrypto, M_EKCD); #endif zfree(di, M_DUMPER); } -/* Registration of dumpers */ +/* + * Allocate and set up a new dumper from the provided template. + */ int -dumper_insert(const struct dumperinfo *di_template, const char *devname, - const struct diocskerneldump_arg *kda) +dumper_create(const struct dumperinfo *di_template, const char *devname, + const struct diocskerneldump_arg *kda, struct dumperinfo **dip) { - struct dumperinfo *newdi, *listdi; - bool inserted; - uint8_t index; - int error; + struct dumperinfo *newdi; + int error = 0; - index = kda->kda_index; - MPASS(index != KDA_REMOVE && index != KDA_REMOVE_DEV && - index != KDA_REMOVE_ALL); - - error = priv_check(curthread, PRIV_SETDUMPER); - if (error != 0) - return (error); + if (dip == NULL) + return (EINVAL); - newdi = malloc(sizeof(*newdi) + strlen(devname) + 1, M_DUMPER, M_WAITOK - | M_ZERO); + /* Allocate a new dumper */ + newdi = malloc(sizeof(*newdi) + strlen(devname) + 1, M_DUMPER, + M_WAITOK | M_ZERO); memcpy(newdi, di_template, sizeof(*newdi)); newdi->blockbuf = NULL; newdi->kdcrypto = NULL; @@ -1259,7 +1253,7 @@ dumper_insert(const struct dumperinfo *di_template, const char *devname, if (kda->kda_encryption != KERNELDUMP_ENC_NONE) { #ifdef EKCD - newdi->kdcrypto = kerneldumpcrypto_create(di_template->blocksize, + newdi->kdcrypto = kerneldumpcrypto_create(newdi->blocksize, kda->kda_encryption, kda->kda_key, kda->kda_encryptedkeysize, kda->kda_encryptedkey); if (newdi->kdcrypto == NULL) { @@ -1291,9 +1285,39 @@ dumper_insert(const struct dumperinfo *di_template, const char *devname, goto cleanup; } } - newdi->blockbuf = malloc(newdi->blocksize, M_DUMPER, M_WAITOK | M_ZERO); + *dip = newdi; + return (0); +cleanup: + dumper_destroy(newdi); + return (error); +} + +/* + * Create a new dumper and register it in the global list. + */ +int +dumper_insert(const struct dumperinfo *di_template, const char *devname, + const struct diocskerneldump_arg *kda) +{ + struct dumperinfo *newdi, *listdi; + bool inserted; + uint8_t index; + int error; + + index = kda->kda_index; + MPASS(index != KDA_REMOVE && index != KDA_REMOVE_DEV && + index != KDA_REMOVE_ALL); + + error = priv_check(curthread, PRIV_SETDUMPER); + if (error != 0) + return (error); + + error = dumper_create(di_template, devname, kda, &newdi); + if (error != 0) + return (error); + /* Add the new configuration to the queue */ mtx_lock(&dumpconf_list_lk); inserted = false; @@ -1310,10 +1334,6 @@ dumper_insert(const struct dumperinfo *di_template, const char *devname, mtx_unlock(&dumpconf_list_lk); return (0); - -cleanup: - free_single_dumper(newdi); - return (error); } #ifdef DDB @@ -1368,6 +1388,9 @@ dumper_config_match(const struct dumperinfo *di, const char *devname, return (true); } +/* + * Remove and free the requested dumper(s) from the global list. + */ int dumper_remove(const char *devname, const struct diocskerneldump_arg *kda) { @@ -1391,7 +1414,7 @@ dumper_remove(const char *devname, const struct diocskerneldump_arg *kda) if (dumper_config_match(di, devname, kda)) { found = true; TAILQ_REMOVE(&dumper_configs, di, di_next); - free_single_dumper(di); + dumper_destroy(di); } } mtx_unlock(&dumpconf_list_lk); diff --git a/sys/sys/conf.h b/sys/sys/conf.h index 409f4b406eb7..6f84a3f03dbc 100644 --- a/sys/sys/conf.h +++ b/sys/sys/conf.h @@ -364,6 +364,9 @@ extern int dumping; /* system is dumping */ int doadump(boolean_t); struct diocskerneldump_arg; +int dumper_create(const struct dumperinfo *di_template, const char *devname, + const struct diocskerneldump_arg *kda, struct dumperinfo **dip); +void dumper_destroy(struct dumperinfo *di); int dumper_insert(const struct dumperinfo *di_template, const char *devname, const struct diocskerneldump_arg *kda); int dumper_remove(const char *devname, const struct diocskerneldump_arg *kda);