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 C050FC636CC for ; Tue, 7 Feb 2023 03:55:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230294AbjBGDz0 (ORCPT ); Mon, 6 Feb 2023 22:55:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230204AbjBGDy7 (ORCPT ); Mon, 6 Feb 2023 22:54:59 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2372C367DD; Mon, 6 Feb 2023 19:54:36 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id v18-20020a17090ae99200b00230f079dcd9so155840pjy.1; Mon, 06 Feb 2023 19:54:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ry1CaivQA+WwrthTA1eQZVLr8NatvP0/+r4itTa9xSI=; b=d8wSKS8rryvPGCmpnm+JTRMWPuer7cSkE915+Di2vStTbeU6J9CDNia1+lKJ4TYA3F FsiWitNkJfkhpGOa3/TWuDlGJ7hoCRvKFsaLeSEyLWy+VFwkWBMOPjP4mVO3kj/AOfTO dfLEUy5AOnIeoq/t3PzsGy1O4+SOKsRbP2Qc+h7hnzcDq5zC5CAfuABjOF37wJlEDJcM ya4VnrJUlMRgeqVncACG8zioe9b0CpHOIXXUE+bnxasciMIEVb1ZOGebhvWfFVJbDsB2 23LNzhzp8J/s/ZXPiEMPXWEev+Jh0Aw4avTPufwGWvkFmZUGBezycgI1BA0/H1w5bUhL KZaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ry1CaivQA+WwrthTA1eQZVLr8NatvP0/+r4itTa9xSI=; b=xGB3rHNlRYepGokvUEsS4b/eGRzqwb0H467SsPab/BVcT/bNSXDxrXULExDxhlUjEE I5MbIMyZtstFDcgMN28qMaIlKjj4ek59PvEKsxaQ2Zjstnlf3JIDCXXZ39hwnxWYcIrd Wz9jCzERs+jhJ6pSWl2wpGcOL/cLpgDt0NiBc7QvfTC3THIcUh12t394/aBuaAF4BwAl TDmOg6De3p1uO/SBK3SPUxAVp9Miqxtz7iUZUj/m6Dh3Z/Tk5h1UREkkIkXk511MXZdL jnUqEThSI+209M8Pl/kIoI0gSAazwPRnRARpiBVe/je2pzYgd9KcsxN5LofVczA2qDCX fDTQ== X-Gm-Message-State: AO0yUKUkyZAUOFyV2BHZ9GMKjB0skEIC6Gm+FNIhPiJ4juOS9SrsqTZU FvTyCSAcwUJ/EXZsVc+AXLk= X-Google-Smtp-Source: AK7set/QqXM+8K/GIbrrktYGZ3tjkjRzSAAFgJgsQE9zms3ILrIsqCklz+JpkGNk5mJ2O3IEsKj7gw== X-Received: by 2002:a17:902:e943:b0:198:adc4:229f with SMTP id b3-20020a170902e94300b00198adc4229fmr12287865pll.26.1675742075566; Mon, 06 Feb 2023 19:54:35 -0800 (PST) Received: from strix-laptop.hitronhub.home ([123.110.9.95]) by smtp.googlemail.com with ESMTPSA id q4-20020a170902b10400b0019682e27995sm7647655plr.223.2023.02.06.19.54.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 19:54:34 -0800 (PST) From: Chih-En Lin To: Andrew Morton , Qi Zheng , David Hildenbrand , "Matthew Wilcox (Oracle)" , Christophe Leroy , John Hubbard , Nadav Amit , Barry Song Cc: 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 , Pasha Tatashin , 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 , Chih-En Lin Subject: [PATCH v4 10/14] mm/userfaultfd: Support COW PTE Date: Tue, 7 Feb 2023 11:51:35 +0800 Message-Id: <20230207035139.272707-11-shiyn.lin@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230207035139.272707-1-shiyn.lin@gmail.com> References: <20230207035139.272707-1-shiyn.lin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If uffd fills the zeropage or installs to COW-ed PTE, break it first. Signed-off-by: Chih-En Lin --- mm/userfaultfd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 0499907b6f1a..3f66aa3eb54f 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -70,6 +70,9 @@ int mfill_atomic_install_pte(struct mm_struct *dst_mm, pmd_t *dst_pmd, struct inode *inode; pgoff_t offset, max_off; + if (break_cow_pte(dst_vma, dst_pmd, dst_addr)) + return -ENOMEM; + _dst_pte = mk_pte(page, dst_vma->vm_page_prot); _dst_pte = pte_mkdirty(_dst_pte); if (page_in_cache && !vm_shared) @@ -229,6 +232,9 @@ static int mfill_zeropage_pte(struct mm_struct *dst_mm, pgoff_t offset, max_off; struct inode *inode; + if (break_cow_pte(dst_vma, dst_pmd, dst_addr)) + return -ENOMEM; + _dst_pte = pte_mkspecial(pfn_pte(my_zero_pfn(dst_addr), dst_vma->vm_page_prot)); dst_pte = pte_offset_map_lock(dst_mm, dst_pmd, dst_addr, &ptl); -- 2.34.1