Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp689141pxb; Thu, 24 Mar 2022 05:20:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAAJ3MFkaKm/x8pj8KY6mutxGAnF9JiVEJ3Gk5oKNZr0AJI01hJNqeIpIWZLhfXoyfz3cb X-Received: by 2002:a17:902:70c1:b0:154:667f:e361 with SMTP id l1-20020a17090270c100b00154667fe361mr5730520plt.148.1648124436676; Thu, 24 Mar 2022 05:20:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648124436; cv=none; d=google.com; s=arc-20160816; b=DCDkwgzY/BRulOZOQISijtKmMNubVH5p2EA6W7QCtY2ujtN0WSkMrZ7wiaTmzz7/kg s0NnO3m/RKSD7dnZJJYh1Pl8D10VLMIALfA5P8or9liQHz5lfuQ/23xAY/opV2uqHSjY HiuLQBGycuqmFvhUQpNkwpctUaCoFnN499AM353zQ8/b9YI7uPKqLl2IRVK+2pNbv3ZR SgrcyYM8x33iGa/1iJS5TopxnwGLpQ2zFzkfygr5RFxKae/kfRUdDsST23H6OyT2GoPj 7EjWRoKXK9PmiBfgQ8QoTFwMZBlCUTfASy2M1FJKS5Kdmf6VwB6nK0zibs/91WC065kx WHmw== 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 :message-id:date:subject:cc:to:from; bh=bAt2VbhoyRtMJ/zFtGlHdbJ48Ew9gBesUcDfdixs/1I=; b=ZavLxyAe+MMKxdtVthvwybHvZSSU+bhflmiR9fXa14zOnaQkPlT32F4mNkR5jQGjQP 7nIJ5cngZF/itNrbrEoqTszLyx5PQDKrhtOplXLx6Kjan/lBGtsy7XQIxT8+bSFLqbIj 4CCkVtxyORLHhMMq0+zGtI2MIx8k1LQB2lOL4LkEKimU4phgrX05mtP9S8MeuzWowzwl PlD4geR2vQK31z9wuDp8miD1+3TnnP4ogqWlqQJI8Pm2o9USMedj2NbdrcUjFhT4jZ89 42AchBV7cmflPu6uVAkAIJEHSXTUnLVr3T1OF0TTBwQRPysjvZw24gXeT1FXd/y2vwcF lXjw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bm23-20020a656e97000000b0038205c14f7dsi24488387pgb.170.2022.03.24.05.20.20; Thu, 24 Mar 2022 05:20:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241120AbiCWB1L (ORCPT + 99 others); Tue, 22 Mar 2022 21:27:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230118AbiCWB1K (ORCPT ); Tue, 22 Mar 2022 21:27:10 -0400 Received: from nksmu.kylinos.cn (mailgw.kylinos.cn [123.150.8.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8772D6E8F8 for ; Tue, 22 Mar 2022 18:25:41 -0700 (PDT) X-UUID: d4584398dece4b498383da4c3e9861c1-20220323 X-UUID: d4584398dece4b498383da4c3e9861c1-20220323 Received: from cs2c.com.cn [(172.17.111.24)] by nksmu.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 1789687103; Wed, 23 Mar 2022 09:24:49 +0800 X-ns-mid: postfix-623A770C-942667795 Received: from localhost.localdomain (unknown [172.20.12.223]) by cs2c.com.cn (NSMail) with ESMTPA id C287C383C640; Wed, 23 Mar 2022 01:25:32 +0000 (UTC) From: xieming To: christoffer.dall@arm.com, marc.zyngier@arm.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, xieming@kylinos.cn Subject: [PATCH] kvm: fix gpu passthrough into vm on arm64 Date: Wed, 23 Mar 2022 09:25:19 +0800 Message-Id: <20220323012519.521058-1-xieming@kylinos.cn> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,T_SPF_PERMERROR,UNPARSEABLE_RELAY 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 1) when passthrough some pcie device, such as AMD gpus, kvm will report:"Unsupported FSC:" err. 2) the main reason is kvm setting memory type to PAGE_S2_DEVICE(DEVICE_nGnRE), but in guestos, all of device io memory type when ioremapping (including gpu driver TTM memory type) is setting to MT_NORMAL_NC. 3) according to ARM64 stage1&stage2 conbining rules. memory type attributes combining rules: Normal-WB < Normal-WT < NormalNC < Device-GRE < Device-nGRE < DevicenGnRE < Device-nGnRnE Normal-WB is weakest,Device-nGnRnE is strongest. refferring to 'Arm Architecture Reference Manual Armv8, for Armv8-A architecture profile' pdf, chapter B2.8 refferring to 'ARM System Memory Management Unit Architecture Specification SMMU architecture version 3.0 and version 3.1' pdf, chapter 13.1.5 4) therefore, the I/O memory attribute of the VM is setting to DevicenGnRE is a big mistake. it causes all device memory accessing in the virtual machine must be aligned. To summarize: stage2 memory type cannot be stronger than stage1 in arm64 archtechture. Signed-off-by: xieming --- virt/kvm/arm/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c index 11103b75c596..9b7fb13f4546 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -1209,7 +1209,7 @@ int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa, pfn = __phys_to_pfn(pa); for (addr = guest_ipa; addr < end; addr += PAGE_SIZE) { - pte_t pte = pfn_pte(pfn, PAGE_S2_DEVICE); + pte_t pte = pfn_pte(pfn, PAGE_S2); if (writable) pte = kvm_s2pte_mkwrite(pte); -- 2.27.0