All of lore.kernel.org
 help / color / mirror / Atom feed
From: Caspar Zhang <caspar@casparzhang.com>
To: ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH] thp/thp03: new testcase
Date: Mon, 29 Oct 2012 18:28:23 +0800	[thread overview]
Message-ID: <508E5A47.9070904@casparzhang.com> (raw)
In-Reply-To: <1351502940-20415-1-git-send-email-cxie@redhat.com>

On 10/29/2012 05:29 PM, cxie@redhat.com wrote:
> From: Madper Xie <cxie@redhat.com>
>
> Modified form a reproducer for
>             https://patchwork.kernel.org/patch/1358441/
> pmd_present would return the wrong value on PROT_NONE ranges or in case
> of a non reproducible race with split_huge_page.
>
> The system will crash when this test failed.
>
> Signed-off-by: Madper Xie <cxie@redhat.com>

Please also attach the runtest entry.

Reviewed-by: Caspar Zhang <caspar@casparzhang.com>

> ---
>   testcases/kernel/mem/thp/thp03.c | 117 +++++++++++++++++++++++++++++++++++++++
>   1 file changed, 117 insertions(+)
>   create mode 100644 testcases/kernel/mem/thp/thp03.c
>
> diff --git a/testcases/kernel/mem/thp/thp03.c b/testcases/kernel/mem/thp/thp03.c
> new file mode 100644
> index 0000000..ee6fa1e
> --- /dev/null
> +++ b/testcases/kernel/mem/thp/thp03.c
> @@ -0,0 +1,117 @@
> +/*
> + * Copyright (C) 2012  Red Hat, Inc.
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of version 2 of the GNU General Public
> + * License as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it would be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + * Further, this software is distributed without any warranty that it
> + * is free of the rightful claim of any third person regarding
> + * infringement or the like.  Any license provided herein, whether
> + * implied or otherwise, applies only to this software file.  Patent
> + * licenses, if any, provided herein do not apply to combinations of
> + * this program with other software, or any other product whatsoever.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> + * 02110-1301, USA.
> + *
> + * thp03 - Case for spliting unaligned memory.
> + *       - System will panic if failed.
> + *
> + * There was a bug in THP, will crash happened due to the following
> + * reason according to developers:
> + *
> + * most VM places are using pmd_none but a few are still using
> + * pmd_present. The meaning is about the same for the pmd. However
> + * pmd_present would return the wrong value on PROT_NONE ranges or in
> + * case of a non reproducible race with split_huge_page.
> + * When the code using pmd_present gets a false negative, the kernel will
> + * crash. It's just an annoying DoS with a BUG_ON triggering: no memory
> + * corruption and no data corruption (nor userland nor kernel).
> + */
> +
> +#include <sys/mman.h>
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +#include <fcntl.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include "mem.h"
> +#include "safe_macros.h"
> +#include "test.h"
> +#include "usctest.h"
> +
> +char *TCID = "thp03";
> +
> +static void thp_test(void);
> +
> +static long hugepage_size;
> +static long unaligned_size;
> +static long page_size;
> +
> +int main(int argc, char **argv)
> +{
> +	int lc;
> +	char *msg;
> +
> +	msg = parse_opts(argc, argv, NULL, NULL);
> +	if (msg != NULL)
> +		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
> +
> +	setup();
> +
> +	for (lc = 0; TEST_LOOPING(lc); lc++) {
> +		Tst_count = 0;
> +
> +		thp_test();
> +	}
> +	tst_resm(TPASS, "system didn't crash, pass.");
> +	cleanup();
> +	tst_exit();
> +}
> +
> +static void thp_test(void)
> +{
> +	void *p;
> +
> +	p = mmap(NULL, unaligned_size, PROT_READ | PROT_WRITE,
> +		MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
> +	if (p == MAP_FAILED)
> +		tst_brkm(TBROK|TERRNO, cleanup, "mmap");
> +
> +	memset(p, 0x00, unaligned_size);
> +	if (mprotect(p, unaligned_size, PROT_NONE) == -1)
> +		tst_brkm(TBROK|TERRNO, cleanup, "mprotect");
> +	if (madvise(p + hugepage_size, page_size, MADV_MERGEABLE) == -1)
> +		tst_brkm(TBROK|TERRNO, cleanup, "madvise");
> +
> +	switch (fork()) {
> +	case -1:
> +		tst_brkm(TBROK|TERRNO, cleanup, "fork");
> +	case 0:
> +		exit(0);
> +	default:
> +		if (waitpid(-1, NULL, 0) == -1)
> +			tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
> +	}
> +}
> +
> +void setup(void)
> +{
> +	hugepage_size = read_meminfo("Hugepagesize:") * KB;
> +	unaligned_size = hugepage_size * 4 - 1;
> +	page_size = SAFE_SYSCONF(NULL, _SC_PAGESIZE);
> +
> +	tst_sig(FORK, DEF_HANDLER, cleanup);
> +	TEST_PAUSE;
> +}
> +
> +void cleanup(void)
> +{
> +	TEST_CLEANUP;
> +}
>


------------------------------------------------------------------------------
The Windows 8 Center - In partnership with Sourceforge
Your idea - your app - 30 days.
Get started!
http://windows8center.sourceforge.net/
what-html-developers-need-to-know-about-coding-windows-8-metro-style-apps/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  reply	other threads:[~2012-10-29 10:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-29  9:29 [LTP] [PATCH] thp/thp03: new testcase cxie
2012-10-29 10:28 ` Caspar Zhang [this message]
2012-10-29 13:57 ` chrubis

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=508E5A47.9070904@casparzhang.com \
    --to=caspar@casparzhang.com \
    --cc=ltp-list@lists.sourceforge.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.