From: Jani Nikula <jani.nikula@intel.com>
To: Michal Wajdeczko <michal.wajdeczko@intel.com>,
Kees Cook <keescook@chromium.org>
Cc: linux-kernel@vger.kernel.org,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Alexey Dobriyan <adobriyan@gmail.com>
Subject: Re: [PATCH 1/2] wordpart.h: Helpers for making u16/u32/u64 values
Date: Mon, 08 Apr 2024 16:24:18 +0300 [thread overview]
Message-ID: <87le5o9ed9.fsf@intel.com> (raw)
In-Reply-To: <11c0a997-f283-476b-bdf6-47b440538f8b@intel.com>
On Tue, 26 Mar 2024, Michal Wajdeczko <michal.wajdeczko@intel.com> wrote:
> On 15.02.2024 23:47, Kees Cook wrote:
>> On Thu, Feb 15, 2024 at 09:40:40PM +0100, Michal Wajdeczko wrote:
>>> On 14.02.2024 23:09, Kees Cook wrote:
>>>> On Wed, Feb 14, 2024 at 10:46:53PM +0100, Michal Wajdeczko wrote:
>>>>> It is quite common practice to make u16, u32 or u64 values from
>>>>> smaller words. Add simple helpers for that.
>>>>>
>>>>> Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
>>>>> ---
>>>>> v2: new macro names due to conflict with crypto/aria.h
>>>>> explicit cast and truncation everywhere (Alexey)
>>>>> moved to wordpart.h (Andy)
>>>>> ---
>>>>> Cc: Kees Cook <keescook@chromium.org>
>>>>> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>>>>> Cc: Alexey Dobriyan <adobriyan@gmail.com>
>>>>> Cc: Jani Nikula <jani.nikula@intel.com>
>>>>> ---
>>>>> include/linux/wordpart.h | 32 ++++++++++++++++++++++++++++++++
>>>>> 1 file changed, 32 insertions(+)
>>>>>
>>>>> diff --git a/include/linux/wordpart.h b/include/linux/wordpart.h
>>>>> index f6f8f83b15b0..8c75a5355112 100644
>>>>> --- a/include/linux/wordpart.h
>>>>> +++ b/include/linux/wordpart.h
>>>>> @@ -31,6 +31,38 @@
>>>>> */
>>>>> #define lower_16_bits(n) ((u16)((n) & 0xffff))
>>>>>
>>>>> +/**
>>>>> + * make_u16_from_u8 - make u16 value from two u8 values
>>>>> + * @hi: value representing upper 8 bits
>>>>> + * @lo: value representing lower 8 bits
>>>>> + */
>>>>> +#define make_u16_from_u8(hi, lo) ((u16)((u16)(u8)(hi) << 8 | (u8)(lo)))
>>>>
>>>> Do we want to actually do type validation here? Right now it's just
>>>> cast/truncating, which based on the version log is by design. Is silent
>>>> truncation the right thing to do?
Doesn't the name imply strongly enough that we're only interested in the
N bits from each parameter? I think not truncating makes these harder to
use (if it means e.g. casting on the caller side).
>>>
>>> note that even FIELD_PREP() is doing silent truncation and these macros
>>> here could be treated as specialized/simplified variants of FIELD_PREP()
>>> as alternate implementation can look like:
>>
>> Also, isn't all of this endian-specific?
None of this assumes endianness.
> endianness shouldn't matter here
>
> so I guess the only question now is whether we want to have simple
> direct macros like lower|upper_bits() or go with macros build on top of
> the FIELD_PREP_CONST() or drop the idea completely and force the drivers
> to invent the wheel on its own
Yeah, please let's do this so we don't have to keep adding them to
drivers.
BR,
Jani.
--
Jani Nikula, Intel
prev parent reply other threads:[~2024-04-08 13:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-14 21:46 [PATCH 1/2] wordpart.h: Helpers for making u16/u32/u64 values Michal Wajdeczko
2024-02-14 21:46 ` [PATCH 2/2] drm/xe: Prefer make_u64_from_u32() over local macro Michal Wajdeczko
2024-02-14 22:09 ` [PATCH 1/2] wordpart.h: Helpers for making u16/u32/u64 values Kees Cook
2024-02-15 20:40 ` Michal Wajdeczko
2024-02-15 22:47 ` Kees Cook
2024-03-26 17:58 ` Michal Wajdeczko
2024-04-08 13:24 ` Jani Nikula [this message]
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=87le5o9ed9.fsf@intel.com \
--to=jani.nikula@intel.com \
--cc=adobriyan@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.wajdeczko@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox