2022-08-25 20:25:04

by Janis Schoetterl-Glausch

[permalink] [raw]
Subject: [PATCH v2] KVM: s390: Pass initialized arg even if unused

This silences smatch warnings reported by kbuild bot:
arch/s390/kvm/gaccess.c:859 guest_range_to_gpas() error: uninitialized symbol 'prot'.
arch/s390/kvm/gaccess.c:1064 access_guest_with_key() error: uninitialized symbol 'prot'.

This is because it cannot tell that the value is not used in this case.
The trans_exc* only examine prot if code is PGM_PROTECTION.
Pass a dummy value for other codes.

Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Janis Schoetterl-Glausch <[email protected]>
---
v1 -> v2
* drop unlikely, WARN_ON_ONCE instead of WARN (thanks Heiko)

arch/s390/kvm/gaccess.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/arch/s390/kvm/gaccess.c b/arch/s390/kvm/gaccess.c
index 082ec5f2c3a5..0243b6e38d36 100644
--- a/arch/s390/kvm/gaccess.c
+++ b/arch/s390/kvm/gaccess.c
@@ -489,6 +489,8 @@ enum prot_type {
PROT_TYPE_ALC = 2,
PROT_TYPE_DAT = 3,
PROT_TYPE_IEP = 4,
+ /* Dummy value for passing an initialized value when code != PGM_PROTECTION */
+ PROT_NONE,
};

static int trans_exc_ending(struct kvm_vcpu *vcpu, int code, unsigned long gva, u8 ar,
@@ -504,6 +506,10 @@ static int trans_exc_ending(struct kvm_vcpu *vcpu, int code, unsigned long gva,
switch (code) {
case PGM_PROTECTION:
switch (prot) {
+ case PROT_NONE:
+ /* We should never get here, acts like termination */
+ WARN_ON_ONCE(1);
+ break;
case PROT_TYPE_IEP:
tec->b61 = 1;
fallthrough;
@@ -968,8 +974,10 @@ static int guest_range_to_gpas(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
return rc;
} else {
gpa = kvm_s390_real_to_abs(vcpu, ga);
- if (kvm_is_error_gpa(vcpu->kvm, gpa))
+ if (kvm_is_error_gpa(vcpu->kvm, gpa)) {
rc = PGM_ADDRESSING;
+ prot = PROT_NONE;
+ }
}
if (rc)
return trans_exc(vcpu, rc, ga, ar, mode, prot);
@@ -1112,8 +1120,6 @@ int access_guest_with_key(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
if (rc == PGM_PROTECTION && try_storage_prot_override)
rc = access_guest_page_with_key(vcpu->kvm, mode, gpas[idx],
data, fragment_len, PAGE_SPO_ACC);
- if (rc == PGM_PROTECTION)
- prot = PROT_TYPE_KEYC;
if (rc)
break;
len -= fragment_len;
@@ -1123,6 +1129,10 @@ int access_guest_with_key(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
if (rc > 0) {
bool terminate = (mode == GACC_STORE) && (idx > 0);

+ if (rc == PGM_PROTECTION)
+ prot = PROT_TYPE_KEYC;
+ else
+ prot = PROT_NONE;
rc = trans_exc_ending(vcpu, rc, ga, ar, mode, prot, terminate);
}
out_unlock:
--
2.34.1


2022-08-31 15:41:20

by Claudio Imbrenda

[permalink] [raw]
Subject: Re: [PATCH v2] KVM: s390: Pass initialized arg even if unused

On Thu, 25 Aug 2022 21:25:40 +0200
Janis Schoetterl-Glausch <[email protected]> wrote:

> This silences smatch warnings reported by kbuild bot:
> arch/s390/kvm/gaccess.c:859 guest_range_to_gpas() error: uninitialized symbol 'prot'.
> arch/s390/kvm/gaccess.c:1064 access_guest_with_key() error: uninitialized symbol 'prot'.
>
> This is because it cannot tell that the value is not used in this case.
> The trans_exc* only examine prot if code is PGM_PROTECTION.
> Pass a dummy value for other codes.
>
> Reported-by: kernel test robot <[email protected]>
> Reported-by: Dan Carpenter <[email protected]>
> Signed-off-by: Janis Schoetterl-Glausch <[email protected]>

Reviewed-by: Claudio Imbrenda <[email protected]>

> ---
> v1 -> v2
> * drop unlikely, WARN_ON_ONCE instead of WARN (thanks Heiko)
>
> arch/s390/kvm/gaccess.c | 16 +++++++++++++---
> 1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/arch/s390/kvm/gaccess.c b/arch/s390/kvm/gaccess.c
> index 082ec5f2c3a5..0243b6e38d36 100644
> --- a/arch/s390/kvm/gaccess.c
> +++ b/arch/s390/kvm/gaccess.c
> @@ -489,6 +489,8 @@ enum prot_type {
> PROT_TYPE_ALC = 2,
> PROT_TYPE_DAT = 3,
> PROT_TYPE_IEP = 4,
> + /* Dummy value for passing an initialized value when code != PGM_PROTECTION */
> + PROT_NONE,
> };
>
> static int trans_exc_ending(struct kvm_vcpu *vcpu, int code, unsigned long gva, u8 ar,
> @@ -504,6 +506,10 @@ static int trans_exc_ending(struct kvm_vcpu *vcpu, int code, unsigned long gva,
> switch (code) {
> case PGM_PROTECTION:
> switch (prot) {
> + case PROT_NONE:
> + /* We should never get here, acts like termination */
> + WARN_ON_ONCE(1);
> + break;
> case PROT_TYPE_IEP:
> tec->b61 = 1;
> fallthrough;
> @@ -968,8 +974,10 @@ static int guest_range_to_gpas(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
> return rc;
> } else {
> gpa = kvm_s390_real_to_abs(vcpu, ga);
> - if (kvm_is_error_gpa(vcpu->kvm, gpa))
> + if (kvm_is_error_gpa(vcpu->kvm, gpa)) {
> rc = PGM_ADDRESSING;
> + prot = PROT_NONE;
> + }
> }
> if (rc)
> return trans_exc(vcpu, rc, ga, ar, mode, prot);
> @@ -1112,8 +1120,6 @@ int access_guest_with_key(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
> if (rc == PGM_PROTECTION && try_storage_prot_override)
> rc = access_guest_page_with_key(vcpu->kvm, mode, gpas[idx],
> data, fragment_len, PAGE_SPO_ACC);
> - if (rc == PGM_PROTECTION)
> - prot = PROT_TYPE_KEYC;
> if (rc)
> break;
> len -= fragment_len;
> @@ -1123,6 +1129,10 @@ int access_guest_with_key(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
> if (rc > 0) {
> bool terminate = (mode == GACC_STORE) && (idx > 0);
>
> + if (rc == PGM_PROTECTION)
> + prot = PROT_TYPE_KEYC;
> + else
> + prot = PROT_NONE;
> rc = trans_exc_ending(vcpu, rc, ga, ar, mode, prot, terminate);
> }
> out_unlock:

2022-09-19 16:25:46

by Christian Borntraeger

[permalink] [raw]
Subject: Re: [PATCH v2] KVM: s390: Pass initialized arg even if unused



Am 25.08.22 um 21:25 schrieb Janis Schoetterl-Glausch:
> This silences smatch warnings reported by kbuild bot:
> arch/s390/kvm/gaccess.c:859 guest_range_to_gpas() error: uninitialized symbol 'prot'.
> arch/s390/kvm/gaccess.c:1064 access_guest_with_key() error: uninitialized symbol 'prot'.
>
> This is because it cannot tell that the value is not used in this case.
> The trans_exc* only examine prot if code is PGM_PROTECTION.
> Pass a dummy value for other codes.
>
> Reported-by: kernel test robot <[email protected]>
> Reported-by: Dan Carpenter <[email protected]>
> Signed-off-by: Janis Schoetterl-Glausch <[email protected]>

Thanks applied.
> ---
> v1 -> v2
> * drop unlikely, WARN_ON_ONCE instead of WARN (thanks Heiko)
>
> arch/s390/kvm/gaccess.c | 16 +++++++++++++---
> 1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/arch/s390/kvm/gaccess.c b/arch/s390/kvm/gaccess.c
> index 082ec5f2c3a5..0243b6e38d36 100644
> --- a/arch/s390/kvm/gaccess.c
> +++ b/arch/s390/kvm/gaccess.c
> @@ -489,6 +489,8 @@ enum prot_type {
> PROT_TYPE_ALC = 2,
> PROT_TYPE_DAT = 3,
> PROT_TYPE_IEP = 4,
> + /* Dummy value for passing an initialized value when code != PGM_PROTECTION */
> + PROT_NONE,
> };
>
> static int trans_exc_ending(struct kvm_vcpu *vcpu, int code, unsigned long gva, u8 ar,
> @@ -504,6 +506,10 @@ static int trans_exc_ending(struct kvm_vcpu *vcpu, int code, unsigned long gva,
> switch (code) {
> case PGM_PROTECTION:
> switch (prot) {
> + case PROT_NONE:
> + /* We should never get here, acts like termination */
> + WARN_ON_ONCE(1);
> + break;
> case PROT_TYPE_IEP:
> tec->b61 = 1;
> fallthrough;
> @@ -968,8 +974,10 @@ static int guest_range_to_gpas(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
> return rc;
> } else {
> gpa = kvm_s390_real_to_abs(vcpu, ga);
> - if (kvm_is_error_gpa(vcpu->kvm, gpa))
> + if (kvm_is_error_gpa(vcpu->kvm, gpa)) {
> rc = PGM_ADDRESSING;
> + prot = PROT_NONE;
> + }
> }
> if (rc)
> return trans_exc(vcpu, rc, ga, ar, mode, prot);
> @@ -1112,8 +1120,6 @@ int access_guest_with_key(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
> if (rc == PGM_PROTECTION && try_storage_prot_override)
> rc = access_guest_page_with_key(vcpu->kvm, mode, gpas[idx],
> data, fragment_len, PAGE_SPO_ACC);
> - if (rc == PGM_PROTECTION)
> - prot = PROT_TYPE_KEYC;
> if (rc)
> break;
> len -= fragment_len;
> @@ -1123,6 +1129,10 @@ int access_guest_with_key(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
> if (rc > 0) {
> bool terminate = (mode == GACC_STORE) && (idx > 0);
>
> + if (rc == PGM_PROTECTION)
> + prot = PROT_TYPE_KEYC;
> + else
> + prot = PROT_NONE;
> rc = trans_exc_ending(vcpu, rc, ga, ar, mode, prot, terminate);
> }
> out_unlock: