From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE8CD353EFD for ; Thu, 29 Jan 2026 17:40:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769708426; cv=none; b=HmIsh7cK3H0oSKqQjrl0a/uG3yRrAZZ1IUq5BqBIXrWOpwcTXqRJ8YXlttII/+3SE6fKq9rRcsmDDy1kuiCKBntVXeFvl5ahEfIuWr+vF59bxYgO3L1eOuFLL8Nkr+dDH2yyAW8AWUmMgGcTqU//IUp2+Ka8LI1ZD/nnybOd7Mc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769708426; c=relaxed/simple; bh=Y7xSqJOLzh/EuohcFb1CceBmaiKhuh4bwDL5EdHyAP4=; h=Mime-Version:Content-Type:Date:Message-Id:Subject:Cc:To:From: References:In-Reply-To; b=nd21TO/+9noDLgq3d4+HG10b1yeRRySDLhaz9R/16zxgnH0fjWDQoaudtJgw0xFEq+bbsTQv0U20ZowVoG3z4ohGqyRLjH1aemEfIhmE/+mbcfxb0lvGWAMiyaAXH6BFjS+QxQVymXMrFVjgtzjNLA7rsEgKjBHIG58++xnaE5Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=f7V7Hx79; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=FY4c2kG4; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="f7V7Hx79"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="FY4c2kG4" Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 60THVmh52033226 for ; Thu, 29 Jan 2026 17:40:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= X7MOImJj+nJlLfYhfSrfFXuD7mz/bcT1kMUBG+e2q/g=; b=f7V7Hx79jkuVVvVr I3cL1XQ68fPAOX24673vkTDdAOoC1EHZZgyJDUv495w0gl5j8bxtYrHw/jT1JpwH RRflRq295ifnjRKV1bKN7aMA+1rBb98hcmGsZFXJ+ymi8Ph7RXYB7J/KuNimU4AV ndEEeSl5h6ZWF+brJjlshuUN8pnRsl30aL19U1UNoSQf5jqQtw5LhpPi0Urj1+H9 AFrFTZ4O1+3CiO7hOANxU/BuaxF03hJiXgSYSJRgzIypXdszXMMaWBS6K4Ef1Sv3 Raie5SYbYv1mN6xTlOj9UPE8z760GiThwxWm0xIHuvgahfHQfOUsSgJbf9QDNFmw SHTLbA== Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4bytqy3jds-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 29 Jan 2026 17:40:21 +0000 (GMT) Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-8c5e166fb75so366012885a.0 for ; Thu, 29 Jan 2026 09:40:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1769708421; x=1770313221; 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=X7MOImJj+nJlLfYhfSrfFXuD7mz/bcT1kMUBG+e2q/g=; b=FY4c2kG4wxzjINBEorFZTXA/jhDzthnFZBQpfPIeuFgdXOMwL5MndPwelo7ZzsUM1o IeooQDn9JrDmFrgfQX8Etti/hEMHJBuQLbuozC8yP4+8gSbkWpkuk3kMoKGsXD/Dk6op cdaR1inpu2gUtJKM1QikoCIxU8eSwJNJmm7oAALJbU+2ZBAeP1EBj2miS3BYZUUViu7H 5L/dkdlUCI3XkTrGwlJ/QfM20CJ0HsJxkZfby4sOhTrMa63OBF0SUKVS76pabYduDSjy S9pyTELb0o4cT2piHryA3VB+I0zvNqmvPAoPTSRLUu3mgescX9PbAp+8JatwsDB9s1Ya bpsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769708421; x=1770313221; h=in-reply-to:references:from:to:cc:subject:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=X7MOImJj+nJlLfYhfSrfFXuD7mz/bcT1kMUBG+e2q/g=; b=WIHbzLKk0XltK1uxu9q4ob3DKVm85MKp6LKBf77aKaAgxeZGGw1bGaDaRQOX7w20hC jMEjNpJ5T5FiZp6sMFII/XhI/cHwk+qY5ruojcMNrMvmfPi7lFHSm4ac27UWI9qohLBt OyBFjeQUqlV+BV/Y254Hqi1RjeMbrTc+fhjxdkqZW9kL0V831pZzdxvlgqopow9I8lhy LAXYo7DwXKiOkeIq3KE/xvvif2l98Y6xUVl4EmOnA3fgHaz71/pnlqgKy0xhm4CCoZj5 SaAoR93u0WjBGL/Ov9BioOB3bXjz/fSD8JhT3iWilx1f1I2gnYC1VwhVk2ocyhiFip5a 6iDQ== X-Forwarded-Encrypted: i=1; AJvYcCXKG1i6SWmMeMyaJiol+nIjTBZBANE1+avSzLWfzmrBX7L3p/yrM3qQazFO6dNM6u9SuLepMeMOxD1slRo=@vger.kernel.org X-Gm-Message-State: AOJu0YyiOlbxPWbVDdtsCXXjTOeMRasURodubgC1MsZOvMZx17ysYiL8 zZqtOLkFUUV193eQDh9Tv8EoLfXMSeS8wcSoN1vtt11IZO8vpUnCnNLhqCY1gnX1Wqsjq+H3GwG 4BkDuSrlgPawVpCY8QWet3dNcPMcijTsYTE15LCcN1JC9t/0O0VjMnPIRoM8sMTCMNsg= X-Gm-Gg: AZuq6aINtIbbZ7eoYJ6oEbPozUc9BOWZLN4ydxvZoSgtGqEybSRm5CgAbK0tCUu3m0b uCScKi/yv6f3xcX+BzNzPUxZ+saExZpygwWPfFHKxyBgfTrrpw8R5U2yRPmJFBsBh5ehsUvVdpn tUWQD4TEIchN1tRmQIdnRnDvIMIKbNtFuXr0E4lIy9Q/1ZRirC8CcbPq0XHg6F4TRWq978zwpai yVGuKQsVtXTM64RkOzh3c4O1l8sVS+d1780kaPXyei+APq9Nzt955ijuVGpjDqbBMh4/tFJmPTj NfmN0W91eOHpbYLick8nX6LYYjN7++UhvAMZxfMSiCUC56h1Jlub34sVMloP0+vVe4SnLrRQDz2 LkbRXJsZyZEofXmlUljse7iNo1rO1x0+rji0criRZAX0/Db64 X-Received: by 2002:a05:620a:7103:b0:8c5:378f:4def with SMTP id af79cd13be357-8c9eb320122mr57574785a.77.1769708420630; Thu, 29 Jan 2026 09:40:20 -0800 (PST) X-Received: by 2002:a05:620a:7103:b0:8c5:378f:4def with SMTP id af79cd13be357-8c9eb320122mr57568485a.77.1769708419892; Thu, 29 Jan 2026 09:40:19 -0800 (PST) Received: from localhost (ip-86-49-253-11.bb.vodafone.cz. [86.49.253.11]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-480705956f1sm111648965e9.11.2026.01.29.09.40.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jan 2026 09:40:19 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@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, 29 Jan 2026 17:40:17 +0000 Message-Id: Subject: Re: [PATCH v3 2/2] RISC-V: KVM: add KVM_CAP_RISCV_SET_HGATP_MODE Cc: , , , , , , To: , , , , , , , , , From: =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= References: <20260125150450.27068-1-fangyu.yu@linux.alibaba.com> <20260125150450.27068-3-fangyu.yu@linux.alibaba.com> In-Reply-To: <20260125150450.27068-3-fangyu.yu@linux.alibaba.com> X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMTI5MDEyNSBTYWx0ZWRfX5qVbUS1CY6c7 i3XiascVw04vAw35dxWLdPi+7kGPj137dY8ljFkKK2iYMK55F20MZgNPjMxumStfSwGwfE20rt9 iJXAbzQejgrj4JGi9uYdP9bS0EUWa9EdtONzzhHFnQ+TJ2o+hS6MAoxguZgJPhkQ1Tgm8mTZvTZ ZR1bRSHiCP0Js87m3kDbijv1wZnhavFU/C6jOXKaUqcS7PXodDkTCZPWTKB7yZjuBlofn7P7SMn mI1SuSofqDqYXHqv5OdRlmE6dA246ybSOi4aCWKbfW504/l80jgAIm6wY3FgdXg53+Re0SEVEeM aucZSfUMgWW8Z+gpx5pqq0f092xda3wWV7WqxPD3Vckn7aEDGbm8W/M4EoKNxwYZpGAO/XHO7Gs qu4jM+Pr3V0rijq/VctI5MHN5ehU9v6NjfElrCHzJrBE7HvXlL22hrsACCq9StLxt40jage22zI GJGHN6vmMACTKG4fUmA== X-Authority-Analysis: v=2.4 cv=Je2xbEKV c=1 sm=1 tr=0 ts=697b9b85 cx=c_pps a=HLyN3IcIa5EE8TELMZ618Q==:117 a=HFCiZzTCIv7qJCpyeE1rag==:17 a=IkcTkHD0fZMA:10 a=vUbySO9Y5rIA:10 a=M51BFTxLslgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=SRrdq9N9AAAA:8 a=Cpfndy8aBPzOrYTrbFgA:9 a=QEXdDO2ut3YA:10 a=bTQJ7kPSJx9SKPbeHEYW:22 X-Proofpoint-ORIG-GUID: jTjczldPZ-kZGd041gI7ONm0Omb4kJGJ X-Proofpoint-GUID: jTjczldPZ-kZGd041gI7ONm0Omb4kJGJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-01-29_02,2026-01-29_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 adultscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 spamscore=0 impostorscore=0 clxscore=1015 bulkscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2601290125 2026-01-25T23:04:50+08:00, : > From: Fangyu Yu > > This capability allows userspace to explicitly select the HGATP mode > for the VM. The selected mode must be less than or equal to the max > HGATP mode supported by the hardware. This capability must be enabled > before creating any vCPUs, and can only be set once per VM. > > Signed-off-by: Fangyu Yu > --- > Documentation/virt/kvm/api.rst | 18 ++++++++++++++++++ > arch/riscv/kvm/vm.c | 26 ++++++++++++++++++++++++-- > include/uapi/linux/kvm.h | 1 + > 3 files changed, 43 insertions(+), 2 deletions(-) > > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.= rst > @@ -8765,6 +8765,24 @@ helpful if user space wants to emulate instruction= s which are not > +7.47 KVM_CAP_RISCV_SET_HGATP_MODE > +--------------------------------- > + > +:Architectures: riscv > +:Type: VM > +:Parameters: args[0] contains the requested HGATP mode > +:Returns: > + - 0 on success. > + - -EINVAL if args[0] is outside the range of HGATP modes supported by = the > + hardware. > + - -EBUSY if vCPUs have already been created for the VM, if the VM has = any > + non-empty memslots, or if the capability has already been set for th= e VM. > + > +This capability allows userspace to explicitly select the HGATP mode for > +the VM. The selected mode must be less than or equal to the maximum HGAT= P > +mode supported by the hardware. "The selected mode must be supported by both KVM and hardware." (The comparison is a technical detail, and incorrect too since the value is bouded from the bottom as well.) > This capability must be enabled before > +creating any vCPUs, and can only be set once per VM. ^ "or memslots" > diff --git a/arch/riscv/kvm/vm.c b/arch/riscv/kvm/vm.c > @@ -202,6 +202,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, lon= g ext) > case KVM_CAP_VM_GPA_BITS: > r =3D kvm_riscv_gstage_gpa_bits(&kvm->arch); > break; > + case KVM_CAP_RISCV_SET_HGATP_MODE: > + r =3D IS_ENABLED(CONFIG_64BIT) ? 1 : 0; Maybe we can return the currently selected mode for a bit of extra info? Another nice option would be to return a bitmask of all supported modes. I think userspace has otherwise no reason to call it, since it's fine to just try enable and handle the -EINVAL as "don't care". 1 syscall instead of 2. > @@ -212,12 +215,31 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, l= ong ext) > =20 > int kvm_vm_ioctl_enable_cap(struct kvm *kvm, struct kvm_enable_cap *cap) > { > + case KVM_CAP_RISCV_SET_HGATP_MODE: > +#ifdef CONFIG_64BIT > + if (cap->args[0] < HGATP_MODE_SV39X4 || > + cap->args[0] > kvm_riscv_gstage_mode(kvm_riscv_gstage_max_pgd_leve= ls)) > + return -EINVAL; > + > + if (kvm->arch.gstage_mode_user_initialized || kvm->created_vcpus || > + !kvm_are_all_memslots_empty(kvm)) > + return -EBUSY; > + > + kvm->arch.gstage_mode_user_initialized =3D true; No need to have gstage_mode_user_initialized, since if the user could have changed it once, there shouldn't be an issue in changing it again. It's the other protections that must work. > + kvm->arch.kvm_riscv_gstage_pgd_levels =3D > + 3 + cap->args[0] - HGATP_MODE_SV39X4; > + kvm_debug("VM (vmid:%lu) using SV%lluX4 G-stage page table format\n", > + kvm->arch.vmid.vmid, > + 39 + (cap->args[0] - HGATP_MODE_SV39X4) * 9); (I don't think this debug message is going to be useful after a short debugging period, and it would clog the log on each VM launch, so I'd rather get rid of it.) Thanks.