From nobody Tue May 9 15:30:16 2023 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 4QG2Cr5yzlz4BKDS; Tue, 9 May 2023 15:30:16 +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 4QG2Cr5W4Yz3r6k; Tue, 9 May 2023 15:30:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683646216; 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=TE7Nif//ACSyTarcNaCOn/N2dl1iM2cQex4/2hWZ6fY=; b=Da9wQAoAbBplFb0PRFPrwiN4kDTXlatZDW7sKc2nfKJ1IU85+8fmiITdFkFZnnWVuewKO8 HJdv9rKoJRIHPylkqaoYmqomOAhtDyl27HAx01Vl+6/D01zBBU9zxCHrvA/Ew2M97Lnb0P c/teVU+aFQZuMjNbtM8hS2++SXbx6GBgv5sZl6ImfZu1kduCyhwGeGa0EMF9TWzEqXE7v9 RpmpKWqi3lgdFTuMnIXsICvi1K4hrhWpqku/VkyNxtYRZOfDjszVGQSc3wIFzqt/v65gg5 5jHBlANWrfhi/zblcIhqkmwMYQR8elzyFTxSa4ffX0QBfNu5MDMmvcWnkJwh+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683646216; 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=TE7Nif//ACSyTarcNaCOn/N2dl1iM2cQex4/2hWZ6fY=; b=MTeBzOIMnjfQAhchlcyF48lAwYK9b1Z+1a1qUAnl7pDVSvKnC2a53bPohqH99iNsj23lKv ya8fo1qkd2hjvEe5SLkhAOUkf095GUCBiydtifoc46K4t2L3bEbaOjICAH7aTYaZdfv9tW tQirIFYRX6Sn7tqmnITdPK+DCTAD+ZU3XtoxV7ZlwqGg/BaGdL5GIMNsM+S8pRTCTn8A4H K5azzeHS9aI4hgBW0Pq5RKbVKhrOCX4HtS7fvDRcGpUSplWaaMsRhcELULgBASLG922x67 6VpSWL1pprnzXftqaeOMPoFbcdk52leyUPW63+CMZl4dPcx2EpWJO0qfgzSYHA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1683646216; a=rsa-sha256; cv=none; b=RfzbOzt82qXVwgRk5fgl7TlbsIrEYEK9EUmT9eQFABkG2C4oRxSKtKMoNl1L4eNiF/hr+Y bG7cKSJnSDpGuXn26u8vVnqiTjBt8fVZN7kOfwu+084bP3MdF2Zc2AShQnUUUBrg5Jk5wQ iQCr5qUUuPWwwyEWvexj0oHsIvCNeF5QCFArq9gQhtD1+7CMsu6Dx0inUEcSilgoXG/Tgq h6QAiC4cpQg4a7YMCwCuafMT1/W5uFNciSbbkXoXtK6plIwwTYIhpWr4BnSsNbOrYhGy+v sIfQgAMLc8ZxuqOYwt0q5LC+SdAK6bEhenBEmhPQOWrKOqN7Qdm+ZFhJn4guPg== 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 4QG2Cr4VGrzY9w; Tue, 9 May 2023 15:30:16 +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 349FUG1x023139; Tue, 9 May 2023 15:30:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 349FUGud023137; Tue, 9 May 2023 15:30:16 GMT (envelope-from git) Date: Tue, 9 May 2023 15:30:16 GMT Message-Id: <202305091530.349FUGud023137@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: d0f67f97579f - main - smp_topo(): make it idempotent 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d0f67f97579f7b2febf29264b1874a95056dec06 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=d0f67f97579f7b2febf29264b1874a95056dec06 commit d0f67f97579f7b2febf29264b1874a95056dec06 Author: Konstantin Belousov AuthorDate: 2023-05-07 18:37:42 +0000 Commit: Konstantin Belousov CommitDate: 2023-05-09 15:30:07 +0000 smp_topo(): make it idempotent If more than one call to the function occurs, it currently allocates the same amount from the group[] array, eventually leading to the memory corruption. Noted and reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D39981 --- sys/kern/subr_smp.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sys/kern/subr_smp.c b/sys/kern/subr_smp.c index df82d948afb0..5a9aeb5ab04a 100644 --- a/sys/kern/subr_smp.c +++ b/sys/kern/subr_smp.c @@ -645,7 +645,14 @@ struct cpu_group * smp_topo(void) { char cpusetbuf[CPUSETBUFSIZ], cpusetbuf2[CPUSETBUFSIZ]; - struct cpu_group *top; + static struct cpu_group *top = NULL; + + /* + * The first call to smp_topo() is guaranteed to occur + * during the kernel boot while we are still single-threaded. + */ + if (top != NULL) + return (top); /* * Check for a fake topology request for debugging purposes.