From patchwork Tue Aug 1 23:35:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Cromie X-Patchwork-Id: 13337386 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 2AFD2EB64DD for ; Tue, 1 Aug 2023 23:36:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 78DDF10E469; Tue, 1 Aug 2023 23:35:51 +0000 (UTC) Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by gabe.freedesktop.org (Postfix) with ESMTPS id B1EF510E463 for ; Tue, 1 Aug 2023 23:35:42 +0000 (UTC) Received: by mail-io1-xd30.google.com with SMTP id ca18e2360f4ac-78666f06691so254162939f.0 for ; Tue, 01 Aug 2023 16:35:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690932942; x=1691537742; 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=G/AtCqJI3wvvzEfNPd3rzcz0cjNcZQ7DwekX9Of62VI=; b=qaE9CU0DjRfPxiq4wM5k3AtUhN7cI8oH3cB+ezxzpHZONTtZGFIQ2X0DbnOwwTfKrB jP2Wo7bp5+KN4EOSJDr3bq3IaoscSy3lfcqCXZB8NY73LN2Homm7TNQwObQdxKBiWh7z JcLOSVq/V6HMJbHMWN5TwqB/Ats80NxDACVmUF17c9o7DYyateU6OsBWbcG6k4hstXI4 cM2NSO12AKjj53j8hcjc2cfB//5g36sVC1zdsm2FDkY9z5Olh76T9eJsD9dw2PVz2Msi g6RoySh+wgG61iPqj4peXKtYMB1PuWhNWoNy9BqA0mPe/CXQiHFrDWxyKUmiF5p7U7oA ayZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690932942; x=1691537742; 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=G/AtCqJI3wvvzEfNPd3rzcz0cjNcZQ7DwekX9Of62VI=; b=Za3aFWvhxagQBwQbBCgK9mmzAmWyv1EevdncZIdpYMGHr388Tm5u8EL7GyZaZUSa8M kJf6yeAXJq8/igMBp4Jz07myOLCW3JjV5XUYDnVDVMK7H6P/18zYk3b2k0hz7MQvCMtV m/gTmGa+PuDKUJzjA/eOWZu3Mt94TAh4ZIePp9h87FZaLYaUu08ENuQIMKfcWRTtCd0g 91hrWAbjG7eOz0chupvVolbiRU3yGt1STTV3aQ7KDoPL/0pVo/ZU2Lrasd5JJLz2NKNF jApLRB80iI+SDkuPIHr53amwk46lfCeYHSb9v+CClu7UbAwVodvXC2Ud++fX+lejqIPj m3AQ== X-Gm-Message-State: ABy/qLZVKWkBvMfUUbXuduAHKbVtczBUuIrDX+WNXU/Q/+W9gntGgcpv LhMzy4vpG7JWWGZdRvwhlsbsAMYF9hLUKA== X-Google-Smtp-Source: APBJJlG0Od5lb50oHBjhZGtTvh6NY2cO9PTyLebV9s07t0PMNy/LBT28bXEWD22kbeauOsTB50SZfA== X-Received: by 2002:a05:6e02:1c41:b0:346:fe2:125a with SMTP id d1-20020a056e021c4100b003460fe2125amr18493108ilg.26.1690932941888; Tue, 01 Aug 2023 16:35:41 -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 t13-20020a92ca8d000000b00348d652a6b4sm4157967ilo.48.2023.08.01.16.35.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 16:35:41 -0700 (PDT) From: Jim Cromie To: jbaron@akamai.com, daniel.vetter@ffwll.ch, dri-devel@lists.freedesktop.org Subject: [PATCH v5 16/23] dyndbg: refactor ddebug_classparam_clamp_input Date: Tue, 1 Aug 2023 17:35:03 -0600 Message-ID: <20230801233515.166971-18-jim.cromie@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230801233515.166971-1-jim.cromie@gmail.com> References: <20230801233515.166971-1-jim.cromie@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 | 66 ++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 63cf14dc3e9f..afcfeffde1d7 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -655,6 +655,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) @@ -673,26 +697,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)); @@ -1156,16 +1169,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, @@ -1182,7 +1206,7 @@ static void ddebug_match_apply_kparam(const struct kernel_param *kp, 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); + ddebug_sync_classbits(kp, modnm); } }