Not sure if this is what you meant, but some tiny rounding errors might occur during conversion if there are many transforms involved between the user space and the viewport space, but this can be avoided if user space values are stored with high enough precision.
In order to convert user units to viewport (physical) units and vice versa you only need the current transformation matrix, viewBox rect and viewport size. I have created a demo which shows how I can determine the line length in physical units: http://jsfiddle.net/9n5hf2jw/1/
The way how real world units are interpreted inside the SVG document is so messed up that even the SVG spec itself discourages their use:
Defining the size of a document in mm and then using mm units for shapes within it is going to give counterintuitive results, since they'll be converted to user units to resolve against the view box. (https://svgwg.org/svg2-draft/coords.html#Units)