From patchwork Fri Jun 30 13:21: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: 697927 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp449592wrs; Fri, 30 Jun 2023 06:22:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlEnqFtg5uYleZHGnU2lENHUwPrPU7Zc8k9BU8Q1ORQA880YbDOKi6PzB9Yu2WSwPhIsJF/X X-Received: by 2002:a1f:de82:0:b0:471:5110:49e8 with SMTP id v124-20020a1fde82000000b00471511049e8mr1726324vkg.4.1688131352844; Fri, 30 Jun 2023 06:22:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131352; cv=none; d=google.com; s=arc-20160816; b=LBDfMuXUUmOQt+mk1YjFFnv60C68JcnieZcXWFE2uHxc8Ey7BvJNT+XmyBmzu0Ib8G jTdYEbe1t/+dwdNQWV5P7BMux1WXMnAU/5fsOUNqf5FvQRZvHm92JiJrZCdxCJQMqxzQ a4BqHJNNkzABeBTZNhGxKRIHA6VcjHUseUDWMGw40Cbv9f43h5jWpHDutmRdaW3rmW85 OcpmkMfHL53RuAWXZO06iI3DECJR+ZVnLL/QMJyViffrsz4X6DigIBRpPEZxn9k7jqOY FyhKi/xLboiZ/ZYXh3RBGC5qJ4Z7FURcalPzlvZeXPiuul9u813uT7CyjOjGEkvfWY6H Bnlw== 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=WCk4vvC6feJ5EFGebo8RId3A7LSTmPdZSonDHzt4Yf8=; fh=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=VUFry7QGXp7KcHCXg4xBoYAZ6tUiVDLU/gXkTxlYpqRq1uH4uwUYFNzQR8t86if8hT JYxW+PfWksErUWZbz0ogY0QdxBO9w5yokXq7tiVk3ilIF0qJRYeqTEUzAE4eXTD6MNlz yV842g67C5LC8Wtcm2pXXkPC6n0KFru7fxVSa3O8UDyP4tE8zg8QI7RU24xaHoCtGlDO oeIVOzTpPpbJev/OeEVVLPuMgcYpY/Gv3460IQH1LJrSSAVjJBUudZppsXSyD56ttGGS lRcWPfWWsb/5UIrZUIAsOAqczdcmgKi1Flzu/IREaNJ9fNM2h7xdanECIK3zgp27L7Ww RrNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CVWFnHbs; 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 q1-20020a056214194100b006215ee4da59si7681597qvk.117.2023.06.30.06.22.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:22:32 -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=CVWFnHbs; 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 1qFE4f-0007aw-8t; Fri, 30 Jun 2023 09:22: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 1qFE4c-0007aK-Ei for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:06 -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 1qFE4a-0003JP-De for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:05 -0400 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-311099fac92so2216391f8f.0 for ; Fri, 30 Jun 2023 06:22:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131322; x=1690723322; 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=WCk4vvC6feJ5EFGebo8RId3A7LSTmPdZSonDHzt4Yf8=; b=CVWFnHbsVL7MM6NcZy0kv7Dp0gaqrqAy0Zwn2rtPPhI8Obq/LTFhYUazYMtxnrdO4a rep9vjz61rTt//5G0jwV/UMSICjzpPBLb8ac7i942N3xB5oMujq59w3MVJXC7O59Lrah MoJLm61z2/xnDlA1ggXmQFRI1eR6JxSjrdvl2KhCXLmC3ABX/+iqTzsK+sfdCk80RwZm 3EetIYjlpS3B1vNjVF9LYD49vDW1i1Eha4izsgmeC4xGd29lgQTlEcvWGU047KD0giQ4 FW7cBE/cRSTo40Oc+17KY8MdHY4PzpcUfxNIhrN3u9gGC8X7w5hpAUgHly+JyZKrMih5 MW/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131322; x=1690723322; 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=WCk4vvC6feJ5EFGebo8RId3A7LSTmPdZSonDHzt4Yf8=; b=e7I4PYp1CfJT6GngHkXljaeke4OWoLu518RkxsaNK7q0UJ4x/f01RCDyw3TRgPLHxQ pj/cpSBsuL3WYT2zP4IlfKsTPAun2qv8IYj0/UQMETDFrSE5vUINaUKpEfsNKyk4h6f/ GsRBjaQjOkSnaJrIX2vjrdOnNKeIkjf00XUMjiK1sWJ6zkfxVmZjs9OQHjStGvVfMBBw pmb/d+vez735iyoEjVAOc5/qaR/aVqODCUh0Jwwf/2S9P6p3SpIU0NOOxJn9eVtRopbO 5QJlZoWxVVhI+s7CAHw0wwEY9k3JFc4xF+msihz2kPoRBVKCJIbDCgZr8bgHVX/xlv23 D1eA== X-Gm-Message-State: ABy/qLbzH4ROVmQOMow88wycZeW+sFsmL0UQls4AvI1M0/3rvThLssFy AskKvso3uXqX/d/57TX87XNF4RWFk3lrFZvZmphiAg== X-Received: by 2002:a5d:660b:0:b0:314:37a:4d2 with SMTP id n11-20020a5d660b000000b00314037a04d2mr2219281wru.60.1688131322094; Fri, 30 Jun 2023 06:22:02 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 01/24] linux-user: Use assert in mmap_fork_start Date: Fri, 30 Jun 2023 15:21:36 +0200 Message-Id: <20230630132159.376995-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-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. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé --- 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 0aa8ae7356..83cbcce769 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 Jun 30 13:21: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: 697930 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp449597wrs; Fri, 30 Jun 2023 06:22:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4SopJLWxDzZb7YEJu+NYYojcDQp9x2XK6Vks/8GWoD01Yp3/ry3tkZJb4d75lh/zJZqGwt X-Received: by 2002:a05:620a:b57:b0:765:ada8:e939 with SMTP id x23-20020a05620a0b5700b00765ada8e939mr2597796qkg.28.1688131353128; Fri, 30 Jun 2023 06:22:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131353; cv=none; d=google.com; s=arc-20160816; b=bGJbHdpmFjLfbkvksrQFg66Df3sUDjqV/vSe/nQNGX1PldDmrvGPHjUuQwun29OQ2M jKxMVfPEPn8Fwa7WG6Z9GB2ZdVlvTDD1awX3DN3HRr0TtTW9zqs96m8g8mMTGQ+XRpEe o6DhDFFNVMoxzyzr3JZL/k84BTITw4dIQOWGN939lTPWuSjKOa1WiWcO7xvVK3DENhUO SPJ3AhqZKrUFIY2P0HKC24PFmvgJfyKNmA5HxKHAsBl63PFkRPu2HpC67SU4CjlrTVlQ zaSbm89zd2+j1Viyi30piM5nN4146tLl+EIZCH5NqlxyE+ooVYfeOx9KPSRvJDDPXn+3 uwxw== 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=1w7w5hHtHWWGiWz1HO0WgOZtt1S0lpKsiOmvKOaRxFE=; fh=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=yO2BSkPvbgDuEs8PNJdt1aQjarX0kffvqxtIzGiNTTErwiFtsEwMODdyIQ6+xml/N7 /KL/x7CQagWE6+faZ1bM39ZyIvU9ki4FvbrH+2WJaz3xrK6Lka+ZCFizunJ+Lb3ZVq81 0A3a/LEeJod6+oJgtUB8u1lAGKiSbOx/bF80mddYJCZODyU7BVHAHhF0cSpRBqQJlHcK 68IYVBjkTjcr6QyPz5viGmd84ZT35SfzZ+hG0gOooVQXzWt4TgKBvZQ8P30QGEeTeX0s XxeX8PPneXGDyU+f5yt2yy9gBxkRjZX3KgAkMuJhrKUaviIl9sVLki2+AaapZHzoZpqN r1Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W3YtS90S; 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 uw20-20020a05620a4d9400b007596780d546si2812289qkn.372.2023.06.30.06.22.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:22:33 -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=W3YtS90S; 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 1qFE4h-0007c2-Fm; Fri, 30 Jun 2023 09:22: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 1qFE4f-0007az-4F for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:09 -0400 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFE4b-0003MO-Ke for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:08 -0400 Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2b69ed7d050so30077251fa.2 for ; Fri, 30 Jun 2023 06:22:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131323; x=1690723323; 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=1w7w5hHtHWWGiWz1HO0WgOZtt1S0lpKsiOmvKOaRxFE=; b=W3YtS90S/GNdWo92ZNaEh29bO6EP6AyUbwnhkSrE4oy22xgqMjZXyJnil1hShT+IZm qfbeESRRf/PSM+QIJoYIotV/P53to7vGObITY3WC1NIoEuwTtWQ+2/J4XqGzfZgdZr6X AiYbCQ740EWY0pm6IAJW/Z6i1NFIORvzDbHkHM2tIcZM7wpK9lsQvnoTwYBYkwCSUCYO jEJsNsseKDtM4D3jGH1v7c9R5ZmBJB8FR9M+1EToLVa4mmI7/FwZFZRObYxoKbhslf28 FRVIfAP5752cCk9v60fyYDLltsozrsjkdjwyVpfRMeGpF25TuJ6liq82WJNfreddEcFa OxpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131323; x=1690723323; 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=1w7w5hHtHWWGiWz1HO0WgOZtt1S0lpKsiOmvKOaRxFE=; b=aUMwhLLu9Jtff1s0K8OQ0wb5A/jUAKUGzT7ui6L8h8a8AoVZ4psQ1kJtuE66Qe4xA/ CUFCYLsVaNjnEL3NCPzkpFbxo3QRQFtMh367tgK6vBh6hbjQhZfFcyBIVfGLcT+7nP6v EYEwGeXChTIAYA8hQtgo8CpyRHXgs7Mn58XNZIXqAJWq4rVYHM2c/69ZYYQfyfJSVM7B m2cjEcOq1AcvykI3kUQu9pS6CD3oCvo/1kZ20ywkOG3t+6P6ym+YKNLz+NSwKjaEyJN8 CjB2gZ+WGHD8eaQtoDQz6NJd/m+3m0EnChmeO3kXMukFqn2yqgFttdIO6nVhSq1Aw1pD 9/Nw== X-Gm-Message-State: ABy/qLYFuRL8KEWWyqSknLmHZUkf+QnhGTQKD8zxYrNSxoNrxuCrg6oZ T9RlUe1sOzoEMW+BkNfRR54pAZS+88YC6hiyA2WpqA== X-Received: by 2002:a05:6512:20d3:b0:4f8:578f:ace1 with SMTP id u19-20020a05651220d300b004f8578face1mr1878820lfr.21.1688131322745; Fri, 30 Jun 2023 06:22:02 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 02/24] linux-user: Fix formatting of mmap.c Date: Fri, 30 Jun 2023 15:21:37 +0200 Message-Id: <20230630132159.376995-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::234; envelope-from=richard.henderson@linaro.org; helo=mail-lj1-x234.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. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé --- 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 83cbcce769..cb5369d2d1 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) { @@ -355,15 +365,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)) { @@ -380,14 +392,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: @@ -400,8 +416,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); } @@ -416,8 +434,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); @@ -478,8 +498,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); @@ -490,32 +512,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)) { @@ -525,9 +551,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) { @@ -565,45 +593,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 */ @@ -612,8 +647,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; } @@ -621,14 +657,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; } @@ -690,16 +728,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, @@ -715,8 +755,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; @@ -730,25 +771,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; @@ -791,8 +834,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 Jun 30 13:21:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 697932 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp449932wrs; Fri, 30 Jun 2023 06:23:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlE3IeSizQ6ZAVxSQo21GYmK3kcNhZLKqhcnth6fz5AcWftIA2Ej0QxjAwzv+2H3HK8yNq33 X-Received: by 2002:a0d:df02:0:b0:56d:40da:1fc2 with SMTP id i2-20020a0ddf02000000b0056d40da1fc2mr2214525ywe.50.1688131391177; Fri, 30 Jun 2023 06:23:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131391; cv=none; d=google.com; s=arc-20160816; b=ZaYcvPqDuG3oAWkDFNzjvvmjT1eq8Jl4vR36TAG6zb/Ll8NGJCvaYQ4S+AYFV+XbHo adsgY96iBWLOhxZbnRArwiDTzxXLzmFe4pNeu2jP2t7aRJ5LG1Crqs+/5pK7CuoMzUUG eqHkf8oufiMjMIKJ//e9GhbJ/I2hW1SkQxsCCSCnJvrUa8L5ZKaEQugqaQ30fvbRHQXk 8DhJxjtSOdsT7owtSURcYPQdbcFIUMlNOUcXGTQZaymbAuy7VIpY5jW1sj5zUQvtkW1Q VfCGjWfDWaKE5dYDAH3iA6W9yqzi7HI/dzUwtMKnEWHoh6r4xH92w0Ss3xaetH6RvsY6 MltQ== 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=m/lN5cy8mvBZHCXHBxQGLZc7gXDGj90XuXQ2MKd1eIg=; fh=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=lkYY9hdTZweJB4dPEBVHDRNU3xRSWLXxGy7Fy8UbBpnzN5osAFn5OWfUUG7eV3gtqt Fbt5K4xg5eB53k/pTMQkev6J6VD7dsw70tl9W7JKmnj6n6/emVTdB6COS0t8lB+zygkn D4uPqQqtxJ55/OLka2bfzRTojLa3q5/DuFJ2+5P0Ckmf1O1ECrnqL7GqlL3K9pWuRaqB 61HcktxcwDk7/JMflbSuYO/EmoDlYzKcEFGj5BeA3XParEyknDp/vApesufbjDGnvgiN 3qfpWaFPaZ68L/P2v3ikyExZKPifJJ20VBMmdqcXrg4GiTaVbhzkjKxWRq3tkxhOAbaS H9WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NJcD9Z3V; 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 m1-20020a05622a118100b00400e685d170si6575776qtk.774.2023.06.30.06.23.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:23:11 -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=NJcD9Z3V; 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 1qFE4g-0007ba-Mq; Fri, 30 Jun 2023 09:22: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 1qFE4d-0007ah-Nn for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:08 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFE4a-0003MQ-UM for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:07 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-313e1c27476so1646851f8f.1 for ; Fri, 30 Jun 2023 06:22:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131323; x=1690723323; 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=m/lN5cy8mvBZHCXHBxQGLZc7gXDGj90XuXQ2MKd1eIg=; b=NJcD9Z3Vx0DORqxD5zGnNTJuAnjz7S5I2l3ygdXCuFi0bXb6K5jePa4Xc+d77yqce9 ZIN2cJAJ+5C+Ejeyuh/zz5FH1ugVVQuAJ5JThk6cS/C4rIwcSAGJoSvRkVCce0PzzmYQ 5ZHvaS51ZIIEcFAzdqh8UfkI/I0xvTsQkG1pYyeuQwZBezVrLfosLxZb+wTz9rvcdAZh BwJNSyKFb2sIXfQAEBcE0m/LXp1/GLdN0TSLXPGraRMB311OlV4DfKZEe+OzAc9xlN8S OcSWt1zbnINy5NSi+E1/EVecucQ/QDgipETsafpmUMeVsrYEfOV2+kR+dgmkLQt1CGef ttig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131323; x=1690723323; 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=m/lN5cy8mvBZHCXHBxQGLZc7gXDGj90XuXQ2MKd1eIg=; b=jLu8SYQuy7WyjRsBVffWeV7g93qX7e+tcIKlr6VyrtyBKYpOTSJg935aEwwaCCc5yZ HGJzNStF15qgri70V8v53n256NSQ/2waKAwUHa2A7ht2Yzghu+7Do+13uHBH+RRqIFwg ZPyB+Zp8FB63I1PAu5Vkc9otO+192bSF0PfCHtRe8+W4qZbgPVCernSxLrWnKZrwSDTJ 8k04Bcgm6F76+ze7zGDLZFudRAFR5su12uc67Jd2amoJWy0avqdZHiKVWwIeouOHgx9E 4z9wCAQVhBdEHy5bpNIozIbrMcgpCFM3rXzEujIxEDqgxNPfDo6Mtmbc+xQTLJL20oVr c50g== X-Gm-Message-State: AC+VfDx6p09B5HQvohf8Da+L2+D0+LzYXuMSEKBAI1Wszo+U4aPVCYh4 R6WLsmORfcCL4ew2/94VMjY3D7EIP0t5jHiWXw1xvw== X-Received: by 2002:a5d:548e:0:b0:311:360e:ea3a with SMTP id h14-20020a5d548e000000b00311360eea3amr6855682wrv.34.1688131323486; Fri, 30 Jun 2023 06:22:03 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 03/24] linux-user/strace: Expand struct flags to hold a mask Date: Fri, 30 Jun 2023 15:21:38 +0200 Message-Id: <20230630132159.376995-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42d.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. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- 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 Jun 30 13:21:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 697929 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp449595wrs; Fri, 30 Jun 2023 06:22:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlHe8ipWfQZrmu6/MoFnHqW7SAIlH1VinbiNeNnG5KZMXD2Z2R+kQjOzoCZLgShM5gpiAkIT X-Received: by 2002:a05:620a:800b:b0:767:36b:7707 with SMTP id ee11-20020a05620a800b00b00767036b7707mr2738788qkb.67.1688131352907; Fri, 30 Jun 2023 06:22:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131352; cv=none; d=google.com; s=arc-20160816; b=fxgA18locYiYshC+2gSfBVNwpaPfAfXp4cWLcZF+Fjju384yEL9TdsQAplBWm48lM9 faFZxViGmkbMHoSeoYeM7n6TJSOTdrUlHp7tlT3Jvsf9/NWYYDLTNj/jhP1qOKQ3zFry Owd370vTTPeMgVcmIBfKIM5Zxhy/YjVgk/CbQ3N7sclDid/JOuFsCI1MupzdUxYUbmfr 89kzzZ5+CwooIDN3CzTNUx1qlyK9vEsZG6eZOcoETwldJP/F629zHRJVCRBXHC3u+Rqj 9zNlIczqxIOqqcExJz15V8Y6BZUyqSMlHfvkFSRCNolsMZsMm+UDLw3uN/hEWXIkkhfp i4og== 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=jnC1m2Ccr4orbb1SmAUD1+fjjb4uAtVXL1WfDqQvv0g=; fh=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=dHW4nh7z4UkDFuZWyTP/rlgYd0pkbkWLXe36dMNxLg2LkmqsUC2EPwN6zkqYr8Z+/o P0RwxS3HbedmyEhMNBy/ScAa96g+dtzAq6LOMoAM4OF37A3ePSa7WYyxnQzq9kf0sy4d uGo4uHXPrwBNhnW6RVHGx9E7fFQ+ZQUYvGCS0/wWWJFFTBp1F2jlzV1lU6/ha+Uvclhr iUmh8rc0jevdpIUhyCEUBMppVg8s6zRIoLlaIbYrHBdwg8hGeZODGhINhD09s1jJsX8t ulBbA8s6igH+Oi0jFgeN/AaIEizwgEki4Y21Cl26fMqFn+LooDsgL/XHd8X8cstAHYdb bakg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FDDxmgLR; 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 t6-20020a05620a0b0600b00763b64c273esi6441742qkg.220.2023.06.30.06.22.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:22:32 -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=FDDxmgLR; 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 1qFE4i-0007cv-7D; Fri, 30 Jun 2023 09:22: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 1qFE4f-0007ay-3A for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:09 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFE4c-0003Md-6q for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:08 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3fbc12181b6so16369065e9.2 for ; Fri, 30 Jun 2023 06:22:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131324; x=1690723324; 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=jnC1m2Ccr4orbb1SmAUD1+fjjb4uAtVXL1WfDqQvv0g=; b=FDDxmgLROUkga4fGVhRr6AaKxQHZGsT7wX/vG58ujanEk0MpsTn+t5b53kiJnUdogY YIX2+r765G4DMAMQSnIs54BdRs6rmJwnf72dBA1RqzDtDXUharcaGgq1diaq0/AVF8Qu f7yT8xZ4NrBC5ZcRw/MACMOeO0WM0wlSKsx80D5xc2ol5Un/QhkUkrHZXwcMwsEvfscw 98GFUECdHf5YZDsY7aJFgkWJw8ySszMuhsAfF5s6aWjMoH0Yuw/JA5PaHM6jT+GnezFy ZpVB5C6lY8SJB1U8Mn7/XwcAZjJ0NkWaWK9WgNShcL8CmWcawPLi6ClYiQRjLJ0SEpbu cOeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131324; x=1690723324; 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=jnC1m2Ccr4orbb1SmAUD1+fjjb4uAtVXL1WfDqQvv0g=; b=hNQhtIlO5c3kRIAhcJsM8kUGpcPQLabDApPlJgY3NZHW+FHeR3PZtDUVlJ51sOaao3 SkCJ2BNpVoTlylcB4wOgNkOBOxa5a0qrjwMNh2a6W4jhdYhaYqu52FdElgxQU4gMjcQs HV2MLqNF3UJ0n6M/BYliJ+b7ZujhqaWDjiCmQaRIAfn5HZNuEuabdKTXSvWgCemI7Km9 0UAi/+CE8fcCH0TPz+4m+D2xmj6ayHRaJ3ztnuJc+wtnHhkBsDlR/jqjzhpZoxScQkVR 5g6wIKNcMl1prTMdQmj/n8fFxJ/r/iLsx7gwXb8E8C59JQmTqjnk9Ij1ncm1Sr+PHLuD xhtQ== X-Gm-Message-State: ABy/qLb9crwdf0QJ9cr+6lG16RiovzAxpjOn/Hv7rn7AidAFLvqwHrYN uMs4DgDFIWz9Glw8A3f5Kn3VDeOB6C/HA5D+htnHpw== X-Received: by 2002:a5d:630a:0:b0:314:1021:cd43 with SMTP id i10-20020a5d630a000000b003141021cd43mr2158455wru.37.1688131324246; Fri, 30 Jun 2023 06:22:04 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 04/24] linux-user: Split TARGET_MAP_* out of syscall_defs.h Date: Fri, 30 Jun 2023 15:21:39 +0200 Message-Id: <20230630132159.376995-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32f.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 Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- 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 Jun 30 13:21: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: 697936 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp450090wrs; Fri, 30 Jun 2023 06:23:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlFNSxj/HQjYYp+wjk64GjGEgW+NIFiYm089g2WtXUFVvG0WsehHNWLaJdlZSY8ODJn0qUqx X-Received: by 2002:a05:620a:25d1:b0:765:5ba6:a5ce with SMTP id y17-20020a05620a25d100b007655ba6a5cemr2395458qko.45.1688131406029; Fri, 30 Jun 2023 06:23:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131406; cv=none; d=google.com; s=arc-20160816; b=Pdrl6qJTiJXmVd+iEJ8grkdvOJZUCCsETzuZRJ8G/iGrKYpKwCxGd0+qycMGFifb+7 aW2KaTUlK25jwcPArrobgAvx0Ohoq6omEbR8tPZTPt6TKkENChl3QV/Rr0uT3G3Wvnvh cWZfvvP5lsMDFYhqQLIkXu+k0SYqu/8kXWInnJjg0Je3qQPbzo9XiBWtrkUmg1aY5TQw JYxMPQMJXih6x5hP37WLXvbHfPj6y6Y8Xz+MiBTYALV5sysmw6rBsQif5mXNcnkUcet5 UpARxUqnoNpj91T323mbaeh4z6PqW43+8ge1ALo20780uVlRPGjyiFX0EzXZNL/jJurB ZnvA== 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=eRhCAakrEPIhhwkjbQqX6qZEbetcXESvazfsDHoPFvs=; fh=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=JrRtgQ6ucZfKjRLPZuHgktLp7BiyfIRb3QBkuJ3m+nU3M8tJyj55nVMsup4+KQlv/5 zlCsFFkL9C7B1N+cS2n6yEGuEvuYNjFCxRyjl8FEUXHxVuMCG0Wj8M4daFcQqb+yV6DC 6CR13VRL68bchyoWsGZYZrvwo4lTwmXO+ts6PDFbQYI9x0ER0Fx/etO92TO+ZWw1wkrp iwNpnDDQ/LD8aGvrc96Q68IkkOEhVjlRidFf71pcuztf1JvuOsFzyJTNkYQXS6zfI/jO LTlcd2n1zPLtSg8BvPHLmOhiEARzgQ5DtnZWNoXkA7Xt6pKV5TlQBWMjZqJ3LggMyZM+ g2Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RMz1tbrS; 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 m6-20020a05620a214600b007463cdd2a59si3800588qkm.675.2023.06.30.06.23.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:23:26 -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=RMz1tbrS; 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 1qFE4f-0007bW-V0; Fri, 30 Jun 2023 09:22: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 1qFE4f-0007ax-27 for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:09 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFE4c-0003Mi-Hj for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:08 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-313e34ab99fso2025410f8f.1 for ; Fri, 30 Jun 2023 06:22:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131325; x=1690723325; 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=eRhCAakrEPIhhwkjbQqX6qZEbetcXESvazfsDHoPFvs=; b=RMz1tbrSPx1JOTe3Klwj+xUvY4wBZJaFu8Hvrlq00ABSgLVY3Zh+DNwluYtuHJ3+iU RfaTL3oUzvKuzLQJMEHZNv1MmvnVIw5QJD1JiVHqDvQNx1+GzdU7BZYRvcZGJCz1TUCr iAq04tLs9af1G1ryJFOvlElv2xnqKse4qKsDF/YPqtXqXKMNfLZaF+vsXG1y/tJR+Ca7 LLsgGh4n4xHVuQ5LDKeVupv5BKGaDeg4dOnyOaDyqwTCWnSTwVODXx2C8OPKtl2GvDht 8tL89/yu81dOyipPcp//ehMkED/2wt8CNBeiGQawsJ03i+UJijOeydiqI7zinRmCiCXz QGHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131325; x=1690723325; 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=eRhCAakrEPIhhwkjbQqX6qZEbetcXESvazfsDHoPFvs=; b=LWnbBYlN+yF19xiD+qh7BDOUh2LwYMNzBEZ5wRItadqL0LIPaZU6Po8xQ4iBGIwzPD KTeL7W3C84Y3K/fsBJFukvgEDoINhCkF6AJGjabLVv7H4mMAgxGMVtZHM6dNG3X1RS+B /IpF7WL7nRl5QHYmFtj03xxBhUeVESb0qhNFTWWBSGvbkpT74Rt3O05SkxEXNODbx/ww Lp4XTxmp3EwhWxCjZwniVp4NXpVj1DrBxNvbbsIhJF4GXzwcHHGu31POSkAqzmOdE+aP Sxz6Jmu/MU5tOgU3s7TqYS639q/vw2H6oZpYACc2xFsZJ+3wx/KWcJQkZTiZhrKxNRbJ /Nww== X-Gm-Message-State: ABy/qLZaUWBTpFWLGv7oxh1Lb4nIWIH8cQsmxjUSHwQkLq/zaegqAYZF EF9TYHnJeuNEC/Tr0R7xitvj206mgUFf6pugM8OReQ== X-Received: by 2002:adf:ead2:0:b0:30d:d85c:4472 with SMTP id o18-20020adfead2000000b0030dd85c4472mr1954864wrn.62.1688131324899; Fri, 30 Jun 2023 06:22:04 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 05/24] linux-user: Split TARGET_PROT_* out of syscall_defs.h Date: Fri, 30 Jun 2023 15:21:40 +0200 Message-Id: <20230630132159.376995-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x432.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 Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé --- 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 Jun 30 13:21: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: 697939 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp450333wrs; Fri, 30 Jun 2023 06:23:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7sZunHt6RzZglJSGUjpwp6aFZjxXllS3wSQ6DBRLJfl2JVWbIPaatbEV/+maEIdhZK53Rv X-Received: by 2002:a05:6808:1808:b0:395:eed6:5193 with SMTP id bh8-20020a056808180800b00395eed65193mr3003053oib.10.1688131434772; Fri, 30 Jun 2023 06:23:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131434; cv=none; d=google.com; s=arc-20160816; b=YCPBwrSduqNjssI1sHcex/oXUk+2neTRzOHveDoWoMvLoFj0SfBIpdNxEnPh2WFS5P ZxL8jxODtiXV1ay3sBDmGHU09iml6ttTgL1yHgB/C/7wbYaZgKScGQQh//GQCr4ung/v 0ciJF8NQHxYXwL8uiKqPcTjxdhd13TFbuqiFUuBN4XRY5tASoBPOb42zk61vYJvaz2XF yR3BxYUlD6FxeGMqs9RA5T0kkxYts9cbReSow84zRYiorFZYDTYqxDxr9lk5KbGq72Sd 9ctVG7ZmoHydKCFaO0hzMaPs/o+sY38NN1Es5YBHe2hZ0lfPInYrQ93mQrKVdBpYY4g5 OIZQ== 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=Q6xb79Qrwr3/yCfe4b5zEEhfS7DawccD4GjG/Ycn2cY=; fh=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=F10R07G5TKOBE/gYcVpauggV4M1HE10RrDzCUAGCw3aTXjDEfrMlZGJbi1+4V2wLfj oOTvz3lXcwXvOW/wpOcd58Z0mpZgZoY1oe38a5RoZK4nDVmkhmuA0UPBPrLEeC7OzgAP XNbocFN8MM1Zb7g0cptLLUeLprtRkboJvBfht5sIZo1JY/qgvFFqzi2qLVMsulyDW4p9 wXzIsyR+hAa3DQWvECkdKSqMi+d3Qd6hKmDtSkVMaGbdjGaoRihdqtGnqPGbts1qTwVK ZtjWf1UYobNCC9WybqOYAYd+j3U97m+Jqa8CkeqdHYDINwOYaKwocnEHazllQTKl12zW DQJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OXfFuGDo; 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 gm2-20020a056214268200b00635e113a0dfsi6757453qvb.138.2023.06.30.06.23.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:23:54 -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=OXfFuGDo; 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 1qFE4g-0007bn-UK; Fri, 30 Jun 2023 09:22: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 1qFE4f-0007b0-61 for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:09 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFE4d-0003Mo-2c for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:08 -0400 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-307d20548adso2129631f8f.0 for ; Fri, 30 Jun 2023 06:22:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131325; x=1690723325; 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=Q6xb79Qrwr3/yCfe4b5zEEhfS7DawccD4GjG/Ycn2cY=; b=OXfFuGDo57Y97RTz+mQ69erMGcanLkMYWqneaVI7r1QbQShfQ3SpYku3MbuV9fTEkr zupgUQFpWZBNlB8JzdAY4BfP3afWTtutURoICQlNeAQOo77ZWAzdKvEvnLVg+QLMMWGu KO9wP85Gx6n2Hiqis28B8r61FjFwwjyTzjlDUURyie+3cb6vc6nLNaS6ZnStrXKmgy+B noaXxXNJ6gj/d6MQG4jvT+ESsRNBx9s7+4CLqc5LFxIpqkhZnIswkUX4aEu1fJsdfEsC W1ssDiq3FzFJD4MFvtF3jrfNEiJ1PMG8oBytxMAM5oZIztwHpn8hGQ0wwax7lT93nOkh AEIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131325; x=1690723325; 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=Q6xb79Qrwr3/yCfe4b5zEEhfS7DawccD4GjG/Ycn2cY=; b=gFyLVnPOq/EBazcP+AuFRsFyCv6e4mH/vaqcuDlqAOfMTju/ls+CkQk/kMIp3vlDs0 KEEtK3gHpOSe0bdeAbLIPzXmkK4nS2bDOdQg5f2OLys11h1HqJQtQLyTRKigzjzeiCb0 ld6eFhVu5vVAAI7X4rE2OH71yLkrTOcZhkaAHymABrzrJA8gAa9XSKbtE8PecJlf4E4/ 7FZii/aHE5WEhrN4XXRCzuOaYjrEn9Pwa4PkgIMjMVPtVpH8CX8dsxeRHTg2524mQEuE 5YgYQWIFUx+m5nyRECAu4kvQRQR6M99HrsHLC/PpnBJSTa/cDkeTMm63D1V8AsId6JMj RjkQ== X-Gm-Message-State: ABy/qLbZU3H41uTVYhfpqp1jp3CQt0VPDh93+qhBTxKxxadwbsTWXZ32 DYwL2C5R4tpaaTO5MVPOifFXt7aYCwXS47vb8eJgXQ== X-Received: by 2002:adf:fecb:0:b0:314:1031:aa96 with SMTP id q11-20020adffecb000000b003141031aa96mr2050541wrs.50.1688131325571; Fri, 30 Jun 2023 06:22:05 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 06/24] linux-user: Populate more bits in mmap_flags_tbl Date: Fri, 30 Jun 2023 15:21:41 +0200 Message-Id: <20230630132159.376995-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42e.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. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- 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 f2cb101d83..459a2d8bc7 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 Jun 30 13:21:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 697945 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp451552wrs; Fri, 30 Jun 2023 06:25:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlGNdQUbGHjv5hkJh7o8Oy9cpPSM3Opdho9TWT2214xX1fcGZv2J2zIYL1qX4rtpyN7xH9fo X-Received: by 2002:a05:6214:2a8d:b0:626:29d4:9a26 with SMTP id jr13-20020a0562142a8d00b0062629d49a26mr3308228qvb.37.1688131557968; Fri, 30 Jun 2023 06:25:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131557; cv=none; d=google.com; s=arc-20160816; b=aqj4Fa8mnbvlHLfEB1m7UV8j/VZNCsjo9rguc75n1hLXdyxbsKgg2RRH+PlRMvQemL 8/etEZcZMjd5+uAOPI0eB25MDSLNdB3xQixm4rTNjsDrkFHlw3f/iHX8rwzOJlouQYTB AlETdhdsl+BTsI2UDZrO/OXObTV0xpKTZ2esUx/YFpzGQpD13/a9zbh6+wEkkU37FseW K0ABGojzmycMm3kHf0kEO+tCmSkB8Le3JOvnnyDauvX0oOGujQipZTPey1MAqyhWS5P2 JwFHNu+o0yBVYo+/FwR9A0zhVBmmQj1zGGHSEyJZMReFWmLnwIeNPewBOB8J5zf+NkZ4 qRPw== 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=lUkCksRepDyJ8GSSdRoBq8cm8bf7/10tPEy1hDkGHcA=; fh=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=AvBugQmO/6YF7WtMwDTWdkpBUo6zCL92rMGeCN5F1sIWg6F61nxD7olvAuutNajrov dOrVpQSAVnkPmZPr5yG+k4fKFFSepsXyZQvQ3lyjxxRdFNtsRbG1jOitxoa8THNxD0Pa 7tAfwCo7rW/UZ1PgFlUc+NPCNWdTz3T62LoMPQ+2fkRNra31tvwzuieKMArp1+enle7b Q/e91CITJGbXlMlblwkT/rmUBeOKzDpdqwhMI+I72pmYYIUAmSZ1/irf1xk5/9IdEOZV yiZZzwW6GN0g2lIcTtd25Dmn79jCNUoffqYL5Y2S2iOhU90fF6jgNj4R7DjHASQiqaQn D3Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ovDjW/I6"; 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 gw12-20020a0562140f0c00b00635e6968076si6521321qvb.509.2023.06.30.06.25.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:25:57 -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="ovDjW/I6"; 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 1qFE4h-0007cY-UK; Fri, 30 Jun 2023 09:22: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 1qFE4g-0007bZ-9S for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:10 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFE4e-0003N3-HN for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:10 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3fbc0981756so15774345e9.0 for ; Fri, 30 Jun 2023 06:22:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131326; x=1690723326; 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=lUkCksRepDyJ8GSSdRoBq8cm8bf7/10tPEy1hDkGHcA=; b=ovDjW/I62QwH9YT8eIZnAFSsRNPFYn3voVOh4biYZxPk4jfjdfHVUa/BbHgsR0425w 1zH4yxitjLx78dmngkoF7gq3i1FJ8DLhtxvY9ONXjCrrp3kdCmS+u5mQG2rAWiAWJrxA B8efsqj+ciwpNdyZPYRA+cTeHdqnVLP/c7s/dF46ZcSiZV75KGLJu6QzGP9XZV/4zGdE 1NshZmcYk1LwqX4GPvGGNhmxRH9TLbfB2uujuGN7UnCpT8w+X8qQbccqjNbKkzZojHQv V7kWFuGQr9GFYeD5r5WEpeDPnaNYioXO+u6xvq1FGyv4nKquyk66QrqRr6dGdM7iPqk6 q2MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131326; x=1690723326; 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=lUkCksRepDyJ8GSSdRoBq8cm8bf7/10tPEy1hDkGHcA=; b=aMYkywIiI++CXwOad83EnrKUQ8hl4a8WJaQbRYmIUh2DGjEvsATljn2fz7hEszAUIe GShP1eZx3v+Tw6rn2hAwTdXEazlBNBWLfnfZ43SUdj2Np3aWY4jHaNkmUfOdP0HIeq5J UinvKzaLJP76Hzi4nwXLu68LjC0XNzuvA1sfkQzbdc/DSphnktdHF90VDi8FAl7zXDnb D/4GAycjzbq0VMgqTOFa/v7Z1UVlr6qR+7U/d3pNQ0ggJKXWeX6vhXEH9AK6ZyQkOtqP lRNEvmdMip/6yQxH2csP3aL0aHemTwNvGF7Om5FevcOFvxXffBOYYWXl5z0rGIteZ+Bo bxKg== X-Gm-Message-State: AC+VfDwE/dBHg9cTQkWT+oAAkYQIwfJ76jtreSBR5ZrTe0GzTXWzoEFr xbOm5feN5JE8HnijD6MiRBLN/HvIVCWNhVhIqWcOYw== X-Received: by 2002:a7b:c393:0:b0:3fb:403d:90c0 with SMTP id s19-20020a7bc393000000b003fb403d90c0mr1792388wmj.39.1688131326194; Fri, 30 Jun 2023 06:22:06 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 07/24] accel/tcg: Introduce page_check_range_empty Date: Fri, 30 Jun 2023 15:21:42 +0200 Message-Id: <20230630132159.376995-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32e.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. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- include/exec/cpu-all.h | 11 +++++++++++ accel/tcg/user-exec.c | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index 8018ce783e..5b2c230d52 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -224,6 +224,17 @@ 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 + * + * Return true if the entire range [@start, @last] is unmapped. + * The memory lock must be held, as the caller will want to 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 8fbcbf9771..25c605dc1b 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 Jun 30 13:21: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: 697941 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp450488wrs; Fri, 30 Jun 2023 06:24:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ69A0fbFai60UcbPWt+Ld18hXGPBktJez1y6uppMp2G7E9zsvB+Lw4e6zCy7jTt4eBxz9t3 X-Received: by 2002:a05:622a:1826:b0:402:c515:5928 with SMTP id t38-20020a05622a182600b00402c5155928mr2658272qtc.61.1688131456126; Fri, 30 Jun 2023 06:24:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131456; cv=none; d=google.com; s=arc-20160816; b=Xhp+Iv8XTMIdRPo7u3RrC2tJLs+uIO1Bj/VZV6sbdxiM2g4wsmfbSbLcHQN2l7gHRZ zvrmpl/4H88FJXYnt7Y3T4twM8XILu4uB9/nxtJBW79EKVOkLaVopitjhGh/cJBV2acn Sv/rifsrzNI0W3dfNmgn/3JjNLTtdYTa3DmCdGY4XDxNF1xynJqXqBduuD3KoWSqRU9O fDISCHLCPYOqxptNgdXKv7STvPOVBcpIFiEvtg4iSFfWmEO6PmhPLbdq2pIP1ZP6KUOI K5J3G8nMxVcASK0Jgdfgy/XHY3ONy/BA3lXZkTX6JL5PCL4LDWLejBF5QoGTjuT5prxB DRsA== 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=l4eJLtUn0SmHiKt99PWqHuWj2v8zKyPa4Rk+HEUnuU8=; b=JFbcA92xpVT5uGJPh8h+uWgYF5xqP+RlKmz4V5mhSNQyzQhSXYRLTDLDFp+pOxFMoR JxObINZwGCSjA9mZBwc+ji6zWUJXcym1EU4t8pxiURtT64pUXHpT2MJBzfrGmyunI24l 6hpadUnCQt+v2avR9Mv1hk9/in/qORJZSNDdhjR4a/RzyVQ/jRB7GFGKVMNnWGBYg/zF 9y1zNb/thBifvmh2Fu+PoSehyK+e/N5L2P6cbCg3urxehrDTdcnNpuIItEoiMQsDaJ6e cUd2FmLrKZCu2TTlEKVuvpKRwaD+fo/jZ76VNEt47wA4m9FGXJ0+M027AkFdMFqIn1AT iq+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Eaiz4Qxr; 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 h4-20020a05622a170400b003fdeb0434eesi6133413qtk.76.2023.06.30.06.24.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:24:16 -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=Eaiz4Qxr; 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 1qFE4i-0007eU-SK; Fri, 30 Jun 2023 09:22: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 1qFE4g-0007bY-9L for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:10 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFE4e-0003Nc-P5 for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:10 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-313e23d0a28so2234244f8f.3 for ; Fri, 30 Jun 2023 06:22:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131327; x=1690723327; 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=Eaiz4QxrUIqwQUx8aBwkhmeEGe9yFNAjkcHRj7+xD/3npjI0yOXBIAcM9SGKhFFHcv dvN3eypvv1Nix/IqPG8fZI7uVuGqWkFO06CkgKKwAk9J/pUGFGWgrObeDeGA0FJVrI4e 1fkM8IV2vBaMP2hHx6ApBrZKS/pvzjAr4CXSeAsoa55S+uIZf1ex+BpxTMpCVD4zBJCp If96eas36X6IFthmOn/S/kFknGlIgWitOhiMYXfs2XK+PWC6sXlnU36l8KSrNWssGHFY IQpYaaSNeqndcHHmgSlbeGwqdRI0ZprUmKK3PArQp5eKGStqSzGml8XqhrOuC0DjQxaR ovpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131327; x=1690723327; 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=aGxC2by/JxSYIE2TUgLBups/gX2Jp3r4k+mK35bMw2Gg0+fgX2/1bRlbvvFFO7l7l+ HmRsUj/Msp/EDyIfo4EhLvOIqunRR+9IoL0NwC9mGlYxAfMSqIyxt9CyvSZIhJCMTcQn 17n+Q1HY1dS5kOzVq9EQ/4aW3MaPAAw7oAv3D5t7QxYU8POuZVpIM9sUWnjUnBaguvi0 6ONi6XYA5m79ookXmyQvcAQQAQ7K1Awez8D55+hdMNM9LSVhdqw9T0CKHpSXltBH8UgX Z55BZPXk45iq9wp6rIMDEZyVBi1uPBqbrpQ9KWPH8BImPBK4gHBDTIVzDA0A0DCbFLBf N7qg== X-Gm-Message-State: ABy/qLar+RFqp8saQJlWUfIR9UA/wyJwsOapO1u1NrbLlpfRxG/nYS84 JfcldNzoMl8V1TolQeR/N7gzmBgUY3Hf9xMGqhGN7g== X-Received: by 2002:a5d:525c:0:b0:313:f61c:42bd with SMTP id k28-20020a5d525c000000b00313f61c42bdmr2728223wrc.59.1688131327039; Fri, 30 Jun 2023 06:22:07 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu, Warner Losh , Kyle Evans Subject: [PATCH 08/24] bsd-user: Use page_check_range_empty for MAP_EXCL Date: Fri, 30 Jun 2023 15:21:43 +0200 Message-Id: <20230630132159.376995-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42b.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 --- 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 Jun 30 13:21: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: 697938 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp450234wrs; Fri, 30 Jun 2023 06:23:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlFkqreTfPa1XxhOjICaW82PlgC39B53Zw6plKlRnHEw8iibogk8IfvEpPzdlJYgxnbNmb+J X-Received: by 2002:a05:620a:2955:b0:765:a55c:b62b with SMTP id n21-20020a05620a295500b00765a55cb62bmr2924911qkp.76.1688131424009; Fri, 30 Jun 2023 06:23:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131423; cv=none; d=google.com; s=arc-20160816; b=erMewqS3aESeLl0EaeS0ltvaBVvfHgoiNmWuXi819swdSj8LOtgu8ku9vkGNpOiISH QidRcmk/1+m2h5v2vim/xy2oT1/iSb7PyD48Jf3bViE1eGWZ65mbHvlUnNQmvPmkkr2V 66/q2RlyG672Vc1cadREiloTLNLjEt0s/K2dCGLFI+f7jFAG5Xn8e581yAx18GvSCDE8 9UgntedfPZMa8Ef2Ngm55xeo2djsh0wjLZayUjIj2+bjyK52zumo1IA9gnFz/2nzxaI8 aFvY7T5oh58kHNLVIkRnJ5A8+H3pqighzrgkLzMrD5K8AGX8y2FkEuwWNWOKQF0/TokY GrOg== 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=KrYEO83mUZLefivMHniXeqFBDxyfnNPTYsBHzpccNBQ=; fh=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=YD+nZusrrb8A9DmqGHbC0Rm95Ur0gSntUayrp9cnkKuIM566O0gxHrYDhuwoe4qvJi q4eUUkisELXt5WdHvMmh/fXeFHcoalb/JBpd1sGQfYzE2ZjeQaO6Z04flk3zK8kYYpYc Gi/JEka4Oxs4xGktqgJeBFbBwi+tWbosladO7AurlyXQR6xw6FVF9pDf1+wao+X2xWhh LW1xS8TWFcXmVErvOT1KlPmPl+byorNuDB2aL8HDlIw/yWiR7v0y6qUATgXysMTKG3Bd 1wcunj3EFaoLEBleVcgz2o3a8hkuvFwGUN10QZKQkCVtV71ykV9Jg40PJ2qhrQ7A15u0 DpTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LXYUpdWr; 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 m18-20020a05620a291200b0076718a3ad56si5477057qkp.185.2023.06.30.06.23.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:23:43 -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=LXYUpdWr; 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 1qFE4k-0007gT-Kg; Fri, 30 Jun 2023 09:22:14 -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 1qFE4g-0007bo-TE for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:10 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFE4f-0003Pi-8T for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:10 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-313e34ab99fso2025483f8f.1 for ; Fri, 30 Jun 2023 06:22:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131328; x=1690723328; 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=KrYEO83mUZLefivMHniXeqFBDxyfnNPTYsBHzpccNBQ=; b=LXYUpdWrRnIAD1HM6dGh+2e903minFPvPqaLvgDsIHpVZ+3Mlh/GrzybUBu0gQR+Ug Yj3+hKguXBr/5DqXhG4Xe2qISjIS3VNDYDmqhXxmEeeugWB/t02EDUJulRT68/Cakr1o v/tMgCuHQ08x9wjzI6crDrfA8YtjGcTXYzrfSi+U8MQWltpFsNgZAavS1C3twDfLVWL8 RBBWaOEThYCOz7z8K2eOP8E2qlWbLNb+vhLDx2ghcdKC+Fq71dgCwDGMLijVEe3uU1pe 7pMGWqZWN+SfUTMYydRu7Yl29USxhRMoM10FoAXfLCjHYqE1W75ciu37El+lCNdZFNVD aHPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131328; x=1690723328; 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=KrYEO83mUZLefivMHniXeqFBDxyfnNPTYsBHzpccNBQ=; b=YvluMkCbTxARkyFAEv05XWklGZt88XSIgX+33LUgxRScgDcUKdMLVWASkYgIy0mddH QwQnV5rXckeAuUlIdcxWcaVHNQBPi0on5h0fBhT/MMfb96QvH9iKuAusooEIf3D+MC2T NEZnuxYPpT4bp2Op6aDvDoAdQIrlpOHwiDdwDm82h543QgTz0swryX8N6qgAQ4u4fxyd 59Fg5Tgs8OO844Mb2QnT8fuVylL914DXl1x2PNBgQwK2rXLF9PhM4QPILQ4MgOEP8ZT+ S4T+NcjRBitR5aOVD4ncASa42CVwWQdElzSNetxCWu+pJxDPUFgsA9CZFFWdZa8QPQrF Ex2w== X-Gm-Message-State: ABy/qLY5p2+slTcMZFVeES4Pa5FZ3TlxuPuzuLml3sRYYW1uGsMfYZxp 2onWXVlmu3eUUmMIeN7OLv+sXJzNWbdifHOE/sPnYg== X-Received: by 2002:adf:fc12:0:b0:314:14ea:e2db with SMTP id i18-20020adffc12000000b0031414eae2dbmr2088627wrr.0.1688131327731; Fri, 30 Jun 2023 06:22:07 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 09/24] linux-user: Implement MAP_FIXED_NOREPLACE Date: Fri, 30 Jun 2023 15:21:44 +0200 Message-Id: <20230630132159.376995-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42a.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 cb5369d2d1..41c2f09fd5 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -502,7 +502,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); @@ -544,7 +544,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; @@ -593,6 +593,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 @@ -608,7 +615,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 Jun 30 13:21:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 697931 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp449911wrs; Fri, 30 Jun 2023 06:23:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5o5dzj5V1o6fG290X2AMLKaxO6H2fE5py9wJKhVRrbKsG9CxuB27qeY/ggjLc2pVSCwuRm X-Received: by 2002:a05:620a:2057:b0:765:abeb:a148 with SMTP id d23-20020a05620a205700b00765abeba148mr2263276qka.37.1688131388714; Fri, 30 Jun 2023 06:23:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131388; cv=none; d=google.com; s=arc-20160816; b=QpY3HgMmpcBmP0lmbvIQJmf6HLPHyucWSRGtUv9u/sNuJp9Yyu7Bkvc9iVpCsfKfU+ EpPd+Da++fgCB9Zqsy4gOsWfKZwkHOFEe55w9sp2QiPi2ye907duhAPP4tVEjXweUPiV JqMb4WhzZC1po2ufi330UHeLi2dWkA19h1eOUTDi0AFXqB00Rtrz8R8UDk/Gxqxtyw2c KxIDRv4VVC7mx9WMir4ujVSwArAAH1WvU/6rusO/AXEGqwKt9ggJV06EX0DptSGSNQa3 639z/AFpS8D67kdnioV/gpMBOB8LONY5xjYy2cK08esck5990uX5ujn9KLVI3oKBf1gt ppOg== 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=xoWOZKa64xsR87TgP0bu6Uv4jgrNi1eFmvRemUFvDuo=; fh=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=Z7V1eKykpfBUOOfzvrDFSaHpl2MXoPOfZ7ErUY1bGIIByLWILPOixMw/bT3fuE0BxX mIuE8nNydPrZ1dPud2ZouhCzPk8k9J3gx9iJskcAA68MlnO4eBr/uU6q9apuP8MiLMkX 95jSEGCYqF1TjFQ1iq24KF/pGSILptrKLxa9gO9LJZOQYcecXF5cXF0rXUd9gE7/jU0G yUBkFwjXfXKwBLPajvH5EBxuwrNMAa4HgNZrjQQSIphKt+qB5SvE0H/sANx8LfL1PEJc kPTIdeA7wqifgXlPw6cmJjx+MPwO9yMV6d07bJZ9OgnUe9+1m9cEipdHHoMJaIE1vbie HHaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Pr1n4G3S; 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 qd15-20020a05620a658f00b007670b879c22si5091054qkn.431.2023.06.30.06.23.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:23:08 -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=Pr1n4G3S; 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 1qFE4m-0007i3-Fz; Fri, 30 Jun 2023 09:22:16 -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 1qFE4i-0007cz-9a for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:12 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFE4g-0003Ps-4j for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:12 -0400 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-3141c3a7547so1703238f8f.2 for ; Fri, 30 Jun 2023 06:22:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131328; x=1690723328; 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=xoWOZKa64xsR87TgP0bu6Uv4jgrNi1eFmvRemUFvDuo=; b=Pr1n4G3SuT6ZTTtzRo7aESDNsoCm85NCENc5sfEA1+zKLFckDJ0ioomsNde129MlBP PQHKgqizLt78oSw7P9RRpXimxIB3gTyOSnwrqAoXYdZXwFBo0ygkE+CYSqcNR/DBcfwz 887Y94Mh9l3y/F4ljRsZYzDdd7dIlmg0Hn2sJTqRW+68jd1lWnTRG+Bq26Rk+681B5Wc vuU1HGwj50xTd86Ttfm3AXgF7xnBpQtagr9B7E3P0R8p8W0IgJHLaqkGt35iHRnDMtoW j1mkTYx5jwTDQE5EUvC88Gi4J2Lqu8JoAb9F9EC4g0GRvtP7OfQnNkPdbv4irlAuWK4/ ROOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131328; x=1690723328; 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=xoWOZKa64xsR87TgP0bu6Uv4jgrNi1eFmvRemUFvDuo=; b=E3f/hJLjkNm5KcITwUlLj4z/VkeD5e+kacSUvnz1FbWkMxFodQS5dR0N4XhX4du2/r RjiFY82+zBBhn2l0B7E6V0lGQp5X9wsuD5IV2UmWvouuU746kCgrmA5Atsek+9cLwkRh 9C00JOKgoZ9VOaLoCkcOrImXCyxM7NSSo75xXzZaCwGI5oa5A5MOAnXjL1O44FlcAbMw shyS/lIZvd4CR3C2yURImJwsz8NpJtzz/NhwhTjro6Xr+iUA87nRvVdF1bl0MqAGpOwM aNSkm0+SuOrGvrMGwyZSWT8X0OZyO0Zga8wR/i4Nqew/0OzSbhlaT82uUUGQrzv5Uldc NHqA== X-Gm-Message-State: ABy/qLbNzx3J0H4LVW7LiCbjoCsaZbQJ631Ura5Z0d4nd8cF1WnbH/P3 +YMak0fofOm16fVP6co/gFUBoIwC6egAsLSSdLIG2g== X-Received: by 2002:a5d:4651:0:b0:313:e9f6:3378 with SMTP id j17-20020a5d4651000000b00313e9f63378mr2202940wrs.4.1688131328450; Fri, 30 Jun 2023 06:22:08 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 10/24] linux-user: Split out target_to_host_prot Date: Fri, 30 Jun 2023 15:21:45 +0200 Message-Id: <20230630132159.376995-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42e.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. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- 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 41c2f09fd5..26d409cb60 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); @@ -453,7 +460,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); @@ -463,7 +470,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; @@ -546,10 +553,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 @@ -606,6 +615,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 @@ -614,7 +625,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); @@ -636,14 +647,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; } @@ -653,7 +664,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; @@ -671,7 +682,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 Jun 30 13:21:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 697934 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp450020wrs; Fri, 30 Jun 2023 06:23:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlFbzsnak6tejMAciq7TEH7NuQcn1EaDIBsKMsAElP9TOh9zMkwj50j64zjqzDosMRx6aK1l X-Received: by 2002:a05:6358:5115:b0:134:e41a:9227 with SMTP id 21-20020a056358511500b00134e41a9227mr2229914rwi.5.1688131399022; Fri, 30 Jun 2023 06:23:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131398; cv=none; d=google.com; s=arc-20160816; b=u6Efpb+ZwGomlXsKGWKYjrP1tzJTcVdd7/wWxP5GTESc4lGscbpXnAZfKLxOoZHoMu hzcTMlrkZW2F8/HlBKSWyFfX1ja7JMcJmE3FF27Lgm7cl6nd3VG8f0gbnfdQFCBjFzcb CejnMen2yoCMKV+eKuT9oI1UCaVKc2HuyKse123wWshbQ5zG9EX4EzCQSTIH9Pz6Kbwm 052CkdbT/oSefKCuRRWI7zgK95JBNpliIQoIfK+5478HpW1gIEEWMJxyChZmlYbkDtVc D+lMx84Xfb1ENeb7eMSzFA6+uErY/w5g9IDQDfBsaJj9kXDX+fSH2x9AIrLxwFpI7DTQ 1+AQ== 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=OUAuwo10Yq9+V7BF7q6x9M7fE+x9XcbokQqcquvrZKI=; fh=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=s6fCeVuaO8DUN0lfEguRpaH/TuAIkX1jq2Bdv1yX6y1kj5UxzYjrfHCnmo3HAurX3S zA4dTk/fC1XOwQTMuyMrLmBHWStrFe4AAZ3J3h57gy8sfBmF5LOxOggfhTyD9lBpDOE+ NO92Uyuh5jCPNGnkAfrDAYqTS6jlSkf1cNxt95XbpBaI6xpsJdCwibajMLMlfDORojSW pTDl2xSZf+dncEbwTK4JVqyxuI3+vsFxjz4PfSeqW5q+/OTs46zh6sAfyXswvWItphrT cpDi278kcYRI0OtIL/Wa/MzWXRtub0OWB3rIDiLAI6lThEtB/U4/MPPfTjs0pJbmHt9s MTAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="eAC6/hdT"; 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 z7-20020a05622a028700b00403435ad3fcsi612013qtw.377.2023.06.30.06.23.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:23: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="eAC6/hdT"; 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 1qFE4k-0007gV-Lb; Fri, 30 Jun 2023 09:22:14 -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 1qFE4i-0007e3-N4 for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:12 -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 1qFE4g-0003QI-Lb for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:12 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3fb4146e8deso23133705e9.0 for ; Fri, 30 Jun 2023 06:22:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131329; x=1690723329; 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=OUAuwo10Yq9+V7BF7q6x9M7fE+x9XcbokQqcquvrZKI=; b=eAC6/hdTA7Sv2mmgrlVtc6HyUyPZfJ5unK1MCQ6VAcuz8B7W6IQ3UuZvjCWtIh0GPB LyafnR4HqDn/cvNKrbsCRBw8b7QnDpmwbPLg9DtpRx0e7RV830nhx3cDKyYRlwa88Hau hXg+tV2vmNJS5GkVmJS4Axdwf707B8c5T0qp+5UxXobIwlnp2OA4OaA3a19DW+McRxm9 AbZA0RGCbLFKM3GDisBgeuI3UJAToDPesLg31cKn0s5Jnq/MOUMkIxF/l5LaMXj9yPRi ElVXBKxchgFimnrgcR59ShZt9CRMtxEKxZjveUvRzNt8lrvzok7OSCuto9P8+jhA0SCG 3OCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131329; x=1690723329; 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=OUAuwo10Yq9+V7BF7q6x9M7fE+x9XcbokQqcquvrZKI=; b=gD2oAtiU2SfHiGGVl+36XmDMDAjWB3+Rcm23trnzbp10Tv4/DzT1JJ3KBBfKNnA9gg heVN0+6UEzmodaSKu6DlfFVWQKgxjKgzi2CT24OWvWqp9iJQ6e1Q9YYHlmueKqPklCsd LV9Enrp8aOOaJ2Z5qkB7A0L4gaKaAq1kMbPI049wlXsezRF5W6u3hRPatn8pXZK3moaZ x6Zek9m0thQKiisXIbD5vOXLbCVTuAnhtGCza4N+f3ZbFZgAJrhP6GBuByKo/OxjCkdb VJiIE6jGNgJFykVvE0WhyAcTqxmoRnzm1kFZ+Ak9lx1wpQ+BvGOO0ADh428Zth2f2vYY iysA== X-Gm-Message-State: ABy/qLZaYYD15orH+ou6lgfsDqfGca4VOEp1KXr6mtDuXbGx+tqeZ+6U fM8FIO10OY2D6FMaM5rMTFIo8P/Zx4FNmswGLVYmuQ== X-Received: by 2002:a5d:4f08:0:b0:313:dfa3:4f7b with SMTP id c8-20020a5d4f08000000b00313dfa34f7bmr2714153wru.20.1688131329301; Fri, 30 Jun 2023 06:22:09 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 11/24] linux-user: Widen target_mmap offset argument to off_t Date: Fri, 30 Jun 2023 15:21:46 +0200 Message-Id: <20230630132159.376995-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-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 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. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- 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 26d409cb60..98be739b5b 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; @@ -456,11 +456,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); @@ -552,7 +553,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; @@ -571,7 +572,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); @@ -675,7 +676,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 459a2d8bc7..94cb4ad8fb 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -10350,7 +10350,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 Jun 30 13:21:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 697933 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp450002wrs; Fri, 30 Jun 2023 06:23:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5tbsh4lRqSKrmTFMRvasbMNxfnHKj4AaKNi/xDTBDlSe/fxTDWpz5QrCa3Fhe3BOIe/mM+ X-Received: by 2002:a05:620a:1990:b0:75b:23a1:d8d8 with SMTP id bm16-20020a05620a199000b0075b23a1d8d8mr3819777qkb.28.1688131398038; Fri, 30 Jun 2023 06:23:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131398; cv=none; d=google.com; s=arc-20160816; b=Dqw/GcG9oE1+5c/rcc6Jnbui/CXvgh4vqCi1xP+Etgm4zbNAo0NHk8WPO3ar/0GLdP cFCj2KTasdPVSyPGzJsQLKu5qEI7ljSUOxmvLTXpplX5IhHT6VnDsllW6aq2X0hUUIjb wzPde4rfXHcHv145Mh/LVf1q8N0GzVt+B1pE56zyEPEpMTjqL4SiZPSUSWdKGya0Pwht dDp5htlNE75Uq/JNANLHBMEHCz95HBWT9zoSZJiJ8Tv9VGQynuCMqUp7GiF4U5VX0PlU OkBzKRkaj7Mf8NEMt9bdD4oLATlhRotfhepy/LoyQ4sMc7cZVz1s0S2atAzmoPiMwDrN X+Mw== 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=Aj62CrXurYGS6qldiW3QI3IQ8iB1Fmrh8m1XANRmtvM=; fh=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=bhJL+6FZRTXMr6eTgeyeNjWkem9o25ol3pb8OI6PFQYFwQ6lQ1nLQyyrchW7x5RhuS 8GEHTo8I5voUC+fKiR8+3dI+LvMNjRDSx1JBUG6JnHD70t8kCku5byotdYQcMTWKgqqQ lNmr43+TgjdfIBUpRvpz/4OKaWCVTpfkR/XOl3c5ZhtHPPakkNgpN/CNP0jf+BxA6256 gyMbpNSVI45xd7elxtwMb9O8H6PkaAUl8imkipL/AaqAEv76CNWwppYUcNNENUdFwt0q SBEhiIzBEjte3kxTKBRs4xaYq86ra1bq6ie4WLfq8SuREM2mz67kN0fBZJ7+M36BPekR 7UqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ONhGhKdT; 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-20020a37e115000000b00761fbbb1613si6611980qkm.626.2023.06.30.06.23.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:23: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=ONhGhKdT; 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 1qFE4l-0007hM-Ck; Fri, 30 Jun 2023 09:22: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 1qFE4j-0007gA-Rj for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:13 -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 1qFE4h-0003Qb-LC for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:13 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-307d58b3efbso2095724f8f.0 for ; Fri, 30 Jun 2023 06:22:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131330; x=1690723330; 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=Aj62CrXurYGS6qldiW3QI3IQ8iB1Fmrh8m1XANRmtvM=; b=ONhGhKdTbnT9axHBqRu8dFWgdD/hkHc8DvqCugeUMxW2FInraUeq7xyNj0asJnyTnw wEIZlx0i9WOfMvJpFdd4c6ZWxrqVjvs8sz2I93xSChmVNFq+4ezM4BI5FB9TgMsGxesE rnHzNudl23A/37o308FwcZ7jP4nqHh+iIuhn/iz+D0A79gfGzwQ8wgS23mYcFWK7Af/u ZWI2tE9Zu+DuzULTCYIV0CWlAd1NJ7krjb4JvuxoVpdLL6X7FjEGMFQr4MOrT/rGdxjM ZvapdL6r+g0KfgVJSTZVfpVJx2bBMld+I7voJiCCoXnOTBMdVft4siYPtm0j17eueFsp JXZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131330; x=1690723330; 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=Aj62CrXurYGS6qldiW3QI3IQ8iB1Fmrh8m1XANRmtvM=; b=mCssGx6r4mfClNgyyR3MZScxXWN3bKx4dOm421qsokIavWvGqvpm2OC0FSWc5amMk4 aXSJK1yl8RrvP7YZwAvBpM5Q9bv2NdJTBYx3OEJ1o2Hg8+/NH0Zt1m6djc/e5z4OoxP9 A5uy1Ck6sjjAYrVaLJZVxkOFvGTs7cVz9pbEl5N9Aecj1ZJAbYSucUG52FjTkgNkhb1o rySTlO31L1MKdQ3zbvOHn/YQHMcmuhGk3Vpr9GKMV+rZSfs917BwnDSVub9zY9Se6UaD W6gAPimloMCMSqRjcEk/rmiUbV+vXEBG2gI7X1t0leGafxnikREo8zfwNnJwaXtkFdyq qymA== X-Gm-Message-State: ABy/qLZDdYO+CicAtwrCDKYIuWZxleTku6IgkFgByVpnnDW6NKbQafkd CnJY2/7QVJult0qYjzbnVsrwEWq52y80MAKctP2eiQ== X-Received: by 2002:a5d:698f:0:b0:314:114d:3300 with SMTP id g15-20020a5d698f000000b00314114d3300mr1964171wru.57.1688131330175; Fri, 30 Jun 2023 06:22:10 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 12/24] linux-user: Rewrite target_mprotect Date: Fri, 30 Jun 2023 15:21:47 +0200 Message-Id: <20230630132159.376995-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-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. 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 98be739b5b..c9bd72d3f9 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 Jun 30 13:21: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: 697948 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp452527wrs; Fri, 30 Jun 2023 06:27:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5AzntQZRBrcKYBNCTjY+OKxil+uOMxq8QLhXmTNXGe5wQ3wRsCQBl4d1w/LqVVaL7Isynd X-Received: by 2002:a05:620a:2984:b0:765:42cd:c192 with SMTP id r4-20020a05620a298400b0076542cdc192mr8825481qkp.37.1688131667628; Fri, 30 Jun 2023 06:27:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131667; cv=none; d=google.com; s=arc-20160816; b=pVI6IEZenbem8A1TvP6f+tXC1wsEZNEKdX4cx/pK2Cbl/w2AeNJDuSoZC3sSI9nWtH gY8xClPiY2mFHqB3fy5Daf1UwtuANGT9Zq2PasDOuhguUfO0a1bJY9zEcC4HFtdXNBjO 1D1Wu9DRtrozxNtx8RSTMvW06tgLGYAE8anUZ8cSvJ/ICpPsnXmaU9WLU7SALCp/76Dz QnYYvvFDmVkmFtZmtmHKfV4Rsk5nQEkxTRodgZBHpQAQrlWdMun0erqLMpQ7auSso/t5 jL9U0DHFu+POlhwrwC0jNrHUrQ6bDo7wsobD67L0OCwIPNhuT2aKs+HPbf7bxibWWLDP q5cQ== 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=ATo4xPCpqlJo0OX4/YmZKCOaCJgLjpigwZg6oDzTrO0=; fh=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=jpa6Up7j+l25UEIvWcOgvazheIkNtZMqKe1HvvM4YqoQQFkrWhtQhY3hsuaBO7m3K4 3IW9RdAagTRz7GMm47OQJmJ/5L7aYxF8Ir72lG2g4u+bAdyck8RrvELYPVlXWXj40Uo8 4Fh+bv9/54r5vjlTwvjkaG4lpJbqpr/l7YWRCKEc3myMFrDXOW+m6FfDY73Bksyr5wCe 12xG2eHgLu7YvAct+VM/zvxUP3cXdIVtKdPf+18pHFLE5/gcipyFSMTcq9flz2MsiloX vBTNH3LpdS01/n1g7ANnU5H4wTH4zRbnV+s1OtsoYWpaL3kIZYDduSOjnyI76oGcVDlx x2AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ncxr59Ow; 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 i22-20020a05620a405600b007672b4ff13fsi3944013qko.604.2023.06.30.06.27.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:27:47 -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=ncxr59Ow; 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 1qFE4n-0007j6-JP; Fri, 30 Jun 2023 09:22: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 1qFE4k-0007gU-Jp for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:14 -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 1qFE4i-0003Qo-Oi for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:14 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-3fbab0d0b88so16304665e9.0 for ; Fri, 30 Jun 2023 06:22:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131331; x=1690723331; 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=ATo4xPCpqlJo0OX4/YmZKCOaCJgLjpigwZg6oDzTrO0=; b=ncxr59OwCTfb75YLVAliXNB93/aaCR+D5anQBig7mwD6jPea6bolwmBK+l1ai8EE/E mIZwGtI4yjQvo50itb3mUnv/s2fVilvYLBm2hlaqJSZZ5I6AOwHgmbueUIt0h9k3ZtzK LiqNaUE6gWz7RWDFlyLRy5dMVKUdPsVIpgHYFXbNbnymxVh7pVHgYT0TtUJ8N+lPvW4e s3wuEgst8UMDJyRy9p/kQt0E6aP4y17PCcC0eQ+6eT0INH2T2p75uCtdJYFRrSBDEswy RKP+9G3zq7GRA5rNOge5YJnjpWxZmU703jnAuWOsjhwuRHOn9iTKVfMu+0SMKBO6BcFb GWWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131331; x=1690723331; 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=ATo4xPCpqlJo0OX4/YmZKCOaCJgLjpigwZg6oDzTrO0=; b=F/ktImeNVJjRrEYUo3YXmba4CMamAFtC9KH24eWFb0hIMdVp+/34Xudk7m4qAR8Gnk c+pxg354mQTiVNl1ureJxm6qXBHLPjUB1tTd6bMzoL9WaRoYn58zGd5w0JtniQpgU0hU 2oXH+8JV9SG/Ol6Sex8x8jl4pbW7WDGPlnjjHK3oYTIOWX1EW+5Z2HL3sCO8WGb0qf5S X94S89CQ9BO/1RLLZDqPZ/fUbADoNaOlso3KpN8lemi9+ND/N6JKWxPoL+pMDIQy64W2 EsfWZuXPvgrtE11OLV5wO8tYmrnIhAyig798hYNprRbnhjXNcv+DmlyeIteqVx+xddFH aupw== X-Gm-Message-State: ABy/qLbuXaXkbtubVydJ/6Sd9gjRWq1s8EiKOnLWO7APxRVYlfjFj6a7 vtGMPPpW2VCzXwiWH9lvOuIzXtgdox6YWsXahV2zJg== X-Received: by 2002:a5d:61d1:0:b0:313:f3a2:e5d9 with SMTP id q17-20020a5d61d1000000b00313f3a2e5d9mr2620690wrv.3.1688131330987; Fri, 30 Jun 2023 06:22:10 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 13/24] linux-user: Rewrite mmap_frag Date: Fri, 30 Jun 2023 15:21:48 +0200 Message-Id: <20230630132159.376995-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-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 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 c9bd72d3f9..e332555dd2 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 @@ -675,27 +678,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 Jun 30 13:21: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: 697944 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp451144wrs; Fri, 30 Jun 2023 06:25:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7fqFzP0MhoF7lYprruMynBbF7SuBFFeKlCFRwy08soxHsdB8aTAyE9l4pgD9pMH9lLM8qn X-Received: by 2002:ac8:5716:0:b0:400:e685:d17f with SMTP id 22-20020ac85716000000b00400e685d17fmr2646033qtw.62.1688131521663; Fri, 30 Jun 2023 06:25:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131521; cv=none; d=google.com; s=arc-20160816; b=dnwf0fhPrHAopG+kJmuWXC9lrIMvZDE8/Q84BO/8Fzh3fu2DkrrdNDByyI1hgx13ey G3luANdEKukFyl0g22XuP9T9JqgmKE9oyoMtlaybI5XKqlPM7eE3hLAUDWJ6oCrupgi+ SvZcBiQBZUfJHMEr5b5mooms+tBCiRL4+I5eMoBa4tioemRjgdIdZDPTbX/dqy9D6hvj AXructkbRxjh/RAGahAuU29FK3GkuXsJk45iNSBj1Bbz6GGxO3FewW4m5GZ70fT8EEZs 9TjWR54AqwJBX9prZtGr03ldLtsh3JSyQ33yPseQFgoC2u7C2bzkzlDJlZZYqdWjicg+ ZP9w== 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=b9o1+scNBHwOltGOMKjLdxQCBRKnxZyx9r5UrOt0WL8=; fh=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=i/9ImakZqqYF1uhNFBFhLY1tQb89AKljdKGByKNlvZE7PKZKlRgURAcm3Tsw1nY0y6 Crpdpt5+CFb8x4ve2qZARqJFI9U2ug/+taXgZMlyH6zXAqLYak4JpybUCrDdVxgQYmBI 43GgeTG0ys4Nh67gR2qPiGtL4+pgL6uxjVXa1pWa0p8Sj/0+Rf/Jy0Et9yZLnc4SjSgH zNkEzIyVMdNC0m6CPZgvHLgDejvUXz9SnfbLaPqgvkUHjTrKNqtRBPfGvh5M4Mne2vKD 9+M1uLvFVkPht041M34pmJMxk97zzUptzieB7AI44simSNbI2yS3cbgwaf7MMAiLzljP t1Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rPRb1G6j; 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 o10-20020a05622a044a00b003f541337f13si8054355qtx.689.2023.06.30.06.25.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:25: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=rPRb1G6j; 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 1qFE4m-0007iY-R1; Fri, 30 Jun 2023 09:22:16 -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 1qFE4k-0007gW-KT for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:14 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFE4j-0003R6-0D for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:14 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3141140f51bso2198675f8f.1 for ; Fri, 30 Jun 2023 06:22:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131331; x=1690723331; 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=b9o1+scNBHwOltGOMKjLdxQCBRKnxZyx9r5UrOt0WL8=; b=rPRb1G6jrKtVeopxrAYnvGkwuDWMl3PwtIcmJT5p0EaMb5dzzWcXb+wndQlQOoT4b/ xhYz67nrdy/9wb51SV/+cXMp0QH2Eaoz6REsrLOSIkT9lOqvV/2olW/JN/qzNx15b783 TwVszseDR8aLOytKXuOjrVyrQ9b87dYPzUagkbPGitYFSTPav3DFduad5sCq/cHq98uw osszEnVKThXbNEWoWJyixfIR/BjU9Vn5vPlWN+5I94rRr+r9Vnky11QHwta8ojHpppsh LmJ0upDyauHnwo8eMjX4aOdudQV+0TljbljWfTlBfVmVb7n/I4/CjZZ0aeFv0biYee6w hg4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131331; x=1690723331; 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=b9o1+scNBHwOltGOMKjLdxQCBRKnxZyx9r5UrOt0WL8=; b=CM6qWjEdtCPtWRS+w0p7hbtEhpDtIYwzturBV+daLramdPt2gdg8v9y0C0J0AhUJSs Kl2JpfLHY6/ihk2wpvi17tKx8CGlThPs+Y9Lq8yMzZ4+IVevReROhLJoUlo1JXwtlkx/ Og+btVR6IlWDPZIQtV0UFJorFNuvG7/zvHT+pddX8XrfYAIdA6yG5TUO9YLaEl1jATF3 BuJbazPvKCjPwnsBd9+y2GTEsa2On10e+ExJipbwP3Zhkrn4P4k0Jayz/liOd2u2dBoR hQzOULfBPAWLk1ReIsud4pSZCTIzPsnuwoLQcfak2LSt9jhY3Ryx9f7azrkITTGc86Yv jpqg== X-Gm-Message-State: ABy/qLZ2PxbVnBrRv3g66OYnZRckc6uh9j6G9eezS2xwXs1mRY9H+X9n DlwQ3MMhLgcAK8K5rFayg+9h3ukVqPCsN+dtDsbxeg== X-Received: by 2002:a5d:6a0b:0:b0:313:e6f3:d05a with SMTP id m11-20020a5d6a0b000000b00313e6f3d05amr2088050wru.16.1688131331671; Fri, 30 Jun 2023 06:22:11 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 14/24] accel/tcg: Introduce page_find_range_empty Date: Fri, 30 Jun 2023 15:21:49 +0200 Message-Id: <20230630132159.376995-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x432.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 5b2c230d52..e2195c7e3d 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -235,6 +235,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 25c605dc1b..dee4931f86 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 Jun 30 13:21: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: 697946 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp451557wrs; Fri, 30 Jun 2023 06:25:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5sMvvhG3F6LqaiofNklPknkwkM5Pd1IgIuhOgt/hLE+bVEDiLlB5Wkdme7w3/UTy0nzGnA X-Received: by 2002:a05:622a:11c5:b0:400:8613:5378 with SMTP id n5-20020a05622a11c500b0040086135378mr3575274qtk.20.1688131558291; Fri, 30 Jun 2023 06:25:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131558; cv=none; d=google.com; s=arc-20160816; b=RANzKiNBt7kBb0YeisYB3vVpkzORwVeRKfwFF8fJpzgIUrI3XpJNzntr6cyoVU6SyB GKqXMc1i7EV+wpvqaZ7Nq8iDNzkllqyjIy53i+bmHcO0st9OC0rGyj+plOWhenE0gxQB U81n1Vk0ciOFQxnwSn3w5g370+drYMIgtw/5Cx7ihvaIlZdRn1wOhCMfCgDreO/R+1Xc fU4UVMxv2Jn3C8nW2gixpzxbGpjZFrkBKV859GSDGvG9BPjKYAY4Ls37x6cwN4uk+Ed6 /VVAdToFEde7yyot8fhcQIzDOPmOyiEJBvPWWKSTFUQV5pmrtHH4GjYN+/fCIUU0Xlsq EcbQ== 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=NwXUao5fPiuRB2dzq6NZ4hhHKX7vwYCJevjTXUXfOjA=; fh=l4eJLtUn0SmHiKt99PWqHuWj2v8zKyPa4Rk+HEUnuU8=; b=J3rzP11gUvA8RAGOztcW1H4twUmBEGA+UpNZxQlhGtuIB0FPuZD1sqdCJ0zfnZM56Y +xHN1xV1CsB7DsqnOrgJYoDlXZMeWHZuMwJvnCBIsc3l8Ngad1QSpZ6clDnAj+BpeuW6 js6h7RYcU8oGWrTPVBPCcM2cmTiRc+bWYqS2XxqS8BN4kUZrUdlwli8tFqr6lOUplU3F 3m3gpNFtMX+ISjOyDjh04WuumVrBmw3abvloRTWVLi2YdOTgacwn0j7S2J2905YzLBKq 8AG1yyZ9x5pxjrcvPEztPSfCTg/ZhqA8waqgjV+ZUJPF7U/4aZlbR5bfWsu8CYVFb5lt wBfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=itKu4EMV; 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 b22-20020ac87fd6000000b003f72e877e5esi443670qtk.104.2023.06.30.06.25.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:25:58 -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=itKu4EMV; 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 1qFE4n-0007iy-Cc; Fri, 30 Jun 2023 09:22: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 1qFE4l-0007hP-Qm for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:15 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFE4k-0003RO-4F for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:15 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-31427ddd3fbso105346f8f.0 for ; Fri, 30 Jun 2023 06:22:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131332; x=1690723332; 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=NwXUao5fPiuRB2dzq6NZ4hhHKX7vwYCJevjTXUXfOjA=; b=itKu4EMVKahoT+E93KzdauxK55wwu4oLz0zFvoMNn5+ep63LvPey39LtQIxBikZf13 xs4VooEnBkqKSW00hceAEbyiHlonw6HRZ+cD2BSoUm5iAl2tlYTuRul9dDSReGd65irD 7fgbLiE+HQzA4dSJnPe1KYJgeQ2ymVbOXbVmPw30j4UtD78CdctsmYiVH0bbo1C9tHYk ggjq5PQrnTJuAi7S0ypeyMb1hltDSrju0LtAkLbnF8brljgONK5fo9rZvJQ8E+NBfntV 4miijhkM7vPqHZkw5jY9I0upLe6Rewr6bV4cNvY//KDfaDVyDLj4igOfOK7tWuHmGlyP cq9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131332; x=1690723332; 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=NwXUao5fPiuRB2dzq6NZ4hhHKX7vwYCJevjTXUXfOjA=; b=Cwj2D0ajAvpuvTaL14Ms4JA5PKVzhyBft+w3CtTiEC3RUk5euCzkERnp0WxgLNsuwd VvYiN4xXsIyF365FKNslr97pHhUuAf4qkJ+iRhUSRwfC0rfE9hZyJysPUSJsg+aA1enW J54fEJ7m9c2cBFoA259Eg6TTPrpMzvOwgoZaecPwB+4Afbs6O9FQvdjd8MdlRsJLFtEJ 39gECUH0AmHcXRFd0sPbdoVh3ORr0ysKJB+g1m05u0ZJNzppSgSYD9pwCyt26v0eDpky uzDz4Gx7tS/856/+f+ZICcwiUMbzw2qudlxZ6aBIYyWxqbfGqRAA8Jl7wId/ZoXaz/MX Dmow== X-Gm-Message-State: ABy/qLZOsJWMKKB6zknmgcj2fTBdlXtjwAzFZxqoxvNprJXvW3kCMdXV O3pi1lMsm2zxJxjoh1RNJkrS9JPhwJcOR+Avg6qvpA== X-Received: by 2002:adf:f20d:0:b0:313:e80b:2273 with SMTP id p13-20020adff20d000000b00313e80b2273mr2005791wro.46.1688131332583; Fri, 30 Jun 2023 06:22:12 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu, Warner Losh , Kyle Evans Subject: [PATCH 15/24] bsd-user: Use page_find_range_empty for mmap_find_vma_reserved Date: Fri, 30 Jun 2023 15:21:50 +0200 Message-Id: <20230630132159.376995-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42b.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 | 47 ++++++----------------------------------------- 1 file changed, 6 insertions(+), 41 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 07b5b8055e..0d06bd457d 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -222,50 +222,15 @@ 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, align); + 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, align); } - 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 Jun 30 13:21:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 697935 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp450073wrs; Fri, 30 Jun 2023 06:23:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlGt+h0C56n+eM/5YEZhakxTOi8fJ7IlCWHwrgq3JKxLG8oqFBY+cQcwDh1HKROdMkuXVWgy X-Received: by 2002:a05:6102:134f:b0:443:580a:4c45 with SMTP id j15-20020a056102134f00b00443580a4c45mr1538699vsl.2.1688131403646; Fri, 30 Jun 2023 06:23:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131403; cv=none; d=google.com; s=arc-20160816; b=ofxWOQTYIGNuKJq+G1bjkykhRoQP6rWmSkSEVvcuEQ1bmH5UHERM17KETRdYUQVr19 fEHXcQ5kMj2t4nOTt4B0XyJ/Aj9LAfsQodE4Iq42HnwIrt6/nxRcCkYnSCEgEXPy1sql YLn4vGYNIMtjTFbhtIJwTlQ6HPWFNBM8raCtcQ225pr1erWjZZAKa2SseBhe9PFWYids wd/qnBSUCarI5ZRT4AxJ36iRlx6DehVOF5QS7Kpd9jEe0TMJYGNcvoQGd60flMDGPSWV V21KWDPzFhZFQvyIMyJZ7P/rtRX+MUKlDydzAUDMaJ0YJnecchRsnzAv62/gYLm58mdL 1u5Q== 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=SsYj9hL3z8sJK1XITfZRh23Ewywzv/qozPGrxwSRr2s=; fh=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=MKovWyoYZvK4z/p4EQpqRTUk7gdBmhjqFF7qIIGxagwpg1KVXrdcikraXGJqYGhmzm /xZM3LJRJdpuY3OJ3gSnROBQiRt2JgLAvGAqG7heQGpk/AJF9OtoDINiDjg5Mvi2EhRo ydzjA/qcWBmqRIZqrtJzli43IQbtji3fBMXJ7xRaITadEHWagKNW5TihOGbbOmY2QAiR ZOfQnrKm4M0pXLhQj7Wz8azwNuUJXh1XMsLew+N0zG3J00wwfkq2SbbFK4r9OuLQlINN 7v5WZzPFk8T9/LBNftRQkz3jYP1ho4FjKyX2HRpK7py9F4lfXlygdV7JTBdUXJEooMW4 LXHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lC7T5t66; 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 ed8-20020ad44ea8000000b006301a766b90si7675991qvb.546.2023.06.30.06.23.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:23: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=lC7T5t66; 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 1qFE4o-0007jH-3x; Fri, 30 Jun 2023 09:22:18 -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 1qFE4m-0007i9-FF for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:16 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFE4k-0003Ra-N4 for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:16 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-31114b46d62so2093417f8f.3 for ; Fri, 30 Jun 2023 06:22:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131333; x=1690723333; 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=SsYj9hL3z8sJK1XITfZRh23Ewywzv/qozPGrxwSRr2s=; b=lC7T5t66amUHgCU5a+vmDTS+a5yMUBbarkPA4mt4ycVZCiADBN4EocdpToR0gYIeWS Q5Mm4tmUNf3KSVexWVt6Eol5vXAoM6PLMWSTxT12EWeWPIFynm5YSJkrHVxNW/q4P00l JNBrVR58ypJdLPBBR5BMLFV/eLQ7Edt4yUrphD3dO2v+KdcBKyIRTnRwDjXDCiy5BN0h EWdWBwL0JKkD3Tl7/DNoNTO44LyiqwSX4hO30O2WBL8fIov9bGixdbtKNNPZ31WbEANY SKkhZlnTakohQjaDzn/xTySkI//afyEo+CNv5Wr5HOCCp/KMwnkboc82Gg606Qal+G8e BzBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131333; x=1690723333; 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=SsYj9hL3z8sJK1XITfZRh23Ewywzv/qozPGrxwSRr2s=; b=N3uQnXjcl/UM2JF1HqpuPQeR7/mXFWNbVSLWvePJy6hdGs/KQ55+b6q6LbguK5XHQF OsHgr0K0mSNWYJYUF9+jXhF7ooXwWX9jY6RFt+unnMGHJa0OVLO0iqnYVaamnB9zNO+E lC9VK3KPw+83E+JS4o9uCmc5I8g61wOSVKznj5AW757bZ2VYCA1cygwmD8v9y2gFSvFJ Z0E+J6EaFA1bE80S9hEO+i9uvwBJYhzk2og09jx5tgFMIWeJmcnzqt6R+AB1K5o/DMcU nuEmQ0aKTfyqOcV9Rdd2le1FTKPWbXGkBeiFFS++tw9msmBKX8WVh1buTOtcL951/nZ1 inLQ== X-Gm-Message-State: ABy/qLbW4XJUaesOec9RwAv2VbEyUsrlGw421u+mepmIhirbAA2OYnhy KvhdJvQuqczVGfL4SutnbHGADBcGinKvm1YC6OTskw== X-Received: by 2002:a5d:5511:0:b0:313:f59c:95ec with SMTP id b17-20020a5d5511000000b00313f59c95ecmr2189079wrv.28.1688131333425; Fri, 30 Jun 2023 06:22:13 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 16/24] linux-user: Use page_find_range_empty for mmap_find_vma_reserved Date: Fri, 30 Jun 2023 15:21:51 +0200 Message-Id: <20230630132159.376995-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42b.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 | 46 ++++++---------------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index e332555dd2..6ecdf9e56d 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -317,49 +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; - if (start > reserved_va - size) { - /* Start at the top of the address space. */ - end_addr = ((reserved_va + 1 - 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. */ - addr = end_addr = ((reserved_va + 1 - 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 Jun 30 13:21: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: 697940 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp450378wrs; Fri, 30 Jun 2023 06:24:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6mXwON41LeKQWsZvIeX4mmB+miZiAemWW89vCG3MnzhDTzkTHrfOtmdjF9H7iLVZh9yC9A X-Received: by 2002:a05:620a:454c:b0:765:a84f:7860 with SMTP id u12-20020a05620a454c00b00765a84f7860mr3024139qkp.34.1688131442713; Fri, 30 Jun 2023 06:24:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131442; cv=none; d=google.com; s=arc-20160816; b=ZQxRzwhDPLNeWj/38K8WRb4PDOY6boWr9UH8hhNlkm9eJ8SC2+l2Ezrj8YWFWKATK2 kPKVyPMyzno6brIvJcSklzdA1TUQozS8QU9HM6TIkerKvgtAlU0pIkKZSKq1ivoi1y2q 1BjrESUrDpctaaYYC3Q2c1rMGFXH3XT8WbbiwYKBwTd2Fsm8SAV7LcUdSGeYQBK/xzOO KRRSWORanBbnwPdpaeQuLHpGVb34hWprwK5jT8r73wNhUqH9+63u8jSYPdmChTjVd61b eYb22nfKXpro1HSe+3cQG7fEnvzvjQEiMy0sozCQDSTpe8L3yczY5/RCX5hLpSKvprEd Fzhw== 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=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=WvBV4DEgQb/06HcFqMXyrLf1JpOdJndjSkq959w8g4/6hes/aKr0k2b9Wi10UQpm7b AYHyO9tg2fOShmUX/2MABeANd+vTS2gIF2+5JApr55qgPOf4tJfDcoYduihvUnTx9+NI oly7cqChcvGm+Kjq/9u3rIP/dy5pWG2I2eDWUqrZxZYJprmTEds57BUZSXOiV69fhK8u F6k7GXgKTS4jfB8meLXSVU+8xUroxsRDwQZ0/35mihfmmyTcYb/y2Yt9kBkZBdu/8SRS j3IHtDaamtCbC5WxCpgpBALuMkrGWpnPr+m2SkfmK1Fx6owbdx+CJxzZ8giPgVuDb83D cEzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D7l69K1+; 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 ot13-20020a05620a818d00b00765a58a72adsi6328979qkn.308.2023.06.30.06.24.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:24:02 -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=D7l69K1+; 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 1qFE4p-0007k9-9Z; Fri, 30 Jun 2023 09:22: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 1qFE4n-0007ix-8u for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:17 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFE4l-0003Rv-Dv for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:16 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-313fb7f0f80so2113400f8f.2 for ; Fri, 30 Jun 2023 06:22:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131334; x=1690723334; 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=D7l69K1+ZTYIs+OSnRT6DtN15GTw2j3btIYmxi0Hy/pF1JWWg9tOjW2uLO3XvrcZnU ZPP2hkeiTJ8UDKcPGeZlQEKMThXsVQ9QlBV/YGpewWeT80hf1Is0EjN2hgZUzkmlz4Y1 oX0ox8aJ348cJRQemdwmV83suQlzX7IqrNtR6+CNiA91iKHlYG/vA7eo6r5mDkUAjvkc /otyr94QBzc959cw9V4nQpEi11nf1dAUqtFsxFWn6QzgpyBbv2yLxvo7Z7XsnSgcLqh4 faVesiGPBkililgHpXhFMkMTiFhQdSluTemT/c/E6R7bHvJ82kdAqwffRLfPobzx7kMz QJ9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131334; x=1690723334; 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=QvgfJ3xr3Kk5K4mn50FwScoS1uHrF3iStekw46DkVOpBNbt4tgwJ9vDzBjAQFO/6z3 wGo6kXwF0paci6Xks7Bm39p+5exxGDV3rYxtSR74Yxc7hv76aR77RiH3ImeOYTObaXXR lPmEOrL/MewpZz8qlyON4hrxDYCYgzHkupVHzgdjaH0BNw9zDutAf3HLNhLDTxct0w8C MLtFbUl43OUzKLLOCIMJUKjrBWIWlpijx7Mi+araoSTC7LEbGNN9hK0NmzsIEZ/cbpm5 nWZlpn7Y6GoqhJ3+h5A8WXPH8g8+JLvfJ3QtmkProVUci3T0tY/zejfFbXtzsfLEJN99 yU9w== X-Gm-Message-State: ABy/qLbEOQUwRjg3qv21FUoObA5E2wYcB6BMEXclcVVRLL1l9iArCbLc TMlaFx5Z0yvvMYcw6lxlrgc9ffRWzQJ4mF//6fVgPg== X-Received: by 2002:a5d:46c5:0:b0:313:e12d:b245 with SMTP id g5-20020a5d46c5000000b00313e12db245mr1872483wrs.29.1688131334020; Fri, 30 Jun 2023 06:22:14 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 17/24] linux-user: Use 'last' instead of 'end' in target_mmap Date: Fri, 30 Jun 2023 15:21:52 +0200 Message-Id: <20230630132159.376995-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42b.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 --- 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 Jun 30 13:21: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: 697937 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp450157wrs; Fri, 30 Jun 2023 06:23:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlFAxidXa3JEAXC86U+4f3kWKUYk8/Kn0gVuKO1sepLt3HGc18NgYsm2nTtRg2VgaOexPWv2 X-Received: by 2002:ad4:5caf:0:b0:5e6:1bf5:1ae0 with SMTP id q15-20020ad45caf000000b005e61bf51ae0mr3625193qvh.18.1688131414845; Fri, 30 Jun 2023 06:23:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131414; cv=none; d=google.com; s=arc-20160816; b=AslkUYeLIiy2/QpMoBMxQyRno2+jRsLc+P2D96jp/O77MWnrTHA2zvfLGbP8RagGtD H2wdGR1fkTX/WSBq1D0C7pzG9lM2hSan0gAj5L75zPP3swN9K2NRbDrHLOOakJDy2Tp+ QC2DOswQyUJJ2qL4cqdoi2llK9LpiRUuTz7TV3lLJY0z07rr94Z0oAnoQabJ/qglUf87 D/eeD1q6juFeBFNfLWk8Arls+uOVxbNosu/2jotxlX+GXF7UzC585s3pxiUfzImKfPYv p7m8XM3MtSbNGubRHkiHJa3YmI1VaJRjatNOHT+xpVz5cz9kZraPZW+QZ9E62ofiWmCd pEIQ== 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=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=PQki3qoku8GhDoeB5DX3+PGfRbLsQ9FKfy80bnxpYmq0Jnw1mYW5q0Jeu9j3bUbjrF tAmslaT5bbFjnHzOiywmMaxwKAHK6DsYqh2R4tN/ZJcLCEdsuo06cx+ZMteUriTUv9J4 sfLJCyGgeB5xMVzQ4IsBHC2r8LHbIzAlm6UFXQ2UjxkWqgjPs4/ZxEZEBIBlOq8qGCml zHkce5vx5vW0wnthB7xIXJ/wDHTQPvCF4Edm4UfEHyK93KqI+hxPn266ancPGyfY/TRc L3TjPTcVdk582va663tLTObH/s5Bu96KeTPhnUgLN065JKDCrQ0O/ilqg+U5eFdPZTOn SJ+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="M/V2YWHO"; 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 11-20020ad45bab000000b0060f7b695034si7805225qvq.426.2023.06.30.06.23.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:23:34 -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="M/V2YWHO"; 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 1qFE4q-0007kt-0D; Fri, 30 Jun 2023 09:22:20 -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 1qFE4n-0007jG-Ua for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:17 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFE4m-0003S2-5X for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:17 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-313f1085ac2so2045194f8f.1 for ; Fri, 30 Jun 2023 06:22:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131334; x=1690723334; 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=M/V2YWHOcTzTeKzlm0waAJuXOJIJBUTVdf9Vu+Eszzes3ILpt/fKz6iQDUd4e+y4Zd Qy4Anq0XMDBsZQQwrq0GI+pq7awn/aC2iE/I7paf2ueOyVIK80bY2O6kzlY5aLJbXlcf dYvjwByWvVmJtxC7mv8+h/wrTs5vCjTCjCOwkZ5CneEZHCX9oP3RvdKuA58WtWZg+giV EYHG1g9u/6U9kcnZ6id4tbQPN5/lYMhRDVOvxFhNGtlIe2bMCJGh+YWikANduTTdcU0q FTBG7lPPaTPK2BXJu01bZ5fTwbidAHGDjfnauZuK+RiH5gbGG09QfcYCunQ5akX+PEFF 2a2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131334; x=1690723334; 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=kVUrkrriy7pOWtvq1nk8Z320Nv0qv5mEQKnioL70cDoHBww7aRppJ77BFgSdBI5iiV 8PXuq7xm7V8WNZN1CrMzOk/xshPIyJrZi/VxiYVjRW7oQyPcby+fZjkLaHJb1HapBAgQ 40YmreG8+ZjDR5Qi1E4oS3jwg+WRYb50Po8gaGyFmqh3hCwKkZrqGfpcUOfBmmjxqQpd nPwLldz8L060O0KtuKfrPVWIQHqMy63b6f92C9gEZwn2tA9RB0N8Kr/1gWa7A0WOLml0 wiul3NhzsXi/fZhe7Ra/JL9bqUDzvMzAHxf3qZ8Vet+3FJV/59NwV1qUEDLjIflvw3rL Vyag== X-Gm-Message-State: ABy/qLbtrpkNn8Dpduz0Jp600PXKcvNevk1Y6oXp50KTyq/nZVmMj7Kp LlMH3UTIP2eRGslRxqzVNuiy82r8h3oXHhtv+0LQIQ== X-Received: by 2002:a5d:58d8:0:b0:313:ee2e:dae1 with SMTP id o24-20020a5d58d8000000b00313ee2edae1mr2311431wrf.18.1688131334616; Fri, 30 Jun 2023 06:22:14 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 18/24] linux-user: Rewrite mmap_reserve Date: Fri, 30 Jun 2023 15:21:53 +0200 Message-Id: <20230630132159.376995-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42c.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 Jun 30 13:21: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: 697928 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp449594wrs; Fri, 30 Jun 2023 06:22:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlGX3CBr14D7eodYcDcIIQsnuNwRipglFwcpC6VLY7A/+0Rz1ndFSxLclSlOzKlXcGN2Cie7 X-Received: by 2002:a05:690c:d07:b0:576:f0d6:3d68 with SMTP id cn7-20020a05690c0d0700b00576f0d63d68mr1933748ywb.32.1688131352927; Fri, 30 Jun 2023 06:22:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131352; cv=none; d=google.com; s=arc-20160816; b=yR5iGWU0l3WL9aSXWdGG0fEX78puxdZwig92La+/HTd4eSs+xDi5un5mc5vljy8jE5 xRzRmcDyXI//eaBaQTQmsvjcwCDqKpRww2ExCMIWGTWNx8EyRGXvv+Xb/vyGTzi7Z3+K v8bFmeOvg1iMPjmQin3s1E5upxfcKXX+x4xmQ+Kp3gRm8YP2Ax4dFEv/he64PuoVmnD5 O7SW8m7LbGX5w0JOVJ3x1qCLR7oUQ6G9K36HeR+zaPO6BvJIFtw8HALm3StYDqnsOd9U 4IxQjCM1Cey4SplIlm7G8lTHmumqMQk5LuBC69YVCk8oPfjUxEFA3j3WjEMrRnXs2aPg /3EA== 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=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=TJBwVhG0/3nxZ+ovMVq9gf3Kr+JEhWUdgI9RFW6zUh0K3XSbhaLpi5SvkJpd6HDmGp SWuT4tXA1/fW5zveVKMpzrgxhRevRxE9jzX6mbgGIx1x5dBsDlhmU3PeffSYjN2sxGat pmciwzkOvjqAW9WWYwK154+Wzfx7RrCURnN2nEF5uwNfq12DX0BzCfFKuk9r5joxyTxB lGZifG1HZEX98BeKHCw93h4O/3gqADIh50UkBIkzPv9OkDYWFA4px5sW5V07t2oexCrz oQTzWthPKRYMBeuLXQIo5hSy7wR2RNl7fhaLx4YIVJ/b+uQdG0S81IdCpNRrGYiNs7hL Jxuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Bf9ReICQ; 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 b1-20020a05622a020100b004034999222fsi45463qtx.663.2023.06.30.06.22.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:22:32 -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=Bf9ReICQ; 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 1qFE4s-0007mu-Qi; Fri, 30 Jun 2023 09:22:22 -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 1qFE4p-0007jx-14 for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:19 -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 1qFE4n-0003ST-AC for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:18 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3fbc0981733so16661035e9.3 for ; Fri, 30 Jun 2023 06:22:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131336; x=1690723336; 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=Bf9ReICQepZmHlH27q33m7J8RebYRc2M5lM7V4u1l7+l2O1Kp/9SX3IVGixiMEXLfN x/q3zFe8/yQPHf6G04ektFlh8qwL5feJRETU/sDVUDpa/6/04xpaUVNI8qJ/O8eufd54 fy64p3g0M/u47sXQmDxwevFxxYkfcldGn1SSuCBklvSaciG9q9X1uMx3w8PHtNn8wGAs 9F4k1ia3RnT5ga9aobQJl+HDp5WuSjIGEpn+gxUKWTxBzyj19oLOIzHa8o12QPAP4FsS pUN5XdXiVdAO8+0Yt+MKeVgnbCfGveAH4NbSPDgV4pmk4CQGRTxHYPy2lihH0Wva5rYV pkng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131336; x=1690723336; 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=j5u3E+TqbmqEclzGxO8ezj6OolHeGu15mpgVIOLTpG892G2oUREFgIEPmeIIkz84cf silRQYBVHLgYexJ7L9Cime+hEZBq09+cmnAM+p99xuSEofcpqM4I/gaviwnrXqZ7/STU cZ9oDNfZlEBEli8CllPViwWK7qoT3oZ9x1LEzHXBr0VYH8Qe0OCX2og1w62asxPlar3i Oo8f0jrmDcpj19Yj2C0e3oYYM4rlRzgv36be60wrvprjdJNnSP7cQ+3/Q0FVwfyo3gK2 USzLMnSTHYDD0NyD5K8TpP0HL2Rw3Q9tKGy2hYUiSkXu1tOLs1l5Xv3j41zsat1L0yv2 yRtg== X-Gm-Message-State: AC+VfDyKlI+F74Gy+fbj2kwKnvqxACpwSWUf1YJI8FNgG6IT7YvN0l7F xyawnj3+lpZ9kzY4GLze0Gl4ZyCyznoCo1/wmY+dIQ== X-Received: by 2002:a7b:c8d1:0:b0:3fa:9554:fb23 with SMTP id f17-20020a7bc8d1000000b003fa9554fb23mr2192997wml.21.1688131335472; Fri, 30 Jun 2023 06:22:15 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 19/24] linux-user: Rename mmap_reserve to mmap_reserve_or_unmap Date: Fri, 30 Jun 2023 15:21:54 +0200 Message-Id: <20230630132159.376995-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-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 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 Jun 30 13:21:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 697951 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp453114wrs; Fri, 30 Jun 2023 06:28:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4IJDmurUiEW6Cryu65NxdsqdD8XFT56LfcnEbsUJSt5glqZ7qadYIZqLwKcSIqKm8MY95S X-Received: by 2002:a05:622a:1010:b0:3f9:efa3:9e6f with SMTP id d16-20020a05622a101000b003f9efa39e6fmr3335347qte.27.1688131734655; Fri, 30 Jun 2023 06:28:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131734; cv=none; d=google.com; s=arc-20160816; b=Ue0vBg/wyvhWNBdbaKhskfcEiYUOGxWYWqO1P1unrjUA2UDxTESE5Io7wcg7u7NaHw U9JjJIuat8HIQ9lZqFGgQkPYU76DxyxgbQBqn89aNKHZ4pN46pmpjeQZOm6O4bySqaEX z9DDWrbqPhowcrwChilI8sU+cGmNEpXwPUZzLvHhPJX+EAqs5PUY8Qs/8JNthHYL5QaA m7L9h94xYuXn1FMeQsFwNESOeY2m68BaF9cDlBbHekDMQyIZgVRgnRyVb34pieWGAnKk f+QwJu9rDsJyhCwlTR6uOQJlIk2e1gtLjQBAcg8SeYN7wqkeeMpx9TOIEQDgWfrfTB91 EkDQ== 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=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=mptRTV9ftX3dw5qoNNks9xiGuxjM44Xrg6YMycxRgJx1N7LEmDV3Mt6pT9DvoJAgH0 i+uDwXEP4YWXHucMnMVVOERBWGGvvCr5hX+Nwg1gwvdzvpo8cChjm+fbz7fx3BiwiW1w KWdQxbA3cawsaVxrzHSVsWxrMj3U2ewUjXqIoSRkfmrVFJAPXdNmS/gwc8seSZGFooLF ti8LVIgHZR6ZiE5F+HY1gSrW6/mCJaFMa41fTHf8POYZj7GavBUr9iwDnvAssIuWve9X clgZkX3N8Aq1yYu/6VzqBq+XwTOUqutFWMhU2DR25tvx7/QTfSKqLk3CRp/28zKIAETT PZQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sLqByRzW; 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 w9-20020ac857c9000000b003f530fda2cdsi6555724qta.62.2023.06.30.06.28.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:28:54 -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=sLqByRzW; 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 1qFE4r-0007ls-M3; Fri, 30 Jun 2023 09:22:21 -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 1qFE4p-0007ka-OR for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:19 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFE4o-0003Se-2X for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:19 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3141140f51bso2198784f8f.1 for ; Fri, 30 Jun 2023 06:22:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131336; x=1690723336; 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=sLqByRzW1MisrQ/5C+YhPStmF2R9/1DcNQTCTWqFjOSUR0xFI8rCF0bhS16piN0yF0 rZVWcl2TE7bxtr1tzxtG8ubEeBkecB8dRSKgrCya6o+dccTIugRtMwo8AT1FmkS4Birk RwCj2pzvm5ZaGVL/cT4GsAAU58dmvQ3UhfdIkpQbH7OJ4oGJMWXDjco4N/bTgTE000VG 4fW4AcKyMJ0kMSQ1+nZsx0DRcOwQCpyNhjbGDR6DqSjjA9be6y35n9xEv4+JYOsEVyg8 gEEQmOMRJDcM/KQR8Hlrq8yoBT/qesSKhd9jqevnyPRh0wnqlgmsBOEpi8FHgvbcifnM IxoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131336; x=1690723336; 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=UCwduGd1P1hSmhah+hFdBOtwbJtU9JjWI61JXKIqeo4V2lM9Fq5u4csm+Thwe4wGs7 Y2zO5nsz63Uh7uECWVYA6pbGPfLE9drDDNNj5R0teH7HoCruunjW4mllnaFBf0il5E9s gLTw1wRGKxVAzgYdjGYbJb9okBcrgMojk9nNYzMenvhDfxgb/am95FlGnJKI0JqQtNYw CTD5yaGSYoG5jlbINYFvWWbZG7xPe3lK5i3kHpTo4E4VIPhtzPBfpUXQGYD9pqar/6cC am8mY5W0KA8QrY1upz23iKHZkSBB+T288mWPtR8M0MkkvD4KdD7MbCpQP4i3go1MMYFp DIfg== X-Gm-Message-State: ABy/qLZ+oUhsKt07B2e05jWrLmsJ/Yik1L4fICCgPGZ2Bmq6gh2xRYVB BPzNa2VOmnsrUuKlQqa5DRK6oBe0tlZV8jMLCbX1OA== X-Received: by 2002:adf:d0c9:0:b0:30f:c1f5:e91e with SMTP id z9-20020adfd0c9000000b0030fc1f5e91emr2270169wrh.27.1688131336579; Fri, 30 Jun 2023 06:22:16 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 20/24] linux-user: Simplify target_munmap Date: Fri, 30 Jun 2023 15:21:55 +0200 Message-Id: <20230630132159.376995-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x429.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 Jun 30 13:21:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 697950 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp452566wrs; Fri, 30 Jun 2023 06:27:52 -0700 (PDT) X-Google-Smtp-Source: APBJJlE1WJhW/XSy+V7OY3njNMj1jmK9eq2KhtfZiYAeb9VEsA/hWW8v/M7ufW0YMbg5qvLp4w4s X-Received: by 2002:a05:6214:2427:b0:625:aa49:19f1 with SMTP id gy7-20020a056214242700b00625aa4919f1mr2848458qvb.62.1688131672252; Fri, 30 Jun 2023 06:27:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131672; cv=none; d=google.com; s=arc-20160816; b=UpNcT7d9zcLAgJtdpfCbRr5aTXGmvzloSaDWgL2kZYXLnbzV/pBj/fGO93vZRkn5SJ MufL/ZbDIH3RYu0qMYrqyYLUtJZ2Vs7wd938cgAEGSEqIpqGb3SvryFWQglRPzfY6c2I AQaOIRB+I1XcSTEjCEagns15zeYxrroCYqUypPxll/QD42oBMkf90x9X8Z5ZgQKZMsF8 2Nn+ML13OWS4fEKBbBDRRH45XWUs8uEpu+Y7ebzPaUo1lGB9/pmUPsOwzcDvsXmkAnod LZyfSkA7c01fsvlagalS/8t4eWygzmBaer8JNrQdrwKpnPU38mEFYI2FIuLGREZAyHkt kbWA== 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=gT4NK9p8wEYJPmQQBQUhLbzesb3JroSJqWwYF2RqsEw=; fh=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=nuOf0nImUW4qRCV45Z1mE4HnaJ/2GszUasHaalHwpui2GM+4HPVDC7Zi/yvDrdUGR8 lNbonXbkFCXaz/0B4fHH+VSp93ZJvYzzsHtjW/oxcLJQJu+qndYsuPtcI7z/ZwL5UAcw sES8hEKixNstNvjHLulsnZC5mQ4YiC7A/6p1l58pUjmAZJeb2luwloNK6+KldHYxTJN5 vxSdBjYPI0BGaK7PAd2m4S2oQfd6tSBpncB+qOIqGR9QeSlv48S+uUk+v7drr6wlIgi3 gt7FSMbabvPm8uj+svUKQ69j84G5IP5iimUii5E7l5s+6AYwqDOPuM2Qd89QQUqKTLiz dVXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IwSGEYbY; 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-20020a05621420e600b00626009daf2csi7908653qvk.543.2023.06.30.06.27.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:27:52 -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=IwSGEYbY; 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 1qFE4r-0007lX-8a; Fri, 30 Jun 2023 09:22:21 -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 1qFE4q-0007lP-JI for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:20 -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 1qFE4o-0003T4-UC for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:20 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-313df030ccaso2105397f8f.1 for ; Fri, 30 Jun 2023 06:22:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131337; x=1690723337; 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=gT4NK9p8wEYJPmQQBQUhLbzesb3JroSJqWwYF2RqsEw=; b=IwSGEYbYQtOu5yoCQo8Hgw4LQe/7+WK5hEzKTgXgC5Wtoc92rRvnIDJcFNs4PP26P4 bOqtRmJsFoUt60YLD8rVqhL2mBl2qJRvy2Sh9dPgvPFWuffJ1sirsTYaFQFnceSwH3g3 eUbGvLWV3EQmjDU4+YZG+GnOm90dp5PxXpJmeGGpRG+gPfgDLfbajYVNz9KzOHHpoD8e Cq/ksRjpAN2GKbReIpVuOxvszh5EdCPmgrvt0SgUkfUSXy82wOeoGowl3dUOIqo+p95i VfPSaDYpgsTkoX2xF+VKGyyeVeXQNj7aZqN+AMjd+Qm3RdWAHr64b2uwMldwlMWP1anl XzAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131337; x=1690723337; 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=gT4NK9p8wEYJPmQQBQUhLbzesb3JroSJqWwYF2RqsEw=; b=BgPOwZNLZr10lHeIj3P6jkgY2NuSQSjKmet8pDZFS8JIvNMDU533UXPokcR9Gpa7y0 1I/VFkZ/HoiaZlHHokNAu42xLOl09dFjw6zrXS2nXs2VmqAYeS8GgCyUqnqoh0DBZZgt OHDx5/YmefBJfNRFG8mgU9AiVJN+TRILkJMjZQPnRS9Pl5+hT2Lu9Q17C2MixJq3m6VM IrBnGSIN8lm3P7L879xHDR5hK/Wq5iYUUKGp4qOvuX1vsi5wcz2rbo7qeg/Trm/eBeJv 9zsiPQz78w+NCIbuNi21PCegTOjacgikdw3d3RLsGRV97AeIzuNR4rmouzjCTOnC0pp6 sayg== X-Gm-Message-State: ABy/qLYoEgZZQpOSxpJyggknrDUeL9tjXXaK764P9XO2LgN4GUl/99H5 8WkrVodcT1bYsd4S29DzilFUlUnbplmxE+X+y6UPBQ== X-Received: by 2002:a5d:45d0:0:b0:314:276e:30ce with SMTP id b16-20020a5d45d0000000b00314276e30cemr402000wrs.51.1688131337246; Fri, 30 Jun 2023 06:22:17 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 21/24] accel/tcg: Accept more page flags in page_check_range Date: Fri, 30 Jun 2023 15:21:56 +0200 Message-Id: <20230630132159.376995-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-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 --- 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 dee4931f86..7a36f95bbc 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 Jun 30 13:21:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 697947 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp452526wrs; Fri, 30 Jun 2023 06:27:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7c+mFGnbY7zPqZ4UNzVWYNgZR+TQY7ZkaC/aTwra/TmB6dzt+6f5vJ7EMrgvAH4kRj8j5l X-Received: by 2002:a05:6214:240b:b0:635:a1f5:5462 with SMTP id fv11-20020a056214240b00b00635a1f55462mr11081688qvb.7.1688131667548; Fri, 30 Jun 2023 06:27:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131667; cv=none; d=google.com; s=arc-20160816; b=N3aSFkIkX9BbTncbkciOFPqwetuldsmaPjtWLehwRdgmYPQra5zeJ6cWqJwavKHlP4 EXqNHwGXefF+X1s62675uL1E/tGfMcY8jZFkZ0Q4F7xUHRKKuG8YLctgftnQrXgTQgjk qQ+8dc533t3SusRuTdfBZS2jPKt8f7THQEoRHTe57F7xfkcTAgfeRxSrtlB7OYB3zQZT qscp778tJvn6sRdIeOt0TgUwgYBglmfAot6K7uDnGgSqLGcZFI6M+WZXAiW99OBbsVYy ackwHXGXpHNzjxrFOxSNlSif3e1OfKwIx2+XuMej5tWg1vlvEzfHOnGCKNDdYoPisWIa WA9w== 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=++INz+dFUs55GL3VAaeUx3Gl63IpijUdLO6j4ZH4eos=; fh=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=nFIoCvr5AZUC+tRatqYhNqysg8e8Bw61ikgnlV9X0jo93Nm6iO/kc7P+UpnQsFgkF7 UxK98KpKOARrVkhXVrP4xsIQRv89wKA7fMxl4vVi5W6xFRSkeDsFGHi2Z9DYA7NdE8Io Dmp3tAU30CVaLMX5l0RCRL63UiZn9YfWpX90wKciFbWnfuYb5MLU1t4SZxTzAYXGJnyx qJ+X6mwBxaxC8gi4jVjF3MzadO+sZA+Txl4SnorgL22n2R0BrfPQIOgrwtJ6Z8a6O6Zr 1sXnvR21TJrctOVQ1pFqjG2Rmyboe1RKQKftvyP9cPFcPWXyYS5wrVFCTsgIzeUgiv+Q VQdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Grea6odi; 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 im13-20020a056214246d00b0062ddaff2cf5si7997561qvb.464.2023.06.30.06.27.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:27:47 -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=Grea6odi; 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 1qFE4t-0007mx-8s; Fri, 30 Jun 2023 09:22: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 1qFE4r-0007m7-Tf for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:21 -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 1qFE4p-0003TG-U6 for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:21 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-3fbc54cab6fso10321735e9.0 for ; Fri, 30 Jun 2023 06:22:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131338; x=1690723338; 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=++INz+dFUs55GL3VAaeUx3Gl63IpijUdLO6j4ZH4eos=; b=Grea6odi9qnObGoYGEW/BYKs0ekEzV0ADjYu1zYuRYZTGN0+vgqRU7zjoBIAyuqHTe xd86JC6yLI9LZMmI8ixmAO6e7Atmdh/96Wvj0vqnHAulABdx5jIx9xiMaAkmImhsHGYL lCYywVnTLvqmDLp8jiyfZnB4cQVV6FCy8mW7oxGQwa43qNHQZwLX9l8e5wDpMH4/q057 WNun7nXKgOpd9YK62WHZDYkmGM4/gGh0QcFNrmqHBSQTrtQ9qWzhZ9tsfqyT5BlbHLzF H6mKCiJzn5pdjdyf3wv5hnrP4pIngzTAcCBgzvglyrnt5JYzEQMYyf6busOS9KhtIIDZ KY8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131338; x=1690723338; 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=++INz+dFUs55GL3VAaeUx3Gl63IpijUdLO6j4ZH4eos=; b=aVR/21xpD4K72o+vq0wr1rt9Oy5iVPDpwgNQpFSKhTWF1SExDzU//QRBUiZoxoTIsR g5ektQo5nP+zf4k5kQpbXfr/1wLkFj2sPL/0jKMv/PEVpmlALuqnhFR7aC5IQgjOuHse oRPQGW8fWt6FsYxf7gIatUfGb5fUPM3Woy8DVwPSDuw+D1iK2N2X+TpSIwTJYRYpz/jr nhhlywLRnsKve4UtqbfpGftq3AYosQWWuXrfsM0Dt+pi0tNqSMjZ3OF2XiqD4Pdr0liJ /aVmV+YOGaWjIKtB7Vt7jBYCkCaZ9NgVhn9qXuUYIeKzVo6ga/Yx0QHrvh8VDqgkF/Ux 5kqw== X-Gm-Message-State: ABy/qLYAz6fx1HYEBOg8OlTbItBi20yn0FXuOYMCdf8p1DvkvX431RjV HQ2OYaRjA11AxvglrbKEvGpJup4GKMNOIumROT1Vmg== X-Received: by 2002:adf:ea91:0:b0:313:f457:6c59 with SMTP id s17-20020adfea91000000b00313f4576c59mr2645853wrm.44.1688131338370; Fri, 30 Jun 2023 06:22:18 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 22/24] accel/tcg: Return bool from page_check_range Date: Fri, 30 Jun 2023 15:21:57 +0200 Message-Id: <20230630132159.376995-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-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 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 e2195c7e3d..30ce44fd90 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 92f9f5af41..a6e8f0f9f6 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -179,7 +179,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 7a36f95bbc..107a8cda61 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 94cb4ad8fb..384dc5a5fe 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8076,7 +8076,7 @@ static int open_self_maps(CPUArchState *cpu_env, int fd) 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 Jun 30 13:21:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 697943 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp450900wrs; Fri, 30 Jun 2023 06:24:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6eKCuBHZO0/ULoPlCTmuVyr+NdHkh71VsOHcidhO34w9bp4n+Ngcv0xQThALgHypyfFcW7 X-Received: by 2002:ac8:5a93:0:b0:3f6:a888:5152 with SMTP id c19-20020ac85a93000000b003f6a8885152mr2385466qtc.38.1688131497617; Fri, 30 Jun 2023 06:24:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131497; cv=none; d=google.com; s=arc-20160816; b=qa0+G2dQvHPgZLk9Yk9Ch4LDW/cDtlVX69LjBlPNzsE4uqFg3u/9ZWh6FgAI3xiw97 Bps+R1IVXze8Jo2MJHsiuW6HNO+4RupEMR5uFNRMmit9RJcSM9zTJRFm3E3fCffzAjbx KPHzkKfGpHoYUs2PYL7G8rU/feDewX10bCP7v5NFQikk3tBQS3JstJTB5tZg37VsVwYV FaAKOemJGZHr1zbWxYe1BGRyYaJmYVOplfxgEG8UVVlFs/SaZC7DlQl7VBOe4YW4rNfA Zs9CHlPm2iaVa6psa6+qSjhjtM07TkaephXXesxi801yhn5r30shdXVUmHFSu0Zlbrpj AZyQ== 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=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=DE1UVwJOAXkt6JxCI4yCdZEWq+91xYRF36cNIgkBxd9DLb9sVY7LjKrEWRO8jbjKMv kaOlABj/hNr+CXXsuf8OseU9HQ76fOxKl8gHNIDdvklu8xY+0/wDlWEo0b/RMBLKO76Z nvgt6njChpFf0OtsACjfHwLSq8HKvsgtZ5rI1rOBwfJCuvnXSvIR75t4uhefj3Bgy81Z WbuDD/O6Dipc5TM9RKaA3o7PBTdg10L1Ne+35ll/H7owsD4DIQyGHZkAq7N5Sh+vgqUx 5IMaElLNadMPhYpTwxwLnCIxk8Sua4OM1h5Wk7akzGeKOhrvQPaD5hRSShW8M86XFCGJ FIGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="IQc/4aLO"; 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 v20-20020a05622a131400b003f4041f0059si5561577qtk.521.2023.06.30.06.24.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:24:57 -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="IQc/4aLO"; 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 1qFE4t-0007nN-TC; Fri, 30 Jun 2023 09:22: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 1qFE4s-0007mD-1O for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:22 -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 1qFE4q-0003TO-EF for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:21 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-3112f5ab0b1so2061328f8f.0 for ; Fri, 30 Jun 2023 06:22:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131339; x=1690723339; 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=IQc/4aLOMArBLv54JuARcDL8HB95+V5k+cLwQXmCpW8vNZAfMqs8sCcpu0ZXEBAyqI RIgrEYYbtbeY6CP4A4Lvtju/DYCIsu2fqY3cZjwYUvZMzE/0+H2Pwe+dBrXCyPxEucHr 3oSqtBiz6Z2U7UvpGQpGDjSlQ5+0K86nMQsgP7hw3D4meFEj56VOxcs33XUduhflP5Hf xMLiFk335BKzFIXCVv5jSPqk46lpBDvMnUwV+HGFPEfdmnhT19ERsHdGrw2GLeTO6b9Y 6/+g1sVt1Gte9BFsv+8N0bX/YmxvpBRUDq49xi1KUSsYalaz6LZeEz+z0EygaRUW/+ry ZU8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131339; x=1690723339; 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=lLqtORaxEzs9SDx/hXOo3bK5z+etjCV0IPj9vgMMTetdlTBJ/RA5PUXKSnd+bq4DKP ZG5vSgWK/xAXr2esUP2jirrZJ8E12ho6q8aqGS3H8wes5Ehibq/YaREzMemGimqhOxBI 2JYJB92PuceTDb9sbgZMw5rt/VjM0N6/6fY8fPxXRFWdcvuq8YhAggqJO0HrytLHQFF+ xRKhP2P+6J6Gq/sU7YqBPE6X8J2BudpmPqtEwwDVUf3hZyOZoeYvCCTS6rDUq/uzBCT4 cy88/j5uZyYrcjjkXLhn0ilmFEyOwK0W4vYRyulwyojp+UHWgECaTDWz2bKtlteN6IB+ Sn3w== X-Gm-Message-State: ABy/qLYQNmw2+blV1i+9WGvhjKy2XGPwEnF6e7GxXypsgJ16K6wyPW5C s1n8urNmKBE76jFsItwNkDlIgp0HYnxUze2KScE8DQ== X-Received: by 2002:adf:cf07:0:b0:313:f4ff:30e9 with SMTP id o7-20020adfcf07000000b00313f4ff30e9mr2451156wrj.53.1688131339131; Fri, 30 Jun 2023 06:22:19 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 23/24] linux-user: Remove can_passthrough_madvise Date: Fri, 30 Jun 2023 15:21:58 +0200 Message-Id: <20230630132159.376995-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-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 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 Jun 30 13:21:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 697949 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp452552wrs; Fri, 30 Jun 2023 06:27:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ62dgnI68prc6GdfB8gVIGAOiF7bwAGTuBI5TGgb5eKlokAsa78jfgU/Tl+AQ/N0IdqQGMJ X-Received: by 2002:a05:620a:4444:b0:763:a20c:fe8b with SMTP id w4-20020a05620a444400b00763a20cfe8bmr2949378qkp.13.1688131670814; Fri, 30 Jun 2023 06:27:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131670; cv=none; d=google.com; s=arc-20160816; b=NbGxFsFEL7WXTUDkdVMya2wfPRTARJbRAqZ0AQwsnD3K+u8JcMAZBBCEhWkEt8Frmw Xd9FYnw2UM2LB50XXEVEraGR3ZkDuWowu0SauupTTdWhvMwbCF8DybDBkPxxLRkIfk7a XGKb+6Fudj2YBnVgqe2G1HMcIvU2phAJrTaNPPyGgSzdYp0wOp5pYe71xnVTrFxpXX/H GX+fLOehXf2Jh8gNerpUlCXoSmq4C69CIBKojj5+e7EGCNgBT+eBpVnBtBn95cMxJeeF E8j4OlnImGKiaRc4g1GHjaZJ1GXMYldEKUX+/MV1WGtao8RZXxN4j6owgvmvI3lA8wYq IpDQ== 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=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=b6Bn8+LgWSjKQmjvnWSf7rnjvWCvACr6fuqhr6Jp/2kmwVAH1D/2KeocdfUCuJgzMD Rck4Ebby69KHQkoa5Dha76w7XUVNhHzy/QuF9WOX6US6b6aSKfCJl/6UTwH3Ze+XE0VG n2gZTeHQj32oi1UaYi26J6CrCNT0G3rKxxhEVeLtjSKIk3IMrRColTbLG3Sblsdb6QwT 7fOcoc2qMnpYd5Ss3yN+bXnkuMV1lZMaXio3XjXYOmJW0sVYLiR92OeezwDwY/Ncr1L7 EnpRQQYLZvj/sNn1pxZO1/YixmS+nS9H53lTdJ0DdrGTazk4nC6UjkB3sZP/6nQkWMll iMhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aPWJJYTD; 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 sk5-20020a05620a3a4500b00766fecc24d2si5691803qkn.738.2023.06.30.06.27.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:27:50 -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=aPWJJYTD; 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 1qFE4u-0007nb-Gd; Fri, 30 Jun 2023 09:22: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 1qFE4t-0007mw-7m for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:23 -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 1qFE4r-0003Tg-LS for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:22 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3fbc0981756so15777065e9.0 for ; Fri, 30 Jun 2023 06:22:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131340; x=1690723340; 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=aPWJJYTDVb+bOYKUampNV2/ZoJuhbiy0/+zrnbUuZVeVLBBWiI08WYiIu/vXpFXxV9 TLe8S/z0bXnZMA3vcRfu9vblijiTkezFSYQPfkpJlL1duThX15SzXGygnF4YXB2ZZVXO kTRfX2cQo9NhqCnrYqCRDCMtnF+V+4epJhgfwZTX++uFcqXVz6XRse5zF9Te67iY9YTR rug90C9Oh2O1/S7GI7ADv7+AMLRXtNZUJAxWsBgfJm8hIKjwyDPz6QDQexFlSRjRbBZY nOQX3d4ks7fJtJUAtxBMVIRO07FbScfwhp2ZL6rkRal++NOwFDMCF632F1A06xNSZz8Q +RFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131340; x=1690723340; 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=JhvYzbVD+JnFKwWspmHwfrMMrqnOJvcS5MdOjHrmSohUWIziF3KvZCteKRTq+2WWl/ +tpDLUG2exoEOPY0PvKIQhNbKGZ7zaTKWYw0BIlq8ccIKGcMRs7aBqF2i69NOvyp8Boj 0xnzKqvcCZX3GxanlpmCznf9mS6z4+HyeUxTHtMqN3SnlUI7LP8TMpRQxOcxFywQskvf NJBauK0VPFq2r1NCigNIQhj1CT5oub5WTu7c/rhSlnv5DLHgUp/719LshJr2L9vKxdlM sWYAGrFhUvX8I5cDKaH2u6aYi4R/dlbjMC6/DQILfjV0GGueRnK1rEKOCwt8Qc6uFquw 4fzA== X-Gm-Message-State: ABy/qLaTvTk0K7f5Q1WCgekKhvc/xZweaZ3qsSClSbkeRotBe8sGV9qg utEuSZNufJZLg6cioatPUY70uOQbWB8XaP8CydBN3w== X-Received: by 2002:adf:f14a:0:b0:314:96f:bb81 with SMTP id y10-20020adff14a000000b00314096fbb81mr2040446wro.22.1688131339825; Fri, 30 Jun 2023 06:22:19 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 24/24] linux-user: Simplify target_madvise Date: Fri, 30 Jun 2023 15:21:59 +0200 Message-Id: <20230630132159.376995-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-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, 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; }