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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F357C61DA4 for ; Tue, 14 Feb 2023 18:00:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229933AbjBNSAn (ORCPT ); Tue, 14 Feb 2023 13:00:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229578AbjBNSAl (ORCPT ); Tue, 14 Feb 2023 13:00:41 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECBEB2A15C for ; Tue, 14 Feb 2023 09:59:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676397598; 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=c7+MNGw6vwnaHZ5KcVeVb+hrtvazbgYAm6V9+SE6quw=; b=gjnQbAJ9N/YhB29pzxiezv97zJV9wJMU+HkuBUNnaQoQcITUTYB8vWduEL54YAbyzZdRFT Rc/29f6+BJQAJCbTkmyVbDBovU0pqV9m+4fP49we2nz3aEiLY9Ita1axCimXVOokOKgvic fi7W/sr7Ey6SomkfdCBZVfzGdG6kxbc= 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.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-148-kaifaejoMXOeBtQZnVH4eg-1; Tue, 14 Feb 2023 12:59:55 -0500 X-MC-Unique: kaifaejoMXOeBtQZnVH4eg-1 Received: by mail-wm1-f72.google.com with SMTP id j37-20020a05600c1c2500b003deaf780ab6so9059331wms.4 for ; Tue, 14 Feb 2023 09:59:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=c7+MNGw6vwnaHZ5KcVeVb+hrtvazbgYAm6V9+SE6quw=; b=g+12eBnMQfaR2MeDtoxVbMZFKOwkQehfh5FTZulPvIN4jeAp02UXiV/I2goiD9rvzk AtwjcAyiCjhs5834kiaC4G2AoQOO18iqkmAcg1VAggXkGCAgfqFrdJu2n+QmHvWsjNEf iuM9cZDOk7/seo+vstTpc99yhpnGUqwBZwkpGYIXPWQEp03/S1lBdaQGIrrUby5SfmDq eGaOB8ac7m6IQeVFRoNI4jFfQqbCTSZI4JzN3o10ZthhnuTLSC/j3xRvcJ6j5l1iILbx Uq407RTDyybEN4gm/bI+S4QphIT/BXBOexRPKXKBDMzIZX970Ih5jk135sTmcWYQVI2X l/2g== X-Gm-Message-State: AO0yUKWy+EgN/NJ7560wIrZKadmxi3H7fDTzPpeceNHkH6HB1JmYz9R/ qaeHoag1+uCJvWX47vwfUscmnfj9BOrDJ3LjUQe7EX/W7B7aOsCNCOSN3VWcYSahUNALfA/GIvD hrnPW4phfSNPOPNRrRac91CH8kc6Qvf2g X-Received: by 2002:a05:600c:818:b0:3dc:5390:6499 with SMTP id k24-20020a05600c081800b003dc53906499mr2889172wmp.1.1676397593942; Tue, 14 Feb 2023 09:59:53 -0800 (PST) X-Google-Smtp-Source: AK7set98816UCJl6OBxQQIva/LK43GcvL27hW/jwL7RgWSMiK6908hg+hJsKTx0b9fYemxxuQH+yLQ== X-Received: by 2002:a05:600c:818:b0:3dc:5390:6499 with SMTP id k24-20020a05600c081800b003dc53906499mr2889151wmp.1.1676397593698; Tue, 14 Feb 2023 09:59:53 -0800 (PST) Received: from ?IPV6:2003:cb:c709:1700:969:8e2b:e8bb:46be? (p200300cbc709170009698e2be8bb46be.dip0.t-ipconnect.de. [2003:cb:c709:1700:969:8e2b:e8bb:46be]) by smtp.gmail.com with ESMTPSA id b18-20020a05600c4e1200b003e00c453447sm21363801wmq.48.2023.02.14.09.59.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Feb 2023 09:59:53 -0800 (PST) Message-ID: <28f1e75a-a1fc-a172-3628-83575e387f9a@redhat.com> Date: Tue, 14 Feb 2023 18:59:50 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH v4 00/14] Introduce Copy-On-Write to Page Table To: Chih-En Lin Cc: Pasha Tatashin , Andrew Morton , Qi Zheng , "Matthew Wilcox (Oracle)" , Christophe Leroy , John Hubbard , Nadav Amit , Barry Song , Steven Rostedt , Masami Hiramatsu , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Yang Shi , Peter Xu , Vlastimil Babka , Zach O'Keefe , Yun Zhou , Hugh Dickins , Suren Baghdasaryan , Yu Zhao , Juergen Gross , Tong Tiangen , Liu Shixin , Anshuman Khandual , Li kunyu , Minchan Kim , Miaohe Lin , Gautam Menghani , Catalin Marinas , Mark Brown , Will Deacon , Vincenzo Frascino , Thomas Gleixner , "Eric W. Biederman" , Andy Lutomirski , Sebastian Andrzej Siewior , "Liam R. Howlett" , Fenghua Yu , Andrei Vagin , Barret Rhoden , Michal Hocko , "Jason A. Donenfeld" , Alexey Gladkov , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Dinglan Peng , Pedro Fonseca , Jim Huang , Huichun Feng References: <20230207035139.272707-1-shiyn.lin@gmail.com> <62c44d12-933d-ee66-ef50-467cd8d30a58@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org On 14.02.23 18:54, Chih-En Lin wrote: >>> >>>> (2) break_cow_pte() can fail, which means that we can fail some >>>> operations (possibly silently halfway through) now. For example, >>>> looking at your change_pte_range() change, I suspect it's wrong. >>> >>> Maybe I should add WARN_ON() and skip the failed COW PTE. >> >> One way or the other we'll have to handle it. WARN_ON() sounds wrong for >> handling OOM situations (e.g., if only that cgroup is OOM). > > Or we should do the same thing like you mentioned: > " > For example, __split_huge_pmd() is currently not able to report a > failure. I assume that we could sleep in there. And if we're not able to > allocate any memory in there (with sleeping), maybe the process should > be zapped either way by the OOM killer. > " > > But instead of zapping the process, we just skip the failed COW PTE. > I don't think the user will expect their process to be killed by > changing the protection. The process is consuming more memory than it is capable of consuming. The process most probably would have died earlier without the PTE optimization. But yeah, it all gets tricky ... > >>> >>>> (3) handle_cow_pte_fault() looks quite complicated and needs quite some >>>> double-checking: we temporarily clear the PMD, to reset it >>>> afterwards. I am not sure if that is correct. For example, what >>>> stops another page fault stumbling over that pmd_none() and >>>> allocating an empty page table? Maybe there are some locking details >>>> missing or they are very subtle such that we better document them. I >>>> recall that THP played quite some tricks to make such cases work ... >>> >>> I think that holding mmap_write_lock may be enough (I added >>> mmap_assert_write_locked() in the fault function btw). But, I might >>> be wrong. I will look at the THP stuff to see how they work. Thanks. >>> >> >> Ehm, but page faults don't hold the mmap lock writable? And so are other >> callers, like MADV_DONTNEED or MADV_FREE. >> >> handle_pte_fault()->handle_pte_fault()->mmap_assert_write_locked() should >> bail out. >> >> Either I am missing something or you didn't test with lockdep enabled :) > > You're right. I thought I enabled the lockdep. > And, why do I have the page fault will handle the mmap lock writable in my mind. > The page fault holds the mmap lock readable instead of writable. > ;-) > > I should check/test all the locks again. > Thanks. Note that we have other ways of traversing page tables, especially, using the rmap which does not hold the mmap lock. Not sure if there are similar issues when suddenly finding no page table where there logically should be one. Or when a page table gets replaced and modified, while rmap code still walks the shared copy. Hm. -- Thanks, David / dhildenb