Patchwork [v2] KVM: fix error handling in svm_cpu_init

login
register
mail settings
Submitter Li RongQing
Date March 15, 2019, 1:47 a.m.
Message ID <1552614432-4738-1-git-send-email-lirongqing@baidu.com>
Download mbox | patch
Permalink /patch/749217/
State New
Headers show

Comments

Li RongQing - March 15, 2019, 1:47 a.m.
sd->save_area should be freed in error path
rename labels to make them readable suggested by Vitaly

Fixes: 70cd94e60c733 ("KVM: SVM: VMRUN should use associated ASID when SEV is enabled")
Signed-off-by: Li RongQing <lirongqing@baidu.com>
Reviewed-by: Brijesh Singh <brijesh.singh@amd.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
---
v1-->v2: rename labels to make them readable suggested by Vitaly

 arch/x86/kvm/svm.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
Vitaly Kuznetsov - March 15, 2019, 9:07 a.m.
Li RongQing <lirongqing@baidu.com> writes:

> sd->save_area should be freed in error path

> rename labels to make them readable suggested by Vitaly

(minor nitpick, not worth resending the patch IMO)
This comment is only helpfull after '---' so reviewers know what changed
between version. It makes little sense when you see this later in 'git log'.

>
> Fixes: 70cd94e60c733 ("KVM: SVM: VMRUN should use associated ASID when SEV is enabled")
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> Reviewed-by: Brijesh Singh <brijesh.singh@amd.com>
> Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
> v1-->v2: rename labels to make them readable suggested by Vitaly
>
>  arch/x86/kvm/svm.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index f13a3a24d360..c6613d1dfa75 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -998,7 +998,7 @@ static int svm_cpu_init(int cpu)
>  	r = -ENOMEM;
>  	sd->save_area = alloc_page(GFP_KERNEL);
>  	if (!sd->save_area)
> -		goto err_1;
> +		goto err_free_sd;
>  
>  	if (svm_sev_enabled()) {
>  		r = -ENOMEM;
> @@ -1006,17 +1006,18 @@ static int svm_cpu_init(int cpu)
>  					      sizeof(void *),
>  					      GFP_KERNEL);
>  		if (!sd->sev_vmcbs)
> -			goto err_1;
> +			goto err_free_saved_area;
>  	}
>  
>  	per_cpu(svm_data, cpu) = sd;
>  
>  	return 0;
>  
> -err_1:
> +err_free_saved_area:
> +	__free_page(sd->save_area);
> +err_free_sd:
>  	kfree(sd);
>  	return r;
> -
>  }
>  
>  static bool valid_msr_intercept(u32 index)

Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Li RongQing - April 17, 2019, 2:38 a.m.
> Li RongQing <lirongqing@baidu.com> writes:

> 

> > sd->save_area should be freed in error path

> 

> > rename labels to make them readable suggested by Vitaly

> 

> (minor nitpick, not worth resending the patch IMO) This comment is only

> helpfull after '---' so reviewers know what changed between version. It makes

> little sense when you see this later in 'git log'.

> 

> >

> > Fixes: 70cd94e60c733 ("KVM: SVM: VMRUN should use associated ASID

> when

> > SEV is enabled")

> > Signed-off-by: Li RongQing <lirongqing@baidu.com>

> > Reviewed-by: Brijesh Singh <brijesh.singh@amd.com>

> > Cc: Vitaly Kuznetsov <vkuznets@redhat.com>

> > ---

> > v1-->v2: rename labels to make them readable suggested by Vitaly

> >

> >  arch/x86/kvm/svm.c | 9 +++++----

> >  1 file changed, 5 insertions(+), 4 deletions(-)

> >

> > diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index

> > f13a3a24d360..c6613d1dfa75 100644

> > --- a/arch/x86/kvm/svm.c

> > +++ b/arch/x86/kvm/svm.c

> > @@ -998,7 +998,7 @@ static int svm_cpu_init(int cpu)

> >  	r = -ENOMEM;

> >  	sd->save_area = alloc_page(GFP_KERNEL);

> >  	if (!sd->save_area)

> > -		goto err_1;

> > +		goto err_free_sd;

> >

> >  	if (svm_sev_enabled()) {

> >  		r = -ENOMEM;

> > @@ -1006,17 +1006,18 @@ static int svm_cpu_init(int cpu)

> >  					      sizeof(void *),

> >  					      GFP_KERNEL);

> >  		if (!sd->sev_vmcbs)

> > -			goto err_1;

> > +			goto err_free_saved_area;

> >  	}

> >

> >  	per_cpu(svm_data, cpu) = sd;

> >

> >  	return 0;

> >

> > -err_1:

> > +err_free_saved_area:

> > +	__free_page(sd->save_area);

> > +err_free_sd:

> >  	kfree(sd);

> >  	return r;

> > -

> >  }

> >

> >  static bool valid_msr_intercept(u32 index)

> 

> Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>

> 


Ping

-RongQing


> --

> Vitaly

Patch

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index f13a3a24d360..c6613d1dfa75 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -998,7 +998,7 @@  static int svm_cpu_init(int cpu)
 	r = -ENOMEM;
 	sd->save_area = alloc_page(GFP_KERNEL);
 	if (!sd->save_area)
-		goto err_1;
+		goto err_free_sd;
 
 	if (svm_sev_enabled()) {
 		r = -ENOMEM;
@@ -1006,17 +1006,18 @@  static int svm_cpu_init(int cpu)
 					      sizeof(void *),
 					      GFP_KERNEL);
 		if (!sd->sev_vmcbs)
-			goto err_1;
+			goto err_free_saved_area;
 	}
 
 	per_cpu(svm_data, cpu) = sd;
 
 	return 0;
 
-err_1:
+err_free_saved_area:
+	__free_page(sd->save_area);
+err_free_sd:
 	kfree(sd);
 	return r;
-
 }
 
 static bool valid_msr_intercept(u32 index)