1

A Linux-on-M1 update

 1 year ago
source link: https://lwn.net/Articles/924557/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

A Linux-on-M1 update

[Posted February 27, 2023 by corbet]
The Asahi Linux project has posted an update and reality check on the status of Linux support for Apple's M1 hardware.
We are continuously upstreaming kernel features, and 6.2 notably adds device trees and basic boot support for M1 Pro/Max/Ultra machines. However, there is still a long road before upstream kernels are usable on laptops. There is no trackpad/keyboard support upstream yet.

While you can boot an upstream 6.2 kernel on desktops (M1 Mac Mini, M1 Max/Ultra Mac Studio) and do useful things with it, that is only the case for 16K page size kernel builds.

No generic ARM64 distro ships 16K kernels today, to our knowledge.


(Log in to post comments)

A Linux-on-M1 update

Posted Feb 27, 2023 18:20 UTC (Mon) by Cyberax (✭ supporter ✭, #52523) [Link]

Sidenote: I _love_ that they switched from Twitter and I don't get the "LOGIN TO TWITTER" message after half a screen of scrolling.

Thank you!

A Linux-on-M1 update

Posted Feb 27, 2023 20:51 UTC (Mon) by proski (subscriber, #104) [Link]

Twitter removed that annoyance recently. Still, it's good that Asahi Linux has switched to a site more appropriate for free software announcements.

Twtitter (was A Linux-on-M1 update)

Posted Feb 28, 2023 0:42 UTC (Tue) by dskoll (subscriber, #1630) [Link]

Pretty OT, but someone told be about nitter.net. In any Twitter URL, replace twitter.com with nitter.net and you can read the thread in peace without actually going to the twitter.com site.

Twtitter (was A Linux-on-M1 update)

Posted Feb 28, 2023 2:17 UTC (Tue) by mathstuf (subscriber, #69389) [Link]

How well is that working with the API restrictions that have been put into place? Or does it just scrape the HTML render?

A Linux-on-M1 update

Posted Feb 27, 2023 19:25 UTC (Mon) by mfuzzey (subscriber, #57966) [Link]

Is it just a question of distros needing to provide packaged kernels with 16k page size or are userspace packages likely to be affected too?

I know userspace can use sysconf to obtain the kernel page size but it wouldn't surprise me if some code just hardcodes 4k.

Though it sounds like the 16k page size is temporary and they are planning on supporting 4k in the future?

A Linux-on-M1 update

Posted Feb 27, 2023 19:47 UTC (Mon) by Shawnl (guest, #163686) [Link]

The toolchain defaults to padding executable ELF sections to 64kb to support all three page size options (4k, 16k, and 64k), and most software doesn't care about page size.

A Linux-on-M1 update

Posted Feb 27, 2023 19:54 UTC (Mon) by josh (subscriber, #17465) [Link]

Anything that does mmap would need to take some care to avoid hardcoding page size, and many applications that do mmap have hidden assumptions of 4k until the first time they're ported to an architecture with a different page size.

A Linux-on-M1 update

Posted Feb 27, 2023 20:12 UTC (Mon) by Paf (subscriber, #91811) [Link]

Can you give some examples? I've worked some with mmap using applications and I can't think of much where they have dependencies on page size (optimizations which are page size dependent, yes, but nothing that just wouldn't work), unless they're using mmap to control hardware or something.

A Linux-on-M1 update

Posted Feb 27, 2023 20:35 UTC (Mon) by ballombe (subscriber, #9523) [Link]

mprotect requires that the address is aligned on a page boundary.
mmap always returns an address that is aligned on a page boundary, so it can be passed to mprotect as is.
However if you want to mprotect only a subset of what mmap returned, you have to make sure
that subset is aligned on page boundary.

A Linux-on-M1 update

Posted Feb 27, 2023 20:43 UTC (Mon) by chris_se (subscriber, #99706) [Link]

> Can you give some examples? I've worked some with mmap using applications and I can't think of much where they have dependencies on page size

From the manpage:

> offset must be a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE).

Also, if you use MAP_FIXED (or MAP_FIXED_NOREPLACE), you have

> addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions.

Furthermore, while this isn't relevant to this specific thread, but if you want to write portable code and also support Windows, it uses a page size of 4kiB of x86_64, but requires all virtual memory mappings to be aligned to 64kiB. (But don't hard-code those numbers, it's possible to query this at runtime.)

I've written quite a bit of code that makes use of mmap() (especially for shared memory IPC) and I made sure to always follow the best practices here and dynamically query the OS for the correct alignments when needed. But I've also stumbled upon a lot of other code on the internet that just hard-codes these values. (Or worse, tries to be clever, and uses per-arch/os #ifdefs instead of querying them at runtime.)

Now obviously not everyone uses offset/fixed addresses, and if you just want to map an entire file (or at least a region that starts at offset 0), you don't have to care about the page size, and you'll never need to query it. (Not even on Windows.) But as soon as your use case gets a bit more complicated, you'll need to take this into account.

A Linux-on-M1 update

Posted Feb 28, 2023 2:51 UTC (Tue) by NYKevin (subscriber, #129325) [Link]

To my understanding, the main "sensible" use case of MAP_FIXED is to replace an existing mapping (that you presumably created without using MAP_FIXED) - indeed, the man page explicitly says that this is the "only safe use for MAP_FIXED." I would tend to assume that you don't have to check alignment in that case, because any reasonable mmap should* already be returning memory that is page-aligned anyway.

* Shockingly, POSIX doesn't say that the return value of mmap needs to be aligned at all, unlike malloc(3), so a conforming implementation could give you an odd address! But I would like to believe that no modern implementation is quite that ridiculous.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK