aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Elisei <alexandru.elisei@arm.com>2020-04-14 15:39:46 +0100
committerWill Deacon <will@kernel.org>2020-04-15 16:27:59 +0100
commitbea6c33ca17c85c76e8455fb86e38036bdb2a928 (patch)
tree93b1b9d4eaf6823d1db74438fdc41306ab7838dc
parentc5e3c9ee46a49874a45a727181af708802fa0d60 (diff)
downloadkvmtool-bea6c33ca17c85c76e8455fb86e38036bdb2a928.tar.gz
ioport: Fail when registering overlapping ports
If we try to register a range of ports which overlaps with another, already registered, I/O ports region then device emulation for that region will not work anymore. There's nothing sane that the ioport emulation layer can do in this case so refuse to allocate the port. This matches the behavior of kvm__register_mmio. There's no need to protect allocating a new ioport struct with a lock, so move the lock to protect the actual ioport insertion in the tree. Reviewed-by: Andre Przywara <andre.przywara@arm.com> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com> Signed-off-by: Will Deacon <will@kernel.org>
-rw-r--r--ioport.c9
1 files changed, 1 insertions, 8 deletions
diff --git a/ioport.c b/ioport.c
index cb778ed8..d9f2e8ea 100644
--- a/ioport.c
+++ b/ioport.c
@@ -68,14 +68,6 @@ int ioport__register(struct kvm *kvm, u16 port, struct ioport_operations *ops, i
struct ioport *entry;
int r;
- br_write_lock(kvm);
-
- entry = ioport_search(&ioport_tree, port);
- if (entry) {
- pr_warning("ioport re-registered: %x", port);
- ioport_remove(&ioport_tree, entry);
- }
-
entry = malloc(sizeof(*entry));
if (entry == NULL)
return -ENOMEM;
@@ -90,6 +82,7 @@ int ioport__register(struct kvm *kvm, u16 port, struct ioport_operations *ops, i
},
};
+ br_write_lock(kvm);
r = ioport_insert(&ioport_tree, entry);
if (r < 0)
goto out_free;