Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp464368rwb; Sat, 17 Sep 2022 08:19:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6v7ssvnhawOfqGrUBKTxGqLgA4RyaOZv5Yarn9Pl8nCJJUEgve4qrDZ2WX24zKe4lhyoDS X-Received: by 2002:a17:90b:4d82:b0:202:9030:e482 with SMTP id oj2-20020a17090b4d8200b002029030e482mr22365961pjb.110.1663427942332; Sat, 17 Sep 2022 08:19:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663427942; cv=none; d=google.com; s=arc-20160816; b=iaHlJrz5XPMy+Kbs+mA0h25VBvfdCstDihjkxF9lD7jTJWMyj8r+vr30NLmCBFNUO1 bV4KhBo0IiIRDvrZysqTQm7Yw2MAJVrI/AflQzY/Piw5AqYiM98ED2E0rbDSO94id2AA OK1Z/0s2zYx+QtcADpDsHBGt6PjGeBjxHq/LtSUDV6K6sN2wWYd7GhrdtZjUm5Lh1jvQ fKrMQqwjZacWm3ypzVSImNTDAIPwwhVmQmciuyhA2Eu2qLRSrqwYVPEsj35HTtT4ja5f +oduZE3ad5t7lRhwyPdZmW7k3zi2PVV+29PTO9PsQClCo9PwLvQEEjJNJXmHCA6IgqLN hyfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:dlp-filter:cms-type :content-transfer-encoding:mime-version:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature:dkim-filter; bh=BsAauzcqvNNVeqImcp9I3CG4uOfDsEQD2S4eOyim4BQ=; b=PcbNcrLrFVaToVc4sBW94ZgBDQsRgPk04Dwx+xI9U9S36ToCk4xvAVT8QKxCUEMy87 cnFy6EpQtZ1BSpm0s/KGznvGY0NcQDwasGFk0UPcbXe8b8zmRDK3mJPkIpF93ChDJEhM 4q5jx+3C5u1foLaVbi0EXSk6C1bSboTsTb4Ma3bsA9/1ERKJv/UWIYxDMbJLh2qtVoWy 5C/6eOCHp+DrO3edeBKwbzY9T4Jgqj4geaXhX94Mv3liUHm6Zaq2PlN12FtL6XBTrHgD KPLi0FghzlqNhtGjMu+yRyKNudoIDncuffjQjwsQdLGyXPnY2kadBYEh1r7WVL9wlLoP WmIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="O7/9ZDyt"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c32-20020a631c60000000b0042b29871d82si25019615pgm.220.2022.09.17.08.18.49; Sat, 17 Sep 2022 08:19:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="O7/9ZDyt"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229733AbiIQOtf (ORCPT + 99 others); Sat, 17 Sep 2022 10:49:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbiIQOtd (ORCPT ); Sat, 17 Sep 2022 10:49:33 -0400 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 395FC30E for ; Sat, 17 Sep 2022 07:49:28 -0700 (PDT) Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20220917144922epoutp02fcbac7f37ca91ac2cee8322d4a3bc339~VrUgeJ50U3103331033epoutp02T for ; Sat, 17 Sep 2022 14:49:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20220917144922epoutp02fcbac7f37ca91ac2cee8322d4a3bc339~VrUgeJ50U3103331033epoutp02T DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1663426162; bh=BsAauzcqvNNVeqImcp9I3CG4uOfDsEQD2S4eOyim4BQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=O7/9ZDytDgosXjDKGYAWTTgEkKeuU7fGF8soGZEMhSEq4GYl4txopQ+oOAJ55RmVU vDgGvG84Wdkwvd+TvwV5Vmn75Vz+XAPd/10AgazDokB3v3xGM+DAcSdS3HD49qJkK5 ZJcwJscwruUhAR2v2+Sq9XbU3uQhPjrA0/+a9vrk= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20220917144921epcas1p4da9b0db30621e65d657d4c9205a79a46~VrUfR6pTy1395813958epcas1p4U; Sat, 17 Sep 2022 14:49:21 +0000 (GMT) Received: from epsmges1p1.samsung.com (unknown [182.195.38.233]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4MVDNc2Krmz4x9Pr; Sat, 17 Sep 2022 14:49:20 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id 84.59.07146.07ED5236; Sat, 17 Sep 2022 23:49:20 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220917144919epcas1p25842370f2680f6b5fcbb25d28e41ba53~VrUdZRMkL1016310163epcas1p2E; Sat, 17 Sep 2022 14:49:19 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220917144919epsmtrp27e1b0612c8ccf9d4dfdaf111a81d5cf9~VrUdVsPLg1715917159epsmtrp2G; Sat, 17 Sep 2022 14:49:19 +0000 (GMT) X-AuditID: b6c32a35-47bfe70000021bea-4c-6325de70ca7d Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 90.A3.14392.F6ED5236; Sat, 17 Sep 2022 23:49:19 +0900 (KST) Received: from jiho-chu04.tn.corp.samsungelectronics.net (unknown [10.113.112.236]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220917144919epsmtip2cc5a9dfc4b7ddcdfb553cbf69bb72b33~VrUdJOuPV0643506435epsmtip2h; Sat, 17 Sep 2022 14:49:19 +0000 (GMT) Date: Sat, 17 Sep 2022 23:49:18 +0900 From: Jiho Chu To: "Arnd Bergmann" Cc: "Greg Kroah-Hartman" , ogabbay@kernel.org, "Krzysztof Kozlowski" , "Mark Brown" , linux-kernel@vger.kernel.org, yelini.jeong@samsung.com, myungjoo.ham@samsung.com Subject: Re: [PATCH v2 01/13] trinity: Add base driver Message-Id: <20220917234918.8b94d2690b8533bd47cf64e0@samsung.com> In-Reply-To: X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprAJsWRmVeSWpSXmKPExsWy7bCmgW7BPdVkg5vnuS3+TjrGbjH14RM2 i+bF69ks9r7eym5xedccNovbjSvYLPb1fGS0eD7tOosDh8fvX5MYPTat6mTzuHNtD5vH/rlr 2D36tqxi9Pi8SS6ALSrbJiM1MSW1SCE1Lzk/JTMv3VbJOzjeOd7UzMBQ19DSwlxJIS8xN9VW ycUnQNctMwfoICWFssScUqBQQGJxsZK+nU1RfmlJqkJGfnGJrVJqQUpOgWmBXnFibnFp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bF69ks9r7eym5xedccNovbjSvYLPb1fGS0eD7tOosDh8fvX5MYPTat6mTzuHNtD5vH/rlr 2D36tqxi9Pi8SS6ALYrLJiU1J7MstUjfLoErY/WLD2wF29UqZt7rY29g7JbrYuTkkBAwkTi2 YSNzFyMXh5DAbkaJa3dvMkEkJCQ23VsOlOAAsoUlDh8uBgkLCbQxSWxerA5iswioSjx52cwG YrMB2TNnrGEHsUUElCV+/ZjECjKTWeAPo8T7jqdgM4UFzCQmTJ0JVsQr4Cix7X0bM4jNKeAi 8fXLPVaIBb8ZJa7u14G4wULibs8KVpAbeAUEJf7uEAYJMwtoSTz8dYsFwpaX2P52DvMERsFZ CFWzkFTNQlK1gJF5FaNkakFxbnpusWGBYV5quV5xYm5xaV66XnJ+7iZGcFRoae5g3L7qg94h RiYOxkOMEhzMSiK8qp4qyUK8KYmVValF+fFFpTmpxYcYpTlYlMR5L3SdjBcSSE8sSc1OTS1I LYLJMnFwSjUwbfwXdG4ezwS5Vdf10q3ldOPZVNKTcgs3NJ2tTWSvUz7a3S/t/nGBjNyym6rM KZzJx67Onu8ibMbyfKHpmxVPnLN/tdy6I7ZyTS9XLsfMldv2BC5d015qMre6c5Fokekp44TA sizW7ZzuKmy31Bd+4ijmPGuwOGDWKe5bH/OX5m1aUnXcRbRwwY7Al86HsmwOnjFJb3jFKLzX JlEl2NBG4IiAx/t/l8Smv9mr2nosOn7Kh/0b+45xP/qwbo311tVSK6YVzkuWimaanpS08q1C zh4f1iW1D/+dblm76ngbz55Jk9bk61tFfF61/R6fptDrrXeS3sZL8vFmCJeZd0U4+lUz2e+S 9iifYxV1/cIaJZbijERDLeai4kQA8xPLmvkCAAA= X-CMS-MailID: 20220917144919epcas1p25842370f2680f6b5fcbb25d28e41ba53 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220917072357epcas1p17b277154f0d020435417450fa0337906 References: <20220917072356.2255620-1-jiho.chu@samsung.com> <20220917072356.2255620-2-jiho.chu@samsung.com> X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 17 Sep 2022 09:41:13 +0200 "Arnd Bergmann" wrote: > On Sat, Sep 17, 2022, at 9:23 AM, Jiho Chu wrote: > > It contains the base codes for trinity driver. Minimal codes to load and > > probe device is provided. The Trinity Family is controlled by the > > Memory-Mapped Registers, the register addresses and offsets are > > described. And user api interfaces are presented to control device under > > ioctl manner. > > I'm not doing a full review of the driver at the moment, but > here are some comments on the usage of chardev ioctl based on > Documentation/driver-api/ioctl.rst > Hi, Arnd Thanks for your review. I'll read the document more precisely. > > +int trinity_probe(struct platform_device *pdev, const struct > > trinity_desc *desc) > > +{ > > + struct device_node *np; > > + struct device *dev; > > + struct trinity_driver *drv; > > + int i, err; > > + > > + dev = &pdev->dev; > > + dev->id = ((desc->ver & TRINITY_MASK_DEV) >> TRINITY_SHIFT_DEV); > > + > > + /* set private data */ > > + drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); > > + if (!drv) > > + return -ENOMEM; > > + > > + drv->dev_id = ida_alloc(&dev_nrs, GFP_KERNEL); > > + if (drv->dev_id < 0) { > > + devm_kfree(dev, drv); > > + return drv->dev_id; > > + } > > + snprintf(drv->name, DEV_NAME_LEN, "%s-%u", desc->type, drv->dev_id); > > + > > + platform_set_drvdata(pdev, drv); > > + dev_set_drvdata(dev, drv); > > + > > If you have the need to manage multiple devices here, maybe use > a dynamic major number and have the chardev code allocate the > minor numbers, instead of using multiple misc devices and > doing that yourself. > I'm little confusing. It means that managing own char devices is proper, not using misc device? But, it's still under misc dir. > > + > > +#ifndef TASK_COMM_LEN > > +#define TASK_COMM_LEN 16 > > +#endif > > + > > +#define TRINITY_APP_NAME_MAX TASK_COMM_LEN > > +#define TRINITY_APP_STAT_MAX 10 > > +#define TRINITY_REQ_STAT_MAX 10 > > The structure layout should not depend on whether an application > has included a header that defines TASK_COMM_LEN. > > What is the purpose of including an application name here? > > > +/** > > + * struct trinity_ioctl_stat_app - Describes stat of the target app > > + * @app_id: Trinity app id (currently, equal to pid) > > + * @name: Trinity app name > > + * @status: Trinity app status > > + * @num_total_reqs: Number of total requests in app (including > > finished ones) > > + * @num_active_reqs: Number of active (running or pending) requests in > > app > > + * @total_alloc_mem: Total size of allocated memory in the device > > + * @total_freed_mem: Total size of freed memory in the device > > + */ > > +struct trinity_ioctl_stat_app { > > + __s32 app_id; > > + > > + char name[TRINITY_APP_NAME_MAX]; > > + enum trinity_app_status status; > > + > > + __u32 num_total_reqs; > > + __u32 num_active_reqs; > > + > > + __u64 total_alloc_mem; > > + __u64 total_freed_mem; > > +} __packed; > > 'enum' in a uapi structure is not well-defined across > architectures, so better use a fixed-size type there. > > Instead of packing the structure, you should keep all > members naturally aligned and add explicit padding > or change some members for 32-bit to 64-bit size > to keep everything naturally aligned. > I checked, the members will be aligned. > > +/** > > + * struct trinity_ioctl_profile_buff - Describes profiling buff info. > > + * @req_id: The target req id for profiling > > + * @profile_pos: The start position to extract profiling data > > + * @profile_size: The size of user-allocated profiling buffer > > + * @profile_buf: The profiling buffer which user allocated > > + */ > > +struct trinity_ioctl_profile_buff { > > + __s32 req_id; > > + __u32 profile_pos; > > + __u32 profile_size; > > + void __user *profile_buf; > > +} __packed; > > Don't put pointers into ioctl structures, they just make compat > mode unnecessarily hard. You can use a __u64 member. > OK. thanks. > > +/** > > + * Major number can not be dynamic as ioctls need it, > > + */ > > +#define TRINITY_DRIVER_MAGIC 0x88 > > + > > +#define TRINITY_IO(no) _IO(TRINITY_DRIVER_MAGIC, no) > > +#define TRINITY_IOR(no, data_type) _IOR(TRINITY_DRIVER_MAGIC, no, > > data_type) > > +#define TRINITY_IOW(no, data_type) _IOW(TRINITY_DRIVER_MAGIC, no, > > data_type) > > +#define TRINITY_IOWR(no, data_type) _IOWR(TRINITY_DRIVER_MAGIC, no, > > data_type) > > These macros just hurt tools that want to parse the headers. > Please just open-code the usage. > > > +#ifdef __KERNEL__ > > +__s32 trinity_run_internal_req(dev_t); > > +#endif > > This doesn't seem to belong into the uapi header. > > Arnd > macros and useless codes will be cleared. Thanks. Jiho Chu