From patchwork Fri Jul 7 20:40:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700054 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4066049wrs; Fri, 7 Jul 2023 13:44:20 -0700 (PDT) X-Google-Smtp-Source: APBJJlHjiCdniUIZ7xQNOUav+WRYYrPx13FhQskpTCOnIXc+ydgPbExLKM/upMlzNDg1fRMfCsx9 X-Received: by 2002:a05:6358:27aa:b0:133:e1e:f0b5 with SMTP id l42-20020a05635827aa00b001330e1ef0b5mr6286815rwb.12.1688762659865; Fri, 07 Jul 2023 13:44:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688762659; cv=none; d=google.com; s=arc-20160816; b=jZUMyCuIreEwh+AiSg9Suow7AcD4kSffqwZwQ14vRwyqG2dtQAXZNoKYoeaAlBKEmY io2YqoHKiDsi4xdbFCml/2jDZIDKlQdHOao9YIheeEX3z5uqiWt3FdR6ck75jav0WeWg Dee2gcqdMl8ZsdDeodhP8KsEd+uktqNpxX2G878tTDL6bWAzCX0F9cbkCL1imSbaPsBO UbLHEr6qRRXNosgKu7IUkufEx6inp98YDjl+uWcKRbe+Uu7rkjDmcQOfp5TxiT/X+Z1M X5IfoK2Btmd2Wss3bdeaQlr6C7kfd+BJXDpnlk3nWPcloVNOlkuiA8yRDJmAwwBk9XU+ EDxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=s3pB3AzQ33HXE3XP6riFkr6cxMvSqstuDeeeDRipPQQ=; fh=jVqwU2n6uDjg7kXqsBiuuwMdTrtXxwX52l5dkNb4FWE=; b=BjlLWh53rgyN+7yUKgDQBk0vaXajSlfPdytBtOy30k7IzLv3zdVvC3u696sTlROVPD z4s01B0Jx1R5AEgXW1uehUIP6lUxLlb5TkItRgMCMAn++9NH2KN4AcnLAsJwmUUp0s6+ XJGH5YtEIDA31wkVxql3EnzcwhmsyKHwjbOvVRig1UjqI+Xk7fOuKDZyX7wHqNRrkgwg y6cS5tOaC7fWhE0iV7t5P2WQcG8y4GzK0sUbzz5euLwnK1T6WBWIXqspR0sa6Gqj4nmO uAKosOS/5vdVineTgFqxQkSl6xRoyMD0XyliFHTO0sRncBbH+JaAJ/xTqO4JAF8D1DgY Ieaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SWom5Nru; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j5-20020a0c9cc5000000b006369bcd178asi3130742qvf.485.2023.07.07.13.44.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 13:44:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SWom5Nru; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHsGb-0004zW-PD; Fri, 07 Jul 2023 16:41:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qHsGS-0004r8-2Q for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:17 -0400 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHsGP-0004uK-Si for qemu-devel@nongnu.org; Fri, 07 Jul 2023 16:41:15 -0400 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-4f9fdb0ef35so3843884e87.0 for ; Fri, 07 Jul 2023 13:41:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688762472; x=1691354472; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=s3pB3AzQ33HXE3XP6riFkr6cxMvSqstuDeeeDRipPQQ=; b=SWom5NruSHwBYfIZXY4JlRIa5yxfyLXmkW7YSt54qa/GuoEyDxm631i4lGmsY/UwcJ a02Zm/B0IUzTk1MnHtPIISPzrh1m6qLjPQf2sX/7DHtFSBKtGLChRLn65lB26oNuyuuy 2t95Ki7+kyG9sXoYcMKYZwdTwkz98olBNJuDPHGHdBchvHsj5RtFEBZxMx/0X6NbZnsn p/2zEg8fHzR8uiKu8S/4Taw+tz4A80CfmXigOrKmD0CJ1YN1ZmC9Kma+oacAFS3Rlmfn roodu7HFwAqcHnLZ64j6rG5BYetynn67OottrcnUKLx7ULbB5uYo8teuXuFr85Zb4HdM +1AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688762472; x=1691354472; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s3pB3AzQ33HXE3XP6riFkr6cxMvSqstuDeeeDRipPQQ=; b=glBIEQxL60g5vQkqZ8WJcREfDnfhF+NsH8B2kTwOTQQ4+BWy+33WjUkL/MlFOT4PTe /7WZabCsljUos++iUqtrsukTxQRRd7hJMNxXaN8kLffEIlskjJFzX8/aEzvsaDtyzXxe maaCqcw5lMR3QwbOk+x7Amts+c1Xx66pA+8Z7dIum+tYrQe2LZ6e11VklC1a8QAuvECe ElaGqGc/Yqh0QKkwiqqobAKtdWS4bpZPn4Oy841jaxWcMngA6rb6j9L7MiH3pG7uGbYR BBajW6Nzi6GzcL5/kwszoBD50dF2r1jS8Bi4rbA9gQyiA+az5hqSE4xGTohhzSY/1bHL c4aA== X-Gm-Message-State: ABy/qLZJqXUTNA1V8EPFa6qDvIt7zWWCqN+1uwWmyNmAHpcDVfC5g8XY tvlb0Rsn2hViCaKmntGhVeUJcuNS3WyQH11SDMx7+w== X-Received: by 2002:a05:6512:3292:b0:4f7:55e4:4665 with SMTP id p18-20020a056512329200b004f755e44665mr4198859lfe.56.1688762472227; Fri, 07 Jul 2023 13:41:12 -0700 (PDT) Received: from localhost.localdomain (host-92-23-208-66.as13285.net. [92.23.208.66]) by smtp.gmail.com with ESMTPSA id q10-20020a1ce90a000000b003fbb25da65bsm3337736wmc.30.2023.07.07.13.41.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 13:41:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, mjt@tls.msk.ru Subject: [PATCH v2 23/24] linux-user: Remove can_passthrough_madvise Date: Fri, 7 Jul 2023 21:40:53 +0100 Message-Id: <20230707204054.8792-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707204054.8792-1-richard.henderson@linaro.org> References: <20230707204054.8792-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::129; envelope-from=richard.henderson@linaro.org; helo=mail-lf1-x129.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Use page_check_range instead, which uses the interval tree instead of checking each page individually. Signed-off-by: Richard Henderson --- linux-user/mmap.c | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index e6463ecd8d..a2bef1ebe6 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -898,23 +898,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, return new_addr; } -static bool can_passthrough_madvise(abi_ulong start, abi_ulong end) -{ - ulong addr; - - if ((start | end) & ~qemu_host_page_mask) { - return false; - } - - for (addr = start; addr < end; addr += TARGET_PAGE_SIZE) { - if (!(page_get_flags(addr) & PAGE_PASSTHROUGH)) { - return false; - } - } - - return true; -} - abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice) { abi_ulong len, end; @@ -964,9 +947,8 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice) * * A straight passthrough for those may not be safe because qemu sometimes * turns private file-backed mappings into anonymous mappings. - * can_passthrough_madvise() helps to check if a passthrough is possible by - * comparing mappings that are known to have the same semantics in the host - * and the guest. In this case passthrough is safe. + * If all guest pages have PAGE_PASSTHROUGH set, mappings have the + * same semantics for the host as for the guest. * * We pass through MADV_WIPEONFORK and MADV_KEEPONFORK if possible and * return failure if not. @@ -984,7 +966,7 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice) ret = -EINVAL; /* fall through */ case MADV_DONTNEED: - if (can_passthrough_madvise(start, end)) { + if (page_check_range(start, len, PAGE_PASSTHROUGH)) { ret = get_errno(madvise(g2h_untagged(start), len, advice)); if ((advice == MADV_DONTNEED) && (ret == 0)) { page_reset_target_data(start, start + len - 1);