Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7045319rwl; Mon, 9 Jan 2023 17:10:14 -0800 (PST) X-Google-Smtp-Source: AMrXdXsWDJiNzKBH38e5dHQzO2IOEas3Ywy+2AABOFiqjOVHNdw2nITiGArHCtMbzxQKBWtpGADx X-Received: by 2002:a05:6a20:d68f:b0:9d:efbf:48e7 with SMTP id it15-20020a056a20d68f00b0009defbf48e7mr84744700pzb.43.1673313014401; Mon, 09 Jan 2023 17:10:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673313014; cv=none; d=google.com; s=arc-20160816; b=vPNou26Hs48V9lEvhSTyKXeq+HUXwx+4MU7r4RwLjtp+G2PZGUiKgXeh3sXB6UZIwf bVJ4tjQsNRtKJJYOdRrqDjFUHu8Qsbp+925myTIFA9vBXQh41cbCOvmcrwarybOIYvLR Op7xJmMca/D7RyCUFa66/aSA+/jaxc8NXYrkoJ7Hb43x4iEgtsjfuabljT/jSleIcmrm 7A7YW++4UIVI4N25ABFP7nO6AcjTKBqjui7ZuJIJ8UTaTXdvBcqIhOcol0PEQ4G+wVh5 Z8VumiNpKYALomBLKQ4JJc5CxTG5kIOp1tg9ddLBANBVbyFBzzwxmQ3v23PidovObYjZ C0Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=DO2gFEgiDABoY96vqldhsa5IX5CM91xrCTzOJpPuUrY=; b=ZUWr0CRzqjMrc4hAsnVI8UvcWRJH4MxuBC42F6p0mBb+2o6UhHNKNu+E0HVQIkjUlL uznT6KsKUXHe5jmNehcoiYX9P0GuO7VnFafmJAgFsBaZhTpBOSM8oof1WV3VS++ZELQ9 qMbEhmyDvmlbLaBGPk30QosRDBmvApWmSI+6LklIN+5PKRwce9kCKJuV5HrQMXqrbyzN Usy4zgP0wFlBmgj7VWh6gMeNAwRm2AeoXFLkYjuUX2530Hxd9szB9RYrtQRJD2M0vfFB F41IJ+8NKXFTIcTqf0zlmVa1oJqLUtF3lXWS3fA2s2hJEAFl9a2J9eXD2EVaZNPOCVwx lV8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Ewp9ZXvb; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 140-20020a630092000000b004ad157c46bbsi9549356pga.649.2023.01.09.17.10.07; Mon, 09 Jan 2023 17:10:14 -0800 (PST) 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=@google.com header.s=20210112 header.b=Ewp9ZXvb; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237912AbjAIXtx (ORCPT + 53 others); Mon, 9 Jan 2023 18:49:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237964AbjAIXts (ORCPT ); Mon, 9 Jan 2023 18:49:48 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9616EC75E for ; Mon, 9 Jan 2023 15:49:46 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id y5so7462450pfe.2 for ; Mon, 09 Jan 2023 15:49:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=DO2gFEgiDABoY96vqldhsa5IX5CM91xrCTzOJpPuUrY=; b=Ewp9ZXvbs6+dHYVP3ZML0r0pXXjliiXz9pzqXOxpkflZPAdA1F36UAnakc7TLXYcEU z5RESDS0Zx++emMFDXE0lGz1w4OcXFoOmbSTnRP059kd2zR5bZNHvFz2ZPHGvJAgRQd5 cJ11vE8MadnikmDvVI82Vx0pbJ9qriGuxB1HcIMFiyBz8vP5SQG1ZduqInjmuR+Uv+Zs NTEbyg5YWRDa+QldmR6QWzwMYPyQxemwEAX4B9YSbmTBGZCtr+rWOcHwzhuw8WHXt3H1 3fnxYs9wq5XDshTVKIREKRhyiK3Kh1ypXfc9Zw4rDKJrewgLC9rA2VxD1Ey4zmBXxduS Cfgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DO2gFEgiDABoY96vqldhsa5IX5CM91xrCTzOJpPuUrY=; b=G7dR66axRqPVjZeDAlGEOa+UEtrKZE5YfpqC5Z45y0DVLiB+gyNjYm/CGZ160qdj99 kpq8JUK0+hZX6/I+4mHblBwyYaIleXBklbndxQariSgOA3OM9/DJp2RxOCfhGh0kDAFL YpwFWLJQTU7rExqmArMtpJrkBlqQvBfXg+q8VXGVahysbKoa9342naS6edeQXkLSnLLa 5ehhCBroeg661OJUvsY/Q2jbqbnkDghkXOUB4W5m4iZytH7RYSdbtZeXpVaKoDBZoXk9 s+9DO+h2addINg9/0tj6+D4y+cLhWdThEWi2jIYww6cb5TyqOhv+7njYWkWg2j8w9LuB lATQ== X-Gm-Message-State: AFqh2ko8E8LGdFOHlgpXD9KlXegW6XyI/P3dw3u8TBqjaI1/rYN4aAxx wtfeE6LjGJBbQM0FfhFprZciNu4c5Q4iwvQrAlNiHQ== X-Received: by 2002:aa7:914e:0:b0:578:202d:a33a with SMTP id 14-20020aa7914e000000b00578202da33amr3376736pfi.23.1673308185711; Mon, 09 Jan 2023 15:49:45 -0800 (PST) MIME-Version: 1.0 References: <20230107040203.never.112-kees@kernel.org> In-Reply-To: <20230107040203.never.112-kees@kernel.org> From: Nick Desaulniers Date: Mon, 9 Jan 2023 15:49:34 -0800 Message-ID: Subject: Re: [PATCH] kunit: memcpy: Split slow memcpy tests into MEMCPY_SLOW_KUNIT_TEST To: Kees Cook Cc: Guenter Roeck , Andrew Morton , Nathan Chancellor , linux-hardening@vger.kernel.org, David Gow , Josh Poimboeuf , Geert Uytterhoeven , Miguel Ojeda , Isabella Basso , Vlastimil Babka , Dan Williams , Rasmus Villemoes , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 On Fri, Jan 6, 2023 at 8:02 PM Kees Cook wrote: > > Since the long memcpy tests may stall a system for tens of seconds > in virtualized architecture environments, split those tests off under > CONFIG_MEMCPY_SLOW_KUNIT_TEST so they can be separately disabled. > > Reported-by: Guenter Roeck > Link: https://lore.kernel.org/lkml/20221226195206.GA2626419@roeck-us.net > Cc: Andrew Morton > Cc: Nathan Chancellor > Cc: linux-hardening@vger.kernel.org > Signed-off-by: Kees Cook Thanks for the patch! Reviewed-by: Nick Desaulniers > --- > Guenter, does this give you the needed flexibility to turn on the memcpy > kunit tests again in your slower environments? > --- > lib/Kconfig.debug | 9 +++++++++ > lib/memcpy_kunit.c | 17 +++++++++++++---- > 2 files changed, 22 insertions(+), 4 deletions(-) > > diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug > index c2c78d0e761c..b5e94807f41c 100644 > --- a/lib/Kconfig.debug > +++ b/lib/Kconfig.debug > @@ -2621,6 +2621,15 @@ config MEMCPY_KUNIT_TEST > > If unsure, say N. > > +config MEMCPY_SLOW_KUNIT_TEST > + tristate "Include exhaustive memcpy tests" if !KUNIT_ALL_TESTS > + depends on MEMCPY_KUNIT_TEST > + default KUNIT_ALL_TESTS > + help > + Some memcpy tests are quite exhaustive in checking for overlaps > + and bit ranges. These can be very slow, so they are split out > + as a separate config. > + > config IS_SIGNED_TYPE_KUNIT_TEST > tristate "Test is_signed_type() macro" if !KUNIT_ALL_TESTS > depends on KUNIT > diff --git a/lib/memcpy_kunit.c b/lib/memcpy_kunit.c > index 89128551448d..cc1f36335a9b 100644 > --- a/lib/memcpy_kunit.c > +++ b/lib/memcpy_kunit.c > @@ -307,8 +307,12 @@ static void set_random_nonzero(struct kunit *test, u8 *byte) > } > } > > -static void init_large(struct kunit *test) > +static int init_large(struct kunit *test) > { > + if (!IS_ENABLED(CONFIG_MEMCPY_SLOW_KUNIT_TEST)) { > + kunit_skip(test, "Slow test skipped. Enable with CONFIG_MEMCPY_SLOW_KUNIT_TEST=y"); > + return -EBUSY; > + } > > /* Get many bit patterns. */ > get_random_bytes(large_src, ARRAY_SIZE(large_src)); > @@ -319,6 +323,8 @@ static void init_large(struct kunit *test) > > /* Explicitly zero the entire destination. */ > memset(large_dst, 0, ARRAY_SIZE(large_dst)); > + > + return 0; > } > > /* > @@ -327,7 +333,9 @@ static void init_large(struct kunit *test) > */ > static void copy_large_test(struct kunit *test, bool use_memmove) > { > - init_large(test); > + > + if (init_large(test)) > + return; > > /* Copy a growing number of non-overlapping bytes ... */ > for (int bytes = 1; bytes <= ARRAY_SIZE(large_src); bytes++) { > @@ -472,7 +480,8 @@ static void memmove_overlap_test(struct kunit *test) > static const int bytes_start = 1; > static const int bytes_end = ARRAY_SIZE(large_src) + 1; > > - init_large(test); > + if (init_large(test)) > + return; > > /* Copy a growing number of overlapping bytes ... */ > for (int bytes = bytes_start; bytes < bytes_end; > @@ -549,8 +558,8 @@ static void strtomem_test(struct kunit *test) > static struct kunit_case memcpy_test_cases[] = { > KUNIT_CASE(memset_test), > KUNIT_CASE(memcpy_test), > - KUNIT_CASE(memcpy_large_test), > KUNIT_CASE(memmove_test), > + KUNIT_CASE(memcpy_large_test), > KUNIT_CASE(memmove_large_test), > KUNIT_CASE(memmove_overlap_test), > KUNIT_CASE(strtomem_test), > -- > 2.34.1 > -- Thanks, ~Nick Desaulniers