From patchwork Thu Feb 10 12:30:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12741875 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 50452C433F5 for ; Thu, 10 Feb 2022 12:37:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3C9A6B007D; Thu, 10 Feb 2022 07:37:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CEC2D6B007E; Thu, 10 Feb 2022 07:37:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8D068D0001; Thu, 10 Feb 2022 07:37:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0208.hostedemail.com [216.40.44.208]) by kanga.kvack.org (Postfix) with ESMTP id AB4606B007D for ; Thu, 10 Feb 2022 07:37:40 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 5EACF84B33A3 for ; Thu, 10 Feb 2022 12:37:40 +0000 (UTC) X-FDA: 79126821480.23.1636FDC Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf11.hostedemail.com (Postfix) with ESMTP id EACAD40003 for ; Thu, 10 Feb 2022 12:37:39 +0000 (UTC) Received: by mail-pl1-f176.google.com with SMTP id x4so1707665plb.4 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=fl4BVx0o9Qvl2XymMtqgnq9wM24DkgD8CXQfDq5cDzlaJaDeXqgr/FCyZYVXHum5ta 565mOs7h19BXKkzYQae5195RmvDZDxGjRuJvl/p2N7DI0IDcuLNHWIMqzTV4k6Ss+1Cv 50CASFjGdniRnVRu7iE89mGWQAwmiJhs/2BGiSHXINNZY/bcOAIRmpQIwIuRQFZP9hiu XwEKjziY2q4cFtAzWxTBTBrHdUcBU3AFFP3UZjGwXcfOPtph1XxLf+IfNz+eAR+cyOzL iaS+JDvo7+2V+xpZfZbDGY5ul9fJe4KZIPyFqldxc3KSGEOjRcb/rJUch3nvR028gA2e 5ZQg== X-Gm-Message-State: AOAM532HFIAGSZ/qwFzbTRfGcXRfJu0QooEhCX/JS9DAeLq2V7fur/SX 0UaAR66Oyz9xRn96PXIOT3Chpg== X-Google-Smtp-Source: ABdhPJxXO3PdREGl7iYGtPoZwu9ZnEuV9DWQ2+VdIf1bDfCvRiQrzRC1gMtC9rR0cVrUjm5h5t4w8g== 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 Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=fG95xjXc; spf=pass (imf11.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Stat-Signature: 51m1gbjui9cdrruzkky5hksosnskdawb X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: EACAD40003 X-Rspam-User: X-HE-Tag: 1644496659-303241 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: 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; }