Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8872C433FE for ; Wed, 9 Dec 2020 16:16:39 +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 9851223BDF for ; Wed, 9 Dec 2020 16:16:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9851223BDF Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine 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.48484.85763 (Exim 4.92) (envelope-from ) id 1kn28j-0004Um-5r; Wed, 09 Dec 2020 16:16:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 48484.85763; Wed, 09 Dec 2020 16:16:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kn28j-0004Ue-1i; Wed, 09 Dec 2020 16:16:29 +0000 Received: by outflank-mailman (input) for mailman id 48484; Wed, 09 Dec 2020 16:16:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kn28h-0004SF-1r for xen-devel@lists.xenproject.org; Wed, 09 Dec 2020 16:16:27 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7e50217e-569d-4108-be58-42ac93a182cc; Wed, 09 Dec 2020 16:16:21 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B4591ADAA; Wed, 9 Dec 2020 16:16:20 +0000 (UTC) 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: 7e50217e-569d-4108-be58-42ac93a182cc 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=1607530580; 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=b+/TxrF4qJUX0wGGTUMyByEWIjy0WZY4LBlGieHkPRc=; b=jCp82V2QdeP4AHedfgWNEX4ayd24waSekvuv7niZe9ARvaGxoizwmB79CEDgcSySxGJu4H U+ePcxt0UxSvKq2vKr1u3xy6b7L4QN61f12K0uVv7+tq3a2gnT56NXko65QyoE4WBNgdOg ugTHHXmSBDCbg1ppbWxjOP4ipVg14DQ= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: paul@xen.org, Juergen Gross , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH RFC 1/3] xen/hypfs: add support for bool leafs in dynamic directories Date: Wed, 9 Dec 2020 17:16:16 +0100 Message-Id: <20201209161618.309-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201209161618.309-1-jgross@suse.com> References: <20201209161618.309-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add support for reading fixed sized leafs and writing bool leafs in dynamic directories with the backing variable being a member of the structure anchored in struct hypfs_dyndir->data. This adds the related leaf read and write functions and a helper macro HYPFS_STRUCT_ELEM() for referencing the element. Signed-off-by: Juergen Gross --- xen/common/hypfs.c | 53 +++++++++++++++++++++++++++++++++++------ xen/include/xen/hypfs.h | 7 ++++++ 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/xen/common/hypfs.c b/xen/common/hypfs.c index 087c63b92f..caee48cc97 100644 --- a/xen/common/hypfs.c +++ b/xen/common/hypfs.c @@ -501,17 +501,26 @@ int hypfs_read_dir(const struct hypfs_entry *entry, return 0; } -int hypfs_read_leaf(const struct hypfs_entry *entry, - XEN_GUEST_HANDLE_PARAM(void) uaddr) +static int hypfs_read_leaf_off(const struct hypfs_entry *entry, + XEN_GUEST_HANDLE_PARAM(void) uaddr, + void *off) { const struct hypfs_entry_leaf *l; unsigned int size = entry->funcs->getsize(entry); + const void *ptr; ASSERT(this_cpu(hypfs_locked) != hypfs_unlocked); l = container_of(entry, const struct hypfs_entry_leaf, e); + ptr = off ? off + (unsigned long)l->u.content : l->u.content; + + return copy_to_guest(uaddr, ptr, size) ? -EFAULT : 0; +} - return copy_to_guest(uaddr, l->u.content, size) ? -EFAULT : 0; +int hypfs_read_leaf(const struct hypfs_entry *entry, + XEN_GUEST_HANDLE_PARAM(void) uaddr) +{ + return hypfs_read_leaf_off(entry, uaddr, NULL); } static int hypfs_read(const struct hypfs_entry *entry, @@ -587,11 +596,12 @@ int hypfs_write_leaf(struct hypfs_entry_leaf *leaf, return ret; } -int hypfs_write_bool(struct hypfs_entry_leaf *leaf, - XEN_GUEST_HANDLE_PARAM(const_void) uaddr, - unsigned int ulen) +static int hypfs_write_bool_off(struct hypfs_entry_leaf *leaf, + XEN_GUEST_HANDLE_PARAM(const_void) uaddr, + unsigned int ulen, void *off) { bool buf; + bool *ptr; ASSERT(this_cpu(hypfs_locked) == hypfs_write_locked); ASSERT(leaf->e.type == XEN_HYPFS_TYPE_BOOL && @@ -604,11 +614,19 @@ int hypfs_write_bool(struct hypfs_entry_leaf *leaf, if ( copy_from_guest(&buf, uaddr, ulen) ) return -EFAULT; - *(bool *)leaf->u.write_ptr = buf; + ptr = off ? off + (unsigned long)leaf->u.write_ptr : leaf->u.write_ptr; + *ptr = buf; return 0; } +int hypfs_write_bool(struct hypfs_entry_leaf *leaf, + XEN_GUEST_HANDLE_PARAM(const_void) uaddr, + unsigned int ulen) +{ + return hypfs_write_bool_off(leaf, uaddr, ulen, NULL); +} + int hypfs_write_custom(struct hypfs_entry_leaf *leaf, XEN_GUEST_HANDLE_PARAM(const_void) uaddr, unsigned int ulen) @@ -644,6 +662,27 @@ int hypfs_write_custom(struct hypfs_entry_leaf *leaf, return ret; } +int hypfs_dyndir_id_read_leaf(const struct hypfs_entry *entry, + XEN_GUEST_HANDLE_PARAM(void) uaddr) +{ + struct hypfs_dyndir_id *dyndata; + + dyndata = hypfs_get_dyndata(); + + return hypfs_read_leaf_off(entry, uaddr, dyndata->data); +} + +int hypfs_dyndir_id_write_bool(struct hypfs_entry_leaf *leaf, + XEN_GUEST_HANDLE_PARAM(const_void) uaddr, + unsigned int ulen) +{ + struct hypfs_dyndir_id *dyndata; + + dyndata = hypfs_get_dyndata(); + + return hypfs_write_bool_off(leaf, uaddr, ulen, dyndata->data); +} + int hypfs_write_deny(struct hypfs_entry_leaf *leaf, XEN_GUEST_HANDLE_PARAM(const_void) uaddr, unsigned int ulen) diff --git a/xen/include/xen/hypfs.h b/xen/include/xen/hypfs.h index 34073faff8..670dc68b48 100644 --- a/xen/include/xen/hypfs.h +++ b/xen/include/xen/hypfs.h @@ -160,6 +160,8 @@ static inline void hypfs_string_set_reference(struct hypfs_entry_leaf *leaf, HYPFS_FIXEDSIZE_INIT(var, XEN_HYPFS_TYPE_BOOL, nam, contvar, \ &hypfs_bool_wr_funcs, 1) +#define HYPFS_STRUCT_ELEM(type, elem) (((type *)NULL)->elem) + extern struct hypfs_entry_dir hypfs_root; int hypfs_add_dir(struct hypfs_entry_dir *parent, @@ -204,6 +206,11 @@ struct hypfs_entry *hypfs_gen_dyndir_id_entry( const struct hypfs_entry_dir *template, unsigned int id, void *data); unsigned int hypfs_dynid_entry_size(const struct hypfs_entry *template, unsigned int id); +int hypfs_dyndir_id_read_leaf(const struct hypfs_entry *entry, + XEN_GUEST_HANDLE_PARAM(void) uaddr); +int hypfs_dyndir_id_write_bool(struct hypfs_entry_leaf *leaf, + XEN_GUEST_HANDLE_PARAM(const_void) uaddr, + unsigned int ulen); #endif #endif /* __XEN_HYPFS_H__ */ -- 2.26.2