Sat Jul 29 23:50:03 2023 UTC ()
drm/linux_ww_mutex: Fix ww acquire context ordering.

XXX pullup-8
XXX pullup-9
XXX pullup-10


(riastradh)
diff -r1.15 -r1.16 src/sys/external/bsd/drm2/linux/linux_ww_mutex.c

cvs diff -r1.15 -r1.16 src/sys/external/bsd/drm2/linux/linux_ww_mutex.c (expand / switch to unified diff)

--- src/sys/external/bsd/drm2/linux/linux_ww_mutex.c 2023/07/29 22:43:56 1.15
+++ src/sys/external/bsd/drm2/linux/linux_ww_mutex.c 2023/07/29 23:50:03 1.16
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: linux_ww_mutex.c,v 1.15 2023/07/29 22:43:56 riastradh Exp $ */ 1/* $NetBSD: linux_ww_mutex.c,v 1.16 2023/07/29 23:50:03 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc. 4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Taylor R. Campbell. 8 * by Taylor R. Campbell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: linux_ww_mutex.c,v 1.15 2023/07/29 22:43:56 riastradh Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: linux_ww_mutex.c,v 1.16 2023/07/29 23:50:03 riastradh Exp $");
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/atomic.h> 36#include <sys/atomic.h>
37#include <sys/condvar.h> 37#include <sys/condvar.h>
38#include <sys/lockdebug.h> 38#include <sys/lockdebug.h>
39#include <sys/lwp.h> 39#include <sys/lwp.h>
40#include <sys/mutex.h> 40#include <sys/mutex.h>
41#include <sys/rbtree.h> 41#include <sys/rbtree.h>
42 42
43#include <linux/ww_mutex.h> 43#include <linux/ww_mutex.h>
44#include <linux/errno.h> 44#include <linux/errno.h>
45 45
46#define WW_WANTLOCK(WW) \ 46#define WW_WANTLOCK(WW) \
@@ -52,41 +52,41 @@ __KERNEL_RCSID(0, "$NetBSD: linux_ww_mut @@ -52,41 +52,41 @@ __KERNEL_RCSID(0, "$NetBSD: linux_ww_mut
52#define WW_UNLOCKED(WW) \ 52#define WW_UNLOCKED(WW) \
53 LOCKDEBUG_UNLOCKED((WW)->wwm_debug, (WW), \ 53 LOCKDEBUG_UNLOCKED((WW)->wwm_debug, (WW), \
54 (uintptr_t)__builtin_return_address(0), 0) 54 (uintptr_t)__builtin_return_address(0), 0)
55 55
56static int 56static int
57ww_acquire_ctx_compare(void *cookie __unused, const void *va, const void *vb) 57ww_acquire_ctx_compare(void *cookie __unused, const void *va, const void *vb)
58{ 58{
59 const struct ww_acquire_ctx *const ctx_a = va; 59 const struct ww_acquire_ctx *const ctx_a = va;
60 const struct ww_acquire_ctx *const ctx_b = vb; 60 const struct ww_acquire_ctx *const ctx_b = vb;
61 61
62 if (ctx_a->wwx_ticket < ctx_b->wwx_ticket) 62 if (ctx_a->wwx_ticket < ctx_b->wwx_ticket)
63 return -1; 63 return -1;
64 if (ctx_a->wwx_ticket > ctx_b->wwx_ticket) 64 if (ctx_a->wwx_ticket > ctx_b->wwx_ticket)
65 return -1; 65 return +1;
66 return 0; 66 return 0;
67} 67}
68 68
69static int 69static int
70ww_acquire_ctx_compare_key(void *cookie __unused, const void *vn, 70ww_acquire_ctx_compare_key(void *cookie __unused, const void *vn,
71 const void *vk) 71 const void *vk)
72{ 72{
73 const struct ww_acquire_ctx *const ctx = vn; 73 const struct ww_acquire_ctx *const ctx = vn;
74 const uint64_t *const ticketp = vk, ticket = *ticketp; 74 const uint64_t *const ticketp = vk, ticket = *ticketp;
75 75
76 if (ctx->wwx_ticket < ticket) 76 if (ctx->wwx_ticket < ticket)
77 return -1; 77 return -1;
78 if (ctx->wwx_ticket > ticket) 78 if (ctx->wwx_ticket > ticket)
79 return -1; 79 return +1;
80 return 0; 80 return 0;
81} 81}
82 82
83static const rb_tree_ops_t ww_acquire_ctx_rb_ops = { 83static const rb_tree_ops_t ww_acquire_ctx_rb_ops = {
84 .rbto_compare_nodes = &ww_acquire_ctx_compare, 84 .rbto_compare_nodes = &ww_acquire_ctx_compare,
85 .rbto_compare_key = &ww_acquire_ctx_compare_key, 85 .rbto_compare_key = &ww_acquire_ctx_compare_key,
86 .rbto_node_offset = offsetof(struct ww_acquire_ctx, wwx_rb_node), 86 .rbto_node_offset = offsetof(struct ww_acquire_ctx, wwx_rb_node),
87 .rbto_context = NULL, 87 .rbto_context = NULL,
88}; 88};
89 89
90void 90void
91ww_acquire_init(struct ww_acquire_ctx *ctx, struct ww_class *class) 91ww_acquire_init(struct ww_acquire_ctx *ctx, struct ww_class *class)
92{ 92{