From patchwork Mon Oct 26 09:13:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11856161 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7B2A761C for ; Mon, 26 Oct 2020 09:14:05 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 46A9E207C4 for ; Mon, 26 Oct 2020 09:14:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="jIQEYVwF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 46A9E207C4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.12078.31634 (Exim 4.92) (envelope-from ) id 1kWyZ8-0004fk-8N; Mon, 26 Oct 2020 09:13:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 12078.31634; Mon, 26 Oct 2020 09:13:22 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZ8-0004fa-1L; Mon, 26 Oct 2020 09:13:22 +0000 Received: by outflank-mailman (input) for mailman id 12078; Mon, 26 Oct 2020 09:13:20 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZ6-0004f1-Sm for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:20 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id dafdec3e-1b45-494f-b5d9-81e097f3cb5a; Mon, 26 Oct 2020 09:13:19 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 1018CB234; Mon, 26 Oct 2020 09:13:19 +0000 (UTC) Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZ6-0004f1-Sm for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:20 +0000 X-Inumbo-ID: dafdec3e-1b45-494f-b5d9-81e097f3cb5a Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id dafdec3e-1b45-494f-b5d9-81e097f3cb5a; Mon, 26 Oct 2020 09:13:19 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1603703599; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S+BqtDReQpO+TXL58A4bLpNMJ+nOUR/20v/rJyuhuj4=; b=jIQEYVwFJQcO6tgFsP5y643ojuRqFb0JEVZyJ8pBXnPRDkcdWxnb7+NoRXv84suKMhSrBV 3vDphIgKzxy01drPzNsfPJGIqunAyg2YYodaHLQep5/3+kytO/1QcnD2qqkxeu32O/V7Wd dOpMtsCMVoo/eFfH4gkcMaRo26xLKY0= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 1018CB234; Mon, 26 Oct 2020 09:13:19 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , George Dunlap , Dario Faggioli Subject: [PATCH 01/12] xen/cpupool: add cpu to sched_res_mask when removing it from cpupool Date: Mon, 26 Oct 2020 10:13:05 +0100 Message-Id: <20201026091316.25680-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026091316.25680-1-jgross@suse.com> References: <20201026091316.25680-1-jgross@suse.com> MIME-Version: 1.0 When a cpu is removed from a cpupool and added to the free cpus it should be added to sched_res_mask, too. The related removal from sched_res_mask in case of core scheduling is already done in schedule_cpu_add(). As long as all cpupools share the same scheduling granularity there is nothing going wrong with the missing removal, but this will change when per-cpupool granularity is fully supported. Signed-off-by: Juergen Gross Reviewed-by: Dario Faggioli --- xen/common/sched/core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c index ed973e90ec..f8c81592af 100644 --- a/xen/common/sched/core.c +++ b/xen/common/sched/core.c @@ -3189,6 +3189,7 @@ int schedule_cpu_rm(unsigned int cpu) /* Adjust cpu masks of resources (old and new). */ cpumask_clear_cpu(cpu_iter, sr->cpus); cpumask_set_cpu(cpu_iter, sr_new[idx]->cpus); + cpumask_set_cpu(cpu_iter, &sched_res_mask); /* Init timer. */ init_timer(&sr_new[idx]->s_timer, s_timer_fn, NULL, cpu_iter); From patchwork Mon Oct 26 09:13:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11856175 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4BE631130 for ; Mon, 26 Oct 2020 09:14:26 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 11AB52076D for ; Mon, 26 Oct 2020 09:14:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="umOd6p2D" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 11AB52076D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.12080.31651 (Exim 4.92) (envelope-from ) id 1kWyZC-0004jy-F9; Mon, 26 Oct 2020 09:13:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 12080.31651; Mon, 26 Oct 2020 09:13:26 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZC-0004jo-BE; Mon, 26 Oct 2020 09:13:26 +0000 Received: by outflank-mailman (input) for mailman id 12080; Mon, 26 Oct 2020 09:13:25 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZB-0004ev-DY for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:25 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c3e88123-e98f-46cc-89ef-ca162c14a811; Mon, 26 Oct 2020 09:13:20 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 32ED1B236; Mon, 26 Oct 2020 09:13:19 +0000 (UTC) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZB-0004ev-DY for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:25 +0000 X-Inumbo-ID: c3e88123-e98f-46cc-89ef-ca162c14a811 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c3e88123-e98f-46cc-89ef-ca162c14a811; Mon, 26 Oct 2020 09:13:20 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1603703599; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ecPsgfMBalsxI2bSrpf4c/uqpvI8X4flzNfflD+HujM=; b=umOd6p2DKuwXUe/IOnnsMi4KI8Shwj6jZGazqTU+jtSkfGgbu2eK/oraBqzdQ+iamG2/EM z38ad7nUJrEgu4aXBWIOlZvGXkEWoHU3hoa/GBd3icnLPsCPx1+zu+jLPDjjSlk9Cq1HgB Uo86j4D3UmTLZ+gIHgqoSziSH2CFf7U= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 32ED1B236; Mon, 26 Oct 2020 09:13:19 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Dario Faggioli , George Dunlap Subject: [PATCH 02/12] xen/cpupool: add missing bits for per-cpupool scheduling granularity Date: Mon, 26 Oct 2020 10:13:06 +0100 Message-Id: <20201026091316.25680-3-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026091316.25680-1-jgross@suse.com> References: <20201026091316.25680-1-jgross@suse.com> MIME-Version: 1.0 Even with storing the scheduling granularity in struct cpupool there are still a few bits missing for being able to have cpupools with different granularity (apart from the missing interface for setting the individual granularities): the number of cpus in a scheduling unit is always taken from the global sched_granularity variable. So store the value in struct cpupool and use that instead of sched_granularity. Signed-off-by: Juergen Gross Reviewed-by: Dario Faggioli --- xen/common/sched/cpupool.c | 3 ++- xen/common/sched/private.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/xen/common/sched/cpupool.c b/xen/common/sched/cpupool.c index 7ea641ca26..6429c8f7b5 100644 --- a/xen/common/sched/cpupool.c +++ b/xen/common/sched/cpupool.c @@ -151,7 +151,7 @@ static void __init cpupool_gran_init(void) unsigned int cpupool_get_granularity(const struct cpupool *c) { - return c ? sched_granularity : 1; + return c ? c->sched_gran : 1; } static void free_cpupool_struct(struct cpupool *c) @@ -289,6 +289,7 @@ static struct cpupool *cpupool_create( } c->sched->cpupool = c; c->gran = opt_sched_granularity; + c->sched_gran = sched_granularity; *q = c; diff --git a/xen/common/sched/private.h b/xen/common/sched/private.h index df50976eb2..685992cab9 100644 --- a/xen/common/sched/private.h +++ b/xen/common/sched/private.h @@ -514,6 +514,7 @@ struct cpupool struct scheduler *sched; atomic_t refcnt; enum sched_gran gran; + unsigned int sched_gran; /* Number of cpus per sched-item. */ }; static inline cpumask_t *cpupool_domain_master_cpumask(const struct domain *d) From patchwork Mon Oct 26 09:13:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11856155 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D2A1061C for ; Mon, 26 Oct 2020 09:13:47 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 945562076D for ; Mon, 26 Oct 2020 09:13:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="gsGfazlp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 945562076D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.12081.31663 (Exim 4.92) (envelope-from ) id 1kWyZD-0004m9-PF; Mon, 26 Oct 2020 09:13:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 12081.31663; Mon, 26 Oct 2020 09:13:27 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZD-0004m0-Kf; Mon, 26 Oct 2020 09:13:27 +0000 Received: by outflank-mailman (input) for mailman id 12081; Mon, 26 Oct 2020 09:13:25 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZB-0004f1-RF for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:25 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f24d1136-c11a-4f8f-880b-54df60084fad; Mon, 26 Oct 2020 09:13:20 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 568CEB23A; Mon, 26 Oct 2020 09:13:19 +0000 (UTC) Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZB-0004f1-RF for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:25 +0000 X-Inumbo-ID: f24d1136-c11a-4f8f-880b-54df60084fad Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f24d1136-c11a-4f8f-880b-54df60084fad; Mon, 26 Oct 2020 09:13:20 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1603703599; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J3RFdnzX1db04Vx257W+zNC99T8L5VMF+AvHyH9dORI=; b=gsGfazlpVNzFEF+sijQLLwzV18BWbOs2htBVfb1s5xf9e0p9HeCzJSCnxPrBoRJfAzhBkh Y2W1r0HcpHmuBq84uXoKqvZDROz7KRlVhyLEFKs1xujahxHwov4Hpc4gpT/3fJyKyiYgpd F2IIHCiinkwz+Nw3LQ594Wf+Xv2o96c= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 568CEB23A; Mon, 26 Oct 2020 09:13:19 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , George Dunlap , Dario Faggioli Subject: [PATCH 03/12] xen/sched: support moving a domain between cpupools with different granularity Date: Mon, 26 Oct 2020 10:13:07 +0100 Message-Id: <20201026091316.25680-4-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026091316.25680-1-jgross@suse.com> References: <20201026091316.25680-1-jgross@suse.com> MIME-Version: 1.0 When moving a domain between cpupools with different scheduling granularity the sched_units of the domain need to be adjusted. Do that by allocating new sched_units and throwing away the old ones in sched_move_domain(). Signed-off-by: Juergen Gross --- xen/common/sched/core.c | 121 ++++++++++++++++++++++++++++++---------- 1 file changed, 90 insertions(+), 31 deletions(-) diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c index f8c81592af..8f1db88593 100644 --- a/xen/common/sched/core.c +++ b/xen/common/sched/core.c @@ -613,17 +613,45 @@ static void sched_move_irqs(const struct sched_unit *unit) vcpu_move_irqs(v); } +/* + * Move a domain from one cpupool to another. + * + * A domain with any vcpu having temporary affinity settings will be denied + * to move. Hard and soft affinities will be reset. + * + * In order to support cpupools with different scheduling granularities all + * scheduling units are replaced by new ones. + * + * The complete move is done in the following steps: + * - check prerequisites (no vcpu with temporary affinities) + * - allocate all new data structures (scheduler specific domain data, unit + * memory, scheduler specific unit data) + * - pause domain + * - temporarily move all (old) units to the same scheduling resource (this + * makes the final resource assignment easier in case the new cpupool has + * a larger granularity than the old one, as the scheduling locks for all + * vcpus must be held for that operation) + * - remove old units from scheduling + * - set new cpupool and scheduler domain data pointers in struct domain + * - switch all vcpus to new units, still assigned to the old scheduling + * resource + * - migrate all new units to scheduling resources of the new cpupool + * - unpause the domain + * - free the old memory (scheduler specific domain data, unit memory, + * scheduler specific unit data) + */ int sched_move_domain(struct domain *d, struct cpupool *c) { struct vcpu *v; - struct sched_unit *unit; + struct sched_unit *unit, *old_unit; + struct sched_unit *new_units = NULL, *old_units; + struct sched_unit **unit_ptr = &new_units; unsigned int new_p, unit_idx; - void **unit_priv; void *domdata; - void *unitdata; - struct scheduler *old_ops; + struct scheduler *old_ops = dom_scheduler(d); void *old_domdata; unsigned int gran = cpupool_get_granularity(c); + unsigned int n_units = DIV_ROUND_UP(d->max_vcpus, gran); int ret = 0; for_each_vcpu ( d, v ) @@ -641,53 +669,78 @@ int sched_move_domain(struct domain *d, struct cpupool *c) goto out; } - unit_priv = xzalloc_array(void *, DIV_ROUND_UP(d->max_vcpus, gran)); - if ( unit_priv == NULL ) + for ( unit_idx = 0; unit_idx < n_units; unit_idx++ ) { - sched_free_domdata(c->sched, domdata); - ret = -ENOMEM; - goto out; - } + unit = sched_alloc_unit_mem(); + if ( unit ) + { + /* Initialize unit for sched_alloc_udata() to work. */ + unit->domain = d; + unit->unit_id = unit_idx * gran; + unit->vcpu_list = d->vcpu[unit->unit_id]; + unit->priv = sched_alloc_udata(c->sched, unit, domdata); + *unit_ptr = unit; + } - unit_idx = 0; - for_each_sched_unit ( d, unit ) - { - unit_priv[unit_idx] = sched_alloc_udata(c->sched, unit, domdata); - if ( unit_priv[unit_idx] == NULL ) + if ( !unit || !unit->priv ) { - for ( unit_idx = 0; unit_priv[unit_idx]; unit_idx++ ) - sched_free_udata(c->sched, unit_priv[unit_idx]); - xfree(unit_priv); - sched_free_domdata(c->sched, domdata); + old_units = new_units; + old_domdata = domdata; ret = -ENOMEM; - goto out; + goto out_free; } - unit_idx++; + + unit_ptr = &unit->next_in_list; } domain_pause(d); - old_ops = dom_scheduler(d); old_domdata = d->sched_priv; + new_p = cpumask_first(d->cpupool->cpu_valid); for_each_sched_unit ( d, unit ) { + spinlock_t *lock; + + /* + * Temporarily move all units to same processor to make locking + * easier when moving the new units to the new processors. + */ + lock = unit_schedule_lock_irq(unit); + sched_set_res(unit, get_sched_res(new_p)); + spin_unlock_irq(lock); + sched_remove_unit(old_ops, unit); } + old_units = d->sched_unit_list; + d->cpupool = c; d->sched_priv = domdata; + unit = new_units; + for_each_vcpu ( d, v ) + { + old_unit = v->sched_unit; + if ( unit->unit_id + gran == v->vcpu_id ) + unit = unit->next_in_list; + + unit->state_entry_time = old_unit->state_entry_time; + unit->runstate_cnt[v->runstate.state]++; + /* Temporarily use old resource assignment */ + unit->res = get_sched_res(new_p); + + v->sched_unit = unit; + } + + d->sched_unit_list = new_units; + new_p = cpumask_first(c->cpu_valid); - unit_idx = 0; for_each_sched_unit ( d, unit ) { spinlock_t *lock; unsigned int unit_p = new_p; - unitdata = unit->priv; - unit->priv = unit_priv[unit_idx]; - for_each_sched_unit_vcpu ( unit, v ) { migrate_timer(&v->periodic_timer, new_p); @@ -713,8 +766,6 @@ int sched_move_domain(struct domain *d, struct cpupool *c) sched_insert_unit(c->sched, unit); - sched_free_udata(old_ops, unitdata); - unit_idx++; } @@ -722,11 +773,19 @@ int sched_move_domain(struct domain *d, struct cpupool *c) domain_unpause(d); - sched_free_domdata(old_ops, old_domdata); + out_free: + for ( unit = old_units; unit; ) + { + if ( unit->priv ) + sched_free_udata(c->sched, unit->priv); + old_unit = unit; + unit = unit->next_in_list; + xfree(old_unit); + } - xfree(unit_priv); + sched_free_domdata(old_ops, old_domdata); -out: + out: rcu_read_unlock(&sched_res_rculock); return ret; From patchwork Mon Oct 26 09:13:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11856157 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D5F5661C for ; Mon, 26 Oct 2020 09:13:57 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9879C2076D for ; Mon, 26 Oct 2020 09:13:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="LNO+6NWh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9879C2076D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.12082.31675 (Exim 4.92) (envelope-from ) id 1kWyZH-0004qm-6W; Mon, 26 Oct 2020 09:13:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 12082.31675; Mon, 26 Oct 2020 09:13:31 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZH-0004qd-0L; Mon, 26 Oct 2020 09:13:31 +0000 Received: by outflank-mailman (input) for mailman id 12082; Mon, 26 Oct 2020 09:13:30 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZG-0004ev-Dq for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:30 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 465e31a0-6598-4ac1-9d0f-563313d478fe; Mon, 26 Oct 2020 09:13:20 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 77B4CB23B; Mon, 26 Oct 2020 09:13:19 +0000 (UTC) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZG-0004ev-Dq for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:30 +0000 X-Inumbo-ID: 465e31a0-6598-4ac1-9d0f-563313d478fe Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 465e31a0-6598-4ac1-9d0f-563313d478fe; Mon, 26 Oct 2020 09:13:20 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1603703599; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XbeoD7GvpOh4XVGvOVBLgVXAc4wxwYUa82TSh2+/HXM=; b=LNO+6NWhImdPet4PPhCO14zZyZJ1jDYmYTHxHlsEVoSK+QGZDlMXEve6KJroGdheLj5ERn WrJ4SJgnuN7YlGZ/hXxTuT/10gRKyxo5QzxYhV1XFXre87ESC0n8Jz61LddgzbFlSuaVVW D/gkfdp8syZHWsoqLwvre3IG5Msnsbc= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 77B4CB23B; Mon, 26 Oct 2020 09:13:19 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Dario Faggioli , George Dunlap Subject: [PATCH 04/12] xen/sched: sort included headers in cpupool.c Date: Mon, 26 Oct 2020 10:13:08 +0100 Message-Id: <20201026091316.25680-5-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026091316.25680-1-jgross@suse.com> References: <20201026091316.25680-1-jgross@suse.com> MIME-Version: 1.0 Common style is to include header files in alphabetical order. Sort the #include statements in cpupool.c accordingly. Signed-off-by: Juergen Gross Acked-by: Dario Faggioli --- xen/common/sched/cpupool.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xen/common/sched/cpupool.c b/xen/common/sched/cpupool.c index 6429c8f7b5..84f326ea63 100644 --- a/xen/common/sched/cpupool.c +++ b/xen/common/sched/cpupool.c @@ -11,15 +11,15 @@ * (C) 2009, Juergen Gross, Fujitsu Technology Solutions */ -#include -#include +#include #include +#include +#include +#include #include #include #include #include -#include -#include #include "private.h" From patchwork Mon Oct 26 09:13:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11856165 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA2E961C for ; Mon, 26 Oct 2020 09:14:08 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 774112076D for ; Mon, 26 Oct 2020 09:14:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="SpVmo6uf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 774112076D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.12084.31699 (Exim 4.92) (envelope-from ) id 1kWyZM-00050v-V8; Mon, 26 Oct 2020 09:13:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 12084.31699; Mon, 26 Oct 2020 09:13:36 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZM-00050h-O7; Mon, 26 Oct 2020 09:13:36 +0000 Received: by outflank-mailman (input) for mailman id 12084; Mon, 26 Oct 2020 09:13:35 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZL-0004ev-E3 for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:35 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8c6bdc73-fd31-4aae-958c-0c85ffd05956; Mon, 26 Oct 2020 09:13:21 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B2FD5B23C; Mon, 26 Oct 2020 09:13:19 +0000 (UTC) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZL-0004ev-E3 for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:35 +0000 X-Inumbo-ID: 8c6bdc73-fd31-4aae-958c-0c85ffd05956 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8c6bdc73-fd31-4aae-958c-0c85ffd05956; Mon, 26 Oct 2020 09:13:21 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1603703599; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IOhsYgKG+zQ0PfhzYSXXErTxqo2b3iMd5G4A+1tHm1s=; b=SpVmo6ufiSpibMZaNeNPngD2dihhkRE5Y/jy0wfvxNgfqb3B4S7F7HVZD2TjiVem0An7tY wE8BG9NNd7AOjSplwENeez+FbXlVhif42kh8c+S1C4RQfLRkCYCLwO0C6B4E/TmsBqbvnu dsRR37datpPzckgAyLMacVbatSZlO58= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B2FD5B23C; Mon, 26 Oct 2020 09:13:19 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH 05/12] docs: fix hypfs path documentation Date: Mon, 26 Oct 2020 10:13:09 +0100 Message-Id: <20201026091316.25680-6-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026091316.25680-1-jgross@suse.com> References: <20201026091316.25680-1-jgross@suse.com> MIME-Version: 1.0 The /params/* entry is missing a writable tag. Signed-off-by: Juergen Gross Acked-by: Jan Beulich --- docs/misc/hypfs-paths.pandoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/misc/hypfs-paths.pandoc b/docs/misc/hypfs-paths.pandoc index dddb592bc5..6c7b2f7ee3 100644 --- a/docs/misc/hypfs-paths.pandoc +++ b/docs/misc/hypfs-paths.pandoc @@ -179,7 +179,7 @@ The minor version of Xen. A directory of runtime parameters. -#### /params/* +#### /params/* [w] The individual parameters. The description of the different parameters can be found in `docs/misc/xen-command-line.pandoc`. From patchwork Mon Oct 26 09:13:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11856179 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D1C461C for ; Mon, 26 Oct 2020 09:14:54 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 29EA8207C4 for ; Mon, 26 Oct 2020 09:14:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="qMnllShS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 29EA8207C4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.12087.31723 (Exim 4.92) (envelope-from ) id 1kWyZR-0005AW-AS; Mon, 26 Oct 2020 09:13:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 12087.31723; Mon, 26 Oct 2020 09:13:41 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZR-0005AF-5F; Mon, 26 Oct 2020 09:13:41 +0000 Received: by outflank-mailman (input) for mailman id 12087; Mon, 26 Oct 2020 09:13:40 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZQ-0004ev-E8 for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:40 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 4e0e474d-5af9-43b8-8c80-c4d9f6ee50d1; Mon, 26 Oct 2020 09:13:21 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id EB53EB23E; Mon, 26 Oct 2020 09:13:19 +0000 (UTC) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZQ-0004ev-E8 for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:40 +0000 X-Inumbo-ID: 4e0e474d-5af9-43b8-8c80-c4d9f6ee50d1 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 4e0e474d-5af9-43b8-8c80-c4d9f6ee50d1; Mon, 26 Oct 2020 09:13:21 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1603703600; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G8a1iKL8UN8o1Ty1vmdQY0A5FOvExIvgwVG3SwZ4QNw=; b=qMnllShSIDuFGZF9rkN+h4h10kPIw8LwFXaswJu96zqzAA4PQ7umLDOvK1PREY9jwJ4Uez YG7kQ6xkfkDJ/Wun3SX1PQZac7sNxALkwYcqZK2E8aOopkxRkpSzYo/MPoL8trbYsvJeDj L1C8PgFcFLOUk7zAR2wF+C3kkKSAP+4= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id EB53EB23E; Mon, 26 Oct 2020 09:13:19 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH 06/12] xen/hypfs: move per-node function pointers into a dedicated struct Date: Mon, 26 Oct 2020 10:13:10 +0100 Message-Id: <20201026091316.25680-7-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026091316.25680-1-jgross@suse.com> References: <20201026091316.25680-1-jgross@suse.com> MIME-Version: 1.0 Move the function pointers currently stored in each hypfs node into a dedicated structure in order to save some space for each node. This will save even more space with additional callbacks added in future. Provide some standard function vectors. Signed-off-by: Juergen Gross --- xen/common/hypfs.c | 25 +++++++++++++++--- xen/include/xen/hypfs.h | 57 +++++++++++++++++++++++++---------------- xen/include/xen/param.h | 15 ++++------- 3 files changed, 62 insertions(+), 35 deletions(-) diff --git a/xen/common/hypfs.c b/xen/common/hypfs.c index 8e932b5cf9..e655e8cfc7 100644 --- a/xen/common/hypfs.c +++ b/xen/common/hypfs.c @@ -24,6 +24,25 @@ CHECK_hypfs_dirlistentry; (DIRENTRY_NAME_OFF + \ ROUNDUP((name_len) + 1, alignof(struct xen_hypfs_direntry))) +struct hypfs_funcs hypfs_dir_funcs = { + .read = hypfs_read_dir, +}; +struct hypfs_funcs hypfs_leaf_ro_funcs = { + .read = hypfs_read_leaf, +}; +struct hypfs_funcs hypfs_leaf_wr_funcs = { + .read = hypfs_read_leaf, + .write = hypfs_write_leaf, +}; +struct hypfs_funcs hypfs_bool_wr_funcs = { + .read = hypfs_read_leaf, + .write = hypfs_write_bool, +}; +struct hypfs_funcs hypfs_custom_wr_funcs = { + .read = hypfs_read_leaf, + .write = hypfs_write_custom, +}; + static DEFINE_RWLOCK(hypfs_lock); enum hypfs_lock_state { hypfs_unlocked, @@ -284,7 +303,7 @@ static int hypfs_read(const struct hypfs_entry *entry, guest_handle_add_offset(uaddr, sizeof(e)); - ret = entry->read(entry, uaddr); + ret = entry->funcs->read(entry, uaddr); out: return ret; @@ -387,14 +406,14 @@ static int hypfs_write(struct hypfs_entry *entry, { struct hypfs_entry_leaf *l; - if ( !entry->write ) + if ( !entry->funcs->write ) return -EACCES; ASSERT(entry->max_size); l = container_of(entry, struct hypfs_entry_leaf, e); - return entry->write(l, uaddr, ulen); + return entry->funcs->write(l, uaddr, ulen); } long do_hypfs_op(unsigned int cmd, diff --git a/xen/include/xen/hypfs.h b/xen/include/xen/hypfs.h index 5ad99cb558..77916ebb58 100644 --- a/xen/include/xen/hypfs.h +++ b/xen/include/xen/hypfs.h @@ -7,6 +7,20 @@ #include struct hypfs_entry_leaf; +struct hypfs_entry; + +struct hypfs_funcs { + int (*read)(const struct hypfs_entry *entry, + XEN_GUEST_HANDLE_PARAM(void) uaddr); + int (*write)(struct hypfs_entry_leaf *leaf, + XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned int ulen); +}; + +extern struct hypfs_funcs hypfs_dir_funcs; +extern struct hypfs_funcs hypfs_leaf_ro_funcs; +extern struct hypfs_funcs hypfs_leaf_wr_funcs; +extern struct hypfs_funcs hypfs_bool_wr_funcs; +extern struct hypfs_funcs hypfs_custom_wr_funcs; struct hypfs_entry { unsigned short type; @@ -15,10 +29,7 @@ struct hypfs_entry { unsigned int max_size; const char *name; struct list_head list; - int (*read)(const struct hypfs_entry *entry, - XEN_GUEST_HANDLE_PARAM(void) uaddr); - int (*write)(struct hypfs_entry_leaf *leaf, - XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned int ulen); + struct hypfs_funcs *funcs; }; struct hypfs_entry_leaf { @@ -42,7 +53,7 @@ struct hypfs_entry_dir { .e.size = 0, \ .e.max_size = 0, \ .e.list = LIST_HEAD_INIT(var.e.list), \ - .e.read = hypfs_read_dir, \ + .e.funcs = &hypfs_dir_funcs, \ .dirlist = LIST_HEAD_INIT(var.dirlist), \ } @@ -52,7 +63,7 @@ struct hypfs_entry_dir { .e.encoding = XEN_HYPFS_ENC_PLAIN, \ .e.name = (nam), \ .e.max_size = (msz), \ - .e.read = hypfs_read_leaf, \ + .e.funcs = &hypfs_leaf_ro_funcs, \ } /* Content and size need to be set via hypfs_string_set_reference(). */ @@ -72,35 +83,37 @@ static inline void hypfs_string_set_reference(struct hypfs_entry_leaf *leaf, leaf->e.size = strlen(str) + 1; } -#define HYPFS_FIXEDSIZE_INIT(var, typ, nam, contvar, wr) \ - struct hypfs_entry_leaf __read_mostly var = { \ - .e.type = (typ), \ - .e.encoding = XEN_HYPFS_ENC_PLAIN, \ - .e.name = (nam), \ - .e.size = sizeof(contvar), \ - .e.max_size = (wr) ? sizeof(contvar) : 0, \ - .e.read = hypfs_read_leaf, \ - .e.write = (wr), \ - .u.content = &(contvar), \ +#define HYPFS_FIXEDSIZE_INIT(var, typ, nam, contvar, fn, wr) \ + struct hypfs_entry_leaf __read_mostly var = { \ + .e.type = (typ), \ + .e.encoding = XEN_HYPFS_ENC_PLAIN, \ + .e.name = (nam), \ + .e.size = sizeof(contvar), \ + .e.max_size = (wr) ? sizeof(contvar) : 0, \ + .e.funcs = (fn), \ + .u.content = &(contvar), \ } #define HYPFS_UINT_INIT(var, nam, contvar) \ - HYPFS_FIXEDSIZE_INIT(var, XEN_HYPFS_TYPE_UINT, nam, contvar, NULL) + HYPFS_FIXEDSIZE_INIT(var, XEN_HYPFS_TYPE_UINT, nam, contvar, \ + &hypfs_leaf_ro_funcs, 0) #define HYPFS_UINT_INIT_WRITABLE(var, nam, contvar) \ HYPFS_FIXEDSIZE_INIT(var, XEN_HYPFS_TYPE_UINT, nam, contvar, \ - hypfs_write_leaf) + &hypfs_leaf_wr_funcs, 1) #define HYPFS_INT_INIT(var, nam, contvar) \ - HYPFS_FIXEDSIZE_INIT(var, XEN_HYPFS_TYPE_INT, nam, contvar, NULL) + HYPFS_FIXEDSIZE_INIT(var, XEN_HYPFS_TYPE_INT, nam, contvar, \ + &hypfs_leaf_ro_funcs, 0) #define HYPFS_INT_INIT_WRITABLE(var, nam, contvar) \ HYPFS_FIXEDSIZE_INIT(var, XEN_HYPFS_TYPE_INT, nam, contvar, \ - hypfs_write_leaf) + &hypfs_leaf_wr_funcs, 1) #define HYPFS_BOOL_INIT(var, nam, contvar) \ - HYPFS_FIXEDSIZE_INIT(var, XEN_HYPFS_TYPE_BOOL, nam, contvar, NULL) + HYPFS_FIXEDSIZE_INIT(var, XEN_HYPFS_TYPE_BOOL, nam, contvar, \ + &hypfs_leaf_ro_funcs, 0) #define HYPFS_BOOL_INIT_WRITABLE(var, nam, contvar) \ HYPFS_FIXEDSIZE_INIT(var, XEN_HYPFS_TYPE_BOOL, nam, contvar, \ - hypfs_write_bool) + &hypfs_bool_wr_funcs, 1) extern struct hypfs_entry_dir hypfs_root; diff --git a/xen/include/xen/param.h b/xen/include/xen/param.h index d0409d3a0e..1b2c7db954 100644 --- a/xen/include/xen/param.h +++ b/xen/include/xen/param.h @@ -116,8 +116,7 @@ extern struct param_hypfs __paramhypfs_start[], __paramhypfs_end[]; { .hypfs.e.type = XEN_HYPFS_TYPE_STRING, \ .hypfs.e.encoding = XEN_HYPFS_ENC_PLAIN, \ .hypfs.e.name = (nam), \ - .hypfs.e.read = hypfs_read_leaf, \ - .hypfs.e.write = hypfs_write_custom, \ + .hypfs.e.funcs = &hypfs_custom_wr_funcs, \ .init_leaf = (initfunc), \ .func = (variable) } #define boolean_runtime_only_param(nam, variable) \ @@ -127,8 +126,7 @@ extern struct param_hypfs __paramhypfs_start[], __paramhypfs_end[]; .hypfs.e.name = (nam), \ .hypfs.e.size = sizeof(variable), \ .hypfs.e.max_size = sizeof(variable), \ - .hypfs.e.read = hypfs_read_leaf, \ - .hypfs.e.write = hypfs_write_bool, \ + .hypfs.e.funcs = &hypfs_bool_wr_funcs, \ .hypfs.u.content = &(variable) } #define integer_runtime_only_param(nam, variable) \ __paramfs __parfs_##variable = \ @@ -137,8 +135,7 @@ extern struct param_hypfs __paramhypfs_start[], __paramhypfs_end[]; .hypfs.e.name = (nam), \ .hypfs.e.size = sizeof(variable), \ .hypfs.e.max_size = sizeof(variable), \ - .hypfs.e.read = hypfs_read_leaf, \ - .hypfs.e.write = hypfs_write_leaf, \ + .hypfs.e.funcs = &hypfs_leaf_wr_funcs, \ .hypfs.u.content = &(variable) } #define size_runtime_only_param(nam, variable) \ __paramfs __parfs_##variable = \ @@ -147,8 +144,7 @@ extern struct param_hypfs __paramhypfs_start[], __paramhypfs_end[]; .hypfs.e.name = (nam), \ .hypfs.e.size = sizeof(variable), \ .hypfs.e.max_size = sizeof(variable), \ - .hypfs.e.read = hypfs_read_leaf, \ - .hypfs.e.write = hypfs_write_leaf, \ + .hypfs.e.funcs = &hypfs_leaf_wr_funcs, \ .hypfs.u.content = &(variable) } #define string_runtime_only_param(nam, variable) \ __paramfs __parfs_##variable = \ @@ -157,8 +153,7 @@ extern struct param_hypfs __paramhypfs_start[], __paramhypfs_end[]; .hypfs.e.name = (nam), \ .hypfs.e.size = 0, \ .hypfs.e.max_size = sizeof(variable), \ - .hypfs.e.read = hypfs_read_leaf, \ - .hypfs.e.write = hypfs_write_leaf, \ + .hypfs.e.funcs = &hypfs_leaf_wr_funcs, \ .hypfs.u.content = &(variable) } #else From patchwork Mon Oct 26 09:13:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11856167 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EF38861C for ; Mon, 26 Oct 2020 09:14:11 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BC1392076D for ; Mon, 26 Oct 2020 09:14:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="u5w8r5Xb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC1392076D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.12083.31687 (Exim 4.92) (envelope-from ) id 1kWyZI-0004th-GP; Mon, 26 Oct 2020 09:13:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 12083.31687; Mon, 26 Oct 2020 09:13:32 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZI-0004tU-Az; Mon, 26 Oct 2020 09:13:32 +0000 Received: by outflank-mailman (input) for mailman id 12083; Mon, 26 Oct 2020 09:13:30 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZG-0004f1-RQ for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:30 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b99fa3f3-aecd-408e-99f0-5f4902718482; Mon, 26 Oct 2020 09:13:21 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 2EA73B241; Mon, 26 Oct 2020 09:13:20 +0000 (UTC) Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZG-0004f1-RQ for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:30 +0000 X-Inumbo-ID: b99fa3f3-aecd-408e-99f0-5f4902718482 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b99fa3f3-aecd-408e-99f0-5f4902718482; Mon, 26 Oct 2020 09:13:21 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1603703600; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZSq8aaykDP1qqXLMQtSSJphelHz62lSdHw2BdhisVQc=; b=u5w8r5XbLREuAI2PEahXh4vzIz3GETulgMztS2x23i1OOAkvALwTqoDwwSbJDENI3vb83/ hBXe3YC6srkKz0vdI9BE74zZtZaZGtmXYBAHCbjy8vY1r1x9dX46rpHHiZpOb6XLHFJDc1 PvBrHsDxHjQ71tzmGAvznsbtbzZamgQ= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 2EA73B241; Mon, 26 Oct 2020 09:13:20 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH 07/12] xen/hypfs: pass real failure reason up from hypfs_get_entry() Date: Mon, 26 Oct 2020 10:13:11 +0100 Message-Id: <20201026091316.25680-8-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026091316.25680-1-jgross@suse.com> References: <20201026091316.25680-1-jgross@suse.com> MIME-Version: 1.0 Instead of handling all errors from hypfs_get_entry() as ENOENT pass up the real error value via ERR_PTR(). Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- xen/common/hypfs.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/xen/common/hypfs.c b/xen/common/hypfs.c index e655e8cfc7..97260bd4a3 100644 --- a/xen/common/hypfs.c +++ b/xen/common/hypfs.c @@ -182,7 +182,7 @@ static struct hypfs_entry *hypfs_get_entry_rel(struct hypfs_entry_dir *dir, while ( again ) { if ( dir->e.type != XEN_HYPFS_TYPE_DIR ) - return NULL; + return ERR_PTR(-ENOENT); if ( !*path ) return &dir->e; @@ -201,7 +201,7 @@ static struct hypfs_entry *hypfs_get_entry_rel(struct hypfs_entry_dir *dir, struct hypfs_entry_dir, e); if ( cmp < 0 ) - return NULL; + return ERR_PTR(-ENOENT); if ( !cmp && strlen(entry->name) == name_len ) { if ( !*end ) @@ -216,13 +216,13 @@ static struct hypfs_entry *hypfs_get_entry_rel(struct hypfs_entry_dir *dir, } } - return NULL; + return ERR_PTR(-ENOENT); } static struct hypfs_entry *hypfs_get_entry(const char *path) { if ( path[0] != '/' ) - return NULL; + return ERR_PTR(-EINVAL); return hypfs_get_entry_rel(&hypfs_root, path + 1); } @@ -446,9 +446,9 @@ long do_hypfs_op(unsigned int cmd, goto out; entry = hypfs_get_entry(path); - if ( !entry ) + if ( IS_ERR(entry) ) { - ret = -ENOENT; + ret = PTR_ERR(entry); goto out; } From patchwork Mon Oct 26 09:13:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11856181 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D874714B2 for ; Mon, 26 Oct 2020 09:14:54 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 99AAF207C4 for ; Mon, 26 Oct 2020 09:14:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="NL/En86Z" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 99AAF207C4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.12094.31771 (Exim 4.92) (envelope-from ) id 1kWyZc-0005YX-CE; Mon, 26 Oct 2020 09:13:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 12094.31771; Mon, 26 Oct 2020 09:13:52 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZc-0005YM-7e; Mon, 26 Oct 2020 09:13:52 +0000 Received: by outflank-mailman (input) for mailman id 12094; Mon, 26 Oct 2020 09:13:50 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZa-0004f1-SN for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:50 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f9b3da22-e431-4730-8a0f-bb74a709d485; Mon, 26 Oct 2020 09:13:21 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6BF8CB243; Mon, 26 Oct 2020 09:13:20 +0000 (UTC) Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZa-0004f1-SN for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:50 +0000 X-Inumbo-ID: f9b3da22-e431-4730-8a0f-bb74a709d485 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f9b3da22-e431-4730-8a0f-bb74a709d485; Mon, 26 Oct 2020 09:13:21 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1603703600; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wzVfNJp5CakgtQPXKcxiHB74zrzQZ4Nkcj6JZDwDa6k=; b=NL/En86Zerx/XqAPLdxbToE9TgYiblPWaYJYlvTQW/RutFLZdUPGjUNGDbRYDww7CLqc7r X2yqGr+HsQeFQdmmqvJebYLtfoEo0/6ClP/pPX9+Irr9DTLuodyTR9hf7mFBCBOhSVbTNl ZZq/IZykawDZMb56HpOMdFrv1W4coS0= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6BF8CB243; Mon, 26 Oct 2020 09:13:20 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH 08/12] xen/hypfs: support dynamic hypfs nodes Date: Mon, 26 Oct 2020 10:13:12 +0100 Message-Id: <20201026091316.25680-9-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026091316.25680-1-jgross@suse.com> References: <20201026091316.25680-1-jgross@suse.com> MIME-Version: 1.0 Add a getsize() function pointer to struct hypfs_funcs for being able to have dynamically filled entries without the need to take the hypfs lock each time the contents are being generated. For directories add a findentry callback to the vector and modify hypfs_get_entry_rel() to use it. Add a HYPFS_VARDIR_INIT() macro for intializing such a directory statically, taking a struct hypfs_funcs pointer as parameter additional to those of HYPFS_DIR_INIT(). Modify HYPFS_VARSIZE_INIT() to take the function vector pointer as an additional parameter as this will be needed for dynamical entries. Move DIRENTRY_SIZE() macro to hypfs.h as it will be needed by the read function of a directory with dynamically generated entries. For being able to let the generic hypfs coding continue to work on normal struct hypfs_entry entities even for dynamical nodes add some infrastructure for allocating a working area for the current hypfs request in order to store needed information for traversing the tree. This area is anchored in a percpu pointer and can be retrieved by any level of the dynamic entries. It will be freed automatically when dropping the hypfs lock. Signed-off-by: Juergen Gross --- xen/common/hypfs.c | 124 +++++++++++++++++++++++++--------------- xen/include/xen/hypfs.h | 39 +++++++++---- 2 files changed, 108 insertions(+), 55 deletions(-) diff --git a/xen/common/hypfs.c b/xen/common/hypfs.c index 97260bd4a3..4c226a06b4 100644 --- a/xen/common/hypfs.c +++ b/xen/common/hypfs.c @@ -19,28 +19,29 @@ CHECK_hypfs_dirlistentry; #endif -#define DIRENTRY_NAME_OFF offsetof(struct xen_hypfs_dirlistentry, name) -#define DIRENTRY_SIZE(name_len) \ - (DIRENTRY_NAME_OFF + \ - ROUNDUP((name_len) + 1, alignof(struct xen_hypfs_direntry))) - struct hypfs_funcs hypfs_dir_funcs = { .read = hypfs_read_dir, + .getsize = hypfs_getsize, + .findentry = hypfs_dir_findentry, }; struct hypfs_funcs hypfs_leaf_ro_funcs = { .read = hypfs_read_leaf, + .getsize = hypfs_getsize, }; struct hypfs_funcs hypfs_leaf_wr_funcs = { .read = hypfs_read_leaf, .write = hypfs_write_leaf, + .getsize = hypfs_getsize, }; struct hypfs_funcs hypfs_bool_wr_funcs = { .read = hypfs_read_leaf, .write = hypfs_write_bool, + .getsize = hypfs_getsize, }; struct hypfs_funcs hypfs_custom_wr_funcs = { .read = hypfs_read_leaf, .write = hypfs_write_custom, + .getsize = hypfs_getsize, }; static DEFINE_RWLOCK(hypfs_lock); @@ -50,6 +51,7 @@ enum hypfs_lock_state { hypfs_write_locked }; static DEFINE_PER_CPU(enum hypfs_lock_state, hypfs_locked); +static DEFINE_PER_CPU(void *, hypfs_dyndata); HYPFS_DIR_INIT(hypfs_root, ""); @@ -71,9 +73,12 @@ static void hypfs_write_lock(void) static void hypfs_unlock(void) { - enum hypfs_lock_state locked = this_cpu(hypfs_locked); + unsigned int cpu = smp_processor_id(); + enum hypfs_lock_state locked = per_cpu(hypfs_locked, cpu); + + XFREE(per_cpu(hypfs_dyndata, cpu)); - this_cpu(hypfs_locked) = hypfs_unlocked; + per_cpu(hypfs_locked, cpu) = hypfs_unlocked; switch ( locked ) { @@ -88,6 +93,23 @@ static void hypfs_unlock(void) } } +void *hypfs_alloc_dyndata(unsigned long size, unsigned long align) +{ + unsigned int cpu = smp_processor_id(); + + ASSERT(per_cpu(hypfs_locked, cpu) != hypfs_unlocked); + ASSERT(per_cpu(hypfs_dyndata, cpu) == NULL); + + per_cpu(hypfs_dyndata, cpu) = _xzalloc(size, align); + + return per_cpu(hypfs_dyndata, cpu); +} + +void *hypfs_get_dyndata(void) +{ + return this_cpu(hypfs_dyndata); +} + static int add_entry(struct hypfs_entry_dir *parent, struct hypfs_entry *new) { int ret = -ENOENT; @@ -122,7 +144,7 @@ static int add_entry(struct hypfs_entry_dir *parent, struct hypfs_entry *new) { unsigned int sz = strlen(new->name); - parent->e.size += DIRENTRY_SIZE(sz); + parent->e.size += HYPFS_DIRENTRY_SIZE(sz); } hypfs_unlock(); @@ -171,15 +193,34 @@ static int hypfs_get_path_user(char *buf, return 0; } +struct hypfs_entry *hypfs_dir_findentry(struct hypfs_entry_dir *dir, + const char *name, + unsigned int name_len) +{ + struct hypfs_entry *entry; + + list_for_each_entry ( entry, &dir->dirlist, list ) + { + int cmp = strncmp(name, entry->name, name_len); + + if ( cmp < 0 ) + return ERR_PTR(-ENOENT); + + if ( !cmp && strlen(entry->name) == name_len ) + return entry; + } + + return ERR_PTR(-ENOENT); +} + static struct hypfs_entry *hypfs_get_entry_rel(struct hypfs_entry_dir *dir, const char *path) { const char *end; struct hypfs_entry *entry; unsigned int name_len; - bool again = true; - while ( again ) + for ( ;; ) { if ( dir->e.type != XEN_HYPFS_TYPE_DIR ) return ERR_PTR(-ENOENT); @@ -192,28 +233,12 @@ static struct hypfs_entry *hypfs_get_entry_rel(struct hypfs_entry_dir *dir, end = strchr(path, '\0'); name_len = end - path; - again = false; + entry = dir->e.funcs->findentry(dir, path, name_len); + if ( IS_ERR(entry) || !*end ) + return entry; - list_for_each_entry ( entry, &dir->dirlist, list ) - { - int cmp = strncmp(path, entry->name, name_len); - struct hypfs_entry_dir *d = container_of(entry, - struct hypfs_entry_dir, e); - - if ( cmp < 0 ) - return ERR_PTR(-ENOENT); - if ( !cmp && strlen(entry->name) == name_len ) - { - if ( !*end ) - return entry; - - again = true; - dir = d; - path = end + 1; - - break; - } - } + path = end + 1; + dir = container_of(entry, struct hypfs_entry_dir, e); } return ERR_PTR(-ENOENT); @@ -227,12 +252,17 @@ static struct hypfs_entry *hypfs_get_entry(const char *path) return hypfs_get_entry_rel(&hypfs_root, path + 1); } +unsigned int hypfs_getsize(const struct hypfs_entry *entry) +{ + return entry->size; +} + int hypfs_read_dir(const struct hypfs_entry *entry, XEN_GUEST_HANDLE_PARAM(void) uaddr) { const struct hypfs_entry_dir *d; const struct hypfs_entry *e; - unsigned int size = entry->size; + unsigned int size = entry->funcs->getsize(entry); ASSERT(this_cpu(hypfs_locked) != hypfs_unlocked); @@ -242,18 +272,18 @@ int hypfs_read_dir(const struct hypfs_entry *entry, { struct xen_hypfs_dirlistentry direntry; unsigned int e_namelen = strlen(e->name); - unsigned int e_len = DIRENTRY_SIZE(e_namelen); + unsigned int e_len = HYPFS_DIRENTRY_SIZE(e_namelen); direntry.e.pad = 0; direntry.e.type = e->type; direntry.e.encoding = e->encoding; - direntry.e.content_len = e->size; + direntry.e.content_len = e->funcs->getsize(e); direntry.e.max_write_len = e->max_size; direntry.off_next = list_is_last(&e->list, &d->dirlist) ? 0 : e_len; if ( copy_to_guest(uaddr, &direntry, 1) ) return -EFAULT; - if ( copy_to_guest_offset(uaddr, DIRENTRY_NAME_OFF, + if ( copy_to_guest_offset(uaddr, HYPFS_DIRENTRY_NAME_OFF, e->name, e_namelen + 1) ) return -EFAULT; @@ -275,22 +305,25 @@ int hypfs_read_leaf(const struct hypfs_entry *entry, l = container_of(entry, const struct hypfs_entry_leaf, e); - return copy_to_guest(uaddr, l->u.content, entry->size) ? -EFAULT: 0; + return copy_to_guest(uaddr, l->u.content, entry->funcs->getsize(entry)) ? + -EFAULT : 0; } static int hypfs_read(const struct hypfs_entry *entry, XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen) { struct xen_hypfs_direntry e; + unsigned int size; long ret = -EINVAL; if ( ulen < sizeof(e) ) goto out; + size = entry->funcs->getsize(entry); e.pad = 0; e.type = entry->type; e.encoding = entry->encoding; - e.content_len = entry->size; + e.content_len = size; e.max_write_len = entry->max_size; ret = -EFAULT; @@ -298,7 +331,7 @@ static int hypfs_read(const struct hypfs_entry *entry, goto out; ret = -ENOBUFS; - if ( ulen < entry->size + sizeof(e) ) + if ( ulen < size + sizeof(e) ) goto out; guest_handle_add_offset(uaddr, sizeof(e)); @@ -314,14 +347,15 @@ int hypfs_write_leaf(struct hypfs_entry_leaf *leaf, { char *buf; int ret; + struct hypfs_entry *e = &leaf->e; ASSERT(this_cpu(hypfs_locked) == hypfs_write_locked); - if ( ulen > leaf->e.max_size ) + if ( ulen > e->max_size ) return -ENOSPC; - if ( leaf->e.type != XEN_HYPFS_TYPE_STRING && - leaf->e.type != XEN_HYPFS_TYPE_BLOB && ulen != leaf->e.size ) + if ( e->type != XEN_HYPFS_TYPE_STRING && + e->type != XEN_HYPFS_TYPE_BLOB && ulen != e->funcs->getsize(e) ) return -EDOM; buf = xmalloc_array(char, ulen); @@ -333,14 +367,14 @@ int hypfs_write_leaf(struct hypfs_entry_leaf *leaf, goto out; ret = -EINVAL; - if ( leaf->e.type == XEN_HYPFS_TYPE_STRING && - leaf->e.encoding == XEN_HYPFS_ENC_PLAIN && + if ( e->type == XEN_HYPFS_TYPE_STRING && + e->encoding == XEN_HYPFS_ENC_PLAIN && memchr(buf, 0, ulen) != (buf + ulen - 1) ) goto out; ret = 0; memcpy(leaf->u.write_ptr, buf, ulen); - leaf->e.size = ulen; + e->size = ulen; out: xfree(buf); @@ -354,7 +388,7 @@ int hypfs_write_bool(struct hypfs_entry_leaf *leaf, ASSERT(this_cpu(hypfs_locked) == hypfs_write_locked); ASSERT(leaf->e.type == XEN_HYPFS_TYPE_BOOL && - leaf->e.size == sizeof(bool) && + leaf->e.funcs->getsize(&leaf->e) == sizeof(bool) && leaf->e.max_size == sizeof(bool) ); if ( ulen != leaf->e.max_size ) diff --git a/xen/include/xen/hypfs.h b/xen/include/xen/hypfs.h index 77916ebb58..c8999b5381 100644 --- a/xen/include/xen/hypfs.h +++ b/xen/include/xen/hypfs.h @@ -2,11 +2,13 @@ #define __XEN_HYPFS_H__ #ifdef CONFIG_HYPFS +#include #include #include #include struct hypfs_entry_leaf; +struct hypfs_entry_dir; struct hypfs_entry; struct hypfs_funcs { @@ -14,6 +16,9 @@ struct hypfs_funcs { XEN_GUEST_HANDLE_PARAM(void) uaddr); int (*write)(struct hypfs_entry_leaf *leaf, XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned int ulen); + unsigned int (*getsize)(const struct hypfs_entry *entry); + struct hypfs_entry *(*findentry)(struct hypfs_entry_dir *dir, + const char *name, unsigned int name_len); }; extern struct hypfs_funcs hypfs_dir_funcs; @@ -45,7 +50,12 @@ struct hypfs_entry_dir { struct list_head dirlist; }; -#define HYPFS_DIR_INIT(var, nam) \ +#define HYPFS_DIRENTRY_NAME_OFF offsetof(struct xen_hypfs_dirlistentry, name) +#define HYPFS_DIRENTRY_SIZE(name_len) \ + (HYPFS_DIRENTRY_NAME_OFF + \ + ROUNDUP((name_len) + 1, alignof(struct xen_hypfs_direntry))) + +#define HYPFS_VARDIR_INIT(var, nam, fn) \ struct hypfs_entry_dir __read_mostly var = { \ .e.type = XEN_HYPFS_TYPE_DIR, \ .e.encoding = XEN_HYPFS_ENC_PLAIN, \ @@ -53,22 +63,25 @@ struct hypfs_entry_dir { .e.size = 0, \ .e.max_size = 0, \ .e.list = LIST_HEAD_INIT(var.e.list), \ - .e.funcs = &hypfs_dir_funcs, \ + .e.funcs = (fn), \ .dirlist = LIST_HEAD_INIT(var.dirlist), \ } -#define HYPFS_VARSIZE_INIT(var, typ, nam, msz) \ - struct hypfs_entry_leaf __read_mostly var = { \ - .e.type = (typ), \ - .e.encoding = XEN_HYPFS_ENC_PLAIN, \ - .e.name = (nam), \ - .e.max_size = (msz), \ - .e.funcs = &hypfs_leaf_ro_funcs, \ +#define HYPFS_DIR_INIT(var, nam) \ + HYPFS_VARDIR_INIT(var, nam, &hypfs_dir_funcs) + +#define HYPFS_VARSIZE_INIT(var, typ, nam, msz, fn) \ + struct hypfs_entry_leaf __read_mostly var = { \ + .e.type = (typ), \ + .e.encoding = XEN_HYPFS_ENC_PLAIN, \ + .e.name = (nam), \ + .e.max_size = (msz), \ + .e.funcs = (fn), \ } /* Content and size need to be set via hypfs_string_set_reference(). */ #define HYPFS_STRING_INIT(var, nam) \ - HYPFS_VARSIZE_INIT(var, XEN_HYPFS_TYPE_STRING, nam, 0) + HYPFS_VARSIZE_INIT(var, XEN_HYPFS_TYPE_STRING, nam, 0, &hypfs_leaf_ro_funcs) /* * Set content and size of a XEN_HYPFS_TYPE_STRING node. The node will point @@ -131,6 +144,12 @@ int hypfs_write_bool(struct hypfs_entry_leaf *leaf, XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned int ulen); int hypfs_write_custom(struct hypfs_entry_leaf *leaf, XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned int ulen); +unsigned int hypfs_getsize(const struct hypfs_entry *entry); +struct hypfs_entry *hypfs_dir_findentry(struct hypfs_entry_dir *dir, + const char *name, + unsigned int name_len); +void *hypfs_alloc_dyndata(unsigned long size, unsigned long align); +void *hypfs_get_dyndata(void); #endif #endif /* __XEN_HYPFS_H__ */ From patchwork Mon Oct 26 09:13:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11856159 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 65F541130 for ; Mon, 26 Oct 2020 09:14:02 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 375A62076D for ; Mon, 26 Oct 2020 09:14:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="PEGW9POG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 375A62076D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.12088.31735 (Exim 4.92) (envelope-from ) id 1kWyZS-0005E8-TP; Mon, 26 Oct 2020 09:13:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 12088.31735; Mon, 26 Oct 2020 09:13:42 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZS-0005Do-LM; Mon, 26 Oct 2020 09:13:42 +0000 Received: by outflank-mailman (input) for mailman id 12088; Mon, 26 Oct 2020 09:13:40 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZQ-0004f1-Rm for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:40 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c2d1a173-a065-4271-967a-ad287a5065d5; Mon, 26 Oct 2020 09:13:21 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A1D3EB244; Mon, 26 Oct 2020 09:13:20 +0000 (UTC) Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZQ-0004f1-Rm for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:40 +0000 X-Inumbo-ID: c2d1a173-a065-4271-967a-ad287a5065d5 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c2d1a173-a065-4271-967a-ad287a5065d5; Mon, 26 Oct 2020 09:13:21 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1603703600; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kfzDywvYxNprz4jIH7nIZnqi8wD+M3kSqllQAfQb1kA=; b=PEGW9POG9sdRUTUTQE3XHqjCbqIUKV3+9Tmk2NH7J/akbaoZTKno/CnHxk+5DeQmQm+qNU rXKR5EVpKbB6ztfuZ+PH660DZ0P69kcIlZPwcm9PdXlnmIhQW6sXUDX+ga2ek6tvAEVuXd bfUqkxKWfJH8zLNC5Icsn8wlm9N3X70= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A1D3EB244; Mon, 26 Oct 2020 09:13:20 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH 09/12] xen/hypfs: add support for id-based dynamic directories Date: Mon, 26 Oct 2020 10:13:13 +0100 Message-Id: <20201026091316.25680-10-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026091316.25680-1-jgross@suse.com> References: <20201026091316.25680-1-jgross@suse.com> MIME-Version: 1.0 Add some helpers to hypfs.c to support dynamic directories with a numerical id as name. The dynamic directory is based on a template specified by the user allowing to use specific access functions and having a predefined set of entries in the directory. Signed-off-by: Juergen Gross --- xen/common/hypfs.c | 76 +++++++++++++++++++++++++++++++++++++++++ xen/include/xen/hypfs.h | 14 ++++++++ 2 files changed, 90 insertions(+) diff --git a/xen/common/hypfs.c b/xen/common/hypfs.c index 4c226a06b4..12be2f6d16 100644 --- a/xen/common/hypfs.c +++ b/xen/common/hypfs.c @@ -257,6 +257,82 @@ unsigned int hypfs_getsize(const struct hypfs_entry *entry) return entry->size; } +int hypfs_read_dyndir_id_entry(struct hypfs_entry_dir *template, + unsigned int id, bool is_last, + XEN_GUEST_HANDLE_PARAM(void) *uaddr) +{ + struct xen_hypfs_dirlistentry direntry; + char name[12]; + unsigned int e_namelen, e_len; + + e_namelen = snprintf(name, sizeof(name), "%u", id); + e_len = HYPFS_DIRENTRY_SIZE(e_namelen); + direntry.e.pad = 0; + direntry.e.type = template->e.type; + direntry.e.encoding = template->e.encoding; + direntry.e.content_len = template->e.funcs->getsize(&template->e); + direntry.e.max_write_len = template->e.max_size; + direntry.off_next = is_last ? 0 : e_len; + if ( copy_to_guest(*uaddr, &direntry, 1) ) + return -EFAULT; + if ( copy_to_guest_offset(*uaddr, HYPFS_DIRENTRY_NAME_OFF, name, + e_namelen + 1) ) + return -EFAULT; + + guest_handle_add_offset(*uaddr, e_len); + + return 0; +} + +static struct hypfs_entry *hypfs_dyndir_findentry(struct hypfs_entry_dir *dir, + const char *name, + unsigned int name_len) +{ + struct hypfs_dyndir_id *data; + + data = hypfs_get_dyndata(); + if ( !data ) + return ERR_PTR(-ENOENT); + + /* Use template with original findentry function. */ + return data->template->e.funcs->findentry(data->template, name, name_len); +} + +static int hypfs_read_dyndir(const struct hypfs_entry *entry, + XEN_GUEST_HANDLE_PARAM(void) uaddr) +{ + struct hypfs_dyndir_id *data; + + data = hypfs_get_dyndata(); + if ( !data ) + return -ENOENT; + + /* Use template with original read function. */ + return data->template->e.funcs->read(&data->template->e, uaddr); +} + +struct hypfs_entry *hypfs_gen_dyndir_entry_id(struct hypfs_entry_dir *template, + unsigned int id) +{ + struct hypfs_dyndir_id *data; + + data = hypfs_alloc_dyndata(sizeof(*data), alignof(*data)); + if ( !data ) + return ERR_PTR(-ENOMEM); + + data->template = template; + data->id = id; + snprintf(data->name, sizeof(data->name), "%u", id); + data->dir = *template; + data->dir.e.name = data->name; + data->dir.e.funcs = &data->funcs; + data->funcs = *template->e.funcs; + data->funcs.findentry = hypfs_dyndir_findentry; + data->funcs.read = hypfs_read_dyndir; + + return &data->dir.e; +} + int hypfs_read_dir(const struct hypfs_entry *entry, XEN_GUEST_HANDLE_PARAM(void) uaddr) { diff --git a/xen/include/xen/hypfs.h b/xen/include/xen/hypfs.h index c8999b5381..adfb522496 100644 --- a/xen/include/xen/hypfs.h +++ b/xen/include/xen/hypfs.h @@ -50,6 +50,15 @@ struct hypfs_entry_dir { struct list_head dirlist; }; +struct hypfs_dyndir_id { + struct hypfs_entry_dir dir; /* Modified copy of template. */ + struct hypfs_funcs funcs; /* Dynamic functions. */ + struct hypfs_entry_dir *template; /* Template used. */ + char name[12]; /* Name of hypfs entry. */ + + unsigned int id; /* Numerical id. */ +}; + #define HYPFS_DIRENTRY_NAME_OFF offsetof(struct xen_hypfs_dirlistentry, name) #define HYPFS_DIRENTRY_SIZE(name_len) \ (HYPFS_DIRENTRY_NAME_OFF + \ @@ -150,6 +159,11 @@ struct hypfs_entry *hypfs_dir_findentry(struct hypfs_entry_dir *dir, unsigned int name_len); void *hypfs_alloc_dyndata(unsigned long size, unsigned long align); void *hypfs_get_dyndata(void); +int hypfs_read_dyndir_id_entry(struct hypfs_entry_dir *template, + unsigned int id, bool is_last, + XEN_GUEST_HANDLE_PARAM(void) *uaddr); +struct hypfs_entry *hypfs_gen_dyndir_entry_id(struct hypfs_entry_dir *template, + unsigned int id); #endif #endif /* __XEN_HYPFS_H__ */ From patchwork Mon Oct 26 09:13:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11856177 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 25C0C61C for ; Mon, 26 Oct 2020 09:14:29 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EDA752076D for ; Mon, 26 Oct 2020 09:14:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="L+h43uW4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EDA752076D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.12085.31708 (Exim 4.92) (envelope-from ) id 1kWyZN-00053i-To; Mon, 26 Oct 2020 09:13:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 12085.31708; Mon, 26 Oct 2020 09:13:37 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZN-00053L-PE; Mon, 26 Oct 2020 09:13:37 +0000 Received: by outflank-mailman (input) for mailman id 12085; Mon, 26 Oct 2020 09:13:35 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZL-0004f1-Rl for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:35 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 07e6da9e-aa3a-4f34-8f06-da9f0e4f8e2e; Mon, 26 Oct 2020 09:13:21 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id E1AA1B245; Mon, 26 Oct 2020 09:13:20 +0000 (UTC) Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZL-0004f1-Rl for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:35 +0000 X-Inumbo-ID: 07e6da9e-aa3a-4f34-8f06-da9f0e4f8e2e Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 07e6da9e-aa3a-4f34-8f06-da9f0e4f8e2e; Mon, 26 Oct 2020 09:13:21 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1603703601; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M2krL48gwKtn5+NJtv6lNCEGODluTgIO1YbuF6efH7k=; b=L+h43uW4CetUkMAM1vDXaII+0gwnfcoYb/izkWwW0fDF4ogdzW7BHD4v/gdgvaBmOMzzRq zfpnAMZrb5Y2uk3vtPGOo8On3aJYFUMAKtnv26Q3xIL0C6IfdKlkiFVO8pixTBAvyPQa1p /irvmsgO06EfxSxhvotv8XmbPFgqF84= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id E1AA1B245; Mon, 26 Oct 2020 09:13:20 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Dario Faggioli Subject: [PATCH 10/12] xen/hypfs: add cpupool directories Date: Mon, 26 Oct 2020 10:13:14 +0100 Message-Id: <20201026091316.25680-11-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026091316.25680-1-jgross@suse.com> References: <20201026091316.25680-1-jgross@suse.com> MIME-Version: 1.0 Add /cpupool/ directories to hypfs. Those are completely dynamic, so the related hypfs access functions need to be implemented. Signed-off-by: Juergen Gross Reviewed-by: Dario Faggioli --- docs/misc/hypfs-paths.pandoc | 9 +++++ xen/common/sched/cpupool.c | 78 ++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/docs/misc/hypfs-paths.pandoc b/docs/misc/hypfs-paths.pandoc index 6c7b2f7ee3..aaca1cdf92 100644 --- a/docs/misc/hypfs-paths.pandoc +++ b/docs/misc/hypfs-paths.pandoc @@ -175,6 +175,15 @@ The major version of Xen. The minor version of Xen. +#### /cpupool/ + +A directory of all current cpupools. + +#### /cpupool/*/ + +The individual cpupools. Each entry is a directory with the name being the +cpupool-id (e.g. /cpupool/0/). + #### /params/ A directory of runtime parameters. diff --git a/xen/common/sched/cpupool.c b/xen/common/sched/cpupool.c index 84f326ea63..8612ee5cf6 100644 --- a/xen/common/sched/cpupool.c +++ b/xen/common/sched/cpupool.c @@ -13,6 +13,8 @@ #include #include +#include +#include #include #include #include @@ -992,6 +994,78 @@ static struct notifier_block cpu_nfb = { .notifier_call = cpu_callback }; +#ifdef CONFIG_HYPFS +static HYPFS_DIR_INIT(cpupool_pooldir, "id"); + +static int cpupool_dir_read(const struct hypfs_entry *entry, + XEN_GUEST_HANDLE_PARAM(void) uaddr) +{ + int ret = 0; + struct cpupool **q; + + spin_lock(&cpupool_lock); + + for_each_cpupool(q) + { + ret = hypfs_read_dyndir_id_entry(&cpupool_pooldir, (*q)->cpupool_id, + !(*q)->next, &uaddr); + if ( ret ) + break; + } + + spin_unlock(&cpupool_lock); + + return ret; +} + +static unsigned int cpupool_dir_getsize(const struct hypfs_entry *entry) +{ + struct cpupool **q; + unsigned int size = 0; + + spin_lock(&cpupool_lock); + + for_each_cpupool(q) + size += HYPFS_DIRENTRY_SIZE(snprintf(NULL, 0, "%d", (*q)->cpupool_id)); + + spin_unlock(&cpupool_lock); + + return size; +} + +static struct hypfs_entry *cpupool_dir_findentry(struct hypfs_entry_dir *dir, + const char *name, + unsigned int name_len) +{ + unsigned long id; + const char *end; + struct cpupool *cpupool; + + id = simple_strtoul(name, &end, 10); + if ( id > INT_MAX || end != name + name_len ) + return ERR_PTR(-ENOENT); + + spin_lock(&cpupool_lock); + + cpupool = __cpupool_find_by_id(id, true); + + spin_unlock(&cpupool_lock); + + if ( !cpupool ) + return ERR_PTR(-ENOENT); + + return hypfs_gen_dyndir_entry_id(&cpupool_pooldir, id); +} + +static struct hypfs_funcs cpupool_dir_funcs = { + .read = cpupool_dir_read, + .getsize = cpupool_dir_getsize, + .findentry = cpupool_dir_findentry, +}; + +static HYPFS_VARDIR_INIT(cpupool_dir, "cpupool", &cpupool_dir_funcs); +#endif + static int __init cpupool_init(void) { unsigned int cpu; @@ -999,6 +1073,10 @@ static int __init cpupool_init(void) cpupool_gran_init(); +#ifdef CONFIG_HYPFS + hypfs_add_dir(&hypfs_root, &cpupool_dir, true); +#endif + cpupool0 = cpupool_create(0, 0, &err); BUG_ON(cpupool0 == NULL); cpupool_put(cpupool0); From patchwork Mon Oct 26 09:13:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11856173 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2ED4561C for ; Mon, 26 Oct 2020 09:14:24 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E90E22076D for ; Mon, 26 Oct 2020 09:14:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="X6sFx1rS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E90E22076D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.12091.31755 (Exim 4.92) (envelope-from ) id 1kWyZX-0005NX-U7; Mon, 26 Oct 2020 09:13:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 12091.31755; Mon, 26 Oct 2020 09:13:47 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZX-0005N9-DC; Mon, 26 Oct 2020 09:13:47 +0000 Received: by outflank-mailman (input) for mailman id 12091; Mon, 26 Oct 2020 09:13:45 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZV-0004f1-S3 for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:45 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d8c24bb7-8e2d-4583-acb4-5a9f8c6fa148; Mon, 26 Oct 2020 09:13:22 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 29ED6B248; Mon, 26 Oct 2020 09:13:21 +0000 (UTC) Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZV-0004f1-S3 for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:45 +0000 X-Inumbo-ID: d8c24bb7-8e2d-4583-acb4-5a9f8c6fa148 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d8c24bb7-8e2d-4583-acb4-5a9f8c6fa148; Mon, 26 Oct 2020 09:13:22 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1603703601; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BtuXFg+GprfOQoW7qcf8PMrXYl8U5hOCU9BdXI7w0yo=; b=X6sFx1rS9WEJvX5kbsaQAt19W7YP4+Bqr2R8LLtyKOUIrvJq/MPQG1mnjkxkKFXfAhCpQe ova2WKr80t7vA5to7plnDvHfrbuK8FuCN0noIsDDYfUeD96tFt7Ko5fv3sMkS9tXs6v6xx TLgu8mcIfDHuNxe5UH8ufStdahvCuYc= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 29ED6B248; Mon, 26 Oct 2020 09:13:21 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Dario Faggioli Subject: [PATCH 11/12] xen/hypfs: add scheduling granularity entry to cpupool entries Date: Mon, 26 Oct 2020 10:13:15 +0100 Message-Id: <20201026091316.25680-12-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026091316.25680-1-jgross@suse.com> References: <20201026091316.25680-1-jgross@suse.com> MIME-Version: 1.0 Add a "sched-gran" entry to the per-cpupool hypfs directories. For now make this entry read-only and let it contain one of the strings "cpu", "core" or "socket". Signed-off-by: Juergen Gross Acked-by: Dario Faggioli --- docs/misc/hypfs-paths.pandoc | 4 +++ xen/common/sched/cpupool.c | 51 +++++++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/docs/misc/hypfs-paths.pandoc b/docs/misc/hypfs-paths.pandoc index aaca1cdf92..f1ce24d7fe 100644 --- a/docs/misc/hypfs-paths.pandoc +++ b/docs/misc/hypfs-paths.pandoc @@ -184,6 +184,10 @@ A directory of all current cpupools. The individual cpupools. Each entry is a directory with the name being the cpupool-id (e.g. /cpupool/0/). +#### /cpupool/*/sched-gran = ("cpu" | "core" | "socket") + +The scheduling granularity of a cpupool. + #### /params/ A directory of runtime parameters. diff --git a/xen/common/sched/cpupool.c b/xen/common/sched/cpupool.c index 8612ee5cf6..8674ac0fdd 100644 --- a/xen/common/sched/cpupool.c +++ b/xen/common/sched/cpupool.c @@ -42,9 +42,10 @@ static DEFINE_SPINLOCK(cpupool_lock); static enum sched_gran __read_mostly opt_sched_granularity = SCHED_GRAN_cpu; static unsigned int __read_mostly sched_granularity = 1; +#define SCHED_GRAN_NAME_LEN 8 struct sched_gran_name { enum sched_gran mode; - char name[8]; + char name[SCHED_GRAN_NAME_LEN]; }; static const struct sched_gran_name sg_name[] = { @@ -53,7 +54,7 @@ static const struct sched_gran_name sg_name[] = { {SCHED_GRAN_socket, "socket"}, }; -static void sched_gran_print(enum sched_gran mode, unsigned int gran) +static const char *sched_gran_get_name(enum sched_gran mode) { const char *name = ""; unsigned int i; @@ -67,8 +68,13 @@ static void sched_gran_print(enum sched_gran mode, unsigned int gran) } } + return name; +} + +static void sched_gran_print(enum sched_gran mode, unsigned int gran) +{ printk("Scheduling granularity: %s, %u CPU%s per sched-resource\n", - name, gran, gran == 1 ? "" : "s"); + sched_gran_get_name(mode), gran, gran == 1 ? "" : "s"); } #ifdef CONFIG_HAS_SCHED_GRANULARITY @@ -1057,6 +1063,43 @@ static struct hypfs_entry *cpupool_dir_findentry(struct hypfs_entry_dir *dir, return hypfs_gen_dyndir_entry_id(&cpupool_pooldir, id); } +static int cpupool_gran_read(const struct hypfs_entry *entry, + XEN_GUEST_HANDLE_PARAM(void) uaddr) +{ + const struct hypfs_dyndir_id *data; + struct cpupool *cpupool; + const char *name = ""; + + data = hypfs_get_dyndata(); + if ( !data ) + return -ENOENT; + + spin_lock(&cpupool_lock); + + cpupool = __cpupool_find_by_id(data->id, true); + if ( cpupool ) + name = sched_gran_get_name(cpupool->gran); + + spin_unlock(&cpupool_lock); + + if ( !cpupool ) + return -ENOENT; + + return copy_to_guest(uaddr, name, strlen(name) + 1) ? -EFAULT : 0; +} + +static struct hypfs_funcs cpupool_gran_funcs = { + .read = cpupool_gran_read, + .getsize = hypfs_getsize, +}; + +static HYPFS_VARSIZE_INIT(cpupool_gran, XEN_HYPFS_TYPE_STRING, "sched-gran", + 0, &cpupool_gran_funcs); +static char granstr[SCHED_GRAN_NAME_LEN] = { + [0 ... SCHED_GRAN_NAME_LEN - 2] = '?', + [SCHED_GRAN_NAME_LEN - 1] = 0 +}; + static struct hypfs_funcs cpupool_dir_funcs = { .read = cpupool_dir_read, .getsize = cpupool_dir_getsize, @@ -1075,6 +1118,8 @@ static int __init cpupool_init(void) #ifdef CONFIG_HYPFS hypfs_add_dir(&hypfs_root, &cpupool_dir, true); + hypfs_string_set_reference(&cpupool_gran, granstr); + hypfs_add_leaf(&cpupool_pooldir, &cpupool_gran, true); #endif cpupool0 = cpupool_create(0, 0, &err); From patchwork Mon Oct 26 09:13:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11856171 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7934B14B2 for ; Mon, 26 Oct 2020 09:14:18 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4CF2F2076D for ; Mon, 26 Oct 2020 09:14:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="KUWQ3HmO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4CF2F2076D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.12090.31747 (Exim 4.92) (envelope-from ) id 1kWyZX-0005MI-4R; Mon, 26 Oct 2020 09:13:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 12090.31747; Mon, 26 Oct 2020 09:13:47 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZX-0005M6-09; Mon, 26 Oct 2020 09:13:47 +0000 Received: by outflank-mailman (input) for mailman id 12090; Mon, 26 Oct 2020 09:13:45 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZV-0004ev-EQ for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:45 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c71bdaa5-202f-4353-9cbf-15d9e856f476; Mon, 26 Oct 2020 09:13:22 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 64294B234; Mon, 26 Oct 2020 09:13:21 +0000 (UTC) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kWyZV-0004ev-EQ for xen-devel@lists.xenproject.org; Mon, 26 Oct 2020 09:13:45 +0000 X-Inumbo-ID: c71bdaa5-202f-4353-9cbf-15d9e856f476 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c71bdaa5-202f-4353-9cbf-15d9e856f476; Mon, 26 Oct 2020 09:13:22 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1603703601; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zwN6kMRipkhMSsm6aORIIrosl9Cg2bYxBav4xp706Is=; b=KUWQ3HmOrCVw2Woxn7ZqwEd2ZJS4dD1x3r4iRWRx7iaQ6h/Wa0CMtME9CsHhcO0Tkzsjb9 3ZnecGwimgvPBhBJhdeeyFwcAxOj/9AQ/G8ZWX5Gz5vaaD86LdI02gbRJswM5CnNAMIczy puqEIMPjqKD3mmyoDSGU7EIsbL/aXwo= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 64294B234; Mon, 26 Oct 2020 09:13:21 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Dario Faggioli Subject: [PATCH 12/12] xen/cpupool: make per-cpupool sched-gran hypfs node writable Date: Mon, 26 Oct 2020 10:13:16 +0100 Message-Id: <20201026091316.25680-13-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026091316.25680-1-jgross@suse.com> References: <20201026091316.25680-1-jgross@suse.com> MIME-Version: 1.0 Make /cpupool//sched-gran in hypfs writable. This will enable per cpupool selectable scheduling granularity. Writing this node is allowed only with no cpu assigned to the cpupool. Allowed are values "cpu", "core" and "socket". Signed-off-by: Juergen Gross --- docs/misc/hypfs-paths.pandoc | 5 ++- xen/common/sched/cpupool.c | 75 +++++++++++++++++++++++++++++++----- 2 files changed, 69 insertions(+), 11 deletions(-) diff --git a/docs/misc/hypfs-paths.pandoc b/docs/misc/hypfs-paths.pandoc index f1ce24d7fe..e86f7d0dbe 100644 --- a/docs/misc/hypfs-paths.pandoc +++ b/docs/misc/hypfs-paths.pandoc @@ -184,10 +184,13 @@ A directory of all current cpupools. The individual cpupools. Each entry is a directory with the name being the cpupool-id (e.g. /cpupool/0/). -#### /cpupool/*/sched-gran = ("cpu" | "core" | "socket") +#### /cpupool/*/sched-gran = ("cpu" | "core" | "socket") [w] The scheduling granularity of a cpupool. +Writing a value is allowed only for cpupools with no cpu assigned and if the +architecture is supporting different scheduling granularities. + #### /params/ A directory of runtime parameters. diff --git a/xen/common/sched/cpupool.c b/xen/common/sched/cpupool.c index 8674ac0fdd..d0c61fb720 100644 --- a/xen/common/sched/cpupool.c +++ b/xen/common/sched/cpupool.c @@ -78,7 +78,7 @@ static void sched_gran_print(enum sched_gran mode, unsigned int gran) } #ifdef CONFIG_HAS_SCHED_GRANULARITY -static int __init sched_select_granularity(const char *str) +static int sched_gran_get(const char *str, enum sched_gran *mode) { unsigned int i; @@ -86,36 +86,43 @@ static int __init sched_select_granularity(const char *str) { if ( strcmp(sg_name[i].name, str) == 0 ) { - opt_sched_granularity = sg_name[i].mode; + *mode = sg_name[i].mode; return 0; } } return -EINVAL; } + +static int __init sched_select_granularity(const char *str) +{ + return sched_gran_get(str, &opt_sched_granularity); +} custom_param("sched-gran", sched_select_granularity); +#else +static int sched_gran_get(const char *str, enum sched_gran *mode) +{ + return -EINVAL; +} #endif -static unsigned int __init cpupool_check_granularity(void) +static unsigned int cpupool_check_granularity(enum sched_gran mode) { unsigned int cpu; unsigned int siblings, gran = 0; - if ( opt_sched_granularity == SCHED_GRAN_cpu ) + if ( mode == SCHED_GRAN_cpu ) return 1; for_each_online_cpu ( cpu ) { - siblings = cpumask_weight(sched_get_opt_cpumask(opt_sched_granularity, - cpu)); + siblings = cpumask_weight(sched_get_opt_cpumask(mode, cpu)); if ( gran == 0 ) gran = siblings; else if ( gran != siblings ) return 0; } - sched_disable_smt_switching = true; - return gran; } @@ -127,7 +134,7 @@ static void __init cpupool_gran_init(void) while ( gran == 0 ) { - gran = cpupool_check_granularity(); + gran = cpupool_check_granularity(opt_sched_granularity); if ( gran == 0 ) { @@ -153,6 +160,9 @@ static void __init cpupool_gran_init(void) if ( fallback ) warning_add(fallback); + if ( opt_sched_granularity != SCHED_GRAN_cpu ) + sched_disable_smt_switching = true; + sched_granularity = gran; sched_gran_print(opt_sched_granularity, sched_granularity); } @@ -1088,13 +1098,58 @@ static int cpupool_gran_read(const struct hypfs_entry *entry, return copy_to_guest(uaddr, name, strlen(name) + 1) ? -EFAULT : 0; } +static int cpupool_gran_write(struct hypfs_entry_leaf *leaf, + XEN_GUEST_HANDLE_PARAM(void) uaddr, + unsigned int ulen) +{ + const struct hypfs_dyndir_id *data; + struct cpupool *cpupool; + enum sched_gran gran; + unsigned int sched_gran; + char name[SCHED_GRAN_NAME_LEN]; + int ret = 0; + + if ( ulen > SCHED_GRAN_NAME_LEN ) + return -ENOSPC; + + if ( copy_from_guest(name, uaddr, ulen) ) + return -EFAULT; + + sched_gran = sched_gran_get(name, &gran) ? 0 + : cpupool_check_granularity(gran); + if ( memchr(name, 0, ulen) != (name + ulen - 1) || sched_gran == 0 ) + return -EINVAL; + + data = hypfs_get_dyndata(); + if ( !data ) + return -ENOENT; + + spin_lock(&cpupool_lock); + + cpupool = __cpupool_find_by_id(data->id, true); + if ( !cpupool ) + ret = -ENOENT; + else if ( !cpumask_empty(cpupool->cpu_valid) ) + ret = -EBUSY; + else + { + cpupool->gran = gran; + cpupool->sched_gran = sched_gran; + } + + spin_unlock(&cpupool_lock); + + return ret; +} + static struct hypfs_funcs cpupool_gran_funcs = { .read = cpupool_gran_read, + .write = cpupool_gran_write, .getsize = hypfs_getsize, }; static HYPFS_VARSIZE_INIT(cpupool_gran, XEN_HYPFS_TYPE_STRING, "sched-gran", - 0, &cpupool_gran_funcs); + SCHED_GRAN_NAME_LEN, &cpupool_gran_funcs); static char granstr[SCHED_GRAN_NAME_LEN] = { [0 ... SCHED_GRAN_NAME_LEN - 2] = '?', [SCHED_GRAN_NAME_LEN - 1] = 0