From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6C5C7C3ABC0 for ; Thu, 8 May 2025 14:21:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:References:From:To:Cc: Subject:Message-Id:Date:Mime-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aLn8TWakPzxE6k9/RSJ3FUZHXUHuY2S7E0GZd77HIzU=; b=1VEFK8ajpAiixY th81E2lZ9IBPpNCSGXm16pkhqPmowIRzxSn0z4mVqZ5cjyz2MjJkAsmIepKqMnKyVE2r7jHM4NfBH 8yq0fQBO0cs4gZdQAg0fephy6IiXy4x9GF5LbWvcDujTs7UhTZMPpeux4O/UNgzdPmlpbWjSgjqQs d28fBXX5UXe6hadh8DBi+k7ppEZdz0hwiKiU+odiRPNTaUdRFJzo9i5ejo6A9ILOTuQ/Lhj7NSAa5 AVa9s1E2lmJdigAZfgZ5pAoXM5c9Xd04S6NycKMXx1ei7Nr9BHp/xOVBabAg4tiMCyLKRqfuVZq/9 j8tnLlVjQ0+otHFl/R9g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uD27i-00000000tmQ-0AAL; Thu, 08 May 2025 14:21:18 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uD1MV-00000000lA1-0EIg for kvm-riscv@lists.infradead.org; Thu, 08 May 2025 13:32:32 +0000 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-43d16a01deaso384125e9.2 for ; Thu, 08 May 2025 06:32:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1746711149; x=1747315949; darn=lists.infradead.org; h=in-reply-to:references:from:to:cc:subject:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Ctop9M+S6pXp/ivb7RmdzyIsAM5dZO8eB9pvvIkCEbM=; b=ZcXIvPO0BnaOIGChIhid9UCEEE7wrJ2ophP5QqaVpOV58522scDSD4OBVRPOUovoXk /xPBfnWLVOnbM8w7NHpiEz8oPUHLFUqWjZJNrAPl8vZqxk+blqg2SHm2qm9fU16bQj4k 6agB2NB00qAS5g0l2GpuvEXTlYuytd7AznOyAcmAEJy1SEobbci+/NPCH5LpUt0eJLpn tnQK4tBn21zagYKC0fDAc+sN1+u3YVcPmRgYNmeG6QrWrK2CMSPfX8HmSbPstSpYprqC SB0uYyL3739daHrHsgcykZgLR5iaEO828Kg89/Z6dlHU0/L/9sAAPAMM4pvMAn1lBNV6 scNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746711149; x=1747315949; h=in-reply-to:references:from:to:cc:subject:message-id:date :content-transfer-encoding:mime-version:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Ctop9M+S6pXp/ivb7RmdzyIsAM5dZO8eB9pvvIkCEbM=; b=O8zeNrZM5hXWdPdLMrdey9AnQoJ1+U0ZTQQfpQ9pms9HvwDbbA6W6sR5i1Gpd8eQlu keyc4qhgSdpm/7mUy84etOpV1g5Yq9tG6p9CRfrXpF50tVMjQ5E7rBkhD+JQqgzsuvOG cnWChGreSPVt5I2BeVl+al+2jkLOgD7vzI0b+r9E683RwquPIYgmEKIkC9zvsXEgMxsR F0aCL5+zcaFWtXdvUXYKwI4UbLIxxxmK4FdwdKgmIHecIFYScKcG6ohq677oPnUmv6mf lwkkaoKBW37RQ2FpvS5uV2b2PYCPrZsA/gqPWSwCcaJPRJ7K7CfMYjj/d6O+8FDJz9Ex TP+A== X-Forwarded-Encrypted: i=1; AJvYcCUrGE7nhNlX+KEZoZr7gatFUB6CjjOJz2mvaNk3vtHE62cxlGt/8hOtP0CGzNboRAHhCJ4QWsL49r4=@lists.infradead.org X-Gm-Message-State: AOJu0Ywoz+vbxywRcjqEn/0X6fIZ+UWVchkPvjqZ2wAW7CzYMDYTIOmS z4H2O+i74chdqFXdhoOicV2V9+o5EwW8Be7b1zarnGoRoQovRpHB50bko/CXa9U= X-Gm-Gg: ASbGncsbavyhfa9dgI8SXq6hEDa6PQgnAHJK3+164/wVV6g0UPmyGDqkO8thiNqDmO/ HLlkqklA7oLbgSWDf/e9S99RgENkTTQdds4GfZU7ssboxa7FP7vmhfK9fsx8NWm25AVgDaw5LiS RlhTJAqYr6a17cy3qJbWuniA/AEft60Mf96cfLfl6BqqJZdWveE3QsAXqmLQTA16xh7ag/bO7Cr mwat4hY1GV4+JwGLlLrbSD1QdNFSbvVP8aaeCdH+dPNEwQKOrM/s1Mh8ooX4DWl4a/P3B7jMhjJ EjF8olft1O3zarUqUpqWg8EGIPOGaFaLKGkDH/bqGYQhRKJg X-Google-Smtp-Source: AGHT+IFV8Gdwh/t9ZunwZV8yC9Gjd4YDqTg8K4dFRuyEe/kGcOgQumaKBu9osZaWckRfANKTr0Qn6g== X-Received: by 2002:a05:600c:cca:b0:439:a3df:66f3 with SMTP id 5b1f17b1804b1-441d44e57d6mr24537645e9.6.1746711149535; Thu, 08 May 2025 06:32:29 -0700 (PDT) Received: from localhost ([2a02:8308:a00c:e200:a451:a252:64ea:9a0e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-442cd32b0c8sm37984755e9.3.2025.05.08.06.32.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 May 2025 06:32:26 -0700 (PDT) Mime-Version: 1.0 Date: Thu, 08 May 2025 15:32:25 +0200 Message-Id: Subject: Re: [PATCH 4/5] RISC-V: KVM: Enable envcfg and sstateen bits lazily Cc: , , , , "linux-riscv" To: "Atish Patra" , "Anup Patel" , "Atish Patra" , "Paul Walmsley" , "Palmer Dabbelt" , "Alexandre Ghiti" From: =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= References: <20250505-kvm_lazy_enable_stateen-v1-0-3bfc4008373c@rivosinc.com> <20250505-kvm_lazy_enable_stateen-v1-4-3bfc4008373c@rivosinc.com> In-Reply-To: <20250505-kvm_lazy_enable_stateen-v1-4-3bfc4008373c@rivosinc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250508_063231_099158_A3A090C9 X-CRM114-Status: GOOD ( 15.21 ) X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+kvm-riscv=archiver.kernel.org@lists.infradead.org 2025-05-05T14:39:29-07:00, Atish Patra : > SENVCFG and SSTATEEN CSRs are controlled by HSENVCFG(62) and > SSTATEEN0(63) bits in hstateen. Enable them lazily at runtime > instead of bootime. > > Signed-off-by: Atish Patra > --- > diff --git a/arch/riscv/kvm/vcpu_insn.c b/arch/riscv/kvm/vcpu_insn.c > @@ -256,9 +256,37 @@ int kvm_riscv_vcpu_hstateen_lazy_enable(struct kvm_vcpu *vcpu, unsigned int csr_ > return KVM_INSN_CONTINUE_SAME_SEPC; > } > > +static int kvm_riscv_vcpu_hstateen_enable_senvcfg(struct kvm_vcpu *vcpu, > + unsigned int csr_num, > + unsigned long *val, > + unsigned long new_val, > + unsigned long wr_mask) > +{ > + return kvm_riscv_vcpu_hstateen_lazy_enable(vcpu, csr_num, SMSTATEEN0_HSENVCFG); > +} Basically the same comments as for [1/5]: Why don't we want to set the ENVCFG bit (62) unconditionally? It would save us the trap on first access. We don't get anything from the trap, so it looks like a net negative to me. > + > +static int kvm_riscv_vcpu_hstateen_enable_stateen(struct kvm_vcpu *vcpu, > + unsigned int csr_num, > + unsigned long *val, > + unsigned long new_val, > + unsigned long wr_mask) > +{ > + const unsigned long *isa = vcpu->arch.isa; > + > + if (riscv_isa_extension_available(isa, SMSTATEEN)) > + return kvm_riscv_vcpu_hstateen_lazy_enable(vcpu, csr_num, SMSTATEEN0_SSTATEEN0); > + else > + return KVM_INSN_EXIT_TO_USER_SPACE; > +} The same argument applies to the SE0 bit (63) when the guest has the sstateen extension. KVM doesn't want to do anything other than stop trapping and reenter, so it seems to me we could just not trap in the first place. Thanks. -- kvm-riscv mailing list kvm-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kvm-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 399BA22CBF4 for ; Thu, 8 May 2025 13:32:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746711153; cv=none; b=Fda2nD16h6nZYKomA3vcqvaQhcXQaNviiX6h5CNm3lamtS2aYuS1dAhW6e09OZjQgArwAcG0PVJNbv1VTN6g86zNp3vUMm7c01Q4mpw4tvRGqbAp5wyCShsv1vSHK1u5U0+7mrrvNPGWO5PAj6R+qnrUYErJYTqDfRYiHtrG61U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746711153; c=relaxed/simple; bh=UaX7lHk6APGzrlNbZtyPi82/m8GJkmtjAztxLDCFxtM=; h=Mime-Version:Content-Type:Date:Message-Id:Subject:Cc:To:From: References:In-Reply-To; b=Vddx9BCFmLvSxF6u4CBDfg13edtWeuInRgDfW0T7SyR/uIz0mjLynrc/08fhlrDNU/4mmFJHwNQEa1Or4UQ230N8HdxI7qDLUr80OEzk1TcrZttw0C2pb52MyS2ZAqbnSOR+thPFcDyPugrd4ubXkusGw3dFjW5zdn2HBdIezks= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=KLrTbFlp; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="KLrTbFlp" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-43d16a01deaso384135e9.2 for ; Thu, 08 May 2025 06:32:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1746711149; x=1747315949; darn=vger.kernel.org; h=in-reply-to:references:from:to:cc:subject:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Ctop9M+S6pXp/ivb7RmdzyIsAM5dZO8eB9pvvIkCEbM=; b=KLrTbFlpR9vF/XiDJfMDK1ST0j/y9ahE3N6zOECj38aO3xGC8SSqB6BwFdrYf/2AjR Vk04OC7b0mTe1GYE8d+FEk0wXgArLp0AnZxLZcFsx0851Qz8qV8vdystFMGzGZbyU4RS X2rD5ZI6SweGZU+IGB9i6mUQ1UnQdpzKMG/cHqX7ncCQxgiMSqdTxhRxAj4W7Cb4DLvO JO7byWMbBm5+oFH1jeVkq0bMFq0Sh+4s0RnpRgqjUu5F+TE8tUVClYvtccDM5NtzLgQv dMbBHVPJ6hCPa0Q/6cIYBAHM0ANjIni0B4L3oR8aijJAuiISpIZWshRfgi3OtE5v/2XL hzyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746711149; x=1747315949; h=in-reply-to:references:from:to:cc:subject:message-id:date :content-transfer-encoding:mime-version:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Ctop9M+S6pXp/ivb7RmdzyIsAM5dZO8eB9pvvIkCEbM=; b=I1ohQSeILJQQC6BLYIbh1bx9fNigYgLh4PR0DjxOVdIN2QQfbwBlfJO6Ie0Or6bxMS L0257jGIhuh0twh1FxF/lHyTnBDtp9B5hVCBPp/rgxU6A9wyCes3+625tn1miYqBH/TM x6dwklaNyR5XkY8v6P3EckmTzQlWy0FFBjRlnzQwAWxn19gxJ9tvmut14GnWAsYDEglp A2ccg7VAWRLNqJnTL/71vZE/s8s7tvq1GybDJGGhkh2GDi8D13I/C6cuYngjNevDTc+L fpUiQFTzBRBKeNZ1rBFunMJVZQNwsrJnmhQker2XohgXjW2To2fqolr8rBv8PlVkboQF pEfg== X-Gm-Message-State: AOJu0YyoUlG3cnQNoF/GhAYd1K3NUaTBaYKzVTEMUJNdagtml7RBTKMN 62xkFP1Nd3E1SVXdEbhHRxZ4zUHL9igLrw8hWLD3Is8Ksfokr2vfzuZUy9YobLw= X-Gm-Gg: ASbGncurJ8s3L8qgB7rd8ccrQ0fSGl2QdhMOa/lAKdkAv0x5o+qAPrJjgycFk+ykzS1 2CTF1iut0WUxe/+mOjvkWMhjlJ2BUKzpqBtk2Dn5Aw0TggLAF62Hej6Wx3VAsLfADJ+LViQ7mPI /Y1CmAtnvZ9vbk3lSnSeiZyy/zU/LnOYg6ZgbCgFfZCDmGepUro5fjMt/RQe39Y5obXrKk41JU+ BpG1ELCRNPFCGof7QrAS5L5nqIS0EBvrRBri/3RJM+VhwvaMKDLSce9rFBTI+puMSSUdQ4Y7JVp THpD4HtnGwgdzX4poeRsWZMTHaBxuA4GmvkvbONOA8bMAEn7 X-Google-Smtp-Source: AGHT+IFV8Gdwh/t9ZunwZV8yC9Gjd4YDqTg8K4dFRuyEe/kGcOgQumaKBu9osZaWckRfANKTr0Qn6g== X-Received: by 2002:a05:600c:cca:b0:439:a3df:66f3 with SMTP id 5b1f17b1804b1-441d44e57d6mr24537645e9.6.1746711149535; Thu, 08 May 2025 06:32:29 -0700 (PDT) Received: from localhost ([2a02:8308:a00c:e200:a451:a252:64ea:9a0e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-442cd32b0c8sm37984755e9.3.2025.05.08.06.32.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 May 2025 06:32:26 -0700 (PDT) Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 08 May 2025 15:32:25 +0200 Message-Id: Subject: Re: [PATCH 4/5] RISC-V: KVM: Enable envcfg and sstateen bits lazily Cc: , , , , "linux-riscv" To: "Atish Patra" , "Anup Patel" , "Atish Patra" , "Paul Walmsley" , "Palmer Dabbelt" , "Alexandre Ghiti" From: =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= References: <20250505-kvm_lazy_enable_stateen-v1-0-3bfc4008373c@rivosinc.com> <20250505-kvm_lazy_enable_stateen-v1-4-3bfc4008373c@rivosinc.com> In-Reply-To: <20250505-kvm_lazy_enable_stateen-v1-4-3bfc4008373c@rivosinc.com> 2025-05-05T14:39:29-07:00, Atish Patra : > SENVCFG and SSTATEEN CSRs are controlled by HSENVCFG(62) and > SSTATEEN0(63) bits in hstateen. Enable them lazily at runtime > instead of bootime. > > Signed-off-by: Atish Patra > --- > diff --git a/arch/riscv/kvm/vcpu_insn.c b/arch/riscv/kvm/vcpu_insn.c > @@ -256,9 +256,37 @@ int kvm_riscv_vcpu_hstateen_lazy_enable(struct kvm_v= cpu *vcpu, unsigned int csr_ > return KVM_INSN_CONTINUE_SAME_SEPC; > } > =20 > +static int kvm_riscv_vcpu_hstateen_enable_senvcfg(struct kvm_vcpu *vcpu, > + unsigned int csr_num, > + unsigned long *val, > + unsigned long new_val, > + unsigned long wr_mask) > +{ > + return kvm_riscv_vcpu_hstateen_lazy_enable(vcpu, csr_num, SMSTATEEN0_HS= ENVCFG); > +} Basically the same comments as for [1/5]: Why don't we want to set the ENVCFG bit (62) unconditionally? It would save us the trap on first access. We don't get anything from the trap, so it looks like a net negative to me. > + > +static int kvm_riscv_vcpu_hstateen_enable_stateen(struct kvm_vcpu *vcpu, > + unsigned int csr_num, > + unsigned long *val, > + unsigned long new_val, > + unsigned long wr_mask) > +{ > + const unsigned long *isa =3D vcpu->arch.isa; > + > + if (riscv_isa_extension_available(isa, SMSTATEEN)) > + return kvm_riscv_vcpu_hstateen_lazy_enable(vcpu, csr_num, SMSTATEEN0_S= STATEEN0); > + else > + return KVM_INSN_EXIT_TO_USER_SPACE; > +} The same argument applies to the SE0 bit (63) when the guest has the sstateen extension. KVM doesn't want to do anything other than stop trapping and reenter, so it seems to me we could just not trap in the first place. Thanks. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ECB77C3ABC0 for ; Thu, 8 May 2025 14:21:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:References:From:To:Cc: Subject:Message-Id:Date:Mime-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=KK+S+JLHiZvDmuMvPfMia7hjaMXg0sziP/grJWWaH+Y=; b=baG8P4WLRDMkZm kvvCGgcwx3wEGk6iRFX3o5DjKGTe+SNRtopiBcG2G7YbWkAIlOrHjWAOSp7yObJEE9Jmyxa2ueFS9 9dRAdD5RzzztBRLUPnCqYdi7VLsUA77KXtnKJrTb2uOwNOXvt+iTNmJpVOKmEkGujZQUj3vmWBDGL DAZgPrdjqjDwETzcD8nrUzdKgJTgqzenom2tkRrW3dOewZpDHmroTJr133vxRRNW58Glz6Q5jDqxd wzZdZ9nBZvG0y+Ud00V9ppH3QxdahvWxZGOQmLeqsocLdrQV3V6SJl3bEsNVmSL58aap79e92nbKg i432NYm7bN9wMeuvaBVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uD27i-00000000tme-1UbS; Thu, 08 May 2025 14:21:18 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uD1MV-00000000lA2-0Ety for linux-riscv@lists.infradead.org; Thu, 08 May 2025 13:32:32 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-43ceeb85ab2so456765e9.0 for ; Thu, 08 May 2025 06:32:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1746711149; x=1747315949; darn=lists.infradead.org; h=in-reply-to:references:from:to:cc:subject:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Ctop9M+S6pXp/ivb7RmdzyIsAM5dZO8eB9pvvIkCEbM=; b=ZcXIvPO0BnaOIGChIhid9UCEEE7wrJ2ophP5QqaVpOV58522scDSD4OBVRPOUovoXk /xPBfnWLVOnbM8w7NHpiEz8oPUHLFUqWjZJNrAPl8vZqxk+blqg2SHm2qm9fU16bQj4k 6agB2NB00qAS5g0l2GpuvEXTlYuytd7AznOyAcmAEJy1SEobbci+/NPCH5LpUt0eJLpn tnQK4tBn21zagYKC0fDAc+sN1+u3YVcPmRgYNmeG6QrWrK2CMSPfX8HmSbPstSpYprqC SB0uYyL3739daHrHsgcykZgLR5iaEO828Kg89/Z6dlHU0/L/9sAAPAMM4pvMAn1lBNV6 scNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746711149; x=1747315949; h=in-reply-to:references:from:to:cc:subject:message-id:date :content-transfer-encoding:mime-version:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Ctop9M+S6pXp/ivb7RmdzyIsAM5dZO8eB9pvvIkCEbM=; b=vclOcHCzTwnGalkC/Ic5k753YpxXQCFf3T9qbjzKkjFb0kJcyLlMQJlbwysxp7cs0p gUwuxDMe7s15UbpxHouVGqtj/mE5AN6Q/4WN+fddWcUYMy1BsvVLptiMals0iQYtvA15 o9sJnX0FyZPf20CLrzoiBaoth8Vm5CawlytCRwwe5W8Rc1PbnS4Nmym6hD/3FqAU15fA MrgrIco99haIxtJ6b5dJgvpjHfwQY7hi7Qq3943XeFmZjJHEuJDXn2yZcBZnQhFr1DCS V52iUUJ3abij0/gWKLtkY7Fz6vQsok9t0/wglosdrqK2BSHiXFApHd9EB6RBjtaAj5R2 eu0A== X-Forwarded-Encrypted: i=1; AJvYcCU31Qrg/rmu57V27Yrn0KVBlpf9DfkRtjvsNUZzvu8Rz0udrpR7qKb1dhiRqQthTphzyxrW8zcZYTg3sQ==@lists.infradead.org X-Gm-Message-State: AOJu0YywT6P5gesUby3RGjR4H4hNNTw/A0I1oIUjjJEiKo7qovaMwrKO m16zaxErhAiHimkolJ22F+++QfuLH9Kg/OLn2HuEZhZchLq4p+cyIymTOvKQC+M= X-Gm-Gg: ASbGncsrEa9BJoNrIexNJBBGpFiFBEBOHis79A27p0/ykc5nHUtGj/dNQC5SFFyy2Ph jyHf9BdfALE6HZiLto4ZWmoUN/BIVEQxPopHhVtOD1RRkxRA61bf+n3Q9xT7gkreAPz/1BU0DPG im/vBw/9Hj18NmaccYazsGigrgPfaweyhi9hJsaGUdFmEvfGLPfJEFfxmtrHegVIrrw03oBB2Ad iL5Y5buJuaJaQ5M0g0pQORHqnkyk6Kub6Vwg7EBZ5upy90AWUWeC3Jg+4yHCJOs/3s9EyKTgy1c kv7m3rL+y+U2G04jd5pRNza5DTTIYu8daaPIztMqnYdLRqO4 X-Google-Smtp-Source: AGHT+IFV8Gdwh/t9ZunwZV8yC9Gjd4YDqTg8K4dFRuyEe/kGcOgQumaKBu9osZaWckRfANKTr0Qn6g== X-Received: by 2002:a05:600c:cca:b0:439:a3df:66f3 with SMTP id 5b1f17b1804b1-441d44e57d6mr24537645e9.6.1746711149535; Thu, 08 May 2025 06:32:29 -0700 (PDT) Received: from localhost ([2a02:8308:a00c:e200:a451:a252:64ea:9a0e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-442cd32b0c8sm37984755e9.3.2025.05.08.06.32.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 May 2025 06:32:26 -0700 (PDT) Mime-Version: 1.0 Date: Thu, 08 May 2025 15:32:25 +0200 Message-Id: Subject: Re: [PATCH 4/5] RISC-V: KVM: Enable envcfg and sstateen bits lazily Cc: , , , , "linux-riscv" To: "Atish Patra" , "Anup Patel" , "Atish Patra" , "Paul Walmsley" , "Palmer Dabbelt" , "Alexandre Ghiti" From: =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= References: <20250505-kvm_lazy_enable_stateen-v1-0-3bfc4008373c@rivosinc.com> <20250505-kvm_lazy_enable_stateen-v1-4-3bfc4008373c@rivosinc.com> In-Reply-To: <20250505-kvm_lazy_enable_stateen-v1-4-3bfc4008373c@rivosinc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250508_063231_100245_704B8589 X-CRM114-Status: GOOD ( 15.21 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 2025-05-05T14:39:29-07:00, Atish Patra : > SENVCFG and SSTATEEN CSRs are controlled by HSENVCFG(62) and > SSTATEEN0(63) bits in hstateen. Enable them lazily at runtime > instead of bootime. > > Signed-off-by: Atish Patra > --- > diff --git a/arch/riscv/kvm/vcpu_insn.c b/arch/riscv/kvm/vcpu_insn.c > @@ -256,9 +256,37 @@ int kvm_riscv_vcpu_hstateen_lazy_enable(struct kvm_vcpu *vcpu, unsigned int csr_ > return KVM_INSN_CONTINUE_SAME_SEPC; > } > > +static int kvm_riscv_vcpu_hstateen_enable_senvcfg(struct kvm_vcpu *vcpu, > + unsigned int csr_num, > + unsigned long *val, > + unsigned long new_val, > + unsigned long wr_mask) > +{ > + return kvm_riscv_vcpu_hstateen_lazy_enable(vcpu, csr_num, SMSTATEEN0_HSENVCFG); > +} Basically the same comments as for [1/5]: Why don't we want to set the ENVCFG bit (62) unconditionally? It would save us the trap on first access. We don't get anything from the trap, so it looks like a net negative to me. > + > +static int kvm_riscv_vcpu_hstateen_enable_stateen(struct kvm_vcpu *vcpu, > + unsigned int csr_num, > + unsigned long *val, > + unsigned long new_val, > + unsigned long wr_mask) > +{ > + const unsigned long *isa = vcpu->arch.isa; > + > + if (riscv_isa_extension_available(isa, SMSTATEEN)) > + return kvm_riscv_vcpu_hstateen_lazy_enable(vcpu, csr_num, SMSTATEEN0_SSTATEEN0); > + else > + return KVM_INSN_EXIT_TO_USER_SPACE; > +} The same argument applies to the SE0 bit (63) when the guest has the sstateen extension. KVM doesn't want to do anything other than stop trapping and reenter, so it seems to me we could just not trap in the first place. Thanks. _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv