From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 242CCD17140 for ; Mon, 21 Oct 2024 21:32:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B8646B009B; Mon, 21 Oct 2024 17:32:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 867FA6B009C; Mon, 21 Oct 2024 17:32:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72FE76B009D; Mon, 21 Oct 2024 17:32:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4FA2C6B009B for ; Mon, 21 Oct 2024 17:32:05 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 009D3ACF6E for ; Mon, 21 Oct 2024 21:31:33 +0000 (UTC) X-FDA: 82698906948.10.4761FC1 Received: from mail-io1-f51.google.com (mail-io1-f51.google.com [209.85.166.51]) by imf06.hostedemail.com (Postfix) with ESMTP id 106DB18001A for ; Mon, 21 Oct 2024 21:31:51 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=google header.b="UC/GJaxV"; dmarc=pass (policy=none) header.from=linuxfoundation.org; spf=pass (imf06.hostedemail.com: domain of skhan@linuxfoundation.org designates 209.85.166.51 as permitted sender) smtp.mailfrom=skhan@linuxfoundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729546157; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=paXKAdDCbh8sHpFq/BpzuFt1t606tSHtvOs61brMXyY=; b=xmK/U8cK3n/aJDp6iRlrMurGROT3zd7R46e9h5JbB9s1OlY0GX/wm/7PKMHEkwly0RP1KU pR79am95EljM8mqHvShnccP2/W+AWcSmd0iy4z1ZqqMOx/fD+zQvAW40m6CZAg0sYQofJW 2ZDWVs8400IUxmfXxSnYrsfs8HkLM1M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729546157; a=rsa-sha256; cv=none; b=VTKa8hkKkZndeNif89Zu/Y6+j2rhW84eRdNxN2r8m0uyzrWUfaqn9foa8Bq0QMu70yvQhP KgsIvztvJmaHkWRIR3klrPKoiQzYw+y9PWBcLTTO1x2xt6CL9/OTwVq7UnwflYOA+aWSEo 83GnvkpZnDs9uiy9mkmAJO2kiR3jMsE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=google header.b="UC/GJaxV"; dmarc=pass (policy=none) header.from=linuxfoundation.org; spf=pass (imf06.hostedemail.com: domain of skhan@linuxfoundation.org designates 209.85.166.51 as permitted sender) smtp.mailfrom=skhan@linuxfoundation.org Received: by mail-io1-f51.google.com with SMTP id ca18e2360f4ac-83a9cd37a11so210803639f.3 for ; Mon, 21 Oct 2024 14:32:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1729546322; x=1730151122; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=paXKAdDCbh8sHpFq/BpzuFt1t606tSHtvOs61brMXyY=; b=UC/GJaxVQNt479h4LaXeS4SMditnMYaNqYDy3C3OglPLVrrRtVmxLHZlfzxTxE0BBv VJMryj+jVJXiu6Oxcv1zV/fZ54MOubG3V9PaRuWnavYC5Ytw8GEIB0gsT5W4BMcfKeVw 499grwQd5hvEmK2EXC5mKhfgzX0SL2HwFox3U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729546322; x=1730151122; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=paXKAdDCbh8sHpFq/BpzuFt1t606tSHtvOs61brMXyY=; b=ZjE0eC8MR3W7/kA/mjBi5ksRLXHUaSFaHneNwE6F/JwLKpdyxroU+JrpNV5PscM5rf xsErVVtHpeg+jniJwEB5miSvLievrcOq1Nzo5zN5/0DZgWJNx5dUwPsOoMKUl+YC1dNg J6Lv9LRAe0q3FRR2TZgAzVxzGU3JzbjZwwp8tGMGBf4Cdv61MmKKIVYxbvAMas0b/Jzh m6rSzEWCOt56TDxHpPocjz3cG5DTwJvAeBC2bnG1R/sBIkj17azC9UXbfSKQJwIJLgtn O3RcoamSzHBEjdAKzUeD25DdpJgPjjm4fhC0S8os0Mp0JMzXOu0GbJ9bLaosuLiXLHJZ QmAQ== X-Forwarded-Encrypted: i=1; AJvYcCVuhzFvVJhCT3cuSAr36bZnX2YaxPivwK5X7DlZn4XsgSOJmHprs6X8oFm6rpB14GbcisRzU2huJw==@kvack.org X-Gm-Message-State: AOJu0YxgxeNsBkKl+veCJP89zFVaJoCWpa/YDyhslux1OYSM2UZDXEjX J6Pyec9RdnfHlMapBnhwZsBIRVPRWnxY02CEMowr1eekjDuLq93sRoA0WShOScs= X-Google-Smtp-Source: AGHT+IGJW8jlcC/yU06sLutaC98aTYwDhazap3Qy/Nz926gm8HncTJMWnKxkTTr2+dGJYQK5IhR+qg== X-Received: by 2002:a05:6602:2dcb:b0:835:3ffe:fe31 with SMTP id ca18e2360f4ac-83aba612b82mr1526697439f.8.1729546321703; Mon, 21 Oct 2024 14:32:01 -0700 (PDT) Received: from [192.168.1.128] ([38.175.170.29]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-83ad1c4e380sm126760239f.13.2024.10.21.14.32.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Oct 2024 14:32:01 -0700 (PDT) Message-ID: <360241aa-49ec-42b1-99c9-759a9a0873a0@linuxfoundation.org> Date: Mon, 21 Oct 2024 15:31:59 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 5/5] selftests/mm: add self tests for guard page feature To: Lorenzo Stoakes , Andrew Morton Cc: Suren Baghdasaryan , "Liam R . Howlett" , Matthew Wilcox , Vlastimil Babka , "Paul E . McKenney" , Jann Horn , David Hildenbrand , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song , Richard Henderson , Ivan Kokshaysky , Matt Turner , Thomas Bogendoerfer , "James E . J . Bottomley" , Helge Deller , Chris Zankel , Max Filippov , Arnd Bergmann , linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linux-arch@vger.kernel.org, Shuah Khan , Christian Brauner , linux-kselftest@vger.kernel.org, Sidhartha Kumar , Jeff Xu , Christoph Hellwig , linux-api@vger.kernel.org, John Hubbard , Shuah Khan References: <090ed13db09bc25863a78eba902d8bf2c6534ced.1729440856.git.lorenzo.stoakes@oracle.com> Content-Language: en-US From: Shuah Khan In-Reply-To: <090ed13db09bc25863a78eba902d8bf2c6534ced.1729440856.git.lorenzo.stoakes@oracle.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 106DB18001A X-Stat-Signature: 1yidmi7xxnfq5b7h9u1hy4fer57zu1pz X-Rspam-User: X-HE-Tag: 1729546311-507419 X-HE-Meta: U2FsdGVkX1+F6a/ab+9ZwnqySnpzKLxVFQz+t93awYN/Chj61SUnUO5J93g53xxMNUm0+xHwJu5D5KNtklDcKAcjnJrfBF4Fmek0/nR7igd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xt4tvh/Z+jzhQqYNz4CQjmMuN8g7FJk0Wc6MdahAQE4PnWdsc0aWD7ttLZJVWm7m1KE5InaKD+vGCJ4+a7royCyymxrTK8Hrb6j9nUuoF7poBTLNMwJh9r4YI5BOo4dgve00vawVYLGcvSjaxGAE8s2jefx//GOrnXyJjA0rIiSUMh01qYFgjjS5YQ9RWYrUpi3/2PbY8wjJ6B38dW0KEqZWYnRRV2Rap5yuHbGGhg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 10/20/24 10:20, Lorenzo Stoakes wrote: > Utilise the kselftest harmness to implement tests for the guard page > implementation. > > We start by implement basic tests asserting that guard pages can be > established (poisoned), cleared (remedied) and that touching poisoned pages > result in SIGSEGV. We also assert that, in remedying a range, non-poison > pages remain intact. > > We then examine different operations on regions containing poison markers > behave to ensure correct behaviour: > > * Operations over multiple VMAs operate as expected. > * Invoking MADV_GUARD_POISION / MADV_GUARD_REMEDY via process_madvise() in > batches works correctly. > * Ensuring that munmap() correctly tears down poison markers. > * Using mprotect() to adjust protection bits does not in any way override > or cause issues with poison markers. > * Ensuring that splitting and merging VMAs around poison markers causes no > issue - i.e. that a marker which 'belongs' to one VMA can function just > as well 'belonging' to another. > * Ensuring that madvise(..., MADV_DONTNEED) does not remove poison markers. > * Ensuring that mlock()'ing a range containing poison markers does not > cause issues. > * Ensuring that mremap() can move a poisoned range and retain poison > markers. > * Ensuring that mremap() can expand a poisoned range and retain poison > markers (perhaps moving the range). > * Ensuring that mremap() can shrink a poisoned range and retain poison > markers. > * Ensuring that forking a process correctly retains poison markers. > * Ensuring that forking a VMA with VM_WIPEONFORK set behaves sanely. > * Ensuring that lazyfree simply clears poison markers. > * Ensuring that userfaultfd can co-exist with guard pages. > * Ensuring that madvise(..., MADV_POPULATE_READ) and > madvise(..., MADV_POPULATE_WRITE) error out when encountering > poison markers. > * Ensuring that madvise(..., MADV_COLD) and madvise(..., MADV_PAGEOUT) do > not remove poison markers. > > If any test is unable to be run due to lack of permissions, that test is > skipped. > > Signed-off-by: Lorenzo Stoakes > --- > tools/testing/selftests/mm/.gitignore | 1 + > tools/testing/selftests/mm/Makefile | 1 + > tools/testing/selftests/mm/guard-pages.c | 1228 ++++++++++++++++++++++ > 3 files changed, 1230 insertions(+) > create mode 100644 tools/testing/selftests/mm/guard-pages.c > > diff --git a/tools/testing/selftests/mm/.gitignore b/tools/testing/selftests/mm/.gitignore > index 689bbd520296..8f01f4da1c0d 100644 > --- a/tools/testing/selftests/mm/.gitignore > +++ b/tools/testing/selftests/mm/.gitignore > @@ -54,3 +54,4 @@ droppable > hugetlb_dio > pkey_sighandler_tests_32 > pkey_sighandler_tests_64 > +guard-pages > diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile > index 02e1204971b0..15c734d6cfec 100644 > --- a/tools/testing/selftests/mm/Makefile > +++ b/tools/testing/selftests/mm/Makefile > @@ -79,6 +79,7 @@ TEST_GEN_FILES += hugetlb_fault_after_madv > TEST_GEN_FILES += hugetlb_madv_vs_map > TEST_GEN_FILES += hugetlb_dio > TEST_GEN_FILES += droppable > +TEST_GEN_FILES += guard-pages > > ifneq ($(ARCH),arm64) > TEST_GEN_FILES += soft-dirty > diff --git a/tools/testing/selftests/mm/guard-pages.c b/tools/testing/selftests/mm/guard-pages.c > new file mode 100644 > index 000000000000..f67d2700d44a > --- /dev/null > +++ b/tools/testing/selftests/mm/guard-pages.c > @@ -0,0 +1,1228 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > + > +#define _GNU_SOURCE > +#include "../kselftest_harness.h" > +#include /* Force the import of the tools version. */ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +/* > + * Ignore the checkpatch warning, as per the C99 standard, section 7.14.1.1: > + * > + * "If the signal occurs other than as the result of calling the abort or raise > + * function, the behavior is undefined if the signal handler refers to any > + * object with static storage duration other than by assigning a value to an > + * object declared as volatile sig_atomic_t" > + */ > +static volatile sig_atomic_t signal_jump_set; > +static sigjmp_buf signal_jmp_buf; > + > +/* > + * Ignore the checkpatch warning, we must read from x but don't want to do > + * anything with it in order to trigger a read page fault. We therefore must use > + * volatile to stop the compiler from optimising this away. > + */ > +#define FORCE_READ(x) (*(volatile typeof(x) *)x) > + Thank you. Reviewed-by: Shuah Khan thanks, -- Shuah