Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1285532pxb; Fri, 21 Jan 2022 14:22:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJxHC5izUPrRb9g3gxc7Ew2TXdzrtQQNVlpBd6Vq3Au+Yq3y8MpERVatVfVmguoE5r5JKIcG X-Received: by 2002:a17:90b:4b83:: with SMTP id lr3mr2680795pjb.59.1642803725465; Fri, 21 Jan 2022 14:22:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642803725; cv=none; d=google.com; s=arc-20160816; b=KvLxDQHVZt3ANN/j1C3/8LUDJhoneZbFG2cMGMBNuvqmSNaESRYqktw4aO9STH5Y2e j1YYF5lCmcgyHWSpfsHwaZuyBaGnkEYt5JbbAyPCVfwKvvSDBgH55KxBVExhi19F86mh pxsCV61YDtvqW0wJDlumMHDyrtFcRNcyPtMpIThj3EbXXvB4a0n+tszDPJz0MtSzQ/cm i9/H+kKMwnd7mrttJZT2vRScskyWk3tdoPms8qwDxBboNrwSdmr/xr2Ehyng5PImgO7W U2cIexr2Mes2jgngah5pU3CrVccUr4ZfA+WFENEpBE0mm5U98zZ2F1jDiAerBi8xCXLy dIsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :organization:from:references:cc:to:content-language:user-agent :mime-version:date:message-id:dkim-signature; bh=JcFuUx6JnIuoyTsFkMKn2U/95+8ifvkCP1zZpo98AmA=; b=pd7qQU0EFUAyY/FQkr4sT7zVaG+rBDIxzJLhfKRgoxb3mlfQeOm6CRrWxFLNakCFRP qqM7G1qjIc4x0C9SmwjLE0FBcC3UR4I1ecxAZ11hU2Y5d6lkc0nEMbWeE4WeuzRBnbqG BxONtF2VW0b+Q2LlIxYUK6ngzw6YqSPUU9jWsUk1ryvYQo5MQ1Ii0vedQImrPcH4mm6k cQQmaO/vnC6HKHx9+K4hLOPrQ6i50GGvfdeo/Unw29jm1MdBZbPiCTzpHypGPN1bXjgG leWODqyRZ8KYKexqdAcekM/AJfrzUoncwgrbYNdynUBXMrnTzfkABD8FTR7UUDISF76o TZjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EW4VcAlk; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p10si6826386pls.262.2022.01.21.14.21.53; Fri, 21 Jan 2022 14:22:05 -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=@redhat.com header.s=mimecast20190719 header.b=EW4VcAlk; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376651AbiATP0a (ORCPT + 99 others); Thu, 20 Jan 2022 10:26:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:28997 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376686AbiATP01 (ORCPT ); Thu, 20 Jan 2022 10:26:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642692386; 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=JcFuUx6JnIuoyTsFkMKn2U/95+8ifvkCP1zZpo98AmA=; b=EW4VcAlknIDCc3AD6qlmFJNmw9e8SMaHXop1M+QPNpH1DJKY3+NlNcBCwV3JtAyxMwdXIP W2Uin48XiwK6fQyKonmBwq5FAzr0DO/G+SAkyzrIi0cIlBWlAa+oiNZpFW8J26wRgmTNth 6XqxnXKR0Z14hCOoEv9d+FAXhDmRadQ= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-583-lFGzwTswPgKdWNsJ7IYQww-1; Thu, 20 Jan 2022 10:26:25 -0500 X-MC-Unique: lFGzwTswPgKdWNsJ7IYQww-1 Received: by mail-ed1-f69.google.com with SMTP id bs4-20020a056402304400b004032af6b7ebso6204710edb.16 for ; Thu, 20 Jan 2022 07:26:24 -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 :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=JcFuUx6JnIuoyTsFkMKn2U/95+8ifvkCP1zZpo98AmA=; b=lr3YemTaUC+ik2Yu3cMJwOTxZGOMjyWQLvNS+FoYkVwoaa90SPvd3ut0BCW6loOgBj hqO7pmFzG4DQZHumdKmjbHNI33SET7MReUzpUstDlwy9NCYkklBdK7ADzXDaZvfwU+Sg x/aSqwQGsiFGloUXNRQ8eb5D7ATjyoDvOfZHA4dAL0nDKnYfaqMVnSuonpyPQhZh5jkj OEZ2ygMhaba0KeO4lHMEsST9TXFV7VTzY3c1cL1Bzg9a/nVM2hnnHMgdMWukrUcOYnVt 4nhI06kXxTABvzSnmDO+TnFturHp4ZVehNIaNqcGqA64KCtoAbMhrlt4e6VS5QPmZMD2 CSTw== X-Gm-Message-State: AOAM5336OIaotzt4n6Q7TW214CBsOvUBEFsYKGzDytL0Z03BMV5QaSWF y8IkCnZTQGvA6ZLOYCMFX+UPgKDJEfR+eVqhOKa8VPqY7hGEp5ZAZBLbDJWIIr3KZg320yeurFP dBzUPSg0WDRbthSLw8io4sgqs X-Received: by 2002:a17:906:4795:: with SMTP id cw21mr10414542ejc.39.1642692383922; Thu, 20 Jan 2022 07:26:23 -0800 (PST) X-Received: by 2002:a17:906:4795:: with SMTP id cw21mr10414523ejc.39.1642692383651; Thu, 20 Jan 2022 07:26:23 -0800 (PST) Received: from ?IPV6:2003:cb:c70e:5800:eeb:dae2:b1c0:f5d1? (p200300cbc70e58000eebdae2b1c0f5d1.dip0.t-ipconnect.de. [2003:cb:c70e:5800:eeb:dae2:b1c0:f5d1]) by smtp.gmail.com with ESMTPSA id gr24sm1107372ejb.185.2022.01.20.07.26.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Jan 2022 07:26:23 -0800 (PST) Message-ID: Date: Thu, 20 Jan 2022 16:26:22 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Content-Language: en-US To: Matthew Wilcox Cc: "zhangliang (AG)" , Andrew Morton , Linux-MM , Linux Kernel Mailing List , wangzhigang17@huawei.com, Linus Torvalds References: <20220113140318.11117-1-zhangliang5@huawei.com> <172ccfbb-7e24-db21-7d84-8c8d8c3805fd@redhat.com> <9cd7eee2-91fd-ddb8-e47d-e8585e5baa05@redhat.com> <747ff31c-6c9e-df6c-f14d-c43aa1c77b4a@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH] mm: reuse the unshared swapcache page in do_wp_page In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20.01.22 15:39, Matthew Wilcox wrote: > On Thu, Jan 20, 2022 at 03:15:37PM +0100, David Hildenbrand wrote: >> On 17.01.22 14:31, zhangliang (AG) wrote: >>> Sure, I will do that :) >> >> I'm polishing up / testing the patches and might send something out for discussion shortly. >> Just a note that on my branch was a version with a wrong condition that should have been fixed now. >> >> I am still thinking about PTE mapped THP. For these, we'll always >> have page_count() > 1, essentially corresponding to the number of still-mapped sub-pages. >> >> So if we end up with a R/O mapped part of a THP, we'll always have to COW and cannot reuse ever, >> although it's really just a single process mapping the THP via PTEs. >> >> One approach would be to scan the currently locked page table for entries mapping >> this same page. If page_count() corresponds to that value, we know that only we are >> mapping the THP and there are no additional references. That would be a special case >> if we find an anon THP in do_wp_page(). Hm. > > You're starting to optimise for some pretty weird cases at that point. So your claim is that read-only, PTE mapped pages are weird? How do you come to that conclusion? If we adjust the THP reuse logic to split on additional references (page_count() == 1) -- similarly as suggested by Linus to fix the CVE -- we're going to end up with exactly that more frequently. > Anon THP is always going to start out aligned (and can be moved by > mremap()). Arguably it should be broken up if it's moved so it can be > reformed into aligned THPs by khugepaged. Can you elaborate, I'm missing the point where something gets moved. I don't care about mremap() at all here. 1. You have a read-only, PTE mapped THP 2. Write fault on the THP 3. We PTE-map the THP because we run into a false positive in our COW logic to handle COW on PTE 4. Write fault on the PTE 5. We always have to COW each and every sub-page and can never reuse, because page_count() > 1 That's essentially what reuse_swap_page() tried to handle before. Eventually optimizing for this is certainly the next step, but I'd like to document which effect the removal of reuse_swap_page() will have to THP. -- Thanks, David / dhildenb