From patchwork Mon Aug 28 15:08:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florent Revest X-Patchwork-Id: 137081 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a7d1:0:b0:3f2:4152:657d with SMTP id p17csp3559114vqm; Mon, 28 Aug 2023 13:17:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHxXiJFbKJOTs+6+Ca3WaxwlSCn2KHSEU0Ykw3vMQLPQV67L9/GUMUjRVanZbnoVY2V0rrP X-Received: by 2002:ac2:4c0f:0:b0:500:ac0b:8d51 with SMTP id t15-20020ac24c0f000000b00500ac0b8d51mr5567556lfq.37.1693253850912; Mon, 28 Aug 2023 13:17:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693253850; cv=none; d=google.com; s=arc-20160816; b=gBLFbPR/J0O/7jXrXsrMol1w51gACNCMRJk9CfcPtPulK/1P0thbKPGSU5iuNqLPG5 n808gYsY+D2awbSLXKvEscU3EeGl2QKaHuTIiCzPngNCCpd+pfE/rdwJPNnSr+FqNsii wlb9C2QBkmeOMg1ioVpFfd2DvLiCWqqckx8M0a3ZkbL7hHXmfISAW0hNpOPkc6pnbpmA GlZhe751fTiXJlkjH/G8gADTZmDpPCJtxJwUryXtmxO8oEu9fzW3qteVaR1Xc1icnSRX jcRyYjSDWa+LFs9mCUGbSu4w+Acq9yBsorX1RmDabAm/sYz/amy8uiP1fs25xv4EOH/r 1RJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dSsehURxisS0cPQOlmw5cEhdkgRF5G0B9O4abug5R1Y=; fh=FNhLt3yXSHM8qH/GYLB+h9UJ6xcEIJOGX4lYhkkTLjY=; b=DeA9V/tlbJ7YU+kPeysqQzjeUW0YoeRghpgQli6eG5pjayyxpieOndH8e4YvHmSiun 8YNwoWCn/atn2jq4ATldT1s+5lae2IGQu8oj0aqHY8PkyCe2P9DVw06gPSJcI5XeJeBG 5uXUV1rAQPxW7DGQA2CQHQxPpyEkpJtaNq1Za59Qyl3CeSt7JXUMCSs2Z1H7q0qgu8I6 hmpOgP/MCkKQLR+YcO+y2c7knoHxigyesA9No77+gAqH9xt7GyqcB3F4/U7gNOWSBtC2 6g1FfJmZfYzQsuz8zGaBtBlv4O02e48E4bnnPVDA2QBZjn1m1V/6Lu6i6N/HLuS6MNmL EUmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="KcBVK2L/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rh26-20020a17090720fa00b0099381745ba0si4935073ejb.156.2023.08.28.13.16.56; Mon, 28 Aug 2023 13:17:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="KcBVK2L/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232340AbjH1PJi (ORCPT + 90 others); Mon, 28 Aug 2023 11:09:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232358AbjH1PJO (ORCPT ); Mon, 28 Aug 2023 11:09:14 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FB47129 for ; Mon, 28 Aug 2023 08:09:10 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-31c3726cc45so2867214f8f.0 for ; Mon, 28 Aug 2023 08:09:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1693235348; x=1693840148; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dSsehURxisS0cPQOlmw5cEhdkgRF5G0B9O4abug5R1Y=; b=KcBVK2L/+QiqeWFTYXdOHgeUKp7DE3X4tkqvOHvJL3c9l2s8PVNUDW7Vbov+Z+q4gQ mcZKACunCQ1/A/aDTljARoKg3f6xbibrlG6bzvrYRt2IfOW/RY1hCJt/5Bjtk9lSUGNn 58lL0yysgJLrF2YisIvCE3BrZVByNt8ljS8SY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693235348; x=1693840148; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dSsehURxisS0cPQOlmw5cEhdkgRF5G0B9O4abug5R1Y=; b=SJAlCCpFKIOVBfqDj9LbJkYLWbkXsX00loWYkE5qZNKpDXDyq+kvxaMdB+Ss3MqqoU vZgbX+n3eUd7A8p2ilabwUYrUVc72mTopi3PhbJA4hmCOUbM+YTQCrf024eYLYA/gcRP PDyDEteZ+y5MzVCgGpIIDjOAVEuG9HE9jbRVDmI8cSUUutPE+hhRiThFdttOOWu07FXa UiAdNsb2wTIPWZshYQ+3iHAIyFf8jnj1uCoj7o1vgpGvWxjq/t2UIr3LcuFY5dRFG3pF 0gwaUG+zazwnQ/61zfeyF2wb3NBPAPU1d/AlA/eeZbttEGnPiWKQfvUCswIdBh3Y02jK BFYw== X-Gm-Message-State: AOJu0YyXDYrv+1P0ngqn9IveTZliqwXY4q5FWZVm9L5HdN8YMTIbRiSE 0MDl4kMzikaTxKFhAdVNb0lUqpK/OTZNdQxHBcw= X-Received: by 2002:a5d:574f:0:b0:317:5ece:e16a with SMTP id q15-20020a5d574f000000b003175ecee16amr18928693wrw.50.1693235348569; Mon, 28 Aug 2023 08:09:08 -0700 (PDT) Received: from revest.zrh.corp.google.com ([2a00:79e0:9d:6:40c6:6cff:63b:c70a]) by smtp.gmail.com with ESMTPSA id v3-20020a5d43c3000000b003140fff4f75sm10730522wrr.17.2023.08.28.08.09.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Aug 2023 08:09:07 -0700 (PDT) From: Florent Revest To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: akpm@linux-foundation.org, catalin.marinas@arm.com, anshuman.khandual@arm.com, joey.gouly@arm.com, mhocko@suse.com, keescook@chromium.org, david@redhat.com, peterx@redhat.com, izbyshev@ispras.ru, broonie@kernel.org, szabolcs.nagy@arm.com, kpsingh@kernel.org, gthelen@google.com, toiwoton@gmail.com, ayush.jain3@amd.com, Florent Revest , Ryan Roberts Subject: [PATCH v4 2/6] kselftest: vm: Fix mdwe's mmap_FIXED test case Date: Mon, 28 Aug 2023 17:08:54 +0200 Message-ID: <20230828150858.393570-3-revest@chromium.org> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog In-Reply-To: <20230828150858.393570-1-revest@chromium.org> References: <20230828150858.393570-1-revest@chromium.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775505349846400814 X-GMAIL-MSGID: 1775505349846400814 I checked with the original author, the mmap_FIXED test case wasn't properly tested and fails. Currently, it maps two consecutive (non overlapping) pages and expects the second mapping to be denied by MDWE but these two pages have nothing to do with each other so MDWE is actually out of the picture here. What the test actually intended to do was to remap a virtual address using MAP_FIXED. However, this operation unmaps the existing mapping and creates a new one so the va is backed by a new page and MDWE is again out of the picture, all remappings should succeed. This patch keeps the test case to make it clear that this situation is expected to work: MDWE shouldn't block a MAP_FIXED replacement. Signed-off-by: Florent Revest Reviewed-by: David Hildenbrand Reviewed-by: Kees Cook Reviewed-by: Catalin Marinas Reviewed-by: Ryan Roberts Tested-by: Ryan Roberts Tested-by: Ayush Jain Fixes: 4cf1fe34fd18 ("kselftest: vm: add tests for memory-deny-write-execute") --- tools/testing/selftests/mm/mdwe_test.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/mm/mdwe_test.c b/tools/testing/selftests/mm/mdwe_test.c index d0954c657feb..91aa9c3099e7 100644 --- a/tools/testing/selftests/mm/mdwe_test.c +++ b/tools/testing/selftests/mm/mdwe_test.c @@ -168,13 +168,10 @@ TEST_F(mdwe, mmap_FIXED) self->p = mmap(NULL, self->size, PROT_READ, self->flags, 0, 0); ASSERT_NE(self->p, MAP_FAILED); - p = mmap(self->p + self->size, self->size, PROT_READ | PROT_EXEC, + /* MAP_FIXED unmaps the existing page before mapping which is allowed */ + p = mmap(self->p, self->size, PROT_READ | PROT_EXEC, self->flags | MAP_FIXED, 0, 0); - if (variant->enabled) { - EXPECT_EQ(p, MAP_FAILED); - } else { - EXPECT_EQ(p, self->p); - } + EXPECT_EQ(p, self->p); } TEST_F(mdwe, arm64_BTI)