Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp8836872rwl; Sat, 31 Dec 2022 13:04:10 -0800 (PST) X-Google-Smtp-Source: AMrXdXtVyZluC9nglSv03//p2NYRHuyO9HxnT4zOkq8LV6H05Hj0D1xW6g4GlEn9XwuDskfYzgBE X-Received: by 2002:a17:907:86aa:b0:7c0:aea2:e910 with SMTP id qa42-20020a17090786aa00b007c0aea2e910mr51367534ejc.3.1672520650382; Sat, 31 Dec 2022 13:04:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672520650; cv=none; d=google.com; s=arc-20160816; b=C/K2uFJL4vFVpszVIpwS2Tdf7T46pjVxWkLdV09XDSkzpDBYp9wef1mVxakAJuAzPF S5R306MIMW9yddvg+MhaiiOTJDEyGf+OtAy8dzwHFYRzAw35sHrFBaR1rZfhG/gleZgO 8RVxQussQNJpzXMUDc7NKzs6LLjyguay4K6Lv6v362EDqe5bBuzvBuN5ueZRWhQHDlpb GYQgLsvXRpruv1ODdPfVNm+9I4lJoYIwKPJ/XZDLSHMb9/Fd34F2d6HiPPKzMo6lZLSH /13il+xX16whpUGO4mjzeeVzmXyg+KhbWXs8Ru6CiOdRgbplrPMH7X92HKwTRwLkX+cV Y24Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=Vb6Q16JYTSwPesxYgul3SiK46hUJhipTxII72ojdhT4=; b=rqnVyYVIlyDAFM9bzLNdZjm4lPDoL6WUM1MURFepsp5Mixirf91GA2VOA0KWvp7eGZ Liu35RmTVxGho/q6bAOYIFq/RUO8bp7yobS9fSNLUsOAW1BokBTPEyDeBYe67SehVdJG rBmEyRxNmA3npkLJpaKztw8vMa/zu8ZJfHkqHyS8xS0WfomNg+B8fAvDwkgJ/uVh0G0h G62v2tMZBB9KonGH8Lkn5sCpPgTjPILyWuflb8h9yHHE4OEPdGdI72r3MU0peEotCuso 5ANqN3nE8eEfFOseKZPUU82FeH3Z8dckhe0C3go7UaXpxfzB8Fvbnlw9+F13ZjCkzkhi KFAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RgcvfVsd; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nd5-20020a170907628500b0084c85491fabsi9038390ejc.207.2022.12.31.13.03.34; Sat, 31 Dec 2022 13:04:10 -0800 (PST) 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=@intel.com header.s=Intel header.b=RgcvfVsd; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235865AbiLaUqO (ORCPT + 61 others); Sat, 31 Dec 2022 15:46:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229597AbiLaUqM (ORCPT ); Sat, 31 Dec 2022 15:46:12 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C2C9E17; Sat, 31 Dec 2022 12:46:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672519570; x=1704055570; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=u54kgTpFKIhoKkny3N85NEinVLOBvPtOhm1ruzzmbI8=; b=RgcvfVsdOez3eQS3yhuWGfp8H1XDb9ClPRs4wn9RDYws8Oxm34W+0e1Y Muw3n2oGm8uNmkbmPdE71yipHIDQlQYQ4HrQLSTiXCruAVsqYeseQrIx4 3NNXMKkkmlMH7dxxUCD4PV0eA7lxTCJVwfHYa/vhZZ4Lai55nzFoj1Hig kGBE6ZpDblJqkoK1a62Vlv0qBisdflErTikuXwZ3rAVJPTrQiXjvjCgLg Ulyr10v1pJgqQcgg4Mli1XH8znhn5RaF549nlG9oKxmuT/4+hRzwjbfPi lgb3fPq1cvdDxmJMrzQQbNHgkxxhzRD75dHkLhyqJyxBInqvXhnBorEvj g==; X-IronPort-AV: E=McAfee;i="6500,9779,10577"; a="407595726" X-IronPort-AV: E=Sophos;i="5.96,290,1665471600"; d="scan'208";a="407595726" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Dec 2022 12:46:09 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10577"; a="982932839" X-IronPort-AV: E=Sophos;i="5.96,290,1665471600"; d="scan'208";a="982932839" Received: from rhweight-wrk1.ra.intel.com ([137.102.106.139]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Dec 2022 12:46:08 -0800 Date: Sat, 31 Dec 2022 12:46:28 -0800 (PST) From: matthew.gerlach@linux.intel.com X-X-Sender: mgerlach@rhweight-WRK1 To: Xu Yilun cc: Andy Shevchenko , hao.wu@intel.com, russell.h.weight@intel.com, basheer.ahmed.muddebihal@intel.com, trix@redhat.com, mdf@kernel.org, linux-fpga@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, tianfei.zhang@intel.com, corbet@lwn.net, gregkh@linuxfoundation.org, linux-serial@vger.kernel.org, jirislaby@kernel.org, geert+renesas@glider.be, niklas.soderlund+renesas@ragnatech.se, macro@orcam.me.uk, johan@kernel.org, lukas@wunner.de, ilpo.jarvinen@linux.intel.com, marpagan@redhat.com, bagasdotme@gmail.com Subject: Re: [PATCH v7 3/4] fpga: dfl: add basic support for DFHv1 In-Reply-To: Message-ID: References: <20221220163652.499831-1-matthew.gerlach@linux.intel.com> <20221220163652.499831-4-matthew.gerlach@linux.intel.com> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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 Mon, 26 Dec 2022, Xu Yilun wrote: > On 2022-12-21 at 11:14:59 -0800, matthew.gerlach@linux.intel.com wrote: >> >> >> On Tue, 20 Dec 2022, Andy Shevchenko wrote: >> >>> On Tue, Dec 20, 2022 at 08:36:51AM -0800, matthew.gerlach@linux.intel.com wrote: >>>> From: Matthew Gerlach >>>> >>>> Version 1 of the Device Feature Header (DFH) definition adds >>>> functionality to the DFL bus. >>>> >>>> A DFHv1 header may have one or more parameter blocks that >>>> further describes the HW to SW. Add support to the DFL bus >>>> to parse the MSI-X parameter. >>>> >>>> The location of a feature's register set is explicitly >>>> described in DFHv1 and can be relative to the base of the DFHv1 >>>> or an absolute address. Parse the location and pass the information >>>> to DFL driver. >>> >>> ... >>> >>>> +/** >>>> + * dfh_find_param() - find data for the given parameter id >>>> + * @dfl_dev: dfl device >>>> + * @param: id of dfl parameter >>>> + * >>>> + * Return: pointer to parameter header on success, NULL otherwise. >>> >>> header is a bit confusing here, does it mean we give and ID and we got >>> something more than just a data as summary above suggests? >> >> Yes, the summary is not correct. It should say "find the parameter block >> for the given parameter id". >> >>> >>> In such case summary and this text should clarify what exactly we get >>> and layout of the data. Since this is a pointer, who is responsible of >>> checking out-of-boundary accesses? For instance, if the parameters are >>> variadic by length the length should be returned as well. Otherwise it >>> should be specified as a constant somewhere, right? >> >> The parameter header has the next/size field; so the caller of >> dfh_find_param should perform boundary checking as part of interpreting the >> parameter data. I think a function to perform this checking and data >> interpretation would help here. > > It is better the DFL core provides the size of the parameter block, just > in this API. It provides the pointer and should be ensured the memory > for the pointer be correctly understood. Ok, how about the following API for dfh_find_param? /** * dfh_find_param() - find parameter block for the given parameter id * @dfl_dev: dfl device * @param_id: id of dfl parameter * @pver: destination to store parameter version * @pcount: destination to store size of parameter data in u64 bit words * * Return: pointer to start of parameter data, PTR_ERR otherwise. */ void *dfh_find_param(struct dfl_device *dfl_dev, int param_id, unsigned *pver, unsigned *pcount) > >> >>> >>>> + */ >>>> +u64 *dfh_find_param(struct dfl_device *dfl_dev, int param_id) >>>> +{ >>>> + return find_param(dfl_dev->params, dfl_dev->param_size, param_id); >>>> +} >>>> +EXPORT_SYMBOL_GPL(dfh_find_param); >>> >>> ... >>> >>>> + finfo = kzalloc(sizeof(*finfo) + dfh_psize, GFP_KERNEL); >>> >>> It sounds like a candidate for struct_size() from overflow.h. >>> I.o.w. check that header and come up with the best what can >>> suit your case. >> >> finfo = kzalloc(struct_size(finfo, params, dfh_psize/sizeof(u64)), >> GFP_KERNEL); >> >> Does seem better. > > How about we change the dfh_get_psize() to like dfh_get_pcount(), so we > don't have to multiply & divide back and forth. We need the size in bytes for calls to kmemdup, devm_kmemdup, and memcpy_fromio, but we only need to divide once here. > > Or we just use size_add()? I think using struct_size is better because the params member of struct dfl_feature_info is a trailing flexible array. Thanks for the feedback, Matthew > > Thanks, > Yilun > >> >> Thanks for the suggestion, >> Matthew Gerlach >> >> >>> >>>> if (!finfo) >>>> return -ENOMEM; >>> >>> -- >>> With Best Regards, >>> Andy Shevchenko >>> >>> >>> >