From patchwork Tue Apr 28 14:32:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 47675 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 83AFD2121F for ; Tue, 28 Apr 2015 14:35:35 +0000 (UTC) Received: by wizk4 with SMTP id k4sf6358599wiz.2 for ; Tue, 28 Apr 2015 07:35:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=ZnNKoT2v2PHAoY5HsljWCRcfRAz5Kw1YNl5W3llzylE=; b=NdPSJwrTSrg+ltEwck8hXSwg5eNFeOO/kNvgv8wXjeq1F2lINt3s3EKpq9m+YdXzLV ua8QtvaHO60BSRDVuPI4ZudoIsVhe3BcRhUPmrbg8t6aggfY53HwH8hCrh/GpXuyWbgf wz+S/tlwNcFoBchgvoMRQR++fYG4VsfO/OOpTMApq+3/80VfXyKqz0ULFWSHozG613LB cvNeAfa0iHWjmSSxwbBbdy4a0YPIIt4HehPj93TAUZQ7Xem1OMbQR0pEXBjFUjD6B3X0 QPmqj43/BwnqSaxJ7GRwSHK4Gk3Tl42kxAAryM5dapQmjCpaDZCAj0CqXh/8d4jz19Ry 3Dng== X-Gm-Message-State: ALoCoQmsvBKcpAcrHCA6TyUben/LHEhKvfNcNBomd3IFb/RrZlbkMR5jp0kkV2OD5Nl/vz7i6+3g X-Received: by 10.194.236.230 with SMTP id ux6mr10435819wjc.5.1430231734884; Tue, 28 Apr 2015 07:35:34 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.8.1 with SMTP id n1ls70816laa.87.gmail; Tue, 28 Apr 2015 07:35:34 -0700 (PDT) X-Received: by 10.152.23.163 with SMTP id n3mr15083779laf.34.1430231734577; Tue, 28 Apr 2015 07:35:34 -0700 (PDT) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id e4si14004977lab.140.2015.04.28.07.35.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Apr 2015 07:35:34 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by lbbzk7 with SMTP id zk7so108947018lbb.0 for ; Tue, 28 Apr 2015 07:35:34 -0700 (PDT) X-Received: by 10.112.219.70 with SMTP id pm6mr14541204lbc.41.1430231734439; Tue, 28 Apr 2015 07:35:34 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.67.65 with SMTP id l1csp1924480lbt; Tue, 28 Apr 2015 07:35:33 -0700 (PDT) X-Received: by 10.52.114.163 with SMTP id jh3mr16117579vdb.93.1430231730019; Tue, 28 Apr 2015 07:35:30 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id u1si23040858vdc.1.2015.04.28.07.35.29 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 28 Apr 2015 07:35:30 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Yn6Zm-0007lP-NJ; Tue, 28 Apr 2015 14:33:30 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Yn6Zl-0007kQ-6p for xen-devel@lists.xenproject.org; Tue, 28 Apr 2015 14:33:29 +0000 Received: from [85.158.139.211] by server-6.bemta-5.messagelabs.com id 52/C9-03284-83A9F355; Tue, 28 Apr 2015 14:33:28 +0000 X-Env-Sender: julien.grall@citrix.com X-Msg-Ref: server-16.tower-206.messagelabs.com!1430231604!8366589!3 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 6.13.14; banners=-,-,- X-VirusChecked: Checked Received: (qmail 21631 invoked from network); 28 Apr 2015 14:33:27 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-16.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 28 Apr 2015 14:33:27 -0000 X-IronPort-AV: E=Sophos;i="5.11,663,1422921600"; d="scan'208";a="257345543" From: Julien Grall To: Date: Tue, 28 Apr 2015 15:32:30 +0100 Message-ID: <1430231563-25648-7-git-send-email-julien.grall@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1430231563-25648-1-git-send-email-julien.grall@citrix.com> References: <1430231563-25648-1-git-send-email-julien.grall@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com Subject: [Xen-devel] [PATCH v6 06/19] xen/dts: Provide an helper to get a DT node from a path provided by a guest X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: patch@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: From: Julien Grall The maximum size of the copied string has been chosen based on the value use by XSM in similar case. Furthermore, Linux seems to allow path up to 4096 characters. Though this could vary from one OS to another. Signed-off-by: Julien Grall Acked-by: Ian Campbell --- Changes in v6: - Add Ian's ack Changes in v4: - Drop DEVICE_TREE_MAX_PATHLEN - Bump the value to PAGE_SIZE (i.e 4096). It's used in XSM and this value seems sensible for Linux - Clarify how the maximum size has been chosen Changes in v3: - Use the new prototype of safe_copy_string_from_guest Changes in v2: - guest_copy_string_from_guest has been renamed into safe_copy_string_from_guest --- xen/common/device_tree.c | 18 ++++++++++++++++++ xen/include/xen/device_tree.h | 14 ++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 02cae91..31f169b 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,7 @@ #include #include #include +#include const void *device_tree_flattened; dt_irq_xlate_func dt_irq_xlate; @@ -277,6 +279,22 @@ struct dt_device_node *dt_find_node_by_path(const char *path) return np; } +int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen, + struct dt_device_node **node) +{ + char *path; + + path = safe_copy_string_from_guest(u_path, u_plen, PAGE_SIZE); + if ( IS_ERR(path) ) + return PTR_ERR(path); + + *node = dt_find_node_by_path(path); + + xfree(path); + + return (*node == NULL) ? -ESRCH : 0; +} + struct dt_device_node *dt_find_node_by_alias(const char *alias) { const struct dt_alias_prop *app; diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 57eb3ee..e187780 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -456,6 +456,20 @@ struct dt_device_node *dt_find_node_by_alias(const char *alias); */ struct dt_device_node *dt_find_node_by_path(const char *path); + +/** + * dt_find_node_by_gpath - Same as dt_find_node_by_path but retrieve the + * path from the guest + * + * @u_path: Xen Guest handle to the buffer containing the path + * @u_plen: Length of the buffer + * @node: TODO + * + * Return 0 if succeed otherwise -errno + */ +int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen, + struct dt_device_node **node); + /** * dt_get_parent - Get a node's parent if any * @node: Node to get parent