From patchwork Tue Aug 1 17:02:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Cromie X-Patchwork-Id: 129414 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2855564vqg; Tue, 1 Aug 2023 11:28:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlEmXZsI7z1kwugH+FT6AWxO+SnTeiIXo0On7P+KEQ0+d4nQr3TKQrBjfctkPUtdCzyy5iqV X-Received: by 2002:a17:903:247:b0:1bb:dc48:644a with SMTP id j7-20020a170903024700b001bbdc48644amr13395568plh.49.1690914539411; Tue, 01 Aug 2023 11:28:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690914539; cv=none; d=google.com; s=arc-20160816; b=skfoTr4gGFRTMDIT0TeVV0yo0GjDEkZeNKhRrTN7XJ5gPJ5iHHkwR2niXhycqS9rK6 mGzvFytic2cba/kav+nOhZY2djOXw88YeW/fgmFz2ilrmR/Hw9lO9PUx/CKSiRLRczI7 tPz6ZaxDwxC5FNPIUbeMX0We4IZDh6i3Ixf1pFQlzOI9AFDlP1V2HRB0raQbcMF0o/F4 iV4nyPz/DAIZMpV2I1eIf8bXttKni7udvuGyOmNlfgQKkrtPQZZPZyeN3DuPBzzJ2Bo0 cfM1BLlND6enh/QPXS4VCUEDef6WDk1aP4BzCoSZ9So/EtbUM2vX8vNkCpTK+e0Vmpus fwtA== 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=JzdwF8Ky49oszxcmFvjLvWpWljuHED+kYuEm071qwpo=; fh=u5vE1TE1dJB7o4IGsVvua16vnF8dhcoUHNlJ2pbkr7c=; b=lWa8u9y6ZNnh3K/gWh1XwYUqelV1hPyOCgIg1jNXioUqr0xBo1AKRxNRR44TKy70Bf ZCXkkubesvzyFzEkyGqM3BkFincuV3H2vN/hLMSir0ZVKQl01ziKQKomqI5LCmt9b9dS lgR9ZMeNIdJiz15g6hdDg8ddV4sIEYEUmqsjXTVTiWQpjY5XuX+dSk3gCZ7xi5ZFskVq /lvRp2LojBLvVI7zLGPNFKxdAkzHehp+30jHDsUnc9C4evTgrQ9rGQWpvW88doovYGZR rDJ+ZpRw7ifkzmaqpyg9rFPZBxJkVUJ4STpaZYEtg87ceSAtzx+OQ2ht3MIGewI19YSX eg5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="celoYRJ/"; 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 kl15-20020a170903074f00b001bb907f3981si9199468plb.302.2023.08.01.11.28.45; Tue, 01 Aug 2023 11:28:59 -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="celoYRJ/"; 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 S234681AbjHARFK (ORCPT + 99 others); Tue, 1 Aug 2023 13:05:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234043AbjHAREi (ORCPT ); Tue, 1 Aug 2023 13:04:38 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 324A62690 for ; Tue, 1 Aug 2023 10:03:59 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-686f090316dso3990757b3a.2 for ; Tue, 01 Aug 2023 10:03:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690909418; x=1691514218; 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=JzdwF8Ky49oszxcmFvjLvWpWljuHED+kYuEm071qwpo=; b=celoYRJ/OdoYC4ga6rguy7rqFCb6eUrhi6p5KERxqpGk9/lSG3t6ylM6fdDfG4eGu+ Qs3qChO6o6AIQ34ujIQuZjivMP6gsvoggXTvhPdosjeFW4Th+VgTvtpsBVSwfv8v4ebF z7mSf8M3mmibb54YP4hvU3RbQ4y1Aue9i0R9zn9L7eODQHtduMbno2DD2atq5mlPsocY 5VOHBLhtlCkCKj96rAjlqab++QLVLxkFk4pF1H5p/GP5XfXoEEY1xclG92laiqPodj2e KVvdD+yGwcTUs1oNTjOSTszzfyEslSJ+6XOzXqVGEe2X6JuVFf3ryJ/CahqupREOv6HT rgWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690909418; x=1691514218; 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=JzdwF8Ky49oszxcmFvjLvWpWljuHED+kYuEm071qwpo=; b=eHUnDKfFUIkkyATTDBwEz8iv657osIfaQdb21QZG6x2CQQLa6v5hAxfJKJSZy6BBl8 UPqtgc+lUe1bfTXtPFaklpsGNxwBgXnj326rJ44uSs391fpXQ3a3bN39MTJy5zuoGIeE T9G7ZO0zY1iw5tKaDz0vQS4Uo07Ujj1mAIRQz3M8mSBixPJVRHefprPBO37Cp364Yb/F Gl0qLcImji+cvUn85MGdl3LRYR+KH5uIBlTynifpFU1LM3kI91ol52tK1Gqy7Jz22e8U DwPMq8rIIMyPQ/lqIofeUjId19N0Od+m/Pl4WvclpsSx7Br4tSSHTkeiwBxiTS3PYTsH HNUg== X-Gm-Message-State: ABy/qLYe8XMVDvl8Iy7XmNWvyy7tVQxxI+d/fxtRY4gCEEKrvItVa85S AnY6LBnyuRbUrDMlC6+TTC4= X-Received: by 2002:a05:6a21:47c8:b0:134:24bf:51b with SMTP id as8-20020a056a2147c800b0013424bf051bmr11828214pzc.30.1690909417747; Tue, 01 Aug 2023 10:03:37 -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 o20-20020a02c6b4000000b0042b144abf71sm3768577jan.179.2023.08.01.10.03.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 10:03:37 -0700 (PDT) From: Jim Cromie To: daniel.vetter@ffwll.ch, daniel@ffwll.ch, jbaron@akamai.com, gregkh@linuxfoundation.org, 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: linux@rasmusvillemoes.dk, joe@perches.com, jani.nikula@intel.com, ville.syrjala@linux.intel.com, seanpaul@chromium.org, robdclark@gmail.com, Jim Cromie Subject: [PATCH v5 16/22] dyndbg: refactor ddebug_classparam_clamp_input Date: Tue, 1 Aug 2023 11:02:49 -0600 Message-ID: <20230801170255.163237-18-jim.cromie@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230801170255.163237-1-jim.cromie@gmail.com> References: <20230801170255.163237-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: 1773052403870864579 X-GMAIL-MSGID: 1773052403870864579 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 c4d7a70a0723..63420f90bcb1 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)); @@ -1155,16 +1168,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,7 +1205,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); } }