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 6B247C7EE24 for ; Tue, 16 May 2023 09:49:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232143AbjEPJt2 (ORCPT ); Tue, 16 May 2023 05:49:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231992AbjEPJt1 (ORCPT ); Tue, 16 May 2023 05:49:27 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84B3A2D62 for ; Tue, 16 May 2023 02:49:24 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4f14ec8d72aso14024853e87.1 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=JDlPWPb0hxUfvoFxr5WNufDWTsphGwnCso9WFXtezOpK1k2bfMX6ylTRPWt7bcH1Cs Q9aaeiA3I0sNL6GscMiZcOCYmDMLiVlpzr9EPWbXmQYCE625UauitCEZiT/MbJ8zlYCj WJIXWxWiUOY5v/Wwg0ql+B15CyHEBVEpKFMCKYOKGCzrGCPwrt/g54vluRIQOSTFgaFY n67SeH9cg57EtR9h2n+1TfQmqtSVZfwCI/ycMqgu9q10sIkDL21qSAETmOHUB/87B9I/ y8qC2S6/1pLc83mMmnFy91QhxOiCXSHWZrI4CEaX58A865dyAhhf7HNyBdfICEjRM7mr l/4A== X-Gm-Message-State: AC+VfDwDrBclhHx3PhYM4MxHtaxxPPOtit8r2DW/zhDlXwiPNpHv4zDq +gus4tP26iE1d4XXgqijaDOQ7Q== X-Google-Smtp-Source: ACHHUZ4l3TyALRDEaGcVcIkdK7q9mH/ov5OVGGAezktN7u9QG834/IDjSuCD7zTf56ZU9ouww0Hd6Q== 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) Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@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