Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp415054rwd; Tue, 16 May 2023 02:55:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6dlCM3SFX+K9xx6PNRQpvm5M7ui4S8IKxpXu0dL0IoaXqzhUIR7x+2gx4DTsPWMs7dS4Yy X-Received: by 2002:a17:90a:eb12:b0:24e:9e6:7067 with SMTP id j18-20020a17090aeb1200b0024e09e67067mr35277968pjz.7.1684230927689; Tue, 16 May 2023 02:55:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684230927; cv=none; d=google.com; s=arc-20160816; b=oZkqU1GzA7Zy+k+FUggBgc8P6bs8pL6Atrrq0nDMRg0JMMwFu4NJt/q1scxDZtu19z mKMZKcM3101UqQv6ayzyiNOXLPyfGrO9AXTnvavjVvP9ABKExMLomvTgqGN739ZMWEMC 20QUhMhWXMXGoL4yxjQSCqTHHlSo6gjIvBQIm1ovRtGwhokh3DI3Yp8W6QknSYtXTMRz vW74zzXJ5FmeE1IrLHxANEFHKGIz6LRMO4IeDBz1LkkuWQUInxzjuz9Pk+3OCnl+dd+8 vwkcCHy5kIcIy+OTfeoh0GnhPTw7pdh9I2Mi9PyVc7N8EnZKqHVckASeVM3FhnlcaDmE EKNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=ZU/9Bd1F4v4AQI4XYwGvMKtVUVhP+Ta/KlDV/Ofhgvw=; b=NoWmygUvW0anocqvaWwFllcz4hBuq6gEtfXxpdNqWcu+xW6uDCwPeVn3Frg0FqW8eF /fzc+DDH0EbMiHav3NjHwMcRoM2R+0iwstaYnlhQ7jKSPfKb7mpc6sflDcQn6eIbYlAe TnYpk/J20kq1+zbZnnPvgeHErbF2bOo0X4g5ymyrFOAjdS6pzsRQjsI6ZWuhENZ0leAO CAb2wSFCOlkCjPzgCwGLoGfR186ZaJldpBfq6l8cHhtgR0rcY11pXzFccy8uNcRZMXTV N5DU6OqOjZLSWRGmScUqqX/wpkm5IkPvole2kUgyzJK1V4eY+jjBeGKH5gYgt/2CIQml LBog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DLO9Sp+4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k17-20020a637b51000000b00533ffeaca3dsi6203609pgn.40.2023.05.16.02.55.11; Tue, 16 May 2023 02:55:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DLO9Sp+4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232147AbjEPJt3 (ORCPT + 99 others); Tue, 16 May 2023 05:49:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231558AbjEPJt0 (ORCPT ); Tue, 16 May 2023 05:49:26 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83EF42D55 for ; Tue, 16 May 2023 02:49:24 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-4f24ddf514eso12309545e87.0 for ; Tue, 16 May 2023 02:49:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684230563; x=1686822563; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=ZU/9Bd1F4v4AQI4XYwGvMKtVUVhP+Ta/KlDV/Ofhgvw=; b=DLO9Sp+4W+z5eLJ4OplpY56KL7dsXPxPyKzZN31e24ZgWla/8bs4IkvAtRU1sNrr4d M/zIAUZjhZlW4P2rkk7T+6W0UVsyD90WG+YdGYFrH/Glii/KUDZq0IpUmntg707CdF5n i37UB3Tbbcas87bL0/efYfe6w3ZnC5XyG3qMqn02SGpfBU+8hNkNlrN1nhw2lKAkzq5B CRMAVzp4RUPFc/3/QZ675+4TlLXQLlc1iMNrOb5F/K4RaFPvTUMi9nJBxjhqICMZPBab XEfOKIgxNn+kxSFXUOWAg+ZiVcGCmn7Ho0MHbSwpND8R8HARcto93DQrGrEkUYhsomoF 2BmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684230563; x=1686822563; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZU/9Bd1F4v4AQI4XYwGvMKtVUVhP+Ta/KlDV/Ofhgvw=; b=UnOo/Sb74qGznp1+LXR38p78eiGiPLcldH99mVGsqoQZ5a5oRYh+PdRutv9N/0DWaY qEqXxT9+5QU8ihxgs0MM+5VxnJX+T0ilGG3gdq8UJnyTSxGVng/HpX7q6pbbrM/e3MBD h9cXNjNhMhOxWpc+77xr9Zv+LiwVLwjZ3tuykBPCNZzZQJn7jik9V+zBwBgyY3rQY6JF 12Gmtr5IuuWzIDEOa3+xFgefQSV2Fdjwf6YgUZ8FGUu4J6bZLVAkLxupxGk25Z5n0ouj VnMK//Jc4ZGMxMFcpWG5f7n2jQNa3jRmWjeB2nXoFfLXMAQuVzKekaqTcmrDi9kRG+Ty 3pQg== X-Gm-Message-State: AC+VfDws781Z1GPbOei9+XumVb/mcAehlRnFJtsiVjWqjb7x9H3QY92k +zWTLSr/HOBPTntxXQGY27JOKg== X-Received: by 2002:a05:6512:2181:b0:4e8:4a21:9c92 with SMTP id b1-20020a056512218100b004e84a219c92mr7419897lft.4.1684230562687; Tue, 16 May 2023 02:49:22 -0700 (PDT) Received: from mutt (c-9b0ee555.07-21-73746f28.bbcust.telenor.se. [85.229.14.155]) by smtp.gmail.com with ESMTPSA id w11-20020a19c50b000000b004f251cf3d31sm2908003lfe.153.2023.05.16.02.49.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 02:49:21 -0700 (PDT) Date: Tue, 16 May 2023 11:49:19 +0200 From: Anders Roxell To: Lorenzo Stoakes Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Matthew Wilcox , David Hildenbrand , linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-security-module@vger.kernel.org, Catalin Marinas , Will Deacon , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Sven Schnelle , Eric Biederman , Kees Cook , Alexander Viro , Christian Brauner , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kentaro Takeda , Tetsuo Handa , Paul Moore , James Morris , "Serge E . Hallyn" , Paolo Bonzini , Jens Axboe , Pavel Begunkov , Jason Gunthorpe , John Hubbard Subject: Re: [PATCH v5 3/6] mm/gup: remove vmas parameter from get_user_pages_remote() Message-ID: <20230516094919.GA411@mutt> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023-05-14 22:26, Lorenzo Stoakes wrote: > The only instances of get_user_pages_remote() invocations which used the > vmas parameter were for a single page which can instead simply look up the > VMA directly. In particular:- > > - __update_ref_ctr() looked up the VMA but did nothing with it so we simply > remove it. > > - __access_remote_vm() was already using vma_lookup() when the original > lookup failed so by doing the lookup directly this also de-duplicates the > code. > > We are able to perform these VMA operations as we already hold the > mmap_lock in order to be able to call get_user_pages_remote(). > > As part of this work we add get_user_page_vma_remote() which abstracts the > VMA lookup, error handling and decrementing the page reference count should > the VMA lookup fail. > > This forms part of a broader set of patches intended to eliminate the vmas > parameter altogether. > > Reviewed-by: Catalin Marinas (for arm64) > Acked-by: David Hildenbrand > Reviewed-by: Janosch Frank (for s390) > Signed-off-by: Lorenzo Stoakes > --- > arch/arm64/kernel/mte.c | 17 +++++++++-------- > arch/s390/kvm/interrupt.c | 2 +- > fs/exec.c | 2 +- > include/linux/mm.h | 34 +++++++++++++++++++++++++++++++--- > kernel/events/uprobes.c | 13 +++++-------- > mm/gup.c | 12 ++++-------- > mm/memory.c | 14 +++++++------- > mm/rmap.c | 2 +- > security/tomoyo/domain.c | 2 +- > virt/kvm/async_pf.c | 3 +-- > 10 files changed, 61 insertions(+), 40 deletions(-) > [...] > diff --git a/mm/memory.c b/mm/memory.c > index 146bb94764f8..63632a5eafc1 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -5590,7 +5590,6 @@ EXPORT_SYMBOL_GPL(generic_access_phys); > int __access_remote_vm(struct mm_struct *mm, unsigned long addr, void *buf, > int len, unsigned int gup_flags) > { > - struct vm_area_struct *vma; > void *old_buf = buf; > int write = gup_flags & FOLL_WRITE; > > @@ -5599,13 +5598,15 @@ int __access_remote_vm(struct mm_struct *mm, unsigned long addr, void *buf, > > /* ignore errors, just check how much was successfully transferred */ > while (len) { > - int bytes, ret, offset; > + int bytes, offset; > void *maddr; > - struct page *page = NULL; > + struct vm_area_struct *vma; > + struct page *page = get_user_page_vma_remote(mm, addr, > + gup_flags, &vma); > + > + if (IS_ERR_OR_NULL(page)) { > + int ret = 0; I see the warning below when building without CONFIG_HAVE_IOREMAP_PROT set. make --silent --keep-going --jobs=32 \ O=/home/anders/.cache/tuxmake/builds/1244/build ARCH=arm \ CROSS_COMPILE=arm-linux-gnueabihf- /home/anders/src/kernel/next/mm/memory.c: In function '__access_remote_vm': /home/anders/src/kernel/next/mm/memory.c:5608:29: warning: unused variable 'ret' [-Wunused-variable] 5608 | int ret = 0; | ^~~ > > - ret = get_user_pages_remote(mm, addr, 1, > - gup_flags, &page, &vma, NULL); > - if (ret <= 0) { > #ifndef CONFIG_HAVE_IOREMAP_PROT > break; > #else > @@ -5613,7 +5614,6 @@ int __access_remote_vm(struct mm_struct *mm, unsigned long addr, void *buf, > * Check if this is a VM_IO | VM_PFNMAP VMA, which > * we can access using slightly different code. > */ > - vma = vma_lookup(mm, addr); > if (!vma) > break; > if (vma->vm_ops && vma->vm_ops->access) Cheers, Anders