Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1257129rdg; Fri, 13 Oct 2023 15:50:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGGDU4i4BRu1GchdkWTgmhhr/J0J1VHkkqK61QpfQfkyLG4D0lgY6L/Ek3iI83CIdfepNs9 X-Received: by 2002:a54:4783:0:b0:3ad:c5f2:2792 with SMTP id o3-20020a544783000000b003adc5f22792mr29473583oic.46.1697237403143; Fri, 13 Oct 2023 15:50:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697237403; cv=none; d=google.com; s=arc-20160816; b=Z/LF6vL0Kf7O28oyhBO7/QLgHT/rTnJu7LIqldjc5Ig6w74ghzBeUIMJYxtf8zqzfT n264BbFyuHnPZwgTssI7eMZpp6+x/2AB+vXRVuVst1uJysdC0Z4wT44BuCiz70bgFDFI Er4JvQtZvzjn/Ynzi9UGZXVp09bAFZzVI/uXq6zWRUmTuXeokhPLfxauAdCzz3QGueG0 mxekeaP9uDI+7OlrjtQN0EV8BV5vCjQYSaB0QgB0Kh+J/xkwly6kR1ygHqT9v5MrRF5o /2F26hzF61aM+sj+euoZks1v0HZv3gDtr8ziCydgrBPqNxxonbXDGSqvsGfD8g3n6+qZ ag7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gKUPZJG7I4VMa4iERW/Xn8lzZwDxy57eOqc/z/Cxr40=; fh=z8A2UgI9Ozi/zM+meU3S7fSTeKB52ixSkA1q1cGr6xs=; b=0AVap1WWnDXo20sPxoj1EQzCoKI1pdJp5Wi7Cm/eEDvSbKJXpavxsWRhVrx8CY2aPj Kky524Wn7KSeN1PJ7rQvRuXtI+PUrAPAXAXeYPZjHwOBkw8pf6YLWLRXfx4oRjBksGRI hAZCDw+Ei6qPyMkvG0A4IS2tT72n4nulZxObmgqJPmVB5Zi5rJ++rJzt7CEBRxXdbU4m cxz54WZNy5RtHSK4cntP7MWPGF2+WizSg8LYjxLkZVEd1y0HJyP4MpSdAynMVrPgTyZW /1pGNMFX31LF05kn5Fe2fZdO01P1jly+d1NJHP7KDWnNtSPTHSorqe7MaBGCgeClQ5Fz r7/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Lk5vx6QE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id r20-20020a6560d4000000b00570979732e4si5163031pgv.392.2023.10.13.15.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:50:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Lk5vx6QE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 0AEE3830D12D; Fri, 13 Oct 2023 15:49:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232332AbjJMWtf (ORCPT + 99 others); Fri, 13 Oct 2023 18:49:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232806AbjJMWt0 (ORCPT ); Fri, 13 Oct 2023 18:49:26 -0400 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0BF61A5; Fri, 13 Oct 2023 15:48:50 -0700 (PDT) Received: by mail-il1-x129.google.com with SMTP id e9e14a558f8ab-351574aca7bso9150155ab.3; Fri, 13 Oct 2023 15:48:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697237329; x=1697842129; darn=vger.kernel.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=gKUPZJG7I4VMa4iERW/Xn8lzZwDxy57eOqc/z/Cxr40=; b=Lk5vx6QEeEVKfha06Gsl0AroxCK9i2GLh1r8oSDQQFQnFvOsaUFhaBuHpcqDtjjtmh PZodt6RqnpjgHAFVsKb1HA0vsofs2WVjtwdx5omGLKag8LluMxsF/bF2m1Y4yCfm+iJN UPEO/5DR8ma2hquv1kyN9hXmzBw2BdsGFjSr5Ex553l6rsznHOfO+s5a7IdDrzYcqgQz pOG6tegYf59RcJdcOcsolzIiGi4AUym8MBkg/nZVjFWROmpHpRUtvgxJtG7UxPkRYsRH bzGfvwvRTW2+8/xTEF0UdFQJHCaTA0NgFM/MBSlCmA4v68X3DlJZmJvbskEph4CYoRgW hINQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697237329; x=1697842129; 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=gKUPZJG7I4VMa4iERW/Xn8lzZwDxy57eOqc/z/Cxr40=; b=HyTSdveAniJut1lz7ztkJ4IMU0rx7xUNkngnAVlPmV3zacFBb6Pjr27KQDF5dIG9OP U7/J/79HT7nDH2LRVBbW49TxPf+m/cUgn9jnim+UbOaRrg849rMyPP3MNwN0FRm0P7Tx JnhI7UDLDLjNO+i/st5jnxaaZZumRokRdCEtFuNPdWYqM+ibUEYNniKUserTNVZDHrh6 ovngkDjcx63Wtx6TAjIpeoEksUG4WbipDeanl6COJ9S/0wLVEHNCkdCk+pD+rAK+rN6D 4ydUgGpt0adEG8VHZfCq81gNZ+R3vZThDAiLlaZ3QehbgbR0V3iRf5TRl+Y5AzON1KTF n/eQ== X-Gm-Message-State: AOJu0YyZ2lOL15d6BNf+gi41728ruEw+YGBCHK1MdHWdhIvdw/wlEPK6 KhWr/pavahmUPVwbtFf4oxxChi0sjgTGsQ== X-Received: by 2002:a92:c7d1:0:b0:357:47a3:adb8 with SMTP id g17-20020a92c7d1000000b0035747a3adb8mr9967408ilk.29.1697237329218; Fri, 13 Oct 2023 15:48:49 -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 t10-20020a92dc0a000000b003512c3e8809sm1683071iln.71.2023.10.13.15.48.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:48:48 -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, Jim Cromie Subject: [PATCH v7b 16/25] dyndbg: refactor ddebug_classparam_clamp_input Date: Fri, 13 Oct 2023 16:48:08 -0600 Message-ID: <20231013224818.3456409-17-jim.cromie@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231013224818.3456409-1-jim.cromie@gmail.com> References: <20231013224818.3456409-1-jim.cromie@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 13 Oct 2023 15:49:54 -0700 (PDT) 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 c11feca70d6f..17eefb35ac96 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -656,6 +656,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) @@ -674,26 +698,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)); @@ -1160,16 +1173,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, @@ -1184,9 +1208,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); } } -- 2.41.0