Re: [hwloc-users] hwloc 1.11 in Android

2016-10-25 Thread Marc Marí
I hacked together a lstopo APK, and the patch I sent earlier makes a
difference, although lstopo still doesn't fully work on Android.

The statically linked binary you sent earlier, run directly on the
shell (as root in an emulator):

Machine (1499MB total) + NUMANode L#0 (P#0 1499MB) + Package L#0 +
Core L#0 + PU L#0 (P#0) Block "vda"
  Block "vdb"
  Block "vdc"
  Block "vdd"
  Net "eth0"

lstopo as an APK *without* the patch I sent (logcat):

ample.lstopoJNI: type=1400 audit(0.0:23): avc: denied { read } for
name="/" dev="rootfs" ino=1 scontext=u:r:untrusted_app:s0:c512,c768
tcontext=u:object_r:rootfs:s0 tclass=dir permissive=0 10-25

lstopo  : Machine + PU L#0 (P#0)

ample.lstopoJNI: type=1400 audit(0.0:24): avc: denied { read } for
name="/" dev="rootfs" ino=1 scontext=u:r:untrusted_app:s0:c512,c768
tcontext=u:object_r:rootfs:s0 tclass=dir permissive=0

lstopo as an APK *with* the patch I sent (logcat):

ample.lstopoJNI: type=1400 audit(0.0:17): avc: denied { read } for
name="devices" dev="sysfs" ino=23
scontext=u:r:untrusted_app:s0:c512,c768
tcontext=u:object_r:sysfs:s0 tclass=dir permissive=0 10-25

lstopo  : buf:Machine (1499MB) + Package L#0 + Core L#0 + PU L#0
(P#0)

ample.lstopoJNI: type=1400 audit(0.0:18): avc: denied { read } for
name="/" dev="rootfs" ino=1 scontext=u:r:untrusted_app:s0:c512,c768
tcontext=u:object_r:rootfs:s0 tclass=dir permissive=0

You can see the "permission denied" messages on the logcat, but with
the patch, there is some extra information. This information seems to be
enough in my use case. If you want to fully integrate lstopo in a
non-root Android application, you will need to work a bit more on this.
Unfortunately, I cannot work on that at this moment.

Marc

>On Tue, 25 Oct 2016 15:57:42 +0200
>Samuel Thibault  wrote:
>
> Hello,
> 
> Brice Goglin, on Tue 25 Oct 2016 10:56:30 +0200, wrote:
> > It's not running as an
> > APK, but it's running inside a shell that was launched by an APK
> > (sshdroid, a ssh server shell). Not sure why this would be
> > different?  
> 
> IIRC such shells have to circumvent some OS protections to run. So
> they are running at higher privilege than normal applications.
> 
> Samuel
> ___
> hwloc-users mailing list
> hwloc-users@lists.open-mpi.org
> https://rfd.newmexicoconsortium.org/mailman/listinfo/hwloc-users


WARNING / LEGAL TEXT: This message is intended only for the use of the
individual or entity to which it is addressed and may contain
information which is privileged, confidential, proprietary, or exempt
from disclosure under applicable law. If you are not the intended
recipient or the person responsible for delivering the message to the
intended recipient, you are strictly prohibited from disclosing,
distributing, copying, or in any way using this message. If you have
received this communication in error, please notify the sender and
destroy and delete any copies you may have received.

http://www.bsc.es/disclaimer
___
hwloc-users mailing list
hwloc-users@lists.open-mpi.org
https://rfd.newmexicoconsortium.org/mailman/listinfo/hwloc-users


Re: [hwloc-users] hwloc 1.11 in Android

2016-10-25 Thread Samuel Thibault
Hello,

Brice Goglin, on Tue 25 Oct 2016 10:56:30 +0200, wrote:
> It's not running as an
> APK, but it's running inside a shell that was launched by an APK
> (sshdroid, a ssh server shell). Not sure why this would be different?

IIRC such shells have to circumvent some OS protections to run. So they
are running at higher privilege than normal applications.

Samuel
___
hwloc-users mailing list
hwloc-users@lists.open-mpi.org
https://rfd.newmexicoconsortium.org/mailman/listinfo/hwloc-users


Re: [hwloc-users] hwloc 1.11 in Android

2016-10-25 Thread Marc Marí
Thanks.

I have not tested master because the library I'm using is not
prepared for hwloc 2.

I'll try to prepare a "quick and dirty" lstopo APK to check my
permission management assumptions, and also to check master.

Marc

>On Tue, 25 Oct 2016 10:56:30 +0200
>Brice Goglin  wrote:
>
> Thanks. I am applying the patch to git master and v1.11 branches.
> 
> I tested my static build of lstopo-no-graphics on Android 6 on aarch64
> [1], it still works without disabling openat. It's not running as an
> APK, but it's running inside a shell that was launched by an APK
> (sshdroid, a ssh server shell). Not sure why this would be different?
> 
> Brice
> 
> [1]
> http://people.bordeaux.inria.fr/goglin/tmp/lstopo-aarch64/lstopo-no-graphics
> 
> 
> 
> Le 25/10/2016 09:11, Marc Marí a écrit :
> > Hello
> >
> > The patch is attached (if attachments are a problem in this list,
> > I'll send it in plain).
> >
> > The only API functions I'm using are from this code:
> >
> > https://github.com/pocl/pocl/blob/master/lib/CL/devices/topology/pocl_topology.c
> >
> > I'm using it in Android 6 for ARM64, and I'm linking dynamically and
> > packing in an APK.
> >
> > I suspect that, if you generate an executable and you run directly
> > on the Android shell, you won't have any premission issues. The
> > problem comes when you run it inside an APK, which is located in a
> > restricted sandbox. I have not tested that assumption.
> >
> > Marc
> >  
> >> On Mon, 24 Oct 2016 17:51:04 +0200
> >> Brice Goglin  wrote:
> >>
> >> Hello
> >> I am interested in seeing the patch, at least. If it isn't too
> >> intrusive, we could easily apply it.
> >> I am surprised to hear that openat fails on Android. I don't
> >> remember having to disable it last time I tried (on Android 4.0 or
> >> 4.1 iirc). But I was building natively (basically just
> >> cross-compiling for armv7 and static linking), maybe you're doing
> >> something different that comes with different constraints?
> >> I'd like to have lstopo available in the play store too (I only
> >> had a textual version last time I tried :))
> >> Brice
> >>
> >>
> >>
> >> Le 24/10/2016 17:42, Marc Marí a écrit :  
> >>> I was porting a library to Android, and this library uses hwloc
> >>> v1.11 in the background. I managed to make it work.
> >>>
> >>> Are you interested in adding Android support for hwloc version
> >>> 1.11? Should I send a patch?
> >>>
> >>> The only change necessary is to disable "openat" (HAVE_OPENAT)
> >>> when compiling for Android. Android does have support for it,
> >>> but, due to the permission system, it cannot be used, so hwloc
> >>> fails.
> >>>
> >>> Marc
> >>>
> >>> WARNING / LEGAL TEXT: This message is intended only for the use of
> >>> the individual or entity to which it is addressed and may contain
> >>> information which is privileged, confidential, proprietary, or
> >>> exempt from disclosure under applicable law. If you are not the
> >>> intended recipient or the person responsible for delivering the
> >>> message to the intended recipient, you are strictly prohibited
> >>> from disclosing, distributing, copying, or in any way using this
> >>> message. If you have received this communication in error, please
> >>> notify the sender and destroy and delete any copies you may have
> >>> received.
> >>>
> >>> http://www.bsc.es/disclaimer
> >>> ___
> >>> hwloc-users mailing list
> >>> hwloc-users@lists.open-mpi.org
> >>> https://rfd.newmexicoconsortium.org/mailman/listinfo/hwloc-users
> >> ___
> >> hwloc-users mailing list
> >> hwloc-users@lists.open-mpi.org
> >> https://rfd.newmexicoconsortium.org/mailman/listinfo/hwloc-users  
> >
> >
> > WARNING / LEGAL TEXT: This message is intended only for the use of
> > the individual or entity to which it is addressed and may contain
> > information which is privileged, confidential, proprietary, or
> > exempt from disclosure under applicable law. If you are not the
> > intended recipient or the person responsible for delivering the
> > message to the intended recipient, you are strictly prohibited from
> > disclosing, distributing, copying, or in any way using this
> > message. If you have received this communication in error, please
> > notify the sender and destroy and delete any copies you may have
> > received.
> >
> > http://www.bsc.es/disclaimer
> >  
> 


WARNING / LEGAL TEXT: This message is intended only for the use of the
individual or entity to which it is addressed and may contain
information which is privileged, confidential, proprietary, or exempt
from disclosure under applicable law. If you are not the intended
recipient or the person responsible for delivering the message to the
intended recipient, you are strictly prohibited from disclosing,
distributing, copying, or in any way using this message. If you have
received this communication in error, please notify the sender and
destroy and delete any copies you may hav

Re: [hwloc-users] hwloc 1.11 in Android

2016-10-25 Thread Brice Goglin
Thanks. I am applying the patch to git master and v1.11 branches.

I tested my static build of lstopo-no-graphics on Android 6 on aarch64
[1], it still works without disabling openat. It's not running as an
APK, but it's running inside a shell that was launched by an APK
(sshdroid, a ssh server shell). Not sure why this would be different?

Brice

[1]
http://people.bordeaux.inria.fr/goglin/tmp/lstopo-aarch64/lstopo-no-graphics



Le 25/10/2016 09:11, Marc Marí a écrit :
> Hello
>
> The patch is attached (if attachments are a problem in this list, I'll
> send it in plain).
>
> The only API functions I'm using are from this code:
>
> https://github.com/pocl/pocl/blob/master/lib/CL/devices/topology/pocl_topology.c
>
> I'm using it in Android 6 for ARM64, and I'm linking dynamically and
> packing in an APK.
>
> I suspect that, if you generate an executable and you run directly on
> the Android shell, you won't have any premission issues. The problem
> comes when you run it inside an APK, which is located in a restricted
> sandbox. I have not tested that assumption.
>
> Marc
>
>> On Mon, 24 Oct 2016 17:51:04 +0200
>> Brice Goglin  wrote:
>>
>> Hello
>> I am interested in seeing the patch, at least. If it isn't too
>> intrusive, we could easily apply it.
>> I am surprised to hear that openat fails on Android. I don't remember
>> having to disable it last time I tried (on Android 4.0 or 4.1 iirc).
>> But I was building natively (basically just cross-compiling for armv7
>> and static linking), maybe you're doing something different that
>> comes with different constraints?
>> I'd like to have lstopo available in the play store too (I only had a
>> textual version last time I tried :))
>> Brice
>>
>>
>>
>> Le 24/10/2016 17:42, Marc Marí a écrit :
>>> I was porting a library to Android, and this library uses hwloc
>>> v1.11 in the background. I managed to make it work.
>>>
>>> Are you interested in adding Android support for hwloc version 1.11?
>>> Should I send a patch?
>>>
>>> The only change necessary is to disable "openat" (HAVE_OPENAT) when
>>> compiling for Android. Android does have support for it, but, due to
>>> the permission system, it cannot be used, so hwloc fails.
>>>
>>> Marc
>>>
>>> WARNING / LEGAL TEXT: This message is intended only for the use of
>>> the individual or entity to which it is addressed and may contain
>>> information which is privileged, confidential, proprietary, or
>>> exempt from disclosure under applicable law. If you are not the
>>> intended recipient or the person responsible for delivering the
>>> message to the intended recipient, you are strictly prohibited from
>>> disclosing, distributing, copying, or in any way using this
>>> message. If you have received this communication in error, please
>>> notify the sender and destroy and delete any copies you may have
>>> received.
>>>
>>> http://www.bsc.es/disclaimer
>>> ___
>>> hwloc-users mailing list
>>> hwloc-users@lists.open-mpi.org
>>> https://rfd.newmexicoconsortium.org/mailman/listinfo/hwloc-users  
>> ___
>> hwloc-users mailing list
>> hwloc-users@lists.open-mpi.org
>> https://rfd.newmexicoconsortium.org/mailman/listinfo/hwloc-users
>
>
> WARNING / LEGAL TEXT: This message is intended only for the use of the
> individual or entity to which it is addressed and may contain
> information which is privileged, confidential, proprietary, or exempt
> from disclosure under applicable law. If you are not the intended
> recipient or the person responsible for delivering the message to the
> intended recipient, you are strictly prohibited from disclosing,
> distributing, copying, or in any way using this message. If you have
> received this communication in error, please notify the sender and
> destroy and delete any copies you may have received.
>
> http://www.bsc.es/disclaimer
>

___
hwloc-users mailing list
hwloc-users@lists.open-mpi.org
https://rfd.newmexicoconsortium.org/mailman/listinfo/hwloc-users

Re: [hwloc-users] hwloc 1.11 in Android

2016-10-25 Thread Marc Marí
Hello

The patch is attached (if attachments are a problem in this list, I'll
send it in plain).

The only API functions I'm using are from this code:

https://github.com/pocl/pocl/blob/master/lib/CL/devices/topology/pocl_topology.c

I'm using it in Android 6 for ARM64, and I'm linking dynamically and
packing in an APK.

I suspect that, if you generate an executable and you run directly on
the Android shell, you won't have any premission issues. The problem
comes when you run it inside an APK, which is located in a restricted
sandbox. I have not tested that assumption.

Marc

>On Mon, 24 Oct 2016 17:51:04 +0200
>Brice Goglin  wrote:
>
> Hello
> I am interested in seeing the patch, at least. If it isn't too
> intrusive, we could easily apply it.
> I am surprised to hear that openat fails on Android. I don't remember
> having to disable it last time I tried (on Android 4.0 or 4.1 iirc).
> But I was building natively (basically just cross-compiling for armv7
> and static linking), maybe you're doing something different that
> comes with different constraints?
> I'd like to have lstopo available in the play store too (I only had a
> textual version last time I tried :))
> Brice
> 
> 
> 
> Le 24/10/2016 17:42, Marc Marí a écrit :
> > I was porting a library to Android, and this library uses hwloc
> > v1.11 in the background. I managed to make it work.
> >
> > Are you interested in adding Android support for hwloc version 1.11?
> > Should I send a patch?
> >
> > The only change necessary is to disable "openat" (HAVE_OPENAT) when
> > compiling for Android. Android does have support for it, but, due to
> > the permission system, it cannot be used, so hwloc fails.
> >
> > Marc
> >
> > WARNING / LEGAL TEXT: This message is intended only for the use of
> > the individual or entity to which it is addressed and may contain
> > information which is privileged, confidential, proprietary, or
> > exempt from disclosure under applicable law. If you are not the
> > intended recipient or the person responsible for delivering the
> > message to the intended recipient, you are strictly prohibited from
> > disclosing, distributing, copying, or in any way using this
> > message. If you have received this communication in error, please
> > notify the sender and destroy and delete any copies you may have
> > received.
> >
> > http://www.bsc.es/disclaimer
> > ___
> > hwloc-users mailing list
> > hwloc-users@lists.open-mpi.org
> > https://rfd.newmexicoconsortium.org/mailman/listinfo/hwloc-users  
> 
> ___
> hwloc-users mailing list
> hwloc-users@lists.open-mpi.org
> https://rfd.newmexicoconsortium.org/mailman/listinfo/hwloc-users



WARNING / LEGAL TEXT: This message is intended only for the use of the
individual or entity to which it is addressed and may contain
information which is privileged, confidential, proprietary, or exempt
from disclosure under applicable law. If you are not the intended
recipient or the person responsible for delivering the message to the
intended recipient, you are strictly prohibited from disclosing,
distributing, copying, or in any way using this message. If you have
received this communication in error, please notify the sender and
destroy and delete any copies you may have received.

http://www.bsc.es/disclaimer

>From 82bc20f1a36e070e29f541533b092434bea85077 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marc=20Mar=C3=AD?= 
Date: Tue, 25 Oct 2016 09:04:03 +0200
Subject: [PATCH] Add basic Android support

---
 config/hwloc.m4  | 3 ++-
 config/hwloc_check_vendor.m4 | 9 +++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/config/hwloc.m4 b/config/hwloc.m4
index 1bcec17..03569eb 100644
--- a/config/hwloc.m4
+++ b/config/hwloc.m4
@@ -665,7 +665,8 @@ EOF])
   AC_DEFINE([HWLOC_HAVE_CLZL], [1], [Define to 1 if you have the `clzl' function.])
 ])
 
-AC_CHECK_FUNCS([openat], [hwloc_have_openat=yes])
+AS_IF([test "$hwloc_c_vendor" != "android"], [AC_CHECK_FUNCS([openat], [hwloc_have_openat=yes])])
+
 
 AC_CHECK_HEADERS([malloc.h])
 AC_CHECK_FUNCS([getpagesize memalign posix_memalign])
diff --git a/config/hwloc_check_vendor.m4 b/config/hwloc_check_vendor.m4
index 0963bc1..0340f4c 100644
--- a/config/hwloc_check_vendor.m4
+++ b/config/hwloc_check_vendor.m4
@@ -86,8 +86,13 @@ AC_DEFUN([_HWLOC_CHECK_COMPILER_VENDOR], [
 hwloc_check_compiler_vendor_result="unknown"
 
 # GNU is probably the most common, so check that one as soon as
-# possible.  Intel pretends to be GNU, so need to check Intel
-# before checking for GNU.
+# possible. Intel and Android pretend to be GNU, so need to
+# check Intel and Android before checking for GNU.
+
+# Android
+AS_IF([test "$hwloc_check_compiler_vendor_result" = "unknown"],
+  [HWLOC_IFDEF_IFELSE([__ANDROID__],
+   [hwloc_check_compiler_vendor_result="android"])])
 
 # Intel
 AS_IF([test