From nobody Sun May 5 06:35:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 15167190313901.8698376317015573; Tue, 23 Jan 2018 06:50:31 -0800 (PST) Received: from localhost ([::1]:33599 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzu1-0008Qn-QG for importer@patchew.org; Tue, 23 Jan 2018 09:50:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43407) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzs1-00075Q-17 for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edzrw-0002JX-QB for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:17 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:49182) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edzrw-0002IP-FU; Tue, 23 Jan 2018 09:48:12 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MTQ1P-1eBdm90eRz-00SKIL; Tue, 23 Jan 2018 15:48:10 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 23 Jan 2018 15:47:55 +0100 Message-Id: <20180123144807.5618-2-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180123144807.5618-1-laurent@vivier.eu> References: <20180123144807.5618-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K0:wpCLzc9kLopZja2236XSDOZA9oiwgErHQNL9RNucOX1917WaDhN PBQEihMpH+WaXXhUkkqtmmEcBeS6ujkCkF2UREvwc5LEXmdsIx9ORTqmiWahJ4dCSXrrmiq ULj1+tUyFNFUoIWwHw06SBzZJLYAaa4dWN6TyVnxA9CZu5sKnbrbhu+yfypUS+g2JxOSM3J mM1vIVl3Ul2t4zCqPlgZA== X-UI-Out-Filterresults: notjunk:1;V01:K0:iJmDBE7uI6k=:57PvMpElEg6j/ECXYcRBLm rZn9y+9ICQ3xDUUlziSLNL+5ssDFNsgMirlmhO5wYVTc8Vd77/3Z22CLy+RgxTIRoU1bMJZ15 g4wFcfapBQ/QHAfa6cQ0DfAdD/UlURRocYmwQVyNIQOuYuY6SFYeeKNiloaNyCBg4UmIVXUlb BYfD8UOUiLgsUsx7K3M7Bq8plV34qYkE06ehiLH+VeCvpG8+HLzCy3PsSJb7a/7v4dwZJ1k8s mwNX0l6kGVWx4Me7QjxegGj3Uu7tpadEEfRr2fXjSF1buuZXxOARzEOljqKZKpmAzRPJsXz0/ F/VyFgaVe/qp1OdnyDaNzYgodGNxSCCJPT5ptwhL7zU9scPZ4HdmRcyAhXyP+3FwGIShOGCNL dv8iW923JiXY5Ih2rRJBeyFLFfB6Zi5qVVVaGYoDchNCZJ7dqJlzpHARDwXJa9k1nKRczAUxh v/z3nk7C8kcKLUcSE+kZzTYhUtyRpbkYQKmZnxZe4FczgR1Q+FouRR+fUrGVpU1z6olX6ZRBg p+RMX0Zbcm9Sls2kAto2dzUcsReGORR49Z37SuDF+w5CcohbP7SrOEyjAFAJcRUAIDDeeryZd FIYiN0wIwirHe1zyXncuSCLTUl9Dns7v5dTkSkpgEuphCkM82vkgxnzbjPg9SPQ6yAm/kKdE6 JWlusiBHxUGC3PErj206XlrueJPcrueIQMrynO7LXbmdRfn5ERt0oCgTurnDoqMdE1V9DYJCk knaeFupM7gXFR3ZTaSJHtRtSm41IgnPQp3D+sVHLxdRpjzVzgcOLhIVz3Ho= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.10 Subject: [Qemu-devel] [PULL 01/13] linux-user: Fix locking order in fork_start() 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: Peter Maydell , qemu-stable@nongnu.org, Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Peter Maydell Our locking order is that the tb lock should be taken inside the mmap_lock, but fork_start() grabs locks the other way around. This means that if a heavily multithreaded guest process (such as Java) calls fork() it can deadlock, with the thread that called fork() stuck in fork_start() with the tb lock and waiting for the mmap lock, but some other thread in tb_find() with the mmap lock and waiting for the tb lock. The cpu_list_lock() should also always be taken last, not first. Fix this by making fork_start() grab the locks in the right order. The order in which we drop locks doesn't matter, so we leave fork_end() the way it is. Signed-off-by: Peter Maydell Cc: qemu-stable@nongnu.org Reviewed-by: Paolo Bonzini Reviewed-by: Alex Benn=C3=A9e Message-Id: <1512397331-15238-1-git-send-email-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 450eb3ce65..e8406917e3 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -127,9 +127,9 @@ int cpu_get_pic_interrupt(CPUX86State *env) /* Make sure everything is in a consistent state for calling fork(). */ void fork_start(void) { - cpu_list_lock(); - qemu_mutex_lock(&tb_ctx.tb_lock); mmap_fork_start(); + qemu_mutex_lock(&tb_ctx.tb_lock); + cpu_list_lock(); } =20 void fork_end(int child) --=20 2.14.3 From nobody Sun May 5 06:35:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516719207333355.32613304025585; Tue, 23 Jan 2018 06:53:27 -0800 (PST) Received: from localhost ([::1]:33620 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzx0-0002ba-LE for importer@patchew.org; Tue, 23 Jan 2018 09:53:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43409) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzs1-00075R-4U for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edzrw-0002Jr-VL for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:17 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:53116) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edzrw-0002IY-LT for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:12 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MHYCK-1ef5nS2WRI-003PY2; Tue, 23 Jan 2018 15:48:10 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 23 Jan 2018 15:47:56 +0100 Message-Id: <20180123144807.5618-3-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180123144807.5618-1-laurent@vivier.eu> References: <20180123144807.5618-1-laurent@vivier.eu> X-Provags-ID: V03:K0:Hz2/MRvBgvoNyWuDIH5Xyajag+PMslGb0SGwzc1G8jcCnYDJZgq e6aox1QvGtxaak3TB4gQwm/nUM+EE2IxaqLAr0xXN75pyKspJXmq9i98CTz8yOJsfPWOAxT 5bYDEm2fObX7g7ysJ1C4IFDz2rphsC9WP0HcsDsnUs3HyUsQt0kGTbryR+qBqFJ7yF9vRub Y/p63Yu3GCJslwF1D0FwA== X-UI-Out-Filterresults: notjunk:1;V01:K0:DsM+9peBhFc=:VjfyhFiya1Hn/REWjKHe8a tKYSF2V83oDfEF0Fj73gKjriZcgqDv6fpVHnqpmc8AF6Vp4H3xTN/xsflGuZCjFCoPUWRRAOF VccZO7KVPL7FmB3ZjwS7TjFSMu0skJ/cNT3TpiptIdIfnJzFAv3Oe10ixGnF0Uyu5qoCWeiPp oVxb6VjnMkeiW+IEmXHb/B091rUJFllaaO4wx57mrJ+NyFlWuFc58rgFuYPmZIexBSqGpOWTr Tii4hTDa/a/T9hKgiigrezFITI8NnRWRaxQ6xykKbAhN7TOCKK/5DRwrldhu0w4qUWXLuxVGN nDp8FL7vc9fxAer+kvgh7FBmDyhU/eOwCLgFFA3COyH4VBnHYSAED1MwHWlX6S2PSbKpPQ6E+ Gch+2xpmx6eYxQWT3dK7ptqRP566XCw/tD9BcHsLARb81n/E4NZPOnOqzJpm2AEMIlQ4VlYlj DpyfOY74H6ynbyAGyAU4S9vGqI6FJozzlFxuHAGlHIGZS8Sw2ggHuPhVDsNcnvMUNnN3o8+SM +CSlsLmVZsROjtIM4Rl+qrq3XCd6V99pppsStw29Wiw0jID4Zmk9W8cKX0RKMoOQ5PEu9zi/i Il9O7VxszRJsXxttKBdtLeYWsds8WSsepe6WVp2wM5qptAdHyJ+G/uQw6Xo+NCK5FRGA1dyeL y87PKUJ860zrEY1ID2/qW17P3o6K8IkCzKwC7UqoSjBeNKwMgoEGvsOEjODxfYoGhkubi0CRH CPBjdtHA/ArrORfV0sjcg7OiqtPRIqhBjIlGAg== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.73 Subject: [Qemu-devel] [PULL 02/13] linux-user: wrap fork() in a start/end exclusive section 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: Peter Maydell , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Maydell When we do a fork() in usermode emulation, we need to be in a start/end exclusive section, so that we can ensure that no other thread is in an RCU section. Otherwise you can get this deadlock: - fork thread: has mmap_lock, waits for rcu_sync_lock (because rcu_init_lock() is registered as a pthread_atfork() hook) - RCU thread: has rcu_sync_lock, waits for rcu_read_(un)lock - another CPU thread: in RCU critical section, waits for mmap_lock This can show up if you have a heavily multithreaded guest program that does a fork(). Signed-off-by: Peter Maydell Reported-by: Stuart Monteith Message-Id: <1512650481-1723-1-git-send-email-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/linux-user/main.c b/linux-user/main.c index e8406917e3..2140465709 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -127,6 +127,7 @@ int cpu_get_pic_interrupt(CPUX86State *env) /* Make sure everything is in a consistent state for calling fork(). */ void fork_start(void) { + start_exclusive(); mmap_fork_start(); qemu_mutex_lock(&tb_ctx.tb_lock); cpu_list_lock(); @@ -147,9 +148,13 @@ void fork_end(int child) qemu_mutex_init(&tb_ctx.tb_lock); qemu_init_cpu_list(); gdbserver_fork(thread_cpu); + /* qemu_init_cpu_list() takes care of reinitializing the + * exclusive state, so we don't need to end_exclusive() here. + */ } else { qemu_mutex_unlock(&tb_ctx.tb_lock); cpu_list_unlock(); + end_exclusive(); } } =20 --=20 2.14.3 From nobody Sun May 5 06:35:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151671920300555.61993983642469; Tue, 23 Jan 2018 06:53:23 -0800 (PST) Received: from localhost ([::1]:33619 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzww-0002Y5-7v for importer@patchew.org; Tue, 23 Jan 2018 09:53:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzs1-00075T-9q for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edzrx-0002L4-GN for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:17 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:53530) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edzrx-0002J7-5P for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:13 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MK26P-1eccpC08ST-001Tjn; Tue, 23 Jan 2018 15:48:11 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 23 Jan 2018 15:47:57 +0100 Message-Id: <20180123144807.5618-4-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180123144807.5618-1-laurent@vivier.eu> References: <20180123144807.5618-1-laurent@vivier.eu> X-Provags-ID: V03:K0:3F1/Ic4jxFHZZVXnDMoPYVFwpCGYk66ConPA/+uPXryjzoUeuMr 5Ekzj4QfeCuQweUEwC8IMEzrGPKYlI7EKMuqc70OFIsy+9MOI9jaiwygYJN2Jvl1lzGGoOE 7Ez5NOQkH6hykImKfkBmqidDJ00PmNDwhFG1t9pWGOnDedWXMMc0ISjgQfPMHWEAFIUPYKX 23Th3NXsmTzXi7607iQOg== X-UI-Out-Filterresults: notjunk:1;V01:K0:2RHHCqty9I0=:yPn85MOc9BaxVaA6us0w/B b1P2Ej8zqWzQ7VQbN95fj9knvENB5vzWM/DoRD/RfMyPlWL0UZ6z/hCgzKztOytr3HbEthfGY V4+fkt5FGmqFWaR49Pi1VolMMAGCH6rvP2NXSduLKwBxyyKIHrLhCwHk6vagR2bkFAoZkOJJQ PjdkA0fH1dvUmMC4LEQs5DLxFKcgwFWD5tGHjnLFIRpSdw6qhcbJNhnM6jAC1NIvpekNay6lm Q6keCVvl7kZC0MrbjsVgAmFFdrCLx6SJBh5dbB2+WKhZW1i8RJ2AZg7eW0sueSFCnCr35xpVG 3FY2TyjzzrZQSkETOG5iicuEebMzzBgpziiclhoUtDR2fIrQbXCW9ZwYJnFqRU/7OSfvNxE2e jS6FsuwTCzg50fwnAsMK8aySBHEcqdulp3xenAJO9M9zpc3HW4FG3vlEZnYGv8ZP+RPxR+JGi YZxl2fEnCBEK75omsaQmd1z2eUX5YY7REIXPj/Nt2jfq9F1+erP+uFgZollvDHHIo6sNvKYdq pvil36YBcobh0t/Ag19X7YbNXKDH0TSdPQeQQTMd38W4DCb/NQLduFaSWZHLhfb75RMCGC44g x3ZY1m4QGRfRri5Zxjc+9/XOhpcCtSNLQCGqCKpmknrDUvbJs4zvUjKshmgtzizOgP31FbdYS dE54mDKpR/24pKZbH3sd6mg/BRIjiFsUnIMl4Oa7Gzwh1Tgw3lk4ivmO2CtHeAxjSuOCzwWij ihGkqauL1HIDEjpGHaFEdPHPcrFevcucBGWgWQ== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.74 Subject: [Qemu-devel] [PULL 03/13] linux-user: Fix length calculations in host_to_target_cmsg() 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: Peter Maydell , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Maydell The handling of length calculations in host_to_target_cmsg() was rather confused: * when checking for whether the target cmsg header fit in the remaining buffer, we were using the host struct size, not the target size * we were setting tgt_len to "target payload + header length" but then using it as if it were the target payload length alone * in various message type cases we weren't handling the possibility that host or target buffers were truncated Fix these problems. The second one in particular is liable to result in us overrunning the guest provided buffer, since we will try to convert more data than is actually present. Fixes: https://bugs.launchpad.net/qemu/+bug/1701808 Reported-by: Bruno Haible Signed-off-by: Peter Maydell Message-Id: <1513345976-22958-2-git-send-email-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 11c9116c4a..a1b9772a85 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1782,7 +1782,7 @@ static inline abi_long host_to_target_cmsg(struct tar= get_msghdr *target_msgh, * to the guest via the CTRUNC bit), unlike truncation * in target_to_host_cmsg, which is a QEMU bug. */ - if (msg_controllen < sizeof(struct cmsghdr)) { + if (msg_controllen < sizeof(struct target_cmsghdr)) { target_msgh->msg_flags |=3D tswap32(MSG_CTRUNC); break; } @@ -1794,8 +1794,6 @@ static inline abi_long host_to_target_cmsg(struct tar= get_msghdr *target_msgh, } target_cmsg->cmsg_type =3D tswap32(cmsg->cmsg_type); =20 - tgt_len =3D TARGET_CMSG_LEN(len); - /* Payload types which need a different size of payload on * the target must adjust tgt_len here. */ @@ -1809,12 +1807,13 @@ static inline abi_long host_to_target_cmsg(struct t= arget_msghdr *target_msgh, break; } default: + tgt_len =3D len; break; } =20 - if (msg_controllen < tgt_len) { + if (msg_controllen < TARGET_CMSG_LEN(tgt_len)) { target_msgh->msg_flags |=3D tswap32(MSG_CTRUNC); - tgt_len =3D msg_controllen; + tgt_len =3D msg_controllen - sizeof(struct target_cmsghdr); } =20 /* We must now copy-and-convert len bytes of payload @@ -1875,6 +1874,10 @@ static inline abi_long host_to_target_cmsg(struct ta= rget_msghdr *target_msgh, uint32_t *v =3D (uint32_t *)data; uint32_t *t_int =3D (uint32_t *)target_data; =20 + if (len !=3D sizeof(uint32_t) || + tgt_len !=3D sizeof(uint32_t)) { + goto unimplemented; + } __put_user(*v, t_int); break; } @@ -1888,6 +1891,10 @@ static inline abi_long host_to_target_cmsg(struct ta= rget_msghdr *target_msgh, struct errhdr_t *target_errh =3D (struct errhdr_t *)target_data; =20 + if (len !=3D sizeof(struct errhdr_t) || + tgt_len !=3D sizeof(struct errhdr_t)) { + goto unimplemented; + } __put_user(errh->ee.ee_errno, &target_errh->ee.ee_errno); __put_user(errh->ee.ee_origin, &target_errh->ee.ee_origin); __put_user(errh->ee.ee_type, &target_errh->ee.ee_type); @@ -1911,6 +1918,10 @@ static inline abi_long host_to_target_cmsg(struct ta= rget_msghdr *target_msgh, uint32_t *v =3D (uint32_t *)data; uint32_t *t_int =3D (uint32_t *)target_data; =20 + if (len !=3D sizeof(uint32_t) || + tgt_len !=3D sizeof(uint32_t)) { + goto unimplemented; + } __put_user(*v, t_int); break; } @@ -1924,6 +1935,10 @@ static inline abi_long host_to_target_cmsg(struct ta= rget_msghdr *target_msgh, struct errhdr6_t *target_errh =3D (struct errhdr6_t *)target_data; =20 + if (len !=3D sizeof(struct errhdr6_t) || + tgt_len !=3D sizeof(struct errhdr6_t)) { + goto unimplemented; + } __put_user(errh->ee.ee_errno, &target_errh->ee.ee_errno); __put_user(errh->ee.ee_origin, &target_errh->ee.ee_origin); __put_user(errh->ee.ee_type, &target_errh->ee.ee_type); @@ -1950,8 +1965,8 @@ static inline abi_long host_to_target_cmsg(struct tar= get_msghdr *target_msgh, } } =20 - target_cmsg->cmsg_len =3D tswapal(tgt_len); - tgt_space =3D TARGET_CMSG_SPACE(len); + target_cmsg->cmsg_len =3D tswapal(TARGET_CMSG_LEN(tgt_len)); + tgt_space =3D TARGET_CMSG_SPACE(tgt_len); if (msg_controllen < tgt_space) { tgt_space =3D msg_controllen; } --=20 2.14.3 From nobody Sun May 5 06:35:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516719531799406.5313560421016; Tue, 23 Jan 2018 06:58:51 -0800 (PST) Received: from localhost ([::1]:33734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ee02F-0007Vb-2T for importer@patchew.org; Tue, 23 Jan 2018 09:58:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43436) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzs1-00075X-W8 for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edzrx-0002Ls-RO for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:18 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:49163) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edzrx-0002JK-FQ for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:13 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MEEHY-1ebq8R21Ps-00FUuk; Tue, 23 Jan 2018 15:48:11 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 23 Jan 2018 15:47:58 +0100 Message-Id: <20180123144807.5618-5-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180123144807.5618-1-laurent@vivier.eu> References: <20180123144807.5618-1-laurent@vivier.eu> X-Provags-ID: V03:K0:U236OxjhNZQP9sV1QSy+To9wxSYlGkkO6HXxMdRcj9GSzWb95zb PIamQUy2y29m3Fd/XT7zfsFuIhxVb3Yn0WBEKYTTe1gmb02wHdk1rWMUnytYBP+GRHNlHZx PgiPG/lkubsR6zYTnE3XzpP9/Jabr1C3XH8FaBxffjaYuqHcprTfLAXiqOTM19GxA/bOCWx f3N+eJLdYjtPFtBnEXOGw== X-UI-Out-Filterresults: notjunk:1;V01:K0:dtu6pRj9CSg=:bPThIwxMkrBJvN3OBa4ey9 wGzHFgTVBP6ff9E+1t1Z1Di4v+VoYbXMbOFxoLNJ+K9XpFWc3bEpUstQFMFoAy/554qq7lNdS CqShdWweYK2M06tBbUJbv+xVp9f7yFswQ/7HYZ8jvM7uG3kNjSsxwTf+NUGueIWdNwrq+khL3 vFnBksyjuftiJIxBnTVNEyI6ohy9nRIV0l6PTK3BzeHDf/eEVnx445dXI30sJmVPcCIj8rWTn nZLZjwpIKWpMFcOGuF3lx8yG5yP5RQUnU7ZWMJ9LFSasAVdJE27M7MsDrgfqvqyOos3FAMaTE gz1u8e5SeQ0DE/CMEgtiRX4uLZ9Q39HHFCVhyOMK7LD7Ne6ehzNUx0sqWnUikkRH7lmNGfG6J PIveNG77zDusgG7aNTEEPFYqLVC4FMR9shv+MiO/FeFvmIDLYmEgk1zKltI6fcX6MdLdFiWWA uH1hfOrjB/j2lQzAKuIh0uPm2PcUnhVmejs/CKEA2CfI0R3pEP2ZRd06MBc41Nulap53d3V5n CJmtowsBHRAIfHDYKxcYpi+OtnJNTFu3eGAS+rYw13Rd/O4Dox9D5WF3GFHrwe5YnYJ6UJquZ PtiNmWTK/hVNj9tBRBynnZsUJVX7y6Wj+fA4/cUuY2QkAGPXoWOH2IxtPJF4Su9lslLAGhRkd ihFghO+SGsBHiMr2f+xx0zse+ab6u1Pycj/c4GdCl/SxxGcTJBEBK0JNx/nXBuAqMdyyGGoBs 4eTmZKAmiuOwjyljRX1NoHPSfXXiFgBqJoJynQ== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.75 Subject: [Qemu-devel] [PULL 04/13] linux-user: Don't use CMSG_ALIGN(sizeof struct cmsghdr) 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: Peter Maydell , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Maydell The Linux struct cmsghdr is already guaranteed to be sufficiently aligned that CMSG_ALIGN(sizeof struct cmsghdr) is always equal to sizeof struct cmsghdr. Stop doing the unnecessary alignment arithmetic for host and target cmsghdr. This follows kernel commit 1ff8cebf49ed9e9ca2 and brings our TARGET_CMSG_* macros back into line with the kernel ones, as well as making them easier to understand. Signed-off-by: Peter Maydell Reviewed-by: Laurent Vivier Message-Id: <1513345976-22958-3-git-send-email-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 4 ++-- linux-user/syscall_defs.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index a1b9772a85..39553c81b6 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1692,7 +1692,7 @@ static inline abi_long target_to_host_cmsg(struct msg= hdr *msgh, void *target_data =3D TARGET_CMSG_DATA(target_cmsg); =20 int len =3D tswapal(target_cmsg->cmsg_len) - - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr)); + - sizeof(struct target_cmsghdr); =20 space +=3D CMSG_SPACE(len); if (space > msgh->msg_controllen) { @@ -1773,7 +1773,7 @@ static inline abi_long host_to_target_cmsg(struct tar= get_msghdr *target_msgh, void *data =3D CMSG_DATA(cmsg); void *target_data =3D TARGET_CMSG_DATA(target_cmsg); =20 - int len =3D cmsg->cmsg_len - CMSG_ALIGN(sizeof (struct cmsghdr)); + int len =3D cmsg->cmsg_len - sizeof(struct cmsghdr); int tgt_len, tgt_space; =20 /* We never copy a half-header but may copy half-data; diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index bec3680b94..a35c52a60a 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -303,9 +303,9 @@ struct target_cmsghdr { __target_cmsg_nxthdr(mhdr, cmsg, cmsg_start) #define TARGET_CMSG_ALIGN(len) (((len) + sizeof (abi_long) - 1) \ & (size_t) ~(sizeof (abi_long) - 1)) -#define TARGET_CMSG_SPACE(len) (TARGET_CMSG_ALIGN (len) \ - + TARGET_CMSG_ALIGN (sizeof (struct target_= cmsghdr))) -#define TARGET_CMSG_LEN(len) (TARGET_CMSG_ALIGN (sizeof (struct target_c= msghdr)) + (len)) +#define TARGET_CMSG_SPACE(len) (sizeof(struct target_cmsghdr) + \ + TARGET_CMSG_ALIGN(len)) +#define TARGET_CMSG_LEN(len) (sizeof(struct target_cmsghdr) + (len)) =20 static __inline__ struct target_cmsghdr * __target_cmsg_nxthdr(struct target_msghdr *__mhdr, --=20 2.14.3 From nobody Sun May 5 06:35:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516719030451397.3768716640294; Tue, 23 Jan 2018 06:50:30 -0800 (PST) Received: from localhost ([::1]:33600 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzu6-0008Td-3f for importer@patchew.org; Tue, 23 Jan 2018 09:50:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43441) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzs2-00075d-3t for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edzry-0002MS-7W for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:18 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:61908) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edzrx-0002KF-Ta for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:14 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MgOZS-1eP6BZ3ouM-00Nhaa; Tue, 23 Jan 2018 15:48:12 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 23 Jan 2018 15:47:59 +0100 Message-Id: <20180123144807.5618-6-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180123144807.5618-1-laurent@vivier.eu> References: <20180123144807.5618-1-laurent@vivier.eu> X-Provags-ID: V03:K0:luA8hJq+VZuSvonZgjeZBULZ9JP7uhkJSi7+fPKsdu8kK0cejUb TJX4iCfP9IC8yYDKQ1ZI5MvfhC1GHGgKuPb8WytFs+QE31cjPXukzQsWdIMGgui/SBZr7zH 29oUcxgiEIKiCcNSdrwcGySUR5Z8QNXBc8L739h7yzTNVuGxQrFIEI10FtM6vB3F6blw/uu 9SlaM5tt5QP9iAGJ3cQ1Q== X-UI-Out-Filterresults: notjunk:1;V01:K0:qrq+Ggasjxw=:kE6qD1oqFWa+Aj+okQLnkV FA1qzVFP+mu6FNMG02zpP+wl1XnMDJXFGTavDISe4DO/E0xc20FbZDK28gQGFU7vG+eNdwYgG 1jlWjXIUZX4BeI7mMm0EyqzHHGgRS+0NnMpCvwuR8lf2Dyx+pff7MMD8+Gxcb1aIcwk/B+EjI WkSBZaYjY7lqlpLoPCrO05bmOUK568VjJlPyLxFDWs8viE7GZLMmMmPO/Btn6Kp1PvveB7na6 0jJj3Yc80IgbHsoDDYD932KNK9VWDH1dRsKAj4tLZ3a0L7DlU3dNlw4wcyX+9pPJ8T5yuyudZ gEsk73bX6zrpA3aQt5kqic1EU4JrZ9pBAFJZIqY6UTO8E5x7m000705i5o27VrCYSiGcN9OkW kf3ZQCcjxps+/BGgf99EHIZML31cr6kryGracklktbl+Ixgy6E9QxDJnF6HvnVQ2M/ABmnthx JwYvjTkTdNt1A43FFPDT5BHymYL4EjmBQZNU3dTPOiv9XRoFrOMZ4GDIZvG9/tYI3Tomnn9ea YU44vUeX6DVsM2T8iXc7Qzf9a4Ky1e6p3lunOM1je97VkUdpg1uZNJSowC/L0d4YUOCL4WT/X P3Zl3J2M8VqdVLLtRrkCOoOu3PA0RLvfJSLMA/SbI2Uc1YAriO793r8NkEH/PzOc3TCxeTpQS SDb9NIi4GPLSiZ8F7mf6y9NXJQKXNbkAX4j70X8YlUcwul5SVfKvRCHUBOq7LgQgkedFaqOe4 YguJxvzDQkHhQF2YN6gia5kqBzC/qAL5wLfvzQ== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.10 Subject: [Qemu-devel] [PULL 05/13] linux-user: Translate flags argument to dup3 syscall 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: Peter Maydell , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Maydell The third argument to dup3() is a flags word which may be O_CLOEXEC. We weren't translating this flag from target to host value, which meant that if the target used a different value from the host (eg sparc guest and x86 host) the dup3() call would fail EINVAL. Do the correct translation. Fixes: https://bugs.launchpad.net/qemu/+bug/1704658 Reported-by: Bruno Haible Signed-off-by: Peter Maydell Reviewed-by: Laurent Vivier Message-Id: <1513351080-25917-1-git-send-email-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 39553c81b6..41ded90ee6 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8490,11 +8490,19 @@ abi_long do_syscall(void *cpu_env, int num, abi_lon= g arg1, #endif #if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3) case TARGET_NR_dup3: - ret =3D get_errno(dup3(arg1, arg2, arg3)); + { + int host_flags; + + if ((arg3 & ~TARGET_O_CLOEXEC) !=3D 0) { + return -EINVAL; + } + host_flags =3D target_to_host_bitmask(arg3, fcntl_flags_tbl); + ret =3D get_errno(dup3(arg1, arg2, host_flags)); if (ret >=3D 0) { fd_trans_dup(arg1, arg2); } break; + } #endif #ifdef TARGET_NR_getppid /* not on alpha */ case TARGET_NR_getppid: --=20 2.14.3 From nobody Sun May 5 06:35:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151671963002084.4279408909266; Tue, 23 Jan 2018 07:00:30 -0800 (PST) Received: from localhost ([::1]:33801 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ee03p-0000Yh-8P for importer@patchew.org; Tue, 23 Jan 2018 10:00:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43602) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzsC-0007G2-Dh for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edzs7-0002X8-TX for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:28 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:52011) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edzs7-0002W8-JI for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:23 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0LuMJr-1ekyap333v-011f2v; Tue, 23 Jan 2018 15:48:12 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 23 Jan 2018 15:48:00 +0100 Message-Id: <20180123144807.5618-7-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180123144807.5618-1-laurent@vivier.eu> References: <20180123144807.5618-1-laurent@vivier.eu> X-Provags-ID: V03:K0:EPpgKHRUtXaDGHoHDPGHuGvUWVZHYyu5oQGK0NxPS+3YTK6JqU7 JB+1dTRK3N8erd2rIxfmT97cE/VH8P4mRG+hrGSu45QwhRUXJ/TwvEvJ4owYLQmL1WNO18F uDge+2kxHpxawRYr30BFD6Mu7nItffswrSV3aH0qAW0FF7vSu2gL1Oflnk++7OdBzkxixcH UlcGNX0BA6ot6amEsInbA== X-UI-Out-Filterresults: notjunk:1;V01:K0:oA1otI66Rn0=:a4xSndZZENBLeAS4tJVhW1 fKfNTx4IzC4+aatcdmGMOk32T2hnGOeYJnS0i8K40Ay7ViGK8X8vd8o20xdmu41K86HC30lZv cIClSMoGk9v25xMzyI9GD+l6Cith+Z/iN4WvOBGqO3qZhwnBL0+b6g//jox9IKFnytPBg8/kd oAKnBwyHIa0sTJKmCdEK+TCg6SDiyTSYrfJGfsGmhXyJ7psaZuiaYz2kVy4wMlei1crp1vS5O WEunchBtG+rdzYkI+24zquOJH9f67pgKXimUz8ziM09jS+TtfERPmohaPRXqqxy8sZHt4w7RI 8MVB/dPBwiDPnEPes3UQzt9RZzZZeCwVdUOwHq5LoU1mWB0L99P0dnhZ/pt8FEBjPtSz28Mn9 uPLCpLF47HjQa4aBFbTOy7+vy/sr3Nsws4crm+IUueliZmvgiKMjXqZYhkNsbqK8Ko8K0ANBY eYKaTw1a+VZWr1RcJv4wD2ctTn7gh3hukQJjhlQ9rtCLm4yN5OQXovVhHgRb6PlFS/WKf5Eu1 WiAblDVDySljnm9olGbRdPzuAEeB8APJXq5kKqQ23Lo3XwwvcgFa+Qg7BqccLseBio4a7K+x/ G65uzk8oKtRvebzuZ+M/oNTc7OkBtH7zPR9FtpLKEkUvD1ZeMIB9nmyEIVkBK1frlCZfDudhL FjFbBTr7uHgcpxTH7aiykih1IydEUshTnWgDari0EDJX2L1KLAZD7tqZRkhWEEcluTskvfZvL frBn8gQqMwihkQAnJ7EewBpq7kjYJqGumKY7kQ== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.13 Subject: [Qemu-devel] [PULL 06/13] linux-user/mmap.c: Avoid choosing NULL as start address 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: Maximilian Riemensberger , Peter Maydell , Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Maximilian Riemensberger mmap() is required by the linux kernel ABI and POSIX to return a non-NULL address when the implementation chooses a start address for the mapping. The current implementation of mmap_find_vma_reserved() can return NULL as start address of a mapping which leads to subsequent crashes inside the guests glibc, e.g. output of qemu-arm-static --strace executing a test binary stx_test: 1879 mmap2(NULL,8388608,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS|= 0x20000,-1,0) =3D 0x00000000 1879 write(2,0xf6fd39d0,79) stx_test: allocatestack.c:514: allocate_sta= ck: Assertion `mem !=3D NULL' failed. This patch fixes mmap_find_vma_reserved() by skipping NULL as start address while searching for a suitable mapping start address. CC: Riku Voipio CC: Laurent Vivier CC: Peter Maydell Signed-off-by: Maximilian Riemensberger Reviewed-by: Laurent Vivier Reviewed-by: Richard Henderson Message-Id: <1515286904-86418-1-git-send-email-riemensberger@cadami.net> Signed-off-by: Laurent Vivier --- linux-user/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 4888f53139..0fbfd6dff2 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -234,7 +234,7 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start= , abi_ulong size) if (prot) { end_addr =3D addr; } - if (addr + size =3D=3D end_addr) { + if (addr && addr + size =3D=3D end_addr) { break; } addr -=3D qemu_host_page_size; --=20 2.14.3 From nobody Sun May 5 06:35:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516719274172948.7825007641682; Tue, 23 Jan 2018 06:54:34 -0800 (PST) Received: from localhost ([::1]:33621 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzy5-0003eT-AD for importer@patchew.org; Tue, 23 Jan 2018 09:54:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43456) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzs2-00075p-MR for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edzrz-0002Pa-RS for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:18 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:62773) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edzrz-0002NW-F5 for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:15 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0M3Sim-1evfJN0zeS-00qyKU; Tue, 23 Jan 2018 15:48:13 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 23 Jan 2018 15:48:01 +0100 Message-Id: <20180123144807.5618-8-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180123144807.5618-1-laurent@vivier.eu> References: <20180123144807.5618-1-laurent@vivier.eu> X-Provags-ID: V03:K0:Mtz/QztMMIglboKJevN/RqxMpSmQ2s3+/J7l1LxbaV+aBb3lTmz EMePRl0CvduOd6wjzOIlNmVfrZqp4fTqoblnFw6zpSic6Tz0WYGd88wE/BwodHY7l0VEll6 pKx7JS+BptcPmZjEE/o94XhxGmmKYcUIYA024wV2sKQNLBy6UDaiRV6slv4SM8zkLg4jopv McSksHL3R/vIwpzjg2kYw== X-UI-Out-Filterresults: notjunk:1;V01:K0:mt7/SHX7OaA=:n8ycVTFpAYFNCwuC7BSuRK aGU53htGuBvvfVrBhzO0bWanKuZBoZ86qp/a10ITonPYZCpdxKb2CtcH2QOygDYv6VNX0B91l fKau+FAUE/eHewb45ThMO12QTmHQCgsYk+pyzGy6tN1yvNaPEDrWpcHsf2EvYxVcsZjsRx92x HXviWq+N14c9BO8a7vOrbT/t7H4bMtRovv8/M5Xh72u4ypjHUHoAB+lSgT8ccIHPmOZ502YWO MXnTyyApGFUEBALsurRVO8hVdPJuWy5hINwxyQnvslu6/wIXeYWOT8v9OLHMFTU39sIQpWDpp H66QSm2Yekvm7WMg+jGx6t87B+H2xbChgFc+r+7RPeWxgTvFMwDl0/hc0+XCDwTAyRKSiIM7I ylastedKmtjX5D5SRl40RtXcNmrp11T9sy9sGYvAzuFa2Tev56ncxB2QvaF6X2sIvHLiAA3o7 u6XwDu+f4IVeTQj15mIf5NHEFKUJy8RweWnRwhcmAtsvSaJ15V0F4XqjYxWAeCXAsuju8QPjD RPu8KyFfR/wnA0EDbQifVLU18MPlxVTeGHUm0gt+DrDXbWXdg9KIct97Oo01EMbD5BXIXbJvq JSYXL+n95z9Rnam/JvsSShxTjSQyrizkQrETOMwhId6Cj1zJ7SScIilaj972LGTP31j1GlNEG BOaFSFcwE3ZL/e08Jf2cv1HUGAkFtalPORmLCLlBI3cldCp/PGj9pUGrxZ0Xi7RYKWHcOLd+W g6Dl+08L3wotkpefGVWUIzq8SRvmF4xljjSu+g== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.75 Subject: [Qemu-devel] [PULL 07/13] linux-user: Fix sched_get/setaffinity conversion 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: Samuel Thibault , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Samuel Thibault sched_get/setaffinity linux-user syscalls were missing conversions for little/big endian, which is hairy since longs may not be the same size either. For simplicity, this just introduces loops to convert bit by bit like is done for select. Signed-off-by: Samuel Thibault Reviewed-by: Laurent Vivier Message-Id: <20180109201643.1479-1-samuel.thibault@ens-lyon.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++--= ---- 1 file changed, 73 insertions(+), 8 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 41ded90ee6..143e4a959d 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7731,6 +7731,73 @@ static TargetFdTrans target_inotify_trans =3D { }; #endif =20 +static int target_to_host_cpu_mask(unsigned long *host_mask, + size_t host_size, + abi_ulong target_addr, + size_t target_size) +{ + unsigned target_bits =3D sizeof(abi_ulong) * 8; + unsigned host_bits =3D sizeof(*host_mask) * 8; + abi_ulong *target_mask; + unsigned i, j; + + assert(host_size >=3D target_size); + + target_mask =3D lock_user(VERIFY_READ, target_addr, target_size, 1); + if (!target_mask) { + return -TARGET_EFAULT; + } + memset(host_mask, 0, host_size); + + for (i =3D 0 ; i < target_size / sizeof(abi_ulong); i++) { + unsigned bit =3D i * target_bits; + abi_ulong val; + + __get_user(val, &target_mask[i]); + for (j =3D 0; j < target_bits; j++, bit++) { + if (val & (1UL << j)) { + host_mask[bit / host_bits] |=3D 1UL << (bit % host_bits); + } + } + } + + unlock_user(target_mask, target_addr, 0); + return 0; +} + +static int host_to_target_cpu_mask(const unsigned long *host_mask, + size_t host_size, + abi_ulong target_addr, + size_t target_size) +{ + unsigned target_bits =3D sizeof(abi_ulong) * 8; + unsigned host_bits =3D sizeof(*host_mask) * 8; + abi_ulong *target_mask; + unsigned i, j; + + assert(host_size >=3D target_size); + + target_mask =3D lock_user(VERIFY_WRITE, target_addr, target_size, 0); + if (!target_mask) { + return -TARGET_EFAULT; + } + + for (i =3D 0 ; i < target_size / sizeof(abi_ulong); i++) { + unsigned bit =3D i * target_bits; + abi_ulong val =3D 0; + + for (j =3D 0; j < target_bits; j++, bit++) { + if (host_mask[bit / host_bits] & (1UL << (bit % host_bits))) { + val |=3D 1UL << j; + } + } + __put_user(val, &target_mask[i]); + } + + unlock_user(target_mask, target_addr, target_size); + return 0; +} + /* do_syscall() should always have a single exit point at the end so that actions, such as logging of syscall results, can be performed. All errnos that do_syscall() returns must be -TARGET_. */ @@ -10376,6 +10443,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_lon= g arg1, mask_size =3D (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) -= 1); =20 mask =3D alloca(mask_size); + memset(mask, 0, mask_size); ret =3D get_errno(sys_sched_getaffinity(arg1, mask_size, mask)= ); =20 if (!is_error(ret)) { @@ -10395,9 +10463,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_lon= g arg1, ret =3D arg2; } =20 - if (copy_to_user(arg3, mask, ret)) { - goto efault; - } + ret =3D host_to_target_cpu_mask(mask, mask_size, arg3, arg= 2); } } break; @@ -10415,13 +10481,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_l= ong arg1, break; } mask_size =3D (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) -= 1); - mask =3D alloca(mask_size); - if (!lock_user_struct(VERIFY_READ, p, arg3, 1)) { - goto efault; + + ret =3D target_to_host_cpu_mask(mask, mask_size, arg3, arg2); + if (ret) { + break; } - memcpy(mask, p, arg2); - unlock_user_struct(p, arg2, 0); =20 ret =3D get_errno(sys_sched_setaffinity(arg1, mask_size, mask)= ); } --=20 2.14.3 From nobody Sun May 5 06:35:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516719379814584.3092795003087; Tue, 23 Jan 2018 06:56:19 -0800 (PST) Received: from localhost ([::1]:33640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzzc-00056X-Ke for importer@patchew.org; Tue, 23 Jan 2018 09:56:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzs2-00075q-NH for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edzs0-0002Pr-4b for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:18 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:52914) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edzrz-0002OF-R7 for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:16 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MUVwx-1eCjhm2sdf-00REMn; Tue, 23 Jan 2018 15:48:13 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 23 Jan 2018 15:48:02 +0100 Message-Id: <20180123144807.5618-9-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180123144807.5618-1-laurent@vivier.eu> References: <20180123144807.5618-1-laurent@vivier.eu> X-Provags-ID: V03:K0:UJRKC/ivc9bSjujaNT3kuF9szvI9wrlmc8eHpkfg67WzHwjRpVK q/m7E2+Wl5e+u9EBv8x7g2bckh4uJz31evKNbgsHb9WycA2JDaRrLYt/VTs6+o3YSIOkJ5A YNKPCXH5aX6D5MwH43M2qoKmaljNFgO0tLiwcSvOrOGde39DLnH2jdxPTnFsZSIoumh6b0I LUGZc9AMLpieSwKSUThWA== X-UI-Out-Filterresults: notjunk:1;V01:K0:Zl4q47UaXZo=:uAsRrLWr60nnOdbxlmdASP 7CEZp/lRdPVdtLuq9fANVhO0/RgNmpg6Ivqb7mQ04Bnej3Z2dGmSxmaHME3VTHgbpjWR4TJUI pPeu3ObeI/wA1i6mzyc0eIZfZYXSlsE2c53LtVVAwry62o/HsxtDhwd5lDRGBh73fFQiort/u ssBnKJ0C0W0FOtBUe5tpHwysw0lBbHQZgn0H15xestOuaERgwSDKaKPORscO1YHl+FwrUSZlW 8LpZYgbfoLIpPLkkX3vKfeyjoWH3jG8xeXJwL5Itr1qlsVyq5vzrLIGLpdd03aWXhgJkAEE/H oj6hhrDemvayDxWwoEy1gbIqEQi83Zusb5jjZCtBx+m2J/srjzswKEd5X3Al9uMdKzpe0lTWI 02Ys1GyuRFeUtt1xLPwlWSzh6cgR6pV/tS67BaSJj0HIwJEzwyPdl5CPOwVKRFgMnBzERzh9b isTcWVBVeoQiAsNS5t7qauAHrcwVp3Di2ki2RJjKPsMjFF+06Cssi99HCMXb2qsZ6D7j5j2RN FCzOoge4NvSEDnCyjq13y38w6GD01iKfkhwqn4MRMybUcdIsKH/Po/GMLbO4MUXzKiqWbhOgo yZL8Nw4YOJjXW4uF+r2NU5aU6Z0n8QAy5b6QaofSHtJdJaN2nhcysnPcL5+H2Jw4lkEIBAQAD ylXsMgTPyWJqtreMJUgEOmxob6+4a04bkKuW3etSmbxHtRKku6aueWh66qw/E1LmMVtd8QTRX IwpsIKXEcGk5E46Lzq1tgmCXAbKlMGxBzHvsag== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.75 Subject: [Qemu-devel] [PULL 08/13] linux-user: Add AT_SECURE auxval 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: Marco A L Barbosa , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Marco A L Barbosa Signed-off-by: Marco A L Barbosa Reviewed-by: Peter Maydell Reviewed-by: Laurent Vivier Message-Id: <20180111183714.22834-2-malbarbo@gmail.com> Signed-off-by: Laurent Vivier --- linux-user/elfload.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 20f3d8c2c3..32a47674e6 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1354,7 +1354,7 @@ struct exec ~(abi_ulong)(TARGET_ELF_EXEC_PAGESIZE-1)) #define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE-1)) =20 -#define DLINFO_ITEMS 14 +#define DLINFO_ITEMS 15 =20 static inline void memcpy_fromfs(void * to, const void * from, unsigned lo= ng n) { @@ -1786,6 +1786,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int a= rgc, int envc, NEW_AUX_ENT(AT_HWCAP, (abi_ulong) ELF_HWCAP); NEW_AUX_ENT(AT_CLKTCK, (abi_ulong) sysconf(_SC_CLK_TCK)); NEW_AUX_ENT(AT_RANDOM, (abi_ulong) u_rand_bytes); + NEW_AUX_ENT(AT_SECURE, (abi_ulong) qemu_getauxval(AT_SECURE)); =20 #ifdef ELF_HWCAP2 NEW_AUX_ENT(AT_HWCAP2, (abi_ulong) ELF_HWCAP2); --=20 2.14.3 From nobody Sun May 5 06:35:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516719029883157.68649388631206; Tue, 23 Jan 2018 06:50:29 -0800 (PST) Received: from localhost ([::1]:33601 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzu9-0008WC-4Y for importer@patchew.org; Tue, 23 Jan 2018 09:50:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43495) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzs5-00077S-5m for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edzs0-0002QM-Cd for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:21 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:61585) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edzs0-0002Ot-34 for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:16 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0Lw10f-1es8X50axZ-017jat; Tue, 23 Jan 2018 15:48:14 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 23 Jan 2018 15:48:03 +0100 Message-Id: <20180123144807.5618-10-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180123144807.5618-1-laurent@vivier.eu> References: <20180123144807.5618-1-laurent@vivier.eu> X-Provags-ID: V03:K0:DlPXebNgWHEi6HEw4vrHo8Bo0/f32kiUpWkTdr8wDyjxXcMI8lk J7H9tex2xcenQF9LUsiT/8R87sSXxhP/QhhYzz88ntZaubCCzQqOH36aWEbv7uJy78FZQVf i8ZB5kSM/NBQHXxYVI/DT1dBQfgGOxHqHbQMBPGtFunPiW7usIdVUGZN3FoL+lKbioEHDVL K7TPRBsOKR/hYNr2tN37Q== X-UI-Out-Filterresults: notjunk:1;V01:K0:1LMFwe7ktc8=:rtAXwIjPCuKZMt1VlfcXo6 fl+/fteocO0IO0fgX8rnc89LbbDR1wwJfffwNdmUk/fdt6xNAPnk56t2H2LG2kHk4ubUmPxxx rRS6Ls4u7AwCS16SagyBCQXEFogEmSLaSZ3EyC4q/3ITxhZPsY64kj91Nn0bjb9U7F16eBaTK xU7lmt+tYcxgUfQG6wwTGywmtH/bDnSbaEPUG+paoTnzr/cGV5kt8e1Eht/rElzhW1xmCBfG+ cCRD/KlPBOm7+Iyoxvx0qpo04xXQtuufxFkeK7aSEhAL8RRhyDTlY+TEAl51//Aznhk0NmC+q Va9IEwVJ0pNJ/ZO88/NLoAqt1cnkJi3BoH05uXXhldfo2peXOJ0m3rd5sdxT838TB0MtJxXyh QAYPQ/57AxCMSSxkLkLT0oNEItj7oMIV1ZzDkfTlvi0bHLDgxo9LTXwcA9N3YPPgBKtllQTet 1y7pRPBI1iL4f1CI3qElOUNIOScRj23M5W8lAERywJJBtxLzJWeT9XmLZ1muSyfBZmR23aG4L vNFhfdrdJYZ4uINSTJUIiBgHBt5cp5K202ZPHH1JGsReK0+VSwoanoLBwkvP0susSD1bmRHAf TJRNj6JYK+h2aOiFWJxyceth82ppbuKKaGXCS2HpqF7Yi9XwmBexggAxWaBHihw0TwPBKSi6y ShhXvv1m4KOvHc9vNWLGS5QvKrlAw7+EWG2Ht73OMHC/dxSE1TsYsgk9bOrcghsR8KtHtcTo2 sVnTm7ZdT4W1lsW/td1AOxp35NQtpjL5P7PrFQ== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.24 Subject: [Qemu-devel] [PULL 09/13] linux-user: Add getcpu() support 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: Samuel Thibault , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Samuel Thibault Signed-off-by: Samuel Thibault Reviewed-by: Laurent Vivier Message-Id: <20180112081435.21299-1-samuel.thibault@ens-lyon.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 143e4a959d..104408c050 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -296,6 +296,8 @@ _syscall3(int, sys_sched_getaffinity, pid_t, pid, unsig= ned int, len, #define __NR_sys_sched_setaffinity __NR_sched_setaffinity _syscall3(int, sys_sched_setaffinity, pid_t, pid, unsigned int, len, unsigned long *, user_mask_ptr); +#define __NR_sys_getcpu __NR_getcpu +_syscall3(int, sys_getcpu, unsigned *, cpu, unsigned *, node, void *, tcac= he); _syscall4(int, reboot, int, magic1, int, magic2, unsigned int, cmd, void *, arg); _syscall2(int, capget, struct __user_cap_header_struct *, header, @@ -10491,6 +10493,23 @@ abi_long do_syscall(void *cpu_env, int num, abi_lo= ng arg1, ret =3D get_errno(sys_sched_setaffinity(arg1, mask_size, mask)= ); } break; + case TARGET_NR_getcpu: + { + unsigned cpu, node; + ret =3D get_errno(sys_getcpu(arg1 ? &cpu : NULL, + arg2 ? &node : NULL, + NULL)); + if (is_error(ret)) { + goto fail; + } + if (arg1 && put_user_u32(cpu, arg1)) { + goto efault; + } + if (arg2 && put_user_u32(node, arg2)) { + goto efault; + } + } + break; case TARGET_NR_sched_setparam: { struct sched_param *target_schp; --=20 2.14.3 From nobody Sun May 5 06:35:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151671920271855.73288829200567; Tue, 23 Jan 2018 06:53:22 -0800 (PST) Received: from localhost ([::1]:33618 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzwv-0002Wl-Ta for importer@patchew.org; Tue, 23 Jan 2018 09:53:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43488) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzs4-00077F-Vg for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edzs0-0002QD-Bg for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:21 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:54552) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edzrz-0002OW-WF for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:16 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MNKx7-1ekKSl2Bvl-0070aV; Tue, 23 Jan 2018 15:48:14 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 23 Jan 2018 15:48:04 +0100 Message-Id: <20180123144807.5618-11-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180123144807.5618-1-laurent@vivier.eu> References: <20180123144807.5618-1-laurent@vivier.eu> X-Provags-ID: V03:K0:kvTfaTvbP8FUPiAVCu8fD2pCOXpl2xpP4mDyqNki/pziHFCjQj2 FRzB9vAxIjc2I7M9lk7eLuHFW9xwSm2OviTFDrqfCtMhr+mJz01lD+QE7+wLtIVWIyJATOS Zkm1Y+KzHPChyCVLQ/TojAucPMfNkE548mQ6di4OmpBWLo+sHWKgrAobUweisk0bHWNEEEz q2Zmkd1xTGxy9hbGlA3xg== X-UI-Out-Filterresults: notjunk:1;V01:K0:0JgM1rN7IWI=:Dt3MDZujlSi2RmhnqXGGsz u45zI15+uvIoWSQkknZvaIjxkT95TOg3+eqZrjhkIH51E+d97M5zapvbsH1E/7X+MKuEdXYZO Wa7gOf/gJFTlxkDlDS7GhXWAe2L+Nc69JZElpTZrihSArGE9Phh6HaW3fk2IgAHnuXC4mp3w7 w8D+ZZtaP+i3CSE4sKggpb72/Eebtkw8OeITehWmf82CRJDjAmabEwvv08OlMeOubgP2bauMj Mbt9PV/mybCF2L7COqN9Z9Z+0nVH626fzUNI/TsRRtjNzoXqQpVFRYZpCIxHhVMxf8775rgIk vnmfB7PdlbNbuAjipV2s2Kzr1vKRsYwSpLCw60EyVj1r3Z0aEvJHYcx3WaMJRq6QfqRulALRk 2rUZTQnaAPnWuu+f+pE8oCgCxhNcSsmqI466lPfZsZywcX2VqbM5qq6NTppcQgzs4utDzV8Yh SwD6CHxI9i9Q8qSlgw7aUE47rh7P9crEqPpyTYX+awN/MYclUQ6m7uqjCWgI2p0g9gVdiqaZZ Ifob+1IZ8IiahV/Nub+J8OKjVOxZ4uBm8yctGYlnLU0bz4znnVr6a2fukdAXcCJCSmEuzg+As 90EJpwjLqqJL8Oz3VrZWqw+liV97eezhvni2Ta9HeRc4iXT4cZ6O3RszohLTgJn/yRDa2XneV dGHqzN9B79F9BFCe06urcXoeGQhalTW63CeWSBY5YBABIu9HAwngLdHcLvRBhK2nkJEYdY/qU is8LIsDtIHl2bnwWx9BbIbbB9nc7yK4f1glngA== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.24 Subject: [Qemu-devel] [PULL 10/13] linux-user: remove nmi.c and fw-path-provider.c 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: Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" linux-user binaries don't need firmware and NMI, so don't add them in this case, move QDEV firmware functions to qdev-fw.c Signed-off-by: Laurent Vivier Acked-by: Paolo Bonzini Message-Id: <20171103193802.11876-1-laurent@vivier.eu> --- hw/core/Makefile.objs | 5 +-- hw/core/qdev-fw.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ hw/core/qdev.c | 77 ----------------------------------------- 3 files changed, 99 insertions(+), 79 deletions(-) create mode 100644 hw/core/qdev-fw.c diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs index f8d7a4aaed..1240728c87 100644 --- a/hw/core/Makefile.objs +++ b/hw/core/Makefile.objs @@ -1,11 +1,12 @@ # core qdev-related obj files, also used by *-user: common-obj-y +=3D qdev.o qdev-properties.o common-obj-y +=3D bus.o reset.o -common-obj-y +=3D fw-path-provider.o +common-obj-$(CONFIG_SOFTMMU) +=3D qdev-fw.o +common-obj-$(CONFIG_SOFTMMU) +=3D fw-path-provider.o # irq.o needed for qdev GPIO handling: common-obj-y +=3D irq.o common-obj-y +=3D hotplug.o -common-obj-y +=3D nmi.o +common-obj-$(CONFIG_SOFTMMU) +=3D nmi.o =20 common-obj-$(CONFIG_EMPTY_SLOT) +=3D empty_slot.o common-obj-$(CONFIG_XILINX_AXI) +=3D stream.o diff --git a/hw/core/qdev-fw.c b/hw/core/qdev-fw.c new file mode 100644 index 0000000000..aa35e9d0ac --- /dev/null +++ b/hw/core/qdev-fw.c @@ -0,0 +1,96 @@ +/* + * qdev fw helpers + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "hw/qdev.h" +#include "hw/fw-path-provider.h" + +const char *qdev_fw_name(DeviceState *dev) +{ + DeviceClass *dc =3D DEVICE_GET_CLASS(dev); + + if (dc->fw_name) { + return dc->fw_name; + } + + return object_get_typename(OBJECT(dev)); +} + +static char *bus_get_fw_dev_path(BusState *bus, DeviceState *dev) +{ + BusClass *bc =3D BUS_GET_CLASS(bus); + + if (bc->get_fw_dev_path) { + return bc->get_fw_dev_path(dev); + } + + return NULL; +} + +static char *qdev_get_fw_dev_path_from_handler(BusState *bus, DeviceState = *dev) +{ + Object *obj =3D OBJECT(dev); + char *d =3D NULL; + + while (!d && obj->parent) { + obj =3D obj->parent; + d =3D fw_path_provider_try_get_dev_path(obj, bus, dev); + } + return d; +} + +char *qdev_get_own_fw_dev_path_from_handler(BusState *bus, DeviceState *de= v) +{ + Object *obj =3D OBJECT(dev); + + return fw_path_provider_try_get_dev_path(obj, bus, dev); +} + +static int qdev_get_fw_dev_path_helper(DeviceState *dev, char *p, int size) +{ + int l =3D 0; + + if (dev && dev->parent_bus) { + char *d; + l =3D qdev_get_fw_dev_path_helper(dev->parent_bus->parent, p, size= ); + d =3D qdev_get_fw_dev_path_from_handler(dev->parent_bus, dev); + if (!d) { + d =3D bus_get_fw_dev_path(dev->parent_bus, dev); + } + if (d) { + l +=3D snprintf(p + l, size - l, "%s", d); + g_free(d); + } else { + return l; + } + } + l +=3D snprintf(p + l , size - l, "/"); + + return l; +} + +char *qdev_get_fw_dev_path(DeviceState *dev) +{ + char path[128]; + int l; + + l =3D qdev_get_fw_dev_path_helper(dev, path, 128); + + path[l - 1] =3D '\0'; + + return g_strdup(path); +} diff --git a/hw/core/qdev.c b/hw/core/qdev.c index f739753e3a..2456035d1a 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -27,7 +27,6 @@ =20 #include "qemu/osdep.h" #include "hw/qdev.h" -#include "hw/fw-path-provider.h" #include "sysemu/sysemu.h" #include "qapi/qmp/qerror.h" #include "qapi/visitor.h" @@ -48,17 +47,6 @@ const VMStateDescription *qdev_get_vmsd(DeviceState *dev) return dc->vmsd; } =20 -const char *qdev_fw_name(DeviceState *dev) -{ - DeviceClass *dc =3D DEVICE_GET_CLASS(dev); - - if (dc->fw_name) { - return dc->fw_name; - } - - return object_get_typename(OBJECT(dev)); -} - static void bus_remove_child(BusState *bus, DeviceState *child) { BusChild *kid; @@ -631,71 +619,6 @@ DeviceState *qdev_find_recursive(BusState *bus, const = char *id) return NULL; } =20 -static char *bus_get_fw_dev_path(BusState *bus, DeviceState *dev) -{ - BusClass *bc =3D BUS_GET_CLASS(bus); - - if (bc->get_fw_dev_path) { - return bc->get_fw_dev_path(dev); - } - - return NULL; -} - -static char *qdev_get_fw_dev_path_from_handler(BusState *bus, DeviceState = *dev) -{ - Object *obj =3D OBJECT(dev); - char *d =3D NULL; - - while (!d && obj->parent) { - obj =3D obj->parent; - d =3D fw_path_provider_try_get_dev_path(obj, bus, dev); - } - return d; -} - -char *qdev_get_own_fw_dev_path_from_handler(BusState *bus, DeviceState *de= v) -{ - Object *obj =3D OBJECT(dev); - - return fw_path_provider_try_get_dev_path(obj, bus, dev); -} - -static int qdev_get_fw_dev_path_helper(DeviceState *dev, char *p, int size) -{ - int l =3D 0; - - if (dev && dev->parent_bus) { - char *d; - l =3D qdev_get_fw_dev_path_helper(dev->parent_bus->parent, p, size= ); - d =3D qdev_get_fw_dev_path_from_handler(dev->parent_bus, dev); - if (!d) { - d =3D bus_get_fw_dev_path(dev->parent_bus, dev); - } - if (d) { - l +=3D snprintf(p + l, size - l, "%s", d); - g_free(d); - } else { - return l; - } - } - l +=3D snprintf(p + l , size - l, "/"); - - return l; -} - -char* qdev_get_fw_dev_path(DeviceState *dev) -{ - char path[128]; - int l; - - l =3D qdev_get_fw_dev_path_helper(dev, path, 128); - - path[l-1] =3D '\0'; - - return g_strdup(path); -} - char *qdev_get_dev_path(DeviceState *dev) { BusClass *bc; --=20 2.14.3 From nobody Sun May 5 06:35:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516719535625799.4265822476295; Tue, 23 Jan 2018 06:58:55 -0800 (PST) Received: from localhost ([::1]:33735 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ee02I-0007Z1-QM for importer@patchew.org; Tue, 23 Jan 2018 09:58:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43507) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzs5-00077y-KJ for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edzs1-0002RE-8W for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:21 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:60970) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edzs0-0002Pu-Te for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:17 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MYvnH-1eH9Ya03pD-00VeDd; Tue, 23 Jan 2018 15:48:15 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 23 Jan 2018 15:48:05 +0100 Message-Id: <20180123144807.5618-12-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180123144807.5618-1-laurent@vivier.eu> References: <20180123144807.5618-1-laurent@vivier.eu> X-Provags-ID: V03:K0:hMFxyN8c5zru5LIll7eVGuZ/RbAZWps8KUZ0gLDws2KgdsFccJ6 4tl7ZI2tZ+hlyiPJTC7Tt8Xrajlg2X6xzzJxc/M1I0iWSS22ogC9/VIimpDQeMirg9qHUEs WunMIH9aCJbygG6qtuE55xtOTLfLEeD7gYq+swkqGAqWb1hvTXIXJfj4axvJF89CRHqUkHO J0v9ReNWPRWH5YPRov9gQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:gHevY1lKvUQ=:tyZIFGyKsV7IAeNdBb2+N9 Fo5vgRnOoNClKypIGgEV0Vtx0KmUYwSSoG3z1yk+5T3DUMqABHBqEMaG4aPzSvnvw85MLUo4r 6PPd002MrC63GibfmAUhopGVH0DEyYsXCtHbMXi+eWyRmqpi2Q0tqNqIGRjYDTbD50zix/47y Wo/s/XLu9+b3B2xJ/ev5av/X8yMEhgEbRTI6LwrfUuFmfC2z5YSD0yQrncTcbcczv4x1OdZPW p1wOS2LgTbmlvLCdmyPI/i17y/mu2ElRYcXFck9vX6xINw9s4O6FEMPE6DLaXgWPM97hOWSxT VkKdVmJJeSxh+FsyjeFQYGOr35CnDJSVigUX+j/J5VxCOca3TkKeu9zSM2wVZkChs0gXs/0lw l5hocaUtsHP2zZcRe8mVUCd7rAEi0v5AqKJMUQsa1aUAEDbRpREfWUNW3L0xp00CwQFhH9T2E 9ID3jCNpXtm+7MheWWNFxlrBCe0HMigIeIBynaydm5xoTtP4QzgRXkvU4os+Y6qcZ/b5xEiGH 0qnHbkUrn/xlzFQs/XzaXoUB4N2BWIGeqPN30ZTKcV9zrDPeNPPEgHw0w0TXoTJFhsI95zR9H PXTpT+cHGosqfzpzdWr9fIK5cZdcPUr8KJzxNAoh2a434tSh5Z81K7rGqx1sMlRX1nnZyKhfw DseamHeXhJsN68Qa7hQi3HWd4LOfdqANqFN76qhy+8pBHZ5A54KwMOxkNmjgY0sIvdaHgvxcX +PPWeUdwk5hLpsZeEXXDrWFwrb/QVJyWGuNIMg== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.75 Subject: [Qemu-devel] [PULL 11/13] linux-user: Propagate siginfo_t through to handle_cpu_signal() 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: Peter Maydell , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Maydell Currently all the architecture/OS specific cpu_signal_handler() functions call handle_cpu_signal() without passing it the siginfo_t. We're going to want that so we can look at the si_code to determine whether this is a SEGV_ACCERR access violation or some other kind of fault, so change the functions to pass through the pointer to the siginfo_t rather than just the si_addr value. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-Id: <1511879725-9576-2-git-send-email-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier --- accel/tcg/user-exec.c | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index f42285ea1c..e8f26ff0cb 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -57,12 +57,13 @@ static void cpu_exit_tb_from_sighandler(CPUState *cpu, = sigset_t *old_set) the effective address of the memory exception. 'is_write' is 1 if a write caused the exception and otherwise 0'. 'old_set' is the signal set which should be restored */ -static inline int handle_cpu_signal(uintptr_t pc, unsigned long address, +static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, int is_write, sigset_t *old_set) { CPUState *cpu =3D current_cpu; CPUClass *cc; int ret; + unsigned long address =3D (unsigned long)info->si_addr; =20 /* We must handle PC addresses from two different sources: * a call return address and a signal frame address. @@ -215,9 +216,8 @@ int cpu_signal_handler(int host_signum, void *pinfo, #endif pc =3D EIP_sig(uc); trapno =3D TRAP_sig(uc); - return handle_cpu_signal(pc, (unsigned long)info->si_addr, - trapno =3D=3D 0xe ? - (ERROR_sig(uc) >> 1) & 1 : 0, + return handle_cpu_signal(pc, info, + trapno =3D=3D 0xe ? (ERROR_sig(uc) >> 1) & 1 = : 0, &MASK_sig(uc)); } =20 @@ -261,9 +261,8 @@ int cpu_signal_handler(int host_signum, void *pinfo, #endif =20 pc =3D PC_sig(uc); - return handle_cpu_signal(pc, (unsigned long)info->si_addr, - TRAP_sig(uc) =3D=3D 0xe ? - (ERROR_sig(uc) >> 1) & 1 : 0, + return handle_cpu_signal(pc, info, + TRAP_sig(uc) =3D=3D 0xe ? (ERROR_sig(uc) >> 1= ) & 1 : 0, &MASK_sig(uc)); } =20 @@ -341,8 +340,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, is_write =3D 1; } #endif - return handle_cpu_signal(pc, (unsigned long)info->si_addr, - is_write, &uc->uc_sigmask); + return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask); } =20 #elif defined(__alpha__) @@ -372,8 +370,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, is_write =3D 1; } =20 - return handle_cpu_signal(pc, (unsigned long)info->si_addr, - is_write, &uc->uc_sigmask); + return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask); } #elif defined(__sparc__) =20 @@ -432,8 +429,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, break; } } - return handle_cpu_signal(pc, (unsigned long)info->si_addr, - is_write, sigmask); + return handle_cpu_signal(pc, info, is_write, sigmask); } =20 #elif defined(__arm__) @@ -466,9 +462,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, * later processor; on v5 we will always report this as a read). */ is_write =3D extract32(uc->uc_mcontext.error_code, 11, 1); - return handle_cpu_signal(pc, (unsigned long)info->si_addr, - is_write, - &uc->uc_sigmask); + return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask); } =20 #elif defined(__aarch64__) @@ -495,8 +489,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, vo= id *puc) /* Ignore bits 23 & 24, controlling indexing. */ || (insn & 0x3a400000) =3D=3D 0x28000000); /* C3.3.7,14-16= */ =20 - return handle_cpu_signal(pc, (uintptr_t)info->si_addr, - is_write, &uc->uc_sigmask); + return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask); } =20 #elif defined(__ia64) @@ -529,9 +522,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, vo= id *puc) default: break; } - return handle_cpu_signal(ip, (unsigned long)info->si_addr, - is_write, - (sigset_t *)&uc->uc_sigmask); + return handle_cpu_signal(ip, info, is_write, (sigset_t *)&uc->uc_sigma= sk); } =20 #elif defined(__s390__) @@ -583,8 +574,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, } break; } - return handle_cpu_signal(pc, (unsigned long)info->si_addr, - is_write, &uc->uc_sigmask); + return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask); } =20 #elif defined(__mips__) @@ -599,8 +589,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, =20 /* XXX: compute is_write */ is_write =3D 0; - return handle_cpu_signal(pc, (unsigned long)info->si_addr, - is_write, &uc->uc_sigmask); + return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask); } =20 #else --=20 2.14.3 From nobody Sun May 5 06:35:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516719443853101.44268912844666; Tue, 23 Jan 2018 06:57:23 -0800 (PST) Received: from localhost ([::1]:33643 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ee00p-00068t-3T for importer@patchew.org; Tue, 23 Jan 2018 09:57:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43522) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzs6-00078R-1Y for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edzs1-0002Rg-M0 for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:22 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:63310) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edzs1-0002Qa-Ba for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:17 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MfHZq-1eSNyH22ck-00OoaS; Tue, 23 Jan 2018 15:48:15 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 23 Jan 2018 15:48:06 +0100 Message-Id: <20180123144807.5618-13-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180123144807.5618-1-laurent@vivier.eu> References: <20180123144807.5618-1-laurent@vivier.eu> X-Provags-ID: V03:K0:t7jvgJY2Pzd3rNu8ICtaAYMPJwotmFxCJyksQJOUjRo9WtHi1/Z 4adLVJ9J1ysZfITQaa8BaZ5fhpDdSsoCMcuikzFZI5sZMo9+lnEfEInLHnE9en4uSIiniXS b5g5wCxZdwtsTstuVD2crQV89/kSMb6ZnV80SpII/1+jZcCVhFx+ZcDHe/AvQOTFA+hbwjo TBj4iTSy5T+XO/jNsZvrw== X-UI-Out-Filterresults: notjunk:1;V01:K0:NydL/eYLj2E=:ydFoFm3lt6wpMMpn/FWtYV xKBbnrViYhdlOZvpEWPnjObL440+G7S0r8wHH7JV34KdDVtgySwAVc0X13tlWxxk4cvVyWsD/ en7kX14H2N+R2kueQb/UNvbf/nwukmIB+JK53JimVeymG4gb6z2E8DXKpABXrmnojvatWqt3S eS4czXSQjRMoDH41r1dFsXe24cM+pA4gR9H9kaYxMIgH97elZ8hBJo7D+0q7em+8oYMgZuRZJ aV6Omm+ZKzpzGOlSLVK9yEuf9h9axXFIDjgNBvKX3bU/kTerHZgvGAkZ79nM8qsAjn2H+Wk0/ gFTe++kIvzOCQFsSftNKSeWM5oNHbVO5CPSZTC6yRWDlPCRVkt2XQDryMcECka4bKzsX8A8Vc HfQA4paMXjLiIBz2Afvvh8ln1q3CT5DtGHDUNgt0jBouQ7aRtiVMiqQUzPCR7wn7JY/NJ019A VgnSgo5e0eonZ5DVkkKhh4SCS60MkRG79dll/lleXUE/HYDmqKhmLXqotBgZFT0sJQlZC6wj/ 46wMUFwPB5/dmfwUwPnXxNORjhm7zA3pDu6rak+lV8oOB75ndb0VVP77+2xbnur2703HBsJmo 52uq2SUBG3d06B1v4ScFXKrdLhFPbiWH8/VtXWfUVo18sJg/j4EO0QyUx7y+mAkqydp7CDIL6 m0J3qCqXDnpSPq21Ar3Ebfp1yQVFGqXfuVX6IzCbb7ianR/IVlgvVCpVY7kpVuBiA32p76Nnl auE8I1pZzIeHUR0GlEcoM0nqLbVW2d/qNniaUQ== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.10 Subject: [Qemu-devel] [PULL 12/13] page_unprotect(): handle calls to pages that are PAGE_WRITE 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: Peter Maydell , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Maydell If multiple guest threads in user-mode emulation write to a page which QEMU has marked read-only because of cached TCG translations, the threads can race in page_unprotect: * threads A & B both try to do a write to a page with code in it at the same time (ie which we've made non-writeable, so SEGV) * they race into the signal handler with this faulting address * thread A happens to get to page_unprotect() first and takes the mmap lock, so thread B sits waiting for it to be done * A then finds the page, marks it PAGE_WRITE and mprotect()s it writable * A can then continue OK (returns from signal handler to retry the memory access) * ...but when B gets the mmap lock it finds that the page is already PAGE_WRITE, and so it exits page_unprotect() via the "not due to protected translation" code path, and wrongly delivers the signal to the guest rather than just retrying the access In particular, this meant that trying to run 'javac' in user-mode emulation would fail with a spurious guest SIGSEGV. Handle this by making page_unprotect() assume that a call for a page which is already PAGE_WRITE is due to a race of this sort and return a "fault handled" indication. Since this would cause an infinite loop if we ever called page_unprotect() for some other kind of fault than "write failed due to bad access permissions", tighten the condition in handle_cpu_signal() to check the signal number and si_code, and add a comment so that if somebody does ever find themselves debugging an infinite loop of faults they have some clue about why. (The trick for identifying the correct setting for current_tb_invalidated for thread B (needed to handle the precise-SMC case) is due to Richard Henderson. Paolo Bonzini suggested just relying on si_code rather than trying anything more complicated.) Signed-off-by: Peter Maydell Message-Id: <1511879725-9576-3-git-send-email-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier --- accel/tcg/translate-all.c | 50 +++++++++++++++++++++++++++++--------------= ---- accel/tcg/user-exec.c | 13 +++++++++++- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 7736257085..67795cd78c 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -2181,29 +2181,41 @@ int page_unprotect(target_ulong address, uintptr_t = pc) =20 /* if the page was really writable, then we change its protection back to writable */ - if ((p->flags & PAGE_WRITE_ORG) && !(p->flags & PAGE_WRITE)) { - host_start =3D address & qemu_host_page_mask; - host_end =3D host_start + qemu_host_page_size; - - prot =3D 0; + if (p->flags & PAGE_WRITE_ORG) { current_tb_invalidated =3D false; - for (addr =3D host_start ; addr < host_end ; addr +=3D TARGET_PAGE= _SIZE) { - p =3D page_find(addr >> TARGET_PAGE_BITS); - p->flags |=3D PAGE_WRITE; - prot |=3D p->flags; - - /* and since the content will be modified, we must invalidate - the corresponding translated code. */ - current_tb_invalidated |=3D tb_invalidate_phys_page(addr, pc); -#ifdef CONFIG_USER_ONLY - if (DEBUG_TB_CHECK_GATE) { - tb_invalidate_check(addr); + if (p->flags & PAGE_WRITE) { + /* If the page is actually marked WRITE then assume this is be= cause + * this thread raced with another one which got here first and + * set the page to PAGE_WRITE and did the TB invalidate for us. + */ +#ifdef TARGET_HAS_PRECISE_SMC + TranslationBlock *current_tb =3D tb_find_pc(pc); + if (current_tb) { + current_tb_invalidated =3D tb_cflags(current_tb) & CF_INVA= LID; } #endif + } else { + host_start =3D address & qemu_host_page_mask; + host_end =3D host_start + qemu_host_page_size; + + prot =3D 0; + for (addr =3D host_start; addr < host_end; addr +=3D TARGET_PA= GE_SIZE) { + p =3D page_find(addr >> TARGET_PAGE_BITS); + p->flags |=3D PAGE_WRITE; + prot |=3D p->flags; + + /* and since the content will be modified, we must invalid= ate + the corresponding translated code. */ + current_tb_invalidated |=3D tb_invalidate_phys_page(addr, = pc); +#ifdef CONFIG_USER_ONLY + if (DEBUG_TB_CHECK_GATE) { + tb_invalidate_check(addr); + } +#endif + } + mprotect((void *)g2h(host_start), qemu_host_page_size, + prot & PAGE_BITS); } - mprotect((void *)g2h(host_start), qemu_host_page_size, - prot & PAGE_BITS); - mmap_unlock(); /* If current TB was invalidated return to main loop */ return current_tb_invalidated ? 2 : 1; diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index e8f26ff0cb..c973752562 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -104,7 +104,18 @@ static inline int handle_cpu_signal(uintptr_t pc, sigi= nfo_t *info, pc, address, is_write, *(unsigned long *)old_set); #endif /* XXX: locking issue */ - if (is_write && h2g_valid(address)) { + /* Note that it is important that we don't call page_unprotect() unless + * this is really a "write to nonwriteable page" fault, because + * page_unprotect() assumes that if it is called for an access to + * a page that's writeable this means we had two threads racing and + * another thread got there first and already made the page writeable; + * so we will retry the access. If we were to call page_unprotect() + * for some other kind of fault that should really be passed to the + * guest, we'd end up in an infinite loop of retrying the faulting + * access. + */ + if (is_write && info->si_signo =3D=3D SIGSEGV && info->si_code =3D=3D = SEGV_ACCERR && + h2g_valid(address)) { switch (page_unprotect(h2g(address), pc)) { case 0: /* Fault not caused by a page marked unwritable to protect --=20 2.14.3 From nobody Sun May 5 06:35:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516719380193142.88838038191034; Tue, 23 Jan 2018 06:56:20 -0800 (PST) Received: from localhost ([::1]:33641 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzzd-000579-S3 for importer@patchew.org; Tue, 23 Jan 2018 09:56:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43513) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edzs5-00078E-RD for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edzs4-0002U9-Fe for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:21 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:56431) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edzs4-0002T6-5w for qemu-devel@nongnu.org; Tue, 23 Jan 2018 09:48:20 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0LpfUc-1fG6NC3aXW-00fVSK; Tue, 23 Jan 2018 15:48:17 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 23 Jan 2018 15:48:07 +0100 Message-Id: <20180123144807.5618-14-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180123144807.5618-1-laurent@vivier.eu> References: <20180123144807.5618-1-laurent@vivier.eu> X-Provags-ID: V03:K0:D04C+WVRnp1C5przisqpiEdauiRHTsQH1AcaAXpmbgalFj5/Hr2 LYYRx9tgklgorvoZO/0DXZ0ae9B/ezJfswDiU5g15Zq5wpX6WpZK+UsMPn36lSv4yNxTfSe Grta+aBXI+Ll6SXVGVx7A5W6xtGGyucOenXoEpRV4QNZTGi6dk8HQ8ny8+X/5csnS5vrgeg X5UrJZwF9fajgvWj2OI7Q== X-UI-Out-Filterresults: notjunk:1;V01:K0:ReAAW9+zbiQ=:QIIgfYsWsX6y2HZuhyU3nN oPulBWC+piXo/EGCBIq+V/nFtX1mNWDX0tegmGn3y4XyDvnw0gb/OkLFpWfe9bogOsLoHMdqX B8skDyn1XS/p92l1LCa6XJ/cuibhVO+hL9vI0fWclytQPAfxClkDKa9YXTGioM/V+6iKNaWrs 2bXNJVcDJm7VTPrW7aUckejjIzub7/5+0TcM3FljnAnDS1dw5htlBCk3wpwIyqt3Uoa5j30ru OqHywpyP/Mpg4XOaYpycCUKcjv+cp+MIT+vl05UIBx/9TAPgs8rxEHEP7Msrt62qOPV95ZRkV wCDP0XPEoBtfIO2Z+Dj+8ktQWt7QLSk6Rq3J9L8OZbfhphefqyIY0TMHytBIPz3mDrAy4C/lj nqAzsDwk3dlp15j61qWzkHy7pV42uRYIfaegw4f0x3XNtTr/OebrGi94w2gzts06++mL/tL++ haGyuOQiyNuv5Qoi00d32f4bmozdfgFv2p5QnrgXFf8RzImA8du0twBMYNqoTj30Puv49WiHQ Ym1AKiPenILetVotLTqRu88KWJTje2/mr4Z1mWTALoDoaXhfdlZY/oLIru3SSkphnHBLuahsb mWHEG8rDDwPEwQzaeiAHgkJZ3D5Zgh5lZVRzDBOjXRalCyrsTVo+YFUOCJptnxiJZEtcHBP8+ NsptOC9QEqPhQq4CnGWGJNfw11vYNzLlzcN36r/JNvcvbiW7z8me/zhHP4igA3nDtusWlEOU1 0Fa6OTHkAHjuZCbxizstDDKbsLlvvyGa7FnA5A== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.75 Subject: [Qemu-devel] [PULL 13/13] linux-user: implement renameat2 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: Andreas Schwab , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Andreas Schwab This is needed for new architectures like RISC-V which do not provide any other rename-like syscall. Signed-off-by: Andreas Schwab Reviewed-by: Laurent Vivier Message-Id: Signed-off-by: Laurent Vivier Reviewed-by: Palmer Dabbelt --- linux-user/syscall.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 104408c050..74378947f0 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -600,6 +600,24 @@ static int sys_utimensat(int dirfd, const char *pathna= me, #endif #endif /* TARGET_NR_utimensat */ =20 +#ifdef TARGET_NR_renameat2 +#if defined(__NR_renameat2) +#define __NR_sys_renameat2 __NR_renameat2 +_syscall5(int, sys_renameat2, int, oldfd, const char *, old, int, newfd, + const char *, new, unsigned int, flags) +#else +static int sys_renameat2(int oldfd, const char *old, + int newfd, const char *new, int flags) +{ + if (flags =3D=3D 0) { + return renameat(oldfd, old, newfd, new); + } + errno =3D ENOSYS; + return -1; +} +#endif +#endif /* TARGET_NR_renameat2 */ + #ifdef CONFIG_INOTIFY #include =20 @@ -8426,6 +8444,22 @@ abi_long do_syscall(void *cpu_env, int num, abi_long= arg1, } break; #endif +#if defined(TARGET_NR_renameat2) + case TARGET_NR_renameat2: + { + void *p2; + p =3D lock_user_string(arg2); + p2 =3D lock_user_string(arg4); + if (!p || !p2) { + ret =3D -TARGET_EFAULT; + } else { + ret =3D get_errno(sys_renameat2(arg1, p, arg3, p2, arg5)); + } + unlock_user(p2, arg4, 0); + unlock_user(p, arg2, 0); + } + break; +#endif #ifdef TARGET_NR_mkdir case TARGET_NR_mkdir: if (!(p =3D lock_user_string(arg1))) --=20 2.14.3