From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D57CC433ED for ; Tue, 11 May 2021 18:52:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1F5DA61185 for ; Tue, 11 May 2021 18:52:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1F5DA61185 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 91FE56B0096; Tue, 11 May 2021 14:51:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8AB376B009A; Tue, 11 May 2021 14:51:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 55DEA6B0099; Tue, 11 May 2021 14:51:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0020.hostedemail.com [216.40.44.20]) by kanga.kvack.org (Postfix) with ESMTP id D5AAF6B0096 for ; Tue, 11 May 2021 14:51:50 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 8C381181AEF3F for ; Tue, 11 May 2021 18:51:50 +0000 (UTC) X-FDA: 78129844380.21.048FF82 Received: from mail-io1-f50.google.com (mail-io1-f50.google.com [209.85.166.50]) by imf10.hostedemail.com (Postfix) with ESMTP id 5E88B40B8CD6 for ; Tue, 11 May 2021 18:51:34 +0000 (UTC) Received: by mail-io1-f50.google.com with SMTP id l21so19199359iob.1 for ; Tue, 11 May 2021 11:51:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rRjPVWmA3B6C3BJqW3B7XKo1gt0YfFP4dH6JiUaATHk=; b=PxeRlSJXRM39kgpoN6KeFxTZQAnoUhXeu+nclS/M+2kxRYVMqnKV0q8mPVXhZsy5vg Yh5sYX9MBGW2y9AcFZ1bjKw0Bs/7nwpSP8BAgVB0s/YKybhdHVLjCmQj+uVzTw2E8gSA /GwV9kAgYQQmSAG+DHbj9PSZbx273IZBKQ8+WG1K3d1YXJdJNytgE5kvae5mzsALEye8 JKZseRGPK1ajmwV/iBiUZ/uF9J3xUpjr9wkJRgYmuw2LQGuN0zCQXZhnr4Tnmh81BNZR mam5/awoKWy/ovmIvCTSJk5OUHvJ2dVKAkjd4ZmIythBwqosCB89Z8+mXi5quEVICiiX 3GYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rRjPVWmA3B6C3BJqW3B7XKo1gt0YfFP4dH6JiUaATHk=; b=MYUHCNitJBYeokGA9Gtono5KowvHAMrMQ/H2y4RYM4AOm7UG4lidsOG5MzPeYyqwGh iOGzeJIYynViViChRmytjDHE+nUteaWFtc5PLRiFr5uI1rEFvSTFx/cfwcnAyergFNYr AFGy52BrSRVXZkbQCIs8pePcrlHsIV1JLb342SzWsb83vfDSzQtfQCgT03qr6JPMONv6 ETYsqO9RaCJppA7cxQfXgPXkOMpD4WGhJ6sQuHxqhExRALNIfQSG4hevAgAn7NhWeatz Ya58EH+LdUiKRboL9CwbwNLAalGrWwDrFkMIpzUoG465Mstb1Bx6dB5UpiP2hgr4XSvE 3jlw== X-Gm-Message-State: AOAM5331QuTtc/qqg4dLNvCp5yUc0UnnwXaoAqFTFzpry1rRMBHC7zXX CCilUypHw0Hbu2HU2+dZ5C8= X-Google-Smtp-Source: ABdhPJyYx+0zjnNjAY7ZVIA6NDghAsc2PTRQ2e1Uh8OdgjONUFgEIByJt6OJJDrVBkkKQIx3aU/Cug== X-Received: by 2002:a02:ac05:: with SMTP id a5mr28620682jao.89.1620759109684; Tue, 11 May 2021 11:51:49 -0700 (PDT) Received: from frodo.mearth (c-24-9-77-57.hsd1.co.comcast.net. [24.9.77.57]) by smtp.googlemail.com with ESMTPSA id t10sm405096ils.36.2021.05.11.11.51.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 11:51:49 -0700 (PDT) From: Jim Cromie To: Jason Baron , linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Jim Cromie Subject: [RFC PATCH v5 21/28] dyndbg: validate ddebug_site_get invariants Date: Tue, 11 May 2021 12:50:50 -0600 Message-Id: <20210511185057.3815777-22-jim.cromie@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511185057.3815777-1-jim.cromie@gmail.com> References: <20210511185057.3815777-1-jim.cromie@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 5E88B40B8CD6 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=PxeRlSJX; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of jimcromie@gmail.com designates 209.85.166.50 as permitted sender) smtp.mailfrom=jimcromie@gmail.com X-Rspamd-Server: rspam03 X-Stat-Signature: 78xncmr6y866iojk4xbfmg1ydzq4ocer Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf10; identity=mailfrom; envelope-from=""; helo=mail-io1-f50.google.com; client-ip=209.85.166.50 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620759094-777652 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This commit adds several BUG_ONs to assert all the invariants needed to support the reliance on the "back-N-to-header-overto-site-out-N" use of the 2 __dyndbg* vectors (with their included headers). RFC: I don't think we want this permanently; BUG_ON/panic seems kinda overkill, but its useful to know if it survives lkp auto-testing. - dp is (struct _ddebug*) to the callsite, passed in. - dh is (struct _ddebug*) to the header. derived from dp & _index. known by BUG_ON(!is_dyndbg_header(dh)) this is the "up-N-to-header" from dp. - dh has good site pointer, to __dyndbg_sites[] by BUG_ON(!is_dyndbg_header_pair()) There are 2 main cases to validate: builtin and loadable modules. For loadable modules, we will depend upon the headers presence, and its site pointer to the vector of _ddebug_sites[], expressed as: BUG_ON(&dh->site[dp->_index] !=3D dp->site); Builtin pr-debugs have the additional property: !!(&__start___dyndbg <=3D dp < __stop___dyndbg), We could use this property directly to return site, but since builtin modules also have a header record, we can use that instead. So the 1st BUG_ON is hoisted out of the !builtin branch, and asserted just before return. Also hoist dh derivation, making it a declaration + initialization + BUG_ON instead. NB: grep -- '->site' will confirm that site is now used just for BUG_ON assertions, so we are close to the drop. NEXT To drop site pointer from struct _ddebug, we need: - recast header as a different struct, unionized with _ddebug. - preserve site pointer there. - drop from struct _ddebug. - fix and fold back any fallout from size reduction. OR defer that, and proceed with compressing __dyndbg_sites[], then replacing ddebug_site_get's guts (with all the BUG_ONs) with a decompress and _index. Signed-off-by: Jim Cromie --- lib/dynamic_debug.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 462d364fc788..af9791258f8f 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -123,6 +123,8 @@ do { \ #define vpr_info(fmt, ...) vnpr_info(1, fmt, ##__VA_ARGS__) #define v2pr_info(fmt, ...) vnpr_info(2, fmt, ##__VA_ARGS__) #define v3pr_info(fmt, ...) vnpr_info(3, fmt, ##__VA_ARGS__) +#define v4pr_info(fmt, ...) vnpr_info(4, fmt, ##__VA_ARGS__) +#define v5pr_info(fmt, ...) vnpr_info(5, fmt, ##__VA_ARGS__) =20 static void vpr_info_dq(const struct ddebug_query *query, const char *ms= g) { @@ -146,7 +148,34 @@ static void vpr_info_dq(const struct ddebug_query *q= uery, const char *msg) =20 static struct _ddebug_site *ddebug_site_get(struct _ddebug *dp) { - return dp->site; /* passthru abstraction */ + struct _ddebug *dh =3D dp - (dp->_index); + + WARN_ON(!is_dyndbg_header_pair(dh, dh->site)); + + if (dp >=3D __start___dyndbg && dp < __stop___dyndbg) { + + v5pr_info("get: %s is builtin: %d %d %s:%s:%d\n", + dp->site->modname, dp->_index, (int)(dp - dh), + dh->site[dp->_index].filename, + dh->site[dp->_index].function, dp->lineno); + + WARN_ON(dp !=3D &__start___dyndbg[dp->_index]); + + WARN_ON(!(dp->_index =3D=3D (dp - dh) && + dp->_index =3D=3D (dp - __start___dyndbg) && + dp->_index =3D=3D (&__start___dyndbg_sites[dp->_index] + - &__start___dyndbg_sites[0]))); + + WARN_ON(&__start___dyndbg_sites[dp->_index] !=3D dp->site); + } else { + v4pr_info("get: %s is loaded: %d %s:%s:%d\n", + dp->site->modname, dp->_index, + dh->site[dp->_index].filename, + dh->site[dp->_index].function, dp->lineno); + } + WARN_ON(&dh->site[dp->_index] !=3D dp->site); + + return dp->site; } static inline void ddebug_site_put(struct _ddebug *dp) { --=20 2.31.1