Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp746062pxb; Tue, 5 Apr 2022 21:29:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEa+VYJTqHSy5YANUzG+Yul+MG55fZR1XepEve9pjUT4FKUy8MCPisahpB7kiyEr3OUFv2 X-Received: by 2002:a63:8443:0:b0:398:6e02:49e7 with SMTP id k64-20020a638443000000b003986e0249e7mr5559280pgd.145.1649219398164; Tue, 05 Apr 2022 21:29:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649219398; cv=none; d=google.com; s=arc-20160816; b=aRDHr3G7F3Kjd0YK5RTQCFlIZS8udTccCkD+sUolV4DDguw8lKL0KkLFpX9ezGPgY2 GeQgqrJP+ECl0F9InuQENkwF6GWyJxoUAp0jP4GD7sYb43n6kARm4vGNcybHj8RPuvZi QBJblMivWqpMqe9PVWt3ihfpQgE8qGSaEsZMtm7J++swihjxvNCwG+5kcYFY+TJYVSyz k19pKtljrQN05jQYcJKzOXyUJiU+Ml2stgC+rjFoiDJkMBJBC86ACGESH6yajN42PrNx GlwQE+xEQGaWyS18bQ0J/DwSx1/uXe1xpRXNDJXTTrnvbudAA3pe4dakdJWTFCLO3wGT zZCg== 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=I1zKPGCsbgT5iEd1JLHnZ62MZjmQs/dAL81/movpu8C7VQCfL+534tEvpQUG+Igbq7 0S4yJtI5O9BEdKaTiWsJsV1CxGuM9AZCLIyNaZY8ZykVExi5h34h9ivrbsGTkIxrYmQK e2PUMzN94UJuiuGlFS13Rwq+Q/W3FPdJP1oxeGtH8wu25Wj8TnUOKz8JNfDNBTRsK34H AoWSZ7MTkyDwN/xhqLPWSuP6qYriBR/q26nz8efaDtS5FAo9DRaIKjSb6s+3HBKShASi BzrGc5R1ZoifixVTio4+qqag6qa9HYtz5pf0Q4XkJcUakXHAaxf9H5RFJSHICZPmD6/Y IjGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=La0oRFO6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id r2-20020a1709028bc200b00153b2d1647bsi13864591plo.131.2022.04.05.21.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 21:29:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=La0oRFO6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 478072E0F09; Tue, 5 Apr 2022 19:52:40 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356313AbiDENH5 (ORCPT + 99 others); Tue, 5 Apr 2022 09:07:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344022AbiDEJQu (ORCPT ); Tue, 5 Apr 2022 05:16:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 876A71D310; Tue, 5 Apr 2022 02:03:41 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 246E961571; Tue, 5 Apr 2022 09:03:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34940C385A1; Tue, 5 Apr 2022 09:03:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149420; bh=AvslXiiGZCRFOeGrGZqo2rx705V5+cRos00EJU0PUxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=La0oRFO6sY0rwoVZlTpeCpU+cWJnjQTxqnQXwv21ba4nVoYsdlxqqI5Yw3f2zlZDv MJ8EsiAAG1g8JykV86MrUPidrFaF03SvbSicFhiG/q4fbsrrs+WxQdvDPCsl50uwKx 0RYVQzE6ZopHFyKbMh8mA31H8VW+22ofhH3V149I= 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.16 0707/1017] virt: acrn: obtain pa from VMA with PFNMAP flag Date: Tue, 5 Apr 2022 09:27:00 +0200 Message-Id: <20220405070415.256927941@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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