* [PATCH 0/1] util: Make some iova_tree functions parameters const
@ 2021-10-12 15:50 Eugenio Pérez
2021-10-12 15:50 ` [PATCH 1/1] util: Make some iova_tree " Eugenio Pérez
0 siblings, 1 reply; 5+ messages in thread
From: Eugenio Pérez @ 2021-10-12 15:50 UTC (permalink / raw)
To: qemu-devel
Cc: Eduardo Habkost, Michael S. Tsirkin, qemu-trivial, Jason Wang,
Richard Henderson, Peter Xu, Paolo Bonzini
Some guidelines misses I found while working on Shadow Virtqueue, that
uses these functions at this moment.
Eugenio Pérez (1):
util: Make some iova_tree parameters const
include/qemu/iova-tree.h | 8 ++++----
hw/i386/intel_iommu.c | 2 +-
util/iova-tree.c | 10 +++++-----
3 files changed, 10 insertions(+), 10 deletions(-)
--
2.27.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/1] util: Make some iova_tree parameters const
2021-10-12 15:50 [PATCH 0/1] util: Make some iova_tree functions parameters const Eugenio Pérez
@ 2021-10-12 15:50 ` Eugenio Pérez
2021-10-12 21:35 ` Peter Xu
2021-10-12 22:21 ` Philippe Mathieu-Daudé
0 siblings, 2 replies; 5+ messages in thread
From: Eugenio Pérez @ 2021-10-12 15:50 UTC (permalink / raw)
To: qemu-devel
Cc: Eduardo Habkost, Michael S. Tsirkin, qemu-trivial, Jason Wang,
Richard Henderson, Peter Xu, Paolo Bonzini
As qemu guidelines:
Unless a pointer is used to modify the pointed-to storage, give it the
"const" attribute.
In the particular case of iova_tree_find it allows to enforce what is
requested by its comment, since the compiler would shout in case of
modifying or freeing the const-qualified returned pointer.
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
include/qemu/iova-tree.h | 8 ++++----
hw/i386/intel_iommu.c | 2 +-
util/iova-tree.c | 10 +++++-----
3 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/include/qemu/iova-tree.h b/include/qemu/iova-tree.h
index b66cf93c4b..8249edd764 100644
--- a/include/qemu/iova-tree.h
+++ b/include/qemu/iova-tree.h
@@ -59,7 +59,7 @@ IOVATree *iova_tree_new(void);
*
* Return: 0 if succeeded, or <0 if error.
*/
-int iova_tree_insert(IOVATree *tree, DMAMap *map);
+int iova_tree_insert(IOVATree *tree, const DMAMap *map);
/**
* iova_tree_remove:
@@ -74,7 +74,7 @@ int iova_tree_insert(IOVATree *tree, DMAMap *map);
*
* Return: 0 if succeeded, or <0 if error.
*/
-int iova_tree_remove(IOVATree *tree, DMAMap *map);
+int iova_tree_remove(IOVATree *tree, const DMAMap *map);
/**
* iova_tree_find:
@@ -92,7 +92,7 @@ int iova_tree_remove(IOVATree *tree, DMAMap *map);
* user is responsible to make sure the pointer is valid (say, no
* concurrent deletion in progress).
*/
-DMAMap *iova_tree_find(IOVATree *tree, DMAMap *map);
+const DMAMap *iova_tree_find(const IOVATree *tree, const DMAMap *map);
/**
* iova_tree_find_address:
@@ -105,7 +105,7 @@ DMAMap *iova_tree_find(IOVATree *tree, DMAMap *map);
*
* Return: same as iova_tree_find().
*/
-DMAMap *iova_tree_find_address(IOVATree *tree, hwaddr iova);
+const DMAMap *iova_tree_find_address(const IOVATree *tree, hwaddr iova);
/**
* iova_tree_foreach:
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 75f075547f..33a8af9191 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -1105,7 +1105,7 @@ static int vtd_page_walk_one(IOMMUTLBEvent *event, vtd_page_walk_info *info)
.translated_addr = entry->translated_addr,
.perm = entry->perm,
};
- DMAMap *mapped = iova_tree_find(as->iova_tree, &target);
+ const DMAMap *mapped = iova_tree_find(as->iova_tree, &target);
if (event->type == IOMMU_NOTIFIER_UNMAP && !info->notify_unmap) {
trace_vtd_page_walk_one_skip_unmap(entry->iova, entry->addr_mask);
diff --git a/util/iova-tree.c b/util/iova-tree.c
index 7990692cbd..8ca6af21cf 100644
--- a/util/iova-tree.c
+++ b/util/iova-tree.c
@@ -42,12 +42,12 @@ IOVATree *iova_tree_new(void)
return iova_tree;
}
-DMAMap *iova_tree_find(IOVATree *tree, DMAMap *map)
+const DMAMap *iova_tree_find(const IOVATree *tree, const DMAMap *map)
{
return g_tree_lookup(tree->tree, map);
}
-DMAMap *iova_tree_find_address(IOVATree *tree, hwaddr iova)
+const DMAMap *iova_tree_find_address(const IOVATree *tree, hwaddr iova)
{
DMAMap map = { .iova = iova, .size = 0 };
@@ -60,7 +60,7 @@ static inline void iova_tree_insert_internal(GTree *gtree, DMAMap *range)
g_tree_insert(gtree, range, range);
}
-int iova_tree_insert(IOVATree *tree, DMAMap *map)
+int iova_tree_insert(IOVATree *tree, const DMAMap *map)
{
DMAMap *new;
@@ -96,9 +96,9 @@ void iova_tree_foreach(IOVATree *tree, iova_tree_iterator iterator)
g_tree_foreach(tree->tree, iova_tree_traverse, iterator);
}
-int iova_tree_remove(IOVATree *tree, DMAMap *map)
+int iova_tree_remove(IOVATree *tree, const DMAMap *map)
{
- DMAMap *overlap;
+ const DMAMap *overlap;
while ((overlap = iova_tree_find(tree, map))) {
g_tree_remove(tree->tree, overlap);
--
2.27.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/1] util: Make some iova_tree parameters const
2021-10-12 15:50 ` [PATCH 1/1] util: Make some iova_tree " Eugenio Pérez
@ 2021-10-12 21:35 ` Peter Xu
2021-10-12 22:21 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 5+ messages in thread
From: Peter Xu @ 2021-10-12 21:35 UTC (permalink / raw)
To: Eugenio Pérez
Cc: Eduardo Habkost, Michael S. Tsirkin, qemu-trivial, Jason Wang,
Richard Henderson, qemu-devel, Paolo Bonzini
On Tue, Oct 12, 2021 at 05:50:01PM +0200, Eugenio Pérez wrote:
> As qemu guidelines:
> Unless a pointer is used to modify the pointed-to storage, give it the
> "const" attribute.
>
> In the particular case of iova_tree_find it allows to enforce what is
> requested by its comment, since the compiler would shout in case of
> modifying or freeing the const-qualified returned pointer.
>
> Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
Acked-by: Peter Xu <peterx@redhat.com>
--
Peter Xu
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/1] util: Make some iova_tree parameters const
2021-10-12 15:50 ` [PATCH 1/1] util: Make some iova_tree " Eugenio Pérez
2021-10-12 21:35 ` Peter Xu
@ 2021-10-12 22:21 ` Philippe Mathieu-Daudé
2021-10-13 18:26 ` Eugenio Perez Martin
1 sibling, 1 reply; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-10-12 22:21 UTC (permalink / raw)
To: Eugenio Pérez, qemu-devel
Cc: Eduardo Habkost, Michael S. Tsirkin, qemu-trivial, Jason Wang,
Richard Henderson, Peter Xu, Paolo Bonzini
On 10/12/21 17:50, Eugenio Pérez wrote:
> As qemu guidelines:
> Unless a pointer is used to modify the pointed-to storage, give it the
> "const" attribute.
>
> In the particular case of iova_tree_find it allows to enforce what is
> requested by its comment, since the compiler would shout in case of
> modifying or freeing the const-qualified returned pointer.
>
> Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> ---
> include/qemu/iova-tree.h | 8 ++++----
> hw/i386/intel_iommu.c | 2 +-
> util/iova-tree.c | 10 +++++-----
> 3 files changed, 10 insertions(+), 10 deletions(-)
> -DMAMap *iova_tree_find_address(IOVATree *tree, hwaddr iova)
> +const DMAMap *iova_tree_find_address(const IOVATree *tree, hwaddr iova)
> {
> DMAMap map = { .iova = iova, .size = 0 };
You missed this one ^
With it declared const:
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/1] util: Make some iova_tree parameters const
2021-10-12 22:21 ` Philippe Mathieu-Daudé
@ 2021-10-13 18:26 ` Eugenio Perez Martin
0 siblings, 0 replies; 5+ messages in thread
From: Eugenio Perez Martin @ 2021-10-13 18:26 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Eduardo Habkost, Michael S. Tsirkin, qemu-trivial, Jason Wang,
Richard Henderson, qemu-level, Peter Xu, Paolo Bonzini
On Wed, Oct 13, 2021 at 12:21 AM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> On 10/12/21 17:50, Eugenio Pérez wrote:
> > As qemu guidelines:
> > Unless a pointer is used to modify the pointed-to storage, give it the
> > "const" attribute.
> >
> > In the particular case of iova_tree_find it allows to enforce what is
> > requested by its comment, since the compiler would shout in case of
> > modifying or freeing the const-qualified returned pointer.
> >
> > Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> > ---
> > include/qemu/iova-tree.h | 8 ++++----
> > hw/i386/intel_iommu.c | 2 +-
> > util/iova-tree.c | 10 +++++-----
> > 3 files changed, 10 insertions(+), 10 deletions(-)
>
> > -DMAMap *iova_tree_find_address(IOVATree *tree, hwaddr iova)
> > +const DMAMap *iova_tree_find_address(const IOVATree *tree, hwaddr iova)
> > {
> > DMAMap map = { .iova = iova, .size = 0 };
>
> You missed this one ^
>
> With it declared const:
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>
Right! Sending v2.
Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-10-13 18:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-12 15:50 [PATCH 0/1] util: Make some iova_tree functions parameters const Eugenio Pérez
2021-10-12 15:50 ` [PATCH 1/1] util: Make some iova_tree " Eugenio Pérez
2021-10-12 21:35 ` Peter Xu
2021-10-12 22:21 ` Philippe Mathieu-Daudé
2021-10-13 18:26 ` Eugenio Perez Martin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).