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 B437EEE49B7 for ; Wed, 11 Sep 2024 14:35:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47843940045; Wed, 11 Sep 2024 10:35:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 401C6940021; Wed, 11 Sep 2024 10:35:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25484940045; Wed, 11 Sep 2024 10:35:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 04649940021 for ; Wed, 11 Sep 2024 10:35:06 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AA58214195A for ; Wed, 11 Sep 2024 14:35:04 +0000 (UTC) X-FDA: 82552704528.08.1D2A9B5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 8EFDE20019 for ; Wed, 11 Sep 2024 14:35:02 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XmcuRJcN; spf=pass (imf13.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726065250; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PF/0q5orqycLDyFBmSuytp8djSJ4rgjRkbyNMLkxAWQ=; b=T92CkmLTaifjAPtenyT/Q42sIwio0k8UGebI+1vLr5UGhvYWUtJVN0NNxmomt6fv2yM7ug Kd8A1GDbm9TkTNcdHbY00+ZwGLjC05wmMAqW3BIrC7ClCgqycIFJsZf8WLvYx/qYuzAR2x LUHchn06/9SRC+gzy6nqVNs8WtdIt8Y= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XmcuRJcN; spf=pass (imf13.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726065250; a=rsa-sha256; cv=none; b=3ko26A/wMEyLGB094bTnsJkES82I54Ml/Qq4IxFnUJaY+nqkbTqaY2gchODJzQBaaqAjUH iXyfU/27Xnbubdek3379xu1SDQpbBxBYUnQgbOYH4EvB4qJCrlxl3MNmwZaXCySLbE5dSf /v/+mvkjwkQrRD+OkR/PyFypxrj9Prk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726065301; 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=XmcuRJcNHJfvuCE37YDFhNG59x4hRuyPGIP4MdQ8zvDM5jX89IL/Uo/4utjp/4pvDyuUTK im2EUDC9MiWmwHBkZY+etI6ZyqaQm1eKvuq6JV7z6/Fi+xmyumNzQbxyPtKgTB10FModpM h9QxOXGLXvKIETE0JxLdl0nj+TA71V8= 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-118-ZamomxdSPdGonKauH14zHA-1; Wed, 11 Sep 2024 10:35:00 -0400 X-MC-Unique: ZamomxdSPdGonKauH14zHA-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-45687583c67so112874401cf.2 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=o+WTqLCe6prWWAzvVedNEOrs5xzHDbFOtOqWVV+Jr0YRy7nt4uIA5arHFy8xs3yEiG n0g3bkpqEF5TjqklzjrEv6fHhbMLXAq2+02SbGSWzann+jx3IYOKFgl6rv3Huwo1QV6I 52rhJ+MzKE16+PJYu8jrhN0PB8dgUP2rx18yNMbd8b+z+H8/75mr8WiA1Jwk4x423okP EBI2dpSIQOna8S08D6fwYWGrINT1xgS3LwS/WCIfjf84SBMKEsHqtmxpoFraIOAMAccy +5PUNqXRAFi9TjP4jczfvJs4FpvRhgbdPswLaBw4gPrs/hGi0OoXcf2ata7frdh97BDQ KTSg== X-Forwarded-Encrypted: i=1; AJvYcCVv5cdf1OdhEkkXQK6Ect0SIPuOchKEV6LjvNokuEQCAUOq91G4CEPQzuAl6/8vOsOF5UX81DF/gQ==@kvack.org X-Gm-Message-State: AOJu0YwocdeHPjFxGN5sZPq6r/CPKs8rsERAPn0AeFHzocGB0mWBvqmn Um8OOqGm31jd4RtFPwMTDEc1zAuVBZd0wPgrr2qfRAmbGwojtuM+CV6Mqm5FP43tKVg1n0vwiFd QQurpc+lYLHd7PVcmMX/L+L6wnxCLDvDsReRj1HDfD7oxdk+S X-Received: by 2002:a05:622a:651:b0:458:4323:d7b3 with SMTP id d75a77b69052e-4584323d91emr68257391cf.34.1726065300142; 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-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 8EFDE20019 X-Stat-Signature: p8euwhnd8yofmcmcmc3eh9ftxci55jxf X-HE-Tag: 1726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rfgdE6UOaPDhYLgOSR9/sJ5DLA7MYg8AnfchwlNJUDlBrj/vUto1wvtEbfhOIeE/d1Niid7hUqYVTmN6aGEB6al+sGJkVvEOQdwPXU5Ewt54k6sq5LxrTjekKLXj8HZhgPpaAqkqocU6M2vS8oKrLJW7F6oku+Y+U6AIVKhYK5SEl3YSviXkYx/Mh01YPAITLomLbUqD2tqeVEkkAM9mmEXwgyCHNpPuo071bJMoLmjeIFrUkFS4JTqQr/BQ2f/v4h5mvAw90lXGLPxdoSKKUTHf7MEEUQYswikuQiBi4LrV0+w== 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: List-Subscribe: List-Unsubscribe: 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