mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maximilian Luz <luzmaximilian@gmail.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Blaž Hrastnik" <blaz@mxxn.io>,
	"Dorian Stoll" <dorian.stoll@tmsp.io>
Subject: Re: [RFC PATCH 8/9] surface_aggregator: Add DebugFS interface
Date: Thu, 24 Sep 2020 00:23:05 +0200	[thread overview]
Message-ID: <5d470a61-bf4d-7ea2-b41f-1163006b1956@gmail.com> (raw)
In-Reply-To: <CAK8P3a0_i=wHnQmfbjCdMgFRSD0eGjEM2uMFft5FJ4M1GSUbHg@mail.gmail.com>

On 9/23/20 8:51 PM, Arnd Bergmann wrote:
> On Wed, Sep 23, 2020 at 8:29 PM Maximilian Luz <luzmaximilian@gmail.com> wrote:
>> On 9/23/20 6:48 PM, Arnd Bergmann wrote:
>>>> + * struct ssam_debug_request - Controller request IOCTL argument.
>>>> + * @target_category: Target category of the SAM request.
>>>> + * @target_id:       Target ID of the SAM request.
>>>> + * @command_id:      Command ID of the SAM request.
>>>> + * @instance_id:     Instance ID of the SAM request.
>>>> + * @flags:           SAM Request flags.
>>>> + * @status:          Request status (output).
>>>> + * @payload:         Request payload (input data).
>>>> + * @payload.data:    Pointer to request payload data.
>>>> + * @payload.length:  Length of request payload data (in bytes).
>>>> + * @response:        Request response (output data).
>>>> + * @response.data:   Pointer to response buffer.
>>>> + * @response.length: On input: Capacity of response buffer (in bytes).
>>>> + *                   On output: Length of request response (number of bytes
>>>> + *                   in the buffer that are actually used).
>>>> + */
>>>> +struct ssam_dbg_request {
>>>> +       __u8 target_category;
>>>> +       __u8 target_id;
>>>> +       __u8 command_id;
>>>> +       __u8 instance_id;
>>>> +       __u16 flags;
>>>> +       __s16 status;
>>>> +
>>>> +       struct {
>>>> +               const __u8 __user *data;
>>>> +               __u16 length;
>>>> +               __u8 __pad[6];
>>>> +       } payload;
>>>> +
>>>> +       struct {
>>>> +               __u8 __user *data;
>>>> +               __u16 length;
>>>> +               __u8 __pad[6];
>>>> +       } response;
>>>> +};
>>>
>>> Binary interfaces are hard. In this case the indirect pointers mean that
>>> 32-bit user space has an incompatible layout, which you should not do.
>>>
>>> Also, having an ioctl on a debugfs file is a bit odd. I wonder if you
>>> could have this as a transactional file that performs only read/write
>>> commands, i.e. you pass in a
>>>
>>> struct ssam_dbg_request {
>>>          __u8 target_category;
>>>          __u8 target_id;
>>>          __u8 command_id;
>>>          __u8 instance_id;
>>>          __u16 flags;
>>>         __u8 payload[]; /* variable-length */
>>> };
>>>
>>> and you get out a
>>>
>>> struct ssam_dbg_response {
>>>         __s16 status;
>>>        __u8 payload[];
>>> };
>>>
>>> and keep the rest unchanged. See fs/libfs.c for how this could be done
>>> with simple_transaction files.
>>
>> Thanks! Is there a way to make this compatible with a 32-bit user space?
> 
> The version I showed avoids the pointers and is compatible with
> 32-bit user space.

I'm not completely convinced yet that the read/write approach is the way
I want to do it, especially with Greg suggesting a misc device, but I'll
keep your solution in mind.
  
>>   From a quick search, compat_ptr and compat_uptr_t would be the right way
>> to transfer pointer?
> 
> If you end up needing an indirect pointer, the most portable way is to
> use a __u64 and read it using u64_to_user_ptr() in the kernel.

Thanks!

>> I've already laid out my main two rationales for using an IOCTL in the
>> reply to Greg, but here's an overview: First, IOCTLs allow me to execute
>> requests in parallel with only a single open file descriptor, and
>> without having to care about allocating buffers for the responses and
>> waiting until the buffer is read (yes, arguably I still have to manage
>> buffers, but only in the IOCTL function which I consider a bit more
>> manageable). I was previously unaware of the simple_transaction helpers
>> though, so thanks for that pointer! Second, I can easily expand that
>> interface to handle events sent by the EC, by having the user space
>> application read from that file. Although that could be moved to a
>> second file. I just felt having that option of keeping in one would
>> eventually result in a cleaner interface
> 
> The debugfs way is usually to just have additional files when you
> do more than one thing, or if you need a new variant of that interface,
> they are cheap.

Alright, thanks!

Regards,
Max

  reply	other threads:[~2020-09-23 22:23 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-23 15:15 [RFC PATCH 0/9] Add support for Microsoft Surface System Aggregator Module Maximilian Luz
2020-09-23 15:15 ` [RFC PATCH 1/9] misc: Add Surface Aggregator subsystem Maximilian Luz
2020-09-23 16:57   ` Greg Kroah-Hartman
2020-09-23 20:34     ` Maximilian Luz
2020-09-24  6:48       ` Greg Kroah-Hartman
2020-09-24 18:16         ` Maximilian Luz
2020-09-23 15:15 ` [RFC PATCH 2/9] surface_aggregator: Add control packet allocation chaching Maximilian Luz
2020-09-23 15:15 ` [RFC PATCH 3/9] surface_aggregator: Add event item " Maximilian Luz
2020-09-23 15:15 ` [RFC PATCH 4/9] surface_aggregator: Add trace points Maximilian Luz
2020-09-23 20:07   ` Steven Rostedt
2020-09-23 23:43     ` Maximilian Luz
2020-09-23 15:15 ` [RFC PATCH 5/9] surface_aggregator: Add error injection capabilities Maximilian Luz
2020-09-23 17:45   ` Greg Kroah-Hartman
2020-09-23 21:28     ` Maximilian Luz
2020-09-23 15:15 ` [RFC PATCH 6/9] surface_aggregator: Add dedicated bus and device type Maximilian Luz
2020-09-23 17:33   ` Greg Kroah-Hartman
2020-09-23 21:12     ` Maximilian Luz
2020-09-24  7:12       ` Greg Kroah-Hartman
2020-09-24 18:15         ` Maximilian Luz
2020-09-23 15:15 ` [RFC PATCH 7/9] docs: driver-api: Add Surface Aggregator subsystem documentation Maximilian Luz
2020-09-23 15:15 ` [RFC PATCH 8/9] surface_aggregator: Add DebugFS interface Maximilian Luz
2020-09-23 16:14   ` Greg Kroah-Hartman
2020-09-23 18:03     ` Maximilian Luz
2020-09-23 18:29       ` Greg Kroah-Hartman
2020-09-23 22:06         ` Maximilian Luz
2020-09-24  6:46           ` Greg Kroah-Hartman
2020-09-24 18:40             ` Maximilian Luz
2020-09-23 16:48   ` Arnd Bergmann
2020-09-23 18:29     ` Maximilian Luz
2020-09-23 18:51       ` Arnd Bergmann
2020-09-23 22:23         ` Maximilian Luz [this message]
2020-09-24  7:41           ` Arnd Bergmann
2020-09-24 18:44             ` Maximilian Luz
2020-09-23 15:15 ` [RFC PATCH 9/9] surface_aggregator: Add Surface ACPI Notify client driver Maximilian Luz
2020-09-23 15:30 ` [RFC PATCH 0/9] Add support for Microsoft Surface System Aggregator Module Arnd Bergmann
2020-09-23 15:43   ` Maximilian Luz
2020-09-23 19:43     ` Arnd Bergmann
2020-09-23 23:28       ` Maximilian Luz
2020-09-24  8:26         ` Arnd Bergmann
2020-09-24 18:59           ` Maximilian Luz
2020-09-24 19:38             ` Arnd Bergmann
2020-09-24 21:07               ` Maximilian Luz
2020-09-25 14:53               ` Andy Shevchenko
2020-09-24  8:30   ` Andy Shevchenko
2020-09-24 19:17     ` Maximilian Luz
2020-09-25 14:58       ` Andy Shevchenko
2020-09-25 15:41         ` Maximilian Luz

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=5d470a61-bf4d-7ea2-b41f-1163006b1956@gmail.com \
    --to=luzmaximilian@gmail.com \
    --cc=arnd@arndb.de \
    --cc=blaz@mxxn.io \
    --cc=dorian.stoll@tmsp.io \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®