All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pekka Paalanen <ppaalanen@gmail.com>
To: Hans de Goede <hdegoede@redhat.com>
Cc: David Airlie <airlied@linux.ie>,
	Christian Kellner <ckellner@redhat.com>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	Javier Martinez Canillas <javierm@redhat.com>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Nitin Joshi1 <njoshi1@lenovo.com>,
	Rajat Jain <rajatja@google.com>,
	Mark Pearson <mpearson@lenovo.com>,
	Benjamin Berg <bberg@redhat.com>
Subject: Re: RFC: Drm-connector properties managed by another driver / privacy screen support
Date: Fri, 24 Apr 2020 12:08:02 +0300	[thread overview]
Message-ID: <20200424120802.35fbffb4@eldfell.localdomain> (raw)
In-Reply-To: <caa677d0-bc43-5045-f4bb-1b762fafc870@redhat.com>


[-- Attachment #1.1: Type: text/plain, Size: 11552 bytes --]

On Fri, 24 Apr 2020 10:24:31 +0200
Hans de Goede <hdegoede@redhat.com> wrote:

> Hi all,
> 
> Pekka, Rajat,
> 
> Thank you for your input in this.
> 
> On 4/24/20 9:40 AM, Pekka Paalanen wrote:
> > On Thu, 23 Apr 2020 11:21:47 -0700
> > Rajat Jain <rajatja@google.com> wrote:
> >   
> >> On Tue, Apr 21, 2020 at 7:46 AM Pekka Paalanen <ppaalanen@gmail.com> wrote:  
> >>>
> >>> On Tue, 21 Apr 2020 14:37:41 +0200
> >>> Hans de Goede <hdegoede@redhat.com> wrote:
> >>>     
> >>>> TL;DR: Yes there will be races, because of both userspace +
> >>>> the firmware having; and potentially using r/w access to
> >>>> the privacy-screen state. But in practice I expect these
> >>>> to not really be an issue. Important here is that userspace
> >>>> only commits the property in a transaction to commit if
> >>>> it actually intends to change the property so as to not
> >>>> needlessly create a situation where we might hit the race.
> >>>>
> >>>> As for 1 vs 2 properties for this I guess that in preparation
> >>>> for potential devices where the state is locked, having a
> >>>> r/w sw-state + a ro hw-state property makes sense.
> >>>>
> >>>> So I suggest that we replace the current "privacy-screen" property
> >>>> from Rajat's patch-set with 2 props named:
> >>>>
> >>>> "privacy-screen-sw-state" (r/w)
> >>>> "privacy-screen-hw-state" (ro)
> >>>>
> >>>> Where for current gen hardware the privacy-screen-hw-state is
> >>>> just a mirror of the sw-state.  
> >>
> >> Just to make sure I understand the semantics correctly:
> >>
> >> - The  "privacy-screen-hw-state" shall be read-only, and can be modified by:
> >>        - Hardware (e.g. HW kill switch).
> >>        - Firmware.
> >>        - (Potentially) needs a notification/irq to the kernel when this
> >> changes (or may be kernel can read it only when userspace queries for
> >> it).
> >>
> >> - The "privacy-screen-sw-state" shall be read-write, and can only be
> >> modified by user space.
> >>          - If user space toggles it, the kernel will attempt to
> >> "request" the change to hardware.
> >>          - Whether the request to hardware was successful or not, the
> >> "privacy-screen-sw-state" will always reflect the latest value
> >> userspace wrote.
> >>          - If the request to hardware was successful, the
> >> "privacy-screen-hw-state" will also change (probably via a separate
> >> notification/irq from HW).
> >>          - We expect the user space to write to
> >> "privacy-screen-sw-state" only if it really wants to toggle the value.  
> > 
> > Hi,
> > 
> > yes, to my understanding, that seems to be the correct idea from this
> > thread. The hw-state property must reflect the actual hardware state at
> > all times.  
> 
> Agree on the hw-state prop reflecting the actual hardware state at
> all times, that one is easy.
> 
> > However, when userspace sets "privacy-screen-sw-state", the driver
> > should attempt to change hardware state regardless of whether the
> > "privacy-screen-sw-state" value changes compared to its old value or
> > not. Otherwise userspace cannot intentionally override a hardware
> > hotkey setting if possible (or would need two atomic commits to do it).  
> 
> Ack / agreed.
> 
> > Mind, the above paragraph is only what I interpreted from this email
> > thread here. Previously I did not think that with atomic KMS, setting a
> > property to a value it already has could trigger anything. But I guess
> > it can?  
> 
> In a way. My idea for the "privacy-screen-sw-state" is for it to reflect
> the last requested value, where the request could come from either a
> firmware controlled hotkey; or from userspace (this seems to be where
> our ideas of how to handle this diverts).
> 
> So what can happen is (with both props being always in sync)
> -userspace reads privacy screen being off
> -user toggles privacy screen on through firmware controlled hotkey
> -kernel gets notified about state toggle, updates both property
>   states to on
> -userspace commits its old knowledge of the property (off), thereby
>   triggering the kernel to turn the privacy screen back off
> 
> So in this case from the kernel pov the property is actually set
> to a new value, not to "a value it already has".

Hi,

that is an interesting point of view.

You are keeping the separation between "wanted" and "actual" state, but
counting firmware/hardware hotkeys as "want" instead of letting them
silently change hardware state.

That seems ok.

> Note there can be races here of course, but lets ignore those (for now).
> Both the hotkey event as well as userspace changing the setting will be
> end-user triggered events and will not happen at high frequency.
> Also I see no way to completely eliminate racing here. Luckily the side
> effects of the race or pretty harmless (annoying maybe, but not causing
> crashes, etc).
> 
> > This design is based on that it can.
> >   
> >> What is not clear to me is if any change to"privacy-screen-hw-state"
> >> shall be propagated to "privacy-screen-sw-state"?
> >>   - If yes, then I think we are not solving any problems of single property.
> >>   - If no, then why do we require userspace to write to sw state only
> >> if something has changed?  
> >
> > No. As already written, the kernel must not change the value of
> > "privacy-screen-sw-state", only userspace can.  
> 
> So this is where out view of how to handle this differs, I do
> not see the hotkey changing the state as different from userspace
> changing it. The reason for me to have both a sw- and a hw-state
> is in case there is a physical switch (typically a slider style
> switch) which forces the state to on / off. In this case userspace
> could still set the "privacy-screen-sw-state" prop and then
> the 2 could differ.

Yes, the locked switch case definitely makes sense to me.

If userspace has to avoid setting the sw property unless it actually
intends to change it, then the sw property being controlled from
multiple sources (firmware, hotkey, the /proc file below) could work.
It would even tell the KMS client when someone else changed the
"wanted" state.

> Lets add one more complication to this, which I think helps.
> Currently the thinkpad_acpi driver exports the privacy screen as:
> 
> /proc/acpi/ibm/lcdshadow
> 
> Userspace can write this and then change the privacy-screen
> setting, this is in shipped kernels and cannot be dropped
> because it is part if the kernel's uABI now.
> This means that another userspace process can change the
> property underneath a kms client. I do not see how this is
> different from the firmware changing the setting based on
> a hotkey press. Yet if we stick with your "only userspace can"
> change the sw-state setting, then does this count as userspace,
> or do you mean only a kms client can ?  And then how is
> another kms-client changing the setting different ?

To me that would be similar to firmware changing hardware state: it's
not the KMS client (the display server) doing it, but something else
behind its back while it thinks it's in full control.

Doing things behind the display server's back is what creates all the
mess here.

Another KMS client cannot set the property behind the display server's
back, because the display server is holding DRM master, and the
property cannot be written without DRM master status. If the display
server drops DRM master, it knows it probably lost all state.

> So to me to avoid confusion the only valid case where the
> hw- and sw-state can differ is if userspace requests
> say "off" as state while the privacy screen is forced on
> by say a physical switch (or e.g. a BIOS option to lock it?).
> 
> Then we would remember the off in sw-state but hw-state would
> still be on.
> 
> I guess that maybe for the enum of the hw-state we need 4 values
> instead of 2:
> 
> Enabled
> Disabled
> Enabled, locked
> Disabled, locked
> 
> To indicate to userspace that atm the state cannot be changed.

If userspace needs that information, sure.

This makes me think that a driver needs to handle different types of
switches/hotkeys through different properties:

- For a hardware latching switch that forces the shield state to be one
  and not the other, it should change the hw-state but it does not seem
  to have a reason to change the sw-state property: it's not a "want",
  it's a hard setting. Changing sw-state would also lose the userspace
  preference of the setting.

- For momentary button or a hotkey that is supposed to just toggle the
  shield state, it would toggle sw-state property since it's a "want"
  that can be overridden. Setting the property leads to changing the
  hw-state as well (if not locked).

Does that make sense?

Maybe this is the best compromise given the display server cannot be in
full control.

> If userspace then still changes sw-state we cache it and apply
> this if the privacy screen control gets unlocked.

Sounds good.

> On hardware where there is no "lock" the 2 properties will simply
> always be the same.

Ok.


Thanks,
pq

> > Let's assume that you have a firmware-implemented hardware hotkey for
> > toggling the shield. The driver also successfully implements
> > "privacy-screen-sw-state" meaning that writing to it will set the
> > hardware shield state. If userspace was writing
> > "privacy-screen-sw-state" even when it does not intend to change
> > hardware state, it would almost immediately override any state set by
> > the hardware hotkey, making the hardware hotkey (randomly) not work.  
> 
> Right, this is why userspace should not set the property unless
> it really means to change it, even then things could still race,
> but as explained above that should normally never happen and luckily
> the side-effects of hitting the race somehow are not that bad.
> 
> > This assumes that the hardware hotkey is a momentary switch that does
> > not stop software from controlling the shield too.  
> 
> This is correct for the Lenovo / thinkpad_acpi case.
> 
> > If the hardware hotkey can stop software from changing the shield
> > state, then it might not be necessary for userspace to avoid unneeded
> > setting of the property. But that depends on which way the hotkey works
> > and which way users want to use it, so it's still best for userspace to
> > not set the property unless it really intends to apply a change.  
> 
> Ack.
> 
> > If possible, it would be good to make this case the prime example of
> > how to correctly implement KMS properties for a hardware feature that
> > can be controlled (and fought over) by both userspace and
> > hardware/firmware. It seems like the same design can also work with
> > hardware switches that force the hardware state to be one or the other,
> > stopping userspace from changing it. Therefore I'd avoid incorporating
> > any specific shield use cases in the design, e.g. "if hw switch is set
> > to shield-on, userspace cannot turn shield off".  
> 
> I agree that it would be good to make this the prime example of
> how to deal with similar cases.
> 
> >> Also, it seems to me that in my current patchset, the property I have
> >> already behaves like "privacy-screen-sw-state". Do I just need to
> >> rename it?  
> 
> Maybe, it looks like we first need to figure out the exact semantics
> of all this.
> 
> Regards,
> 
> Hans
> 


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2020-04-24  9:08 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-15  9:42 RFC: Drm-connector properties managed by another driver / privacy screen support Hans de Goede
2020-04-15  9:52 ` Daniel Vetter
2020-04-15 10:11   ` Hans de Goede
2020-04-15 10:22     ` Daniel Vetter
2020-04-15 11:39       ` Hans de Goede
2020-04-15 11:56         ` Hans de Goede
2020-04-15 12:01         ` Daniel Vetter
2020-04-15 13:02           ` Hans de Goede
2020-04-15 17:54             ` Daniel Vetter
2020-04-15 18:19               ` Hans de Goede
2020-04-15 18:29                 ` Daniel Vetter
2020-04-15 19:50                   ` Hans de Goede
2020-04-16  6:46                     ` Daniel Vetter
2020-04-15 15:28 ` Jani Nikula
2020-04-15 15:40   ` Hans de Goede
2020-04-15 17:14     ` [External] " Mark Pearson
2020-04-15 18:06       ` Hans de Goede
2020-04-15 19:20     ` Rajat Jain
2020-04-15 21:10       ` Jani Nikula
2020-04-15 21:21         ` Hans de Goede
2020-04-15 21:51           ` [External] " Mark Pearson
2020-04-17  9:05         ` Pekka Paalanen
2020-04-17  9:02     ` Pekka Paalanen
2020-04-17 11:55       ` Jani Nikula
2020-04-17 14:18         ` Daniel Vetter
2020-04-17 14:54           ` Benjamin Berg
2020-04-21 12:37         ` Hans de Goede
2020-04-21 12:40           ` Daniel Vetter
2020-04-21 14:46           ` Pekka Paalanen
2020-04-23 18:21             ` Rajat Jain
2020-04-24  7:40               ` Pekka Paalanen
2020-04-24  8:24                 ` Hans de Goede
2020-04-24  9:08                   ` Pekka Paalanen [this message]
2020-04-24 10:32                     ` Hans de Goede
2020-04-17 14:17       ` Daniel Vetter
2020-04-20  8:27         ` Operating KMS UAPI (Re: RFC: Drm-connector properties managed by another driver / privacy screen support) Pekka Paalanen
2020-04-20 10:04           ` Pekka Paalanen
2020-04-20 10:18             ` Simon Ser
2020-04-21 12:15             ` Daniel Vetter
2020-04-21 14:33               ` Pekka Paalanen
2020-04-21 14:39                 ` Simon Ser
2020-04-23 15:01                 ` Daniel Vetter
2020-04-24  8:32                   ` Pekka Paalanen
2020-04-28 14:51                     ` Daniel Vetter
2020-04-29 10:07                       ` Pekka Paalanen
2020-04-30 13:53                         ` Daniel Vetter
2020-05-04  9:49                           ` Pekka Paalanen
2020-05-04 11:00                             ` Daniel Vetter
2020-05-04 12:22                               ` Pekka Paalanen
2020-05-05  8:48                                 ` Daniel Vetter
2020-05-07  9:03                                   ` Pekka Paalanen
2020-04-20 10:15           ` Simon Ser
2020-04-20 12:22             ` Pekka Paalanen
2020-04-20 12:33               ` Simon Ser

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200424120802.35fbffb4@eldfell.localdomain \
    --to=ppaalanen@gmail.com \
    --cc=airlied@linux.ie \
    --cc=bberg@redhat.com \
    --cc=ckellner@redhat.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hdegoede@redhat.com \
    --cc=javierm@redhat.com \
    --cc=mpearson@lenovo.com \
    --cc=njoshi1@lenovo.com \
    --cc=rajatja@google.com \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.