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 50845C433FE for ; Tue, 22 Nov 2022 15:35:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CFCB46B0073; Tue, 22 Nov 2022 10:35:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CAD818E0002; Tue, 22 Nov 2022 10:35:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B74E28E0001; Tue, 22 Nov 2022 10:35:57 -0500 (EST) 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 A9F506B0073 for ; Tue, 22 Nov 2022 10:35:57 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 689341C68AB for ; Tue, 22 Nov 2022 15:35:57 +0000 (UTC) X-FDA: 80161478754.21.5F90027 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf18.hostedemail.com (Postfix) with ESMTP id 2D2C31C0018 for ; Tue, 22 Nov 2022 15:35:54 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8357A22007; Tue, 22 Nov 2022 15:35:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1669131353; h=from:from:reply-to: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=xzeEtRVGkBValjf4cAqJIIBnm0WLgHIJrOj2Qpyeryk=; b=hSz8uo53GqZkaSBqbG3aIh16lgMQB2Sw8gZ6Z+fnEjIR6uPvpuBuVkR8TpcuCDJwN2rjjn iqJmydTFhzXH0tY5jw9oJ6zK0Sx7/l0zZrHLYI1mzVvp/woqabMd2RthMdqBUz+tckoXxt gvUiGWpp9yM7xLCq0tNctpGuD1es/pI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1669131353; h=from:from:reply-to: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=xzeEtRVGkBValjf4cAqJIIBnm0WLgHIJrOj2Qpyeryk=; b=87yFyDfodelF6paPP+3fZVkcbfCamfu6aYJAmnQjTNh2RXFp/RQ8a0uSheJsgsaRl+tSbc rgSpbkEWiLk/2KDQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E380913B01; Tue, 22 Nov 2022 15:35:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id /ANwNljsfGPGGwAAMHmgww (envelope-from ); Tue, 22 Nov 2022 15:35:52 +0000 Message-ID: <34835490-57d7-4e26-7474-008b2c4c6b39@suse.cz> Date: Tue, 22 Nov 2022 16:35:52 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH mm-unstable v1 08/20] mm: extend FAULT_FLAG_UNSHARE support to anything in a COW mapping Content-Language: en-US To: David Hildenbrand , linux-kernel@vger.kernel.org Cc: x86@kernel.org, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-samsung-soc@vger.kernel.org, linux-rdma@vger.kernel.org, linux-media@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-perf-users@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kselftest@vger.kernel.org, Linus Torvalds , Andrew Morton , Jason Gunthorpe , John Hubbard , Peter Xu , Greg Kroah-Hartman , Andrea Arcangeli , Hugh Dickins , Nadav Amit , Matthew Wilcox , Mike Kravetz , Muchun Song , Shuah Khan , Lucas Stach , David Airlie , Oded Gabbay , Arnd Bergmann , Christoph Hellwig , Alex Williamson References: <20221116102659.70287-1-david@redhat.com> <20221116102659.70287-9-david@redhat.com> From: Vlastimil Babka In-Reply-To: <20221116102659.70287-9-david@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=hSz8uo53; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=87yFyDfo; spf=pass (imf18.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669131355; a=rsa-sha256; cv=none; b=jtRjpA1ey0EQclugmCioozKqEiDmATSeKhdW3jEhXDMHGDYOnBR1uP64sjOSHyUC0ww9Sd k3MYoBVJVF3c7xAmupbq+Macwh3tVk26EhvnHp3nSkYNTFCnxmZy58vZWkXnWcOcxOUttd 8Q/1QaLuHOtBbnoPb2D38vZ8LFq8CYE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669131355; 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=xzeEtRVGkBValjf4cAqJIIBnm0WLgHIJrOj2Qpyeryk=; b=wsJ37Ny3RUKfPMlwrisZ4BpFV4+aNwKtlu/004pwot5BrQfGSFjq4m/sa+kiserDemQ9+n DhvpctOjn9nsl2GE+VgLWeXFA8fgHlpi9etLPKwvi0aIxSzlaWEcS718bKbZ0oCR7p5skx L6c2cGaM+dRsWb/oMaI2wtbqcx6Fnyc= X-Stat-Signature: t86u8bgdazhnccwye63t1ueawczmmidw X-Rspamd-Server: rspam08 X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=hSz8uo53; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=87yFyDfo; spf=pass (imf18.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspamd-Queue-Id: 2D2C31C0018 X-HE-Tag: 1669131354-928313 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 11/16/22 11:26, David Hildenbrand wrote: > Extend FAULT_FLAG_UNSHARE to break COW on anything mapped into a > COW (i.e., private writable) mapping and adjust the documentation > accordingly. > > FAULT_FLAG_UNSHARE will now also break COW when encountering the shared > zeropage, a pagecache page, a PFNMAP, ... inside a COW mapping, by > properly replacing the mapped page/pfn by a private copy (an exclusive > anonymous page). > > Note that only do_wp_page() needs care: hugetlb_wp() already handles > FAULT_FLAG_UNSHARE correctly. wp_huge_pmd()/wp_huge_pud() also handles it > correctly, for example, splitting the huge zeropage on FAULT_FLAG_UNSHARE > such that we can handle FAULT_FLAG_UNSHARE on the PTE level. > > This change is a requirement for reliable long-term R/O pinning in > COW mappings. > > Signed-off-by: David Hildenbrand Reviewed-by: Vlastimil Babka > --- > include/linux/mm_types.h | 8 ++++---- > mm/memory.c | 4 ---- > 2 files changed, 4 insertions(+), 8 deletions(-) > > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h > index 5e7f4fac1e78..5e9aaad8c7b2 100644 > --- a/include/linux/mm_types.h > +++ b/include/linux/mm_types.h > @@ -1037,9 +1037,9 @@ typedef struct { > * @FAULT_FLAG_REMOTE: The fault is not for current task/mm. > * @FAULT_FLAG_INSTRUCTION: The fault was during an instruction fetch. > * @FAULT_FLAG_INTERRUPTIBLE: The fault can be interrupted by non-fatal signals. > - * @FAULT_FLAG_UNSHARE: The fault is an unsharing request to unshare (and mark > - * exclusive) a possibly shared anonymous page that is > - * mapped R/O. > + * @FAULT_FLAG_UNSHARE: The fault is an unsharing request to break COW in a > + * COW mapping, making sure that an exclusive anon page is > + * mapped after the fault. > * @FAULT_FLAG_ORIG_PTE_VALID: whether the fault has vmf->orig_pte cached. > * We should only access orig_pte if this flag set. > * > @@ -1064,7 +1064,7 @@ typedef struct { > * > * The combination FAULT_FLAG_WRITE|FAULT_FLAG_UNSHARE is illegal. > * FAULT_FLAG_UNSHARE is ignored and treated like an ordinary read fault when > - * no existing R/O-mapped anonymous page is encountered. > + * applied to mappings that are not COW mappings. > */ > enum fault_flag { > FAULT_FLAG_WRITE = 1 << 0, > diff --git a/mm/memory.c b/mm/memory.c > index d47ad33c6487..56b21ab1e4d2 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -3432,10 +3432,6 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf) > } > wp_page_reuse(vmf); > return 0; > - } else if (unshare) { > - /* No anonymous page -> nothing to do. */ > - pte_unmap_unlock(vmf->pte, vmf->ptl); > - return 0; > } > copy: > /*