@@ -91,44 +91,44 @@ void kvm_riscv_vcpu_free_vector_context(struct kvm_vcpu *vcpu)
91
91
}
92
92
#endif
93
93
94
- static void * kvm_riscv_vcpu_vreg_addr (struct kvm_vcpu * vcpu ,
94
+ static int kvm_riscv_vcpu_vreg_addr (struct kvm_vcpu * vcpu ,
95
95
unsigned long reg_num ,
96
- size_t reg_size )
96
+ size_t reg_size ,
97
+ void * * reg_val )
97
98
{
98
99
struct kvm_cpu_context * cntx = & vcpu -> arch .guest_context ;
99
- void * reg_val ;
100
100
size_t vlenb = riscv_v_vsize / 32 ;
101
101
102
102
if (reg_num < KVM_REG_RISCV_VECTOR_REG (0 )) {
103
103
if (reg_size != sizeof (unsigned long ))
104
- return NULL ;
104
+ return - EINVAL ;
105
105
switch (reg_num ) {
106
106
case KVM_REG_RISCV_VECTOR_CSR_REG (vstart ):
107
- reg_val = & cntx -> vector .vstart ;
107
+ * reg_val = & cntx -> vector .vstart ;
108
108
break ;
109
109
case KVM_REG_RISCV_VECTOR_CSR_REG (vl ):
110
- reg_val = & cntx -> vector .vl ;
110
+ * reg_val = & cntx -> vector .vl ;
111
111
break ;
112
112
case KVM_REG_RISCV_VECTOR_CSR_REG (vtype ):
113
- reg_val = & cntx -> vector .vtype ;
113
+ * reg_val = & cntx -> vector .vtype ;
114
114
break ;
115
115
case KVM_REG_RISCV_VECTOR_CSR_REG (vcsr ):
116
- reg_val = & cntx -> vector .vcsr ;
116
+ * reg_val = & cntx -> vector .vcsr ;
117
117
break ;
118
118
case KVM_REG_RISCV_VECTOR_CSR_REG (datap ):
119
119
default :
120
- return NULL ;
120
+ return - ENOENT ;
121
121
}
122
122
} else if (reg_num <= KVM_REG_RISCV_VECTOR_REG (31 )) {
123
123
if (reg_size != vlenb )
124
- return NULL ;
125
- reg_val = cntx -> vector .datap
124
+ return - EINVAL ;
125
+ * reg_val = cntx -> vector .datap
126
126
+ (reg_num - KVM_REG_RISCV_VECTOR_REG (0 )) * vlenb ;
127
127
} else {
128
- return NULL ;
128
+ return - ENOENT ;
129
129
}
130
130
131
- return reg_val ;
131
+ return 0 ;
132
132
}
133
133
134
134
int kvm_riscv_vcpu_get_reg_vector (struct kvm_vcpu * vcpu ,
@@ -141,17 +141,20 @@ int kvm_riscv_vcpu_get_reg_vector(struct kvm_vcpu *vcpu,
141
141
unsigned long reg_num = reg -> id & ~(KVM_REG_ARCH_MASK |
142
142
KVM_REG_SIZE_MASK |
143
143
rtype );
144
- void * reg_val = NULL ;
145
144
size_t reg_size = KVM_REG_SIZE (reg -> id );
145
+ void * reg_val ;
146
+ int rc ;
146
147
147
- if (rtype == KVM_REG_RISCV_VECTOR &&
148
- riscv_isa_extension_available (isa , v )) {
149
- reg_val = kvm_riscv_vcpu_vreg_addr (vcpu , reg_num , reg_size );
150
- }
151
-
152
- if (!reg_val )
148
+ if (rtype != KVM_REG_RISCV_VECTOR )
153
149
return - EINVAL ;
154
150
151
+ if (!riscv_isa_extension_available (isa , v ))
152
+ return - ENOENT ;
153
+
154
+ rc = kvm_riscv_vcpu_vreg_addr (vcpu , reg_num , reg_size , & reg_val );
155
+ if (rc )
156
+ return rc ;
157
+
155
158
if (copy_to_user (uaddr , reg_val , reg_size ))
156
159
return - EFAULT ;
157
160
@@ -168,17 +171,20 @@ int kvm_riscv_vcpu_set_reg_vector(struct kvm_vcpu *vcpu,
168
171
unsigned long reg_num = reg -> id & ~(KVM_REG_ARCH_MASK |
169
172
KVM_REG_SIZE_MASK |
170
173
rtype );
171
- void * reg_val = NULL ;
172
174
size_t reg_size = KVM_REG_SIZE (reg -> id );
175
+ void * reg_val ;
176
+ int rc ;
173
177
174
- if (rtype == KVM_REG_RISCV_VECTOR &&
175
- riscv_isa_extension_available (isa , v )) {
176
- reg_val = kvm_riscv_vcpu_vreg_addr (vcpu , reg_num , reg_size );
177
- }
178
-
179
- if (!reg_val )
178
+ if (rtype != KVM_REG_RISCV_VECTOR )
180
179
return - EINVAL ;
181
180
181
+ if (!riscv_isa_extension_available (isa , v ))
182
+ return - ENOENT ;
183
+
184
+ rc = kvm_riscv_vcpu_vreg_addr (vcpu , reg_num , reg_size , & reg_val );
185
+ if (rc )
186
+ return rc ;
187
+
182
188
if (copy_from_user (reg_val , uaddr , reg_size ))
183
189
return - EFAULT ;
184
190
0 commit comments