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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BCBEC433F5 for ; Mon, 24 Jan 2022 19:14:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346527AbiAXTOB (ORCPT ); Mon, 24 Jan 2022 14:14:01 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:41566 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345298AbiAXTL6 (ORCPT ); Mon, 24 Jan 2022 14:11:58 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 18B0A60BB9; Mon, 24 Jan 2022 19:11:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25D53C340EB; Mon, 24 Jan 2022 19:11:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643051517; bh=ATbwbrhLYhUw5b7slfxUdG2/4HZMt/W6+8bip6jDOLM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ldVqTc/ZcIBEKvYrq6COGH0FSSWXEi7jQnX25+S1uPQXkAYXYvA8B8Cho47e/8Y27 Nf6h2v0u5KXwBYVJ/ecUGTNjRX+W3LxXhjpHyZpu0+lM1Ei+cIVp8BwZ1y0RbV0Byl eE5VTa4hrhJQtiO8iBxjqIxE9Y7J3RVi55TLVP8A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Suren Baghdasaryan , Ben Hutchings Subject: [PATCH 4.14 180/186] mips,s390,sh,sparc: gup: Work around the "COW can break either way" issue Date: Mon, 24 Jan 2022 19:44:15 +0100 Message-Id: <20220124183942.899147289@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183937.101330125@linuxfoundation.org> References: <20220124183937.101330125@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Ben Hutchings In Linux 4.14 and 4.19 these architectures still have their own implementations of get_user_pages_fast(). These also need to force the write flag on when taking the fast path. Fixes: 407faed92b4a ("gup: document and work around "COW can break either way" issue") Fixes: 5e24029791e8 ("gup: document and work around "COW can break either way" issue") Signed-off-by: Ben Hutchings --- arch/mips/mm/gup.c | 9 ++++++++- arch/s390/mm/gup.c | 9 ++++++++- arch/sh/mm/gup.c | 9 ++++++++- arch/sparc/mm/gup.c | 9 ++++++++- 4 files changed, 32 insertions(+), 4 deletions(-) --- a/arch/mips/mm/gup.c +++ b/arch/mips/mm/gup.c @@ -272,7 +272,14 @@ int get_user_pages_fast(unsigned long st next = pgd_addr_end(addr, end); if (pgd_none(pgd)) goto slow; - if (!gup_pud_range(pgd, addr, next, write, pages, &nr)) + /* + * The FAST_GUP case requires FOLL_WRITE even for pure reads, + * because get_user_pages() may need to cause an early COW in + * order to avoid confusing the normal COW routines. So only + * targets that are already writable are safe to do by just + * looking at the page tables. + */ + if (!gup_pud_range(pgd, addr, next, 1, pages, &nr)) goto slow; } while (pgdp++, addr = next, addr != end); local_irq_enable(); --- a/arch/s390/mm/gup.c +++ b/arch/s390/mm/gup.c @@ -285,7 +285,14 @@ int get_user_pages_fast(unsigned long st might_sleep(); start &= PAGE_MASK; - nr = __get_user_pages_fast(start, nr_pages, write, pages); + /* + * The FAST_GUP case requires FOLL_WRITE even for pure reads, + * because get_user_pages() may need to cause an early COW in + * order to avoid confusing the normal COW routines. So only + * targets that are already writable are safe to do by just + * looking at the page tables. + */ + nr = __get_user_pages_fast(start, nr_pages, 1, pages); if (nr == nr_pages) return nr; --- a/arch/sh/mm/gup.c +++ b/arch/sh/mm/gup.c @@ -240,7 +240,14 @@ int get_user_pages_fast(unsigned long st next = pgd_addr_end(addr, end); if (pgd_none(pgd)) goto slow; - if (!gup_pud_range(pgd, addr, next, write, pages, &nr)) + /* + * The FAST_GUP case requires FOLL_WRITE even for pure reads, + * because get_user_pages() may need to cause an early COW in + * order to avoid confusing the normal COW routines. So only + * targets that are already writable are safe to do by just + * looking at the page tables. + */ + if (!gup_pud_range(pgd, addr, next, 1, pages, &nr)) goto slow; } while (pgdp++, addr = next, addr != end); local_irq_enable(); --- a/arch/sparc/mm/gup.c +++ b/arch/sparc/mm/gup.c @@ -262,7 +262,14 @@ int get_user_pages_fast(unsigned long st next = pgd_addr_end(addr, end); if (pgd_none(pgd)) goto slow; - if (!gup_pud_range(pgd, addr, next, write, pages, &nr)) + /* + * The FAST_GUP case requires FOLL_WRITE even for pure reads, + * because get_user_pages() may need to cause an early COW in + * order to avoid confusing the normal COW routines. So only + * targets that are already writable are safe to do by just + * looking at the page tables. + */ + if (!gup_pud_range(pgd, addr, next, 1, pages, &nr)) goto slow; } while (pgdp++, addr = next, addr != end);