From patchwork Fri Jan 27 18:25:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 49579 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp980514wrn; Fri, 27 Jan 2023 10:28:20 -0800 (PST) X-Google-Smtp-Source: AK7set8mnfBaiopE+QNkdjCzI2KVz/I0QMDz//tS0DYecUnLdjkAw9l2fWBngUkaPBgC0B9/l8xE X-Received: by 2002:a17:90b:4a4b:b0:22c:2f5e:33df with SMTP id lb11-20020a17090b4a4b00b0022c2f5e33dfmr6605947pjb.22.1674844100511; Fri, 27 Jan 2023 10:28:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674844100; cv=none; d=google.com; s=arc-20160816; b=Ggs4C84kZ1ujnFhKi9cBio0fBlXNMKWYNk3ttfmtG+phUVWUEt1w8TEwLKV+BIycsv l5GGM43SbaVVvdAP5VKXsu0YQfddLAYrx7OrcE2S2u7pNARt4ZNffI+cDRHvDU33uKPF 76DH4GGe4ZUBwog3h5q8BTxUCNCLbWtJaLM5nqxsJR2OmAI91Gf7R0jqn2NTkvskwMcU WrMYGqX5kkdMfV209WvDqq1/226X4GevZ5Fs5DgvG1WUt0bdvbRs+Vms1XXS8gUVyvuF 4lu7EMZweqY9Jucjpz2XYGIIapNRPALyDXKrrdOp62Qe2IUJyZh2eLquBSHW5S50+ZXL ClIA== 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=Zm221noYPDv16VavlZywICLYGigsQ3r83tHpYQ6Bets=; b=fM4I5aKo4/gKxwTEHRYZKLVL7yZP1PKqzYfNps02BGRihIJHAcKU20WESufnFrUNJu fsdP4T6kOj+bZE2l7vD0jMhTlS+Fq0oyrR7I6nIbUSA4u+w35FaNBevZ240tBDeQiPD1 YqPrsohHHz3sU1Lv6En3/W6cF5JKoh5xklQTJcnSsDhCcjKjDIFQssPmGG/vJCc7Zu+/ UFRMYKrJT+uVMAahfTWDF5n3dKJnck/OXj3WMKiHBaFym/1A30uJZnagcNG7tg3qnzuH 6RwKnu+VwGUPDksT70yCaxctLQm14Bd/Q0Gi1kSqLz19LjFmOEPmdOwS/4NkhK8UU6gy Qmuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=ZcBhDH5t; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dw18-20020a17090b095200b002262a74af32si5243278pjb.40.2023.01.27.10.28.08; Fri, 27 Jan 2023 10:28:20 -0800 (PST) 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; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=ZcBhDH5t; 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 S234713AbjA0S0x (ORCPT + 99 others); Fri, 27 Jan 2023 13:26:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235328AbjA0S02 (ORCPT ); Fri, 27 Jan 2023 13:26:28 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C12083959 for ; Fri, 27 Jan 2023 10:26:23 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id b10so5377367pjo.1 for ; Fri, 27 Jan 2023 10:26:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Zm221noYPDv16VavlZywICLYGigsQ3r83tHpYQ6Bets=; b=ZcBhDH5tOacQHuA94vrShOzYvQg6QtjBICmN2cS9lLp1eNzFB5yxsNZPBOaH2GNR6m M5ZLuxW0OtCybveoStp55DxKU8uE0CxX5PfGQPKUBBnGgNvfRWDLBHWWcQjmA0eZe3bS 0gICApwRPkQqa5+iA0bzYwDiu+ARraoCbqtymSf1RtjJ56UefDcSvvHA9neCIP/RLe+L Kq89X4xXUrnImpbZxkgb6zSUkHEl9QULQMfmpvOi2kCMFN1Fd9u6yshUOIupfzv7+26D FQzOb1OxA5eOjhxcYwlwt3DoLbjMDjg9TaRwKVBqiHlJ9uZ+TfYZQI2DY6/BwGy43OOh EyfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Zm221noYPDv16VavlZywICLYGigsQ3r83tHpYQ6Bets=; b=yOzytGGAwVZGaBXvfcaVQTpz8JjQ3PGUdmEUv52Xa6s47I94trM14Aq2SQdtfd2g0R FMg8ZiDcsjCTXUflRCmuzoWkhriKnHREJaGl5caNjJXjHlo0RRXOvMHASlEXel+WWTBu +3crtxuNkj+KdrOxm94ATYnmcBnbxBfo8MZuGGcEFeO48nhVxxCDZG07aDi1Q5oz6zLC r3C5F05gLW3YDmk9xuk7/DcJrLDAkSamdsCD220SuCyt026/KTxmuM+1kFCQXznJtmtR gu2fPGsT9EB59PCLdUkw7rnYsyv4i0sKzlrLLSW8xYHfCfN/DY5lK+c3de+uFcLaW7Op 61HQ== X-Gm-Message-State: AO0yUKVPbTZdOTEgAcw41EjEL2tN7vTwApDB7/VraqHpByf1qg+pc+Lr J5UV60WbpIJH5XrdrJde1vdpL3Br/juTEvr/ X-Received: by 2002:a05:6a20:8423:b0:bc:5a6:1b2a with SMTP id c35-20020a056a20842300b000bc05a61b2amr9264595pzd.49.1674843982840; Fri, 27 Jan 2023 10:26:22 -0800 (PST) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id jc5-20020a17090325c500b00189d4c666c8sm3195219plb.153.2023.01.27.10.26.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 10:26:22 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Andrew Jones , Anup Patel , Atish Patra , Guo Ren , Heiko Stuebner , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paul Walmsley , Sergey Matyukevich , Will Deacon Subject: [PATCH v3 10/14] RISC-V: KVM: Disable all hpmcounter access for VS/VU mode Date: Fri, 27 Jan 2023 10:25:54 -0800 Message-Id: <20230127182558.2416400-11-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230127182558.2416400-1-atishp@rivosinc.com> References: <20230127182558.2416400-1-atishp@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756201327137288715?= X-GMAIL-MSGID: =?utf-8?q?1756201327137288715?= Any guest must not get access to any hpmcounter including cycle/instret without any checks. We achieve that by disabling all the bits except TM bit in hcounteren. However, instret and cycle access for guest user space can be enabled upon explicit request (via ONE REG) or on first trap from VU mode to maintain ABI requirement in the future. This patch doesn't support that as ONE REG interface is not settled yet. Reviewed-by: Andrew Jones Signed-off-by: Atish Patra Reviewed-by: Anup Patel --- arch/riscv/kvm/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kvm/main.c b/arch/riscv/kvm/main.c index 58c5489..c5d400f 100644 --- a/arch/riscv/kvm/main.c +++ b/arch/riscv/kvm/main.c @@ -49,7 +49,8 @@ int kvm_arch_hardware_enable(void) hideleg |= (1UL << IRQ_VS_EXT); csr_write(CSR_HIDELEG, hideleg); - csr_write(CSR_HCOUNTEREN, -1UL); + /* VS should access only the time counter directly. Everything else should trap */ + csr_write(CSR_HCOUNTEREN, 0x02); csr_write(CSR_HVIP, 0);