From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4BF0C4741F for ; Tue, 6 Oct 2020 20:45:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 96E2020866 for ; Tue, 6 Oct 2020 20:45:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602017153; bh=dTZvdmu0coKjJ73PeKDmtsLkatLr3qg5OjT3MCA0mFU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=gIKsYBNa9EJJr3sQhJo+qJiewZWop8oU8GJ5mLfVkzOsRwAn9QsuquX9s9ONhssjd svu+UiOvjhUBxP6jazeidSPphqNK21xn1qzoZZRiqCDzy+WYm4C4GdtC2E8cPJsy44 hIRA4b4fyaRxh6vPwvSYxyCJJnQ0im83fNmbnMJA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727377AbgJFUpw (ORCPT ); Tue, 6 Oct 2020 16:45:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727333AbgJFUpq (ORCPT ); Tue, 6 Oct 2020 16:45:46 -0400 Received: from mail-il1-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CC56C0613D3 for ; Tue, 6 Oct 2020 13:45:46 -0700 (PDT) Received: by mail-il1-x144.google.com with SMTP id j13so140709ilc.4 for ; Tue, 06 Oct 2020 13:45:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QJIYIgyrqCiWMzT/Dqk/C0paHkprMmoejDFq2Ds2CjI=; b=HBjUSoVMYo8I4oCixKd5VLIoFWCMgqEJyqLPLBTGkQI1cx6K7VnUUVX4diQfmHLv38 lPbI4K0+lx9jSjEbth/nCH5yLUDfzgHM24DLLQZPcXltwt4nZnbovHlOpmL1+94E9/70 g+nIUflrO9XI+RYG3SCv7e1dzay94aAMpuFyU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QJIYIgyrqCiWMzT/Dqk/C0paHkprMmoejDFq2Ds2CjI=; b=i50Sw1vbiQ7UVkp9pll8csgdWR10UagbYPCSRlJ430InR2GUlHlLFpckmHh3wOGy9+ mWTqBYV9mu/TJDRhxGjUuoGVByE4Khb2JdHugmY1bmpLsGkwdKNKYFkmWjmh2qiIA7xH P6kVmNboQ6GUUeUZsW4MRKGXwsGi9CploSp/hnrUhNYGpe2OAUZZk0E5ZsXDV/TMT9+6 vqFC7GtW+CP4uxex/f71KMGzpWH7V4KJX2RBUEcNz+brcTUnWSV5a0TzmvDOwG0afEYf twqG09cvZ7XoS++NJWlKIjg7qrRSCFnVAUpTymWDuIzlP9+T4E4SXVHl+p1snAIag+NG Nhjg== X-Gm-Message-State: AOAM532L4JGx9krh9Uy5upC6q4/n5HZgdAqePUbp9SWlFZJPF+Qcq6xt 5dh7oF+JHfnELdOS7ImUI/JBeEy6p8tmuQ== X-Google-Smtp-Source: ABdhPJzgXRZJcYVcGpyc+YcMGHiDUBKQng+aWWzztb5Xctf9UkSeR+DUoU879vSnxa+MSYIlQjAA5Q== X-Received: by 2002:a05:6e02:44d:: with SMTP id a13mr5245547ils.273.1602017145731; Tue, 06 Oct 2020 13:45:45 -0700 (PDT) Received: from shuah-t480s.internal (c-24-9-64-241.hsd1.co.comcast.net. [24.9.64.241]) by smtp.gmail.com with ESMTPSA id s69sm1665627ili.54.2020.10.06.13.45.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2020 13:45:45 -0700 (PDT) From: Shuah Khan To: shuah@kernel.org, keescook@chromium.org, gregkh@linuxfoundation.org Cc: Shuah Khan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 02/11] selftests:lib:test_counters: add new test for counters Date: Tue, 6 Oct 2020 14:44:33 -0600 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a new selftest for testing counter_atomic* Counters API. This test load test_counters test modules and unloads. The test module runs tests and prints results in dmesg. There are a number of atomic_t usages in the kernel where atomic_t api is used strictly for counting and not for managing object lifetime. In some cases, atomic_t might not even be needed. The purpose of these counters is to clearly differentiate atomic_t counters from atomic_t usages that guard object lifetimes, hence prone to overflow and underflow errors. It allows tools that scan for underflow and overflow on atomic_t usages to detect overflow and underflows to scan just the cases that are prone to errors. Simple atomic counters api provides interfaces for simple atomic counters that just count, and don't guard resource lifetimes. Counter will wrap around to 0 when it overflows and should not be used to guard resource lifetimes, device usage and open counts that control state changes, and pm states. Using counter_atomic* to guard lifetimes could lead to use-after free when it overflows and undefined behavior when used to manage state changes and device usage/open states. Signed-off-by: Shuah Khan --- MAINTAINERS | 1 + tools/testing/selftests/lib/Makefile | 1 + tools/testing/selftests/lib/config | 1 + tools/testing/selftests/lib/test_counters.sh | 5 +++++ 4 files changed, 8 insertions(+) create mode 100755 tools/testing/selftests/lib/test_counters.sh diff --git a/MAINTAINERS b/MAINTAINERS index 4e82d0ffcab0..26719b8dd48e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15845,6 +15845,7 @@ L: linux-kernel@vger.kernel.org S: Maintained F: include/linux/counters.h F: lib/test_counters.c +F: tools/testing/selftests/lib/test_counters.sh SIMPLE FIRMWARE INTERFACE (SFI) S: Obsolete diff --git a/tools/testing/selftests/lib/Makefile b/tools/testing/selftests/lib/Makefile index a105f094676e..e8960d7934e2 100644 --- a/tools/testing/selftests/lib/Makefile +++ b/tools/testing/selftests/lib/Makefile @@ -5,5 +5,6 @@ all: TEST_PROGS := printf.sh bitmap.sh prime_numbers.sh strscpy.sh +TEST_PROGS += test_counters.sh include ../lib.mk diff --git a/tools/testing/selftests/lib/config b/tools/testing/selftests/lib/config index b80ee3f6e265..6ed25024d371 100644 --- a/tools/testing/selftests/lib/config +++ b/tools/testing/selftests/lib/config @@ -3,3 +3,4 @@ CONFIG_TEST_BITMAP=m CONFIG_PRIME_NUMBERS=m CONFIG_TEST_STRSCPY=m CONFIG_TEST_BITOPS=m +CONFIG_TEST_COUNTERS=m diff --git a/tools/testing/selftests/lib/test_counters.sh b/tools/testing/selftests/lib/test_counters.sh new file mode 100755 index 000000000000..c8731aef2498 --- /dev/null +++ b/tools/testing/selftests/lib/test_counters.sh @@ -0,0 +1,5 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# Tests the Simple Atomic Counters interfaces using test_counters +# kernel module +$(dirname $0)/../kselftest/module.sh "test_counters" test_counters -- 2.25.1