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 X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BF42C43331 for ; Thu, 7 Nov 2019 19:54:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1112A21D79 for ; Thu, 7 Nov 2019 19:54:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b="xJlo1DuP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1112A21D79 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=joelfernandes.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5A43B6B0006; Thu, 7 Nov 2019 14:54:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5551B6B0008; Thu, 7 Nov 2019 14:54:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3CD636B000A; Thu, 7 Nov 2019 14:54:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0157.hostedemail.com [216.40.44.157]) by kanga.kvack.org (Postfix) with ESMTP id 14B616B0006 for ; Thu, 7 Nov 2019 14:54:06 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id A8DCA181AEF1E for ; Thu, 7 Nov 2019 19:54:05 +0000 (UTC) X-FDA: 76130532450.15.women96_40cabd1e84f63 X-HE-Tag: women96_40cabd1e84f63 X-Filterd-Recvd-Size: 4624 Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Thu, 7 Nov 2019 19:54:05 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id 15so2664778pgt.7 for ; Thu, 07 Nov 2019 11:54:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Yt65JEzI8B4ThC22+VCw7CM+LK+ArEMO8/zLSXCHvk0=; b=xJlo1DuPB3YVBQAgFBR+GjVfwFtDBuQ75nv+sOnYtZPQ9qSXZxB8HraZUGDFxy1Drz f71wLXCjXxGHlCCs4z60NYnl14ny5cszdYwgmbJgZFxncgjtZ1MXyr1R/0NkJ+bOhIbG 3pRidFtRgR2sgu8rJHSs23dG8WMz3UGcczVaM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Yt65JEzI8B4ThC22+VCw7CM+LK+ArEMO8/zLSXCHvk0=; b=F6QXOnLsQeUOaVMPlTfV7loI69qohrEWELgxklx+dczYNrF3GdSMMT4KiY0f3Aymvj Z45EVOdBpA9VsLF9k5av0CbWI0lNpGGSnISgSENdAvzRr/vHX0catiefy4EygInx0ZX1 RUNBAyU1NafD6E57G/97dg8kJaNf1J7kaHvAGwAGzvtcH7Makp7L3LlhnLRR7TiyxU2E x0jwSW7FL0IYxaHp0HtwHQRtBg+z0iJpdB3NOw6edVHQjWoGxh/2a75bysN0gbAZv1Cp pzoZpv/PDlSBlQhJyyB1RPiQdwBkR4PanOBMPsu412pD+WY0Qie+P/LX+kw27mvWK6o6 IkFA== X-Gm-Message-State: APjAAAVsoW8oepp+1P+qVcKo0krcQ8kxrEaPOCIAx17ERH0UJVO8GsR+ d/WErPczryDRe0FcqEhTJR14Lw== X-Google-Smtp-Source: APXvYqyoeYqV+vMTE2cL67Ov6JWJRzPg3lrGLBosK857p3VGFNE53iEGD9JcdWLwOQIALLrrUutrDg== X-Received: by 2002:a63:d70f:: with SMTP id d15mr6903311pgg.424.1573156444237; Thu, 07 Nov 2019 11:54:04 -0800 (PST) Received: from joelaf.cam.corp.google.com ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id y2sm3365870pfe.126.2019.11.07.11.54.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 11:54:03 -0800 (PST) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: "Joel Fernandes (Google)" , Andrew Morton , Hugh Dickins , kernel-team@android.com, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Shuah Khan Subject: [PATCH 2/2] memfd: Add test for COW on MAP_PRIVATE and F_SEAL_FUTURE_WRITE mappings Date: Thu, 7 Nov 2019 14:53:55 -0500 Message-Id: <20191107195355.80608-2-joel@joelfernandes.org> X-Mailer: git-send-email 2.24.0.rc1.363.gb1bccd3e3d-goog In-Reply-To: <20191107195355.80608-1-joel@joelfernandes.org> References: <20191107195355.80608-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: In this test, the parent and child both have writable private mappings. The test shows that without the patch in this series, the parent and child shared the same memory which is incorrect. In other words, COW needs to be triggered so any writes to child's copy stays local to the child. Signed-off-by: Joel Fernandes (Google) --- tools/testing/selftests/memfd/memfd_test.c | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/s= elftests/memfd/memfd_test.c index c67d32eeb668..334a7eea2004 100644 --- a/tools/testing/selftests/memfd/memfd_test.c +++ b/tools/testing/selftests/memfd/memfd_test.c @@ -290,6 +290,40 @@ static void mfd_assert_read_shared(int fd) munmap(p, mfd_def_size); } =20 +static void mfd_assert_fork_private_write(int fd) +{ + int *p; + pid_t pid; + + p =3D mmap(NULL, + mfd_def_size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE, + fd, + 0); + if (p =3D=3D MAP_FAILED) { + printf("mmap() failed: %m\n"); + abort(); + } + + p[0] =3D 22; + + pid =3D fork(); + if (pid =3D=3D 0) { + p[0] =3D 33; + exit(0); + } else { + waitpid(pid, NULL, 0); + + if (p[0] !=3D 22) { + printf("MAP_PRIVATE copy-on-write failed: %m\n"); + abort(); + } + } + + munmap(p, mfd_def_size); +} + static void mfd_assert_write(int fd) { ssize_t l; @@ -760,6 +794,8 @@ static void test_seal_future_write(void) mfd_assert_read_shared(fd2); mfd_fail_write(fd2); =20 + mfd_assert_fork_private_write(fd); + munmap(p, mfd_def_size); close(fd2); close(fd); --=20 2.24.0.rc1.363.gb1bccd3e3d-goog