Re: [PATCH kvmtool v3 9/9] kvmtool: Allow standard size specifiers for memory bank

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Dec 20, 2018 at 03:21:26PM +0000, Julien Grall wrote:
> From: Suzuki K Poulose <suzuki.poulose@xxxxxxx>
> 
> Allow standard suffixes, K, M, G, T & P suffixes for sizes and addresses for
> memory bank parameters. By default, the size is specified in MB.
> 
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@xxxxxxx>
> 
> ---
> 
>     Changes in v2:
>         - Patch added
> ---
>  builtin-run.c | 50 ++++++++++++++++++++++++++++++++++++++++++--------
>  1 file changed, 42 insertions(+), 8 deletions(-)
> 
> diff --git a/builtin-run.c b/builtin-run.c
> index 568af5c..c907295 100644
> --- a/builtin-run.c
> +++ b/builtin-run.c
> @@ -49,9 +49,11 @@
>  #include <ctype.h>
>  #include <stdio.h>
>  
> -#define MB_SHIFT		(20)
>  #define KB_SHIFT		(10)
> +#define MB_SHIFT		(20)
>  #define GB_SHIFT		(30)
> +#define TB_SHIFT		(40)
> +#define PB_SHIFT		(50)
>  
>  __thread struct kvm_cpu *current_kvm_cpu;
>  
> @@ -87,6 +89,37 @@ void kvm_run_set_wrapper_sandbox(void)
>  	kvm_run_wrapper = KVM_RUN_SANDBOX;
>  }
>  
> +static int __parse_size_spec(char **next)
> +{
> +	int shift = 0;
> +
> +	switch(**next) {
> +	case 'K': shift = KB_SHIFT; break;
> +	case 'M': shift = MB_SHIFT; break;
> +	case 'G': shift = GB_SHIFT; break;
> +	case 'T': shift = TB_SHIFT; break;
> +	case 'P': shift = PB_SHIFT; break;

Might be better to make this case-insensitive.

> +	}
> +	if (shift)
> +		(*next)++;
> +	return shift;
> +}
> +
> +static u64 parse_mem_size_spec(char **next)
> +{
> +	int shift = __parse_size_spec(next);
> +
> +	/* By default the size is in MB, if none is specified */
> +	if (!shift)
> +		shift = 20;

Does this also happen if somebody passes malformed input, e.g. a size of
128Q? If so, shouldn't we be advancing the next pointer in that case?

Will



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux