From patchwork Tue Feb 7 03:51:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chih-En Lin X-Patchwork-Id: 13130968 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 CC0B3C636CC for ; Tue, 7 Feb 2023 03:54:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229775AbjBGDyj (ORCPT ); Mon, 6 Feb 2023 22:54:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230180AbjBGDyP (ORCPT ); Mon, 6 Feb 2023 22:54:15 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACD6C36444; Mon, 6 Feb 2023 19:53:56 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id e19so6451550plc.9; Mon, 06 Feb 2023 19:53:56 -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=P2hiqzbHJQraqi9uwlHzBIrzOyDxCP/J3GJiV5ChdNY=; b=bmOC7XUPYoB8TNQF7f0wYym0XRU34TbLiGrQ4u3lU2iawbK3M9Yxa2YG5f2unStsBz Gl7fnqxofqZfItKUqy/uxWj4gKzfqEHOiZpN3jsLN+pXOzyJRlfM6RG1F5aqeUQD56rm PfpHbRAv5wRzLb7GbK7Dtvb20vGmVB8yYws60BRLU39ZhuDrjQjtjXkww0bx9kbB+KiN QLE80k9KYlUBvl3ALbdcdlXaSO/lIoktoU+FuFkbrp/+L0s0YiAKRSdpxRqHHhIKiXS/ w+LEABWKYLafPT81g2ZVH6IIUA2YjdTap9V5QJ406//JaGKHHilBqrDZ0tSmNSWU2W/P LSbg== 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=P2hiqzbHJQraqi9uwlHzBIrzOyDxCP/J3GJiV5ChdNY=; b=ARhKoWGhnpr1SSdqxLPdfwH+I1mOPopduHKRO2VCESw6Oet394RFkfK+rHIBnqLq54 Jt7iyTVXPvCC6draj1yTHj6U4whcVJd/S79Y1Yd/5AE8D5DLWFD2nnRlPTbfKaHM3wy5 XbmlTIpX2fJIhOXWOlxSOryDtq2lKS+4xOssYCaMzJ1TZyYLYcJGpcjk4PO/GyEhfSnI WaJnA9bnICDflvwDFJGcOFCWnIqhm2xcCBkJsyR6sE5wVvz0ZFuSYNl5tnYQa6rh7+4H hrM48heXh971b++iOG6VDDtJYSy064gJcFOdgNhs8R7CHWFzoR+U/RAhQK6WDjhrXqX7 0OKw== X-Gm-Message-State: AO0yUKUFXjuSlg0VJ5ihobnf2cTZ4hXThkZYxqrZ8T11LVRiNAw+tE+z lvBjx1uqnVOJLM6acrL0g3Q= X-Google-Smtp-Source: AK7set9XER72kqQ2uHZQ9Dv9OhzTxcotdKJFhFXMKaajUQO56abILAuY/kvBJuFI6YmYXpde35qWlw== X-Received: by 2002:a17:902:f691:b0:199:2f45:14fd with SMTP id l17-20020a170902f69100b001992f4514fdmr1033089plg.31.1675742029047; Mon, 06 Feb 2023 19:53:49 -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.53.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 19:53:48 -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 06/14] mm/ksm: Break COW PTE before modify shared PTE Date: Tue, 7 Feb 2023 11:51:31 +0800 Message-Id: <20230207035139.272707-7-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 Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org Break COW PTE before merge the page that reside in COW-ed PTE. Signed-off-by: Chih-En Lin --- mm/ksm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/ksm.c b/mm/ksm.c index dd02780c387f..ce3887d3b04c 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1045,7 +1045,7 @@ static int write_protect_page(struct vm_area_struct *vma, struct page *page, pte_t *orig_pte) { struct mm_struct *mm = vma->vm_mm; - DEFINE_PAGE_VMA_WALK(pvmw, page, vma, 0, 0); + DEFINE_PAGE_VMA_WALK(pvmw, page, vma, 0, PVMW_BREAK_COW_PTE); int swapped; int err = -EFAULT; struct mmu_notifier_range range; @@ -1163,6 +1163,8 @@ static int replace_page(struct vm_area_struct *vma, struct page *page, barrier(); if (!pmd_present(pmde) || pmd_trans_huge(pmde)) goto out; + if (break_cow_pte(vma, pmd, addr)) + goto out; mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, mm, addr, addr + PAGE_SIZE);