From mboxrd@z Thu Jan 1 00:00:00 1970 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=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 25BD9C433E0 for ; Mon, 15 Feb 2021 09:27:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D2D4B64E6D for ; Mon, 15 Feb 2021 09:27:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230208AbhBOJ1k (ORCPT ); Mon, 15 Feb 2021 04:27:40 -0500 Received: from foss.arm.com ([217.140.110.172]:33848 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230191AbhBOJ1X (ORCPT ); Mon, 15 Feb 2021 04:27:23 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3410431B; Mon, 15 Feb 2021 01:26:37 -0800 (PST) Received: from [192.168.0.130] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B13EC3F40C; Mon, 15 Feb 2021 01:26:34 -0800 (PST) Subject: Re: [PATCH V3 11/14] coresight: sink: Add TRBE driver To: Mathieu Poirier Cc: linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, suzuki.poulose@arm.com, mike.leach@linaro.org, lcherian@marvell.com, linux-kernel@vger.kernel.org References: <1611737738-1493-1-git-send-email-anshuman.khandual@arm.com> <1611737738-1493-12-git-send-email-anshuman.khandual@arm.com> <20210211190024.GD2186000@xps15> <20210212165734.GA2692426@xps15> From: Anshuman Khandual Message-ID: Date: Mon, 15 Feb 2021 14:56:54 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210212165734.GA2692426@xps15> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/12/21 10:27 PM, Mathieu Poirier wrote: > [...] > >>> >>> >>>> + if (nr_pages < 2) >>>> + return NULL; >>>> + >>>> + buf = kzalloc_node(sizeof(*buf), GFP_KERNEL, trbe_alloc_node(event)); >>>> + if (IS_ERR(buf)) >>>> + return ERR_PTR(-ENOMEM); >>>> + >>>> + pglist = kcalloc(nr_pages, sizeof(*pglist), GFP_KERNEL); >>>> + if (IS_ERR(pglist)) { >>>> + kfree(buf); >>>> + return ERR_PTR(-ENOMEM); >>>> + } >>>> + >>>> + for (i = 0; i < nr_pages; i++) >>>> + pglist[i] = virt_to_page(pages[i]); >>>> + >>>> + buf->trbe_base = (unsigned long) vmap(pglist, nr_pages, VM_MAP, PAGE_KERNEL); >>>> + if (IS_ERR((void *)buf->trbe_base)) { >>> >>> Why not simply make buf->trbe_base a void * instead of having to do all this >> >> There are many arithmetic and comparison operations involving trbe_base >> element. Hence it might be better to keep it as unsigned long, also to >> keeps it consistent with other pointers i.e trbe_write, trbe_limit. > > That is a fair point. Please add a comment to explain your design choice and > make sure the sparse checker is happy with all of it. Added a comment. > >> >> Snippet from $cat drivers/hwtracing/coresight/coresight-trbe.c | grep "trbe_base" >> There are just two places type casting trbe_base back to (void *). >> >> memset((void *)buf->trbe_base + head, ETE_IGNORE_PACKET, len); >> return buf->trbe_base + offset; >> WARN_ON(buf->trbe_write < buf->trbe_base); >> set_trbe_base_pointer(buf->trbe_base); >> buf->trbe_base = (unsigned long)vmap(pglist, nr_pages, VM_MAP, PAGE_KERNEL); >> if (IS_ERR((void *)buf->trbe_base)) { >> return ERR_PTR(buf->trbe_base); >> buf->trbe_limit = buf->trbe_base + nr_pages * PAGE_SIZE; >> buf->trbe_write = buf->trbe_base; >> vunmap((void *)buf->trbe_base); >> base = get_trbe_base_pointer(); >> buf->trbe_write = buf->trbe_base + PERF_IDX2OFF(handle->head, buf); >> if (buf->trbe_limit == buf->trbe_base) { >> buf->trbe_write = buf->trbe_base + PERF_IDX2OFF(handle->head, buf); >> if (buf->trbe_limit == buf->trbe_base) { >> offset = get_trbe_limit_pointer() - get_trbe_base_pointer(); >> buf->trbe_write = buf->trbe_base + PERF_IDX2OFF(handle->head, buf); >> if (buf->trbe_limit == buf->trbe_base) { >> WARN_ON(buf->trbe_base != get_trbe_base_pointer()); >> if (get_trbe_write_pointer() == get_trbe_base_pointer()) >> >>> casting? And IS_ERR() doesn't work with vmap(). >> >> Sure, will drop IS_ERR() here. >> > > [...] > > >>> >>>> + >>>> +static ssize_t dbm_show(struct device *dev, struct device_attribute *attr, char *buf) >>>> +{ >>>> + struct trbe_cpudata *cpudata = dev_get_drvdata(dev); >>>> + >>>> + return sprintf(buf, "%d\n", cpudata->trbe_dbm); >>>> +} >>>> +static DEVICE_ATTR_RO(dbm); >>> >>> What does "dbm" stand for? Looking at the documentation for TRBIDR_EL1.F, I >>> don't see what "dbm" relates to. >> >> I made it up to refer TRBIDR_EL1.F as "Dirty (and Access Flag) Bit Management". >> Could change it as "afdbm" to be more specific or if it is preferred. >> > > I don't see "afdbm" being a better solution - why not simply "flag"? Replaced all reference for "dbm" with "flag". From mboxrd@z Thu Jan 1 00:00:00 1970 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=-5.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 D88A2C433E6 for ; Mon, 15 Feb 2021 09:27:45 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 4132364E05 for ; Mon, 15 Feb 2021 09:27:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4132364E05 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ePtJJU0KpRDedVH9SFoHkI0cqUopSzBDPyl20ibm1v8=; b=LYhCkjmj3IkYKKa+6ic3wjfYp BCYcJdi2SviHbZKBNXxcWYct7xvUmwb/M5CKFbkBm+9i3Jmdb1bl01MsaPoE2w3sDgAtjMyQPCrHA r6oqbQMv7WhleyY5cju195mY4R+a0W1hLyH/WBzE8ZVrnua6cC231s3+QOoKhP/eBFTKOgdmGwPe4 9KcBAD/JygF7i6vMzzFwmthEUnFMvwPfY0/8BTM30Zvo0MUhJoc0THWb8w8PhVqjONzjBlN1Woye7 /OegRcmDLRfiD5iQfZnPJ8k4amxYpFblgsa8abZzK45lZvYk3rdWA4cN9vRPNjW4HBT+odvc30Q5z xb8vYeVTQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lBa9R-00085n-02; Mon, 15 Feb 2021 09:26:41 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lBa9O-000851-8I for linux-arm-kernel@lists.infradead.org; Mon, 15 Feb 2021 09:26:39 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3410431B; Mon, 15 Feb 2021 01:26:37 -0800 (PST) Received: from [192.168.0.130] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B13EC3F40C; Mon, 15 Feb 2021 01:26:34 -0800 (PST) Subject: Re: [PATCH V3 11/14] coresight: sink: Add TRBE driver To: Mathieu Poirier References: <1611737738-1493-1-git-send-email-anshuman.khandual@arm.com> <1611737738-1493-12-git-send-email-anshuman.khandual@arm.com> <20210211190024.GD2186000@xps15> <20210212165734.GA2692426@xps15> From: Anshuman Khandual Message-ID: Date: Mon, 15 Feb 2021 14:56:54 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210212165734.GA2692426@xps15> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210215_042638_435633_3A6F78AD X-CRM114-Status: GOOD ( 18.51 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, coresight@lists.linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, lcherian@marvell.com, mike.leach@linaro.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2/12/21 10:27 PM, Mathieu Poirier wrote: > [...] > >>> >>> >>>> + if (nr_pages < 2) >>>> + return NULL; >>>> + >>>> + buf = kzalloc_node(sizeof(*buf), GFP_KERNEL, trbe_alloc_node(event)); >>>> + if (IS_ERR(buf)) >>>> + return ERR_PTR(-ENOMEM); >>>> + >>>> + pglist = kcalloc(nr_pages, sizeof(*pglist), GFP_KERNEL); >>>> + if (IS_ERR(pglist)) { >>>> + kfree(buf); >>>> + return ERR_PTR(-ENOMEM); >>>> + } >>>> + >>>> + for (i = 0; i < nr_pages; i++) >>>> + pglist[i] = virt_to_page(pages[i]); >>>> + >>>> + buf->trbe_base = (unsigned long) vmap(pglist, nr_pages, VM_MAP, PAGE_KERNEL); >>>> + if (IS_ERR((void *)buf->trbe_base)) { >>> >>> Why not simply make buf->trbe_base a void * instead of having to do all this >> >> There are many arithmetic and comparison operations involving trbe_base >> element. Hence it might be better to keep it as unsigned long, also to >> keeps it consistent with other pointers i.e trbe_write, trbe_limit. > > That is a fair point. Please add a comment to explain your design choice and > make sure the sparse checker is happy with all of it. Added a comment. > >> >> Snippet from $cat drivers/hwtracing/coresight/coresight-trbe.c | grep "trbe_base" >> There are just two places type casting trbe_base back to (void *). >> >> memset((void *)buf->trbe_base + head, ETE_IGNORE_PACKET, len); >> return buf->trbe_base + offset; >> WARN_ON(buf->trbe_write < buf->trbe_base); >> set_trbe_base_pointer(buf->trbe_base); >> buf->trbe_base = (unsigned long)vmap(pglist, nr_pages, VM_MAP, PAGE_KERNEL); >> if (IS_ERR((void *)buf->trbe_base)) { >> return ERR_PTR(buf->trbe_base); >> buf->trbe_limit = buf->trbe_base + nr_pages * PAGE_SIZE; >> buf->trbe_write = buf->trbe_base; >> vunmap((void *)buf->trbe_base); >> base = get_trbe_base_pointer(); >> buf->trbe_write = buf->trbe_base + PERF_IDX2OFF(handle->head, buf); >> if (buf->trbe_limit == buf->trbe_base) { >> buf->trbe_write = buf->trbe_base + PERF_IDX2OFF(handle->head, buf); >> if (buf->trbe_limit == buf->trbe_base) { >> offset = get_trbe_limit_pointer() - get_trbe_base_pointer(); >> buf->trbe_write = buf->trbe_base + PERF_IDX2OFF(handle->head, buf); >> if (buf->trbe_limit == buf->trbe_base) { >> WARN_ON(buf->trbe_base != get_trbe_base_pointer()); >> if (get_trbe_write_pointer() == get_trbe_base_pointer()) >> >>> casting? And IS_ERR() doesn't work with vmap(). >> >> Sure, will drop IS_ERR() here. >> > > [...] > > >>> >>>> + >>>> +static ssize_t dbm_show(struct device *dev, struct device_attribute *attr, char *buf) >>>> +{ >>>> + struct trbe_cpudata *cpudata = dev_get_drvdata(dev); >>>> + >>>> + return sprintf(buf, "%d\n", cpudata->trbe_dbm); >>>> +} >>>> +static DEVICE_ATTR_RO(dbm); >>> >>> What does "dbm" stand for? Looking at the documentation for TRBIDR_EL1.F, I >>> don't see what "dbm" relates to. >> >> I made it up to refer TRBIDR_EL1.F as "Dirty (and Access Flag) Bit Management". >> Could change it as "afdbm" to be more specific or if it is preferred. >> > > I don't see "afdbm" being a better solution - why not simply "flag"? Replaced all reference for "dbm" with "flag". _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel