Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp913442pxb; Wed, 6 Apr 2022 04:06:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQt8nsCSycsLyKtVNTRUhmHPjgpIPPlzcd60Vm+MDhQyXRBThQeVH1/LWKl97/vM8kirhp X-Received: by 2002:a63:ad0c:0:b0:374:50b4:c955 with SMTP id g12-20020a63ad0c000000b0037450b4c955mr6562272pgf.530.1649243206446; Wed, 06 Apr 2022 04:06:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649243206; cv=none; d=google.com; s=arc-20160816; b=KJEcbtYSQRav98h6v9Zdl9vrlibElroql2Eav8alX2i0CKkEVyrUnjoCaE8gFPhfO2 HXNS0EMDvrmzkT/FXWg1xQL/cLfxDFm8XuZkuonMSa/hhPVlx+kqX+SptjEOz/2avjmJ 0jTVsufx+0/YjyKjJjIsXudklzHgTQ2HJFttkgEAOHdTAwtsJ4vBnzB2/exVCprcpffi LTwEfsUi6jbeMQODqwWC6RXgzr7zvC30Yg3Eb0nKrsWQNHVP8ZwV5HzoNJXvZHLKJz/3 zfW2XCndIDjQanV7MplcBg/3DSl6PJfN9DujWZM7hlPsCGFKSBHNTV6oNel/PYXOYL8C D5vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SFdnJmR68Aq6qzBPKEzfQEzMB1l1Zta66lQ4TZEgE4w=; b=DT/uVmMVbyiWIgo2wGIaTMg9suaRd1OU9D/7QhlE7MRlHITWvLE0M0xviBGlYAH/aR sdfaou20ggMNZsheUjh3Kqco67HHRz7K8iJBmQfsiEkBeJrmmIMmrmllFRHsoz5Wdmwo PZqKX8mOASkxA68JPl+tSTpkZDChGPfMk2+1U7rHd/dtAqIx6OI8kFqXkJriXXLS3FWG A76uUERMsPoLqDGW+Z1fNO9mbdyXgMV0RDbdQ9Uaqb7p5IH48k5zpyw6qvaFM67j1+lx 4mOvH+ovUrWg0ZV4nQN1kXmZ+3rZODztUJPxELi5OAB7wb4nhrA5VJpIqv3yqNgwKOOf TkTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gOWe46uA; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id o6-20020a056a0015c600b004fa3a8e0009si16544555pfu.192.2022.04.06.04.06.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 04:06:46 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gOWe46uA; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C4B0D30B95A; Wed, 6 Apr 2022 02:28:50 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358135AbiDEUgP (ORCPT + 99 others); Tue, 5 Apr 2022 16:36:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349501AbiDEJt6 (ORCPT ); Tue, 5 Apr 2022 05:49:58 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E02B89B; Tue, 5 Apr 2022 02:47:50 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 5DCCCCE1C90; Tue, 5 Apr 2022 09:47:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73263C385A3; Tue, 5 Apr 2022 09:47:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649152067; bh=AvslXiiGZCRFOeGrGZqo2rx705V5+cRos00EJU0PUxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gOWe46uAWDXGbiGsj6/89e2cbBwCk5rwnEG6PNWsoyqBWG57rnrIYBSmhre/SjaQ7 UQ1fO6zJxBUkBqBh6xwjFRJ88FQ/Pg6g8KZjaqkqGG0Y8bLECQFHWLVTeQA/4wbMbn UptkRSJpAl8HBqnSNeJ3gol9sXVG75JWHlnXC/cg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yonghua Huang , Fei Li , Sasha Levin Subject: [PATCH 5.15 643/913] virt: acrn: obtain pa from VMA with PFNMAP flag Date: Tue, 5 Apr 2022 09:28:25 +0200 Message-Id: <20220405070359.114200785@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yonghua Huang [ Upstream commit 8a6e85f75a83d16a71077e41f2720c691f432002 ] acrn_vm_ram_map can't pin the user pages with VM_PFNMAP flag by calling get_user_pages_fast(), the PA(physical pages) may be mapped by kernel driver and set PFNMAP flag. This patch fixes logic to setup EPT mapping for PFN mapped RAM region by checking the memory attribute before adding EPT mapping for them. Fixes: 88f537d5e8dd ("virt: acrn: Introduce EPT mapping management") Signed-off-by: Yonghua Huang Signed-off-by: Fei Li Link: https://lore.kernel.org/r/20220228022212.419406-1-yonghua.huang@intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/virt/acrn/mm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/virt/acrn/mm.c b/drivers/virt/acrn/mm.c index c4f2e15c8a2b..3b1b1e7a844b 100644 --- a/drivers/virt/acrn/mm.c +++ b/drivers/virt/acrn/mm.c @@ -162,10 +162,34 @@ int acrn_vm_ram_map(struct acrn_vm *vm, struct acrn_vm_memmap *memmap) void *remap_vaddr; int ret, pinned; u64 user_vm_pa; + unsigned long pfn; + struct vm_area_struct *vma; if (!vm || !memmap) return -EINVAL; + mmap_read_lock(current->mm); + vma = vma_lookup(current->mm, memmap->vma_base); + if (vma && ((vma->vm_flags & VM_PFNMAP) != 0)) { + 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); + if (ret < 0) { + dev_dbg(acrn_dev.this_device, + "Failed to lookup PFN at VMA:%pK.\n", (void *)memmap->vma_base); + return ret; + } + + return acrn_mm_region_add(vm, memmap->user_vm_pa, + PFN_PHYS(pfn), memmap->len, + ACRN_MEM_TYPE_WB, memmap->attr); + } + mmap_read_unlock(current->mm); + /* Get the page number of the map region */ nr_pages = memmap->len >> PAGE_SHIFT; pages = vzalloc(nr_pages * sizeof(struct page *)); -- 2.34.1