Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp820052pxb; Tue, 12 Apr 2022 14:21:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqqwn4YUHdhVlTpC5Lx/jhyBZr30SrjrsIo67K1PZdXYUzwl0XRuaNMVBl9E9QN9xsYSYJ X-Received: by 2002:a17:902:9b94:b0:156:2c08:14a5 with SMTP id y20-20020a1709029b9400b001562c0814a5mr39317502plp.60.1649798486210; Tue, 12 Apr 2022 14:21:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649798486; cv=none; d=google.com; s=arc-20160816; b=Hx9Bqpp+vKppdPDKmbtWOzx94FHIPsYrMOUfG/ZLJ+a/QJ3f56EpsX+zIqDECIfCxn 0gC+9oxxbHLdqmrql1ALJFmxtF6c3Dz98nk7X9/GJh/ZNcyGDTojHgKF69t5/1Pu2UF5 3+/cru2en9UfB8CDc5gbX9BJJjDgiogNjspFGVEWM7CJuBeSpMS2p/jRKqS1g70ojVK7 N40eM5gBqenTvQNOtNo+IfGlWb2dmCWeSZ9XLDZH2yXrK1NWpIbXav5eSVKVFIb3TAnd Nhgh9dhtVSUU0X90HU3VvJrMycRvlDu3kD1jTn14ULM0z8pmUzAhAnzQp4fCYiqA5xxP FQYg== 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=Qtq5TYcnn/XCQ2Zf9TtcZ97SPcjhkRMXiuZt/Y52YbrFlXoqAl5ybFDIH9WGVO4RjO acEu2TYQXgfXmrwQ/258KJ8VU+TMeVsGukXH27NvgvSJvJTKhyOsaBolig0+0yrMgsih jGNCMr6+bj68VYZb4GhlK6RAvyUhdi8TL58i0cbwJPdGh/JVQ7t2m+DSNJLuTmMYnjUd ix0mhZJdqSWQEJ0JasPA42SrcwaESUtu/P+BVRBF80Bes64ii4eoY3gG+VrBy+fm+3cd yCYKDj8jzWUYaFUahiSBqDQ7UPFnNQX6LZTWpQiSlmO/FlIUAOGaDX9392FtJp+el9Dy sxXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=ZjcjKgTM; 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 Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id c1-20020a634e01000000b0039cf4316714si3812829pgb.421.2022.04.12.14.21.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 14:21:26 -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=@ventanamicro.com header.s=google header.b=ZjcjKgTM; 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 Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AD5A2108183; Tue, 12 Apr 2022 13:34:01 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243481AbiDLL1C (ORCPT + 99 others); Tue, 12 Apr 2022 07:27:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352819AbiDLLZm (ORCPT ); Tue, 12 Apr 2022 07:25:42 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C89CF2B1BE for ; Tue, 12 Apr 2022 03:08:35 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id o5-20020a17090ad20500b001ca8a1dc47aso2327379pju.1 for ; Tue, 12 Apr 2022 03:08:35 -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=ZjcjKgTMmHHkgO/IqeBOUs/4V91uJO5cAnoFfwZcqQBWRdM1x4KzQIdkPWTuz8bEsK feTlunsl4JYlrvlr23mjh2z18M9kwNNH3XhmPEiqJZeP8LyDDqgGtMBuzvLuwFxX28gL xDFlsfpaL5UvYRq+zvzdmGLNmKF+bJVW2e/evZmzoH0Wxuu4QLKaJUzR/51eZF5Juny+ M5la1s5esTCj0/GiWzDL5wIqLF4WVQ94Q7+t4Dr/m2wjxYFX31MQjO3eKpwFn5dmzO91 Gi+X+HH4ABfSdlvOr1Kyq+tDAqsq/FuYVw3piPy1cdn4sjluJjkX22igFUSYX6qoCIxT tZ8A== 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=BAKSsbygZ8K6KAkQDvE3qzFiT/NhY2ZjBOTwgx+lruuWdEfK6sRhbpwyCQOVogVrpX 94eb/RNbsDPsCj6kR1iH0j+pxydpZZR/rdmLrrTuBBpFGRYwSetkR0ZMfsS5exjT8ztq 44v9VEzmJsqadsg5LZhc6fc3x9nAWYebel6+9DIGL75iaaxlXTotDDqN6EuUtkEnh1Ai GxsI7CU6QR4oJZ4W4qe8rQyoc0MjVkPzjoQ8sMt/76ozv0yV3fuOZyepqVFSuLWvugLh 5FYpfwyjq/IFTc1C4LCCpu4SKaS/fYkTep4WuyAtYJkW67Lwq9+jUIF77hwpZ2GGeF1v Wy5w== X-Gm-Message-State: AOAM53205uVuk9Eg4O8zsDDKoXklhA75AF0ePXExP46EnVYjRhC5ndMK QDzAGX2MBMrWqvlJ6OWpWtfWyw== X-Received: by 2002:a17:90b:2790:b0:1cb:5cb5:f8ab with SMTP id pw16-20020a17090b279000b001cb5cb5f8abmr4132834pjb.190.1649758115322; Tue, 12 Apr 2022 03:08:35 -0700 (PDT) Received: from localhost.localdomain ([122.182.197.47]) by smtp.gmail.com with ESMTPSA id j9-20020a056a00130900b004f73df40914sm37515088pfu.82.2022.04.12.03.08.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 03:08:34 -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 2/6] RISC-V: KVM: Add Sv57x4 mode support for G-stage Date: Tue, 12 Apr 2022 15:37:09 +0530 Message-Id: <20220412100713.1415094-3-apatel@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220412100713.1415094-1-apatel@ventanamicro.com> References: <20220412100713.1415094-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,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 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