Skip to content

createdump can read memory with process_vm_readv on Linux - #420

Merged
hoyosjs merged 2 commits into
dotnet:masterfrom
nxtn:createdump
Jan 28, 2020
Merged

hoyosjs merged 2 commits into
dotnet:masterfrom
nxtn:createdump

Conversation

@nxtn

@nxtn nxtn commented Dec 1, 2019

Copy link
Copy Markdown
Contributor

See benchmark results in microsoft/clrmd#351

@nxtn

nxtn commented Dec 1, 2019

Copy link
Copy Markdown
Contributor Author

This system call was added in Linux 3.2, which requires at least RHEL 7.

@jkotas

jkotas commented Dec 1, 2019 •

Copy link
Copy Markdown
Member

We should drop support for RHEL6 for .NET 5. Opened #423

@0xd4d

0xd4d commented Dec 1, 2019

Copy link
Copy Markdown

Will probably also fix dotnet/diagnostics#548

@lpereira lpereira left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I like the changes, there are some comments regarding portability and (possible) performance enhancements.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ssize_t is a signed, 64-bit integer; ULONG32 is an unsigned, 32-bit integer. It's unlikely that read will be larger than size as that's the quantity passed as a parameter, however assigning read to *done will at least generate a warning.

(Using 32-bit integers to denote sizes is something we should fix throughout the runtime. It should use size_t throughout.)

@lpereira lpereira Dec 2, 2019 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, are there any places where it would be beneficial to pass an iovec array rather than just 1 element at a time to process_vm_readv()? (There could be a fallback method to go through each one and read the memory on OSes that do not offer this particular syscall or a similar feature.)

It might be a good idea to #ifdef this for Linux only, or check if the syscall exist during build-time. For instance, the FreeBSD procfs supports /proc/<PID>/mem but does not have this syscall, so this breaks createdump on FreeBSD. On systems without process_vm_readv() but with a compatible procfs, you might benefit from using readv() instead of pread() and have similar speedups if the suggestion above is possible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may even be Linux distros that don't support process_vm_readv so a build-time check (like all the other HAVE_xxxx defines) should be added falling back to the proc//mem code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Distro Version Kernel
RHEL 7.0 3.10
CentOS 7.0 3.10
Oracle Linux 7.0 3.10
Fedora 29 4.18
Debian 9 4.9
Ubuntu 16.04 4.4
Linux Mint 18 4.4
openSUSE 15 4.12
SLES 12 SP2 4.4
Alpline Linux 3.8 4.14

There may even be Linux distros that don't support process_vm_readv

All supported Linux distros meet the minimum version requirement, so I assume it only needs to check for Linux.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For instance, the FreeBSD procfs supports /proc/<PID>/mem

The createdump doc says /proc doesn't work on FreeBSD. Can you confirm it? Thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, are there any places where it would be beneficial to pass an iovec array rather than just 1 element at a time to process_vm_readv()?

There are some parallel read operations, but they are invoked on ICLRDataTarget instead of DumpDataTarget. It's not easy to extend that interface.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote that createdump doc 2 or 3 years ago and at the time, it didn't look like FreeBSD supported /proc//mem but now I'm not sure.

@hoyosjs
hoyosjs requested review from hoyosjs and mikem8361 December 2, 2019 19:39
@nxtn nxtn changed the title createdump can read memory with process_vm_readv createdump can read memory with process_vm_readv on Linux Dec 3, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though we are sure of such a feature in most modern kernels, why not test for it in

check_function_exists(sigreturn HAVE_SIGRETURN)

That way we have this consistent, users can build for other platforms with no hard-coded elements, and makes bring-up platforms easier.

@hoyosjs

hoyosjs commented Dec 6, 2019

Copy link
Copy Markdown
Member

The changes look fine to me, thanks for the change :) Right now doing thorough testing is a little harder with the migration - we are not producing official drops we can consume in the broader test infrastructure. Once I get around to that I'll test this and let you know how it goes.

@lpereira
lpereira dismissed their stale review December 10, 2019 17:39

Conversations have been resolved.

@hoyosjs

hoyosjs commented Jan 28, 2020

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
You have several pipelines (over 10) configured to build pull requests in this repository. Specify which pipelines you would like to run by using /azp run [pipelines] command. You can specify multiple pipelines using a comma separated list.

@hoyosjs

hoyosjs commented Jan 28, 2020

Copy link
Copy Markdown
Member

/azp list

@hoyosjs

hoyosjs commented Jan 28, 2020

Copy link
Copy Markdown
Member

/azp run runtime

@hoyosjs
hoyosjs self-requested a review January 28, 2020 18:41
@ghost

ghost commented Jan 28, 2020

Copy link
Copy Markdown

Hello @hoyosjs!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

iovec remote{ (void*)(ULONG_PTR)address, size };
ssize_t read = process_vm_readv(m_pid, &local, 1, &remote, 1, 0);
#else
assert(m_fd != -1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikem8361 Any reason these are not runtime-like asserts?

@hoyosjs hoyosjs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only comment that sustains from @lpereira comments:

  • Check if size is bigger than IOV_MAX.
  • Check if read is safely castable. We can't easily use size_t on a COM boundary, but we can check for overflows as needed.

@mikem8361

mikem8361 commented Jan 28, 2020 via email

Copy link
Copy Markdown
Contributor

@hoyosjs
hoyosjs merged commit 531feac into dotnet:master Jan 28, 2020
@nxtn
nxtn deleted the createdump branch January 29, 2020 02:51
@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants