public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Ondrej Kozina <okozina@redhat.com>
To: Christian Brauner <brauner@kernel.org>
Cc: linux-block@vger.kernel.org, bluca@debian.org,
	gmazyland@gmail.com, axboe@kernel.dk, hch@infradead.org,
	jonathan.derrick@linux.dev
Subject: Re: [PATCH 5/5] sed-opal: Add command to read locking range parameters.
Date: Wed, 5 Apr 2023 11:39:48 +0200	[thread overview]
Message-ID: <36d11bf6-a0c9-b02f-020c-df25d06c7aee@redhat.com> (raw)
In-Reply-To: <20230405-komitee-treten-36f2c0a823b6@brauner>

On 05. 04. 23 10:27, Christian Brauner wrote:
> On Wed, Mar 22, 2023 at 04:16:04PM +0100, Ondrej Kozina wrote:
>> +	if (!response_token_matches(tok, OPAL_STARTNAME)) {
>> +		pr_debug("Unexpected response token type %d.\n", n);
>> +		return OPAL_INVAL_PARAM;
>> +	}
>> +
>> +	if (response_get_u64(resp, ++n) != column) {
> 
> Please don't rely on side-effects and increment explicitly before or
> after the functin call so ++n and n++ doesn't matter.

Going to fix in version 2.

> 
>> +		pr_debug("Token %d does not match expected column %u.\n", n, column);
>> +		return OPAL_INVAL_PARAM;
>> +	}
>> +
>> +	val = response_get_u64(resp, ++n);
>> +
>> +	tok = response_get_token(resp, ++n);
>> +	if (IS_ERR(tok))
>> +		return PTR_ERR(tok);
>> +
>> +	if (!response_token_matches(tok, OPAL_ENDNAME)) {
>> +		pr_debug("Unexpected response token type %d.\n", n);
>> +		return OPAL_INVAL_PARAM;
>> +	}
>> +
>> +	*value = val;
>> +	*iter = ++n;
> 
> This is how they explain side-effects in textbooks. :)

Ditto.

(...)
>> +
>> +	/* skip session info when copying back to uspace */
>> +	if (!ret && copy_to_user(data + offsetof(struct opal_lr_status, range_start),
>> +				(void *)opal_lrst + offsetof(struct opal_lr_status, range_start),
> 
> Better written as
> 
> (void *)(opal_lrst + offsetof(struct opal_lr_status, range_start))

Nack. I need to read bytes from offset _inside_ struct opal_lr_status. 
This change would actually read from memory beyond pointed to by 
opal_lrst pointer.

(...)
>> diff --git a/include/uapi/linux/sed-opal.h b/include/uapi/linux/sed-opal.h
>> index d7a1524023db..3905c8ffedbf 100644
>> --- a/include/uapi/linux/sed-opal.h
>> +++ b/include/uapi/linux/sed-opal.h
>> @@ -78,6 +78,16 @@ struct opal_user_lr_setup {
>>   	struct opal_session_info session;
>>   };
>>   
>> +struct opal_lr_status {
>> +	struct opal_session_info session;
>> +	__u64 range_start;
>> +	__u64 range_length;
>> +	__u32 RLE; /* Read Lock enabled */
>> +	__u32 WLE; /* Write Lock Enabled */
> 
> Why is that in capital letters if I may ask? That seems strange uapi for
> Linux. And why not just "read_lock_enabled" and "write_lock_enabled"
> given that we also have "range_start" and "range_length". Let's not
> CREAT one of those weird uapis if we don't have to.

See 'opal_user_lr_setup' struct above. Since the new command is supposed 
to return those parameters I did not want to add confusion by naming it 
differently.

> 
>> +	__u32 l_state;
> 
> "locking_state"?

Same as above, see 'opal_lock_unlock' struct. It's even spicier 
considering it's impossible to set WRITE_ONLY state (lock only read I/O)
with sed-opal iface.


  reply	other threads:[~2023-04-05  9:40 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-22 15:15 [PATCH 0/5] sed-opal: add command to read locking range attributes Ondrej Kozina
2023-03-22 15:16 ` [PATCH 1/5] sed-opal: do not add user authority twice in boolean ace Ondrej Kozina
2023-03-29 14:15   ` Christian Brauner
2023-03-29 15:20     ` Ondrej Kozina
2023-04-04 15:23       ` Christoph Hellwig
2023-04-05  8:18       ` Christian Brauner
2023-03-22 15:16 ` [PATCH 2/5] sed-opal: add helper for adding user authorities in ACE Ondrej Kozina
2023-03-29 15:28   ` Christian Brauner
2023-04-04 15:25   ` Christoph Hellwig
2023-03-22 15:16 ` [PATCH 3/5] sed-opal: allow user authority to get locking range attributes Ondrej Kozina
2023-03-29 15:31   ` Christian Brauner
2023-04-04 15:26   ` Christoph Hellwig
2023-03-22 15:16 ` [PATCH 4/5] sed-opal: add helper to get multiple columns at once Ondrej Kozina
2023-03-29 15:32   ` Christian Brauner
2023-04-04 15:26   ` Christoph Hellwig
2023-03-22 15:16 ` [PATCH 5/5] sed-opal: Add command to read locking range parameters Ondrej Kozina
2023-04-04 15:27   ` Christoph Hellwig
2023-04-05  8:27   ` Christian Brauner
2023-04-05  9:39     ` Ondrej Kozina [this message]
2023-04-05 10:53       ` Luca Boccassi
2023-04-02 14:49 ` [PATCH 0/5] sed-opal: add command to read locking range attributes Luca Boccassi
2023-04-05 11:12 ` [PATCH v2 " Ondrej Kozina
2023-04-05 11:12   ` [PATCH v2 1/5] sed-opal: do not add same authority twice in boolean ace Ondrej Kozina
2023-04-05 11:12   ` [PATCH v2 2/5] sed-opal: add helper for adding user authorities in ACE Ondrej Kozina
2023-04-05 11:12   ` [PATCH v2 3/5] sed-opal: allow user authority to get locking range attributes Ondrej Kozina
2023-04-05 11:12   ` [PATCH v2 4/5] sed-opal: add helper to get multiple columns at once Ondrej Kozina
2023-04-05 11:12   ` [PATCH v2 5/5] sed-opal: Add command to read locking range parameters Ondrej Kozina
2023-04-05 13:46   ` [PATCH v2 0/5] sed-opal: add command to read locking range attributes Jens Axboe

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=36d11bf6-a0c9-b02f-020c-df25d06c7aee@redhat.com \
    --to=okozina@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=bluca@debian.org \
    --cc=brauner@kernel.org \
    --cc=gmazyland@gmail.com \
    --cc=hch@infradead.org \
    --cc=jonathan.derrick@linux.dev \
    --cc=linux-block@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