From patchwork Tue Sep 25 20:51:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 974735 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=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42KYDr3K4fz9s4Z for ; Wed, 26 Sep 2018 06:52:59 +1000 (AEST) Received: from localhost ([::1]:55210 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4uKE-0008Ef-7t for incoming@patchwork.ozlabs.org; Tue, 25 Sep 2018 16:52:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4uJT-0008EK-Pz for qemu-devel@nongnu.org; Tue, 25 Sep 2018 16:52:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g4uJP-0002EI-Dn for qemu-devel@nongnu.org; Tue, 25 Sep 2018 16:52:07 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:52581) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g4uJP-0002Da-4W for qemu-devel@nongnu.org; Tue, 25 Sep 2018 16:52:03 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MBDva-1fuTdk2gEo-00Cgtq; Tue, 25 Sep 2018 22:51:54 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 25 Sep 2018 22:51:29 +0200 Message-Id: <20180925205129.25261-6-laurent@vivier.eu> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180925205129.25261-1-laurent@vivier.eu> References: <20180925205129.25261-1-laurent@vivier.eu> X-Provags-ID: V03:K1:f8B6Ft4k5shA7pJQW9/qGpJUxXpBwbDQma+TWR37cshvOyHy0yJ xl4jJoIP5qCEN5udmk6i3RMI7is0jhDEQo1VsMeDqBSIDFjwSE8Fw+h0FUGr+cJVLR4L88I oIPQWw3qw7eoAP3I8EopKInKnQvXotEC90zXmI2qWadYXSXxw1tnjHs3KYifRjOJj506lgO EqnuVg8vdAvb/jYTi0Ihw== X-UI-Out-Filterresults: notjunk:1; V01:K0:fNKuY/iFdCA=:prCNYaCwzevDy7nr8t3D41 AzSJSUrRNyceqsX68PVfYrguaJKBoSAQTappZExZmdcpMASS5mAmJ+2yCMk1X92zBR4UUfIbg vPDLuSNrG1z/hTtsl0Xa9ZpYTR8+qzhozEnspVqG5hGNQJaDuUOpfyQbJMcsR7PnuV1VJCo7w UFznM9zONAaTokkGy9Oar06878vgCgzvkW2Urb/T7wPnE4PVZ3oa+FN+TfdXaK/aF7U8GYmmU oq3SFLKyDE0ViLLS3wsW6H3O19bsM+UHrn3/2p/+U/S0O5iSB7F217L4xrYZy3s9K2e/sOvX2 tl1z8xxA1Y3lclNa0SPCBpBVdzT3pGR0LNCBAufNNk2SDW7P3BO66xUgLqavtSZf/6AhUtXKE YVt4zB+mXPbry5R+OfkMdsMCuMgGZAVPe1Mym7sZyzcVFcuoiYxczXbikAvLoihBI4YJWUZwJ EImTtnsZcinzt2Dk4EqMNx6vVCPbRXJ3LUNfIQXYKcE8ImVWAzgg5Xsl84HX6yx7y9lfF++76 LFc1CYkdCWl6TmPHZDnLJ1yNNbscyrNfa2SMQvCYrLtYVUJ/3dBRXKda17c1H+M3WnDdVoL+p pOl/RvnesRO5cup2CWxqDZsaIr30KDgX7rRM3hCAafv8ztVs7Nthd1cIrdDFm4y0Kxo1/fts6 VKPymcgEoRhDd2zpzcCDZNy/Y9gCbqylhdRp6TBdW6xiFAFT19DEcylnucvLNiQMSqPU= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.130 Subject: [Qemu-devel] [PULL v2 5/5] linux-user: do setrlimit selectively X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Max Filippov , Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Max Filippov setrlimit guest calls that affect memory resources (RLIMIT_{AS,DATA,STACK}) may interfere with QEMU internal memory management. They may result in QEMU lockup because mprotect call in page_unprotect would fail with ENOMEM error code, causing infinite loop of SIGSEGV. E.g. it happens when running libstdc++ testsuite for xtensa target on x86_64 host. Don't call host setrlimit for memory-related resources. Reviewed-by: Peter Maydell Signed-off-by: Max Filippov Message-Id: <20180917181314.22551-1-jcmvbkbc@gmail.com> [lv: rebase on master] Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 019af632df..ae3c0dfef7 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7879,7 +7879,21 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, rlim.rlim_cur = target_to_host_rlim(target_rlim->rlim_cur); rlim.rlim_max = target_to_host_rlim(target_rlim->rlim_max); unlock_user_struct(target_rlim, arg2, 0); - return get_errno(setrlimit(resource, &rlim)); + /* + * If we just passed through resource limit settings for memory then + * they would also apply to QEMU's own allocations, and QEMU will + * crash or hang or die if its allocations fail. Ideally we would + * track the guest allocations in QEMU and apply the limits ourselves. + * For now, just tell the guest the call succeeded but don't actually + * limit anything. + */ + if (resource != RLIMIT_AS && + resource != RLIMIT_DATA && + resource != RLIMIT_STACK) { + return get_errno(setrlimit(resource, &rlim)); + } else { + return 0; + } } #endif #ifdef TARGET_NR_getrlimit