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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AC467EE49BD for ; Wed, 11 Sep 2024 14:45:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:In-Reply-To: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=PF/0q5orqycLDyFBmSuytp8djSJ4rgjRkbyNMLkxAWQ=; b=CZCxSaf4XKMi79I/Jz+/I0SiEB hjYLgPJaR44lcR0sGAMbdr6S+CcbveBZ+NPjMxZLZt0wPIODKhHy8FIarXJuNm7dZmy+shhNOzQo8 wUXC8LAkTBRzPZtnhhBPyq/z0l7qCzRUESDaDaFYFqURXd0Jl7rzdC0EiLI1+brTsZVwwKaeo710k MxWoz5HG5e6T6hhjL3ZB6TDUQ1h4Ey9oTKNJbJ0E25pXXDwzmqUNUkmeYhtY+T0TZJ09tFpVckbCg wbhwb/QGfWjukS0Ole7kWENrv0mjwRkEHJ9N67szf/PRbdlo1gM/C1h4FUhh3BXaTTUHvn+Yapvva vDcytehg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soOb6-00000009zXs-367Q; Wed, 11 Sep 2024 14:45:32 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soOQz-00000009w0V-3stT for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 14:35:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726065303; 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: in-reply-to:in-reply-to:references:references; bh=PF/0q5orqycLDyFBmSuytp8djSJ4rgjRkbyNMLkxAWQ=; b=OMwsXpAQCmVSZO3CD2nWwWG4mMVKDh5sWY/+chp3ZPZxa92Ona0lfsqIh/53CKoPm6Llk2 DMUEvFFPcexB7O/TTxR/WLPslEEA9MopxdD+Lufn3eSJbEHKWG05nWt6wEDAybiW3S37kO SKDjYjcHR0fBh0JHB5+0+mVyQhK+2VY= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-633-8RrmJfePPdOzBbTdMaB_9A-1; Wed, 11 Sep 2024 10:35:00 -0400 X-MC-Unique: 8RrmJfePPdOzBbTdMaB_9A-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-458432fe9baso28107421cf.1 for ; Wed, 11 Sep 2024 07:35:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726065300; x=1726670100; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=PF/0q5orqycLDyFBmSuytp8djSJ4rgjRkbyNMLkxAWQ=; b=FT2zrfzvBx6eJRuYHXmb9GwFdqodvb8BKGAR04wVctNWF4+f5ZjekW59ItnoIp4LvB +yo4HL+L6h5tF0cG2DhVdSOnFEjLjzJdSIozZiqqJI/wXu/DY231Kv4DgT+1ceRDQP/W n1QCtLE7zvqFZ11flemHr6ZyWM8ADgXKG0LNmhitGKgoavB3A7laJbrGuHC/CXslFn06 z/70zVydf7ZdWn74tqeDeaUgTkKtD2b5zPXji98AdQIwguRfFlsRuhFZn3k5eniv18j4 ZGUBwr97OBtk8+MybVkNOqWq0Igl0wwGg6TixU29RxWMI78aWwvjy7w3b46oCckzCuQf EfpA== X-Forwarded-Encrypted: i=1; AJvYcCX1JM1HFppeyzKYG75Cwb63c7oICBy39GZoQDzSsc09MTr275ZXlVil1WlvEReOnTaHAiNIt0t7PspI8kVXGooz@lists.infradead.org X-Gm-Message-State: AOJu0Yw6kofjbQjvCTSUZaGcNgfmRadS8RWJXY/dUtfumljwYJKIyCl8 LmNWALQaLQdaC1CtayQKGm8JzAfxUL/lyqgDq3Lp5KgKt79bnST25Vc+OpmHrOmCeEsk9uKZRXE 1K68hC2/qWpOA96oV4goGIEQALVO4rsZlVyktoWAGag16LR9/TBEOtKt0vcCE7zuIY23eOZiz X-Received: by 2002:a05:622a:651:b0:458:4323:d7b3 with SMTP id d75a77b69052e-4584323d91emr68257481cf.34.1726065300149; Wed, 11 Sep 2024 07:35:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFngkfkq1nQs7Kv0mNC7ulS6e7nNeL51I8RbbZOuMP/jFQHPk0ALPxgHZnZfq+Gumf6CJkjkA== X-Received: by 2002:a05:622a:651:b0:458:4323:d7b3 with SMTP id d75a77b69052e-4584323d91emr68257071cf.34.1726065299714; Wed, 11 Sep 2024 07:34:59 -0700 (PDT) Received: from x1n (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-45822e61a77sm41722191cf.20.2024.09.11.07.34.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 07:34:58 -0700 (PDT) Date: Wed, 11 Sep 2024 10:34:54 -0400 From: Peter Xu To: Yan Zhao Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Gavin Shan , Catalin Marinas , x86@kernel.org, Ingo Molnar , Paolo Bonzini , Dave Hansen , Thomas Gleixner , Alistair Popple , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sean Christopherson , Oscar Salvador , Jason Gunthorpe , Borislav Petkov , Zi Yan , Axel Rasmussen , David Hildenbrand , Will Deacon , Kefeng Wang , Alex Williamson Subject: Re: [PATCH v2 07/19] mm/fork: Accept huge pfnmap entries Message-ID: References: <20240826204353.2228736-8-peterx@redhat.com> <20240909152546.4ef47308e560ce120156bc35@linux-foundation.org> <20240909161539.aa685e3eb44cdc786b8c05d2@linux-foundation.org> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_073506_070724_D13691F4 X-CRM114-Status: GOOD ( 33.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Sep 11, 2024 at 10:16:55AM +0800, Yan Zhao wrote: > On Tue, Sep 10, 2024 at 08:16:10AM -0400, Peter Xu wrote: > > On Tue, Sep 10, 2024 at 10:52:01AM +0800, Yan Zhao wrote: > > > Hi Peter, > > > > Hi, Yan, > > > > > > > > Not sure if I missed anything. > > > > > > It looks that before this patch, pmd/pud are alawys write protected without > > > checking "is_cow_mapping(vma->vm_flags) && pud_write(pud)". pud_wrprotect() > > > clears dirty bit by moving the dirty value to the software bit. > > > > > > And I have a question that why previously pmd/pud are always write protected. > > > > IIUC this is a separate question - the move of dirty bit in pud_wrprotect() > > is to avoid wrongly creating shadow stack mappings. In our discussion I > > think that's an extra complexity and can be put aside; the dirty bit will > > get recovered in pud_clear_saveddirty() later, so it's not the same as > > pud_mkclean(). > But pud_clear_saveddirty() will only set dirty bit when write bit is 1. Yes, it's because x86 wants to avoid unexpected write=0 && dirty=1 entries, because it can wrongly reflect a shadow stack mapping. Here we cannot recover the dirty bit if set only if write bit is 1 first. > > > > > AFAIU pmd/pud paths don't consider is_cow_mapping() because normally we > > will not duplicate pgtables in fork() for most of shared file mappings > > (!CoW). Please refer to vma_needs_copy(), and the comment before returning > > false at last. I think it's not strictly is_cow_mapping(), as we're > > checking anon_vma there, however it's mostly it, just to also cover > > MAP_PRIVATE on file mappings too when there's no CoW happened (as if CoW > > happened then anon_vma will appear already). > > > > There're some outliers, e.g. userfault protected, or pfnmaps/mixedmaps. > > Userfault & mixedmap are not involved in this series at all, so let's > > discuss pfnmaps. > > > > It means, fork() can still copy pgtable for pfnmap vmas, and it's relevant > > to this series, because before this series pfnmap only exists in pte level, > > hence IMO the is_cow_mapping() must exist for pte level as you described, > > because it needs to properly take care of those. Note that in the pte > > processing it also checks pte_write() to make sure it's a COWed page, not a > > RO page cache / pfnmap / ..., for example. > > > > Meanwhile, since pfnmap won't appear in pmd/pud, I think it's fair that > > pmd/pud assumes when seeing a huge mapping it must be MAP_PRIVATE otherwise > > the whole copy_page_range() could be already skipped. IOW I think they > > only need to process COWed pages here, and those pages require write bit > > removed in both parent and child when fork(). > Is it also based on that there's no MAP_SHARED huge DEVMAP pages up to now? Correct. Thanks, -- Peter Xu