Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2001992imu; Fri, 14 Dec 2018 04:19:32 -0800 (PST) X-Google-Smtp-Source: AFSGD/VdK7Sf7zPbcLJporw04craz45bxzMY0NDUZOxI07Eg9QeMzaF+55zRrdeEe6c87Die3Vjw X-Received: by 2002:a63:7a09:: with SMTP id v9mr1203226pgc.112.1544789972371; Fri, 14 Dec 2018 04:19:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544789972; cv=none; d=google.com; s=arc-20160816; b=ze3iYunT8AgfO8rz6qbPku1dTdghrnvHkNEWxfUT2I1DCcLN3rfmQPN5AlUW3/K7ac CNNJ8IpKSTmnNisK87iWGoN5K/2WiSDzy6XGiz+U0aCFpVb4sTfG7XLoWInDqhXdhhCx jS9nt+XueT1p9HrLq/StysbtWDd/0hQ4uGazKf5XOYhvZGYUqsOl4SCCLiM0XB7pOeqW DKZ5A4RXzjNkCTyNUwiryXfevU8pnB9y3DpUNHq06cJKPD3hmqoVa3LNZ82qIfr3EIAk fBbXlTPnXxfW00rzoi014WrQUBFm8CG9S9qUwwODd2vqr1susfIenmgRaNobodxgY6rH UzWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wE9FMLP5J7QobaC1rlapupPY9+3pWJ30Ks442MVoPhY=; b=nFIvRXWkwlhFf3Ey1AQ5sQ5MwUOpZvcP5ZqXEEinpmnbozZjoyotvkd0Hq4Xy+Sxdz FyaYDbMBzK/RBqJ2vWisO1Dy2cfcTw3jokpeQsB+8sDM2w0IfhKOxJTmiwcgJkVchT7J xkZe7v8Nh8DmNsRDOMFSsEewiTc8I+/fVRErrFLUz1aY/BgZLyD9RPW9gfWDrCM5YN/6 4yrRjtb1kcRjczrKoJWfyE/HZ8tLoT6d60dWYfohJz8RUuTwa5TQW3v+08L44WEBiFvt 77q/NP0f7vNeLJbf8AhLXWNMxYtY8n2Rdx/w9kz9IL8npO98lLCyMvkFx9uvR2cy0Adg 60Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Eyg4EoHt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 21si3921379pgk.74.2018.12.14.04.19.17; Fri, 14 Dec 2018 04:19:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Eyg4EoHt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732756AbeLNMQ2 (ORCPT + 99 others); Fri, 14 Dec 2018 07:16:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:36582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732139AbeLNMQY (ORCPT ); Fri, 14 Dec 2018 07:16:24 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DCD20214AE; Fri, 14 Dec 2018 12:16:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544789783; bh=5tlCNz3LZdp1AVGKLX9V++84n+pRM+5khOfoONeLZig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Eyg4EoHtgVGUBNsRw+zlomzPPH1dWNg0A2c1ZraHo0LvW+lLDFjkfqIpuWXZB5XcA +FMXik1diXDOTpNT9o5NckUuShJYSMBMFrLR0pHA1ocLWEa7CMGDmKP6LdPw9NqBxf GWPj9xod0cXAUXAu43cbHUHhPsl6f1K2CADVGVoQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lorenzo Stoakes , Paolo Bonzini , Jan Kara , Michal Hocko , Linus Torvalds , Ben Hutchings Subject: [PATCH 4.4 75/88] mm: remove write/force parameters from __get_user_pages_unlocked() Date: Fri, 14 Dec 2018 13:00:49 +0100 Message-Id: <20181214115708.360510296@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181214115702.151309521@linuxfoundation.org> References: <20181214115702.151309521@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lorenzo Stoakes commit d4944b0ecec0af882483fe44b66729316e575208 upstream. This removes the redundant 'write' and 'force' parameters from __get_user_pages_unlocked() to make the use of FOLL_FORCE explicit in callers as use of this flag can result in surprising behaviour (and hence bugs) within the mm subsystem. Signed-off-by: Lorenzo Stoakes Acked-by: Paolo Bonzini Reviewed-by: Jan Kara Acked-by: Michal Hocko Signed-off-by: Linus Torvalds [bwh: Backported to 4.4: - Defer changes in process_vm_rw_single_vec() and async_pf_execute() since they use get_user_pages_unlocked() here - Adjust context] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- include/linux/mm.h | 3 +-- mm/gup.c | 19 ++++++++++--------- mm/nommu.c | 14 ++++++++++---- virt/kvm/kvm_main.c | 11 ++++++++--- 4 files changed, 29 insertions(+), 18 deletions(-) --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1207,8 +1207,7 @@ long get_user_pages_locked(struct task_s int *locked); long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm, unsigned long start, unsigned long nr_pages, - int write, int force, struct page **pages, - unsigned int gup_flags); + struct page **pages, unsigned int gup_flags); long get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm, unsigned long start, unsigned long nr_pages, int write, int force, struct page **pages); --- a/mm/gup.c +++ b/mm/gup.c @@ -764,17 +764,11 @@ EXPORT_SYMBOL(get_user_pages_locked); */ __always_inline long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm, unsigned long start, unsigned long nr_pages, - int write, int force, struct page **pages, - unsigned int gup_flags) + struct page **pages, unsigned int gup_flags) { long ret; int locked = 1; - if (write) - gup_flags |= FOLL_WRITE; - if (force) - gup_flags |= FOLL_FORCE; - down_read(&mm->mmap_sem); ret = __get_user_pages_locked(tsk, mm, start, nr_pages, pages, NULL, &locked, false, gup_flags); @@ -805,8 +799,15 @@ long get_user_pages_unlocked(struct task unsigned long start, unsigned long nr_pages, int write, int force, struct page **pages) { - return __get_user_pages_unlocked(tsk, mm, start, nr_pages, write, - force, pages, FOLL_TOUCH); + unsigned int flags = FOLL_TOUCH; + + if (write) + flags |= FOLL_WRITE; + if (force) + flags |= FOLL_FORCE; + + return __get_user_pages_unlocked(tsk, mm, start, nr_pages, + pages, flags); } EXPORT_SYMBOL(get_user_pages_unlocked); --- a/mm/nommu.c +++ b/mm/nommu.c @@ -211,8 +211,7 @@ EXPORT_SYMBOL(get_user_pages_locked); long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm, unsigned long start, unsigned long nr_pages, - int write, int force, struct page **pages, - unsigned int gup_flags) + struct page **pages, unsigned int gup_flags) { long ret; down_read(&mm->mmap_sem); @@ -227,8 +226,15 @@ long get_user_pages_unlocked(struct task unsigned long start, unsigned long nr_pages, int write, int force, struct page **pages) { - return __get_user_pages_unlocked(tsk, mm, start, nr_pages, write, - force, pages, 0); + unsigned int flags = 0; + + if (write) + flags |= FOLL_WRITE; + if (force) + flags |= FOLL_FORCE; + + return __get_user_pages_unlocked(tsk, mm, start, nr_pages, + pages, flags); } EXPORT_SYMBOL(get_user_pages_unlocked); --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1352,10 +1352,15 @@ static int hva_to_pfn_slow(unsigned long npages = get_user_page_nowait(current, current->mm, addr, write_fault, page); up_read(¤t->mm->mmap_sem); - } else + } else { + unsigned int flags = FOLL_TOUCH | FOLL_HWPOISON; + + if (write_fault) + flags |= FOLL_WRITE; + npages = __get_user_pages_unlocked(current, current->mm, addr, 1, - write_fault, 0, page, - FOLL_TOUCH|FOLL_HWPOISON); + page, flags); + } if (npages != 1) return npages;