Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(789)

Side by Side Diff: dm-bht.c

Issue 5361004: CHROMIUM: verity: Cleanup dm_bht_verify_path. (Closed) Base URL: http://git.chromium.org/git/dm-verity.git@master
Patch Set: Fix per codereview. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 The Chromium OS Authors <chromium-os-dev@chromium.org> 2 * Copyright (C) 2010 The Chromium OS Authors <chromium-os-dev@chromium.org>
3 * 3 *
4 * Device-Mapper block hash tree interface. 4 * Device-Mapper block hash tree interface.
5 * See Documentation/device-mapper/dm-bht.txt for details. 5 * See Documentation/device-mapper/dm-bht.txt for details.
6 * 6 *
7 * This file is released under the GPL. 7 * This file is released under the GPL.
8 */ 8 */
9 9
10 #include <asm/atomic.h> 10 #include <asm/atomic.h>
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 return leaf >> dm_bht_get_level_shift(bht, depth); 148 return leaf >> dm_bht_get_level_shift(bht, depth);
149 } 149 }
150 150
151 static __always_inline u8 *dm_bht_node(struct dm_bht *bht, 151 static __always_inline u8 *dm_bht_node(struct dm_bht *bht,
152 struct dm_bht_entry *entry, 152 struct dm_bht_entry *entry,
153 unsigned int node_index) 153 unsigned int node_index)
154 { 154 {
155 return &entry->nodes[node_index * bht->digest_size]; 155 return &entry->nodes[node_index * bht->digest_size];
156 } 156 }
157 157
158 static inline struct dm_bht_entry *dm_bht_get_entry(struct dm_bht *bht,
159 unsigned int depth,
160 unsigned int block_index)
161 {
162 unsigned int index = dm_bht_index_at_level(bht, depth, block_index);
163 struct dm_bht_level *level = dm_bht_get_level(bht, depth);
164
165 BUG_ON(index >= level->count);
166
167 return &level->entries[index];
168 }
169
170 static inline u8 *dm_bht_get_node(struct dm_bht *bht,
171 struct dm_bht_entry *parent,
Will Drewry 2010/11/30 19:30:27 does it make sense to call this 'parent' and not j
Mandeep Singh Baines 2010/11/30 23:11:51 Agree. Fixed.
172 unsigned int depth,
173 unsigned int block_index)
174 {
175 unsigned int index = dm_bht_index_at_level(bht, depth, block_index);
176 struct dm_bht_level *level = dm_bht_get_level(bht, depth);
177
178 BUG_ON(index >= level->count);
179
180 return dm_bht_node(bht, parent, index % bht->node_count);
181 }
182
158 183
159 /*----------------------------------------------- 184 /*-----------------------------------------------
160 * Implementation functions 185 * Implementation functions
161 *-----------------------------------------------*/ 186 *-----------------------------------------------*/
162 187
163 static int dm_bht_initialize_entries(struct dm_bht *bht); 188 static int dm_bht_initialize_entries(struct dm_bht *bht);
164 189
165 static int dm_bht_read_callback_stub(void *ctx, sector_t start, u8 *dst, 190 static int dm_bht_read_callback_stub(void *ctx, sector_t start, u8 *dst,
166 sector_t count, 191 sector_t count,
167 struct dm_bht_entry *entry); 192 struct dm_bht_entry *entry);
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 atomic_set(&bht->root_state, DM_BHT_ENTRY_VERIFIED); 712 atomic_set(&bht->root_state, DM_BHT_ENTRY_VERIFIED);
688 return 0; 713 return 0;
689 } 714 }
690 715
691 /* dm_bht_verify_path 716 /* dm_bht_verify_path
692 * Verifies the path from block_index to depth=0. Returns 0 on ok. 717 * Verifies the path from block_index to depth=0. Returns 0 on ok.
693 */ 718 */
694 static int dm_bht_verify_path(struct dm_bht *bht, unsigned int block_index, 719 static int dm_bht_verify_path(struct dm_bht *bht, unsigned int block_index,
695 dm_bht_compare_cb compare_cb) 720 dm_bht_compare_cb compare_cb)
696 { 721 {
697 » unsigned int depth = bht->depth; 722 » unsigned int depth = bht->depth - 1;
698 » struct dm_bht_level *level; 723 » struct dm_bht_entry *entry = dm_bht_get_entry(bht, depth, block_index);
699 » struct dm_bht_entry *entry; 724 » struct hash_desc *hash_desc = &bht->hash_desc[smp_processor_id()];
700 » struct dm_bht_entry *parent = NULL;
701 » u8 *node;
702 » unsigned int node_index;
703 » unsigned int entry_index;
704 » unsigned int parent_index = 0; /* for logging */
705 » struct hash_desc *hash_desc;
706 » int state;
707 » int ret = 0;
708 725
709 » hash_desc = &bht->hash_desc[smp_processor_id()]; 726 » while (depth > 0) {
710 » while (depth-- > 0) { 727 » » struct dm_bht_entry *parent;
711 » » level = dm_bht_get_level(bht, depth); 728 » » u8 *node;
712 » » entry_index = dm_bht_index_at_level(bht, depth, block_index); 729 » » int state;
713 » » DMDEBUG("verify_path for bi=%u on d=%d ei=%u (max=%u)",
714 » » » block_index, depth, entry_index, level->count);
715 » » BUG_ON(entry_index >= level->count);
716 » » entry = &level->entries[entry_index];
717 730
718 » » /* Catch any existing errors */ 731 » » DMDEBUG("verify_path for bi=%u on d=%d", block_index, depth);
732
719 state = atomic_read(&entry->state); 733 state = atomic_read(&entry->state);
720 » » if (state <= DM_BHT_ENTRY_ERROR) { 734 » » if (state == DM_BHT_ENTRY_VERIFIED) {
721 » » » DMCRIT("entry(d=%u,idx=%u) is in an error state: %d", 735 » » » DMDEBUG("verify_path node %u is verified in parent",
722 » » » depth, entry_index, state); 736 » » » » block_index);
737 » » » entry = dm_bht_get_entry(bht, --depth, block_index);
738 » » » continue;
739 » » } else if (state <= DM_BHT_ENTRY_ERROR) {
740 » » » DMCRIT("entry(d=%u,b=%u) is in an error state: %d",
741 » » » depth, block_index, state);
723 DMCRIT("verification is not possible"); 742 DMCRIT("verification is not possible");
724 » » » ret = 1; 743 » » » return 1;
Will Drewry 2010/11/30 19:30:27 This is counter to the current kernel style guidel
725 » » » break;
726 } else if (state <= DM_BHT_ENTRY_PENDING) { 744 } else if (state <= DM_BHT_ENTRY_PENDING) {
727 » » » DMERR("entry not ready for verify: d=%u,e=%u", 745 » » » DMERR("entry not ready for verify: d=%u,b=%u",
728 » » » depth, entry_index); 746 » » » depth, block_index);
729 » » » ret = 1; 747 » » » return 1;
730 » » » break;
731 } 748 }
732 749
733 /* At depth 0, we're at the page underneath the root node and 750 /* At depth 0, we're at the page underneath the root node and
734 * leave its validation to a separate path. 751 * leave its validation to a separate path.
735 */ 752 */
736 if (depth == 0) 753 if (depth == 0)
737 break; 754 break;
738 755
739 /* Grab the parent entry where the current entry hash is. */
740 parent_index = dm_bht_index_at_level(bht, depth - 1,
741 block_index);
742 level = dm_bht_get_level(bht, depth - 1);
743 BUG_ON(parent_index >= level->count);
744 parent = &level->entries[parent_index];
745
746 /* Because we are one level down, the node_index into the
747 * the parent's node list modulo the number of nodes.
748 */
749 node_index = entry_index % bht->node_count;
750
751 /* If the nodes in entry have already been checked against the
752 * parent, then we're done.
753 */
754 if (state == DM_BHT_ENTRY_VERIFIED) {
755 DMDEBUG("verify_path node %u is verified in parent %u",
756 node_index, parent_index);
757 /* If this entry has been checked, move along. */
758 continue;
759 }
760
761 /* We need to check that this entry matches the expected 756 /* We need to check that this entry matches the expected
762 * hash in the parent->nodes. 757 * hash in the parent->nodes.
763 */ 758 */
764 » » node = dm_bht_node(bht, parent, node_index); 759 » » parent = dm_bht_get_entry(bht, depth - 1, block_index);
765 » » DMDEBUG("verify_path: node is not verified in parent " 760 » » BUG_ON(atomic_read(&parent->state) < DM_BHT_ENTRY_READY);
Will Drewry 2010/11/30 19:30:27 It'd be worth updating the comment above the funct
766 » » "(d=%u,ei=%u,p=%u,pnode=%u)", 761 » » node = dm_bht_get_node(bht, parent, depth, block_index);
767 » » depth, entry_index, parent_index, node_index);
768 762
769 if (dm_bht_compute_and_compare(bht, hash_desc, 763 if (dm_bht_compute_and_compare(bht, hash_desc,
770 virt_to_page(entry->nodes), 764 virt_to_page(entry->nodes),
771 node, compare_cb)) { 765 node, compare_cb)) {
772 DMERR("failed to verify entry's hash against parent " 766 DMERR("failed to verify entry's hash against parent "
773 » » » "(d=%u,ei=%u,p=%u,pnode=%u)", 767 » » » "(d=%u,bi=%u)", depth, block_index);
Will Drewry 2010/11/30 19:30:27 Not a huge fan of losing the debugging insight, bu
Mandeep Singh Baines 2010/11/30 23:11:51 Its not totally lost. You should be able to derive
774 » » » depth, entry_index, parent_index, node_index); 768 » » » return DM_BHT_ENTRY_ERROR_MISMATCH;
Will Drewry 2010/11/30 19:30:27 As per the comment on the return earlier, this cou
775 » » » ret = DM_BHT_ENTRY_ERROR_MISMATCH;
776 » » » break;
777 } 769 }
778 770
779 /* Instead of keeping a bitmap of which children have been
780 * checked, this data is kept in the child state. If full
781 * reverifies have been set, then no intermediate entry/node is
782 * ever marked as verified.
783 */
784 if (bht->verify_mode != DM_BHT_FULL_REVERIFY) 771 if (bht->verify_mode != DM_BHT_FULL_REVERIFY)
Will Drewry 2010/11/30 19:30:27 We could also make this a single call too: void d
Mandeep Singh Baines 2010/11/30 23:11:51 Could we now just: BUG_ON(atomic_read(&entry->sta
785 atomic_cmpxchg(&entry->state, 772 atomic_cmpxchg(&entry->state,
786 DM_BHT_ENTRY_READY, 773 DM_BHT_ENTRY_READY,
787 DM_BHT_ENTRY_VERIFIED); 774 DM_BHT_ENTRY_VERIFIED);
775
776 entry = parent;
777 depth--;
788 } 778 }
789 » return ret; 779
780 » return 0;
790 } 781 }
791 782
792 /** 783 /**
793 * dm_bht_store_block - sets a given block's hash in the tree 784 * dm_bht_store_block - sets a given block's hash in the tree
794 * @bht: pointer to a dm_bht_create()d bht 785 * @bht: pointer to a dm_bht_create()d bht
795 * @block_index:numeric index of the block in the tree 786 * @block_index:numeric index of the block in the tree
796 * @digest: array of u8s containing the digest of length @bht->digest_size 787 * @digest: array of u8s containing the digest of length @bht->digest_size
797 * 788 *
798 * Returns 0 on success, >0 when data is pending, and <0 when a IO or other 789 * Returns 0 on success, >0 when data is pending, and <0 when a IO or other
799 * error has occurred. 790 * error has occurred.
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 DMERR("no root digest exists to export"); 1293 DMERR("no root digest exists to export");
1303 if (available > 0) 1294 if (available > 0)
1304 *hexdigest = 0; 1295 *hexdigest = 0;
1305 return -1; 1296 return -1;
1306 } 1297 }
1307 dm_bht_bin_to_hex(bht->root_digest, hexdigest, bht->digest_size); 1298 dm_bht_bin_to_hex(bht->root_digest, hexdigest, bht->digest_size);
1308 return 0; 1299 return 0;
1309 } 1300 }
1310 EXPORT_SYMBOL(dm_bht_root_hexdigest); 1301 EXPORT_SYMBOL(dm_bht_root_hexdigest);
1311 1302
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698