This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt][hwasan] Support for Intel LAM v6 API
ClosedPublic

Authored by glider on Aug 24 2022, 3:30 AM.

Details

Summary

Version 6 of Intel LAM kernel patches
(https://lore.kernel.org/all/20220815041803.17954-1-kirill.shutemov@linux.intel.com/)
introduces arch_prctl(ARCH_GET_MAX_TAG_BITS), which (unlike
ARCH_GET_UNTAG_MASK) can be used to determine if the kernel really
supports pointer tagging.

Depends on D132545

Diff Detail

Event Timeline

glider created this revision.Aug 24 2022, 3:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 24 2022, 3:30 AM
Herald added subscribers: Enna1, dberris. · View Herald Transcript
glider requested review of this revision.Aug 24 2022, 3:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 24 2022, 3:30 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
kstoimenov added inline comments.Aug 24 2022, 1:38 PM
compiler-rt/lib/hwasan/hwasan_linux.cpp
137

Does it have to kTagBits? Could it be 'num_bits < kTagBits' because you would be able to fit tag if it is >= kTagBits?

kstoimenov requested changes to this revision.Aug 24 2022, 1:40 PM
This revision now requires changes to proceed.Aug 24 2022, 1:40 PM
vitalybuka added inline comments.Aug 24 2022, 2:16 PM
compiler-rt/lib/hwasan/hwasan_linux.cpp
137

Even more, why do we use this call at all if patches support ARCH_GET_UNTAG_MASK?
We expect particular bits for hwasan, so better check exact mask.
if ((kAddressTagMask & returned_mask) != kAddressTagMask) return false;

glider added inline comments.Aug 24 2022, 2:28 PM
compiler-rt/lib/hwasan/hwasan_linux.cpp
137

Does it have to kTagBits? Could it be 'num_bits < kTagBits' because you would be able to fit tag if it is >= kTagBits?

Fair enough, we need to check for >=

137

Even more, why do we use this call at all if patches support ARCH_GET_UNTAG_MASK?
We expect particular bits for hwasan, so better check exact mask.
if ((kAddressTagMask & returned_mask) != kAddressTagMask) return false;

Good catch, but we need to check both.
ARCH_GET_UNTAG_MASK will return a nonzero mask even if the hardware doesn't support LAM.

vitalybuka added inline comments.Aug 24 2022, 2:28 PM
compiler-rt/lib/hwasan/hwasan_linux.cpp
137

my mistake, ARCH_GET_UNTAG_MASK is for enabled tagging
so (num_bits < kTagBits) is appropriate here

vitalybuka accepted this revision.Aug 24 2022, 2:32 PM

Assuming the comment is straightforward

kstoimenov accepted this revision.Aug 24 2022, 2:36 PM

Feel free to push after addressing the comments.

This revision is now accepted and ready to land.Aug 24 2022, 2:36 PM
glider updated this revision to Diff 455517.Aug 25 2022, 2:50 AM

Use ARCH_GET_UNTAG_MASK to double check HWASan can place tags in this bit range.

glider added inline comments.Aug 25 2022, 3:21 AM
compiler-rt/lib/hwasan/hwasan_linux.cpp
137

Ah, you are right, we can only check the mask in EnableTaggingAbi().

glider updated this revision to Diff 455583.Aug 25 2022, 7:45 AM

Compare the mask returned by ARCH_GET_UNTAG_MASK to what HWASan expects.

Also use unsigned long variables to get values from arch_prctl.

vitalybuka accepted this revision.Aug 25 2022, 2:33 PM
This revision was landed with ongoing or failed builds.Aug 26 2022, 1:21 AM
This revision was automatically updated to reflect the committed changes.