Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7025286rwl; Mon, 9 Jan 2023 16:50:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXvpIWQs3AurRmSFmclCJ4EcXcuWpr7yDak9bMrMlqDmUJ2uDqO3HwQOupg2tTpymcfs2TW6 X-Received: by 2002:a17:907:3a91:b0:84d:34a4:46fd with SMTP id fh17-20020a1709073a9100b0084d34a446fdmr7468865ejc.71.1673311851770; Mon, 09 Jan 2023 16:50:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673311851; cv=none; d=google.com; s=arc-20160816; b=CvevmDQNV9ZFOmN6K6XcX/2ElpNMHlEU1Kl2ISCtB5tkeJKiBF3HXzNFOl0BUHy93z jeRoCiyy5IJYyLiiqBbXwiPVsi0wdWviFU4fi8vbh7FKIemiat9q/fLsAeMX8lPal0lq eWs95rCh0xQOjGtrnmcs6DVN1ecCejxj7TLlaFGVU1qBgKp4rx2X/HKlQQm4X2YNJ/Xu R5V7r6k6pliMkgtqb+y9ll3vL1RK7Nq0BbytTLV50Ci6HKMXPSEbQqFLp2Heieq5YZE9 U3Ybd2mKjPqtcw+jzDfnWeaZP8sm/ExDzFoByF90jQVEzwFkZjxgFsyIz5k35bq9+fWv hSNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=02bsn0yiJNUpWqqLqFldR8saSUfX8/r+gUypjApx5FM=; b=uZvVxHqlnmYmPL57pUs9IofHwdK1I4g0t2aJR21iIUY/a49nTP8mELMHHIGXB86gVB zyTwR/VLlESxnUJv/P6feO/XuOAfzH6k6Axv68tqsEq9dBo8CLWs6lmYEO9WvFustS4i 535cbkZg5EPPqgXQE1kW3NDMZdbNbPwLxfBRuOkKSb1hIa+2+NrVPFUlBpZPCgZwP+UT NY1j/I9jqUHdsuHSNCwqfv3Mu6qJ+3wQ5HUo1F6gPf925SEMNdxglOqMSqSERGEEdW+s eIwIWPWtE2uSpWHRGCbY6jgl1i5qBMVi2mt8WT39GdPKAR2E0mvKYzskhdXkiodbPxZq Oa9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dPbg0lHh; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sb17-20020a1709076d9100b0082b07d48ce3si11497420ejc.495.2023.01.09.16.50.38; Mon, 09 Jan 2023 16:50:51 -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=@gmail.com header.s=20210112 header.b=dPbg0lHh; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235239AbjAJALf (ORCPT + 55 others); Mon, 9 Jan 2023 19:11:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234576AbjAJALd (ORCPT ); Mon, 9 Jan 2023 19:11:33 -0500 Received: from mail-oo1-xc2f.google.com (mail-oo1-xc2f.google.com [IPv6:2607:f8b0:4864:20::c2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE81714005; Mon, 9 Jan 2023 16:11:32 -0800 (PST) Received: by mail-oo1-xc2f.google.com with SMTP id 187-20020a4a09c4000000b004d8f3cb09f5so2843303ooa.6; Mon, 09 Jan 2023 16:11:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=02bsn0yiJNUpWqqLqFldR8saSUfX8/r+gUypjApx5FM=; b=dPbg0lHhxnePHWXXo3mDLoQvlVa8AI0mAdMIGM61iCPZ86eDP/OuD2I4E24+XQoGdp UuN+kyJYdGD+Cuhy0I5vHVJZOoANKzOIWLBXG1TB3FH+idwxTOnoenrM1IXUNjB4AxvA cWYWtgKysJ5cuSKOI52kOwifEb9aZvTWuqIt/tsV9J3ettT+3KMcmULjT5GZyxKBovr7 nQ/CdV0vmFCo/muH1MWluEUrN4OG5aIkph5+FFKX2BFhfDYQJVhX23nPaXNHNMngAcxx XDuTMvLiDIV0dCk8Uc3ypsBS+VnCqSqHbsxHGRjkATrdsmTRhwo7f8aqG33Bf4gyUEU7 K4Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=02bsn0yiJNUpWqqLqFldR8saSUfX8/r+gUypjApx5FM=; b=aOt5m7cdCbguik4ujfFshWzkbL4WybNpTblKDVxmWrkFJRIs1pn3nHfridUdNxCNri vy9AMbTSE3elBkQRq2ys5c2SXzYGb2w4cSNWt8pVEuSzX9jsHioeC/zPXA7b6HQcR27p CNWDJUzksTrH/xENPcrOGeRNYY60kt5e+CCEo/Sm5johtHuRvVxQheDaOP2lbNbXwjw9 A8+RJruQDdqrBeF0wMacEytzK1yKZEsx7m3cmufTLM+SdL+uegpIIKNSqavTRIhmR8iX uAe9zD8Qltz2F+NdSwNDHRWQBvwmVAL2dZxeg3Ca+STYg7jVBnMmsbQLynyh+095u8wW x5Ww== X-Gm-Message-State: AFqh2krLNzE2u1Q0LXv8tNq9cVsffCHowhX5bWY98uAjeBNM+A7L8OKd dLy1uNpNRMiiE4sETnoCmCU= X-Received: by 2002:a05:6820:823:b0:4f1:f375:c240 with SMTP id bg35-20020a056820082300b004f1f375c240mr4690785oob.6.1673309492270; Mon, 09 Jan 2023 16:11:32 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id o78-20020a4a2c51000000b004a0b424f99dsm4928789ooo.43.2023.01.09.16.11.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 16:11:31 -0800 (PST) Sender: Guenter Roeck Date: Mon, 9 Jan 2023 16:11:30 -0800 From: Guenter Roeck To: Kees Cook Cc: Andrew Morton , Nathan Chancellor , linux-hardening@vger.kernel.org, David Gow , Nick Desaulniers , Josh Poimboeuf , Geert Uytterhoeven , Miguel Ojeda , Isabella Basso , Vlastimil Babka , Dan Williams , Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: Re: [PATCH] kunit: memcpy: Split slow memcpy tests into MEMCPY_SLOW_KUNIT_TEST Message-ID: <20230110001130.GA1808090@roeck-us.net> References: <20230107040203.never.112-kees@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230107040203.never.112-kees@kernel.org> X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no 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 06, 2023 at 08:02:07PM -0800, 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 > --- > Guenter, does this give you the needed flexibility to turn on the memcpy > kunit tests again in your slower environments? Yes, it does, and it works. Reviewed-and-tested-by: Guenter Roeck > --- > 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 As Geert noticed, bool should be sufficient here since this is not a separate test. Thanks, Guenter > + 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 >