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 AF391C433EF for ; Thu, 20 Jan 2022 15:26:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D67FB6B0093; Thu, 20 Jan 2022 10:26:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D16876B0096; Thu, 20 Jan 2022 10:26:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB7276B0099; Thu, 20 Jan 2022 10:26:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0077.hostedemail.com [216.40.44.77]) by kanga.kvack.org (Postfix) with ESMTP id AB66D6B0093 for ; Thu, 20 Jan 2022 10:26:27 -0500 (EST) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 62DD895295 for ; Thu, 20 Jan 2022 15:26:27 +0000 (UTC) X-FDA: 79051042014.31.1A413F5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id C19E8100004 for ; Thu, 20 Jan 2022 15:26:26 +0000 (UTC) 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-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-237--0vkYXn-P2uVGSNN_06NHg-1; Thu, 20 Jan 2022 10:26:25 -0500 X-MC-Unique: -0vkYXn-P2uVGSNN_06NHg-1 Received: by mail-ed1-f70.google.com with SMTP id k10-20020a50cb8a000000b00403c8326f2aso6241636edi.6 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=wDjQxZOF+yIhNslauHEll9EYakjVibQOouHvd6w3i8L+g8GCOQCmpxk41+o3pooQWV ZVypB5n3NH/bz0QU2OkWKTHj192r4xvHX64Xx88L1EL2d614RlClKSb8/5jdIPQLQPd3 2NACH/jgHuJ4NuRlqClE/UKWySMPsAfx2MSZlK746frZJ9pnQGbLgpRaS2kqLPJki9h/ 06wUY+6tOHy9jQUOIfQKkjB/UPJGbKYUyJbGXBACSHzIJumJ+Xg8MZgatGVZkF2Sn9qa aNIAatGvrnIewSb+c7xzgxyupVcUj4Ll1pnRuOcUIMj14h+4GNRB4SMUx1iY+e4TmBia qbQg== X-Gm-Message-State: AOAM5324QkrXuJQ7eDQ+N0oByWswgp4MC7Hh4emYjT2NQ6Ke5VCZ/PV/ dGJlg+VdjL9VLPalvbm82Wv5f+YulL8s73NAzZvUeVHC5pToEfBRyUKj7cDBkpvHD2VgUcP/76N AXxSM+ib4cm4= X-Received: by 2002:a17:906:4795:: with SMTP id cw21mr10414545ejc.39.1642692383926; Thu, 20 Jan 2022 07:26:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJy4ABnzPg+275IpNEeFqOv2Bl3qkyZQ/tUMXHw6wdfpQpRGOsWTlX1Ux9PRNpnvv2mEvqAvqA== 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 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: 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-Queue-Id: C19E8100004 X-Stat-Signature: mkuwcb5xdiezpwpahnftxyozrwwsnjag Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EW4VcAlk; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf05.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com X-Rspamd-Server: rspam08 X-HE-Tag: 1642692386-526689 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 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