public inbox for linux-riscv@lists.infradead.org
 help / color / mirror / Atom feed
From: Aurelien Jarno <aurelien@aurel32.net>
To: linux-riscv@lists.infradead.org
Cc: Bo YU <tsu.yubo@gmail.com>, Andreas Gruenbacher <agruenba@redhat.com>
Subject: Re: potential riscv special bug maybe found
Date: Wed, 9 Aug 2023 16:47:37 +0200	[thread overview]
Message-ID: <ZNOnCakhwIeue3yr@aurel32.net> (raw)
In-Reply-To: <20230309151841.bomov6hq3ybyp42a@debian>


[-- Attachment #1.1.1: Type: text/plain, Size: 1316 bytes --]

Hi,

On 2023-03-09 23:18, Bo YU wrote:
> Hi,
> 
> I am sorry if this is noise.
> 
> Some days ago I noticed strace 6.2 was built failed on riscv64 due to
> test cases[0]. There is one program from strace can reproduce it:
> 
> ```
> ./tests/read-write ```
> 
> It will be hang.
> 
> In fact, the issue has existed since 5.18. I `git bisect` and finally
> found out the issue was introduced by the commit[1]:
> 
> commit 631f871f071746789e9242e514ab0f49067fa97a
> Author: Andreas Gruenbacher <agruenba@redhat.com>
> Date:   Tue Nov 9 12:56:06 2021 +0100
> 
>     fs/iomap: Fix buffered write page prefaulting
> 
> I do not think there is a problem with this commit, because it does not
> affect others arch expect riscv and after I reverted it, it will pass
> all test cases from strace(There is still one case failed on qemu, but
> this is another store).
> 
> I try to debug something but failed.
> Would be appreciated it any help.

Please find attached a simpler reproducer extracted from strace, which
should make the issue easier to reproduce. It hangs on riscv64 and needs
to be killed with -9, while it works fine on amd64.

Regards
Aurelien

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                     http://aurel32.net

[-- Attachment #1.1.2: read-write.c --]
[-- Type: text/x-csrc, Size: 2277 bytes --]

/*
 * Check decoding and dumping of read and write syscalls.
 *
 * Copyright (c) 2016 Dmitry V. Levin <ldv@strace.io>
 * Copyright (c) 2016-2021 The strace developers.
 * All rights reserved.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/mman.h>

# define LENGTH_OF(arg) ((unsigned int) sizeof(arg) - 1)
# define ARRAY_SIZE(a_)        (sizeof(a_) / sizeof((a_)[0]))

static void *
tail_alloc(const size_t size)
{
	const size_t page_size = sysconf(_SC_PAGESIZE);
	const size_t len = (size + page_size - 1) & -page_size;
	const size_t alloc_size = len + 6 * page_size;

	void *p = mmap(NULL, alloc_size, PROT_READ | PROT_WRITE,
		       MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
	if (MAP_FAILED == p) {
		perror("mmap");
		exit(1);
	}

	void *start_work = p + 3 * page_size;
	void *tail_guard = start_work + len;

	if (munmap(p, page_size) ||
	    munmap(p + 2 * page_size, page_size) ||
	    munmap(tail_guard, page_size) ||
	    munmap(tail_guard + 2 * page_size, page_size)) {
		perror("munmap");
		exit(1);
	}

	memset(start_work, 0xff, len);
	return tail_guard - size;
}

static void
fill_memory_ex(void *ptr, size_t size, unsigned char start,
	       unsigned int period)
{
	unsigned char *p = ptr;

	for (typeof(size) i = 0; i < size; ++i) {
		p[i] = start + i % period;
	}
}

int
main(void)
{
	static const char tmp[] = "read-write-tmpfile";
	long rc;
	long fdr;
	long fdw;

	unlink(tmp);

	fdr = open(tmp, O_CREAT|O_EXCL|O_RDONLY, 0600);
	if (fdr < 0) {
		perror("create");
		exit(1);
	}

	fdw = open(tmp, O_TRUNC|O_WRONLY);
	if (fdw < 0) {
		perror("open");
		exit(1);
	}

	static const char w_c[] = "0123456789abcde";
	const unsigned int w_len = LENGTH_OF(w_c);

	rc = write(fdw, w_c, w_len);
	if (rc != (int) w_len) {
		perror("write");
		exit(1);
	}

	static const size_t six_wide_size = 1 << 20;
	static const size_t fetch_size = 1 << 16;
	const size_t buf_size = six_wide_size + fetch_size;
	const size_t sizes[] = {
		buf_size,
		buf_size + 1,
	};
	char *big_buf = tail_alloc(buf_size);

	fill_memory_ex(big_buf, buf_size, 0, 0x100);

	for (size_t i = 0; i < ARRAY_SIZE(sizes); i++) {
		write(fdw, big_buf, sizes[i]);
	}

	close(fdw);

	return 0;
}

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 161 bytes --]

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2023-08-09 14:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-09 15:18 potential riscv special bug maybe found Bo YU
2023-08-09 14:47 ` Aurelien Jarno [this message]
2023-08-10 11:09   ` Alexandre Ghiti
2023-08-11  9:32     ` Alexandre Ghiti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZNOnCakhwIeue3yr@aurel32.net \
    --to=aurelien@aurel32.net \
    --cc=agruenba@redhat.com \
    --cc=linux-riscv@lists.infradead.org \
    --cc=tsu.yubo@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox