From nobody Tue Nov 26 07:00:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709152010781490.82087960303613; Wed, 28 Feb 2024 12:26:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfQUc-0007zu-UP; Wed, 28 Feb 2024 15:25:30 -0500 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 1rfQUb-0007zK-E7 for qemu-devel@nongnu.org; Wed, 28 Feb 2024 15:25:29 -0500 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfQUW-0007Lz-9f for qemu-devel@nongnu.org; Wed, 28 Feb 2024 15:25:29 -0500 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-29ab78237d2so67946a91.1 for ; Wed, 28 Feb 2024 12:25:23 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id oh5-20020a17090b3a4500b0029ab712f648sm2118499pjb.38.2024.02.28.12.25.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 12:25:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709151923; x=1709756723; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FeF7fzEyCne6DT9i0AjI3AaZvbjspKahuYDo6eT9HQw=; b=djshCp09lGMTHPRQQcwLiau1Qa3WG+Ao+Hk5wINjaQRphv8GGz6sSLssGtH8Ibeetz JCQvpno+ODI25AmCRgyQNcvxyCIKNtB/tqHl9RtR98e32lMTHbru00cBbyIQoBpdixcz XdzdexUOFwGRI86rfJ8sX9eT4Lg/yXDSRiLB4vfQh/596BhLBeNml1WPgw0Bxm76dUYY sU2TWP7jfvFbXjjsAE6fyWARsr6h6w48n6KkkaRwKW7j9iq0Kt1NtQAEBYW2jj+Q+KGz IEeRnlz9/XQ8r/9ECc5fM9C8NhEK6sLB0BidoWKuUzOezDSXXYXQp0dg9Mu2txkYGNR4 znJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709151923; x=1709756723; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FeF7fzEyCne6DT9i0AjI3AaZvbjspKahuYDo6eT9HQw=; b=IY/xJnOftuJHpMAWiUHgcE27JeC+h5vmkPGHPyFHk6W80ngtpe3U3J1LGkOYyueTVW 30AqCp7we6XrLaN328dpjrY+ur1yha8MK9mP6D2h2LhtN/HlROBwb868BNZbnH7ytUKP RnwAWArhZfpCfofzHTcJbpE1C83TdnyDqHrpRD5+dCiahthUZktQI7CazutgYncld6g7 TYekPPH/InC8GOHrUokWzntzwgn3rRnOAnc2KScVkPISi7wI/Yfq2Ndwpt9q2Bf8KH7O qCRli3GxO8AtVN29mgdNHVMWZnpLRBdbcrR23pV3y/j4UiBg5zVgFH2P0Hj+aNKAZ+Yd LtEA== X-Gm-Message-State: AOJu0YzlwYXgI8yvwu0aWc8en0bubEBBPkuqOxHNsosXLDHZuVc59aB7 8lksixizHkWIQWoLAQ9BB4Cv2+e3R1cM43PLrDPqSvrJlE2o28MAXEQdRO3osixOHFf2/RQfuOJ z X-Google-Smtp-Source: AGHT+IE5XRJrqoVYo7frj9BME26umkgmV05D9tvxvaRCOJcPoPZVG8hS/uHc7cW7L8R37iOnq87MQQ== X-Received: by 2002:a17:90b:3791:b0:29a:a436:4dda with SMTP id mz17-20020a17090b379100b0029aa4364ddamr332457pjb.0.1709151922839; Wed, 28 Feb 2024 12:25:22 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, richard.purdie@linuxfoundation.org, mjt@tls.msk.ru, iii@linux.ibm.com Subject: [PATCH v2 1/5] linux-user/x86_64: Handle the vsyscall page in open_self_maps_{2, 4} Date: Wed, 28 Feb 2024 10:25:14 -1000 Message-Id: <20240228202518.33180-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228202518.33180-1-richard.henderson@linaro.org> References: <20240228202518.33180-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=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: fail (Header signature does not verify) X-ZM-MESSAGEID: 1709152011922100003 Content-Type: text/plain; charset="utf-8" This is the only case in which we expect to have no host memory backing for a guest memory page, because in general linux user processes cannot map any pages in the top half of the 64-bit address space. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2170 Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/syscall.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e384e14248..bc8c06522f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7994,6 +7994,10 @@ static void open_self_maps_4(const struct open_self_= maps_data *d, path =3D "[heap]"; } else if (start =3D=3D info->vdso) { path =3D "[vdso]"; +#ifdef TARGET_X86_64 + } else if (start =3D=3D TARGET_VSYSCALL_PAGE) { + path =3D "[vsyscall]"; +#endif } =20 /* Except null device (MAP_ANON), adjust offset for this fragment. */ @@ -8082,6 +8086,18 @@ static int open_self_maps_2(void *opaque, target_ulo= ng guest_start, uintptr_t host_start =3D (uintptr_t)g2h_untagged(guest_start); uintptr_t host_last =3D (uintptr_t)g2h_untagged(guest_end - 1); =20 +#ifdef TARGET_X86_64 + /* + * Because of the extremely high position of the page within the guest + * virtual address space, this is not backed by host memory at all. + * Therefore the loop below would fail. This is the only instance + * of not having host backing memory. + */ + if (guest_start =3D=3D TARGET_VSYSCALL_PAGE) { + return open_self_maps_3(opaque, guest_start, guest_end, flags); + } +#endif + while (1) { IntervalTreeNode *n =3D interval_tree_iter_first(d->host_maps, host_start, host_start); --=20 2.34.1 From nobody Tue Nov 26 07:00:37 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=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709151980; cv=none; d=zohomail.com; s=zohoarc; b=UDZjXhOpQ1Lp2laZNXiTu19VWrMGbxLNu8TPO6+2hRfvVG37n8tF/Y1gg+PqpBPN7ohzxq71IfGVn8zn5A9N9WmLD7iy/qk8IqfCN+9ATT4u7pecDBqkKj+jtfEkTFG7eP0yDdAvGjp631mEY07CXGqendXKKoZo1s7UjkuemhY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709151980; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uYpmvWcDo9XJ8PEub2Zz6TVzblWCi4U6QK1BUlbCzJU=; b=ZTzu+3yvWxOjuSou90/Um4yHgXZKrr4MLngUKmBP7a4yIs17yWprMOmZD6l3hyzn+5nyUmIBIyJoVUqvUHshKJdLx63Uwmh16IDRoa8C4/duJPDTFJTdfRTKtYjMBGfZk6OVJFg/Oj2DA+A75Zso3IelOTLT39UV+AhBDHJOCyo= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709151980952815.0015625853738; Wed, 28 Feb 2024 12:26:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfQUb-0007zJ-8P; Wed, 28 Feb 2024 15:25:29 -0500 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 1rfQUZ-0007yq-Qy for qemu-devel@nongnu.org; Wed, 28 Feb 2024 15:25:27 -0500 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfQUX-0007M9-VB for qemu-devel@nongnu.org; Wed, 28 Feb 2024 15:25:27 -0500 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-299b92948a6so74154a91.3 for ; Wed, 28 Feb 2024 12:25:25 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id oh5-20020a17090b3a4500b0029ab712f648sm2118499pjb.38.2024.02.28.12.25.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 12:25:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709151924; x=1709756724; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uYpmvWcDo9XJ8PEub2Zz6TVzblWCi4U6QK1BUlbCzJU=; b=ZuiSzcsiVV3QK5uuxZKUMgcV8OG6xgt/60HjQFzFp6hccCjzyV8xBW51LIaB12d1vX fiP8bu7BbADetVeD7mzEKXA9EZqUCu7JjXBeCVlNVMgIbEGE0Bxk+mQhy8eefBz6Sccl E3ic4+BYcp+BaAgplHV4zBjC3aBpae0GjSFyD9/yDAg0jWyrrhqjUlcjtEe07t7IdOWh X15k1qe7YgImLGZLTanlpvlEdW47S7dXmsS0QFk8HleIv9MzN1AK8IN9utzGyfsbmDD+ opsC/W3a8cR6Vf+/Z/8PviNaOh77hQznlbpgno/1E9WzXj/L5b805Dw9+3LOfkvgwhNu kxqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709151924; x=1709756724; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uYpmvWcDo9XJ8PEub2Zz6TVzblWCi4U6QK1BUlbCzJU=; b=LJ/1kIjiiwnImNAwBFcn1Sm5+nKgZc6b3jhmwDZiaxfM7z6cc/UKN5q1qEojKvYgYy bjKv9IHhP+rATr2xoueOlIuIuI+nYDr/7yC7M58xaeOQSh7gDY26NIOx9NY4piwQQhUt Z8bsIXMN6CEOsJd8dcvtcwBXiGVHDPchMxD3jcWV4KtIwYBlLima7BUq5noGSUcmh7G9 z4bDsJe13amGQpvrWS6NUhNpqaw3uCK1gYEAdvPqCWFhb22MZcoVdbAUwOm3BG/ZEXhV 7KETXjBOTksnms/W5Am4BPvFn+tP5qwO+gyG9R21j7jCH8L2PcGjDRW5xM/626XOWKTg g/aA== X-Gm-Message-State: AOJu0Yz/0ZadDiFYp334BqeoIfL1Con2lPkVk6cf5MKegFWcW1mKQ2pW o/NyomlCDGUKmlz4vno//aYNoVQ1f2IifOyXmOwsnDYaimeZtoeWPVUIKcn9+6dRCAmphqfNNVo E X-Google-Smtp-Source: AGHT+IG2gks6tKbJ90ttA2XGR+baKFdv/JDAyktePlU80AHYmmIZdyEEfNK+0Rr9rJvHp8QcrP+H7A== X-Received: by 2002:a17:90b:1c07:b0:299:4f5a:62d5 with SMTP id oc7-20020a17090b1c0700b002994f5a62d5mr291809pjb.18.1709151924493; Wed, 28 Feb 2024 12:25:24 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, richard.purdie@linuxfoundation.org, mjt@tls.msk.ru, iii@linux.ibm.com, Song Gao Subject: [PATCH v2 2/5] linux-user/loongarch64: Remove TARGET_FORCE_SHMLBA Date: Wed, 28 Feb 2024 10:25:15 -1000 Message-Id: <20240228202518.33180-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228202518.33180-1-richard.henderson@linaro.org> References: <20240228202518.33180-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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 @linaro.org) X-ZM-MESSAGEID: 1709151982185100001 Content-Type: text/plain; charset="utf-8" The kernel abi was changed with commit d23b77953f5a4fbf94c05157b186aac2a247ae32 Author: Huacai Chen Date: Wed Jan 17 12:43:08 2024 +0800 LoongArch: Change SHMLBA from SZ_64K to PAGE_SIZE during the v6.8 cycle. Reviewed-by: Song Gao Signed-off-by: Richard Henderson --- linux-user/loongarch64/target_syscall.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/linux-user/loongarch64/target_syscall.h b/linux-user/loongarch= 64/target_syscall.h index 8b5de52124..39f229bb9c 100644 --- a/linux-user/loongarch64/target_syscall.h +++ b/linux-user/loongarch64/target_syscall.h @@ -38,11 +38,4 @@ struct target_pt_regs { #define TARGET_MCL_FUTURE 2 #define TARGET_MCL_ONFAULT 4 =20 -#define TARGET_FORCE_SHMLBA - -static inline abi_ulong target_shmlba(CPULoongArchState *env) -{ - return 64 * KiB; -} - #endif --=20 2.34.1 From nobody Tue Nov 26 07:00:37 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=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709152024; cv=none; d=zohomail.com; s=zohoarc; b=Kq918CZ8NYB6r0qrRcs9CAIn4IcvPdAXW/B7gb9YJKlq/8NP0vVPGHHTvqoOOFUd1/9SWrZsUOeRzgUucY1P03AJ/sGPS03H4qBtQPC9IYyXrEnPCXAmZPtwYoN0E37SAEakvkTaR84hui3ObVUZgemPtzoS/rxvxP3Gp9X6fn8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709152024; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0U9PMwHiZszNU3T0CkEUezw6dw3Df8531lwjpQDns4A=; b=GxVdf96bwgK/sIjZ8NmasyoVIFeG0oTyHczB3JZjMAKx4QWIQcL8Hdm0NAB29RQ8Or/hv6rAS/mZObx0QBxBbdet47cg9FX7f9Z/HjL6rorMCk0p/P82EMcz8NRr6YQt8032kL71g1gWabasEW+e1pwiO3Dg5xaOgyD8vQJ3aw8= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709152024565277.1420260321903; Wed, 28 Feb 2024 12:27:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfQUh-00080q-CN; Wed, 28 Feb 2024 15:25:35 -0500 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 1rfQUe-000806-Sm for qemu-devel@nongnu.org; Wed, 28 Feb 2024 15:25:32 -0500 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfQUa-0007MR-0L for qemu-devel@nongnu.org; Wed, 28 Feb 2024 15:25:32 -0500 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-5d8b276979aso96657a12.2 for ; Wed, 28 Feb 2024 12:25:27 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id oh5-20020a17090b3a4500b0029ab712f648sm2118499pjb.38.2024.02.28.12.25.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 12:25:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709151926; x=1709756726; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0U9PMwHiZszNU3T0CkEUezw6dw3Df8531lwjpQDns4A=; b=PbS9FMiRrGu4V+2whtbxugrsiDpcpFs0Y4PA7EVVH7mBeMGg3saF6BFjgYf3M48RLE 2Tjr0DM2vh6iwvvYm7dk+J7IjfOnuNPMZrsBrLzgQMWDtmzdu99kqPoul5bS12TXG9ER 7TmyifQDHt3JOsPN4h4vTRc5LT5C5unUhXlN7J+NXbhrio+Qr1y54KVfPjQzy9bPeQgK x9aWpWuUj72IWjMLb0XRIwX8i5D9U31HGQo9JQ0Tbapj5eKXbQ+o6B6JphGsWhGOjnP4 /wBTvz+wfwpYkyFfJ3brcyaTBRCXCephq7d5Ps8hkc45fxVfsObugibGAQ0SbOgWrmUR bOXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709151926; x=1709756726; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0U9PMwHiZszNU3T0CkEUezw6dw3Df8531lwjpQDns4A=; b=hEWk/D4PZ6RatyB3njt/4K+buA78YLCZ8s6YD20WhMCN82Fry51hsSuTAkfFdI4w1U ImqLjMA6xbHETlSGf1ZQBuhslX6xOJ9GIWhxm2SCfYc+lUNmOsU6KPs86XRS4xWRlJ0v GovoQtrkNqibiSbSUDmg4PsURHwuj0BkzF3OevxpvbdvYPNtdMSTtTgZzrhY9nUzWdP2 P60iIu1yfJg4Kx9FCSw2I5HZmVEj7WligsjeSZygs+ndWHhBZgY5GPiZML8DP0d4ZX3k 8r3/kpBI98vB+6gmaxS2DK+in9TQB2Gx4t0ASierpUyolD1aKpWsNeCyZ34Iby7rRu7l R7qg== X-Gm-Message-State: AOJu0YwCzyFcdxmx9if5ViPmwdFXCqYA5f2UO6RjizCEBlY1kLaOnUwL kQ7l7hOkiIpvu5buOjPwDwiMlmje2n6li4uOVK5CiUxIi6eSBOh382OgVyqqbA1QhiVOBhyf35y i X-Google-Smtp-Source: AGHT+IGrFJIJTQgrMZlXVgIQeNd1TLRU+Oed90gJbzNNR97eRW8DTu3VIIaMmArgH+gnle4paNkhTQ== X-Received: by 2002:a17:90b:3753:b0:299:a5a1:46e2 with SMTP id ne19-20020a17090b375300b00299a5a146e2mr244104pjb.25.1709151926253; Wed, 28 Feb 2024 12:25:26 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, richard.purdie@linuxfoundation.org, mjt@tls.msk.ru, iii@linux.ibm.com Subject: [PATCH v2 3/5] linux-user: Add strace for shmat Date: Wed, 28 Feb 2024 10:25:16 -1000 Message-Id: <20240228202518.33180-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228202518.33180-1-richard.henderson@linaro.org> References: <20240228202518.33180-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::535; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x535.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=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 @linaro.org) X-ZM-MESSAGEID: 1709152025990100011 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/strace.c | 23 +++++++++++++++++++++++ linux-user/strace.list | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/linux-user/strace.c b/linux-user/strace.c index cf26e55264..47d6ec3263 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -670,6 +670,25 @@ print_semctl(CPUArchState *cpu_env, const struct sysca= llname *name, } #endif =20 +static void +print_shmat(CPUArchState *cpu_env, const struct syscallname *name, + abi_long arg0, abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4, abi_long arg5) +{ + static const struct flags shmat_flags[] =3D { + FLAG_GENERIC(SHM_RND), + FLAG_GENERIC(SHM_REMAP), + FLAG_GENERIC(SHM_RDONLY), + FLAG_GENERIC(SHM_EXEC), + }; + + print_syscall_prologue(name); + print_raw_param(TARGET_ABI_FMT_ld, arg0, 0); + print_pointer(arg1, 0); + print_flags(shmat_flags, arg2, 1); + print_syscall_epilogue(name); +} + #ifdef TARGET_NR_ipc static void print_ipc(CPUArchState *cpu_env, const struct syscallname *name, @@ -683,6 +702,10 @@ print_ipc(CPUArchState *cpu_env, const struct syscalln= ame *name, print_ipc_cmd(arg3); qemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4); break; + case IPCOP_shmat: + print_shmat(cpu_env, &(const struct syscallname){ .name =3D "shmat= " }, + arg1, arg4, arg2, 0, 0, 0); + break; default: qemu_log(("%s(" TARGET_ABI_FMT_ld "," diff --git a/linux-user/strace.list b/linux-user/strace.list index 6655d4f26d..dfd4237d14 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -1398,7 +1398,7 @@ { TARGET_NR_sgetmask, "sgetmask" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_shmat -{ TARGET_NR_shmat, "shmat" , NULL, NULL, print_syscall_ret_addr }, +{ TARGET_NR_shmat, "shmat" , NULL, print_shmat, print_syscall_ret_addr }, #endif #ifdef TARGET_NR_shmctl { TARGET_NR_shmctl, "shmctl" , NULL, NULL, NULL }, --=20 2.34.1 From nobody Tue Nov 26 07:00:37 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=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709152022; cv=none; d=zohomail.com; s=zohoarc; b=csZEKqxbmucxAVEkmAzikZ1Vj1rpuzY7ZHfw31RQRbDZjSZHicgcrxKb4uLfq382MS7Frfujayolf15JwLBwegAuxRv01vl50+1ETkeZ6JtX/uGs0bhftpKnn38G1rw6tI0TozSbF929NmqxmKWIHysRdJi6XcXNw5jthcMzXz0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709152022; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uPBaP6Nvz5twvhuDlhbUvNtwTF9Ex3S1vqWc/rUTDIY=; b=R/IyFYG+a4kzCSbNIotj8BgQpMkGX+UnNLN3T2geNnPRMWpS7/wQZk+BgN6X1h5wQF6wtROGaq+dTZHHXBePii0fLPRzqpTIXZYn7ZVmCjV4Rm1+AtFzGaocpc02ZaPaPZvrRBsUHC1Pdp+xb9dgOmTA9YDjh59Y5u6KWQkOFVw= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709152022366317.9129623147941; Wed, 28 Feb 2024 12:27:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfQUf-00080E-7W; Wed, 28 Feb 2024 15:25:33 -0500 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 1rfQUd-0007zv-HM for qemu-devel@nongnu.org; Wed, 28 Feb 2024 15:25:31 -0500 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfQUb-0007Mc-HQ for qemu-devel@nongnu.org; Wed, 28 Feb 2024 15:25:31 -0500 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-29a378040daso63075a91.1 for ; Wed, 28 Feb 2024 12:25:28 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id oh5-20020a17090b3a4500b0029ab712f648sm2118499pjb.38.2024.02.28.12.25.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 12:25:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709151928; x=1709756728; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uPBaP6Nvz5twvhuDlhbUvNtwTF9Ex3S1vqWc/rUTDIY=; b=vIk6xCZVq7QLKagEaxk/6V/AmZVmNtsMMSM63yYfmT9DPqfxQldSxocjOXqiTL5j0K pLmjEwt7qyQLy0biuaeNH5KDnWnrlr4lkrlvCYruwgoZq+MBaNZJKT7TNQUXCAbo1jsO 4BCLmvpYYYi56HVsA7TbTViOQkarhZrgMUvktvYeVTgxOyzkL8vBXLqlmGg05P8tPdMq maHCKjOnTo/u0fqt9LmUD3MGC1xElaMxag5KOkJBs/34hGZjAQcCzDCx3E25kbSH/lBX 2PygybeQgg8tibyXozliMqcfE558F0krZqNIEEHWzM74jcp0OaLz5VNCdK2UmhqY55nz vYDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709151928; x=1709756728; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uPBaP6Nvz5twvhuDlhbUvNtwTF9Ex3S1vqWc/rUTDIY=; b=a5+lCqFEWbS836Cv6Q7XaDDg2rcTyZs1GUzN+b8gj/n2aBJ2SRznWKbKmnvmR3GkDS lvP35BfUc81Ks+r5mN2qrZrEOx4lVC0lfd9CL1D8DW5UkiK1MehbJs91xFUa+vwDn7Dk ufT/hHPY4Bwoyh1fWzfBhRj7RnFw4qZPEL9N7cS0MJljUr0hvmW2F3YDR8D1U9GJQoge kzO8sE7Je+AjjSLaXZy0PcZYfLbu5gP9itKFGB9b0qFLWKf418m+a3uGF+uBKNgs4SAO YKEdqbhAqyPoCXtSzv4cfKCgg2Sgez99MS+QgpHR3r4//5nwIaXy1ISb+VTydJ9UiKh7 90ag== X-Gm-Message-State: AOJu0YzuTlH5PabBGiBRu4D3UmoMCbLzmwM7Xct8mu3Kt2DmpcVNhsxC lrQ+4Ag6I0ScIjKDcdk32Bu/S+ixOzl/Ar8LqRlLkEt2Vv4m+3RqwmQHu5DLyHJW69YQ8weKX4t Z X-Google-Smtp-Source: AGHT+IFvthCH2/jTS1/fq1T6qH3gqIG92ZgYOBDfSTpW9Lt4JOtDM7Ztd3jYNKaOmVpgg125piux8g== X-Received: by 2002:a17:90b:30c6:b0:29a:b67b:fe5e with SMTP id hi6-20020a17090b30c600b0029ab67bfe5emr235652pjb.36.1709151927903; Wed, 28 Feb 2024 12:25:27 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, richard.purdie@linuxfoundation.org, mjt@tls.msk.ru, iii@linux.ibm.com Subject: [PATCH v2 4/5] linux-user: Rewrite target_shmat Date: Wed, 28 Feb 2024 10:25:17 -1000 Message-Id: <20240228202518.33180-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228202518.33180-1-richard.henderson@linaro.org> References: <20240228202518.33180-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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 @linaro.org) X-ZM-MESSAGEID: 1709152023993100007 Content-Type: text/plain; charset="utf-8" Handle combined host and guest alignment requirements. Handle host and guest page size differences. Handle SHM_EXEC. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/115 Signed-off-by: Richard Henderson --- linux-user/mmap.c | 172 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 136 insertions(+), 36 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 82f4026283..4505fd7376 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -1236,69 +1236,161 @@ static inline abi_ulong target_shmlba(CPUArchState= *cpu_env) } #endif =20 +#if defined(__arm__) || defined(__mips__) || defined(__sparc__) +#define HOST_FORCE_SHMLBA 1 +#else +#define HOST_FORCE_SHMLBA 0 +#endif + abi_ulong target_shmat(CPUArchState *cpu_env, int shmid, abi_ulong shmaddr, int shmflg) { CPUState *cpu =3D env_cpu(cpu_env); - abi_ulong raddr; struct shmid_ds shm_info; int ret; - abi_ulong shmlba; + int h_pagesize; + int t_shmlba, h_shmlba, m_shmlba; + size_t t_len, h_len, m_len; =20 /* shmat pointers are always untagged */ =20 - /* find out the length of the shared memory segment */ + /* + * Because we can't use host shmat() unless the address is sufficiently + * aligned for the host, we'll need to check both. + * TODO: Could be fixed with softmmu. + */ + t_shmlba =3D target_shmlba(cpu_env); + h_pagesize =3D qemu_real_host_page_size(); + h_shmlba =3D (HOST_FORCE_SHMLBA ? SHMLBA : h_pagesize); + m_shmlba =3D MAX(t_shmlba, h_shmlba); + + if (shmaddr) { + if (shmaddr & (m_shmlba - 1)) { + if (shmflg & SHM_RND) { + /* + * The guest is allowing the kernel to round the address. + * Assume that the guest is ok with us rounding to the + * host required alignment too. Anyway if we don't, we'll + * get an error from the kernel. + */ + shmaddr &=3D ~(m_shmlba - 1); + if (shmaddr =3D=3D 0 && (shmflg & SHM_REMAP)) { + return -TARGET_EINVAL; + } + } else { + int require =3D TARGET_PAGE_SIZE; +#ifdef TARGET_FORCE_SHMLBA + require =3D t_shmlba; +#endif + /* + * Include host required alignment, as otherwise we cannot + * use host shmat at all. + */ + require =3D MAX(require, h_shmlba); + if (shmaddr & (require - 1)) { + return -TARGET_EINVAL; + } + } + } + } else { + if (shmflg & SHM_REMAP) { + return -TARGET_EINVAL; + } + } + /* All rounding now manually concluded. */ + shmflg &=3D ~SHM_RND; + + /* Find out the length of the shared memory segment. */ ret =3D get_errno(shmctl(shmid, IPC_STAT, &shm_info)); if (is_error(ret)) { /* can't get length, bail out */ return ret; } + t_len =3D TARGET_PAGE_ALIGN(shm_info.shm_segsz); + h_len =3D ROUND_UP(shm_info.shm_segsz, h_pagesize); + m_len =3D MAX(t_len, h_len); =20 - shmlba =3D target_shmlba(cpu_env); - - if (shmaddr & (shmlba - 1)) { - if (shmflg & SHM_RND) { - shmaddr &=3D ~(shmlba - 1); - } else { - return -TARGET_EINVAL; - } - } - if (!guest_range_valid_untagged(shmaddr, shm_info.shm_segsz)) { + if (!guest_range_valid_untagged(shmaddr, m_len)) { return -TARGET_EINVAL; } =20 WITH_MMAP_LOCK_GUARD() { - void *host_raddr; + bool mapped =3D false; + void *want, *test; abi_ulong last; =20 - if (shmaddr) { - host_raddr =3D shmat(shmid, (void *)g2h_untagged(shmaddr), shm= flg); - } else { - abi_ulong mmap_start; - - /* In order to use the host shmat, we need to honor host SHMLB= A. */ - mmap_start =3D mmap_find_vma(0, shm_info.shm_segsz, - MAX(SHMLBA, shmlba)); - - if (mmap_start =3D=3D -1) { + if (!shmaddr) { + shmaddr =3D mmap_find_vma(0, m_len, m_shmlba); + if (shmaddr =3D=3D -1) { return -TARGET_ENOMEM; } - host_raddr =3D shmat(shmid, g2h_untagged(mmap_start), - shmflg | SHM_REMAP); + mapped =3D !reserved_va; + } else if (shmflg & SHM_REMAP) { + /* + * If host page size > target page size, the host shmat may map + * more memory than the guest expects. Reject a mapping that + * would replace memory in the unexpected gap. + * TODO: Could be fixed with softmmu. + */ + if (t_len < h_len && + !page_check_range_empty(shmaddr + t_len, + shmaddr + h_len - 1)) { + return -TARGET_EINVAL; + } + } else { + if (!page_check_range_empty(shmaddr, shmaddr + m_len - 1)) { + return -TARGET_EINVAL; + } } =20 - if (host_raddr =3D=3D (void *)-1) { - return get_errno(-1); - } - raddr =3D h2g(host_raddr); - last =3D raddr + shm_info.shm_segsz - 1; + /* All placement is now complete. */ + want =3D (void *)g2h_untagged(shmaddr); =20 - page_set_flags(raddr, last, + /* + * Map anonymous pages across the entire range, then remap with + * the shared memory. This is required for a number of corner + * cases for which host and guest page sizes differ. + */ + if (h_len !=3D t_len) { + int mmap_p =3D PROT_READ | (shmflg & SHM_RDONLY ? 0 : PROT_WRI= TE); + int mmap_f =3D MAP_PRIVATE | MAP_ANONYMOUS + | (reserved_va || (shmflg & SHM_REMAP) + ? MAP_FIXED : MAP_FIXED_NOREPLACE); + + test =3D mmap(want, m_len, mmap_p, mmap_f, -1, 0); + if (unlikely(test !=3D want)) { + /* shmat returns EINVAL not EEXIST like mmap. */ + ret =3D (test =3D=3D MAP_FAILED && errno !=3D EEXIST + ? get_errno(-1) : -TARGET_EINVAL); + if (mapped) { + do_munmap(want, m_len); + } + return ret; + } + mapped =3D true; + } + + if (reserved_va || mapped) { + shmflg |=3D SHM_REMAP; + } + test =3D shmat(shmid, want, shmflg); + if (test =3D=3D MAP_FAILED) { + ret =3D get_errno(-1); + if (mapped) { + do_munmap(want, m_len); + } + return ret; + } + assert(test =3D=3D want); + + last =3D shmaddr + m_len - 1; + page_set_flags(shmaddr, last, PAGE_VALID | PAGE_RESET | PAGE_READ | - (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE)); + (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE) | + (shmflg & SHM_EXEC ? PAGE_EXEC : 0)); =20 - shm_region_rm_complete(raddr, last); - shm_region_add(raddr, last); + shm_region_rm_complete(shmaddr, last); + shm_region_add(shmaddr, last); } =20 /* @@ -1312,7 +1404,15 @@ abi_ulong target_shmat(CPUArchState *cpu_env, int sh= mid, tb_flush(cpu); } =20 - return raddr; + if (qemu_loglevel_mask(CPU_LOG_PAGE)) { + FILE *f =3D qemu_log_trylock(); + if (f) { + fprintf(f, "page layout changed following shmat\n"); + page_dump(f); + qemu_log_unlock(f); + } + } + return shmaddr; } =20 abi_long target_shmdt(abi_ulong shmaddr) --=20 2.34.1 From nobody Tue Nov 26 07:00:37 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=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709151987; cv=none; d=zohomail.com; s=zohoarc; b=fXptHEPuVmkJJROqWcniwhdLcwKA9B6IYCcuMzNN24LBllQGDouPVkphx3npuDvZvQiIVCfRqfCHDCKZKNOkq1aYkss9KxyPqqCpO5n+xvaAw+PlP3WAgaScvkRJaqMquvwT+4h99XfKQ/atKasAV4n/AKgLH6GIQP5BLRdGjVA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709151987; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=p6tPGvcWUCgEHkg4WhhgoNhXXsmKMPZyhGixNdkwuIE=; b=ULdn8Xq3KG/53ahmxGrYKWz3SoLvUm04zd7RWSG9imKAECSkRPKwZLyACD+iJD3DxOnPOSBC5Gg20Woy7TxyIu3KSlTonb0aG/VJGAOziEyHwM6GlIuHkLA6don4A+weiGl/luu5MuuwSVwI9L0jtTT0Zh/D3OBKNm5fbh1/tY4= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709151987891526.5803777923804; Wed, 28 Feb 2024 12:26:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfQUw-00087k-2U; Wed, 28 Feb 2024 15:25:51 -0500 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 1rfQUs-00086E-Ov for qemu-devel@nongnu.org; Wed, 28 Feb 2024 15:25:47 -0500 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfQUd-0007Mv-2K for qemu-devel@nongnu.org; Wed, 28 Feb 2024 15:25:46 -0500 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-5cfd95130c6so103368a12.1 for ; Wed, 28 Feb 2024 12:25:30 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id oh5-20020a17090b3a4500b0029ab712f648sm2118499pjb.38.2024.02.28.12.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 12:25:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709151929; x=1709756729; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=p6tPGvcWUCgEHkg4WhhgoNhXXsmKMPZyhGixNdkwuIE=; b=T4axga2FbF4om3bn1Y4hsgNRtmpOjBaUc4/NxeH+EEP0dtdxzMa8leX1rLiOPCadJr UafXs7ZNmgYCsdYndtyMgB/fse1N2+IJYQuJUjg+i1vZoczWhkjIX9SlVYtE1kw2lF9h hYU7/P3jPuRUZFYTs4cP8CdH7wStrQeZrYymAVLPNL57ECFQhTYJeWfWLPFu1wo8Ju5X FGnrGzKe9az6norOL3u4I61oxn6+0+gIiiwt+D6FQG6DVj52WQ2tMvSLiJM0hAWqPtaM vEWC0RANXD7QMVu7mLadL2wW7spVzHuv7mR+R3YUljAtZ7hl2KkeINAEQ9ag3FjoBLOb 84Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709151929; x=1709756729; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p6tPGvcWUCgEHkg4WhhgoNhXXsmKMPZyhGixNdkwuIE=; b=gTqmFA+Yloe7TveitLaMb+x34FgLzOTXB4FhzWE8PTxZ2VRXylShRm3x84vqJD5/ZL zXi3Ldu8CrWbBgaieoiLRUckuOZ3aS2tE9evWWZbS+iEltTha6M/ReFr0aJnUXQaJdmp cXNQnq5ddhcVaClptl5GXOPkOrsMIqD1bvpL14ajDBf5PX6nziA9sFCcsT51forgo0BW lQQNWBJlNeWHOvXYr+hjfg1PmrlR38HqjPT1e5lo510UZCxC5/sJR2OY7e9/lROZohz1 QjXWAXJNcpYDg69xrza6y5M8pdMMfPw5SeSfSeotLkxrYV3IVFaYcVa5ojv5HO0An8bH kE3w== X-Gm-Message-State: AOJu0YxhB3ONJeCg9pXBayDmE1jCDzz1+OqD9VkZT5lhKjG4G7Xv/y8U 0OBpbSUc9/Plq2RtM7Cyulw54uDDeM1r9jo+H3EFt0zJts5pOO9BjWUkPLz1sqFn1W88/ca3L64 h X-Google-Smtp-Source: AGHT+IFpLKEaiu7JuvZ8j3W1ZjVyxMMXEWIJpJnC0TU19pabpd4XPWCuEh4EQADC6JBJztYQ7+DxkQ== X-Received: by 2002:a17:90a:4206:b0:299:df2:66b2 with SMTP id o6-20020a17090a420600b002990df266b2mr262073pjg.22.1709151929447; Wed, 28 Feb 2024 12:25:29 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, richard.purdie@linuxfoundation.org, mjt@tls.msk.ru, iii@linux.ibm.com Subject: [PATCH v2 5/5] tests/tcg: Check that shmat() does not break /proc/self/maps Date: Wed, 28 Feb 2024 10:25:18 -1000 Message-Id: <20240228202518.33180-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228202518.33180-1-richard.henderson@linaro.org> References: <20240228202518.33180-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::52b; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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 @linaro.org) X-ZM-MESSAGEID: 1709151989867100003 Content-Type: text/plain; charset="utf-8" From: Ilya Leoshkevich Add a regression test for a recently fixed issue, where shmat() desynced the guest and the host view of the address space and caused open("/proc/self/maps") to SEGV. Signed-off-by: Ilya Leoshkevich Message-Id: Signed-off-by: Richard Henderson --- tests/tcg/multiarch/linux/linux-shmat-maps.c | 55 ++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/tcg/multiarch/linux/linux-shmat-maps.c diff --git a/tests/tcg/multiarch/linux/linux-shmat-maps.c b/tests/tcg/multi= arch/linux/linux-shmat-maps.c new file mode 100644 index 0000000000..0ccf7a973a --- /dev/null +++ b/tests/tcg/multiarch/linux/linux-shmat-maps.c @@ -0,0 +1,55 @@ +/* + * Test that shmat() does not break /proc/self/maps. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include +#include +#include +#include +#include +#include + +int main(void) +{ + char buf[128]; + int err, fd; + int shmid; + ssize_t n; + void *p; + + shmid =3D shmget(IPC_PRIVATE, 1, IPC_CREAT | 0600); + assert(shmid !=3D -1); + + /* + * The original bug required a non-NULL address, which skipped the + * mmap_find_vma step, which could result in a host mapping smaller + * than the target mapping. Choose an address at random. + */ + p =3D shmat(shmid, (void *)0x800000, SHM_RND); + if (p =3D=3D (void *)-1) { + /* + * Because we are now running the testcase for all guests for which + * we have a cross-compiler, the above random address might confli= ct + * with the guest executable in some way. Rather than stopping, + * continue with a system supplied address, which should never fai= l. + */ + p =3D shmat(shmid, NULL, 0); + assert(p !=3D (void *)-1); + } + + fd =3D open("/proc/self/maps", O_RDONLY); + assert(fd !=3D -1); + do { + n =3D read(fd, buf, sizeof(buf)); + assert(n >=3D 0); + } while (n !=3D 0); + close(fd); + + err =3D shmdt(p); + assert(err =3D=3D 0); + err =3D shmctl(shmid, IPC_RMID, NULL); + assert(err =3D=3D 0); + + return EXIT_SUCCESS; +} --=20 2.34.1