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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62715C433F5 for ; Fri, 17 Dec 2021 21:21:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D384F6B007D; Fri, 17 Dec 2021 16:20:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CC10C6B007E; Fri, 17 Dec 2021 16:20:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B134A6B0080; Fri, 17 Dec 2021 16:20:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id 9C87C6B007D for ; Fri, 17 Dec 2021 16:20:50 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 5B71A8249980 for ; Fri, 17 Dec 2021 21:20:40 +0000 (UTC) X-FDA: 78928555440.27.FFD107C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 3E4EC18003E for ; Fri, 17 Dec 2021 21:20:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639776038; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8IJZxPgG4L44oWGcui35r4UlNG5572tZdi98rWwaG8g=; b=c+wxLDSkP9779337L3T4bui8rFIv9wfuvIpBVqLpzUbLRp5QzM2wRPP7WOcMAR1nmv/xH2 GSjkqpFyVzRlya+qaK81A7nSSA9GDJNqXdQTz2pOs4/8ol4kndrrPkheLSey9PNNoMxaea bNTxsNtpxDDeH6q8+jTYARvTphYM0QU= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-307-6Jp46M3SMZmJ08mu6j4zEg-1; Fri, 17 Dec 2021 16:20:32 -0500 X-MC-Unique: 6Jp46M3SMZmJ08mu6j4zEg-1 Received: by mail-wm1-f72.google.com with SMTP id o18-20020a05600c511200b00332fa17a02eso1598167wms.5 for ; Fri, 17 Dec 2021 13:20:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=8IJZxPgG4L44oWGcui35r4UlNG5572tZdi98rWwaG8g=; b=cSPSwquqWTKXgUx9VEoLHUapIELo2zDbeNZMqPs+ZKY6wUVS953s1ILUGIJCdkhpXK Xgl+t75Gor3F7xO+pt+TTtsauvwhr0Tq+CFks6k8sC+GD+EELvz5apX+Tj26W/QuxE2H QkeWGuV3OKLzj4B8XI+72gx94Go+bwVOIzfCR3Wst24Ro20bskYGQmhK8jeOV/Slibg3 4OHUA5dHc6UN2AvzRqcoDGXpxbr+7M55soSiaHByGZa6zJ9/blhZ3vVRsoUO9J2SeZe+ q3zCOiROSbGcbsNWxssl8QFKdjaHwPxDQkf9ENOedv6m0tgOsDxdR881qvv4SNDyLbhm TCzw== X-Gm-Message-State: AOAM533tooiUIXXSURIqCTRPPfvIUW2tUHtvRk1UgVVZNP9kXW3aTQQC yCOpJpDvNYIGy/Gf6U05/Cd49ad7X8Osb9cKcrPMwPF4V8qqb9WiAa623tZLXZTU1OTduZvx9gj qNGfm/pwMUsI= X-Received: by 2002:a5d:47ab:: with SMTP id 11mr3927183wrb.148.1639776031470; Fri, 17 Dec 2021 13:20:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJynyrJqHzLIVQ/5dOHLdUALTS3GVx082kmC3nUnoCPPI43f3cBoGLl7cQzviQKhtACK6Zxaeg== X-Received: by 2002:a5d:47ab:: with SMTP id 11mr3927144wrb.148.1639776031272; Fri, 17 Dec 2021 13:20:31 -0800 (PST) Received: from [192.168.3.132] (p4ff234b8.dip0.t-ipconnect.de. [79.242.52.184]) by smtp.gmail.com with ESMTPSA id b13sm8544391wrh.32.2021.12.17.13.20.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Dec 2021 13:20:30 -0800 (PST) Message-ID: <0d96835d-bcf4-1192-536c-0af314405880@redhat.com> Date: Fri, 17 Dec 2021 22:20:29 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [PATCH v1 06/11] mm: support GUP-triggered unsharing via FAULT_FLAG_UNSHARE (!hugetlb) To: Nadav Amit , Jason Gunthorpe Cc: Linus Torvalds , Linux Kernel Mailing List , Andrew Morton , Hugh Dickins , David Rientjes , Shakeel Butt , John Hubbard , Mike Kravetz , Mike Rapoport , Yang Shi , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Jann Horn , Michal Hocko , Rik van Riel , Roman Gushchin , Andrea Arcangeli , Peter Xu , Donald Dutile , Christoph Hellwig , Oleg Nesterov , Jan Kara , Linux-MM , "open list:KERNEL SELFTEST FRAMEWORK" , "open list:DOCUMENTATION" References: <20211217113049.23850-1-david@redhat.com> <20211217113049.23850-7-david@redhat.com> <54c492d7-ddcd-dcd0-7209-efb2847adf7c@redhat.com> <20211217204705.GF6385@nvidia.com> <2E28C79D-F79C-45BE-A16C-43678AD165E9@vmware.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <2E28C79D-F79C-45BE-A16C-43678AD165E9@vmware.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 3E4EC18003E X-Stat-Signature: 37sa3y89is5ruf7cn4wu1y1w9pqpyf46 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=c+wxLDSk; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf24.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com X-HE-Tag: 1639776036-926367 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: On 17.12.21 22:15, Nadav Amit wrote: > > >> On Dec 17, 2021, at 12:47 PM, Jason Gunthorpe wrote: >> >> On Fri, Dec 17, 2021 at 12:36:43PM -0800, Linus Torvalds wrote: >> >>>> 5. Take a R/O pin (RDMA, VFIO, ...) >>>> -> refcount > 1 >>>> >>>> 6. memset(mem, 0xff, pagesize); >>>> -> Write fault -> COW >>> >>> I do not believe this is actually a bug. >>> >>> You asked for a R/O pin, and you got one. >>> >>> Then somebody else modified that page, and you got exactly what you >>> asked for - a COW event. The original R/O pin has the original page >>> that it asked for, and can read it just fine. >> >> To remind all, the GUP users, like RDMA, VFIO use >> FOLL_FORCE|FOLL_WRITE to get a 'r/o pin' specifically because of the >> COW breaking the coherence. In these case 'r/o pin' does not mean >> "snapshot the data", but its only a promise not to write to the pages >> and still desires coherence with the memory map. >> >> Eg in RDMA we know of apps asking for a R/O pin of something in .bss >> then filling that something with data finally doing the actual >> DMA. Breaking COW after pin breaks those apps. >> >> The above #5 can occur for O_DIRECT read and in that case the >> 'snapshot the data' is perfectly fine as racing the COW with the >> O_DIRECT read just resolves the race toward the read() direction. >> >> IIRC there is some other scenario that motivated this patch? > > I think that there is an assumption that once a page is COW-broken, > it would never have another write-fault that might lead to COW > breaking later. > > AFAIK at least after userfaultfd-WP followed by > userfaultfd-write-unprotect a page might be write-protected and > go through do_wp_page() a second time to be COW-broken again. In > such case, I think the FOLL_FORCE|FOLL_WRITE would not help. > > I suspect (not sure) that this might even happen with mprotect() > since I do not see all code-paths preserving whether the page > was writable. > uffd-wp and mprotect() are broken as well, yes. But the easiest example is just swap + read fault. Section 2 and 3 in [1], along with reproducers. Note that I didn't mention uffd-wp and mprotect(), because these require "manual intervention". With swap, it's not your application doing something "special". [1] https://lore.kernel.org/r/3ae33b08-d9ef-f846-56fb-645e3b9b4c66@redhat.com -- Thanks, David / dhildenb