Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp11476151rwd; Thu, 22 Jun 2023 13:56:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6F+z6xpTg2QOF4cQMXsO+ocs1pgOo0wSTJMW27oRUlqg1qt6KQzy/YT9SuFHmPCOf/3lW8 X-Received: by 2002:a17:90a:710:b0:25c:1138:d97c with SMTP id l16-20020a17090a071000b0025c1138d97cmr17174597pjl.24.1687467395559; Thu, 22 Jun 2023 13:56:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687467395; cv=none; d=google.com; s=arc-20160816; b=xPrtcu4q3fj+6R2wJUniTzUGF7H8K0MTHb0dehkN1uHsSLSA61vjdmANE6H13Svrdw W2tN0iZI/X75I529T3njWYalG+qqWCvF1ZFy9SmruDtYyVGMuQ5mfoIk7Pi26V/aj6PF eZj5pRnDDY/hk8kr00cI03p8DWI0X3va43d8QuPc/FdKZhjNgOtxSXKw/e5WATu7TdTa UdZIpaN2CJ6slQswjuuQxyFQ/skY3OiENV9mWZLS+VPJs7/4OXrAXlkKPGZkAmcO4Gjf D/ndWbpUdvpuS9VhYQU5IL8WjKWGCs13psqctG3nJEwMJnx7YAgdWGj0TjLH94/EEyil qfHg== 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:dkim-signature:date; bh=pw4ylFOI5MC67k88Xw8BHF9F5U0/F6yAo4XeRQvZ3dk=; b=0+dFUITr3r5lj6rgPogVtx5ihU8GhCKbHBSYQeyHth+1gAw8USKGTV8LUX453P4Wt+ Iqj7HsJy+9pIaYJXFz3JTiYw/hCQBLeoaPyFwIw2A04JMoNUnVPyz57nDtqS1PIlmutD KMB8tbeBSfdXMw63MEbUt3dfV4Zxe5ynG825RcV/F5qr5UMgc62enGj3AU5xldBUmMpW 7pmXDDJ5ehtN3NcXbd5PAS7ZMVRFowbVzsuxciu18u5UEV/3cQvHfhLzu4u9ysCXaja1 a6Vku2mY9e/ZYO7g9ormmAFZKt88sKe/NQ/2ix7gqS3uzRRA55u+mYbvBSWThi8bLPPY Xjdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@t-8ch.de header.s=mail header.b=lg4BaVBZ; 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 b1-20020a17090a5a0100b002532e1993basi340920pjd.154.2023.06.22.13.56.22; Thu, 22 Jun 2023 13:56:35 -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=@t-8ch.de header.s=mail header.b=lg4BaVBZ; 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 S230322AbjFVT4Z (ORCPT + 99 others); Thu, 22 Jun 2023 15:56:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229643AbjFVT4Y (ORCPT ); Thu, 22 Jun 2023 15:56:24 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCDB2F1; Thu, 22 Jun 2023 12:56:22 -0700 (PDT) Date: Thu, 22 Jun 2023 21:56:19 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=t-8ch.de; s=mail; t=1687463780; bh=sjhMAnWC+WRXas1AobjF7bEqN7SCFpSlpfEgghDu3ZY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lg4BaVBZWGV5eFXgYBMM7duPkZ4vK9SZ9Kd2MWai1NvPvpBmP4Akvz4cYcbP9gAkC f0ePQyBJPmsU1uy7aW8D9ivtVgAcbx0PvfqBqNS8rMSFcRao+HKEkc9mHi8xlwWPbk wFvNiz5HFpPmVzN12e749DBZHpK55liL57uZZZEQ= From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: Zhangjin Wu Cc: arnd@arndb.de, david.laight@aculab.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, w@1wt.eu Subject: Re: [PATCH v4 10/10] selftests/nolibc: add mmap and munmap test cases Message-ID: <97fbbe17-b261-475c-8959-71cccaa5a2f5@t-8ch.de> References: <20230622193249.1190336-1-falcon@tinylab.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230622193249.1190336-1-falcon@tinylab.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Hi Zhangjin, On 2023-06-23 03:32:49+0800, Zhangjin Wu wrote: > > On 2023-06-19 23:55:41+0800, Zhangjin Wu wrote: > > > Three mmap/munmap related test cases are added: > > > > > > - mmap(NULL, 0, PROT_READ, MAP_PRIVATE, 0, 0), MAP_FAILED, EINVAL) > > > > > > The length argument must be greater than 0, otherwise, fail with -EINVAL. > > > > > > - munmap((void *)-1, 4*1024), -1, EINVAL) > > > > > > Invalid (void *)-1 address fail with -EINVAL. > > > > > > - test_mmap_munmap(4*1024) > > > > > > It finds a init file, mmap() it and then munmap(). > > > > > > Signed-off-by: Zhangjin Wu > > > --- > > > tools/testing/selftests/nolibc/nolibc-test.c | 31 ++++++++++++++++++++ > > > 1 file changed, 31 insertions(+) > > > > > > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c > > > index 80ab29e2887c..f7c0ca72cb28 100644 > > > --- a/tools/testing/selftests/nolibc/nolibc-test.c > > > +++ b/tools/testing/selftests/nolibc/nolibc-test.c > > > @@ -592,6 +592,34 @@ static int test_stat_timestamps(void) > > > return 0; > > > } > > > > > > +int test_mmap_munmap(int size) > > > +{ > > > + char init_files[5][20] = {"/init", "/sbin/init", "/etc/init", "/bin/init", "/bin/sh"}; > > > > Why not /proc/1/exe or even /proc/self/exe? > > > > I know your other series tries to remove the procfs dependency, but > > we're not there yet :-). > > > > Yeah, '/proc/self/exe' is a choice, if so, the 'has_proc' should be added ;-) Currently procfs is a hard requirement. So I would leave 'has_proc' to the other series that may change this. > > Also does it make sense to pass a size parameter? > > Why not use either PAGE_SIZE or the real size of the binary from > > fstat(). > > > > Ok, as the manpage of mmap shows: > > For mmap(), offset must be a multiple of the underlying huge page > size. The system automatically aligns length to be a multiple of > the underlying huge page size. > > For munmap(), addr, and length must both be a multiple of the > underlying huge page size. > > perhaps we should do further tests: > > * the real size/length > * even > the real size > * the PAGE_SIZE > * not aligned with PAGE_SIZE > > If such tests are required, the 'size' and even 'offset' arguments could be > provided to cover different combination or we do such tests internally, then, > the arguments are not required. I think task of nolibc-test is to test the code in nolibc itself. The custom mmap implementation is trivial and directly calls the syscall. These additionally proposed tests would effectively test the core kernels implementation of mmap() and not the code of nolibc. Therefore I don't think they are necessary in nolibc-test and the functionality is hopefully already be tested in another testsuite. Note: Testing mmap is indeed useful to test the implementation of my_syscall6() by providing a bogus value in the 'offset' parameter. I think we do have such a testcase. Thomas