Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp932284pxb; Fri, 22 Apr 2022 14:40:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzT6hLSfOp2Y8N7GPdKHbaCGYDA9KzHM99qlIrncuq4F239cgIOcnUOlU1D5UMGbCEradQn X-Received: by 2002:aa7:8e85:0:b0:50c:f0a6:2312 with SMTP id a5-20020aa78e85000000b0050cf0a62312mr4176919pfr.74.1650663656663; Fri, 22 Apr 2022 14:40:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650663656; cv=none; d=google.com; s=arc-20160816; b=E5HW9t6XLrruZ+EqQu+JI8gPUW6nhciUl7DcoTrVaJBC5/ikyckcv6MLGWl5eUwJ5Q kF2elKetpbiSIG94aV///lj2trEmPlTC96yHKuswoqMztoch8Mabi4kw+N5yHC0zD14t QMeOheul5JgmVJOynmyL/sr4neEuHEmbN1NMOVVdvcE9cg+7L4GWJDxfotf601gYuKZg KT95uO8cltz3jeeVOcdfEexRjJvgzliG82R3domsghH9ki1Y+Dhx/6fkYgPvzbrZ5h1h xgQFKuz1io0aN+nFayZmJY588woo3E/Y2Mg9k/Y03Fde+v1X7gXE5axehc3uI82X7CJC cXUw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TPHPVEhymfv8oSdQwn6KZ7VGPONNXumfRuRVQxny474=; b=llCPgFmxPdS9oMjdQjtX7rOuE0pZTfBGkTG3t+vDsP37v6LYov8c9/juIjBOFe+iXw E9oSJNstcP4O/+OPDm6d2KDxiRdXklBPd8f7u2tLz/4onLKWsre7/Xx7/JaYEKWDRHwP 1HuCbMTWyAPiZbW/ALQauOIoYN4jwmAiRPHKXF6AecpcZlmeDIaCdRAEQH9HyJUfhYAD OFLb3YqatFxg7r9qBaMOn8rUT4uY7vNyQhSthYcUJ//auvYuSE7v6pbkuJ5OPKB5JHx8 uHWSKjRbFDSpiaQwCa2zfIkqRajCmHyr3uZHREyLF8RT3Txzo/R0BnkoiZ5QbN685y4g fhwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=PAgsii84; 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 Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id f12-20020a63e30c000000b003aa8b55016asi5805658pgh.479.2022.04.22.14.40.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 14:40:56 -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=@ventanamicro.com header.s=google header.b=PAgsii84; 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 84B881E0657; Fri, 22 Apr 2022 12:48:19 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378021AbiDTL2K (ORCPT + 99 others); Wed, 20 Apr 2022 07:28:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377995AbiDTL15 (ORCPT ); Wed, 20 Apr 2022 07:27:57 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61A72640A for ; Wed, 20 Apr 2022 04:25:11 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id i24so1650088pfa.7 for ; Wed, 20 Apr 2022 04:25:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TPHPVEhymfv8oSdQwn6KZ7VGPONNXumfRuRVQxny474=; b=PAgsii84VgeZ/Q2oKSCovvB872ig347wVkn4dZtpPKF7+4mn6c/HRZpP4/hStmf1ys T7LVGobfgoMFGbYfMGlLNiU26A0EjUVf7TBM1D4uUq8fUtnZ7cGJDBOhnPhnxVllcU8U 45QLawAPuR++SGIfj0ocQyV259l2+NhuJ5HUKagx4sBBd2EvxtvxNxR+DY6De8T70+Nm 6+e4rDRHYm1u7+Kyw8yrA9DiCG3qz+3E2IkIalzQRqz+h+p+YsbhfLjtzAEZK7UCPTAo AyQItG5Wqq3QpZIHx5QTwdpHWc6XZ0Z120bW/WuYMO2Jq04oY8moZuS6TiTrIoE+dyvb KP8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TPHPVEhymfv8oSdQwn6KZ7VGPONNXumfRuRVQxny474=; b=4bt0w9CnT61BnbHXi0MTGxbK7QiZxf0dZwJM4O5oFey7keFkLHJhifCt+Q2aTM2RfT JAZM6bMs7R7OUqwlW2/VWtbooxv3vjh7Qk6KD1JmZm2abkSYSMZI5kUs9IM20SYtBrvt d7DY7Eq3+gI2+oYgKvzKvfNR54HNu40DzNoWglS3FYmisyPpXBBmY909kKqAI9M8AjsX j+4IVFTv+MIJXxBP9fDqdkzplu9UvO5fLtQa1q9wtCqUt+dylyn7P88uqdeJ2HZbRFFr 7xe597d0y33nHLpdSgxW+vk1SAJ1k195WPNQm8m9i+jxdh18cjGATBBf/TwI4X24HVJa d1Ug== X-Gm-Message-State: AOAM531qgNihZawt2qT8zjHcg83tg8X+VR7J/hH9M2TuRqxooKXq3Q8N pe0gCVgMLwuT4yvGwjgrgaIapw== X-Received: by 2002:a05:6a00:9a2:b0:505:974f:9fd6 with SMTP id u34-20020a056a0009a200b00505974f9fd6mr22641638pfg.12.1650453910832; Wed, 20 Apr 2022 04:25:10 -0700 (PDT) Received: from localhost.localdomain ([122.167.88.101]) by smtp.gmail.com with ESMTPSA id u12-20020a17090a890c00b001b8efcf8e48sm22529274pjn.14.2022.04.20.04.25.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 04:25:10 -0700 (PDT) From: Anup Patel To: Paolo Bonzini , Atish Patra Cc: Palmer Dabbelt , Paul Walmsley , Alistair Francis , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel Subject: [PATCH v2 2/7] RISC-V: KVM: Add Sv57x4 mode support for G-stage Date: Wed, 20 Apr 2022 16:54:45 +0530 Message-Id: <20220420112450.155624-3-apatel@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220420112450.155624-1-apatel@ventanamicro.com> References: <20220420112450.155624-1-apatel@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE 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 Latest QEMU supports G-stage Sv57x4 mode so this patch extends KVM RISC-V G-stage handling to detect and use Sv57x4 mode when available. Signed-off-by: Anup Patel --- arch/riscv/include/asm/csr.h | 1 + arch/riscv/kvm/main.c | 3 +++ arch/riscv/kvm/mmu.c | 11 ++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index e935f27b10fd..cc40521e438b 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -117,6 +117,7 @@ #define HGATP_MODE_SV32X4 _AC(1, UL) #define HGATP_MODE_SV39X4 _AC(8, UL) #define HGATP_MODE_SV48X4 _AC(9, UL) +#define HGATP_MODE_SV57X4 _AC(10, UL) #define HGATP32_MODE_SHIFT 31 #define HGATP32_VMID_SHIFT 22 diff --git a/arch/riscv/kvm/main.c b/arch/riscv/kvm/main.c index c374dad82eee..1549205fe5fe 100644 --- a/arch/riscv/kvm/main.c +++ b/arch/riscv/kvm/main.c @@ -105,6 +105,9 @@ int kvm_arch_init(void *opaque) case HGATP_MODE_SV48X4: str = "Sv48x4"; break; + case HGATP_MODE_SV57X4: + str = "Sv57x4"; + break; default: return -ENODEV; } diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c index dc0520792e31..8823eb32dcde 100644 --- a/arch/riscv/kvm/mmu.c +++ b/arch/riscv/kvm/mmu.c @@ -751,14 +751,23 @@ void kvm_riscv_gstage_update_hgatp(struct kvm_vcpu *vcpu) void kvm_riscv_gstage_mode_detect(void) { #ifdef CONFIG_64BIT + /* Try Sv57x4 G-stage mode */ + csr_write(CSR_HGATP, HGATP_MODE_SV57X4 << HGATP_MODE_SHIFT); + if ((csr_read(CSR_HGATP) >> HGATP_MODE_SHIFT) == HGATP_MODE_SV57X4) { + gstage_mode = (HGATP_MODE_SV57X4 << HGATP_MODE_SHIFT); + gstage_pgd_levels = 5; + goto skip_sv48x4_test; + } + /* Try Sv48x4 G-stage mode */ csr_write(CSR_HGATP, HGATP_MODE_SV48X4 << HGATP_MODE_SHIFT); if ((csr_read(CSR_HGATP) >> HGATP_MODE_SHIFT) == HGATP_MODE_SV48X4) { gstage_mode = (HGATP_MODE_SV48X4 << HGATP_MODE_SHIFT); gstage_pgd_levels = 4; } - csr_write(CSR_HGATP, 0); +skip_sv48x4_test: + csr_write(CSR_HGATP, 0); __kvm_riscv_hfence_gvma_all(); #endif } -- 2.25.1