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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 84315C3DA4A for ; Wed, 14 Aug 2024 18:25:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:In-Reply-To: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=J2cPNLPL+St3jqqHF4HLffkaByfXjHy/Gso61Lw3y7s=; b=VjAF0nrOswLZaH23wcrzXzP4/+ 4r49R5lqLXjQzQ5i6tkR+8b2VMxGcp8lE3Gq3GVdmDX2O3YhKp3ihwxNEbVoPPwYBR4CJhQx6uRDU 5HwDsoiBj/5c0IUgimDJYK8H1OFLU0Qs98TBGI6ToTbsFSOJKoC90PWOgLxReWcrc5Li2BRacOJxJ E+HeaskA/iT9CEexaiWhPAOyDYLY3huymt3Bc/4LRc/+oksuP+le2NxkKmIdrB4Nf7VQktiY5b1H3 vKKdutuM43jc0VgUWA9fC/9ZNkMmTM6a1EHfxsUjTtP8M2QYqsJ8HilQMJjHjUu86OQRKvu5XT9n7 oYcsG5RA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1seIgj-00000007vtm-1Fez; Wed, 14 Aug 2024 18:25:37 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1seIg5-00000007vkO-1xWW for linux-arm-kernel@lists.infradead.org; Wed, 14 Aug 2024 18:24:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723659896; 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=jM9I6KXfOIGDTYiqOueuc9W6Wg4LVE5yRHd0jcvmklulTOQ6f2eZZtbQG2pXGf7QY/gZsf qV8wXtaBtNBoJ+T5ZheGhoXagmzEYAvWd5yQ4IGsFL5pbsRgxsLxoN4/uoRjhPlxgSOUPX jiJMv6fmHV/24GCu2igB9aHYDPsjnTE= Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-96-Jmv_gx-KOK2ZaY8E0cgfIA-1; Wed, 14 Aug 2024 14:24:51 -0400 X-MC-Unique: Jmv_gx-KOK2ZaY8E0cgfIA-1 Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-3db2030c151so5674b6e.0 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=BbqxABuD6NbvM9k2gdVx3mvzT7pAA9gN9LR3l7ovt/bsT9adSmDhojgkZveExHMYYS 6IJ5t1NSH7sTO5aFrMAT44RxpIUvduWvwLpCVEU0t35wO4Y7WPoPbKB/4iLweU21k0mu Hf2Y/pCmfWTjjxGabYi9ibha8f1cQhPJqyg0woIJOEpc7c7UrNLBhbUK8bW2hi26ZJZG 9qZShcQuSmmsEV4xqkKn9RLsOYFSC+x1mGl78xBBQg+hEdRyzS39SfyaFywmeNTST0++ 2dfZ0sst2gIlfglijVSVZnMCktZIGPtOe4Vlg/GTOAI1tgFlcY8DoIpN7PRj614BV6PF u17A== X-Forwarded-Encrypted: i=1; AJvYcCWnW+4YYYBpIlvZPa1ETQBWYMIn/X4GYcjN8haUf96NGiviA7JhgpLrRAqFwfQlclubyi55+u3WNjMfWomq1xmN@lists.infradead.org X-Gm-Message-State: AOJu0YwyCOog23GdeyQqnaZWSmr0Z4yOSp9L7zrazT5jvAnWoLYpzC3O nH1kQlsBxABTAZXus0W1LBqtK3OMYsCO5SwZBbnpwHTjKaLWRWreMZsMiQXvMbNH88n78RwinUw nwup30cYyBxNmIzhqCr3zisbFgZw4HhD55krHncaeN1vrAE+J5C2Kx/C/95FN/RgG3VjgXrz5 X-Received: by 2002:a05:6358:c028:b0:1b1:a6bd:7d1b with SMTP id e5c5f4694b2df-1b38581118fmr19890655d.0.1723659890281; 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240814_112457_607177_8E22B4E3 X-CRM114-Status: GOOD ( 28.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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