From patchwork Wed Nov 1 00:26:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Cromie X-Patchwork-Id: 13442437 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3E9BFC4708E for ; Wed, 1 Nov 2023 00:27:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ZKYwX6PlKirCQ7XLWvaftt3onqBij/al291HyDr2Q3k=; b=gyeLYf/oSXux7F WB1/lmsuPblsDwI7Hqvse03OkJWwq087oDYRcV0BQnIxHLhRuhyDNL1SUfg6fodhXzGyCzSenSxZO LvxvG220INfURDiBp9Zvv1STMP/z1+thFbaXihhjvuUUxtzBfT2hB9lZssiQ5wQ1+JtOQiU8w5M3d CyXCzZD6rDw0HlEQ2v9BDXiT1qsosYGtfB6CKd888w8bye6R0uP1YXINdmunufJ/ud0do8l1/TNbX 9CvvYPKcs/SWRLRPYVuVzTlJTCs58WuuoyC3j1K1bATBcAms6kB11UX4FPGIA1nRKG/gQetUi07aQ 5tZgMXDBJN+YhWyud5Kw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qxz4Y-006OxI-2h; Wed, 01 Nov 2023 00:27:02 +0000 Received: from mail-io1-xd29.google.com ([2607:f8b0:4864:20::d29]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qxz4B-006OWD-2a for linux-arm-kernel@lists.infradead.org; Wed, 01 Nov 2023 00:26:43 +0000 Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-7a92727934eso218574339f.3 for ; Tue, 31 Oct 2023 17:26:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698798398; x=1699403198; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=U/Y22HDoQtQ5J6jKu+XMrHNDFCbaw7mLlFMAwMGHHHY=; b=lmxutg2/okGk5AYBQkk1ZD7a2fpNdKgGqRjuhyZCygIGWlGD8LOeb/GosRfXCQDfHN TfMYVcMoZDjKo4hD7Sh6bXcH5QIIr19da0F7E/CY6zhnoY+4rdxSbtmO0tq+rOa1AwKL R4rBrtC5V7yqf7iZymyToaxFErMzFroO7LTdMqqrvHOM/g1FiLNDlezH8hKAp1P510PX VeFARbp7PNOZ1MwOR1ScrZavr+MCi6ktYBf6H24VelW3cZ+JuMVLkAUr7mNT0Jqz45Yq jvUlF/jIwV83mld4qVZoyv1b0qBqQZKZprc/Li+lWO6x7uaSitEPnqWaC73MbG/dCEzT X75Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698798398; x=1699403198; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U/Y22HDoQtQ5J6jKu+XMrHNDFCbaw7mLlFMAwMGHHHY=; b=vpqmet9jljYOS8Q58AdMr/SGLE8qBCiPnKp9sVRUMvCyKZ53bcf+2u06Fl/ZCtN52e 7I7mv2viQ3TdTbLHQ6/efjsh/7sgCV2xJ6CBcCyoElMdLkxGhzDFkMin7atboJzeIKmH n32Ji+3bP3806UQL+JOq1ZUqls438UbN8kAB9EWJYLhv0hNjQeKw7ZkHWQ4q+fLXHcrB QbnJiOAR8rhgXCeVZI1NfdpPe4YRWdeC8nHQA8JPX//Uj9eiZoNxk4yjfKbIcybFc8Nq BgfnAA9eIJmzaU9iVt2Rhg5lfmi1PSl2IHLQEDsu99SsJnnMKdRDg5w4byoveaTgIcjn D7Nw== X-Gm-Message-State: AOJu0YwIBei5FY5RFFpKPbb/oHlzy03tFox/yEilz+Z9sNyHxqV9Q1FU yJ1KklN6wNRGHlvw3crLNFM= X-Google-Smtp-Source: AGHT+IGplcxVeKRrxfEzIe5t4tRpaoRwBH4GttUH+1bSvDZD6oSEvtngVm7LhpLRqTeegbroJkeBfg== X-Received: by 2002:a05:6e02:11b0:b0:359:4048:38da with SMTP id 16-20020a056e0211b000b00359404838damr1276156ilj.1.1698798398709; Tue, 31 Oct 2023 17:26:38 -0700 (PDT) Received: from frodo.. (c-73-78-62-130.hsd1.co.comcast.net. [73.78.62.130]) by smtp.googlemail.com with ESMTPSA id t1-20020a92c901000000b00357cc8df1d5sm141701ilp.68.2023.10.31.17.26.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 17:26:38 -0700 (PDT) From: Jim Cromie To: linux-kernel@vger.kernel.org, jbaron@akamai.com, gregkh@linuxfoundation.org, dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Cc: lb@semihalf.com, linux@rasmusvillemoes.dk, joe@perches.com, mcgrof@kernel.org, daniel.vetter@ffwll.ch, jani.nikula@intel.com, ville.syrjala@linux.intel.com, seanpaul@chromium.org, robdclark@gmail.com, groeck@google.com, yanivt@google.com, bleung@google.com, linux-doc@vger.kernel.org, quic_saipraka@quicinc.com, will@kernel.org, catalin.marinas@arm.com, quic_psodagud@quicinc.com, maz@kernel.org, arnd@arndb.de, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, mingo@redhat.com, jim.cromie@gmail.com Subject: [PATCH v7d 15/23] dyndbg: refactor ddebug_classparam_clamp_input Date: Tue, 31 Oct 2023 18:26:01 -0600 Message-ID: <20231101002609.3533731-16-jim.cromie@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231101002609.3533731-1-jim.cromie@gmail.com> References: <20231101002609.3533731-1-jim.cromie@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231031_172639_860239_2D8599CD X-CRM114-Status: GOOD ( 15.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Extract input validation code, from param_set_dyndbg_module_classes() (the sys-node >handler) to new: ddebug_classparam_clamp_input(kp), call it from former. It takes kernel-param arg, so it can complain about "foo: bad input". Reuse ddparam_clamp_input(kp) in ddebug_sync_classbits(), to validate inputs from parent's params, just like our own. To support that reuse, alter ddebug_sync_classbits() and caller to pass kp instead of kp->arg. Signed-off-by: Jim Cromie --- lib/dynamic_debug.c | 70 ++++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 7d3261dede77..f878a6f09fc8 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -653,6 +653,30 @@ static int ddebug_apply_class_bitmap(const struct ddebug_class_param *dcp, #define CLASSMAP_BITMASK(width) ((1UL << (width)) - 1) +static void ddebug_class_param_clamp_input(unsigned long *inrep, const struct kernel_param *kp) +{ + const struct ddebug_class_param *dcp = kp->arg; + const struct ddebug_class_map *map = dcp->map; + + switch (map->map_type) { + case DD_CLASS_TYPE_DISJOINT_BITS: + /* expect bits. mask and warn if too many */ + if (*inrep & ~CLASSMAP_BITMASK(map->length)) { + pr_warn("%s: input: 0x%lx exceeds mask: 0x%lx, masking\n", + KP_NAME(kp), *inrep, CLASSMAP_BITMASK(map->length)); + *inrep &= CLASSMAP_BITMASK(map->length); + } + break; + case DD_CLASS_TYPE_LEVEL_NUM: + /* input is bitpos, of highest verbosity to be enabled */ + if (*inrep > map->length) { + pr_warn("%s: level:%ld exceeds max:%d, clamping\n", + KP_NAME(kp), *inrep, map->length); + *inrep = map->length; + } + break; + } +} static int param_set_dyndbg_module_classes(const char *instr, const struct kernel_param *kp, const char *modnm) @@ -671,26 +695,15 @@ static int param_set_dyndbg_module_classes(const char *instr, pr_err("expecting numeric input, not: %s > %s\n", instr, KP_NAME(kp)); return -EINVAL; } + ddebug_class_param_clamp_input(&inrep, kp); switch (map->map_type) { case DD_CLASS_TYPE_DISJOINT_BITS: - /* expect bits. mask and warn if too many */ - if (inrep & ~CLASSMAP_BITMASK(map->length)) { - pr_warn("%s: input: 0x%lx exceeds mask: 0x%lx, masking\n", - KP_NAME(kp), inrep, CLASSMAP_BITMASK(map->length)); - inrep &= CLASSMAP_BITMASK(map->length); - } v2pr_info("bits:0x%lx > %s.%s\n", inrep, modnm ?: "*", KP_NAME(kp)); totct += ddebug_apply_class_bitmap(dcp, &inrep, *dcp->bits, modnm); *dcp->bits = inrep; break; case DD_CLASS_TYPE_LEVEL_NUM: - /* input is bitpos, of highest verbosity to be enabled */ - if (inrep > map->length) { - pr_warn("%s: level:%ld exceeds max:%d, clamping\n", - KP_NAME(kp), inrep, map->length); - inrep = map->length; - } old_bits = CLASSMAP_BITMASK(*dcp->lvl); new_bits = CLASSMAP_BITMASK(inrep); v2pr_info("lvl:%ld bits:0x%lx > %s\n", inrep, new_bits, KP_NAME(kp)); @@ -1157,16 +1170,27 @@ static const char * const ddebug_classmap_typenames[] = { ddebug_classmap_typenames[_cm->map_type]); \ }) -static void ddebug_sync_classbits(const struct ddebug_class_param *dcp, const char *modname) +static void ddebug_sync_classbits(const struct kernel_param *kp, const char *modname) { - /* clamp initial bitvec, mask off hi-bits */ - if (*dcp->bits & ~CLASSMAP_BITMASK(dcp->map->length)) { - *dcp->bits &= CLASSMAP_BITMASK(dcp->map->length); - v2pr_info("preset classbits: %lx\n", *dcp->bits); + struct ddebug_class_param *dcp = kp->arg; + unsigned long new_bits; + + ddebug_class_param_clamp_input(dcp->bits, kp); + + switch (dcp->map->map_type) { + case DD_CLASS_TYPE_DISJOINT_BITS: + v2pr_info(" %s: classbits: 0x%lx\n", KP_NAME(kp), *dcp->bits); + ddebug_apply_class_bitmap(dcp, dcp->bits, 0UL, modname); + break; + case DD_CLASS_TYPE_LEVEL_NUM: + new_bits = CLASSMAP_BITMASK(*dcp->lvl); + v2pr_info(" %s: lvl:%ld bits:0x%lx\n", KP_NAME(kp), *dcp->lvl, new_bits); + ddebug_apply_class_bitmap(dcp, &new_bits, 0UL, modname); + break; + default: + pr_err("bad map type %d\n", dcp->map->map_type); + return; } - /* force class'd prdbgs (in USEr module) to match (DEFINEr module) class-param */ - ddebug_apply_class_bitmap(dcp, dcp->bits, ~0, modname); - ddebug_apply_class_bitmap(dcp, dcp->bits, 0, modname); } static void ddebug_match_apply_kparam(const struct kernel_param *kp, @@ -1181,9 +1205,9 @@ static void ddebug_match_apply_kparam(const struct kernel_param *kp, dcp = (struct ddebug_class_param *)kp->arg; if (map == dcp->map) { - v2pr_info("found kp:%s =0x%lx", kp->name, *dcp->bits); - vpr_cm_info(map, "mapped to:"); - ddebug_sync_classbits(dcp, modnm); + v2pr_info(" found kp:%s =0x%lx", kp->name, *dcp->bits); + vpr_cm_info(map, " mapped to:"); + ddebug_sync_classbits(kp, modnm); } }