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=-5.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 F2BA5C433E0 for ; Tue, 12 Jan 2021 19:02:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 209FD230F9 for ; Tue, 12 Jan 2021 19:02:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 209FD230F9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A1BA96B00A7; Tue, 12 Jan 2021 14:02:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D2FD6B00A8; Tue, 12 Jan 2021 14:02:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8921F6B00A9; Tue, 12 Jan 2021 14:02:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0204.hostedemail.com [216.40.44.204]) by kanga.kvack.org (Postfix) with ESMTP id 745F96B00A7 for ; Tue, 12 Jan 2021 14:02:40 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 34206180AD81F for ; Tue, 12 Jan 2021 19:02:40 +0000 (UTC) X-FDA: 77698044480.18.pest54_5e00d4627517 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 0D8EB100ED585 for ; Tue, 12 Jan 2021 19:02:38 +0000 (UTC) X-HE-Tag: pest54_5e00d4627517 X-Filterd-Recvd-Size: 7644 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 Jan 2021 19:02:37 +0000 (UTC) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 10CIsxP1031755; Tue, 12 Jan 2021 14:02:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=Wgt5iAjT3dQ4/lFwAY3eQTk2ZLrzz5N5osAZFQK7Pjw=; b=kGmmErgax4hA67K4zsa69ctfyq0zFFmqR14DN8lJhmddYev3bFDJ9VdZQPqv3HtqfDj2 Ogp1DcwqJa8M+VI+RG6Ke83+/BLXglzlgqSPhO1qgU5MlyVlE293EVJD/dbhyn0k+9vk X/5Bb77VuLnKHsTE0NVMjOY0v77LcmvbQ2HQHL1Hwds8BT5RCXdENpnaXpZjg40H9p4q s3s7MsiOx53OWX/suzh0YmvjUAG4RwaSp9aKqKWfrjqnAJIi/uWqoYTmtZoKngFbdQxk OzUypc0eb7yUPcEMZkVLJ6n8Jpp4oMwjPAGSyzTa9Sormi1jCopNWvXiG3CfTICABGw9 /Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 361hfg06nv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 12 Jan 2021 14:02:30 -0500 Received: from m0098414.ppops.net (m0098414.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 10CItVKr033448; Tue, 12 Jan 2021 14:02:29 -0500 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 361hfg06mp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 12 Jan 2021 14:02:29 -0500 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 10CJ2N03003589; Tue, 12 Jan 2021 19:02:27 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma04ams.nl.ibm.com with ESMTP id 35y448c20c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 12 Jan 2021 19:02:27 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 10CJ2K0T31850854 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Jan 2021 19:02:20 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3197552050; Tue, 12 Jan 2021 19:02:25 +0000 (GMT) Received: from pomme.local (unknown [9.145.179.152]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 903B852059; Tue, 12 Jan 2021 19:02:24 +0000 (GMT) Subject: Re: [PATCH] mm/userfaultfd: fix memory corruption due to writeprotect To: Peter Zijlstra Cc: Vinayak Menon , Linus Torvalds , Andy Lutomirski , Peter Xu , Nadav Amit , Yu Zhao , Andrea Arcangeli , linux-mm , lkml , Pavel Emelyanov , Mike Kravetz , Mike Rapoport , stable , Minchan Kim , Will Deacon , surenb@google.com References: <1FCC8F93-FF29-44D3-A73A-DF943D056680@gmail.com> <20201221223041.GL6640@xz-x1> <20210105153727.GK3040@hirez.programming.kicks-ass.net> <0201238b-e716-2a3c-e9ea-d5294ff77525@linux.vnet.ibm.com> From: Laurent Dufour Message-ID: Date: Tue, 12 Jan 2021 20:02:24 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343,18.0.737 definitions=2021-01-12_15:2021-01-12,2021-01-12 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 priorityscore=1501 mlxlogscore=978 bulkscore=0 impostorscore=0 adultscore=0 malwarescore=0 spamscore=0 lowpriorityscore=0 clxscore=1015 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101120108 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: Le 12/01/2021 =C3=A0 17:57, Peter Zijlstra a =C3=A9crit=C2=A0: > On Tue, Jan 12, 2021 at 04:47:17PM +0100, Laurent Dufour wrote: >> Le 12/01/2021 =C3=A0 12:43, Vinayak Menon a =C3=A9crit=C2=A0: >=20 >>> Possibility of race against other PTE modifiers >>> >>> 1) Fork - We have seen a case of SPF racing with fork marking PTEs RO= and that >>> is described and fixed here https://lore.kernel.org/patchwork/patch/1= 062672/ >=20 > Right, that's exactly the kind of thing I was worried about. >=20 >>> 2) mprotect - change_protection in mprotect which does the deferred f= lush is >>> marked under vm_write_begin/vm_write_end, thus SPF bails out on fault= s >>> on those VMAs. >=20 > Sure, mprotect also changes vm_flags, so it really needs that anyway. >=20 >>> 3) userfaultfd - mwriteprotect_range is not protected unlike in (2) a= bove. >>> But SPF does not take UFFD faults. >>> 4) hugetlb - hugetlb_change_protection - called from mprotect and cov= ered by >>> (2) above. >=20 >>> 5) Concurrent faults - SPF does not handle all faults. Only anon page= faults. >=20 > What happened to shared/file-backed stuff? ISTR I had that working. File-backed mappings are not processed in a speculative way, there were o= ptions=20 to manage some of them depending on the underlying file system but that's= still=20 not done. Shared anonymous mapping, are also not yet handled in a speculative way (= vm_ops=20 is not null). >>> Of which do_anonymous_page and do_swap_page are NONE/NON-PRESENT->PRE= SENT >>> transitions without tlb flush. And I hope do_wp_page with RO->RW is f= ine as well. >=20 > The tricky one is demotion, specifically write to non-write. >=20 >>> I could not see a case where speculative path cannot see a PTE update= done via >>> a fault on another CPU. >=20 > One you didn't mention is the NUMA balancing scanning crud; although I > think that's fine, loosing a PTE update there is harmless. But I've not > thought overly hard on it. That's a good point, I need to double check on that side. >> You explained it fine. Indeed SPF is handling deferred TLB invalidatio= n by >> marking the VMA through vm_write_begin/end(), as for the fork case you >> mentioned. Once the PTL is held, and the VMA's seqcount is checked, th= e PTE >> values read are valid. >=20 > That should indeed work, but are we really sure we covered them all? > Should we invest in better TLBI APIs to make sure we can't get this > wrong? That may be a good option to identify deferred TLB invalidation but I've = no clue=20 on what this API would look like.