Re: [PATCH v6 1/6] mm/memblock: Tag memblocks with crypto capabilities

From: Martin Fernandez
Date: Tue Feb 08 2022 - 09:39:55 EST


On 2/7/22, Kees Cook <keescook@xxxxxxxxxxxx> wrote:
> On Thu, Feb 03, 2022 at 01:43:23PM -0300, Martin Fernandez wrote:
>> +/**
>> + * memblock_node_is_crypto_capable - get if whole node is capable
>> + * of encryption
>> + * @nid: number of node
>> + *
>> + * Iterate over all memory memblock_type and find if all regions under
>> + * node @nid are capable of hardware encryption.
>> + *
>> + * Return:
>> + * true if every region in memory memblock_type is capable of
>> + * encryption, false otherwise.
>> + */
>> +bool __init_memblock memblock_node_is_crypto_capable(int nid)
>> +{
>> + struct memblock_region *region;
>> + bool crypto_capable = false;
>> + bool not_crypto_capable = false;
>> +
>> + for_each_mem_region(region) {
>> + if (memblock_get_region_node(region) == nid) {
>> + crypto_capable =
>> + crypto_capable ||
>> + (region->flags & MEMBLOCK_CRYPTO_CAPABLE);
>
> This was already mentioned, but I just thought I'd add: this made me
> double-take, given the "||" (instead of "|") in an assignment. It looked
> like a typo, but yes it's correct. I was expecting something like:
>
> crypto_capable |=
> !!(region->flags & MEMBLOCK_CRYPTO_CAPABLE);
>
>> + not_crypto_capable =
>> + not_crypto_capable ||
>> + !(region->flags & MEMBLOCK_CRYPTO_CAPABLE);
>
> not_crypto_capable |=
> !(region->flags & MEMBLOCK_CRYPTO_CAPABLE);
>

Yes, this also works. Thanks.