From patchwork Wed Oct 26 09:25:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 9396435 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0E06660231 for ; Wed, 26 Oct 2016 09:26:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDE692836D for ; Wed, 26 Oct 2016 09:26:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B232A28963; Wed, 26 Oct 2016 09:26:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A01B2836D for ; Wed, 26 Oct 2016 09:26:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932368AbcJZJZy (ORCPT ); Wed, 26 Oct 2016 05:25:54 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:35860 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932207AbcJZJZw (ORCPT ); Wed, 26 Oct 2016 05:25:52 -0400 Received: by mail-wm0-f67.google.com with SMTP id c17so470565wmc.3; Wed, 26 Oct 2016 02:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sguopOGyREPn1fyqeqveG/YynBZ/Aj41RA/Fi8oqVIM=; b=NFA8PZN9vJ9JDu/9C3F9aWzkkVpoZEQqZj/RtrfsrUXTzziUUaq39jTfB17co88fow W+Ow0tGhShACK6NurgZDvmZ2ZKQYlXVWk+AgvZbEdT+Bad7SWjFHRcDgespLqE6l1uhd mgBJ/CDc/16asAFghWtaw8ZSLJUEEs2l2vW11EQ0hp7zWwxKoMuZY78G35D0bH8GKDC/ AC46CwBQ/fJ4wUhLYWhEDUxCtaDLFwtjDKbdMTXVaqftlEAokCmslFyJwpd0erBlPLD4 2cZRGm0XQG9rRPGH1M1jxs8vDOjMnawaavYpMmcQk8PLRh8VCgpPUw65sU91O193WUPI abmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sguopOGyREPn1fyqeqveG/YynBZ/Aj41RA/Fi8oqVIM=; b=NOnVgibvx50j9nGrmIZzBorla//7YdVzApB10TiUCVlluBTjiwVSuNjX8w+5xCKwAh KSQK1AK5ONlebkaSIKPhPz+r01OPbMplhgIC6K6TQr1eQVsQX/vDpr20BRy+y7+8jRvx QLArS4EYmh/Y6aqCLDThouOc3F88MVQH97/7uxnR+zZCUSB0/pOgjp8N78Bk729pc+5/ 75qXsl5P/W8OX5/KfbHtOdUbfCJBNrkoxGWil9mDUz724HvWE4yhF7bmcSCFkiCWtvQZ R1+iNeOk+p2x6BQJi6DxQ4sExC8v45taphlrgJ3zcfUExk5KjLfv2/MqLU8Vnv8x4le8 iGYA== X-Gm-Message-State: ABUngvfebWfUIXErx0MNhhXbpl26jnw4s3Teofs0Si1VPPnWhpdVLxB+UMeM8mqVJplnJA== X-Received: by 10.194.235.165 with SMTP id un5mr1288470wjc.200.1477473950249; Wed, 26 Oct 2016 02:25:50 -0700 (PDT) Received: from localhost (cpc94060-newt37-2-0-cust185.19-3.cable.virginm.net. [92.234.204.186]) by smtp.gmail.com with ESMTPSA id k17sm8478885wmd.8.2016.10.26.02.25.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 26 Oct 2016 02:25:48 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org Cc: Linus Torvalds , Michal Hocko , Jan Kara , Hugh Dickins , Dave Hansen , Rik van Riel , Mel Gorman , Andrew Morton , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lorenzo Stoakes Subject: [PATCH v2] mm: remove unnecessary __get_user_pages_unlocked() calls Date: Wed, 26 Oct 2016 10:25:48 +0100 Message-Id: <20161026092548.12712-1-lstoakes@gmail.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161025233609.5601-1-lstoakes@gmail.com> References: <20161025233609.5601-1-lstoakes@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In hva_to_pfn_slow() we are able to replace __get_user_pages_unlocked() with get_user_pages_unlocked() since we can now pass gup_flags. In async_pf_execute() we need to pass different tsk, mm arguments so get_user_pages_remote() is the sane replacement here (having added manual acquisition and release of mmap_sem.) Since we pass a NULL pages parameter the subsequent call to __get_user_pages_locked() will have previously bailed any attempt at VM_FAULT_RETRY, so we do not change this behaviour by using get_user_pages_remote() which does not invoke VM_FAULT_RETRY logic at all. Additionally get_user_pages_remote() reintroduces use of the FOLL_TOUCH flag. However, this flag was originally silently dropped by 1e9877902dc7e ("mm/gup: Introduce get_user_pages_remote()"), so this appears to have been unintentional and reintroducing it is therefore not an issue. Signed-off-by: Lorenzo Stoakes --- v2: update description to reference dropped FOLL_TOUCH flag virt/kvm/async_pf.c | 7 ++++--- virt/kvm/kvm_main.c | 5 ++--- 2 files changed, 6 insertions(+), 6 deletions(-) -- 2.10.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/virt/kvm/async_pf.c b/virt/kvm/async_pf.c index 8035cc1..e8c832c 100644 --- a/virt/kvm/async_pf.c +++ b/virt/kvm/async_pf.c @@ -82,10 +82,11 @@ static void async_pf_execute(struct work_struct *work) /* * This work is run asynchromously to the task which owns * mm and might be done in another context, so we must - * use FOLL_REMOTE. + * access remotely. */ - __get_user_pages_unlocked(NULL, mm, addr, 1, NULL, - FOLL_WRITE | FOLL_REMOTE); + down_read(&mm->mmap_sem); + get_user_pages_remote(NULL, mm, addr, 1, FOLL_WRITE, NULL, NULL); + up_read(&mm->mmap_sem); kvm_async_page_present_sync(vcpu, apf); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 2907b7b..c45d951 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1415,13 +1415,12 @@ static int hva_to_pfn_slow(unsigned long addr, bool *async, bool write_fault, npages = get_user_page_nowait(addr, write_fault, page); up_read(¤t->mm->mmap_sem); } else { - unsigned int flags = FOLL_TOUCH | FOLL_HWPOISON; + unsigned int flags = FOLL_HWPOISON; if (write_fault) flags |= FOLL_WRITE; - npages = __get_user_pages_unlocked(current, current->mm, addr, 1, - page, flags); + npages = get_user_pages_unlocked(addr, 1, page, flags); } if (npages != 1) return npages;