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 E3D45C3DA4A for ; Wed, 14 Aug 2024 18:24:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 11C906B007B; Wed, 14 Aug 2024 14:24:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0CD5F6B0082; Wed, 14 Aug 2024 14:24:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB0086B0083; Wed, 14 Aug 2024 14:24:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CBF0B6B007B for ; Wed, 14 Aug 2024 14:24:55 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6CAEE1C4B41 for ; Wed, 14 Aug 2024 18:24:55 +0000 (UTC) X-FDA: 82451677350.15.C9D42A5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 5883740006 for ; Wed, 14 Aug 2024 18:24:53 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KejV07ZF; spf=pass (imf04.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723659857; 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=J2cPNLPL+St3jqqHF4HLffkaByfXjHy/Gso61Lw3y7s=; b=xTlWn1U2qxQ2Rkwpm2+HreuRPPT5swIWrG4OXm3SoMYYEJJ7Cb8JehF0maPjiPwymqCKiU G2PuJ+04n1/Mjjkx7BaXDp6e/dEgB61R0Hl3i5VP2Df5uxggqOUoD3O4w0Auvi32c+6PbN /nEO7IiHAE+b22q7zHehuNZhltj8unY= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KejV07ZF; spf=pass (imf04.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723659857; a=rsa-sha256; cv=none; b=3VSommps7n7ze1CSCL8riSQl6yi3v2R5IWtsLDpFi7IS81RE6kbkYVemWdR7SUPNCbTjDL XsgkhaOLq+ookvd6pq2pSzQPl2TxJnPTIz4UdibUZ9UV98uWbiaYd8fbvs/a+VJdaWv4Nx 3d0aZa7DRpGJmWLVpGaQSBizo/dGpHk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723659892; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=J2cPNLPL+St3jqqHF4HLffkaByfXjHy/Gso61Lw3y7s=; b=KejV07ZFbPYS5oAIWm91YRcXlk4IFh+aOBxsWQgOy1memIH14D3ffOjXJLQKlQSZpqOshy x5fekxYVO8TvI9OknlIBcgFoDXrsT4e2BddbsOilcacvmt7fFzGr4oWWy1zKJ9NdlKO6Jn ssIHHy0D06Ko1rLt3edZyJqeiPACxFQ= Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-150-6nb5ypmYOKiADJPC6fEGmA-1; Wed, 14 Aug 2024 14:24:51 -0400 X-MC-Unique: 6nb5ypmYOKiADJPC6fEGmA-1 Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3d93859d818so6012b6e.1 for ; Wed, 14 Aug 2024 11:24:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723659890; x=1724264690; 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=J2cPNLPL+St3jqqHF4HLffkaByfXjHy/Gso61Lw3y7s=; b=eFQQcYHewHxEXGH6P0HvRMjHoEMv0DZUYstz51LdC5XrHwHY0bjPGN1qZOq8UFaQHm 6UpvWGKD5TMpyVo5oaeNzeY5yIvWVvEq6eIOPyk8eTVM8pjvTJ5QCHIg4poIGd4StWtD viQQSBI2wT2Vp8EtDpFbANHMS+mIf5F5zwpuMRDMqTgvRWmcrnKfIMwtLHMs0dskGa3P mauSvFo8cM1BfFHKwCWKcduFAhSTwLLdmynMhrq4gqmpPBNMsJpbYvkvC2iLEds03c+4 3LDpNfHEaliPh9Sh6FxDg5GW2/3RTtDVyZs1eZYZZ+yL6lZ4qz0MwrxmwoJ+l4JwvGwR Lyfg== X-Gm-Message-State: AOJu0YyPlFSXU1IAisCG/lBIJwiG+7ch0MjiS/IETjoxJfcRugmO2Tcb I4CdmEmnoSceeQTsFuCFfE5NqzfCyPmqFRgN5NNgpcWx+OuC3nB3eeeAYvfvkSLbs0oOX9Zo0qH mMTifO6d8xeggv6uZJbqQ7HTvBKL3ayKRP26zARHXLPJ734FT X-Received: by 2002:a05:6358:c028:b0:1b1:a6bd:7d1b with SMTP id e5c5f4694b2df-1b38581118fmr19891655d.0.1723659890286; Wed, 14 Aug 2024 11:24:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEgt7WDSWzC1mFW4VC3ihVIhbo4veIl/vdn/5xf3Z6L6GSvPP96mM0aI9XRX2zeVv7mjRtyQ== X-Received: by 2002:a05:6358:c028:b0:1b1:a6bd:7d1b with SMTP id e5c5f4694b2df-1b38581118fmr19888655d.0.1723659889910; Wed, 14 Aug 2024 11:24:49 -0700 (PDT) Received: from x1n (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a4f0e00c31sm89382785a.88.2024.08.14.11.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 11:24:49 -0700 (PDT) Date: Wed, 14 Aug 2024 14:24:47 -0400 From: Peter Xu To: Jason Gunthorpe Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sean Christopherson , Oscar Salvador , Axel Rasmussen , linux-arm-kernel@lists.infradead.org, x86@kernel.org, Will Deacon , Gavin Shan , Paolo Bonzini , Zi Yan , Andrew Morton , Catalin Marinas , Ingo Molnar , Alistair Popple , Borislav Petkov , David Hildenbrand , Thomas Gleixner , kvm@vger.kernel.org, Dave Hansen , Alex Williamson , Yan Zhao Subject: Re: [PATCH 09/19] mm: New follow_pfnmap API Message-ID: References: <20240809160909.1023470-1-peterx@redhat.com> <20240809160909.1023470-10-peterx@redhat.com> <20240814131954.GK2032816@nvidia.com> MIME-Version: 1.0 In-Reply-To: <20240814131954.GK2032816@nvidia.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 5883740006 X-Stat-Signature: erwi7317m6a8erh5uwynjztzzny4ohbb X-HE-Tag: 1723659893-657037 X-HE-Meta: U2FsdGVkX1+TDcrNOfPDFDgkcrOrX9dFauXzRuq5/8UCo14kwTUR5b/ZwJPp0WvY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QRY2fMAbb/XhZfmGeXxwu/4sGwbNVsp1Ooo3ZWzzLUnrzX7blHxZcdVz+LdQTGvGL1brRHJR3p7FkAyL9Ve++yAmoQWgXe3zgTBzCuHToNZcJifOTGSUEUswdApCGTLNDuEQJwEuW1UNYFwWpwZ7Xn+O5DqPEx8VevBb9A2mafVgzEfNYD8PWKg2Y/4FwpN4hXvKHgWJEbJiHEFATMDnNqf3c4kGHIvnWIjk2ic1lFhQTEiZ8goKpKf0U80hsWBAVq2KLcfq35AXT03CstHepuOQS4fL9qMq9IHFg3Em/0PHrOhdGjqGjYuGiL0gfa3GbFPNXmZ63NUaJSTGHpahzTeDhuOEwTnwNpELIZh34eiezkgPmz/k= 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: List-Subscribe: List-Unsubscribe: On Wed, Aug 14, 2024 at 10:19:54AM -0300, Jason Gunthorpe wrote: > On Fri, Aug 09, 2024 at 12:08:59PM -0400, Peter Xu wrote: > > > +/** > > + * follow_pfnmap_start() - Look up a pfn mapping at a user virtual address > > + * @args: Pointer to struct @follow_pfnmap_args > > + * > > + * The caller needs to setup args->vma and args->address to point to the > > + * virtual address as the target of such lookup. On a successful return, > > + * the results will be put into other output fields. > > + * > > + * After the caller finished using the fields, the caller must invoke > > + * another follow_pfnmap_end() to proper releases the locks and resources > > + * of such look up request. > > + * > > + * During the start() and end() calls, the results in @args will be valid > > + * as proper locks will be held. After the end() is called, all the fields > > + * in @follow_pfnmap_args will be invalid to be further accessed. > > + * > > + * If the PTE maps a refcounted page, callers are responsible to protect > > + * against invalidation with MMU notifiers; otherwise access to the PFN at > > + * a later point in time can trigger use-after-free. > > + * > > + * Only IO mappings and raw PFN mappings are allowed. > > What does this mean? The paragraph before said this can return a > refcounted page? This came from the old follow_pte(), I kept that as I suppose we should allow VM_IO | VM_PFNMAP just like before, even if in this case I suppose only the pfnmap matters where huge mappings can start to appear. > > > + * The mmap semaphore > > + * should be taken for read, and the mmap semaphore cannot be released > > + * before the end() is invoked. > > This function is not safe for IO mappings and PFNs either, VFIO has a > known security issue to call it. That should be emphasised in the > comment. Any elaboration on this? I could have missed that.. > > The caller must be protected by mmu notifiers or other locking that > guarentees the PTE cannot be removed while the caller is using it. In > all cases. > > Since this hold the PTL until end is it always safe to use the > returned address before calling end? I suppose so? As the pgtable is stable, I thought it means it's safe, but I'm not sure now when you mentioned there's a VFIO known issue, so I could have overlooked something. There's no address returned, but pfn, pgprot, write, etc. The user needs to do proper mapping if they need an usable address, e.g. generic_access_phys() does ioremap_prot() and recheck the pfn didn't change. Thanks, -- Peter Xu