-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
nrf_security: cracen: Improve DCACHE handling #20419
Open
karstenkoenig
wants to merge
1
commit into
nrfconnect:main
Choose a base branch
from
karstenkoenig:dcache_cracen
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,7 +86,6 @@ void sx_blkcipher_free(struct sxblkcipher *c) | |
sx_cmdma_release_hw(&c->dma); | ||
} | ||
|
||
|
||
static int sx_blkcipher_hw_reserve(struct sxblkcipher *c) | ||
{ | ||
int err = SX_OK; | ||
|
@@ -149,8 +148,7 @@ static int sx_blkcipher_create_aesxts(struct sxblkcipher *c, const struct sxkeyr | |
mode = CMDMA_BLKCIPHER_MODE_SET(BLKCIPHER_MODEID_XTS); | ||
keyszfld = 0; | ||
|
||
sx_cmdma_newcmd(&c->dma, c->descs, | ||
KEYREF_AES_HWKEY_CONF(key1->cfg) | mode | keyszfld, | ||
sx_cmdma_newcmd(&c->dma, c->descs, KEYREF_AES_HWKEY_CONF(key1->cfg) | mode | keyszfld, | ||
c->cfg->dmatags->cfg); | ||
if (KEYREF_IS_USR(key1)) { | ||
ADD_CFGDESC(c->dma, key1->key, key1->sz, c->cfg->dmatags->key); | ||
|
@@ -240,8 +238,7 @@ int sx_blkcipher_create_aesctr_dec(struct sxblkcipher *c, const struct sxkeyref | |
return sx_blkcipher_create_aes_ba411(c, key, iv, &ba411ctrcfg, ba411ctrcfg.decr); | ||
} | ||
|
||
int sx_blkcipher_create_aesecb_enc(struct sxblkcipher *c, const struct sxkeyref *key | ||
) | ||
int sx_blkcipher_create_aesecb_enc(struct sxblkcipher *c, const struct sxkeyref *key) | ||
{ | ||
return sx_blkcipher_create_aes_ba411(c, key, NULL, &ba411ecbcfg, CM_CFG_ENCRYPT); | ||
} | ||
|
@@ -381,7 +378,9 @@ int sx_blkcipher_status(struct sxblkcipher *c) | |
} | ||
|
||
#if CONFIG_DCACHE | ||
sys_cache_data_invd_range((void *)&c->extramem, sizeof(c->extramem)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. invalidate range should be avoided as it could lead to memory loss on that cacheline if something else on the line was written by the core, e.g. if extramem is somewhere on the stack |
||
sx_cmdma_outdescs_flush_and_invd_dcache(&c->dma); | ||
/* extramem is often a target for out descriptors, this might not be needed anymore */ | ||
sys_cache_data_flush_and_invd_range((void *)&c->extramem, sizeof(c->extramem)); | ||
#endif | ||
|
||
sx_blkcipher_free(c); | ||
|
@@ -435,6 +434,8 @@ int sx_blkcipher_ecb_simple(uint8_t *key, size_t key_size, uint8_t *input, size_ | |
#if CONFIG_DCACHE | ||
sys_cache_data_flush_range(in_descs, sizeof(in_descs)); | ||
sys_cache_data_flush_range(&out_desc, sizeof(out_desc)); | ||
sys_cache_data_flush_range(&cmd, sizeof(cmd)); | ||
sys_cache_data_flush_range(key, key_size); | ||
sys_cache_data_flush_range(input, input_size); | ||
sys_cache_data_flush_range(output, output_size); | ||
#endif | ||
|
@@ -451,7 +452,7 @@ int sx_blkcipher_ecb_simple(uint8_t *key, size_t key_size, uint8_t *input, size_ | |
sx_cmdma_release_hw(NULL); | ||
|
||
#if CONFIG_DCACHE | ||
sys_cache_data_invd_range(output, output_size); | ||
sys_cache_data_flush_and_invd_range(output, output_size); | ||
#endif | ||
|
||
return r; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this patch it is my understanding that the driver would do this:
In this new version we will do this:
Won't the sys_cache_data_flush_and_invd_range overwrite what CRAECN just wrote to RAM? Or am I misreading this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm thanks for raising this to my attention again, I thought this would be perfect as
sys_cache_data_flush_and_invd_range
is the same as cache eviction and that might happen at any time anyways and makes sure all the data the core has written to gets properly stored. A cacheline can be shared between output buffer and other data structures from the core, and if the core wrote to that other data it isn't allowed to get lost either.But there is still chance for failure. The granularity for our data cache isn't a full cacheline, but a data unit, so sharing a cache line between local data structures and an output buffer for dma can be ok as long as the output buffer is 32bit aligned and is a multiple of 32bits in size.
But if the output buffer and some other date share the same dataunit in a cacheline you can get a conflict, but then both operations (data_flush_and_invd_range and invd_range) are wrong, as they both lead to a data loss, as this will either throw away the dirty memory inside the cores data cache, or write out the full 32bit word on a flush overwriting part of the output buffer. Need to take another round through this, and also the client side then.