Util-Linux package development
 help / color / mirror / Atom feed
* [PATCH] Add setsid option to save child process id
From: Marc Aurèle La France @ 2025-01-26 17:40 UTC (permalink / raw)
  To: util-linux

Add an option to save the child's pid into a file.

Marc.

diff -NRapruz -X /etc/diff.excludes util-linux-2.40.4/sys-utils/setsid.1.adoc devel-2.40.4/sys-utils/setsid.1.adoc
--- util-linux-2.40.4/sys-utils/setsid.1.adoc
+++ devel-2.40.4/sys-utils/setsid.1.adoc
@@ -31,6 +31,9 @@ Always create a new process.
 *-w*, *--wait*::
 Wait for the execution of the program to end, and return the exit status of this program as the exit status of *setsid*.

+*-p*, *--pidfile* _file_::
+If forked, write the process id of the program to _file_.
+
 *-V*, *--version*::
 Display version information and exit.

diff -NRapruz -X /etc/diff.excludes util-linux-2.40.4/sys-utils/setsid.c devel-2.40.4/sys-utils/setsid.c
--- util-linux-2.40.4/sys-utils/setsid.c
+++ devel-2.40.4/sys-utils/setsid.c
@@ -14,6 +14,9 @@
  *
  * 2008-08-20 Daniel Kahn Gillmor <dkg@fifthhorseman.net>
  * - if forked, wait on child process and emit its return code.
+ *
+ * 2025-01-25 Marc Aurèle La France <tsi@tuyoix.net>
+ * - If forked, save the child's process id in a file.
  */
 #include <getopt.h>
 #include <stdio.h>
@@ -39,11 +42,12 @@ static void __attribute__((__noreturn__)) usage(void)
 	fputs(_("Run a program in a new session.\n"), out);

 	fputs(USAGE_OPTIONS, out);
-	fputs(_(" -c, --ctty     set the controlling terminal to the current one\n"), out);
-	fputs(_(" -f, --fork     always fork\n"), out);
-	fputs(_(" -w, --wait     wait program to exit, and use the same return\n"), out);
+	fputs(_(" -c, --ctty               set the controlling terminal to the current one\n"), out);
+	fputs(_(" -f, --fork               always fork\n"), out);
+	fputs(_(" -w, --wait               wait program to exit, and use the same return\n"), out);
+	fputs(_(" -p, --pidfile <file>     write child pid to <file>\n"), out);

-	fprintf(out, USAGE_HELP_OPTIONS(16));
+	fprintf(out, USAGE_HELP_OPTIONS(26));

 	fprintf(out, USAGE_MAN_TAIL("setsid(1)"));
 	exit(EXIT_SUCCESS);
@@ -55,14 +59,17 @@ int main(int argc, char **argv)
 	int ctty = 0;
 	pid_t pid;
 	int status = 0;
+	const char *pidpath = NULL;
+	FILE *pidfile;

 	static const struct option longopts[] = {
-		{"ctty", no_argument, NULL, 'c'},
-		{"fork", no_argument, NULL, 'f'},
-		{"wait", no_argument, NULL, 'w'},
-		{"version", no_argument, NULL, 'V'},
-		{"help", no_argument, NULL, 'h'},
-		{NULL, 0, NULL, 0}
+		{"ctty",    no_argument,       NULL, 'c'},
+		{"fork",    no_argument,       NULL, 'f'},
+		{"wait",    no_argument,       NULL, 'w'},
+		{"pidfile", required_argument, NULL, 'p'},
+		{"version", no_argument,       NULL, 'V'},
+		{"help",    no_argument,       NULL, 'h'},
+		{NULL,      0,                 NULL, 0}
 	};

 	setlocale(LC_ALL, "");
@@ -70,7 +77,7 @@ int main(int argc, char **argv)
 	textdomain(PACKAGE);
 	close_stdout_atexit();

-	while ((ch = getopt_long(argc, argv, "+Vhcfw", longopts, NULL)) != -1)
+	while ((ch = getopt_long(argc, argv, "+Vhcfp:w", longopts, NULL)) != -1)
 		switch (ch) {
 		case 'c':
 			ctty=1;
@@ -81,6 +88,9 @@ int main(int argc, char **argv)
 		case 'w':
 			status = 1;
 			break;
+		case 'p':
+			pidpath = optarg;
+			break;

 		case 'h':
 			usage();
@@ -105,6 +115,16 @@ int main(int argc, char **argv)
 			break;
 		default:
 			/* parent */
+			if (pidpath) {
+				pidfile = fopen(pidpath, "w");
+				if (pidfile == NULL)
+					warn(_("cannot open pidfile %s"),
+						pidpath);
+				else {
+					fprintf(pidfile, "%d\n", pid);
+					fclose(pidfile);
+				}
+			}
 			if (!status)
 				return EXIT_SUCCESS;
 			if (wait(&status) != pid)

^ permalink raw reply

* [PATCH] Fix --disable-widechar compile warnings
From: Marc Aurèle La France @ 2025-01-26 17:38 UTC (permalink / raw)
  To: util-linux

Fix warnings when compiling without wide char support.

Marc.

diff -NRapruz -X /etc/diff.excludes util-linux-2.40.4/lib/mbsedit.c devel-2.40.4/lib/mbsedit.c
--- util-linux-2.40.4/lib/mbsedit.c
+++ devel-2.40.4/lib/mbsedit.c
@@ -174,8 +174,8 @@ static size_t mbs_insert(char *str, wint_t c, size_t *ncells)
 	memmove(str + n, str, bytes);
 	memcpy(str, in, n);
 	str[bytes + n] = '\0';
-out:
 #ifdef HAVE_WIDECHAR
+out:
 	free(in);
 #endif
 	return n;
diff -NRapruz -X /etc/diff.excludes util-linux-2.40.4/text-utils/pg.c devel-2.40.4/text-utils/pg.c
--- util-linux-2.40.4/text-utils/pg.c
+++ devel-2.40.4/text-utils/pg.c
@@ -146,7 +146,9 @@ static long startline;			/* start line from argv[] */
 static int nextfile = 1;		/* files to advance */
 static jmp_buf jmpenv;			/* jump from signal handlers */
 static int canjump;			/* jmpenv is valid */
+#ifdef HAVE_WIDECHAR
 static wchar_t wbuf[READBUF];		/* used in several widechar routines */
+#endif

 static char *copyright;
 static const char *helpscreen = N_("\

^ permalink raw reply

* Re: [PATCH v2] alpha/elf: Fix misc/setarch test of util-linux by removing 32bit support
From: John Paul Adrian Glaubitz @ 2025-01-26 17:15 UTC (permalink / raw)
  To: Ivan Kokshaysky, Eric W. Biederman
  Cc: Maciej W. Rozycki, Arnd Bergmann, Richard Henderson, Matt Turner,
	Kees Cook, Paul E. McKenney, linux-alpha, linux-mm, linux-kernel,
	Michael Cree, Sam James, Geert Uytterhoeven, Michael Karcher,
	Chris Hofstaedtler, util-linux, linux-mips, loongarch
In-Reply-To: <Z4uECl9wQ2sqdKym@minute>

Hi Eric,

On Sat, 2025-01-18 at 11:35 +0100, Ivan Kokshaysky wrote:
> On Sun, Jan 12, 2025 at 11:39:01PM -0600, Eric W. Biederman wrote:
> ...
> > --- a/arch/alpha/include/asm/pgtable.h
> > +++ b/arch/alpha/include/asm/pgtable.h
> > @@ -360,7 +360,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
> >  
> >  extern void paging_init(void);
> >  
> > -/* We have our own get_unmapped_area to cope with ADDR_LIMIT_32BIT.  */
> > +/* We have our own get_unmapped_area */
> >  #define HAVE_ARCH_UNMAPPED_AREA
> 
> Just remove the definition. As the comment suggests, the only reason
> it exists is ADDR_LIMIT_32BIT, which is gone.
> 
> > --- a/arch/alpha/kernel/osf_sys.c
> > +++ b/arch/alpha/kernel/osf_sys.c
> > @@ -1210,8 +1210,7 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
> >  	return ret;
> >  }
> >  
> > -/* Get an address range which is currently unmapped.  Similar to the
> > -   generic version except that we know how to honor ADDR_LIMIT_32BIT.  */
> > +/* Get an address range which is currently unmapped. */
> >  
> >  static unsigned long
> >  arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
> > @@ -1230,13 +1229,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
> >  		       unsigned long len, unsigned long pgoff,
> >  		       unsigned long flags, vm_flags_t vm_flags)
> >  {
> > -	unsigned long limit;
> > -
> > -	/* "32 bit" actually means 31 bit, since pointers sign extend.  */
> > -	if (current->personality & ADDR_LIMIT_32BIT)
> > -		limit = 0x80000000;
> > -	else
> > -		limit = TASK_SIZE;
> > +	unsigned long limit = TASK_SIZE;
> >  
> >  	if (len > limit)
> >  		return -ENOMEM;
> 
> Likewise, just remove these functions. The generic_get_unmapped_area()
> works fine, tested on up1500.

Can you send a follow-up integrating those changes? It would be good if
SET_PERSONALITY() could be fixed on alpha for v6.14.

Adrian

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

^ permalink raw reply

* [PATCH] lscpu: make three column descriptions more grammatical
From: Benno Schulenberg @ 2025-01-26 11:09 UTC (permalink / raw)
  To: util-linux

Change an adverb to an adjective, use the plural "lines",
and use the plural form of the verb "have".  Also, put a
clarification between parentheses, and reshuffle it a bit
for clarity.

Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
---
 sys-utils/lscpu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 21c5a99cf..9dd12a64f 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -146,7 +146,7 @@ static struct lscpu_coldesc coldescs_cpu[] =
 	[COL_CPU_ADDRESS]      = { "ADDRESS", N_("physical address of a CPU") },
 	[COL_CPU_CONFIGURED]   = { "CONFIGURED", N_("shows if the hypervisor has allocated the CPU"), 0, 0, SCOLS_JSON_BOOLEAN_OPTIONAL },
 	[COL_CPU_ONLINE]       = { "ONLINE", N_("shows if Linux currently makes use of the CPU"), SCOLS_FL_RIGHT, 0, SCOLS_JSON_BOOLEAN_OPTIONAL },
-	[COL_CPU_MHZ]          = { "MHZ", N_("shows the currently MHz of the CPU"), SCOLS_FL_RIGHT, 0, SCOLS_JSON_NUMBER },
+	[COL_CPU_MHZ]          = { "MHZ", N_("shows the current MHz of the CPU"), SCOLS_FL_RIGHT, 0, SCOLS_JSON_NUMBER },
 	[COL_CPU_SCALMHZ]      = { "SCALMHZ%", N_("shows scaling percentage of the CPU frequency"), SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER },
 	[COL_CPU_MAXMHZ]       = { "MAXMHZ", N_("shows the maximum MHz of the CPU"), SCOLS_FL_RIGHT, 0, SCOLS_JSON_NUMBER },
 	[COL_CPU_MINMHZ]       = { "MINMHZ", N_("shows the minimum MHz of the CPU"), SCOLS_FL_RIGHT, 0, SCOLS_JSON_NUMBER },
@@ -163,8 +163,8 @@ static struct lscpu_coldesc coldescs_cache[] =
 	[COL_CACHE_WAYS]       = { "WAYS", N_("ways of associativity"), SCOLS_FL_RIGHT, 0, SCOLS_JSON_NUMBER },
 	[COL_CACHE_ALLOCPOL]   = { "ALLOC-POLICY", N_("allocation policy") },
 	[COL_CACHE_WRITEPOL]   = { "WRITE-POLICY", N_("write policy") },
-	[COL_CACHE_PHYLINE]    = { "PHY-LINE", N_("number of physical cache line per cache tag"), SCOLS_FL_RIGHT, 0, SCOLS_JSON_NUMBER },
-	[COL_CACHE_SETS]       = { "SETS", N_("number of sets in the cache; set lines has the same cache index"), SCOLS_FL_RIGHT, 0, SCOLS_JSON_NUMBER },
+	[COL_CACHE_PHYLINE]    = { "PHY-LINE", N_("number of physical cache lines per cache tag"), SCOLS_FL_RIGHT, 0, SCOLS_JSON_NUMBER },
+	[COL_CACHE_SETS]       = { "SETS", N_("number of sets in the cache (lines in a set have the same cache index)"), SCOLS_FL_RIGHT, 0, SCOLS_JSON_NUMBER },
 	[COL_CACHE_COHERENCYSIZE] = { "COHERENCY-SIZE", N_("minimum amount of data in bytes transferred from memory to cache"), SCOLS_FL_RIGHT, 0, SCOLS_JSON_NUMBER }
 };
 
-- 
2.48.1


^ permalink raw reply related

* lscpu uses unfitting "MHz" in frequency scaling item
From: Benno Schulenberg @ 2025-01-26 10:52 UTC (permalink / raw)
  To: util-linux


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


Hi,

Since commit 9b9e4f5d06be55f4b9e1a52b448055933df92c6b
from four years ago, lscpu lists also an item like this:

   CPU(s) scaling MHz: 61%

The printed value is a percentage, not a frequency, so the
"MHz" should not be there, I think -- the percentage would
be the same no matter whether the frequencies (in other items)
are shown in kHz or MHz or GHz.  So I propose to change the
message to:

   CPU(s) frequency scaling: 61%

Or abbreviated:

   CPU(s) freq. scaling: 61%


[In Dutch I'm translating it as if it said:

     CPU(s) frequency level: 61%

as the word "scaling" here is untranslatable.]


I would provide a patch, but the message occurs in a dozen
or more tests.  And probably the column name needs to be
changed too, from SCALMHZ% to FREQSCAL% or SCALING%?


Benno

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

^ permalink raw reply

* Re: [PATCH V2] blkid: allow up to 64k erofs block sizes
From: Gao Xiang @ 2025-01-25 15:19 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: util-linux, xiang, Karel Zak
In-Reply-To: <e0eb2d1f-48fd-4d2b-b087-20a87b396218@redhat.com>

On Fri, Jan 24, 2025 at 08:37:12AM -0600, Eric Sandeen wrote:
> Today, mkfs.erofs defaults to page size for block size, but blkid
> does not recognize this. Increase the limit to 64k.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>

Reviewed-by: Gao Xiang <xiang@kernel.org>

Thanks,
Gao Xiang

^ permalink raw reply

* Re: [RFC] ipcs for POSIX IPC
From: Prasanna Paithankar @ 2025-01-25 10:39 UTC (permalink / raw)
  To: Masatake YAMATO; +Cc: kzak, util-linux
In-Reply-To: <20240424.221517.2073047999286647720.yamato@redhat.com>

On Wed, 24 Apr 2024 at 18:45, Masatake YAMATO <yamato@redhat.com> wrote:
> On Wed, 24 Apr 2024 11:52:40 +0200, Karel Zak wrote:
>> On Wed, Apr 24, 2024 at 04:10:48AM +0530, Prasanna Paithankar wrote:
>>> The 'ipcs' (and 'ipcrm') command provides information on (or removes
>>> some) System V IPC resources. I'd like to know why no similar utility
>>> for POSIX IPC has existed for a long time. I would like to know if
>>> such a tool exists in case I missed it. If not, I will provide patches
>>> to ipcs and ipcrm (or should I separate the functionality into a new
>>> utility).
>>
>> I would suggest improving 'lsipc' instead of using the old 'ipcs'.
>>
>> The question is where to find information about POSIX IPC. For System
>> V, there is /proc/sysvipc, but there is no equivalent for POSIX (or I
>> am not aware of it). It seems that the only way to gather this
>> information is by scanning all processes' memory maps for /dev/shm.
>> This could be achieved by using lsfd.

Gathered information about POSIX IPC by scanning through /dev/shm (for
shm and sem) and /dev/mqueue (for mqueue).
Used libmount to mount /dev/mqueue if not already mounted in ipcutils.c.

Patched ipcrm.c and ipcmk.c to unlink and open POSIX IPC objects respectively.

Didn't add short command line options in ipcrm as recommended (Open
Group requirements).

Pull request open at: https://github.com/util-linux/util-linux/pull/3382

Yours sincerely
Prasanna Paithankar

>
> Masatake YAMATO
>
>>     Karel
>>
>>>
>>> Yours sincerely
>>> Prasanna Paithankar
>>>
>>
>> --
>>  Karel Zak  <kzak@redhat.com>
>>  http://karelzak.blogspot.com
>>
----------------------------------------------------------------

From 7a16f0535469dbf94d631cf40ddc539322b6d291 Mon Sep 17 00:00:00 2001
From: Prasanna Paithankar <paithankarprasanna@gmail.com>
Date: Thu, 23 Jan 2025 03:23:52 +0530
Subject: [PATCH 0/2]

The following changes since commit eba4f374fe49e3369e58acedaaed3e4581b1ce80:

  Merge branch 'column-handle-osc8-links' of
https://github.com/juarezr/util-linux (2025-01-22 11:47:04 +0100)

are available in the Git repository at:

  https://github.com/PrasannaPaithankar/util-linux.git ipc

for you to fetch changes up to 7a16f0535469dbf94d631cf40ddc539322b6d291:

  added POSIX IPC paathnames; modified sys-utils/Makemodule.am
(2025-01-23 03:18:31 +0530)

----------------------------------------------------------------

Prasanna Paithankar (2):
  added POSIX IPC support to lsipc, ipcrm, ipcmk
  added POSIX IPC paathnames; modified sys-utils/Makemodule.am

 include/pathnames.h     |  11 +-
 sys-utils/Makemodule.am |  16 +-
 sys-utils/ipcmk.1.adoc  |  15 +-
 sys-utils/ipcmk.c       |  93 ++++++++-
 sys-utils/ipcrm.1.adoc  |  21 +-
 sys-utils/ipcrm.c       | 137 +++++++++++-
 sys-utils/ipcutils.c    | 285 +++++++++++++++++++++++++
 sys-utils/ipcutils.h    |  52 +++++
 sys-utils/lsipc.1.adoc  |  22 +-
 sys-utils/lsipc.c       | 448 +++++++++++++++++++++++++++++++++++++---
 10 files changed, 1040 insertions(+), 60 deletions(-)

--
2.43.0

----------------------------------------------------------------

From c457ec945b4457418af6d5d80f4e6357b15cba9b Mon Sep 17 00:00:00 2001
From: Prasanna Paithankar <paithankarprasanna@gmail.com>
Date: Thu, 23 Jan 2025 03:08:02 +0530
Subject: [PATCH 1/2] added POSIX IPC support to lsipc, ipcrm, ipcmk

---
 sys-utils/ipcmk.1.adoc |  15 +-
 sys-utils/ipcmk.c      |  93 ++++++++-
 sys-utils/ipcrm.1.adoc |  21 +-
 sys-utils/ipcrm.c      | 137 ++++++++++++-
 sys-utils/ipcutils.c   | 285 ++++++++++++++++++++++++++
 sys-utils/ipcutils.h   |  52 +++++
 sys-utils/lsipc.1.adoc |  22 +-
 sys-utils/lsipc.c      | 448 ++++++++++++++++++++++++++++++++++++++---
 8 files changed, 1021 insertions(+), 52 deletions(-)

diff --git a/sys-utils/ipcmk.1.adoc b/sys-utils/ipcmk.1.adoc
index 605b9286c..a4871f438 100644
--- a/sys-utils/ipcmk.1.adoc
+++ b/sys-utils/ipcmk.1.adoc
@@ -20,7 +20,7 @@ ipcmk - make various IPC resources

 == DESCRIPTION

-*ipcmk* allows you to create System V inter-process communication
(IPC) objects: shared memory segments, message queues, and semaphore
arrays.
+*ipcmk* allows you to create POSIX and System V inter-process
communication (IPC) objects: shared memory segments, message queues,
and semaphore (arrays for System V).

 == OPTIONS

@@ -29,12 +29,24 @@ Resources can be specified with these options:
 *-M*, *--shmem* _size_::
 Create a shared memory segment of _size_ bytes. The _size_ argument
may be followed by the multiplicative suffixes KiB (=1024), MiB
(=1024*1024), and so on for GiB, etc. (the "iB" is optional, e.g., "K"
has the same meaning as "KiB") or the suffixes KB (=1000), MB
(=1000*1000), and so on for GB, etc.

+*-m*, *--posix-shmem* _size_::
+Create a POSIX shared memory segment of _size_ bytes. The _size_
argument may be followed by the multiplicative suffixes KiB (=1024),
MiB (=1024*1024), and so on for GiB, etc. (the "iB" is optional, e.g.,
"K" has the same meaning as "KiB") or the suffixes KB (=1000), MB
(=1000*1000), and so on for GB, etc.
+
 *-Q*, *--queue*::
 Create a message queue.

+*-q*, *--posix-mqueue*::
+Create a POSIX message queue.
+
 *-S*, *--semaphore* _number_::
 Create a semaphore array with _number_ of elements.

+*-s*, *--posix-semaphore*::
+Create a POSIX named semaphore.
+
+*-n*, *--name* _name_::
+Name of the POSIX IPC object. This option is mandatory for POSIX IPC objects.
+
 Other options are:

 *-p*, *--mode* _mode_::
@@ -50,6 +62,7 @@ mailto:hayden.james@gmail.com[Hayden A. James]

 *ipcrm*(1),
 *ipcs*(1),
+*lsipc*(1),
 *sysvipc*(7)

 include::man-common/bugreports.adoc[]
diff --git a/sys-utils/ipcmk.c b/sys-utils/ipcmk.c
index 67a7637f6..7e48b270e 100644
--- a/sys-utils/ipcmk.c
+++ b/sys-utils/ipcmk.c
@@ -26,8 +26,12 @@
 #include <stdlib.h>
 #include <sys/ipc.h>
 #include <sys/msg.h>
+#include <mqueue.h>
 #include <sys/sem.h>
+#include <semaphore.h>
 #include <sys/shm.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
 #include <sys/time.h>

 #include "c.h"
@@ -44,6 +48,23 @@ static int create_shm(size_t size, int permission)
  return shmget(key, size, permission | IPC_CREAT);
 }

+static int create_posix_shm(const char *name, size_t size, int permission)
+{
+ int shmfd;
+
+ if (-1 == (shmfd = shm_open(name, O_RDWR | O_CREAT, permission)))
+ return -1;
+
+ if (-1 == ftruncate(shmfd, size)) {
+ close(shmfd);
+ return -1;
+ }
+
+ close(shmfd);
+ printf(_("POSIX shared memory name: %s\n"), name);
+ return 0;
+}
+
 static int create_msg(int permission)
 {
  key_t key;
@@ -52,6 +73,14 @@ static int create_msg(int permission)
  return msgget(key, permission | IPC_CREAT);
 }

+static int create_posix_msg(const char *name, int permission)
+{
+ if (-1 == mq_open(name, O_RDWR | O_CREAT, permission, NULL))
+ return -1;
+ printf(_("POSIX message queue name: %s\n"), name);
+ return 0;
+}
+
 static int create_sem(int nsems, int permission)
 {
  key_t key;
@@ -60,6 +89,18 @@ static int create_sem(int nsems, int permission)
  return semget(key, nsems, permission | IPC_CREAT);
 }

+static int create_posix_sem(const char *name, int permission)
+{
+ sem_t *sem;
+
+ if (SEM_FAILED == (sem = sem_open(name, O_CREAT, permission, 0)))
+ return -1;
+
+ sem_close(sem);
+ printf(_("POSIX semaphore name: %s\n"), name);
+ return 0;
+}
+
 static void __attribute__((__noreturn__)) usage(void)
 {
  FILE *out = stdout;
@@ -71,9 +112,13 @@ static void __attribute__((__noreturn__)) usage(void)

  fputs(USAGE_OPTIONS, out);
  fputs(_(" -M, --shmem <size>       create shared memory segment of
size <size>\n"), out);
+ fputs(_(" -m, --posix-shmem <size> create POSIX shared memory
segment of size <size>\n"), out);
  fputs(_(" -S, --semaphore <number> create semaphore array with
<number> elements\n"), out);
+ fputs(_(" -s, --posix-semaphore    create POSIX semaphore\n"), out);
  fputs(_(" -Q, --queue              create message queue\n"), out);
+ fputs(_(" -q, --posix-mqueue       create POSIX message queue\n"), out);
  fputs(_(" -p, --mode <mode>        permission for the resource
(default is 0644)\n"), out);
+ fputs(_(" -n, --name <name>        name of the POSIX resource\n"), out);

  fputs(USAGE_SEPARATOR, out);
  fprintf(out, USAGE_HELP_OPTIONS(26));
@@ -81,6 +126,9 @@ static void __attribute__((__noreturn__)) usage(void)
  fputs(USAGE_ARGUMENTS, out);
  fprintf(out, USAGE_ARG_SIZE(_("<size>")));

+ fputs(USAGE_SEPARATOR, out);
+ fputs(_(" -n, --name <name> option is required for POSIX IPC\n"), out);
+
  fprintf(out, USAGE_MAN_TAIL("ipcmk(1)"));

  exit(EXIT_SUCCESS);
@@ -89,15 +137,20 @@ static void __attribute__((__noreturn__)) usage(void)
 int main(int argc, char **argv)
 {
  int permission = 0644;
+ char *name = NULL;
  int opt;
  size_t size = 0;
  int nsems = 0;
- int ask_shm = 0, ask_msg = 0, ask_sem = 0;
+ int ask_shm = 0, ask_msg = 0, ask_sem = 0, ask_pshm = 0, ask_pmsg =
0, ask_psem = 0;
  static const struct option longopts[] = {
  {"shmem", required_argument, NULL, 'M'},
+ {"posix-shmem", required_argument, NULL, 'm'},
  {"semaphore", required_argument, NULL, 'S'},
+ {"posix-semaphore", required_argument, NULL, 's'},
  {"queue", no_argument, NULL, 'Q'},
+ {"posix-mqueue", no_argument, NULL, 'q'},
  {"mode", required_argument, NULL, 'p'},
+ {"name", required_argument, NULL, 'n'},
  {"version", no_argument, NULL, 'V'},
  {"help", no_argument, NULL, 'h'},
  {NULL, 0, NULL, 0}
@@ -108,19 +161,29 @@ int main(int argc, char **argv)
  textdomain(PACKAGE);
  close_stdout_atexit();

- while((opt = getopt_long(argc, argv, "hM:QS:p:Vh", longopts, NULL)) != -1) {
+ while((opt = getopt_long(argc, argv, "hM:m:QqS:sp:n:Vh", longopts,
NULL)) != -1) {
  switch(opt) {
  case 'M':
  size = strtosize_or_err(optarg, _("failed to parse size"));
  ask_shm = 1;
  break;
+ case 'm':
+ size = strtosize_or_err(optarg, _("failed to parse size"));
+ ask_pshm = 1;
+ break;
  case 'Q':
  ask_msg = 1;
  break;
+ case 'q':
+ ask_pmsg = 1;
+ break;
  case 'S':
  nsems = strtos32_or_err(optarg, _("failed to parse elements"));
  ask_sem = 1;
  break;
+ case 's':
+ ask_psem = 1;
+ break;
  case 'p':
  {
  char *end = NULL;
@@ -130,6 +193,9 @@ int main(int argc, char **argv)
  err(EXIT_FAILURE, _("failed to parse mode"));
  break;
  }
+ case 'n':
+ name = optarg;
+ break;
  case 'h':
  usage();
  case 'V':
@@ -139,10 +205,16 @@ int main(int argc, char **argv)
  }
  }

- if(!ask_shm && !ask_msg && !ask_sem) {
+ if(!ask_shm && !ask_msg && !ask_sem && !ask_pshm && !ask_pmsg && !ask_psem) {
  warnx(_("bad usage"));
  errtryhelp(EXIT_FAILURE);
  }
+
+ if ((ask_pshm + ask_pmsg + ask_psem > 0) && name == NULL) {
+ warnx(_("name is required for POSIX IPC"));
+ errtryhelp(EXIT_FAILURE);
+ }
+
  if (ask_shm) {
  int shmid;
  if (-1 == (shmid = create_shm(size, permission)))
@@ -151,6 +223,11 @@ int main(int argc, char **argv)
  printf(_("Shared memory id: %d\n"), shmid);
  }

+ if (ask_pshm) {
+ if (-1 == create_posix_shm(name, size, permission))
+ err(EXIT_FAILURE, _("create POSIX shared memory failed"));
+ }
+
  if (ask_msg) {
  int msgid;
  if (-1 == (msgid = create_msg(permission)))
@@ -159,6 +236,11 @@ int main(int argc, char **argv)
  printf(_("Message queue id: %d\n"), msgid);
  }

+ if (ask_pmsg) {
+ if (-1 == create_posix_msg(name, permission))
+ err(EXIT_FAILURE, _("create POSIX message queue failed"));
+ }
+
  if (ask_sem) {
  int semid;
  if (-1 == (semid = create_sem(nsems, permission)))
@@ -167,5 +249,10 @@ int main(int argc, char **argv)
  printf(_("Semaphore id: %d\n"), semid);
  }

+ if (ask_psem) {
+ if (-1 == create_posix_sem(name, permission))
+ err(EXIT_FAILURE, _("create POSIX semaphore failed"));
+ }
+
  return EXIT_SUCCESS;
 }
diff --git a/sys-utils/ipcrm.1.adoc b/sys-utils/ipcrm.1.adoc
index 98e363892..f4a8b4546 100644
--- a/sys-utils/ipcrm.1.adoc
+++ b/sys-utils/ipcrm.1.adoc
@@ -23,19 +23,19 @@ ipcrm - remove certain IPC resources

 == DESCRIPTION

-*ipcrm* removes System V inter-process communication (IPC) objects
and associated data structures from the system. In order to delete
such objects, you must be superuser, or the creator or owner of the
object.
+*ipcrm* removes POSIX and System V inter-process communication (IPC)
objects and associated data structures from the system. In order to
delete such objects, you must be superuser, or the creator or owner of
the object.

-System V IPC objects are of three types: shared memory, message
queues, and semaphores. Deletion of a message queue or semaphore
object is immediate (regardless of whether any process still holds an
IPC identifier for the object). A shared memory object is only removed
after all currently attached processes have detached (*shmdt*(2)) the
object from their virtual address space.
+POSIX and System V IPC objects are of three types: shared memory,
message queues, and semaphores. Deletion of a message queue or
semaphore object is immediate (regardless of whether any process still
holds an IPC identifier for the object). A shared memory object is
only removed after all currently attached processes have detached
(*shmdt*(2)) the object from their virtual address space.

 Two syntax styles are supported. The old Linux historical syntax
specifies a three-letter keyword indicating which class of object is
to be deleted, followed by one or more IPC identifiers for objects of
this type.

 The SUS-compliant syntax allows the specification of zero or more
objects of all three types in a single command line, with objects
specified either by key or by identifier (see below). Both keys and
identifiers may be specified in decimal, hexadecimal (specified with
an initial '0x' or '0X'), or octal (specified with an initial '0').

-The details of the removes are described in *shmctl*(2), *msgctl*(2),
and *semctl*(2). The identifiers and keys can be found by using
*ipcs*(1).
+The details of the removes are described in *shmctl*(2),
*shm_unlink*(3), *msgctl*(2), *mq_unlink*(3), *semctl*(2), and
*sem_unlink*(3). The identifiers and keys can be found by using
*lsipc*(1) or *ipcs*(1).

 == OPTIONS

-*-a*, *--all* [*shm*] [*msg*] [*sem*]::
+*-a*, *--all* [*shm*] [*pshm*] [*msg*] [*pmsg*] [*sem*] [*psem*]::
 Remove all resources. When an option argument is provided, the
removal is performed only for the specified resource types.
 +
 _Warning!_ Do not use *-a* if you are unsure how the software using
the resources might react to missing objects. Some programs create
these resources at startup and may not have any code to deal with an
unexpected disappearance.
@@ -46,18 +46,27 @@ Remove the shared memory segment created with
_shmkey_ after the last detach is
 *-m*, *--shmem-id* _shmid_::
 Remove the shared memory segment identified by _shmid_ after the last
detach is performed.

+*-x*, *--posix-shmem* _name_::
+Remove the POSIX shared memory segment created with _name_.
+
 *-Q*, *--queue-key* _msgkey_::
 Remove the message queue created with _msgkey_.

 *-q*, *--queue-id* _msgid_::
 Remove the message queue identified by _msgid_.

+*-y*, *--posix-mqueue* _name_::
+Remove the POSIX message queue created with _name_.
+
 *-S*, *--semaphore-key* _semkey_::
 Remove the semaphore created with _semkey_.

 *-s*, *--semaphore-id* _semid_::
 Remove the semaphore identified by _semid_.

+*-z*, *--posix-semaphore* _name_::
+Remove the POSIX named semaphore created with _name_.
+
 include::man-common/help-version.adoc[]

 == NOTES
@@ -69,13 +78,17 @@ In its first Linux implementation, *ipcrm* used
the deprecated syntax shown in t

 *ipcmk*(1),
 *ipcs*(1),
+*lsipc*(1),
 *msgctl*(2),
+*mq_unlink*(3),
 *msgget*(2),
 *semctl*(2),
 *semget*(2),
+*sem_unlink*(3),
 *shmctl*(2),
 *shmdt*(2),
 *shmget*(2),
+*shm_unlink*(3),
 *ftok*(3),
 *sysvipc*(7)

diff --git a/sys-utils/ipcrm.c b/sys-utils/ipcrm.c
index 26255c494..2d080b007 100644
--- a/sys-utils/ipcrm.c
+++ b/sys-utils/ipcrm.c
@@ -20,6 +20,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
 #include "c.h"
 #include "nls.h"
 #include "strutils.h"
@@ -29,8 +31,11 @@

 typedef enum type_id {
  SHM,
+ PSHM,
  SEM,
+ PSEM,
  MSG,
+ PMSG,
  ALL
 } type_id;

@@ -48,14 +53,17 @@ static void __attribute__((__noreturn__)) usage(void)
  fputs(_("Remove certain IPC resources.\n"), out);

  fputs(USAGE_OPTIONS, out);
- fputs(_(" -m, --shmem-id <id>        remove shared memory segment by
id\n"), out);
- fputs(_(" -M, --shmem-key <key>      remove shared memory segment by
key\n"), out);
- fputs(_(" -q, --queue-id <id>        remove message queue by id\n"), out);
- fputs(_(" -Q, --queue-key <key>      remove message queue by key\n"), out);
- fputs(_(" -s, --semaphore-id <id>    remove semaphore by id\n"), out);
- fputs(_(" -S, --semaphore-key <key>  remove semaphore by key\n"), out);
- fputs(_(" -a, --all[=shm|msg|sem]    remove all (in the specified
category)\n"), out);
- fputs(_(" -v, --verbose              explain what is being done\n"), out);
+ fputs(_(" -m, --shmem-id <id>         remove shared memory segment
by id\n"), out);
+ fputs(_(" -M, --shmem-key <key>       remove shared memory segment
by key\n"), out);
+ fputs(_("     --posix-shmem <name>   remove POSIX shared memory
segment by name\n"), out);
+ fputs(_(" -q, --queue-id <id>         remove message queue by id\n"), out);
+ fputs(_(" -Q, --queue-key <key>       remove message queue by key\n"), out);
+ fputs(_("     --posix-mqueue <name>   remove POSIX message queue by
name\n"), out);
+ fputs(_(" -s, --semaphore-id <id>     remove semaphore by id\n"), out);
+ fputs(_(" -S, --semaphore-key <key>   remove semaphore by key\n"), out);
+ fputs(_("     --posix-semaphore <name> remove POSIX semaphore by
name\n"), out);
+ fputs(_(" -a, --all[=shm|pshm|msg|pmsg|sem|psem] remove all (in the
specified category)\n"), out);
+ fputs(_(" -v, --verbose               explain what is being done\n"), out);

  fputs(USAGE_SEPARATOR, out);
  fprintf(out, USAGE_HELP_OPTIONS(28));
@@ -229,6 +237,50 @@ static int key_to_id(type_id type, char *s)
  return id;
 }

+static int remove_name(type_id type, char *name)
+{
+ int ret;
+
+ switch (type) {
+ case PSHM:
+ if (verbose)
+ printf(_("removing POSIX shared memory `%s'\n"), name);
+ ret = shm_unlink(name);
+ break;
+ case PMSG:
+ if (verbose)
+ printf(_("removing POSIX message queue `%s'\n"), name);
+ ret = mq_unlink(name);
+ break;
+ case PSEM:
+ if (verbose)
+ printf(_("removing POSIX semaphore `%s'\n"), name);
+ ret = sem_unlink(name);
+ break;
+ default:
+ errx(EXIT_FAILURE, "impossible occurred");
+ }
+
+ if (ret < 0) {
+ switch (errno) {
+ case EACCES:
+ case EPERM:
+ warnx(_("permission denied for name `%s'"), name);
+ break;
+ case ENOENT:
+ warnx(_("name `%s' not found"), name);
+ break;
+ case ENAMETOOLONG:
+ warnx(_("name `%s' too long"), name);
+ break;
+ default:
+ err(EXIT_FAILURE, _("name failed"));
+ }
+ return 1;
+ }
+ return 0;
+}
+
 static int remove_all(type_id type)
 {
  int ret = 0;
@@ -236,13 +288,19 @@ static int remove_all(type_id type)

  struct shmid_ds shmseg;

+ struct posix_shm_data *shmds, *shmdsp;
+
  struct semid_ds semary;
  struct seminfo seminfo;
  union semun arg;

+ struct posix_sem_data *semds, *semdsp;
+
  struct msqid_ds msgque;
  struct msginfo msginfo;

+ struct posix_msg_data *msgds, *msgdsp;
+
  if (type == SHM || type == ALL) {
  maxid = shmctl(0, SHM_INFO, &shmseg);
  if (maxid < 0)
@@ -255,6 +313,16 @@ static int remove_all(type_id type)
  ret |= remove_id(SHM, 0, rm_me);
  }
  }
+ if (type == PSHM || type == ALL) {
+ if (posix_ipc_shm_get_info(NULL, &shmds) > 0) {
+ for (shmdsp = shmds; shmdsp->next != NULL; shmdsp = shmdsp->next) {
+ if (verbose)
+ printf(_("removing POSIX shared memory `%s'\n"), shmdsp->name);
+ ret |= remove_name(PSHM, shmdsp->name);
+ }
+ posix_ipc_shm_free_info(shmds);
+ }
+ }
  if (type == SEM || type == ALL) {
  arg.array = (ushort *) (void *)&seminfo;
  maxid = semctl(0, 0, SEM_INFO, arg);
@@ -269,6 +337,16 @@ static int remove_all(type_id type)
  ret |= remove_id(SEM, 0, rm_me);
  }
  }
+ if (type == PSEM || type == ALL) {
+ if (posix_ipc_sem_get_info(NULL, &semds) > 0) {
+ for (semdsp = semds; semdsp->next != NULL; semdsp = semdsp->next) {
+ if (verbose)
+ printf(_("removing POSIX semaphore `%s'\n"), semdsp->sname);
+ ret |= remove_name(PSEM, semdsp->sname);
+ }
+ posix_ipc_sem_free_info(semds);
+ }
+ }
  if (type == MSG || type == ALL) {
  maxid =
     msgctl(0, MSG_INFO, (struct msqid_ds *)(void *)&msginfo);
@@ -282,6 +360,16 @@ static int remove_all(type_id type)
  ret |= remove_id(MSG, 0, rm_me);
  }
  }
+ if (type == PMSG || type == ALL) {
+ if (posix_ipc_msg_get_info(NULL, &msgds) > 0) {
+ for (msgdsp = msgds; msgdsp->next != NULL; msgdsp = msgdsp->next) {
+ if (verbose)
+ printf(_("removing POSIX message queue `%s'\n"), msgdsp->mname);
+ ret |= remove_name(PMSG, msgdsp->mname);
+ }
+ posix_ipc_msg_free_info(msgds);
+ }
+ }
  return ret;
 }

@@ -294,13 +382,22 @@ int main(int argc, char **argv)
  int rm_all = 0;
  type_id what_all = ALL;

+ enum {
+ OPT_PSHM = CHAR_MAX + 1,
+ OPT_PMSG,
+ OPT_PSEM
+ };
+
  static const struct option longopts[] = {
  {"shmem-id", required_argument, NULL, 'm'},
  {"shmem-key", required_argument, NULL, 'M'},
+ {"posix-shmem", required_argument, NULL, OPT_PSHM},
  {"queue-id", required_argument, NULL, 'q'},
  {"queue-key", required_argument, NULL, 'Q'},
+ {"posix-mqueue", required_argument, NULL, OPT_PMSG},
  {"semaphore-id", required_argument, NULL, 's'},
  {"semaphore-key", required_argument, NULL, 'S'},
+ {"posix-semaphore", required_argument, NULL, OPT_PSEM},
  {"all", optional_argument, NULL, 'a'},
  {"verbose", no_argument, NULL, 'v'},
  {"version", no_argument, NULL, 'V'},
@@ -309,8 +406,10 @@ int main(int argc, char **argv)
  };

  /* if the command is executed without parameters, do nothing */
- if (argc == 1)
- return 0;
+ if (argc == 1) {
+ warnx(_("bad usage"));
+ errtryhelp(EXIT_FAILURE);
+ }

  setlocale(LC_ALL, "");
  bindtextdomain(PACKAGE, LOCALEDIR);
@@ -368,15 +467,33 @@ int main(int argc, char **argv)
  if (remove_id(SEM, iskey, id))
  ret++;
  break;
+ case OPT_PSHM:
+ if (remove_name(PSHM, optarg))
+ ret++;
+ break;
+ case OPT_PMSG:
+ if (remove_name(PMSG, optarg))
+ ret++;
+ break;
+ case OPT_PSEM:
+ if (remove_name(PSEM, optarg))
+ ret++;
+ break;
  case 'a':
  rm_all = 1;
  if (optarg) {
  if (!strcmp(optarg, "shm"))
  what_all = SHM;
+ else if (!strcmp(optarg, "pshm"))
+ what_all = PSHM;
  else if (!strcmp(optarg, "msg"))
  what_all = MSG;
+ else if (!strcmp(optarg, "pmsg"))
+ what_all = PMSG;
  else if (!strcmp(optarg, "sem"))
  what_all = SEM;
+ else if (!strcmp(optarg, "psem"))
+ what_all = PSEM;
  else
  errx(EXIT_FAILURE,
      _("unknown argument: %s"), optarg);
diff --git a/sys-utils/ipcutils.c b/sys-utils/ipcutils.c
index 4d4bebb74..7aeccbeca 100644
--- a/sys-utils/ipcutils.c
+++ b/sys-utils/ipcutils.c
@@ -51,6 +51,30 @@ int ipc_msg_get_limits(struct ipc_limits *lim)
  lim->msgmax = msginfo.msgmax;
  }

+ /* POSIX IPC */
+ FILE *f;
+
+ f = fopen(_PATH_PROC_POSIX_IPC_MSGMNI, "r");
+ if (f) {
+ if(fscanf(f, "%"SCNu64, &lim->msgmni_posix) != 1)
+ lim->msgmni_posix = 0;
+ fclose(f);
+ }
+
+ f = fopen(_PATH_PROC_POSIX_IPC_MSGMNB, "r");
+ if (f) {
+ if(fscanf(f, "%"SCNu64, &lim->msgmnb_posix) != 1)
+ lim->msgmnb_posix = 0;
+ fclose(f);
+ }
+
+ f = fopen(_PATH_PROC_POSIX_IPC_MSGMAX, "r");
+ if (f) {
+ if(fscanf(f, "%"SCNu64, &lim->msgmax_posix) != 1)
+ lim->msgmax_posix = 0;
+ fclose(f);
+ }
+
  return 0;
 }

@@ -227,6 +251,75 @@ void ipc_shm_free_info(struct shm_data *shmds)
  }
 }

+int posix_ipc_shm_get_info(const char *name, struct posix_shm_data **shmds)
+{
+ DIR *d;
+ int i = 0;
+ struct posix_shm_data *p;
+ struct dirent *de;
+
+ p = *shmds = xcalloc(1, sizeof(struct posix_shm_data));
+ p->next = NULL;
+
+ d = opendir(_PATH_DEV_SHM);
+ if (!d)
+ err(EXIT_FAILURE, _("cannot open %s"), _PATH_DEV_SHM);
+
+ while ((de = readdir(d)) != NULL) {
+ if ((de->d_name[0] == '.' && de->d_name[1] == '\0') ||
+    (de->d_name[0] == '.' && de->d_name[1] == '.' &&
+     de->d_name[2] == '\0'))
+ continue;
+
+ if (strncmp(de->d_name, "sem.", 4) == 0)
+ continue;
+
+ struct stat st;
+ char path[PATH_MAX];
+ snprintf(path, sizeof(path), "%s/%s", _PATH_DEV_SHM, de->d_name);
+ if (stat(path, &st) < 0)
+ continue;
+
+ memset(path, 0, sizeof(path));
+ path[0] = '/';
+ strcat(path, de->d_name);
+
+ p->name = xstrdup(path);
+ p->cuid = st.st_uid;
+ p->cgid = st.st_gid;
+ p->size = st.st_size;
+ p->mode = st.st_mode;
+ p->mtime = st.st_mtime;
+
+ if (name != NULL) {
+ if (strcmp(name, path) == 0) {
+ i = 1;
+ break;
+ }
+ continue;
+ }
+
+ p->next = xcalloc(1, sizeof(struct posix_shm_data));
+ p = p->next;
+ p->next = NULL;
+ i++;
+ }
+
+ if (i == 0)
+ free(*shmds);
+ closedir(d);
+ return i;
+}
+
+void posix_ipc_shm_free_info(struct posix_shm_data *shmds)
+{
+ while (shmds) {
+ struct posix_shm_data *next = shmds->next;
+ free(shmds);
+ shmds = next;
+ }
+}
+
 static void get_sem_elements(struct sem_data *p)
 {
  size_t i;
@@ -366,6 +459,80 @@ void ipc_sem_free_info(struct sem_data *semds)
  }
 }

+int posix_ipc_sem_get_info(const char *name, struct posix_sem_data **semds)
+{
+ DIR *d;
+ int i = 0;
+ struct posix_sem_data *p;
+ struct dirent *de;
+
+ p = *semds = xcalloc(1, sizeof(struct posix_sem_data));
+ p->next = NULL;
+
+ d = opendir(_PATH_DEV_SHM);
+ if (!d)
+ err(EXIT_FAILURE, _("cannot open %s"), _PATH_DEV_SHM);
+
+ while ((de = readdir(d)) != NULL) {
+ if ((de->d_name[0] == '.' && de->d_name[1] == '\0') ||
+    (de->d_name[0] == '.' && de->d_name[1] == '.' &&
+     de->d_name[2] == '\0'))
+ continue;
+
+ if (strncmp(de->d_name, "sem.", 4) != 0)
+ continue;
+
+ struct stat st;
+ char path[PATH_MAX];
+ snprintf(path, sizeof(path), "%s/%s", _PATH_DEV_SHM, de->d_name);
+ if (stat(path, &st) < 0)
+ continue;
+
+ sem_t *sem = sem_open(de->d_name + 4, 0);
+ if (sem == SEM_FAILED)
+ continue;
+ sem_getvalue(sem, &p->sval);
+ sem_close(sem);
+
+ memset(path, 0, sizeof(path));
+ path[0] = '/';
+ strcat(path, de->d_name + 4);
+
+ p->sname = xstrdup(path);
+ p->cuid = st.st_uid;
+ p->cgid = st.st_gid;
+ p->mode = st.st_mode;
+ p->mtime = st.st_mtime;
+
+ if (name != NULL) {
+ if (strcmp(name, path) == 0) {
+ i = 1;
+ break;
+ }
+ continue;
+ }
+
+ p->next = xcalloc(1, sizeof(struct posix_sem_data));
+ p = p->next;
+ p->next = NULL;
+ i++;
+ }
+
+ if (i == 0)
+ free(*semds);
+ closedir(d);
+ return i;
+}
+
+void posix_ipc_sem_free_info(struct posix_sem_data *semds)
+{
+ while (semds) {
+ struct posix_sem_data *next = semds->next;
+ free(semds);
+ semds = next;
+ }
+}
+
 int ipc_msg_get_info(int id, struct msg_data **msgds)
 {
  FILE *f;
@@ -477,6 +644,124 @@ void ipc_msg_free_info(struct msg_data *msgds)
  }
 }

+int posix_ipc_msg_get_info(const char *name, struct posix_msg_data **msgds)
+{
+ FILE *f;
+ DIR *d;
+ int i = 0, mounted = 0;
+ struct posix_msg_data *p;
+ struct dirent *de;
+
+ p = *msgds = xcalloc(1, sizeof(struct msg_data));
+ p->next = NULL;
+
+ d = opendir(_PATH_DEV_MQUEUE);
+ if (!d) {
+ if (errno == ENOENT) {
+ struct libmnt_context *ctx;
+
+ ctx = mnt_new_context();
+ if (!ctx)
+ err(EXIT_FAILURE, _("cannot create libmount context"));
+
+ if (mnt_context_set_source(ctx, "none") < 0)
+ err(EXIT_FAILURE, _("cannot set source"));
+
+ if (mnt_context_set_target(ctx, _PATH_DEV_MQUEUE) < 0)
+ err(EXIT_FAILURE, _("cannot set target"));
+
+ if (mnt_context_set_fstype(ctx, "mqueue") < 0)
+ err(EXIT_FAILURE, _("cannot set filesystem type"));
+
+ if (mnt_context_mount(ctx) < 0)
+ err(EXIT_FAILURE, _("cannot mount %s"), _PATH_DEV_MQUEUE);
+
+ mounted = 1;
+ } else err(EXIT_FAILURE, _("cannot open %s"), _PATH_DEV_MQUEUE);
+ }
+
+ while ((de = readdir(d)) != NULL) {
+ if ((de->d_name[0] == '.' && de->d_name[1] == '\0') ||
+    (de->d_name[0] == '.' && de->d_name[1] == '.' &&
+     de->d_name[2] == '\0'))
+ continue;
+
+ struct stat st;
+ char path[PATH_MAX];
+ snprintf(path, sizeof(path), "%s/%s", _PATH_DEV_MQUEUE, de->d_name);
+ if (stat(path, &st) < 0)
+ continue;
+
+ f = fopen(path, "r");
+ if (!f)
+ continue;
+ if (fscanf(f, "QSIZE:%"SCNu64, &p->q_cbytes) != 1) {
+ fclose(f);
+ continue;
+ }
+ fclose(f);
+
+ memset(path, 0, sizeof(path));
+ path[0] = '/';
+ strcat(path, de->d_name);
+
+ p->mname = xstrdup(path);
+
+ mqd_t mq = mq_open(path, O_RDONLY);
+ struct mq_attr attr;
+ mq_getattr(mq, &attr);
+ p->q_qnum = attr.mq_curmsgs;
+ mq_close(mq);
+
+ p->cuid = st.st_uid;
+ p->cgid = st.st_gid;
+ p->mode = st.st_mode;
+ p->mtime = st.st_mtime;
+
+ if (name != NULL) {
+ if (strcmp(name, path) == 0) {
+ i = 1;
+ break;
+ }
+ continue;
+ }
+
+ p->next = xcalloc(1, sizeof(struct posix_msg_data));
+ p = p->next;
+ p->next = NULL;
+ i++;
+ }
+
+ if (i == 0)
+ free(*msgds);
+ closedir(d);
+
+ if (mounted) {
+ struct libmnt_context *ctx;
+
+ ctx = mnt_new_context();
+ if (!ctx)
+ err(EXIT_FAILURE, _("cannot create libmount context"));
+
+ if (mnt_context_set_target(ctx, _PATH_DEV_MQUEUE) < 0)
+ err(EXIT_FAILURE, _("cannot set target"));
+
+ if (mnt_context_umount(ctx) < 0)
+ err(EXIT_FAILURE, _("cannot umount %s"), _PATH_DEV_MQUEUE);
+ }
+
+ return i;
+}
+
+void posix_ipc_msg_free_info(struct posix_msg_data *msgds)
+{
+ while (msgds) {
+ struct posix_msg_data *next = msgds->next;
+ free(msgds);
+ msgds = next;
+ }
+}
+
 void ipc_print_perms(FILE *f, struct ipc_stat *is)
 {
  struct passwd *pw;
diff --git a/sys-utils/ipcutils.h b/sys-utils/ipcutils.h
index 0234465d2..7c6963aa5 100644
--- a/sys-utils/ipcutils.h
+++ b/sys-utils/ipcutils.h
@@ -18,12 +18,15 @@
 #include <sys/msg.h>
 #include <sys/sem.h>
 #include <sys/shm.h>
+#include <mqueue.h>
+#include <semaphore.h>
 #include <sys/types.h>
 #include <time.h>
 #include <unistd.h>
 #include <grp.h>
 #include <pwd.h>
 #include <stdint.h>
+#include <libmount.h>

 /*
  * SHM_DEST and SHM_LOCKED are defined in kernel headers, but inside
@@ -99,6 +102,7 @@ enum {
 };

 struct ipc_limits {
+ /* System V IPC */
  uint64_t shmmni; /* max number of segments */
  uint64_t shmmax; /* max segment size */
  uint64_t shmall; /* max total shared memory */
@@ -113,6 +117,11 @@ struct ipc_limits {
  int msgmni; /* max queues system wide */
  uint64_t msgmax; /* max size of message */
  int msgmnb; /* default max size of queue */
+
+ /* POSIX IPC */
+ uint64_t msgmax_posix; /* max size of message */
+ uint64_t msgmni_posix; /* max queues system wide */
+ uint64_t msgmnb_posix; /* default max number of messages in a queue */
 };

 extern int ipc_msg_get_limits(struct ipc_limits *lim);
@@ -153,6 +162,20 @@ struct shm_data {
 extern int ipc_shm_get_info(int id, struct shm_data **shmds);
 extern void ipc_shm_free_info(struct shm_data *shmds);

+struct posix_shm_data {
+ char *name;
+ int64_t mtime; /* last change time */
+ uid_t cuid;
+ gid_t cgid;
+ off_t size;
+ unsigned int mode;
+
+ struct posix_shm_data *next;
+};
+
+extern int posix_ipc_shm_get_info(const char *name, struct
posix_shm_data **shmds);
+extern void posix_ipc_shm_free_info(struct posix_shm_data *shmds);
+
 /* See 'struct sem_array' in kernel sources
  */
 struct sem_elem {
@@ -175,6 +198,20 @@ struct sem_data {
 extern int ipc_sem_get_info(int id, struct sem_data **semds);
 extern void ipc_sem_free_info(struct sem_data *semds);

+struct posix_sem_data {
+ char *sname;
+ int64_t mtime; /* last change time */
+ uid_t cuid;
+ gid_t cgid;
+ unsigned int mode;
+ int sval; /* semaphore value */
+
+ struct posix_sem_data *next;
+};
+
+extern int posix_ipc_sem_get_info(const char *name, struct
posix_sem_data **semds);
+extern void posix_ipc_sem_free_info(struct posix_sem_data *semds);
+
 /* See 'struct msg_queue' in kernel sources
  */
 struct msg_data {
@@ -195,4 +232,19 @@ struct msg_data {
 extern int ipc_msg_get_info(int id, struct msg_data **msgds);
 extern void ipc_msg_free_info(struct msg_data *msgds);

+struct posix_msg_data {
+ char *mname;
+ int64_t mtime;
+ uid_t cuid;
+ gid_t cgid;
+ unsigned int mode;
+ uint64_t q_cbytes; /* current number of bytes on the queue */
+ long q_qnum; /* number of messages on the queue */
+
+ struct posix_msg_data *next;
+};
+
+extern int posix_ipc_msg_get_info(const char *name, struct
posix_msg_data **msgds);
+extern void posix_ipc_msg_free_info(struct posix_msg_data *msgds);
+
 #endif /* UTIL_LINUX_IPCUTILS_H */
diff --git a/sys-utils/lsipc.1.adoc b/sys-utils/lsipc.1.adoc
index 3ee790e21..01deaf95f 100644
--- a/sys-utils/lsipc.1.adoc
+++ b/sys-utils/lsipc.1.adoc
@@ -16,12 +16,15 @@ lsipc - show information on IPC facilities
currently employed in the system

 == DESCRIPTION

-*lsipc* shows information on the System V inter-process communication
facilities for which the calling process has read access.
+*lsipc* shows information on the POSIX and System V inter-process
communication facilities for which the calling process has read
access.

 == OPTIONS

 *-i*, *--id* _id_::
-Show full details on just the one resource element identified by
_id_. This option needs to be combined with one of the three resource
options: *-m*, *-q* or *-s*. It is possible to override the default
output format for this option with the *--list*, *--raw*, *--json* or
*--export* option.
+Show full details on just the one resource element (System V)
identified by _id_. This option needs to be combined with one of the
three resource options: *-m*, *-q* or *-s*. It is possible to override
the default output format for this option with the *--list*, *--raw*,
*--json* or *--export* option.
+
+*-N*, *--name* _name_::
+Show full details on just the one resource element (POSIX) identified
by _name_. This option needs to be combined with one of the three
resource options: *-M*, *-Q* or *-S*. It is possible to override the
default output format for this option with the *--list*, *--raw*,
*--json* or *--export* option.

 *-g*, *--global*::
 Show system-wide usage and limits of IPC resources. This option may
be combined with one of the three resource options: *-m*, *-q* or
*-s*. The default is to show information about all resources.
@@ -31,13 +34,22 @@ include::man-common/help-version.adoc[]
 === Resource options

 *-m*, *--shmems*::
-Write information about active shared memory segments.
+Write information about active System V shared memory segments.
+
+*-M*, *--posix-shmems*::
+Write information about active POSIX shared memory segments.

 *-q*, *--queues*::
-Write information about active message queues.
+Write information about active System V message queues.
+
+*-Q*, *--posix-mqueues*::
+Write information about active POSIX message queues. Mounts
/dev/mqueue if not already mounted.

 *-s*, *--semaphores*::
-Write information about active semaphore sets.
+Write information about active System V semaphore sets.
+
+*-S*, *--posix-semaphores*::
+Write information about active POSIX named semaphores.

 === Output formatting

diff --git a/sys-utils/lsipc.c b/sys-utils/lsipc.c
index 85ebcafd3..c095f315c 100644
--- a/sys-utils/lsipc.c
+++ b/sys-utils/lsipc.c
@@ -59,12 +59,17 @@ enum {
  COLDESC_IDX_GEN_FIRST = 0,
  COL_KEY = COLDESC_IDX_GEN_FIRST,
  COL_ID,
- COL_OWNER,
- COL_PERMS,
- COL_CUID,
- COL_CUSER,
- COL_CGID,
- COL_CGROUP,
+
+ /* generic and posix */
+ COLDESC_IDX_GEN_POSIX_FIRST,
+ COL_OWNER = COLDESC_IDX_GEN_POSIX_FIRST,
+ COL_PERMS,
+ COL_CUID,
+ COL_CUSER,
+ COL_CGID,
+ COL_CGROUP,
+ COLDSEC_IDX_GEN_POSIX_LAST = COL_CGROUP,
+
  COL_UID,
  COL_USER,
  COL_GID,
@@ -72,6 +77,12 @@ enum {
  COL_CTIME,
  COLDESC_IDX_GEN_LAST = COL_CTIME,

+ /* posix-specific */
+ COLDESC_IDX_POSIX_FIRST,
+ COL_NAME = COLDESC_IDX_POSIX_FIRST,
+ COL_MTIME,
+ COLDESC_IDX_POSIX_LAST = COL_MTIME,
+
  /* msgq-specific */
  COLDESC_IDX_MSG_FIRST,
  COL_USEDBYTES = COLDESC_IDX_MSG_FIRST,
@@ -107,7 +118,12 @@ enum {
  COL_LIMIT,
  COL_USED,
  COL_USEPERC,
- COLDESC_IDX_SUM_LAST = COL_USEPERC
+ COLDESC_IDX_SUM_LAST = COL_USEPERC,
+
+ /* posix-sem-specific */
+ COLDESC_IDX_POSIX_SEM_FIRST,
+ COL_SVAL = COLDESC_IDX_POSIX_SEM_FIRST,
+ COLDESC_IDX_POSIX_SEM_LAST = COL_SVAL
 };

 /* not all columns apply to all options, so we specify a legal range
for each */
@@ -161,6 +177,10 @@ static const struct lsipc_coldesc coldescs[] =
  [COL_GROUP] = { "GROUP", N_("Group name"), N_("Group name"), 1},
  [COL_CTIME] = { "CTIME", N_("Time of the last change"), N_("Last
change"), 1, SCOLS_FL_RIGHT},

+ /* posix-common */
+ [COL_NAME] = { "NAME",     N_("Resource name"), N_("Name"), 1 },
+ [COL_MTIME] = { "MTIME",   N_("Time of last action"), N_("Last
action"), 1, SCOLS_FL_RIGHT},
+
  /* msgq-specific */
  [COL_USEDBYTES] = { "USEDBYTES",N_("Bytes used"), N_("Bytes used"),
1, SCOLS_FL_RIGHT},
  [COL_MSGS] = { "MSGS", N_("Number of messages"), N_("Messages"), 1},
@@ -189,6 +209,9 @@ static const struct lsipc_coldesc coldescs[] =
  [COL_USED]      = { "USED",     N_("Currently used"), N_("Used"), 1,
SCOLS_FL_RIGHT },
  [COL_USEPERC] = { "USE%",     N_("Currently use percentage"),
N_("Use"), 1, SCOLS_FL_RIGHT },
  [COL_LIMIT]     = { "LIMIT",    N_("System-wide limit"),
N_("Limit"), 1, SCOLS_FL_RIGHT },
+
+ /* posix-sem-specific */
+ [COL_SVAL] = { "SVAL", N_("Semaphore value"), N_("Value"), 1, SCOLS_FL_RIGHT}
 };


@@ -296,11 +319,15 @@ static void __attribute__((__noreturn__)) usage(void)

  fputs(USAGE_SEPARATOR, out);
  fputs(_("Resource options:\n"), out);
- fputs(_(" -m, --shmems      shared memory segments\n"), out);
- fputs(_(" -q, --queues      message queues\n"), out);
- fputs(_(" -s, --semaphores  semaphores\n"), out);
- fputs(_(" -g, --global      info about system-wide usage (may be
used with -m, -q and -s)\n"), out);
- fputs(_(" -i, --id <id>     print details on resource identified by
<id>\n"), out);
+ fputs(_(" -m, --shmems           shared memory segments\n"), out);
+ fputs(_(" -M, --posix-shmems     POSIX shared memory segments\n"), out);
+ fputs(_(" -q, --queues         message queues\n"), out);
+ fputs(_(" -Q, --posix-mqueues POSIX message queues\n"), out);
+ fputs(_(" -s, --semaphores     semaphores\n"), out);
+ fputs(_(" -S, --posix-semaphores POSIX semaphores\n"), out);
+ fputs(_(" -g, --global       info about system-wide usage (may be
used with -m, -q and -s)\n"), out);
+ fputs(_(" -i, --id <id>          print details on resource
identified by <id>\n"), out);
+ fputs(_(" -N, --name <name>      print details on posix resource
identified by <name>\n"), out);

  fputs(USAGE_OPTIONS, out);
  fputs(_("     --noheadings         don't print headings\n"), out);
@@ -322,22 +349,32 @@ static void __attribute__((__noreturn__)) usage(void)
  fputs(USAGE_SEPARATOR, out);
  fprintf(out, USAGE_HELP_OPTIONS(26));

- fprintf(out, _("\nGeneric columns:\n"));
+ fprintf(out, _("\nGeneric System V columns:\n"));
  for (i = COLDESC_IDX_GEN_FIRST; i <= COLDESC_IDX_GEN_LAST; i++)
  fprintf(out, " %14s  %s\n", coldescs[i].name, _(coldescs[i].help));
+
+ fprintf(out, _("\nGeneric POSIX columns:\n"));
+ fprintf(out, " %14s  %s\n", coldescs[COL_NAME].name,
_(coldescs[COL_NAME].help));
+ for (i = COLDESC_IDX_GEN_POSIX_FIRST; i <= COLDSEC_IDX_GEN_POSIX_LAST; i++)
+ fprintf(out, " %14s  %s\n", coldescs[i].name, _(coldescs[i].help));
+ fprintf(out, " %14s  %s\n", coldescs[COL_MTIME].name,
_(coldescs[COL_MTIME].help));

- fprintf(out, _("\nShared-memory columns (--shmems):\n"));
+ fprintf(out, _("\nSystem V Shared-memory columns (--shmems):\n"));
  for (i = COLDESC_IDX_SHM_FIRST; i <= COLDESC_IDX_SHM_LAST; i++)
  fprintf(out, " %14s  %s\n", coldescs[i].name, _(coldescs[i].help));

- fprintf(out, _("\nMessage-queue columns (--queues):\n"));
+ fprintf(out, _("\nSystem V Message-queue columns (--queues):\n"));
  for (i = COLDESC_IDX_MSG_FIRST; i <= COLDESC_IDX_MSG_LAST; i++)
  fprintf(out, " %14s  %s\n", coldescs[i].name, _(coldescs[i].help));

- fprintf(out, _("\nSemaphore columns (--semaphores):\n"));
+ fprintf(out, _("\nSystem V Semaphore columns (--semaphores):\n"));
  for (i = COLDESC_IDX_SEM_FIRST; i <= COLDESC_IDX_SEM_LAST; i++)
  fprintf(out, " %14s  %s\n", coldescs[i].name, _(coldescs[i].help));

+ fprintf(out, _("\nPOSIX Semaphore columns (--posix-semaphores):\n"));
+ for (i = COLDESC_IDX_POSIX_SEM_FIRST; i <= COLDESC_IDX_POSIX_SEM_LAST; i++)
+ fprintf(out, " %14s  %s\n", coldescs[i].name, _(coldescs[i].help));
+
  fprintf(out, _("\nSummary columns (--global):\n"));
  for (i = COLDESC_IDX_SUM_FIRST; i <= COLDESC_IDX_SUM_LAST; i++)
  fprintf(out, " %14s  %s\n", coldescs[i].name, _(coldescs[i].help));
@@ -728,6 +765,92 @@ static void do_sem_global(struct lsipc_control
*ctl, struct libscols_table *tb)
  global_set_data(ctl, tb, "SEMVMX", _("Semaphore max value"), 0,
lim.semvmx, 0, 0);
 }

+static void do_posix_sem(const char *name, struct lsipc_control *ctl,
struct libscols_table *tb)
+{
+ struct libscols_line *ln;
+ struct passwd *pw = NULL;
+ struct group *gr = NULL;
+ struct posix_sem_data *semds, *p;
+ char *arg = NULL;
+
+ scols_table_set_name(tb, "posix-semaphores");
+ if (posix_ipc_sem_get_info(name, &semds) < 1) {
+ if (name)
+ warnx(_("name %s not found"), name);
+ return;
+ }
+ for (p = semds; p->next != NULL || name != NULL; p = p->next) {
+ size_t n;
+
+ ln = scols_table_new_line(tb, NULL);
+ if (!ln)
+ err(EXIT_FAILURE, _("failed to allocate output line"));
+
+ /* no need to call getpwuid() for the same user */
+ if (!(pw && pw->pw_uid == p->cuid))
+ pw = getpwuid(p->cuid);
+
+ /* no need to call getgrgid() for the same user */
+ if (!(gr && gr->gr_gid == p->cgid))
+ gr = getgrgid(p->cgid);
+
+ for (n = 0; n < ncolumns; n++) {
+ int rc = 0;
+ switch (get_column_id(n)) {
+ case COL_NAME:
+ rc = scols_line_set_data(ln, n, p->sname);
+ break;
+ case COL_OWNER:
+ arg = get_username(&pw, p->cuid);
+ if (!arg)
+ xasprintf(&arg, "%u", p->cuid);
+ rc = scols_line_refer_data(ln, n, arg);
+ break;
+ case COL_PERMS:
+ if (ctl->numperms)
+ xasprintf(&arg, "%#o", p->mode & 0777);
+ else {
+ arg = xmalloc(11);
+ xstrmode(p->mode & 0777, arg);
+ }
+ rc = scols_line_refer_data(ln, n, arg);
+ break;
+ case COL_MTIME:
+ if (p->mtime != 0)
+ rc = scols_line_refer_data(ln, n,
+ make_time(ctl->time_mode,
+  (time_t) p->mtime));
+ break;
+ case COL_CUID:
+ rc = scols_line_sprintf(ln, n, "%u", p->cuid);
+ break;
+ case COL_CUSER:
+ arg = get_username(&pw, p->cuid);
+ if (arg)
+ rc = scols_line_refer_data(ln, n, arg);
+ break;
+ case COL_CGID:
+ rc = scols_line_sprintf(ln, n, "%u", p->cgid);
+ break;
+ case COL_CGROUP:
+ arg = get_groupname(&gr, p->cgid);
+ if (arg)
+ rc = scols_line_refer_data(ln, n, arg);
+ break;
+ case COL_SVAL:
+ rc = scols_line_sprintf(ln, n, "%d", p->sval);
+ break;
+ }
+ if (rc != 0)
+ err(EXIT_FAILURE, _("failed to add output data"));
+ arg = NULL;
+ }
+ if (name != NULL)
+ break;
+ }
+ posix_ipc_sem_free_info(semds);
+}
+
 static void do_msg(int id, struct lsipc_control *ctl, struct
libscols_table *tb)
 {
  struct libscols_line *ln;
@@ -861,6 +984,101 @@ static void do_msg(int id, struct lsipc_control
*ctl, struct libscols_table *tb)
  ipc_msg_free_info(msgds);
 }

+static void do_posix_msg(const char *name, struct lsipc_control *ctl,
struct libscols_table *tb)
+{
+    struct libscols_line *ln;
+ struct passwd *pw = NULL;
+ struct group *gr = NULL;
+ struct posix_msg_data *msgds, *p;
+ char *arg = NULL;
+
+ if (posix_ipc_msg_get_info(name, &msgds) < 1) {
+ if (name != NULL)
+ warnx(_("mqueue %s not found"), name);
+ return;
+ }
+ scols_table_set_name(tb, "posix-messages");
+
+ for (p = msgds; p->next != NULL || name != NULL; p = p->next) {
+ size_t n;
+ ln = scols_table_new_line(tb, NULL);
+
+ if (!ln)
+ err(EXIT_FAILURE, _("failed to allocate output line"));
+
+ /* no need to call getpwuid() for the same user */
+ if (!(pw && pw->pw_uid == p->cuid))
+ pw = getpwuid(p->cuid);
+
+ /* no need to call getgrgid() for the same user */
+ if (!(gr && gr->gr_gid == p->cgid))
+ gr = getgrgid(p->cgid);
+
+ for (n = 0; n < ncolumns; n++) {
+ int rc = 0;
+
+ switch (get_column_id(n)) {
+ case COL_NAME:
+ rc = scols_line_refer_data(ln, n, p->mname);
+ break;
+ case COL_OWNER:
+ arg = get_username(&pw, p->cuid);
+ if (!arg)
+ xasprintf(&arg, "%u", p->cuid);
+ rc = scols_line_refer_data(ln, n, arg);
+ break;
+ case COL_PERMS:
+ if (ctl->numperms)
+ xasprintf(&arg, "%#o", p->mode & 0777);
+ else {
+ arg = xmalloc(11);
+ xstrmode(p->mode & 0777, arg);
+ rc = scols_line_refer_data(ln, n, arg);
+ }
+ break;
+ case COL_CUID:
+ rc = scols_line_sprintf(ln, n, "%u", p->cuid);
+ break;
+ case COL_CUSER:
+ arg = get_username(&pw, p->cuid);
+ if (arg)
+ rc = scols_line_refer_data(ln, n, arg);
+ break;
+ case COL_CGID:
+ rc = scols_line_sprintf(ln, n, "%u", p->cgid);
+ break;
+ case COL_CGROUP:
+ arg = get_groupname(&gr, p->cgid);
+ if (arg)
+ rc = scols_line_refer_data(ln, n, arg);
+ break;
+ case COL_MTIME:
+ if (p->mtime != 0)
+ rc = scols_line_refer_data(ln, n,
+ make_time(ctl->time_mode,
+  (time_t) p->mtime));
+ break;
+ case COL_USEDBYTES:
+ if (ctl->bytes)
+ xasprintf(&arg, "%ju", p->q_cbytes);
+ else
+ arg = size_to_human_string(SIZE_SUFFIX_1LETTER,
+ p->q_cbytes);
+ rc = scols_line_refer_data(ln, n, arg);
+ break;
+ case COL_MSGS:
+ rc = scols_line_sprintf(ln, n, "%ju", p->q_qnum);
+ break;
+ }
+ if (rc != 0)
+ err(EXIT_FAILURE, _("failed to set data"));
+ arg = NULL;
+ }
+ if (name != NULL)
+ break;
+ }
+ posix_ipc_msg_free_info(msgds);
+}

 static void do_msg_global(struct lsipc_control *ctl, struct libscols_table *tb)
 {
@@ -879,9 +1097,31 @@ static void do_msg_global(struct lsipc_control
*ctl, struct libscols_table *tb)
  ipc_msg_free_info(msgds);
  }

- global_set_data(ctl, tb, "MSGMNI", _("Number of message queues"),
msgqs, lim.msgmni, 1, 0);
- global_set_data(ctl, tb, "MSGMAX", _("Max size of message (bytes)"),
0, lim.msgmax, 0, 1);
- global_set_data(ctl, tb, "MSGMNB", _("Default max size of queue
(bytes)"), 0, lim.msgmnb, 0, 1);
+ global_set_data(ctl, tb, "MSGMNI", _("Number of System V message
queues"), msgqs, lim.msgmni, 1, 0);
+ global_set_data(ctl, tb, "MSGMAX", _("Max size of System V message
(bytes)"), 0, lim.msgmax, 0, 1);
+ global_set_data(ctl, tb, "MSGMNB", _("Default max size of System V
queue (bytes)"), 0, lim.msgmnb, 0, 1);
+}
+
+static void do_posix_msg_global(struct lsipc_control *ctl, struct
libscols_table *tb)
+{
+ struct posix_msg_data *pmsgds;
+ struct ipc_limits lim;
+ int pmsgqs = 0;
+
+ ipc_msg_get_limits(&lim);
+
+ /* count number of used posix queues */
+ if (posix_ipc_msg_get_info(NULL, &pmsgds) > 0) {
+ struct posix_msg_data *p;
+
+ for (p = pmsgds; p->next != NULL; p = p->next)
+ ++pmsgqs;
+ posix_ipc_msg_free_info(pmsgds);
+ }
+
+ global_set_data(ctl, tb, "MQUMNI", _("Number of POSIX message
queues"), pmsgqs, lim.msgmni_posix, 1, 0);
+ global_set_data(ctl, tb, "MQUMAX", _("Max size of POSIX message
(bytes)"), 0, lim.msgmax_posix, 0, 1);
+ global_set_data(ctl, tb, "MQUMNB", _("Number of messages in POSIX
message queue"), 0, lim.msgmnb_posix, 0, 0);
 }


@@ -1054,6 +1294,100 @@ static void do_shm(int id, struct
lsipc_control *ctl, struct libscols_table *tb)
  ipc_shm_free_info(shmds);
 }

+static void do_posix_shm(const char *name, struct lsipc_control *ctl,
struct libscols_table *tb)
+{
+ struct libscols_line *ln;
+ struct passwd *pw = NULL;
+ struct group *gr = NULL;
+ struct posix_shm_data *shmds, *p;
+ char *arg = NULL;
+
+ if (posix_ipc_shm_get_info(name, &shmds) < 1) {
+ if (name != NULL)
+ warnx(_("shm %s not found"), name);
+ return;
+ }
+
+ scols_table_set_name(tb, "posix-sharedmemory");
+
+ for (p = shmds; p->next != NULL || name != NULL ; p = p->next) {
+ size_t n;
+ ln = scols_table_new_line(tb, NULL);
+
+ if (!ln)
+ err(EXIT_FAILURE, _("failed to allocate output line"));
+
+ /* no need to call getpwuid() for the same user */
+ if (!(pw && pw->pw_uid == p->cuid))
+ pw = getpwuid(p->cuid);
+
+ /* no need to call getgrgid() for the same user */
+ if (!(gr && gr->gr_gid == p->cgid))
+ gr = getgrgid(p->cgid);
+
+ for (n = 0; n < ncolumns; n++) {
+ int rc = 0;
+
+ switch (get_column_id(n)) {
+ case COL_NAME:
+ rc = scols_line_refer_data(ln, n, p->name);
+ break;
+ case COL_OWNER:
+ arg = get_username(&pw, p->cuid);
+ if (!arg)
+ xasprintf(&arg, "%u", p->cuid);
+ rc = scols_line_refer_data(ln, n, arg);
+ break;
+ case COL_PERMS:
+ if (ctl->numperms)
+ xasprintf(&arg, "%#o", p->mode & 0777);
+ else {
+ arg = xmalloc(11);
+ xstrmode(p->mode & 0777, arg);
+ }
+ rc = scols_line_refer_data(ln, n, arg);
+ break;
+ case COL_CUID:
+ rc = scols_line_sprintf(ln, n, "%u", p->cuid);
+ break;
+ case COL_CUSER:
+ arg = get_username(&pw, p->cuid);
+ if (arg)
+ rc = scols_line_refer_data(ln, n, arg);
+ break;
+ case COL_CGID:
+ rc = scols_line_sprintf(ln, n, "%u", p->cgid);
+ break;
+ case COL_CGROUP:
+ arg = get_groupname(&gr, p->cgid);
+ if (arg)
+ rc = scols_line_refer_data(ln, n, arg);
+ break;
+ case COL_SIZE:
+ if (ctl->bytes)
+ xasprintf(&arg, "%ju", p->size);
+ else
+ arg = size_to_human_string(SIZE_SUFFIX_1LETTER,
+ p->size);
+ rc = scols_line_refer_data(ln, n, arg);
+ break;
+ case COL_MTIME:
+ if (p->mtime != 0)
+ rc = scols_line_refer_data(ln, n,
+ make_time(ctl->time_mode,
+  (time_t) p->mtime));
+ break;
+ }
+ if (rc != 0)
+ err(EXIT_FAILURE, _("failed to set data"));
+ arg = NULL;
+ }
+ if (name != NULL)
+ break;
+ }
+ posix_ipc_shm_free_info(shmds);
+}
+
 static void do_shm_global(struct lsipc_control *ctl, struct libscols_table *tb)
 {
  struct shm_data *shmds;
@@ -1081,11 +1415,13 @@ static void do_shm_global(struct lsipc_control
*ctl, struct libscols_table *tb)
 int main(int argc, char *argv[])
 {
  int opt, msg = 0, sem = 0, shm = 0, id = -1;
+ int pmsg = 0, pshm = 0, psem = 0;
  int show_time = 0, show_creat = 0, global = 0;
  size_t i;
  struct lsipc_control *ctl = xcalloc(1, sizeof(struct lsipc_control));
  static struct libscols_table *tb;
  char *outarg = NULL;
+ char *name = NULL;

  /* long only options. */
  enum {
@@ -1103,11 +1439,15 @@ int main(int argc, char *argv[])
  { "id",             required_argument, NULL, 'i' },
  { "json",           no_argument, NULL, 'J' },
  { "list",           no_argument,        NULL, 'l' },
+ { "name",           required_argument, NULL, 'N' },
  { "newline",        no_argument, NULL, 'n' },
  { "noheadings",     no_argument, NULL, OPT_NOHEAD },
  { "notruncate",     no_argument, NULL, OPT_NOTRUNC },
  { "numeric-perms",  no_argument, NULL, 'P' },
  { "output",         required_argument, NULL, 'o' },
+ { "posix-mqueues",  no_argument, NULL, 'Q' },
+ { "posix-semaphores", no_argument, NULL, 'S' },
+ { "posix-shmems",   no_argument, NULL, 'M' },
  { "queues",         no_argument, NULL, 'q' },
  { "raw",            no_argument, NULL, 'r' },
  { "semaphores",     no_argument, NULL, 's' },
@@ -1121,9 +1461,9 @@ int main(int argc, char *argv[])

  static const ul_excl_t excl[] = { /* rows and cols in ASCII order */
  { 'J', 'e', 'l', 'n', 'r' },
- { 'g', 'i' },
+ { 'N', 'g', 'i' },
  { 'c', 'o', 't' },
- { 'm', 'q', 's' },
+ { 'M', 'Q', 'S', 'm', 'q', 's' },
  { 0 }
  };
  int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
@@ -1137,7 +1477,7 @@ int main(int argc, char *argv[])

  scols_init_debug(0);

- while ((opt = getopt_long(argc, argv, "bceghi:Jlmno:PqrstVy",
longopts, NULL)) != -1) {
+ while ((opt = getopt_long(argc, argv, "bceghi:JlMmN:no:PQqrSstVy",
longopts, NULL)) != -1) {

  err_exclusive_options(opt, longopts, excl, excl_st);

@@ -1148,6 +1488,9 @@ int main(int argc, char *argv[])
  case 'i':
  id = strtos32_or_err(optarg, _("failed to parse IPC identifier"));
  break;
+ case 'N':
+ name = optarg;
+ break;
  case 'e':
  ctl->outmode = OUT_EXPORT;
  break;
@@ -1173,6 +1516,17 @@ int main(int argc, char *argv[])
  LOWER = COLDESC_IDX_MSG_FIRST;
  UPPER = COLDESC_IDX_MSG_LAST;
  break;
+ case 'Q':
+ pmsg = 1;
+ add_column(columns, ncolumns++, COL_NAME);
+ add_column(columns, ncolumns++, COL_PERMS);
+ add_column(columns, ncolumns++, COL_OWNER);
+ add_column(columns, ncolumns++, COL_MTIME);
+ add_column(columns, ncolumns++, COL_USEDBYTES);
+ add_column(columns, ncolumns++, COL_MSGS);
+ LOWER = COLDESC_IDX_POSIX_FIRST;
+ UPPER = COLDESC_IDX_POSIX_LAST;
+ break;
  case 'l':
  ctl->outmode = OUT_LIST;
  break;
@@ -1192,6 +1546,16 @@ int main(int argc, char *argv[])
  LOWER = COLDESC_IDX_SHM_FIRST;
  UPPER = COLDESC_IDX_SHM_LAST;
  break;
+ case 'M':
+ pshm = 1;
+ add_column(columns, ncolumns++, COL_NAME);
+ add_column(columns, ncolumns++, COL_PERMS);
+ add_column(columns, ncolumns++, COL_OWNER);
+ add_column(columns, ncolumns++, COL_SIZE);
+ add_column(columns, ncolumns++, COL_MTIME);
+ LOWER = COLDESC_IDX_POSIX_FIRST;
+ UPPER = COLDESC_IDX_POSIX_LAST;
+ break;
  case 'n':
  ctl->outmode = OUT_NEWLINE;
  break;
@@ -1208,6 +1572,16 @@ int main(int argc, char *argv[])
  LOWER = COLDESC_IDX_SEM_FIRST;
  UPPER = COLDESC_IDX_SEM_LAST;
  break;
+ case 'S':
+ psem = 1;
+ add_column(columns, ncolumns++, COL_NAME);
+ add_column(columns, ncolumns++, COL_PERMS);
+ add_column(columns, ncolumns++, COL_OWNER);
+ add_column(columns, ncolumns++, COL_MTIME);
+ add_column(columns, ncolumns++, COL_SVAL);
+ LOWER = COLDESC_IDX_POSIX_FIRST;
+ UPPER = COLDESC_IDX_POSIX_LAST;
+ break;
  case OPT_NOTRUNC:
  ctl->notrunc = 1;
  break;
@@ -1240,10 +1614,10 @@ int main(int argc, char *argv[])
  }

  /* default is global */
- if (msg + shm + sem == 0) {
- msg = shm = sem = global = 1;
- if (show_time || show_creat || id != -1)
- errx(EXIT_FAILURE, _("--global is mutually exclusive with --creator,
--id and --time"));
+ if (msg + shm + sem + pmsg + pshm + psem == 0) {
+ msg = shm = sem = pmsg = pshm = psem = global = 1;
+ if (show_time || show_creat || id != -1 || name != NULL)
+ errx(EXIT_FAILURE, _("--global is mutually exclusive with --creator,
--id, --name and --time"));
  }
  if (global) {
  add_column(columns, ncolumns++, COL_RESOURCE);
@@ -1256,7 +1630,7 @@ int main(int argc, char *argv[])
  }

  /* default to pretty-print if --id specified */
- if (id != -1 && !ctl->outmode)
+ if ((id != -1 || name != NULL) && !ctl->outmode)
  ctl->outmode = OUT_PRETTY;

  if (!ctl->time_mode)
@@ -1270,8 +1644,10 @@ int main(int argc, char *argv[])
  if (show_creat) {
  add_column(columns, ncolumns++, COL_CUID);
  add_column(columns, ncolumns++, COL_CGID);
- add_column(columns, ncolumns++, COL_UID);
- add_column(columns, ncolumns++, COL_GID);
+ if (!(pmsg || pshm || psem)) {
+ add_column(columns, ncolumns++, COL_UID);
+ add_column(columns, ncolumns++, COL_GID);
+ }
  }
  if (msg && show_time) {
  add_column(columns, ncolumns++, COL_SEND);
@@ -1312,18 +1688,32 @@ int main(int argc, char *argv[])
  else
  do_msg(id, ctl, tb);
  }
+ if (pmsg) {
+ if (global)
+ do_posix_msg_global(ctl, tb);
+ else
+ do_posix_msg(name, ctl, tb);
+ }
  if (shm) {
  if (global)
  do_shm_global(ctl ,tb);
  else
  do_shm(id, ctl, tb);
  }
+ if (pshm) {
+ if (!global)
+ do_posix_shm(name, ctl, tb);
+ }
  if (sem) {
  if (global)
  do_sem_global(ctl, tb);
  else
  do_sem(id, ctl, tb);
  }
+ if (psem) {
+ if (!global)
+ do_posix_sem(name, ctl, tb);
+ }

  print_table(ctl, tb);

--
2.43.0

----------------------------------------------------------------

From 7a16f0535469dbf94d631cf40ddc539322b6d291 Mon Sep 17 00:00:00 2001
From: Prasanna Paithankar <paithankarprasanna@gmail.com>
Date: Thu, 23 Jan 2025 03:18:31 +0530
Subject: [PATCH 2/2] added POSIX IPC paathnames; modified
 sys-utils/Makemodule.am

---
 include/pathnames.h     | 11 +++++++++--
 sys-utils/Makemodule.am | 16 ++++++++++------
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/include/pathnames.h b/include/pathnames.h
index a30194b10..34ba11ca3 100644
--- a/include/pathnames.h
+++ b/include/pathnames.h
@@ -187,7 +187,7 @@

 #define _PATH_PROC_KERNEL "/proc/sys/kernel"

-/* ipc paths */
+/* System V ipc paths */
 #define _PATH_PROC_SYSV_MSG "/proc/sysvipc/msg"
 #define _PATH_PROC_SYSV_SEM "/proc/sysvipc/sem"
 #define _PATH_PROC_SYSV_SHM "/proc/sysvipc/shm"
@@ -208,6 +208,13 @@
 #define _PATH_PROC_PIPE_MAX_SIZE _PATH_PROC_SYS_FS "/pipe-max-size"
 #define _PATH_PROC_BINFMT_MISC _PATH_PROC_SYS_FS "/binfmt_misc"

+/* Posix ipc paths */
+#define _PATH_DEV_MQUEUE "/dev/mqueue"
+#define _PATH_PROC_POSIX_IPC_MSGMAX _PATH_PROC_SYS_FS "/mqueue/msgsize_max"
+#define _PATH_PROC_POSIX_IPC_MSGMNB _PATH_PROC_SYS_FS "/mqueue/msg_max"
+#define _PATH_PROC_POSIX_IPC_MSGMNI _PATH_PROC_SYS_FS "/mqueue/queues_max"
+#define _PATH_DEV_SHM "/dev/shm"
+
 /* irqtop paths */
 #define _PATH_PROC_INTERRUPTS "/proc/interrupts"
 #define _PATH_PROC_SOFTIRQS "/proc/softirqs"
@@ -243,4 +250,4 @@
 # define UL_VENDORDIR_PATH      NULL
 #endif

-#endif /* PATHNAMES_H */
+#endif /* PATHNAMES_H */
\ No newline at end of file
diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am
index 8cc69be60..03955c85c 100644
--- a/sys-utils/Makemodule.am
+++ b/sys-utils/Makemodule.am
@@ -43,8 +43,11 @@ if BUILD_IPCRM
 usrbin_exec_PROGRAMS += ipcrm
 MANPAGES += sys-utils/ipcrm.1
 dist_noinst_DATA += sys-utils/ipcrm.1.adoc
-ipcrm_SOURCES = sys-utils/ipcrm.c
-ipcrm_LDADD = $(LDADD) libcommon.la
+ipcrm_SOURCES = sys-utils/ipcrm.c \
+ sys-utils/ipcutils.c \
+ sys-utils/ipcutils.h
+ipcrm_LDADD = $(LDADD) libcommon.la libmount.la
+ipcrm_CFLAGS = $(AM_CFLAGS) -I$(ul_libmount_incdir)
 endif

 if BUILD_IPCS
@@ -54,7 +57,8 @@ dist_noinst_DATA += sys-utils/ipcs.1.adoc
 ipcs_SOURCES = sys-utils/ipcs.c \
  sys-utils/ipcutils.c \
  sys-utils/ipcutils.h
-ipcs_LDADD = $(LDADD) libcommon.la
+ipcs_LDADD = $(LDADD) libcommon.la libmount.la
+ipcs_CFLAGS = $(AM_CFLAGS) -I$(ul_libmount_incdir)
 endif

 if BUILD_IRQTOP
@@ -93,8 +97,8 @@ dist_noinst_DATA += sys-utils/lsipc.1.adoc
 lsipc_SOURCES = sys-utils/lsipc.c \
  sys-utils/ipcutils.c \
  sys-utils/ipcutils.h
-lsipc_LDADD = $(LDADD) libcommon.la libsmartcols.la
-lsipc_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir)
+lsipc_LDADD = $(LDADD) libcommon.la libsmartcols.la libmount.la
+lsipc_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir) -I$(ul_libmount_incdir)
 endif

 if BUILD_RENICE
@@ -591,4 +595,4 @@ if HAVE_LINUX_LANDLOCK_H
 setpriv_SOURCES += sys-utils/setpriv-landlock.c
 endif
 setpriv_LDADD = $(LDADD) -lcap-ng libcommon.la
-endif
+endif
\ No newline at end of file
--
2.43.0

^ permalink raw reply related

* [PATCH V2] blkid: allow up to 64k erofs block sizes
From: Eric Sandeen @ 2025-01-24 14:37 UTC (permalink / raw)
  To: util-linux; +Cc: xiang, Karel Zak
In-Reply-To: <71d43b45-9d53-48a1-8751-7080e50937e9@redhat.com>

Today, mkfs.erofs defaults to page size for block size, but blkid
does not recognize this. Increase the limit to 64k.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

V2: Test for too-small blocksize, and simplify too-large blocksize
test.  (the prior > 31 || <shift test> was probably just avoiding
a shift overflow but there's really no reason, so just look directly
at blkszbits)

(There might be strange arches out there > 64k but I don't know if
erofs really works with blocks that big, so for now let's just
limit it to 64k?)

diff --git a/libblkid/src/superblocks/erofs.c b/libblkid/src/superblocks/erofs.c
index 05822460b..89620db47 100644
--- a/libblkid/src/superblocks/erofs.c
+++ b/libblkid/src/superblocks/erofs.c
@@ -73,8 +73,8 @@ static int probe_erofs(blkid_probe pr, const struct blkid_idmag *mag)
 	if (!sb)
 		return errno ? -errno : BLKID_PROBE_NONE;
 
-	/* EROFS is restricted to 4KiB block size */
-	if (sb->blkszbits > 31 || (1U << sb->blkszbits) > 4096)
+	/* block size must be between 512 and 64k */
+	if (sb->blkszbits < 9 || sb->blkszbits > 16)
 		return BLKID_PROBE_NONE;
 
 	if (!erofs_verify_checksum(pr, mag, sb))


^ permalink raw reply related

* Re: [PATCH] blkid: allow up to 64k erofs block sizes
From: Gao Xiang @ 2025-01-23 23:22 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: util-linux, xiang, Karel Zak
In-Reply-To: <71d43b45-9d53-48a1-8751-7080e50937e9@redhat.com>

Hi Eric,

On Thu, Jan 23, 2025 at 01:17:10PM -0600, Eric Sandeen wrote:
> Today, mkfs.erofs defaults to page size for block size, but blkid
> does not recognize this. Increase the limit to 64k.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 
> (There might be strange arches out there > 64k but I don't know if
> erofs really works with blocks that big, so for now let's just
> limit it to 64k?)
> 
> diff --git a/libblkid/src/superblocks/erofs.c b/libblkid/src/superblocks/erofs.c
> index 05822460b..89620db47 100644
> --- a/libblkid/src/superblocks/erofs.c
> +++ b/libblkid/src/superblocks/erofs.c
> @@ -73,8 +73,8 @@ static int probe_erofs(blkid_probe pr, const struct blkid_idmag *mag)
>  	if (!sb)
>  		return errno ? -errno : BLKID_PROBE_NONE;
>  
> -	/* EROFS is restricted to 4KiB block size */
> -	if (sb->blkszbits > 31 || (1U << sb->blkszbits) > 4096)
> +	/* block size must be between 512 and 64k */
> +	if (sb->blkszbits > 31 || (1U << sb->blkszbits) > 65536)

I think it should be

	if (sb->blkszbits < 9 || ..

?

Also (1U << sb->blkszbits) might be overflowed, so just use
sb->blkszbits > 16.

Otherwise it looks good to me.

Thanks,
Gao Xiang

>  		return BLKID_PROBE_NONE;
>  
>  	if (!erofs_verify_checksum(pr, mag, sb))
> 

^ permalink raw reply

* [PATCH] blkid: allow up to 64k erofs block sizes
From: Eric Sandeen @ 2025-01-23 19:17 UTC (permalink / raw)
  To: util-linux; +Cc: xiang, Karel Zak

Today, mkfs.erofs defaults to page size for block size, but blkid
does not recognize this. Increase the limit to 64k.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

(There might be strange arches out there > 64k but I don't know if
erofs really works with blocks that big, so for now let's just
limit it to 64k?)

diff --git a/libblkid/src/superblocks/erofs.c b/libblkid/src/superblocks/erofs.c
index 05822460b..89620db47 100644
--- a/libblkid/src/superblocks/erofs.c
+++ b/libblkid/src/superblocks/erofs.c
@@ -73,8 +73,8 @@ static int probe_erofs(blkid_probe pr, const struct blkid_idmag *mag)
 	if (!sb)
 		return errno ? -errno : BLKID_PROBE_NONE;
 
-	/* EROFS is restricted to 4KiB block size */
-	if (sb->blkszbits > 31 || (1U << sb->blkszbits) > 4096)
+	/* block size must be between 512 and 64k */
+	if (sb->blkszbits > 31 || (1U << sb->blkszbits) > 65536)
 		return BLKID_PROBE_NONE;
 
 	if (!erofs_verify_checksum(pr, mag, sb))


^ permalink raw reply related

* License Combination: LGPL and BSD-4-Clause
From: Mario @ 2025-01-22 10:34 UTC (permalink / raw)
  To: util-linux, dave, kerolasa, kzak

Hi there,

I have a question about the compatibility of two software licenses in
util-linux. Here is an example:

The file text-utils/hexdump-parse.c is licensed under the BSD-4-Clause license.
This file includes the header file include/xalloc.h, which is licensed
under the LGPL.

According to the GNU licence compatibility list
(https://www.gnu.org/licenses/license-list.html.en#OriginalBSD),
this combination of licenses is not allowed.

I would like to know:

How can the resulting binary from this combination be used in a
license-compliant manner?
Are there any possible solutions or workarounds to resolve the license
incompatibility?

Any insight or guidance on this matter would be greatly appreciated.

Thank you very much for your time.

Best regards,
Mario

^ permalink raw reply

* Re: [PATCH v2] alpha/elf: Fix misc/setarch test of util-linux by removing 32bit support
From: Ivan Kokshaysky @ 2025-01-18 10:35 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: John Paul Adrian Glaubitz, Maciej W. Rozycki, Arnd Bergmann,
	Richard Henderson, Matt Turner, Kees Cook, Paul E. McKenney,
	linux-alpha, linux-mm, linux-kernel, Michael Cree, Sam James,
	Geert Uytterhoeven, Michael Karcher, Chris Hofstaedtler,
	util-linux, linux-mips, loongarch
In-Reply-To: <87y0zfs26i.fsf_-_@email.froward.int.ebiederm.org>

On Sun, Jan 12, 2025 at 11:39:01PM -0600, Eric W. Biederman wrote:
...
> --- a/arch/alpha/include/asm/pgtable.h
> +++ b/arch/alpha/include/asm/pgtable.h
> @@ -360,7 +360,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
>  
>  extern void paging_init(void);
>  
> -/* We have our own get_unmapped_area to cope with ADDR_LIMIT_32BIT.  */
> +/* We have our own get_unmapped_area */
>  #define HAVE_ARCH_UNMAPPED_AREA

Just remove the definition. As the comment suggests, the only reason
it exists is ADDR_LIMIT_32BIT, which is gone.

> --- a/arch/alpha/kernel/osf_sys.c
> +++ b/arch/alpha/kernel/osf_sys.c
> @@ -1210,8 +1210,7 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
>  	return ret;
>  }
>  
> -/* Get an address range which is currently unmapped.  Similar to the
> -   generic version except that we know how to honor ADDR_LIMIT_32BIT.  */
> +/* Get an address range which is currently unmapped. */
>  
>  static unsigned long
>  arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
> @@ -1230,13 +1229,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
>  		       unsigned long len, unsigned long pgoff,
>  		       unsigned long flags, vm_flags_t vm_flags)
>  {
> -	unsigned long limit;
> -
> -	/* "32 bit" actually means 31 bit, since pointers sign extend.  */
> -	if (current->personality & ADDR_LIMIT_32BIT)
> -		limit = 0x80000000;
> -	else
> -		limit = TASK_SIZE;
> +	unsigned long limit = TASK_SIZE;
>  
>  	if (len > limit)
>  		return -ENOMEM;

Likewise, just remove these functions. The generic_get_unmapped_area()
works fine, tested on up1500.

Ivan.

^ permalink raw reply

* fallocate: --insert-range does not work with --posix
From: Johannes Schauer Marin Rodrigues @ 2025-01-16 12:58 UTC (permalink / raw)
  To: util-linux

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

Hi,

Steps to reproduce:

    $ fallocate -l 1024 test.img
    $ fallocate --posix --insert-range --offset=0 --length=4096 test.img
    $ ls -l test.img
    -rw-r--r-- 1 root root 4096 Jan 12 16:57 test.img

The size of test.img should be 5120 bytes and not 4096. It works fine
without --posix.

This issue can also be expressed as another test:

--- a/tests/expected/misc/fallocate
+++ b/tests/expected/misc/fallocate
@@ -1 +1,2 @@
 384
+4480
--- a/tests/ts/misc/fallocate
+++ b/tests/ts/misc/fallocate
@@ -34,6 +34,9 @@ else
                && ts_skip "'${fs_type}' not supported"
 fi
 
+$TS_CMD_FALLOCATE -x -i -o 0 -l 4096 $IMAGE >> $TS_OUTPUT 2>> $TS_ERRLOG
+stat -c "%s" $IMAGE >> $TS_OUTPUT 2>> $TS_ERRLOG
+
 rm -f $IMAGE
 
 ts_finalize

I also wonder why the size of --insert-range has to be 4096. If I try
smaller sizes, it does not work on my machine even when not using
--posix. If this is by design, maybe it should be mentioned in the
man page?

I'm running Debian bookworm and reproduced this with util-linux from
git.

Thanks!

cheers, josch

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

-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEElFhU6KL81LF4wVq58sulx4+9g+EFAmeJAnUACgkQ8sulx4+9
g+F+HQ/9FAgAvXntXGig9S0A/ruhS8uSONYr5YBcsLEixVgkd6w0x9XOVbU9HkDL
mtvtF1hbKR0A7BoMrlNKbDDAIbcaxJePMhfPpVUuRF5YRA2WSm6hOc09fOMx1pvP
2gN8vuV2z26xlND1eyEXT+2gt49zGJZYucuGywiV3AK+wuAQ+XsUqWRxQ2d3JtIY
zvxylVhwhPgnfkWzNxGcThyadvY1G7SOUvwHqZTJWBgZpiDZN0L7AswH+VU6dXeL
wFTs7PRcJYIuosc6Vrdl5LcM26W2UNhg9Zw3nKWsTkB40IcRts8hwT4F5He4HHHo
pxlD/UK3Ad38L7uoX6opL5WPjq66KeRmA21doa5PkZAFqLkaIpfixMVifs8PfrXb
8oCOxpNEGPxKoLDzoulEwaDLGGAAChUqObVwG1+loz95At6lePGB6VQUsZBOtNmb
roRHrX3RRiMFuv0zsS2eiCj1AZPyLBYoialisnUUHwBYbubFgW4WbEVdZ819lE4W
7LCFBUFQ0zzCw32PoUC8QM7XcHz6jB1Hf4e0Vumjnu3JfJg9S14uQdu4aTNoz8xi
q+7N8F+k+9WFKADHeuY/A4/EGlq90Ad4KOYhvil7eRjnPe0bMgs096lnvUcxL9lN
vzCYCIFNeqZJY8ac3xfvOFeYBhzo9BJlh9wy70t35IzrECTcvak=
=zdOL
-----END PGP SIGNATURE-----

^ permalink raw reply

* Re: [PATCH] Fix non-Linux build
From: Karel Zak @ 2025-01-14  9:32 UTC (permalink / raw)
  To: Samuel Thibault, util-linux
In-Reply-To: <Z4PiQCAhViwlpqnG@begin>

On Sun, Jan 12, 2025 at 04:39:44PM GMT, Samuel Thibault wrote:
> This fixes non-Linux builds, by:
> 
> - making sfdisk discard option conditioned by availability of BLKDISCARD
> - defining and using blkid_probe_get_buffer only if O_DIRECT is
>   available
> - always building src/fs_statmount.c and src/tab_listmount.c, they
>   already contain proper conditions to make them void if support is not
>   available.

 Applied, thanks!

    Karel
-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com


^ permalink raw reply

* [ANNOUNCE] util-linux v2.40.4
From: Karel Zak @ 2025-01-13 17:30 UTC (permalink / raw)
  To: linux-kernel, linux-fsdevel, util-linux


The util-linux stable maintenance release v2.40.4 is now available at
 
  http://www.kernel.org/pub/linux/utils/util-linux/v2.40
 
Feedback and bug reports, as always, are welcomed.
 
Please note that the previous release, v2.40.3 (4 days ago), contained
a bug that made it impossible to use some /sbin/mount.<type> helpers.
I apologize for this bug and kindly request that you use v2.40.4 instead.

  Karel


-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com


^ permalink raw reply

* [PATCH v2] alpha/elf: Fix misc/setarch test of util-linux by removing 32bit support
From: Eric W. Biederman @ 2025-01-13  5:39 UTC (permalink / raw)
  To: John Paul Adrian Glaubitz
  Cc: Maciej W. Rozycki, Arnd Bergmann, Richard Henderson, Matt Turner,
	Kees Cook, Paul E. McKenney, linux-alpha, linux-mm, linux-kernel,
	Michael Cree, Sam James, Geert Uytterhoeven, Michael Karcher,
	Chris Hofstaedtler, util-linux, linux-mips, loongarch
In-Reply-To: <78f3ae1f68842a9d1af62caaac3929834ce6ecfa.camel@physik.fu-berlin.de>


Richard Henderson <richard.henderson@linaro.org> writes[1]:

> There was a Spec benchmark (I forget which) which was memory bound and ran
> twice as fast with 32-bit pointers.
>
> I copied the idea from DEC to the ELF abi, but never did all the other work
> to allow the toolchain to take advantage.
>
> Amusingly, a later Spec changed the benchmark data sets to not fit into a
> 32-bit address space, specifically because of this.
>
> I expect one could delete the ELF bit and personality and no one would
> notice. Not even the 10 remaining Alpha users.

In [2] it was pointed out that parts of setarch weren't working
properly on alpha because it has it's own SET_PERSONALITY
implementation.  In the discussion that followed Richard Henderson
pointed out that the 32bit pointer support for alpha was never
completed.

Fix this by removing alpha's 32bit pointer support.

As a bit of paranoia refuse to execute any alpha binaries that have
the EF_ALPHA_32BIT flag set.  Just in case someone somewhere has
binaries that try to use alpha's 32bit pointer support.

[1] https://lkml.kernel.org/r/CAFXwXrkgu=4Qn-v1PjnOR4SG0oUb9LSa0g6QXpBq4ttm52pJOQ@mail.gmail.com
[2] https://lkml.kernel.org/r/20250103140148.370368-1-glaubitz@physik.fu-berlin.de
v1: https://lkml.kernel.org/r/87jzb2tdb7.fsf_-_@email.froward.int.ebiederm.org
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Tested-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---

Kees can you pick this one up?

 arch/alpha/include/asm/elf.h       |  6 +-----
 arch/alpha/include/asm/pgtable.h   |  2 +-
 arch/alpha/include/asm/processor.h |  8 ++------
 arch/alpha/kernel/osf_sys.c        | 11 ++---------
 4 files changed, 6 insertions(+), 21 deletions(-)

diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
index 4d7c46f50382..50c82187e60e 100644
--- a/arch/alpha/include/asm/elf.h
+++ b/arch/alpha/include/asm/elf.h
@@ -74,7 +74,7 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(x) ((x)->e_machine == EM_ALPHA)
+#define elf_check_arch(x) (((x)->e_machine == EM_ALPHA) && !((x)->e_flags & EF_ALPHA_32BIT))
 
 /*
  * These are used to set parameters in the core dumps.
@@ -137,10 +137,6 @@ extern int dump_elf_task(elf_greg_t *dest, struct task_struct *task);
 	: amask (AMASK_CIX) ? "ev6" : "ev67");	\
 })
 
-#define SET_PERSONALITY(EX)					\
-	set_personality(((EX).e_flags & EF_ALPHA_32BIT)		\
-	   ? PER_LINUX_32BIT : PER_LINUX)
-
 extern int alpha_l1i_cacheshape;
 extern int alpha_l1d_cacheshape;
 extern int alpha_l2_cacheshape;
diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
index 635f0a5f5bbd..02e8817a8921 100644
--- a/arch/alpha/include/asm/pgtable.h
+++ b/arch/alpha/include/asm/pgtable.h
@@ -360,7 +360,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
 
 extern void paging_init(void);
 
-/* We have our own get_unmapped_area to cope with ADDR_LIMIT_32BIT.  */
+/* We have our own get_unmapped_area */
 #define HAVE_ARCH_UNMAPPED_AREA
 
 #endif /* _ALPHA_PGTABLE_H */
diff --git a/arch/alpha/include/asm/processor.h b/arch/alpha/include/asm/processor.h
index 55bb1c09fd39..5dce5518a211 100644
--- a/arch/alpha/include/asm/processor.h
+++ b/arch/alpha/include/asm/processor.h
@@ -8,23 +8,19 @@
 #ifndef __ASM_ALPHA_PROCESSOR_H
 #define __ASM_ALPHA_PROCESSOR_H
 
-#include <linux/personality.h>	/* for ADDR_LIMIT_32BIT */
-
 /*
  * We have a 42-bit user address space: 4TB user VM...
  */
 #define TASK_SIZE (0x40000000000UL)
 
-#define STACK_TOP \
-  (current->personality & ADDR_LIMIT_32BIT ? 0x80000000 : 0x00120000000UL)
+#define STACK_TOP (0x00120000000UL)
 
 #define STACK_TOP_MAX	0x00120000000UL
 
 /* This decides where the kernel will search for a free chunk of vm
  * space during mmap's.
  */
-#define TASK_UNMAPPED_BASE \
-  ((current->personality & ADDR_LIMIT_32BIT) ? 0x40000000 : TASK_SIZE / 2)
+#define TASK_UNMAPPED_BASE (TASK_SIZE / 2)
 
 /* This is dead.  Everything has been moved to thread_info.  */
 struct thread_struct { };
diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
index 86185021f75a..a08e8edef1a4 100644
--- a/arch/alpha/kernel/osf_sys.c
+++ b/arch/alpha/kernel/osf_sys.c
@@ -1210,8 +1210,7 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
 	return ret;
 }
 
-/* Get an address range which is currently unmapped.  Similar to the
-   generic version except that we know how to honor ADDR_LIMIT_32BIT.  */
+/* Get an address range which is currently unmapped. */
 
 static unsigned long
 arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
@@ -1230,13 +1229,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
 		       unsigned long len, unsigned long pgoff,
 		       unsigned long flags, vm_flags_t vm_flags)
 {
-	unsigned long limit;
-
-	/* "32 bit" actually means 31 bit, since pointers sign extend.  */
-	if (current->personality & ADDR_LIMIT_32BIT)
-		limit = 0x80000000;
-	else
-		limit = TASK_SIZE;
+	unsigned long limit = TASK_SIZE;
 
 	if (len > limit)
 		return -ENOMEM;
-- 
2.41.0


^ permalink raw reply related

* Re: [PATCH] alpha/elf: Fix misc/setarch test of util-linux by removing 32bit support
From: Eric W. Biederman @ 2025-01-13  5:32 UTC (permalink / raw)
  To: Ivan Kokshaysky
  Cc: John Paul Adrian Glaubitz, Arnd Bergmann, Richard Henderson,
	Matt Turner, Kees Cook, Paul E. McKenney, linux-alpha, linux-mm,
	linux-kernel, Michael Cree, Sam James, Maciej W. Rozycki,
	Geert Uytterhoeven, Michael Karcher, Chris Hofstaedtler,
	util-linux, linux-mips, loongarch
In-Reply-To: <Z4KN_aOT6uZRAm8a@minute>

Ivan Kokshaysky <ink@unseen.parts> writes:

> On Fri, Jan 10, 2025 at 06:16:28PM -0600, Eric W. Biederman wrote:
>> 
>> Richard Henderson <richard.henderson@linaro.org> writes[1]:
>> 
>> > There was a Spec benchmark (I forget which) which was memory bound and ran
>> > twice as fast with 32-bit pointers.
>> >
>> > I copied the idea from DEC to the ELF abi, but never did all the other work
>> > to allow the toolchain to take advantage.
>> >
>> > Amusingly, a later Spec changed the benchmark data sets to not fit into a
>> > 32-bit address space, specifically because of this.
>> >
>> > I expect one could delete the ELF bit and personality and no one would
>> > notice. Not even the 10 remaining Alpha users.
>> 
>> In [2] it was pointed out that parts of setarch weren't working
>> properly on alpha because it has it's own SET_PERSONALITY
>> implementation.  In the discussion that followed Richard Henderson
>> pointed out that the 32bit pointer support for alpha was never
>> completed.
>> 
>> Fix this by removing alpha's 32bit pointer support.
>> 
>> As a bit of paranoia refuse to execute any alpha binaries that hafe
>> the EF_ALPHA_32BIT flag set.  Just to fail explicitly in case someone
>> somewhere has binaries that trying to use alpha's 32bit pointer
>> support.
>
> In general I agree, but then someone ought to remove the "--taso" option
> from GNU ld, which produces such binaries.

Please feel free to write such a patch.  I don't know the GNU ld process
well enough to write that patch.

It would be good to remove dead code and confusing code from GNU ld,
as well as from the linux kernel.

Eric

^ permalink raw reply

* [PATCH] Fix non-Linux build
From: Samuel Thibault @ 2025-01-12 15:39 UTC (permalink / raw)
  To: util-linux

This fixes non-Linux builds, by:

- making sfdisk discard option conditioned by availability of BLKDISCARD
- defining and using blkid_probe_get_buffer only if O_DIRECT is
  available
- always building src/fs_statmount.c and src/tab_listmount.c, they
  already contain proper conditions to make them void if support is not
  available.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c
index 5e7c1d926..d8261c442 100644
--- a/disk-utils/sfdisk.c
+++ b/disk-utils/sfdisk.c
@@ -1370,6 +1370,7 @@ static int command_partattrs(struct sfdisk *sf, int argc, char **argv)
 	return write_changes(sf);
 }
 
+#ifdef BLKDISCARD
 /*
  * sfdisk --discard-free <device>
  */
@@ -1432,6 +1433,12 @@ done:
 	fdisk_unref_table(tb);
 	return rc;
 }
+#else /* BLKDISCARD */
+static int command_discard_free(struct sfdisk *sf, int argc, char **argv)
+{
+	fdisk_warnx(sf->cxt, _("Discard unsupported on your system."));
+}
+#endif /* BLKDISCARD */
 
 /*
  * sfdisk --disk-id <device> [<str>]
diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c
index 5a156251c..61b93021c 100644
--- a/libblkid/src/probe.c
+++ b/libblkid/src/probe.c
@@ -791,6 +791,7 @@ const unsigned char *blkid_probe_get_buffer(blkid_probe pr, uint64_t off, uint64
 	return real_off ? bf->data + (real_off - bf->off + bias) : bf->data + bias;
 }
 
+#ifdef O_DIRECT
 /*
  * This is blkid_probe_get_buffer with the read done as an O_DIRECT operation.
  * Note that @off is offset within probing area, the probing area is defined by
@@ -817,6 +818,7 @@ const unsigned char *blkid_probe_get_buffer_direct(blkid_probe pr, uint64_t off,
 	}
 	return ret;
 }
+#endif
 
 /**
  * blkid_probe_reset_buffers:
diff --git a/libblkid/src/superblocks/ext.c b/libblkid/src/superblocks/ext.c
index 7a9f8c9b9..c0779c233 100644
--- a/libblkid/src/superblocks/ext.c
+++ b/libblkid/src/superblocks/ext.c
@@ -164,6 +164,7 @@ static struct ext2_super_block *ext_get_super(
 		 * then declare a checksum mismatch.
 		 */
 		if (!blkid_probe_verify_csum(pr, csum, le32_to_cpu(es->s_checksum))) {
+#ifdef O_DIRECT
 			if (blkid_probe_reset_buffers(pr))
 				return NULL;
 
@@ -175,6 +176,9 @@ static struct ext2_super_block *ext_get_super(
 			csum = crc32c(~0, es, offsetof(struct ext2_super_block, s_checksum));
 			if (!blkid_probe_verify_csum(pr, csum, le32_to_cpu(es->s_checksum)))
 				return NULL;
+#else
+			return NULL;
+#endif
 		}
 	}
 	if (fc)
diff --git a/libmount/meson.build b/libmount/meson.build
index 05b31d4d4..29a43be02 100644
--- a/libmount/meson.build
+++ b/libmount/meson.build
@@ -24,6 +24,7 @@ lib_mount_sources = '''
   src/mountP.h
   src/cache.c
   src/fs.c
+  src/fs_statmount.c
   src/init.c
   src/iter.c
   src/lock.c
@@ -31,6 +32,7 @@ lib_mount_sources = '''
   src/optstr.c
   src/tab.c
   src/tab_diff.c
+  src/tab_listmount.c
   src/tab_parse.c
   src/tab_update.c
   src/test.c
@@ -43,8 +45,6 @@ lib_mount_sources = '''
 
 if LINUX
   lib_mount_sources += '''
-    src/fs_statmount.c
-    src/tab_listmount.c
     src/hooks.c
     src/monitor.c
     src/optlist.c
diff --git a/libmount/src/Makemodule.am b/libmount/src/Makemodule.am
index 49f6d6f03..5a5c787a4 100644
--- a/libmount/src/Makemodule.am
+++ b/libmount/src/Makemodule.am
@@ -11,6 +11,7 @@ libmount_la_SOURCES = \
 	libmount/src/mountP.h \
 	libmount/src/cache.c \
 	libmount/src/fs.c \
+	libmount/src/fs_statmount.c \
 	libmount/src/init.c \
 	libmount/src/iter.c \
 	libmount/src/lock.c \
@@ -19,6 +20,7 @@ libmount_la_SOURCES = \
 	libmount/src/optstr.c \
 	libmount/src/tab.c \
 	libmount/src/tab_diff.c \
+	libmount/src/tab_listmount.c \
 	libmount/src/tab_parse.c \
 	libmount/src/tab_update.c \
 	libmount/src/test.c \
@@ -30,8 +32,6 @@ libmount_la_SOURCES += \
 	libmount/src/context.c \
 	libmount/src/context_mount.c \
 	libmount/src/context_umount.c \
-	libmount/src/fs_statmount.c \
-	libmount/src/tab_listmount.c \
 	libmount/src/hooks.c \
 	libmount/src/hook_mount.c \
 	libmount/src/hook_mount_legacy.c \

^ permalink raw reply related

* Re: [PATCH] alpha/elf: Fix misc/setarch test of util-linux by removing 32bit support
From: John Paul Adrian Glaubitz @ 2025-01-12 14:56 UTC (permalink / raw)
  To: Maciej W. Rozycki
  Cc: Eric W. Biederman, Arnd Bergmann, Richard Henderson, Matt Turner,
	Kees Cook, Paul E. McKenney, linux-alpha, linux-mm, linux-kernel,
	Michael Cree, Sam James, Geert Uytterhoeven, Michael Karcher,
	Chris Hofstaedtler, util-linux, linux-mips, loongarch
In-Reply-To: <alpine.DEB.2.21.2501120146480.18889@angie.orcam.me.uk>

On Sun, 2025-01-12 at 14:40 +0000, Maciej W. Rozycki wrote:
> On Sat, 11 Jan 2025, John Paul Adrian Glaubitz wrote:
> 
> > > the EF_ALPHA_32BIT flag set.  Just to fail explicitly in case someone
> > > somewhere has binaries that trying to use alpha's 32bit pointer
> >                             ^^^ are
> 
>  If nitpicking, I'd say just "try".

No objection. I was just hinting at obvious grammar mistakes. ;-)

Adrian

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

^ permalink raw reply

* Re: [PATCH] alpha/elf: Fix misc/setarch test of util-linux by removing 32bit support
From: Maciej W. Rozycki @ 2025-01-12 14:40 UTC (permalink / raw)
  To: John Paul Adrian Glaubitz
  Cc: Eric W. Biederman, Arnd Bergmann, Richard Henderson, Matt Turner,
	Kees Cook, Paul E. McKenney, linux-alpha, linux-mm, linux-kernel,
	Michael Cree, Sam James, Geert Uytterhoeven, Michael Karcher,
	Chris Hofstaedtler, util-linux, linux-mips, loongarch
In-Reply-To: <2758fa70d237ff972b0c8d7114777dc4a20c8f3b.camel@physik.fu-berlin.de>

On Sat, 11 Jan 2025, John Paul Adrian Glaubitz wrote:

> > the EF_ALPHA_32BIT flag set.  Just to fail explicitly in case someone
> > somewhere has binaries that trying to use alpha's 32bit pointer
>                             ^^^ are

 If nitpicking, I'd say just "try".

  Maciej

^ permalink raw reply

* Re: [PATCH] alpha: Fix personality flag propagation across an exec
From: Maciej W. Rozycki @ 2025-01-12 14:40 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Eric W. Biederman, John Paul Adrian Glaubitz, Richard Henderson,
	Matt Turner, Kees Cook, Paul E. McKenney, linux-alpha, linux-mm,
	linux-kernel, Michael Cree, Sam James, Geert Uytterhoeven,
	Michael Karcher, Chris Hofstaedtler, util-linux, linux-mips,
	loongarch
In-Reply-To: <bff9bd35-4d47-45fc-90c5-28b79425fc8b@app.fastmail.com>

On Thu, 9 Jan 2025, Arnd Bergmann wrote:

> >  This is similar to the MIPS n32 ABI, which also implies a 32-bit address 
> > space while still using 64-bit registers for everything, starting from 
> > stack slots (it's also ILP32 with the `long long' C data type only making 
> > proper use of the full width of the CPU registers, while Alpha's --taso 
> > ABI is I believe IP32 (?) with the plain `long' C data type still 64-bit, 
> > just as with the regular LP64 ABI).
> 
> I'm pretty sure it's still LP64 on Alpha Linux with gcc. There is an
> -mpointer-size=32 option in gcc for VMS, but I don't see anything like
> that in Linux. The only thing that is implemented here is the option
> for the linker that sets the EF_ALPHA_32BIT bit, but none of the
> code generation takes advantage of the upper bits being zero.

 Pretty useless then nowadays (I knew about the option back in 1990s, 
though since forgot, and then never bothered to get into its details and 
considered cleaning up code instead a better use of resources).  Thanks 
for the explanation, and good riddance!

  Maciej

^ permalink raw reply

* Re: [PATCH] alpha/elf: Fix misc/setarch test of util-linux by removing 32bit support
From: John Paul Adrian Glaubitz @ 2025-01-11 21:26 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: Arnd Bergmann, Richard Henderson, Matt Turner, Kees Cook,
	Paul E. McKenney, linux-alpha, linux-mm, linux-kernel,
	Michael Cree, Sam James, Maciej W. Rozycki, Geert Uytterhoeven,
	Michael Karcher, Chris Hofstaedtler, util-linux, linux-mips,
	loongarch
In-Reply-To: <87jzb2tdb7.fsf_-_@email.froward.int.ebiederm.org>

Hi Eric,

On Fri, 2025-01-10 at 18:16 -0600, Eric W. Biederman wrote:
> Richard Henderson <richard.henderson@linaro.org> writes[1]:
> 
> > There was a Spec benchmark (I forget which) which was memory bound and ran
> > twice as fast with 32-bit pointers.
> > 
> > I copied the idea from DEC to the ELF abi, but never did all the other work
> > to allow the toolchain to take advantage.
> > 
> > Amusingly, a later Spec changed the benchmark data sets to not fit into a
> > 32-bit address space, specifically because of this.
> > 
> > I expect one could delete the ELF bit and personality and no one would
> > notice. Not even the 10 remaining Alpha users.
> 
> In [2] it was pointed out that parts of setarch weren't working
> properly on alpha because it has it's own SET_PERSONALITY
> implementation.  In the discussion that followed Richard Henderson
> pointed out that the 32bit pointer support for alpha was never
> completed.
> 
> Fix this by removing alpha's 32bit pointer support.
> 
> As a bit of paranoia refuse to execute any alpha binaries that hafe
> the EF_ALPHA_32BIT flag set.  Just to fail explicitly in case someone
> somewhere has binaries that trying to use alpha's 32bit pointer
> support.
> 
> [1] https://lkml.kernel.org/r/CAFXwXrkgu=4Qn-v1PjnOR4SG0oUb9LSa0g6QXpBq4ttm52pJOQ@mail.gmail.com
> [2] https://lkml.kernel.org/r/20250103140148.370368-1-glaubitz@physik.fu-berlin.de
> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
> ---
>  arch/alpha/include/asm/elf.h       |  6 +-----
>  arch/alpha/include/asm/pgtable.h   |  2 +-
>  arch/alpha/include/asm/processor.h |  8 ++------
>  arch/alpha/kernel/osf_sys.c        | 11 ++---------
>  4 files changed, 6 insertions(+), 21 deletions(-)
> 
> diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
> index 4d7c46f50382..50c82187e60e 100644
> --- a/arch/alpha/include/asm/elf.h
> +++ b/arch/alpha/include/asm/elf.h
> @@ -74,7 +74,7 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
>  /*
>   * This is used to ensure we don't load something for the wrong architecture.
>   */
> -#define elf_check_arch(x) ((x)->e_machine == EM_ALPHA)
> +#define elf_check_arch(x) (((x)->e_machine == EM_ALPHA) && !((x)->e_flags & EF_ALPHA_32BIT))
>  
>  /*
>   * These are used to set parameters in the core dumps.
> @@ -137,10 +137,6 @@ extern int dump_elf_task(elf_greg_t *dest, struct task_struct *task);
>  	: amask (AMASK_CIX) ? "ev6" : "ev67");	\
>  })
>  
> -#define SET_PERSONALITY(EX)					\
> -	set_personality(((EX).e_flags & EF_ALPHA_32BIT)		\
> -	   ? PER_LINUX_32BIT : PER_LINUX)
> -
>  extern int alpha_l1i_cacheshape;
>  extern int alpha_l1d_cacheshape;
>  extern int alpha_l2_cacheshape;
> diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
> index 635f0a5f5bbd..02e8817a8921 100644
> --- a/arch/alpha/include/asm/pgtable.h
> +++ b/arch/alpha/include/asm/pgtable.h
> @@ -360,7 +360,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
>  
>  extern void paging_init(void);
>  
> -/* We have our own get_unmapped_area to cope with ADDR_LIMIT_32BIT.  */
> +/* We have our own get_unmapped_area */
>  #define HAVE_ARCH_UNMAPPED_AREA
>  
>  #endif /* _ALPHA_PGTABLE_H */
> diff --git a/arch/alpha/include/asm/processor.h b/arch/alpha/include/asm/processor.h
> index 55bb1c09fd39..5dce5518a211 100644
> --- a/arch/alpha/include/asm/processor.h
> +++ b/arch/alpha/include/asm/processor.h
> @@ -8,23 +8,19 @@
>  #ifndef __ASM_ALPHA_PROCESSOR_H
>  #define __ASM_ALPHA_PROCESSOR_H
>  
> -#include <linux/personality.h>	/* for ADDR_LIMIT_32BIT */
> -
>  /*
>   * We have a 42-bit user address space: 4TB user VM...
>   */
>  #define TASK_SIZE (0x40000000000UL)
>  
> -#define STACK_TOP \
> -  (current->personality & ADDR_LIMIT_32BIT ? 0x80000000 : 0x00120000000UL)
> +#define STACK_TOP (0x00120000000UL)
>  
>  #define STACK_TOP_MAX	0x00120000000UL
>  
>  /* This decides where the kernel will search for a free chunk of vm
>   * space during mmap's.
>   */
> -#define TASK_UNMAPPED_BASE \
> -  ((current->personality & ADDR_LIMIT_32BIT) ? 0x40000000 : TASK_SIZE / 2)
> +#define TASK_UNMAPPED_BASE (TASK_SIZE / 2)
>  
>  /* This is dead.  Everything has been moved to thread_info.  */
>  struct thread_struct { };
> diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
> index 86185021f75a..a08e8edef1a4 100644
> --- a/arch/alpha/kernel/osf_sys.c
> +++ b/arch/alpha/kernel/osf_sys.c
> @@ -1210,8 +1210,7 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
>  	return ret;
>  }
>  
> -/* Get an address range which is currently unmapped.  Similar to the
> -   generic version except that we know how to honor ADDR_LIMIT_32BIT.  */
> +/* Get an address range which is currently unmapped. */
>  
>  static unsigned long
>  arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
> @@ -1230,13 +1229,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
>  		       unsigned long len, unsigned long pgoff,
>  		       unsigned long flags, vm_flags_t vm_flags)
>  {
> -	unsigned long limit;
> -
> -	/* "32 bit" actually means 31 bit, since pointers sign extend.  */
> -	if (current->personality & ADDR_LIMIT_32BIT)
> -		limit = 0x80000000;
> -	else
> -		limit = TASK_SIZE;
> +	unsigned long limit = TASK_SIZE;
>  
>  	if (len > limit)
>  		return -ENOMEM;

Compile- and boot-tested on QEMU alpha, works as expected:

glaubitz@debian-alpha:~/util-linux$ ./tests/ts/misc/setarch 
         misc: setarch                        ...
                : options                     ...[  110.194279] pid=558, couldn't seal address 0, ret=-12.
 OK
                : uname26                     ... OK
                : uname26-version             ... OK
                : show                        ... OK
           ... OK (all 4 sub-tests PASSED)
glaubitz@debian-alpha:~/util-linux$

Tested-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>

Adrian

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

^ permalink raw reply

* Re: [PATCH] alpha/elf: Fix misc/setarch test of util-linux by removing 32bit support
From: Ivan Kokshaysky @ 2025-01-11 15:27 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: John Paul Adrian Glaubitz, Arnd Bergmann, Richard Henderson,
	Matt Turner, Kees Cook, Paul E. McKenney, linux-alpha, linux-mm,
	linux-kernel, Michael Cree, Sam James, Maciej W. Rozycki,
	Geert Uytterhoeven, Michael Karcher, Chris Hofstaedtler,
	util-linux, linux-mips, loongarch
In-Reply-To: <87jzb2tdb7.fsf_-_@email.froward.int.ebiederm.org>

On Fri, Jan 10, 2025 at 06:16:28PM -0600, Eric W. Biederman wrote:
> 
> Richard Henderson <richard.henderson@linaro.org> writes[1]:
> 
> > There was a Spec benchmark (I forget which) which was memory bound and ran
> > twice as fast with 32-bit pointers.
> >
> > I copied the idea from DEC to the ELF abi, but never did all the other work
> > to allow the toolchain to take advantage.
> >
> > Amusingly, a later Spec changed the benchmark data sets to not fit into a
> > 32-bit address space, specifically because of this.
> >
> > I expect one could delete the ELF bit and personality and no one would
> > notice. Not even the 10 remaining Alpha users.
> 
> In [2] it was pointed out that parts of setarch weren't working
> properly on alpha because it has it's own SET_PERSONALITY
> implementation.  In the discussion that followed Richard Henderson
> pointed out that the 32bit pointer support for alpha was never
> completed.
> 
> Fix this by removing alpha's 32bit pointer support.
> 
> As a bit of paranoia refuse to execute any alpha binaries that hafe
> the EF_ALPHA_32BIT flag set.  Just to fail explicitly in case someone
> somewhere has binaries that trying to use alpha's 32bit pointer
> support.

In general I agree, but then someone ought to remove the "--taso" option
from GNU ld, which produces such binaries.

Ivan.

> [1] https://lkml.kernel.org/r/CAFXwXrkgu=4Qn-v1PjnOR4SG0oUb9LSa0g6QXpBq4ttm52pJOQ@mail.gmail.com
> [2] https://lkml.kernel.org/r/20250103140148.370368-1-glaubitz@physik.fu-berlin.de
> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
> ---
>  arch/alpha/include/asm/elf.h       |  6 +-----
>  arch/alpha/include/asm/pgtable.h   |  2 +-
>  arch/alpha/include/asm/processor.h |  8 ++------
>  arch/alpha/kernel/osf_sys.c        | 11 ++---------
>  4 files changed, 6 insertions(+), 21 deletions(-)
> 
> diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
> index 4d7c46f50382..50c82187e60e 100644
> --- a/arch/alpha/include/asm/elf.h
> +++ b/arch/alpha/include/asm/elf.h
> @@ -74,7 +74,7 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
>  /*
>   * This is used to ensure we don't load something for the wrong architecture.
>   */
> -#define elf_check_arch(x) ((x)->e_machine == EM_ALPHA)
> +#define elf_check_arch(x) (((x)->e_machine == EM_ALPHA) && !((x)->e_flags & EF_ALPHA_32BIT))
>  
>  /*
>   * These are used to set parameters in the core dumps.
> @@ -137,10 +137,6 @@ extern int dump_elf_task(elf_greg_t *dest, struct task_struct *task);
>  	: amask (AMASK_CIX) ? "ev6" : "ev67");	\
>  })
>  
> -#define SET_PERSONALITY(EX)					\
> -	set_personality(((EX).e_flags & EF_ALPHA_32BIT)		\
> -	   ? PER_LINUX_32BIT : PER_LINUX)
> -
>  extern int alpha_l1i_cacheshape;
>  extern int alpha_l1d_cacheshape;
>  extern int alpha_l2_cacheshape;
> diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
> index 635f0a5f5bbd..02e8817a8921 100644
> --- a/arch/alpha/include/asm/pgtable.h
> +++ b/arch/alpha/include/asm/pgtable.h
> @@ -360,7 +360,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
>  
>  extern void paging_init(void);
>  
> -/* We have our own get_unmapped_area to cope with ADDR_LIMIT_32BIT.  */
> +/* We have our own get_unmapped_area */
>  #define HAVE_ARCH_UNMAPPED_AREA
>  
>  #endif /* _ALPHA_PGTABLE_H */
> diff --git a/arch/alpha/include/asm/processor.h b/arch/alpha/include/asm/processor.h
> index 55bb1c09fd39..5dce5518a211 100644
> --- a/arch/alpha/include/asm/processor.h
> +++ b/arch/alpha/include/asm/processor.h
> @@ -8,23 +8,19 @@
>  #ifndef __ASM_ALPHA_PROCESSOR_H
>  #define __ASM_ALPHA_PROCESSOR_H
>  
> -#include <linux/personality.h>	/* for ADDR_LIMIT_32BIT */
> -
>  /*
>   * We have a 42-bit user address space: 4TB user VM...
>   */
>  #define TASK_SIZE (0x40000000000UL)
>  
> -#define STACK_TOP \
> -  (current->personality & ADDR_LIMIT_32BIT ? 0x80000000 : 0x00120000000UL)
> +#define STACK_TOP (0x00120000000UL)
>  
>  #define STACK_TOP_MAX	0x00120000000UL
>  
>  /* This decides where the kernel will search for a free chunk of vm
>   * space during mmap's.
>   */
> -#define TASK_UNMAPPED_BASE \
> -  ((current->personality & ADDR_LIMIT_32BIT) ? 0x40000000 : TASK_SIZE / 2)
> +#define TASK_UNMAPPED_BASE (TASK_SIZE / 2)
>  
>  /* This is dead.  Everything has been moved to thread_info.  */
>  struct thread_struct { };
> diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
> index 86185021f75a..a08e8edef1a4 100644
> --- a/arch/alpha/kernel/osf_sys.c
> +++ b/arch/alpha/kernel/osf_sys.c
> @@ -1210,8 +1210,7 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
>  	return ret;
>  }
>  
> -/* Get an address range which is currently unmapped.  Similar to the
> -   generic version except that we know how to honor ADDR_LIMIT_32BIT.  */
> +/* Get an address range which is currently unmapped. */
>  
>  static unsigned long
>  arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
> @@ -1230,13 +1229,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
>  		       unsigned long len, unsigned long pgoff,
>  		       unsigned long flags, vm_flags_t vm_flags)
>  {
> -	unsigned long limit;
> -
> -	/* "32 bit" actually means 31 bit, since pointers sign extend.  */
> -	if (current->personality & ADDR_LIMIT_32BIT)
> -		limit = 0x80000000;
> -	else
> -		limit = TASK_SIZE;
> +	unsigned long limit = TASK_SIZE;
>  
>  	if (len > limit)
>  		return -ENOMEM;
> -- 
> 2.41.0
> 
> 

^ permalink raw reply

* Re: [PATCH] alpha/elf: Fix misc/setarch test of util-linux by removing 32bit support
From: Arnd Bergmann @ 2025-01-11 11:26 UTC (permalink / raw)
  To: Eric W. Biederman, John Paul Adrian Glaubitz
  Cc: Richard Henderson, Matt Turner, Kees Cook, Paul E. McKenney,
	linux-alpha, linux-mm, linux-kernel, Michael Cree, Sam James,
	Maciej W. Rozycki, Geert Uytterhoeven, Michael Karcher,
	Chris Hofstaedtler, util-linux, linux-mips, loongarch
In-Reply-To: <87jzb2tdb7.fsf_-_@email.froward.int.ebiederm.org>

On Sat, Jan 11, 2025, at 01:16, Eric W. Biederman wrote:
> Richard Henderson <richard.henderson@linaro.org> writes[1]:
>
>> There was a Spec benchmark (I forget which) which was memory bound and ran
>> twice as fast with 32-bit pointers.
>>
>> I copied the idea from DEC to the ELF abi, but never did all the other work
>> to allow the toolchain to take advantage.
>>
>> Amusingly, a later Spec changed the benchmark data sets to not fit into a
>> 32-bit address space, specifically because of this.
>>
>> I expect one could delete the ELF bit and personality and no one would
>> notice. Not even the 10 remaining Alpha users.
>
> In [2] it was pointed out that parts of setarch weren't working
> properly on alpha because it has it's own SET_PERSONALITY
> implementation.  In the discussion that followed Richard Henderson
> pointed out that the 32bit pointer support for alpha was never
> completed.
>
> Fix this by removing alpha's 32bit pointer support.
>
> As a bit of paranoia refuse to execute any alpha binaries that hafe
> the EF_ALPHA_32BIT flag set.  Just to fail explicitly in case someone
> somewhere has binaries that trying to use alpha's 32bit pointer
> support.
>
> [1] 
> https://lkml.kernel.org/r/CAFXwXrkgu=4Qn-v1PjnOR4SG0oUb9LSa0g6QXpBq4ttm52pJOQ@mail.gmail.com
> [2] 
> https://lkml.kernel.org/r/20250103140148.370368-1-glaubitz@physik.fu-berlin.de
> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>

Reviewed-by: Arnd Bergmann <arnd@arndb.de>

^ permalink raw reply

* Re: [PATCH] alpha/elf: Fix misc/setarch test of util-linux by removing 32bit support
From: John Paul Adrian Glaubitz @ 2025-01-11 10:37 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: Arnd Bergmann, Richard Henderson, Matt Turner, Kees Cook,
	Paul E. McKenney, linux-alpha, linux-mm, linux-kernel,
	Michael Cree, Sam James, Maciej W. Rozycki, Geert Uytterhoeven,
	Michael Karcher, Chris Hofstaedtler, util-linux, linux-mips,
	loongarch
In-Reply-To: <87jzb2tdb7.fsf_-_@email.froward.int.ebiederm.org>

Hi Eric,

On Fri, 2025-01-10 at 18:16 -0600, Eric W. Biederman wrote:
> Richard Henderson <richard.henderson@linaro.org> writes[1]:
> 
> > There was a Spec benchmark (I forget which) which was memory bound and ran
> > twice as fast with 32-bit pointers.
> > 
> > I copied the idea from DEC to the ELF abi, but never did all the other work
> > to allow the toolchain to take advantage.
> > 
> > Amusingly, a later Spec changed the benchmark data sets to not fit into a
> > 32-bit address space, specifically because of this.
> > 
> > I expect one could delete the ELF bit and personality and no one would
> > notice. Not even the 10 remaining Alpha users.
> 
> In [2] it was pointed out that parts of setarch weren't working
> properly on alpha because it has it's own SET_PERSONALITY
> implementation.  In the discussion that followed Richard Henderson
> pointed out that the 32bit pointer support for alpha was never
> completed.
> 
> Fix this by removing alpha's 32bit pointer support.
> 
> As a bit of paranoia refuse to execute any alpha binaries that hafe
                                                                 ^^^^ hafe->have

> the EF_ALPHA_32BIT flag set.  Just to fail explicitly in case someone
> somewhere has binaries that trying to use alpha's 32bit pointer
                            ^^^ are

> support.
> 
> [1] https://lkml.kernel.org/r/CAFXwXrkgu=4Qn-v1PjnOR4SG0oUb9LSa0g6QXpBq4ttm52pJOQ@mail.gmail.com
> [2] https://lkml.kernel.org/r/20250103140148.370368-1-glaubitz@physik.fu-berlin.de
> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
> ---
>  arch/alpha/include/asm/elf.h       |  6 +-----
>  arch/alpha/include/asm/pgtable.h   |  2 +-
>  arch/alpha/include/asm/processor.h |  8 ++------
>  arch/alpha/kernel/osf_sys.c        | 11 ++---------
>  4 files changed, 6 insertions(+), 21 deletions(-)
> 
> diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
> index 4d7c46f50382..50c82187e60e 100644
> --- a/arch/alpha/include/asm/elf.h
> +++ b/arch/alpha/include/asm/elf.h
> @@ -74,7 +74,7 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
>  /*
>   * This is used to ensure we don't load something for the wrong architecture.
>   */
> -#define elf_check_arch(x) ((x)->e_machine == EM_ALPHA)
> +#define elf_check_arch(x) (((x)->e_machine == EM_ALPHA) && !((x)->e_flags & EF_ALPHA_32BIT))
>  
>  /*
>   * These are used to set parameters in the core dumps.
> @@ -137,10 +137,6 @@ extern int dump_elf_task(elf_greg_t *dest, struct task_struct *task);
>  	: amask (AMASK_CIX) ? "ev6" : "ev67");	\
>  })
>  
> -#define SET_PERSONALITY(EX)					\
> -	set_personality(((EX).e_flags & EF_ALPHA_32BIT)		\
> -	   ? PER_LINUX_32BIT : PER_LINUX)
> -
>  extern int alpha_l1i_cacheshape;
>  extern int alpha_l1d_cacheshape;
>  extern int alpha_l2_cacheshape;
> diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
> index 635f0a5f5bbd..02e8817a8921 100644
> --- a/arch/alpha/include/asm/pgtable.h
> +++ b/arch/alpha/include/asm/pgtable.h
> @@ -360,7 +360,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
>  
>  extern void paging_init(void);
>  
> -/* We have our own get_unmapped_area to cope with ADDR_LIMIT_32BIT.  */
> +/* We have our own get_unmapped_area */
>  #define HAVE_ARCH_UNMAPPED_AREA
>  
>  #endif /* _ALPHA_PGTABLE_H */
> diff --git a/arch/alpha/include/asm/processor.h b/arch/alpha/include/asm/processor.h
> index 55bb1c09fd39..5dce5518a211 100644
> --- a/arch/alpha/include/asm/processor.h
> +++ b/arch/alpha/include/asm/processor.h
> @@ -8,23 +8,19 @@
>  #ifndef __ASM_ALPHA_PROCESSOR_H
>  #define __ASM_ALPHA_PROCESSOR_H
>  
> -#include <linux/personality.h>	/* for ADDR_LIMIT_32BIT */
> -
>  /*
>   * We have a 42-bit user address space: 4TB user VM...
>   */
>  #define TASK_SIZE (0x40000000000UL)
>  
> -#define STACK_TOP \
> -  (current->personality & ADDR_LIMIT_32BIT ? 0x80000000 : 0x00120000000UL)
> +#define STACK_TOP (0x00120000000UL)
>  
>  #define STACK_TOP_MAX	0x00120000000UL
>  
>  /* This decides where the kernel will search for a free chunk of vm
>   * space during mmap's.
>   */
> -#define TASK_UNMAPPED_BASE \
> -  ((current->personality & ADDR_LIMIT_32BIT) ? 0x40000000 : TASK_SIZE / 2)
> +#define TASK_UNMAPPED_BASE (TASK_SIZE / 2)
>  
>  /* This is dead.  Everything has been moved to thread_info.  */
>  struct thread_struct { };
> diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
> index 86185021f75a..a08e8edef1a4 100644
> --- a/arch/alpha/kernel/osf_sys.c
> +++ b/arch/alpha/kernel/osf_sys.c
> @@ -1210,8 +1210,7 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
>  	return ret;
>  }
>  
> -/* Get an address range which is currently unmapped.  Similar to the
> -   generic version except that we know how to honor ADDR_LIMIT_32BIT.  */
> +/* Get an address range which is currently unmapped. */
>  
>  static unsigned long
>  arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
> @@ -1230,13 +1229,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
>  		       unsigned long len, unsigned long pgoff,
>  		       unsigned long flags, vm_flags_t vm_flags)
>  {
> -	unsigned long limit;
> -
> -	/* "32 bit" actually means 31 bit, since pointers sign extend.  */
> -	if (current->personality & ADDR_LIMIT_32BIT)
> -		limit = 0x80000000;
> -	else
> -		limit = TASK_SIZE;
> +	unsigned long limit = TASK_SIZE;
>  
>  	if (len > limit)
>  		return -ENOMEM;

Looks good to me besides the two spelling mistakes above in the comment.

Reviewed-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>

Will also test and report back shortly.

Adrian

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox