devicetree-spec.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: Florian Fainelli <f.fainelli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Cyril Novikov <cnovikov-wte42BQEg7M@public.gmane.org>,
	devicetree-spec-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: Virtualization difficulty -- phandles
Date: Sun, 16 Jul 2017 15:35:48 +1000	[thread overview]
Message-ID: <20170716053548.GL17539@umbus.fritz.box> (raw)
In-Reply-To: <4594fc97-9b9f-267e-ee8e-8cbe89341fe7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 6237 bytes --]

On Thu, Jul 13, 2017 at 09:47:01AM -0700, Florian Fainelli wrote:
> On 07/12/2017 09:23 PM, Cyril Novikov wrote:
> > On 7/12/2017 10:10 AM, Florian Fainelli wrote:
> >> On 07/11/2017 11:15 PM, Cyril Novikov wrote:
> >>> Hi, all!
> >>>
> >>> The product that I work on supports physical device assignment (aka
> >>> "pass-through") to virtual machines, which means we need to take
> >>> portions of the physical FDT and include them in the guest FDT. This
> >>> needs to happen automatically in software.
> >>>
> >>> The problem is phandles, because we cannot identify them in the blob and
> >>> therefore can't find any dependent devices/nodes that also need to be
> >>> included in the guest FDT. So the process cannot be fully automated. We
> >>> can't even advise the user what other devices should be assigned to the
> >>> VM. The hypervisor runs or bare metal, so having to parse the source DTS
> >>> files for this is very inconvenient.
> >>>
> >>> Would it be possible to add metadata properties to the binary FDT
> >>> format, which would identify other property cells that are in fact
> >>> phandles? It could be a per-node property or a single root node
> >>> property, up to you guys. DTC would then automatically generate the
> >>> metadata property along with the phandle property when compiling the
> >>> DTS.
> >>
> >> phandles are already per-node properties, they are not quite different
> >> from normal properties actually. If a node is referred to by other
> >> nodes, the DTC compiler would add a phandle = <N> (and maybe even
> >> linux,phandle = <N> depending on options passed to it) where N is a
> >> global integer that keeps being incremented every time a new phandle is
> >> generated.
> >>
> >> When you strip or create new nodes from a base blob for your virtual
> >> machine, either the node is still existing, in which case its phandle
> >> property (if existing) is still valid and can still be referenced to, or
> >> it is a new node and then you can control how to allocate new phandle
> >> integers.
> >>
> >> I guess I am just not clear on what problem you are seeing with phandles
> >> based on your description of what you want to do?
> > 
> > Maybe I should have worded it differently: the problem is with phandle
> > references rather than phandle properties themselves, does it make it
> > more clear?
> 
> It does, thanks.
> 
> > There is no way to know that a certain aligned 4 byte
> > sequence is a phandle that references another part of the FDT.

In fact a phandle reference doesn't even have to be 4-byte aligned.

> You can
> > for some standard properties whose format is known not only to the
> > driver, but you can't in general. That makes it impossible to analyze
> > and detect dependencies between different parts of the FDT automatically.
> 
> I see what you mean now, there is indeed no way to tell whether a
> property that has an integer is just a normal integer versus an integer
> corresponding to a phandle.

Right.  Device tree properties are simply bytestrings until you use a
binding to interpret them.

> You could argue that property that specify a phandle should have a name
> that suggests so, like "phy-handle" but then this stops working with
> e.g: gpios that are (at least with Linux) specified as e.g: reset-gpios.

Not to mention that it doesn't help with properties which include
phandle references along with other information.

> In any case, you would have to have some sort of heuristic built into
> your FDT mangling code that tries to check if a given property is
> designating a phandle as opposed to having a more robust approach...

> > I think this situation is solvable with automatically DTC-generated
> > metadata. I'm also interested if there are other hypervisor vendors that
> > had to deal with this and how big is the demand for a solution. If we
> > are the first one, at least let it register that there's a problem and
> > interest in addressing it.
> 
> That would work, I have not heard of a similar problem with the
> hypervisor folks that I worked with, but AFAIR they were generating
> their DTS almost from scratch as opposed to mangling/passing through
> parts of an existing one.

So.  dtc in fact already has code to add metadata which marks phandle
references - so far it's only used in "plugin" files which are
intended to compile into overlays which can be runtime applied.  The
phandle fixup information goes into the special __local_fixups__ and
__fixups__ nodes (which have gratuitiously different format, but
that's a rant for elsewhere).

I've had a request from someone else to add __local_fixups__
information in a non-plugin tree for yet another application, and it
would be pretty straightforward to implement that.

But.. I'm very uneasy about the idea.

The first thing, is that this relies on the dts file containing the
&whatever phandle reference syntax wherever there should be a phandle
reference.  That's normal, but nothing stops a user from simply
putting an actual number there, manually assigning that number to
another node's phandle and generating a valid dtb that way.

More importantly, it won't detect phandles if the tree comes from a
source other than a dts - for example if you flatten /proc/device-tree
with -I fs, or have code which flattens a tree presented by real Open
Firmware it won't have that phandle metadata, just integer values.

Now those might not be something that happens in your use case, but
I'm pretty concerned that if I added this functionality, people are
going to forget that properties are all, fundamentally, bytestrings
and get surprised when tools don't magically know where the phandles
are in some cases.

That said, I'm open to persuasion if a good enough case is made for
this functionality.


But then, as Mark Rutland says in his other replies, locating phandles
is far from the only problem in trying to passthrough random DT nodes
to a guest.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2017-07-16  5:35 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-12  6:15 Virtualization difficulty -- phandles Cyril Novikov
2017-07-12 17:10 ` Florian Fainelli
     [not found]   ` <180baf3e-9e7b-c791-3be2-81d807b14759-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-07-13  4:23     ` Cyril Novikov
2017-07-13 16:47       ` Florian Fainelli
     [not found]         ` <4594fc97-9b9f-267e-ee8e-8cbe89341fe7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-07-16  5:35           ` David Gibson [this message]
     [not found]             ` <20170716053548.GL17539-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2017-07-18  1:37               ` Cyril Novikov
2017-07-19  3:30                 ` David Gibson
2017-07-24 17:09               ` Frank Rowand
     [not found]                 ` <597629DC.5060800-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-07-25  7:50                   ` David Gibson
     [not found]                     ` <20170725075034.GD8978-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2017-07-27 20:58                       ` Frank Rowand
     [not found]                         ` <597A53E1.4010002-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-07-27 21:59                           ` Pantelis Antoniou
2017-07-28  4:25                           ` David Gibson
2017-07-14 10:58 ` Mark Rutland
2017-07-18  1:47   ` Cyril Novikov
2017-07-19  3:40     ` David Gibson
     [not found]       ` <20170719034029.GT3140-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2017-07-22  4:24         ` Cyril Novikov
2017-07-24  6:14           ` David Gibson
2017-07-24 16:27 ` Frank Rowand
     [not found]   ` <59762000.7000302-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-07-24 23:00     ` Cyril Novikov

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=20170716053548.GL17539@umbus.fritz.box \
    --to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
    --cc=cnovikov-wte42BQEg7M@public.gmane.org \
    --cc=devicetree-spec-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=f.fainelli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /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 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).