Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5559481pxb; Mon, 14 Feb 2022 01:55:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJzJWnEBINNi62US+i+lx1uTAc7WBUXKyGI815GyqlHkixZbkhhq1b9cubL0iPHVu19/FLS0 X-Received: by 2002:a63:3c5:: with SMTP id 188mr6402151pgd.441.1644832538497; Mon, 14 Feb 2022 01:55:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644832538; cv=none; d=google.com; s=arc-20160816; b=MJrbrgrlTIgPNmnF0SRqA4/40UXu6jJq4DSm9UoBsuhF5UwAvDDcSuQCd97ikzQO5Z BKwWzUFpkC8rdxcmltEhXNwMH+jrF7riNt6pj0SfSg2XNqHA6Wohf+Sh2FUeXZtBEzyh V8hiIx8VxDy1/lKVUpCjeiEM/Adq0d8W8FwSssHMaRGK5wXMwhuYK36URFnFHMRf9W09 4nOrj4uTxwz4uVQi005gH4smSBRG+kXqrlPlgUVc8bFbh3RJFs0R4P3RXKlS3YC45nib 3fhoMXSd0IqJNw/0KydkQ01xvahKAbhaxHj2j6pSlKqTbu1by+wjp2SMDcq39STqmovc ufug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kILCWGYQN4aCmOVzGkGgpbDqf3vflThkp2WsD9ah7ls=; b=D1K0GScFLT0Py4xkm+P/215gHTAFx8NTUM38Pjzcwiy4gh+h14YHAs/SRsXmTbYbRK akkT16B4e5od73LVsN0CAREPbN/+0mgK9GkIMoGmrYVVB2J35Goeup7AnFO3bj0U5q7X w0fjgujTgvZVgOpezUNGtlmXaIqXFCCTQdMpaq6vtPaWwfHrXWWHhyXek3CF3ElFsibL WNZPM+zZF/YzMKDAWFWf2nP5+y5rri7RLYGBG02u1+n/Z8zSaKGStX7rva4QTWCHjw8/ KTGXgrEa04z4MVZNdRhid3bBdMtquaEcTdwMK6I3wn4l+Ba9gokC8s8tjCt/JNAeUW4g rN4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=fG95xjXc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d5si24231121pfj.222.2022.02.14.01.55.26; Mon, 14 Feb 2022 01:55:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=fG95xjXc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241629AbiBJMhk (ORCPT + 96 others); Thu, 10 Feb 2022 07:37:40 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:55074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241614AbiBJMhh (ORCPT ); Thu, 10 Feb 2022 07:37:37 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6515AB3 for ; Thu, 10 Feb 2022 04:37:39 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id w1so1700268plb.6 for ; Thu, 10 Feb 2022 04:37:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kILCWGYQN4aCmOVzGkGgpbDqf3vflThkp2WsD9ah7ls=; b=fG95xjXcp5pb/4AZm3qvm7w7s5VMHbtcG0Lx0tYYXqTPxFq3Uc9uBYT7LAv2r+KKbS O4ERCsf/+TVyMN0TI/YJ5AQEXti7JI7zzwU0mLvt4C3cBqleBqOzGfuRZcC1OF+y8qK2 vSoUE7Hf9EA/yx8S3k+43lmfcwEiQw/pT+Qqytcy93VzMeV9T5V1d8vGtrZWnnkTZ83m gsLyBS9KN5r5acorSo3QXiEsgVjacHClEVUDMD4sG3kLdlBslDcPD75Vy3XQBiXZPJMa t7zXdHWqMkokITwK0wwNIOyWHuSRyTfwh6IqmbAlxzQ9Gwc1zYBjlhUYgd302H5unjo9 UwFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kILCWGYQN4aCmOVzGkGgpbDqf3vflThkp2WsD9ah7ls=; b=MC//iyPS0roU4ey1pYO5Kx16K/VhM8qesCrTtuy+4Nq8faQ27LBtOgFuUPAYzvoqLI hbA1XLFFo66i1jatXnV+jU6BC6BN73+ITOMn7MeU7CfaIVLrYLnQ1BQcweRg8Zs6PzLI WlYHFN44M0FPYTqsSa1VOOzthwak0b3uQQA1dHIZvChf1kuw3rx4ici6Etf3gwDIEvG6 FARajU9RPGDmmJgv7kisPhusRoJ7ZYYxFw+6vL+Zzo8pG4DBBldSC6MVFPgAYVWDgXpM TfRMVJ+etTRHLVXaruLe9jsApRbI1VpJgjxkZUxEYQjz9vkSJxGEImdkLLrMRKpkEafm JCsQ== X-Gm-Message-State: AOAM5337Do5IJc5Xx6KnjqyJH9H/IJ+f7QRzb9G8ciyPhcyC3SBToh7j DdOsqXt0A5Fn9DoNqCVxu8KEA7MPztMoJWQP X-Received: by 2002:a17:903:1211:: with SMTP id l17mr7635562plh.11.1644496658991; Thu, 10 Feb 2022 04:37:38 -0800 (PST) Received: from FVFYT0MHHV2J.tiktokcdn.com ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id i8sm11767812pgf.94.2022.02.10.04.37.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 04:37:38 -0800 (PST) From: Muchun Song To: akpm@linux-foundation.org, zi.yan@cs.rutgers.edu, kirill.shutemov@linux.intel.com, rientjes@google.com, lars.persson@axis.com, mike.kravetz@oracle.com, ziy@nvidia.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, fam.zheng@bytedance.com, Muchun Song Subject: [PATCH v5 4/7] mm: hugetlb: fix missing cache flush in hugetlb_mcopy_atomic_pte() Date: Thu, 10 Feb 2022 20:30:55 +0800 Message-Id: <20220210123058.79206-5-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) In-Reply-To: <20220210123058.79206-1-songmuchun@bytedance.com> References: <20220210123058.79206-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org folio_copy() will copy the data from one page to the target page, then the target page will be mapped to the user space address, which might have an alias issue with the kernel address used to copy the data from the page to. There are 2 ways to fix this issue. 1) insert flush_dcache_page() after folio_copy(). 2) replace folio_copy() with copy_user_huge_page() which already considers the cache maintenance. We chose 2) way to fix the issue since architectures can optimize this situation. It is also make backports easier. Fixes: 8cc5fcbb5be8 ("mm, hugetlb: fix racy resv_huge_pages underflow on UFFDIO_COPY") Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz --- mm/hugetlb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a1baa198519a..eba7681d15d0 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5818,7 +5818,8 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, *pagep = NULL; goto out; } - folio_copy(page_folio(page), page_folio(*pagep)); + copy_user_huge_page(page, *pagep, dst_addr, dst_vma, + pages_per_huge_page(h)); put_page(*pagep); *pagep = NULL; } -- 2.11.0