From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by sourceware.org (Postfix) with ESMTPS id 599BE3858D28 for ; Tue, 7 Dec 2021 21:37:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 599BE3858D28 Received: by mail-pg1-x529.google.com with SMTP id f125so304408pgc.0 for ; Tue, 07 Dec 2021 13:37:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Uj+kNWDHkcccZ2bdB5Tb338qxZEcRFdjyNhi/G1/jLU=; b=Bz3a1Lnn1wqI1Y2/UJcmqR8mP99d4Am6C++4jiG1iJ/zatSRAk/P8k4seh7KTS/SrQ cjaE1mGgtTVvQAfk8+QVbu3MpFiOpGfsH8b1oKx8lDPydtXrbqWJQH4FlCYJV99yQkDP 4n0XUIgWoi2NcO9yyaeFW7TDZ39R2fwf/AyhQ4hw4HQ5/zhTxygs/AWGM5Evof338iZR +m4AxBS0EjvVzO/BajjozSwjCRdCe7+BWqQPdLdD4O0YeGlN3+V3NDr6qE2czGISjpmG Ua1C+zUiK4EJkGtOux8N5bMTO17xXHERz3E4YwbX9OtgXFBq1naulx2QnqSaCRyKsCvD CuHg== X-Gm-Message-State: AOAM533ofby3vp7fVhUz+kd86rlxoCcMVXRvOMRSgFPX3ZTOORQseLIS JitEoeTWHQ0M+znjnihtXIVlTP3moSUHbPSSKBE= X-Google-Smtp-Source: ABdhPJysF4HkwLLxpu9uChzP4y3S2ItWatekt8OogxXagbWFrByKk+oiauH/yZao3iFAdLKXxgPYPDd1kC/n9Cd5LmI= X-Received: by 2002:a63:1858:: with SMTP id 24mr26362586pgy.338.1638913019382; Tue, 07 Dec 2021 13:36:59 -0800 (PST) MIME-Version: 1.0 References: <20211101054952.2349590-1-goldstein.w.n@gmail.com> <20211106183322.3129442-1-goldstein.w.n@gmail.com> In-Reply-To: From: Noah Goldstein Date: Tue, 7 Dec 2021 15:36:48 -0600 Message-ID: Subject: Re: [PATCH v4 1/5] string: Make tests birdirectional test-memcpy.c To: Stafford Horne Cc: GNU C Library Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Dec 2021 21:37:02 -0000 On Tue, Dec 7, 2021 at 3:10 PM Stafford Horne wrote: > > On Sat, Nov 06, 2021 at 01:33:18PM -0500, Noah Goldstein via Libc-alpha wrote: > > This commit updates the memcpy tests to test both dst > src and dst < > > src. This is because there is logic in the code based on the > > Reviewed-by: H.J. Lu > > --- > > string/test-memcpy.c | 167 +++++++++++++++++++++++++++++++++++------- > > string/test-memmove.c | 75 ++++++++++++++++++- > > 2 files changed, 214 insertions(+), 28 deletions(-) > > > > diff --git a/string/test-memcpy.c b/string/test-memcpy.c > [..] > > static void > > -do_test1 (size_t size) > > +do_test1 (size_t align1, size_t align2, size_t size) > > { > > void *large_buf; > > - large_buf = mmap (NULL, size * 2 + page_size, PROT_READ | PROT_WRITE, > > - MAP_PRIVATE | MAP_ANON, -1, 0); > > + size_t mmap_size, region_size; > > + > > + align1 &= (page_size - 1); > > + if (align1 == 0) > > + align1 = page_size; > > + > > + align2 &= (page_size - 1); > > + if (align2 == 0) > > + align2 = page_size; > > + > > + region_size = (size + page_size - 1) & (~(page_size - 1)); > > + > > + mmap_size = region_size * 2 + 3 * page_size; > > + large_buf = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, > > + MAP_PRIVATE | MAP_ANON, -1, 0); > > if (large_buf == MAP_FAILED) > > { > > - puts ("Failed to allocat large_buf, skipping do_test1"); > > + puts ("Failed to allocate large_buf, skipping do_test1"); > > return; > > } > > - > > - if (mprotect (large_buf + size, page_size, PROT_NONE)) > > + if (mprotect (large_buf + region_size + page_size, page_size, PROT_NONE)) > > error (EXIT_FAILURE, errno, "mprotect failed"); > > > > - size_t arrary_size = size / sizeof (uint32_t); > > - uint32_t *dest = large_buf; > > - uint32_t *src = large_buf + size + page_size; > > + size_t array_size = size / sizeof (uint32_t); > > + uint32_t *dest = large_buf + align1; > > + uint32_t *src = large_buf + region_size + 2 * page_size + align2; > > Hello, this causes Bus errors on the new OpenRISC port I am working on. Bugzilla for this issue is here: https://sourceware.org/bugzilla/show_bug.cgi?id=28572 There is a patch attached to the bugzilla and a patch proposed by Adhemerval Zanella that both fix the issue. > > > size_t i; > > size_t repeats; > > for(repeats = 0; repeats < 2; repeats++) > > { > > - for (i = 0; i < arrary_size; i++) > > + for (i = 0; i < array_size; i++) > > src[i] = (uint32_t) i; > > The bus errors happen here caused when align2 is 1 or 2. OpenRISC (and maybe > other architectures?) do not support unaligned copies of words. > > I fixed this by limiting the align1/align2 to 4 but I am not sure if that is > what you are trying to copy here. > > Maybe we need to change how we setup the src array. > > > - > > FOR_EACH_IMPL (impl, 0) > > { > > - printf ("\t\tRunning: %s\n", impl->name); > > memset (dest, -1, size); > > CALL (impl, (char *) dest, (char *) src, size); > > - for (i = 0; i < arrary_size; i++) > > + for (i = 0; i < array_size; i++) > > if (dest[i] != src[i]) > > { > > error (0, 0, > > "Wrong result in function %s dst \"%p\" src \"%p\" offset \"%zd\"", > > impl->name, dest, src, i); > > ret = 1; > > - munmap ((void *) large_buf, size * 2 + page_size); > > + munmap ((void *) large_buf, mmap_size); > > return; > > } > > } > > - dest = src; > > - src = large_buf; > > + dest = large_buf + region_size + 2 * page_size + align1; > > + src = large_buf + align2; > > + } > > + munmap ((void *) large_buf, mmap_size); > > +} > > + > [..] > > @@ -306,8 +341,88 @@ test_main (void) > > > > do_random_tests (); > > > > - do_test1 (0x100000); > > - do_test1 (0x2000000); > > + do_test1 (0, 0, 0x100000); > > + do_test1 (0, 0, 0x2000000); > > + > > + for (i = 4096; i < 32768; i += 4096) > > + { > > + for (j = 1; j <= 1024; j <<= 1) > > + { > > + do_test1 (0, j, i); > > + do_test1 (4095, j, i); > > + do_test1 (4096 - j, 0, i); > > + > > + do_test1 (0, j - 1, i); > > + do_test1 (4095, j - 1, i); > > + do_test1 (4096 - j - 1, 0, i); > > + > > + do_test1 (0, j + 1, i); > > + do_test1 (4095, j + 1, i); > > + do_test1 (4096 - j, 1, i); > > These +1, -1's cause non-aligned word access. > > > + } > > + } > > + > > -Stafford