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=-12.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 5166BC433E5 for ; Sat, 25 Jul 2020 16:37:30 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 146E7206E3 for ; Sat, 25 Jul 2020 16:37:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CiOFTNUE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 146E7206E3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies-bounces@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94) (envelope-from ) id 1jzNAC-0000QZ-3u; Sat, 25 Jul 2020 12:36:44 -0400 Received: from mail-oi1-x241.google.com ([2607:f8b0:4864:20::241]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94) (envelope-from ) id 1jzN9q-0000Ml-TU for kernelnewbies@kernelnewbies.org; Sat, 25 Jul 2020 12:36:23 -0400 Received: by mail-oi1-x241.google.com with SMTP id r8so10770249oij.5 for ; Sat, 25 Jul 2020 09:36:21 -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=V1qRiRiPORWYvtQXCH8oBnodBbuhKS5hMbBnVO8vAEU=; b=CiOFTNUEQOTkSNf8ct0RBLg9NkbV+8eFQ74XN23uoVIj2SSl1aiDZxUHjvgfY5/9vI bHDsexE3qx8oFLIU+s8YLlXUcOXK69A2IWkIO7EK87nARFwETaRKDnIs+7hhM1hyO0ai +yShEGrO+evWApVOaKsL+ikxVe7B3ya9orU+9kZ50eBhyaWgTxf6jt+Wy9Q8qKQJhjL0 FgVVcXpZMMbjn16WQjrclgAy1Xfi/36WokNYCTvYz88L3hLTEtR0lBL+z1dPOzP06r/z /lFf0+zOEC583mk/DwevPfC6t52IhAdmcNY59NQr6ayc/apUB9oEQ2C+xikUBg1TvojQ L0cA== 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=V1qRiRiPORWYvtQXCH8oBnodBbuhKS5hMbBnVO8vAEU=; b=MoerI1IdSF/S4ZdUV5WSGHDpMZtlHvWrMJ+xxDAjT/PPAnS3TX5c4J2ASpyCW4RBEA vLB2Pteo2/IewFCvbo9Knb0jXqQS68f8RmrAJ1XFil19Ca+BbaX9MZGSLd+YcatYs1pE Z22Wycys9ZIRYlJB6hpCz+lBjbWbPyIK4lsk1XvS0sptIt3Hjd9h9S0cuJpkAywJHMbC ZzpMyyJo3vqL3ERp5zFrHxbiSq44EielQFSWWf8Cup0kmubteyteqBGA4e3W+Or3LN44 1mUQ62tHK1oH3mtxfW3Ira3Qyo3ww89eYNSs+UI6wY25CuAj7ZtwKWCiL+nFuMqqHQIS 3Hpg== X-Gm-Message-State: AOAM533fMqths+oRtMDB8e/LLfBYnGZ5BPK7yL3a1853OeakRLicWJtZ NxJI93oWwrB+dXp7SNWgL1U= X-Google-Smtp-Source: ABdhPJwoxB8Wri7f2nf/KapNN4KIojOiKPYR7onRKlEUNIik/DTc7u07cNQNqojeajrlNHcacxEoQg== X-Received: by 2002:aca:c5c2:: with SMTP id v185mr12705625oif.75.1595694979614; Sat, 25 Jul 2020 09:36:19 -0700 (PDT) Received: from frodo.hsd1.co.comcast.net ([2601:284:8204:6ba0::af38]) by smtp.googlemail.com with ESMTPSA id r1sm953938oij.44.2020.07.25.09.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jul 2020 09:36:18 -0700 (PDT) From: Jim Cromie To: jbaron@akamai.com Subject: [PATCH 2/3] dyndbg: zhandle+1 plus info tweaks, BUG_ONs Date: Sat, 25 Jul 2020 10:36:01 -0600 Message-Id: <20200725163602.2828969-3-jim.cromie@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200725163602.2828969-1-jim.cromie@gmail.com> References: <20200725163602.2828969-1-jim.cromie@gmail.com> MIME-Version: 1.0 Cc: Jim Cromie , kernelnewbies@kernelnewbies.org X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kernelnewbies-bounces@kernelnewbies.org In preparation for union between zhandle and callsite, add a +1 offset to zhandle as its created & stored, and a corresponding -1 in the get/put helper funcs which access it. With the +1, the value cannot work as a pointer, so we'll get early detonation if the union goes poorly. This relys on the 'fact' uhm observation that zhandles were always even numbered. So far so good. Also add BUG-ONs to track/assert invariants into ddebug_zpool_init and the get/put inline helpers, and several debug prints. Signed-off-by: Jim Cromie --- lib/dynamic_debug.c | 72 +++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index bb23d5d56116..96252ffacb77 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -145,13 +145,15 @@ static void vpr_info_dq(const struct ddebug_query *query, const char *msg) static inline struct _ddebug* ddebug_zrec_get(long unsigned int handle) { + BUG_ON(!(handle % 2)); /* distinct from pointer */ return (struct _ddebug*) - zs_map_object(dd_callsite_zpool, handle, ZS_MM_RW); + zs_map_object(dd_callsite_zpool, handle - 1, ZS_MM_RW); } static inline void ddebug_zrec_put(long unsigned int handle) { - zs_unmap_object(dd_callsite_zpool, handle); + BUG_ON(!(handle % 2)); /* distinct from pointer */ + zs_unmap_object(dd_callsite_zpool, handle - 1); } /* @@ -587,22 +589,31 @@ static int remaining(int wrote) return 0; } -static char *dynamic_emit_prefix(const struct _ddebug *dp, char *buf) +static char *dynamic_emit_prefix( struct _ddebug *dp, char *buf) { int pos_after_tid; int pos = 0; - struct _ddebug *desc; + struct _ddebug *desc = dp; /* updated if zhandle */ *buf = '\0'; + BUG_ON(dp->zhandle == 1); + if (!dp->zhandle) { - pr_err("Nul zhandle: %s.%s\n", dp->modname, dp->function); - desc = dp; - } else { + /* without union, happens until late-init */ + pr_err("nul zhandle: %s.%s\n", dp->modname, dp->function); + } else if (dp->zhandle % 2) { + /* normal ops, after zpool filled + zhandle is odd to distinguish from pointer + */ desc = ddebug_zrec_get(dp->zhandle); - v3pr_info("good zhandle: %s.%s\n", + v3pr_info("get zhandle: %s.%s\n", desc->modname, desc->function); - } + } else + /* with union, happens until late-init */ + pr_err("some transitional state: %s.%s %lu\n", + desc->modname, desc->function, dp->zhandle); + if (desc->flags & _DPRINTK_FLAGS_INCL_TID) { if (in_interrupt()) @@ -627,9 +638,9 @@ static char *dynamic_emit_prefix(const struct _ddebug *dp, char *buf) buf[PREFIX_SIZE - 1] = '\0'; if (!dp->zhandle) { - pr_err("Nul zhandle\n"); - } else { - v3pr_info("got zhandle\n"); + pr_err("Nul zhandle: %s.%s\n", desc->modname, desc->function); + } else if (dp->zhandle % 2) { + v2pr_info("put zhandle: %s.%s\n", desc->modname, desc->function); ddebug_zrec_put(dp->zhandle); } @@ -898,7 +909,6 @@ static int ddebug_proc_show(struct seq_file *m, void *p) struct ddebug_iter *iter = m->private; struct _ddebug *dp = p; struct flagsbuf flags; - long unsigned int handle; if (p == SEQ_START_TOKEN) { seq_puts(m, @@ -906,16 +916,19 @@ static int ddebug_proc_show(struct seq_file *m, void *p) return 0; } - BUG_ON(!dp->zhandle); - handle = dp->zhandle; + BUG_ON(!dp->zhandle); /* must be set by now */ - dp = ddebug_zrec_get(handle); + if (dp->zhandle == 1) + vpr_info("dp:%p mapping ?? h:%lu %s.%s\n", dp, dp->zhandle, + iter->table->mod_name, dp->function); + + dp = ddebug_zrec_get(dp->zhandle); if (!dp) { - pr_err("zs-map failed on %lu\n", handle); + pr_err("zs-map failed on %lu\n", dp->zhandle); return 0; // bail } - v3pr_info("mapped h:%lu %s\n", handle, dp->function); + v3pr_info("mapped h:%lu %s\n", dp->zhandle, dp->function); seq_printf(m, "%s:%u [%s]%s =%s \"", trim_prefix(dp->filename), dp->lineno, @@ -924,7 +937,7 @@ static int ddebug_proc_show(struct seq_file *m, void *p) seq_escape(m, dp->format, "\t\r\n\""); seq_puts(m, "\"\n"); - ddebug_zrec_put(handle); + ddebug_zrec_put(dp->zhandle); return 0; } @@ -935,6 +948,7 @@ static int ddebug_proc_show(struct seq_file *m, void *p) */ static void ddebug_proc_stop(struct seq_file *m, void *p) { + vpr_info("called\n"); mutex_unlock(&ddebug_lock); } @@ -947,7 +961,6 @@ static const struct seq_operations ddebug_proc_seqops = { static int ddebug_proc_open(struct inode *inode, struct file *file) { - vpr_info("called\n"); return seq_open_private(file, &ddebug_proc_seqops, sizeof(struct ddebug_iter)); } @@ -972,7 +985,7 @@ static const struct proc_ops proc_fops = { /* * copy struct _ddebug records into the zpool, and remember zhandle in * the struct. This is close to what we'll want to unionize the - * handle and the struct + * handle and the struct. */ static void ddebug_zpool_add(struct _ddebug *dp) { @@ -985,7 +998,21 @@ static void ddebug_zpool_add(struct _ddebug *dp) pr_err("pool malloc failed on %s\n", dp->function); return; } - dp->zhandle = handle; + + /* We want !!is_odd(zhandle), to insure crash if used as a + pointer. Then we can test the unionized value to see if + its a pointer or a zhandle to a zrec. Observation shows + handle is always even, and the BUG_ON confirms, so + ++zhandle gives us our testable condition. + */ + BUG_ON(handle % 2); + + /* update zhandle in kmem record before copy to zrec, so its + in both places, to avoid use-after-restore inconsistencies. + This will break once we unionize (the zrec), hopefully all + these comments will help sort it all out. + */ + dp->zhandle = handle + 1; cursor = (struct _ddebug *) zs_map_object(dd_callsite_zpool, handle, ZS_MM_WO); @@ -999,6 +1026,7 @@ static void ddebug_zpool_add(struct _ddebug *dp) v3pr_info("h:%lu %s\n", handle, cursor->function); zs_unmap_object(dd_callsite_zpool, handle); + } /* -- 2.26.2 _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies