From nobody Sun Feb 8 06:49:53 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D000BC77B73 for ; Tue, 30 May 2023 19:40:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232976AbjE3Tko (ORCPT ); Tue, 30 May 2023 15:40:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231173AbjE3Tkk (ORCPT ); Tue, 30 May 2023 15:40:40 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26F4CE8 for ; Tue, 30 May 2023 12:40:38 -0700 (PDT) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34UJLxUY021706; Tue, 30 May 2023 19:40:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-03-30; bh=KTVZNDKD326ut2TnMMYnyBizEHBrnTbV8E2qMCf8Cjk=; b=dLYX5DaOX0L5VdE6BPJi+PU09h4RqBOOffISedbZgxQebr3ZuHncU7Nk/GNo8nBWn4vI zUvYYky93M4N9LeR2NTjvdwAyDC3ohSJIBYsXeATBEs5bH+WauEL1fLR6R1l3Thmmjvy 451BWIaDchuGnTV6JZwKVjF8/8k/rMZ2ixA046q4efjpON7hwvszn4M0vQoZiXIuKW4w JYg7vWfiAYJg87Fa8+H7wrTIE/BrnmSAXN1jgmgCrgjnDGIKaXnGVovUmYCtp1YpNk5H AZ991AWR2SoKvGedlRoEdB87BVsdn7zV1TZZfZbnCAI6KwcMPJPeJdvthjwiG1lI26TF Rg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qvhjh3qnd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 May 2023 19:40:33 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34UJ69Sm003695; Tue, 30 May 2023 19:40:32 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2169.outbound.protection.outlook.com [104.47.58.169]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3qv4ybyrdw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 May 2023 19:40:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MUXkYM2FZS6HrUIhFg9p/3EqWoCOBuplEcbhncaUMT5dnGHCPhzQaw9n9JbE+fOVwUHfTlLxFsIvsm22RJUxh5bt15WuNyzu/kz9SjWaGS2G72+73Gg93W6YpJv599BmuPgqYCCfKIQmAyRHGSuYPxTOgzr9DEbtnbVZQdLYJ7aBAhotySwmQ+4CXT9WxsgXIthJ3B309Kh6lohh+qdtyGizw5IumvNCCKLMN/A9JXoubGRzxAm+pYR0rEoIDBwESRs8oIEKUaOiUiiOdoNWk0+kwzKrTfW2DSgU7/zmwKTu0CRZ3veDAWAsYsCyeu+bsRlJynjg4bo3sCItIDKGvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KTVZNDKD326ut2TnMMYnyBizEHBrnTbV8E2qMCf8Cjk=; b=iLnob6QC6Udmsyl2zw/TLesT6BngOyNBO6/ectGj3i8wq5P9p7ame4CIBqTwrwGvrSXS08IPgpasr0AYbJunOSOcVfYZ+Bgxl662EJJ6g1R46Q5mahZppjXNbizqG7r2a+0FOvV5PAsRfq319E9SI4k0GIxLjtnAQZ+ldRJnh/h3WfRT+Zgewduv6NbSEEcOMj7URPc7RUIzdOK1s5ja/8ZgqYIm2TuyjspWecE9k1dUHMpdbWL+Tke4jNvjMgozB+6RHavA7U2hcxur/FeLz2dpSRHGHSGGisDWOW0cElXEq0n8DfVUFjWEVSeFLu/ChKyzDZ9diepMs1KjXuV3YA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KTVZNDKD326ut2TnMMYnyBizEHBrnTbV8E2qMCf8Cjk=; b=M8l9HO4HOkk8EMnjBR3DKtMAidhhHBFoxInt21qxmkwXdB4ebsmlWMUq7X99LLpYwt2uVOB6JGUbGYZq390uoDvAS7nTlxe9iCOTyFpVG49B1W7rFHYfZcG5GNm0EVmj6StyhqK6WsmIV8c6MzBmHMz4ZbLrpyUtBBGiBXUKZQI= Received: from CO1PR10MB4705.namprd10.prod.outlook.com (2603:10b6:303:96::11) by CY5PR10MB6214.namprd10.prod.outlook.com (2603:10b6:930:31::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Tue, 30 May 2023 19:40:30 +0000 Received: from CO1PR10MB4705.namprd10.prod.outlook.com ([fe80::11b8:4b2e:26c5:1bb3]) by CO1PR10MB4705.namprd10.prod.outlook.com ([fe80::11b8:4b2e:26c5:1bb3%2]) with mapi id 15.20.6433.022; Tue, 30 May 2023 19:40:30 +0000 From: chris hyser To: chris.hyser@oracle.com, linux-kernel@vger.kernel.org, peterz@infradead.org, gregkh@linuxfoundation.org, "Rafael J. Wysocki" Subject: [PATCH 1/4] debugfs: return EINVAL if write to unsigned simple files exceed storage. Date: Tue, 30 May 2023 15:40:09 -0400 Message-Id: <20230530194012.44411-2-chris.hyser@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230530194012.44411-1-chris.hyser@oracle.com> References: <20230530194012.44411-1-chris.hyser@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SJ0PR03CA0384.namprd03.prod.outlook.com (2603:10b6:a03:3a1::29) To CO1PR10MB4705.namprd10.prod.outlook.com (2603:10b6:303:96::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4705:EE_|CY5PR10MB6214:EE_ X-MS-Office365-Filtering-Correlation-Id: 6e63dd7b-2f66-4e7e-7f9f-08db6145b9ba X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Hxk0UAThCy3N/SO/Bi9Pl6b7GaVw5ghe7crhs6m6u77veCEY9yxXtH9S4vE4gFritu3LM7Anz21b4hAh+xcBT00A68eLV3ozF4ZfZTsjvTFR+dfrbIck7w1zzRBlkpyHlxSyOi7/N5cbAomLYwbeLMXYms6IOPYWqDdXSUv3NQ07kI7ZFwpak6P9D7lxQxAkQSPlzw55uWi2PwWMIcLt5LpyuR80qHc6o/KohViCeM2VO90CZMvrgA7rlDB+HR7L0sKe458ICFsdGyQqNFRaksNbkML0S1h2z0S+GcrfXVeXD1XSfHK++hPg2IvGfhiRheLKaVeM/YYUhtB4mR5ITl7P/TeGdukTZkwxVLCKE1Jn9v8opfHjVspMyNom1LBs2G+F3QRBjv8HNfaFn0OVWishNmCOFtlv26s90wM+iWC3epGx3EQgDSTr608XBEDIsoFjMnKf7JbBmMbYbvCgxKd0bqhY+FserKtos5wf2ESWnFweZ2IUfSsC+V5NcJ1VehIwMidVGvEjms2mgDK0RsJI9YGypy6U4/YC24bUvNO4Mw7GHMLDHkmJOG/zt548 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR10MB4705.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(396003)(366004)(346002)(136003)(376002)(451199021)(478600001)(8676002)(8936002)(5660300002)(6916009)(36756003)(2906002)(86362001)(66946007)(66556008)(66476007)(316002)(38100700002)(41300700001)(2616005)(186003)(6512007)(26005)(1076003)(6506007)(6486002)(6666004)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?/UtIxtnNRf/QcL92mD0bDAA8sYGGSeAN8qWJ6KRCe66eoA1DGzlI9pHjXk94?= =?us-ascii?Q?fkvf15NccpZJb0rGvL2MB+qbQGtMMAYblVltv7xpZbvGWmJI2eAE7SCte4sU?= =?us-ascii?Q?h/d6xxZi0ZMmoRscywVq0kI04o5lDtzp2/QAuW67IDGZbwxLuQ4fR4yxjRg6?= =?us-ascii?Q?ivCehKHun03bVs8Tir5sj1d6SEvti5GfrUZ2anHZUMO2Rr0gB3nV4uDIpRCh?= =?us-ascii?Q?og0/tPJe/6qbIlEZlxDb+FCkJY+QdOgeoViGpJIbSxGTc/AoUDVs5H/WN71g?= =?us-ascii?Q?Rym/QyESAl0m/t0CRbH+Iy+NzvZAfPGmCX4SRKonqsfRBqRolplC2s/caC+k?= =?us-ascii?Q?Ju45oVUnmKmCH5ndX9Mz0rF7Gx+7mgMHc/qI/uWAl3jkFEYVBbqfchOVgYt1?= =?us-ascii?Q?CMW6TRVbwy2P4LoxsM+wZDuGbLQ/poT8veUP/Ee/OtVpjC4JET4m8UeR2V0f?= =?us-ascii?Q?U7ri+RDcbQa6nbEYHAiqQINyS4WmM4sUvFbO56i7wpT3kwYyrda5SS20vr9f?= =?us-ascii?Q?91KRJFhOo9iX7atGCuou/zm5aRpxI+l8jFbZt2N9HSJgNS21wBkHi7iSsX+9?= =?us-ascii?Q?2CO/TeJIuPOr1mrF4FptbVzTnxL5ug5nwjtRc93poGxykW4W02wijGQrP9J7?= =?us-ascii?Q?Mg8xSxCGIZJlfjOiyh+hjOrpc6qIgp54hGX+zXQlduHFXSJE9pswJ3yxCwKk?= =?us-ascii?Q?JtKA5Kdv+MHcnUEFacDbIknIUe7jl+79I/Xv3ytsRz/oGEOqyp5sANe4qMik?= =?us-ascii?Q?lwiZdhayOvp20zGjbZv7YSkr6umI6KJogIdEcWgL6DmefvyPs5TLxSivaEwK?= =?us-ascii?Q?22nCENB2amnAXd938+5DghilBUxeuHB2d9bPfofkRqqGkHDFoTUE+RWggGvV?= =?us-ascii?Q?7yntwScAWjqn1t+q68riuC6L9x4U4Bdc895SpMZujlDpjsuJHYfglgw15DAg?= =?us-ascii?Q?VLO9T4XBWla4du8a0T3nxShJVlsHsPuBW3RHWPPjFjO5KxnNBNrvclIFBDZ+?= =?us-ascii?Q?9EA1S4k3DzrLXyroMGV5sU0yv99Fkb133ef7MPb3OnplBCxPyt+vvkaLbxek?= =?us-ascii?Q?FV1y6qU2/NmjpO06e1eAyFYhPUfP5LdMcj1MEYrweHS7RUuVtQHJxufkcHRs?= =?us-ascii?Q?+AmRuFaEK3HbWoqYqp5BLEzfLhHSTcTCi52maj/YS28JhKTlG29ehhjoh8g6?= =?us-ascii?Q?QAeUFa3JEbYc4OIEQvEF+2xpZftdo/uAvV46cyTrv0ayifkxBEw7dzfayFqf?= =?us-ascii?Q?g9dCxU9Jn4NzUsCdmq95RdTbpuly7my6DUAXSasIghoXSsluqxPI2Iw2i7/Q?= =?us-ascii?Q?no6IKRcE8kNz08THazvHvKbT18OiFadFqgX/FT1v7i+B1vQW7AB0Iu5658te?= =?us-ascii?Q?zLhnuKd4OJnRrElyPL0//pHuKs9HOWXiCJN/5+qmrBLbjy+ucuxjzJARxZGH?= =?us-ascii?Q?7TLqB086NHen4kSpTWn/yaSytvq4CRHdNC6YdlqttmfOImCmhT18yVJjaAOT?= =?us-ascii?Q?KxRcqH44r+3Llq/QmDf7n32zZpuvMLZ8sJFZ8iz1b+JPC93QQN+jfz9HMSwE?= =?us-ascii?Q?22JV0IcmgrN96Qwh1SDwiaBkiP4ZrXgvFAO5lgQk?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: ss2y6p5HUW0f/R7SYCV8QA1br+jbUMQrcDeWuDSVf2qGdCWtxJ1Tk8Z/izUmGo7gSnbT6kOT24gABL+T4PdCrvfD/Hg91Aq5n2Cfsm1eeHsjltPsrY4cJ2rz+p1XzHDYDdhJOLYnXXrdxxjVh4Waiq7nlCyA+72pwsgZiMO6qLxJ1+0KcBE2iZh9wA1mdeIYeIWezqdpACvMdhPmNrZ1joTihd3J/SNZPfcp/bUREdhFlFtLTCvj721g9b8X11iB9HSpKxwqFXcfCDzYrTH2vlZX5v33HERZgya1P+OeNGD7cdY1WHw09mNlguERDaT/N4kR4ckR05AbRMCmIEYyk52QZSRcvbls78izhv7EAyjgRAOE1Epav+CF+w221xtAKhadsgtoah1C+2J65YTteES5XCMI4vg6A4bwqn0mRt8Y4pHHwb2UGbpGQMQ9zKrE6XXf36DerGvhpwFfyu9uyoHrMx33JB1BtKp/wBBdxO3/WCH3NSx/NXdweHaKOaZYoZOgDiKsmC2dxuzc7BBmEm9ldQNBrBQnUVdL1FIt40KUdMfW3uVogJxsXqD3/JxnP4F+UhjO6CWsN03qXqA7gHViXClODbNNSifba2pPO0IKlBPDeWNlleAE2lovHq0BBHdnjaooID/3Gi23u7HrN/IRLqdyqRZ4Z/7MCnnlv2donD3R+6bJzDODYnyxAqX66KAwr+GkrXv8hM3wic1bqj4mSBdmoijsy+5V+xKoU7RiISkPQiNMPSexyctf8lPRVkdKbw+8A+U5rp66I41YAF4pdHlGjAGWSs+vWpz2UJq7fbJWV6hFrJf4bqx+EmZxEq11r+5javl0zTfZmOLBfw+x1UeAAGP3yU7LbarUYWAgaz7Fra5umBdwcwYSo73V X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6e63dd7b-2f66-4e7e-7f9f-08db6145b9ba X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4705.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2023 19:40:30.1077 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vc7Y2KrR1ryH3r96Iy8CS0a0UIYoUHT0DxoGmaR+ZXvGaZqNmyLSpM1eESRlnBPe5+QdPiwVegeiKp7yl/CEaQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR10MB6214 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-30_15,2023-05-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 bulkscore=0 suspectscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305300159 X-Proofpoint-GUID: 2a0_VyNLEvLDnDs6A1dJRDvQPPO553oY X-Proofpoint-ORIG-GUID: 2a0_VyNLEvLDnDs6A1dJRDvQPPO553oY Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Writes to the debug files created by "debugfs_create_*" (u8/u16/u32/u64), (x8/x16/x32/x64) should not silently succeed if the value exceeds the storage space for the type and upper written bits are lost. Absent an error, a read should return the last written value. Current behaviour is to down cast the storage type thus losing upper bits (thus u64/x64 files are unaffected). This patch ensures the written value fits into the specified storage space returning EINVAL on error. Signed-off-by: Chris Hyser --- Documentation/filesystems/debugfs.rst | 7 ++++--- fs/debugfs/file.c | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Documentation/filesystems/debugfs.rst b/Documentation/filesyst= ems/debugfs.rst index dc35da8b8792..6f1ac8d7f108 100644 --- a/Documentation/filesystems/debugfs.rst +++ b/Documentation/filesystems/debugfs.rst @@ -85,9 +85,10 @@ created with any of:: struct dentry *parent, u64 *value); =20 These files support both reading and writing the given value; if a specific -file should not be written to, simply set the mode bits accordingly. The -values in these files are in decimal; if hexadecimal is more appropriate, -the following functions can be used instead:: +file should not be written to, simply set the mode bits accordingly. Writ= ten +values that exceed the storage for the type return EINVAL. The values in t= hese +files are in decimal; if hexadecimal is more appropriate, the following +functions can be used instead:: =20 void debugfs_create_x8(const char *name, umode_t mode, struct dentry *parent, u8 *value); diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 1f971c880dde..743ddd04f8d8 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -429,6 +429,8 @@ static struct dentry *debugfs_create_mode_unsafe(const = char *name, umode_t mode, =20 static int debugfs_u8_set(void *data, u64 val) { + if (val > (1 << sizeof(u8) * 8) - 1) + return -EINVAL; *(u8 *)data =3D val; return 0; } @@ -465,6 +467,8 @@ EXPORT_SYMBOL_GPL(debugfs_create_u8); =20 static int debugfs_u16_set(void *data, u64 val) { + if (val > (1 << sizeof(u16) * 8) - 1) + return -EINVAL; *(u16 *)data =3D val; return 0; } @@ -501,6 +505,8 @@ EXPORT_SYMBOL_GPL(debugfs_create_u16); =20 static int debugfs_u32_set(void *data, u64 val) { + if (val > (1ull << sizeof(u32) * 8) - 1) + return -EINVAL; *(u32 *)data =3D val; return 0; } --=20 2.31.1 From nobody Sun Feb 8 06:49:53 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40C4DC77B73 for ; Tue, 30 May 2023 19:41:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233306AbjE3TlB (ORCPT ); Tue, 30 May 2023 15:41:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233207AbjE3Tku (ORCPT ); Tue, 30 May 2023 15:40:50 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA6E4C9 for ; Tue, 30 May 2023 12:40:46 -0700 (PDT) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34UJEtD4002489; Tue, 30 May 2023 19:40:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-03-30; bh=Zxjg7z3fa9CALbmlAr+UvBOJ5h4y8BfV0NJkPtfRUAI=; b=jSI2izY0J9nP3OXs1ZzxlStJXppMS3VepkqFkcZhnE8hvTiEyXAE0JZPHOGvr+XVWC+R IcYssqwSaHkyRQYzQLqqHlfzhpEZTv4z0eVUKXyK7tE+xWKDDQb/uGDIKZGQcDg8iQ8W pmASCsF4Vqsdh+myEJyoNGJWxl0NpreA8d0H/L0derRx71rYxRAVcs0UAWaZLiNoanMP NZExkD375+e5Z9yUeIkgLA4dTPtqAWIhK59QEa2MNkgnN62PisNHnqGmiuZ/gnHCL8tk 3ipaiFrpkTnPw8r0WLkEB7Kmy2yBGaipKcFszIq2p3/skg1H4fazESb6yUGwq7Ddre7u XA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qvhd9uubv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 May 2023 19:40:36 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34UJYdk5019748; Tue, 30 May 2023 19:40:35 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qu8a4mb4q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 May 2023 19:40:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tv/xE4wPM00Qx3tCUasvRO+6ooSMlcDPRz2yYwpSBZ/qKD5klIYEaduVaUEC2P2qHAw7Nu3W3qr/IEtiQHgzgIaHR1mvck4YjB6j/66+A90feoWhI/yR/yz5epRjR0qnvG3eCi371MvYqYlFs28ee43XBCXqQaOnBKYJiMPdTvrBc/JvB6re24ZXnPpB7dDc9xE0U18gEEKmQS7C64QAGjbBKbRfvIGtndobsU/6Qc2SGtq629BvcCo+KT/EOJTykxV06SYFZoswDgv4fKUCXtHriyqbJNM5BYHxSONTnK7CeTOaXcxStaXW7uxoGh4T/8S4pPt54U6+DloZOBvcZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Zxjg7z3fa9CALbmlAr+UvBOJ5h4y8BfV0NJkPtfRUAI=; b=GzrrU7v7V03x/nlw7ttaDkfeqoVxESXL2twPok08106l+3LPF/bTCTvj1X7YZrNMnWfMM1Yn9NS6UU++GKJ2zppHR+OiAq5O+aySgRnGONVfijbrVCnfVrDknfZ6noRIdBBkj29YoweKhXNRmdE2qbNIHg/zAQFswfJC+DCea53/aTu2R7iMI96AycruFJoecJseSZ1IMRqk+aa1dNRcUzf0ee0vHQClaf37hTXZf1J69ofmzvgqVZQ7wHsnuXDJ71thf7gxJ9Ln0fFaNKbFlCqmj5mHE8JPn9+y8AKQyWnmfQ6AEdOmtPEInnOZWdRdDNQ/+ZDdzcrxdsl8vLx0mQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Zxjg7z3fa9CALbmlAr+UvBOJ5h4y8BfV0NJkPtfRUAI=; b=GIFQBfy+yY+mNOi5xbsPC8l9eN5dhSXPlmQCSkk+G7RHJvIxKYqH7oV2frcONc3x6UN21pK0Vb9bzUgUnBqY8n6AE6+s77Ej1yqYCVfxgzqinRZK6BE851bSMqsGwmN5mh2kh4nEFu7ARvJ8mL/+G8nvWWYXK7EwcClsOpDqSm8= Received: from CO1PR10MB4705.namprd10.prod.outlook.com (2603:10b6:303:96::11) by CY5PR10MB6214.namprd10.prod.outlook.com (2603:10b6:930:31::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Tue, 30 May 2023 19:40:32 +0000 Received: from CO1PR10MB4705.namprd10.prod.outlook.com ([fe80::11b8:4b2e:26c5:1bb3]) by CO1PR10MB4705.namprd10.prod.outlook.com ([fe80::11b8:4b2e:26c5:1bb3%2]) with mapi id 15.20.6433.022; Tue, 30 May 2023 19:40:32 +0000 From: chris hyser To: chris.hyser@oracle.com, linux-kernel@vger.kernel.org, peterz@infradead.org, gregkh@linuxfoundation.org, "Rafael J. Wysocki" Subject: [PATCH 2/4] debugfs: Provide min/max checking for simple u8, u16, u32, u64 debugfs files. Date: Tue, 30 May 2023 15:40:10 -0400 Message-Id: <20230530194012.44411-3-chris.hyser@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230530194012.44411-1-chris.hyser@oracle.com> References: <20230530194012.44411-1-chris.hyser@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SJ0PR03CA0375.namprd03.prod.outlook.com (2603:10b6:a03:3a1::20) To CO1PR10MB4705.namprd10.prod.outlook.com (2603:10b6:303:96::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4705:EE_|CY5PR10MB6214:EE_ X-MS-Office365-Filtering-Correlation-Id: 44889246-5b36-4e02-94b0-08db6145bb48 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KahGeb2DHOkdV2tkZv7LZczEd+oEXfoym7FEGXMN0TwYWBoEuOe725oh56ymgYvSz48Zb9Jf3FoS8WEGcaw87pQnuUXKiDh+V97sH5VPyzfC9DOHcRmsbBmOteQP7W1zByCU65hoDI8w2+Z5HgKv2dAKcSiyxptVj25Rt7zX2hiRxoiaQzTUxBeSDocfwen/cUj9s97sMkkxJVMO2yoaXHTArt5Ba3irOHkdnSpEbmMto5iQJ2WfALoLAQcm7aa1ewwpca5d6+RiORxbcIZYptY9UBX4ITP+z8NE6VUi6cp98fjTCS6uE+1IV2b8w/Ot/FPVshAFCpn+50PA3iChMqZGeuCMPKAtY36+RKqrwR4XffMXGZi2VjLEok7aDcAMCXaMu3e0uagHDoYNByg4eGIkkk7uPxXkyqiowClF4oHRUzoGrjAmFEeAc6v+q+3GBcU4Tp192bL+MgeCmk+ziorGZMo082TasYnqcQiA9lFSWpgYrK2d52LZwQpJrva3/R3RgC06yqqgsRv2+9Q2t5S/L6OF2DQRN8vYtqxsXhQkqOzqppRNJ/KykzZMqmJ2 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR10MB4705.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(396003)(366004)(346002)(136003)(376002)(451199021)(478600001)(8676002)(8936002)(5660300002)(6916009)(30864003)(36756003)(2906002)(86362001)(66946007)(66556008)(66476007)(316002)(38100700002)(41300700001)(2616005)(186003)(6512007)(26005)(1076003)(6506007)(6486002)(6666004)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?iNzIg0b9/CA91ezbvmGMom7pIr4nn1hpggcHH4xaymUs3sCSmcZs76upEMrn?= =?us-ascii?Q?G7GHDwDpq3lkx5KSZckrY6xi4NtLpoTPvjQYxn8+6jQMBAsV+BcmjPNWbcgK?= =?us-ascii?Q?jIji0Tdxzv4uvvdsVtRShxt+8bcn9xaloBXp/HxxQ3qSlZwd0K/aRo5+GYTY?= =?us-ascii?Q?Hpej1ta0um5noFZ6UcT6cGjw1B3YNkSe9x5uQqwCjYArZcUf5jmVyMAToTCH?= =?us-ascii?Q?Wy/A46xwynuZhaQ0IPMZw2ZkNkcIrT2QAz8uFHGEIZdaFzEkYPWwFphNLxPb?= =?us-ascii?Q?3O2SNYexVMRhEs78thkhUPMYxvWOo4EPefKpxlYDeLzLpXC/Mo9hiVBnqWTB?= =?us-ascii?Q?SyKQiQWdu/z3xfX8KrrZTbY5XrR1jRFz/kCMw5raGqAXI+qq5edbGPoKakF+?= =?us-ascii?Q?OPtPG03Oqa623OQwZhoVvNRChFMceiclqYo+LcApBlNv4OU8qDlKdZe0bFjf?= =?us-ascii?Q?8Z/6tEdB7rrajs0U3Zp6NHUxn8iSwPKf/eh1v0yb/I9Z1mRxlfUI72lsN/WS?= =?us-ascii?Q?Awtwfku16RlfezS55f90NuWTbA+G16j8ao55YXck+Rboo4Leu0tdHiiJgeO5?= =?us-ascii?Q?f1w210S28PlCQjO47BXo1el9Ysz+Cu8MLXAjmdDGrmcjjRjR1kEJ7K2n/9Rz?= =?us-ascii?Q?yvEAQhYsm3W+9ojdteTX+6KhIfQihvG0A2XUjPYAF+Kfshwf+8T3/+XPfkK6?= =?us-ascii?Q?7X88cD1MsjSXRp2Hx+RPamrtI+KEs58mYV8BagLKeto/xaT2pChwd09SPS7X?= =?us-ascii?Q?7BkZEoCCg8fChupo7DSuWqqpP9G0hXKzcZ7tjDnpcoeveQhobAmyNmKYbtl9?= =?us-ascii?Q?E2p+T6SPaSp8LAjWBuiXWmF8VGAbFeisl1TxemqY+bKRcrbKyaT1tVVGm4O4?= =?us-ascii?Q?Rg3RE5SRsnCiO106+NVkzm2yPyGAjiFJA/1ndSdmLqSP8LhWkDPGVvwXkj5E?= =?us-ascii?Q?qs69IFJ7g4j7lZMlZz3R0t2XZ03gFTKjgqFORXFXnz1rXBgEYVQSd+WUfzzS?= =?us-ascii?Q?+B03tD8qrOTzlA4nZcRuVQukHfU/sa9rejTgv7paneSAlC7okjXxNhjTlmjg?= =?us-ascii?Q?ZczvHOqU02n0tQT0zUueMAW7q3wuE+xuxu7vkgKjlu2SMSg8U04sl2eEmF7B?= =?us-ascii?Q?iCfeZXL8rVvc8//aJt9lxQlHWiglyLlA+J9tZGxxvE6ejiF8uOj3uJ+7xJnO?= =?us-ascii?Q?iQYV5+s34cjc8EFQIWBxvT6p14fvBywHb96h3BIbFCJE7aUEMrpWcFOcPZWP?= =?us-ascii?Q?WV9zGCO8oRROAZtq9NgxX63bmtekQsTjyzQKf/BcHY3Djapm4ydckpvtQ+93?= =?us-ascii?Q?Z7fslh24NuQ/2dnErKvGJNwh+SR8ktKG/owRbKDCPzuaiGEg27bBY3ok5zZB?= =?us-ascii?Q?mS1b1DNBKqWnaIuvmfF/W9JUNZPxx6iSiGGnAcguHls7/vO0eCgcYJiDv8MC?= =?us-ascii?Q?SoKuH43I43uZOmy9noL3Alg/KrUj+otWUxQmQY+IZj2tOJRV4uUg3wDlbRGo?= =?us-ascii?Q?orgQ++8mMAWKB1hxwnwfirktOIPYk7bIjmJ1zz2wrPRS2TD/4dvzeQYg164F?= =?us-ascii?Q?95YtVjGCyrj6yagYCyDZvGSZly55KYE6+HhvHTQ/?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: QX5TOhw/98qT1DFKtA+0gStuLa4UtaSsdOaYV7FfxMoNF4zdQEUM4i+OQ3rbpsECeYWEYaKYCPR7/tlwvsGTydC97GzCPmwPYbeMsRyyxtLufKZ17rfOasQ7ah2kV34esAnyeqFA7iMH8vmUsStkHMQxMOuPXiuJqbkIMFimLrX2PecqiUNZEk12xSVVe5HzPSTACJurH24sizp6pu9d4Ym4/zJ28SYDKNqMibItXkWLl93h1KCLkOomH6r+/mOAmTIqjGkZ4FPBUC7Fg+KymmtBWFvZRSaDKCxLW+WFppvDZM015CuO6lGRhRx2W9RSIPM8B7Og7cZwBDjCuyMV4JNYLkJ6ZdmJBOS9H7f0EFSGYMU4cKvIRs8nH6HTzI5lrLlsCjVS2A4KkTq1rGJXwljgvJfpbl6QFg+if88rxKQWc+1rlODYFGbQGt/gRgL6GLbiqvtcV60NVEjQJcMvfgC8WPzidkoqH3dQzPIQZlhb+dUS97b0IHhHZylgZQC5uq2zz/KyCIz0COJ8Ddz/vkVRGVFGgV6ZAaG1ImR2Y6d/gee+CMuE6VpQNmjsaj3IfSbwSKGCI1zYacZP0lyJYIrSGRfIDjEZdYcgHKThXBnQGCpWJhoi1KbxOf5/exmHK6jJrWf+KaLalYpyNI/LYxK0RDJvzCjGbv3YjGON3w5v/uYyRMA+C9VNu0HE714/5kv2EQTMazS9oBpm+gg3ZUniqYcVDs9Td//gf2kCBACM1smCsVxnJwj1EvifdgBlwjU5mWHS2bmN51bEG3p5GosD3twddKXe0lhOAgjc8tBXVxnvA5x46NFThB7MxYUQ1b0nn0C07E0Us9q7jLxsfhx37nfgMq1ESY5rPpYDMNqLViKKELNuO1jWuEHxmcUb X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 44889246-5b36-4e02-94b0-08db6145bb48 X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4705.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2023 19:40:32.7689 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 81nmkSJSnYwTrtjE7PMfmUIsUiP9J+RPiol5sovZM8JyeCiePIGm801zRGQnX97tTrEeL1Hfi1TpVCRDwExnaw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR10MB6214 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-30_15,2023-05-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305300159 X-Proofpoint-GUID: db2bk-tEHevCL_piht6FzJavvyW9joMo X-Proofpoint-ORIG-GUID: db2bk-tEHevCL_piht6FzJavvyW9joMo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch extends the simple file interface to include min/max checking files. Writes to a file are checked such that the written value must satisfy the specified check (as well as fit into the specified storage): minmax: 'min' <=3D value <=3D 'max' min: 'min' <=3D value max: value <=3D 'max' Failure of the check returns EINVAL. While the same checks could be done by providing a custom "set(void *data, u64 val) function" in DEFINE_DEBUGFS_ATTRIBUTE() for each file needing said check, each instance would require a private struct file_operations. Using the same trick as the unsigned simple files (u8/u16/u32/u64), this patch supports "unlimited" users with only two struct file_operations per unsigned type. As min/max checking only applies to set/writing, read-only files make no sense. Various macros are provided to simplify setting up the params struct. Signed-off-by: Chris Hyser --- Documentation/filesystems/debugfs.rst | 39 ++++++ fs/debugfs/file.c | 189 ++++++++++++++++++++++++++ include/linux/debugfs.h | 60 ++++++++ 3 files changed, 288 insertions(+) diff --git a/Documentation/filesystems/debugfs.rst b/Documentation/filesyst= ems/debugfs.rst index 6f1ac8d7f108..31d186e952eb 100644 --- a/Documentation/filesystems/debugfs.rst +++ b/Documentation/filesystems/debugfs.rst @@ -99,6 +99,45 @@ functions can be used instead:: void debugfs_create_x64(const char *name, umode_t mode, struct dentry *parent, u64 *value); =20 +Some use cases require min/max checking of the written values preserving t= he +initial value on failure and returning EINVAL for the write. + + void debugfs_create_u8_minmax(const char *name, umode_t mode, + struct dentry *parent, + struct debugfs_minmax_params *mnxp); + void debugfs_create_u16_minmax(const char *name, umode_t mode, + struct dentry *parent, + struct debugfs_minmax_params *mnxp); + void debugfs_create_u32_minmax(const char *name, umode_t mode, + struct dentry *parent, + struct debugfs_minmax_params *mnxp); + void debugfs_create_u64_minmax(const char *name, umode_t mode, + struct dentry *parent, + struct debugfs_minmax_params *mnxp); + +These functions are called with the following parameter structure, flags a= nd +helper macros. The parameter structure must be available for the duration = of +the file, thus requiring global or malloced memory. Failure of the specifi= ed +check(s) return EINVAL. + +struct debugfs_minmax_params { + void *value; + u64 min; + u64 max; + u8 flags; +}; + +Flags are defined as such: + DEBUGFS_ATTR_MIN 1 + DEBUGFS_ATTR_MAX 2 + DEBUGFS_ATTR_MINMAX (DEBUGFS_ATTR_MIN | DEBUGFS_ATTR_MAX) + +Additional helper macros provide for + DEBUGFS_MINMAX_ATTRIBUTES_BASE(name_parm_ptr, value, min, max, flags); + DEBUGFS_MIN_ATTRIBUTES(name_parm_ptr, value, min); + DEBUGFS_MAX_ATTRIBUTES(name_parm_ptr, value, max); + DEBUGFS_MINMAX_ATTRIBUTES(name_parm_ptr, value, min, max); + These functions are useful as long as the developer knows the size of the value to be exported. Some types can have different widths on different architectures, though, complicating the situation somewhat. There are diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 743ddd04f8d8..bd655b286da6 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -578,6 +578,195 @@ void debugfs_create_u64(const char *name, umode_t mod= e, struct dentry *parent, } EXPORT_SYMBOL_GPL(debugfs_create_u64); =20 +static int debugfs_minmax_chk(struct debugfs_minmax_params *mnxp, u64 val) +{ + if ((mnxp->flags & 0x1) && val < mnxp->min) + return -EINVAL; + if ((mnxp->flags & 0x2) && val > mnxp->max) + return -EINVAL; + return 0; +} + +static int debugfs_u8_minmax_set(void *data, u64 val) +{ + struct debugfs_minmax_params *mnxp =3D data; + int err =3D debugfs_minmax_chk(mnxp, val); + + if (err) + return err; + return debugfs_u8_set(mnxp->value, val); +} + +static int debugfs_u8_minmax_get(void *data, u64 *val) +{ + struct debugfs_minmax_params *mnxp =3D data; + + return debugfs_u16_get(mnxp->value, val); +} + +DEFINE_DEBUGFS_ATTRIBUTE(fops_u8_minmax, debugfs_u8_minmax_get, debugfs_u8= _minmax_set, "%llu\n"); +DEFINE_DEBUGFS_ATTRIBUTE(fops_u8_minmax_wo, NULL, debugfs_u8_minmax_set, "= %llu\n"); + +/** + * debugfs_create_u8_minmax - create a debugfs file that is used to both r= ead + * and write an unsigned 8-bit value if it satisfies a min check, max = check + * or both. + * @name: a pointer to a string containing the name of the file to create. + * @mode: the permission that the file should have + * @parent: a pointer to the parent dentry for this file. This should be a + * directory dentry if set. If this parameter is %NULL, then the + * file will be created in the root of the debugfs filesystem. + * @mnxp: a pointer to the parameter struct which holds the test limits, t= he + * test to perform and a pointer to the variable to display and mod= ify. + * + * This function creates a file in debugfs with the given name that contai= ns + * the value of the specified variable. If the @mode variable is so + * set, it can be read from, and written to. + */ +void debugfs_create_u8_minmax(const char *name, umode_t mode, + struct dentry *parent, + struct debugfs_minmax_params *mnxp) +{ + debugfs_create_mode_unsafe(name, mode, parent, mnxp, &fops_u8_minmax, + NULL, &fops_u8_minmax_wo); +} +EXPORT_SYMBOL_GPL(debugfs_create_u8_minmax); + +static int debugfs_u16_minmax_set(void *data, u64 val) +{ + struct debugfs_minmax_params *mnxp =3D data; + int err =3D debugfs_minmax_chk(mnxp, val); + + if (err) + return err; + return debugfs_u16_set(mnxp->value, val); +} + +static int debugfs_u16_minmax_get(void *data, u64 *val) +{ + struct debugfs_minmax_params *mnxp =3D data; + + return debugfs_u16_get(mnxp->value, val); +} + +DEFINE_DEBUGFS_ATTRIBUTE(fops_u16_minmax, debugfs_u16_minmax_get, debugfs_= u16_minmax_set, "%llu\n"); +DEFINE_DEBUGFS_ATTRIBUTE(fops_u16_minmax_wo, NULL, debugfs_u16_minmax_set,= "%llu\n"); + +/** + * debugfs_create_u16_minmax - create a debugfs file that is used to both = read + * and write an unsigned 16-bit value if it satisfies a min check, max= check + * or both. + * @name: a pointer to a string containing the name of the file to create. + * @mode: the permission that the file should have + * @parent: a pointer to the parent dentry for this file. This should be a + * directory dentry if set. If this parameter is %NULL, then the + * file will be created in the root of the debugfs filesystem. + * @mnxp: a pointer to the parameter struct which holds the test limits, t= he + * test to perform and a pointer to the variable to display and mod= ify. + * + * This function creates a file in debugfs with the given name that contai= ns + * the value of the specified variable. If the @mode variable is so + * set, it can be read from, and written to. + */ +void debugfs_create_u16_minmax(const char *name, umode_t mode, + struct dentry *parent, + struct debugfs_minmax_params *mnxp) +{ + debugfs_create_mode_unsafe(name, mode, parent, mnxp, &fops_u16_minmax, + NULL, &fops_u16_minmax_wo); +} +EXPORT_SYMBOL_GPL(debugfs_create_u16_minmax); + +static int debugfs_u32_minmax_set(void *data, u64 val) +{ + struct debugfs_minmax_params *mnxp =3D data; + int err =3D debugfs_minmax_chk(mnxp, val); + + if (err) + return err; + return debugfs_u32_set(mnxp->value, val); +} + +static int debugfs_u32_minmax_get(void *data, u64 *val) +{ + struct debugfs_minmax_params *mnxp =3D data; + + return debugfs_u32_get(mnxp->value, val); +} + +DEFINE_DEBUGFS_ATTRIBUTE(fops_u32_minmax, debugfs_u32_minmax_get, debugfs_= u32_minmax_set, "%llu\n"); +DEFINE_DEBUGFS_ATTRIBUTE(fops_u32_minmax_wo, NULL, debugfs_u32_minmax_set,= "%llu\n"); + +/** + * debugfs_create_u32_minmax - create a debugfs file that is used to both = read + * and write an unsigned 32-bit value if it satisfies a min check, max= check + * or both. + * @name: a pointer to a string containing the name of the file to create. + * @mode: the permission that the file should have + * @parent: a pointer to the parent dentry for this file. This should be a + * directory dentry if set. If this parameter is %NULL, then the + * file will be created in the root of the debugfs filesystem. + * @mnxp: a pointer to the parameter struct which holds the test limits, t= he + * test to perform and a pointer to the variable to display and mod= ify. + * + * This function creates a file in debugfs with the given name that contai= ns + * the value of the specified variable. If the @mode variable is so + * set, it can be read from, and written to. + */ +void debugfs_create_u32_minmax(const char *name, umode_t mode, + struct dentry *parent, + struct debugfs_minmax_params *mnxp) +{ + debugfs_create_mode_unsafe(name, mode, parent, mnxp, &fops_u32_minmax, + NULL, &fops_u32_minmax_wo); +} +EXPORT_SYMBOL_GPL(debugfs_create_u32_minmax); + +static int debugfs_u64_minmax_set(void *data, u64 val) +{ + struct debugfs_minmax_params *mnxp =3D data; + int err =3D debugfs_minmax_chk(mnxp, val); + + if (err) + return err; + return debugfs_u64_set(mnxp->value, val); +} + +static int debugfs_u64_minmax_get(void *data, u64 *val) +{ + struct debugfs_minmax_params *mnxp =3D data; + + return debugfs_u64_get(mnxp->value, val); +} + +DEFINE_DEBUGFS_ATTRIBUTE(fops_u64_minmax, debugfs_u64_minmax_get, debugfs_= u64_minmax_set, "%llu\n"); +DEFINE_DEBUGFS_ATTRIBUTE(fops_u64_minmax_wo, NULL, debugfs_u64_minmax_set,= "%llu\n"); + +/** + * debugfs_create_u64_minmax - create a debugfs file that is used both to = read + * and write an unsigned 64-bit value if it satisfies a min check, max= check + * or both. + * @name: a pointer to a string containing the name of the file to create. + * @mode: the permission that the file should have + * @parent: a pointer to the parent dentry for this file. This should be a + * directory dentry if set. If this parameter is %NULL, then the + * file will be created in the root of the debugfs filesystem. + * @mnxp: a pointer to the parameter struct which holds the test limits, t= he + * test to perform and a pointer to the variable to display and mod= ify. + * + * This function creates a file in debugfs with the given name that contai= ns + * the value of the specified variable. If the @mode variable is so + * set, it can be read from, and written to. + */ +void debugfs_create_u64_minmax(const char *name, umode_t mode, + struct dentry *parent, + struct debugfs_minmax_params *mnxp) +{ + debugfs_create_mode_unsafe(name, mode, parent, mnxp, &fops_u64_minmax, + NULL, &fops_u64_minmax_wo); +} +EXPORT_SYMBOL_GPL(debugfs_create_u64_minmax); + static int debugfs_ulong_set(void *data, u64 val) { *(unsigned long *)data =3D val; diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h index ea2d919fd9c7..322fecb22a0a 100644 --- a/include/linux/debugfs.h +++ b/include/linux/debugfs.h @@ -43,6 +43,36 @@ struct debugfs_u32_array { u32 n_elements; }; =20 +struct debugfs_minmax_params { + void *value; + u64 min; + u64 max; + u8 flags; +}; + +/* debugfs_minmax_params "flag" values + */ +#define DEBUGFS_ATTR_MIN 1 +#define DEBUGFS_ATTR_MAX 2 +#define DEBUGFS_ATTR_MINMAX (DEBUGFS_ATTR_MIN | DEBUGFS_ATTR_MAX) + +#define DEBUGFS_MINMAX_ATTRIBUTES_BASE(__name, __value, __min, __max, __fl= ags) \ +static struct debugfs_minmax_params __name =3D { \ + .value =3D (__value), \ + .min =3D (__min), \ + .max =3D (__max), \ + .flags =3D (__flags), \ +} + +#define DEBUGFS_MIN_ATTRIBUTES(__name, __value, __min) \ + DEBUGFS_MINMAX_ATTRIBUTES_BASE(__name, __value, __min, 0, DEBUGFS_ATTR_MI= N) + +#define DEBUGFS_MAX_ATTRIBUTES(__name, __value, __max) \ + DEBUGFS_MINMAX_ATTRIBUTES_BASE(__name, __value, 0, __max, DEBUGFS_ATTR_MA= X) + +#define DEBUGFS_MINMAX_ATTRIBUTES(__name, __value, __min, __max) \ + DEBUGFS_MINMAX_ATTRIBUTES_BASE(__name, __value, __min, __max, DEBUGFS_ATT= R_MINMAX) + extern struct dentry *arch_debugfs_dir; =20 #define DEFINE_DEBUGFS_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, __is= _signed) \ @@ -122,6 +152,20 @@ void debugfs_create_u32(const char *name, umode_t mode= , struct dentry *parent, u32 *value); void debugfs_create_u64(const char *name, umode_t mode, struct dentry *par= ent, u64 *value); + +void debugfs_create_u8_minmax(const char *name, umode_t mode, + struct dentry *parent, + struct debugfs_minmax_params *mnxp); +void debugfs_create_u16_minmax(const char *name, umode_t mode, + struct dentry *parent, + struct debugfs_minmax_params *mnxp); +void debugfs_create_u32_minmax(const char *name, umode_t mode, + struct dentry *parent, + struct debugfs_minmax_params *mnxp); +void debugfs_create_u64_minmax(const char *name, umode_t mode, + struct dentry *parent, + struct debugfs_minmax_params *mnxp); + void debugfs_create_ulong(const char *name, umode_t mode, struct dentry *p= arent, unsigned long *value); void debugfs_create_x8(const char *name, umode_t mode, struct dentry *pare= nt, @@ -287,6 +331,22 @@ static inline void debugfs_create_u32(const char *name= , umode_t mode, static inline void debugfs_create_u64(const char *name, umode_t mode, struct dentry *parent, u64 *value) { } =20 +static inline void debugfs_create_u8_minmax(const char *name, umode_t mode, + struct dentry *parent, + struct debugfs_minmax_params *mnxp) { } + +static inline void debugfs_create_u16_minmax(const char *name, umode_t mod= e, + struct dentry *parent, + struct debugfs_minmax_params *mnxp) { } + +static inline void debugfs_create_u32_minmax(const char *name, umode_t mod= e, + struct dentry *parent, + struct debugfs_minmax_params *mnxp) { } + +static inline void debugfs_create_u64_minmax(const char *name, umode_t mod= e, + struct dentry *parent, + struct debugfs_minmax_params *mnxp) { } + static inline void debugfs_create_ulong(const char *name, umode_t mode, struct dentry *parent, unsigned long *value) { } --=20 2.31.1 From nobody Sun Feb 8 06:49:53 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1A51C77B73 for ; Tue, 30 May 2023 19:40:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233273AbjE3Tk6 (ORCPT ); Tue, 30 May 2023 15:40:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231173AbjE3Tkr (ORCPT ); Tue, 30 May 2023 15:40:47 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93426F9 for ; Tue, 30 May 2023 12:40:45 -0700 (PDT) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34UJW1se002469; Tue, 30 May 2023 19:40:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-03-30; bh=L43E44kWSr0c0jV9sRrZTB0m3KhuZQDOHJYJYhQ2QY0=; b=LBID6qz8tU+rqzg0SvjhycBU53t+UUPJaT7lUJmjW5b6vBJyezZDfzVN5xH4gPAB5Gl2 7H67q7TjzF9A+62JxWvNykzToPqmxUFidgEPhYK2ce3+oX1dUY/KbkyywbRZyGAX4RWL GZkXrILRj+adhncxsDfn0oRfKJ23LUEGzFXIWK0AH4vUlOsYWdOORevNmMKONK2CJVDk 09GZowJBn4EzQD+IQ9ncs+J1aRKyTGHDMoA+ab57OD2V99Rj07VaoWUUejlLFKdYNQhM jAG8xc/iHn4WE+uGk1qxPDeu4dNuauAmZ0gWYf6/K/irCHEzyOMikJqx51YuCy6MG/yX zg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qvhd9uuby-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 May 2023 19:40:38 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34UIlE6u019825; Tue, 30 May 2023 19:40:37 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2169.outbound.protection.outlook.com [104.47.58.169]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qu8a4mb6b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 May 2023 19:40:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GjEN5tXh6NyFisHuBMk8r5StuZuRepbJx/R8DIrJew72bXJ9DNMztRiJ9upI7AQ5L/rGbdmH+wL5niFATf5gRUVWXYqWvHj4LEn2u3mekpTxOkBnLTQ34jFPuIGJlxl8Ki1uhJQ4zAnufOOuDlu8JvaHqOtlDY29x2fD276yQEAIxVcd9hjb8FhrVQotIMpgNuGLqHL5efRtcq4QhHZuCVAwqpAQIBqEDOxn0YJRV8ncfL7RcV8w/AreiSIANpydLmEn2URzlnRG5O47ZocQP5VuD8GHzF6Q04riEi8Ahnpu3yKRwyE7IdvZilSkkJ1Y2u4v5Dt3fWuE5L7mF5MzuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=L43E44kWSr0c0jV9sRrZTB0m3KhuZQDOHJYJYhQ2QY0=; b=NVqp5rm1PuGcU+KSTkGnAbFpKaioalpe2XnC/Ddo/oilKdiKxOi9yu37+ugYE1lwwnOqaezQ62pUPl974H9YtjKhro9OEBqNmmGDFV8DkU0kkzj1Tsput5i94dF1oVso3CY2T65UuInOUORYZzDBQqDVc1BFuM27Vdm+Jf/yM/G29/bDRsemP65cdDW4vkjDPeFe2sCa27aout07zpifgZfHKIbRuvJJ+yvgcKpGf6X87Ntc8H4SqtEJTFZ8stTdi5R3cVMwhrq/DsuqBG/QLP2tb6Py8fX48tHUS4DNendZ1X3ZNtkkAP93UhbRqrkJViWOTUcj0iM1xLWKmAKHrA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=L43E44kWSr0c0jV9sRrZTB0m3KhuZQDOHJYJYhQ2QY0=; b=tpKePSeHy3hoXL03NZu9CalGqAQ4EQXQ+qKxHIOWv7KeGps+q9A8u/I43+Djcf2eANRdD3OrBWAmOT6WX0duKhrUQ6RJ742qrMZGI7VrPIoizGgYDJudGYAtYcbI0nk5RBphPzACINoGPEMf0V7DPz7+QHZTllZeUgWKn3rigio= Received: from CO1PR10MB4705.namprd10.prod.outlook.com (2603:10b6:303:96::11) by CY5PR10MB6214.namprd10.prod.outlook.com (2603:10b6:930:31::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Tue, 30 May 2023 19:40:35 +0000 Received: from CO1PR10MB4705.namprd10.prod.outlook.com ([fe80::11b8:4b2e:26c5:1bb3]) by CO1PR10MB4705.namprd10.prod.outlook.com ([fe80::11b8:4b2e:26c5:1bb3%2]) with mapi id 15.20.6433.022; Tue, 30 May 2023 19:40:35 +0000 From: chris hyser To: chris.hyser@oracle.com, linux-kernel@vger.kernel.org, peterz@infradead.org, gregkh@linuxfoundation.org, "Rafael J. Wysocki" Subject: [PATCH 3/4] debugfs: provide testing for the min/max simple debug files. Date: Tue, 30 May 2023 15:40:11 -0400 Message-Id: <20230530194012.44411-4-chris.hyser@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230530194012.44411-1-chris.hyser@oracle.com> References: <20230530194012.44411-1-chris.hyser@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SJ0PR03CA0382.namprd03.prod.outlook.com (2603:10b6:a03:3a1::27) To CO1PR10MB4705.namprd10.prod.outlook.com (2603:10b6:303:96::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4705:EE_|CY5PR10MB6214:EE_ X-MS-Office365-Filtering-Correlation-Id: 5ca88047-85c1-4911-d352-08db6145bcbe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Trtk8dU6wD59R/GKVqVadu8aBrgJvDz2eaE5/JHexPZ9gBbBhRiCTZidPh4NQvTfT+527pA1wh6v51/7u5EnCpSyy8dOGQg2HT/j2DnhOptqa5cuXxkfhf1O8iBo5byMWbKzmv1VOcu6oHWiRlXrWamXP/LS15qU91I3SjZpfOj0auloZQbRtSAK1Br1KemA/UFPHEQ/l8R5+Bfvb4v1Ni+gJ+OCKugk2wmx3ZPWhZDVjwnrp+Wrf1VFBw+HaFwHMAEM16a+Bsrbyz6IQo186HDlp1N7fYe5ORMdkkaSEpgepKQoi37gmK2s0uoYj+ShVHMxHU0QlqwfZTS5P81GoE//c8K1i5fgvTOdTMGHYOfQoM/54P4bpeBxGZJGiBeuiaiWmrGCHHV222en8GauQ0aDbvY7Ndu8NEXGnEr8Qh9wE9dXbL+lf6N3WEucpEPJAT2zX7NGXUAJWaLpjr0oFHunOfLGY4Kv0wz2LNKDwKHr6tLziVrE3BDiYB9D9R4lt4aFipuEk+VuoW16TwIAWFs+AMNQl/BW04lpGJW8hzz5NpvN0lNymaskdFpEn9upDYnnZ6sPvcll7Njy64fv2eEsyWiNMkBjJ2+9X4psTGk= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR10MB4705.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(396003)(366004)(346002)(136003)(376002)(451199021)(478600001)(8676002)(8936002)(5660300002)(6916009)(36756003)(2906002)(86362001)(66946007)(66556008)(66476007)(316002)(38100700002)(41300700001)(2616005)(186003)(6512007)(26005)(1076003)(6506007)(6486002)(6666004)(83380400001)(2004002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?1dUgy34BowQh5MoHiM1kt/DnD678Aagk42GJ2xixHw1CoiGTrLtbrZQ9goMS?= =?us-ascii?Q?ToAgmwAvHuOsPcONa67Ox0PZWFsL8NckMUBWdNUhS3IpZntkBz5HbURwhPGI?= =?us-ascii?Q?XYrZ6v4CtGOySNiHRDaVrmFVW7fdL8SuM0plbarNf+MHVV32RMmO9u43DN0D?= =?us-ascii?Q?8ce36zmiRrjxynQQeocAABf3mXzXj/hXoMpDrvNHZDceAABClTryjtegIDqQ?= =?us-ascii?Q?ZMKRDS+N+DEEWaTzRQbkVJAYk9J4hod5LJ7XEi2J//Hw0dbcehVc5kOS5inn?= =?us-ascii?Q?fY5rfMzx1UCnhNHivp9E/NHFkd0OOLgMiGO5vQtikuwtJZIftXBoBbZVdlP6?= =?us-ascii?Q?dTxSBdQerXzMgGMmiDyEyXfc1ZjfcoWWLwhGw7Ni+tGzvYLgOXHKYWqH7+V8?= =?us-ascii?Q?qi7cnWHAM6rXm+UYsPxe0qwmn7YcoR8IvVCR27cgdwrhS+nEsSFAd0V49Oyl?= =?us-ascii?Q?pous+4gl43fLKiht10MierLmwDLNIsctJE9VdRlyonwqp/rhNMJwbQLtKa2H?= =?us-ascii?Q?ba7zUR75F/uk+26ovHM9OikbAFbq9YKGYVrElKMmlMITISfCaGzyyKpFOt8P?= =?us-ascii?Q?QKb+2J/vlNjwi94OB8/Fi62GDQyFiVrhdKhQOX9bRDGHFDg4BVlj8hZyM4wR?= =?us-ascii?Q?SGMES41Etz8Oo/PpSVYjF4kEqvGRldrxIuAO6p1W99z7BcOKI8w14tKcV47u?= =?us-ascii?Q?LzJacfQm0dKAthBC3RpeZxAlhrC+FTyxZXB6PWoBadys0iHPU+R9bqut/JX5?= =?us-ascii?Q?8L/w4QP46AJ1PRbPHtUatCf1HA7CnXcJ5BbctmWxbZbG5vTyCwGlJ72ZU6RQ?= =?us-ascii?Q?DLBdooVXBemP8WKsZmEV0HhwvyG2cVdxZxBgCJRyGwQiPCL3uslmuJtEzMhj?= =?us-ascii?Q?foxggpCTzZI0ErzhTqXU0L8ZNaXy0+lGLcWpUkMy48iWFFoT63PY3XB1+lxo?= =?us-ascii?Q?zWMZf75kuudcZzKCnaXarK2fQqILPa6j+Y2xQJb1rlgx6w+FnxTPKiuWWoX1?= =?us-ascii?Q?iHu4YIrdoARAMUsYibmZO38HY9KtQ1r/9sDd2jGQmvvRyz43XmyeCLYawbJ6?= =?us-ascii?Q?xm5iRN4tBmcFu3UHdCC1angF+NWxT5cHu2WTVJENV9S8mdDqDmW+0AmSrYrm?= =?us-ascii?Q?eBuP9NWgPgLK4EyXyfTyPY38u1cPizQikXLvRc/x0EqlUft777X1h6yswv12?= =?us-ascii?Q?xV+1wlR39M9DwvTmSPXXFvXiiDCUqL4mhWuzX/WwLlfemDOP8UByFt2pdKD7?= =?us-ascii?Q?Xrj4C++8o3qM/5EyTbq2vxyTAOmpB9XLlxGrB1RDiBkbwkg321ohl1A9sEg1?= =?us-ascii?Q?gePWHFYuZOww5XnhbQiFQR0pyMDt1X8biyGryzF/+kcWPUlqpN8UkPV/z5q0?= =?us-ascii?Q?mPIUNIaOfVBLWeqUP6VT8Z2uqZFjikyZUmMbsu9Y9U94n5PWW55oFeH2lC78?= =?us-ascii?Q?Z/Ku5l+fJ/3aogjftHyGIgOFUNj/YOUxSXLjEx8c/gG+tnCujJMO8eXRaLsp?= =?us-ascii?Q?a8IlDWREddAjnDZBt/j8do4GHUgRCXkycVeLDrONsNGH7yTCD6X4eLnquDEo?= =?us-ascii?Q?uhA6jiUoeURbVXt3BUS1yAwgs9Yf8FpgesRCbOiF?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 5nwE3OFj78sBMmadpP+geI7VpETmmXIQ4a1TfoQVkogNIZhwTeS4actnc9QJTI7Kaln3g4wwHXA0dhP6wiDWeh2aM2tdoD1wO44QR8k+uxFmB02BYrV5PsE6lWwsuOmJyvWpyJ5ZxZaKfD8ozBF35mOLxdwE+BpuHUaTWInlIr26amKHL8vVjOPgrUdHX2O5dLuhXLq4QefalVGCNiIfuaJZbDV4ovDiCFO6VBaLcmKjK44THMNAPM6Z3xuByvx9kPkQlllCFP4yHl0cEjk4/ncngmBO3zUtaTC6hMLTHczbkFK3qZVC5+8s6W3e+V0S+ou29hEFqbnN1gbE8MWlRI3UKqLdWyRk4mQD5pK2Ej4HkyJojT/4llkZhhJ/U6NOQKbAgTtGNNUli/8BK4+aWAkuCCR8abNn6QFYAo1IUC/tCPnAVMYY9utpijohzQ7qUFVEI6VTxhfvJvVqqfcSrzEBhw3kAuarkVhkTu8mEFH2X6AI10zT6ROX+JmUCvOCnwSscGG0IT0epD7y9yxmE2Us8xKGqQ15QFyH7iOBnK2MzmCJwRZGKYV5lwZqMtGBkoJ8YxbUt6jBNlsmP8DsgptaDlE6TD1GWzHEQaqLeRHwdnmZbPPJakF9Ostxz336ciXa7Yar46fro5Bqydj3JsuaTQ4nqyDsmOqx3CeYhgYaDjimYTzOc0fyKrNCVrLkQ1e+LKI1YZ+UJ4d4TOvCz8iC7zY3dPxvfu5LrGgX79cdHlP4hl1lIraKxhxwmwE+4PRDBVHiMyVI8CYV+JlBzhX9q8J7t+jFswVrvBANCILryIaLPiCoftJF7QVfd2v/gAZ9LnBXS5gTZRLckkj8wEHLgqx59lgIuCXdvy2OgxvHZIuu05oaQqmJ90ZGJjZj X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5ca88047-85c1-4911-d352-08db6145bcbe X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4705.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2023 19:40:35.2130 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /InH29DAdB6ng/Nrj5oIGlmrwsBzoaUkRf3chrfeBALXIy7cvyy6TZg2FiOvtCqSvWJR+b8DIODq16SlmtcHgQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR10MB6214 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-30_15,2023-05-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305300159 X-Proofpoint-GUID: NCYLMpkoE6_OjbnK1UGAvw_OVnbvhB7x X-Proofpoint-ORIG-GUID: NCYLMpkoE6_OjbnK1UGAvw_OVnbvhB7x Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch contains a module and a bash script which tests the new simple "unsigned min/max checking" files. The module creates the debugfs files and encodes the test type and test parameters in the file name which the script decodes and tests. Currently the files were placed under testscripts though auto testing is not yet enabled. The hope is that this eases testing of the patches. Signed-off-by: Chris Hyser --- tools/testing/selftests/debugfs/Makefile | 15 ++ tools/testing/selftests/debugfs/minmax_test.c | 140 +++++++++++++++++ .../testing/selftests/debugfs/test_minmax.sh | 147 ++++++++++++++++++ 3 files changed, 302 insertions(+) create mode 100644 tools/testing/selftests/debugfs/Makefile create mode 100644 tools/testing/selftests/debugfs/minmax_test.c create mode 100755 tools/testing/selftests/debugfs/test_minmax.sh diff --git a/tools/testing/selftests/debugfs/Makefile b/tools/testing/selft= ests/debugfs/Makefile new file mode 100644 index 000000000000..5dddaaf6c7a2 --- /dev/null +++ b/tools/testing/selftests/debugfs/Makefile @@ -0,0 +1,15 @@ +obj-m :=3D minmax_test.o + +KDIR :=3D ../../../.. +PWD :=3D $(shell pwd) +WARN_FLAGS +=3D -Wall + +.PHONY: all +all: + $(MAKE) -C $(KDIR) M=3D$(PWD) modules + +clean: + $(MAKE) -C $(KDIR) M=3D$(PWD) clean + + +include ../lib.mk diff --git a/tools/testing/selftests/debugfs/minmax_test.c b/tools/testing/= selftests/debugfs/minmax_test.c new file mode 100644 index 000000000000..0e0f6bcd6302 --- /dev/null +++ b/tools/testing/selftests/debugfs/minmax_test.c @@ -0,0 +1,140 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Test debugfs minmax simple files. + * + * Copyright (c) 2023 Oracle and/or its affiliates. + * Author: Chris Hyser + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of version 2.1 of the GNU Lesser General Public License= as + * published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but WIT= HOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public Li= cense + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, see . + */ + +#include +#include +#include +#include + +MODULE_LICENSE("GPL"); + +#define MIN_MAX 1 + +static struct dentry *dir =3D NULL; + +#ifdef MIN_MAX +u8 test_max_8 =3D 250; +DEBUGFS_MAX_ATTRIBUTES(test_max_8_p, &test_max_8, 252); + +u8 test_min_8 =3D 250; +DEBUGFS_MIN_ATTRIBUTES(test_min_8_p, &test_min_8, 25); + +u8 test_minmax_8 =3D 250; +DEBUGFS_MINMAX_ATTRIBUTES(test_minmax_8_p, &test_minmax_8, 100, 253); + + +u16 test_max_16 =3D 250; +DEBUGFS_MAX_ATTRIBUTES(test_max_16_p, &test_max_16, 0x1fff); + +u16 test_min_16 =3D 250; +DEBUGFS_MIN_ATTRIBUTES(test_min_16_p, &test_min_16, 100); + +u16 test_minmax_16 =3D 250; +DEBUGFS_MINMAX_ATTRIBUTES(test_minmax_16_p, &test_minmax_16, 100, 300); + + +u32 test_max_32 =3D 250; +DEBUGFS_MAX_ATTRIBUTES(test_max_32_p, &test_max_32, 0x1fffffff); + +u32 test_min_32 =3D 250; +DEBUGFS_MIN_ATTRIBUTES(test_min_32_p, &test_min_32, 100); + +u32 test_minmax_32 =3D 250; +DEBUGFS_MINMAX_ATTRIBUTES(test_minmax_32_p, &test_minmax_32, 100, 0x1fffff= ff); + +/* test setting everything directly */ +u32 test_minmax_32_s =3D 250; +static struct debugfs_minmax_params test_minmax_32_ps =3D { + .value =3D &test_minmax_32_s, + .min =3D 100, + .max =3D 0x1fffffff, + .flags =3D 3, +}; + +u64 test_max_64 =3D 250; +DEBUGFS_MAX_ATTRIBUTES(test_max_64_p, &test_max_64, 0x1fffffff); + +u64 test_min_64 =3D 250; +DEBUGFS_MIN_ATTRIBUTES(test_min_64_p, &test_min_64, 100); + +u64 test_minmax_64 =3D 250; +DEBUGFS_MINMAX_ATTRIBUTES(test_minmax_64_p, &test_minmax_64, 100, 300); +#endif + +u8 test_reg_8 =3D 250; +u16 test_reg_16 =3D 250; +u32 test_reg_32 =3D 250; +u64 test_reg_64 =3D 250; + +u8 test_regx_8 =3D 250; +u16 test_regx_16 =3D 250; +u32 test_regx_32 =3D 250; +u64 test_regx_64 =3D 250; + + +/* File names consist of test__<1st param>__. + */ + +int init_module(void) +{ + pr_err("minmax_test: init_module()\n"); + dir =3D debugfs_create_dir("minmax_test", 0); + if (dir =3D=3D NULL) { + printk(KERN_ALERT "minmax_test: can't create dir 'minmax_test'\n"); + return -1; + } + +#ifdef MIN_MAX + debugfs_create_u8_minmax("test_max_252_8", 0644, dir, &test_max_8_= p); + debugfs_create_u8_minmax("test_min_25_8", 0644, dir, &test_min_8_p= ); + debugfs_create_u8_minmax("test_minmax_100_253_8", 0644, dir, &test= _minmax_8_p); + + debugfs_create_u16_minmax("test_max_0x1fff_16", 0644, dir, &test_m= ax_16_p); + debugfs_create_u16_minmax("test_min_100_16", 0644, dir, &test_min_= 16_p); + debugfs_create_u16_minmax("test_minmax_100_300_16", 0644, dir, &te= st_minmax_16_p); + + debugfs_create_u32_minmax("test_max_0x1fffffff_32", 0644, dir, &te= st_max_32_p); + debugfs_create_u32_minmax("test_min_100_32", 0644, dir, &test_min_= 32_p); + debugfs_create_u32_minmax("test_minmax_100_0x1fffffff_32", 0644, d= ir, &test_minmax_32_p); + debugfs_create_u32_minmax("testss_minmax_100_0x1fffffff_32", 0644,= dir, &test_minmax_32_ps); + + debugfs_create_u64_minmax("test_max_0x1fffffff_64", 0644, dir, &te= st_max_64_p); + debugfs_create_u64_minmax("test_min_100_64", 0644, dir, &test_min_= 64_p); + debugfs_create_u64_minmax("test_minmax_100_300_64", 0644, dir, &te= st_minmax_64_p); +#endif + + debugfs_create_u8("test_reg_8", 0644, dir, &test_reg_8); + debugfs_create_u16("test_reg_16", 0644, dir, &test_reg_16); + debugfs_create_u32("test_reg_32", 0644, dir, &test_reg_32); + debugfs_create_u64("test_reg_64", 0644, dir, &test_reg_64); + + debugfs_create_x8("test_regx_8", 0644, dir, &test_regx_8); + debugfs_create_x16("test_regx_16", 0644, dir, &test_regx_16); + debugfs_create_x32("test_regx_32", 0644, dir, &test_regx_32); + debugfs_create_x64("test_regx_64", 0644, dir, &test_regx_64); + return 0; +} + +void cleanup_module(void) +{ + pr_err("minmax_test: cleanup_module()\n"); + debugfs_remove_recursive(dir); +} diff --git a/tools/testing/selftests/debugfs/test_minmax.sh b/tools/testing= /selftests/debugfs/test_minmax.sh new file mode 100755 index 000000000000..67ed7b9abac2 --- /dev/null +++ b/tools/testing/selftests/debugfs/test_minmax.sh @@ -0,0 +1,147 @@ +#!/bin/bash + +# SPDX-License-Identifier: GPL-2.0-only +# +# Test debugfs minmax simple files. +# +# Copyright (c) 2023 Oracle and/or its affiliates. +# Author: Chris Hyser +# +# This library is free software; you can redistribute it and/or modify it +# under the terms of version 2.1 of the GNU Lesser General Public License = as +# published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, but WITH= OUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public Lic= ense +# for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library; if not, see . + +rmmod minmax_test 2>/dev/null +insmod minmax_test.ko + +cd /sys/kernel/debug/minmax_test +pwd + +function split_wds() +{ + words=3D() + local IFS=3D_ + for w in $1; do + words+=3D($w) + done +} + +function test_max() +{ + echo $2 > $1 + local res=3D$? + local rv=3D$(cat $1) + if ! (( res =3D=3D 0 && $2 =3D=3D rv )); then + return 1 + fi + + local max=3D$(($2 + 1)) + echo $max > $1 2>/dev/null + res=3D$? + rv=3D$(cat $1) + if ! [[ $res -ne 0 && $2 -eq $rv ]]; then + return 1 + fi + return 0 +} + +function test_min() +{ + echo $2 > $1 + local res=3D$? + local rv=3D$(cat $1) + if ! [[ $res -eq 0 && $2 -eq $rv ]]; then + return 1 + fi + + local min=3D$(($2 - 1)) + echo $min > $1 2>/dev/null + res=3D$? + rv=3D$(cat $1) + if ! [[ $res -ne 0 && $2 -eq $rv ]]; then + return 1 + fi + return 0 +} + +function test_minmax() +{ + test_min $1 ${words[2]} + if [[ $? -ne 0 ]]; then + echo "$1: min error" + return 1 + fi + test_max $1 ${words[3]} + if [[ $? -ne 0 ]]; then + echo "$1: max error" + return 1 + fi + return 0 +} + +function test_reg() +{ + if [[ $2 -eq 64 ]]; then + local V=3D313 + + echo $V > $1 2>/dev/null + + local rv=3D$(cat $1) + if ! (( rv =3D=3D V )); then + return 1 + fi + return 0 + fi + + local max=3D$(((1 << $2) - 1)) + test_max $1 $max + if [[ $? -ne 0 ]]; then + echo "$1: reg/x error" + return 1 + fi + return 0 +} + +rc=3D0 +for f in *; do + split_wds $f + echo file: $f + + if [[ ${words[1]} =3D=3D "min" ]]; then + test_min $f ${words[2]} + if [[ $? -ne 0 ]]; then + echo "$f: min error" + rc=3D1 + fi + elif [[ ${words[1]} =3D=3D "max" ]]; then + test_max $f ${words[2]} + if [[ $? -ne 0 ]]; then + echo "$f: max error" + rc=3D1 + fi + elif [[ ${words[1]} =3D=3D "minmax" ]]; then + test_minmax $f ${words[2]} ${words[3]} + if [[ $? -ne 0 ]]; then + echo "$f: minmax error" + rc=3D1 + fi + elif [[ ${words[1]} =3D=3D "reg" || ${words[1]} =3D=3D "regx" ]]; then + test_reg $f ${words[2]} + if [[ $? -ne 0 ]]; then + echo "$f: reg/x error" + rc=3D1 + fi + fi +done + +rmmod minmax_test + +exit $rc --=20 2.31.1 From nobody Sun Feb 8 06:49:53 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E924C77B73 for ; Tue, 30 May 2023 19:40:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233217AbjE3Tkw (ORCPT ); Tue, 30 May 2023 15:40:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233157AbjE3Tkq (ORCPT ); Tue, 30 May 2023 15:40:46 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32BB7102 for ; Tue, 30 May 2023 12:40:46 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34UJNmrU008438; Tue, 30 May 2023 19:40:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-03-30; bh=ojlOUfItYtdZWxTopSJwNQjnNgRqTrdhWu+gqHbclyo=; b=yoZG3jSVq1qJaBULxHUZb2wzz1/k0HdTOtV+OV9RVmLZF7qXfrcwR6zZw3qXWvP/byIc rq5/nMKUJHiKkGnNdrESeD0RDgNEhvGZsZU8pCuYLdvVulHcLwvWgDKQKCgCEByfQmZ2 /iVJKDBWsXJXUj1C148yhJqg64sBB6k5tq7wIfKs5PstGn8u2TX/e1AgvP5eQwbW94hB SqCRIEhOYywKFODjetn6QAO8QbjvWyUdM9eoSyeQXZvWOxdDXW1UiUkffcIAL3Be/4YN tjGdYl16m+WcIjXQADDndhMStw0SgBP5kSwg1U9WQJEuv9755tTZSUUIKsYgsnk/okzi Ng== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qvhmjkr0r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 May 2023 19:40:41 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34UHr6Rr003757; Tue, 30 May 2023 19:40:40 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2109.outbound.protection.outlook.com [104.47.70.109]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3qv4ybyrku-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 May 2023 19:40:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nzE+6xxuybFJrSsArFkKZp19d1mdduJofmJQk76ubH9RVBrrrt0LwpxSgi5E3hluhSI0TfpYvb2cRhpC4WLFElN1EnkNj/2hFNMXQQssO0/66t/2ZxBCpHBkqYr4DL8LSb2aYUTd6bSGdjWrYGaImbWz6HGhao2zkOQWQR8WAapsnRt1bp2FXYSEW/JISYFigQ26NPCSnuXvzieFMqkyJKJ/4lpdiEWRbetr0uShD2JORKZEISGRPa7xetDz3OIZHDutvvDYK2Cr8/zNdV4P0OZtWI6WMMV8IHm7BKmy/TjuRXq/Ihn+91kozWYzUE9279aVNxByP49xbvTSuXBE+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ojlOUfItYtdZWxTopSJwNQjnNgRqTrdhWu+gqHbclyo=; b=HmsYF0ZxA1sqhrYn/OFZRHjMiCc7AqCyik1Y1BgoSNec9AwBeNj9x/n08o+yY1N/q3VrPoM+dtGzSgGxvK5QChXbjnq86tQ/QRlJOMHZ/ek75sqSb0Cqi8GKvtM48Dsp82e9rZmhNyHcyaRYgI9zhx9rzzQrmlZn9sjZiexbk/pAG5MhjrdntLxy0Jnh3Do6dL6Z/4sTPwsI2u9n0wssIGUuDN4f3XHU02+V1zmz8970HhSjx+hZl3CgR3pmLrwDQF2gWsF5s3fAitGos9WuzwjY/6VVOR2EQl510ZGU6T4q7iL1uYcs7mZNtscqRHIHG95MCG0e1fyF4KnisF2TVw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ojlOUfItYtdZWxTopSJwNQjnNgRqTrdhWu+gqHbclyo=; b=D1CQh1FU73kqCplj+iHyvwTR4AOrB0GxIk+6jTt5+eW6bWkbgkz/nqkAjfyc1BLYM9OoO/yvGh8WhoI+JbxdOaKMNW3hBMLZGDwcwzoP2lPFVrBg4DjDuElDPc5p5ym4ifCk8ctFqbFYoH14aEK6O/2mG3F0da4MLpg0eR2k1/c= Received: from CO1PR10MB4705.namprd10.prod.outlook.com (2603:10b6:303:96::11) by DS7PR10MB7252.namprd10.prod.outlook.com (2603:10b6:8:ee::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.22; Tue, 30 May 2023 19:40:38 +0000 Received: from CO1PR10MB4705.namprd10.prod.outlook.com ([fe80::11b8:4b2e:26c5:1bb3]) by CO1PR10MB4705.namprd10.prod.outlook.com ([fe80::11b8:4b2e:26c5:1bb3%2]) with mapi id 15.20.6433.022; Tue, 30 May 2023 19:40:38 +0000 From: chris hyser To: chris.hyser@oracle.com, linux-kernel@vger.kernel.org, peterz@infradead.org, gregkh@linuxfoundation.org, "Rafael J. Wysocki" Subject: [PATCH 4/4] sched/numa: Fix divide by zero for sysctl_numa_balancing_scan_size. Date: Tue, 30 May 2023 15:40:12 -0400 Message-Id: <20230530194012.44411-5-chris.hyser@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230530194012.44411-1-chris.hyser@oracle.com> References: <20230530194012.44411-1-chris.hyser@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SJ0PR03CA0078.namprd03.prod.outlook.com (2603:10b6:a03:331::23) To CO1PR10MB4705.namprd10.prod.outlook.com (2603:10b6:303:96::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4705:EE_|DS7PR10MB7252:EE_ X-MS-Office365-Filtering-Correlation-Id: 77b5009a-7a7a-483b-f729-08db6145be7e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jxXp4A/STa66RZQIz4pV4pE0ScDLQkI/b4+xCPZ/jC/k7jzBHkiXbwDHP4vv9nDOlS3kRCd5fLhQqvn3+QaWHCh6KGgMN1BcSqjgIa0qXdVku+EQHRMIudtbcbhf/7LAPaNDUWLUIT9a+njI/En6XLalAs+HWyUWFq7KTT2Gm0Zm52o5I8fUJIMo+z1dfks0+mUzwDeqB5OkUGlaURYea9mb5L38nufcwl9txtdzal/Ap9lK6EyyQTinyPiFKqAdA6db3vcvHRXnOQfTauEshYqACmSuT8aSwJ7sz3hqM2vmtUihQZiEwAQuDoJgPUjOWebYEvBcH89TOeHUC8HXayvqoXxi5CiqHgk6d3+f8CqtrF2DkGhEauJ7mOnOYAfC0FESIcoWhpCHucra6JWKqcQh1q+q0O9of2G4J7IPVpuk6Z/b83oA0tuWXJjOzigXA84r4qPMrTaAKWhIdECJJdL4IVazogijStf0FoRdzyi9TbNBaHDHuvXJHK7wCkHI56erPofiNWtzgwEN4t57/otP8oJEzKtIAtQJAoJXSW+x0ihcQWLJ693y8RnJluq1 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR10MB4705.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(366004)(376002)(396003)(136003)(346002)(451199021)(38100700002)(316002)(41300700001)(6666004)(6512007)(6916009)(86362001)(6486002)(8936002)(2906002)(8676002)(66946007)(2616005)(36756003)(66556008)(66476007)(6506007)(26005)(1076003)(83380400001)(478600001)(5660300002)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?dbyGQJgAh6t0BCJBFnZjwvJSyXhnM1cSqO3um36NDowjeVKm/jBduF7XarRC?= =?us-ascii?Q?tJDjcKSg5b+ADm4sZ6MHAeTxqykXnUPuq/WfcGSv2mwBsRx3EfS2Axzrxp5a?= =?us-ascii?Q?foYaO5ioVG6LhA1FTXgV660rmAns6EExnoaKhHja1xUnZEYlfwZG3/mu0uN5?= =?us-ascii?Q?DanbZqtp7XLyqtKWWA2nFrlBHPNp+d018VrkkwlfJRVYXuDlrqriJTQAs42A?= =?us-ascii?Q?QZo8NYZIE/43nllBvfd/37lUBr4Pgu+n6SXG+EDCAYcLzcNSLhiGPWrjJe64?= =?us-ascii?Q?ZeRu4946BFF1SleTtMg3m57PM+kf+Lr8dw1ZKFXcvijxNnuV++hK4Heh+RPe?= =?us-ascii?Q?ShRZbqOVvHVXzusysLwSNOezDcFIsWdXDdS3tK/e/+X+DVo204+u3rKuak3g?= =?us-ascii?Q?06VPcq8qROT00ovdJj2b5wgwK6YZ6jos2vb1jEwdQWBJT1TOVrJlTMObs8VW?= =?us-ascii?Q?PUQ0bzkuyA5gDPb6ncY9Hgl6PE7FX14mVQNL+zUBSaQW7wuZVv6iVWBBBZlU?= =?us-ascii?Q?PAFh+7iWNrLGLU6c+ai7NsbaoVSsqoMHNJ7oIz9fpUIqEfM18Ixz2FtyESK+?= =?us-ascii?Q?C2zOS0Btwvok7ygnz+kX8WVI9lDLS/7Cr2DFARu7hL3BVsmhFGUiydKHVNOG?= =?us-ascii?Q?wqwldyk16066wfP7h6bkaMJfQm98bzVd+bPA4LI79OH2lskPw4iKnK9DLnbL?= =?us-ascii?Q?tI1txKcAu+6EOoS4/UJUSVKOqW+12I4zCMuYma6KyRh49XABg+ymOKnMcMRN?= =?us-ascii?Q?SC6Phrc4hx8Y/ME4uPcFzJtm4AQmjrU8diCBYcCaVrBzrRruHoOU0Fy+NHRp?= =?us-ascii?Q?wDVD7Zg7WmY0dNfinoB+Sp3psOXiJ0njlps5bwGuPwTJZjrrAvy2/7Ae6W4l?= =?us-ascii?Q?3+Ko6/cVdMGgofXorRX+4tq2wK8WzJ5s1AO0FzfjW21eiWcf91K3LwlCJi7T?= =?us-ascii?Q?j4TfMSdMrICoKnZQUWL2i8MuujwEI5ReBl/Ld5c2yHkO/zxo7iUoTN3f3hKt?= =?us-ascii?Q?cRiwE4n6+fUT5LBr1YHwfb/5aRXgNBjXK60d1A4HozRlGNykK3IMG7WKof/J?= =?us-ascii?Q?9MMlwgBdcRbs0RhWr+FCXTfQHIo6pJiZdeL08sZn1+hXqUOV6534tPIj6IEg?= =?us-ascii?Q?UzucxPOoopJBqeSnTuVp/g0GptKSWAcdsHdATr7T4KiiFAY6t1ypGWXOUPes?= =?us-ascii?Q?HxBX4ylxBtpnvMY3LjbVrB9W3RiuhBZm62aksoLR/GWa70/KDjXayfNgT/Zd?= =?us-ascii?Q?1tYIaDhwCZeIEpY3oFAuUTEi+ncWsf04QPJfLkETxMosvXTvxbYktViKnsnu?= =?us-ascii?Q?rXdNI8tUxg7Y5muFXKnHHY/9d5oS8Kh+ZRQLsXTR/ZbfJrUK9YcJE6A9w9i2?= =?us-ascii?Q?yMDgwv9Qqk2+LcETqHbMwUEXkekfkyt7uEQS8rDTRzIbBNYa9Tm8J4kPnYu9?= =?us-ascii?Q?luoi23Gkp7o+nFkerciDx37e0H2gvOGkp1Xn89JenICDMefvuGkM61DKRxA7?= =?us-ascii?Q?x+A4c+zVeIL4AT54nBUb4ZKkGw1lW80KMYkX4NPgJ2TVkqWNvPNZ0fgCAQDW?= =?us-ascii?Q?pZH6nhFoiposBTK+lcI+7hz5d5jMc/R06Wak6zVT?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: CdiWqXehZla4wE4Yu27HF8XFPrv/yQ5brOUoAx5Y8HDg67DCBHV8j6S8Hc8j5yLl7Z8dnJnc1spuSQeKk4kAgikUOUKFAxuGTpi7w0QZc5DOSBNLtaYFH2VPsA5C586pXJ2t7jdKp4TKznzI1tz6XazSSr0KJCz/9V8OEZ8JS/0Z4VjMvPvvX4UM+vZdVDYR7KDbWVS/X1k4I2vbKijS/1LV9Y59uygbh4jhCMYvXqOgBqEt6coqUKILyPAm34O6LZ3hMqOwPBGg8Qem4td4H87K3EeF0Rvym3rFgXn8CTkj1pwoZBdYacysLXy0/imvh5YMVuZgDzDH6WMKvcwGOMt/J0/mrDjW95X1Rp6BB0jPy+ZuKeaAAsGr3c79QJZ6Ojft3gtmcIjtq0MNc9WFjfP9AOOqxqh/HqN2INyzXPk6Lnu3TZ0ElF39U4qlPucqm6j2oP/IlIWnqsp9OEV21ejCnC+Xg3myotddNHFxtmY2+WpcOYU2OZtei8rF03Xs3GRXzENXp8R17KURNEXknjG7so20zWeKOz0D82xmUpazWXMS7dbs4xy6ciQT6VDVe9hE/SzjZIm9EKUOuqCcJwqJqewWRjeYW85XoTJwYpqm+anJLPpRSet3yXlHkYa/DEjQ7D2bTEUoL2FydyNnhXrk5bGQk+bUftSRUN0qy5nnv4ZD/q1fBrNEst+8V/ONJxmo/mQpl/TaiWuyraEU9VdSfOYhUeC1hSVkZDN5r/YdjFBbxqRc1NeLhODC9xwDzxCzA5jBO9XLX5cgi1dWjcDjYMQUQtCH652dgA0eOkHok0I+zMxTDR2g0YQ/rhXY0Y05D/L//cBs/k70b7mBgddSzlthvcnME0YEeyMif8yH121Ak6mI5KooCq+3q5NO X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 77b5009a-7a7a-483b-f729-08db6145be7e X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4705.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2023 19:40:38.1386 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0RVE990Kxg5JQfYVFxGvQ+POCTv9cUWRN7HN1DBrYBNwkINA14RVN1iZwC8+g3uHOJsQHkbMX7uzSPK0WOU36w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB7252 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-30_15,2023-05-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 bulkscore=0 suspectscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305300159 X-Proofpoint-ORIG-GUID: t4Q1Sn7kwBTMhEsdxujHGntetzpsfzyq X-Proofpoint-GUID: t4Q1Sn7kwBTMhEsdxujHGntetzpsfzyq Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Commit 6419265899d9 ("sched/fair: Fix division by zero sysctl_numa_balancing_scan_size") prevented a divide by zero by using sysctl mechanisms to return EINVAL for a sysctl_numa_balancing_scan_size value of zero. When moved from a sysctl to a debugfs file, this checking was lost. This patch puts zero checking back in place using the debugfs minmax checking mechanism. Cc: stable@vger.kernel.org Fixes: 8a99b6833c88 ("sched: Move SCHED_DEBUG sysctl to debugfs") Signed-off-by: Chris Hyser --- kernel/sched/debug.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c index 066ff1c8ae4e..b9e53ecc539a 100644 --- a/kernel/sched/debug.c +++ b/kernel/sched/debug.c @@ -216,6 +216,13 @@ static const struct file_operations sched_scaling_fops= =3D { =20 #endif /* SMP */ =20 +#ifdef CONFIG_NUMA_BALANCING + +/* prevent divide by zero */ +DEBUGFS_MIN_ATTRIBUTES(scan_size_mb_params, &sysctl_numa_balancing_scan_si= ze, 1); + +#endif /* CONFIG_NUMA_BALANCING */ + #ifdef CONFIG_PREEMPT_DYNAMIC =20 static ssize_t sched_dynamic_write(struct file *filp, const char __user *u= buf, @@ -371,7 +378,7 @@ static __init int sched_init_debug(void) debugfs_create_u32("scan_delay_ms", 0644, numa, &sysctl_numa_balancing_sc= an_delay); debugfs_create_u32("scan_period_min_ms", 0644, numa, &sysctl_numa_balanci= ng_scan_period_min); debugfs_create_u32("scan_period_max_ms", 0644, numa, &sysctl_numa_balanci= ng_scan_period_max); - debugfs_create_u32("scan_size_mb", 0644, numa, &sysctl_numa_balancing_sca= n_size); + debugfs_create_u32_minmax("scan_size_mb", 0644, numa, &scan_size_mb_param= s); debugfs_create_u32("hot_threshold_ms", 0644, numa, &sysctl_numa_balancing= _hot_threshold); #endif =20 --=20 2.31.1