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 519A3C52D6F for ; Wed, 21 Aug 2024 19:11:52 +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=BAq367Lg1/3EfbDlw0i1dZv1l3nmGW6xuUPajxTPQeg=; b=GASjyBvHF1AjDusdOjML2gEmt7 6HTZFl+/e2U9LxjN3nVn/BVz/w3U7XeivitMHUvXPMabLjLbfJ3Xk0dnTN+tFAGMx0yY+qJb64exK nDbAHDTbNGM2knTPCy2HkzZhKmFZ7zK3mIR+c9NVQgHy0bS9WKxxEOtVq+eKrS1r3LL8qBiSKdeZq hPVVTXze8Xc209y/SIIUmP1xizyg0J+JVs2WxNiqBiOoS94JdUbUjdrwV4+pOD1ulbAPTBkPwbcpU rZstCoBWd7n+uRIKoqnumjzHFUvphuuZ/5oJRUP9TxVL0A6qMGuakLfYnuItEgeIk2SxeHpIkh+Gn JNrKL91A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgqk5-0000000A9Ln-1iuS; Wed, 21 Aug 2024 19:11:37 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgqjK-0000000A9CV-3qKo for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 19:10:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724267450; 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=BAq367Lg1/3EfbDlw0i1dZv1l3nmGW6xuUPajxTPQeg=; b=hG+FoLKVuTIMvQov1W8xqodNd0cGHoOzuLOp2TnO6z1/gO7ibvtWRWY3Kqu+jQo1rpO9nV yJ755+oSRWH+ZBupu4wLh6OD9pJqrOP/T9WXEZmnlTV6veuhT2wwy7jX1mkWoyh4V86Sde KOq/1h9uxIn5PnLMpfc9SdFeAhuTO9A= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-427-O6qKCt2IMc2OhVrFHMBBZA-1; Wed, 21 Aug 2024 15:10:47 -0400 X-MC-Unique: O6qKCt2IMc2OhVrFHMBBZA-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6bf6bcee8ccso76277296d6.0 for ; Wed, 21 Aug 2024 12:10:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724267447; x=1724872247; 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=BAq367Lg1/3EfbDlw0i1dZv1l3nmGW6xuUPajxTPQeg=; b=D4ugIF/+FY6Tk9fDyf2KkN8F+Puk+ZmeaB5R/aOaKAmuUmBjv1NahfF2SqnyOkwTWJ q7qk9lRseN3wmkqfmMyRh4LZBRt2aQz8iTRyjXDedB8O+Zg+1Do+bA0hOS3oCrlebJ+a 4Lj4K5ti4I6KFEBjhfth4arWc3nDGdKCed+H777f49KU9zHHARxv48ZZhqy6wTwDin30 pVPuZ7ATpY6NE0Td3kmvRhWjNenqCA5a0ttPaq2alwJP+p/EDo/IdNFkoxfh8kKmUtrK qtGnxlFWggZ/CoEt7qmAHAdRW1tAQ1H6/1D7tjR5xFyQ2LfJWAtUCAPX6Xz7kUIiTORr d6Bw== X-Forwarded-Encrypted: i=1; AJvYcCWPFzWiDmp271zl1cDLTzHDYcFLaoqWEZngL7TsUlr9l6q9ZUGq8A40zV9UVFmx0A7wmeD8vrSM7j0gJGqZ3igu@lists.infradead.org X-Gm-Message-State: AOJu0YwY/7EjJKbM1n+GIwgJmUe/Vq2eSXkGTJ0m9oNfwoXSO4HN88f6 PbKxiEzUzAWmHtAG6Oa99sZ4MhvKQuooO6CtF456LHySPgl6QlyNE+HUJasPj9tn4dO+ZR3FfHd NqmT9DXqJYYdQcyaMnMJTyLW3RG1ultyLgUTvsf9TXr1UG1ml8Fv6zfhUzdekLWzs8O3zAqbE X-Received: by 2002:a05:6214:4881:b0:6bf:7cc0:7283 with SMTP id 6a1803df08f44-6c155d5b159mr43529516d6.6.1724267447175; Wed, 21 Aug 2024 12:10:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF0EFUeCwlBx0qAmDzBtd+l4FNnqw758KbLszeGCNNuUW9zuat7gLyeNsx6mlWpwsnSymqf3g== X-Received: by 2002:a05:6214:4881:b0:6bf:7cc0:7283 with SMTP id 6a1803df08f44-6c155d5b159mr43529176d6.6.1724267446788; Wed, 21 Aug 2024 12:10:46 -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 6a1803df08f44-6bf6fe1bb00sm64630186d6.55.2024.08.21.12.10.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 12:10:46 -0700 (PDT) Date: Wed, 21 Aug 2024 15:10:43 -0400 From: Peter Xu To: Sean Christopherson Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Oscar Salvador , Jason Gunthorpe , 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> MIME-Version: 1.0 In-Reply-To: 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-20240821_121051_051571_D4938D21 X-CRM114-Status: GOOD ( 25.95 ) 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 Fri, Aug 16, 2024 at 04:12:24PM -0700, Sean Christopherson wrote: > On Fri, Aug 09, 2024, Peter Xu wrote: > > Introduce a pair of APIs to follow pfn mappings to get entry information. > > It's very similar to what follow_pte() does before, but different in that > > it recognizes huge pfn mappings. > > ... > > > +int follow_pfnmap_start(struct follow_pfnmap_args *args); > > +void follow_pfnmap_end(struct follow_pfnmap_args *args); > > I find the start+end() terminology to be unintuitive. E.g. I had to look at the > implementation to understand why KVM invoke fixup_user_fault() if follow_pfnmap_start() > failed. > > What about follow_pfnmap_and_lock()? And then maybe follow_pfnmap_unlock()? > Though that second one reads a little weird. If to go with the _lock() I tend to drop "and" to follow_pfnmap_[un]lock(). However looks like David preferred me keeping the name, so we don't reach a quorum yet. I'm happy to change the name as long as we have enough votes.. > > > + * Return: zero on success, -ve otherwise. > > ve? This one came from the old follow_pte() and I kept it. I only knew this after search: a short way to write "negative" (while positive is "+ve"). Doesn't look like something productive.. I'll spell it out in the next version. > > > +int follow_pfnmap_start(struct follow_pfnmap_args *args) > > +{ > > + struct vm_area_struct *vma = args->vma; > > + unsigned long address = args->address; > > + struct mm_struct *mm = vma->vm_mm; > > + spinlock_t *lock; > > + pgd_t *pgdp; > > + p4d_t *p4dp, p4d; > > + pud_t *pudp, pud; > > + pmd_t *pmdp, pmd; > > + pte_t *ptep, pte; > > + > > + pfnmap_lockdep_assert(vma); > > + > > + if (unlikely(address < vma->vm_start || address >= vma->vm_end)) > > + goto out; > > + > > + if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) > > + goto out; > > Why use goto intead of simply? > > return -EINVAL; > > That's relevant because I think the cases where no PxE is found should return > -ENOENT, not -EINVAL. E.g. if the caller doesn't precheck, then it can bail > immediately on EINVAL, but know that it's worth trying to fault-in the pfn on > ENOENT. I tend to avoid changing the retval in this series to make the goal of this patchset simple. One issue is I _think_ there's one ioctl() that will rely on this retval: acrn_dev_ioctl -> acrn_vm_memseg_map -> acrn_vm_ram_map -> follow_pfnmap_start So we may want to try check with people to not break it.. Thanks, -- Peter Xu