Re: [PATCH v2] KVM: const-ify all relevant uses of struct kvm_memory_slot

From: Paolo Bonzini
Date: Mon Aug 02 2021 - 09:40:16 EST


On 31/07/21 00:27, Hamza Mahfooz wrote:
@@ -1440,7 +1440,7 @@ static bool kvm_set_pte_rmapp(struct kvm *kvm, struct kvm_rmap_head *rmap_head,
struct slot_rmap_walk_iterator {
/* input fields. */
- struct kvm_memory_slot *slot;
+ const struct kvm_memory_slot *slot;
gfn_t start_gfn;
gfn_t end_gfn;
int start_level;
@@ -1467,16 +1467,20 @@ rmap_walk_init_level(struct slot_rmap_walk_iterator *iterator, int level)
static void
slot_rmap_walk_init(struct slot_rmap_walk_iterator *iterator,
- struct kvm_memory_slot *slot, int start_level,
+ const struct kvm_memory_slot *slot, int start_level,
int end_level, gfn_t start_gfn, gfn_t end_gfn)
{
- iterator->slot = slot;
- iterator->start_level = start_level;
- iterator->end_level = end_level;
- iterator->start_gfn = start_gfn;
- iterator->end_gfn = end_gfn;
+ struct slot_rmap_walk_iterator iter = {
+ .slot = slot,
+ .start_gfn = start_gfn,
+ .end_gfn = end_gfn,
+ .start_level = start_level,
+ .end_level = end_level
+ };
+
+ rmap_walk_init_level(&iter, start_level);
- rmap_walk_init_level(iterator, iterator->start_level);
+ memcpy(iterator, &iter, sizeof(struct slot_rmap_walk_iterator));
}
static bool slot_rmap_walk_okay(struct slot_rmap_walk_iterator *iterator)

I don't understand, just changing the argument works. There is no need to change the body of the function.

Paolo