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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC32AC4332F for ; Wed, 4 Jan 2023 19:56:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 69BAB8E0003; Wed, 4 Jan 2023 14:56:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 64BDE8E0001; Wed, 4 Jan 2023 14:56:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 513EC8E0003; Wed, 4 Jan 2023 14:56:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 40A968E0001 for ; Wed, 4 Jan 2023 14:56:40 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id DC3E1A0C6A for ; Wed, 4 Jan 2023 19:56:39 +0000 (UTC) X-FDA: 80318174118.20.F7CFFFD Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by imf12.hostedemail.com (Postfix) with ESMTP id 3068740005 for ; Wed, 4 Jan 2023 19:56:37 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=piWDU7gL; spf=pass (imf12.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.52 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672862198; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1ifeoxPcOFrYuK6F+TgbiUrd0ztltIDwUxl6It3jUMk=; b=Vq+cNnJz5DGfqb6wZNSHSvo7fbrs2HxrdODl+9cVZ/PNzfMm7Nx0oGP92hbw7/wkmyjzZJ rKySrkXVpK6PghzA/1InH1xtWO1EukvMM283JegBOVTbrocivQAOCD/P263eYgextCE3ST 3anS8aIOcHOMK7MoWmLbqn4CIIy8HUs= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=piWDU7gL; spf=pass (imf12.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.52 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672862198; a=rsa-sha256; cv=none; b=KN6Ifn6kWP52wI56ukwuhrKR6shXLynG3BuckXkvkNd2G/fAAA1gZlZhw9MCQ9VvMTW+hu Xf+QHDkFu/xRS7uCL4iTOv22wV5NfpbPt331yhcCCaP67JIo1tQ29AoyzTrKWpMseXY7m/ J0gmRJ7xAdA2SuoNevZ5Ifth6Rcjn0o= Received: by mail-wm1-f52.google.com with SMTP id bg13-20020a05600c3c8d00b003d9712b29d2so24775920wmb.2 for ; Wed, 04 Jan 2023 11:56:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=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=1ifeoxPcOFrYuK6F+TgbiUrd0ztltIDwUxl6It3jUMk=; b=piWDU7gL1nHMrxwQ0Q/NCykuPeih/kHlzWdGfZ0BCEGNV55R3hU5HSrtsZb16U4A5I 36syKEZYqrFQGb9ghe8S46YDHiUJK47SuxWjB0ZSOO/cTLkMtQjjVDqORF1cTi1NKMZQ rAmzYEt78dzhOma2zQByCQZpG87aO8VwBzd8Gxoy3mAv6cWEfOEU53aj/PUuORF4xxGR eqHUa6EP5ssp2Aun6ImGBq/vZlYa4N+CSaDiRMNirol752AYeuMQzOKK/z6fwvhbbuYS LuqAKg3rNEhxnG8qsOMgxzgyfsS27UB/8ZF/tOn1mddyM2yaNpK6qADe9ndv/4dff/HW Z5Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=1ifeoxPcOFrYuK6F+TgbiUrd0ztltIDwUxl6It3jUMk=; b=A+Twif90qtscD/J4b69yjyVwzxkR3wVCoHxOUfPJrbnLStBhW2hxD5I2S9Onj4PRSq 9dnG8cvxNxTBjgJ/uMQ7n7M3Jp7veA1AqEBaTmmEEdTlA59JNrmonJaEbIdEtIO42edR GQ9H5PvFgr9Q3butFFXGdK3Q17Zb2gSUmU/CpV1HGIy6hLaBRapOKu7lzuJc/sT2Kf4W JG2g5diEUU9dApl/0hqmjB/ZmJ97JEOKtDXrdUZxWXjD/NtT61cocYQe7HlCHU4diaBW QVYSq4g1tO+7w0HB40lmvpR8fRIkiMUnUF5iBTvY+2BavMG3f24o1qgwKaH9dbKFF8Jt MyfA== X-Gm-Message-State: AFqh2kprJOuN8bi6kTMbH7+ZHdoFXToZJQBgJDH87myT5hdg8Uy0ckQM 4wwRB+9N8WBuz7hD5fJ/kZY= X-Google-Smtp-Source: AMrXdXt2CKt2uukWx7vXejwlNDs9tCcYERDZuM0p1LGX1G51+lHvyxi1Qz0KV/uvtTgf1jfStOeppg== X-Received: by 2002:a05:600c:5006:b0:3d2:3eda:dd1 with SMTP id n6-20020a05600c500600b003d23eda0dd1mr35033523wmr.17.1672862196590; Wed, 04 Jan 2023 11:56:36 -0800 (PST) Received: from localhost (host81-157-153-247.range81-157.btcentralplus.com. [81.157.153.247]) by smtp.gmail.com with ESMTPSA id x7-20020a05600c2d0700b003c6c3fb3cf6sm44978164wmf.18.2023.01.04.11.56.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 11:56:35 -0800 (PST) Date: Wed, 4 Jan 2023 19:56:35 +0000 From: Lorenzo Stoakes To: Alistair Popple Cc: "Yu, Fenghua" , Vinod Koul , "Jiang, Dave" , "dmaengine@vger.kernel.org" , "Zhu, Tony" , Andrew Morton , "linux-mm@kvack.org" , Christoph Hellwig , "Shankar, Ravi V" Subject: Re: [PATCH 09/17] mm: export access_remote_vm() symbol Message-ID: References: <20230103163505.1569356-1-fenghua.yu@intel.com> <20230103163505.1569356-10-fenghua.yu@intel.com> <87tu16rdea.fsf@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87tu16rdea.fsf@nvidia.com> X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3068740005 X-Rspam-User: X-Stat-Signature: 3twyffih73q6fmeibjmjr4a7oujez4ap X-HE-Tag: 1672862197-603340 X-HE-Meta: U2FsdGVkX1+xRX/twcaukqKT9HLWNroxY0p5yZaQADqdUD9jQ12P7sN+bYsdJYHsGyo3XdA6XJZTuLLOLyg0EN4L8WFk5Ybj4YI4fmsEzjN9nnqUsQS2peTCsXeAnnj4iSWlR/PGd3jLyG0RFRs+kY3Oc4VzJ8g7J0Gp/lPGWW0S90VPBkythmumVXmYgl+2086biZZqGdJ0WkdBuhMpBGRwAlXQR8eT+yuBDUMTPtHIauVEBFSeeTCzHdn5pkKkQso/MAu6sbLdIyFqlQDWwAMKgisxDHpqXG3eHPEwzGJ1eGhvpIQZviR0bnjJyjf6/sEVNYKwQaLuWTa4hT/Bx7YXz2xA0Bf1qSv9h4NYX9cHlECG4Gisdp/Ty7fjHBMlZzKKSYDP3CmvJnauy/vfrqCznxNucuypXxqNBRuufQkaVLPy5zN5GivS27pvdC1xG/1llBVVOK4xxhRTknd8ypj5nHx2pFmgFL+Fc5z+jmut49v4eqKKW0thxezB9DqWyHX/ezA68iLnwjz+s9nUlJe+qA3lpP9IjqrDm2zViGkaKV14qT9QrjN3xrqqvL6BZH94eEl91vKNpOecxq/RVc2NOsfdUxcwuMWTQ513OHooVmBHnNlPK2e47lL4+s1shp4BCNtVDK5mZgRQDePyIFdK6A1uBWMjAdyh+tlLx7KYOgXeRifMgOKlE2tv675cgmzatQnA07WSA7PIs1htqXKLbDyos3/DzRD27m+2xSqPqcezDCeBM8lZ9cpc7KaO96/Y0DKLPqEbRctTEbP1jmpDbbTlFwgc5v54fnx7+9/JjsZQBRYWORTtEiob+Z1eqV7Sg/BbEETOeBqb0MQxlkzqjI3UxSUaNtkeCw8bXaP2Y3ILLw/DWAWBQnBkXMswI7U4fewK3ZbpsD3tGkgAiHX5BZECDxImOkJywZpcL+bfxxbDjl31s9WywAHdPhgePWqsGmwQ00bVVD818LZ RmNOTy33 dJnPmNB6HebwVkLuGroki7okQSNLdSdF/6LfkFPGLxisqP1wqtvDCGZA6EaywQVFlLqQGpx/JWYFJUoBCxxhpoxmY0im5fo0J/QQEbbOouGV2kuv31q3N0M1XdO5eYFp976AH2m3Uc/Dfmv/XnEke7pisfyWSa9fKaepPYd7Gffa3ddY= 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: On Wed, Jan 04, 2023 at 05:12:31PM +1100, Alistair Popple wrote: > Obviously something must still be holding a mmgrab() though. That should > happen as part of the PASID allocation done by iommu_sva_bind_device(). I'm not familiar with the iommu code, but a brief glance suggests that no mmgrab() is being performed for intel devices? I may have missed something though. We do need to be absolutely sure the mm sticks around (hence the grab) but if we need userland mappings that we have to have a subsequent mmget_not_zero(). > >> I definitely don't feel as if simply exporting this is a safe option, and you would in > >> that case need a new function that handles different scenarios of mm > >> ownership/not. > > Note this isn't that different from get_user_pages_remote(). get_user_pages_remote() differs in that, most importantly, it requires the mm_lock is held on invocation (implying that the mm will stick around), which is not the case for access_remote_vm() (as __access_remote_vm() subsequently obtains it), but also in that it pins pages but doesn't copy things to a buffer (rather returning VMAs or struct page objects). Also note the comment around get_user_pages_remote() saying nobody should be using it due to lack of FAULT_FLAG_ALLOW_RETRY handling :) yes it feels like GUP is a bit of a mess. > In any case though iommu_sva_find() already takes care of doing > mmget_not_zero(). I wonder if it makes more sense to define a wrapper > (eg. iommu_access_pasid) that takes a PASID and does the mm > lookup/access_vm/mmput? My concern is exposing something highly delicate _which accesses remote mas a public API with implicit assumptions whose one and only (core kernel) user treats with enormous caution. Even if this iommu code were to use it correctly, we'd end up with an interface which could be subject to real risks which other drivers may misuse. Another question is - why can't we:- 1. mmgrab() [or safely assume we already have a reference] + mmget_not_zero() 2. acquire mm read lock to stop VMAs disappearing underneath us and pin pages with get_user_pages_remote() 3. copy what we need using e.g. copy_from_user()/copy_to_user() 4. unwind