[Xen-devel] [PATCH] XSM/policy: Allow the source domain access to settime and setdomainhandle domctls while creating domain.

2016-07-07 Thread Anshul Makkar anshul.makkar
From: Anshul Makkar 

This patch resolves the following permission denied scenarios while creating
new domU :
avc:  denied  { setdomainhandle } for domid=0 target=1
scontext=system_u:system_r:dom0_t tcontext=system_u:system_r:domU_t 
tclass=domain

avc:  denied  { settime } for domid=0 target=1 scontext=system_u:system_r:dom0_t
tcontext=system_u:system_r:domU_t tclass=domain

Signed-off-by: Anshul Makkar 
---
 tools/flask/policy/modules/xen.if | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/flask/policy/modules/xen.if 
b/tools/flask/policy/modules/xen.if
index fd96303..8c43c28 100644
--- a/tools/flask/policy/modules/xen.if
+++ b/tools/flask/policy/modules/xen.if
@@ -48,7 +48,8 @@ define(`declare_build_label', `
 define(`create_domain_common', `
allow $1 $2:domain { create max_vcpus setdomainmaxmem setaddrsize
getdomaininfo hypercall setvcpucontext getscheduler
-   getvcpuinfo getaddrsize getaffinity setaffinity };
+   getvcpuinfo getaddrsize getaffinity setaffinity
+   settime setdomainhandle };
allow $1 $2:domain2 { set_cpuid settsc setscheduler setclaim
set_max_evtchn set_vnumainfo get_vnumainfo cacheflush
psr_cmt_op psr_cat_op soft_reset };
-- 
1.9.1


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH] credi2-ratelimit: Implement rate limit for credit2 scheduler

2016-07-06 Thread Anshul Makkar anshul.makkar
From: Anshul Makkar 

Rate limit assures that a vcpu will execute for a minimum amount of time before
being put at the back of a queue or being preempted by higher priority thread.

It introduces a minimum amount of latency to enable a VM to batch its work and
it also ensures that system is not spending most of its time in
VMEXIT/VMENTRY because of VM that is waking/sleeping at high rate.

ratelimit can be disabled by setting it to 0.

Signed-off-by: Anshul Makkar 
---
---
 xen/common/sched_credit2.c | 115 ++---
 1 file changed, 98 insertions(+), 17 deletions(-)

diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c
index 1933ff1..6718574 100644
--- a/xen/common/sched_credit2.c
+++ b/xen/common/sched_credit2.c
@@ -171,6 +171,11 @@ integer_param("sched_credit2_migrate_resist", 
opt_migrate_resist);
 #define c2r(_ops, _cpu) (CSCHED2_PRIV(_ops)->runq_map[(_cpu)])
 /* CPU to runqueue struct macro */
 #define RQD(_ops, _cpu) (_PRIV(_ops)->rqd[c2r(_ops, _cpu)])
+/* Find the max of time slice */
+#define MAX_TSLICE(t1, t2)  \
+   ({ typeof (t1) _t1 = (t1); \
+  typeof (t1) _t2 = (t2); \
+  _t1 > _t2 ? _t1 < 0 ? 0 : _t1 : _t2 < 0 ? 0 : _t2; })
 
 /*
  * Shifts for load average.
@@ -280,6 +285,7 @@ struct csched2_private {
 struct csched2_runqueue_data rqd[NR_CPUS];
 
 unsigned int load_window_shift;
+unsigned ratelimit_us; /* each cpupool can have its onw ratelimit */
 };
 
 /*
@@ -1588,6 +1594,34 @@ csched2_dom_cntl(
 return rc;
 }
 
+static int csched2_sys_cntl(const struct scheduler *ops,
+struct xen_sysctl_scheduler_op *sc)
+{
+int rc = -EINVAL;
+xen_sysctl_credit_schedule_t *params = >u.sched_credit;
+struct csched2_private *prv = CSCHED2_PRIV(ops);
+unsigned long flags;
+
+switch (sc->cmd )
+{
+case XEN_SYSCTL_SCHEDOP_putinfo:
+if ( params->ratelimit_us &&
+( params->ratelimit_us < CSCHED2_MIN_TIMER ||
+  params->ratelimit_us > MICROSECS(CSCHED2_MAX_TIMER) ))
+return rc;
+spin_lock_irqsave(>lock, flags);
+prv->ratelimit_us = params->ratelimit_us;
+spin_unlock_irqrestore(>lock, flags);
+break;
+
+case XEN_SYSCTL_SCHEDOP_getinfo:
+params->ratelimit_us = prv->ratelimit_us;
+rc = 0;
+break;
+}
+return rc;
+}
+
 static void *
 csched2_alloc_domdata(const struct scheduler *ops, struct domain *dom)
 {
@@ -1657,12 +1691,15 @@ csched2_dom_destroy(const struct scheduler *ops, struct 
domain *dom)
 
 /* How long should we let this vcpu run for? */
 static s_time_t
-csched2_runtime(const struct scheduler *ops, int cpu, struct csched2_vcpu 
*snext)
+csched2_runtime(const struct scheduler *ops, int cpu,
+struct csched2_vcpu *snext, s_time_t now)
 {
-s_time_t time; 
+s_time_t time;
 int rt_credit; /* Proposed runtime measured in credits */
 struct csched2_runqueue_data *rqd = RQD(ops, cpu);
 struct list_head *runq = >runq;
+s_time_t runtime = 0;
+struct csched2_private *prv = CSCHED2_PRIV(ops);
 
 /*
  * If we're idle, just stay so. Others (or external events)
@@ -1680,6 +1717,14 @@ csched2_runtime(const struct scheduler *ops, int cpu, 
struct csched2_vcpu *snext
 
 /* 1) Basic time: Run until credit is 0. */
 rt_credit = snext->credit;
+if (snext->vcpu->is_running)
+runtime = now - snext->vcpu->runstate.state_entry_time;
+if ( runtime < 0 )
+{
+runtime = 0;
+d2printk("%s: Time went backwards? now %"PRI_stime" state_entry_time 
%"PRI_stime"\n",
+  _func__, now, snext->runstate.state_entry_time);
+}
 
 /* 2) If there's someone waiting whose credit is positive,
  * run until your credit ~= his */
@@ -1695,11 +1740,24 @@ csched2_runtime(const struct scheduler *ops, int cpu, 
struct csched2_vcpu *snext
 }
 
 /* The next guy may actually have a higher credit, if we've tried to
- * avoid migrating him from a different cpu.  DTRT.  */
+ * avoid migrating him from a different cpu.  DTRT.
+ * Even if the next guy has higher credit and current vcpu has executed
+ * for less amount of time than rate limit, allow it to run for minimum
+ * amount of time.
+ */
 if ( rt_credit <= 0 )
 {
-time = CSCHED2_MIN_TIMER;
-SCHED_STAT_CRANK(runtime_min_timer);
+if ( snext->vcpu->is_running && prv->ratelimit_us)
+   /* implies the current one has executed for time < ratelimit and 
thus
+* it has neen selcted int runq_candidate to run next.
+* No need to check for this condition again.
+*/
+time = MAX_TSLICE(CSCHED2_MIN_TIMER,
+   MICROSECS(prv->ratelimit_us) - runtime);
+

[Xen-devel] [PATCH] iommu/quirk: disable shared EPT for Sandybridge and earlier processors.

2015-11-24 Thread Anshul Makkar anshul.makkar
From: Anshul Makkar 

Sandybridge or earlier processors don't have huge page support for
IOTLB which leads to fallback on 4k pages and causes performance issues.

Shared EPT will be disabled only if the user has not provided explicit
choice on the command line.

Signed-off-by: Anshul Makkar 
---
v2:
   * Removed the use of extra variable to control the shared EPT and made
 the existent variable as tristate.
   * Narrowed down the check for processors to Sandybridge and older including
 Atom processors.

 docs/misc/xen-command-line.markdown  |  2 +-
 xen/drivers/passthrough/iommu.c  |  2 +-
 xen/drivers/passthrough/vtd/quirks.c | 14 ++
 xen/include/xen/iommu.h  |  2 +-
 4 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/docs/misc/xen-command-line.markdown 
b/docs/misc/xen-command-line.markdown
index a2e427c..6b69ba2 100644
--- a/docs/misc/xen-command-line.markdown
+++ b/docs/misc/xen-command-line.markdown
@@ -896,7 +896,7 @@ debug hypervisor only).
 
 > `sharept`
 
-> Default: `true`
+> Default: `true` if newer than SandyBridge or `false` if Sandybridge or 
earlier.
 
 >> Control whether CPU and IOMMU page tables should be shared.
 
diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c
index d5137733..9367987 100644
--- a/xen/drivers/passthrough/iommu.c
+++ b/xen/drivers/passthrough/iommu.c
@@ -51,7 +51,7 @@ bool_t __read_mostly iommu_passthrough;
 bool_t __read_mostly iommu_snoop = 1;
 bool_t __read_mostly iommu_qinval = 1;
 bool_t __read_mostly iommu_intremap = 1;
-bool_t __read_mostly iommu_hap_pt_share = 1;
+s8 __read_mostly iommu_hap_pt_share = -1;
 bool_t __read_mostly iommu_debug;
 bool_t __read_mostly amd_iommu_perdev_intremap = 1;
 
diff --git a/xen/drivers/passthrough/vtd/quirks.c 
b/xen/drivers/passthrough/vtd/quirks.c
index 143..7d63c8d 100644
--- a/xen/drivers/passthrough/vtd/quirks.c
+++ b/xen/drivers/passthrough/vtd/quirks.c
@@ -320,6 +320,20 @@ void __init platform_quirks_init(void)
 /* Tylersburg interrupt remap quirk */
 if ( iommu_intremap )
 tylersburg_intremap_quirk();
+
+/*
+ * Disable shared EPT ("sharept") on Sandybridge and older processors
+ * by default.
+ * SandyBridge has no huge page support for IOTLB which leads to fallback
+ * on 4k pages and leads to performance degradation.
+ *
+ * Shared EPT ("sharept") will be disabled only if user has not
+ * provided explicit choice on the command line thus iommu_hap_pt_share is
+ * at its initialized value of -1.
+ */
+if ( (boot_cpu_data.x86 == 0x06 && (boot_cpu_data.x86_model <= 0x2F ||
+  boot_cpu_data.x86_model == 0x36)) && (iommu_hap_pt_share == -1) )
+iommu_hap_pt_share = 0;
 }
 
 /*
diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h
index 8f3a20e..d52d06f 100644
--- a/xen/include/xen/iommu.h
+++ b/xen/include/xen/iommu.h
@@ -31,7 +31,7 @@ extern bool_t iommu_enable, iommu_enabled;
 extern bool_t force_iommu, iommu_verbose;
 extern bool_t iommu_workaround_bios_bug, iommu_igfx, iommu_passthrough;
 extern bool_t iommu_snoop, iommu_qinval, iommu_intremap;
-extern bool_t iommu_hap_pt_share;
+extern s8 iommu_hap_pt_share;
 extern bool_t iommu_debug;
 extern bool_t amd_iommu_perdev_intremap;
 
-- 
1.9.1


___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel