Skip to content

Commit 7be3e33

Browse files
Pierre Morelfrankjaa
authored andcommitted
KVM: s390: vsie: clarifications on setting the APCB
The APCB is part of the CRYCB. The calculation of the APCB origin can be done by adding the APCB offset to the CRYCB origin. Current code makes confusing transformations, converting the CRYCB origin to a pointer to calculate the APCB origin. Let's make things simpler and keep the CRYCB origin to make these calculations. Signed-off-by: Pierre Morel <pmorel@linux.ibm.com> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Acked-by: David Hildenbrand <david@redhat.com> Acked-by: Janosch Frank <frankja@linux.ibm.com> Signed-off-by: Janosch Frank <frankja@linux.ibm.com> Link: https://lore.kernel.org/r/20230214122841.13066-2-pmorel@linux.ibm.com Message-Id: <20230214122841.13066-2-pmorel@linux.ibm.com>
1 parent 2f2c091 commit 7be3e33

1 file changed

Lines changed: 29 additions & 21 deletions

File tree

arch/s390/kvm/vsie.c

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,15 @@ static int prepare_cpuflags(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
138138
}
139139
/* Copy to APCB FORMAT1 from APCB FORMAT0 */
140140
static int setup_apcb10(struct kvm_vcpu *vcpu, struct kvm_s390_apcb1 *apcb_s,
141-
unsigned long apcb_o, struct kvm_s390_apcb1 *apcb_h)
141+
unsigned long crycb_gpa, struct kvm_s390_apcb1 *apcb_h)
142142
{
143143
struct kvm_s390_apcb0 tmp;
144+
unsigned long apcb_gpa;
144145

145-
if (read_guest_real(vcpu, apcb_o, &tmp, sizeof(struct kvm_s390_apcb0)))
146+
apcb_gpa = crycb_gpa + offsetof(struct kvm_s390_crypto_cb, apcb0);
147+
148+
if (read_guest_real(vcpu, apcb_gpa, &tmp,
149+
sizeof(struct kvm_s390_apcb0)))
146150
return -EFAULT;
147151

148152
apcb_s->apm[0] = apcb_h->apm[0] & tmp.apm[0];
@@ -157,15 +161,19 @@ static int setup_apcb10(struct kvm_vcpu *vcpu, struct kvm_s390_apcb1 *apcb_s,
157161
* setup_apcb00 - Copy to APCB FORMAT0 from APCB FORMAT0
158162
* @vcpu: pointer to the virtual CPU
159163
* @apcb_s: pointer to start of apcb in the shadow crycb
160-
* @apcb_o: pointer to start of original apcb in the guest2
164+
* @crycb_gpa: guest physical address to start of original guest crycb
161165
* @apcb_h: pointer to start of apcb in the guest1
162166
*
163167
* Returns 0 and -EFAULT on error reading guest apcb
164168
*/
165169
static int setup_apcb00(struct kvm_vcpu *vcpu, unsigned long *apcb_s,
166-
unsigned long apcb_o, unsigned long *apcb_h)
170+
unsigned long crycb_gpa, unsigned long *apcb_h)
167171
{
168-
if (read_guest_real(vcpu, apcb_o, apcb_s,
172+
unsigned long apcb_gpa;
173+
174+
apcb_gpa = crycb_gpa + offsetof(struct kvm_s390_crypto_cb, apcb0);
175+
176+
if (read_guest_real(vcpu, apcb_gpa, apcb_s,
169177
sizeof(struct kvm_s390_apcb0)))
170178
return -EFAULT;
171179

@@ -178,16 +186,20 @@ static int setup_apcb00(struct kvm_vcpu *vcpu, unsigned long *apcb_s,
178186
* setup_apcb11 - Copy the FORMAT1 APCB from the guest to the shadow CRYCB
179187
* @vcpu: pointer to the virtual CPU
180188
* @apcb_s: pointer to start of apcb in the shadow crycb
181-
* @apcb_o: pointer to start of original guest apcb
189+
* @crycb_gpa: guest physical address to start of original guest crycb
182190
* @apcb_h: pointer to start of apcb in the host
183191
*
184192
* Returns 0 and -EFAULT on error reading guest apcb
185193
*/
186194
static int setup_apcb11(struct kvm_vcpu *vcpu, unsigned long *apcb_s,
187-
unsigned long apcb_o,
195+
unsigned long crycb_gpa,
188196
unsigned long *apcb_h)
189197
{
190-
if (read_guest_real(vcpu, apcb_o, apcb_s,
198+
unsigned long apcb_gpa;
199+
200+
apcb_gpa = crycb_gpa + offsetof(struct kvm_s390_crypto_cb, apcb1);
201+
202+
if (read_guest_real(vcpu, apcb_gpa, apcb_s,
191203
sizeof(struct kvm_s390_apcb1)))
192204
return -EFAULT;
193205

@@ -200,7 +212,7 @@ static int setup_apcb11(struct kvm_vcpu *vcpu, unsigned long *apcb_s,
200212
* setup_apcb - Create a shadow copy of the apcb.
201213
* @vcpu: pointer to the virtual CPU
202214
* @crycb_s: pointer to shadow crycb
203-
* @crycb_o: pointer to original guest crycb
215+
* @crycb_gpa: guest physical address of original guest crycb
204216
* @crycb_h: pointer to the host crycb
205217
* @fmt_o: format of the original guest crycb.
206218
* @fmt_h: format of the host crycb.
@@ -211,50 +223,46 @@ static int setup_apcb11(struct kvm_vcpu *vcpu, unsigned long *apcb_s,
211223
* Return 0 or an error number if the guest and host crycb are incompatible.
212224
*/
213225
static int setup_apcb(struct kvm_vcpu *vcpu, struct kvm_s390_crypto_cb *crycb_s,
214-
const u32 crycb_o,
226+
const u32 crycb_gpa,
215227
struct kvm_s390_crypto_cb *crycb_h,
216228
int fmt_o, int fmt_h)
217229
{
218-
struct kvm_s390_crypto_cb *crycb;
219-
220-
crycb = (struct kvm_s390_crypto_cb *) (unsigned long)crycb_o;
221-
222230
switch (fmt_o) {
223231
case CRYCB_FORMAT2:
224-
if ((crycb_o & PAGE_MASK) != ((crycb_o + 256) & PAGE_MASK))
232+
if ((crycb_gpa & PAGE_MASK) != ((crycb_gpa + 256) & PAGE_MASK))
225233
return -EACCES;
226234
if (fmt_h != CRYCB_FORMAT2)
227235
return -EINVAL;
228236
return setup_apcb11(vcpu, (unsigned long *)&crycb_s->apcb1,
229-
(unsigned long) &crycb->apcb1,
237+
crycb_gpa,
230238
(unsigned long *)&crycb_h->apcb1);
231239
case CRYCB_FORMAT1:
232240
switch (fmt_h) {
233241
case CRYCB_FORMAT2:
234242
return setup_apcb10(vcpu, &crycb_s->apcb1,
235-
(unsigned long) &crycb->apcb0,
243+
crycb_gpa,
236244
&crycb_h->apcb1);
237245
case CRYCB_FORMAT1:
238246
return setup_apcb00(vcpu,
239247
(unsigned long *) &crycb_s->apcb0,
240-
(unsigned long) &crycb->apcb0,
248+
crycb_gpa,
241249
(unsigned long *) &crycb_h->apcb0);
242250
}
243251
break;
244252
case CRYCB_FORMAT0:
245-
if ((crycb_o & PAGE_MASK) != ((crycb_o + 32) & PAGE_MASK))
253+
if ((crycb_gpa & PAGE_MASK) != ((crycb_gpa + 32) & PAGE_MASK))
246254
return -EACCES;
247255

248256
switch (fmt_h) {
249257
case CRYCB_FORMAT2:
250258
return setup_apcb10(vcpu, &crycb_s->apcb1,
251-
(unsigned long) &crycb->apcb0,
259+
crycb_gpa,
252260
&crycb_h->apcb1);
253261
case CRYCB_FORMAT1:
254262
case CRYCB_FORMAT0:
255263
return setup_apcb00(vcpu,
256264
(unsigned long *) &crycb_s->apcb0,
257-
(unsigned long) &crycb->apcb0,
265+
crycb_gpa,
258266
(unsigned long *) &crycb_h->apcb0);
259267
}
260268
}

0 commit comments

Comments
 (0)