From: Jason Gunthorpe <jgg@nvidia.com>
To: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Andy Gospodarek <andrew.gospodarek@broadcom.com>,
Aron Silverton <aron.silverton@oracle.com>,
Dan Williams <dan.j.williams@intel.com>,
Daniel Vetter <daniel.vetter@ffwll.ch>,
Dave Jiang <dave.jiang@intel.com>,
David Ahern <dsahern@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Christoph Hellwig <hch@infradead.org>,
Itay Avraham <itayavr@nvidia.com>, Jiri Pirko <jiri@nvidia.com>,
Jakub Kicinski <kuba@kernel.org>,
Leonid Bloch <lbloch@nvidia.com>,
Leon Romanovsky <leonro@nvidia.com>,
linux-cxl@vger.kernel.org, linux-rdma@vger.kernel.org,
Saeed Mahameed <saeedm@nvidia.com>
Subject: Re: [PATCH v3 07/10] fwctl/mlx5: Support for communicating with mlx5 fw
Date: Tue, 27 Aug 2024 12:07:48 -0300 [thread overview]
Message-ID: <20240827150748.GC335450@nvidia.com> (raw)
In-Reply-To: <20240823154830.00007d8c@Huawei.com>
On Fri, Aug 23, 2024 at 03:48:30PM +0100, Jonathan Cameron wrote:
> On Wed, 21 Aug 2024 15:10:59 -0300
> Jason Gunthorpe <jgg@nvidia.com> wrote:
>
> > From: Saeed Mahameed <saeedm@nvidia.com>
> >
> > mlx5's fw has long provided a User Context concept. This has a long
> > history in RDMA as part of the devx extended verbs programming
> > interface. A User Context is a security envelope that contains objects and
> > controls access. It contains the Protection Domain object from the
> > InfiniBand Architecture and both togther provide the OS with the necessary
> > tools to bind a security context like a process to the device.
> >
> > The security context is restricted to not be able to touch the kernel or
> > other processes. In the RDMA verbs case it is also restricted to not touch
> > global device resources.
> >
> > The fwctl_mlx5 takes this approach and builds a User Context per fwctl
> > file descriptor and uses a FW security capability on the User Context to
> > enable access to global device resources. This makes the context useful
> > for provisioning and debugging the global device state.
> >
> > mlx5 already has a robust infrastructure for delivering RPC messages to
> > fw. Trivially connect fwctl's RPC mechanism to mlx5_cmd_do(). Enforce the
> > User Context ID in every RPC header so the FW knows the security context
> > of the issuing ID.
> >
> > Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
> > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
>
> Trivial stuff only. Feel free to ignore if you really like the code
> the way it is. I don't know the MLX5 parts, but based on just what
> is visible here and in this series.
>
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> > diff --git a/drivers/fwctl/mlx5/main.c b/drivers/fwctl/mlx5/main.c
> > new file mode 100644
> > index 00000000000000..8839770fbe7ba5
> > --- /dev/null
> > +++ b/drivers/fwctl/mlx5/main.c
>
>
> > +
> > +static void *mlx5ctl_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
> > + void *rpc_in, size_t in_len, size_t *out_len)
> > +{
> > + struct mlx5ctl_dev *mcdev =
> > + container_of(uctx->fwctl, struct mlx5ctl_dev, fwctl);
> > + struct mlx5ctl_uctx *mfd =
> > + container_of(uctx, struct mlx5ctl_uctx, uctx);
> > + void *rpc_alloc __free(kvfree) = NULL;
>
> Whilst you can't completely pair this with destructor, I'd still
> move this as locally as possible.
Yeah, this is a troubling area for cleanup.h here.
I can't really move it as locally as possible because the assignment
is in a scope:
} else {
rpc_out = rpc_alloc = kvzalloc(*out_len, GFP_KERNEL);
if (!rpc_alloc)
return ERR_PTR(-ENOMEM);
}
So given the choice of putting it at the top or put a NULL initialized
variable above the if, I'm feeling the top is more kernely?
Or this is just the wrong place to use a cleanup.h technique??
--- a/drivers/fwctl/mlx5/main.c
+++ b/drivers/fwctl/mlx5/main.c
@@ -226,7 +226,6 @@ static void *mlx5ctl_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
container_of(uctx->fwctl, struct mlx5ctl_dev, fwctl);
struct mlx5ctl_uctx *mfd =
container_of(uctx, struct mlx5ctl_uctx, uctx);
- void *rpc_alloc __free(kvfree) = NULL;
void *rpc_out;
int ret;
@@ -253,8 +252,8 @@ static void *mlx5ctl_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
if (*out_len <= in_len) {
rpc_out = rpc_in;
} else {
- rpc_out = rpc_alloc = kvzalloc(*out_len, GFP_KERNEL);
- if (!rpc_alloc)
+ rpc_out = kvzalloc(*out_len, GFP_KERNEL);
+ if (!rpc_out)
return ERR_PTR(-ENOMEM);
}
@@ -272,11 +271,12 @@ static void *mlx5ctl_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
* but an error code was returned inside out. Everything else
* means the RPC did not make it to the device.
*/
- if (ret && ret != -EREMOTEIO)
+ if (ret && ret != -EREMOTEIO) {
+ if (rpc_out != rpc_in)
+ kfree(rpc_out);
return ERR_PTR(ret);
- if (rpc_out == rpc_in)
- return rpc_in;
- return_ptr(rpc_alloc);
+ }
+ return rpc_out;
}
Arguably it is clearer like above.. Let's go with the above, I think
this was too clever a use of cleanup.h, it seems to work alot better
with simpler cases.
> > +static void mlx5ctl_remove(struct auxiliary_device *adev)
> > +{
> > + struct mlx5ctl_dev *mcdev __free(mlx5ctl) = auxiliary_get_drvdata(adev);
>
> I'm not keen on the non constructor being paired with destructor
> but it's your code so you get keep the confusion if you really
> like it.
>
> I'd just have an explicit put.
Yes, I thought I did that already.. Hum must have just thought about it
Jason
next prev parent reply other threads:[~2024-08-27 15:07 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-21 18:10 [PATCH v3 00/10] Introduce fwctl subystem Jason Gunthorpe
2024-08-21 18:10 ` [PATCH v3 01/10] fwctl: Add basic structure for a class subsystem with a cdev Jason Gunthorpe
2024-08-23 13:48 ` Jonathan Cameron
2024-08-21 18:10 ` [PATCH v3 02/10] fwctl: Basic ioctl dispatch for the character device Jason Gunthorpe
2024-08-23 14:02 ` Jonathan Cameron
2024-08-27 14:56 ` Jason Gunthorpe
2024-08-21 18:10 ` [PATCH v3 03/10] fwctl: FWCTL_INFO to return basic information about the device Jason Gunthorpe
2024-08-23 14:14 ` Jonathan Cameron
2024-08-27 14:47 ` Jason Gunthorpe
2024-08-27 14:55 ` Andy Gospodarek
2024-08-21 18:10 ` [PATCH v3 04/10] taint: Add TAINT_FWCTL Jason Gunthorpe
2024-08-21 23:35 ` Greg Kroah-Hartman
2024-08-22 15:34 ` Jason Gunthorpe
2024-08-21 18:10 ` [PATCH v3 05/10] fwctl: FWCTL_RPC to execute a Remote Procedure Call to device firmware Jason Gunthorpe
2024-08-21 23:49 ` Jakub Kicinski
2024-08-22 0:14 ` Jason Gunthorpe
2024-08-22 0:30 ` Jakub Kicinski
2024-08-27 15:27 ` Jason Gunthorpe
2024-08-23 14:23 ` Jonathan Cameron
2024-08-21 18:10 ` [PATCH v3 06/10] fwctl: Add documentation Jason Gunthorpe
2024-08-23 14:35 ` Jonathan Cameron
2024-08-27 14:58 ` Jason Gunthorpe
2024-08-21 18:10 ` [PATCH v3 07/10] fwctl/mlx5: Support for communicating with mlx5 fw Jason Gunthorpe
2024-08-23 14:48 ` Jonathan Cameron
2024-08-27 15:07 ` Jason Gunthorpe [this message]
2024-08-21 18:11 ` [PATCH v3 08/10] mlx5: Create an auxiliary device for fwctl_mlx5 Jason Gunthorpe
2024-08-21 18:11 ` [PATCH v3 09/10] fwctl/cxl: Add driver for CXL mailbox for handling CXL features commands (RFC) Jason Gunthorpe
2024-08-21 18:11 ` [PATCH v3 10/10] cxl: Create an auxiliary device for fwctl_cxl Jason Gunthorpe
2024-09-13 22:39 ` [PATCH v3 00/10] Introduce fwctl subystem Dave Jiang
2024-09-16 7:54 ` Leon Romanovsky
2024-09-17 20:59 ` Dave Jiang
2024-12-05 22:28 ` Shannon Nelson
2024-12-05 23:58 ` Jason Gunthorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240827150748.GC335450@nvidia.com \
--to=jgg@nvidia.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=andrew.gospodarek@broadcom.com \
--cc=aron.silverton@oracle.com \
--cc=dan.j.williams@intel.com \
--cc=daniel.vetter@ffwll.ch \
--cc=dave.jiang@intel.com \
--cc=dsahern@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=hch@infradead.org \
--cc=itayavr@nvidia.com \
--cc=jiri@nvidia.com \
--cc=kuba@kernel.org \
--cc=lbloch@nvidia.com \
--cc=leonro@nvidia.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=saeedm@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.