From nobody Tue Feb 10 14:49:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610970952; cv=none; d=zohomail.com; s=zohoarc; b=TkrvGZwV6mTAleUspkH0C5Lm7Y4f/5/AwYcukAofHIrNZa4mUygwOFcpKmn3MqxsYl5bDZCVSZJ87xW9L/rUjFNqq5InKFichKheQK26zH06iWB44cENc/FTFVzBG+GoNuFsEjYJfzuElooX2O2foDifIgdkxzGu43JH+aZY+AY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610970952; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=puNmDHfyAfcD8/V1nWe0SEp7VXPx3Ta6JdhxgAf41VQ=; b=DoMwnOiDAxvX3q0oF58KXdACwzY8YEErEbECd5cn8sTCmMIHsjkJV6t3PiM9r1hriIsIzmNmA7XATjRh3hnvHcVsODIy2pA4XNfZQ+VR8ivAwUNGD4sPvzN9PIek7UIxXYX50U9mY3hv3rOucriQNpawDn5UIGovlg6xZEeER8o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610970952853832.9729828304831; Mon, 18 Jan 2021 03:55:52 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.69612.124725 (Exim 4.92) (envelope-from ) id 1l1T7y-0005Wa-Rh; Mon, 18 Jan 2021 11:55:22 +0000 Received: by outflank-mailman (output) from mailman id 69612.124725; Mon, 18 Jan 2021 11:55:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l1T7y-0005WT-N3; Mon, 18 Jan 2021 11:55:22 +0000 Received: by outflank-mailman (input) for mailman id 69612; Mon, 18 Jan 2021 11:55:21 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l1T7x-0005WJ-Nd for xen-devel@lists.xenproject.org; Mon, 18 Jan 2021 11:55:21 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1fdcd800-bc5c-4b1f-9238-a8bacdf01211; Mon, 18 Jan 2021 11:55:20 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 3E3F8AE6E; Mon, 18 Jan 2021 11:55:19 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version 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" X-Inumbo-ID: 1fdcd800-bc5c-4b1f-9238-a8bacdf01211 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=1610970919; h=from:from:reply-to: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=puNmDHfyAfcD8/V1nWe0SEp7VXPx3Ta6JdhxgAf41VQ=; b=LKhUzS3Mtj5N4dH+eQojKJdwGXU/6AjfDXlVHVOqTGDH43r0t55CioEIJctCzhQcNqpaZV OBtDohXKZ2eVamR6DILxGTKPqq5AAiY/yM8Y3jEmU8gEjLrV0u+tUGoYKhpaC4gkB1XSao KsdEfMQMqtK1ABBcW5lq/FTfvcgbGZE= 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 v4 1/5] xen/hypfs: support dynamic hypfs nodes Date: Mon, 18 Jan 2021 12:55:12 +0100 Message-Id: <20210118115516.11001-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210118115516.11001-1-jgross@suse.com> References: <20210118115516.11001-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Add a HYPFS_VARDIR_INIT() macro for initializing 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. 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. The normal way to handle allocation and freeing is to allocate the data in the enter() callback of a node and to free it in the related exit() callback. Add a hypfs_add_dyndir() function for adding a dynamic directory template to the tree, which is needed for having the correct reference to its position in hypfs. Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- V2: - switch to xzalloc_bytes() in hypfs_alloc_dyndata() (Jan Beulich) - carved out from previous patch - use enter() and exit() callbacks for allocating and freeing dyndata memory - add hypfs_add_dyndir() V3: - switch hypfs_alloc_dyndata() to be type safe (Jan Beulich) - rename HYPFS_VARDIR_INIT() to HYPFS_DIR_INIT_FUNC() (Jan Beulich) V4: - use temporary variables for avoiding multiple per_cpu() uses (Jan Beulich) - add comment (Jan Beulich) - hide hypfs_alloc_dyndata() type unsafe backing function (Jan Beulich) --- xen/common/hypfs.c | 43 +++++++++++++++++++++++++++++++++++++++++ xen/include/xen/hypfs.h | 29 +++++++++++++++++---------- 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/xen/common/hypfs.c b/xen/common/hypfs.c index 73497ea1d7..6c0e59dedd 100644 --- a/xen/common/hypfs.c +++ b/xen/common/hypfs.c @@ -72,6 +72,7 @@ enum hypfs_lock_state { hypfs_write_locked }; static DEFINE_PER_CPU(enum hypfs_lock_state, hypfs_locked); +static DEFINE_PER_CPU(struct hypfs_dyndata *, hypfs_dyndata); =20 static DEFINE_PER_CPU(const struct hypfs_entry *, hypfs_last_node_entered); =20 @@ -155,6 +156,36 @@ static void node_exit_all(void) node_exit(*last); } =20 +#undef hypfs_alloc_dyndata +void *hypfs_alloc_dyndata(unsigned long size) +{ + unsigned int cpu =3D smp_processor_id(); + struct hypfs_dyndata **dyndata =3D &per_cpu(hypfs_dyndata, cpu); + + ASSERT(per_cpu(hypfs_locked, cpu) !=3D hypfs_unlocked); + ASSERT(*dyndata =3D=3D NULL); + + *dyndata =3D xzalloc_bytes(size); + + return *dyndata; +} + +void *hypfs_get_dyndata(void) +{ + struct hypfs_dyndata *dyndata =3D this_cpu(hypfs_dyndata); + + ASSERT(dyndata); + + return dyndata; +} + +void hypfs_free_dyndata(void) +{ + struct hypfs_dyndata **dyndata =3D &this_cpu(hypfs_dyndata); + + XFREE(*dyndata); +} + static int add_entry(struct hypfs_entry_dir *parent, struct hypfs_entry *n= ew) { int ret =3D -ENOENT; @@ -216,6 +247,18 @@ int hypfs_add_dir(struct hypfs_entry_dir *parent, return ret; } =20 +void hypfs_add_dyndir(struct hypfs_entry_dir *parent, + struct hypfs_entry_dir *template) +{ + /* + * As the template is only a placeholder for possibly multiple dynamic= ally + * generated directories, the link up to its parent can be static, whi= le + * the "real" children of the parent are to be found via the parent's + * findentry function only. + */ + template->e.parent =3D &parent->e; +} + int hypfs_add_leaf(struct hypfs_entry_dir *parent, struct hypfs_entry_leaf *leaf, bool nofault) { diff --git a/xen/include/xen/hypfs.h b/xen/include/xen/hypfs.h index a6dfdb7d8e..d028c01283 100644 --- a/xen/include/xen/hypfs.h +++ b/xen/include/xen/hypfs.h @@ -76,7 +76,7 @@ struct hypfs_entry_dir { struct list_head dirlist; }; =20 -#define HYPFS_DIR_INIT(var, nam) \ +#define HYPFS_DIR_INIT_FUNC(var, nam, fn) \ struct hypfs_entry_dir __read_mostly var =3D { \ .e.type =3D XEN_HYPFS_TYPE_DIR, \ .e.encoding =3D XEN_HYPFS_ENC_PLAIN, \ @@ -84,22 +84,25 @@ struct hypfs_entry_dir { .e.size =3D 0, \ .e.max_size =3D 0, \ .e.list =3D LIST_HEAD_INIT(var.e.list), \ - .e.funcs =3D &hypfs_dir_funcs, \ + .e.funcs =3D (fn), \ .dirlist =3D LIST_HEAD_INIT(var.dirlist), \ } =20 -#define HYPFS_VARSIZE_INIT(var, typ, nam, msz) \ - struct hypfs_entry_leaf __read_mostly var =3D { \ - .e.type =3D (typ), \ - .e.encoding =3D XEN_HYPFS_ENC_PLAIN, \ - .e.name =3D (nam), \ - .e.max_size =3D (msz), \ - .e.funcs =3D &hypfs_leaf_ro_funcs, \ +#define HYPFS_DIR_INIT(var, nam) \ + HYPFS_DIR_INIT_FUNC(var, nam, &hypfs_dir_funcs) + +#define HYPFS_VARSIZE_INIT(var, typ, nam, msz, fn) \ + struct hypfs_entry_leaf __read_mostly var =3D { \ + .e.type =3D (typ), \ + .e.encoding =3D XEN_HYPFS_ENC_PLAIN, \ + .e.name =3D (nam), \ + .e.max_size =3D (msz), \ + .e.funcs =3D (fn), \ } =20 /* 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) =20 /* * Set content and size of a XEN_HYPFS_TYPE_STRING node. The node will poi= nt @@ -150,6 +153,8 @@ extern struct hypfs_entry_dir hypfs_root; =20 int hypfs_add_dir(struct hypfs_entry_dir *parent, struct hypfs_entry_dir *dir, bool nofault); +void hypfs_add_dyndir(struct hypfs_entry_dir *parent, + struct hypfs_entry_dir *template); int hypfs_add_leaf(struct hypfs_entry_dir *parent, struct hypfs_entry_leaf *leaf, bool nofault); const struct hypfs_entry *hypfs_node_enter(const struct hypfs_entry *entry= ); @@ -177,6 +182,10 @@ struct hypfs_entry *hypfs_leaf_findentry(const struct = hypfs_entry_dir *dir, struct hypfs_entry *hypfs_dir_findentry(const struct hypfs_entry_dir *dir, const char *name, unsigned int name_len); +void *hypfs_alloc_dyndata(unsigned long size); +#define hypfs_alloc_dyndata(type) ((type *)hypfs_alloc_dyndata(sizeof(type= ))) +void *hypfs_get_dyndata(void); +void hypfs_free_dyndata(void); #endif =20 #endif /* __XEN_HYPFS_H__ */ --=20 2.26.2