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

Fix hash_lock / keystore.sk_dk_lock lock inversion #7115

Merged
merged 1 commit into from
Feb 4, 2018

Conversation

behlendorf
Copy link
Contributor

@behlendorf behlendorf commented Feb 2, 2018

Description

The keystore.sk_dk_lock should not be held while performing I/O. Drop the lock when reading from disk and update the code so they the first successful caller adds the key.

Motivation and Context

#7112

How Has This Been Tested?

Locally built, overnight ztest run underway.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (a change to man pages or other documentation)

Checklist:

  • My code follows the ZFS on Linux code style requirements.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • All commit messages are properly formatted and contain Signed-off-by.
  • Change has been approved by a ZFS on Linux member.

@behlendorf behlendorf requested a review from tcaputi February 2, 2018 01:45
Copy link
Contributor

@tcaputi tcaputi left a comment

Choose a reason for hiding this comment

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

LGTM. This solution is a lot better than the previous one.

/* Lookup the key in the tree of currently loaded keys */
rw_enter(&spa->spa_keystore.sk_dk_lock, RW_READER);
ret = spa_keystore_dsl_key_hold_impl(spa, dckobj, tag, &dck_ks);
rw_exit(&spa->spa_keystore.sk_dk_lock);
if (!ret) {
Copy link
Contributor

Choose a reason for hiding this comment

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

probably should change this to ret == 0 while we're here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do

The keystore.sk_dk_lock should not be held while performing I/O.
Drop the lock when reading from disk and update the code so
they the first successful caller adds the lock.

Improve error handling in spa_keystore_create_mapping_impl().

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
TEST_ZTEST_TIMEOUT=3600
Issue openzfs#7112
@behlendorf behlendorf force-pushed the ztest-keystore-deadlock2 branch from 1cacf7d to b2d2ea0 Compare February 2, 2018 20:42
@behlendorf
Copy link
Contributor Author

@tcaputi I've refresh this can you look at it again.

Copy link
Contributor

@tcaputi tcaputi left a comment

Choose a reason for hiding this comment

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

LGTM

@codecov
Copy link

codecov bot commented Feb 3, 2018

Codecov Report

Merging #7115 into master will decrease coverage by 0.1%.
The diff coverage is 80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7115      +/-   ##
==========================================
- Coverage   75.43%   75.33%   -0.11%     
==========================================
  Files         296      296              
  Lines       95912    95910       -2     
==========================================
- Hits        72355    72253     -102     
- Misses      23557    23657     +100
Flag Coverage Δ
#kernel 74.84% <80%> (+0.13%) ⬆️
#user 67.39% <80%> (-0.11%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1b66810...b2d2ea0. Read the comment docs.

@sempervictus
Copy link
Contributor

Zlooped for the last ~4h, no sudden death yet.

@mailinglists35
Copy link

is this going to be included in 0.7.6 release?

@tcaputi
Copy link
Contributor

tcaputi commented Feb 3, 2018

is this going to be included in 0.7.6 release?

Encryption is not going to be included at all until 0.8.0.

@behlendorf behlendorf merged commit 0d23f5e into openzfs:master Feb 4, 2018
Nasf-Fan pushed a commit to Nasf-Fan/zfs that referenced this pull request Feb 13, 2018
The keystore.sk_dk_lock should not be held while performing I/O.
Drop the lock when reading from disk and update the code so
they the first successful caller adds the key.

Improve error handling in spa_keystore_create_mapping_impl().

Reviewed by: Thomas Caputi <tcaputi@datto.com>
Reviewed-by: RageLtMan <rageltman@sempervictus>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes openzfs#7112
Closes openzfs#7115
@behlendorf behlendorf deleted the ztest-keystore-deadlock2 branch April 19, 2021 19:30
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

Successfully merging this pull request may close these issues.

4 participants