From nobody Sat May 18 12:05:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1687379887; cv=none; d=zohomail.com; s=zohoarc; b=kGKXa/w8mNDuFGomtey49DnJjFk9f1Ap7etaAuuoy6tqE/d3shzN1igDETCd3RYL1p3eiTFHrxbfZ6kIITniE5bfcpOLQrx4jxFFKkt3yzD1JPzuZVPmopiswdAC+7/liWodnGZ29hrHizAdkHsMKbf7gAMfDmM2y70eO6OWYSs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687379887; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0ZY8vwmLmzLOcX/i4g/GVyWuQ3vKveULuVZbaYah6LM=; b=NB2TB7D4Yd+pZnkn8dR+nyWgZ4p8ecWtBaW9fLd5F+p2Uk4R3m/PhMVqfL1ksz8NJ47tjECxwLQqtXXnRhSB/ndiC0WNtPpp7tBD0ggDEIYvfqKNetPIGoquJLJBX8RBxJ+qmxKm8pG1T1eojPwlfli3CsueT5RYU+0ooCUpC6s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1687379887724862.803300971729; Wed, 21 Jun 2023 13:38:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qC4ZO-0006tf-Bg; Wed, 21 Jun 2023 16:36:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qC4ZM-0006sF-QJ; Wed, 21 Jun 2023 16:36:48 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qC4ZL-0008B7-1R; Wed, 21 Jun 2023 16:36:48 -0400 Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35LKYBBq008265; Wed, 21 Jun 2023 20:36:44 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rc7u98swg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:44 +0000 Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35LKZpp5016957; Wed, 21 Jun 2023 20:36:43 GMT Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rc7u98svf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:43 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35L9XXCA020019; Wed, 21 Jun 2023 20:36:41 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma03fra.de.ibm.com (PPS) with ESMTPS id 3r94f5aasu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:41 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35LKad7n43778462 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Jun 2023 20:36:39 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0BA9520043; Wed, 21 Jun 2023 20:36:39 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8690320040; Wed, 21 Jun 2023 20:36:38 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.179.1.208]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 21 Jun 2023 20:36:38 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=0ZY8vwmLmzLOcX/i4g/GVyWuQ3vKveULuVZbaYah6LM=; b=CE5MhzPsfTAe+VrJmJllk5B+h0kfc+AfCy3C1dxQKzOHcES20th9uCS2KM94VY+JeCn4 Jk8/hmxlNzkwLUyAT4Eix1qnKsAC9gxpJ/tkUpWa4VGhrclsJ/PUFXHWs+D1wsKbSje0 EGzGhiaq9gL5jGq0JIDW2zxdCZFpEBEYcgdQCmtv3LLQr5czMcXaSIUF7xhpCEYPg/bc asxrJywPhr2ErA3uF4HW5Zl5vjCYk9JBCfYssLMaXAH6et+eqbv0flyQyCK9dazWkiHK Jc8K721y9ABbSKd/Kntb7z7r3efN5b3234HwNGqJ4w6yYwMJ134SH5LP6s6sZwdQJH0b QQ== From: Ilya Leoshkevich To: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Laurent Vivier , Peter Maydell , Richard Henderson , David Hildenbrand Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-s390x@nongnu.org, Ilya Leoshkevich Subject: [PATCH v4 1/8] linux-user: Expose do_guest_openat() and do_guest_readlink() Date: Wed, 21 Jun 2023 22:36:20 +0200 Message-Id: <20230621203627.1808446-2-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230621203627.1808446-1-iii@linux.ibm.com> References: <20230621203627.1808446-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 5wwq5GsQgq0d-PeOp3VgETPDji-NKcQf X-Proofpoint-ORIG-GUID: Zznn1hGS_qkxvr3L-giXXSRTelF_OFPN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-21_12,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 bulkscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1015 phishscore=0 suspectscore=0 mlxscore=0 priorityscore=1501 adultscore=0 impostorscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306210172 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1687379888164100001 These functions will be required by the GDB stub in order to provide the guest view of /proc to GDB. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Ilya Leoshkevich Reviewed-by: Richard Henderson --- linux-user/qemu.h | 3 +++ linux-user/syscall.c | 54 ++++++++++++++++++++++++++++---------------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 92f9f5af41..a5830ec239 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -165,6 +165,9 @@ typedef struct TaskState { } TaskState; =20 abi_long do_brk(abi_ulong new_brk); +int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, + int flags, mode_t mode); +ssize_t do_guest_readlink(const char *pathname, char *buf, size_t bufsiz); =20 /* user access */ =20 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f2cb101d83..fa83737192 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8448,7 +8448,8 @@ static int open_hardware(CPUArchState *cpu_env, int f= d) } #endif =20 -static int do_openat(CPUArchState *cpu_env, int dirfd, const char *pathnam= e, int flags, mode_t mode) +int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, + int flags, mode_t mode) { struct fake_open { const char *filename; @@ -8520,6 +8521,36 @@ static int do_openat(CPUArchState *cpu_env, int dirf= d, const char *pathname, int return safe_openat(dirfd, path(pathname), flags, mode); } =20 +ssize_t do_guest_readlink(const char *pathname, char *buf, size_t bufsiz) +{ + ssize_t ret; + + if (!pathname || !buf) { + errno =3D EFAULT; + return -1; + } + + if (!bufsiz) { + /* Short circuit this for the magic exe check. */ + errno =3D EINVAL; + return -1; + } + + if (is_proc_myself((const char *)pathname, "exe")) { + /* + * Don't worry about sign mismatch as earlier mapping + * logic would have thrown a bad address error. + */ + ret =3D MIN(strlen(exec_path), bufsiz); + /* We cannot NUL terminate the string. */ + memcpy(buf, exec_path, ret); + } else { + ret =3D readlink(path(pathname), buf, bufsiz); + } + + return ret; +} + static int do_execveat(CPUArchState *cpu_env, int dirfd, abi_long pathname, abi_long guest_argp, abi_long guest_envp, int flags) @@ -8994,7 +9025,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, in= t num, abi_long arg1, case TARGET_NR_open: if (!(p =3D lock_user_string(arg1))) return -TARGET_EFAULT; - ret =3D get_errno(do_openat(cpu_env, AT_FDCWD, p, + ret =3D get_errno(do_guest_openat(cpu_env, AT_FDCWD, p, target_to_host_bitmask(arg2, fcntl_flags= _tbl), arg3)); fd_trans_unregister(ret); @@ -9004,7 +9035,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, in= t num, abi_long arg1, case TARGET_NR_openat: if (!(p =3D lock_user_string(arg2))) return -TARGET_EFAULT; - ret =3D get_errno(do_openat(cpu_env, arg1, p, + ret =3D get_errno(do_guest_openat(cpu_env, arg1, p, target_to_host_bitmask(arg3, fcntl_flags= _tbl), arg4)); fd_trans_unregister(ret); @@ -10229,22 +10260,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env,= int num, abi_long arg1, void *p2; p =3D lock_user_string(arg1); p2 =3D lock_user(VERIFY_WRITE, arg2, arg3, 0); - if (!p || !p2) { - ret =3D -TARGET_EFAULT; - } else if (!arg3) { - /* Short circuit this for the magic exe check. */ - ret =3D -TARGET_EINVAL; - } else if (is_proc_myself((const char *)p, "exe")) { - /* - * Don't worry about sign mismatch as earlier mapping - * logic would have thrown a bad address error. - */ - ret =3D MIN(strlen(exec_path), arg3); - /* We cannot NUL terminate the string. */ - memcpy(p2, exec_path, ret); - } else { - ret =3D get_errno(readlink(path(p), p2, arg3)); - } + ret =3D get_errno(do_guest_readlink(p, p2, arg3)); unlock_user(p2, arg2, ret); unlock_user(p, arg1, 0); } --=20 2.40.1 From nobody Sat May 18 12:05:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1687379848; cv=none; d=zohomail.com; s=zohoarc; b=aKPs0efyxbTptnLDKST9YQqARN+7ZACXqBu+clsiYogs3POLg4F5Q7xTmUc9pdtIcDLNfSqfy4v1qo1z8vAmr2z6++wOS421Blj08dIYBE0moc2mlPT92IhKTayDAoWPvGV/43wnP1h5Y3Oa0qHPcOmsGKU+DKPHAmuppvJjEl4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687379848; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=G84DodHSsx2+R+Uh0++Gk9hlTeuuUerf2U/DEhm8Zo4=; b=cpla/voHO4wbOCl0uLQLhEEZQ5r93fFTz3TPGg9cryxS4phyMlzXNE5ehxPMpIPsB5CAbxn54YC4NoxWXBauEcgoQhOJMrXfDaNZIVBCeBg9e/0ggFpjFmmDrnfOZ+8gzYzzQDYQuaIxWwY3rEXcPW+HFU3N+dnPCk+3a6zCtzc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1687379848460505.4408099116953; Wed, 21 Jun 2023 13:37:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qC4ZS-0006wU-7P; Wed, 21 Jun 2023 16:36:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qC4ZP-0006us-Rw; Wed, 21 Jun 2023 16:36:51 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qC4ZO-0008CA-5Q; Wed, 21 Jun 2023 16:36:51 -0400 Received: from pps.filterd (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35LKEDLL021604; Wed, 21 Jun 2023 20:36:47 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rc82g8ey4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:47 +0000 Received: from m0353727.ppops.net (m0353727.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35LKG2g4026347; Wed, 21 Jun 2023 20:36:46 GMT Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rc82g8ex9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:46 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35L97hCO017775; Wed, 21 Jun 2023 20:36:44 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma04fra.de.ibm.com (PPS) with ESMTPS id 3r94f5aa8u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:44 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35LKafqB28771026 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Jun 2023 20:36:41 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 91ECE20043; Wed, 21 Jun 2023 20:36:41 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 13EFC20040; Wed, 21 Jun 2023 20:36:41 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.179.1.208]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 21 Jun 2023 20:36:40 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=G84DodHSsx2+R+Uh0++Gk9hlTeuuUerf2U/DEhm8Zo4=; b=Cx/8I7lDkQQIxY9fnDxISARjoJ9ivzxcaXssnlBUHRvu6h+1vZbl8FjRwISEW0wKZXb4 Co0FLjb0oGoJuvUYNdFvtoejWLIdW0is4GmGKQAZ12Sn+stQZ5C/b41Zjk/6Uv6gcvfO rhu3zdbaDkJp9E8RnKdZw7OEVBMBQ7yJsFX59wDh4MrTDewLj1wAMqOxtJGQ5sbrf9kh BNBa7mFRB6JbVg3zAkcE/GLFva6Izt/e4aySGitUYUDhx4NcjKbNPFSCHOC7K1oGwGdS 6bX4iy1p/TU1sEeY9JBRig6X+dWilE/vIbATncUbhKxQvMY69z+De9AmX8LyeKQ3r8nb XQ== From: Ilya Leoshkevich To: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Laurent Vivier , Peter Maydell , Richard Henderson , David Hildenbrand Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-s390x@nongnu.org, Ilya Leoshkevich Subject: [PATCH v4 2/8] linux-user: Add "safe" parameter to do_guest_openat() Date: Wed, 21 Jun 2023 22:36:21 +0200 Message-Id: <20230621203627.1808446-3-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230621203627.1808446-1-iii@linux.ibm.com> References: <20230621203627.1808446-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: AnmY8nIrlpyf3LdtNm26o4fsnvza8g7L X-Proofpoint-GUID: z2hYohVPCc6hFoa50qdsB8JZ59pYEEFI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-21_12,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 phishscore=0 clxscore=1015 adultscore=0 bulkscore=0 impostorscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306210172 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.156.1; envelope-from=iii@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1687379850564100001 Content-Type: text/plain; charset="utf-8" gdbstub cannot meaningfully handle QEMU_ERESTARTSYS, and it doesn't need to. Add a parameter to do_guest_openat() that makes it use openat() instead of safe_openat(), so that it becomes usable from gdbstub. Signed-off-by: Ilya Leoshkevich Reviewed-by: Richard Henderson --- linux-user/qemu.h | 2 +- linux-user/syscall.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index a5830ec239..9b8e0860d7 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -166,7 +166,7 @@ typedef struct TaskState { =20 abi_long do_brk(abi_ulong new_brk); int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, - int flags, mode_t mode); + int flags, mode_t mode, bool safe); ssize_t do_guest_readlink(const char *pathname, char *buf, size_t bufsiz); =20 /* user access */ diff --git a/linux-user/syscall.c b/linux-user/syscall.c index fa83737192..ecd9f5e23d 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8449,7 +8449,7 @@ static int open_hardware(CPUArchState *cpu_env, int f= d) #endif =20 int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, - int flags, mode_t mode) + int flags, mode_t mode, bool safe) { struct fake_open { const char *filename; @@ -8476,7 +8476,11 @@ int do_guest_openat(CPUArchState *cpu_env, int dirfd= , const char *pathname, }; =20 if (is_proc_myself(pathname, "exe")) { - return safe_openat(dirfd, exec_path, flags, mode); + if (safe) { + return safe_openat(dirfd, exec_path, flags, mode); + } else { + return openat(dirfd, exec_path, flags, mode); + } } =20 for (fake_open =3D fakes; fake_open->filename; fake_open++) { @@ -8518,7 +8522,11 @@ int do_guest_openat(CPUArchState *cpu_env, int dirfd= , const char *pathname, return fd; } =20 - return safe_openat(dirfd, path(pathname), flags, mode); + if (safe) { + return safe_openat(dirfd, path(pathname), flags, mode); + } else { + return openat(dirfd, path(pathname), flags, mode); + } } =20 ssize_t do_guest_readlink(const char *pathname, char *buf, size_t bufsiz) @@ -9027,7 +9035,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, in= t num, abi_long arg1, return -TARGET_EFAULT; ret =3D get_errno(do_guest_openat(cpu_env, AT_FDCWD, p, target_to_host_bitmask(arg2, fcntl_flags= _tbl), - arg3)); + arg3, true)); fd_trans_unregister(ret); unlock_user(p, arg1, 0); return ret; @@ -9037,7 +9045,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, in= t num, abi_long arg1, return -TARGET_EFAULT; ret =3D get_errno(do_guest_openat(cpu_env, arg1, p, target_to_host_bitmask(arg3, fcntl_flags= _tbl), - arg4)); + arg4, true)); fd_trans_unregister(ret); unlock_user(p, arg2, 0); return ret; --=20 2.40.1 From nobody Sat May 18 12:05:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1687379841; cv=none; d=zohomail.com; s=zohoarc; b=UW7VET5yYNVjp4A/7NwNiyte4JZQ46dmGviBQWyIt+5HxhrozprSjr/hks7c7u8iKUTYZUjaz7CJnZX5Kv9iIF9YdYUZR1WBFtSP98C5wwYhW89ewtQT6VV+OzlNEXVuvVubG2P71STmTBsyW8ZaZcSPnwprgMcsIdSyHk7sB0Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687379841; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NKnkVeDXnL9p5qjmprO1civlthCt5Eb82R3lV90MBQU=; b=mU7kDFwXxinuSxY036OGPSiQGXhRTkhvyIA/y/pTCTcmlFCBcCEaNT8p2BzCmweXmKB6GrgXx2pAXJe6glPMSN648M1kVAAr0bAGujueL1lnwc3/NzQlLRGjfTvkscvxKwqGLff58sW5L1RT9ebyIs2b4ksBULAVdTqj6Dik2c8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1687379841500339.7942768543089; Wed, 21 Jun 2023 13:37:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qC4ZT-0006xu-6L; Wed, 21 Jun 2023 16:36:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qC4ZQ-0006vX-Sa; Wed, 21 Jun 2023 16:36:52 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qC4ZP-0008Ci-2U; Wed, 21 Jun 2023 16:36:52 -0400 Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35LK9tJH016304; Wed, 21 Jun 2023 20:36:49 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rc7u98t0q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:48 +0000 Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35LKDemV031048; Wed, 21 Jun 2023 20:36:48 GMT Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rc7u98syx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:47 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35L3oNXc002196; Wed, 21 Jun 2023 20:36:46 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma03fra.de.ibm.com (PPS) with ESMTPS id 3r94f5aasv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:45 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35LKahdH30999262 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Jun 2023 20:36:43 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8B5C320040; Wed, 21 Jun 2023 20:36:43 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0EB7620043; Wed, 21 Jun 2023 20:36:43 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.179.1.208]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 21 Jun 2023 20:36:42 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=NKnkVeDXnL9p5qjmprO1civlthCt5Eb82R3lV90MBQU=; b=Z/M8mjclEmyfQgeKckGp83G8AaU4wazlL1sXPZy07mTZ6FxvJ47aDj4FRc4//GFAEZ1j WSKtIAG2k2MLvHenaO7XXKKEFVFwlKdPywrhu5/X5o7hj1QkiO9C55rbUmfF5pdV+MjV 3XkU2y/T+P6t0HAGEmlPUq/8vR8Dp4ba+fDeIbebwwPhkDDJ+onyB+R+cgSEfHdP55nJ 2NCOkRRxQ/kgyv7nFXGi1yHFAhdyP+DpFEIVI7rHFnMGahKz51k0rUWxvIyp9lwJJtMH V8QQtWbP5ZDpfwIhD7z+JXCiqi3iod3Ha/CidFLfR1HEy1T51Ir4AOCXUfJLDSzDmqr0 pw== From: Ilya Leoshkevich To: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Laurent Vivier , Peter Maydell , Richard Henderson , David Hildenbrand Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-s390x@nongnu.org, Ilya Leoshkevich Subject: [PATCH v4 3/8] linux-user: Emulate /proc/self/smaps Date: Wed, 21 Jun 2023 22:36:22 +0200 Message-Id: <20230621203627.1808446-4-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230621203627.1808446-1-iii@linux.ibm.com> References: <20230621203627.1808446-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: kK1gxCTdCrJrcv31Z92vArUK77-V1oli X-Proofpoint-ORIG-GUID: bZGMfZESkRzPWgw_XO8rpx44dPCIMIbF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-21_12,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 bulkscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1015 phishscore=0 suspectscore=0 mlxscore=0 priorityscore=1501 adultscore=0 impostorscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306210172 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1687379842693100003 Content-Type: text/plain; charset="utf-8" /proc/self/smaps is an extension of /proc/self/maps: it provides the same lines, plus additional information about each range. GDB uses /proc/self/smaps when available, which means that generate-core-file tries it first before falling back to /proc/self/maps. This, in turn, causes it to dump the host mappings, since /proc/self/smaps is not emulated and is just passed through. Fix by emulating /proc/self/smaps. Provide true values only for Size, KernelPageSize, MMUPageSize and VmFlags. Leave all other values at 0, which is a valid conservative estimate. Signed-off-by: Ilya Leoshkevich Reviewed-by: Richard Henderson --- linux-user/syscall.c | 58 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index ecd9f5e23d..08162cc966 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8042,7 +8042,36 @@ static int open_self_cmdline(CPUArchState *cpu_env, = int fd) return 0; } =20 -static int open_self_maps(CPUArchState *cpu_env, int fd) +static void show_smaps(int fd, unsigned long size) +{ + unsigned long page_size_kb =3D TARGET_PAGE_SIZE >> 10; + unsigned long size_kb =3D size >> 10; + + dprintf(fd, "Size: %lu kB\n" + "KernelPageSize: %lu kB\n" + "MMUPageSize: %lu kB\n" + "Rss: 0 kB\n" + "Pss: 0 kB\n" + "Pss_Dirty: 0 kB\n" + "Shared_Clean: 0 kB\n" + "Shared_Dirty: 0 kB\n" + "Private_Clean: 0 kB\n" + "Private_Dirty: 0 kB\n" + "Referenced: 0 kB\n" + "Anonymous: 0 kB\n" + "LazyFree: 0 kB\n" + "AnonHugePages: 0 kB\n" + "ShmemPmdMapped: 0 kB\n" + "FilePmdMapped: 0 kB\n" + "Shared_Hugetlb: 0 kB\n" + "Private_Hugetlb: 0 kB\n" + "Swap: 0 kB\n" + "SwapPss: 0 kB\n" + "Locked: 0 kB\n" + "THPeligible: 0\n", size_kb, page_size_kb, page_size_kb= ); +} + +static int open_self_maps_1(CPUArchState *cpu_env, int fd, bool smaps) { CPUState *cpu =3D env_cpu(cpu_env); TaskState *ts =3D cpu->opaque; @@ -8089,6 +8118,18 @@ static int open_self_maps(CPUArchState *cpu_env, int= fd) } else { dprintf(fd, "\n"); } + if (smaps) { + show_smaps(fd, max - min); + dprintf(fd, "VmFlags:%s%s%s%s%s%s%s%s\n", + (flags & PAGE_READ) ? " rd" : "", + (flags & PAGE_WRITE_ORG) ? " wr" : "", + (flags & PAGE_EXEC) ? " ex" : "", + e->is_priv ? "" : " sh", + (flags & PAGE_READ) ? " mr" : "", + (flags & PAGE_WRITE_ORG) ? " mw" : "", + (flags & PAGE_EXEC) ? " me" : "", + e->is_priv ? "" : " ms"); + } } } =20 @@ -8103,11 +8144,25 @@ static int open_self_maps(CPUArchState *cpu_env, in= t fd) " --xp 00000000 00:00 0", TARGET_VSYSCALL_PAGE, TARGET_VSYSCALL_PAGE + TARGET_PA= GE_SIZE); dprintf(fd, "%*s%s\n", 73 - count, "", "[vsyscall]"); + if (smaps) { + show_smaps(fd, TARGET_PAGE_SIZE); + dprintf(fd, "VmFlags: ex\n"); + } #endif =20 return 0; } =20 +static int open_self_maps(CPUArchState *cpu_env, int fd) +{ + return open_self_maps_1(cpu_env, fd, false); +} + +static int open_self_smaps(CPUArchState *cpu_env, int fd) +{ + return open_self_maps_1(cpu_env, fd, true); +} + static int open_self_stat(CPUArchState *cpu_env, int fd) { CPUState *cpu =3D env_cpu(cpu_env); @@ -8459,6 +8514,7 @@ int do_guest_openat(CPUArchState *cpu_env, int dirfd,= const char *pathname, const struct fake_open *fake_open; static const struct fake_open fakes[] =3D { { "maps", open_self_maps, is_proc_myself }, + { "smaps", open_self_smaps, is_proc_myself }, { "stat", open_self_stat, is_proc_myself }, { "auxv", open_self_auxv, is_proc_myself }, { "cmdline", open_self_cmdline, is_proc_myself }, --=20 2.40.1 From nobody Sat May 18 12:05:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1687379845; cv=none; d=zohomail.com; s=zohoarc; b=XySt/JJXqDSq0j4LsP4rMptpcZPg1o0MNtariRSQIxduX0OkfjGCFjo/JOjSY7jDrvX9M/PXxQzHN2N/k8abYvUzYa3JCsz77TXTNtrLsP2Ak8gu/f9bTayM8McRXfix7xIclUPfGMokJkPX2RFDvloSbYoRfsLXSeucEqN27PE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687379845; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ecx4lQo5WRp3o8z1DdIMZAnLsE8WXq4Knht2GICERP4=; b=hAEjWFtHAP3E/ZKn3BFg+dyDJkwDq2/UkTSAYb2Krp6OhsB+N5kT4xP3Jf6CDTM5+MJImJTwKVefaMd1b5ESfvqufECnKF1ezjengUkjud9+uDq02s9mTIKFUo2mKV+EcBY/2c3PHrg+gmha4VLyY2sFD8Hw6aHE8WEqutT16o8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1687379845339183.72154423192057; Wed, 21 Jun 2023 13:37:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qC4ZU-0006yi-Ph; Wed, 21 Jun 2023 16:36:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qC4ZT-0006xx-Bg; Wed, 21 Jun 2023 16:36:55 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qC4ZR-0008DS-OH; Wed, 21 Jun 2023 16:36:55 -0400 Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35LKTn60026725; Wed, 21 Jun 2023 20:36:51 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rc89pg5xn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:51 +0000 Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35LKVLt4031240; Wed, 21 Jun 2023 20:36:50 GMT Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rc89pg5vq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:50 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35LAoGef017049; Wed, 21 Jun 2023 20:36:48 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma03fra.de.ibm.com (PPS) with ESMTPS id 3r94f5aasw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:48 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35LKajpt17367806 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Jun 2023 20:36:45 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AB0932004D; Wed, 21 Jun 2023 20:36:45 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2EE3820040; Wed, 21 Jun 2023 20:36:45 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.179.1.208]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 21 Jun 2023 20:36:45 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=Ecx4lQo5WRp3o8z1DdIMZAnLsE8WXq4Knht2GICERP4=; b=lL09CaB5i6TwltOX1mJpY3/HzqvlV5tVF7kbY94Rjeav1Vs4Nmpf3BVRCibcv2pwVRzr ExNQJbWainHvz+dHOB4ceUMHOlM6Gvsn9ECEe8I5v3h+o8RjFBiuB4HR8cBvqoT8u/q0 azuIKfdNEg5aW6JDMNyR8Fmh7To0f/t66RvVUVOxJ9bg0nx5iuQJl3tpt/QuQ4FR0wRv sDdLSxLjj4rTgUYNyMbKg65Cv4GESna++9SuamBvuACS5hT6zkwGSlRFOMJtBSG/9hqF 05AUzfEnTLMpwD5hVbNlR2rJUM8jiHdxrJvrX5Je3uZROtlOBvQmnOSnbzs31fJV4JKM SA== From: Ilya Leoshkevich To: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Laurent Vivier , Peter Maydell , Richard Henderson , David Hildenbrand Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-s390x@nongnu.org, Ilya Leoshkevich Subject: [PATCH v4 4/8] gdbstub: Expose gdb_get_process() and gdb_get_first_cpu_in_process() Date: Wed, 21 Jun 2023 22:36:23 +0200 Message-Id: <20230621203627.1808446-5-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230621203627.1808446-1-iii@linux.ibm.com> References: <20230621203627.1808446-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: CMojB-1BKi_O6duSszaz8F-9qXhPrmx0 X-Proofpoint-ORIG-GUID: 4JUe-hdRrq2S4G5k6lMcNSoy0pH8LtaW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-21_12,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 adultscore=0 impostorscore=0 priorityscore=1501 clxscore=1015 bulkscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306210167 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1687379845976100009 These functions will be needed by user-target.c in order to retrieve the name of the executable. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Ilya Leoshkevich --- gdbstub/gdbstub.c | 16 ++++++++-------- gdbstub/internals.h | 2 ++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index be18568d0a..9139fec92a 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -211,7 +211,7 @@ static uint32_t gdb_get_cpu_pid(CPUState *cpu) return cpu->cluster_index + 1; } =20 -static GDBProcess *gdb_get_process(uint32_t pid) +GDBProcess *gdb_get_process(uint32_t pid) { int i; =20 @@ -247,7 +247,7 @@ static CPUState *find_cpu(uint32_t thread_id) return NULL; } =20 -static CPUState *get_first_cpu_in_process(GDBProcess *process) +CPUState *gdb_get_first_cpu_in_process(GDBProcess *process) { CPUState *cpu; =20 @@ -325,7 +325,7 @@ static CPUState *gdb_get_cpu(uint32_t pid, uint32_t tid) return NULL; } =20 - return get_first_cpu_in_process(process); + return gdb_get_first_cpu_in_process(process); } else { /* a specific thread */ cpu =3D find_cpu(tid); @@ -354,7 +354,7 @@ static const char *get_feature_xml(const char *p, const= char **newp, size_t len; int i; const char *name; - CPUState *cpu =3D get_first_cpu_in_process(process); + CPUState *cpu =3D gdb_get_first_cpu_in_process(process); CPUClass *cc =3D CPU_GET_CLASS(cpu); =20 len =3D 0; @@ -490,7 +490,7 @@ void gdb_register_coprocessor(CPUState *cpu, =20 static void gdb_process_breakpoint_remove_all(GDBProcess *p) { - CPUState *cpu =3D get_first_cpu_in_process(p); + CPUState *cpu =3D gdb_get_first_cpu_in_process(p); =20 while (cpu) { gdb_breakpoint_remove_all(cpu); @@ -653,7 +653,7 @@ static int gdb_handle_vcont(const char *p) goto out; } =20 - cpu =3D get_first_cpu_in_process(process); + cpu =3D gdb_get_first_cpu_in_process(process); while (cpu) { if (newstates[cpu->cpu_index] =3D=3D 1) { newstates[cpu->cpu_index] =3D cur_action; @@ -1280,7 +1280,7 @@ static void handle_v_attach(GArray *params, void *use= r_ctx) goto cleanup; } =20 - cpu =3D get_first_cpu_in_process(process); + cpu =3D gdb_get_first_cpu_in_process(process); if (!cpu) { goto cleanup; } @@ -1403,7 +1403,7 @@ static void handle_query_curr_tid(GArray *params, voi= d *user_ctx) * first thread). */ process =3D gdb_get_cpu_process(gdbserver_state.g_cpu); - cpu =3D get_first_cpu_in_process(process); + cpu =3D gdb_get_first_cpu_in_process(process); g_string_assign(gdbserver_state.str_buf, "QC"); gdb_append_thread_id(cpu, gdbserver_state.str_buf); gdb_put_strbuf(); diff --git a/gdbstub/internals.h b/gdbstub/internals.h index 33d21d6488..25e4d5eeaa 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -129,6 +129,8 @@ void gdb_read_byte(uint8_t ch); */ bool gdb_got_immediate_ack(void); /* utility helpers */ +GDBProcess *gdb_get_process(uint32_t pid); +CPUState *gdb_get_first_cpu_in_process(GDBProcess *process); CPUState *gdb_first_attached_cpu(void); void gdb_append_thread_id(CPUState *cpu, GString *buf); int gdb_get_cpu_index(CPUState *cpu); --=20 2.40.1 From nobody Sat May 18 12:05:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1687379902; cv=none; d=zohomail.com; s=zohoarc; b=lapO0mNqmc61qVF2zNdCK6qAarU8aMfwVPLd0km0HhQDxaNT+E6Uuupl5ZLP9jh1SfyGavOm9tQRHtDM4q4XytBGh3HU6r2H5ysVUma5Vhdk5E93cpePKvpYsv0uI/wx24OLaTqCjxbIGbgkN+AkcNjxtWY5P1jnWklUFrAmEBo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687379902; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ng7WfdXlg9ZV8SK9VXpYm3h2tEulweiCY+p5AzwDX5o=; b=IjXv5BXcNorZQ+ejBRCmnHfLZliLDWtKWldUQl41LPhqTr1UOhlPpAvPkY7aSSnBKkCH1saIKCoAPRWSKdBzHj5RbxpQijaueu/FbkywYPt46QABB7x1DsJdVg858jPAckK+1DPZA0QzuZeuBBEzlJovPys/Gw8snzy8IxDhQu8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168737990223514.808796085367362; Wed, 21 Jun 2023 13:38:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qC4ZW-0006zw-2M; Wed, 21 Jun 2023 16:36:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qC4ZV-0006yo-2H; Wed, 21 Jun 2023 16:36:57 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qC4ZT-0008E8-G2; Wed, 21 Jun 2023 16:36:56 -0400 Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35LKTmmw026718; Wed, 21 Jun 2023 20:36:53 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rc89pg60m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:53 +0000 Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35LKUapB029089; Wed, 21 Jun 2023 20:36:52 GMT Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rc89pg5xv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:52 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35LFaGE6031816; Wed, 21 Jun 2023 20:36:50 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma02fra.de.ibm.com (PPS) with ESMTPS id 3r94f5aam1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:50 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35LKamwn16057020 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Jun 2023 20:36:48 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 52FC22004B; Wed, 21 Jun 2023 20:36:48 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CC22620040; Wed, 21 Jun 2023 20:36:47 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.179.1.208]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 21 Jun 2023 20:36:47 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=Ng7WfdXlg9ZV8SK9VXpYm3h2tEulweiCY+p5AzwDX5o=; b=g1wZSB2y/IECQGExvUAk0LNFlvdF64DhAgy45vdWd8DdpZUttE8VohLRP9NWBAsJYwFP PbkcrXWw6taJshYGjy/XcqhjA4F9ql0q/tWXy/8jNgYUd5eSal9BMEKgJPe4hWRNWhfm 1ih/RE75M9cWkYwc1m1lFEmWUxZ5US2attNvU28oYyFJyjsEGRnT99oJptdBQf8x5Nba u1JrpnSfi20WLo/JRMDdMtK9zV9aQxpY4YjXV0s43flp02tbfMSvVOApm+1qX9Xoq1g4 e9srOJwh9z31/qmiMeLlfUm9DslLotjUWmqLOGyo02HEfV5Vjz3ylNEe5+Kh5sOI9uvK 7A== From: Ilya Leoshkevich To: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Laurent Vivier , Peter Maydell , Richard Henderson , David Hildenbrand Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-s390x@nongnu.org, Ilya Leoshkevich Subject: [PATCH v4 5/8] gdbstub: Report the actual qemu-user pid Date: Wed, 21 Jun 2023 22:36:24 +0200 Message-Id: <20230621203627.1808446-6-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230621203627.1808446-1-iii@linux.ibm.com> References: <20230621203627.1808446-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: AXPk5wnf-_p4Z-NMVCDfqwR7g9Nz4307 X-Proofpoint-ORIG-GUID: AF_Cuca7twhGw6Q8nUMi450LRQ98OGAY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-21_12,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 adultscore=0 impostorscore=0 priorityscore=1501 clxscore=1015 bulkscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306210167 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1687379904320100007 Currently qemu-user reports pid 1 to GDB. Resolve the TODO and report the actual PID. Using getpid() relies on the assumption that there is only one GDBProcess. Add an assertion to make sure that future changes don't break it. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Ilya Leoshkevich --- gdbstub/gdbstub.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 9139fec92a..c7e3ee71f2 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -202,13 +202,16 @@ void gdb_memtox(GString *buf, const char *mem, int le= n) =20 static uint32_t gdb_get_cpu_pid(CPUState *cpu) { - /* TODO: In user mode, we should use the task state PID */ +#ifdef CONFIG_USER_ONLY + return getpid(); +#else if (cpu->cluster_index =3D=3D UNASSIGNED_CLUSTER_INDEX) { /* Return the default process' PID */ int index =3D gdbserver_state.process_num - 1; return gdbserver_state.processes[index].pid; } return cpu->cluster_index + 1; +#endif } =20 GDBProcess *gdb_get_process(uint32_t pid) @@ -2146,19 +2149,25 @@ void gdb_read_byte(uint8_t ch) void gdb_create_default_process(GDBState *s) { GDBProcess *process; - int max_pid =3D 0; + int pid; =20 +#ifdef CONFIG_USER_ONLY + assert(gdbserver_state.process_num =3D=3D 0); + pid =3D getpid(); +#else if (gdbserver_state.process_num) { - max_pid =3D s->processes[s->process_num - 1].pid; + pid =3D s->processes[s->process_num - 1].pid; + } else { + pid =3D 0; } + /* We need an available PID slot for this process */ + assert(pid < UINT32_MAX); + pid++; +#endif =20 s->processes =3D g_renew(GDBProcess, s->processes, ++s->process_num); process =3D &s->processes[s->process_num - 1]; - - /* We need an available PID slot for this process */ - assert(max_pid < UINT32_MAX); - - process->pid =3D max_pid + 1; + process->pid =3D pid; process->attached =3D false; process->target_xml[0] =3D '\0'; } --=20 2.40.1 From nobody Sat May 18 12:05:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1687379863; cv=none; d=zohomail.com; s=zohoarc; b=EgGoNn+zwpHZLalD5sRGQIf6UTFhzOTukuJqs+5JkOCSMlxjCN5FozaPuPHNffducDsYdHQJSnpWk06owd/E/Z1rb2QJtdkLn78tKz8/hVwr/qurjp/yseFWkViAow0QXoG8gTrnuXhO6xwfVtAZ6c3XcTMr0Sc7afWnY12Wx0E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687379863; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ahMhY2u/DpFVErbZsXrJH0wjQ5jtL+O7LQPw+xOoAZY=; b=nqWxwsEdcxO7EbT0lRrhqNKoVtf+e4PFJGYesCMekC0u/DNVNlD9PfPRB52y4wZEm/BuMYNMnoiIzMzMTtMaqlCGlMvtqHNqxQyiGPq84z02r3R5wg/eciSg7VPxhHSjxBXB5Q2eFeHvxQW5rfFJGxmhUIAaZd336rgcN97455Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1687379862995420.82948289505896; Wed, 21 Jun 2023 13:37:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qC4Zr-0007dx-DV; Wed, 21 Jun 2023 16:37:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qC4Zp-0007b1-45; Wed, 21 Jun 2023 16:37:17 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qC4Zn-000093-0V; Wed, 21 Jun 2023 16:37:16 -0400 Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35LK9td2016315; Wed, 21 Jun 2023 20:37:13 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rc7u98thp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:37:12 +0000 Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35LKOHR3006902; Wed, 21 Jun 2023 20:37:11 GMT Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rc7u98t48-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:37:11 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35LFbkM2015370; Wed, 21 Jun 2023 20:36:52 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma01fra.de.ibm.com (PPS) with ESMTPS id 3r94f52ahv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:52 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35LKaoRS46924232 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Jun 2023 20:36:50 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 48D892004B; Wed, 21 Jun 2023 20:36:50 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B6E9B20040; Wed, 21 Jun 2023 20:36:49 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.179.1.208]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 21 Jun 2023 20:36:49 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : mime-version; s=pp1; bh=ahMhY2u/DpFVErbZsXrJH0wjQ5jtL+O7LQPw+xOoAZY=; b=Vq+K4FmcCS/mlkH5Xz/d02SAva98Q8nH6yOlf246mafkhj64t3dIimMP8H4gGpwU/UT2 Uqb/Tv2sGz/yFNiWa5HIv27eGe+3/h3z+iByao7GjDwjoOdPIgwTf8/h1nZHmIwmM2Gn ZqtoJj8XoCS8PhIb5Ev24MeM1n4Y457KuiRYBRGYjKxcEY8SjoZSEx+53ecgtuXQ9X4u D9KYpeZJ+PLjkyQadyJrFnwu85AWdZC/rseWIgP9VqkkV0j1r/KVePk05K8OaxURmgDG x30yK7Vwt1wVBmKGJgsOhWB3qD9/99fsxNbStoQsmK00dKV9+vTODsqpG8irWPcd0B1j 5w== From: Ilya Leoshkevich To: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Laurent Vivier , Peter Maydell , Richard Henderson , David Hildenbrand Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-s390x@nongnu.org, Ilya Leoshkevich , "Dominik 'Disconnect3d' Czarnota" Subject: [PATCH v4 6/8] gdbstub: Add support for info proc mappings Date: Wed, 21 Jun 2023 22:36:25 +0200 Message-Id: <20230621203627.1808446-7-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230621203627.1808446-1-iii@linux.ibm.com> References: <20230621203627.1808446-1-iii@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 3KnuIU4Ai-9KmgKPHNT_6B_B8_4uigum X-Proofpoint-ORIG-GUID: XiEP9650TWIyHcFGih4pvr8Xf7-_8s7T Content-Transfer-Encoding: quoted-printable X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-21_12,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 bulkscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1015 phishscore=0 suspectscore=0 mlxscore=0 priorityscore=1501 adultscore=0 impostorscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306210172 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1687379864069100001 Content-Type: text/plain; charset="utf-8" Currently the GDB's generate-core-file command doesn't work well with qemu-user: the resulting dumps are huge [1] and at the same time incomplete (argv and envp are missing). The reason is that GDB has no access to proc mappings and therefore has to fall back to using heuristics for discovering them. This is, in turn, because qemu-user does not implement the Host I/O feature of the GDB Remote Serial Protocol. Implement vFile:{open,close,pread,readlink} and also qXfer:exec-file:read+. With that, generate-core-file begins to work on aarch64 and s390x. [1] https://sourceware.org/pipermail/gdb-patches/2023-May/199432.html Co-developed-by: Dominik 'Disconnect3d' Czarnota Signed-off-by: Ilya Leoshkevich --- gdbstub/gdbstub.c | 45 +++++++++++++- gdbstub/internals.h | 5 ++ gdbstub/user-target.c | 139 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 187 insertions(+), 2 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index c7e3ee71f2..d2efefd352 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -1337,6 +1337,36 @@ static const GdbCmdParseEntry gdb_v_commands_table[]= =3D { .cmd =3D "Kill;", .cmd_startswith =3D 1 }, +#ifdef CONFIG_USER_ONLY + /* + * Host I/O Packets. See [1] for details. + * [1] https://sourceware.org/gdb/onlinedocs/gdb/Host-I_002fO-Packets.= html + */ + { + .handler =3D gdb_handle_v_file_open, + .cmd =3D "File:open:", + .cmd_startswith =3D 1, + .schema =3D "s,L,L0" + }, + { + .handler =3D gdb_handle_v_file_close, + .cmd =3D "File:close:", + .cmd_startswith =3D 1, + .schema =3D "l0" + }, + { + .handler =3D gdb_handle_v_file_pread, + .cmd =3D "File:pread:", + .cmd_startswith =3D 1, + .schema =3D "l,L,L0" + }, + { + .handler =3D gdb_handle_v_file_readlink, + .cmd =3D "File:readlink:", + .cmd_startswith =3D 1, + .schema =3D "s0" + }, +#endif }; =20 static void handle_v_commands(GArray *params, void *user_ctx) @@ -1482,11 +1512,14 @@ static void handle_query_supported(GArray *params, = void *user_ctx) ";ReverseStep+;ReverseContinue+"); } =20 -#if defined(CONFIG_USER_ONLY) && defined(CONFIG_LINUX) +#if defined(CONFIG_USER_ONLY) +#if defined(CONFIG_LINUX) if (gdbserver_state.c_cpu->opaque) { g_string_append(gdbserver_state.str_buf, ";qXfer:auxv:read+"); } #endif + g_string_append(gdbserver_state.str_buf, ";qXfer:exec-file:read+"); +#endif =20 if (params->len && strstr(get_param(params, 0)->data, "multiprocess+")) { @@ -1625,13 +1658,21 @@ static const GdbCmdParseEntry gdb_gen_query_table[]= =3D { .cmd_startswith =3D 1, .schema =3D "s:l,l0" }, -#if defined(CONFIG_USER_ONLY) && defined(CONFIG_LINUX) +#if defined(CONFIG_USER_ONLY) +#if defined(CONFIG_LINUX) { .handler =3D gdb_handle_query_xfer_auxv, .cmd =3D "Xfer:auxv:read::", .cmd_startswith =3D 1, .schema =3D "l,l0" }, +#endif + { + .handler =3D gdb_handle_query_xfer_exec_file, + .cmd =3D "Xfer:exec-file:read:", + .cmd_startswith =3D 1, + .schema =3D "l:l,l0" + }, #endif { .handler =3D gdb_handle_query_attached, diff --git a/gdbstub/internals.h b/gdbstub/internals.h index 25e4d5eeaa..f2b46cce41 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -189,6 +189,11 @@ typedef union GdbCmdVariant { void gdb_handle_query_rcmd(GArray *params, void *user_ctx); /* softmmu */ void gdb_handle_query_offsets(GArray *params, void *user_ctx); /* user */ void gdb_handle_query_xfer_auxv(GArray *params, void *user_ctx); /*user */ +void gdb_handle_v_file_open(GArray *params, void *user_ctx); /* user */ +void gdb_handle_v_file_close(GArray *params, void *user_ctx); /* user */ +void gdb_handle_v_file_pread(GArray *params, void *user_ctx); /* user */ +void gdb_handle_v_file_readlink(GArray *params, void *user_ctx); /* user */ +void gdb_handle_query_xfer_exec_file(GArray *params, void *user_ctx); /* u= ser */ =20 void gdb_handle_query_attached(GArray *params, void *user_ctx); /* both */ =20 diff --git a/gdbstub/user-target.c b/gdbstub/user-target.c index fa0e59ec9a..5f0098c806 100644 --- a/gdbstub/user-target.c +++ b/gdbstub/user-target.c @@ -11,6 +11,10 @@ #include "exec/gdbstub.h" #include "qemu.h" #include "internals.h" +#ifdef CONFIG_LINUX +#include "linux-user/loader.h" +#include "linux-user/qemu.h" +#endif =20 /* * Map target signal numbers to GDB protocol signal numbers and vice @@ -281,3 +285,138 @@ void gdb_handle_query_xfer_auxv(GArray *params, void = *user_ctx) gdbserver_state.str_buf->len, true); } #endif + +static const char *get_filename_param(GArray *params, int i) +{ + const char *hex_filename =3D get_param(params, i)->data; + gdb_hextomem(gdbserver_state.mem_buf, hex_filename, + strlen(hex_filename) / 2); + g_byte_array_append(gdbserver_state.mem_buf, (const guint8 *)"", 1); + return (const char *)gdbserver_state.mem_buf->data; +} + +static void hostio_reply_with_data(const void *buf, size_t n) +{ + g_string_printf(gdbserver_state.str_buf, "F%zx;", n); + gdb_memtox(gdbserver_state.str_buf, buf, n); + gdb_put_packet_binary(gdbserver_state.str_buf->str, + gdbserver_state.str_buf->len, true); +} + +void gdb_handle_v_file_open(GArray *params, void *user_ctx) +{ + const char *filename =3D get_filename_param(params, 0); + uint64_t flags =3D get_param(params, 1)->val_ull; + uint64_t mode =3D get_param(params, 2)->val_ull; + +#ifdef CONFIG_LINUX + int fd =3D do_guest_openat(gdbserver_state.g_cpu->env_ptr, 0, filename, + flags, mode, false); +#else + int fd =3D open(filename, flags, mode); +#endif + if (fd < 0) { + g_string_printf(gdbserver_state.str_buf, "F-1,%d", errno); + } else { + g_string_printf(gdbserver_state.str_buf, "F%d", fd); + } + gdb_put_strbuf(); +} + +void gdb_handle_v_file_close(GArray *params, void *user_ctx) +{ + int fd =3D get_param(params, 0)->val_ul; + + if (close(fd) =3D=3D -1) { + g_string_printf(gdbserver_state.str_buf, "F-1,%d", errno); + gdb_put_strbuf(); + return; + } + + gdb_put_packet("F00"); +} + +#define BUFSIZ 8192 + +void gdb_handle_v_file_pread(GArray *params, void *user_ctx) +{ + int fd =3D get_param(params, 0)->val_ul; + size_t count =3D get_param(params, 1)->val_ull; + off_t offset =3D get_param(params, 2)->val_ull; + + size_t bufsiz =3D MIN(count, BUFSIZ); + g_autofree char *buf =3D g_try_malloc(bufsiz); + if (buf =3D=3D NULL) { + gdb_put_packet("E12"); + return; + } + + ssize_t n =3D pread(fd, buf, bufsiz, offset); + if (n < 0) { + g_string_printf(gdbserver_state.str_buf, "F-1,%d", errno); + gdb_put_strbuf(); + return; + } + hostio_reply_with_data(buf, n); +} + +void gdb_handle_v_file_readlink(GArray *params, void *user_ctx) +{ + const char *filename =3D get_filename_param(params, 0); + + g_autofree char *buf =3D g_try_malloc(BUFSIZ); + if (buf =3D=3D NULL) { + gdb_put_packet("E12"); + return; + } + +#ifdef CONFIG_LINUX + ssize_t n =3D do_guest_readlink(filename, buf, BUFSIZ); +#else + ssize_t n =3D readlink(filename, buf, BUFSIZ); +#endif + if (n < 0) { + g_string_printf(gdbserver_state.str_buf, "F-1,%d", errno); + gdb_put_strbuf(); + return; + } + hostio_reply_with_data(buf, n); +} + +void gdb_handle_query_xfer_exec_file(GArray *params, void *user_ctx) +{ + uint32_t pid =3D get_param(params, 0)->val_ul; + uint32_t offset =3D get_param(params, 1)->val_ul; + uint32_t length =3D get_param(params, 2)->val_ul; + + GDBProcess *process =3D gdb_get_process(pid); + if (!process) { + gdb_put_packet("E00"); + return; + } + + CPUState *cpu =3D gdb_get_first_cpu_in_process(process); + if (!cpu) { + gdb_put_packet("E00"); + return; + } + + TaskState *ts =3D cpu->opaque; + if (!ts || !ts->bprm || !ts->bprm->filename) { + gdb_put_packet("E00"); + return; + } + + size_t total_length =3D strlen(ts->bprm->filename); + if (offset > total_length) { + gdb_put_packet("E00"); + return; + } + if (offset + length > total_length) { + length =3D total_length - offset; + } + + g_string_printf(gdbserver_state.str_buf, "l%.*s", length, + ts->bprm->filename + offset); + gdb_put_strbuf(); +} --=20 2.40.1 From nobody Sat May 18 12:05:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1687379843; cv=none; d=zohomail.com; s=zohoarc; b=DHyb63oqQHVJY66Ojn1uSo5dKQLYedgi9Xwxb05JJKyxu2C0oMJegDagROUBET7Av11qUdUK1lHq+HWpMNoDdZ7dkBent78z0U8Q36abOo+XKd/jNJAfpx4flUbXcpDFBhJDasAv1Oj0hVypy+z48qMeUGZdLiAYMzUslt+gfGw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687379843; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hkF6Ozvx4FPBA20KrX19IeWIjWHpcac1PcepJTSpkNA=; b=ilxyzFjNAJZR6hsfIzFcMgtmCElzBvAi20IHIAnA9zUTAWAtHUgwMfKxeclBqLvljOEAUwEv3y4E64sYDfD81W0vHqprfOnVamZYpxamQYuSnHd8hh5dz4QW39J/D8iDvP1dWytGQLlOTsZeHmmtRL34tPUoxo0K17VM7or54O8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1687379843322864.2171635557344; Wed, 21 Jun 2023 13:37:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qC4Zc-00075e-Tk; Wed, 21 Jun 2023 16:37:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qC4Zb-000743-0X; Wed, 21 Jun 2023 16:37:03 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qC4ZZ-0008FO-Bf; Wed, 21 Jun 2023 16:37:02 -0400 Received: from pps.filterd (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35LKEKiS021963; Wed, 21 Jun 2023 20:36:58 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rc82g8f2w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:58 +0000 Received: from m0353727.ppops.net (m0353727.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35LKKpv0010792; Wed, 21 Jun 2023 20:36:57 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rc82g8f24-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:57 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35L3AgBn029539; Wed, 21 Jun 2023 20:36:54 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma03ams.nl.ibm.com (PPS) with ESMTPS id 3r94f532s3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:54 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35LKaq7o5767806 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Jun 2023 20:36:52 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3EB262004B; Wed, 21 Jun 2023 20:36:52 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A93B120040; Wed, 21 Jun 2023 20:36:51 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.179.1.208]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 21 Jun 2023 20:36:51 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=hkF6Ozvx4FPBA20KrX19IeWIjWHpcac1PcepJTSpkNA=; b=i8tav/PtsvNIz0jSxH8Rd+Fu+xOrjICCfY5QCodaiEmKzc54EIKJ562ZyZTUIb9OQJMo JwQg4hp3JTgk0koJnVHsB+T5rWPPE5SIZTrMigT218zBTiUp06oFWmCDsSvvsyIkrhd4 zbTtDeFirHmbBhS+WgIl7ZwS64YPGNONwckbjQ6TxaryHOQxluwAfSsyip1Y+Qoilm3L nY/BAWUzTqEZEnr1mQRPqT5gT8AEf7bKp+IE0O7Z2/mbnHtdYY8u0OZmmTuYNEoyx/a6 M9yN+GQB4a55Q430YrmctIzvzBbUcYmf2Zj29gUbGTDUTCxJvXc+RM+a37BaIkEXKgPp Yw== From: Ilya Leoshkevich To: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Laurent Vivier , Peter Maydell , Richard Henderson , David Hildenbrand Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-s390x@nongnu.org, Ilya Leoshkevich Subject: [PATCH v4 7/8] docs: Document security implications of debugging Date: Wed, 21 Jun 2023 22:36:26 +0200 Message-Id: <20230621203627.1808446-8-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230621203627.1808446-1-iii@linux.ibm.com> References: <20230621203627.1808446-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 8woW_lOX8HUWM-kvDYVt8SFJly4uC4Tr X-Proofpoint-GUID: GR9kkEMBaZrw5-Fk9_oi7kMvyRb1f2uE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-21_12,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 phishscore=0 clxscore=1015 adultscore=0 bulkscore=0 impostorscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306210172 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.156.1; envelope-from=iii@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1687379844260100005 Now that the GDB stub explicitly implements reading host files (note that it was already possible by changing the emulated code to open and read those files), concerns may arise that it undermines security. Document the status quo, which is that the users are already responsible for securing the GDB connection themselves. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Ilya Leoshkevich --- docs/system/gdb.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/system/gdb.rst b/docs/system/gdb.rst index 7d3718deef..9906991b84 100644 --- a/docs/system/gdb.rst +++ b/docs/system/gdb.rst @@ -214,3 +214,18 @@ The memory mode can be checked by sending the followin= g command: =20 ``maintenance packet Qqemu.PhyMemMode:0`` This will change it back to normal memory mode. + +Security considerations +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Connecting to the GDB socket allows running arbitrary code inside the gues= t; +in case of the TCG emulation, which is not considered a security boundary,= this +also means running arbitrary code on the host. Additionally, when debugging +qemu-user, it allows directly downloading any file readable by QEMU from t= he +host. + +The GDB socket is not protected by authentication, authorization or encryp= tion. +It is therefore a responsibility of the user to make sure that only author= ized +clients can connect to it, e.g., by using a unix socket with proper +permissions, or by opening a TCP socket only on interfaces that are not +reachable by potential attackers. --=20 2.40.1 From nobody Sat May 18 12:05:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1687379880; cv=none; d=zohomail.com; s=zohoarc; b=KrqeFMjZE86/z9CISH99csGP6/G1koalO/qri9FYnBPOmfuRHGOufuLusazYFP6HZBVrkWAgRquTrO+Nv92ULJUnwWIO0BBOwlhh3Mj2yYoU/BnGrvTiUonpcyiX3kwu2oISDNP3L3SCEPFwf0rSHfIRNJgPiMdgAgGv+lOp7cc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687379880; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TdiIGw6EKMH60FCKoexCpccB5g6GF4b9SqalWcn+2hU=; b=FtibanuELL4mi/sKPATdjXEJ/38R1IBh+s2sv8tpNiZCqc2wMuh3rq3JYrc7rZJyKkKl6ZT669bifCKMmxHeUkNuSC8ZD5spOId8DdZA1tgX8bZ2uRsBumqigwPgMkG+yObHW0jIOp3vf0RjR3EHDiKW2sFFPgxWayLlrhHOUIM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1687379880146114.19413493838192; Wed, 21 Jun 2023 13:38:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qC4Zf-0007Ef-Fb; Wed, 21 Jun 2023 16:37:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qC4Zd-00075n-03; Wed, 21 Jun 2023 16:37:05 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qC4Zb-0008IO-4Z; Wed, 21 Jun 2023 16:37:04 -0400 Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35LKGx8R008635; Wed, 21 Jun 2023 20:37:00 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rc83wrf94-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:37:00 +0000 Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35LKSFPE012981; Wed, 21 Jun 2023 20:36:59 GMT Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rc83wrf7r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:59 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35L2eYbW023647; Wed, 21 Jun 2023 20:36:57 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma04fra.de.ibm.com (PPS) with ESMTPS id 3r94f5aa8y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jun 2023 20:36:56 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35LKasWY62390638 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Jun 2023 20:36:54 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 713F120043; Wed, 21 Jun 2023 20:36:54 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EB5D920040; Wed, 21 Jun 2023 20:36:53 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.179.1.208]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 21 Jun 2023 20:36:53 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=TdiIGw6EKMH60FCKoexCpccB5g6GF4b9SqalWcn+2hU=; b=YdtarQEUn+cuSxunMKEEPvl9cDjKFcaXGb5lX2Eyf7pVjhYdFKAdSntoMyysss5+LIUc ggQah6xG6IXK5MAcy+tCODoXqvF3e4A5DQRQMt0KsEXbUyqroE99F8TiP/52qUVHYUY4 v165z4K8Nd5BGuAmVq1aGhnPxUaRAF00HUKCKJ2q+vQ2ANvPwOPq8GxEWf1OnN3xWd6o E+KCV1bNpnf7/pvvvzzb/JS/aSYfJRp0lIKR16A6B+UtBD2fKGNXdpSQP2Uc3kT1sOtu YbvHoCrkSozdnr/fO+U8If4MU0EPOPchFrsTzFIYdQ9aYsKMKvnPwnQoowwYNW/jZR9a Iw== From: Ilya Leoshkevich To: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Laurent Vivier , Peter Maydell , Richard Henderson , David Hildenbrand Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-s390x@nongnu.org, Ilya Leoshkevich Subject: [PATCH v4 8/8] tests/tcg: Add a test for info proc mappings Date: Wed, 21 Jun 2023 22:36:27 +0200 Message-Id: <20230621203627.1808446-9-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230621203627.1808446-1-iii@linux.ibm.com> References: <20230621203627.1808446-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: e155cBitdUeJE5gm05xsc16-QbLiI91g X-Proofpoint-ORIG-GUID: SRrfTpcgVgZMnpGjRLgOPsVy6-co75nx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-21_12,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 phishscore=0 adultscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=866 clxscore=1015 impostorscore=0 priorityscore=1501 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306210172 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.156.1; envelope-from=iii@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1687379882125100004 Content-Type: text/plain; charset="utf-8" Add a small test to prevent regressions. Signed-off-by: Ilya Leoshkevich --- tests/tcg/multiarch/Makefile.target | 9 ++- .../multiarch/gdbstub/test-proc-mappings.py | 65 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/multiarch/gdbstub/test-proc-mappings.py diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Make= file.target index 373db69648..43bddeaf21 100644 --- a/tests/tcg/multiarch/Makefile.target +++ b/tests/tcg/multiarch/Makefile.target @@ -81,6 +81,13 @@ run-gdbstub-qxfer-auxv-read: sha1 --bin $< --test $(MULTIARCH_SRC)/gdbstub/test-qxfer-auxv-read.py, \ basic gdbstub qXfer:auxv:read support) =20 +run-gdbstub-proc-mappings: sha1 + $(call run-test, $@, $(GDB_SCRIPT) \ + --gdb $(HAVE_GDB_BIN) \ + --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \ + --bin $< --test $(MULTIARCH_SRC)/gdbstub/test-proc-mappings.py, \ + proc mappings support) + run-gdbstub-thread-breakpoint: testthread $(call run-test, $@, $(GDB_SCRIPT) \ --gdb $(HAVE_GDB_BIN) \ @@ -97,7 +104,7 @@ run-gdbstub-%: $(call skip-test, "gdbstub test $*", "need working gdb") endif EXTRA_RUNS +=3D run-gdbstub-sha1 run-gdbstub-qxfer-auxv-read \ - run-gdbstub-thread-breakpoint + run-gdbstub-proc-mappings run-gdbstub-thread-breakpoint =20 # ARM Compatible Semi Hosting Tests # diff --git a/tests/tcg/multiarch/gdbstub/test-proc-mappings.py b/tests/tcg/= multiarch/gdbstub/test-proc-mappings.py new file mode 100644 index 0000000000..a23bbcee7f --- /dev/null +++ b/tests/tcg/multiarch/gdbstub/test-proc-mappings.py @@ -0,0 +1,65 @@ +"""Test that gdbstub has access to proc mappings. + +This runs as a sourced script (via -x, via run-test.py).""" +from __future__ import print_function +import gdb +import sys + + +n_failures =3D 0 + + +def report(cond, msg): + """Report success/fail of a test""" + if cond: + print("PASS: {}".format(msg)) + else: + print("FAIL: {}".format(msg)) + global n_failures + n_failures +=3D 1 + + +def run_test(): + """Run through the tests one by one""" + try: + mappings =3D gdb.execute("info proc mappings", False, True) + except gdb.error as exc: + exc_str =3D str(exc) + if "Not supported on this target." in exc_str: + # Detect failures due to an outstanding issue with how GDB han= dles + # the x86_64 QEMU's target.xml, which does not contain the + # definition of orig_rax. Skip the test in this case. + print("SKIP: {}".format(exc_str)) + return + raise + report(isinstance(mappings, str), "Fetched the mappings from the infer= ior") + report("/sha1" in mappings, "Found the test binary name in the mapping= s") + + +def main(): + """Prepare the environment and run through the tests""" + try: + inferior =3D gdb.selected_inferior() + print("ATTACHED: {}".format(inferior.architecture().name())) + except (gdb.error, AttributeError): + print("SKIPPING (not connected)") + exit(0) + + if gdb.parse_and_eval('$pc') =3D=3D 0: + print("SKIP: PC not set") + exit(0) + + try: + # These are not very useful in scripts + gdb.execute("set pagination off") + gdb.execute("set confirm off") + + # Run the actual tests + run_test() + except gdb.error: + report(False, "GDB Exception: {}".format(sys.exc_info()[0])) + print("All tests complete: %d failures" % n_failures) + exit(n_failures) + + +main() --=20 2.40.1