Skip to content

Commit 7dc0e10

Browse files
Xu Yilunjgunthorpe
authored andcommitted
iommufd: Add a pre_destroy() op for objects
Add a pre_destroy() op which gives objects a chance to clear their short term users references before destruction. This op is intended for external driver created objects (e.g. idev) which does deterministic destruction. In order to manage the lifecycle of interrelated objects as well as the deterministic destruction (e.g. vdev can't outlive idev, and idev destruction can't fail), short term users references are allowed to live out of an ioctl execution. An immediate use case is, vdev holds idev's short term user reference until vdev destruction completes, idev leverages existing wait_shortterm mechanism to ensure it is destroyed after vdev. This extended usage makes the referenced object unable to just wait for its reference gone. It needs to actively trigger the reference removal, as well as prevent new references before wait. Should implement these work in pre_destroy(). Link: https://patch.msgid.link/r/[email protected] Suggested-by: Jason Gunthorpe <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Nicolin Chen <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Tested-by: Nicolin Chen <[email protected]> Signed-off-by: Xu Yilun <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent e6d41ee commit 7dc0e10

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/iommu/iommufd/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "iommufd_test.h"
2424

2525
struct iommufd_object_ops {
26+
void (*pre_destroy)(struct iommufd_object *obj);
2627
void (*destroy)(struct iommufd_object *obj);
2728
void (*abort)(struct iommufd_object *obj);
2829
};
@@ -160,6 +161,9 @@ static int iommufd_object_dec_wait_shortterm(struct iommufd_ctx *ictx,
160161
if (refcount_dec_and_test(&to_destroy->shortterm_users))
161162
return 0;
162163

164+
if (iommufd_object_ops[to_destroy->type].pre_destroy)
165+
iommufd_object_ops[to_destroy->type].pre_destroy(to_destroy);
166+
163167
if (wait_event_timeout(ictx->destroy_wait,
164168
refcount_read(&to_destroy->shortterm_users) == 0,
165169
msecs_to_jiffies(60000)))

0 commit comments

Comments
 (0)