drm/i915: Rework sdvo proxy i2c locking
Subsystems (2)
PATCH 1/1 drm/i915: Rework sdvo proxy i2c locking
lockdep complaints about a locking recursion for the i2c bus lock because both the sdvo ddc proxy bus and the gmbus nested within use the same locking class. It's not really a deadlock since we never nest the other way round, but it's annoying.
Fix it by pulling the gmbus locking into the i2c lock_ops for both i2c_adapater and making sure that the ddc_proxy_xfer function is entirely lockless.
Re-layouting the extracted function resulted in some whitespace cleanups, I figured we might as well keep them.
--- drivers/gpu/drm/i915/intel_i2c.c | 36 +++++++++++++++++++-- drivers/gpu/drm/i915/intel_sdvo.c | 68 ++++++++++++++++++++++++++++++++------- 2 files changed, 90 insertions(+), 14 deletions(-)
drivers/gpu/drm/i915/intel_i2c.c +34 -2
@@ -592,7 +592,6 @@ gmbus_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num)int ret;intel_display_power_get (dev_priv,POWER_DOMAIN_GMBUS ); -mutex_lock (&dev_priv->gmbus_mutex);if (bus->force_bit) { ret = i2c_bit_algo.master_xfer (adapter, msgs, num);
@@ -604,7 +603,6 @@ gmbus_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num) bus->force_bit |=GMBUS_FORCE_BIT_RETRY ; } -mutex_unlock (&dev_priv->gmbus_mutex);intel_display_power_put (dev_priv,POWER_DOMAIN_GMBUS );return ret;
@@ -624,6 +622,39 @@ static const struct i2c_algorithm gmbus_algorithm = { .functionality = gmbus_func }; +static void gmbus_lock_bus (struct i2c_adapter *adapter, +unsigned int flags) +{ +struct intel_gmbus *bus =to_intel_gmbus (adapter); +struct drm_i915_private *dev_priv = bus->dev_priv; + +mutex_lock (&dev_priv->gmbus_mutex); +} + +static int gmbus_trylock_bus (struct i2c_adapter *adapter, +unsigned int flags) +{ +struct intel_gmbus *bus =to_intel_gmbus (adapter); +struct drm_i915_private *dev_priv = bus->dev_priv; + +return mutex_trylock (&dev_priv->gmbus_mutex); +} + +static void gmbus_unlock_bus (struct i2c_adapter *adapter, +unsigned int flags) +{ +struct intel_gmbus *bus =to_intel_gmbus (adapter); +struct drm_i915_private *dev_priv = bus->dev_priv; + +mutex_unlock (&dev_priv->gmbus_mutex); +} + +const struct i2c_lock_operations gmbus_lock_ops = { + .lock_bus = gmbus_lock_bus, + .trylock_bus = gmbus_trylock_bus, + .unlock_bus = gmbus_unlock_bus, +}; +/** * intel_gmbus_setup - instantiate all Intel i2c GMBuses * @dev_priv: i915 device private
@@ -665,6 +696,7 @@ int intel_setup_gmbus(struct drm_i915_private *dev_priv) bus->dev_priv = dev_priv; bus->adapter.algo = &gmbus_algorithm; + bus->adapter.lock_ops = &gmbus_lock_ops;/* * We wish to retry with bit banging
drivers/gpu/drm/i915/intel_sdvo.c +56 -12
124 lines not on this page · raw message
Signature · 6 lines
2.13.3 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✓ Fi.CI.BAT: success for drm/i915: Rework sdvo proxy i2c locking
== Series Details ==
== Series Details ==
Series: drm/i915: Rework sdvo proxy i2c locking
URL : https://patchwork.freedesktop.org/series/27907/
State : success
== Summary ==
Series 27907v1 drm/i915: Rework sdvo proxy i2c locking
https://patchwork.freedesktop.org/api/1.0/series/27907/revisions/1/mbox/
Test kms_pipe_crc_basic:
Subgroup hang-read-crc-pipe-a:
pass -> DMESG-WARN (fi-pnv-d510) fdo#101597
Subgroup suspend-read-crc-pipe-b:
dmesg-warn -> PASS (fi-byt-n2820) fdo#101705fdo#101597 https://bugs.freedesktop.org/show_bug.cgi?id=101597
fdo#101705 https://bugs.freedesktop.org/show_bug.cgi?id=101705
fi-bdw-5557u total:280 pass:269 dwarn:0 dfail:0 fail:0 skip:11 time:447s fi-blb-e6850 total:280 pass:225 dwarn:1 dfail:0 fail:0 skip:54 time:358s fi-bsw-n3050 total:280 pass:244 dwarn:0 dfail:0 fail:0 skip:36 time:538s fi-bxt-j4205 total:280 pass:261 dwarn:0 dfail:0 fail:0 skip:19 time:513s fi-byt-j1900 total:280 pass:255 dwarn:1 dfail:0 fail:0 skip:24 time:492s fi-byt-n2820 total:280 pass:252 dwarn:0 dfail:0 fail:0 skip:28 time:492s fi-glk-2a total:280 pass:261 dwarn:0 dfail:0 fail:0 skip:19 time:601s fi-hsw-4770 total:280 pass:264 dwarn:0 dfail:0 fail:0 skip:16 time:444s fi-hsw-4770r total:280 pass:264 dwarn:0 dfail:0 fail:0 skip:16 time:418s fi-ilk-650 total:280 pass:230 dwarn:0 dfail:0 fail:0 skip:50 time:423s fi-ivb-3520m total:280 pass:262 dwarn:0 dfail:0 fail:0 skip:18 time:498s fi-ivb-3770 total:280 pass:262 dwarn:0 dfail:0 fail:0 skip:18 time:477s fi-kbl-7500u total:280 pass:262 dwarn:0 dfail:0 fail:0 skip:18 time:463s fi-kbl-7560u total:280 pass:270 dwarn:0 dfail:0 fail:0 skip:10 time:575s fi-kbl-r total:280 pass:262 dwarn:0 dfail:0 fail:0 skip:18 time:582s fi-pnv-d510 total:280 pass:222 dwarn:3 dfail:0 fail:0 skip:55 time:569s fi-skl-6260u total:280 pass:270 dwarn:0 dfail:0 fail:0 skip:10 time:462s fi-skl-6700hq total:280 pass:263 dwarn:0 dfail:0 fail:0 skip:17 time:600s fi-skl-6700k total:280 pass:262 dwarn:0 dfail:0 fail:0 skip:18 time:472s fi-skl-6770hq total:280 pass:270 dwarn:0 dfail:0 fail:0 skip:10 time:474s fi-skl-gvtdvm total:280 pass:266 dwarn:1 dfail:0 fail:0 skip:13 time:438s fi-skl-x1585l total:280 pass:269 dwarn:0 dfail:0 fail:0 skip:11 time:475s fi-snb-2520m total:280 pass:252 dwarn:0 dfail:0 fail:0 skip:28 time:548s fi-snb-2600 total:280 pass:251 dwarn:0 dfail:0 fail:0 skip:29 time:405s
fb7cda75b61e4ab4243dad8a23475d1c39ccb333 drm-tip: 2017y-07m-25d-17h-49m-38s UTC integration manifest f17a05e05c84 drm/i915: Rework sdvo proxy i2c locking
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_5279/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoting Daniel Vetter (2017-07-26 07:02:44)
Quoted 49 lines
lockdep complaints about a locking recursion for the i2c bus lock because both the sdvo ddc proxy bus and the gmbus nested within use the same locking class. It's not really a deadlock since we never nest the other way round, but it's annoying.
Fix it by pulling the gmbus locking into the i2c
lock_opsfor bothi2c_adapaterand making sure that theddc_proxy_xferfunction is entirely lockless.Re-layouting the extracted function resulted in some whitespace cleanups, I figured we might as well keep them.
Signed-off-by Daniel Vetter <[email protected]>---
drivers/gpu/drm/i915/intel_sdvo.c +6
-5@@ -451,23 +451,24 @@ static const char * const cmd_status_names[] = { "Scaling not supported" }; -static bool intel_sdvo_write_cmd (struct intel_sdvo *intel_sdvo,u8 cmd, -const void *args,int args_len) +static bool __intel_sdvo_write_cmd (struct intel_sdvo *intel_sdvo,u8 cmd, +const void *args,int args_len, +bool locked) {u8 *buf, status;struct i2c_msg *msgs;int i, ret = true; -/* Would be simpler to allocate both in one go ? */ +/* Would be simpler to allocate both in one go ? */ buf =kzalloc (args_len *2 +2 ,GFP_KERNEL );if (!buf)return false; msgs =kcalloc (args_len +3 ,sizeof (*msgs),GFP_KERNEL );if (!msgs) { -kfree (buf); +kfree (buf);return false; - } + }intel_sdvo_debug_write (intel_sdvo, cmd, args, args_len);
drivers/gpu/drm/i915/intel_sdvo.c static bool intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd, · line 502
Quoted 5 lines
drivers/gpu/drm/i915/intel_sdvo.c +1
-1@@ -498,7 +499,10 @@ static bool intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd, msgs[i+2 ].len =1 ; msgs[i+2 ].buf = &status; - ret =i2c_transfer (intel_sdvo->i2c, msgs, i+3 ); +if (locked)
locked=true is called from the unlocked context, very confusing.
Quoted 48 lines
drivers/gpu/drm/i915/intel_sdvo.c +15
-6+ ret =i2c_transfer (intel_sdvo->i2c, msgs, i+3 ); + else + ret =__i2c_transfer (intel_sdvo->i2c, msgs, i+3 );if (ret <0 ) {DRM_DEBUG_KMS ("I2c transfer returned %d\n" , ret); ret = false;@@ -516,6 +520,12 @@ static bool intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd,return ret; } +static bool intel_sdvo_write_cmd (struct intel_sdvo *intel_sdvo,u8 cmd, +const void *args,int args_len) +{ +return __intel_sdvo_write_cmd (intel_sdvo, cmd, args, args_len, true); +} +static bool intel_sdvo_read_response (struct intel_sdvo *intel_sdvo,void *response,int response_len) {@@ -602,13 +612,13 @@ static int intel_sdvo_get_pixel_multiplier(const struct drm_display_mode *adjustreturn 4 ; } -static bool intel_sdvo_set_control_bus_switch (struct intel_sdvo *intel_sdvo, -u8 ddc_bus) +static bool __intel_sdvo_set_control_bus_switch (struct intel_sdvo *intel_sdvo, +u8 ddc_bus) {/* This must be the immediately preceding write before the i2c xfer */ -return intel_sdvo_write_cmd (intel_sdvo, -SDVO_CMD_SET_CONTROL_BUS_SWITCH , - &ddc_bus,1 ); +return __intel_sdvo_write_cmd (intel_sdvo, +SDVO_CMD_SET_CONTROL_BUS_SWITCH , + &ddc_bus,1 , false); }static bool intel_sdvo_set_value (struct intel_sdvo *intel_sdvo,u8 cmd,const void *data,int len)@@ -2934,7 +2944,7 @@ static int intel_sdvo_ddc_proxy_xfer(struct i2c_adapter *adapter, {struct intel_sdvo *sdvo = adapter->algo_data; -if (!intel_sdvo_set_control_bus_switch (sdvo, sdvo->ddc_bus)) +if (!__intel_sdvo_set_control_bus_switch (sdvo, sdvo->ddc_bus))return -EIO ;return sdvo->i2c->algo->master_xfer (sdvo->i2c, msgs, num);
drivers/gpu/drm/i915/intel_sdvo.c static const struct i2c_algorithm intel_sdvo_ddc_proxy = { · line 2970
Quoted 10 lines
drivers/gpu/drm/i915/intel_sdvo.c +7
-0@@ -2951,6 +2961,39 @@ static const struct i2c_algorithm intel_sdvo_ddc_proxy = { .functionality = intel_sdvo_ddc_proxy_func }; +static void proxy_lock_bus (struct i2c_adapter *adapter, +unsigned int flags) +{ +struct intel_sdvo *sdvo = adapter->algo_data; +struct drm_i915_private *dev_priv =to_i915 (sdvo->base.base.dev); + +mutex_lock (&dev_priv->gmbus_mutex);
sdvo->i2c->lock_ops->lock_bus(sdvo->i2c, flags);
drivers/gpu/drm/i915/intel_sdvo.c static const struct i2c_algorithm intel_sdvo_ddc_proxy = { · line 2979
Quoted 9 lines
drivers/gpu/drm/i915/intel_sdvo.c +9
-0+} + +static int proxy_trylock_bus (struct i2c_adapter *adapter, +unsigned int flags) +{ +struct intel_sdvo *sdvo = adapter->algo_data; +struct drm_i915_private *dev_priv =to_i915 (sdvo->base.base.dev); + +return mutex_trylock (&dev_priv->gmbus_mutex);
sdvo->i2c->lock_ops->trylock_bus(sdvo->i2c, flags);
drivers/gpu/drm/i915/intel_sdvo.c static const struct i2c_algorithm intel_sdvo_ddc_proxy = { · line 2988
Quoted 9 lines
drivers/gpu/drm/i915/intel_sdvo.c +9
-0+} + +static void proxy_unlock_bus (struct i2c_adapter *adapter, +unsigned int flags) +{ +struct intel_sdvo *sdvo = adapter->algo_data; +struct drm_i915_private *dev_priv =to_i915 (sdvo->base.base.dev); + +mutex_unlock (&dev_priv->gmbus_mutex);
sdvo->i2c->lock_ops->unlock_bus(sdvo->i2c, flags);
On reflection, you only need to hook up gmbus.lock_ops since gmbus is a different lockclass it will be allowed to nest.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx