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=-0.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 14BF3C35242 for ; Tue, 11 Feb 2020 22:01:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BEC4E20714 for ; Tue, 11 Feb 2020 22:01:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="X+HdT8yK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BEC4E20714 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3B4186B00C5; Tue, 11 Feb 2020 17:01:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 363E36B02E4; Tue, 11 Feb 2020 17:01:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 252AF6B0303; Tue, 11 Feb 2020 17:01:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0079.hostedemail.com [216.40.44.79]) by kanga.kvack.org (Postfix) with ESMTP id 0E2596B00C5 for ; Tue, 11 Feb 2020 17:01:50 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B20E92477 for ; Tue, 11 Feb 2020 22:01:49 +0000 (UTC) X-FDA: 76479219138.01.swing31_4a13bedff744e X-HE-Tag: swing31_4a13bedff744e X-Filterd-Recvd-Size: 8164 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Tue, 11 Feb 2020 22:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581458508; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=rWHxGWyzztYU6CFozWluCA4h1l/yjlaH2wwc8npged8=; b=X+HdT8yKcp26gJSaOYKSWvtYqhSvDcReC/9tp+6jnCCyzCXEP30QsZ0xF/TqJ3PbeuPdxp B/nr69Uk8eXg5QJ4OM9Gug5d7hIUv8lD1/ZmkVAIE9rOsj58YF6tEgJDs8SgAZo2uR/MpD HvpTy7lL4T/yo5PPcvYaEmST2qRtHy0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-416-zbjpJmJjM_mzqCyXoFQ8FQ-1; Tue, 11 Feb 2020 17:01:43 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D29961084436; Tue, 11 Feb 2020 22:01:41 +0000 (UTC) Received: from segfault.boston.devel.redhat.com (segfault.boston.devel.redhat.com [10.19.60.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 01D0527062; Tue, 11 Feb 2020 22:01:40 +0000 (UTC) From: Jeff Moyer To: "Kirill A. Shutemov" Cc: Justin He , Catalin Marinas , "Kirill A.Shutemov" , "linux-mm\@kvack.org" Subject: Re: bug: data corruption introduced by commit 83d116c53058 ("mm: fix double page fault on arm64 if PTE_AF is cleared") References: <20200211173352.wjm6govzcqy355y7@box> <20200211214439.v6bowbkyienrwtdd@box> X-PGP-KeyID: 1F78E1B4 X-PGP-CertKey: F6FE 280D 8293 F72C 65FD 5A58 1FF8 A7CA 1F78 E1B4 Date: Tue, 11 Feb 2020 17:01:40 -0500 In-Reply-To: <20200211214439.v6bowbkyienrwtdd@box> (Kirill A. Shutemov's message of "Wed, 12 Feb 2020 00:44:39 +0300") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: zbjpJmJjM_mzqCyXoFQ8FQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="=-=-=" 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: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable "Kirill A. Shutemov" writes: > On Tue, Feb 11, 2020 at 12:55:50PM -0500, Jeff Moyer wrote: >> "Kirill A. Shutemov" writes: >>=20 >> > On Tue, Feb 11, 2020 at 11:44:06AM -0500, Jeff Moyer wrote: >> >> Hi, Justin, >> >>=20 >> >> Justin He writes: >> >> >> Thanks for the report. But this commit 83d116c53058 doesn't add th= e >> >> >> new clear_page code path. Besides the pte_mkyoung part, It just re= fines >> >> >> the codes(no functional change) and add a WARN_ON_ONCE to indicate >> >> >> there is any obscure case before. >> >> > >> >> > I can't reproduce it with your provided test file on my arm64 qemu = with >> >> > a pmem device. >> >> > Could you do me a favor that just revert 83d116c53058 but keep that >> >> > WARN_ON_ONCE after clear_page()? Is there any difference? >> >> > Thanks for your help >> >>=20 >> >> Below is the patch I used to put the WARN_ON_ONCE after the clear_pag= e, >> >> just to be sure that's what you intended. So with 83d116c53058 >> >> reverted, and the below patch applied, the WARN_ON_ONCE does not >> >> trigger. >> > >> > I cannot explain this. There is no locking to prevent the same scenari= o >> > before. It might be an timing difference. >> > >> > Could try to put a delay before the copy to make race window larger? >>=20 >> I reverted my change to the reproducer, and now it triggers the warning. > > I'm not sure I follow. > > My understanding is that you failed to reproduce the issue with > 83d116c53058 reverted and WARN_ON_ONCE() placed. I failed to reproduce the issue with the test code I provided in this email thread. However, if I simply use the original t_mmap_cow_race from xfstests, I can trigger the WARN_ON_ONCE. There is no need to insert a delay in the kernel. Does that make sense? > My ask was to try to put some mdelay() just before > __copy_from_user_inatomic(). The mdelay() may help with reproducing the > issue on the old code. > > If the bug still fails to reproduce I may misunderstand the source of the > bug and need to look further. I understand your request. Inserting a udelay(10) with the code I provided does not trigger the warning. However, see above. I'm including the unmodified t_mmap_cow_race.c code here for your convenience. This is the code that triggers the warning with 83d116c53058 reverted, and the WARN_ON_ONCE added. Let me know if I'm stilling confusing you. :) Cheers, Jeff --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=t_mmap_cow_race.c Content-Transfer-Encoding: quoted-printable // SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2017 Intel Corporation. */ #include #include #include #include #include #include #include #include #include #include #include #define MiB(a) ((a)*1024*1024) #define NUM_THREADS 2 void err_exit(char *op) { =09fprintf(stderr, "%s: %s\n", op, strerror(errno)); =09exit(1); } void worker_fn(void *ptr) { =09char *data =3D (char *)ptr; =09volatile int a; =09int i, err; =09for (i =3D 0; i < 10; i++) { =09=09a =3D data[0]; =09=09data[0] =3D a; =09=09err =3D madvise(data, MiB(2), MADV_DONTNEED); =09=09if (err < 0) =09=09=09err_exit("madvise"); =09=09/* Mix up the thread timings to encourage the race. */ =09=09err =3D usleep(rand() % 100); =09=09if (err < 0) =09=09=09err_exit("usleep"); =09} } int main(int argc, char *argv[]) { =09pthread_t thread[NUM_THREADS]; =09int i, j, fd, err; =09char *data; =09if (argc < 2) { =09=09printf("Usage: %s \n", basename(argv[0])); =09=09exit(0); =09} =09fd =3D open(argv[1], O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); =09if (fd < 0) =09=09err_exit("fd"); =09/* This allows us to map a huge page. */ =09ftruncate(fd, 0); =09ftruncate(fd, MiB(2)); =09/* =09 * First we set up a shared mapping. Our write will (hopefully) get =09 * the filesystem to give us a 2MiB huge page DAX mapping. We will =09 * then use this 2MiB page for our private mapping race. =09 */ =09data =3D mmap(NULL, MiB(2), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); =09if (data =3D=3D MAP_FAILED) =09=09err_exit("shared mmap"); =09data[0] =3D 1; =09err =3D munmap(data, MiB(2)); =09if (err < 0) =09=09err_exit("shared munmap"); =09for (i =3D 0; i < 500; i++) { =09=09data =3D mmap(NULL, MiB(2), PROT_READ|PROT_WRITE, MAP_PRIVATE, =09=09=09=09fd, 0); =09=09if (data =3D=3D MAP_FAILED) =09=09=09err_exit("private mmap"); =09=09for (j =3D 0; j < NUM_THREADS; j++) { =09=09=09err =3D pthread_create(&thread[j], NULL, =09=09=09=09=09(void*)&worker_fn, data); =09=09=09if (err) =09=09=09=09err_exit("pthread_create"); =09=09} =09=09for (j =3D 0; j < NUM_THREADS; j++) { =09=09=09err =3D pthread_join(thread[j], NULL); =09=09=09if (err) =09=09=09=09err_exit("pthread_join"); =09=09} =09=09err =3D munmap(data, MiB(2)); =09=09if (err < 0) =09=09=09err_exit("private munmap"); =09} =09err =3D close(fd); =09if (err < 0) =09=09err_exit("close"); =09return 0; } --=-=-=--