public inbox for cgroups@vger.kernel.org
 help / color / mirror / Atom feed
From: "Michal Koutný" <mkoutny-IBi9RG/b67k@public.gmane.org>
To: Vipin Sharma <vipinsh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Cc: tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	rdunlap-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org,
	thomas.lendacky-5C7GfCeVMHo@public.gmane.org,
	brijesh.singh-5C7GfCeVMHo@public.gmane.org,
	jon.grimm-5C7GfCeVMHo@public.gmane.org,
	eric.vantassell-5C7GfCeVMHo@public.gmane.org,
	pbonzini-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
	hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org,
	frankja-tEXmvtCZX7AybS5Ee8rs3A@public.gmane.org,
	borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org,
	corbet-T1hC0tSOHrs@public.gmane.org,
	seanjc-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
	vkuznets-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
	wanpengli-1Nz4purKYjRBDgjK7y7TUQ@public.gmane.org,
	jmattson-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
	joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org,
	tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org,
	mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
	bp-Gina5bIWoIWzQB+pC5nmwQ@public.gmane.org,
	hpa-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org,
	gingell-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
	rientjes-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
	dionnaglaze-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
	kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [Patch v3 1/2] cgroup: sev: Add misc cgroup controller
Date: Thu, 11 Mar 2021 19:59:03 +0100	[thread overview]
Message-ID: <YEpod5X29YqMhW/g@blackbook> (raw)
In-Reply-To: <20210304231946.2766648-2-vipinsh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 3931 bytes --]

Hi Vipin.

On Thu, Mar 04, 2021 at 03:19:45PM -0800, Vipin Sharma <vipinsh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org> wrote:
>  arch/x86/kvm/svm/sev.c        |  65 +++++-
>  arch/x86/kvm/svm/svm.h        |   1 +
>  include/linux/cgroup_subsys.h |   4 +
>  include/linux/misc_cgroup.h   | 130 +++++++++++
>  init/Kconfig                  |  14 ++
>  kernel/cgroup/Makefile        |   1 +
>  kernel/cgroup/misc.c          | 402 ++++++++++++++++++++++++++++++++++
Given different two-fold nature (SEV caller vs misc controller) of some
remarks below, I think it makes sense to split this into two patches:
a) generic controller implementation,
b) hooking the controller into SEV ASIDs management.

> +#ifndef CONFIG_KVM_AMD_SEV
> +/*
> + * When this config is not defined, SEV feature is not supported and APIs in
> + * this file are not used but this file still gets compiled into the KVM AMD
> + * module.
> + *
> + * We will not have MISC_CG_RES_SEV and MISC_CG_RES_SEV_ES entries in the enum
> + * misc_res_type {} defined in linux/misc_cgroup.h.
BTW, was there any progress on conditioning sev.c build on
CONFIG_KVM_AMD_SEV? (So that the defines workaround isn't needeed.)

>  static int sev_asid_new(struct kvm_sev_info *sev)
>  {
> -	int pos, min_asid, max_asid;
> +	int pos, min_asid, max_asid, ret;
>  	bool retry = true;
> +	enum misc_res_type type;
> +
> +	type = sev->es_active ? MISC_CG_RES_SEV_ES : MISC_CG_RES_SEV;
> +	sev->misc_cg = get_current_misc_cg();
> +	ret = misc_cg_try_charge(type, sev->misc_cg, 1);
It may be safer to WARN_ON(sev->misc_cg) at this point (see below).


> [...]
> +e_uncharge:
> +	misc_cg_uncharge(type, sev->misc_cg, 1);
> +	put_misc_cg(sev->misc_cg);
> +	return ret;
vvv

> @@ -140,6 +171,10 @@ static void sev_asid_free(int asid)
>  	}
>  
>  	mutex_unlock(&sev_bitmap_lock);
> +
> +	type = sev->es_active ? MISC_CG_RES_SEV_ES : MISC_CG_RES_SEV;
> +	misc_cg_uncharge(type, sev->misc_cg, 1);
> +	put_misc_cg(sev->misc_cg);
It may be safer to set sev->misc_cg to NULL here.

(IIUC, with current asid_{new,free} calls it shouldn't matter but why to
rely on it in the future.)

> +++ b/kernel/cgroup/misc.c
> [...]
> +static void misc_cg_reduce_charge(enum misc_res_type type, struct misc_cg *cg,
> +				  unsigned long amount)
misc_cg_cancel_charge seems to be a name more consistent with what we
already have in pids and memory controller.


> +static ssize_t misc_cg_max_write(struct kernfs_open_file *of, char *buf,
> +				 size_t nbytes, loff_t off)
> +{
> [...]
> +
> +	if (!strcmp(MAX_STR, buf)) {
> +		max = ULONG_MAX;
MAX_NUM for consistency with other places.

> +	} else {
> +		ret = kstrtoul(buf, 0, &max);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	cg = css_misc(of_css(of));
> +
> +	if (misc_res_capacity[type])
> +		cg->res[type].max = max;
In theory, parallel writers can clash here, so having the limit atomic
type to prevent this would resolve it. See also commit a713af394cf3
("cgroup: pids: use atomic64_t for pids->limit").

> +static int misc_cg_current_show(struct seq_file *sf, void *v)
> +{
> +	int i;
> +	struct misc_cg *cg = css_misc(seq_css(sf));
> +
> +	for (i = 0; i < MISC_CG_RES_TYPES; i++) {
> +		if (misc_res_capacity[i])
Since there can be some residual charges after removing capacity (before
draining), maybe the condition along the line

if (misc_res_capacity[i] || atomic_long_read(&cg->res[i].usage))

would be more informative for debugging.

> +static int misc_cg_capacity_show(struct seq_file *sf, void *v)
> +{
> +	int i;
> +	unsigned long cap;
> +
> +	for (i = 0; i < MISC_CG_RES_TYPES; i++) {
> +		cap = READ_ONCE(misc_res_capacity[i]);
Why is READ_ONCE only here and not in other places that (actually) check
against the set capacity value? Also, there should be a paired
WRITE_ONCCE in misc_cg_set_capacity().


Thanks,
Michal

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2021-03-11 18:59 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-04 23:19 [Patch v3 0/2] cgroup: New misc cgroup controller Vipin Sharma
2021-03-04 23:19 ` [Patch v3 1/2] cgroup: sev: Add " Vipin Sharma
     [not found]   ` <20210304231946.2766648-2-vipinsh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2021-03-11 18:59     ` Michal Koutný [this message]
2021-03-12 19:07       ` Vipin Sharma
     [not found]         ` <YEu74hkEPEyvxC85-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2021-03-15 18:34           ` Michal Koutný
2021-03-12 19:48       ` Vipin Sharma
2021-03-12 20:51         ` Sean Christopherson
     [not found]           ` <YEvUTatAjIoP7dPD-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2021-03-12 21:18             ` Tom Lendacky
2021-03-19 21:28     ` Jacob Pan
2021-03-22 18:54       ` Vipin Sharma
     [not found]         ` <YFjn7wv/iMO4Isgz-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2021-03-24 16:17           ` Jacob Pan
2021-03-24 22:09             ` Vipin Sharma
     [not found] ` <20210304231946.2766648-1-vipinsh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2021-03-04 23:19   ` [Patch v3 2/2] cgroup: sev: Miscellaneous cgroup documentation Vipin Sharma
2021-03-07 12:48 ` [Patch v3 0/2] cgroup: New misc cgroup controller Tejun Heo
2021-03-11 18:58   ` Michal Koutný
2021-03-11 19:39     ` Tejun Heo
2021-03-12 17:49     ` Vipin Sharma
     [not found]       ` <YEupplaAWU1i0G6B-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2021-03-15 19:10         ` Michal Koutný
2021-03-22 18:24           ` Vipin Sharma

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=YEpod5X29YqMhW/g@blackbook \
    --to=mkoutny-ibi9rg/b67k@public.gmane.org \
    --cc=borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org \
    --cc=bp-Gina5bIWoIWzQB+pC5nmwQ@public.gmane.org \
    --cc=brijesh.singh-5C7GfCeVMHo@public.gmane.org \
    --cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=corbet-T1hC0tSOHrs@public.gmane.org \
    --cc=dionnaglaze-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=eric.vantassell-5C7GfCeVMHo@public.gmane.org \
    --cc=frankja-tEXmvtCZX7AybS5Ee8rs3A@public.gmane.org \
    --cc=gingell-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org \
    --cc=hpa-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org \
    --cc=jmattson-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=jon.grimm-5C7GfCeVMHo@public.gmane.org \
    --cc=joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org \
    --cc=kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=pbonzini-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=rdunlap-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=rientjes-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=seanjc-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org \
    --cc=thomas.lendacky-5C7GfCeVMHo@public.gmane.org \
    --cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=vipinsh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=vkuznets-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=wanpengli-1Nz4purKYjRBDgjK7y7TUQ@public.gmane.org \
    --cc=x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.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