From patchwork Thu Mar 28 08:46:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13608186 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 7E356C54E67 for ; Thu, 28 Mar 2024 08:46:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED0796B0099; Thu, 28 Mar 2024 04:46:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E81896B009A; Thu, 28 Mar 2024 04:46:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D22696B009B; Thu, 28 Mar 2024 04:46:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id AE3FB6B0099 for ; Thu, 28 Mar 2024 04:46:40 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BD3FC1210EF for ; Thu, 28 Mar 2024 08:46:39 +0000 (UTC) X-FDA: 81945816918.18.0C99FF8 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf11.hostedemail.com (Postfix) with ESMTP id 2060240008 for ; Thu, 28 Mar 2024 08:46:37 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fJQ4qQ6+; dmarc=none; spf=none (imf11.hostedemail.com: domain of BATV+62e9139b449b679ee457+7522+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+62e9139b449b679ee457+7522+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=1711615598; 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=k8Anl1as3ek0+VrxzOKuWdGKsmgPAuR9n8xz26CHgC4=; b=2O7p18HJMROKNDbfBVaIUXQFQB59NCyALJRVgu10wmg7TBTeeM7/qHFrZpgCIBf57C0ZeC nqsBvL+asQjlcM9sjhFbBXDy/e2CbEDwtXrHMRJObQaCALBYclQsmhwPM/9565MUpuQbLJ 5ufziObq/nlZ5574cY1+eRBey74UCoQ= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fJQ4qQ6+; dmarc=none; spf=none (imf11.hostedemail.com: domain of BATV+62e9139b449b679ee457+7522+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+62e9139b449b679ee457+7522+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711615598; a=rsa-sha256; cv=none; b=GqVOs+weMR/L0fVkK9WxoKwt4OZNA4BrxzHtxIa7PKquAvKNGmF5xK84CJJHboYHgc8+Cd MP/WYASW0V5LJuUW/QiiHeRPq8OYQ5otx5Llhap8thswapqkT7F3C+nCaVAb47IzrH9/m/ qwOH2fsziC3SXVGlkV46640s1qAgMRM= 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=k8Anl1as3ek0+VrxzOKuWdGKsmgPAuR9n8xz26CHgC4=; b=fJQ4qQ6+efadpvyiPGzbB6yn3W is9aFsbjv94+FOQOohTsKRYu1W6DSsp5NfqW6Wckuah3F6AsXxYRjGBa6RF4j2wanPx5Q6IHe626K xGZ/x8eEh3/TFz9SbsmIzz+oyJuhAxtD1tmrI0Sb+y7DI14mSa3QF7MCJeNThehft60vVWlAKMUq6 bD+CqD55VpmhwVU5p4RVj4TDhfv/QnZRiYBwXVsy8MkjVl8nrumR7A70rKWfKhBAsOrPFmbDHgft5 qDG3ds0T7Vl6dTWoAkEdCxMX+L1g/kuujRTtxA0om0N3sZxsOIfNTc78yRBjCX0EXOklcKH2yzpwQ wfZU9scA==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rplP9-0000000D8gV-1oP8; Thu, 28 Mar 2024 08:46:35 +0000 From: Christoph Hellwig To: Andrew Morton , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Fei Li Cc: x86@kernel.org, linux-mm@kvack.org, David Hildenbrand Subject: [PATCH 1/3] virt: acrn: stop using follow_pfn Date: Thu, 28 Mar 2024 09:46:27 +0100 Message-Id: <20240328084629.2955393-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240328084629.2955393-1-hch@lst.de> References: <20240328084629.2955393-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-Rspam-User: X-Stat-Signature: j9py1an1ditrt1jih7kgjee8zfjoqbe7 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2060240008 X-HE-Tag: 1711615597-157549 X-HE-Meta: U2FsdGVkX19sv07RdztV9vwC2KmkvRcLS1bYhcsoSqlppv+IIBuhi5NJiZiptHSgqLjK/wt4nR2HWRh8AYOziqrooDfOmTFgt82hEu5jql/ubjfIH+iKEaDkuI7cTM7cVLkrUg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ikjrMa/ssd9D7gWWPJHtiDWIxoUaV7e8g7CZXXb0sVSaB+irDVVyGx66Pu7itwfCn8yED59VrkdVzcFQ4aA/2c2i8lKIppnJct78rUWJQ/qsl6JeWOrJL2OtZCDbZRrDsgy/fCFvoWLHVm43DP4p+/Nm2WkqTRxXS1m9gkwNx6NwHOHnj6ZnmSHzQAwn3/5/TVfvYWIvw42Qdv/fNw01KwqwR83eCE1ehhGgsNks+caBmM8Iv8K7V0GaOSnibf/aOnsZlG2zVGhKcUJ4= 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,