Bug 338995 - shmat with hugepages (SHM_HUGETLB) fails with EINVAL when executed on valgrind
Summary: shmat with hugepages (SHM_HUGETLB) fails with EINVAL when executed on valgrind
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: memcheck (show other bugs)
Version: 3.9.0
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-10 23:19 UTC by Hideaki Kimura
Modified: 2014-11-04 13:26 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hideaki Kimura 2014-09-10 23:19:35 UTC
This seems like a new variant of shmat-related bug reports on valgrind.
I tested with valgrind 3.9.0 and 3.8.1. Both cause EINVAL error if a user code calls shmat with SHM_HUGETLB parameter to use hugepages.

If the user code doesn't have SHM_HUGETLB option or runs it without valgrind, it goes fine.

int main(int argc, char **argv) {
  int shmid = ::shmget(
    ::getpid(),
    1ULL << 21,
    // IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);  // <-- this works fine
    IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR | SHM_HUGETLB);  // <-- This causes EINVAL
  if (shmid == -1) {
    std::cerr << "shmget failed!"
      << "[Errno " << errno << "] " << std::strerror(errno) << std::endl;
    return 1;
  } else {
    std::cout << "shmget() ok" << std::endl;
  }

  void* block = ::shmat(shmid, NULL, 0);
  if (block == ((void*) -1)) {
    std::cerr << "shmat failed!"
      << "[Errno " << errno << "] " << std::strerror(errno) << std::endl;
    ::shmctl(shmid, IPC_RMID, NULL);
    return 1;
  } else {
    std::cout << "shmat() ok" << std::endl;
  }
  ::shmdt(block);
  ::shmctl(shmid, IPC_RMID, NULL);
  return 0;
}

My environment is Fedora 19, x86_64.

Reproducible: Always

Steps to Reproduce:
1. Sample code above
2.
3.

Actual Results:  
EINVAL error at shmat

Expected Results:  
Should work fine.
Comment 1 Philippe Waroquiers 2014-11-01 22:08:51 UTC
Bug is fixed in revision 14683
or rather, this revision ensures that SHM_HUGETLB flag is ignored.
A warning is given (once) to the user if such a flag is ignored
Comment 2 Hideaki Kimura 2014-11-02 23:41:41 UTC
Thanks for the fix. Yes, ignoring SHM_HUGETLB is sufficient for my usecase (and probably everyone's, who cares TLB performance in valgrind runs).
Is it in 3.10.0 release?
Comment 3 Philippe Waroquiers 2014-11-04 13:26:10 UTC
(In reply to Hideaki Kimura from comment #2)
> Thanks for the fix. Yes, ignoring SHM_HUGETLB is sufficient for my usecase
> (and probably everyone's, who cares TLB performance in valgrind runs).
> Is it in 3.10.0 release?
It is in the SVN version (the future 3.11.0).