Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4428757rdh; Wed, 29 Nov 2023 00:53:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJh6Wy0Dj5up4e7d90FwtyDPfPWssSU7J7RXK/gCKhynRljMo5T3FBnw6HS2ZWbdGVveUL X-Received: by 2002:a05:6a21:9993:b0:18b:9b41:eb90 with SMTP id ve19-20020a056a21999300b0018b9b41eb90mr20055309pzb.10.1701248034290; Wed, 29 Nov 2023 00:53:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701248034; cv=none; d=google.com; s=arc-20160816; b=i2yz7gDajYqtqnSWGtklULeG6xeEXhOxfquyDZfiM+M/cY2hc82obQFHoDGuPe2x9P zHAc2BqtDWcM7HxKxhGfyXixpx726peS3zBXU+vH/Iyt+42wSsVomR893dlLjNGQhrCg GDBVNUqwC7D695jaDrPyYBaYTbUtAhwhGYGdwN8nx4/hBePxyPHfDlfHwRWzePZz0GHu FUBnkt4tHLvqTeQq8tWS00SJEaGNS3ndOOxsCNxsyDZmN0goKfb65xHmoG0yOrY9VkYY KDu67PVf/E1AacggGYEdwQ9bj1MRUji2N7Cijv2RQqvKs/OnsYSid+jCuln5nChyImF1 RZtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=D7agUQ/RGJLrtqazajVP9mEyFM0WVNEdO+0oBG2uRDQ=; fh=zoSMQ4a4QwWNxeEeetXsvOtHDlTyNHz2tNRhoYEheKU=; b=RolUFmbnmAMHf+MvDoWDMWWCcdylISWLC0KfExSxYud26ofNpWduEr3DsylK57BUX5 1Rz3zkI7rsPK+2yJ1S3dVSxNftF7lU7SSfKV3ZFYboHVD7NCDh/qYEAYD4VboN/u3/dc SD4Bb1CNyTNGux6pPvqH2cbX79fVjocAcFMKt5kdPl3chph06WfkUXL709amDrIaOZJu awJXSk/yZ07DYenMyUWLiPi0TGZoCkf+G+s+h17XmKrVDWsDBlyQekH/jgQznVGcnxNh 1Nx5UKd9e6FYdg5dtYo0MaezlM7GIcP8XzJyNKVq6b0nvMeQ7OfONB5CR1ZqVOKmCOup cuZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=H10Gz0c3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id d5-20020a170902cec500b001cc4770b9aesi8100607plg.419.2023.11.29.00.53.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 00:53:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=H10Gz0c3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 42A278043EF0; Wed, 29 Nov 2023 00:53:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232064AbjK2Ixb (ORCPT + 99 others); Wed, 29 Nov 2023 03:53:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230172AbjK2Ixa (ORCPT ); Wed, 29 Nov 2023 03:53:30 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E008AF for ; Wed, 29 Nov 2023 00:53:36 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07F62C433C7; Wed, 29 Nov 2023 08:53:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701248016; bh=3eLt23KooZa2k2I13M7RSXAGLV1T4oMfWl3vu8htwmg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=H10Gz0c3p5v4a9BqkCBUfFhbKlxaGH2dQYHXYqZneRUQxkzvQwROkFvxs4Rg8WvxC S8QlKDnjKBwY5Vpjv4JJUHKT3vJcZCUps0TFUqyC4XWMd7l14OuAScT1a2YmqYNGLo Wtf7cA9G2XPCJbTXDJVBUgnCmqEoRe6wxquimnOLui+qvzj7Ztu+IbBnlrbXBHsTXY 6LxgFjHdPm37ysKu/Q4Ydk/eZK7IdsdbKf1RgXtHiI3Myq8xjiqQXvb694Z7h3WtoB ra7qfCfO/yhM96Ih3Vfuo4WL+QHBvf9jzhkVX7lH54048S6kowXlPwREYfjOlwpV+N buiuIt3WJFAaw== Date: Wed, 29 Nov 2023 00:53:34 -0800 From: Saeed Mahameed To: Greg Kroah-Hartman Cc: Arnd Bergmann , Jason Gunthorpe , Leon Romanovsky , Jiri Pirko , Leonid Bloch , Itay Avraham , Jakub Kicinski , linux-kernel@vger.kernel.org, Saeed Mahameed Subject: Re: [PATCH V3 3/5] misc: mlx5ctl: Add info ioctl Message-ID: References: <20231121070619.9836-1-saeed@kernel.org> <20231121070619.9836-4-saeed@kernel.org> <2023112722-imitate-impromptu-c9a7@gregkh> <2023112802-false-tumble-ea38@gregkh> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <2023112802-false-tumble-ea38@gregkh> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 29 Nov 2023 00:53:48 -0800 (PST) On 28 Nov 09:13, Greg Kroah-Hartman wrote: >On Mon, Nov 27, 2023 at 12:39:22PM -0800, Saeed Mahameed wrote: >> On 27 Nov 19:09, Greg Kroah-Hartman wrote: >> > On Mon, Nov 20, 2023 at 11:06:17PM -0800, Saeed Mahameed wrote: >> > > +static int mlx5ctl_info_ioctl(struct file *file, >> > > + struct mlx5ctl_info __user *arg, >> > > + size_t usize) >> > > +{ >> > > + struct mlx5ctl_fd *mfd = file->private_data; >> > > + struct mlx5ctl_dev *mcdev = mfd->mcdev; >> > > + struct mlx5_core_dev *mdev = mcdev->mdev; >> > > + struct mlx5ctl_info *info; >> > > + size_t ksize = 0; >> > > + int err = 0; >> > > + >> > > + ksize = max(sizeof(struct mlx5ctl_info), usize); >> > >> > Why / How can usize be larger than the structure size and you still want >> > to allocate a memory chunk that big? Shouldn't the size always match? >> > >> >> new user-space old kernel, the driver would allocate the usiae and make >> sure to clear all the buffer with 0's, then fill in what the kernel >> understands and send the whole buffer back to user with trailer always >> zeroed out. > >No, at that point you know something is wrong and you need to just abort >and return -EINVAL as the structure sizes do not match. > >If you need to "extend" the structure to include more information, do so >in a new ioctl. > Ack, will remove these fields. >> > > --- /dev/null >> > > +++ b/include/uapi/misc/mlx5ctl.h >> > > @@ -0,0 +1,24 @@ >> > > +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 WITH Linux-syscall-note */ >> > > +/* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */ >> > > + >> > > +#ifndef __MLX5CTL_IOCTL_H__ >> > > +#define __MLX5CTL_IOCTL_H__ >> > > + >> > > +struct mlx5ctl_info { >> > > + __aligned_u64 flags; >> > >> > Is this used? >> > >> >> no, not yet, but it is good for future extendibility and compatibility >> checking. > >But you are not checking anything now, so please don't include something >that will not work in the future. > Ack, will remove. >> > > + __u32 size; >> > > + __u8 devname[64]; /* underlaying ConnectX device */ >> > >> > 64 should be a define somewhere, right? And why 64? >> > >> >> It is usually the kobj->name of the underlying device, I will have to >> define this in the uAPI. 64 seemed large enough, any other suggestion ? > >What happens if the names get bigger? > >> This field is informational only for the user to have an idea which is the >> underlying physical device, it's ok if in odd situation the name has to be >> truncated to fit into the uAPI buffer. > >As the truncation will happen on the right side of the string, usually >the actual device id or unique identifier, that's not going to help out >much to drop that portion :( > Right :/, it's an assumption that mlx5 devices can either be a pci device or an auxiliary device in case of a mlx5-subfunction, so i don't expect the names to get larger and can easily fit in 64B string, but you are right, I shouldn't make such assumption in an IOCTL, I will figure out something or completely drop this field in V4. >> > > + __u16 uctx_uid; /* current process allocated UCTX UID */ >> > > + __u16 reserved1; >> > >> > Where is this checked to be always 0? Well it's a read so I guess where >> > is the documentation saying it will always be set to 0? >> > >> >> I forgot to add the checks in the info ioctl path, will add that. >> Isn't it an unwritten rule that reserved fields has to be always 0 ? >> Do I really need to document this ? > >It is a written rule that reserved fields must be 0, please see the >documentation for how to write an ioctl. > Ack, will document. >thanks, > >greg k-h