All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Sasha Levin <levinsasha928@gmail.com>
Cc: avi@redhat.com, mtosatti@redhat.com, gregkh@linuxfoundation.org,
	sjenning@linux.vnet.ibm.com, dan.magenheimer@oracle.com,
	kvm@vger.kernel.org
Subject: Re: [RFC 07/10] KVM: add KVM TMEM host side interface
Date: Thu, 28 Jun 2012 21:59:25 -0400	[thread overview]
Message-ID: <20120629015925.GA30193@phenom.dumpdata.com> (raw)
In-Reply-To: <1338980418-2519-7-git-send-email-levinsasha928@gmail.com>

On Wed, Jun 06, 2012 at 01:00:15PM +0200, Sasha Levin wrote:
> This is the host side interface that the guests which support KVM TMEM
> talk to.
> 
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> ---
>  arch/x86/kvm/tmem/Kconfig            |    6 +++
>  arch/x86/kvm/tmem/Makefile           |    2 +
>  arch/x86/kvm/tmem/host.c             |   78 ++++++++++++++++++++++++++++++++++
>  arch/x86/kvm/tmem/host.h             |   20 +++++++++
>  arch/x86/kvm/x86.c                   |    8 +---
>  drivers/staging/zcache/zcache-main.c |   35 +++++++++++++++-
>  6 files changed, 141 insertions(+), 8 deletions(-)
>  create mode 100644 arch/x86/kvm/tmem/host.c
>  create mode 100644 arch/x86/kvm/tmem/host.h
> 
> diff --git a/arch/x86/kvm/tmem/Kconfig b/arch/x86/kvm/tmem/Kconfig
> index 15d8301..1a59e4f 100644
> --- a/arch/x86/kvm/tmem/Kconfig
> +++ b/arch/x86/kvm/tmem/Kconfig
> @@ -13,4 +13,10 @@ menuconfig KVM_TMEM
>  
>  if KVM_TMEM
>  
> +config KVM_TMEM_HOST
> +	bool "Host-side KVM TMEM"
> +	---help---
> +	With this option on, the KVM host will be able to process KVM TMEM requests
> +	coming from guests.
> +
>  endif # KVM_TMEM
> diff --git a/arch/x86/kvm/tmem/Makefile b/arch/x86/kvm/tmem/Makefile
> index 6812d46..706cd36 100644
> --- a/arch/x86/kvm/tmem/Makefile
> +++ b/arch/x86/kvm/tmem/Makefile
> @@ -1 +1,3 @@
>  ccflags-y += -Idrivers/staging/zcache/
> +
> +obj-$(CONFIG_KVM_TMEM_HOST)			+= host.o
> diff --git a/arch/x86/kvm/tmem/host.c b/arch/x86/kvm/tmem/host.c
> new file mode 100644
> index 0000000..9e73395
> --- /dev/null
> +++ b/arch/x86/kvm/tmem/host.c
> @@ -0,0 +1,78 @@
> +/*
> + * KVM TMEM host side interface
> + *
> + * Copyright (c) 2012 Sasha Levin
> + *
> + */
> +
> +#include <linux/kvm_types.h>
> +#include <linux/kvm_host.h>
> +
> +#include "tmem.h"
> +#include <zcache.h>
> +
> +int use_kvm_tmem_host = 1;

__mostly_read and bool

> +
> +static int no_kvmtmemhost(char *s)
> +{
> +	use_kvm_tmem_host = 0;
> +	return 1;
> +}
> +
> +__setup("nokvmtmemhost", no_kvmtmemhost);
> +
> +int kvm_pv_tmem_op(struct kvm_vcpu *vcpu, gpa_t addr, unsigned long *ret)
> +{
> +	struct tmem_kvm_op op;
> +	struct page *page;
> +	int r;
> +	unsigned long flags;
> +
> +	if (!use_kvm_tmem_host || !zcache_enabled) {
> +		*ret = -ENXIO;
> +		return 0;
> +	}
> +
> +	r = kvm_read_guest(vcpu->kvm, addr, &op, sizeof(op));
> +	if (r < 0) {
> +		*ret = r;
> +		return 0;

Shouldn't this return r?

> +	}
> +
> +	switch (op.cmd) {
> +	case TMEM_NEW_POOL:
> +		*ret = zcache_new_pool(op.cli_id, op.u.new.flags);
> +		break;
> +	case TMEM_DESTROY_POOL:
> +		*ret = zcache_destroy_pool(op.cli_id, op.pool_id);
> +		break;
> +	case TMEM_NEW_PAGE:
> +		break;
> +	case TMEM_PUT_PAGE:
> +		page = gfn_to_page(vcpu->kvm, op.u.gen.gfn);
> +		local_irq_save(flags);
> +		*ret = zcache_put_page(op.cli_id, op.pool_id,
> +				&op.u.gen.oid, op.u.gen.index, page);
> +		local_irq_restore(flags);
> +		break;
> +	case TMEM_GET_PAGE:
> +		page = gfn_to_page(vcpu->kvm, op.u.gen.gfn);
> +		local_irq_save(flags);
> +		*ret = zcache_get_page(op.cli_id, op.pool_id,
> +			&op.u.gen.oid, op.u.gen.index, page);
> +		local_irq_restore(flags);
> +		break;
> +	case TMEM_FLUSH_PAGE:
> +		local_irq_save(flags);
> +		*ret = zcache_flush_page(op.cli_id, op.pool_id,
> +				&op.u.gen.oid, op.u.gen.index);
> +		local_irq_restore(flags);
> +		break;
> +	case TMEM_FLUSH_OBJECT:
> +		local_irq_save(flags);
> +		*ret = zcache_flush_object(op.cli_id, op.pool_id, &op.u.gen.oid);
> +		local_irq_restore(flags);
> +		break;
> +	}
> +	return 0;
> +}
> diff --git a/arch/x86/kvm/tmem/host.h b/arch/x86/kvm/tmem/host.h
> new file mode 100644
> index 0000000..17ba0c4
> --- /dev/null
> +++ b/arch/x86/kvm/tmem/host.h
> @@ -0,0 +1,20 @@
> +#ifndef _KVM_TMEM_HOST_H_
> +#define _KVM_TMEM_HOST_H_
> +
> +#ifdef CONFIG_KVM_TMEM_HOST
> +
> +extern int use_kvm_tmem_host;
> +
> +extern int kvm_pv_tmem_op(struct kvm_vcpu *vcpu, gpa_t addr, unsigned long *ret);
> +
> +#else
> +
> +static inline int kvm_pv_tmem_op(struct kvm_vcpu *vcpu, gpa_t addr, unsigned long *ret)
> +{
> +	*ret = -ENOSUPP;
> +	return 0;
> +}
> +
> +#endif
> +
> +#endif
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 4c5b6ab..c92d4c8 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -27,6 +27,7 @@
>  #include "kvm_cache_regs.h"
>  #include "x86.h"
>  #include "cpuid.h"
> +#include "tmem/host.h"
>  
>  #include <linux/clocksource.h>
>  #include <linux/interrupt.h>
> @@ -4993,13 +4994,6 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
>  	return 1;
>  }
>  
> -static int kvm_pv_tmem_op(struct kvm_vcpu *vcpu, gpa_t addr, unsigned long *ret)
> -{
> -	*ret = -ENOTSUPP;
> -
> -	return 0;
> -}
> -
>  static inline gpa_t hc_gpa(struct kvm_vcpu *vcpu, unsigned long a0,
>  				unsigned long a1)
>  {
> diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c
> index a196aff..65c0ab0 100644
> --- a/drivers/staging/zcache/zcache-main.c
> +++ b/drivers/staging/zcache/zcache-main.c
> @@ -1692,7 +1692,7 @@ out:
>  	return ret;
>  }
>  
> -static int zcache_new_pool(uint16_t cli_id, uint32_t flags)
> +int zcache_new_pool(uint16_t cli_id, uint32_t flags)
>  {
>  	int poolid = -1;
>  	struct tmem_pool *pool;
> @@ -2011,6 +2011,37 @@ out:
>  	return ret;
>  }
>  
> +#ifdef CONFIG_KVM_TMEM_HOST
> +extern int use_kvm_tmem_host;
> +
> +static int __zcache_init_kvm(void)
> +{
> +	int ret = 0;
> +
> +	if (use_kvm_tmem_host) {
> +		ret = zcache_new_client(KVM_CLIENT);
> +		if (ret) {
> +			pr_err("zcache: can't create client\n");
> +			return -1;
> +		} else {
> +			pr_info("zcache: enabled support for KVM TMEM\n");
> +		}
> +	}
> +	zbud_init();
> +	register_shrinker(&zcache_shrinker);
> +
> +	return 0;
> +}
> +
> +#else
> +
> +static inline int static int __zcache_init_kvm(void)
> +{
> +	return 0;
> +}
> +
> +#endif
> +
>  static int __init zcache_init(void)
>  {
>  	int ret = 0;
> @@ -2053,6 +2084,8 @@ static int __init zcache_init(void)
>  		pr_err("zcache: can't create client\n");
>  		goto out;
>  	}
> +	if (__zcache_init_kvm())
> +		goto out;
>  #endif
>  #ifdef CONFIG_CLEANCACHE
>  	if (zcache_enabled && use_cleancache) {
> -- 
> 1.7.8.6

  reply	other threads:[~2012-06-29  2:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-06 11:00 [RFC 01/10] KVM: reintroduce hc_gpa Sasha Levin
2012-06-06 11:00 ` [RFC 02/10] KVM: wire up the TMEM HC Sasha Levin
2012-06-06 11:00 ` [RFC 03/10] zcache: export zcache interface Sasha Levin
2012-06-06 11:00 ` [RFC 04/10] KVM: add KVM TMEM entries in the appropriate config menu entry Sasha Levin
2012-06-06 11:00 ` [RFC 05/10] KVM: bring in general tmem definitions Sasha Levin
2012-06-06 11:00 ` [RFC 06/10] zcache: move out client declaration and add a KVM client Sasha Levin
2012-06-06 11:00 ` [RFC 07/10] KVM: add KVM TMEM host side interface Sasha Levin
2012-06-29  1:59   ` Konrad Rzeszutek Wilk [this message]
2012-06-06 11:00 ` [RFC 08/10] KVM: add KVM TMEM guest support Sasha Levin
2012-06-06 11:00 ` [RFC 09/10] KVM: support guest side cleancache Sasha Levin
2012-06-06 11:00 ` [RFC 10/10] KVM: support guest side frontswap Sasha Levin
2012-06-06 11:06 ` [RFC 01/10] KVM: reintroduce hc_gpa Avi Kivity
2012-06-06 11:32   ` Sasha Levin
2012-06-06 11:38     ` Avi Kivity
2012-06-06 11:45       ` Sasha Levin
2012-06-06 12:15         ` Avi Kivity
2012-06-06 12:32           ` Sasha Levin
2012-06-06 12:37             ` Avi Kivity

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=20120629015925.GA30193@phenom.dumpdata.com \
    --to=konrad.wilk@oracle.com \
    --cc=avi@redhat.com \
    --cc=dan.magenheimer@oracle.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kvm@vger.kernel.org \
    --cc=levinsasha928@gmail.com \
    --cc=mtosatti@redhat.com \
    --cc=sjenning@linux.vnet.ibm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.