lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <e96b3c20055105af9ba76f0abefeb5a236023f37.camel@linux.ibm.com>
Date:   Fri, 03 Feb 2023 16:32:41 +0100
From:   Janis Schoetterl-Glausch <scgl@...ux.ibm.com>
To:     Janosch Frank <frankja@...ux.ibm.com>,
        Christian Borntraeger <borntraeger@...ux.ibm.com>,
        Claudio Imbrenda <imbrenda@...ux.ibm.com>,
        Heiko Carstens <hca@...ux.ibm.com>,
        Vasily Gorbik <gor@...ux.ibm.com>,
        Alexander Gordeev <agordeev@...ux.ibm.com>
Cc:     David Hildenbrand <david@...hat.com>,
        Jonathan Corbet <corbet@....net>, kvm@...r.kernel.org,
        linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org,
        linux-kselftest@...r.kernel.org, linux-s390@...r.kernel.org,
        Paolo Bonzini <pbonzini@...hat.com>,
        Shuah Khan <shuah@...nel.org>,
        Sven Schnelle <svens@...ux.ibm.com>
Subject: Re: [PATCH v6 10/14] KVM: s390: Refactor absolute vm mem_op function

On Fri, 2023-02-03 at 15:48 +0100, Janosch Frank wrote:
> On 1/25/23 22:26, Janis Schoetterl-Glausch wrote:
> > Remove code duplication with regards to the CHECK_ONLY flag.
> > Decrease the number of indents.
> > No functional change indented.
> > 
> > Suggested-by: Janosch Frank <frankja@...ux.ibm.com>
> > Signed-off-by: Janis Schoetterl-Glausch <scgl@...ux.ibm.com>
> > ---
> > 
> > 
> > Cosmetic only, can be dropped.
> > 
> > 
> >   arch/s390/kvm/kvm-s390.c | 43 ++++++++++++++++------------------------
> >   1 file changed, 17 insertions(+), 26 deletions(-)
> > 
> > diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
> > index 588cf70dc81e..cfd09cb43ef6 100644
> > --- a/arch/s390/kvm/kvm-s390.c
> > +++ b/arch/s390/kvm/kvm-s390.c
> > @@ -2794,6 +2794,7 @@ static void *mem_op_alloc_buf(struct kvm_s390_mem_op *mop)
> >   static int kvm_s390_vm_mem_op_abs(struct kvm *kvm, struct kvm_s390_mem_op *mop)
> >   {
> >   	void __user *uaddr = (void __user *)mop->buf;
> > +	enum gacc_mode acc_mode;
> >   	void *tmpbuf = NULL;
> >   	int r, srcu_idx;
> >   
> > @@ -2813,33 +2814,23 @@ static int kvm_s390_vm_mem_op_abs(struct kvm *kvm, struct kvm_s390_mem_op *mop)
> >   		goto out_unlock;
> >   	}
> >   
> > -	switch (mop->op) {
> > -	case KVM_S390_MEMOP_ABSOLUTE_READ: {
> > -		if (mop->flags & KVM_S390_MEMOP_F_CHECK_ONLY) {
> > -			r = check_gpa_range(kvm, mop->gaddr, mop->size, GACC_FETCH, mop->key);
> > -		} else {
> > -			r = access_guest_abs_with_key(kvm, mop->gaddr, tmpbuf,
> > -						      mop->size, GACC_FETCH, mop->key);
> > -			if (r == 0) {
> > -				if (copy_to_user(uaddr, tmpbuf, mop->size))
> > -					r = -EFAULT;
> > -			}
> > -		}
> > -		break;
> > -	}
> > -	case KVM_S390_MEMOP_ABSOLUTE_WRITE: {
> > -		if (mop->flags & KVM_S390_MEMOP_F_CHECK_ONLY) {
> > -			r = check_gpa_range(kvm, mop->gaddr, mop->size, GACC_STORE, mop->key);
> > -		} else {
> > -			if (copy_from_user(tmpbuf, uaddr, mop->size)) {
> > -				r = -EFAULT;
> > -				break;
> > -			}
> > -			r = access_guest_abs_with_key(kvm, mop->gaddr, tmpbuf,
> > -						      mop->size, GACC_STORE, mop->key);
> > +	acc_mode = mop->op == KVM_S390_MEMOP_ABSOLUTE_READ ? GACC_FETCH : GACC_STORE;
> 
> Would the line be too long if that variable would be initialized where 
> it's defined?

Just fits at 100 columns. Want me to move it?

> 
> > +	if (mop->flags & KVM_S390_MEMOP_F_CHECK_ONLY) {
> > +		r = check_gpa_range(kvm, mop->gaddr, mop->size, acc_mode, mop->key);
> 
> We should early return i.e. goto out_unlock.
> 
> IMHO else if, else patterns should either be switches (testing the same 
> variable) or kept as short as possible / be avoided.
> 
> > +	} else if (acc_mode == GACC_FETCH) {
> > +		r = access_guest_abs_with_key(kvm, mop->gaddr, tmpbuf,
> > +					      mop->size, GACC_FETCH, mop->key);
> 
> I'd guess it's personal taste whether you use GACC_FETCH or access_mode 
> but if you don't use it here then we can remove the variable all 
> together, no?

Yeah, I think I did replace it, but then undid it.
Probably just because it is a bit more explicit.
It's used in check_gpa_range, so no, unless you want to dump the expression
directly in there.
> 
> > +		if (r)
> > +			goto out_unlock;
> > +		if (copy_to_user(uaddr, tmpbuf, mop->size))
> > +			r = -EFAULT;
> > +	} else {
> > +		if (copy_from_user(tmpbuf, uaddr, mop->size)) {
> > +			r = -EFAULT;
> > +			goto out_unlock;
> >   		}
> > -		break;
> > -	}
> > +		r = access_guest_abs_with_key(kvm, mop->gaddr, tmpbuf,
> > +					      mop->size, GACC_STORE, mop->key);
> >   	}
> >   
> >   out_unlock:
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ