From patchwork Sun Jul 9 18:29:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700880 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4828390wrs; Sun, 9 Jul 2023 11:35:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlG3L2XT5tl6j+EQzEfYrBxaZ6Vf0FSTqkIF+hor3FnzCJat2LPeqDfM4bO8IhgnDC+b2OUH X-Received: by 2002:a05:620a:4611:b0:767:494f:4ab5 with SMTP id br17-20020a05620a461100b00767494f4ab5mr11762951qkb.39.1688927737435; Sun, 09 Jul 2023 11:35:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688927737; cv=none; d=google.com; s=arc-20160816; b=QhXhX02Lj8MQXqmGoKMA2zqlu/OUI2AxjmFXKGQK4di446j0bZeakVZSItFzIIaMOe scnnuIR0F0D+62yUUe4Uka9oQqlGnakaqPxmDc5HMuwf9dtQb0JSgERFt4g0yHGd3yIi VUaxiv+wFS08QDq7zQW4wQC6aaZGmiF16Hv1rV8+mc+gZzzOMswQ2AcGiC1q7uH7JruG Q8xVc9NDLp77xihZVz84Y4CeyYVeE9d7vhk3lACk+QmsDeCE5poa5u4mto6FzX0izaAF H5xHjT/TVldjmiO4Azj+MBmw/xcIwEg03jyDvh2vnpK1TpvYd4D0A5Y8NqrexOSspFrw 4lYA== 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=ZRHsYp/A8D0Uk3Tfg/o0B0POYY0J/63KdYiHo0geXzY=; fh=4nfr0hkxlMpWE4oToQ1q4rzQVecv6te3cGVRc3YFjiI=; b=mbBwN3cWtrqEcFkmv8BfNoX+/gOYJoFEu2e5wDtsOD4TKiEhFhmuZjuu1wPKb6babL THiuV0prSt34BdgoTPU3zVAk3eb0uJiz/TCMSccMdJ9S5sg+gIzxmbMiryweBgm9/xN9 Equ6TuGxCi+2xJRYC+NpBQWnbHEliLIbzOLQehu4VxVcWTymw5Vx4SKBMmPkYKU+tC9p AW3l3ErQm1dJ1AclyYgte4/nBmta0qVakhTXnuq3sbJjIR1dqOjmErZna6+HVKFbXUq6 ynzQr+TQKZwLQ4O9HPnPw+gQnm05PIZHOpFnU4nFFm3UBzjjV+xOMcTA6iCHr8LgL77w oFYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mMoCMklI; 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 d26-20020a05620a137a00b0076541ed7f95si4778561qkl.9.2023.07.09.11.35.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 11:35:37 -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=mMoCMklI; 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 1qIZEG-0005TN-7z; Sun, 09 Jul 2023 14:33:52 -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 1qIZEA-0004eg-Sd for qemu-devel@nongnu.org; Sun, 09 Jul 2023 14:33:46 -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 1qIZE8-0004K5-KE for qemu-devel@nongnu.org; Sun, 09 Jul 2023 14:33:46 -0400 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-307d20548adso3709569f8f.0 for ; Sun, 09 Jul 2023 11:33:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688927623; x=1691519623; 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=ZRHsYp/A8D0Uk3Tfg/o0B0POYY0J/63KdYiHo0geXzY=; b=mMoCMklIrOEVeo9gSyyjnpyAee6Tn3Zwd9lMS9f0NVqSbhQDLo1leNcYaVy7ES37TE nPFQBH4wuDkHZYxvdqd0SBNj6p0UdH3PMc9yZpnK5iLY+pRnzOYxlqXrJwyrBgiPjmmE u+f/CxM4aqDoL/CpjNbiBgP/R20At12TaKz6etgSGb5XaHwWU3bSx/oJJWH29NmElfvU nfp9j/J1E1PZXS5kzjl8cYiRg8xh1bRwqUmTxllDd3h3DxukZSIO0i6auuhvtPw3FYso QVB110MhdNSafXl9Q8/ghLixOfjO6MGimStFCZwGxiqihZvZiaBfLFCLpg20GK+vBZb3 UQAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688927623; x=1691519623; 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=ZRHsYp/A8D0Uk3Tfg/o0B0POYY0J/63KdYiHo0geXzY=; b=l8E5NL4S/vnxF98Bg0sEURmqp/gSd5QHfm4WaZ+qYLQ3M+OWlq4fFAKV5RJy4mS6Nd gz5kevU8/TJyO4xjXDExad5DZ2QbnlAW1B+GDT8zrOGK38fSwDg1Mfu7XIlMMgm3YdGr 89L5Sp8LvfUXbvwiBjorJV3O0wIPsJGilsUtwso5otX7ZozP6qX8nNTD0z9Upvibnd0+ UDxm2HjjyqP2xF6xLLGllFEK2Y7IM8Tt+xiCVAOSHS2gVhmP1QFTVZ3Yp5tKn8IEe/hl D8GYcbb9MwJ0yQu24hQuq/FH9nvoNiCPX/A2j7DRa8UMK1OBv3vN3Ap3baRKayJYzsjC ryfg== X-Gm-Message-State: ABy/qLaQ9aFKxlJhvivmnEBAZiArkeKnLZYjTTJt7nXe/B2XqLH+pS76 OrD6/QHm/4lFW7Sy4PSFpES+0cik5BCi5Q3SEkyvhg== X-Received: by 2002:a5d:5109:0:b0:314:dc0:73f1 with SMTP id s9-20020a5d5109000000b003140dc073f1mr8442169wrt.38.1688927623387; Sun, 09 Jul 2023 11:33:43 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id e17-20020a5d4e91000000b0031433760a92sm9635256wru.115.2023.07.09.11.33.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 11:33:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu Subject: [PATCH 42/45] linux-user: Remove can_passthrough_madvise Date: Sun, 9 Jul 2023 19:29:31 +0100 Message-Id: <20230709182934.309468-80-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709182934.309468-1-richard.henderson@linaro.org> References: <20230709182934.309468-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 Use page_check_range instead, which uses the interval tree instead of checking each page individually. Signed-off-by: Richard Henderson Message-Id: <20230707204054.8792-26-richard.henderson@linaro.org> --- 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 c0946322fb..49cfa873e0 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);