Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2880926pxb; Tue, 21 Sep 2021 09:35:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYuVYnsSgmReLLprqeaGI2xqPQoZVjxE9rXmsMR1QCl1GlGOnR67kG1DLGqo8omD+q8jEv X-Received: by 2002:a05:6638:372a:: with SMTP id k42mr764276jav.71.1632242134617; Tue, 21 Sep 2021 09:35:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632242134; cv=none; d=google.com; s=arc-20160816; b=sfReSVMWDZeqMkRmvcb0bHg1B1TBr3eLDS98nOjHUWorTgqB0D1A2Y0++HCn+QpwmT UezCvQ/C+e9O1VvY7hnIcvM0qG9fBKgYV0/IX+Jo1E9aovzNH6/MoqC5HU4U9JVuylrA JEC8sH8nI94+pAiPWR7R4kYObE+LD7xBs9T37OF4pLwRewuCf+qX379mOnaORHUCeXYa gXUOy/KulJXe6OooBf2bKZzxNZle0c89Rp+m+Nq19zYGXknyQr/Un9jxd2ddVo1RHKIZ UWp3VftluiI2zaZNU1MyvddKH+gwwDxZrCa47w8kgvgxAGYMSjWAszDZBVG27O/xQFtH 8IUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=XXlfpcBmbRno5SA+gst6Gevlk7ltg9389UQ9dhNVCvA=; b=qdnjkSqy0HVRrVEfRMaXP9VX9WNnIBxREez/XsJBugPAYBFbYSSpUtzRzzhxzze5w2 uzSTxdF8T0FTYUjUDnD+Cxnre3fUXKDL7SdG4WoQA39z27uFWhTCB1f9/oZWk4I3MxN7 GutL8lcIDYRNygtq3OglMTRmskBxuJalch28NdKERhjXazVsZXnpesy6HiOR/GaEZm+Q niWmrlBOjMcgd+Bnz6k2Q9BSlnsz1kBI5z4iuvfz5DFWkb95xcZYC7WYI4pNmWj7OdCU OBLZe3hXBijJP4x9TtEuA+CEAWJsQ3bBJRlbpctqmqTOtutzfsm2e06hsc3oeRfedm8w OZ7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Wf+QnXwZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i12si16252152jac.26.2021.09.21.09.35.21; Tue, 21 Sep 2021 09:35:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Wf+QnXwZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S229684AbhIUQfD (ORCPT + 99 others); Tue, 21 Sep 2021 12:35:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbhIUQfA (ORCPT ); Tue, 21 Sep 2021 12:35:00 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19673C061574 for ; Tue, 21 Sep 2021 09:33:32 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id z8-20020a056214040800b00380dea65c01so24912862qvx.4 for ; Tue, 21 Sep 2021 09:33:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=XXlfpcBmbRno5SA+gst6Gevlk7ltg9389UQ9dhNVCvA=; b=Wf+QnXwZGfTR93ea68ZPKzFik9oK5cF0gl/6r7BXDTKkCEkNlT5puLNHR76CLQ4TxS sqnivS0sK15CMFeU/ykdAnnhQlLBTCOEwfM3X+Sc1uvAZ3q2dU+XX2CTC6tqtw/qpobw jEpk3zQXOidiuHrp/6oAP/MWm+Ybq220aML/CuZnSDiuYveXKux6S17aaiLnikWbL+QL k+qzoGVvrmTGw0A2trsphU4lw0U4aTCe3vkkP2ZuPFRvH5Eg6dTZcXR2p3I8D0o3GQAN wmv53dN1fi7EhnyFpRlW+rbaFzAB2o8DOg/NIAJK4uDK/coDPCIvKWAdo9GuKq7tFxG7 uVsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=XXlfpcBmbRno5SA+gst6Gevlk7ltg9389UQ9dhNVCvA=; b=eWxFVB1hk6NgDXygu8TK1z8CwBbESc40jqJIEQFakQyat+qf7TVPrtoUWd7BBA7TaO Jb+GOd9qMf/ScYwH34jahZ2wOjJGs4J2MJGmAz5hqgWX2f/nccxLSiTQiuLMm8CLXs5k Rv8GiLavniwdQX/Vfh6FEL8H3r7ufhF99Gyf6j9FYTfere9c3udSAptcqtwzO/EJ2LWl RA3pDZR82lQrEcIhML1P7B3y7OFu3wjC/8bxQxtCoJPaeOZYlVp4saNOVddqb9xq7BeW ylRlauaB6uJlcKFxCt1LVHqza4l4ikJwHqv4WumrncXklsplBz8oZrxLCaEj8wZZNbmw Le3A== X-Gm-Message-State: AOAM5320GcfcwfBeZ7kEv97o9KGTK5AWRsK5qPYrhWcVNekN3cZ6Cd9e JEN3GWohUhmrPgA8I/g2K/KeUw28askvr6sbyVO+ X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:ed57:a230:8c3d:64d8]) (user=axelrasmussen job=sendgmr) by 2002:a05:6902:124e:: with SMTP id t14mr39259664ybu.106.1632242011222; Tue, 21 Sep 2021 09:33:31 -0700 (PDT) Date: Tue, 21 Sep 2021 09:33:23 -0700 In-Reply-To: <20210921163323.944352-1-axelrasmussen@google.com> Message-Id: <20210921163323.944352-3-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210921163323.944352-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog Subject: [PATCH 3/3] userfaultfd/selftests: don't rely on GNU extensions for random numbers From: Axel Rasmussen To: Andrew Morton , Peter Xu , Shuah Khan Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Axel Rasmussen Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Two arguments for doing this: First, and maybe most importantly, the resulting code is significantly shorter / simpler. Then, we avoid using GNU libc extensions. Why does this matter? It makes testing userfaultfd with the selftest easier e.g. on distros which use something other than glibc (e.g., Alpine, which uses musl); basically, it makes the test more portable. Signed-off-by: Axel Rasmussen --- tools/testing/selftests/vm/userfaultfd.c | 26 ++++-------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index aad5211f5012..9d9f60e71524 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -57,6 +57,7 @@ #include #include #include +#include #include "../kselftest.h" @@ -528,22 +529,10 @@ static void continue_range(int ufd, __u64 start, __u64 len) static void *locking_thread(void *arg) { unsigned long cpu = (unsigned long) arg; - struct random_data rand; unsigned long page_nr = *(&(page_nr)); /* uninitialized warning */ - int32_t rand_nr; unsigned long long count; - char randstate[64]; - unsigned int seed; - if (bounces & BOUNCE_RANDOM) { - seed = (unsigned int) time(NULL) - bounces; - if (!(bounces & BOUNCE_RACINGFAULTS)) - seed += cpu; - bzero(&rand, sizeof(rand)); - bzero(&randstate, sizeof(randstate)); - if (initstate_r(seed, randstate, sizeof(randstate), &rand)) - err("initstate_r failed"); - } else { + if (!(bounces & BOUNCE_RANDOM)) { page_nr = -bounces; if (!(bounces & BOUNCE_RACINGFAULTS)) page_nr += cpu * nr_pages_per_cpu; @@ -551,15 +540,8 @@ static void *locking_thread(void *arg) while (!finished) { if (bounces & BOUNCE_RANDOM) { - if (random_r(&rand, &rand_nr)) - err("random_r failed"); - page_nr = rand_nr; - if (sizeof(page_nr) > sizeof(rand_nr)) { - if (random_r(&rand, &rand_nr)) - err("random_r failed"); - page_nr |= (((unsigned long) rand_nr) << 16) << - 16; - } + if (getrandom(&page_nr, sizeof(page_nr), 0) != sizeof(page_nr)) + err("getrandom failed"); } else page_nr += 1; page_nr %= nr_pages; -- 2.33.0.464.g1972c5931b-goog