From patchwork Fri Jul 7 20:40:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700041 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4065312wrs; Fri, 7 Jul 2023 13:42:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlGY+AlitwdPRDY8rmN9uV7QdtclkxdvPXi5BXroOTwxskzz1W5kePf6gjAwTjDA7aTBO7x2 X-Received: by 2002:a05:6358:9184:b0:132:ce1f:6793 with SMTP id j4-20020a056358918400b00132ce1f6793mr7501298rwa.21.1688762532035; Fri, 07 Jul 2023 13:42:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762532; cv=none; d=google.com; s=arc-20160816; b=whkQGTOuPFVigY+5cOFKqtNyhm4oXuY1jsHlFc09Jax3UZrS6n8Hvk4wh3NP+ZUtl1 6QcMey4biVGjGZIXo7wjkyFLwmIsdgMQnFGQ+4nYfWXuIz3KRwtG4XKd8Mnc7kM3dh26 IQ9bql06MEjhAvgmgO/lL63Tqd8dcS6vtCxJPy2dj8rskImsJmHOvwhgYNGbcKaZ1b80 BkOWb0TKTWmlAHP+Rg0sO9iw8otSQb+sQkUyIM2nEM/FVWuU2dIuCgRcyaJTBAwKQUYA wHjxThBvL2NPis8cAJjVfscMrharoUJuFYrRk2n2SJHf9KZOPUkmgVvV97vus06t2pac tlYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Xqq6acmDez25lx55OCz0HM5T/6u0RG73b+x1AtLg/sQ=; fh=1lFznT7T8SaB6qvJwL+l8YZVr291z45CfOlDlCUV7JU=; b=hqBLeaROI4waDEmPCD1JYyCGWhmhjWjaZr2F8fYgjdWS8LtnbgN5ncIBy4YWpBY7aq toPoIZfdTsXTStuEcafHYHZHSEFR531ISxv6s8n+TVHLReZVc396gxVH5hZPZ/WGgnCQ eY6vHx4vYZrus6Yr53O8+mYUcAbYorMEYt3Ri4zI99eVxkFmw1ifnI7GsgLPZXKqgU8a Rgb4HPx0fo6/XKgrGcmM3tS9p6CLDpi2KDKHcRG9v+ycI/9L0Jza0dcgsWiMxNkYawny 1LcT+9/Ju8vVIHX+vZoP7Fhg4n3cGilSfdGg6mEHJ9EXhZ3dJTMe+Xv22ZLqFLyG0Gnq 8DBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UuH/qllR"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p8-20020a0ccb88000000b006300b838254si3191424qvk.38.2023.07.07.13.42.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:42:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UuH/qllR"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGF-0004ig-FN; Fri, 07 Jul 2023 16:41:03 -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 1qHsGC-0004hs-RA for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:00 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGB-0004ZM-1f for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:00 -0400 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-3143b88faebso2555863f8f.3 for ; Fri, 07 Jul 2023 13:40:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762457; x=1691354457; 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=Xqq6acmDez25lx55OCz0HM5T/6u0RG73b+x1AtLg/sQ=; b=UuH/qllR8Dd8ye4FXvsFtMOb9GOU+QIKw4+jmEs5gmtpkNBsX6Y93mhSJ3itwH7Hjj KH5VYeVKa/HPrbZnmRMW44fG2BR5gg83UvnpkqyhZO88mJPsBATb4/isRu+FxwiHtfCj nwoJjulL16xpbRkrXT0gZZZb31EBXGruKCUrH1ESiR+jxzxNHz8rm7t9+lBTc+7ls6nM Ih65hHCCD5brO+sCWQX6BQZFmJzkIOVf/DqppuIRh9r3zZy7AV0I0BOsmV/pj7/O70ho Rtq1sOACnfpuqwWFrut1oaTmqKkJzeRY3q1ZmuwY6fRzhwWLzAJp0Aw3+boLinkkKs/v ToGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762457; x=1691354457; 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=Xqq6acmDez25lx55OCz0HM5T/6u0RG73b+x1AtLg/sQ=; b=GPoAWDbkITIWRsGcH10yZF7lEDwxR4+LpE2gkzq3GYu5+KgRP9LTgK0aKID5x1kDAT 4NUlxkDlkAtsPNj8fOts+PfSXr4vKgLVfRS7HfAmsju6Dw1gOr9VDGlaRZWtKtdjj6Zd +/qPJEbnpsclK07wFB13StSn2OnycAfJfH9DLDY7f6plLP2Rffee20b9gGCULdMOIMNn pZWImpeDH5NaPY4ll5SlLb0GRcLkha4kA18m6UMPc3ZxiyNqmtODApwlwhsr9OH3nX2c N2NIhcJ47SXpXuI3HZDqxgeu7pHkmi4aevibxatWxaqCfxlDGnp2/lEZlnGfdIc4PpSm FqGw== X-Gm-Message-State: ABy/qLa3GcsmK0VieIFlp9oOrFNbqo6EYbKpP6QKcG1+OIkDhOygJgiL OUb4qfr4OgkZlmVAlanCOCg1ukwmhfuQb7jctthW0w== X-Received: by 2002:a05:600c:2102:b0:3fa:9538:963e with SMTP id u2-20020a05600c210200b003fa9538963emr4995728wml.36.1688762457686; Fri, 07 Jul 2023 13:40:57 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.40.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:40:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru, =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Subject: [PATCH v2 01/24] linux-user: Use assert in mmap_fork_start Date: Fri, 7 Jul 2023 21:40:30 +0100 Message-Id: <20230707204054.8792-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x433.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Assert is preferred over if+abort for the error message. Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/mmap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 2692936773..bae3dcdc27 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -49,8 +49,7 @@ bool have_mmap_lock(void) /* Grab lock to make sure things are in a consistent state after fork(). */ void mmap_fork_start(void) { - if (mmap_lock_count) - abort(); + assert(mmap_lock_count == 0); pthread_mutex_lock(&mmap_mutex); } From patchwork Fri Jul 7 20:40:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700036 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4064903wrs; Fri, 7 Jul 2023 13:41:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlEEfEHDsz55hDOdzIg2vS8qPLSBYy4cLHlXen/uBBvFFNWa0nrnBue+ary3HRM8SFlb6EIS X-Received: by 2002:a05:622a:1486:b0:403:2511:7d58 with SMTP id t6-20020a05622a148600b0040325117d58mr8090236qtx.9.1688762477281; Fri, 07 Jul 2023 13:41:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762477; cv=none; d=google.com; s=arc-20160816; b=t5EBblrHxD1Wy42ofBG1YxBgCR+3DI9UVsQycfpdrnX0NkyQ81JtPzPkC0w/kXtm6m eXXUMnruiM1C/8F0OtY6eoUju6iJDB71foSGjArZGmo58GyOUJeS+Hb0wh4IYCznNb/q 7vS6ifMbFHMLQtT1GkTt2jSJ4Ghsd/mYIdnF5nET1I3j5iukVid8GJPVM4sVwLr5NfOr IFWhgzEOndIt9oBm/X6eF+5pQRz0nDhV3S4uK1dUjtqgcomiL9OqIr/cJexH8ztXmWzF PYAnP4bV6EqiJ/1rjQU1gik5Vmkkwbmfsgd0ZE8uycw7qo+opXW+b1PFxuJA+Z9jIMvX Dogw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dswbdM8u0vKS5b/Y+xHQ8ysMGD+ac31F9xSR20ouNPw=; fh=1lFznT7T8SaB6qvJwL+l8YZVr291z45CfOlDlCUV7JU=; b=gZCIy2jTv+YMYGUq9syGagRI3lXDi+r6sog11LDuiFr6Art3HBHsCkYjVXueZrLUHF 74xUPaCGOtrQWBqpccJCgK7/nrCJHGEmCMMSLjL639LmKsm7qQWedhNd+pjTKkNVPMeo PMvTRUy9lRO6hKdt/6LGj/hYwXUzfBCVMHHa+t7AbPC0gjPrnxhOWoyDNOA/tB8MEla0 j0FtMGbz9Tlg6BS0+fttxR0q9Koe6V0HSwBc2Nq4iHaK55Ud3KaBImxKW9/vYpstG5Hi CgX8sYeCkb4nVPfBTMpopfOUbwfUI2oF6L+0S/y26qMV5klqRFKy0bsIaejPQIyzFMo8 umxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TLsL2UWu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j21-20020ac85c55000000b003f6b4123a25si3305381qtj.120.2023.07.07.13.41.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:41:17 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TLsL2UWu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGJ-0004kn-6d; Fri, 07 Jul 2023 16:41: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 1qHsGF-0004iU-AC for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:03 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGC-0004b4-Nu for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:03 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3fbc59de0e2so25201105e9.3 for ; Fri, 07 Jul 2023 13:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762459; x=1691354459; 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=dswbdM8u0vKS5b/Y+xHQ8ysMGD+ac31F9xSR20ouNPw=; b=TLsL2UWuibrdP1oJuf2jZN6fypg3tDFmFb4tvePpMpdfcycQQ83AbRfA9ohtuS6xvQ cN6691+t4zgLYlsCUfuN5do4viQQXANbu7or1WDbuHm8EHaSP0DvYqbYNpHr3QT3ZQgr +YYntCfF4VY8DNhy7I0D/3IcQI90A68iO+I+fQkPHllOZV4HY75EElZ0lL6qxeYciqOx D6VUatdfAvahKamg9zmCWxSixO5V7ci3gBLseNNX3j+AH8h3RCSUMLNqEgpC9enAcQH5 Vz6wZdYedvaqhcFVExg6w8ttwyt0nSOm4sHQcMAIpWMGfke+H3yfVkE/Gg9NDtSQPhpP Foeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762459; x=1691354459; 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=dswbdM8u0vKS5b/Y+xHQ8ysMGD+ac31F9xSR20ouNPw=; b=NdhlnPqYzjvj/JPYrxZbBGZASJNlF8uhwAYEP+tcyqNJGW592baZn198/Uj+1eihfP /A5ZB3RpMYgT1TCMn7+Y6er/c7xObl2VnsbdwYU8JBR1aP+mJKxf8BYRO3TdUIb6qTwQ E5mzyq8oQh4n1I+v7JEtHakQuIFPwlewCZ/sqk/78JerDHRetIcWad+nIwng8kbcsiRm s9yRe9AM4cqmfbBVxQaaH56dTYHhYS2VwMp9KbpLSIpMfp+CcLHbi3b/baUQrnOnqRj1 LgBDAAbsvjfI/agxlCjtZolyQN1RSQnkH8p6EObsHbRI+/yaRnhJyJ6TpwwFOL00gmtv Ockw== X-Gm-Message-State: ABy/qLaN9eDKHhOtNXfD96u1J4Jl+56ZL1papcoFEw/BLiauJobj3EDk XJ6g93AaXxIDBNolaTy4Qehg7M/EDKg32oQ+/GdyWw== X-Received: by 2002:a1c:6a12:0:b0:3fb:ba04:6d57 with SMTP id f18-20020a1c6a12000000b003fbba046d57mr4719994wmc.5.1688762459048; Fri, 07 Jul 2023 13:40:59 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:40:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru, =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Subject: [PATCH v2 02/24] linux-user: Fix formatting of mmap.c Date: Fri, 7 Jul 2023 21:40:32 +0100 Message-Id: <20230707204054.8792-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32a.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Fix all checkpatch.pl errors within mmap.c. Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/mmap.c | 199 ++++++++++++++++++++++++++++------------------ 1 file changed, 122 insertions(+), 77 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index bae3dcdc27..12275593a1 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -55,10 +55,11 @@ void mmap_fork_start(void) void mmap_fork_end(int child) { - if (child) + if (child) { pthread_mutex_init(&mmap_mutex, NULL); - else + } else { pthread_mutex_unlock(&mmap_mutex); + } } /* @@ -202,40 +203,47 @@ static int mmap_frag(abi_ulong real_start, /* get the protection of the target pages outside the mapping */ prot1 = 0; - for(addr = real_start; addr < real_end; addr++) { - if (addr < start || addr >= end) + for (addr = real_start; addr < real_end; addr++) { + if (addr < start || addr >= end) { prot1 |= page_get_flags(addr); + } } if (prot1 == 0) { /* no page was there, so we allocate one */ void *p = mmap(host_start, qemu_host_page_size, prot, flags | MAP_ANONYMOUS, -1, 0); - if (p == MAP_FAILED) + if (p == MAP_FAILED) { return -1; + } prot1 = prot; } prot1 &= PAGE_BITS; prot_new = prot | prot1; if (!(flags & MAP_ANONYMOUS)) { - /* msync() won't work here, so we return an error if write is - possible while it is a shared mapping */ - if ((flags & MAP_TYPE) == MAP_SHARED && - (prot & PROT_WRITE)) + /* + * msync() won't work here, so we return an error if write is + * possible while it is a shared mapping. + */ + if ((flags & MAP_TYPE) == MAP_SHARED && (prot & PROT_WRITE)) { return -1; + } /* adjust protection to be able to read */ - if (!(prot1 & PROT_WRITE)) + if (!(prot1 & PROT_WRITE)) { mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE); + } /* read the corresponding file data */ - if (pread(fd, g2h_untagged(start), end - start, offset) == -1) + if (pread(fd, g2h_untagged(start), end - start, offset) == -1) { return -1; + } /* put final protection */ - if (prot_new != (prot1 | PROT_WRITE)) + if (prot_new != (prot1 | PROT_WRITE)) { mprotect(host_start, qemu_host_page_size, prot_new); + } } else { if (prot_new != prot1) { mprotect(host_start, qemu_host_page_size, prot_new); @@ -264,8 +272,10 @@ abi_ulong mmap_next_start = TASK_UNMAPPED_BASE; unsigned long last_brk; -/* Subroutine of mmap_find_vma, used when we have pre-allocated a chunk - of guest address space. */ +/* + * Subroutine of mmap_find_vma, used when we have pre-allocated + * a chunk of guest address space. + */ static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size, abi_ulong align) { @@ -361,15 +371,17 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) * - shmat() with SHM_REMAP flag */ ptr = mmap(g2h_untagged(addr), size, PROT_NONE, - MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE, -1, 0); + MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE, -1, 0); /* ENOMEM, if host address space has no memory */ if (ptr == MAP_FAILED) { return (abi_ulong)-1; } - /* Count the number of sequential returns of the same address. - This is used to modify the search algorithm below. */ + /* + * Count the number of sequential returns of the same address. + * This is used to modify the search algorithm below. + */ repeat = (ptr == prev ? repeat + 1 : 0); if (h2g_valid(ptr + size - 1)) { @@ -386,14 +398,18 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) /* The address is not properly aligned for the target. */ switch (repeat) { case 0: - /* Assume the result that the kernel gave us is the - first with enough free space, so start again at the - next higher target page. */ + /* + * Assume the result that the kernel gave us is the + * first with enough free space, so start again at the + * next higher target page. + */ addr = ROUND_UP(addr, align); break; case 1: - /* Sometimes the kernel decides to perform the allocation - at the top end of memory instead. */ + /* + * Sometimes the kernel decides to perform the allocation + * at the top end of memory instead. + */ addr &= -align; break; case 2: @@ -406,8 +422,10 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) break; } } else { - /* Since the result the kernel gave didn't fit, start - again at low memory. If any repetition, fail. */ + /* + * Since the result the kernel gave didn't fit, start + * again at low memory. If any repetition, fail. + */ addr = (repeat ? -1 : 0); } @@ -422,8 +440,10 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) return (abi_ulong)-1; } wrapped = 1; - /* Don't actually use 0 when wrapping, instead indicate - that we'd truly like an allocation in low memory. */ + /* + * Don't actually use 0 when wrapping, instead indicate + * that we'd truly like an allocation in low memory. + */ addr = (mmap_min_addr > TARGET_PAGE_SIZE ? TARGET_PAGE_ALIGN(mmap_min_addr) : TARGET_PAGE_SIZE); @@ -484,8 +504,10 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, real_start = start & qemu_host_page_mask; host_offset = offset & qemu_host_page_mask; - /* If the user is asking for the kernel to find a location, do that - before we truncate the length for mapping files below. */ + /* + * If the user is asking for the kernel to find a location, do that + * before we truncate the length for mapping files below. + */ if (!(flags & MAP_FIXED)) { host_len = len + offset - host_offset; host_len = HOST_PAGE_ALIGN(host_len); @@ -496,32 +518,36 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, } } - /* When mapping files into a memory area larger than the file, accesses - to pages beyond the file size will cause a SIGBUS. - - For example, if mmaping a file of 100 bytes on a host with 4K pages - emulating a target with 8K pages, the target expects to be able to - access the first 8K. But the host will trap us on any access beyond - 4K. - - When emulating a target with a larger page-size than the hosts, we - may need to truncate file maps at EOF and add extra anonymous pages - up to the targets page boundary. */ - + /* + * When mapping files into a memory area larger than the file, accesses + * to pages beyond the file size will cause a SIGBUS. + * + * For example, if mmaping a file of 100 bytes on a host with 4K pages + * emulating a target with 8K pages, the target expects to be able to + * access the first 8K. But the host will trap us on any access beyond + * 4K. + * + * When emulating a target with a larger page-size than the hosts, we + * may need to truncate file maps at EOF and add extra anonymous pages + * up to the targets page boundary. + */ if ((qemu_real_host_page_size() < qemu_host_page_size) && !(flags & MAP_ANONYMOUS)) { struct stat sb; - if (fstat (fd, &sb) == -1) - goto fail; + if (fstat(fd, &sb) == -1) { + goto fail; + } - /* Are we trying to create a map beyond EOF?. */ - if (offset + len > sb.st_size) { - /* If so, truncate the file map at eof aligned with - the hosts real pagesize. Additional anonymous maps - will be created beyond EOF. */ - len = REAL_HOST_PAGE_ALIGN(sb.st_size - offset); - } + /* Are we trying to create a map beyond EOF?. */ + if (offset + len > sb.st_size) { + /* + * If so, truncate the file map at eof aligned with + * the hosts real pagesize. Additional anonymous maps + * will be created beyond EOF. + */ + len = REAL_HOST_PAGE_ALIGN(sb.st_size - offset); + } } if (!(flags & MAP_FIXED)) { @@ -531,9 +557,11 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, host_len = len + offset - host_offset; host_len = HOST_PAGE_ALIGN(host_len); - /* Note: we prefer to control the mapping address. It is - especially important if qemu_host_page_size > - qemu_real_host_page_size */ + /* + * Note: we prefer to control the mapping address. It is + * especially important if qemu_host_page_size > + * qemu_real_host_page_size. + */ p = mmap(g2h_untagged(start), host_len, host_prot, flags | MAP_FIXED | MAP_ANONYMOUS, -1, 0); if (p == MAP_FAILED) { @@ -571,45 +599,52 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, goto fail; } - /* worst case: we cannot map the file because the offset is not - aligned, so we read it */ + /* + * worst case: we cannot map the file because the offset is not + * aligned, so we read it + */ if (!(flags & MAP_ANONYMOUS) && (offset & ~qemu_host_page_mask) != (start & ~qemu_host_page_mask)) { - /* msync() won't work here, so we return an error if write is - possible while it is a shared mapping */ - if ((flags & MAP_TYPE) == MAP_SHARED && - (host_prot & PROT_WRITE)) { + /* + * msync() won't work here, so we return an error if write is + * possible while it is a shared mapping + */ + if ((flags & MAP_TYPE) == MAP_SHARED && (host_prot & PROT_WRITE)) { errno = EINVAL; goto fail; } retaddr = target_mmap(start, len, target_prot | PROT_WRITE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (retaddr == -1) + if (retaddr == -1) { goto fail; - if (pread(fd, g2h_untagged(start), len, offset) == -1) + } + if (pread(fd, g2h_untagged(start), len, offset) == -1) { goto fail; + } if (!(host_prot & PROT_WRITE)) { ret = target_mprotect(start, len, target_prot); assert(ret == 0); } goto the_end; } - + /* handle the start of the mapping */ if (start > real_start) { if (real_end == real_start + qemu_host_page_size) { /* one single host page */ ret = mmap_frag(real_start, start, end, host_prot, flags, fd, offset); - if (ret == -1) + if (ret == -1) { goto fail; + } goto the_end1; } ret = mmap_frag(real_start, start, real_start + qemu_host_page_size, host_prot, flags, fd, offset); - if (ret == -1) + if (ret == -1) { goto fail; + } real_start += qemu_host_page_size; } /* handle the end of the mapping */ @@ -618,8 +653,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, real_end - qemu_host_page_size, end, host_prot, flags, fd, offset + real_end - qemu_host_page_size - start); - if (ret == -1) + if (ret == -1) { goto fail; + } real_end -= qemu_host_page_size; } @@ -627,14 +663,16 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, if (real_start < real_end) { void *p; unsigned long offset1; - if (flags & MAP_ANONYMOUS) + if (flags & MAP_ANONYMOUS) { offset1 = 0; - else + } else { offset1 = offset + real_start - start; + } p = mmap(g2h_untagged(real_start), real_end - real_start, host_prot, flags, fd, offset1); - if (p == MAP_FAILED) + if (p == MAP_FAILED) { goto fail; + } passthrough_start = real_start; passthrough_end = real_end; } @@ -696,16 +734,18 @@ static void mmap_reserve(abi_ulong start, abi_ulong size) } end = real_end; } - if (prot != 0) + if (prot != 0) { real_start += qemu_host_page_size; + } } if (end < real_end) { prot = 0; for (addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) { prot |= page_get_flags(addr); } - if (prot != 0) + if (prot != 0) { real_end -= qemu_host_page_size; + } } if (real_start != real_end) { mmap(g2h_untagged(real_start), real_end - real_start, PROT_NONE, @@ -721,8 +761,9 @@ int target_munmap(abi_ulong start, abi_ulong len) trace_target_munmap(start, len); - if (start & ~TARGET_PAGE_MASK) + if (start & ~TARGET_PAGE_MASK) { return -TARGET_EINVAL; + } len = TARGET_PAGE_ALIGN(len); if (len == 0 || !guest_range_valid_untagged(start, len)) { return -TARGET_EINVAL; @@ -736,25 +777,27 @@ int target_munmap(abi_ulong start, abi_ulong len) if (start > real_start) { /* handle host page containing start */ prot = 0; - for(addr = real_start; addr < start; addr += TARGET_PAGE_SIZE) { + for (addr = real_start; addr < start; addr += TARGET_PAGE_SIZE) { prot |= page_get_flags(addr); } if (real_end == real_start + qemu_host_page_size) { - for(addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) { + for (addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) { prot |= page_get_flags(addr); } end = real_end; } - if (prot != 0) + if (prot != 0) { real_start += qemu_host_page_size; + } } if (end < real_end) { prot = 0; - for(addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) { + for (addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) { prot |= page_get_flags(addr); } - if (prot != 0) + if (prot != 0) { real_end -= qemu_host_page_size; + } } ret = 0; @@ -797,8 +840,10 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, flags, g2h_untagged(new_addr)); if (reserved_va && host_addr != MAP_FAILED) { - /* If new and old addresses overlap then the above mremap will - already have failed with EINVAL. */ + /* + * If new and old addresses overlap then the above mremap will + * already have failed with EINVAL. + */ mmap_reserve(old_addr, old_size); } } else if (flags & MREMAP_MAYMOVE) { From patchwork Fri Jul 7 20:40:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700061 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4066553wrs; Fri, 7 Jul 2023 13:45:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlHOZnJA4mcGWqCP91ZUnHv79frsPLrd+0Wf9DJS+VKll1g9wrtbpfVIkILWgcnzyHXuYkJJ X-Received: by 2002:a05:620a:240b:b0:767:1d7e:ec3d with SMTP id d11-20020a05620a240b00b007671d7eec3dmr10318092qkn.2.1688762740053; Fri, 07 Jul 2023 13:45:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762740; cv=none; d=google.com; s=arc-20160816; b=s/LzxbGf95SS/655Arwaoh+1pVRx68PK0juAX7jP3AOVHwNUW4VH5xixKtDgF/xLkK 3S+MKQTSS/EgTuSM6rII5FH/wBWXOot/855XTpcMNI3JGAAXkiAlZe6FLgEwuxTuPqqZ 54KW1z83v1viRKZdnxm3CPdGIdNLm7rf8d6qm+BuYI5FdXj2TsAUsgyFDBL8D1EdSBl8 QW+3XKP5jn+9uNv1AwQVfLzOKNhKUFc2J2aliY8/7vBkKPo3eATSUQnhGgU2/VJJCAE/ HzKpxpdeFWETT7Lp7OtlSYAcWdMpHBNrlPv0DONT8v+6Cp1XxmcUbX1xkur7gvqcx1Ad rpXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TuE92ojiCiB0kid/37dktEAllihSi6c5vwdjoHYShlU=; fh=Snw/yWAI/7AA6tppTg8XdyKlL779shjlYiHUTcQyZPQ=; b=r94sGtm5paFOduKopzfthRADm2j2GI1RnIvRVaCXsEaSAM2EUnQKnHMwPbIjQF9wbJ rmGYHamPwUSphEdZfKyM2GF+D2IPR2QJ3SDgjbbYP/0cjIMFaQd6bhXEmhf/+HQg/lNZ OCyDr21U29AJLO/N2B6N4u9khIIWcVJN2UBlUpDYyh4ZjuTi+LXEmdcYkxg9P7YR8g25 7TC9rtTkwIiBNNRGnLsI71CO5xEBs7gHriyQCvWAgKSveLmL9DllxdsvOHJtc7f8WXyh m985tPxNzmgQVPlcmLwCtOr4My0+8BlJX6+KaLiGpCwFFLhidV6NhTqhsZK96glTu+pw nxpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ydYqv60j; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x14-20020a0ce24e000000b00632229fe7dasi3168082qvl.327.2023.07.07.13.45.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:45:40 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ydYqv60j; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGH-0004kF-IK; Fri, 07 Jul 2023 16:41:05 -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 1qHsGF-0004iQ-8R for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:03 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGD-0004bz-DK for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:02 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3fbf7fbe722so23733785e9.3 for ; Fri, 07 Jul 2023 13:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762460; x=1691354460; 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=TuE92ojiCiB0kid/37dktEAllihSi6c5vwdjoHYShlU=; b=ydYqv60j2ssYBe54FIBdniEaujplpZ6maSi8R+KwDa5lxos39pgjHDAQA5Ii2fRv66 iJUTAYV3SQOObupbpTYdfaWhf8O9ePZSwi/mQd9l4nn2wKcv/sX8IuoTHyXaFiaD6+0k 7+MpTeeGwItzv1UywXyKp5EeDqnOCySzE0v5Lmc10Y9IZw+DKbi3HPcoJqZ9KGQTQTgy jpo1SuF5oMUuhKwFKuaT5HbPODp3KAlC/bsetyB06zVgSiHTVcogR3mW0Yu6KqE0qEoj VjyiU5vU0caRNhjTODcDLQBuRkUIaGR5B6rzpfDh9N1Cd9uwwqcGJ0StG1Ba3BAzaCr7 GQNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762460; x=1691354460; 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=TuE92ojiCiB0kid/37dktEAllihSi6c5vwdjoHYShlU=; b=LeTbKCOtgAr5i/k6hF80QzMrm9eoHoyxb5lVSN3bDmFSb2jLjC+GtEwXhKjq81JrUB 4ENjrRl1FyBQHfj+vLITkff5WPJ+4H1Iiqxu1jRBGAer5KuM/gQEhfKgTrZn+YqAs3CN 98DUjO9iNUUqwoBw8uFfnPhXOPQpBr4yoFLPGONadPJG1IbxzPIiz4x0z7xAlZcN0CyI XnAJgB9D7S5o+6haRSgzDn1WlQA1wJJipDeIm06cPSEZcSH1Nb0ZULlV4xG2yobm3mCV JHKmBelW2NukXV+hcFknUydRw6O7BtadpDO90tGH5BHWs4asyHQEkUwhlfERPtz5Odo+ WWlQ== X-Gm-Message-State: ABy/qLayTB+l63RISg2piGAP2EHF2FCYh7BNTTMQRgAfkd1XxBcJCImm Iomh5oLw/NStvK43w2GvQyCCYcPpmWCSEykzDlFZkg== X-Received: by 2002:a05:600c:2043:b0:3fc:25:ced6 with SMTP id p3-20020a05600c204300b003fc0025ced6mr2599849wmg.13.1688762459860; Fri, 07 Jul 2023 13:40:59 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:40:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru, =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v2 03/24] linux-user/strace: Expand struct flags to hold a mask Date: Fri, 7 Jul 2023 21:40:33 +0100 Message-Id: <20230707204054.8792-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32c.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org A zero bit value does not make sense -- it must relate to some field in some way. Define FLAG_BASIC with a build-time sanity check. Adjust FLAG_GENERIC and FLAG_TARGET to use it. Add FLAG_GENERIC_MASK and FLAG_TARGET_MASK. Fix up the existing flag definitions for build errors. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- linux-user/strace.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/linux-user/strace.c b/linux-user/strace.c index aad2b62ca4..566396d051 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -46,15 +46,21 @@ struct syscallname { */ struct flags { abi_long f_value; /* flag */ + abi_long f_mask; /* mask */ const char *f_string; /* stringified flag */ }; +/* No 'struct flags' element should have a zero mask. */ +#define FLAG_BASIC(V, M, N) { V, M | QEMU_BUILD_BUG_ON_ZERO(!(M)), N } + /* common flags for all architectures */ -#define FLAG_GENERIC(name) { name, #name } +#define FLAG_GENERIC_MASK(V, M) FLAG_BASIC(V, M, #V) +#define FLAG_GENERIC(V) FLAG_BASIC(V, V, #V) /* target specific flags (syscall_defs.h has TARGET_) */ -#define FLAG_TARGET(name) { TARGET_ ## name, #name } +#define FLAG_TARGET_MASK(V, M) FLAG_BASIC(TARGET_##V, TARGET_##M, #V) +#define FLAG_TARGET(V) FLAG_BASIC(TARGET_##V, TARGET_##V, #V) /* end of flags array */ -#define FLAG_END { 0, NULL } +#define FLAG_END { 0, 0, NULL } /* Structure used to translate enumerated values into strings */ struct enums { @@ -963,7 +969,7 @@ print_syscall_ret_ioctl(CPUArchState *cpu_env, const struct syscallname *name, #endif UNUSED static const struct flags access_flags[] = { - FLAG_GENERIC(F_OK), + FLAG_GENERIC_MASK(F_OK, R_OK | W_OK | X_OK), FLAG_GENERIC(R_OK), FLAG_GENERIC(W_OK), FLAG_GENERIC(X_OK), @@ -999,9 +1005,9 @@ UNUSED static const struct flags mode_flags[] = { }; UNUSED static const struct flags open_access_flags[] = { - FLAG_TARGET(O_RDONLY), - FLAG_TARGET(O_WRONLY), - FLAG_TARGET(O_RDWR), + FLAG_TARGET_MASK(O_RDONLY, O_ACCMODE), + FLAG_TARGET_MASK(O_WRONLY, O_ACCMODE), + FLAG_TARGET_MASK(O_RDWR, O_ACCMODE), FLAG_END, }; @@ -1010,7 +1016,9 @@ UNUSED static const struct flags open_flags[] = { FLAG_TARGET(O_CREAT), FLAG_TARGET(O_DIRECTORY), FLAG_TARGET(O_EXCL), +#if TARGET_O_LARGEFILE != 0 FLAG_TARGET(O_LARGEFILE), +#endif FLAG_TARGET(O_NOCTTY), FLAG_TARGET(O_NOFOLLOW), FLAG_TARGET(O_NONBLOCK), /* also O_NDELAY */ @@ -1075,7 +1083,7 @@ UNUSED static const struct flags umount2_flags[] = { }; UNUSED static const struct flags mmap_prot_flags[] = { - FLAG_GENERIC(PROT_NONE), + FLAG_GENERIC_MASK(PROT_NONE, PROT_READ | PROT_WRITE | PROT_EXEC), FLAG_GENERIC(PROT_EXEC), FLAG_GENERIC(PROT_READ), FLAG_GENERIC(PROT_WRITE), @@ -1103,7 +1111,7 @@ UNUSED static const struct flags mmap_flags[] = { #ifdef MAP_POPULATE FLAG_TARGET(MAP_POPULATE), #endif -#ifdef TARGET_MAP_UNINITIALIZED +#if defined(TARGET_MAP_UNINITIALIZED) && TARGET_MAP_UNINITIALIZED != 0 FLAG_TARGET(MAP_UNINITIALIZED), #endif FLAG_TARGET(MAP_HUGETLB), @@ -1201,13 +1209,13 @@ UNUSED static const struct flags statx_flags[] = { FLAG_GENERIC(AT_SYMLINK_NOFOLLOW), #endif #ifdef AT_STATX_SYNC_AS_STAT - FLAG_GENERIC(AT_STATX_SYNC_AS_STAT), + FLAG_GENERIC_MASK(AT_STATX_SYNC_AS_STAT, AT_STATX_SYNC_TYPE), #endif #ifdef AT_STATX_FORCE_SYNC - FLAG_GENERIC(AT_STATX_FORCE_SYNC), + FLAG_GENERIC_MASK(AT_STATX_FORCE_SYNC, AT_STATX_SYNC_TYPE), #endif #ifdef AT_STATX_DONT_SYNC - FLAG_GENERIC(AT_STATX_DONT_SYNC), + FLAG_GENERIC_MASK(AT_STATX_DONT_SYNC, AT_STATX_SYNC_TYPE), #endif FLAG_END, }; @@ -1481,14 +1489,10 @@ print_flags(const struct flags *f, abi_long flags, int last) const char *sep = ""; int n; - if ((flags == 0) && (f->f_value == 0)) { - qemu_log("%s%s", f->f_string, get_comma(last)); - return; - } for (n = 0; f->f_string != NULL; f++) { - if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) { + if ((flags & f->f_mask) == f->f_value) { qemu_log("%s%s", sep, f->f_string); - flags &= ~f->f_value; + flags &= ~f->f_mask; sep = "|"; n++; } From patchwork Fri Jul 7 20:40:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700037 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4064911wrs; Fri, 7 Jul 2023 13:41:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlHTnmrWbrKviEhrtMLP3X0/w6opN27f6XZVxaRrjWLHPWwY+Jz3C12JbVGdTSv1ZEUYHFsT X-Received: by 2002:a05:620a:4555:b0:765:4330:6e6c with SMTP id u21-20020a05620a455500b0076543306e6cmr7967783qkp.55.1688762478491; Fri, 07 Jul 2023 13:41:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762478; cv=none; d=google.com; s=arc-20160816; b=F7i+s188FolegsqfFU4JIDXy2Gl98+lGj7tsGbsuq454Rc11GG1GzEP/M3qm8NWXw+ 0LCrv1uTkIKpjKv+ETRm5GtbIayGfuoTtuUGKMgCDtxkiN9ebXYP/lRb2ZYAAEAH9rOw /VFhg2kPwmEACjw9hi5eYjtXyp8p6MlC7pP4pP5Kvo1keWuxlPFf/c076V1t/G3+ipLr Lv7KTbuuOzE/u60SJQ6KTfUkoobRXbw6GryYPLXZOH444vqzOlV7b7dPtNELUWOxzqB0 R1uaLyVP6LoQS7jetfb6+ef2va5xC9U067sAFCzUpnwjVBnbQd+E0xC4TEot1G1eB8r7 HrEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Xm/88LESveI60RzcZ8mZWBsO4QkC6Ygg53ln6ZnSnG0=; fh=Snw/yWAI/7AA6tppTg8XdyKlL779shjlYiHUTcQyZPQ=; b=w3qS849+69mzRvBDmqNwnWiTlTi8KoH62s7W8lWlpkxb5fTJkyFI8KiifkuJEj/xIH U0zEBwsl+u5o+uk4YjEHpmy3P+bPiykoTTntApd/9On0xbDctamStvptNMHO0LpN97kk x6Csw72AoKjzfHVhYJEQmtPP4S1u7H6ZNAKcr5R0vQk3fdNPJGKb+K+wxm+5nLqXrTK9 UOuaOKvDqdnkzQX1GQ4QgfbBGCJ7v1iytbRJq4qyCOfAB2GRXZ2XtY8eyZ58REEbN6s7 ml4r5pZaoESPA3pSK76mWM2akDPn52c1BI6l5L4SGX3tCt7WT35ts3uvW1TrBb/X/Jij y4iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="oUn/K4G6"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k5-20020ac85fc5000000b003e4488d669asi3116614qta.288.2023.07.07.13.41.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:41:18 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="oUn/K4G6"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGI-0004km-S9; Fri, 07 Jul 2023 16:41:06 -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 1qHsGG-0004jV-W7 for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:05 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGD-0004cd-Oa for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:04 -0400 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-313f1085ac2so2334991f8f.1 for ; Fri, 07 Jul 2023 13:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762460; x=1691354460; 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=Xm/88LESveI60RzcZ8mZWBsO4QkC6Ygg53ln6ZnSnG0=; b=oUn/K4G6KjOPfhLLuMyr5CvFbuEk9e3YTGFFPGaEzTiSKIW+LbOYWAd98USKNk5M9e MNvTYHZOOC2/coelMk5rwNFtPDSpLmccPNOgC7umF+h2DPNJXegY9JVkaQo3J7GPIYhC klkZo+lz/taJ9nhCUqCYpQXkuvYHPOnsU6SZ2BtDWos0VQuT0H7FBEzRYUS2jVxWukzC 25ReBA3AFmJJlazob8k1YCns6+hqMLJNek6Nj9kWpVRZpW0l7LDclAIVz2dZUNcuayhy prjVyj24UtRN8+OeaK7oKwYMcBUi9ypWKRFgQ9nBx9wV0vMwoYVEyTIu8fuaeDTHB1h3 4uEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762460; x=1691354460; 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=Xm/88LESveI60RzcZ8mZWBsO4QkC6Ygg53ln6ZnSnG0=; b=jBuuLPZ7/TWDGFEL+I8jJFGPW4GPjNKaVOSOLYjyGHjVskjo92Z158LqDl03Hfgm3o y8/C6RaEHQfBmbqR3CJzLXCcjYBPJjjZ3yRF3+AfjAWMZUWY7IYhxyutjyv3LI22BS/u LUlx3VACtSUuDnHD3a1pDb9fILnDh56PseBD/vmSwOTVC/J674bt2EjlUGpPHHHmkQkl hzkrwPUXs7SqYHIzyTvN51S4WQxTPO0DAm0dH6RRiGd3g3/2LuFcdHG/YgcMh5YJ+YYo 0O/aWsIo9Xv8yWZOJVFNKl8FFn21DqHpGOskKozsRVd8UGhPrIMdf9IBllLaeyPsOoze xLtw== X-Gm-Message-State: ABy/qLYwZOKF5Hak5N1cZORP0Q9HbvEN5WIU6JnIzOgXtlnSOw25n9eE xqM/c/wGMZU+mILaBfgMZbehqyrB3X6mh71UI5QQOQ== X-Received: by 2002:adf:e483:0:b0:314:1bb7:8a19 with SMTP id i3-20020adfe483000000b003141bb78a19mr4617443wrm.35.1688762460364; Fri, 07 Jul 2023 13:41:00 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru, =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v2 04/24] linux-user: Split TARGET_MAP_* out of syscall_defs.h Date: Fri, 7 Jul 2023 21:40:34 +0100 Message-Id: <20230707204054.8792-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x434.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Move the values into the per-target target_mman.h headers Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- linux-user/alpha/target_mman.h | 13 +++++ linux-user/generic/target_mman.h | 54 ++++++++++++++++++++ linux-user/hppa/target_mman.h | 10 ++++ linux-user/mips/target_mman.h | 11 +++++ linux-user/mips64/target_mman.h | 2 +- linux-user/ppc/target_mman.h | 3 ++ linux-user/sparc/target_mman.h | 4 ++ linux-user/syscall_defs.h | 85 +------------------------------- linux-user/xtensa/target_mman.h | 11 +++++ 9 files changed, 108 insertions(+), 85 deletions(-) diff --git a/linux-user/alpha/target_mman.h b/linux-user/alpha/target_mman.h index 051544f5ab..6bb03e7336 100644 --- a/linux-user/alpha/target_mman.h +++ b/linux-user/alpha/target_mman.h @@ -1,6 +1,19 @@ #ifndef ALPHA_TARGET_MMAN_H #define ALPHA_TARGET_MMAN_H +#define TARGET_MAP_ANONYMOUS 0x10 +#define TARGET_MAP_FIXED 0x100 +#define TARGET_MAP_GROWSDOWN 0x01000 +#define TARGET_MAP_DENYWRITE 0x02000 +#define TARGET_MAP_EXECUTABLE 0x04000 +#define TARGET_MAP_LOCKED 0x08000 +#define TARGET_MAP_NORESERVE 0x10000 +#define TARGET_MAP_POPULATE 0x20000 +#define TARGET_MAP_NONBLOCK 0x40000 +#define TARGET_MAP_STACK 0x80000 +#define TARGET_MAP_HUGETLB 0x100000 +#define TARGET_MAP_FIXED_NOREPLACE 0x200000 + #define TARGET_MADV_DONTNEED 6 #define TARGET_MS_ASYNC 1 diff --git a/linux-user/generic/target_mman.h b/linux-user/generic/target_mman.h index 32bf1a52d0..7b888fb7f8 100644 --- a/linux-user/generic/target_mman.h +++ b/linux-user/generic/target_mman.h @@ -1,6 +1,60 @@ #ifndef LINUX_USER_TARGET_MMAN_H #define LINUX_USER_TARGET_MMAN_H +/* These are defined in linux/mmap.h */ +#define TARGET_MAP_SHARED 0x01 +#define TARGET_MAP_PRIVATE 0x02 +#define TARGET_MAP_SHARED_VALIDATE 0x03 + +/* 0x0100 - 0x4000 flags are defined in asm-generic/mman.h */ +#ifndef TARGET_MAP_GROWSDOWN +#define TARGET_MAP_GROWSDOWN 0x0100 +#endif +#ifndef TARGET_MAP_DENYWRITE +#define TARGET_MAP_DENYWRITE 0x0800 +#endif +#ifndef TARGET_MAP_EXECUTABLE +#define TARGET_MAP_EXECUTABLE 0x1000 +#endif +#ifndef TARGET_MAP_LOCKED +#define TARGET_MAP_LOCKED 0x2000 +#endif +#ifndef TARGET_MAP_NORESERVE +#define TARGET_MAP_NORESERVE 0x4000 +#endif + +/* Other MAP flags are defined in asm-generic/mman-common.h */ +#ifndef TARGET_MAP_TYPE +#define TARGET_MAP_TYPE 0x0f +#endif +#ifndef TARGET_MAP_FIXED +#define TARGET_MAP_FIXED 0x10 +#endif +#ifndef TARGET_MAP_ANONYMOUS +#define TARGET_MAP_ANONYMOUS 0x20 +#endif +#ifndef TARGET_MAP_POPULATE +#define TARGET_MAP_POPULATE 0x008000 +#endif +#ifndef TARGET_MAP_NONBLOCK +#define TARGET_MAP_NONBLOCK 0x010000 +#endif +#ifndef TARGET_MAP_STACK +#define TARGET_MAP_STACK 0x020000 +#endif +#ifndef TARGET_MAP_HUGETLB +#define TARGET_MAP_HUGETLB 0x040000 +#endif +#ifndef TARGET_MAP_SYNC +#define TARGET_MAP_SYNC 0x080000 +#endif +#ifndef TARGET_MAP_FIXED_NOREPLACE +#define TARGET_MAP_FIXED_NOREPLACE 0x100000 +#endif +#ifndef TARGET_MAP_UNINITIALIZED +#define TARGET_MAP_UNINITIALIZED 0x4000000 +#endif + #ifndef TARGET_MADV_NORMAL #define TARGET_MADV_NORMAL 0 #endif diff --git a/linux-user/hppa/target_mman.h b/linux-user/hppa/target_mman.h index f9b6b97032..97f87d042a 100644 --- a/linux-user/hppa/target_mman.h +++ b/linux-user/hppa/target_mman.h @@ -1,6 +1,16 @@ #ifndef HPPA_TARGET_MMAN_H #define HPPA_TARGET_MMAN_H +#define TARGET_MAP_TYPE 0x2b +#define TARGET_MAP_FIXED 0x04 +#define TARGET_MAP_ANONYMOUS 0x10 +#define TARGET_MAP_GROWSDOWN 0x8000 +#define TARGET_MAP_POPULATE 0x10000 +#define TARGET_MAP_NONBLOCK 0x20000 +#define TARGET_MAP_STACK 0x40000 +#define TARGET_MAP_HUGETLB 0x80000 +#define TARGET_MAP_UNINITIALIZED 0 + #define TARGET_MADV_MERGEABLE 65 #define TARGET_MADV_UNMERGEABLE 66 #define TARGET_MADV_HUGEPAGE 67 diff --git a/linux-user/mips/target_mman.h b/linux-user/mips/target_mman.h index e7ba6070fe..d1d96decf5 100644 --- a/linux-user/mips/target_mman.h +++ b/linux-user/mips/target_mman.h @@ -1 +1,12 @@ +#define TARGET_MAP_NORESERVE 0x0400 +#define TARGET_MAP_ANONYMOUS 0x0800 +#define TARGET_MAP_GROWSDOWN 0x1000 +#define TARGET_MAP_DENYWRITE 0x2000 +#define TARGET_MAP_EXECUTABLE 0x4000 +#define TARGET_MAP_LOCKED 0x8000 +#define TARGET_MAP_POPULATE 0x10000 +#define TARGET_MAP_NONBLOCK 0x20000 +#define TARGET_MAP_STACK 0x40000 +#define TARGET_MAP_HUGETLB 0x80000 + #include "../generic/target_mman.h" diff --git a/linux-user/mips64/target_mman.h b/linux-user/mips64/target_mman.h index e7ba6070fe..7bdc47d902 100644 --- a/linux-user/mips64/target_mman.h +++ b/linux-user/mips64/target_mman.h @@ -1 +1 @@ -#include "../generic/target_mman.h" +#include "../mips/target_mman.h" diff --git a/linux-user/ppc/target_mman.h b/linux-user/ppc/target_mman.h index e7ba6070fe..c90be347f6 100644 --- a/linux-user/ppc/target_mman.h +++ b/linux-user/ppc/target_mman.h @@ -1 +1,4 @@ +#define TARGET_MAP_NORESERVE 0x40 +#define TARGET_MAP_LOCKED 0x80 + #include "../generic/target_mman.h" diff --git a/linux-user/sparc/target_mman.h b/linux-user/sparc/target_mman.h index e7ba6070fe..3fdee19d8a 100644 --- a/linux-user/sparc/target_mman.h +++ b/linux-user/sparc/target_mman.h @@ -1 +1,5 @@ +#define TARGET_MAP_NORESERVE 0x40 +#define TARGET_MAP_LOCKED 0x100 +#define TARGET_MAP_GROWSDOWN 0x0200 + #include "../generic/target_mman.h" diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index cc37054cb5..118a8ac7da 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -1262,90 +1262,7 @@ struct target_winsize { #define TARGET_PROT_MTE 0x20 #endif -/* Common */ -#define TARGET_MAP_SHARED 0x01 /* Share changes */ -#define TARGET_MAP_PRIVATE 0x02 /* Changes are private */ -#if defined(TARGET_HPPA) -#define TARGET_MAP_TYPE 0x03 /* Mask for type of mapping */ -#else -#define TARGET_MAP_TYPE 0x0f /* Mask for type of mapping */ -#endif - -/* Target specific */ -#if defined(TARGET_MIPS) -#define TARGET_MAP_FIXED 0x10 /* Interpret addr exactly */ -#define TARGET_MAP_ANONYMOUS 0x0800 /* don't use a file */ -#define TARGET_MAP_GROWSDOWN 0x1000 /* stack-like segment */ -#define TARGET_MAP_DENYWRITE 0x2000 /* ETXTBSY */ -#define TARGET_MAP_EXECUTABLE 0x4000 /* mark it as an executable */ -#define TARGET_MAP_LOCKED 0x8000 /* pages are locked */ -#define TARGET_MAP_NORESERVE 0x0400 /* don't check for reservations */ -#define TARGET_MAP_POPULATE 0x10000 /* populate (prefault) pagetables */ -#define TARGET_MAP_NONBLOCK 0x20000 /* do not block on IO */ -#define TARGET_MAP_STACK 0x40000 /* ignored */ -#define TARGET_MAP_HUGETLB 0x80000 /* create a huge page mapping */ -#elif defined(TARGET_PPC) -#define TARGET_MAP_FIXED 0x10 /* Interpret addr exactly */ -#define TARGET_MAP_ANONYMOUS 0x20 /* don't use a file */ -#define TARGET_MAP_GROWSDOWN 0x0100 /* stack-like segment */ -#define TARGET_MAP_DENYWRITE 0x0800 /* ETXTBSY */ -#define TARGET_MAP_EXECUTABLE 0x1000 /* mark it as an executable */ -#define TARGET_MAP_LOCKED 0x0080 /* pages are locked */ -#define TARGET_MAP_NORESERVE 0x0040 /* don't check for reservations */ -#define TARGET_MAP_POPULATE 0x8000 /* populate (prefault) pagetables */ -#define TARGET_MAP_NONBLOCK 0x10000 /* do not block on IO */ -#define TARGET_MAP_STACK 0x20000 /* ignored */ -#define TARGET_MAP_HUGETLB 0x40000 /* create a huge page mapping */ -#elif defined(TARGET_ALPHA) -#define TARGET_MAP_ANONYMOUS 0x10 /* don't use a file */ -#define TARGET_MAP_FIXED 0x100 /* Interpret addr exactly */ -#define TARGET_MAP_GROWSDOWN 0x01000 /* stack-like segment */ -#define TARGET_MAP_DENYWRITE 0x02000 /* ETXTBSY */ -#define TARGET_MAP_EXECUTABLE 0x04000 /* mark it as an executable */ -#define TARGET_MAP_LOCKED 0x08000 /* lock the mapping */ -#define TARGET_MAP_NORESERVE 0x10000 /* no check for reservations */ -#define TARGET_MAP_POPULATE 0x20000 /* pop (prefault) pagetables */ -#define TARGET_MAP_NONBLOCK 0x40000 /* do not block on IO */ -#define TARGET_MAP_STACK 0x80000 /* ignored */ -#define TARGET_MAP_HUGETLB 0x100000 /* create a huge page mapping */ -#elif defined(TARGET_HPPA) -#define TARGET_MAP_ANONYMOUS 0x10 /* don't use a file */ -#define TARGET_MAP_FIXED 0x04 /* Interpret addr exactly */ -#define TARGET_MAP_GROWSDOWN 0x08000 /* stack-like segment */ -#define TARGET_MAP_DENYWRITE 0x00800 /* ETXTBSY */ -#define TARGET_MAP_EXECUTABLE 0x01000 /* mark it as an executable */ -#define TARGET_MAP_LOCKED 0x02000 /* lock the mapping */ -#define TARGET_MAP_NORESERVE 0x04000 /* no check for reservations */ -#define TARGET_MAP_POPULATE 0x10000 /* pop (prefault) pagetables */ -#define TARGET_MAP_NONBLOCK 0x20000 /* do not block on IO */ -#define TARGET_MAP_STACK 0x40000 /* ignored */ -#define TARGET_MAP_HUGETLB 0x80000 /* create a huge page mapping */ -#elif defined(TARGET_XTENSA) -#define TARGET_MAP_FIXED 0x10 /* Interpret addr exactly */ -#define TARGET_MAP_ANONYMOUS 0x0800 /* don't use a file */ -#define TARGET_MAP_GROWSDOWN 0x1000 /* stack-like segment */ -#define TARGET_MAP_DENYWRITE 0x2000 /* ETXTBSY */ -#define TARGET_MAP_EXECUTABLE 0x4000 /* mark it as an executable */ -#define TARGET_MAP_LOCKED 0x8000 /* pages are locked */ -#define TARGET_MAP_NORESERVE 0x0400 /* don't check for reservations */ -#define TARGET_MAP_POPULATE 0x10000 /* populate (prefault) pagetables */ -#define TARGET_MAP_NONBLOCK 0x20000 /* do not block on IO */ -#define TARGET_MAP_STACK 0x40000 -#define TARGET_MAP_HUGETLB 0x80000 /* create a huge page mapping */ -#else -#define TARGET_MAP_FIXED 0x10 /* Interpret addr exactly */ -#define TARGET_MAP_ANONYMOUS 0x20 /* don't use a file */ -#define TARGET_MAP_GROWSDOWN 0x0100 /* stack-like segment */ -#define TARGET_MAP_DENYWRITE 0x0800 /* ETXTBSY */ -#define TARGET_MAP_EXECUTABLE 0x1000 /* mark it as an executable */ -#define TARGET_MAP_LOCKED 0x2000 /* pages are locked */ -#define TARGET_MAP_NORESERVE 0x4000 /* don't check for reservations */ -#define TARGET_MAP_POPULATE 0x8000 /* populate (prefault) pagetables */ -#define TARGET_MAP_NONBLOCK 0x10000 /* do not block on IO */ -#define TARGET_MAP_STACK 0x20000 /* ignored */ -#define TARGET_MAP_HUGETLB 0x40000 /* create a huge page mapping */ -#define TARGET_MAP_UNINITIALIZED 0x4000000 /* for anonymous mmap, memory could be uninitialized */ -#endif +#include "target_mman.h" #if (defined(TARGET_I386) && defined(TARGET_ABI32)) \ || (defined(TARGET_ARM) && defined(TARGET_ABI32)) \ diff --git a/linux-user/xtensa/target_mman.h b/linux-user/xtensa/target_mman.h index e7ba6070fe..d1d96decf5 100644 --- a/linux-user/xtensa/target_mman.h +++ b/linux-user/xtensa/target_mman.h @@ -1 +1,12 @@ +#define TARGET_MAP_NORESERVE 0x0400 +#define TARGET_MAP_ANONYMOUS 0x0800 +#define TARGET_MAP_GROWSDOWN 0x1000 +#define TARGET_MAP_DENYWRITE 0x2000 +#define TARGET_MAP_EXECUTABLE 0x4000 +#define TARGET_MAP_LOCKED 0x8000 +#define TARGET_MAP_POPULATE 0x10000 +#define TARGET_MAP_NONBLOCK 0x20000 +#define TARGET_MAP_STACK 0x40000 +#define TARGET_MAP_HUGETLB 0x80000 + #include "../generic/target_mman.h" From patchwork Fri Jul 7 20:40:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700048 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4065824wrs; Fri, 7 Jul 2023 13:43:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlG991SpQ1+WAc3hziOVfBciNUBQoL9RMNXctPYlUnI6DBrak0XiQ2OeYSy7jKsNCSno0ZWw X-Received: by 2002:ac8:5fc5:0:b0:3f5:31c9:2578 with SMTP id k5-20020ac85fc5000000b003f531c92578mr7924034qta.67.1688762610664; Fri, 07 Jul 2023 13:43:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762610; cv=none; d=google.com; s=arc-20160816; b=Xvz11lA2tBf5o+pMPFYALtWBlbXC01KZKzxprlXWoDLUBi5A7tiG7NenCSLGvkHvGf H8ZhRmmV77BWCMSIdYJnKGSkPkBNR8QN/HC6BzM6hJ71Hc1aFji8xhywzpQBTPCmJGd0 tn9jTGBjQiv6Ty7H2NdEUCSDjkGIzAlafTu2KxcN/5E2yC212J5WOi4U/PSh3H4mDNw7 d0irQCw/wX04PDY7sAs0J43EsWI3nOaF9CcVJFP5ftWOhzyfQOZOGK98TmyA4foWDZ7z q4b7Atofubwsa/j9MlEZdSpdqbkW4h7AjnKkPAIaPjIvmVjck+94iWF0HsKcaryDs3lQ olGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mY6tTuYQJnWBze2KXsMQEugLPFruzX0150L5BphLiXg=; fh=1lFznT7T8SaB6qvJwL+l8YZVr291z45CfOlDlCUV7JU=; b=G+LFJ/sTpU3eo1plQIbDU+sykN5aT5r1XaTA0YGKdxJTl8IFF9T0vHdqdWS+WPOj2o bcNsiO09ICiSKFkSSZmCI7CU8+JUWKAUgJZqSv5PR0Pn5PQwkcOy7/9po2MnzdTU98lJ sR346Je9daPSqrug0DVq8cC7frEUzdFXNysTWChg8gS797Wp4UmDkjr+Tfe3QGHs/X84 HPcaxGL/SCC2jRnHlF5+B3Zg4iQD3sUc433/D58u1yIO9OOmxPS4jb6hROviX/80A3HQ iUF3F5BzN1hDpxNgIu2z/w9xA456BnNcYYEbY7ffaT4nzK29gwgxwTQZfwtBtPl2NqFp O9Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gGKHZ8Vm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s34-20020a05622a1aa200b00403489b9d8fsi3016425qtc.472.2023.07.07.13.43.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:43:30 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gGKHZ8Vm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGJ-0004kr-Hu; Fri, 07 Jul 2023 16:41: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 1qHsGG-0004j4-9b for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:04 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGE-0004dL-FG for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:03 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-3fbca8935bfso25736075e9.3 for ; Fri, 07 Jul 2023 13:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762461; x=1691354461; 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=mY6tTuYQJnWBze2KXsMQEugLPFruzX0150L5BphLiXg=; b=gGKHZ8VmW2tSaGVmW6c99QAmNI24HmOYeTjAJDacfVqMLr5LtBR+yEegcqGOTv07Fb ZyqUQcc9EwKeBqg7q4MgelxJ14cju6WcGvl661hx0zq6fkYWhMWhp6aj5AtyNB7WssmZ eIz93QDUb6A30tQIDaz1g45AANR7AAia8cGwtQVOlY6v0nOW/suHPsV+bfbb0/JhCv/z 3PDXKDIi7Ib4cZivuwwUbwG7EGEG7h+/lG55C+MBZ15nJ/26i4P6I2Wpl2ZKGy/AUzbR zgd2VXvq/Oh+aJ/eIMnSfHWxYneFerAJm6KcQuJWpqI4vJWY3Ogbuuw4kc09JD/KxbCm 66fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762461; x=1691354461; 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=mY6tTuYQJnWBze2KXsMQEugLPFruzX0150L5BphLiXg=; b=a+FSQVcZ3mj7j7CnJQB/5hG7J4S4cVNQQeZxpW+aHnuRwMmgHd76l/Yc4Q3SJSe1qz 5VjW6C+iNvVOtt7dXkCthknMq6f6jW2bmvaYncAMSlsPsQYjTix5zDnUoRGAIyzs+LoI pQVQRBzpMFonQu5W0EuiSaZeJ0JwWWUWeGGsRM/gDIemuVy5a357tEirJ3t7iDLHhUG5 aqgkBQ2AGQC5r6kypyrzlTMSxKth2zjwQ6wQT/b5k3va/Zxhddaexm9ahTGO5rtSPJ/t /PwKsy3uTVbiYLO3yBXeLfEl4LLFhzODk/2pwqPvKhTFwZicy2rgYI/nWJf5LQiIViA2 TNcw== X-Gm-Message-State: ABy/qLariwm6mRlUvDEMlcvRiAntGm0Ypc36CHkHa+oemdkG9c8ufD+j 0hkqz2F834dEiWbt9m90k2rMd5E40NHREDrbcMwqmw== X-Received: by 2002:a7b:c3d7:0:b0:3fb:a6ee:4cec with SMTP id t23-20020a7bc3d7000000b003fba6ee4cecmr4499416wmj.33.1688762460838; Fri, 07 Jul 2023 13:41:00 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru, =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Subject: [PATCH v2 05/24] linux-user: Split TARGET_PROT_* out of syscall_defs.h Date: Fri, 7 Jul 2023 21:40:35 +0100 Message-Id: <20230707204054.8792-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x335.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Move the values into the per-target target_mman.h headers Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/aarch64/target_mman.h | 3 +++ linux-user/generic/target_mman.h | 4 ++++ linux-user/mips/target_mman.h | 2 ++ linux-user/syscall_defs.h | 11 ----------- linux-user/xtensa/target_mman.h | 2 ++ 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/linux-user/aarch64/target_mman.h b/linux-user/aarch64/target_mman.h index e7ba6070fe..7f15cab25e 100644 --- a/linux-user/aarch64/target_mman.h +++ b/linux-user/aarch64/target_mman.h @@ -1 +1,4 @@ +#define TARGET_PROT_BTI 0x10 +#define TARGET_PROT_MTE 0x20 + #include "../generic/target_mman.h" diff --git a/linux-user/generic/target_mman.h b/linux-user/generic/target_mman.h index 7b888fb7f8..39a650e751 100644 --- a/linux-user/generic/target_mman.h +++ b/linux-user/generic/target_mman.h @@ -1,6 +1,10 @@ #ifndef LINUX_USER_TARGET_MMAN_H #define LINUX_USER_TARGET_MMAN_H +#ifndef TARGET_PROT_SEM +#define TARGET_PROT_SEM 0x08 +#endif + /* These are defined in linux/mmap.h */ #define TARGET_MAP_SHARED 0x01 #define TARGET_MAP_PRIVATE 0x02 diff --git a/linux-user/mips/target_mman.h b/linux-user/mips/target_mman.h index d1d96decf5..e9f3905a52 100644 --- a/linux-user/mips/target_mman.h +++ b/linux-user/mips/target_mman.h @@ -1,3 +1,5 @@ +#define TARGET_PROT_SEM 0x10 + #define TARGET_MAP_NORESERVE 0x0400 #define TARGET_MAP_ANONYMOUS 0x0800 #define TARGET_MAP_GROWSDOWN 0x1000 diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 118a8ac7da..9387ed422d 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -1251,17 +1251,6 @@ struct target_winsize { #include "termbits.h" -#if defined(TARGET_MIPS) || defined(TARGET_XTENSA) -#define TARGET_PROT_SEM 0x10 -#else -#define TARGET_PROT_SEM 0x08 -#endif - -#ifdef TARGET_AARCH64 -#define TARGET_PROT_BTI 0x10 -#define TARGET_PROT_MTE 0x20 -#endif - #include "target_mman.h" #if (defined(TARGET_I386) && defined(TARGET_ABI32)) \ diff --git a/linux-user/xtensa/target_mman.h b/linux-user/xtensa/target_mman.h index d1d96decf5..e9f3905a52 100644 --- a/linux-user/xtensa/target_mman.h +++ b/linux-user/xtensa/target_mman.h @@ -1,3 +1,5 @@ +#define TARGET_PROT_SEM 0x10 + #define TARGET_MAP_NORESERVE 0x0400 #define TARGET_MAP_ANONYMOUS 0x0800 #define TARGET_MAP_GROWSDOWN 0x1000 From patchwork Fri Jul 7 20:40:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700044 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4065538wrs; Fri, 7 Jul 2023 13:42:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlF4ptaebQL4HpK5WaYxyMWUwHh4zgMjMOJ0jlyD3FVHhxDUMvBniWzAY3qMujF/jCPP8ENb X-Received: by 2002:ac8:5c45:0:b0:3f6:c609:e9da with SMTP id j5-20020ac85c45000000b003f6c609e9damr7237698qtj.44.1688762561647; Fri, 07 Jul 2023 13:42:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762561; cv=none; d=google.com; s=arc-20160816; b=FoBLCEnQKMve4fJTUOXmBv9hPeGMb76XFTyy++AttM2bEWSHAMFPtTlk3TIqGTFG5l QazJZyazoTa54HTIo5Pl1bFbWIwH/ANbWkIrgRVmW0bAj3OfCD4WR+tR7u6lHm/y5jw5 kmwmcpy44P1VLGwVaDTbScUtulONf9aUIVi0axIfqptXDZam9G53umLMZA6NNvoacCke VcE8xgXpHUTy5U3H5N8ljy84B3CMVeTYxejUIvBRJOPSXKEtX953UODKb77jw+PpksoJ olaycjdVirU6wgRWMJhODK3LrggQF59Ek0fx4La21azv748rHTDsb5aRQdsPq2xRVZJk KBtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=b2kxpoTo/D6lAeqPJxWGsbdox8UTpGN/fykOYkONe80=; fh=Snw/yWAI/7AA6tppTg8XdyKlL779shjlYiHUTcQyZPQ=; b=C+SA1jFHZTOeKA80EKaTmzSuerDzZ5KlF/fUF95WwOFCDqqTFsSeMpck6ykVeEOP8W 9yV3FbfSHRJG3mfgBBf6STdi62wBFGZyIPRU+Sfbh679GWy1Rs4vXt9kr/YKOfoZ1qXL pNNV+jw6sFjO97iRINYKKFCtfc7i7bJIsNouE4RplPMvbvemx/Vuyw7TxQPoWRoV2E3n r4Ex4HNEsZxUZjJE8jqquuAmF9ZT3SVnmKJEvCXoS7yT0BArtCD17UQgo9JOowLA8FJn Ib5yLR+Pv7Q7C0jqHie7oGOv0cjbZXrmiL/F03pEpu0OXpm6QaGKTQEpn8kKxLHjNn2i VIpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eSf0ydDe; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e19-20020a05622a111300b004021c5962f6si3154533qty.422.2023.07.07.13.42.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:42:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eSf0ydDe; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGJ-0004mg-Tv; Fri, 07 Jul 2023 16:41: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 1qHsGG-0004j7-KZ for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:04 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGE-0004e2-Rm for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:04 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3fbc6ab5ff5so25328905e9.1 for ; Fri, 07 Jul 2023 13:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762461; x=1691354461; 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=b2kxpoTo/D6lAeqPJxWGsbdox8UTpGN/fykOYkONe80=; b=eSf0ydDeKFGinF4i7T4iQAz0VkndFzqqlUdrTnjvGdATg2a01+ecgaVy4ZM61YCOW6 GFGJSczA382gPKWJeYUmH+6CkbSnbM4ZDOpM7vZ23+wiX/Kplp16XUZUV7ku55uBL3BZ uxa4GEBGM9vicrJiJEcDcbG3NbrCXUgazYr3vgf9t+ss21iG37SdK1ZCTyMBi7BulyfB 7aPj3xaSHwKdM4fDWcmqRwlhHulNRkN2d9NQLRo3RdSNoUrfSMGZeTg1dFbzCWmzgWwU ppa8bUZRvsJkZy0JyFuFbFBjmrdUxzKX/pufbxzm6BhuuLNn37nHOEnc6EfX2UzLgNRR FuDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762461; x=1691354461; 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=b2kxpoTo/D6lAeqPJxWGsbdox8UTpGN/fykOYkONe80=; b=UE8Oi9P8R2Fey+ZYEog56qPYTsLVBmAMVwltGOxT51iYgE8umWFHPEdPfKTmQnrldU GhlLM2DLi7UQ2B8IKx/P6sT+gAkwpQc7K+pvOjY8mcrdtllMWzaHoPIWl/rr3L3Eeyar mop5f07QwkRcg8akMlRYluk0/IyxP5xTtoP1ZbzyNhskVsQDRoie76sK4TSM6hNN/CWn /TZp4OCxCciz9CTGuIeygCtKdV2WyEQek0ne0kAPAloAEkfVVLeH+wx5TOdJGG82N9Q9 3NSbmY2XPZveDTd9DcHfNMuWhxhJfCs90lx3l+dmAms/RmntzOco3+Hf+mRDOMz9idBy UQZQ== X-Gm-Message-State: ABy/qLZrovdObEgLvS+9gkvlRo+V1PYyviImlGPik/QzOZG8hWSNfRGh 783edkjffizAxIOuDiNuvoG1p4M5pDtXpn15frbGjA== X-Received: by 2002:a05:600c:210a:b0:3f6:58ad:ed85 with SMTP id u10-20020a05600c210a00b003f658aded85mr4664061wml.10.1688762461345; Fri, 07 Jul 2023 13:41:01 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru, =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v2 06/24] linux-user: Populate more bits in mmap_flags_tbl Date: Fri, 7 Jul 2023 21:40:36 +0100 Message-Id: <20230707204054.8792-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x331.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, UPPERCASE_50_75=0.008 autolearn=no 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Fix translation of TARGET_MAP_SHARED and TARGET_MAP_PRIVATE, which are types not single bits. Add TARGET_MAP_SHARED_VALIDATE, TARGET_MAP_SYNC, TARGET_MAP_NONBLOCK, TARGET_MAP_POPULATE, TARGET_MAP_FIXED_NOREPLACE, and TARGET_MAP_UNINITIALIZED. Update strace to match. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- linux-user/strace.c | 23 ++++++++++------------- linux-user/syscall.c | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/linux-user/strace.c b/linux-user/strace.c index 566396d051..af5c5f135b 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -1094,28 +1094,25 @@ UNUSED static const struct flags mmap_prot_flags[] = { }; UNUSED static const struct flags mmap_flags[] = { - FLAG_TARGET(MAP_SHARED), - FLAG_TARGET(MAP_PRIVATE), + FLAG_TARGET_MASK(MAP_SHARED, MAP_TYPE), + FLAG_TARGET_MASK(MAP_PRIVATE, MAP_TYPE), + FLAG_TARGET_MASK(MAP_SHARED_VALIDATE, MAP_TYPE), FLAG_TARGET(MAP_ANONYMOUS), FLAG_TARGET(MAP_DENYWRITE), - FLAG_TARGET(MAP_FIXED), - FLAG_TARGET(MAP_GROWSDOWN), FLAG_TARGET(MAP_EXECUTABLE), -#ifdef MAP_LOCKED + FLAG_TARGET(MAP_FIXED), + FLAG_TARGET(MAP_FIXED_NOREPLACE), + FLAG_TARGET(MAP_GROWSDOWN), + FLAG_TARGET(MAP_HUGETLB), FLAG_TARGET(MAP_LOCKED), -#endif -#ifdef MAP_NONBLOCK FLAG_TARGET(MAP_NONBLOCK), -#endif FLAG_TARGET(MAP_NORESERVE), -#ifdef MAP_POPULATE FLAG_TARGET(MAP_POPULATE), -#endif -#if defined(TARGET_MAP_UNINITIALIZED) && TARGET_MAP_UNINITIALIZED != 0 + FLAG_TARGET(MAP_STACK), + FLAG_TARGET(MAP_SYNC), +#if TARGET_MAP_UNINITIALIZED != 0 FLAG_TARGET(MAP_UNINITIALIZED), #endif - FLAG_TARGET(MAP_HUGETLB), - FLAG_TARGET(MAP_STACK), FLAG_END, }; diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 08162cc966..2c0c6e745e 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6002,9 +6002,16 @@ static const StructEntry struct_termios_def = { .print = print_termios, }; +/* If the host does not provide these bits, they may be safely discarded. */ +#ifndef MAP_UNINITIALIZED +#define MAP_UNINITIALIZED 0 +#endif + static const bitmask_transtbl mmap_flags_tbl[] = { - { TARGET_MAP_SHARED, TARGET_MAP_SHARED, MAP_SHARED, MAP_SHARED }, - { TARGET_MAP_PRIVATE, TARGET_MAP_PRIVATE, MAP_PRIVATE, MAP_PRIVATE }, + { TARGET_MAP_TYPE, TARGET_MAP_SHARED, MAP_TYPE, MAP_SHARED }, + { TARGET_MAP_TYPE, TARGET_MAP_PRIVATE, MAP_TYPE, MAP_PRIVATE }, + { TARGET_MAP_TYPE, TARGET_MAP_SHARED_VALIDATE, + MAP_TYPE, MAP_SHARED_VALIDATE }, { TARGET_MAP_FIXED, TARGET_MAP_FIXED, MAP_FIXED, MAP_FIXED }, { TARGET_MAP_ANONYMOUS, TARGET_MAP_ANONYMOUS, MAP_ANONYMOUS, MAP_ANONYMOUS }, @@ -6022,6 +6029,13 @@ static const bitmask_transtbl mmap_flags_tbl[] = { Recognize it for the target insofar as we do not want to pass it through to the host. */ { TARGET_MAP_STACK, TARGET_MAP_STACK, 0, 0 }, + { TARGET_MAP_SYNC, TARGET_MAP_SYNC, MAP_SYNC, MAP_SYNC }, + { TARGET_MAP_NONBLOCK, TARGET_MAP_NONBLOCK, MAP_NONBLOCK, MAP_NONBLOCK }, + { TARGET_MAP_POPULATE, TARGET_MAP_POPULATE, MAP_POPULATE, MAP_POPULATE }, + { TARGET_MAP_FIXED_NOREPLACE, TARGET_MAP_FIXED_NOREPLACE, + MAP_FIXED_NOREPLACE, MAP_FIXED_NOREPLACE }, + { TARGET_MAP_UNINITIALIZED, TARGET_MAP_UNINITIALIZED, + MAP_UNINITIALIZED, MAP_UNINITIALIZED }, { 0, 0, 0, 0 } }; From patchwork Fri Jul 7 20:40:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700038 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4064981wrs; Fri, 7 Jul 2023 13:41:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlH7PYiRMaHezCmCn3m7jRMMBUswZojc0X0czyvR0YzIkpouPIDDmznfnaA/30mBLKlc5EVy X-Received: by 2002:a05:620a:2a03:b0:765:a23b:cc27 with SMTP id o3-20020a05620a2a0300b00765a23bcc27mr8615720qkp.14.1688762491237; Fri, 07 Jul 2023 13:41:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762491; cv=none; d=google.com; s=arc-20160816; b=g5gKwMJLv/k1mkHK5kWPqQNWZP412kHV/UVX81JeE46q+CfEbMz5o0bIzEQQv7zpuh Y+tPBd55c4e9ihCq50DMNrXLxzxx5AVC6kOic9zFkaYZHINPiSTY/rv6cL7G3eXuAwrC eVFvlhQlt14ZG0pWLlsMdSzD4mP1eIAydXYIXGaXawxjlRs7L3N1l6w5u/+oJ0HZ/3gp YWCoBuCgwqCn4zmPutGbygXdXAFpU62iztlGfCarqc+Azm8vxM/5FP22zxjfAxOQxGHt ra/ldkfs0GNelKKZFDbmxI09w1EvEmm7SIlz3OQVVSdVrxd/cu1c56MmNu4Lv9XKp9pN uCSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uv8+woMvmELVOwJANlOof4wFWPUartGkqI3cjtir6qk=; fh=Snw/yWAI/7AA6tppTg8XdyKlL779shjlYiHUTcQyZPQ=; b=ifAyArhDGDa+KGgDB8ZU+SjA9neCjFVieH/t7FTSONECTMWktkG0MRaYrg2Yy3JhBp GDRTpteQzRUDbpswoSi9APQU3OzDkdql0aO65UGlKYnewLBn+qhpCe/KsawEJ+2pKDMv tlpMJjjeqRc5KqkDCsHT1C2v/Stc6Jijz/GxC2YGZ8xClv1L8GJh37wZcVnWthQH7HdC IeGt5snvyHR8Fjv4r/wvTHH34eitL4WHk5XAB/YFoMhNS/+Zi+OHXXmJKkOpB6NM/Xzi oOr6xYvVU3yS9I79YApaa+zXy2J8aZb9dn9snj3IaZoCuxz1NLrp/GOkuarjTQ6/0cDK wDmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jgq+Io+3; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z6-20020a05620a100600b00766f9f2f7d8si3247696qkj.311.2023.07.07.13.41.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:41:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jgq+Io+3; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGI-0004kH-6f; Fri, 07 Jul 2023 16:41:06 -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 1qHsGG-0004jY-Vl for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:05 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGF-0004eV-92 for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:04 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3fbef8ad9bbso25947465e9.0 for ; Fri, 07 Jul 2023 13:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762462; x=1691354462; 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=uv8+woMvmELVOwJANlOof4wFWPUartGkqI3cjtir6qk=; b=jgq+Io+3ZRmvY500Cz+kTrgl96r6l5zpE7ly+hb9a8UiLxmY6Zg2eB8nAafyaVD+ZV 4jiJWraPuu7ega6zgsKS3Ra9H8J015a8YFhU4CfConc0Qu5aMTFyai+gUoXOgGN3qe44 IY89oUatrLM+XLmqlbuCSDYqdmmyDcKxLnbenbq5rj6J1zs9XZ4dw9TsmKNZ2VnhhYy1 HFCDtTONHgiKONFi6a8+IZewBtkwW4qTOWmuFbNJFxxFzCALaYbtrU7Gb9T/oZS6SCQP Dus2CmIwPbNngaEbWwvsiJBqSPJJk5axq21Ewc9EN+eHAZEEqfi91AIuAlDV2pmsXhAI Lqsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762462; x=1691354462; 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=uv8+woMvmELVOwJANlOof4wFWPUartGkqI3cjtir6qk=; b=iSlo7M4WNFzUsXx7FPaeAWfFX1oZ49KdffUjmj+aywLyGuk8nrbcRTxq+j+wlqSxxh ZtRBYIAOaa9rLKKcD67yMFCfpSnZmvvfk2D2ABpMHIiiV+3+5xrXmiIRjxTBW7NrfQ22 S7HnlBbSkMcjPILqVsOzm3Li9nM+nmGxZkWUfxiviDlbNFm9lt1M4sFdN84u+O5Kh9Iz m+5Z9MFqS9dMmIX5oqPB2CQ7dyRnr0GYK1/0mZtfSQseG+xxri40pX3oMsEWIsIRZeqe YtRzlBd3NpSHwHG+EJF92YS8XSD9HN7mVRqlFJl/Gwj3a/qn+PhTLiO5IhYBuosPqpwK DReA== X-Gm-Message-State: ABy/qLZ9QmqiD6/VIIZ2GlsKWmjtp2llDkivrqDzctOU8MTLI6CfnCAu H86nA7CXLwtH07ntXLtnU/zAZ02DaMNBMHdlD1S1xQ== X-Received: by 2002:a1c:6a03:0:b0:3fb:a576:3212 with SMTP id f3-20020a1c6a03000000b003fba5763212mr4554412wmc.39.1688762461946; Fri, 07 Jul 2023 13:41:01 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru, =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v2 07/24] accel/tcg: Introduce page_check_range_empty Date: Fri, 7 Jul 2023 21:40:37 +0100 Message-Id: <20230707204054.8792-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32c.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Examine the interval tree to validate that a region has no existing mappings. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- include/exec/cpu-all.h | 12 ++++++++++++ accel/tcg/user-exec.c | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index 472fe9ad9c..94f828b109 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -224,6 +224,18 @@ void page_set_flags(target_ulong start, target_ulong last, int flags); void page_reset_target_data(target_ulong start, target_ulong last); int page_check_range(target_ulong start, target_ulong len, int flags); +/** + * page_check_range_empty: + * @start: first byte of range + * @last: last byte of range + * Context: holding mmap lock + * + * Return true if the entire range [@start, @last] is unmapped. + * The memory lock must be held so that the caller will can ensure + * the result stays true until a new mapping can be installed. + */ +bool page_check_range_empty(target_ulong start, target_ulong last); + /** * page_get_target_data(address) * @address: guest virtual address diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index d95b875a6a..ab684a3ea2 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -598,6 +598,13 @@ int page_check_range(target_ulong start, target_ulong len, int flags) return ret; } +bool page_check_range_empty(target_ulong start, target_ulong last) +{ + assert(last >= start); + assert_memory_lock(); + return pageflags_find(start, last) == NULL; +} + void page_protect(tb_page_addr_t address) { PageFlagsNode *p; From patchwork Fri Jul 7 20:40:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700043 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4065406wrs; Fri, 7 Jul 2023 13:42:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlG5EC/qi5xQ99SP4Qj+x9W8hT9gU1R/l4aAIhiNUrAbke6V7g93NuYSyJHvHFjoOeqShR4T X-Received: by 2002:a0c:e108:0:b0:628:6879:ee48 with SMTP id w8-20020a0ce108000000b006286879ee48mr5434267qvk.50.1688762543687; Fri, 07 Jul 2023 13:42:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762543; cv=none; d=google.com; s=arc-20160816; b=OyzhONbiRVlw+rhmdRBASlz/Gez6yluCL2FYNnqOpaTBLKKzYjgrsghF9LS2QlcdCO axHUyGHojkIlxwS+MS9OoDE08JWgkPOS5yVD/fIHzbbjTmtkcNxh1ksiijuuOf/58ZVG UsYtxS06EBzh8iQCgXDWpl4EskdjOBM9CkF187l2zdw2J74VBwQlHm1sr3XoKS1MmNhC THiFLkhJh8CuScP/Kvyr7fsOp4iI3pq15tf64LJMCn3vUczY2b7v4ydiILcDI67bZ9VI Yd15h3YH3xMn0f3MFvTtzJVYL3xOo+skkE33Lxb99koldx2uKqmxO35+OwJz1d19r83s FM3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QWcGYI7xB8LlKTPPYJbQ3MPkeMAscTRkJ+piG/iDAy8=; fh=c5yfIwOUC8JO1RlChQuc3YChZ5JSRT1D/lDsc4eQOLI=; b=x5TXnfopoZJmFXppe1RpilbbSROWmTnuO21w9fWPcnCke1Nnhi0tt59QDGlzcCuWRN unpNRPEcfx8Qxykj3HJf7BBuOv3U0m1q3lOuSX5/US3qjw7CzkXrZwYeGcLctvmwrlBB jbib7I25N+5jnIzuYyxSg9aLwhMZTP6GRSlLHbWrVhOmTTITy2ZMcIMmLOirBCZR74y9 Dhdo5e4M0qgOdEeTHVoLtmTGyLDtzamwYK4XeFs6lY3Bno3nRt7TVT8+czQ4suRNwJvv m9KqmF5uohXFgEAcToRtYCTQegljYgFN2oyrNI/a4CLqkufipDUZlh8YR1sQ1B5/I/SS McrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kgLd9JZg; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e13-20020a0ce3cd000000b00636f4bbef27si3164721qvl.193.2023.07.07.13.42.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:42:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kgLd9JZg; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGM-0004o3-6s; Fri, 07 Jul 2023 16:41:10 -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 1qHsGK-0004nR-ML for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:08 -0400 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGG-0004g8-Ro for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:08 -0400 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-4f76a0a19d4so3614421e87.2 for ; Fri, 07 Jul 2023 13:41:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762463; x=1691354463; 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=QWcGYI7xB8LlKTPPYJbQ3MPkeMAscTRkJ+piG/iDAy8=; b=kgLd9JZgzUCnBaWwYIHeSliIdqz/CKARNj85jImEDDcsHeY0pgtIW7ztsTJ0HGyNcN 3clYBcy+0OZjalk998XWFASrSjp3abW4rwS7y3S4R2b0qN6FWOxmalGJTintaRw0RnPG kHvJDrR/eO15Q8h93eztPsNlg4Qqsr4FKX72T+gSqpVxwatto76A189TqhpleV5+/q6n MDFl/OUUtEwgcjq++8UvajWgQkkhnLa2eralseRgVwySLsFyuUN1fKa1OPIaUovEpcR+ DG7PmQ/qfxBic6aeiYMY6IrkYifAQ5tf96IgTHQPzR3FrAGNvi6Nvm53FyvOy4uL8LuJ 5ClQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762463; x=1691354463; 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=QWcGYI7xB8LlKTPPYJbQ3MPkeMAscTRkJ+piG/iDAy8=; b=HpsNav8kOVWj/jsBdflaO5VtlVKq01RpAcRc4FvzcSlpqKS7vOwS7lA22kbD0KGksE 6n6ddlSmJ7RAzMiQEQBI/1sI0av2maU2acHNfBQq6YNth2MR22IGJQqunUDMsi1IVLLn PqTcD+iZCVWz7Pk0LhgaOGGWKFr1GQDaLEsv0tFhqpUx0mWbZylJZVBQuRQXuxtNHFZD Yy/nmEpIHanG8IZ1NrOqWlkAV6VojLLBK5HsZ4jUZ0VMkVP/8frHIdH266SH52q/G7xa 16vBn8QImuQCtr3LRrx9uel4FGzqtNmEj4aEdrdG6O/rwc1yj0qWD1/Qp6+gf7xw+MLn lEHA== X-Gm-Message-State: ABy/qLbM/E/yynev8LtAeADtEXES+lp6mTZXNlf9D0fMQblhpPPP8/F3 ErBXUs/WFnJs8z3LOZY0WZpFyBNfGRAl4xcZakrGdA== X-Received: by 2002:a05:6512:3b83:b0:4f6:45af:70b8 with SMTP id g3-20020a0565123b8300b004f645af70b8mr5412257lfv.58.1688762463004; Fri, 07 Jul 2023 13:41:03 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru, Warner Losh , Kyle Evans Subject: [PATCH v2 08/24] bsd-user: Use page_check_range_empty for MAP_EXCL Date: Fri, 7 Jul 2023 21:40:38 +0100 Message-Id: <20230707204054.8792-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::133; envelope-from=richard.henderson@linaro.org; helo=mail-lf1-x133.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The previous check returned -1 when any page within [start, start+len) is unmapped, not when all are unmapped. Cc: Warner Losh Cc: Kyle Evans Signed-off-by: Richard Henderson Reviewed-by: Warner Losh --- bsd-user/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 565b9f97ed..07b5b8055e 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -609,7 +609,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, } /* Reject the mapping if any page within the range is mapped */ - if ((flags & MAP_EXCL) && page_check_range(start, len, 0) < 0) { + if ((flags & MAP_EXCL) && !page_check_range_empty(start, end - 1)) { errno = EINVAL; goto fail; } From patchwork Fri Jul 7 20:40:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700049 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4065861wrs; Fri, 7 Jul 2023 13:43:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlFPenVONDxUPh/5g4H6F1iGOLLbcdl9Tx5NUn/YOymPqbvIlfOQ+YNP+E0+I2YrIZDHGl/p X-Received: by 2002:ac8:5a82:0:b0:400:7de9:635a with SMTP id c2-20020ac85a82000000b004007de9635amr6807765qtc.57.1688762620785; Fri, 07 Jul 2023 13:43:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762620; cv=none; d=google.com; s=arc-20160816; b=HZl51MdyhjmX62hJ3BQubj7v8lZANiBmY/WFPoB9dxGHd40sWv5we2pVub7nSh03cm q6F0f1BsBjKv5ZnfIEH6h5/PmSmfq8RDZKw0MhSaj+66JqB0IWw0JEWH5McCtw7HhQX0 7vbbIYZloVLkHDpeG4N+BhWyDjdI8EyzJFXWhWhSqODlnXXWzLPatJsbbtS9OFCEncf7 lHG62EWOmb4mWhQD5efzKsLtNzr/SBpvbLxfEXZJ/NXR0XBAJQR7GUwyiT8DfP6PRBSx g/wu7a6sVEPU8KuOA1RJNqun+pF9hJMJmI32Zuqz75Eyw5C9PlW2OjTNUL/7xwZppsCl hDkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qGV05zqZ+kYKrbzC2hjbmm/a6tBHPtbV1LUiCeA7Icg=; fh=jVqwU2n6uDjg7kXqsBiuuwMdTrtXxwX52l5dkNb4FWE=; b=A81s/FEun7mn1pRYG1NBrg/sNbV+7q9s9zD/YorAm/hUtADKGs+jDW6vvqmyyo3EEq 9B7P1n1s617DNmmeSrQXVl2Hegoiwa0fS0gVSfWOLGpzPY/3Dl38JinTFzauArIV5bAX Vey9wBqcWPlIrhQau90hpWEr/93cUwckvQcuqWE/9cR7fdP04mOZKL8v10/fSqopJFnO d6hafFLfJsFPIqxH8Yf0sFEPab6DXmKM0ztC0P4eKt1XnPywcXQZPYNFU4Am3QH8KVFF 1PZ5GQT8Sz40tqEVjOUjQfRNxck15UGaL4uzzxrAoVXnb00cyIOImTR0FrujJC1TcBiP nofQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iNM8wBWf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l6-20020a05622a174600b0040375dd0da4si3046694qtk.636.2023.07.07.13.43.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:43:40 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iNM8wBWf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGM-0004og-Qz; Fri, 07 Jul 2023 16:41:10 -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 1qHsGK-0004nS-Mm for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:08 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGH-0004gx-2Z for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:08 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3fbea14700bso24685945e9.3 for ; Fri, 07 Jul 2023 13:41:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762463; x=1691354463; 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=qGV05zqZ+kYKrbzC2hjbmm/a6tBHPtbV1LUiCeA7Icg=; b=iNM8wBWftYTJNXz5D2VDQQjww9AvpUGEuDnbMzYBq4psrzbtXKaSl3rgByvXJap/en U5bnBRSht7q915qBoLI9byGyWp3rgURcD4zQcI23K1GmwxCNhOes4g+ConeyDNUfWTdB qKOigVkUw9l7Sbe6a1rUzeSxETFaYmSQXulDZID2uiW+Tx6f09ulLxZJTM5Y48YrFksr IGj9aOk6gQzyjXR/XSdxY8yURzucwjBeYgrVUnangyqhzqZ55gUTFG5Qe2HE4GiLM5UX j3B1NCvHGB5VIJ7exp1gYDJWyW8q/Us8mFSJhrO1SDo6NDwHHj625iHb3OYGtaUZUFdn nzqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762463; x=1691354463; 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=qGV05zqZ+kYKrbzC2hjbmm/a6tBHPtbV1LUiCeA7Icg=; b=IQAV3zFSTyYJ10p1r8ycegnbwgzBXPOfsapznmlA9M7DeMsHykNt6iWRgdg7JcpaYx fWSmXyv4SUiHjPQW9XxXlXTRvU2FHhsseZSZ/S3cnZapklpk0t0noo18X+5PBNpQti4s Mlf03d8/hNrbkv8DPJNln+XY+3Keaa8pqoaRhL0ozcwV2h8W1ktVQJo5qXoO3VV/xH7F 0vSq8rBX4xPlINYp8gu1IxPOTB57FjtvcK/yyOKyK27f7BWYmOIokFxkys+SDnj1fNnt 3g6Mp7YLUV+0fQ0H23TSAkOTHwbTfqN6KlazwxtaigezBKC2sRv6lqQ0VhohFXwgXjEF svvg== X-Gm-Message-State: ABy/qLbyAYDt+Byi0ykn5jewwdVUaNzL0TlYKaBP8OgiiULk/qHlni38 Jdll+9auHKtXoVb9H1GdB6OzplWXUyaHh13tfk3GUg== X-Received: by 2002:a7b:c392:0:b0:3fb:d1db:5454 with SMTP id s18-20020a7bc392000000b003fbd1db5454mr5373575wmj.35.1688762463732; Fri, 07 Jul 2023 13:41:03 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru Subject: [PATCH v2 09/24] linux-user: Implement MAP_FIXED_NOREPLACE Date: Fri, 7 Jul 2023 21:40:39 +0100 Message-Id: <20230707204054.8792-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32a.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Richard Henderson --- linux-user/mmap.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 12275593a1..b2e130e700 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -508,7 +508,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, * If the user is asking for the kernel to find a location, do that * before we truncate the length for mapping files below. */ - if (!(flags & MAP_FIXED)) { + if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { host_len = len + offset - host_offset; host_len = HOST_PAGE_ALIGN(host_len); start = mmap_find_vma(real_start, host_len, TARGET_PAGE_SIZE); @@ -550,7 +550,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, } } - if (!(flags & MAP_FIXED)) { + if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { unsigned long host_start; void *p; @@ -599,6 +599,13 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, goto fail; } + /* Validate that the chosen range is empty. */ + if ((flags & MAP_FIXED_NOREPLACE) + && !page_check_range_empty(start, end - 1)) { + errno = EEXIST; + goto fail; + } + /* * worst case: we cannot map the file because the offset is not * aligned, so we read it @@ -614,7 +621,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, goto fail; } retaddr = target_mmap(start, len, target_prot | PROT_WRITE, - MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, + (flags & (MAP_FIXED | MAP_FIXED_NOREPLACE)) + | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (retaddr == -1) { goto fail; From patchwork Fri Jul 7 20:40:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700056 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4066052wrs; Fri, 7 Jul 2023 13:44:20 -0700 (PDT) X-Google-Smtp-Source: APBJJlHshuB13KtRcohwaOchtAFMEnqkmuQrOO9Ss6T4cdc+E/oYWUeR9UW8lAmvm62tpKTLXczS X-Received: by 2002:a0c:f503:0:b0:635:7b84:f91c with SMTP id j3-20020a0cf503000000b006357b84f91cmr7882090qvm.20.1688762660636; Fri, 07 Jul 2023 13:44:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762660; cv=none; d=google.com; s=arc-20160816; b=zFxIRO1MTZ+jH6xOQ791VWGkXnayvC0zFK6MWWt7KSLHPs9yUcYhzjvWBCiC/OFrMO REN8kawD8DMb/7i/JjNaaAclyWMiKwu2WrNmMcPhIugqsEq9hVf9yPL6/XK0e3z8Wdm4 BfPkcdZs4INvGQEFyxe6Ui+II2qKTKBF6t7W8Cdo44viIKExJTOpY4UU68Jy/DD4KQlH rGGcxrjChcEy97DChttZaOhvQQXj6YqQAdkVNle691B8y8E8nlpSoSuqQq8jG69B9aMi xsvlhXdrTnfswKzQJM7huHT6RUzFSZLP7pRiX7BMlIaOEtHi0e+/ShiNhXIC7qpPs6Hk KdmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=f2/OyoNqam0/AVMCv04Uy+mQaVidqBwtlKBQnTyCUHY=; fh=Snw/yWAI/7AA6tppTg8XdyKlL779shjlYiHUTcQyZPQ=; b=OMRaMm38Rbz2JUOBcX+i2UMonTsDivyUAu/NnHyA7RqK+PxETEDcSfzVpZ73BACPXG eUq4Ovncw2EmYzqUecWZ86iX/Ega1sbhB+xViqHmG9J2G/vOYQH/zPnD1IXefVpuWLlN 4SK8ej4D3rjd4SaLUhdcB9B82yDL1gL4JhkR8BFvGeQBw1+wIY3STbN9nUnaSn0E7Lnb M89+tKcN2iBCH6kHzYQn/bYXSF0t2c1kCwE3YiDIew4dXop5EzRXHwbj/FVuadQFN/RY 1/KL2nLUb9FJRAgq6RMB+eog8/eMFVEH3nf1P96LlGts+JYauSGtW8h9J8wY/QbIA+e6 +3zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dqSnTN7U; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g4-20020a0cdf04000000b006261bd7a355si3061147qvl.375.2023.07.07.13.44.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:44:20 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dqSnTN7U; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGN-0004pX-L8; Fri, 07 Jul 2023 16:41:11 -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 1qHsGL-0004nr-8P for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:09 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGH-0004hs-Nh for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:08 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3144098df56so2553915f8f.2 for ; Fri, 07 Jul 2023 13:41:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762464; x=1691354464; 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=f2/OyoNqam0/AVMCv04Uy+mQaVidqBwtlKBQnTyCUHY=; b=dqSnTN7U/fntXFnEghGFlRVqkpjpSGql+qRtj3+6KhwnL7Iwp2cFfrDjz/FsQmkbZ9 hnIghGBjkHz8Ll35tH0/adBTjCi+l51jgcHYgP15dk1AhwJAmlym5kzO+fTWRK8vS8Rs SnFiiQlqcDljhpAdiPN2Of0/VAjUsBcL4Sjb1Y/LpzeccgNKcsBKb9NgmUZ9ahl4av0r weUgArFh0bEqe7RWulEXLwOnC+F9DLD/CPHqoP6IC1G+LD7P/yTn3+xfqbPz32lnvFAb MZarlO2TR7mWb4InX9Jjyz0o5D3i0V3IMrEVterKTm2a0XIV3Lg7wJh9BEOnrLcTlAW7 qrRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762464; x=1691354464; 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=f2/OyoNqam0/AVMCv04Uy+mQaVidqBwtlKBQnTyCUHY=; b=OOJ3V6bXqTs2tAftt9ISaVMc0JaGbHE1+NaZry1qO8GCxvcKdwhLj4cTfrCprT8ryv sxb9tar3ThIbcYI+N0m5XfPFtKfx48y+fQxxGs0ZKyrRSfsZlGq8BgxTxVMrku/tgTFU Msngc5QHYO51Ldw2yvk55bfVNkpPL/9ubFLi3196IjbxL2H4REsrOek5jiZB0y+TU1VZ nzy53bYcYZhHyWnpJkPmAlVwISA/4ZLiXI7o43lKju/M2prq9kr9XP7GY5kIX8MBV6dJ 4WTQ861YdrmmhjiYcmfDtu0+8GUL+CtGEci2TS5oYHSnQTP012g7l0N1BDZtKA+TsPtu j29Q== X-Gm-Message-State: ABy/qLZySLbTfzTxL11ig4lxSZ25WX830b4ig+KUWSFSNKmYrQ58IMPi fM52+l+tLCq2y+7Uz3+nlvDtztAONDvR+Soi1O2+2g== X-Received: by 2002:a7b:cc9a:0:b0:3fb:40ff:1cba with SMTP id p26-20020a7bcc9a000000b003fb40ff1cbamr5379965wma.6.1688762464247; Fri, 07 Jul 2023 13:41:04 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru, =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v2 10/24] linux-user: Split out target_to_host_prot Date: Fri, 7 Jul 2023 21:40:40 +0100 Message-Id: <20230707204054.8792-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x436.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Split out from validate_prot_to_pageflags, as there is not one single host_prot for the entire range. We need to adjust prot for every host page that overlaps multiple guest pages. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- linux-user/mmap.c | 77 +++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index b2e130e700..422583ed4f 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -68,24 +68,11 @@ void mmap_fork_end(int child) * Return 0 if the target prot bitmask is invalid, otherwise * the internal qemu page_flags (which will include PAGE_VALID). */ -static int validate_prot_to_pageflags(int *host_prot, int prot) +static int validate_prot_to_pageflags(int prot) { int valid = PROT_READ | PROT_WRITE | PROT_EXEC | TARGET_PROT_SEM; int page_flags = (prot & PAGE_BITS) | PAGE_VALID; - /* - * For the host, we need not pass anything except read/write/exec. - * While PROT_SEM is allowed by all hosts, it is also ignored, so - * don't bother transforming guest bit to host bit. Any other - * target-specific prot bits will not be understood by the host - * and will need to be encoded into page_flags for qemu emulation. - * - * Pages that are executable by the guest will never be executed - * by the host, but the host will need to be able to read them. - */ - *host_prot = (prot & (PROT_READ | PROT_WRITE)) - | (prot & PROT_EXEC ? PROT_READ : 0); - #ifdef TARGET_AARCH64 { ARMCPU *cpu = ARM_CPU(thread_cpu); @@ -113,18 +100,34 @@ static int validate_prot_to_pageflags(int *host_prot, int prot) return prot & ~valid ? 0 : page_flags; } +/* + * For the host, we need not pass anything except read/write/exec. + * While PROT_SEM is allowed by all hosts, it is also ignored, so + * don't bother transforming guest bit to host bit. Any other + * target-specific prot bits will not be understood by the host + * and will need to be encoded into page_flags for qemu emulation. + * + * Pages that are executable by the guest will never be executed + * by the host, but the host will need to be able to read them. + */ +static int target_to_host_prot(int prot) +{ + return (prot & (PROT_READ | PROT_WRITE)) | + (prot & PROT_EXEC ? PROT_READ : 0); +} + /* NOTE: all the constants are the HOST ones, but addresses are target. */ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) { abi_ulong end, host_start, host_end, addr; - int prot1, ret, page_flags, host_prot; + int prot1, ret, page_flags; trace_target_mprotect(start, len, target_prot); if ((start & ~TARGET_PAGE_MASK) != 0) { return -TARGET_EINVAL; } - page_flags = validate_prot_to_pageflags(&host_prot, target_prot); + page_flags = validate_prot_to_pageflags(target_prot); if (!page_flags) { return -TARGET_EINVAL; } @@ -142,7 +145,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) host_end = HOST_PAGE_ALIGN(end); if (start > host_start) { /* handle host page containing start */ - prot1 = host_prot; + prot1 = target_prot; for (addr = host_start; addr < start; addr += TARGET_PAGE_SIZE) { prot1 |= page_get_flags(addr); } @@ -153,19 +156,19 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) end = host_end; } ret = mprotect(g2h_untagged(host_start), qemu_host_page_size, - prot1 & PAGE_BITS); + target_to_host_prot(prot1)); if (ret != 0) { goto error; } host_start += qemu_host_page_size; } if (end < host_end) { - prot1 = host_prot; + prot1 = target_prot; for (addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) { prot1 |= page_get_flags(addr); } ret = mprotect(g2h_untagged(host_end - qemu_host_page_size), - qemu_host_page_size, prot1 & PAGE_BITS); + qemu_host_page_size, target_to_host_prot(prot1)); if (ret != 0) { goto error; } @@ -174,8 +177,8 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) /* handle the pages in the middle */ if (host_start < host_end) { - ret = mprotect(g2h_untagged(host_start), - host_end - host_start, host_prot); + ret = mprotect(g2h_untagged(host_start), host_end - host_start, + target_to_host_prot(target_prot)); if (ret != 0) { goto error; } @@ -211,7 +214,8 @@ static int mmap_frag(abi_ulong real_start, if (prot1 == 0) { /* no page was there, so we allocate one */ - void *p = mmap(host_start, qemu_host_page_size, prot, + void *p = mmap(host_start, qemu_host_page_size, + target_to_host_prot(prot), flags | MAP_ANONYMOUS, -1, 0); if (p == MAP_FAILED) { return -1; @@ -232,7 +236,8 @@ static int mmap_frag(abi_ulong real_start, /* adjust protection to be able to read */ if (!(prot1 & PROT_WRITE)) { - mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE); + mprotect(host_start, qemu_host_page_size, + target_to_host_prot(prot1) | PROT_WRITE); } /* read the corresponding file data */ @@ -242,11 +247,13 @@ static int mmap_frag(abi_ulong real_start, /* put final protection */ if (prot_new != (prot1 | PROT_WRITE)) { - mprotect(host_start, qemu_host_page_size, prot_new); + mprotect(host_start, qemu_host_page_size, + target_to_host_prot(prot_new)); } } else { if (prot_new != prot1) { - mprotect(host_start, qemu_host_page_size, prot_new); + mprotect(host_start, qemu_host_page_size, + target_to_host_prot(prot_new)); } if (prot_new & PROT_WRITE) { memset(g2h_untagged(start), 0, end - start); @@ -459,7 +466,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, { abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_len, passthrough_start = -1, passthrough_end = -1; - int page_flags, host_prot; + int page_flags; mmap_lock(); trace_target_mmap(start, len, target_prot, flags, fd, offset); @@ -469,7 +476,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, goto fail; } - page_flags = validate_prot_to_pageflags(&host_prot, target_prot); + page_flags = validate_prot_to_pageflags(target_prot); if (!page_flags) { errno = EINVAL; goto fail; @@ -552,10 +559,12 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { unsigned long host_start; + int host_prot; void *p; host_len = len + offset - host_offset; host_len = HOST_PAGE_ALIGN(host_len); + host_prot = target_to_host_prot(target_prot); /* * Note: we prefer to control the mapping address. It is @@ -612,6 +621,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, */ if (!(flags & MAP_ANONYMOUS) && (offset & ~qemu_host_page_mask) != (start & ~qemu_host_page_mask)) { + int host_prot = target_to_host_prot(target_prot); + /* * msync() won't work here, so we return an error if write is * possible while it is a shared mapping @@ -620,7 +631,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, errno = EINVAL; goto fail; } - retaddr = target_mmap(start, len, target_prot | PROT_WRITE, + retaddr = target_mmap(start, len, host_prot | PROT_WRITE, (flags & (MAP_FIXED | MAP_FIXED_NOREPLACE)) | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); @@ -642,14 +653,14 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, if (real_end == real_start + qemu_host_page_size) { /* one single host page */ ret = mmap_frag(real_start, start, end, - host_prot, flags, fd, offset); + target_prot, flags, fd, offset); if (ret == -1) { goto fail; } goto the_end1; } ret = mmap_frag(real_start, start, real_start + qemu_host_page_size, - host_prot, flags, fd, offset); + target_prot, flags, fd, offset); if (ret == -1) { goto fail; } @@ -659,7 +670,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, if (end < real_end) { ret = mmap_frag(real_end - qemu_host_page_size, real_end - qemu_host_page_size, end, - host_prot, flags, fd, + target_prot, flags, fd, offset + real_end - qemu_host_page_size - start); if (ret == -1) { goto fail; @@ -677,7 +688,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, offset1 = offset + real_start - start; } p = mmap(g2h_untagged(real_start), real_end - real_start, - host_prot, flags, fd, offset1); + target_to_host_prot(target_prot), flags, fd, offset1); if (p == MAP_FAILED) { goto fail; } From patchwork Fri Jul 7 20:40:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700040 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4065189wrs; Fri, 7 Jul 2023 13:41:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlFu6PKRJ9jkaDEB3YU3ElwfhNAuBeyQHWNPvizhXcXdr3baBBrKZdJ8rCJc2HUfHumph3Up X-Received: by 2002:a37:2c81:0:b0:765:a720:5a61 with SMTP id s123-20020a372c81000000b00765a7205a61mr4996238qkh.31.1688762516735; Fri, 07 Jul 2023 13:41:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762516; cv=none; d=google.com; s=arc-20160816; b=at3tMEWSBe4XLtK7h5W4vleYnaKSMt1ikIrXcxudbxABPZRk3fHmBsidGYstLgHYQY BSJqQs7dCDlb4L6duvKBVbt9WV0FSaICaKdl08gAVs/7mXXvPQwlcyUOWDYjuNC4hkfg bZDLzCdb115dlZlMUUrRU+sBwDM5D7bUYnhXizbj+4xx/ZsOee00vd8H/EI9srTTEHiY KP7RcwQWZklEZxKIaptE1jrtOkVxW/vxKuFMXEUfLLesbCMcr6/4eFytsuSr+6CeAl8W 6ALEs+FSgUAP3S4Yq/rTbfGeNAU0JP8MqlOiLBC88wusLiIty61ormR/IwIJ6EVjU5Wv XrBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rBQg9cfWnYMnQbgH1xQmPDp7YLGiDcpxqAFflb/oQe8=; fh=Snw/yWAI/7AA6tppTg8XdyKlL779shjlYiHUTcQyZPQ=; b=SFfwyzGN0ivm/8ixm/VGZ0P+QMASQ8AVHXMgmjVQ+1iIrjUWz7/hWEPNM/zXCxdxv8 eKo8jB7V5iAcNUbYD+PU0LVJraIeOMuwFm5AtsRNkzKQNaL2Pq+OZh9RUTndPXr0TQLU 5C/dl/ZJA0SNmdEdggrVftBbw/c6q4DpU/LYL38XYPRIExQpIJacwFWLxK0cJXyAJXy9 Sa/KaQsAnFjSDM56weWmsfFsT0mr/MsSYrShE0jhwg5bm353c1rZqoN4RXHROF26Hrwo IOTjT5bdWtD3nGd/z1zMSYNsbSWMsNuEq+CPMGfAYLEIBw8SLlWbiGQTqA8xtSdt0rK8 CT5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vih31CfP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s5-20020a05620a030500b00763978e06f7si3301397qkm.384.2023.07.07.13.41.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:41:56 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vih31CfP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGL-0004o0-Kp; Fri, 07 Jul 2023 16:41:09 -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 1qHsGK-0004nb-Ry for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:08 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGI-0004ib-3J for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:08 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3fb4146e8deso29580165e9.0 for ; Fri, 07 Jul 2023 13:41:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762464; x=1691354464; 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=rBQg9cfWnYMnQbgH1xQmPDp7YLGiDcpxqAFflb/oQe8=; b=Vih31CfPlYQYpzDeGEsYi6gSeBGx/jG6//rAOE0MxtRPSGBOJqNRWnBlTwy7MnICvd IsdELpwMFumR/d4m+ywNELOp9gzVZyydjqNfiAi9NNe49vA0SuXzbraFZ3UPwLj4vUs5 gk2VEdRtaQ9ziTypQTWf2dB9vLfN/UiL9CsnxoBCLWGONBMEQvOtHjC+wZA9yep66hMQ /ylReFTSIMKSHglCjHtSodxBxksJpDCjs+EsNmaSHK03SDfaLidJLkzekXSzOGmD/2PG iXK/AsXNwSgNq7HXUy2mx9S+/uF30zMYM6iUPxrjKJmOShN9lNYl6evJDT5M8+O23Ddq TjWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762464; x=1691354464; 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=rBQg9cfWnYMnQbgH1xQmPDp7YLGiDcpxqAFflb/oQe8=; b=hRvwGrBo4CBdFBC43snqOBTibO6GVXp07OcpQQD0bv/Jbu+lhp7pECKt64eCih0EoR FSRpcsEVFNs0ttJam/El+Bib3eNEkQRXSE7BGuF/KgOVBUc/kYKHEvyFMdgdIQqERwqc D1nSyYrTCsMdOj1T9JukGLkQmm26bIkDoBp10ybOqmZlaer6SWgWEzMRpCqbgOTyq+wa c2IZBhVTU1waVh1t2LzwhbH3XjwlhESOh6GWDS6tQKIqvirbIJSV5U44TnzLF6UsgBlI zeNlOGUZsSdZnSv9DkbmdrkPODVNjXOTjU/Qu3XCFb8TdAEIZg46wiMkkTOO96XdYz3U a7OQ== X-Gm-Message-State: ABy/qLbeKnGfeCrzXLH1fpxkIT6tfn3na3igbfFwivb/iq9DDZNryWIp HJ1jXbLrfnQLgEG5xBbSRL//+PD4qiOzPEUGGv4qAQ== X-Received: by 2002:a05:600c:2311:b0:3f9:b748:ff37 with SMTP id 17-20020a05600c231100b003f9b748ff37mr6478315wmo.20.1688762464768; Fri, 07 Jul 2023 13:41:04 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru, =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v2 11/24] linux-user: Widen target_mmap offset argument to off_t Date: Fri, 7 Jul 2023 21:40:41 +0100 Message-Id: <20230707204054.8792-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x336.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org We build with _FILE_OFFSET_BITS=64, so off_t = off64_t = uint64_t. With an extra cast, this fixes emulation of mmap2, which could overflow the computation of the full value of offset. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- linux-user/user-mmap.h | 2 +- linux-user/mmap.c | 14 ++++++++------ linux-user/syscall.c | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index 480ce1c114..3fc986f92f 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -20,7 +20,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot); abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, - int flags, int fd, abi_ulong offset); + int flags, int fd, off_t offset); int target_munmap(abi_ulong start, abi_ulong len); abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_ulong new_size, unsigned long flags, diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 422583ed4f..bba01804b3 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -195,7 +195,7 @@ error: /* map an incomplete host page */ static int mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong end, - int prot, int flags, int fd, abi_ulong offset) + int prot, int flags, int fd, off_t offset) { abi_ulong real_end, addr; void *host_start; @@ -462,11 +462,12 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) /* NOTE: all the constants are the HOST ones */ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, - int flags, int fd, abi_ulong offset) + int flags, int fd, off_t offset) { - abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_len, + abi_ulong ret, end, real_start, real_end, retaddr, host_len, passthrough_start = -1, passthrough_end = -1; int page_flags; + off_t host_offset; mmap_lock(); trace_target_mmap(start, len, target_prot, flags, fd, offset); @@ -558,7 +559,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, } if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { - unsigned long host_start; + uintptr_t host_start; int host_prot; void *p; @@ -577,7 +578,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, goto fail; } /* update start so that it points to the file position at 'offset' */ - host_start = (unsigned long)p; + host_start = (uintptr_t)p; if (!(flags & MAP_ANONYMOUS)) { p = mmap(g2h_untagged(start), len, host_prot, flags | MAP_FIXED, fd, host_offset); @@ -681,7 +682,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, /* map the middle (easier) */ if (real_start < real_end) { void *p; - unsigned long offset1; + off_t offset1; + if (flags & MAP_ANONYMOUS) { offset1 = 0; } else { diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 2c0c6e745e..b9b5e37c5e 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -10430,7 +10430,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, #endif ret = target_mmap(arg1, arg2, arg3, target_to_host_bitmask(arg4, mmap_flags_tbl), - arg5, arg6 << MMAP_SHIFT); + arg5, (off_t)(abi_ulong)arg6 << MMAP_SHIFT); return get_errno(ret); #endif case TARGET_NR_munmap: From patchwork Fri Jul 7 20:40:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700051 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4065923wrs; Fri, 7 Jul 2023 13:43:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlHt08qVnDyU5OC18dcJOCsvzBPMoMRs5ALMok9GcELEeBedvIi64siEEmkdtEP2JlnjN7di X-Received: by 2002:a37:b484:0:b0:766:fb06:5f2 with SMTP id d126-20020a37b484000000b00766fb0605f2mr5057034qkf.50.1688762636721; Fri, 07 Jul 2023 13:43:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762636; cv=none; d=google.com; s=arc-20160816; b=jPK1TMgIcYUcypubN9zKVajv/cGaC4e2uqvL9zmATQS/xjmyBbG+U4R0smzjkJIx9D CCstEM3PGRBu0uuVcOHNaWu1CxZz/82CnjvMx40K7IzHY+wyv8NzPVfX0Y7TaPf3MSP1 SrrDAblD4vPCeOYZQdKI41UZZKhjDZquAlCBBXY/ttO1MS+I/ZHLleQxylqvQsHuoN2D lvHLTvp/2qUJe8D4HKqRChymnLvO1Hi6mTLLcEJgP6j0aKZdRzSU3K1J3uwaG8AgD1nm borTs1p601swiMdT9ECkWQa7SBnA6SaphgtN6EvcCk/e4U5ZsfOMCmAh39QOdPfI0ICM 8qJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OCjpCmgTYSJQaYpH88C84bJaDepq/uowpCtDyP1aGHQ=; fh=jVqwU2n6uDjg7kXqsBiuuwMdTrtXxwX52l5dkNb4FWE=; b=O8NAovCfp9vry5dXNzR+nBUtIy+G1xU5I50NObnLh7OtHnthlE9cxbH+kCqiAYRMtD 5ekuMuSqj3SXJhNwk9d7DbSodg2GmcANxuDDWWfInArn/+gAcID4iM5ROtaxLvbN4b6j zE9LTuSU//FlHrAc+gFdTDtLm6HIMv9s7r3n6NC49yJSH2fSxRcFY4C67u9zVOOrJyrJ ePaqiCUoK3OIpWaVmbySvYq63RSlYDpZ1cdj8tBYsOL+9XaPU9ZHatBeITkxPgYljtEg 4GCRNY6SMVmFc/2/mu5zGDIjhg0AqvIkinVy0qXQZlh6BbBHHLl0GwPOkxLHCrfrFfD8 QgaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TvPj6GzA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o17-20020ae9f511000000b0075ebdc36f02si3338987qkg.134.2023.07.07.13.43.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:43:56 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TvPj6GzA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGO-0004px-TR; Fri, 07 Jul 2023 16:41:12 -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 1qHsGM-0004o2-30 for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:10 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGI-0004jY-Rf for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:09 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3fbca8935bfso25737055e9.3 for ; Fri, 07 Jul 2023 13:41:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762465; x=1691354465; 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=OCjpCmgTYSJQaYpH88C84bJaDepq/uowpCtDyP1aGHQ=; b=TvPj6GzAViK4mk0PAiMD6pbfRRPNSwGvG1kZOve0FdwtwxAGAGN54APvkTKTPOPAzG /JaHBKfy3X5yoviHstNQLCk3e/8RR4Ax6uAUIN05mmuad+gamq9amI7zx5tEIqV+tBSR kKnJZUNzkp5Nxkq7In4TYqqOP4DyzBo63iJTSYp11MDArDz4OpEHa+XJKa1rPwBxnaqC 2tgSlmjFr5ZSZCEd/7WsG8YXZCirEVadMeOM6JtUOsY+JcMIW48iLk1dkc5RqP9Hj0/+ xjkUDyvbUrHbjDJg1JomvCTIUj7yxVr8jXEMJ9UEG+apGbMItcvnGs8u3EMwmSU8pMLY t2uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762465; x=1691354465; 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=OCjpCmgTYSJQaYpH88C84bJaDepq/uowpCtDyP1aGHQ=; b=h0rpaQbS8rvMkL1W9y9AB4JTTE4thqjfIb9GUAnvXCtUJLMV7jntNg9joeHMweY2b6 Ym8r/45819i4jMtn/R1hDnZ95D15V5AT4uEQJ7fvGmQz8uiz913GYAlSBNOS5xQKAt7n yZgEspvU66KpKxHDHa2vbW/X6viwLnB+sG50BtEi+snosZb9g0FRu2XminFzJbLvVGgw 341hnlXXmPUYyyL+gPXiNt6Wc5JXqCPTZJjRJIKhANB/MuU1L+XAPOSng2xz4B8woDsc 2TZcZluzzHLueLhXHlcWyruxd+sGEdXlck89Udw8i+FjFazxwF9FN4JE+e9ZKETW9nLe +Hgg== X-Gm-Message-State: ABy/qLaDvUqXieBelzadGH69zg3V8LOywSHaCCF/UkZ4vmctaTx9lI0e RpPxCyify3mKV9atVydY+CXbN8kKeSd1WpEqRztOVQ== X-Received: by 2002:a7b:c7d1:0:b0:3fa:9590:a365 with SMTP id z17-20020a7bc7d1000000b003fa9590a365mr4463993wmk.17.1688762465546; Fri, 07 Jul 2023 13:41:05 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru Subject: [PATCH v2 12/24] linux-user: Rewrite target_mprotect Date: Fri, 7 Jul 2023 21:40:42 +0100 Message-Id: <20230707204054.8792-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32c.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Use 'last' variables instead of 'end' variables. When host page size > guest page size, detect when adjacent host pages have the same protection and merge that expanded host range into fewer syscalls. Signed-off-by: Richard Henderson --- linux-user/mmap.c | 106 +++++++++++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 39 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index bba01804b3..c03b0b4e43 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -119,8 +119,11 @@ static int target_to_host_prot(int prot) /* NOTE: all the constants are the HOST ones, but addresses are target. */ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) { - abi_ulong end, host_start, host_end, addr; - int prot1, ret, page_flags; + abi_ulong starts[3]; + abi_ulong lens[3]; + int prots[3]; + abi_ulong host_start, host_last, last; + int prot1, ret, page_flags, nranges; trace_target_mprotect(start, len, target_prot); @@ -131,63 +134,88 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) if (!page_flags) { return -TARGET_EINVAL; } - len = TARGET_PAGE_ALIGN(len); - end = start + len; - if (!guest_range_valid_untagged(start, len)) { - return -TARGET_ENOMEM; - } if (len == 0) { return 0; } + len = TARGET_PAGE_ALIGN(len); + if (!guest_range_valid_untagged(start, len)) { + return -TARGET_ENOMEM; + } + + last = start + len - 1; + host_start = start & qemu_host_page_mask; + host_last = HOST_PAGE_ALIGN(last) - 1; + nranges = 0; mmap_lock(); - host_start = start & qemu_host_page_mask; - host_end = HOST_PAGE_ALIGN(end); - if (start > host_start) { - /* handle host page containing start */ + + if (host_last - host_start < qemu_host_page_size) { + /* Single host page contains all guest pages: sum the prot. */ prot1 = target_prot; - for (addr = host_start; addr < start; addr += TARGET_PAGE_SIZE) { - prot1 |= page_get_flags(addr); + for (abi_ulong a = host_start; a < start; a += TARGET_PAGE_SIZE) { + prot1 |= page_get_flags(a); } - if (host_end == host_start + qemu_host_page_size) { - for (addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) { - prot1 |= page_get_flags(addr); + for (abi_ulong a = last; a < host_last; a += TARGET_PAGE_SIZE) { + prot1 |= page_get_flags(a + 1); + } + starts[nranges] = host_start; + lens[nranges] = qemu_host_page_size; + prots[nranges] = prot1; + nranges++; + } else { + if (host_start < start) { + /* Host page contains more than one guest page: sum the prot. */ + prot1 = target_prot; + for (abi_ulong a = host_start; a < start; a += TARGET_PAGE_SIZE) { + prot1 |= page_get_flags(a); + } + /* If the resulting sum differs, create a new range. */ + if (prot1 != target_prot) { + starts[nranges] = host_start; + lens[nranges] = qemu_host_page_size; + prots[nranges] = prot1; + nranges++; + host_start += qemu_host_page_size; } - end = host_end; } - ret = mprotect(g2h_untagged(host_start), qemu_host_page_size, - target_to_host_prot(prot1)); - if (ret != 0) { - goto error; + + if (last < host_last) { + /* Host page contains more than one guest page: sum the prot. */ + prot1 = target_prot; + for (abi_ulong a = last; a < host_last; a += TARGET_PAGE_SIZE) { + prot1 |= page_get_flags(a + 1); + } + /* If the resulting sum differs, create a new range. */ + if (prot1 != target_prot) { + host_last -= qemu_host_page_size; + starts[nranges] = host_last + 1; + lens[nranges] = qemu_host_page_size; + prots[nranges] = prot1; + nranges++; + } } - host_start += qemu_host_page_size; - } - if (end < host_end) { - prot1 = target_prot; - for (addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) { - prot1 |= page_get_flags(addr); + + /* Create a range for the middle, if any remains. */ + if (host_start < host_last) { + starts[nranges] = host_start; + lens[nranges] = host_last - host_start + 1; + prots[nranges] = target_prot; + nranges++; } - ret = mprotect(g2h_untagged(host_end - qemu_host_page_size), - qemu_host_page_size, target_to_host_prot(prot1)); - if (ret != 0) { - goto error; - } - host_end -= qemu_host_page_size; } - /* handle the pages in the middle */ - if (host_start < host_end) { - ret = mprotect(g2h_untagged(host_start), host_end - host_start, - target_to_host_prot(target_prot)); + for (int i = 0; i < nranges; ++i) { + ret = mprotect(g2h_untagged(starts[i]), lens[i], + target_to_host_prot(prots[i])); if (ret != 0) { goto error; } } - page_set_flags(start, start + len - 1, page_flags); + page_set_flags(start, last, page_flags); ret = 0; -error: + error: mmap_unlock(); return ret; } From patchwork Fri Jul 7 20:40:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700058 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4066248wrs; Fri, 7 Jul 2023 13:44:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlELab3jeaxTuLd6zUq+dXm588eku8DKuoG2xBnhtrYSevgR+2VXkjyHjEFkp5flGCZFZEci X-Received: by 2002:a05:622a:1a83:b0:402:6c1d:f249 with SMTP id s3-20020a05622a1a8300b004026c1df249mr7247213qtc.5.1688762689500; Fri, 07 Jul 2023 13:44:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762689; cv=none; d=google.com; s=arc-20160816; b=G8RgEYFP+ptUUL8RWvCDoXXleob1vli6/RPDAHlz4Be58H8j50Gjw9/j31wqeeu4Ui AnaxPIIuXYyHTmtAYc0u8dl3lCFUSVJIl2zxMBMMSY4PO8/NYp4qj7zbsfvQnJdLcqjB lbRk/x+vAL4eiHXrVuerTQw6VNrjy8z+p9GaeQnYMHFARUcAvcHXQavNkRWM52M/PnlL VXliXfD0PXnryymBJoxbBIfnZkpCgz7vXkcKouGWZ1FULRQKELYoahK7XgRcQ6x7xT9h 0PXC8ra3hnfaUP/nibg0231I8I7ZnRR6v+ExYuduDM/421gdbW5TrDQVjuSOh+IEc0Tk NpFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MuBZN1PJhm7PqMGesb3PWoo/GpX6aBurTafnauxIUyg=; fh=jVqwU2n6uDjg7kXqsBiuuwMdTrtXxwX52l5dkNb4FWE=; b=0cpfUPzfz/Qs6zLk0IW28zvi/1Awh0fLi+Hyz91BgW2HItUUXL+/6MzZKlSBGXH703 vMDqn1+uOGHfZ6Y0EwrMUuIx77nT7oIsggGD011Tw3PiWIUpXezZ8UNNoWgxR8uTpaer cWmyR4mjEP6Ie2zslgrhpuV+KLrRhtNna0CJUVvnbY1MYwXd6moRJ4zPm3a99whQrSdX I/1y6/rkL8HpM03WE/pco5Og0s/1lv4XYsa/p+kbqnqni9jrLj/+pALarXeMoFQvTG9C AEy7n0AkhEXNduxwPsnGIBt4sB2AQm/PDql8O2+D2TDhRhMl4bZen4e+sx3O3whlh1dF X5mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="jg/BoUyu"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q17-20020a05622a031100b0040389c4cebesi3113774qtw.174.2023.07.07.13.44.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:44:49 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="jg/BoUyu"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGY-0004yn-Ow; Fri, 07 Jul 2023 16:41:23 -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 1qHsGP-0004q0-Ce for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:13 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGJ-0004kK-Np for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:12 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3fbc12181b6so25699485e9.2 for ; Fri, 07 Jul 2023 13:41:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762466; x=1691354466; 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=MuBZN1PJhm7PqMGesb3PWoo/GpX6aBurTafnauxIUyg=; b=jg/BoUyuC6LYqBsrpsY+pzEiy3gbdMGXuoXu4hEpesjKbZANtjKnsnbpHq9t3tjwkb k35QjY4aLSzqVJv4Sa/b0oVBsFkZlbL2NeOmT7u78/AJhxeGPyCRFBtnP7V/9J922JLw dXSkSKyOK1VyIsBv2BRXgxU/V86siebDyhKA9JbKDz4OgJSzBw9Pl1AMe9vyIKLrSEcW vw5ErisWCFvvYItqe87XdCPIINT8pSFIlwWmC7Sh8rYqSTckfGn+htM4t09ARhyEMQAb fUiqP195DSY3STiS2MzzVOT3FoJfEC2ZSakF6wuUpVVDdQsVF82WYLGao65g6J4gmMBx M/8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762466; x=1691354466; 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=MuBZN1PJhm7PqMGesb3PWoo/GpX6aBurTafnauxIUyg=; b=TbQ2VlR77g5ijAFqWXUNwiWzdL0Bd0A9Skm69zycqCyunJ62b1J1OcaNMoWMgA69AF +xDT4AImqjR0lG7kvU2CQZJN4dUmBdV+SLlGqSRn6uLvM1LiFRWN90+NynnLaDWcAGmM lAk1KHl12ekar8PSNLN5VRCOgZ4uwEb32UO0moFC31Wkd0wXKIpvqo/OvdEIas2iWAEu 3EpFGCO1Moj3VggvVSFY/9rxwV1zNHtMrb7XUm+eecXYUPgtdkqbYm/0/ZZzRCRyaV3U X4pjDhRrkrmGjxf3d4iK67DOXHSG870bm8jFAyNaYS4vFX32V91Srv5sUySICXkR5KhH LnaQ== X-Gm-Message-State: ABy/qLaFYN2b1ayf6g44kJl9V+N5xpgKovDNZoPM1xgnZ9qlcPVpUKG3 wTIgn3fVWZ7asBknLN7LR4ZGaX/jPiYvlQmThhUdrg== X-Received: by 2002:a1c:7911:0:b0:3fc:92:73d6 with SMTP id l17-20020a1c7911000000b003fc009273d6mr1839483wme.11.1688762466159; Fri, 07 Jul 2023 13:41:06 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru Subject: [PATCH v2 13/24] linux-user: Rewrite mmap_frag Date: Fri, 7 Jul 2023 21:40:43 +0100 Message-Id: <20230707204054.8792-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32d.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Use 'last' variables instead of 'end' variables. Always zero MAP_ANONYMOUS fragments, which we previously failed to do if they were not writable; early exit in case we allocate a new page from the kernel, known zeros. Signed-off-by: Richard Henderson --- linux-user/mmap.c | 123 +++++++++++++++++++++++----------------------- 1 file changed, 62 insertions(+), 61 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index c03b0b4e43..db4705e049 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -221,73 +221,76 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) } /* map an incomplete host page */ -static int mmap_frag(abi_ulong real_start, - abi_ulong start, abi_ulong end, - int prot, int flags, int fd, off_t offset) +static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, + int prot, int flags, int fd, off_t offset) { - abi_ulong real_end, addr; + abi_ulong real_last; void *host_start; - int prot1, prot_new; + int prot_old, prot_new; + int host_prot_old, host_prot_new; - real_end = real_start + qemu_host_page_size; - host_start = g2h_untagged(real_start); - - /* get the protection of the target pages outside the mapping */ - prot1 = 0; - for (addr = real_start; addr < real_end; addr++) { - if (addr < start || addr >= end) { - prot1 |= page_get_flags(addr); - } + if (!(flags & MAP_ANONYMOUS) + && (flags & MAP_TYPE) == MAP_SHARED + && (prot & PROT_WRITE)) { + /* + * msync() won't work with the partial page, so we return an + * error if write is possible while it is a shared mapping. + */ + errno = EINVAL; + return false; } - if (prot1 == 0) { - /* no page was there, so we allocate one */ + real_last = real_start + qemu_host_page_size - 1; + host_start = g2h_untagged(real_start); + + /* Get the protection of the target pages outside the mapping. */ + prot_old = 0; + for (abi_ulong a = real_start; a < start; a += TARGET_PAGE_SIZE) { + prot_old |= page_get_flags(a); + } + for (abi_ulong a = real_last; a > last; a -= TARGET_PAGE_SIZE) { + prot_old |= page_get_flags(a); + } + + if (prot_old == 0) { + /* + * Since !(prot_old & PAGE_VALID), there were no guest pages + * outside of the fragment we need to map. Allocate a new host + * page to cover, discarding whatever else may have been present. + */ void *p = mmap(host_start, qemu_host_page_size, target_to_host_prot(prot), flags | MAP_ANONYMOUS, -1, 0); if (p == MAP_FAILED) { - return -1; + return false; } - prot1 = prot; + prot_old = prot; } - prot1 &= PAGE_BITS; + prot_new = prot | prot_old; - prot_new = prot | prot1; - if (!(flags & MAP_ANONYMOUS)) { - /* - * msync() won't work here, so we return an error if write is - * possible while it is a shared mapping. - */ - if ((flags & MAP_TYPE) == MAP_SHARED && (prot & PROT_WRITE)) { - return -1; - } + host_prot_old = target_to_host_prot(prot_old); + host_prot_new = target_to_host_prot(prot_new); - /* adjust protection to be able to read */ - if (!(prot1 & PROT_WRITE)) { - mprotect(host_start, qemu_host_page_size, - target_to_host_prot(prot1) | PROT_WRITE); - } + /* Adjust protection to be able to write. */ + if (!(host_prot_old & PROT_WRITE)) { + host_prot_old |= PROT_WRITE; + mprotect(host_start, qemu_host_page_size, host_prot_old); + } - /* read the corresponding file data */ - if (pread(fd, g2h_untagged(start), end - start, offset) == -1) { - return -1; - } - - /* put final protection */ - if (prot_new != (prot1 | PROT_WRITE)) { - mprotect(host_start, qemu_host_page_size, - target_to_host_prot(prot_new)); - } + /* Read or zero the new guest pages. */ + if (flags & MAP_ANONYMOUS) { + memset(g2h_untagged(start), 0, last - start + 1); } else { - if (prot_new != prot1) { - mprotect(host_start, qemu_host_page_size, - target_to_host_prot(prot_new)); - } - if (prot_new & PROT_WRITE) { - memset(g2h_untagged(start), 0, end - start); + if (pread(fd, g2h_untagged(start), last - start + 1, offset) == -1) { + return false; } } - return 0; + + /* Put final protection */ + if (host_prot_new != host_prot_old) { + mprotect(host_start, qemu_host_page_size, host_prot_new); + } + return true; } #if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64 @@ -681,27 +684,25 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, if (start > real_start) { if (real_end == real_start + qemu_host_page_size) { /* one single host page */ - ret = mmap_frag(real_start, start, end, - target_prot, flags, fd, offset); - if (ret == -1) { + if (!mmap_frag(real_start, start, end - 1, + target_prot, flags, fd, offset)) { goto fail; } goto the_end1; } - ret = mmap_frag(real_start, start, real_start + qemu_host_page_size, - target_prot, flags, fd, offset); - if (ret == -1) { + if (!mmap_frag(real_start, start, + real_start + qemu_host_page_size - 1, + target_prot, flags, fd, offset)) { goto fail; } real_start += qemu_host_page_size; } /* handle the end of the mapping */ if (end < real_end) { - ret = mmap_frag(real_end - qemu_host_page_size, - real_end - qemu_host_page_size, end, - target_prot, flags, fd, - offset + real_end - qemu_host_page_size - start); - if (ret == -1) { + if (!mmap_frag(real_end - qemu_host_page_size, + real_end - qemu_host_page_size, end - 1, + target_prot, flags, fd, + offset + real_end - qemu_host_page_size - start)) { goto fail; } real_end -= qemu_host_page_size; From patchwork Fri Jul 7 20:40:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700059 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4066296wrs; Fri, 7 Jul 2023 13:44:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlEInYMHGgC4LlUQDkHmb/45KWt7/5bdtnUVMRDZ0n1Es3Bxzx/sxbfAkBFKYY8Bnvsd3TGu X-Received: by 2002:a05:622a:1a83:b0:402:6c1d:f249 with SMTP id s3-20020a05622a1a8300b004026c1df249mr7247587qtc.5.1688762699211; Fri, 07 Jul 2023 13:44:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762699; cv=none; d=google.com; s=arc-20160816; b=LIIvqcwW8TfJJ8jtZgmKAxaswwGCkrHa4losVq6sV74cqmSo/oqT1NMrfNj9wsxMYq CQhhpsyfMhVrw0dfgetMkudfhlNUw2txGwhigAUe5kqOLQNPWnZKYAWqOyyXGgi7Co/L oEEameDAOajtadXAZ/E+z2bVBNmIMUWD/uv0STiA+/+3JOth1lBACpI6uDNpj61ao+xa +Y4k7OwnjSqeHSVAhkYe8zrHLVj3wgggsKo19SR9HBMVJph0kSfPpVsN56psLmzWS2DC tBOtVCjGHLSIv5daX+WB6JUn+MWwpmIB32HodFAKXUojdUjo48GPrY/b52+48cUmQdiS gZgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BvCmbIPrY85Qj0xJIhdk6WMERPf4zDCfB4ii0LMHB14=; fh=jVqwU2n6uDjg7kXqsBiuuwMdTrtXxwX52l5dkNb4FWE=; b=cezhwIJNq/FrYF/LFgYGSIKFNSfOFFcqNNSwEUa/CMixzQfHYGOGl/0gkhUZEen4i3 1DhGsX8ijS9Svl2gBDFVzZyTh5qVlfgP7ylcZujtjY+PdRdX8ujlom4PO5M3BZRPsLUl OxnUecD+UinHBwFjaSUDuYzJ1YGUAeXNuQvl5fIDRm+877dbxZhKvb/bEoFwYs1fArnb 3ZmswIbQNVHHWI1fUP6g/edNJPG7ktddBpvfVH2AUmMK7/tgD3f687C1HUsL3cQ5WkWM k/Gcn6Oi5r8QgcSx3BzG6FyRM3kqjvh9NNG2+4IpfcQaWoEwkfmChhX9FAfmv2AIWerQ ld7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KLl+5beI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a21-20020a05622a02d500b004035a6b7724si3164024qtx.665.2023.07.07.13.44.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:44:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KLl+5beI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGa-0004zN-2Y; Fri, 07 Jul 2023 16:41:24 -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 1qHsGM-0004o1-2t for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:10 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGK-0004kr-3Y for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:09 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fb4146e8deso29580435e9.0 for ; Fri, 07 Jul 2023 13:41:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762466; x=1691354466; 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=BvCmbIPrY85Qj0xJIhdk6WMERPf4zDCfB4ii0LMHB14=; b=KLl+5beIy5d/Or79p7wL2ZUINOf8is3PBYA1CgLVbX+AS5FlnzP9OO9QBnPUm0TLsM /atE6H0yS4rBywUY0vpiHkyzALSCCex2PCGiwFz5PEO3UhtTK8LhZLEC26aqLgBe4w73 ErLGZy7xZnlTVuuuFfutUk3RkZ2rXQkKjv3KpVQH0uFN7QVPdQwaQFFBrpvtLABQgmjk 77dIZbOezX6aopsoNfwKJzCpDMKURN956yXvj+wPS7jA9Bvx6jlVoCa1lVYHrT8PWPqp Aka35xs315wCd7/oRRWRQbc2D5W8m/XWPF9dVL7DDruFydeNwjkYZ/GIJNzwJ4gRpVAu mU3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762466; x=1691354466; 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=BvCmbIPrY85Qj0xJIhdk6WMERPf4zDCfB4ii0LMHB14=; b=AITctq2Wq31+M/c/CvXM38/5HCBGUzaAN7nKGxFu8w9/A0VFOaIid+/gOsNFT7QWIw T3lI6a4q/fFpSCN8TGBYUYZIxIyIKNQ35BDRlE+LOLUnKLv0+8onF9QXLRRizLXWglDn a1BXHR/soasuJv213k1GXKWjwIF/ZhOr6GV4aGY2ymQBeu+KQnz9YkNIjUg48Ygvbujj AqW4k3x0FJ5rkFlJxEORG7cJT2SzwBmxXrPGSgDHuqmiczPOU2rfGKBq1yHMzRcfoO7E sORcjZj1PbHx4L/PzZG1hTyZ2Kr6OdSFCbOb8FPH8LVQ5o/I/at8dHIW5f4MXOz9XbUP q76Q== X-Gm-Message-State: ABy/qLbBS0W+R4Oi8CShL+tMTk3Yif/QeLHSFH9Pe/+4CkiSRianVSHw XliB32+4ueVhbCKORTTdqJKmBQ8IuawNaVgUAHvKqw== X-Received: by 2002:a1c:4c08:0:b0:3fa:935e:e185 with SMTP id z8-20020a1c4c08000000b003fa935ee185mr6638470wmf.22.1688762466658; Fri, 07 Jul 2023 13:41:06 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru Subject: [PATCH v2 14/24] accel/tcg: Introduce page_find_range_empty Date: Fri, 7 Jul 2023 21:40:44 +0100 Message-Id: <20230707204054.8792-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32b.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Use the interval tree to locate an unused range in the VM. Signed-off-by: Richard Henderson --- include/exec/cpu-all.h | 15 +++++++++++++++ accel/tcg/user-exec.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index 94f828b109..eb1c54701a 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -236,6 +236,21 @@ int page_check_range(target_ulong start, target_ulong len, int flags); */ bool page_check_range_empty(target_ulong start, target_ulong last); +/** + * page_find_range_empty + * @min: first byte of search range + * @max: last byte of search range + * @len: size of the hole required + * @align: alignment of the hole required (power of 2) + * + * If there is a range [x, x+@len) within [@min, @max] such that + * x % @align == 0, then return x. Otherwise return -1. + * The memory lock must be held, as the caller will want to ensure + * the returned range stays empty until a new mapping can be installed. + */ +target_ulong page_find_range_empty(target_ulong min, target_ulong max, + target_ulong len, target_ulong align); + /** * page_get_target_data(address) * @address: guest virtual address diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index ab684a3ea2..e4f9563730 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -605,6 +605,47 @@ bool page_check_range_empty(target_ulong start, target_ulong last) return pageflags_find(start, last) == NULL; } +target_ulong page_find_range_empty(target_ulong min, target_ulong max, + target_ulong len, target_ulong align) +{ + target_ulong len_m1, align_m1; + + assert(min <= max); + assert(max <= GUEST_ADDR_MAX); + assert(len != 0); + assert(is_power_of_2(align)); + assert_memory_lock(); + + len_m1 = len - 1; + align_m1 = align - 1; + + /* Iteratively narrow the search region. */ + while (1) { + PageFlagsNode *p; + + /* Align min and double-check there's enough space remaining. */ + min = (min + align_m1) & ~align_m1; + if (min > max) { + return -1; + } + if (len_m1 > max - min) { + return -1; + } + + p = pageflags_find(min, min + len_m1); + if (p == NULL) { + /* Found! */ + return min; + } + if (max <= p->itree.last) { + /* Existing allocation fills the remainder of the search region. */ + return -1; + } + /* Skip across existing allocation. */ + min = p->itree.last + 1; + } +} + void page_protect(tb_page_addr_t address) { PageFlagsNode *p; From patchwork Fri Jul 7 20:40:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700060 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4066526wrs; Fri, 7 Jul 2023 13:45:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlEKXHEpVZEtlUgJ9euZkI6HpFvXFgHMJgSDJYAnUsIr0Q1H+WkU3FJOJqMyZ7PPx9YZfZMh X-Received: by 2002:ac8:5bd3:0:b0:402:d5b0:6324 with SMTP id b19-20020ac85bd3000000b00402d5b06324mr9051208qtb.45.1688762735928; Fri, 07 Jul 2023 13:45:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762735; cv=none; d=google.com; s=arc-20160816; b=0Sn02J1KY6ohxDawS6e8uPlFPsnOQPUoZYpahCzDuVm09wrx2EDY8NrAYe+xeXJH4C NFdYXRyoQXvQW1AncW3YBRyRLCUm0DkyuO5GEOITZc4sXg8ih71Syu/Nl1MRNiamVHOh U5jF+Ej6oK2m5Z0lTQ1XcoXXZS2VytZeqS7yf/IOaPgTTWuUEkn/RAuBzs0nSvGwOhZ5 ZLoQ+RSvFn8hOC+JwOjjx+0qI86Li+O7xIY57IvX96DAYsfEKIxAJfzstWNkaue5LGGy LrF6MnTfk1bp1c9BYuImdN/TGImY/Fhuy3+/CndegY0dNFpztxEMd3Y3fpDRJu+T+/5L AF3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PKe+fUX0NmdphUHrFTyrG/qLSqkF3tQdOsXgmGYWYgc=; fh=c5yfIwOUC8JO1RlChQuc3YChZ5JSRT1D/lDsc4eQOLI=; b=Y6ilGYfKKVzyUhtJJl6conDo4RfLfHHpbmKoecEVhmT7l4FO0CJiuWLPjS48LIjHbP qu6qUKi0cZzvkV8keA3Ty8FYefSGOE+Z4hIBNCQQcN6aqjXrVrNHKYzAWnHCaklkp5xf 8qCUfLsRCktkIX05mmiEVr06QTatWH2ohvsnwh8jseXgGCwxSBWW5BTPQ86m+8wy5zLM 2mslcd+KKcZzTY0cRSVkvwaQWi3KURWnQ6YvHPJp6UbRmRs4Z3RL/mbBjhzMyjswzH1D rUkJ+sO3qOrGKFxvRVqYM0hiqQehUwkO9pL+6+HvqCqaq54boxx8nEbYBPlR1Osw3pDE YvEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hqkcjVrj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id pi1-20020a05620a378100b00767471599e3si3249556qkn.253.2023.07.07.13.45.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:45:35 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hqkcjVrj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGa-0004zS-IG; Fri, 07 Jul 2023 16:41:24 -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 1qHsGM-0004oG-DQ for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:10 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGK-0004m8-Ro for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:10 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fbea147034so24480915e9.0 for ; Fri, 07 Jul 2023 13:41:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762467; x=1691354467; 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=PKe+fUX0NmdphUHrFTyrG/qLSqkF3tQdOsXgmGYWYgc=; b=hqkcjVrjecW9ZGOCxywyxtkSkvDxsHfzboWDqkQozjmmZlpNf4L6Lci466McRPMknX UZwT4OFF5rE4nlPv5DabmD0C3J6HdZ25OPT7fDFsu4p2tV/eeYOjd+YBXN4jFmwoPKeZ zxboOLhK3s5VLVj1dBrTtY4u2hbA4YPtn7q3Xuv79kyc+b8PywoalbHupzCSS0dE1/T4 eP6v70sfJ2JrPQSBd8uAfCdO/hB+bEAnLNz2+OCM3opQNTdHIoYz1NuoDMtvIJ4lpFp4 Lg/aJiYXq+x3Oek1TDjwvYUyBjgzoTgdUeuC6bFzGpua2YXpB+fNMKvst1XAvDPuvNGI jL2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762467; x=1691354467; 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=PKe+fUX0NmdphUHrFTyrG/qLSqkF3tQdOsXgmGYWYgc=; b=jirhNnmA1HZdmoxV5EihpO7I+Ldpq8wty3xajhv+QkLfbVyny/Bj49KHKdGvrqc1zx mtk0qRv4nkw3ircz8BU1jA5T/gAY9l2OW6Av9FdRB19E267buYiL1KKZYxSfMg0x7QvH PgtjR0BSow0XYQGmG5dA5jTNe/efoq0x4xVOBm8vC2jUTCcSrneLvQjrt0hUQiZ7sc2i BD8O1rCzrfPtl4nA4UYH/7wAr1+eua1xG8/uOTzHTlv5XDCKZ/jx4ob3u9/WsxMr0rQk MQ1/PlbmaLpr3sMdh6hRHBboMJh/ASqZO3IVSCWYEYhs9KwXQPv5gd1NPZ8744eQv06Q Z3Sg== X-Gm-Message-State: ABy/qLYOP626dwRKRTPh+ec8IaKJPaeVw9SULIfkE2CHEfwoFJVPgpgs UrZxiSWVfW+YFZEGAgw+kp6jnf3yiFWItFpFd/3C+w== X-Received: by 2002:a7b:cd8c:0:b0:3fa:991c:2af9 with SMTP id y12-20020a7bcd8c000000b003fa991c2af9mr4826847wmj.16.1688762467409; Fri, 07 Jul 2023 13:41:07 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru, Warner Losh , Kyle Evans Subject: [PATCH v2 15/24] bsd-user: Use page_find_range_empty for mmap_find_vma_reserved Date: Fri, 7 Jul 2023 21:40:45 +0100 Message-Id: <20230707204054.8792-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x329.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Use the interval tree to find empty space, rather than probing each page in turn. Cc: Warner Losh Cc: Kyle Evans Signed-off-by: Richard Henderson --- bsd-user/mmap.c | 48 +++++++----------------------------------------- 1 file changed, 7 insertions(+), 41 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 07b5b8055e..aca8764356 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -222,50 +222,16 @@ unsigned long last_brk; static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size, abi_ulong alignment) { - abi_ulong addr; - abi_ulong end_addr; - int prot; - int looped = 0; + abi_ulong ret; - if (size > reserved_va) { - return (abi_ulong)-1; + ret = page_find_range_empty(start, reserved_va, size, alignment); + if (ret == -1 && start > TARGET_PAGE_SIZE) { + /* Restart at the beginning of the address space. */ + ret = page_find_range_empty(TARGET_PAGE_SIZE, start - 1, + size, alignment); } - size = HOST_PAGE_ALIGN(size) + alignment; - end_addr = start + size; - if (end_addr > reserved_va) { - end_addr = reserved_va + 1; - } - addr = end_addr - qemu_host_page_size; - - while (1) { - if (addr > end_addr) { - if (looped) { - return (abi_ulong)-1; - } - end_addr = reserved_va + 1; - addr = end_addr - qemu_host_page_size; - looped = 1; - continue; - } - prot = page_get_flags(addr); - if (prot) { - end_addr = addr; - } - if (end_addr - addr >= size) { - break; - } - addr -= qemu_host_page_size; - } - - if (start == mmap_next_start) { - mmap_next_start = addr; - } - /* addr is sufficiently low to align it up */ - if (alignment != 0) { - addr = (addr + alignment) & ~(alignment - 1); - } - return addr; + return ret; } /* From patchwork Fri Jul 7 20:40:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700062 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4066651wrs; Fri, 7 Jul 2023 13:45:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlG2bzAJsG4Hp/MXqJdXef323WJEcLFGPZHy7IPA8SSkEK9fNTB0N5VNU79Me1w7cC90qNh5 X-Received: by 2002:ac8:5e51:0:b0:403:2e12:69ad with SMTP id i17-20020ac85e51000000b004032e1269admr8631629qtx.11.1688762755218; Fri, 07 Jul 2023 13:45:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762755; cv=none; d=google.com; s=arc-20160816; b=LT/rNWVtyNOtmg5S85PlFCjhxYWGao7Ny4Y2YkWNoeB9ucUcYCU+tcmq14NQx/gZ3k KWvQFvI5zS4U1Ze5OmKp98V4x2N2dByx7V8hRD/4Ed1SC0qiSq/PYcXptpcRHwWOQh09 Czlo2e+FkhNz08HnaSC5uMK/Bo4n0TMCz/cZfUdAngcU5Er6ETKH1/Mo+qlZ4xeIUD8h ryVWEDZgEs6cS0SRc/X6+7y9cyaSrPobLJul5HtSA1c7jdO+woR70H65F0wj2HoM6QGV YnCyWjVRFaPhIYpni79heWnjG07avOHuh4hClLcVA0XoPndYebnywoMWMfngVxym14YH oyqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kiFBqOav2YcGHKvTnJ77ytzLXJE7Ik+NidTUqHroIfU=; fh=jVqwU2n6uDjg7kXqsBiuuwMdTrtXxwX52l5dkNb4FWE=; b=tTb19nOvePXFsWkuOxllCqz8txsMctGsB2ZgW2iQMpBW/SneILxDZnQ8VFx6uVCplJ ZzUrIo0qX2ympR/6sLmfLgB5Cyaw+bsqVEslDsIGfbkZZZKdG1dFwNFkUNdDpoM5BMyM qSPTnT9ZpzNt5widHrXmxxeU4id6y8zUWnb2lWV9ixL+eA4sthUOgEYmHEFXcWGIYpf8 XtbfYlvs/ryhYAyXS1fSvJec5lRrE8+P/+9ATUM+rfTARjA5k8kgkfrvFY0fNNwvS82t 7jXkzNnOuHQsUu3NQZCyIvIeLrf+hizo+R5FPbxeI233imP0IwuHhqsGlnZ+y0o5LsmB T5LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sVuOsFi4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c21-20020ac87dd5000000b004035964d820si3234142qte.311.2023.07.07.13.45.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:45:55 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sVuOsFi4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGP-0004qB-MB; Fri, 07 Jul 2023 16:41:13 -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 1qHsGM-0004oj-Sc for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:10 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGL-0004mi-5a for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:10 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3fbf1b82d9cso25265845e9.2 for ; Fri, 07 Jul 2023 13:41:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762468; x=1691354468; 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=kiFBqOav2YcGHKvTnJ77ytzLXJE7Ik+NidTUqHroIfU=; b=sVuOsFi4B0MTOTW82lsGjgcUiO0FfrFjm9YLeoJ2bqc5UFqIBl8bOZyTdByuZjnAaT j4AlrXkMkkji2OyW+MLNiLyTYjA5O+amD3OvQw3pIlomFBj0rALDdhYUufQidE9LYMKv ri+pcb7JVHCFOaB33j7uoq05rnXjwDqdCvZbhdxqvYdCWxrfql5fuSma1iSxM2enoQIe IfR3Wrz/f2SsGJ5TDNlNvgic94Ekz8TKu3Q2Nlfm1bu3S/3QWtbgR+Hfuh22qaZkNrKZ QtdZdOvHruC2C3edPq5qNXX8fcgJmfRSVS7TABILOGNOOAwxZs590agkYZ7NSx7Lvxb5 fI3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762468; x=1691354468; 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=kiFBqOav2YcGHKvTnJ77ytzLXJE7Ik+NidTUqHroIfU=; b=CvrvBQ5QG49EnITLkCa715WDFEuC0glJTXSd6pyMtHtRjkWVT7iTHnBlMBNLfdYzjD XsnOeNmpqx4w6lYsRIoe1lhXWnyqXcjr0YCJ2XfTjXpZyrPVRKiLLi6pqNPQNcTYaLNc CXCDCQTR9wjRVXTWJ6qbR3BYUbGD3Bvm17IAOYptldsuwjYpmMiRCdYW1nj8TDHD6XDZ aA9yZftC38F5zbGK3+L103NlR0w4V1EQjqZDIfcmYyQMMADFmMMxXw/dv+m1BeGkkLmY 4kiQvyV3ndUtHIiUnC2wDf4FrlGfnx3j2mpdH/kCsSmfnZepjsa/PEVQO6HqPiN15X9b rDNg== X-Gm-Message-State: ABy/qLbSFmbahPeBjDnLFLNVznhw5g1zmeE329Xd6KQihe8ilD05ERq9 gyM+9LnQYyArQ1sX9bznAS4V6Oks3oU6u1lV6rYgvQ== X-Received: by 2002:a7b:cc86:0:b0:3f9:c8b2:dfbd with SMTP id p6-20020a7bcc86000000b003f9c8b2dfbdmr3576182wma.19.1688762467883; Fri, 07 Jul 2023 13:41:07 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru Subject: [PATCH v2 16/24] linux-user: Use page_find_range_empty for mmap_find_vma_reserved Date: Fri, 7 Jul 2023 21:40:46 +0100 Message-Id: <20230707204054.8792-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x331.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Use the interval tree to find empty space, rather than probing each page in turn. Signed-off-by: Richard Henderson --- linux-user/mmap.c | 52 ++++++----------------------------------------- 1 file changed, 6 insertions(+), 46 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index db4705e049..6ecdf9e56d 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -317,55 +317,15 @@ unsigned long last_brk; static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size, abi_ulong align) { - abi_ulong addr, end_addr, incr = qemu_host_page_size; - int prot; - bool looped = false; + target_ulong ret; - if (size > reserved_va) { - return (abi_ulong)-1; + ret = page_find_range_empty(start, reserved_va, size, align); + if (ret == -1 && start > mmap_min_addr) { + /* Restart at the beginning of the address space. */ + ret = page_find_range_empty(mmap_min_addr, start - 1, size, align); } - /* Note that start and size have already been aligned by mmap_find_vma. */ - - end_addr = start + size; - /* - * Start at the top of the address space, ignoring the last page. - * If reserved_va == UINT32_MAX, then end_addr wraps to 0, - * throwing the rest of the calculations off. - * TODO: rewrite using last_addr instead. - * TODO: use the interval tree instead of probing every page. - */ - if (start > reserved_va - size) { - end_addr = ((reserved_va - size) & -align) + size; - looped = true; - } - - /* Search downward from END_ADDR, checking to see if a page is in use. */ - addr = end_addr; - while (1) { - addr -= incr; - if (addr > end_addr) { - if (looped) { - /* Failure. The entire address space has been searched. */ - return (abi_ulong)-1; - } - /* Re-start at the top of the address space (see above). */ - addr = end_addr = ((reserved_va - size) & -align) + size; - looped = true; - } else { - prot = page_get_flags(addr); - if (prot) { - /* Page in use. Restart below this page. */ - addr = end_addr = ((addr - size) & -align) + size; - } else if (addr && addr + size == end_addr) { - /* Success! All pages between ADDR and END_ADDR are free. */ - if (start == mmap_next_start) { - mmap_next_start = addr; - } - return addr; - } - } - } + return ret; } /* From patchwork Fri Jul 7 20:40:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700050 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4065882wrs; Fri, 7 Jul 2023 13:43:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlHpUBTXpqDp42RPhCfnP5dMarWameKam8YPi9RVqh7XJl1WSpgxSDuaa96fOmrQWbMDX+ib X-Received: by 2002:a0c:e0d3:0:b0:635:f921:de18 with SMTP id x19-20020a0ce0d3000000b00635f921de18mr5056572qvk.53.1688762625822; Fri, 07 Jul 2023 13:43:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762625; cv=none; d=google.com; s=arc-20160816; b=VTPwMISOL6bi78L+hrIE9jCSp18M4ugV6s/QSCuOBuz4SSCS6KnVhc/Fm4MhofCOyz hozNvdefgnQcOYdFoHGKWXyiOigwT/dhqWnvg//OD2F8OJJH87U1THzdENky5cTiU8PA KaMgKZI4gkCYU/3bEv7WkZp8EPD48/K6s7Bn7xEcfUe++4zB5/FNb9XDQld7UXog2N5B 7CXiPivEscceSXn1XMePHbfUdj2sKQPeJhywo679bGoy3ciYuAEoebsPdbWKcYyHhW8S nn170FFnAUYT1+cApYSBxVKaKvl8FRPh4NWgAcBlDOKJl495RkGOk0LONeuYV5u171Q/ gdCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VDUsgzcY3wT2DD7oU5Y2Go2253hS4srcoNjY2t7BE68=; fh=jVqwU2n6uDjg7kXqsBiuuwMdTrtXxwX52l5dkNb4FWE=; b=L1PK8iGW+3CLJ42CwNk/1UISDkz2dlv/50sjch9cPPxH+pdfhc1pZAhk9IXSWp8sF6 akZlktcwKSJihWIGE8EtQK/ABWQU66OUVx7+ATvEsrMM0OR0/KgJCajlahd1L7dWL2yW 3zaQ24dN3QnLMhmiCtaHYulc+DI6UQ+ncs6iMeXbPwL02nsy1OEwDNNfCt8d9HQRctNd 2Awyft1Uah2R46i32hSjv8m8KOhT2CvLSJw2G0RZC4zXixiLLBZVGazsi2NOwEVwOolF He+qbyVLpYaBz2bPpzhY7Pj/3uKclpE6Oe6VFUqrdcts5K1OUf1lYyNKMz1k1XJ1L9eR HFGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="XG/IaR+R"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e20-20020a0ce3d4000000b00571bb7c3c01si3126651qvl.337.2023.07.07.13.43.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:43:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="XG/IaR+R"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGR-0004qd-S4; Fri, 07 Jul 2023 16:41:15 -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 1qHsGN-0004pY-K4 for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:11 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGL-0004nm-PB for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:11 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3fbc5d5742eso25639645e9.3 for ; Fri, 07 Jul 2023 13:41:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762468; x=1691354468; 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=VDUsgzcY3wT2DD7oU5Y2Go2253hS4srcoNjY2t7BE68=; b=XG/IaR+R2DTf+Lf3VhSuFhaAxFEtyJhmQ+KvpGwEhQN19ikfHnvH6NVwhGFN5ZmBQf 9IlImciC6Sg2+DArbiLuDnPrXlQWntpe6CvFEtVMrZq0oJUeSWy0/hxUcJyBc/tJdiHe dEaRSb6XNCvcrjJ8sowQJmD1+s8rKYo3k+jF0uBglhgx0ejq5Uv+lXohKl6CyAbE/9xf o/CioblQrkPdddnKLgLsTcRWvhDBECz1Lo6xo5ZKtQKK4AzQmkOeyRgcvgp3KHvelkT4 tw0ykVbfBPPyvGQnQCNrW6oLhXMVfU7OJQeYoMvPNe5BJDd+LR3aAPcTk+nYJRQy7WzY 8Kyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762468; x=1691354468; 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=VDUsgzcY3wT2DD7oU5Y2Go2253hS4srcoNjY2t7BE68=; b=ODTNT4/rJykFeH4ovohHuTtueaFEsrYQ+YPLcyxrAch84uBa+QLKvOuiEZq1ZK3pEE dgAb8dDX2RutoM0WGAnoc4Bqrf/vi/SDGUtqOBwklSn0g6cJU/rYk7qyfBo4CGdR3lpo 3xaeZL7mTbG8cXJPaPvm5hbx19aV0HlgEnCbCEsv2NZ+7cwBxf0IoW6jCRkCsMro8RWZ vGT8YrTNmiXPuhECiIYH8/yP/y1LXAXNVGhhXh8KXvae3m2ZxDPN5hHbZwryWfryPYLS UAeVDIqeqxhBns7YvQcKJeCC8FKRnskZNNiGdp+tP4vLjnjoxK4xfBUwvCKDbtZhyIji yVgw== X-Gm-Message-State: ABy/qLamqotYwtEYubhULWTjHMx2G5EP7u7wp6q/vvQXvRKEhY3AzPk+ +QNmRdzMvTPfwT9oWriIUxdjqedbYXZaYCWE0DWRdA== X-Received: by 2002:a05:600c:b45:b0:3fb:bc6d:41f1 with SMTP id k5-20020a05600c0b4500b003fbbc6d41f1mr4633186wmr.17.1688762468502; Fri, 07 Jul 2023 13:41:08 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru Subject: [PATCH v2 17/24] linux-user: Use 'last' instead of 'end' in target_mmap Date: Fri, 7 Jul 2023 21:40:47 +0100 Message-Id: <20230707204054.8792-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x336.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Complete the transition within the mmap functions to a formulation that does not overflow at the end of the address space. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- linux-user/mmap.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 6ecdf9e56d..67a117823f 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -455,8 +455,8 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, int flags, int fd, off_t offset) { - abi_ulong ret, end, real_start, real_end, retaddr, host_len, - passthrough_start = -1, passthrough_end = -1; + abi_ulong ret, last, real_start, real_last, retaddr, host_len; + abi_ulong passthrough_start = -1, passthrough_last = 0; int page_flags; off_t host_offset; @@ -580,29 +580,30 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, host_start += offset - host_offset; } start = h2g(host_start); + last = start + len - 1; passthrough_start = start; - passthrough_end = start + len; + passthrough_last = last; } else { if (start & ~TARGET_PAGE_MASK) { errno = EINVAL; goto fail; } - end = start + len; - real_end = HOST_PAGE_ALIGN(end); + last = start + len - 1; + real_last = HOST_PAGE_ALIGN(last) - 1; /* * Test if requested memory area fits target address space * It can fail only on 64-bit host with 32-bit target. * On any other target/host host mmap() handles this error correctly. */ - if (end < start || !guest_range_valid_untagged(start, len)) { + if (last < start || !guest_range_valid_untagged(start, len)) { errno = ENOMEM; goto fail; } /* Validate that the chosen range is empty. */ if ((flags & MAP_FIXED_NOREPLACE) - && !page_check_range_empty(start, end - 1)) { + && !page_check_range_empty(start, last)) { errno = EEXIST; goto fail; } @@ -642,9 +643,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, /* handle the start of the mapping */ if (start > real_start) { - if (real_end == real_start + qemu_host_page_size) { + if (real_last == real_start + qemu_host_page_size - 1) { /* one single host page */ - if (!mmap_frag(real_start, start, end - 1, + if (!mmap_frag(real_start, start, last, target_prot, flags, fd, offset)) { goto fail; } @@ -658,18 +659,18 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, real_start += qemu_host_page_size; } /* handle the end of the mapping */ - if (end < real_end) { - if (!mmap_frag(real_end - qemu_host_page_size, - real_end - qemu_host_page_size, end - 1, + if (last < real_last) { + abi_ulong real_page = real_last - qemu_host_page_size + 1; + if (!mmap_frag(real_page, real_page, last, target_prot, flags, fd, - offset + real_end - qemu_host_page_size - start)) { + offset + real_page - start)) { goto fail; } - real_end -= qemu_host_page_size; + real_last -= qemu_host_page_size; } /* map the middle (easier) */ - if (real_start < real_end) { + if (real_start < real_last) { void *p; off_t offset1; @@ -678,13 +679,13 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, } else { offset1 = offset + real_start - start; } - p = mmap(g2h_untagged(real_start), real_end - real_start, + p = mmap(g2h_untagged(real_start), real_last - real_start + 1, target_to_host_prot(target_prot), flags, fd, offset1); if (p == MAP_FAILED) { goto fail; } passthrough_start = real_start; - passthrough_end = real_end; + passthrough_last = real_last; } } the_end1: @@ -692,16 +693,16 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, page_flags |= PAGE_ANON; } page_flags |= PAGE_RESET; - if (passthrough_start == passthrough_end) { - page_set_flags(start, start + len - 1, page_flags); + if (passthrough_start > passthrough_last) { + page_set_flags(start, last, page_flags); } else { if (start < passthrough_start) { page_set_flags(start, passthrough_start - 1, page_flags); } - page_set_flags(passthrough_start, passthrough_end - 1, + page_set_flags(passthrough_start, passthrough_last, page_flags | PAGE_PASSTHROUGH); - if (passthrough_end < start + len) { - page_set_flags(passthrough_end, start + len - 1, page_flags); + if (passthrough_last < last) { + page_set_flags(passthrough_last + 1, last, page_flags); } } the_end: From patchwork Fri Jul 7 20:40:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700045 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4065732wrs; Fri, 7 Jul 2023 13:43:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlFeuHlmrTiP2nA2ykOr9USPQYNEyE4HQ0lKkxQVWH4JhnPYCSvc0uPZbwxNXuj5Kzp3gV4n X-Received: by 2002:ac8:588d:0:b0:403:394c:bf39 with SMTP id t13-20020ac8588d000000b00403394cbf39mr5253694qta.40.1688762592823; Fri, 07 Jul 2023 13:43:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762592; cv=none; d=google.com; s=arc-20160816; b=xK0UNWm19Yj2AaQ4kb/KQAP0V4wggALlilKwKWEGfUuFIWWsY6qTHr11ROs7wGl54J 026lc2ukeC7fxmX9fh8kb+kn6Luxp/ht1RmzH5/v6fCumIFFZhjMgS/4VwmQtMMiHQj6 YahQHix3bVfAUH187k4XMIgxkawGey6Pq2PCY1ni/2yJb8qkM9g7xHZjwCGQVQG4QQwa Oj2z9MAj8zbjJXLqyvCk6CJBRXABYOl76WNbu8uosDUfVXkxyl9j7ILmnKFgDb6kYKc+ Xbq8SDb4pwV2h83DJDL2IFSZbvoGWzjAHSuepNQuz5qyNv5W165Q8qbK4xUtIv0HbWZc 67MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0rcUcYz/ENHU71nYFSKtvNzNb/+e+Z1fgOhw2rx254o=; fh=jVqwU2n6uDjg7kXqsBiuuwMdTrtXxwX52l5dkNb4FWE=; b=pR9lxRKCdbVdADPZV0CAUti0e+UG2Zmaf6dx1YKBK5DFKEWA/QBqK6FJBvTZaFHZR+ BA2/cJ48IsPAmwksS1zUv+Vn1g12cu6sXOc98k3xuqEmy1i5ynEQY3ei/Us+aysBMu/K BaSRhxhuGWc6PJjBZoNc/pK1EN2Rs714BBJ0+HPlyzjI5gPVlFZq264Q5KsdMpck8OvC xnSJKdppH5XEZUjh36poUh/15Fvcze3x10A3xc2rp7rUCFYHkUNxN3T0mi8Xp68HE9+3 HrSeMoz3tftBIHMaDAqws0jC9c6OSYi4aTZA6sPO42UeUrNFjecqKMrJ9jnXQQK7WUpM 4Jyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ALrpDHm1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h14-20020a05622a170e00b003f8682e1211si3218544qtk.360.2023.07.07.13.43.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:43:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ALrpDHm1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGT-0004r7-Sf; Fri, 07 Jul 2023 16:41:17 -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 1qHsGO-0004ph-DO for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:12 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGM-0004oc-OA for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:12 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3142ee41fd2so2412540f8f.3 for ; Fri, 07 Jul 2023 13:41:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762469; x=1691354469; 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=0rcUcYz/ENHU71nYFSKtvNzNb/+e+Z1fgOhw2rx254o=; b=ALrpDHm1yixuEDx84oh/VAWyOmAdn+xln8TIxt/+JACL7ScSF+xrsSW7MKV2K2u75j A+cDe40s/6reaI8XT6rJTTdutml0TPdMXpwDODuwU0iNlOOKamit2kayfizBmFkyy5or 2nsNljUZCtRcSyFcZ2bbhAa4yaEpCu/15QssKFy7Vj2ZKsrUw24M1W9El40hnxi4LAUP 7RSiW9mFi+GIcl/sgd13VX1SgiLj03JCYK6HIMwopj34sDXfu7gphyMbJnw8FPAfoN5D xINizRUaGhWptXS1ZFTvyMOdiqskEnSxSIUfE5qln1Evc31cK7jbPB3WeEpD31JFyOrR GkNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762469; x=1691354469; 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=0rcUcYz/ENHU71nYFSKtvNzNb/+e+Z1fgOhw2rx254o=; b=Mi81ssTLTrnWgwHF8SK1dBgtPx/iE8Nw0TPulxbyZpYq2wVDOqf+21qBIpklZ4SQ4u BRRLbd3gCSdi5tslWHXU9Z3sUBTSsfun2xubW+0ZQs0ug/yh4JZzE+xnHDZEr7aHAUtW k7EhVkpfDsJeHYRMDmUQMopJarDD88iDfryHH+0FAZKtvS0UKu9fT5zvEGn/Wp2MH5iQ beu1UObEYUyhRdhV09SU9XhnXNmbiIiUKRIavXGyd2RBvywsipGODloEd/X7MVPcCjNa 1yAfCD1pnsngnD9gxPSmcwouwjSKd9JiBHRyTyDqEzlHkb5js2N/H29j0ca+DbNyl8gE G+iA== X-Gm-Message-State: ABy/qLabN00x+6iNVFCJiLKEdErgzgPkGcvapJxobshZKaX1/84dHOEw 5SVAoalcN8I8CV+KVYZD5NCfAmhPrD+dgVCtaItfzg== X-Received: by 2002:a05:6000:104c:b0:313:e55f:b78c with SMTP id c12-20020a056000104c00b00313e55fb78cmr4711529wrx.21.1688762469252; Fri, 07 Jul 2023 13:41:09 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru Subject: [PATCH v2 18/24] linux-user: Rewrite mmap_reserve Date: Fri, 7 Jul 2023 21:40:48 +0100 Message-Id: <20230707204054.8792-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x436.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Use 'last' variables instead of 'end' variables; be careful about avoiding overflow. Assert that the mmap succeeded. Signed-off-by: Richard Henderson --- linux-user/mmap.c | 68 +++++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 67a117823f..6b030dac42 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -722,47 +722,63 @@ fail: return -1; } -static void mmap_reserve(abi_ulong start, abi_ulong size) +static void mmap_reserve(abi_ulong start, abi_ulong len) { abi_ulong real_start; - abi_ulong real_end; - abi_ulong addr; - abi_ulong end; + abi_ulong real_last; + abi_ulong real_len; + abi_ulong last; + abi_ulong a; + void *host_start, *ptr; int prot; + last = start + len - 1; real_start = start & qemu_host_page_mask; - real_end = HOST_PAGE_ALIGN(start + size); - end = start + size; - if (start > real_start) { - /* handle host page containing start */ + real_last = HOST_PAGE_ALIGN(last) - 1; + + /* + * If guest pages remain on the first or last host pages, + * adjust the deallocation to retain those guest pages. + * The single page special case is required for the last page, + * lest real_start overflow to zero. + */ + if (real_last - real_start < qemu_host_page_size) { prot = 0; - for (addr = real_start; addr < start; addr += TARGET_PAGE_SIZE) { - prot |= page_get_flags(addr); + for (a = real_start; a < start; a += TARGET_PAGE_SIZE) { + prot |= page_get_flags(a); } - if (real_end == real_start + qemu_host_page_size) { - for (addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) { - prot |= page_get_flags(addr); - } - end = real_end; + for (a = last; a < real_last; a += TARGET_PAGE_SIZE) { + prot |= page_get_flags(a + 1); + } + if (prot != 0) { + return; + } + } else { + for (prot = 0, a = real_start; a < start; a += TARGET_PAGE_SIZE) { + prot |= page_get_flags(a); } if (prot != 0) { real_start += qemu_host_page_size; } - } - if (end < real_end) { - prot = 0; - for (addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) { - prot |= page_get_flags(addr); + + for (prot = 0, a = last; a < real_last; a += TARGET_PAGE_SIZE) { + prot |= page_get_flags(a + 1); } if (prot != 0) { - real_end -= qemu_host_page_size; + real_last -= qemu_host_page_size; + } + + if (real_last < real_start) { + return; } } - if (real_start != real_end) { - mmap(g2h_untagged(real_start), real_end - real_start, PROT_NONE, - MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE, - -1, 0); - } + + real_len = real_last - real_start + 1; + host_start = g2h_untagged(real_start); + + ptr = mmap(host_start, real_len, PROT_NONE, + MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE, -1, 0); + assert(ptr == host_start); } int target_munmap(abi_ulong start, abi_ulong len) From patchwork Fri Jul 7 20:40:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700046 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4065778wrs; Fri, 7 Jul 2023 13:43:21 -0700 (PDT) X-Google-Smtp-Source: APBJJlFjr8lGUScbEuTqqs056eqxyGuWxp3JL05AQNnGqsu34Zn4z3IMmu05f7juoNJQgv7pqpOp X-Received: by 2002:a05:620a:40d6:b0:765:8a18:e3c0 with SMTP id g22-20020a05620a40d600b007658a18e3c0mr8079744qko.57.1688762601349; Fri, 07 Jul 2023 13:43:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762601; cv=none; d=google.com; s=arc-20160816; b=OQPg5V2La3ZDGR0iQ5sdczZhls2NDuekh5wA1HaXpIakOEUCsh5dTIBgsdR0A60+BK AHTMXRvVc6v7rBlYrat8ZoYV5MvVH17DEvX8+H93IvlqfLz2GSriiK4qfq6P0GBHq3aR +kzg3fPwOjZKhYMsYOyPRLs7yynL3/r2BuRUAuJRgwXF9ZZJIG937cWO7oH44J6pEFCv cGVuMj62TqBMeI5li8axKq4ExHvdoe9kbzbT3bRzTxBsQEImvskW32sr96RxQKfLSUrn ZAFrrlTzJcfLJo6N/tt4k75WLgzE59MIs2aaINFBBh01FtUHb5zcaXhHlDaYFqSU7lAQ LWRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mwwpiV6MaHNjI0ciuX+pvMo7jFfE+x6J89Pmy8AxQUY=; fh=jVqwU2n6uDjg7kXqsBiuuwMdTrtXxwX52l5dkNb4FWE=; b=GMDmWG+O0+9jTt8wK6rzRFd8ZnmQc1x30iEQ7733gA0p/I+nznJ3KoAtT7vFeP13oe OBBfbbJbiWpGD3lbt7W66Cu0PPOGJG9I3xGO3UqTaNtDse9eQtPAsD+lRgITG3VD5BoA zJdNhi2vfdqxx+OTaFkjtD7LBY6ZokXtvhC5eBynQEVFlOKaQ5ypyV/ylb05vjmvBXXT 782hTUAaMZ1AMs6tM9whi8R3eX5uSyWRWd9pUlAqnG36l5YCLbIQB9H50f40RYDn/Yh7 8wdCrRxBpsMcB+sqijXbQcBHD7NdgVz2ZcrGHumu2MVhaIsvrbAFVPmKXL6D59tLGvDi bP5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EYUh2BLP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l13-20020a37f50d000000b0076715a35f43si3161537qkk.495.2023.07.07.13.43.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:43:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EYUh2BLP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGU-0004u0-4r; Fri, 07 Jul 2023 16:41: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 1qHsGP-0004pz-Af for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:13 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGN-0004q7-Dw for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:12 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fbea147034so24481445e9.0 for ; Fri, 07 Jul 2023 13:41:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762470; x=1691354470; 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=mwwpiV6MaHNjI0ciuX+pvMo7jFfE+x6J89Pmy8AxQUY=; b=EYUh2BLPTRNhAdG8tv0Cy5osBdVuMu2/SSrMZ5R2SvfSdaE1zHVjASH1VhZ2UmDL9b VwSRdSaEhBMnmX4ocUljlSp5Zhd2sEG1Y1haV3Qo8dNA6RxB2acGAo3gKsT3YJ52gT/M MbksAWc9pOPXwuk3yiH/nhDXWWNVSTddTNHyN5gwklvWaDmFQiGGooZKBO4Tv7Zlj/P3 sOCuwf1W1AisIy82XRFJ1yonbWO5Xrf6c0vHNR92KdvHziW1kXFt416EXGuLQCipmXxU Dwf09s6qtxmOXMmtT02qQgb1qQw2BCNMa/tjeQp58kw9LacxYEvPGrQbdOE6pbrgAjIZ o1Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762470; x=1691354470; 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=mwwpiV6MaHNjI0ciuX+pvMo7jFfE+x6J89Pmy8AxQUY=; b=XoFzOQBrXVLDpm6B6zoQzsQRggGRffH+y9lrI9XwMileZnsgAzdlpj54idUDFCrSBU 1tDZIeafODRpPFaxOOfCDyt4RKrW36/rGyIwR3m8S2d4dUCmOw5NBZvaBH4jwq7tiiPi HuOIb53crwo6H7TUmYGnvI3D9H65TQj3uMI8moadwCGf9q+/D+wPy9hyQsCtEDJfVbaX T6c/C0K1yR2n1+whtyXpF/cPcCqloDVnczku/bK5CRWwdQCIYNHp8/VQh4827x6mMP7i wHVO2/SIlp858TSKYZqf+ufDt/5l4Skt3FLETOcCCuHK1T6EzjE16yp8ZVId2SziOIPY 3uqA== X-Gm-Message-State: ABy/qLaDfTz+RrGNMpNisoswJPhkt5qX//O4Tl1MAth3cH4D6aVGS4oK 4bN3qt4kXMwcIz7/2uzV3KrtEbpIynhrJXaup0Djyg== X-Received: by 2002:a7b:c389:0:b0:3fc:9e:eead with SMTP id s9-20020a7bc389000000b003fc009eeeadmr1688890wmj.20.1688762470139; Fri, 07 Jul 2023 13:41:10 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru Subject: [PATCH v2 19/24] linux-user: Rename mmap_reserve to mmap_reserve_or_unmap Date: Fri, 7 Jul 2023 21:40:49 +0100 Message-Id: <20230707204054.8792-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32b.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org If !reserved_va, munmap instead and assert success. Update all callers. Signed-off-by: Richard Henderson --- linux-user/mmap.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 6b030dac42..8c90a690dd 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -722,14 +722,14 @@ fail: return -1; } -static void mmap_reserve(abi_ulong start, abi_ulong len) +static void mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) { abi_ulong real_start; abi_ulong real_last; abi_ulong real_len; abi_ulong last; abi_ulong a; - void *host_start, *ptr; + void *host_start; int prot; last = start + len - 1; @@ -776,9 +776,15 @@ static void mmap_reserve(abi_ulong start, abi_ulong len) real_len = real_last - real_start + 1; host_start = g2h_untagged(real_start); - ptr = mmap(host_start, real_len, PROT_NONE, - MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE, -1, 0); - assert(ptr == host_start); + if (reserved_va) { + void *ptr = mmap(host_start, real_len, PROT_NONE, + MAP_FIXED | MAP_ANONYMOUS + | MAP_PRIVATE | MAP_NORESERVE, -1, 0); + assert(ptr == host_start); + } else { + int ret = munmap(host_start, real_len); + assert(ret == 0); + } } int target_munmap(abi_ulong start, abi_ulong len) @@ -830,11 +836,7 @@ int target_munmap(abi_ulong start, abi_ulong len) ret = 0; /* unmap what we can */ if (real_start < real_end) { - if (reserved_va) { - mmap_reserve(real_start, real_end - real_start); - } else { - ret = munmap(g2h_untagged(real_start), real_end - real_start); - } + mmap_reserve_or_unmap(real_start, real_end - real_start); } if (ret == 0) { @@ -871,7 +873,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, * If new and old addresses overlap then the above mremap will * already have failed with EINVAL. */ - mmap_reserve(old_addr, old_size); + mmap_reserve_or_unmap(old_addr, old_size); } } else if (flags & MREMAP_MAYMOVE) { abi_ulong mmap_start; @@ -886,7 +888,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, flags | MREMAP_FIXED, g2h_untagged(mmap_start)); if (reserved_va) { - mmap_reserve(old_addr, old_size); + mmap_reserve_or_unmap(old_addr, old_size); } } } else { @@ -912,7 +914,8 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, errno = ENOMEM; host_addr = MAP_FAILED; } else if (reserved_va && old_size > new_size) { - mmap_reserve(old_addr + old_size, old_size - new_size); + mmap_reserve_or_unmap(old_addr + old_size, + old_size - new_size); } } } else { From patchwork Fri Jul 7 20:40:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700053 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4066027wrs; Fri, 7 Jul 2023 13:44:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlENSQDCDuoNGDr45A4J2/lSTtrBXhxjach8k3icd0ojrT9DBQncodghZaZTkOgRgOCP6nEO X-Received: by 2002:a1f:3fca:0:b0:47e:672e:304c with SMTP id m193-20020a1f3fca000000b0047e672e304cmr4816722vka.4.1688762657759; Fri, 07 Jul 2023 13:44:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762657; cv=none; d=google.com; s=arc-20160816; b=HW4C4RXE4g0pqF37qM08cI9uW9gaTOJQB4EAGoeQzin5CZw/+55Rb7TzV6fcd8twT7 2MrO4XJzn/V//DL833+BZ9viFOFW8eM1x7rAkBwhPMYiy8NCZqiqFCEGiaF82dV9AuEA j5jKOfRGLCJ5x2IIaFrPYOsPHgGwtcMCra3cX9SjJyiAs409S+vWNtDinFgRcbitkaer xA9zgCB5fF5OxfIoIC9bQkV2V7l24Q6tueBGchGJ0cTlpnmbC1e8O094N/QrenqWiSLj BkbQk18KFPfIzPoF2n2bBec1diDNHuEUE9cHvAJr12JV+uA/oh6t2d341OrHycBi9FOL ZTzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RSslPOCtrCKSd7/qnt5s8BU5QI6BNVbM4GALvEx3wRA=; fh=jVqwU2n6uDjg7kXqsBiuuwMdTrtXxwX52l5dkNb4FWE=; b=Lzz8o49r7+zjv+bzzwx0zJTafOvwy0ddRoAkatB23VCKrBArWZOxDhrHS32c5QUhvW b7BdKnEn/BgxlOqbkMsNO9QE9eV6JZIaNa4OTZZxOK9uAAPCcGmQh2HVI9q/afTUha3O cJwpADzUMjH3yy0pts/08Y9+/EzIIxw2s0BusG7IIs/9hevW/aitwkVQr9kXoyoQUXJK F6LV3HKqZKkUbzZbziihdIpqFm693R7MBfN1ArJga81LQq6Q2JJHhZ/paOOS4KDHhL26 wJBmCaZ9KgF8O3BsVjtWeQmGdCllK3iz9ZjEk5zfz/y2CP5RVIVhZoPdJPDYmfPbqAPQ 7+bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Dh+xFwKl; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i17-20020a0cf391000000b0061964c0b8ddsi3105734qvk.12.2023.07.07.13.44.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:44:17 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Dh+xFwKl; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGc-000516-8I; Fri, 07 Jul 2023 16:41:26 -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 1qHsGP-0004qI-Oe for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:13 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGN-0004qX-Sh for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:13 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-3fbca8935bfso25738385e9.3 for ; Fri, 07 Jul 2023 13:41:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762470; x=1691354470; 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=RSslPOCtrCKSd7/qnt5s8BU5QI6BNVbM4GALvEx3wRA=; b=Dh+xFwKlUvBRt4/Q+YLBkxEuTJnw2WmaPoAOr9RVl3xweMDf0YZErCpnq19FJ2/Z2c lXfq69IG8FcRqQpEjuXVl8RK8zKmQNjeJUeFP3Irfg3Hf633eeWaSe20wFZHOlExvxfd DN6PG24bcdtokPSHZl0fNGomfWCQuvHo8fNoARgKRWp/G3k8xU+wkAgdABQ3aYCAko4l HIS9COBxXShLrSMlUCEMQjtoCiNHpG4qI9tPyHhCyJ0PC8U7FpcTMF1dN5kquWApoGSl 9BBT8gDRxepEFAm6KLK/WZHGZMktpmyqWtHMb2t9qQjZYjPQA++Ckgx7qjnIWt4D3MiZ 7bJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762470; x=1691354470; 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=RSslPOCtrCKSd7/qnt5s8BU5QI6BNVbM4GALvEx3wRA=; b=KjTlAtWGUJghyIfeNVVleJ95B5IO0cxtNFRwHKKQc1udtKkfHw2vim3WWoWMngREtO KU4DwPfeEBpbo2fQYxe8yT01X3Ab4iu5UzqSpTgDHa6vZhn97Tw3VxMAcHgtTTe2oxOm rzELBNhHIcPyZBf2A55SQJMgcB1Lrt7NKVdATmxfvVDO48mFX7XuNaViirbCcBkYlXOo Fe4HgtoTNd2YX2lS6aNAeLHjr+zK9C4eb6+fofVLBxRvLIGfkQVEUirubrptF+L8+ing Ui1y700Qcxw+U7AyJffmQeq86Zdg98ix9tgp11cOEzjiqkNWTFOxyOHIbrAzQ7yCiT4E IGhA== X-Gm-Message-State: ABy/qLZ4y5KFcKiOtaUvX2tsJjxsc0F0eg7LzZY6Ha4JFQ/IrY+6VuFP iFpHRZ9OlzIiPrNylSdgJ4yQkQrb1bnpdvH75/3QIg== X-Received: by 2002:a7b:c3d7:0:b0:3fb:a6ee:4cec with SMTP id t23-20020a7bc3d7000000b003fba6ee4cecmr4499609wmj.33.1688762470660; Fri, 07 Jul 2023 13:41:10 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru Subject: [PATCH v2 20/24] linux-user: Simplify target_munmap Date: Fri, 7 Jul 2023 21:40:50 +0100 Message-Id: <20230707204054.8792-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x335.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org All of the guest to host page adjustment is handled by mmap_reserve_or_unmap; there is no need to duplicate that. There are no failure modes for munmap after alignment and guest address range have been validated. Signed-off-by: Richard Henderson --- linux-user/mmap.c | 47 ++++------------------------------------------- 1 file changed, 4 insertions(+), 43 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 8c90a690dd..e6463ecd8d 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -789,9 +789,6 @@ static void mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) int target_munmap(abi_ulong start, abi_ulong len) { - abi_ulong end, real_start, real_end, addr; - int prot, ret; - trace_target_munmap(start, len); if (start & ~TARGET_PAGE_MASK) { @@ -803,47 +800,11 @@ int target_munmap(abi_ulong start, abi_ulong len) } mmap_lock(); - end = start + len; - real_start = start & qemu_host_page_mask; - real_end = HOST_PAGE_ALIGN(end); - - if (start > real_start) { - /* handle host page containing start */ - prot = 0; - for (addr = real_start; addr < start; addr += TARGET_PAGE_SIZE) { - prot |= page_get_flags(addr); - } - if (real_end == real_start + qemu_host_page_size) { - for (addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) { - prot |= page_get_flags(addr); - } - end = real_end; - } - if (prot != 0) { - real_start += qemu_host_page_size; - } - } - if (end < real_end) { - prot = 0; - for (addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) { - prot |= page_get_flags(addr); - } - if (prot != 0) { - real_end -= qemu_host_page_size; - } - } - - ret = 0; - /* unmap what we can */ - if (real_start < real_end) { - mmap_reserve_or_unmap(real_start, real_end - real_start); - } - - if (ret == 0) { - page_set_flags(start, start + len - 1, 0); - } + mmap_reserve_or_unmap(start, len); + page_set_flags(start, start + len - 1, 0); mmap_unlock(); - return ret; + + return 0; } abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, From patchwork Fri Jul 7 20:40:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700052 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4065942wrs; Fri, 7 Jul 2023 13:44:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlHe8CPIzuOqHzgewTOT7SCj6OG0b9VZxPqnTRausFEuddao2mfNhFbmPh7rdCiD8W8reSn/ X-Received: by 2002:a05:6358:2490:b0:134:c584:5585 with SMTP id m16-20020a056358249000b00134c5845585mr7935400rwc.3.1688762640673; Fri, 07 Jul 2023 13:44:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762640; cv=none; d=google.com; s=arc-20160816; b=rXaDC5SKmbyANq3jSt5U7Bv2Pyutgj7ICrH12dqaZo/hhDLjzU4uavrHXPbqin/02P cRhqagJtC/Ro6C7KOJ+j6RQjsbRSosSPwHxe12oDfmNY+xcS2NqUsu4kQXdQz4GJKMri +zatvdNe+dkVUe9qp9RD7womX6lE86ursy+zQPcX3ghzuOrGEUMyqcT41wL48kt8w3w1 MbvOdcRsVo8p8nm5HtcM5Qr6T/dw1iNcVozAVijy4W3r+J1SJLcjVCqvo+k59KT9s8gq 9GXUMpryNKY8UeVgxkzmveDbAKFhKOCi8H5Ytu72dv9eznE0bbq3kESOWTTD95o7snRV +1RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JtsN07dASo7micW3VRbXtJ/m5hRykEBCvqHdibzbQc0=; fh=jVqwU2n6uDjg7kXqsBiuuwMdTrtXxwX52l5dkNb4FWE=; b=rukJkMJGg0p0/ixIi3WEywyAqeYeLOB7IcLyiU6mDidPVTRsphpH97v0ytJw75nBmO 1+n7XQis81Fbe16TbmZ6oMBGKshnu5GO06GrAz/HB4vx+YW1QfWq94SnHTr09NkWQ7mA mHr7jEUBhVSdH6mbmaZhKyikNfYnvy/BiJhlrRoXn2V3LtGcwfbnUCgso2Zg0HlclSVn FNQq2K+Otceno8flWkvxzgL27tKW6kkZULnntdjtVGM7WBndD4tfu41GUxWdJw0fDpvB OjekpbdRjpLXeRLo+mCUd7gCnowXyTtkcIpzuidj+6fg3gRjsltl34uhWU4aiEf/D9+L 9y9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nBqXifMh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d21-20020a05622a15d500b00403757ba1a3si3101623qty.264.2023.07.07.13.44.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:44:00 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nBqXifMh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGc-00051L-PX; Fri, 07 Jul 2023 16:41:26 -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 1qHsGQ-0004qj-Ju for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:15 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGO-0004sS-S3 for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:14 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-3142860734aso3084824f8f.1 for ; Fri, 07 Jul 2023 13:41:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762471; x=1691354471; 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=JtsN07dASo7micW3VRbXtJ/m5hRykEBCvqHdibzbQc0=; b=nBqXifMhdGILcAes+j/eTy+FIfY532P8+LxZ1PoQK5tgqgoePheTFCLqCfrR0ahtyC IWt8pu7MTq4G7qAZLBVeYpO7OnGapoP+cYDdXoi4vCMYohT9PprRvvetnaG5RKBU69gJ YMltMsKZ7RWcd4QRW+geGyut58iG4oApj/V1GHA7HH1yd9vzmXbGUgpzW9QSl5D2t5bA UiK5qv3mIGCxDh1lgRujaaKm+HWFAMwCn5vPpVqkH9j8mVOLjGkuWm/Sv5ZoOnOfuggh cpJAuD9MmOWLGhw5xx2Do42b22uj83y999oSR1c4sEzchueRnC5y4kvwHrDlHK3SRBtW PerA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762471; x=1691354471; 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=JtsN07dASo7micW3VRbXtJ/m5hRykEBCvqHdibzbQc0=; b=TPF5R2d1nKeC5joC9yB4GlLSBCgPtHwgBwg96w23vWRFvaQD18ev6ZzeSwsr7cfYTh obgydSFM45dIkyc7Qdb7Ek8JlwqgT2ZkmLUnp74WiZcJYTk484k0YWGy7qkT/5V9IabU 3PLfayygcnL/qAJ6OUp2ZtxTmA/WBSUC5v+WH17gDaKe01GPiLo7+7te99hFvON/zYMP YQWPrmC13t/WT/QpBlbbnV2zyBml3j6DxsTI0yU1YnCLAlewnWd9ZiBDoMg6d0UTSJ+q aC/txU+mAPAqIM++nDhHGSWOQpUE2x+oAhnEVQxAncP3noY6UuaCGDMpirwmOcBDFPdq zf4w== X-Gm-Message-State: ABy/qLaLBUb93/dvL1d9Fyw7RjM/a22LXkC4715+1SeNsWirmUWLDKLt j/AGcD/HnTj8TQ+V5sA9p+EF/aXnPavna6nVpaQm9w== X-Received: by 2002:a5d:58c5:0:b0:314:385d:3f32 with SMTP id o5-20020a5d58c5000000b00314385d3f32mr9418621wrf.29.1688762471193; Fri, 07 Jul 2023 13:41:11 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru Subject: [PATCH v2 21/24] accel/tcg: Accept more page flags in page_check_range Date: Fri, 7 Jul 2023 21:40:51 +0100 Message-Id: <20230707204054.8792-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x435.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Only PAGE_WRITE needs special attention, all others can be handled as we do for PAGE_READ. Adjust the mask. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- accel/tcg/user-exec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index e4f9563730..1e8fcaf6b0 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -561,8 +561,8 @@ int page_check_range(target_ulong start, target_ulong len, int flags) } missing = flags & ~p->flags; - if (missing & PAGE_READ) { - ret = -1; /* page not readable */ + if (missing & ~PAGE_WRITE) { + ret = -1; /* page doesn't match */ break; } if (missing & PAGE_WRITE) { From patchwork Fri Jul 7 20:40:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700057 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4066120wrs; Fri, 7 Jul 2023 13:44:28 -0700 (PDT) X-Google-Smtp-Source: APBJJlG4wUpmjbsYZ0Jbo4bSNTdFR825EupzrMJ2S2rx7RRhSvu8W7vNn/2nenIpcFZPexGmolYO X-Received: by 2002:a05:620a:4504:b0:765:aaa8:67ab with SMTP id t4-20020a05620a450400b00765aaa867abmr8714386qkp.26.1688762668486; Fri, 07 Jul 2023 13:44:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762668; cv=none; d=google.com; s=arc-20160816; b=kdyKQqZL4Z1aM3j6XN9RoCYhj/i2S3E89BcuRwUvIkMIUzf1ROxeQaLNGqETYXS1Og xvO0ZVFrGCkTmxcvYgv+OjSgVBLE2M9ONY6MOSRLbZomwZFJPLqyhH10G+FyJiOWnrGV 8vPeb3qlXq2/ga3MtHq6V+cq/DkzEWcnVRXWK1Xw6Pac0SF9IyiVSgsNAsNpCQf8b80t nyZ8NmyX2SugNjbYiYxohwBzQ6v1N3L66YKjDIXn7Z0zZCweBmO7hsT4F/YPCkrDtolR an+0fAKYd4qkuE9YPDWApSzEtGeiYjCm+WMdJes8h0iD0qWYdg+d/O4IarZHcfRVjNKw OSZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NrUZ8QAdQn7rr78o1RLkcwLT++qZEmejSpYBhGhX2sE=; fh=jVqwU2n6uDjg7kXqsBiuuwMdTrtXxwX52l5dkNb4FWE=; b=qROvLEyspOOeYsZV9hZwSiO5Hd89XoZsA3YAR4ZpQ+9BtpzYqKeGEDzGIiSbCuW4Vn K5b7RVzSpjZhAST1pCs8dV3MtQ5U25ToSgqB0I/42+oK8d4e7ZqysiafbfGcUJdCw42+ s+2IeTtQrRnRNhLNm/UQG4ll6MPjqlTu2B5CLV3QRi1zXIIGxMT9ULVQsPU7aBXJ+y5Z xzHulL64JF8J6vRy28LOtjd24oxaoQPRZbtIHMgzfmLeWBnp99mSlLlhRdFbQW15Pqle TlG/bAcXJsG886/z6cqEmAqObOH1xHH+PGvCZ2mxAZMWCWRSxMR1Q0A0E1+Q7Xc8eYqK xeAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TpAJMgH6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l13-20020a37f50d000000b0076715a35f43si3162483qkk.495.2023.07.07.13.44.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:44:28 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TpAJMgH6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGZ-0004yo-49; Fri, 07 Jul 2023 16:41:23 -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 1qHsGS-0004r6-2Q for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:17 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGP-0004tQ-9i for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:15 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fbc656873eso29297405e9.1 for ; Fri, 07 Jul 2023 13:41:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762471; x=1691354471; 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=NrUZ8QAdQn7rr78o1RLkcwLT++qZEmejSpYBhGhX2sE=; b=TpAJMgH6hGgOJ1eS6RqcjLN3z1yu3KQF0JnnMKIFDZh5UuO4QqcMMIbL3Inj6k9d7S b/xkZ75nVgDaGwJE7thaYhKr+W+NJvBO8kTzFOfq7VG2yfpz50LEgn4SAY/qEJ8MS6TZ zz6s6nDMapXaqPwe5FW7E2OOuSNviHOi7LiCeGS+Lfs4O6r8M/H/22G7XnOcEJFCUpKZ PgedJ5L/XAp1WBjyDwNR3fBkvffrMAeaFWdWnHcBfoIOlKQ873oHD/+QvBhgvVvtJJuB 5+X9F1QXOHh4p4bN/zDLbgotdjgxZdHowuQGHc6h2Y2i1nSV7JlFMFZkQat/wpV9qmKh Zo/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762471; x=1691354471; 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=NrUZ8QAdQn7rr78o1RLkcwLT++qZEmejSpYBhGhX2sE=; b=gFiJHn8fF81k05BgIos4bodHokoMC8ZbmMiESKc59WW5evp3XS46/lynw4Iygw/woX DOu6gbUrGuT0SXJVsXufwe04wkUKhcNmE4M7NFU8kcD43IgbP9Wp1uSPEVCezsoxQgs1 PC72Qj64IpzSbzMsavWzUvuCNVhurt7gwn+91pE5f8vfszQBJ60JQw4fxXNGL6Tfe41h SEzcw3Yv9Dax6TEI3FBi/nKPqVDQtBeet5thHcY+BtlJ5U/LyU33RgoaCmAaeIxVuXeR EQT0iZwl2IiggqKo4Eut1Tjz8m0DQcDWPE1VgXbAp9aKnd4L95leDTodVYyuHOuOFANf 9kUA== X-Gm-Message-State: ABy/qLaoFiesAQf7q0jR6t+1XQW53jkHVeRb1k3KuG70Zh4IqhKiFNOz 5yXjJJRgyOLnPZdWdO2okXNEkounVn5wWpvBFBnTbA== X-Received: by 2002:a05:600c:3651:b0:3fb:f0ef:4669 with SMTP id y17-20020a05600c365100b003fbf0ef4669mr6544112wmq.17.1688762471630; Fri, 07 Jul 2023 13:41:11 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru Subject: [PATCH v2 22/24] accel/tcg: Return bool from page_check_range Date: Fri, 7 Jul 2023 21:40:52 +0100 Message-Id: <20230707204054.8792-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32b.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Replace the 0/-1 result with true/false. Invert the sense of the test of all callers. Document the function. Signed-off-by: Richard Henderson --- bsd-user/qemu.h | 2 +- include/exec/cpu-all.h | 13 ++++++++++++- linux-user/qemu.h | 2 +- accel/tcg/user-exec.c | 22 +++++++++++----------- linux-user/syscall.c | 2 +- target/hppa/op_helper.c | 2 +- target/riscv/vector_helper.c | 2 +- target/sparc/ldst_helper.c | 2 +- accel/tcg/ldst_atomicity.c.inc | 4 ++-- 9 files changed, 31 insertions(+), 20 deletions(-) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 41d84e0b81..edf9602f9b 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -267,7 +267,7 @@ abi_long do_freebsd_sysarch(void *cpu_env, abi_long arg1, abi_long arg2); static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) { - return page_check_range((target_ulong)addr, size, type) == 0; + return page_check_range((target_ulong)addr, size, type); } /* diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index eb1c54701a..94f44f1f59 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -222,7 +222,18 @@ int walk_memory_regions(void *, walk_memory_regions_fn); int page_get_flags(target_ulong address); void page_set_flags(target_ulong start, target_ulong last, int flags); void page_reset_target_data(target_ulong start, target_ulong last); -int page_check_range(target_ulong start, target_ulong len, int flags); + +/** + * page_check_range + * @start: first byte of range + * @len: length of range + * @flags: flags required for each page + * + * Return true if every page in [@start, @start+@len) has @flags set. + * Return false if any page is unmapped. Thus testing flags == 0 is + * equivalent to testing for flags == PAGE_VALID. + */ +bool page_check_range(target_ulong start, target_ulong last, int flags); /** * page_check_range_empty: diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 9b8e0860d7..802794db63 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -182,7 +182,7 @@ static inline bool access_ok_untagged(int type, abi_ulong addr, abi_ulong size) : !guest_range_valid_untagged(addr, size)) { return false; } - return page_check_range((target_ulong)addr, size, type) == 0; + return page_check_range((target_ulong)addr, size, type); } static inline bool access_ok(CPUState *cpu, int type, diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 1e8fcaf6b0..df60c7d673 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -520,19 +520,19 @@ void page_set_flags(target_ulong start, target_ulong last, int flags) } } -int page_check_range(target_ulong start, target_ulong len, int flags) +bool page_check_range(target_ulong start, target_ulong len, int flags) { target_ulong last; int locked; /* tri-state: =0: unlocked, +1: global, -1: local */ - int ret; + bool ret; if (len == 0) { - return 0; /* trivial length */ + return true; /* trivial length */ } last = start + len - 1; if (last < start) { - return -1; /* wrap around */ + return false; /* wrap around */ } locked = have_mmap_lock(); @@ -551,33 +551,33 @@ int page_check_range(target_ulong start, target_ulong len, int flags) p = pageflags_find(start, last); } if (!p) { - ret = -1; /* entire region invalid */ + ret = false; /* entire region invalid */ break; } } if (start < p->itree.start) { - ret = -1; /* initial bytes invalid */ + ret = false; /* initial bytes invalid */ break; } missing = flags & ~p->flags; if (missing & ~PAGE_WRITE) { - ret = -1; /* page doesn't match */ + ret = false; /* page doesn't match */ break; } if (missing & PAGE_WRITE) { if (!(p->flags & PAGE_WRITE_ORG)) { - ret = -1; /* page not writable */ + ret = false; /* page not writable */ break; } /* Asking about writable, but has been protected: undo. */ if (!page_unprotect(start, 0)) { - ret = -1; + ret = false; break; } /* TODO: page_unprotect should take a range, not a single page. */ if (last - start < TARGET_PAGE_SIZE) { - ret = 0; /* ok */ + ret = true; /* ok */ break; } start += TARGET_PAGE_SIZE; @@ -585,7 +585,7 @@ int page_check_range(target_ulong start, target_ulong len, int flags) } if (last <= p->itree.last) { - ret = 0; /* ok */ + ret = true; /* ok */ break; } start = p->itree.last + 1; diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b9b5e37c5e..a7b8b1edb4 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8105,7 +8105,7 @@ static int open_self_maps_1(CPUArchState *cpu_env, int fd, bool smaps) max = h2g_valid(max - 1) ? max : (uintptr_t) g2h_untagged(GUEST_ADDR_MAX) + 1; - if (page_check_range(h2g(min), max - min, flags) == -1) { + if (!page_check_range(h2g(min), max - min, flags)) { continue; } diff --git a/target/hppa/op_helper.c b/target/hppa/op_helper.c index 32c27c66b2..f25a5a72aa 100644 --- a/target/hppa/op_helper.c +++ b/target/hppa/op_helper.c @@ -168,7 +168,7 @@ target_ureg HELPER(probe)(CPUHPPAState *env, target_ulong addr, uint32_t level, uint32_t want) { #ifdef CONFIG_USER_ONLY - return (page_check_range(addr, 1, want) == 0) ? 1 : 0; + return page_check_range(addr, 1, want); #else int prot, excp; hwaddr phys; diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c index 1e06e7447c..1f9549f168 100644 --- a/target/riscv/vector_helper.c +++ b/target/riscv/vector_helper.c @@ -583,7 +583,7 @@ vext_ldff(void *vd, void *v0, target_ulong base, cpu_mmu_index(env, false)); if (host) { #ifdef CONFIG_USER_ONLY - if (page_check_range(addr, offset, PAGE_READ) < 0) { + if (page_check_range(addr, offset, PAGE_READ)) { vl = i; goto ProbeSuccess; } diff --git a/target/sparc/ldst_helper.c b/target/sparc/ldst_helper.c index 981a47d8bb..78b03308ae 100644 --- a/target/sparc/ldst_helper.c +++ b/target/sparc/ldst_helper.c @@ -1191,7 +1191,7 @@ uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr, case ASI_PNFL: /* Primary no-fault LE */ case ASI_SNF: /* Secondary no-fault */ case ASI_SNFL: /* Secondary no-fault LE */ - if (page_check_range(addr, size, PAGE_READ) == -1) { + if (!page_check_range(addr, size, PAGE_READ)) { ret = 0; break; } diff --git a/accel/tcg/ldst_atomicity.c.inc b/accel/tcg/ldst_atomicity.c.inc index de70531a7a..4de0a80492 100644 --- a/accel/tcg/ldst_atomicity.c.inc +++ b/accel/tcg/ldst_atomicity.c.inc @@ -159,7 +159,7 @@ static uint64_t load_atomic8_or_exit(CPUArchState *env, uintptr_t ra, void *pv) * another process, because the fallback start_exclusive solution * provides no protection across processes. */ - if (!page_check_range(h2g(pv), 8, PAGE_WRITE_ORG)) { + if (page_check_range(h2g(pv), 8, PAGE_WRITE_ORG)) { uint64_t *p = __builtin_assume_aligned(pv, 8); return *p; } @@ -194,7 +194,7 @@ static Int128 load_atomic16_or_exit(CPUArchState *env, uintptr_t ra, void *pv) * another process, because the fallback start_exclusive solution * provides no protection across processes. */ - if (!page_check_range(h2g(p), 16, PAGE_WRITE_ORG)) { + if (page_check_range(h2g(p), 16, PAGE_WRITE_ORG)) { return *p; } #endif From patchwork Fri Jul 7 20:40:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700054 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4066049wrs; Fri, 7 Jul 2023 13:44:20 -0700 (PDT) X-Google-Smtp-Source: APBJJlHjiCdniUIZ7xQNOUav+WRYYrPx13FhQskpTCOnIXc+ydgPbExLKM/upMlzNDg1fRMfCsx9 X-Received: by 2002:a05:6358:27aa:b0:133:e1e:f0b5 with SMTP id l42-20020a05635827aa00b001330e1ef0b5mr6286815rwb.12.1688762659865; Fri, 07 Jul 2023 13:44:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762659; cv=none; d=google.com; s=arc-20160816; b=jZUMyCuIreEwh+AiSg9Suow7AcD4kSffqwZwQ14vRwyqG2dtQAXZNoKYoeaAlBKEmY io2YqoHKiDsi4xdbFCml/2jDZIDKlQdHOao9YIheeEX3z5uqiWt3FdR6ck75jav0WeWg Dee2gcqdMl8ZsdDeodhP8KsEd+uktqNpxX2G878tTDL6bWAzCX0F9cbkCL1imSbaPsBO UbLHEr6qRRXNosgKu7IUkufEx6inp98YDjl+uWcKRbe+Uu7rkjDmcQOfp5TxiT/X+Z1M X5IfoK2Btmd2Wss3bdeaQlr6C7kfd+BJXDpnlk3nWPcloVNOlkuiA8yRDJmAwwBk9XU+ EDxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=s3pB3AzQ33HXE3XP6riFkr6cxMvSqstuDeeeDRipPQQ=; fh=jVqwU2n6uDjg7kXqsBiuuwMdTrtXxwX52l5dkNb4FWE=; b=BjlLWh53rgyN+7yUKgDQBk0vaXajSlfPdytBtOy30k7IzLv3zdVvC3u696sTlROVPD z4s01B0Jx1R5AEgXW1uehUIP6lUxLlb5TkItRgMCMAn++9NH2KN4AcnLAsJwmUUp0s6+ XJGH5YtEIDA31wkVxql3EnzcwhmsyKHwjbOvVRig1UjqI+Xk7fOuKDZyX7wHqNRrkgwg y6cS5tOaC7fWhE0iV7t5P2WQcG8y4GzK0sUbzz5euLwnK1T6WBWIXqspR0sa6Gqj4nmO uAKosOS/5vdVineTgFqxQkSl6xRoyMD0XyliFHTO0sRncBbH+JaAJ/xTqO4JAF8D1DgY Ieaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SWom5Nru; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j5-20020a0c9cc5000000b006369bcd178asi3130742qvf.485.2023.07.07.13.44.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:44:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SWom5Nru; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGb-0004zW-PD; Fri, 07 Jul 2023 16:41:25 -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 1qHsGS-0004r8-2Q for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:17 -0400 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGP-0004uK-Si for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:15 -0400 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-4f9fdb0ef35so3843884e87.0 for ; Fri, 07 Jul 2023 13:41:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762472; x=1691354472; 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=s3pB3AzQ33HXE3XP6riFkr6cxMvSqstuDeeeDRipPQQ=; b=SWom5NruSHwBYfIZXY4JlRIa5yxfyLXmkW7YSt54qa/GuoEyDxm631i4lGmsY/UwcJ a02Zm/B0IUzTk1MnHtPIISPzrh1m6qLjPQf2sX/7DHtFSBKtGLChRLn65lB26oNuyuuy 2t95Ki7+kyG9sXoYcMKYZwdTwkz98olBNJuDPHGHdBchvHsj5RtFEBZxMx/0X6NbZnsn p/2zEg8fHzR8uiKu8S/4Taw+tz4A80CfmXigOrKmD0CJ1YN1ZmC9Kma+oacAFS3Rlmfn roodu7HFwAqcHnLZ64j6rG5BYetynn67OottrcnUKLx7ULbB5uYo8teuXuFr85Zb4HdM +1AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762472; x=1691354472; 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=s3pB3AzQ33HXE3XP6riFkr6cxMvSqstuDeeeDRipPQQ=; b=glBIEQxL60g5vQkqZ8WJcREfDnfhF+NsH8B2kTwOTQQ4+BWy+33WjUkL/MlFOT4PTe /7WZabCsljUos++iUqtrsukTxQRRd7hJMNxXaN8kLffEIlskjJFzX8/aEzvsaDtyzXxe maaCqcw5lMR3QwbOk+x7Amts+c1Xx66pA+8Z7dIum+tYrQe2LZ6e11VklC1a8QAuvECe ElaGqGc/Yqh0QKkwiqqobAKtdWS4bpZPn4Oy841jaxWcMngA6rb6j9L7MiH3pG7uGbYR BBajW6Nzi6GzcL5/kwszoBD50dF2r1jS8Bi4rbA9gQyiA+az5hqSE4xGTohhzSY/1bHL c4aA== X-Gm-Message-State: ABy/qLZJqXUTNA1V8EPFa6qDvIt7zWWCqN+1uwWmyNmAHpcDVfC5g8XY tvlb0Rsn2hViCaKmntGhVeUJcuNS3WyQH11SDMx7+w== X-Received: by 2002:a05:6512:3292:b0:4f7:55e4:4665 with SMTP id p18-20020a056512329200b004f755e44665mr4198859lfe.56.1688762472227; Fri, 07 Jul 2023 13:41:12 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru Subject: [PATCH v2 23/24] linux-user: Remove can_passthrough_madvise Date: Fri, 7 Jul 2023 21:40:53 +0100 Message-Id: <20230707204054.8792-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::129; envelope-from=richard.henderson@linaro.org; helo=mail-lf1-x129.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Use page_check_range instead, which uses the interval tree instead of checking each page individually. Signed-off-by: Richard Henderson --- linux-user/mmap.c | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index e6463ecd8d..a2bef1ebe6 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -898,23 +898,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, return new_addr; } -static bool can_passthrough_madvise(abi_ulong start, abi_ulong end) -{ - ulong addr; - - if ((start | end) & ~qemu_host_page_mask) { - return false; - } - - for (addr = start; addr < end; addr += TARGET_PAGE_SIZE) { - if (!(page_get_flags(addr) & PAGE_PASSTHROUGH)) { - return false; - } - } - - return true; -} - abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice) { abi_ulong len, end; @@ -964,9 +947,8 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice) * * A straight passthrough for those may not be safe because qemu sometimes * turns private file-backed mappings into anonymous mappings. - * can_passthrough_madvise() helps to check if a passthrough is possible by - * comparing mappings that are known to have the same semantics in the host - * and the guest. In this case passthrough is safe. + * If all guest pages have PAGE_PASSTHROUGH set, mappings have the + * same semantics for the host as for the guest. * * We pass through MADV_WIPEONFORK and MADV_KEEPONFORK if possible and * return failure if not. @@ -984,7 +966,7 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice) ret = -EINVAL; /* fall through */ case MADV_DONTNEED: - if (can_passthrough_madvise(start, end)) { + if (page_check_range(start, len, PAGE_PASSTHROUGH)) { ret = get_errno(madvise(g2h_untagged(start), len, advice)); if ((advice == MADV_DONTNEED) && (ret == 0)) { page_reset_target_data(start, start + len - 1); From patchwork Fri Jul 7 20:40:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700055 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4066053wrs; Fri, 7 Jul 2023 13:44:20 -0700 (PDT) X-Google-Smtp-Source: APBJJlGeJ4O+DSbNRk+EeZc1CeFTCRSk92UibVfBJo6GznyXnzwPgLCsQNbtguEzBcfDlllyagLY X-Received: by 2002:a05:622a:593:b0:3f8:3090:15c9 with SMTP id c19-20020a05622a059300b003f8309015c9mr6619310qtb.30.1688762660699; Fri, 07 Jul 2023 13:44:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762660; cv=none; d=google.com; s=arc-20160816; b=FzZlN/cfnNGgpinW6dNUPpkFvfEhoKEiDyIocOPHcCSWeiSn22R9f1/vcWneICsgha 01umWiGJ2o4bQF8OqpCpcKFBab/03q/+dvpNpt86BdHxo/3JQpwBAXxxKV6JrWD94Flt /8TJH2IMuwDCU1RYaToZzWMuV9Ccz5lqgD+j7itc4wrXLUh+EAKl4PIaAds++ut8cbqF TsrUnokLuUtQEhnJOE5S2vSafkKAuNQZcZWz91Df40u1B1VZWj1E2sGw4uTjw1cIQ+nO ayXP3RCTc61DszKAcf64Jlilx4k7+pUFmDhCgVD92ggLKMC3AXicTX8ozv82UHZ1ER8t NFEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Z4tz1Qg7924YrzRDQ0nhW1mfYwrF0UAZkf+8N9yiaRs=; fh=jVqwU2n6uDjg7kXqsBiuuwMdTrtXxwX52l5dkNb4FWE=; b=IorFzG6lV5GAHTB5/7n2OlHUN+Ab9L1V9Nmk8OjmVZMNMpvK9TApGi2ncaVIKlV0XR h1R11c5BYCw00lM4UpByy9K2lreQj1T2IlelnbtCkkzgHGaK3eYjBDxbznn27wv16kh3 DSxto2y90SJog4+TGPcwUHpPWzJkVaK+pnLxjWKQDlOR8ObFM5T2Iht2r9dugP1/1bPv /l/hFqTGhOUpLiRssMO1oDtHbKGmK9hE8lJ3erpqi3E/pFQBvV58ir7SSSgSuY74bt1x 5OgJtmjZw7MwfAs3PPLaa0kygZFJr0l0NtKY1KYa13TSI4oY5JU3VXrcZW45ciEveAG+ l6XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=c7v1EOzd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6-20020ac85906000000b00403a152aaa0si464991qty.794.2023.07.07.13.44.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:44:20 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=c7v1EOzd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGb-0004zr-4T; Fri, 07 Jul 2023 16:41:25 -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 1qHsGT-0004su-J9 for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:17 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGR-0004v4-RS for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:17 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3fbf1b82d9cso25266485e9.2 for ; Fri, 07 Jul 2023 13:41:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762473; x=1691354473; 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=Z4tz1Qg7924YrzRDQ0nhW1mfYwrF0UAZkf+8N9yiaRs=; b=c7v1EOzd7+Jktv2/UHfyzhvSITchi4KvSbUT/d/T4CaKwpKlzEtLFTRsSyjqsEi/p/ kBqjCas0O9w07N8813Z306F+FDLHjTnLw0bmGiJZz8cfCepRSUQXbCjpxAQCbYcM0NL3 noBSBIhz3JjBSTkLHZOjHW2BGkKJGpicN1VLBeA/+sZ4zYRiZJULGhUcEBGuB6uVoZfX kEw2cR/dvaK/fIoS4z6ZdP68dCTMnOHHI5DHHKfsgZUz+I2b6kIKYeta9xssHm+mMHi7 H6Rk2kWdN6kLh8XVNR5QjuzOQigeMH2yosUR42sngI7JGEBxAmpIHmZ+RvAFVxTe5ULv 1Ijg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762473; x=1691354473; 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=Z4tz1Qg7924YrzRDQ0nhW1mfYwrF0UAZkf+8N9yiaRs=; b=ZxtObTJysdxQtT9Mq6Pnw1VIxNRLFfKBK6GNLDsVeR9atiaM1Q++AIwZgi4Z8OtJda TGk4xmz+Y/TtkeB291d0ZA0Pk6UWys4Akz8hfvI8d44UNZ9IEBOexeTa5+3/+LJ6WaOL WiZrd5Q4W+mZ6x6bpwgY8VFacTXywSzhRVM3VrkcInZJ2FYIHUoK2ykc1J0uZ0B9+PCV 4Y4vOFaz8tAQ5cv6lhSE1H/9RJSnU4x6gf+C5mTx2pkNmjLHKHFWJnJPBIeHlnij072H ewwId5y5NeWxSOwaVqRBwbPaGLsRur2tiARIkPfJOu/1ZTQtp36gKyTgsiCZ+0Vw+jVb f7Qg== X-Gm-Message-State: ABy/qLbzc7ib4jqoTVxBRgOdrtFl65nCr5oAy5YqyK6XCkrHsgGivsql m9nr4DxEEQM/QCMiJCXdB6wi8iC+tt3rsc33zs69sg== X-Received: by 2002:a7b:c4c6:0:b0:3f8:b6c:84aa with SMTP id g6-20020a7bc4c6000000b003f80b6c84aamr4477900wmk.24.1688762472947; Fri, 07 Jul 2023 13:41:12 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru Subject: [PATCH v2 24/24] linux-user: Simplify target_madvise Date: Fri, 7 Jul 2023 21:40:54 +0100 Message-Id: <20230707204054.8792-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x334.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The trivial length 0 check can be moved up, simplifying some of the other cases. The end < start test is handled by guest_range_valid_untagged. Signed-off-by: Richard Henderson --- linux-user/mmap.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index a2bef1ebe6..48b83ca8bf 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -900,28 +900,17 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice) { - abi_ulong len, end; + abi_ulong len; int ret = 0; if (start & ~TARGET_PAGE_MASK) { return -TARGET_EINVAL; } - len = TARGET_PAGE_ALIGN(len_in); - - if (len_in && !len) { - return -TARGET_EINVAL; - } - - end = start + len; - if (end < start) { - return -TARGET_EINVAL; - } - - if (end == start) { + if (len_in == 0) { return 0; } - - if (!guest_range_valid_untagged(start, len)) { + len = TARGET_PAGE_ALIGN(len_in); + if (len == 0 || !guest_range_valid_untagged(start, len)) { return -TARGET_EINVAL; }