From patchwork Thu Jul 13 16:36:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Cromie X-Patchwork-Id: 120039 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1963741vqm; Thu, 13 Jul 2023 10:06:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlFEtpTHjXi/PvGJBHTG2gulI5ih8haOGwWN25AtYSddXviFn6YeS3kbgiUAd+pY2EUU5Gl9 X-Received: by 2002:a05:6402:6c2:b0:51a:200b:d8ff with SMTP id n2-20020a05640206c200b0051a200bd8ffmr2489257edy.13.1689268005247; Thu, 13 Jul 2023 10:06:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689268005; cv=none; d=google.com; s=arc-20160816; b=KMalB8j6RWaSmDQK5pDDbH/moy4ySH1PlJFoafqbNytTOAVC4jnwePH/oRiWgy7FLc HA8Ch72yFhOVQyYwLOFqG489+sRK8g9zqCS7j0kNYm+GEuH+VdyC3ScVxmxEmcnJDz79 brugTkMpRGmmI07mUV+Qh9BfkxFKNxNPMpDQyWI8VVWBjn7kYfMDsIaNuCL1hQeHfW1A KvfBx2TosLHw9acJniImo+X4SUw04pwGmh/9G5G0LbJBd+lsVfDuBrmuPpVn19ewkTyv z5+d/moyNYSWQfHWngSQoiRajRAywFyrIq+KLEikQVd2/GrH11gJndO88CPHVk00iByo FFlw== 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=er10hRf8jzqmY/TOv8apCdhuiXnH4dQdxbq4v1bZDkk=; fh=/CYHsJHkAPOgOy4IDXYU5w+VojxE3561vOD18ijZg9Q=; b=BYPfcMAZMNde8SAWtzFB73dRbDQOgnGaBn5JnuVZEmJNW5tq4EAMeOHQS7ESmV1mRH 6Dy4hBjN7kY9iVAh6KB9KDmfxeSTUvC+7i/pO79yeyf5i2Zq421Z/youqzzmzEcYDrOF dKTcQrAb4y0YG2qMTZCAaHWX82UAbMoaEDDKHBRYizz+lDCr/Lm3FlszU4hlbt27Hfhu xWu/LPqRMWb/KctpX7Sae62C7Eb6BnjZtzU0MT96s6DZkfWcDE9iuWc+M2/zPZ0a9vCk 4QLV/c2O0hGAQch6HXe/UAHANaDUDGu0Bwpajv9yF4SB5WLRha076KFwiprxu+Vk/gNy s7qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=nUtZHBh0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ba26-20020a0564021ada00b0051ffa0d6dacsi428192edb.113.2023.07.13.10.06.13; Thu, 13 Jul 2023 10:06:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=nUtZHBh0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233184AbjGMQib (ORCPT + 99 others); Thu, 13 Jul 2023 12:38:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234796AbjGMQhW (ORCPT ); Thu, 13 Jul 2023 12:37:22 -0400 Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89FA930D1 for ; Thu, 13 Jul 2023 09:37:00 -0700 (PDT) Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-3460b67fdd8so3671515ab.0 for ; Thu, 13 Jul 2023 09:37:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689266220; x=1691858220; 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=er10hRf8jzqmY/TOv8apCdhuiXnH4dQdxbq4v1bZDkk=; b=nUtZHBh03mIOJN4TWeLHRJ7jlkXD96Xyn30/rBF0dI6hQoIWMFxjppRngSnY1uXBml tiwPgfApv3SHpplOUnVzmGvrNcF0FA3keXhzN9fI3HUXnMPEZnsNdETwn9lLaDc0vDM2 oFx2VZf8C8IMnrht7WmcehhH6e/oQ5e6/jlwzALoEuqshmQd6KDJWaHx2a1OldzEbiU8 xaRXYa6xQINeBZUyiOtmcihHw/k+g7qBeSykmV7xieHlMRfmqIBBU8cpH0Eo19uBt1aa SyVbYMxHCIlQZPQ6q9k048SMN2a4TFnmi+AGvmIiVS660FSyRzceY4AmMaG85bRF9XgS iaGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689266220; x=1691858220; 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=er10hRf8jzqmY/TOv8apCdhuiXnH4dQdxbq4v1bZDkk=; b=Ml73EiqKTL9/Feg8gVzgX6mm2Z6p77apkZBZKRNkvit3v/FryCrz9+E4hEtU7I2sLJ fsnAhMVCHJCTfCFORyXR3B2i0+y40IBQePXxMhbIUZFRWXbYRfDlzsP4N8zYlSHbbbjI g4vX9j3k1H6V8vbCuOLgbXXJiZyEr+JxyTlKFmMH9xkNwu10sRoejCBCflpj1csCFpWM eNMN4QD2bYAGR4RuIaWkYenXV+2u5gMXOqVyyUDKV2SwG65xUxecpJ+Mf5sxO+ODbh9A pF9pL9vXG3PAuMTHE0yiDc4bO33DKHS9koPxF4sWsMDfviLeLgoiwmQtIZvgQAtZoCCR 3zxw== X-Gm-Message-State: ABy/qLbV9n8yLrJbF9KkahJEhDzdAIiRmBhmnabpcguFUOJ+uIDa+GoH F9vxcaXdsTbGbDLVyXp0VGU= X-Received: by 2002:a92:ce04:0:b0:345:d2fe:da92 with SMTP id b4-20020a92ce04000000b00345d2feda92mr2149751ilo.10.1689266219846; Thu, 13 Jul 2023 09:36:59 -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 s7-20020a92d907000000b00345950d7e94sm2147571iln.20.2023.07.13.09.36.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 09:36:59 -0700 (PDT) From: Jim Cromie To: jbaron@akamai.com, daniel.vetter@ffwll.ch, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Cc: jani.nikula@intel.com, ville.syrjala@linux.intel.com, seanpaul@chromium.org, robdclark@gmail.com, gregkh@linuxfoundation.org, Jim Cromie Subject: [PATCH v4 14/21] dyndbg: refactor ddebug_classparam_clamp_input Date: Thu, 13 Jul 2023 10:36:19 -0600 Message-ID: <20230713163626.31338-15-jim.cromie@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230713163626.31338-1-jim.cromie@gmail.com> References: <20230713163626.31338-1-jim.cromie@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771325887684958764 X-GMAIL-MSGID: 1771325887684958764 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 8e7bf5e9388b..4743ac2972b1 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -649,6 +649,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) @@ -668,26 +692,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)); @@ -1147,16 +1160,27 @@ static const char* ddebug_classmap_typenames[] = { v2pr_info(_msg " module:%s base:%d len:%d type:%s\n", ##__VA_ARGS__, \ cm->mod_name, cm->base, cm->length, 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, const struct ddebug_class_map *map, const char *modnm) @@ -1171,7 +1195,7 @@ static void ddebug_match_apply_kparam(const struct kernel_param *kp, const struc 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); } }