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 X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A59EC433E7 for ; Tue, 1 Sep 2020 16:15:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C4DC320767 for ; Tue, 1 Sep 2020 16:15:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="DMJZzRBu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C4DC320767 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 518A590000C; Tue, 1 Sep 2020 12:15:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4EDB8900002; Tue, 1 Sep 2020 12:15:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 404F490000C; Tue, 1 Sep 2020 12:15:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0038.hostedemail.com [216.40.44.38]) by kanga.kvack.org (Postfix) with ESMTP id 26D93900002 for ; Tue, 1 Sep 2020 12:15:45 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id CFD6F3623 for ; Tue, 1 Sep 2020 16:15:44 +0000 (UTC) X-FDA: 77214993408.29.woman31_281194227099 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id 747BE180868FA for ; Tue, 1 Sep 2020 16:15:41 +0000 (UTC) X-HE-Tag: woman31_281194227099 X-Filterd-Recvd-Size: 7846 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Tue, 1 Sep 2020 16:15:39 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id m5so925354pgj.9 for ; Tue, 01 Sep 2020 09:15:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U1h0WFxrmlZti/5PdriJmCxO8e4BuJ9nFjihIY3qycs=; b=DMJZzRBurdYUN4x8gReiESvjIjB6WMHksdeGaRDN41WunAsqZ5Yvt1bO5dntkRFy3t 8wwhIkp4rgfa2J7aKnYStujtMWjfHwnF6BkSHyc7XPqxl15S8Wx58seJIlrKeXoJmuGj MQaukCMelikiVQ/1Wm711W7exb+6DNt43lv72RbxdW6K74pL+q9Y56zYnklCSiMeeL35 pRebHGva3Zi2MmJ3dxDLMqa5QnCLLLYiGadJKrLiaLGeasmp+w0PpyFwxsv0zQw8Or3z 1eho9mmEcHG7AK6OcGSov1ce9KH+R9Js6Mtep8s4aW9yT+PGaaaWQiXvT8tY8YznovIj 7SWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U1h0WFxrmlZti/5PdriJmCxO8e4BuJ9nFjihIY3qycs=; b=WBUuCb9b9YhDUMqSNRYLYHfjyaHB8EwB6HqqaEGNTMy/1nfJbbVVlidgZPUTMCnP6t yOb8MZ2z7QmBCrB5oi33bRcyDnCRIOqE0tCBbeAjKYGvNq2G4hl5tJtWQzSQ5vVn/C3c Vou/PV7pwflA9wmijPoVjcibM62pCsgY9GKn+1jpbCJ8DdVh6S9onYhoWSY/m+JAp2fD uedC3szVXUohR7nvcjnSwL231cAgVo/1XwVv7Cvku9Ri3/ymD7NDjcg9ncyScF7a70sU oLSKA/sXdjrqgEQXxeNKWHH3SxBO7OrWq7/B4MTwVcNqb7TDCQPXM75vaWMMo1qpmpo/ FABg== X-Gm-Message-State: AOAM531BNv1cHz1S7WpWCF1ubu6ab38hLYBsIbVAXk9Sm/LcQvs80wGl H50aAF2POP3cEmEJF9D3CezCDA== X-Google-Smtp-Source: ABdhPJzWV89RR/QWyu3dI160WKOjSKjBNJugNB1VuwvaljQHlhcb659AvPrOk3k8yapRkjnyxkRAeg== X-Received: by 2002:a63:1b42:: with SMTP id b2mr1968103pgm.397.1598976938667; Tue, 01 Sep 2020 09:15:38 -0700 (PDT) Received: from nagraj.lan ([175.100.146.50]) by smtp.gmail.com with ESMTPSA id d77sm2553169pfd.121.2020.09.01.09.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 09:15:37 -0700 (PDT) From: Sumit Semwal To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Alexey Dobriyan , Jonathan Corbet Cc: Mauro Carvalho Chehab , Kees Cook , Michal Hocko , Colin Cross , Alexey Gladkov , Matthew Wilcox , Jason Gunthorpe , "Kirill A . Shutemov" , Michel Lespinasse , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Song Liu , Huang Ying , Vlastimil Babka , Yang Shi , chenqiwu , Mathieu Desnoyers , John Hubbard , Mike Christie , Bart Van Assche , Amit Pundir , Thomas Gleixner , Christian Brauner , Daniel Jordan , Adrian Reber , Nicolas Viennot , Al Viro , linux-fsdevel@vger.kernel.org, John Stultz , Sumit Semwal Subject: [PATCH v7 2/3] mm: memory: Add access_remote_vm_locked variant Date: Tue, 1 Sep 2020 21:44:58 +0530 Message-Id: <20200901161459.11772-3-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901161459.11772-1-sumit.semwal@linaro.org> References: <20200901161459.11772-1-sumit.semwal@linaro.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 747BE180868FA X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This allows accessing a remote vm while the mmap_lock is already held by the caller. While adding support for anonymous vma naming, show_map_vma() needs to access the remote vm to get the name of the anonymous vma. Since show_map_vma() already holds the mmap_lock, so this _locked variant was required. Signed-off-by: Sumit Semwal --- include/linux/mm.h | 2 ++ mm/memory.c | 49 ++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index ca6e6a81576b..e9212c0bb5ac 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1708,6 +1708,8 @@ extern int access_remote_vm(struct mm_struct *mm, u= nsigned long addr, void *buf, int len, unsigned int gup_flags); extern int __access_remote_vm(struct task_struct *tsk, struct mm_struct = *mm, unsigned long addr, void *buf, int len, unsigned int gup_flags); +extern int access_remote_vm_locked(struct mm_struct *mm, unsigned long a= ddr, + void *buf, int len, unsigned int gup_flags); =20 long get_user_pages_remote(struct mm_struct *mm, unsigned long start, unsigned long nr_pages, diff --git a/mm/memory.c b/mm/memory.c index 602f4283122f..207be99390e9 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4726,17 +4726,17 @@ EXPORT_SYMBOL_GPL(generic_access_phys); /* * Access another process' address space as given in mm. If non-NULL, u= se the * given task for page fault accounting. + * This variant assumes that the mmap_lock is already held by the caller= , so + * doesn't take the mmap_lock. */ -int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm, - unsigned long addr, void *buf, int len, unsigned int gup_flags) +int __access_remote_vm_locked(struct task_struct *tsk, struct mm_struct = *mm, + unsigned long addr, void *buf, int len, + unsigned int gup_flags) { struct vm_area_struct *vma; void *old_buf =3D buf; int write =3D gup_flags & FOLL_WRITE; =20 - if (mmap_read_lock_killable(mm)) - return 0; - /* ignore errors, just check how much was successfully transferred */ while (len) { int bytes, ret, offset; @@ -4785,9 +4785,46 @@ int __access_remote_vm(struct task_struct *tsk, st= ruct mm_struct *mm, buf +=3D bytes; addr +=3D bytes; } + return buf - old_buf; +} + +/* + * Access another process' address space as given in mm. If non-NULL, u= se the + * given task for page fault accounting. + */ +int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm, + unsigned long addr, void *buf, int len, unsigned int gup_flags) +{ + int ret; + + if (mmap_read_lock_killable(mm)) + return 0; + + ret =3D __access_remote_vm_locked(tsk, mm, addr, buf, len, gup_flags); mmap_read_unlock(mm); =20 - return buf - old_buf; + return ret; +} + +/** + * access_remote_vm_locked - access another process' address space, with= out + * taking the mmap_lock. This allows nested calls from callers that alre= ady have + * taken the lock. + * + * @mm: the mm_struct of the target address space + * @addr: start address to access + * @buf: source or destination buffer + * @len: number of bytes to transfer + * @gup_flags: flags modifying lookup behaviour + * + * The caller must hold a reference on @mm, as well as hold the mmap_loc= k + * + * Return: number of bytes copied from source to destination. + */ +int access_remote_vm_locked(struct mm_struct *mm, unsigned long addr, vo= id *buf, + int len, unsigned int gup_flags) +{ + return __access_remote_vm_locked(NULL, mm, addr, buf, len, gup_flags); } =20 /** --=20 2.28.0