From patchwork Sun Mar 24 23:45:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13600983 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 1B4F6C47DD9 for ; Sun, 24 Mar 2024 23:45:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E520D6B0082; Sun, 24 Mar 2024 19:45:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E00FB6B0083; Sun, 24 Mar 2024 19:45:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC8476B0087; Sun, 24 Mar 2024 19:45:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C0F126B0082 for ; Sun, 24 Mar 2024 19:45:56 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8C7A914036E for ; Sun, 24 Mar 2024 23:45:56 +0000 (UTC) X-FDA: 81933567912.21.DDF3168 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf22.hostedemail.com (Postfix) with ESMTP id E5E3EC0011 for ; Sun, 24 Mar 2024 23:45:53 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=JkAT4erV; dmarc=none; spf=none (imf22.hostedemail.com: domain of BATV+9b69c840030af2843ecd+7518+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+9b69c840030af2843ecd+7518+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711323954; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/JEts1OStKnPL5ABrwf0B3OJqNn8LrF0B4WO72a4AMQ=; b=HuIf27PEsJpTDHbhT1bMxzB8i994nDA5N4hH4GLvG/aezwFtNLxzTJnqY4tti+Xo8pj17k 48OWx9Web+dz1YC5zhUztIOPSB/3p0XW0p/o7DJh7xdYFmnkHe2kW9OyEzLeklDTEsykBZ dj246sgRuxrTs5TE078SSSDs7n0ur3g= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=JkAT4erV; dmarc=none; spf=none (imf22.hostedemail.com: domain of BATV+9b69c840030af2843ecd+7518+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+9b69c840030af2843ecd+7518+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711323954; a=rsa-sha256; cv=none; b=jz6W2cO4PpZRawfhAxvEfzYzlfHb3HNay+ddDbYA+vPlEFXMdn+kbTRMzr9nZenGBdfz6a OkXwGkhPBmJ9y2NUUaXoXBXenIW8oIFYrsbkjn/YwcsOX3JBkECY/INApZNGwdtOEhaeSU cLk/MO1F53pMCctAUpN+wBu6WSbm6JY= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=/JEts1OStKnPL5ABrwf0B3OJqNn8LrF0B4WO72a4AMQ=; b=JkAT4erVPwVXLqkZ8mTIARGcGd M9o2nNwfv7CTTDIwlTGg7CUQK/qczAKCkd+z+0GSrayHlDZ/hT4jdOmKjWFVLcDcXidxYqVZENAdm dX3U55q7sIMTP+3kykLhJL6ZT+JH4aWBmM0ywIlXAMUZuvxVYuCevnRwdDwyqWAkOEZPCQTiZumuR QavHISGR/mTImQqRIAUIbEcXpUfBgrH/pu+xdTaGpZkkFel0gqtkcQ9T7/vggDqk0OS5UMygq1E2T SASwhv9yVsP8WQRVBPXXUyREMDTxQWG2sHQGWg1mtEfrTtrjmoA2mI2JY0gDrPiOI1NXESTn7rrRJ 6u5kqtWw==; Received: from [210.13.83.2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1roXXD-0000000DwmR-14sN; Sun, 24 Mar 2024 23:45:51 +0000 From: Christoph Hellwig To: Andrew Morton , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Fei Li Cc: x86@kernel.org, linux-mm@kvack.org Subject: [PATCH 1/3] virt: acrn: stop using follow_pfn Date: Mon, 25 Mar 2024 07:45:40 +0800 Message-Id: <20240324234542.2038726-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240324234542.2038726-1-hch@lst.de> References: <20240324234542.2038726-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: E5E3EC0011 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 9rf4od6o19cei3isddmzku8ppxn3oamx X-HE-Tag: 1711323953-337933 X-HE-Meta: U2FsdGVkX19MkB4Fcimqytd7HjBDCN/EYB17GZXez+aKMr6gS29r8N0RzU0/b4LypVkECPvhf7Rj9UwB2lQze87Sv+uA4mlvaVH7Yg5JTw++CEdeDJOhfzrFN072erR1CdkqpAQMfgUc+iKSndvJQ7eZAwBbE9d/6g7ALs4wIVXc/hbCeGSimlYfO2qeaDH/UvIZ8dVyGEvA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J88Qwj/xNXJ3W/QfsYYbbIsww1bDJE/h+y/3LLbCfdtDlWPdZysYaywVyEuQh5o6I/EzVjM4cQJfNX2G5yLSTsOf2eraTJPfUyB++ddAzweFLPgYmItj0c6EvnTcygG9ATiyKJ3FLz6LMWdQ== 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: Switch from follow_pfn to follow_pte so that we can get rid of follow_pfn. Note that this doesn't fix any of the pre-existing raciness and lack of permission checking in the code. Signed-off-by: Christoph Hellwig Reviewed-by: David Hildenbrand --- drivers/virt/acrn/mm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/virt/acrn/mm.c b/drivers/virt/acrn/mm.c index fa5d9ca6be5706..69c3f619f88196 100644 --- a/drivers/virt/acrn/mm.c +++ b/drivers/virt/acrn/mm.c @@ -171,18 +171,24 @@ int acrn_vm_ram_map(struct acrn_vm *vm, struct acrn_vm_memmap *memmap) mmap_read_lock(current->mm); vma = vma_lookup(current->mm, memmap->vma_base); if (vma && ((vma->vm_flags & VM_PFNMAP) != 0)) { + spinlock_t *ptl; + pte_t *ptep; + if ((memmap->vma_base + memmap->len) > vma->vm_end) { mmap_read_unlock(current->mm); return -EINVAL; } - ret = follow_pfn(vma, memmap->vma_base, &pfn); - mmap_read_unlock(current->mm); + ret = follow_pte(vma->vm_mm, memmap->vma_base, &ptep, &ptl); if (ret < 0) { + mmap_read_unlock(current->mm); dev_dbg(acrn_dev.this_device, "Failed to lookup PFN at VMA:%pK.\n", (void *)memmap->vma_base); return ret; } + pfn = pte_pfn(ptep_get(ptep)); + pte_unmap_unlock(ptep, ptl); + mmap_read_unlock(current->mm); return acrn_mm_region_add(vm, memmap->user_vm_pa, PFN_PHYS(pfn), memmap->len,