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 27096C001DE for ; Fri, 4 Aug 2023 07:23:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A8B08D000D; Fri, 4 Aug 2023 03:23:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 530528D0002; Fri, 4 Aug 2023 03:23:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A97E8D000D; Fri, 4 Aug 2023 03:23:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 253AB8D0002 for ; Fri, 4 Aug 2023 03:23:52 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E71201212D4 for ; Fri, 4 Aug 2023 07:23:51 +0000 (UTC) X-FDA: 81085582662.26.E97FFCD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id AFAE61A0003 for ; Fri, 4 Aug 2023 07:23:49 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dQedoIMq; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@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=1691133829; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=X0SDuWX0PVJtjYbmSJGuOQKYEPGZD7rqG2wXMixgOng=; b=Dcxc5jugGr1sPglHwP5y8F9QM2XT7hFVyrXQ5tgifGTg+STk+jc9tF54OvCaJF7oAe4+nK xbSzKT4sEEr/QtQZoBdgl3Sfv2PXOnnCbatp/8acOVX6PwK99ak+rXctOHKKjCKy1F2892 yt+5Ha5Wib3xnIKgtTDobOcwUtdZQrE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691133829; a=rsa-sha256; cv=none; b=4PSH9/UAjwf1H1NF1+E/De4sEq7KywBjTapBMGix1TM8hh3xaKf/9kocB9us16Wci/J4jw mlMmW5qOC/WeGxPYJYHpygemuHmBBkyXJxOo62Ea63x9KqbKO2Tj2QNG0PJQlyO64wbBzz N1iyrBcbRvw6sa6/0SHYiGnOPe5DbEk= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dQedoIMq; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691133828; 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=X0SDuWX0PVJtjYbmSJGuOQKYEPGZD7rqG2wXMixgOng=; b=dQedoIMqRlDkMV380V9iemiV3qu0wJ2GbE89wk3Sz0Hr+CWtqf2sxA710QDCyteaF6DCxl spRxnBdx8KwfqXw+5+bLuLRDwdsZQS3/Bq5uCkzapYkUfNXSo5kfDK6RA4/0dY0G7W6NiB HWkfzo2SMNPj480KMPrtiObDGExz4NE= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-511-URQdT4ZgOy6yiQ63GPRKBQ-1; Fri, 04 Aug 2023 03:23:47 -0400 X-MC-Unique: URQdT4ZgOy6yiQ63GPRKBQ-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3178ddc3d94so1063327f8f.1 for ; Fri, 04 Aug 2023 00:23:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691133826; x=1691738626; 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=X0SDuWX0PVJtjYbmSJGuOQKYEPGZD7rqG2wXMixgOng=; b=ikbtZRVeQuT5PLk00616sLabydtbN9CCpgFo0JyAvEp9wHAMz/fhzncI9PmDCiwbig q1SjAnvqpyIF5KoD7/UaFjuEcm01rCb/Utp/yoUm8rk9i0TNsXs6V1PVYAd+mRyh27k1 2vBFKtfaBmcV9eLdgWtr2Pg1tbNSXVemsOz/r0ZbuejltHSfOo76OaO+h0dwdP3IFX8q ASN5JnGdqWKabWzvyhmXth5l8Aq6RvLi1cA5bWiwXtX/JUI0Fkg6qv71LGy3n9nsshT3 dmuPWHdkuo9Qnb6AD2ilL/+OfR+TOGRXonHGZ/afLPePwZzhoq2EJedsOXih1O9mhvBF XvVQ== X-Gm-Message-State: AOJu0Yz3i6lG90Pb5EJ+CQk/XeJBZ5Cq4y9p76wktLB3XRDroUv+OnIo 3jqsUQdU1+JzwNEYbZhTPi5nfNv0pMXsfb2qZuUb6Z6yMUKcWXT3LXFBerefZP9f8zVYyxmWPav 52NlwYn3n9r8= X-Received: by 2002:a05:6000:10cc:b0:313:df08:7b7e with SMTP id b12-20020a05600010cc00b00313df087b7emr706551wrx.14.1691133826147; Fri, 04 Aug 2023 00:23:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFRwRNR51hbvYFIT6vOA55mQLzv8RpfVuaFFCwVgPE4ZVELsqeyAcuZh0skiXntG1j72b0zzQ== X-Received: by 2002:a05:6000:10cc:b0:313:df08:7b7e with SMTP id b12-20020a05600010cc00b00313df087b7emr706537wrx.14.1691133825702; Fri, 04 Aug 2023 00:23:45 -0700 (PDT) Received: from ?IPV6:2003:cb:c724:5900:10b9:2373:11c6:216c? (p200300cbc724590010b9237311c6216c.dip0.t-ipconnect.de. [2003:cb:c724:5900:10b9:2373:11c6:216c]) by smtp.gmail.com with ESMTPSA id k14-20020adfd84e000000b003177e9b2e64sm1741887wrl.90.2023.08.04.00.23.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Aug 2023 00:23:45 -0700 (PDT) Message-ID: Date: Fri, 4 Aug 2023 09:23:43 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [RFC v1 1/3] mm/mmu_notifier: Add a new notifier for mapping updates (new pages) To: "Kasireddy, Vivek" , Alistair Popple Cc: Jason Gunthorpe , "Kim, Dongwon" , "Chang, Junxiao" , "dri-devel@lists.freedesktop.org" , Hugh Dickins , Peter Xu , "linux-mm@kvack.org" , Gerd Hoffmann , Mike Kravetz References: <48f22686-2c1b-fd9d-91ba-da6105d410db@redhat.com> <3427735b-2a73-2df7-ebd9-0d1066a55771@redhat.com> <2aee6681-f756-9ace-74d8-2f1e1e7b3ae6@redhat.com> <87cz0364kx.fsf@nvdebian.thelocal> 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 X-Rspamd-Queue-Id: AFAE61A0003 X-Rspam-User: X-Stat-Signature: gokecrx7iq43pkno1zh8f7b5uej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iERFGq6omejJk1j3i9LcO+CNXAYImq712KGd7bvJUS3ePZUCGd1EU9QFDDgWM++JrXSsxmKMcIOqW+NXt+qkYVHahqA96A8RjLfbzXlVq5aSwUe9fuvHR9t4/lRROdMX4yBfUS000oo8yGEOehOOmIf/dio0vXs8aoX/eluDJtaWfYbCuG6xucplIXpxWjG6Hj53CUESNljL1COKkwJintbEXXfUmyOeaWLwEZ9PAuT+QqbDDL2yGCxinblzfXTlOwalPt8h9SKHJUAltwwZj4S9V+Ugl6fetdGTYLJKoGbUWZtFodfvRK+VZ+V1dHyc1VeMlkQpQdaVnPun330DX4BFThhCoLtTtgfbEzBCyyJ+PAUjdb2UFVHObqaKE+jlFUjObypsjaQ8QUs7KqWOJd3io5FxwO2KaXM+dWVQZSwFnCMQ== 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 04.08.23 08:39, Kasireddy, Vivek wrote: > Hi Alistair, David, Jason, > >>>>>>>> Right, the "the zero pages are changed into writable pages" in your >>>>>>>> above comment just might not apply, because there won't be any >> page >>>>>>>> replacement (hopefully :) ). >>>>>> >>>>>>> If the page replacement does not happen when there are new writes >> to the >>>>>>> area where the hole previously existed, then would we still get an >>>>>> invalidate >>>>>>> when this happens? Is there any other way to get notified when the >> zeroed >>>>>>> page is written to if the invalidate does not get triggered? >>>>>> >>>>>> What David is saying is that memfd does not use the zero page >>>>>> optimization for hole punches. Any access to the memory, including >>>>>> read-only access through hmm_range_fault() will allocate unique >>>>>> pages. Since there is no zero page and no zero-page replacement there >>>>>> is no issue with invalidations. >>>> >>>>> It looks like even with hmm_range_fault(), the invalidate does not get >>>>> triggered when the hole is refilled with new pages because of writes. >>>>> This is probably because hmm_range_fault() does not fault in any pages >>>>> that get invalidated later when writes occur. >>>> hmm_range_fault() returns the current content of the VMAs, or it >>>> faults. If it returns pages then it came from one of these two places. >>>> If your VMA is incoherent with what you are doing then you have >>>> bigger >>>> problems, or maybe you found a bug. >> >> Note it will only fault in pages if HMM_PFN_REQ_FAULT is specified. You >> are setting that however you aren't setting HMM_PFN_REQ_WRITE which is >> what would trigger a fault to bring in the new pages. Does setting that >> fix the issue you are seeing? > No, adding HMM_PFN_REQ_WRITE still doesn't help in fixing the issue. > Although, I do not have THP enabled (or built-in), shmem does not evict > the pages after hole punch as noted in the comment in shmem_fallocate(): > if ((u64)unmap_end > (u64)unmap_start) > unmap_mapping_range(mapping, unmap_start, > 1 + unmap_end - unmap_start, 0); > shmem_truncate_range(inode, offset, offset + len - 1); > /* No need to unmap again: hole-punching leaves COWed pages */ > > As a result, the pfn is still valid and the pte is pte_present() and pte_write(). > This is the reason why adding in HMM_PFN_REQ_WRITE does not help; Just to understand your setup: you are definitely using a MAP_SHARED shmem mapping, and not accidentally a MAP_PRIVATE mapping? -- Cheers, David / dhildenb