From patchwork Wed Dec 11 05:33:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jeff Xu X-Patchwork-Id: 13902941 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 A8C14E77182 for ; Wed, 11 Dec 2024 05:33:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A4908D0015; Wed, 11 Dec 2024 00:33:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 154CD8D0013; Wed, 11 Dec 2024 00:33:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F36DD8D0015; Wed, 11 Dec 2024 00:33:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D6CC18D0013 for ; Wed, 11 Dec 2024 00:33:16 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 3CF76A0250 for ; Wed, 11 Dec 2024 05:33:16 +0000 (UTC) X-FDA: 82881559782.14.A8B5FF4 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by imf05.hostedemail.com (Postfix) with ESMTP id 16557100009 for ; Wed, 11 Dec 2024 05:32:30 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=KAvsbX2k; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf05.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.216.51 as permitted sender) smtp.mailfrom=jeffxu@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733895183; a=rsa-sha256; cv=none; b=bABAj1yEcGph0YZf19ycx7cC6ryvvSdJm4mjRH9Ipq8/K3E0IHdSwdO35G4Ub0y8ZdIISe KIojDJfSIPY2vBCk2URS1gSj2JJmwrRydNeMaxu3gratRfcznSQ9Bxw6lhLH+qXl4Dd6NN +SfLdKJMSbcXWfnkF9cPTQ0YKp58e7w= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=KAvsbX2k; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf05.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.216.51 as permitted sender) smtp.mailfrom=jeffxu@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733895183; 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: references:dkim-signature; bh=TcPnvSnitIZYgE4SSPh1sjaLPoyZLCmck1DlGFSmRwU=; b=6wpX2/RnPjMp1KPkKXLiJfV4URFMzm8nHWnvA7c0EecE1M/gb70NdkmbNTp64wOnBeNjQ/ Ft73QH2YziH4vrMiWk4qVC3NSK3Id+9yRBdq2kKqpvurraVNbF3Ut8HB0+nnf5IkoDbUs+ HKez7X5KoWE8x+XI+nR4j0+u+HflIXg= Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2ee6d0a57acso719203a91.1 for ; Tue, 10 Dec 2024 21:33:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733895193; x=1734499993; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TcPnvSnitIZYgE4SSPh1sjaLPoyZLCmck1DlGFSmRwU=; b=KAvsbX2kLjsdJ0oFlgkNukpU0qwMoYskHxyOUtg00B57WgZNP9433KWcU7jtofdNKM THN1i9uIMrX/o/Gmstd1z1uCAdvV4u1KJtNAbHpbwCWAkd4S7ev9UCt0PJ7W8nvEuoFG bCvhw1LJUUcMsFD+68fZ3I3/rYUaw+8MpcAQk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733895193; x=1734499993; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TcPnvSnitIZYgE4SSPh1sjaLPoyZLCmck1DlGFSmRwU=; b=bxOVa0APJH62v2EYLChHTX38Vhm7DBaV0OrTdxIuMCpMsehSvcSD++wF7Anr5y9n6E PNjS02FdGg3kxk7odFm3gEiBgxUeenJ9iaSwyG8SoUmZ3qHlfJWjzCgquIauHE/rQnbg FPtZTKOgdYrGekRfdxNappg5sZzYAwwgNXRaMa4JPsrsGAR/He6eaSXSuWZC9wB7b7ql 4GYFLtwOQwFb3Y19rF5HyUvv+d8A6IrpxN6qiz4m62RR5x+r2FnkYseAFLeL2Tnpw/P6 Uk1zBEeJxsyKm/LATCpG/SQUO0aJRK+BjZLk60ggd9Tc2ZsEoIY8XpsccwMXLENYM3Os uXeA== X-Forwarded-Encrypted: i=1; AJvYcCWVM+GuvgZk8uYpTdl6d9j+tH/FH0k9mcV03+avBLENPypO8I/0zFG/THDo0vMasqx4qWn5YVGYrA==@kvack.org X-Gm-Message-State: AOJu0YxxA7zAznq+XKtZDa7/WFoTcYeUPwYec+yHkCXErKObRMOlZGhT A+ipsV8ZmgPkj5oaGZr35VFejgwLJbv0qW3oum8D6M356yGXai1Az8jOgMl4Jg== X-Gm-Gg: ASbGncv/nAAZelG4sHsuhi/KFtoD/BJ21Mt8mTOrOy/1SpualnnBtFGOlycMa7AKCVd Sdcp2Ov9go/6YkiGIkAYKwBwYRc3vdyLoMheP++5kybJ1FfUXC74CNEK0TIioM5lNQ0OrnLMxGO Xb1r+bIJk1Ht0pbjUEVKnqCPnTs0QNAdX9/vPKGZ5UQ16F7J70mThlezpPkW1AySACZEBzVrp9v 1vkjirTcppTXaMyJzqSikGQwTteXyFsRHyNGnWvYWgVw8hmouHiuGe/cmtbdtXtR5uAjbwuuyzk MSGc2priSl59/PI= X-Google-Smtp-Source: AGHT+IFhn0Xr1EvCCo7gWlc9e87/kYfh8vrGg7FJA2vVTx9fVRgwJXmWhxS6Xfg8pWi6I36Ea52j1A== X-Received: by 2002:a17:90b:33cd:b0:2ee:6db1:21dc with SMTP id 98e67ed59e1d1-2f127f8dec6mr980737a91.1.1733895192980; Tue, 10 Dec 2024 21:33:12 -0800 (PST) Received: from localhost (238.76.127.34.bc.googleusercontent.com. [34.127.76.238]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2ef4600d109sm10721682a91.44.2024.12.10.21.33.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 10 Dec 2024 21:33:12 -0800 (PST) From: jeffxu@chromium.org To: akpm@linux-foundation.org, vbabka@suse.cz, lorenzo.stoakes@oracle.com, Liam.Howlett@Oracle.com, broonie@kernel.org, skhan@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, jorgelo@chromium.org, keescook@chromium.org, pedro.falcato@gmail.com, rdunlap@infradead.org, jannh@google.com, Jeff Xu Subject: [RFC PATCH v1 0/1] refactor mseal_test Date: Wed, 11 Dec 2024 05:33:10 +0000 Message-ID: <20241211053311.245636-1-jeffxu@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 16557100009 X-Stat-Signature: abqewmeoj4kqoycwyx1qgdk98ms1kpj8 X-HE-Tag: 1733895150-637426 X-HE-Meta: U2FsdGVkX19+p194gs58M7+vQ4F7cNQVIP8WWzmONwnNFwElmnmZ/jX7JUd3JfiPML3MR4KAx75POI+8L19jut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lJx05JRiHyTEz6tZpVbZElBmVzhQRSeo0wdwRyY3KRUivVii3DropoK2BtKEE2mwl9dpLGiHzOHogJ/Qo+rsgu0Z7LWmsxfmKfutKLgpqQ+4810aodXKg1UHAzLVBDZTBlWjCnQS/qrqrALxO+wp8zc0X+I32Ui14XpUhiMi7qneAgGTaL5pk7VPl9RHteOCUGwg7++yncxtKUOYpSN49fVGohdtefepAVV1GjHXwCOAi/ygc0ZCwpB12vp6cTwCU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.306920, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Jeff Xu This change creates the initial version of memorysealing.c. The introduction of memorysealing.c, which replaces mseal_test.c and uses the kselftest_harness, aims to initiate a discussion on using the selftest harness for memory sealing tests. Upon approval of this approach, the migration of tests from mseal_test.c to memorysealing.c can be implemented in a step-by-step manner. This tests addresses following feedbacks from previous reviews: 1> Use kselftest_harness instead of custom macro, such as EXPECT_XX, ASSERT_XX, etc. (Lorenzo Stoakes, Mark Brown, etc) [1] 2> Use MAP_FAILED to check the return of mmap (Lorenzo Stoakes). 3> Adding a check for vma size and prot bits. The discussion for this can be found in [2] [3], here is a brief summary: This is to follow up on Pedro’s in-loop change (from can_modify_mm to can_modify_vma). When mseal_test is initially created, they have a common pattern: setup memory layout, seal the memory, perform a few mm-api steps, verify return code (not zero). Because of the nature of out-of-loop, it is sufficient to just verify the error code in a few cases. With Pedro's in-loop change, the sealing check happens later in the stack, thus there are more things and scenarios to verify. And there were feedbacks to me that mseal_test should be extensive enough to discover all regressions. Hence I'm adding check for vma size and prot bits. In this change: we created two fixtures: Fixture basic: This creates a single VMA, the VMA has a PROT_NONE page at each end to prevent auto-merging. Fixture wo_vma: Two VMAs back to end, a PROT_NONE page at each end to prevent auto-merging. In addition, I add one test (mprotec) in each fixture for discussion. [1] https://lore.kernel.org/all/20240830180237.1220027-5-jeffxu@chromium.org/ [2] https://lore.kernel.org/all/CABi2SkUgDZtJtRJe+J9UNdtZn=EQzZcbMB685P=1rR7DUhg=6Q@mail.gmail.com/ [3] https://lore.kernel.org/all/2qywbjb5ebtgwkh354w3lj3vhaothvubjokxq5fhyri5jeeton@duqngzo3swjz/ Jeff Xu (1): selftest/mm: refactor mseal_test tools/testing/selftests/mm/.gitignore | 1 + tools/testing/selftests/mm/Makefile | 1 + tools/testing/selftests/mm/memorysealing.c | 182 +++++++++++++++++++++ tools/testing/selftests/mm/memorysealing.h | 116 +++++++++++++ tools/testing/selftests/mm/mseal_test.c | 67 +------- 5 files changed, 301 insertions(+), 66 deletions(-) create mode 100644 tools/testing/selftests/mm/memorysealing.c create mode 100644 tools/testing/selftests/mm/memorysealing.h