Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User provided ioctl() write mask is ignored #38

Closed
cmcantalupo opened this issue Apr 30, 2018 · 8 comments
Closed

User provided ioctl() write mask is ignored #38

cmcantalupo opened this issue Apr 30, 2018 · 8 comments

Comments

@cmcantalupo
Copy link
Contributor

I believe this needs to be "&=" not "=" otherwise you are ignoring the user's request to only write a subset of the bits in the MSR.

op->wmask = msr_whitelist_writemask(op->msr);

As it is written, if someone provides a write mask in the ioctl structure that sets only the first 14 bits of the MSR_PKG_POWER_LIMIT msr, but the white list gives permission to write the entire register, then when they call into the batch ioctl all bits above bit 14 will be zeroed in the register.

@mcfadden8
Copy link
Collaborator

How do we determine how many bits the user wishes to write? We allow for the user to be able to write a 0 or 1 to any of the bits defined in the write mask. If I recall correctly, there are not presently semantics for the user to say they only want to write the first 14 bits of the MSR.

@cmcantalupo
Copy link
Contributor Author

cmcantalupo commented May 1, 2018

I had misinterpreted the msr_batch_op.wmask:

__u64 wmask; // Out: Write mask applied to wrmsr

as an input parameter to the ioctl. It says right there in the comment that it is an out parameter.

Can the implementation be changed so that this is an input parameter? Then you could just &= the user mask with the one from the whitelist before doing the read-modify-write in the driver. The call could set the msr_batch_op.err if the provided mask was not a subset of the whitelist mask.

The alternative would be user trying to do the read-modify-write with batch operations to the ioctl().

@cmcantalupo cmcantalupo changed the title User provided IOCTL write mask is ignored User provided ioctl() write mask is ignored May 1, 2018
@cmcantalupo
Copy link
Contributor Author

cmcantalupo commented May 1, 2018

Something like the commit below should do the trick:
cmcantalupo@ba57451

@mcfadden8
Copy link
Collaborator

mcfadden8 commented May 1, 2018

Overall, I like the proposed changes.

Modifying the wmask to be an IN parameter allows the user to specify exactly which bits they intend to write in the MSR and the proposed check will make sure that the user is allowed to change all of those bits.

@rountree, @slabasan, we need to take care that this change doesn't have unintended consequences on other applications that may be assuming the previous semantics. Do we know how many folks are using the batch interface for writing MSRs?

Also, how do we make sure that this is consistently carried out in the write() interface? The write() interface does not currently allow a means for specifying which bits are intended to be written.

@cmcantalupo
Copy link
Contributor Author

In the case of the non-batched approach, it is quite feasible to do the read-modify-write in user space. (pread(), modify, pwrite()). Since the pwrite() interface does not allow for masking at a finer granularity than bytes, it is not really feasible to translate this feature to the pwrite() semantics.

@mcfadden8
Copy link
Collaborator

I agree that we would need to leave the seek()/read()/write() mechanism as needing to interact with the entire MSR word. There is a side-effect in the current implementation that a user might assume they are able to write a certain set of bits when, in fact, they will only be allowed to alter a subset of those bits depending upon the whitelist mask.

@cmcantalupo
Copy link
Contributor Author

Added a pull request here:

#40

and I'm adding this patch to the OpenHPC distro of msr-safe.

@slabasan
Copy link
Collaborator

slabasan commented Oct 3, 2022

Closing this PR, issue has been resolved.

@slabasan slabasan closed this as completed Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants