lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <7accc5fa-7e0b-4cb1-abc7-debc451285b6@amd.com>
Date: Fri, 11 Oct 2024 17:22:48 +0700
From: "Suthikulpanit, Suravee" <suravee.suthikulpanit@....com>
To: Uros Bizjak <ubizjak@...il.com>, linux-kernel@...r.kernel.org,
 iommu@...ts.linux.dev
Cc: joro@...tes.org, robin.murphy@....com, vasant.hegde@....com,
 jgg@...dia.com, kevin.tian@...el.com, jon.grimm@....com,
 santosh.shukla@....com, pandoh@...gle.com, kumaranand@...gle.com
Subject: Re: [PATCH v5 2/6] iommu/amd: Introduce helper function to update
 256-bit DTE

On 10/7/2024 9:42 PM, Uros Bizjak wrote:
> 
> 
> On 7. 10. 24 06:13, Suravee Suthikulpanit wrote:
> 
>> +
>>   
>> /****************************************************************************
>>    *
>>    * Helper functions
>>    *
>>    
>> ****************************************************************************/
>> +static void write_dte_upper128(struct dev_table_entry *ptr, struct 
>> dev_table_entry *new)
>> +{
>> +    struct dev_table_entry old = {};
>> +
>> +    do {
>> +        old.data128[1] = ptr->data128[1];
>> +        new->data[2] &= ~DTE_DATA2_INTR_MASK;
>> +        new->data[2] |= old.data[2] & (DTE_DATA2_INTR_MASK | 
>> DTE_DATA2_RESV_MASK);
>> +    } while (!try_cmpxchg128(&ptr->data128[1], &old.data128[1], 
>> new->data128[1]));
> 
> Please note that try_cmpxchg inherently updates &old.data128[1] above on 
> failure. There is no need to update value again in the loop.
> 
> Please also note that the value from ptr->data128[1] should be read 
> using READ_ONCE() to prevent compiler from merging, refetching or 
> reordering the read. Currently, there is no READ_ONCE() implemented for 
> __int128, so something like the attached patch should be used.

Thanks for pointing this out. I will introduce the attached patch 
separately in this series on your behalf as author/sign-off, and review 
the current code to properly use the READ_ONCE().

Thanks,
Suravee

> Based on the above, the loop should be rewritten as:
> 
>      old.data128[1] = READ_ONCE(ptr->data128[1]);
>      do {
>          new->data[2] &= ~DTE_DATA2_INTR_MASK;
>          new->data[2] |= old.data[2] & (DTE_DATA2_INTR_MASK | 
> DTE_DATA2_RESV_MASK);
>      } while (!try_cmpxchg128(&ptr->data128[1], &old.data128[1], 
> new->data128[1]));
> 
>> +}
>> +
>> +static void write_dte_lower128(struct dev_table_entry *ptr, struct 
>> dev_table_entry *new)
>> +{
>> +    struct dev_table_entry old = {};
>> +
>> +    /*
>> +     * Need to preserve DTE[96:106], which can be set by information 
>> in IVRS table.
>> +     * See set_dev_entry_from_acpi().
>> +     */
>> +    new->data[1] |= ptr->data[1] & DTE_FLAG_MASK;

>> +
>> +    do {
>> +        old.data128[0] = ptr->data128[0];
>> +    } while (!try_cmpxchg128(&ptr->data128[0], &old.data128[0], 
>> new->data128[0]));
> 
> And this one as:
> 
>      old.data128[0] = READ_ONCE(ptr->data128[0]);
>      do {
>      } while (!try_cmpxchg128(&ptr->data128[0], &old.data128[0], 
> new->data128[0]));
> 
> Best regards,
> Uros.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ