From patchwork Fri Sep 14 18:40:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kenneth Magic X-Patchwork-Id: 970028 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="Gk1nPwi+"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42BkqV68d8z9s3x for ; Sat, 15 Sep 2018 04:40:49 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 238863E7659 for ; Fri, 14 Sep 2018 20:40:46 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id CF16C3E7631 for ; Fri, 14 Sep 2018 20:40:43 +0200 (CEST) Received: from mail-yb1-xb43.google.com (mail-yb1-xb43.google.com [IPv6:2607:f8b0:4864:20::b43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id C24641400B86 for ; Fri, 14 Sep 2018 20:40:42 +0200 (CEST) Received: by mail-yb1-xb43.google.com with SMTP id t10-v6so5227165ybb.1 for ; Fri, 14 Sep 2018 11:40:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=tV0d5K7IZ8xKuDJjtmRuM77TqOO5pdyhGKm5lKC9WrQ=; b=Gk1nPwi+hTM+zAIqYqLGj/Kf02I/yp4hjsSdm7weY+WhAIYXZd8BtupxzZHnt9nVyk 3ORextNvhTEeGDgPMAVXZvYnU+4CzeskEkV2pmxqui7GvceCKNzOFtr2488T6SaB9FG9 0XRCXP1Xw2i5AqiLJUx3m8WbiXWMiqQUYv7hzMIE/Sf7KMkG/KetJHM0tb0VbPGpvXba I031+EP7pDPspe4xqzzR9mj0CTOFfufcjCL3mcq27AMzEB745n1AR/MjZ6m+hmBJyGQw FHkG3zKUIqSxB9Naj8vIgpfrjpYSFG+Lx/Jeua3+XXiGHOjakEBMqM0XVjtYqoBM1+3C x6bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=tV0d5K7IZ8xKuDJjtmRuM77TqOO5pdyhGKm5lKC9WrQ=; b=cY5BgbbevUTkCWSnib5z7pwWkCRZ1V/sy/O7wfT8ok7CoMNw4wAWm4n6kxd3ZRQHCc tak+HFchSzZNjUp0V6rYdYvlAiCJTGJvQB1EXjDWEebB7GIfnaBuB14nUafSM165sayE nMRi8Ug/2L3tAmOqv2Pq/YUA062XjWCC6m3+gWEgWgaF+4u5VPacfVZgC8eYHCjWCS4g S/jeQ8pbPar1lDuABmwIeNHmrJFJwgd7BRqkWpVIBTFqLeJCKRQhgwoR6xkFjmAJsRPq P8Tk46NW6SzNXzQ4ZYXcRo6qbQuICgQ79/pmghDWHi2Q22tD2Vjd8SmOkFH7EO9+tDF4 aTGw== X-Gm-Message-State: APzg51BMsTev05ZSG/+8LY1i6Z+GXrei69L18qUtxQgLauIpS27BalSg TvP1KtAWBD7fq6g1XQGjQIXuec/7l5/HUhxr58lQYNwKkX0= X-Google-Smtp-Source: ANB0VdYKbVDMnigxr+vRS+xloPzOHnGxFsdY9tF4+y+TW7kVV7iT7zE6JWVJRAJAer5rBocCkyHqZayP7IVt46GKh6w= X-Received: by 2002:a25:add3:: with SMTP id d19-v6mr6293162ybe.347.1536950440881; Fri, 14 Sep 2018 11:40:40 -0700 (PDT) MIME-Version: 1.0 From: Kenneth Magic Date: Fri, 14 Sep 2018 11:40:21 -0700 Message-ID: To: ltp@lists.linux.it X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-14.9 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, ENV_AND_HDR_SPF_MATCH, HTML_MESSAGE, SPF_PASS, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Cc: kernel-team@android.com Subject: [LTP] [PATCH] Correct the kernel_bits value in x86 PER_LINUX32. X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Android runs all 32bit programs in a PER_LIINUX32 personality even under a 64 bit kernel, causing the machine to show up as "i686". Check for and correct this case so tests use the correct kernel_bits value. Signed-off-by: Kenneth Magic --- lib/tst_kernel.c | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/lib/tst_kernel.c b/lib/tst_kernel.c index 42d64cbdc..8edafb8ff 100644 --- a/lib/tst_kernel.c +++ b/lib/tst_kernel.c @@ -15,21 +15,28 @@ * along with this program. If not, see . */ +#include #include #include "test.h" #include "tst_kernel.h" -int tst_kernel_bits(void) +static int get_kernel_bits_from_uname(struct utsname *buf) { - struct utsname buf; - int kernel_bits; - - if (uname(&buf)) { + if (uname(buf)) { tst_brkm(TBROK | TERRNO, NULL, "uname()"); return -1; } - kernel_bits = strstr(buf.machine, "64") ? 64 : 32; + return strstr(buf->machine, "64") ? 64 : 32; +} + +int tst_kernel_bits(void) +{ + struct utsname buf; + int kernel_bits = get_kernel_bits_from_uname(&buf); + + if (kernel_bits == -1) + return -1; /* * ARM64 (aarch64) defines 32-bit compatibility modes as @@ -40,6 +47,34 @@ int tst_kernel_bits(void) || !strcmp(buf.machine, "s390x")) kernel_bits = 64; +#ifdef __ANDROID__ + /* Android's bionic libc sets the PER_LINUX32 personality for all 32-bit + * programs. This will cause buf.machine to report as i686 even though + * the kernel itself is 64-bit. + */ + if (!strcmp(buf.machine, "i686") && + (personality(0xffffffff) & PER_MASK) == PER_LINUX32) { + /* Set the personality back to the default. */ + if (personality(PER_LINUX) == -1) { + tst_brkm(TBROK | TERRNO, NULL, "personality()"); + return -1; + } + + /* Redo the uname check without the PER_LINUX32 personality to + * determine the actual kernel bits value. + */ + kernel_bits = get_kernel_bits_from_uname(&buf); + if (kernel_bits == -1) + return -1; + + /* Set the personality back to PER_LINUX32. */ + if (personality(PER_LINUX32) == -1) { + tst_brkm(TBROK | TERRNO, NULL, "personality()"); + return -1; + } + } +#endif /* __ANDROID__ */ + tst_resm(TINFO, "uname.machine=%s kernel is %ibit", buf.machine, kernel_bits);