public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@qumranet.com>
To: Dave Hansen <dave@linux.vnet.ibm.com>
Cc: kvm-devel <kvm@vger.kernel.org>,
	Anthony Liguori <aliguori@us.ibm.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/4] reduce stack usage in kvm_vcpu_ioctl()
Date: Mon, 11 Aug 2008 12:41:34 +0300	[thread overview]
Message-ID: <48A0094E.8020203@qumranet.com> (raw)
In-Reply-To: <1217874695-28430-1-git-send-email-dave@linux.vnet.ibm.com>

Dave Hansen wrote:
> Same as the last one, but this time we use kmalloc()
> for all of the uses.
>
> Note that the kfree()s take advantage of the fact that
> kfree() is OK on NULL.
>
> Signed-off-by: Dave Hansen <dave@linux.vnet.ibm.com>
> ---
>  virt/kvm/kvm_main.c |   48 ++++++++++++++++++++++++++++++------------------
>  1 files changed, 30 insertions(+), 18 deletions(-)
>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 7dd9b0b..70bf180 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -1118,6 +1118,9 @@ static long kvm_vcpu_ioctl(struct file *filp,
>  	struct kvm_vcpu *vcpu = filp->private_data;
>  	void __user *argp = (void __user *)arg;
>  	int r;
> +	struct kvm_fpu *fpu = NULL;
> +	struct kvm_sregs *kvm_sregs = NULL;
> +
>   

Spurious blank line.

>  
>  	if (vcpu->kvm->mm != current->mm)
>  		return -EIO;
> @@ -1165,25 +1168,29 @@ out_free2:
>  		break;
>  	}
>  	case KVM_GET_SREGS: {
> -		struct kvm_sregs kvm_sregs;
> -
> -		memset(&kvm_sregs, 0, sizeof kvm_sregs);
> -		r = kvm_arch_vcpu_ioctl_get_sregs(vcpu, &kvm_sregs);
> +		kvm_sregs = kzalloc(sizeof(struct kvm_sregs), GFP_KERNEL);
> +		r = -ENOMEM;
> +		if (!kvm_sregs)
> +			goto out;
> +		memset(kvm_sregs, 0, sizeof(struct kvm_sregs));
>   

memset unneeded after kzalloc.


btw, this is a generic problem, and could be handled generically:

struct ioctl_handler_entry {
    u32 ioctl;
    union {
        long (*handler_parg)(void *arg);
        long (*handler_larg)(long arg);
    };
};

void process_ioctl(struct ioctl_handler_entry *ioctls)
{
     search for correct entry;
     allocate memory (get size from ioctl number);
     copy from user (if _IOW);
     call handler;
     copy to user (if _IOR, and no error);
     free memory;
}

I imagine this can be used to simplify many ioctls.

-- 
error compiling committee.c: too many arguments to function


  reply	other threads:[~2008-08-11  9:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-04 18:31 [PATCH 1/4] reduce kvm stack usage in kvm_arch_vm_ioctl() Dave Hansen
2008-08-04 18:31 ` [PATCH 2/4] reduce stack usage in kvm_vcpu_ioctl() Dave Hansen
2008-08-11  9:41   ` Avi Kivity [this message]
2008-08-04 18:31 ` [PATCH 3/4] reduce stack usage in kvm_arch_vcpu_ioctl() Dave Hansen
2008-08-04 18:31 ` [PATCH 4/4] kvm: reduce stack usage in kvm_pv_mmu_op() Dave Hansen
2008-08-11  9:29 ` [PATCH 1/4] reduce kvm stack usage in kvm_arch_vm_ioctl() Avi Kivity
  -- strict thread matches above, loose matches on Subject: below --
2008-08-11 17:01 Dave Hansen
2008-08-11 17:01 ` [PATCH 2/4] reduce stack usage in kvm_vcpu_ioctl() Dave Hansen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48A0094E.8020203@qumranet.com \
    --to=avi@qumranet.com \
    --cc=aliguori@us.ibm.com \
    --cc=dave@linux.vnet.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox