Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp1358419pxb; Sat, 9 Jan 2021 17:22:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJyX1NDw8XfWV2J5ovGpT6dqYODy1DNSw2aeEoG1vJs2lVDiOzpUZbtqViC+ox2NCTyrFVlP X-Received: by 2002:aa7:d919:: with SMTP id a25mr9451878edr.81.1610241768021; Sat, 09 Jan 2021 17:22:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610241768; cv=none; d=google.com; s=arc-20160816; b=aWi2UbiUFWIfhC8N3w6BZmNOfxeuSNRUNUv8DlTPRCKLc+tMPqcerDrnlYrhG3Gj15 0Cb2305FoZHWlp+O65vNnI71A7Obr0evMzfp577ukaYa+dMkBTv7a+aPGWiG/9qQ3LpG Of8t9Gj/QW32INHw2hIr2a++fvBFB4tCJfzihV+UbEBXhzHf0cBvKDmImKQQxAIHbD7v nQmmGcfniDMFnFdWyry3gCwukkgXn/A+U2xKkfWu8whmMp+bWB5qUuRT6WX8ypBM3W2d ZGLM/wFEAguZGBgA38lGSsQsdchvmLWXjkIXjdYQjKuUnqRzTTUNdpfZy80fV9Tb26km EjHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=M0DYh8R0owREjUF0rW5MfN/Je7rGC/Z6PzqB2A/sjLU=; b=AlS/rjlv4KvSb6eQADxKOn9+97mNMA2LoDFz1M0rVGjjU+UGiIFH/HnjwFvDzUog0N 87N9R4JSa2VlWqTWx4P571ZjCCDVHlMkloneVn31K3ThSR/I0+PTJKgNSEwEEdkqPBfe P/FMZGJRrzU+IE/aPtiSzSULY4mMscQQPmh1tZGzRMQp4AQQm7sGqDUwiGwVf0MLFLqA fFqPTbtzAhgUUG7ea3at6ameZrWal0+/88qbiDhP92lp8lLNluyTB9rvWfvkmnvocVuG BKltxX0e0M8FhJOqZ+ZSc97OzsfZPBu4j5K1j/Exaiwd5Wlung82xMHCpM0Sk7s/khQD ulUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=XMHZ4hzJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r24si5019473eji.211.2021.01.09.17.22.24; Sat, 09 Jan 2021 17:22:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=XMHZ4hzJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726385AbhAJBUx (ORCPT + 99 others); Sat, 9 Jan 2021 20:20:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726062AbhAJBUw (ORCPT ); Sat, 9 Jan 2021 20:20:52 -0500 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 151F4C06179F for ; Sat, 9 Jan 2021 17:20:12 -0800 (PST) Received: by mail-lf1-x133.google.com with SMTP id b26so32351247lff.9 for ; Sat, 09 Jan 2021 17:20:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=M0DYh8R0owREjUF0rW5MfN/Je7rGC/Z6PzqB2A/sjLU=; b=XMHZ4hzJ1KNIJdjirbYY7rn4bf/WGrGFrNvC0Oc7tHmzgtnGZSAb9fcI7GCEG3NK7U ZpNccWHn+HG7I1P55LoqodGQk4Yyv0xPbnZIYecEcJJgaAbMVZrWg9/uQgSCNwQg+X87 Qe0r8A6ELy7+wBwCuVGrMSbtiopg6PL3G+OkQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=M0DYh8R0owREjUF0rW5MfN/Je7rGC/Z6PzqB2A/sjLU=; b=qpj1s4KG3aNIYjSaA1Ycry+FEo0Ih1IFksaeRH9qkKAgUCoMG3hK9WN7LArFV7ZM/J juTX57boF+96Va+tAsMkxmKOFchZaHWIcpcDlQ4KKs4mWRGhkysnSSYKIS+s67Sqq3BB 7E9aLp407V8OBnXNVTtMTpw4oEpdtt0JamFt6hFev2wAnvFBpwXIhttNzdI2iBwkogiI 98VfFoscfIzqtF4nVSgEmptSD+usK2JWdZzepZB5uLBhjlkRFS4aoQJ93hFxkE423/rL mxj2hNwqyxGQOJaihDkEIzywhS3sMI9GbAnb5H4AroXVKNRVjRdjOG8T2C60l376R74O HLYQ== X-Gm-Message-State: AOAM531RZdXlflvOEApFZUuLyxZvaFemRumJlZA9OleScZRJ2yMW6Z8k 47wAnkoDEWe59IHTVfHdGJCrOwUNlIzwVw== X-Received: by 2002:a2e:7102:: with SMTP id m2mr4743127ljc.245.1610241610373; Sat, 09 Jan 2021 17:20:10 -0800 (PST) Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com. [209.85.167.47]) by smtp.gmail.com with ESMTPSA id w6sm2804891lji.74.2021.01.09.17.20.07 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 09 Jan 2021 17:20:08 -0800 (PST) Received: by mail-lf1-f47.google.com with SMTP id h205so32365113lfd.5 for ; Sat, 09 Jan 2021 17:20:07 -0800 (PST) X-Received: by 2002:a2e:b4af:: with SMTP id q15mr4287325ljm.507.1610241607590; Sat, 09 Jan 2021 17:20:07 -0800 (PST) MIME-Version: 1.0 References: <20210110004435.26382-1-aarcange@redhat.com> In-Reply-To: From: Linus Torvalds Date: Sat, 9 Jan 2021 17:19:51 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 0/1] mm: restore full accuracy in COW page reuse To: Andrea Arcangeli Cc: Andrew Morton , Linux-MM , Linux Kernel Mailing List , Yu Zhao , Andy Lutomirski , Peter Xu , Pavel Emelyanov , Mike Kravetz , Mike Rapoport , Minchan Kim , Will Deacon , Peter Zijlstra , Hugh Dickins , "Kirill A. Shutemov" , Matthew Wilcox , Oleg Nesterov , Jann Horn , Kees Cook , John Hubbard , Leon Romanovsky , Jason Gunthorpe , Jan Kara , Kirill Tkhai , Nadav Amit , Jens Axboe Content-Type: multipart/mixed; boundary="00000000000006197605b88197b9" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --00000000000006197605b88197b9 Content-Type: text/plain; charset="UTF-8" On Sat, Jan 9, 2021 at 4:55 PM Linus Torvalds wrote: > > What part of "clear_refs is the _least_ important of the three cases" > are you not willing to understand? In fact, I couldn't even turn on that code with my normal config, because it depends on CONFIG_CHECKPOINT_RESTORE that I didn't even have enabled. IOW, that code is some special-case stuff, and instead of messing up the rest of the VM, it should be made to conform to all the normal VM rules and requirements. Here's two patches to basically start doing that. The first one is the same one I already sent out earlier, fixing the locking. And yes, it can be improved upon, but before improving on it, let's _fix_ the code. The second is a trivial "oh, look, I can see that the page is pinned, soft-dirty cannot work so don't do it then". Again, it can be improved upon, most particularly by doing the same (simple) tests for the hugepage case too, which I didn't do. Note: I have not a single actual user of this code that I can test with, so this is all ENTIRELY untested. IOW, I am in no way claiming that these patches are perfect and correct, and the only way to do things. But what I _am_ claiming is that this clear_refs code (and the UFFD code) is of secondary importance, and instead of messing up the core VM, we should fix these special cases to not do bad things. It really is that simple. And no, I didn't make the UFFDIO_WRITEPROTECT code take the mmap_sem for writing. For whoever wants to look at that, it's mwriteprotect_range() in mm/userfaultfd.c and the fix is literally to turn the read-lock (and unlock) into a write-lock (and unlock). Linus --00000000000006197605b88197b9 Content-Type: text/x-patch; charset="US-ASCII"; name="0001-mm-fix-clear_refs_write-locking.patch" Content-Disposition: attachment; filename="0001-mm-fix-clear_refs_write-locking.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_kjqg91vp0 RnJvbSBkYWNiNWRlNjJiNjU0ZjFmNWRmMTE0N2UyNjNiNWI0ZTVmZTJhZjQ0IE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBMaW51cyBUb3J2YWxkcyA8dG9ydmFsZHNAbGludXgtZm91bmRh dGlvbi5vcmc+CkRhdGU6IEZyaSwgOCBKYW4gMjAyMSAxMzoxMzo0MSAtMDgwMApTdWJqZWN0OiBb UEFUQ0ggMS8yXSBtbTogZml4IGNsZWFyX3JlZnNfd3JpdGUgbG9ja2luZwoKVHVybmluZyBwYWdl IHRhYmxlIGVudHJpZXMgcmVhZC1vbmx5IHJlcXVpcmVzIHRoZSBtbWFwX3NlbSBoZWxkIGZvcgp3 cml0aW5nLgoKU28gc3RvcCBkb2luZyB0aGUgb2RkIGdhbWVzIHdpdGggdHVybmluZyB0aGluZ3Mg ZnJvbSByZWFkIGxvY2tzIHRvIHdyaXRlCmxvY2tzIGFuZCBiYWNrLiAgSnVzdCBnZXQgdGhlIHdy aXRlIGxvY2suCgpTaWduZWQtb2ZmLWJ5OiBMaW51cyBUb3J2YWxkcyA8dG9ydmFsZHNAbGludXgt Zm91bmRhdGlvbi5vcmc+Ci0tLQogZnMvcHJvYy90YXNrX21tdS5jIHwgMzIgKysrKysrKysrLS0t LS0tLS0tLS0tLS0tLS0tLS0tLS0KIDEgZmlsZSBjaGFuZ2VkLCA5IGluc2VydGlvbnMoKyksIDIz IGRlbGV0aW9ucygtKQoKZGlmZiAtLWdpdCBhL2ZzL3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kJbW1hcF9yZWFkX3VubG9jayhtbSk7Citv dXRfdW5sb2NrOgorCQltbWFwX3dyaXRlX3VubG9jayhtbSk7CiBvdXRfbW06CiAJCW1tcHV0KG1t KTsKIAl9Ci0tIAoyLjI5LjIuMTU3LmcxZDQ3NzkxYTM5Cgo= --00000000000006197605b88197b9 Content-Type: text/x-patch; charset="US-ASCII"; name="0002-mm-don-t-play-games-with-pinned-pages-in-clear_page_.patch" Content-Disposition: attachment; filename="0002-mm-don-t-play-games-with-pinned-pages-in-clear_page_.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_kjqg955v1 RnJvbSBiNDA5NTBiNjQ3NTA5ZjcyMjJlMWY3MTc0ZDYxMDQ1ZDE1ZjU2ZjFjIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBMaW51cyBUb3J2YWxkcyA8dG9ydmFsZHNAbGludXgtZm91bmRh dGlvbi5vcmc+CkRhdGU6IFNhdCwgOSBKYW4gMjAyMSAxNzowOToxMCAtMDgwMApTdWJqZWN0OiBb UEFUQ0ggMi8yXSBtbTogZG9uJ3QgcGxheSBnYW1lcyB3aXRoIHBpbm5lZCBwYWdlcyBpbiBjbGVh cl9wYWdlX3JlZnMKClR1cm5pZ24gYSBwaW5uZWQgcGFnZSByZWFkLW9ubHkgYnJlYWtzIHRoZSBw aW5uaW5nIGFmdGVyIENPVy4gRG9uJ3QgZG8gaXQuCgpUaGUgd2hvbGUgInRyYWNrIHBhZ2Ugc29m dCBkaXJ0eSIgc3RhdGUgZG9lc24ndCB3b3JrIHdpdGggcGlubmVkIHBhZ2VzCmFueXdheSwgc2lu Y2UgdGhlIHBhZ2UgbWlnaHQgYmUgZGlydGllZCBieSB0aGUgcGlubmluZyBlbnRpdHkgd2l0aG91 dApldmVyIGJlaW5nIG5vdGljZWQgaW4gdGhlIHBhZ2UgdGFibGVzLgoKU2lnbmVkLW9mZi1ieTog TGludXMgVG9ydmFsZHMgPHRvcnZhbGRzQGxp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