From patchwork Tue Sep 25 08:54:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 974308 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 42KFPN17Mwz9sB5 for ; Tue, 25 Sep 2018 18:59:20 +1000 (AEST) Received: from localhost ([::1]:51721 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4jBd-0006VE-NN for incoming@patchwork.ozlabs.org; Tue, 25 Sep 2018 04:59:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4j7w-0003S1-0I for qemu-devel@nongnu.org; Tue, 25 Sep 2018 04:55:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g4j7n-0000DF-OU for qemu-devel@nongnu.org; Tue, 25 Sep 2018 04:55:24 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:42249) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g4j7n-0000CS-Dv for qemu-devel@nongnu.org; Tue, 25 Sep 2018 04:55:19 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Mdva2-1fX2CL3HM6-00azBI; Tue, 25 Sep 2018 10:55:07 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 25 Sep 2018 10:54:32 +0200 Message-Id: <20180925085432.3791-6-laurent@vivier.eu> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180925085432.3791-1-laurent@vivier.eu> References: <20180925085432.3791-1-laurent@vivier.eu> X-Provags-ID: V03:K1:0VNIbOyDGca8rd1l3pOCUu+0dkjl7YCp3wllQ+Syh3NstwCI9pk TlH8U22ujQzdeV9Nni5gqdYzCXIliDw+4UCb/d3KePAZv79dJBamIlk+ka5h4+OeDDW7y14 A6Qu7/zltsv6r7JW3+zCEoEbujRmkIBpWFiTgYmSzRQ1dyCFzXGh/qHKzCy6/jYBvSQz/TJ /9PohDhfjY4FR7GtiR4Jg== X-UI-Out-Filterresults: notjunk:1; V01:K0:+vYfhZcjYSU=:JWiWxiPtd+idLZxI5n36Cd mN/fIRHu+hyrDpvMbAon0NdgsW5WgvAieOBnsWWedtr8MRGoEUDMuU1Ija49mCzThYtehyA11 9A244+pIJYoDd7sWyyz+FE03yrT9mZhwOeKAGF9BgX460uilVxEYd1+kI5m28EPI3YuMV7GAE PP+yRr2dZBOARklZUUDH8lZO10veallap1Iw2AnfZCQEobyMrKzvtpzNuTWQ5x4NuhbdSIrjc t6omOrxQWVjjul4hUyhz7fRkfhN4zxSBcv0OgLo3V/GI68SoAcA+IpuUv8WM8KcuwA2GUjnQ4 GbGUfYhprvZzEwUqTGb7OavJeftKwUI7LNSS4jIFYZWKvW7p+bh7u/OuJ61Z7dkBmy3Hcpg+X oqkgbLlgF5VOJKDx3H7YvCL2bltBygukPbfEuCvc3V3uA821yg44yfX9xNkaPvy6P6m9FBAPx 20BW4hBNlb0IV1//Dkqg6FGP2jGeKMMbvkHoMYuJLOIuB7vt5jKqP1HBJboommsml5uLq6brk ilr7iBiugBArHTQ/uiklXrUo6L3LO4/pxXtLidqBbA431Yo+8pluLaBEuk0vkIKBu8fUzCdFG kbyyJjfgnKQgBmAize804kcb2E66WjXsJ1z5Jf6U2dZYGfKmfXY68tMplKJZbqzZkX+EMaE2y rA1e0KhmrwqnFP7o+DAWse8l3v3J6Dv8ASwprkt3hxz8Zmvo2VB7OkJxyAMmMZ4ZbWEo= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.134 Subject: [Qemu-devel] [PULL 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