Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp9257000rwp; Thu, 20 Jul 2023 01:56:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlHgHgC1JKHF5crj3i6BupjCjCc8bhrUFRF+Gc0T4OkuAsCiwdkWT750X41YT+Bso3PoJ+WC X-Received: by 2002:a17:906:649a:b0:994:5503:69c1 with SMTP id e26-20020a170906649a00b00994550369c1mr5003151ejm.18.1689843417885; Thu, 20 Jul 2023 01:56:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689843417; cv=none; d=google.com; s=arc-20160816; b=KDNaywdXkxSIHaUAQWyDWQfU48UiG8loyoE35AFCbd6MNI2KEioFg+ShcvkCtv8K/H NkdQQAu60ItJXXHBOWCX/Kh5GkaA6IKssOBc5hv6xSQi10XqKo5vEzdseL/yrBNGHSoh Px9remm+u2KGRqCaR+jUG5wuNOEnlH/9aYNEeTmzd5/GlgMB8TPnW0AwiykwcszfRplv woLkmYm4O5DpdEyr62UDMD5ZqIjcRsJMvrMRPTORDR1/S3KjnzOXszzf4CN82FgFQp56 Z5XDy3SspGTVzR/af3Lz5EAmB2AVRTeD189e3dChBgk6oRvyHFEVW61cHDLmGpKBg6T5 9tKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=DNGJaYEpeCAI7drQ8W8ZV+PTc4Zy8Ohv1zP8hIu3TR8=; fh=ndblg2dALUQcsjGAGAPUQ5KoZyCh2MVOlF+6a8mdrLk=; b=wLC8yNnS0g/hP/pD+23SkumGRUliiLmryLFDtFKE9/sJOfggBWt5hKNToo/pwN+04J BlS4yC9DcddMPAr0ma5JQ6FMnNlmpDADcXUsy771FPk3ErG+KYCa0AhPTxjBfUQPEzL0 4NsquW8zCgXdG8WTRm2+D/hDuJ+2kNjQn9AJdUp+Hp2Zd8hh+4lR15Vdbjsa8odWAGer z50mls0KwW/WptOG9F8uVj0lNvwhrTROs2S3huCf34EybKFroUZGJCL5BzwwNrkvskc1 /uJYkxQ8EC67gWLC5FQhy4ByATQHvub35L067LhekdMOHjyF2efeoYoZcnz39JFqCEqW 0Yww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=aZoe4sdI; 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 u7-20020a170906124700b0098e78ff1a8fsi384278eja.358.2023.07.20.01.56.33; Thu, 20 Jul 2023 01:56:57 -0700 (PDT) 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=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=aZoe4sdI; 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 S229814AbjGTIQ1 (ORCPT + 99 others); Thu, 20 Jul 2023 04:16:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229705AbjGTIQZ (ORCPT ); Thu, 20 Jul 2023 04:16:25 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14AD72686 for ; Thu, 20 Jul 2023 01:16:23 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-31441bc0092so389920f8f.1 for ; Thu, 20 Jul 2023 01:16:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1689840981; x=1690445781; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=DNGJaYEpeCAI7drQ8W8ZV+PTc4Zy8Ohv1zP8hIu3TR8=; b=aZoe4sdItvYTIGvKmdBkwWvSm9XIortrvDEcFOv6U9T3bIJ8wJnc6+CdANOPnQrFGc b0efaIB7KWoqmRTL3zp9zVjPLbqwS7QZ9OcJvAiEtHKiNyasiXXEHCx01wZ8w7V52ooO VZOs8dgeSuhEJGHUnBfSMnTt2rJW17BNUCa9NOJL6VT5n8XjqhdAxgnCetbYFNQWPXHz X7ja3ACB0l+HqW62c75Hq8g4y36DXolIpV9WqT1ww8yPETw0kowXqC4Jn7UiXdaKsC8B 140VXB7XUvRAbyNj5Wz6RlEpo38ImoCnfE2LhyY3zi5M+fexasEdd0sZlnkUE+60ARi4 ON0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689840981; x=1690445781; h=content-transfer-encoding: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=DNGJaYEpeCAI7drQ8W8ZV+PTc4Zy8Ohv1zP8hIu3TR8=; b=X53kLNN7ltgzVCRcZsF6YNKp9XqSy/muOUBB0HwgTYBf66dBXXHxeTtXHBbIGKqOJq qvJ/wBdtup+yWrswBl+4KMH6m2rTKP+06yWR7Exazqy0s102f5/KTGtrvNuyn/p+V859 MNo5ufuh06fMwHbADewZBCcb6MfI9YBwxGi+OHzBkW2bLM3OU+v638m3ZwkrFt+h7ezn X2TCVX3j0JFwMc8tmBxu5N7l3g6gtB4E6tNghMpQK8bVT86kPL5z9PcR5PL5Ur9DOEMQ Rq6DHWKYXOJgceqBPfdg6WnWNP2nZEdV8FjWeU/RL1aL0S6jxKmJD6QaoR9x09VUVg+P HjcQ== X-Gm-Message-State: ABy/qLbT3of4Jtylp9bJlU5AX8NMMWJW1uQ6nkAt5pnpeX+NivXa4N2w zMGCzqED+L6VR8Fj5JieaEA81q5uMaIjbvXO4tHI9g== X-Received: by 2002:a5d:456c:0:b0:316:f1a5:269f with SMTP id a12-20020a5d456c000000b00316f1a5269fmr1310004wrc.70.1689840981522; Thu, 20 Jul 2023 01:16:21 -0700 (PDT) MIME-Version: 1.0 References: <20230714165508.94561-1-charlie@rivosinc.com> <20230714165508.94561-3-charlie@rivosinc.com> In-Reply-To: <20230714165508.94561-3-charlie@rivosinc.com> From: Alexandre Ghiti Date: Thu, 20 Jul 2023 10:16:10 +0200 Message-ID: Subject: Re: [PATCH v6 2/4] RISC-V: mm: Add tests for RISC-V mm To: Charlie Jenkins Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, conor@kernel.org, paul.walmsley@sifive.com, palmer@rivosinc.com, aou@eecs.berkeley.edu, anup@brainfault.org, konstantin@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, mick@ics.forth.gr, jrtc27@jrtc27.com, rdunlap@infradead.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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, Jul 14, 2023 at 6:55=E2=80=AFPM Charlie Jenkins wrote: > > Add tests that enforce mmap hint address behavior. mmap should default > to sv48. mmap will provide an address at the highest address space that > can fit into the hint address, unless the hint address is less than sv39 > and not 0, then it will return a sv39 address. In addition, ensure that > rlimit changes do not cause mmap to fail. > > Signed-off-by: Charlie Jenkins > --- > tools/testing/selftests/riscv/Makefile | 2 +- > tools/testing/selftests/riscv/mm/.gitignore | 1 + > tools/testing/selftests/riscv/mm/Makefile | 21 +++ > .../selftests/riscv/mm/testcases/mmap.c | 133 ++++++++++++++++++ > 4 files changed, 156 insertions(+), 1 deletion(-) > create mode 100644 tools/testing/selftests/riscv/mm/.gitignore > create mode 100644 tools/testing/selftests/riscv/mm/Makefile > create mode 100644 tools/testing/selftests/riscv/mm/testcases/mmap.c > > diff --git a/tools/testing/selftests/riscv/Makefile b/tools/testing/selft= ests/riscv/Makefile > index 9dd629cc86aa..1b79da90396e 100644 > --- a/tools/testing/selftests/riscv/Makefile > +++ b/tools/testing/selftests/riscv/Makefile > @@ -5,7 +5,7 @@ > ARCH ?=3D $(shell uname -m 2>/dev/null || echo not) > > ifneq (,$(filter $(ARCH),riscv)) > -RISCV_SUBTARGETS ?=3D hwprobe vector > +RISCV_SUBTARGETS ?=3D hwprobe vector mm > else > RISCV_SUBTARGETS :=3D > endif > diff --git a/tools/testing/selftests/riscv/mm/.gitignore b/tools/testing/= selftests/riscv/mm/.gitignore > new file mode 100644 > index 000000000000..9a6f303edcd3 > --- /dev/null > +++ b/tools/testing/selftests/riscv/mm/.gitignore > @@ -0,0 +1 @@ > +mmap > diff --git a/tools/testing/selftests/riscv/mm/Makefile b/tools/testing/se= lftests/riscv/mm/Makefile > new file mode 100644 > index 000000000000..cf68e63e7495 > --- /dev/null > +++ b/tools/testing/selftests/riscv/mm/Makefile > @@ -0,0 +1,21 @@ > +# SPDX-License-Identifier: GPL-2.0 > +# Originally tools/testing/selftests/arm64/signal > + > +# Additional include paths needed by kselftest.h and local headers > +CFLAGS +=3D -D_GNU_SOURCE -std=3Dgnu99 -I. > + > +SRCS :=3D $(filter-out testcases/testcases.c,$(wildcard testcases/*.c)) > +PROGS :=3D $(patsubst %.c,%,$(SRCS)) > + > +# Generated binaries to be installed by top KSFT script > +TEST_GEN_PROGS :=3D $(notdir $(PROGS)) > + > +# Get Kernel headers installed and use them. > + > +# Including KSFT lib.mk here will also mangle the TEST_GEN_PROGS list > +# to account for any OUTPUT target-dirs optionally provided by > +# the toplevel makefile > +include ../../lib.mk > + > +$(TEST_GEN_PROGS): $(PROGS) > + cp $(PROGS) $(OUTPUT)/ > diff --git a/tools/testing/selftests/riscv/mm/testcases/mmap.c b/tools/te= sting/selftests/riscv/mm/testcases/mmap.c > new file mode 100644 > index 000000000000..d8e751f7b8c9 > --- /dev/null > +++ b/tools/testing/selftests/riscv/mm/testcases/mmap.c > @@ -0,0 +1,133 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +#include > +#include > +#include > + > +#include "../../kselftest_harness.h" > +struct addresses { > + int *no_hint; > + int *on_37_addr; > + int *on_38_addr; > + int *on_46_addr; > + int *on_47_addr; > + int *on_55_addr; > + int *on_56_addr; > +}; > + > +void do_mmaps(struct addresses *mmap_addresses) > +{ > + // Place all of the hint addresses on the boundaries of mmap > + // sv39, sv48, sv57 > + // User addresses end at 1<<38, 1<<47, 1<<56 respectively Doesn't checkpatch complain about those comments? Shouldn't you use /* */ instead? > + void *on_37_bits =3D (void *)(1UL << 37); > + void *on_38_bits =3D (void *)(1UL << 38); > + void *on_46_bits =3D (void *)(1UL << 46); > + void *on_47_bits =3D (void *)(1UL << 47); > + void *on_55_bits =3D (void *)(1UL << 55); > + void *on_56_bits =3D (void *)(1UL << 56); > + > + int prot =3D PROT_READ | PROT_WRITE; > + int flags =3D MAP_PRIVATE | MAP_ANONYMOUS; > + > + mmap_addresses->no_hint =3D > + mmap(NULL, 5 * sizeof(int), prot, flags, 0, 0); > + mmap_addresses->on_37_addr =3D > + mmap(on_37_bits, 5 * sizeof(int), prot, flags, 0, 0); > + mmap_addresses->on_38_addr =3D > + mmap(on_38_bits, 5 * sizeof(int), prot, flags, 0, 0); > + mmap_addresses->on_46_addr =3D > + mmap(on_46_bits, 5 * sizeof(int), prot, flags, 0, 0); > + mmap_addresses->on_47_addr =3D > + mmap(on_47_bits, 5 * sizeof(int), prot, flags, 0, 0); > + mmap_addresses->on_55_addr =3D > + mmap(on_55_bits, 5 * sizeof(int), prot, flags, 0, 0); > + mmap_addresses->on_56_addr =3D > + mmap(on_56_bits, 5 * sizeof(int), prot, flags, 0, 0); > +} > + > +TEST(default_rlimit) > +{ > +// Only works on 64 bit > +#if __riscv_xlen =3D=3D 64 > + struct addresses mmap_addresses; > + > + do_mmaps(&mmap_addresses); > + > + EXPECT_NE(mmap_addresses.no_hint, MAP_FAILED); > + EXPECT_NE(mmap_addresses.on_37_addr, MAP_FAILED); > + EXPECT_NE(mmap_addresses.on_38_addr, MAP_FAILED); > + EXPECT_NE(mmap_addresses.on_46_addr, MAP_FAILED); > + EXPECT_NE(mmap_addresses.on_47_addr, MAP_FAILED); > + EXPECT_NE(mmap_addresses.on_55_addr, MAP_FAILED); > + EXPECT_NE(mmap_addresses.on_56_addr, MAP_FAILED); > + > + EXPECT_LT((unsigned long)mmap_addresses.no_hint, 1UL << 47); > + EXPECT_LT((unsigned long)mmap_addresses.on_37_addr, 1UL << 38); > + EXPECT_LT((unsigned long)mmap_addresses.on_38_addr, 1UL << 38); > + EXPECT_LT((unsigned long)mmap_addresses.on_46_addr, 1UL << 38); > + EXPECT_LT((unsigned long)mmap_addresses.on_47_addr, 1UL << 47); > + EXPECT_LT((unsigned long)mmap_addresses.on_55_addr, 1UL << 47); > + EXPECT_LT((unsigned long)mmap_addresses.on_56_addr, 1UL << 56); > +#endif > +} > + > +TEST(zero_rlimit) > +{ > +// Only works on 64 bit > +#if __riscv_xlen =3D=3D 64 > + struct addresses mmap_addresses; > + struct rlimit rlim_new =3D { .rlim_cur =3D 0, .rlim_max =3D RLIM_= INFINITY }; > + > + setrlimit(RLIMIT_STACK, &rlim_new); > + > + do_mmaps(&mmap_addresses); > + > + EXPECT_NE(mmap_addresses.no_hint, MAP_FAILED); > + EXPECT_NE(mmap_addresses.on_37_addr, MAP_FAILED); > + EXPECT_NE(mmap_addresses.on_38_addr, MAP_FAILED); > + EXPECT_NE(mmap_addresses.on_46_addr, MAP_FAILED); > + EXPECT_NE(mmap_addresses.on_47_addr, MAP_FAILED); > + EXPECT_NE(mmap_addresses.on_55_addr, MAP_FAILED); > + EXPECT_NE(mmap_addresses.on_56_addr, MAP_FAILED); > + > + EXPECT_LT((unsigned long)mmap_addresses.no_hint, 1UL << 47); > + EXPECT_LT((unsigned long)mmap_addresses.on_37_addr, 1UL << 38); > + EXPECT_LT((unsigned long)mmap_addresses.on_38_addr, 1UL << 38); > + EXPECT_LT((unsigned long)mmap_addresses.on_46_addr, 1UL << 38); > + EXPECT_LT((unsigned long)mmap_addresses.on_47_addr, 1UL << 47); > + EXPECT_LT((unsigned long)mmap_addresses.on_55_addr, 1UL << 47); > + EXPECT_LT((unsigned long)mmap_addresses.on_56_addr, 1UL << 56); > +#endif > +} > + > +TEST(infinite_rlimit) > +{ > +// Only works on 64 bit > +#if __riscv_xlen =3D=3D 64 > + struct addresses mmap_addresses; > + struct rlimit rlim_new =3D { .rlim_cur =3D RLIM_INFINITY, > + .rlim_max =3D RLIM_INFINITY }; > + > + setrlimit(RLIMIT_STACK, &rlim_new); > + > + do_mmaps(&mmap_addresses); > + > + EXPECT_NE(mmap_addresses.no_hint, MAP_FAILED); > + EXPECT_NE(mmap_addresses.on_37_addr, MAP_FAILED); > + EXPECT_NE(mmap_addresses.on_38_addr, MAP_FAILED); > + EXPECT_NE(mmap_addresses.on_46_addr, MAP_FAILED); > + EXPECT_NE(mmap_addresses.on_47_addr, MAP_FAILED); > + EXPECT_NE(mmap_addresses.on_55_addr, MAP_FAILED); > + EXPECT_NE(mmap_addresses.on_56_addr, MAP_FAILED); > + > + EXPECT_LT((unsigned long)mmap_addresses.no_hint, 1UL << 47); > + EXPECT_LT((unsigned long)mmap_addresses.on_37_addr, 1UL << 38); > + EXPECT_LT((unsigned long)mmap_addresses.on_38_addr, 1UL << 38); > + EXPECT_LT((unsigned long)mmap_addresses.on_46_addr, 1UL << 38); > + EXPECT_LT((unsigned long)mmap_addresses.on_47_addr, 1UL << 47); > + EXPECT_LT((unsigned long)mmap_addresses.on_55_addr, 1UL << 47); > + EXPECT_LT((unsigned long)mmap_addresses.on_56_addr, 1UL << 56); > +#endif > +} > + > +TEST_HARNESS_MAIN > -- > 2.41.0 >