From patchwork Wed Mar 22 15:07: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: 665902 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp203775wrt; Wed, 22 Mar 2023 08:09:18 -0700 (PDT) X-Google-Smtp-Source: AK7set+Vowgb0TjwSNv4Zpe+zrz5hr6hFT5ilvg367nwWtcm6zS47+pMon8XAhksNPuHf8H4ZmMf X-Received: by 2002:a05:622a:1748:b0:3c0:1010:8d4a with SMTP id l8-20020a05622a174800b003c010108d4amr4763964qtk.1.1679497758117; Wed, 22 Mar 2023 08:09:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679497758; cv=none; d=google.com; s=arc-20160816; b=DwJf0Vo+GdJ313G3rY99eJsOmRp2ALEAp/kx3aVUf+Hrt1IDQ72Oo5SdJLY+QVeGHS higeQPeGtwF3/HPruRXB05WFJ7HPK84nQn9MRfqBQihK0CPPlLZ6VK+L99P0wxb2HEEY T72CD9+hKbaImOp7gTFWZrt+YCvGI3p1SbrvGH3i5HyWs1iO49VGpeIIhU1nEcH5cCCs ZG9PXbd2t5Sb0N/YDyBi/v+QJVNhJcIqPa087534aBpP2GR8g0pTvxvXuJzEjdFZcoQP IlohsGtD7BoPjCRhPakWxRth03I/UC9dy0sPhha5u0fgiEsROOw9+PaBoj72LavvFAby y+Hw== 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=fml4Pm46/jWkyRSlZ3NNbqY5RtzmzqQcXM/tCMICWQU=; b=PhBsgRMSNKQskGC2DSzTP4dCwiAIo3Zy2zeJ68pXhQI/grSozp4BxBHBRU66nYcTVe is8uMDE9u9ZVItMxn/Usu/yXLpXmpt+MEFNMcdbZnxuneC2pXXKA7r0RDk2Y49S0lxZV eTCqcuNI/InpEnPoaBhvBTqY2RihHJynYs/OsvfU+92PqoAyqEErRqpXduSa8z50l/2R SIVbsOcYKPjdmbFS8vY7exOQWuJzL6QS9JSFGyjtJOlEPJYd7LbAc6x4Sr/ldcWpp4bV oirA11DvG2NrYQE1PBskd2NkFfq30w3BNz3R4hh7ih3hZnRphCuzsZ3KBONfjlvdXcL5 EDzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vUUrDkVh; 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 v6-20020a05622a188600b003e38b50d3dbsi1282643qtc.277.2023.03.22.08.09.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 22 Mar 2023 08:09: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=vUUrDkVh; 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 1pf04d-0003IG-A9; Wed, 22 Mar 2023 11:08: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 1pf04H-0002xt-Ls for qemu-devel@nongnu.org; Wed, 22 Mar 2023 11:08:02 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pf04B-0007JH-J3 for qemu-devel@nongnu.org; Wed, 22 Mar 2023 11:07:56 -0400 Received: by mail-pl1-x634.google.com with SMTP id c18so19536671ple.11 for ; Wed, 22 Mar 2023 08:07:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679497674; 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=fml4Pm46/jWkyRSlZ3NNbqY5RtzmzqQcXM/tCMICWQU=; b=vUUrDkVhbiDvd1uNkVlGrN+9kqArX90/d9k4NCt/q+/fGZAl5hRx69OVOflrDaHGrL oHxG2fJtoPwwzq//ghL03rFu7lW6INyNNp95AiLMnwZ4cUZw0xy01buGf5pjkJU1bde2 9UCzxGm+zYvr7smXozlrn7tq7VC1qIGeWpe/NoeiIDsjgMohLCjUILH+sR6zVtKBZy7i n6iBQAD87XiR+dd69/lNJlBcMAxdT2huoKNyEySmjOQ0ghGw3hJnrLYoFHBnCNgswyNu KpvDlbq/BQVss/OznQ5Mc3ZzmYrXvkou+AAExv486xkOYN+d2m4CHD6XZ67C0MnS8rox gwTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679497674; 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=fml4Pm46/jWkyRSlZ3NNbqY5RtzmzqQcXM/tCMICWQU=; b=Fu32AguO4hJM0rUhiYZDm3vyqLGSoA5sLd9rc7gr1ABdO+oW1lOj1wG1i5xI4zQJRl RGnId7kGmp5ewwdm+X7Dx1lfx+ywvgxj5ymq5tWO2htTuCoBWfcX7kSz32wyNjFQShgm OeY+81cWqUa48t6nN6IGlF6KfKyqFTich/HQdiSJ0ZCbxyMltYC1h9EmktFXdcOgKCf5 JMvFrM1efmZWVeB37ngj8PNgPO9bZbLdtX+knzXf3knGAhbwBKIvyVqlXlx0tKO7DG44 ltUMIhwXpwpHADQUXIeoj6KWqH1W/BEhs+1MOUkPL986CWoutUfTkJ1K6J2/VdkeKu9w qKEQ== X-Gm-Message-State: AAQBX9fVoHlZB4tXb1BFf/aH2GL9Bdcje48XiCX7EQ0vqnHQSY/ZcNpT pkWPygCi9Dq1cB42U6vkbP5b/M2E4GpZ6033Qy0= X-Received: by 2002:a17:903:2345:b0:19a:59d1:389e with SMTP id c5-20020a170903234500b0019a59d1389emr2718562plh.23.1679497674323; Wed, 22 Mar 2023 08:07:54 -0700 (PDT) Received: from stoup.. (24-113-166-229.wavecable.com. [24.113.166.229]) by smtp.gmail.com with ESMTPSA id 17-20020a170902ee5100b0019339f3368asm10757555plo.3.2023.03.22.08.07.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 08:07:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: cota@braap.org, peter.maydell@linaro.org, =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= Subject: [PATCH for-8.0 06/11] accel/tcg: Pass last not end to page_reset_target_data Date: Wed, 22 Mar 2023 08:07:39 -0700 Message-Id: <20230322150744.175010-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230322150744.175010-1-richard.henderson@linaro.org> References: <20230322150744.175010-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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 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 Pass the address of the last byte to be changed, rather than the first address past the last byte. This avoids overflow when the last page of the address space is involved. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- include/exec/cpu-all.h | 2 +- accel/tcg/user-exec.c | 11 +++++------ linux-user/mmap.c | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index be99cd3621..090922e4a8 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -286,7 +286,7 @@ 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 end); +void page_reset_target_data(target_ulong start, target_ulong last); int page_check_range(target_ulong start, target_ulong len, int flags); /** diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 035f8096b2..20b6fc2f6e 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -508,7 +508,7 @@ void page_set_flags(target_ulong start, target_ulong last, int flags) } if (!flags || reset) { - page_reset_target_data(start, last + 1); + page_reset_target_data(start, last); inval_tb |= pageflags_unset(start, last); } if (flags) { @@ -814,15 +814,14 @@ typedef struct TargetPageDataNode { static IntervalTreeRoot targetdata_root; -void page_reset_target_data(target_ulong start, target_ulong end) +void page_reset_target_data(target_ulong start, target_ulong last) { IntervalTreeNode *n, *next; - target_ulong last; assert_memory_lock(); - start = start & TARGET_PAGE_MASK; - last = TARGET_PAGE_ALIGN(end) - 1; + start &= TARGET_PAGE_MASK; + last |= ~TARGET_PAGE_MASK; for (n = interval_tree_iter_first(&targetdata_root, start, last), next = n ? interval_tree_iter_next(n, start, last) : NULL; @@ -885,7 +884,7 @@ void *page_get_target_data(target_ulong address) return t->data[(page - region) >> TARGET_PAGE_BITS]; } #else -void page_reset_target_data(target_ulong start, target_ulong end) { } +void page_reset_target_data(target_ulong start, target_ulong last) { } #endif /* TARGET_PAGE_DATA_SIZE */ /* The softmmu versions of these helpers are in cputlb.c. */ diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 9c70f51d97..0aa8ae7356 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -946,7 +946,7 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice) if (can_passthrough_madvise(start, end)) { ret = get_errno(madvise(g2h_untagged(start), len, advice)); if ((advice == MADV_DONTNEED) && (ret == 0)) { - page_reset_target_data(start, start + len); + page_reset_target_data(start, start + len - 1); } } }