From: Scott Bauer <sbauer@plzdonthack.me>
To: Revanth Rajashekar <revanth.rajashekar@intel.com>
Cc: linux-block@vger.kernel.org,
Jonathan Derrick <jonathan.derrick@intel.com>,
zub@linux.fjfi.cvut.cz
Subject: Re: [PATCH 3/3] block: sed-opal: Add support to read/write opal tables generically
Date: Sun, 25 Aug 2019 16:08:46 -0400 [thread overview]
Message-ID: <20190825200846.GA30738@hacktheplanet> (raw)
In-Reply-To: <20190821191051.3535-4-revanth.rajashekar@intel.com>
On Wed, Aug 21, 2019 at 01:10:51PM -0600, Revanth Rajashekar wrote:
[snip]
> The ioctl provides a private field with the intentiont to accommodate
> any future expansions to the ioctl.
spelling (intentiont)
[snip]
> + * IO_BUFFER_LENGTH = 2048
> + * sizeof(header) = 56
> + * No. of Token Bytes in the Response = 11
> + * MAX size of data that can be carried in response buffer
> + * at a time is : 2048 - (56 + 11) = 1981 = 0x7BD.
> + */
> +#define OPAL_MAX_READ_TABLE (0x7BD)
> +
> +static int read_table_data(struct opal_dev *dev, void *data)
> +{
> + dst = (u8 __user *)(uintptr_t)read_tbl->data;
> + if (copy_to_user(dst + off, dev->prev_data, dev->prev_d_len)) {
> + pr_debug("Error copying data to userspace\n");
> + err = -EFAULT;
> + break;
> + }
I'm with Jon on this one. Even though the spec says we have a max size, lets not put our trust in firmware engineers.
A simple if check is easy to place before the CTU and will solve any future wtf debugging on a userland program.
> +static int opal_generic_read_write_table(struct opal_dev *dev,
> + struct opal_read_write_table *rw_tbl)
> +{
> + const struct opal_step write_table_steps[] = {
> + { start_admin1LSP_opal_session, &rw_tbl->key },
> + { write_table_data, rw_tbl },
> + { end_opal_session, }
> + };
> +
> + const struct opal_step read_table_steps[] = {
> + { start_admin1LSP_opal_session, &rw_tbl->key },
> + { read_table_data, rw_tbl },
> + { end_opal_session, }
> + };
> + int ret = 0;
> +
> + mutex_lock(&dev->dev_lock);
> + setup_opal_dev(dev);
> + if (rw_tbl->flags & OPAL_TABLE_READ) {
> + if (rw_tbl->size > 0)
> + ret = execute_steps(dev, read_table_steps,
> + ARRAY_SIZE(read_table_steps));
> + } else if (rw_tbl->flags & OPAL_TABLE_WRITE) {
> + if (rw_tbl->size > 0)
> + ret = execute_steps(dev, write_table_steps,
> + ARRAY_SIZE(write_table_steps));
> + } else {
> + pr_debug("Invalid bit set in the flag.\n");
> + ret = -EINVAL;
> + }
> + mutex_unlock(&dev->dev_lock);
> +
> + return ret;
> +}
Do we expect to add more flags in the future? I ask because this function can quickly get out
of hand with regard to the else if chain and the function table list above. If we think we're going
to add more flags in the future lets slap a switch statement in here to call opal_table_write() and
opal_table_read(). We can deal with that in the future I guess, I just don't want a 3000 line function.
> diff --git a/include/uapi/linux/sed-opal.h b/include/uapi/linux/sed-opal.h
> index 59eed0bdffd3..a803ed0534da 100644
> --- a/include/uapi/linux/sed-opal.h
> +++ b/include/uapi/linux/sed-opal.h
> +struct opal_read_write_table {
> + struct opal_key key;
> + const __u64 data;
> + const __u8 table_uid[OPAL_UID_LENGTH];
> + __u64 offset;
> + __u64 size;
> + #define OPAL_TABLE_READ (1 << 0)
> + #define OPAL_TABLE_WRITE (1 << 1)
> + __u64 flags;
> + __u64 priv;
> +};
Two things, can you double check the pahole on this struct (Google it or ask Jon he knows).
Second, can you lift those defines into Enumerations or out of the struct? Is there a reason
they're in there?
next prev parent reply other threads:[~2019-08-25 20:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-21 19:10 [PATCH 0/3] block: sed-opal - Generic Read/Write Opal Tables Revanth Rajashekar
2019-08-21 19:10 ` [PATCH 1/3] block: sed-opal: Expose enum opal_uid and opaluid definitions to the users by moving it to "include/uapi/linux/sed-opal.h" Revanth Rajashekar
2019-08-21 19:10 ` [PATCH 2/3] block: sed-opal: Generalizing write data to any opal table Revanth Rajashekar
2019-08-21 19:10 ` [PATCH 3/3] block: sed-opal: Add support to read/write opal tables generically Revanth Rajashekar
2019-08-23 16:58 ` Derrick, Jonathan
2019-08-25 20:08 ` Scott Bauer [this message]
2019-08-26 19:27 ` Derrick, Jonathan
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=20190825200846.GA30738@hacktheplanet \
--to=sbauer@plzdonthack.me \
--cc=jonathan.derrick@intel.com \
--cc=linux-block@vger.kernel.org \
--cc=revanth.rajashekar@intel.com \
--cc=zub@linux.fjfi.cvut.cz \
/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.