[v3] compel/ppc64le: make task size detection more robust

Submitted by Mike Rapoport on Sept. 7, 2017, 8:41 a.m.

Details

Message ID 1504773719-13644-1-git-send-email-rppt@linux.vnet.ibm.com
State Accepted
Series "compel/ppc64le: make task size detection more robust"
Headers show

Commit Message

Mike Rapoport Sept. 7, 2017, 8:41 a.m.
The recent changes to user address space limits in the Linux kernel break
the assumption that TASK_SIZE is 128TB. For now, the maximal task size on
ppc64le is 512TB and we need to detect it in runtime for compatibility with
older kernels.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Acked-by: Laurent Dufour <ldufour@linux.vnet.ibm.com>
---
v3: drop unused definition of TASK_SIZE_128TB
v2: fix off-by-one

 compel/arch/ppc64/src/lib/infect.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/compel/arch/ppc64/src/lib/infect.c b/compel/arch/ppc64/src/lib/infect.c
index 8112588..1fa333e 100644
--- a/compel/arch/ppc64/src/lib/infect.c
+++ b/compel/arch/ppc64/src/lib/infect.c
@@ -2,6 +2,7 @@ 
 #include <sys/types.h>
 #include <sys/uio.h>
 #include <sys/user.h>
+#include <sys/mman.h>
 #include <stdint.h>
 #include <errno.h>
 #include <compel/plugins/std/syscall-codes.h>
@@ -9,6 +10,7 @@ 
 #include "errno.h"
 #include "log.h"
 #include "common/bug.h"
+#include "common/page.h"
 #include "infect.h"
 #include "infect-priv.h"
 
@@ -458,7 +460,18 @@  int arch_fetch_sas(struct parasite_ctl *ctl, struct rt_sigframe *s)
  *
  * NOTE: 32bit tasks are not supported.
  */
-#define TASK_SIZE_USER64	(0x0000400000000000UL)
-#define TASK_SIZE		TASK_SIZE_USER64
+#define TASK_SIZE_64TB  (0x0000400000000000UL)
+#define TASK_SIZE_512TB (0x0002000000000000UL)
 
-unsigned long compel_task_size(void) { return TASK_SIZE; }
+#define TASK_SIZE_MIN TASK_SIZE_64TB
+#define TASK_SIZE_MAX TASK_SIZE_512TB
+
+unsigned long compel_task_size(void)
+{
+	unsigned long task_size;
+
+	for (task_size = TASK_SIZE_MIN; task_size < TASK_SIZE_MAX; task_size <<= 1)
+		if (munmap((void *)task_size, page_size()))
+			break;
+	return task_size;
+}

Comments

Andrei Vagin Sept. 9, 2017, 1:17 a.m.
On Thu, Sep 07, 2017 at 11:41:59AM +0300, Mike Rapoport wrote:
> The recent changes to user address space limits in the Linux kernel break
> the assumption that TASK_SIZE is 128TB. For now, the maximal task size on
> ppc64le is 512TB and we need to detect it in runtime for compatibility with
> older kernels.
> 
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
> Acked-by: Laurent Dufour <ldufour@linux.vnet.ibm.com>
> ---
> v3: drop unused definition of TASK_SIZE_128TB
> v2: fix off-by-one
> 
>  compel/arch/ppc64/src/lib/infect.c | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/compel/arch/ppc64/src/lib/infect.c b/compel/arch/ppc64/src/lib/infect.c
> index 8112588..1fa333e 100644
> --- a/compel/arch/ppc64/src/lib/infect.c
> +++ b/compel/arch/ppc64/src/lib/infect.c
> @@ -2,6 +2,7 @@
>  #include <sys/types.h>
>  #include <sys/uio.h>
>  #include <sys/user.h>
> +#include <sys/mman.h>
>  #include <stdint.h>
>  #include <errno.h>
>  #include <compel/plugins/std/syscall-codes.h>
> @@ -9,6 +10,7 @@
>  #include "errno.h"
>  #include "log.h"
>  #include "common/bug.h"
> +#include "common/page.h"
>  #include "infect.h"
>  #include "infect-priv.h"
>  
> @@ -458,7 +460,18 @@ int arch_fetch_sas(struct parasite_ctl *ctl, struct rt_sigframe *s)
>   *
>   * NOTE: 32bit tasks are not supported.
>   */
> -#define TASK_SIZE_USER64	(0x0000400000000000UL)
> -#define TASK_SIZE		TASK_SIZE_USER64
> +#define TASK_SIZE_64TB  (0x0000400000000000UL)
> +#define TASK_SIZE_512TB (0x0002000000000000UL)
>  
> -unsigned long compel_task_size(void) { return TASK_SIZE; }
> +#define TASK_SIZE_MIN TASK_SIZE_64TB
> +#define TASK_SIZE_MAX TASK_SIZE_512TB
> +
> +unsigned long compel_task_size(void)
> +{
> +	unsigned long task_size;
> +
> +	for (task_size = TASK_SIZE_MIN; task_size < TASK_SIZE_MAX; task_size <<= 1)
> +		if (munmap((void *)task_size, page_size()))

What if you unmap something useful?

> +			break;
> +	return task_size;
> +}
> -- 
> 2.7.4
>
Mike Rapoport Sept. 12, 2017, 12:13 a.m.
On Fri, Sep 08, 2017 at 06:17:49PM -0700, Andrei Vagin wrote:
> On Thu, Sep 07, 2017 at 11:41:59AM +0300, Mike Rapoport wrote:
> > The recent changes to user address space limits in the Linux kernel break
> > the assumption that TASK_SIZE is 128TB. For now, the maximal task size on
> > ppc64le is 512TB and we need to detect it in runtime for compatibility with
> > older kernels.
> > 
> > Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
> > Acked-by: Laurent Dufour <ldufour@linux.vnet.ibm.com>
> > ---
> > v3: drop unused definition of TASK_SIZE_128TB
> > v2: fix off-by-one
> > 
> >  compel/arch/ppc64/src/lib/infect.c | 19 ++++++++++++++++---
> >  1 file changed, 16 insertions(+), 3 deletions(-)
> > 
> > diff --git a/compel/arch/ppc64/src/lib/infect.c b/compel/arch/ppc64/src/lib/infect.c
> > index 8112588..1fa333e 100644
> > --- a/compel/arch/ppc64/src/lib/infect.c
> > +++ b/compel/arch/ppc64/src/lib/infect.c
> > @@ -2,6 +2,7 @@
> >  #include <sys/types.h>
> >  #include <sys/uio.h>
> >  #include <sys/user.h>
> > +#include <sys/mman.h>
> >  #include <stdint.h>
> >  #include <errno.h>
> >  #include <compel/plugins/std/syscall-codes.h>
> > @@ -9,6 +10,7 @@
> >  #include "errno.h"
> >  #include "log.h"
> >  #include "common/bug.h"
> > +#include "common/page.h"
> >  #include "infect.h"
> >  #include "infect-priv.h"
> >  
> > @@ -458,7 +460,18 @@ int arch_fetch_sas(struct parasite_ctl *ctl, struct rt_sigframe *s)
> >   *
> >   * NOTE: 32bit tasks are not supported.
> >   */
> > -#define TASK_SIZE_USER64	(0x0000400000000000UL)
> > -#define TASK_SIZE		TASK_SIZE_USER64
> > +#define TASK_SIZE_64TB  (0x0000400000000000UL)
> > +#define TASK_SIZE_512TB (0x0002000000000000UL)
> >  
> > -unsigned long compel_task_size(void) { return TASK_SIZE; }
> > +#define TASK_SIZE_MIN TASK_SIZE_64TB
> > +#define TASK_SIZE_MAX TASK_SIZE_512TB
> > +
> > +unsigned long compel_task_size(void)
> > +{
> > +	unsigned long task_size;
> > +
> > +	for (task_size = TASK_SIZE_MIN; task_size < TASK_SIZE_MAX; task_size <<= 1)
> > +		if (munmap((void *)task_size, page_size()))
> 
> What if you unmap something useful?

The we die. But the same holds for arm as well.
 
> > +			break;
> > +	return task_size;
> > +}
> > -- 
> > 2.7.4
> > 
>
Andrei Vagin Sept. 17, 2017, 4:17 a.m.
Applied, thanks
On Thu, Sep 07, 2017 at 11:41:59AM +0300, Mike Rapoport wrote:
> The recent changes to user address space limits in the Linux kernel break
> the assumption that TASK_SIZE is 128TB. For now, the maximal task size on
> ppc64le is 512TB and we need to detect it in runtime for compatibility with
> older kernels.
> 
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
> Acked-by: Laurent Dufour <ldufour@linux.vnet.ibm.com>
> ---
> v3: drop unused definition of TASK_SIZE_128TB
> v2: fix off-by-one
> 
>  compel/arch/ppc64/src/lib/infect.c | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/compel/arch/ppc64/src/lib/infect.c b/compel/arch/ppc64/src/lib/infect.c
> index 8112588..1fa333e 100644
> --- a/compel/arch/ppc64/src/lib/infect.c
> +++ b/compel/arch/ppc64/src/lib/infect.c
> @@ -2,6 +2,7 @@
>  #include <sys/types.h>
>  #include <sys/uio.h>
>  #include <sys/user.h>
> +#include <sys/mman.h>
>  #include <stdint.h>
>  #include <errno.h>
>  #include <compel/plugins/std/syscall-codes.h>
> @@ -9,6 +10,7 @@
>  #include "errno.h"
>  #include "log.h"
>  #include "common/bug.h"
> +#include "common/page.h"
>  #include "infect.h"
>  #include "infect-priv.h"
>  
> @@ -458,7 +460,18 @@ int arch_fetch_sas(struct parasite_ctl *ctl, struct rt_sigframe *s)
>   *
>   * NOTE: 32bit tasks are not supported.
>   */
> -#define TASK_SIZE_USER64	(0x0000400000000000UL)
> -#define TASK_SIZE		TASK_SIZE_USER64
> +#define TASK_SIZE_64TB  (0x0000400000000000UL)
> +#define TASK_SIZE_512TB (0x0002000000000000UL)
>  
> -unsigned long compel_task_size(void) { return TASK_SIZE; }
> +#define TASK_SIZE_MIN TASK_SIZE_64TB
> +#define TASK_SIZE_MAX TASK_SIZE_512TB
> +
> +unsigned long compel_task_size(void)
> +{
> +	unsigned long task_size;
> +
> +	for (task_size = TASK_SIZE_MIN; task_size < TASK_SIZE_MAX; task_size <<= 1)
> +		if (munmap((void *)task_size, page_size()))
> +			break;
> +	return task_size;
> +}
> -- 
> 2.7.4
>