Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Rosetta with VZ driver #1155

Merged
merged 2 commits into from
Nov 23, 2022

Conversation

chancez
Copy link
Contributor

@chancez chancez commented Nov 15, 2022

@jandubois jandubois linked an issue Nov 16, 2022 that may be closed by this pull request
@cedws
Copy link

cedws commented Nov 16, 2022

I don't have any comments on the changes other than nice work and LGTM, but do you have any suggested reading material on how this Rosetta acceleration works?

Thanks.

@chancez chancez marked this pull request as ready for review November 16, 2022 18:23
@chancez
Copy link
Contributor Author

chancez commented Nov 16, 2022

Okay, PR is updated based on feedback and I like it much better than the initial MVP. Let me know what you all think. I also rebased and moved it from draft->ready to review.

@chancez
Copy link
Contributor Author

chancez commented Nov 16, 2022

@cedws

I don't have any comments on the changes other than nice work and LGTM, but do you have any suggested reading material on how this Rosetta acceleration works?

Thanks.

For how it works with Linux: https://developer.apple.com/documentation/virtualization/running_intel_binaries_in_linux_vms_with_rosetta

Rosetta in general: https://developer.apple.com/documentation/apple-silicon/about-the-rosetta-translation-environment

pkg/limayaml/limayaml.go Outdated Show resolved Hide resolved
)

func createRosettaDirectoryShareConfiguration(install bool) (*vz.VirtioFileSystemDeviceConfiguration, error) {
return nil, fmt.Errorf("Rosetta is unsupported on non-ARM64 hosts")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do a warning instead of error.

This is to make vz template runnable on both arm & x64

Copy link
Contributor Author

@chancez chancez Nov 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't users just disable Rosetta on x86 in that case? I guess this would be better UX for users so they don't have to worry about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think in that case, we probably can still return an error here, but we can turn it into a named error and check using errors.Is in the caller.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


if driver.Yaml.Rosetta.Enabled {
logrus.Info("Setting up Rosetta share")
directorySharingDeviceConfig, err := createRosettaDirectoryShareConfiguration(driver.Yaml.Rosetta.Install)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought,

Do we needed Rosetta.Install ?
Can we directly install since Rosetta.Enabled is true already ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. I figured it would make sense to make it configurable in case users want to install Rosetta themselves. I already have it installed, so I'm not sure what it actually looks like if you try without it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During installation nothing will pop-up or happen. It just like installation via command line. So i think it should be fine.

But let's also hear others opinion on this.

Copy link
Member

@AkihiroSuda AkihiroSuda Nov 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we directly install since Rosetta.Enabled is true already ?

👍 , assuming that Enabled = true doesn't show the macOS password popup as long as Rosetta is already installed on the macOS host.

If my assumption is untrue, probably we can't avoid having Install property, but it has to be documented in vz.yaml.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AkihiroSuda Your assumption is true. Only for installation the password pop-up will be shown. Not for every run of rosetta.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so we want to remove the install configuration altogether. I'll rip that out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR updated

@chancez
Copy link
Contributor Author

chancez commented Nov 16, 2022

There was also some discussion about whether or not this should be enabled by default in the other PR. What do people think?

@chancez chancez force-pushed the pr/chancez/vz_rosetta branch 2 times, most recently from b53ba06 to badcb22 Compare November 16, 2022 20:42
@AkihiroSuda
Copy link
Member

There was also some discussion about whether or not this should be enabled by default in the other PR. What do people think?

The mount can be enabled by default, but binfmt should be probably opt-in for now.
The vz.yaml template can have rosetta.binfmt: true by default.

@chancez
Copy link
Contributor Author

chancez commented Nov 17, 2022

There was also some discussion about whether or not this should be enabled by default in the other PR. What do people think?

The mount can be enabled by default, but binfmt should be probably opt-in for now. The vz.yaml template can have rosetta.binfmt: true by default.

Is that best done via FillDefault or should we change the field to Disable so the zero value is that Rosetta is enabled? (Disable: false)

@AkihiroSuda
Copy link
Member

There was also some discussion about whether or not this should be enabled by default in the other PR. What do people think?

The mount can be enabled by default, but binfmt should be probably opt-in for now. The vz.yaml template can have rosetta.binfmt: true by default.

Is that best done via FillDefault or should we change the field to Disable so the zero value is that Rosetta is enabled? (Disable: false)

Lima itself should leave it disabled by default. The vz.yaml template file may have rosetta.binfmt: true line to override the built-in default value.

@chancez
Copy link
Contributor Author

chancez commented Nov 18, 2022

@AkihiroSuda Sorry I meant for rosetta.enabled.

Also what are your thoughts about the Rosetta installation behavior?

@AkihiroSuda
Copy link
Member

Looks like installing rosetta requires the root of the macOS host, so it should be disabled by default.

https://developer.apple.com/documentation/virtualization/running_intel_binaries_in_linux_vms_with_rosetta?language=objc

Installing Rosetta is a one-time process per computer that requires the user to grant permission for the system to install Rosetta. If Rosetta is already installed in macOS, the system activates it for use under the Virtualization framework; if Rosetta isn’t installed, the framework downloads the installer from the network and performs the installation. The installer interactively prompts the user for authorization, and your app should handle any of the possible error conditions that could occur during the authorization, download, and installation process.

@chancez
Copy link
Contributor Author

chancez commented Nov 21, 2022

@AkihiroSuda then it sounds like the PR as it is should be correct with the current defaults and vz.yaml. I've rebased.

@chancez chancez force-pushed the pr/chancez/vz_rosetta branch 2 times, most recently from 7cc9272 to 9180ce9 Compare November 21, 2022 22:49
@chancez
Copy link
Contributor Author

chancez commented Nov 22, 2022

Getting a build error on my errRosettaUnsupported variable from being used, presumably because it's running without the build tags, but I'm not sure quite where/how to fix it currently.

@chancez chancez force-pushed the pr/chancez/vz_rosetta branch 2 times, most recently from 5fec1fc to 674c567 Compare November 22, 2022 01:08
@AkihiroSuda
Copy link
Member

Thanks, almost looks good, but while Rosetta should be disabled by default, I assume it can be automatically installed to the macOS host when Rosetta is explicitly enabled in the YAML
#1155 (comment)

@AkihiroSuda AkihiroSuda added this to the v0.14 milestone Nov 22, 2022
@chancez chancez requested review from AkihiroSuda and balajiv113 and removed request for AkihiroSuda and balajiv113 November 22, 2022 16:32
@chancez
Copy link
Contributor Author

chancez commented Nov 22, 2022

PR is updated to remove the install configuration.

AkihiroSuda
AkihiroSuda previously approved these changes Nov 22, 2022
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@@ -0,0 +1,12 @@
//go:build darwin && !arm64
// +build darwin,!arm64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we need to use !no_vz buildtag in both rosetta files to avoid this issue
#1176

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

pkg/vz/errors.go Outdated
@@ -0,0 +1,8 @@
//go:build darwin
// +build darwin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this tags ??
errors.go can be generic irrespective of platform (We can move this https://github.com/lima-vm/lima/blob/master/pkg/vz/vz_driver_others.go#L13 as well here)

If we need this tag, then naming the file as errors_darwin.go should be sufficient and consistent across i believe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without build tags the variable is detected as unused in non-darwin builds.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed the file, and I updated build tags as more were required due to your previous comment: #1155 (comment)

@balajiv113
Copy link
Member

Apart from those minor comments. Changes LGTM.
Works great, tested in M1 👍 And throws warning as well for intel :)

I couldn't test install rosetta flow, as i already had it installed.

if errors.Is(err, errRosettaUnsupported) {
logrus.Warnf("Unable to configure Rosetta: %s", err)
} else if err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, any error from createRosettaDirectoryShareConfiguration can be a warning.
e.g., failure of installation of Rosetta

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still unsure of this. Is there other example cases where Lima fails to do setup and continues on anyways? It seems like continuing on would lead to unexpected results for users who may not notice the warnings, etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there other example cases where Lima fails to do setup and continues on anyways?

Yes, in a bunch of places (git grep -F .Warn)

e.g.,

logrus.Warnf("DEGRADED. The VM seems running, but file sharing and port forwarding may not work. (hint: see %q)", haStderrPath)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. I've updated it to warn instead.

Signed-off-by: Chance Zibolski <chance.zibolski@gmail.com>
Signed-off-by: Chance Zibolski <chance.zibolski@gmail.com>
@chancez chancez requested review from balajiv113 and AkihiroSuda and removed request for balajiv113 and AkihiroSuda November 22, 2022 22:34
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda merged commit 69d032b into lima-vm:master Nov 23, 2022
@AkihiroSuda
Copy link
Member

Released beta.1 with Rosetta
https://github.com/lima-vm/lima/releases/tag/v0.14.0-beta.1

@chancez chancez deleted the pr/chancez/vz_rosetta branch November 23, 2022 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Rosetta2 as a binfmt_misc handler on macOS Ventura
5 participants