Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3564624pxb; Mon, 24 Jan 2022 12:19:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwiV8uM1+cYeyvInyoFUmFYuOotJGwQQ2H30jsGKOAjhJxKFKGm5DYnferHKf5CFiRz+wBx X-Received: by 2002:a17:90b:1e05:: with SMTP id pg5mr25448pjb.86.1643055473130; Mon, 24 Jan 2022 12:17:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643055473; cv=none; d=google.com; s=arc-20160816; b=dDpuSUDkCpVAXT5CleV0IhObwlwsrzPZXNrxWfcWkdOYknROouyAftE/TbtOwapT6K k0M3KFX61R2rU2Ur2uQ5q61oXPiOnsADtltJWLM22gAzzxIy37s/yyat2Zr6iiyyD9Cs Eqsu7jBjmspVoM5s73c7A+dkGx1uIDTyNf9sVEf1W75ZbYFo3OqrWBkxfY5csgFvDxGe BbFHfryGLmxoXPRCDgAEsEkbLDxZhwXX8FUR2+AHzYF9qwqk3okNFIAN1rvSllzROCJO dCVp2S4CWazshTPwcG8Y8JKdY4b13MQsUy/WDro5vsaatCG9ctHVyGFApYXOdqJC4fVy 9hmg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=H+w205EJAstQ4+IxApo8Mg1xrsvTxeDUwRPmB+prLSY=; b=JFWCTJM4TnyPy2aMircUaKStYPDFHb245KxDVJBtbHbP1CPQASs4/PnD7Vho4qIl0y GBX/xL1jCM2mLDNKHXiXNHvYa7/7BT8SNQixQvKTPIjPKi9tMtBsRT33OqsTm9ZgkgeK mZbwlY4gbarzxsS75jukRw1+HDz+bMTSznU0nzJwjeWSTZpirFRW4FEV0Gll6PLyxFqt 5ZAupPlJnd/TX5C3tNuIc3ODjsMo/nohEC/804yNRPOQNA46AB1lG67JbqMheqZYMx9o zH4QGivhOu30HNQtnu/TU60PP7A5FC/IIcb0shSdtMZBkqd6i+DqGnWX7mRCDUaxlfoN TEpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ldVqTc/Z"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m5si14888318pgb.728.2022.01.24.12.17.40; Mon, 24 Jan 2022 12:17:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ldVqTc/Z"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349136AbiAXTUT (ORCPT + 99 others); Mon, 24 Jan 2022 14:20:19 -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: linux-kernel@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);