From patchwork Mon Mar 6 02:12: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: 659233 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp1598731wrb; Sun, 5 Mar 2023 18:14:41 -0800 (PST) X-Google-Smtp-Source: AK7set/2LbWdl3zRAaJ1cRymgisgUt4BT4/RWVeTDukf6suWBJrdDX5uKe77oK3gZpNIcI9i3CmG X-Received: by 2002:a05:6214:5289:b0:571:7da:eb56 with SMTP id kj9-20020a056214528900b0057107daeb56mr13820669qvb.5.1678068881189; Sun, 05 Mar 2023 18:14:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678068881; cv=none; d=google.com; s=arc-20160816; b=vLJPot5rkNAChbnhoUH71X/1mRbOUjzGIQMFbaXhk64QSjlf5gluYZZH7eADL1EBMD 2Pwq05uX8R9wETvc5pWrUAOiI6UgpLVvYm8G1gaWZKaIFtoP+e3HJJzDHcHwu08mbmxl 0fGbuNOxnjlqrYIm+oV92CFUVqQyThGJXgv2J2T450luTLXHjxROc73Ym6KdMbS+fW8p dgBDKmtrl5Ro4gp/Vi8rjdqW4KD0IZPbJAJKzedh2RYr+vLe9HXgdavJpIgA+AyDSPFu srp3//n6XFdVsKXwdfitD27i+Sp+/lyppSd1o6C76MFwiI+N2dWzZzhnR5NZ9kue64np LNXA== 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:to:from :dkim-signature; bh=Ady9NqbXl1TpoUN6B9C30ttWlGK5vJamM2lGeKTFSb8=; b=yJ7g/aa/1FZppCFtXhIH5QoUJ8ORj1bKxVYnq1Dgv+udAbIervw+foUQZESWC1M3Ah 7jJbTYniA0miLiucFLioYqY8o1dcLMsFiIsudcb3UKIJ7rTLr1N5JYZZ3myfCHIyDlgF 19i0Yyp/6WOsaK2U6kD5qll7fIY+kcTyKf1Bc0C6SoILic/hxLytrXA/wqRF/x9ehgN6 wmx9mZzwgf+20Iz/oaOqrCkgfq14fDjRzxr8DW1HNE2WgNjugI/ceUpdcGOTYU+YLF7R RGGgvAl4bJjqSMqtUR5mKwnLzzq9SBayEDMlKBZHyM2uua2LszwPkiiNlb9oIYQM4RRI nlog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="pJr/lKqc"; 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 br38-20020a05620a462600b00742adba1ecesi6774425qkb.507.2023.03.05.18.14.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 05 Mar 2023 18:14:41 -0800 (PST) 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="pJr/lKqc"; 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 1pZ0Li-0003EN-D9; Sun, 05 Mar 2023 21:13:14 -0500 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 1pZ0Lg-0003Dq-Mu for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:12 -0500 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pZ0Lf-000606-6v for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:12 -0500 Received: by mail-pg1-x52a.google.com with SMTP id q23so4629574pgt.7 for ; Sun, 05 Mar 2023 18:13:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678068789; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Ady9NqbXl1TpoUN6B9C30ttWlGK5vJamM2lGeKTFSb8=; b=pJr/lKqc+axnjxicbWBuYHrR/GJDNBUQM71S/dgLNVsOflmAU2RDypLqa2c1W1fLH1 qQcCz9uzYPLDgay4U97n6hMNdz0F7twONfI1O2NgHRyOpRFM4miJkN1+4IL62PNDRt2v m7rFkWzB64KHW1VvjIN0VqwXcwf6hG0AyiTUxwYcInlOgAedR2l7Oos+TlkQVOZnJNZc nI8ENTSz7qGL8xkjOF+giYOQWp9jZKAY9B6o9YekLDuwneiI4EdBUGiSy9qRHlM31878 ge9CtJNWg/5BeemlL+FI6I+E3o3fkny+B+AzVPXW4n5aFp52xUZhujKaxKsLe3eX9Nik IGew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678068789; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ady9NqbXl1TpoUN6B9C30ttWlGK5vJamM2lGeKTFSb8=; b=GxKtjRecosZTVDF8DuxouBzkocDpR2VX64dyqGmBmUlVak1ZbQWPqo2UmYG32E4eXt 7+Q8N3D7M7mOHu5fPx7uU3O/P5/OL8HKGTeNxReVY8sMhBpUhNJHjxOac+ytHshUiBuC YbWKU615cSGed5j6KI2t4AJEb1rGuSfvKCBMxX9jLutOLMpPl7adm4zgbuy2bVYh2Inv NPJqtC1DkLL9zNBxHkRgfaOhLPvaacZvtKQvCC0JuboZgeokmvZaJ+jVO8GqMUMQGY5d I9VU22BG726Qk4W+uoYE1A3EghOoymg4LkGsra3ncuC3SdosDo13bIPcMaQbNo3bDluX jr1Q== X-Gm-Message-State: AO0yUKUDLIThyf/zKiaifa+X5PtAkJ3y8tNOZoQ+iUIeKUGNMytzI2gd 3b5gDfBjdAoTH7rQ4jCHUNxLx+cnz6RS7vYoR+EV0A== X-Received: by 2002:a62:1814:0:b0:5ef:6f18:9d55 with SMTP id 20-20020a621814000000b005ef6f189d55mr8221628pfy.28.1678068789480; Sun, 05 Mar 2023 18:13:09 -0800 (PST) Received: from stoup.. ([2602:ae:154a:9f01:87cc:49bb:2900:c08b]) by smtp.gmail.com with ESMTPSA id d18-20020a630e12000000b005030136314dsm5048434pgl.71.2023.03.05.18.13.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 18:13:09 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 1/9] linux-user: Diagnose incorrect -R size Date: Sun, 5 Mar 2023 18:12:59 -0800 Message-Id: <20230306021307.1879483-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306021307.1879483-1-richard.henderson@linaro.org> References: <20230306021307.1879483-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52a.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 Zero is the value for 'off', and should not be used with -R. We have been enforcing host page alignment for the non-R fallback of MAX_RESERVED_VA, but failing to enforce for -R. Signed-off-by: Richard Henderson --- linux-user/main.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/linux-user/main.c b/linux-user/main.c index 4ff30ff980..f4dea25242 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -395,6 +395,16 @@ static void handle_arg_reserved_va(const char *arg) fprintf(stderr, "Unrecognised -R size suffix '%s'\n", p); exit(EXIT_FAILURE); } + if (reserved_va == 0) { + fprintf(stderr, "Invalid -R size value 0\n"); + exit(EXIT_FAILURE); + } + /* Must be aligned with the host page size as it is used with mmap. */ + if (reserved_va & qemu_host_page_mask) { + fprintf(stderr, "Invalid -R size value %lu: must be aligned mod %lu\n", + reserved_va, qemu_host_page_size); + exit(EXIT_FAILURE); + } } static void handle_arg_singlestep(const char *arg) From patchwork Mon Mar 6 02:13:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 659231 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp1598680wrb; Sun, 5 Mar 2023 18:14:29 -0800 (PST) X-Google-Smtp-Source: AK7set8M1m8CzuKtKwXA4yAm1MgMfp06HFJeNEwdLkG1WZ0uJ631RH+0Qq6EW44fv2qhleGF+Hqb X-Received: by 2002:ac8:7f06:0:b0:3b9:a3c5:dae9 with SMTP id f6-20020ac87f06000000b003b9a3c5dae9mr14704169qtk.48.1678068869105; Sun, 05 Mar 2023 18:14:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678068869; cv=none; d=google.com; s=arc-20160816; b=b+WZgZ3j3/XxV5vWZu06ZaDa8W9UBOBx+33hlMThCJsbTObQ8seTy3ngm/LYd6nR4h pUVOZit1aJBQIf1RNZ8+s1WqidVAmvKcO1NJ4i91heUr+JUAC2DxQWW2RG+Yg/EuB61z rgz8GnP8ERXLfIJHzpUdRE20TBce4L5wZw2zUVG+SrTrhd7itJzBsw6VfZ/0DUq+mzvP 67HwJqERBJM37lLjwTzcmoIK4B16FvNfjsifbI7AvZKAcaILeEj7DgLArhkE7WnZr5Xw hsCBZrAIC82UcXOP2sojJDkIsa8i/NBWGK5TXfaVyJfG6KoSQoJaT3B4macOBp1lffRy qx2Q== 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:to:from :dkim-signature; bh=U6sNLD8XHJNiSXrFn1QLQM94uDPxds/0DDVitXItwws=; b=Liw4zLGADOuP0PkbVgO+kNtNu6lDTScDsMWq49Otk2LdzXrf6QvweiEZNd3IbqQify rly1igH1a7xOfflCr9r+5iFWVi5kcEYzpRbgfFw4ma2yO48eQ+tVvZGnOxZT5A+bPQeB R+mP2eDJLmOik3xpzo7JHq8utjo96X+LDqVN0mWTex0kwvBuR/CjXh3pmOfI9P7BpeT9 HOFqbQUvetjiZHddMOwTj3pc66tQPvCHBu8UBlpWh3jn/fY2OM8nCqVdJyahVIv5lnpp 3GMejRH+5yS/HhhhpxwXEidAFDKPNHQbJqsEHwFdSG+cSBn3Mk/lYwAHvbhA5vTiZW+1 Oxpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GXbui6B0; 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 c2-20020ac87d82000000b003ba1d7c216fsi6785221qtd.381.2023.03.05.18.14.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 05 Mar 2023 18:14:29 -0800 (PST) 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=GXbui6B0; 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 1pZ0Li-0003EO-ML; Sun, 05 Mar 2023 21:13:14 -0500 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 1pZ0Lh-0003Dz-9O for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:13 -0500 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pZ0Lf-00060k-O2 for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:13 -0500 Received: by mail-pj1-x1029.google.com with SMTP id h17-20020a17090aea9100b0023739b10792so7532141pjz.1 for ; Sun, 05 Mar 2023 18:13:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678068790; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=U6sNLD8XHJNiSXrFn1QLQM94uDPxds/0DDVitXItwws=; b=GXbui6B0Ff5augnmFC3SJ9MST6JBFnwBZcnR2OMqZyGPTbgnw/yxKLkNacspnPb4f2 mdPGLpD5GcIUr/NjZSzRs3LTgoykIb3eIvMFiCOFW35tx6/6b+IEQizZZGrF3BnyweoW itBm7FpeczYhSvzgF2IYTn9X/kPpymIVI581GNB3e05HWBAh5REZk7x1rQEC2lqC6uMc ma3b9xLg0T2zGdBeLPhBu7mXRBVNtaEZs7HaFMjBj2Y6kfM69b3jWzwnBzOQN88o0l9w Y+jcw1DsCb1YoJvNVqAWkB2cFrffNXtqQUwhpvNIUQUWfafFyX6ozb/tPp2YiYgGTTwX xuIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678068790; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U6sNLD8XHJNiSXrFn1QLQM94uDPxds/0DDVitXItwws=; b=F397NXeZq8iz1ncczA6/Y+sNbAhMa78CvjWvrd+fgxbasXK4tPxyTpHgZZ6fkkWXLN wfy82gO3Z5VObRu4Xd5nZ6/L0H5srTgo5tWr2/zWVIgRaI6ls+BgAWaUAqzyiHhNRms1 jWEt5PTPW0SQ4Ajel3MUmnRdfyfgN+D9aO6MRBfKQMAQis0ZoprDj2j5Dt6WDBJVhzCu F5LDU83Qr7lUTYUMrn1jNjASdwCdnfHR+uC8LvIz9a019YPNn/W6Bl9u4qG3matx6mGx 7eB4iZEAoxkJRKRyOh2y3T34/c/Ru19OFxxFY72vVJiDjLoSyYgnsXw+txqgHCncZuyg JQoA== X-Gm-Message-State: AO0yUKWsQEtMojfz0HYQBBW9VIHObLyCdwilFRJJUC/qBWKmFTCE0i37 a/Dwp+zmZxOiHpXFVzt3ipkC6xwFvWV8ErHswljDuw== X-Received: by 2002:a05:6a20:8f27:b0:cc:65c3:c8cb with SMTP id b39-20020a056a208f2700b000cc65c3c8cbmr10653059pzk.42.1678068790318; Sun, 05 Mar 2023 18:13:10 -0800 (PST) Received: from stoup.. ([2602:ae:154a:9f01:87cc:49bb:2900:c08b]) by smtp.gmail.com with ESMTPSA id d18-20020a630e12000000b005030136314dsm5048434pgl.71.2023.03.05.18.13.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 18:13:09 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 2/9] linux-user: Rename max_reserved_va in main Date: Sun, 5 Mar 2023 18:13:00 -0800 Message-Id: <20230306021307.1879483-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306021307.1879483-1-richard.henderson@linaro.org> References: <20230306021307.1879483-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.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 Rename to local_max_va, to avoid a conflict with the next patch. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- linux-user/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index f4dea25242..5fcaddffc2 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -680,7 +680,7 @@ int main(int argc, char **argv, char **envp) int i; int ret; int execfd; - unsigned long max_reserved_va; + unsigned long local_max_va; bool preserve_argv0; error_init(argv[0]); @@ -786,9 +786,9 @@ int main(int argc, char **argv, char **envp) * still try it, if directed by the command-line option, but * not by default. */ - max_reserved_va = MAX_RESERVED_VA(cpu); + local_max_va = MAX_RESERVED_VA(cpu); if (reserved_va != 0) { - if (max_reserved_va && reserved_va > max_reserved_va) { + if (local_max_va && reserved_va > local_max_va) { fprintf(stderr, "Reserved virtual address too big\n"); exit(EXIT_FAILURE); } @@ -797,7 +797,7 @@ int main(int argc, char **argv, char **envp) * reserved_va must be aligned with the host page size * as it is used with mmap() */ - reserved_va = max_reserved_va & qemu_host_page_mask; + reserved_va = local_max_va & qemu_host_page_mask; } { From patchwork Mon Mar 6 02:13:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 659230 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp1598662wrb; Sun, 5 Mar 2023 18:14:24 -0800 (PST) X-Google-Smtp-Source: AK7set8cU0Swc9WEc8ZbCYLwAYUrnRdV+zXL1h1zxsf/YyS9gAKOk4ycWXqwAO1orfAuEdSJqnY8 X-Received: by 2002:a05:6214:262b:b0:56e:92a8:e18e with SMTP id gv11-20020a056214262b00b0056e92a8e18emr18133839qvb.31.1678068864116; Sun, 05 Mar 2023 18:14:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678068864; cv=none; d=google.com; s=arc-20160816; b=rCpYiuJwkmikTeV1qndTxqs23rfx7eJn/ZhvEkvjxYItLaCQyLLqCi+RbbOGsTNQJH w/RSG90NXwvsHnTZGzF7GgOk5vPNAAyKFW4mQ1UrLBsRnTB8zH4A6XA8ojOpIUkYaMTf 5DXLuWsgGLDr033vVJhC8cpP9mFti7bDwrjtpkIuugbXGZv/m9LnTl78CiDBwTvW/w80 iUIvoMUPJhwZT8fXKMtdlu8/b4goelMVLO0QNdFZDoDlHae7mOakO4urSXONh2w3q8Ut HgA9d20sOLJugu6Ov8I0KyAP2Ncfr9HjIY7OdK4HLke9pOGZRt5Ic1KFgfsenw2oizNU k5VA== 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:to:from :dkim-signature; bh=QlRIa4mqF+/zPLE6gRuo0J3urdHypr+y4L2ws8MEG1I=; b=fQap1uJDn6LBFBt+Rk+sxOV/rSw2Im3m+c5WQfTr/nrkU/t8SaES6JNoDbvNWWuaf7 P89q/0JHYxvX3t7VgLoRyk8NdBUl1aG3rXwxJUrDhPCMnp6J0JF9RW9e7SYK1uv6GWbG uuLzH0kmv6o02/9tezYoSM5C6FdIN/NkcIP7TeutKRXbfDsfgFA/yJAwVc/veqexbiZY Mi8//AFbsFpJ9cUvXcyp5EeuEmwrRVVZCt1rFRNkD5I76R/8CSJEhYgF0ytsgyutFU6m oGhOd5fGjz+8XgKSPgMSUL8ICLy/7JPymH/zuVet9avq8JnX+ZZLYPnhqj3LNtsufx9n CxtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="DE+/LtxL"; 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 h5-20020a0cf405000000b004c703352c1asi6107072qvl.372.2023.03.05.18.14.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 05 Mar 2023 18:14:24 -0800 (PST) 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="DE+/LtxL"; 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 1pZ0Ll-0003Fc-3y; Sun, 05 Mar 2023 21:13:17 -0500 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 1pZ0Lj-0003Et-Jc for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:15 -0500 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pZ0Lg-00061U-TO for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:15 -0500 Received: by mail-pl1-x635.google.com with SMTP id a9so8649052plh.11 for ; Sun, 05 Mar 2023 18:13:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678068791; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=QlRIa4mqF+/zPLE6gRuo0J3urdHypr+y4L2ws8MEG1I=; b=DE+/LtxL0NKgA/930lO6R64pIzUZyw83exoB+6WMuhyEph6kr+fKLqVV8Dmbf6Rpv8 5hnyTkxX5+Hg+OANZBg6iezo4Ss4/ilqXmw7Ky1BZG8jWBXfXjnXUBaFZb1ydxzq3JMU wBAe/y0Z264FR9QoNJSxy83aXv9R7Yyyg4BmQZ7FGYIIR0/hngC/nLrMeRwxz2Cgxlx2 ZktLbvCpyKZJhLRDxUPfph7nFwODFx7B+W7yHeIKaEcttbWcZgm1oJU43S8zqSyvF5uI qpz1AAdgFDQZLtYcWucu3YsGMYZoDjipLa94E8w6RNJ69/sxWAhGLWcaMgixXQ2sN8aa U2qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678068791; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QlRIa4mqF+/zPLE6gRuo0J3urdHypr+y4L2ws8MEG1I=; b=1OQmqxpCuHl37AnFD+OYnmF5Dt5zLU2XV3Tu2zFhM42KqG9RSOJiMDOeE6saG/feM7 IvSwO+IBdkV3wPNLNANrGZy162v1NcamQ4Uy9U48DXtZL4db/+OwYim+PhhA9csPBKXH nQ0oiN16sE6kCb2GfI+NZEMoBcmvFTmK4RCT5yJ2qm9Sts8w6/exSEmVMkzihOSmA0kz EwS8zxjMCA/W3nYwqompBePeoPeRhjdDG9JDRTTwx5EqUbPkDbsjTnm9kBng8FST4jpR o4DLK0D6RvnjDk4CCGysHO8EXpv4tMFJOS0f9++U2gDOlBBb2zMM6xXS8hgl9VJBHyF2 j+LA== X-Gm-Message-State: AO0yUKVZmYvdb5GjqJtnZfRRaf2cerenqCrGfH3nyGTXZqnGjRWy/Aq8 fkxpCic1cOw50x41vs4ZoYW5T5sVjGGNJgzToumdtw== X-Received: by 2002:a17:902:cec1:b0:19e:ab29:1ec2 with SMTP id d1-20020a170902cec100b0019eab291ec2mr6640894plg.65.1678068791255; Sun, 05 Mar 2023 18:13:11 -0800 (PST) Received: from stoup.. ([2602:ae:154a:9f01:87cc:49bb:2900:c08b]) by smtp.gmail.com with ESMTPSA id d18-20020a630e12000000b005030136314dsm5048434pgl.71.2023.03.05.18.13.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 18:13:10 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 3/9] include/exec: Replace reserved_va with max_reserved_va Date: Sun, 5 Mar 2023 18:13:01 -0800 Message-Id: <20230306021307.1879483-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306021307.1879483-1-richard.henderson@linaro.org> References: <20230306021307.1879483-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.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 In addition to the rename, change the semantics to be the last byte of the guest va, rather than the following byte. This avoids some overflow conditions. Signed-off-by: Richard Henderson --- include/exec/cpu-all.h | 15 ++++++++++++--- linux-user/arm/target_cpu.h | 2 +- bsd-user/main.c | 18 +++++++----------- bsd-user/mmap.c | 12 ++++++------ bsd-user/signal.c | 4 ++-- linux-user/elfload.c | 36 ++++++++++++++++++------------------ linux-user/main.c | 36 ++++++++++++++++-------------------- linux-user/mmap.c | 20 ++++++++++---------- linux-user/signal.c | 4 ++-- target/arm/cpu.c | 2 +- 10 files changed, 75 insertions(+), 74 deletions(-) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index 2eb1176538..7ef6b9a94d 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -152,12 +152,21 @@ static inline void tswap64s(uint64_t *s) */ extern uintptr_t guest_base; extern bool have_guest_base; -extern unsigned long reserved_va; + +/* + * If non-zero, the guest virtual address space is a contiguous subset + * of the host virtual address space, i.e. '-R reserved-va' is in effect + * either from the command-line or by default. The value is the last + * byte of the guest address space e.g. UINT32_MAX. + * + * If zero, the host and guest virtual address spaces are intermingled. + */ +extern unsigned long max_reserved_va; /* * Limit the guest addresses as best we can. * - * When not using -R reserved_va, we cannot really limit the guest + * When not using -R , we cannot really limit the guest * to less address space than the host. For 32-bit guests, this * acts as a sanity check that we're not giving the guest an address * that it cannot even represent. For 64-bit guests... the address @@ -171,7 +180,7 @@ extern unsigned long reserved_va; #define GUEST_ADDR_MAX_ \ ((MIN_CONST(TARGET_VIRT_ADDR_SPACE_BITS, TARGET_ABI_BITS) <= 32) ? \ UINT32_MAX : ~0ul) -#define GUEST_ADDR_MAX (reserved_va ? reserved_va - 1 : GUEST_ADDR_MAX_) +#define GUEST_ADDR_MAX (max_reserved_va ? : GUEST_ADDR_MAX_) #else diff --git a/linux-user/arm/target_cpu.h b/linux-user/arm/target_cpu.h index 89ba274cfc..f6383a7cd1 100644 --- a/linux-user/arm/target_cpu.h +++ b/linux-user/arm/target_cpu.h @@ -30,7 +30,7 @@ static inline unsigned long arm_max_reserved_va(CPUState *cs) * the high addresses. Restrict linux-user to the * cached write-back RAM in the system map. */ - return 0x80000000ul; + return 0x7ffffffful; } else { /* * We need to be able to map the commpage. diff --git a/bsd-user/main.c b/bsd-user/main.c index 41290e16f9..de413bd1d2 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -67,16 +67,12 @@ bool have_guest_base; # if HOST_LONG_BITS > TARGET_VIRT_ADDR_SPACE_BITS # if TARGET_VIRT_ADDR_SPACE_BITS == 32 && \ (TARGET_LONG_BITS == 32 || defined(TARGET_ABI32)) -/* - * There are a number of places where we assign reserved_va to a variable - * of type abi_ulong and expect it to fit. Avoid the last page. - */ -# define MAX_RESERVED_VA (0xfffffffful & TARGET_PAGE_MASK) +# define MAX_RESERVED_VA 0xfffffffful # else -# define MAX_RESERVED_VA (1ul << TARGET_VIRT_ADDR_SPACE_BITS) +# define MAX_RESERVED_VA ((1ul << TARGET_VIRT_ADDR_SPACE_BITS) - 1) # endif # else -# define MAX_RESERVED_VA 0 +# define MAX_RESERVED_VA (-1ul) # endif #endif @@ -86,9 +82,9 @@ bool have_guest_base; * if directed by the command-line option, but not by default. */ #if HOST_LONG_BITS == 64 && TARGET_VIRT_ADDR_SPACE_BITS <= 32 -unsigned long reserved_va = MAX_RESERVED_VA; +unsigned long max_reserved_va = MAX_RESERVED_VA; #else -unsigned long reserved_va; +unsigned long max_reserved_va; #endif static const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX; @@ -464,8 +460,8 @@ int main(int argc, char **argv) target_environ = envlist_to_environ(envlist, NULL); envlist_free(envlist); - if (reserved_va) { - mmap_next_start = reserved_va; + if (max_reserved_va) { + mmap_next_start = max_reserved_va; } { diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index d6c5a344c9..e9a330d599 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -227,14 +227,14 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size, int prot; int looped = 0; - if (size > reserved_va) { + if (size > max_reserved_va) { return (abi_ulong)-1; } size = HOST_PAGE_ALIGN(size) + alignment; end_addr = start + size; - if (end_addr > reserved_va) { - end_addr = reserved_va; + if (end_addr > max_reserved_va) { + end_addr = max_reserved_va + 1; } addr = end_addr - qemu_host_page_size; @@ -243,7 +243,7 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size, if (looped) { return (abi_ulong)-1; } - end_addr = reserved_va; + end_addr = max_reserved_va + 1; addr = end_addr - qemu_host_page_size; looped = 1; continue; @@ -291,7 +291,7 @@ static abi_ulong mmap_find_vma_aligned(abi_ulong start, abi_ulong size, size = HOST_PAGE_ALIGN(size); - if (reserved_va) { + if (max_reserved_va) { return mmap_find_vma_reserved(start, size, (alignment != 0 ? 1 << alignment : 0)); } @@ -759,7 +759,7 @@ int target_munmap(abi_ulong start, abi_ulong len) ret = 0; /* unmap what we can */ if (real_start < real_end) { - if (reserved_va) { + if (max_reserved_va) { mmap_reserve(real_start, real_end - real_start); } else { ret = munmap(g2h_untagged(real_start), real_end - real_start); diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 58a5386395..be12568f6c 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -492,7 +492,7 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) /* * Convert forcefully to guest address space: addresses outside - * reserved_va are still valid to report via SEGV_MAPERR. + * max_reserved_va are still valid to report via SEGV_MAPERR. */ guest_addr = h2g_nocheck(host_addr); @@ -512,7 +512,7 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) } /* - * With reserved_va, the whole address space is PROT_NONE, + * With max_reserved_va, the whole address space is PROT_NONE, * which means that we may get ACCERR when we want MAPERR. */ if (page_get_flags(guest_addr) & PAGE_VALID) { diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 5928c14dfc..104c13ec77 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -204,10 +204,10 @@ static bool init_guest_commpage(void) * The vsyscall page is at a high negative address aka kernel space, * which means that we cannot actually allocate it with target_mmap. * We still should be able to use page_set_flags, unless the user - * has specified -R reserved_va, which would trigger an assert(). + * has specified -R , which would trigger an assert(). */ - if (reserved_va != 0 && - TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE >= reserved_va) { + if (max_reserved_va != 0 && + TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE - 1 >= max_reserved_va) { error_report("Cannot allocate vsyscall page"); exit(EXIT_FAILURE); } @@ -2484,11 +2484,11 @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr, } /* Sanity check the guest binary. */ - if (reserved_va) { - if (guest_hiaddr > reserved_va) { + if (max_reserved_va) { + if (guest_hiaddr - 1 > max_reserved_va) { error_report("%s: requires more than reserved virtual " "address space (0x%" PRIx64 " > 0x%lx)", - image_name, (uint64_t)guest_hiaddr, reserved_va); + image_name, (uint64_t)guest_hiaddr - 1, max_reserved_va); exit(EXIT_FAILURE); } } else { @@ -2503,16 +2503,16 @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr, } /* - * Expand the allocation to the entire reserved_va. + * Expand the allocation to the entire max_reserved_va. * Exclude the mmap_min_addr hole. */ - if (reserved_va) { + if (max_reserved_va) { guest_loaddr = (guest_base >= mmap_min_addr ? 0 : mmap_min_addr - guest_base); - guest_hiaddr = reserved_va; + guest_hiaddr = max_reserved_va + 1; } - /* Reserve the address space for the binary, or reserved_va. */ + /* Reserve the address space for the binary, or max_reserved_va. */ test = g2h_untagged(guest_loaddr); addr = mmap(test, guest_hiaddr - guest_loaddr, PROT_NONE, flags, -1, 0); if (test != addr) { @@ -2716,7 +2716,7 @@ static void pgb_dynamic(const char *image_name, long align) if (HI_COMMPAGE) { uintptr_t addr, commpage; - /* 64-bit hosts should have used reserved_va. */ + /* 64-bit hosts should have used max_reserved_va. */ assert(sizeof(uintptr_t) == 4); /* @@ -2736,15 +2736,15 @@ static void pgb_reserved_va(const char *image_name, abi_ulong guest_loaddr, int flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE; void *addr, *test; - if (guest_hiaddr > reserved_va) { + if (guest_hiaddr - 1 > max_reserved_va) { error_report("%s: requires more than reserved virtual " "address space (0x%" PRIx64 " > 0x%lx)", - image_name, (uint64_t)guest_hiaddr, reserved_va); + image_name, (uint64_t)guest_hiaddr - 1, max_reserved_va); exit(EXIT_FAILURE); } /* Widen the "image" to the entire reserved address space. */ - pgb_static(image_name, 0, reserved_va, align); + pgb_static(image_name, 0, max_reserved_va + 1, align); /* osdep.h defines this as 0 if it's missing */ flags |= MAP_FIXED_NOREPLACE; @@ -2752,17 +2752,17 @@ static void pgb_reserved_va(const char *image_name, abi_ulong guest_loaddr, /* Reserve the memory on the host. */ assert(guest_base != 0); test = g2h_untagged(0); - addr = mmap(test, reserved_va, PROT_NONE, flags, -1, 0); + addr = mmap(test, max_reserved_va + 1, PROT_NONE, flags, -1, 0); if (addr == MAP_FAILED || addr != test) { error_report("Unable to reserve 0x%lx bytes of virtual address " "space at %p (%s) for use as guest address space (check your " "virtual memory ulimit setting, min_mmap_addr or reserve less " - "using -R option)", reserved_va, test, strerror(errno)); + "using -R option)", max_reserved_va + 1, test, strerror(errno)); exit(EXIT_FAILURE); } qemu_log_mask(CPU_LOG_PAGE, "%s: base @ %p for %lu bytes\n", - __func__, addr, reserved_va); + __func__, addr, max_reserved_va + 1); } void probe_guest_base(const char *image_name, abi_ulong guest_loaddr, @@ -2773,7 +2773,7 @@ void probe_guest_base(const char *image_name, abi_ulong guest_loaddr, if (have_guest_base) { pgb_have_guest_base(image_name, guest_loaddr, guest_hiaddr, align); - } else if (reserved_va) { + } else if (max_reserved_va) { pgb_reserved_va(image_name, guest_loaddr, guest_hiaddr, align); } else if (guest_loaddr) { pgb_static(image_name, guest_loaddr, guest_hiaddr, align); diff --git a/linux-user/main.c b/linux-user/main.c index 5fcaddffc2..f5731a1157 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -107,18 +107,16 @@ static const char *last_log_filename; # if HOST_LONG_BITS > TARGET_VIRT_ADDR_SPACE_BITS # if TARGET_VIRT_ADDR_SPACE_BITS == 32 && \ (TARGET_LONG_BITS == 32 || defined(TARGET_ABI32)) -/* There are a number of places where we assign reserved_va to a variable - of type abi_ulong and expect it to fit. Avoid the last page. */ -# define MAX_RESERVED_VA(CPU) (0xfffffffful & TARGET_PAGE_MASK) +# define MAX_RESERVED_VA(CPU) 0xfffffffful # else -# define MAX_RESERVED_VA(CPU) (1ul << TARGET_VIRT_ADDR_SPACE_BITS) +# define MAX_RESERVED_VA(CPU) ((1ul << TARGET_VIRT_ADDR_SPACE_BITS) - 1) # endif # else -# define MAX_RESERVED_VA(CPU) 0 +# define MAX_RESERVED_VA(CPU) (-1ul) # endif #endif -unsigned long reserved_va; +unsigned long max_reserved_va; static void usage(int exitcode); @@ -369,7 +367,8 @@ static void handle_arg_reserved_va(const char *arg) { char *p; int shift = 0; - reserved_va = strtoul(arg, &p, 0); + + max_reserved_va = strtoul(arg, &p, 0); switch (*p) { case 'k': case 'K': @@ -383,10 +382,10 @@ static void handle_arg_reserved_va(const char *arg) break; } if (shift) { - unsigned long unshifted = reserved_va; + unsigned long unshifted = max_reserved_va; p++; - reserved_va <<= shift; - if (reserved_va >> shift != unshifted) { + max_reserved_va <<= shift; + if (max_reserved_va >> shift != unshifted) { fprintf(stderr, "Reserved virtual address too big\n"); exit(EXIT_FAILURE); } @@ -395,16 +394,17 @@ static void handle_arg_reserved_va(const char *arg) fprintf(stderr, "Unrecognised -R size suffix '%s'\n", p); exit(EXIT_FAILURE); } - if (reserved_va == 0) { + if (max_reserved_va == 0) { fprintf(stderr, "Invalid -R size value 0\n"); exit(EXIT_FAILURE); } /* Must be aligned with the host page size as it is used with mmap. */ - if (reserved_va & qemu_host_page_mask) { + if (max_reserved_va & qemu_host_page_mask) { fprintf(stderr, "Invalid -R size value %lu: must be aligned mod %lu\n", - reserved_va, qemu_host_page_size); + max_reserved_va, qemu_host_page_size); exit(EXIT_FAILURE); } + max_reserved_va--; } static void handle_arg_singlestep(const char *arg) @@ -787,17 +787,13 @@ int main(int argc, char **argv, char **envp) * not by default. */ local_max_va = MAX_RESERVED_VA(cpu); - if (reserved_va != 0) { - if (local_max_va && reserved_va > local_max_va) { + if (max_reserved_va != 0) { + if (max_reserved_va > local_max_va) { fprintf(stderr, "Reserved virtual address too big\n"); exit(EXIT_FAILURE); } } else if (HOST_LONG_BITS == 64 && TARGET_VIRT_ADDR_SPACE_BITS <= 32) { - /* - * reserved_va must be aligned with the host page size - * as it is used with mmap() - */ - reserved_va = local_max_va & qemu_host_page_mask; + max_reserved_va = local_max_va; } { diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 28135c9e6a..547be8dff6 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -274,16 +274,16 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size, int prot; bool looped = false; - if (size > reserved_va) { + if (size > max_reserved_va) { return (abi_ulong)-1; } /* Note that start and size have already been aligned by mmap_find_vma. */ end_addr = start + size; - if (start > reserved_va - size) { + if (start > max_reserved_va + 1 - size) { /* Start at the top of the address space. */ - end_addr = ((reserved_va - size) & -align) + size; + end_addr = ((max_reserved_va + 1 - size) & -align) + size; looped = true; } @@ -297,7 +297,7 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size, return (abi_ulong)-1; } /* Re-start at the top of the address space. */ - addr = end_addr = ((reserved_va - size) & -align) + size; + addr = end_addr = ((max_reserved_va + 1 - size) & -align) + size; looped = true; } else { prot = page_get_flags(addr); @@ -339,7 +339,7 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) size = HOST_PAGE_ALIGN(size); - if (reserved_va) { + if (max_reserved_va) { return mmap_find_vma_reserved(start, size, align); } @@ -755,7 +755,7 @@ int target_munmap(abi_ulong start, abi_ulong len) ret = 0; /* unmap what we can */ if (real_start < real_end) { - if (reserved_va) { + if (max_reserved_va) { mmap_reserve(real_start, real_end - real_start); } else { ret = munmap(g2h_untagged(real_start), real_end - real_start); @@ -791,7 +791,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, host_addr = mremap(g2h_untagged(old_addr), old_size, new_size, flags, g2h_untagged(new_addr)); - if (reserved_va && host_addr != MAP_FAILED) { + if (max_reserved_va && host_addr != MAP_FAILED) { /* If new and old addresses overlap then the above mremap will already have failed with EINVAL. */ mmap_reserve(old_addr, old_size); @@ -808,13 +808,13 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, host_addr = mremap(g2h_untagged(old_addr), old_size, new_size, flags | MREMAP_FIXED, g2h_untagged(mmap_start)); - if (reserved_va) { + if (max_reserved_va) { mmap_reserve(old_addr, old_size); } } } else { int prot = 0; - if (reserved_va && old_size < new_size) { + if (max_reserved_va && old_size < new_size) { abi_ulong addr; for (addr = old_addr + old_size; addr < old_addr + new_size; @@ -834,7 +834,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, new_size, old_size, flags); errno = ENOMEM; host_addr = MAP_FAILED; - } else if (reserved_va && old_size > new_size) { + } else if (max_reserved_va && old_size > new_size) { mmap_reserve(old_addr + old_size, old_size - new_size); } } diff --git a/linux-user/signal.c b/linux-user/signal.c index 098f3a787d..f40b0a616a 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -808,7 +808,7 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) /* * Convert forcefully to guest address space: addresses outside - * reserved_va are still valid to report via SEGV_MAPERR. + * max_reserved_va are still valid to report via SEGV_MAPERR. */ guest_addr = h2g_nocheck(host_addr); @@ -827,7 +827,7 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc) } /* - * With reserved_va, the whole address space is PROT_NONE, + * With max_reserved_va, the whole address space is PROT_NONE, * which means that we may get ACCERR when we want MAPERR. */ if (page_get_flags(guest_addr) & PAGE_VALID) { diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 5182ed0c91..b9cd0d3e33 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -264,7 +264,7 @@ static void arm_cpu_reset_hold(Object *obj) } } /* - * Enable 48-bit address space (TODO: take reserved_va into account). + * Enable 48-bit address space (TODO: take max_reserved_va into account). * Enable TBI0 but not TBI1. * Note that this must match useronly_clean_ptr. */ From patchwork Mon Mar 6 02:13:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 659229 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp1598615wrb; Sun, 5 Mar 2023 18:14:15 -0800 (PST) X-Google-Smtp-Source: AK7set+oMctcs9/ECBRK2ggpb6qvBhEV10f4XypDuMkpbnCaseY7JiXunR0nCG0j9fhADEi8BWWY X-Received: by 2002:ac8:7dd6:0:b0:3ba:3ac7:ccf1 with SMTP id c22-20020ac87dd6000000b003ba3ac7ccf1mr14752354qte.58.1678068855692; Sun, 05 Mar 2023 18:14:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678068855; cv=none; d=google.com; s=arc-20160816; b=f8+TrxvxZA+eVlBZKSf5ALPL0dH9idCUoox3h8qRMsN90xkV/3q6gJAqcXGcpZIHrN Y1EUy1GiB6nRK5AamRhs9jd4Wb8aNZyKh71hXtdlqjSS3uwhNtCe+46I43zOV7xFTwyo 1qnb4PgRbbnYkPis8Ljqr36hi+4hZNDcwf4qxWObPc6DDuv89HyzhrCggwcgVeyx1tor 1HFoG3ej+TXsJLW7vp+daMBsv194Kww92dqYIeq1TO6/uxv6LGdTvmJJK505ztd/zfbH gEVf31+9qkowethSdc1ScwmepD/tR1uoiiIerVSkd4wJtmOMOE22Zhu/XfvRKBICG9MW fTbA== 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:to:from :dkim-signature; bh=d/d0OBIClNgz9uS/ri2TTMH+bBSoAaI+6QK8Ud7Uf5M=; b=WRpW//aFkP257PE+LHjy1lWdMOALqW9nAknmnCTYKVK3x8foLV/xyRZBQ+/0GR7rxU jPJdMpKyB7zm2J+GA8W8jeR8shrsuMuznFQEGhtguezwE129fzShkiKbzF/e08bR03Hy 1rAhhF7cyhCj4kDSzVXt6x4bVm5UjT4YpyudMpYdovnqHdo1EnN0mnbhJpeifutfXgC6 zz3d4rDip8ARoEvttd5gC2wON6IPFKd60OczRIAxYVI5jBW9vCXGIXQrNn7+WeTFdWO+ k+PzSrBBt6OpSWVCsepqkGsl1uXvsY/mXUHkQqHlMBaA91ERZdthLxlomf7eKeOaDw3n we5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=igcpnZtg; 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 u19-20020a05620a0c5300b0071eb8581636si7127997qki.666.2023.03.05.18.14.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 05 Mar 2023 18:14:15 -0800 (PST) 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=igcpnZtg; 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 1pZ0Lo-0003PH-Kb; Sun, 05 Mar 2023 21:13:20 -0500 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 1pZ0Lj-0003Ew-Tn for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:15 -0500 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pZ0Lh-00061i-Fi for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:15 -0500 Received: by mail-pj1-x1044.google.com with SMTP id x20-20020a17090a8a9400b00233ba727724so9830030pjn.1 for ; Sun, 05 Mar 2023 18:13:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678068792; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=d/d0OBIClNgz9uS/ri2TTMH+bBSoAaI+6QK8Ud7Uf5M=; b=igcpnZtghlU0m6W6J66lr/2xsUcTj5Mx4VbBdRW5FAL5G+2c24lhFYX3kYyQXEhZy7 jbWXYY2Qp5U0YLY4ug4RHGs6ZsLq1oDuoUNmlOjE1Ro8llPTlwSlcCKGkQBleYz0oIz4 Bib+45i3pwFc5hLNa1FLWqrQkHN10p3FQ27nBTCyvw6r5AR1a3wtddxC5QcGz9uGwYhZ B9joQaOKUbVfH6cn+LM9nd/xluMv3vQJMQVbwrcwBCzEQ8qphuUyLWyKAIdabpDHvXV8 ouinMDwKjOCeRHe/N30xfvoiv/7+pTMJlc47NctV6gGQE7A/8BdubspJXRTDhzYfZgQc XPlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678068792; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d/d0OBIClNgz9uS/ri2TTMH+bBSoAaI+6QK8Ud7Uf5M=; b=h8BTCO6jNCahmLEcp0G/YIlbcAk8TvqL73E4B24udFW2k1BUD6ELDDwcaKDi5uetl3 s6+9PaVUsIBhBjKsI9aGgesEWCnNrMTE2mSL1OXB/qY7OI1dNkueJo2RL7ldXkfj+AIU e4zQXOI5Z3tJMP+sJNQtElWrCWNjwVEdXYK0S8IpKe3jm3bOWhhU0f1eIbvyc1MaOa8w 4qw6leo0g2alkHlV9jw3SSMCGRNQG8x2n7aLS8/D2shIejMw8GBmwE/CcA6Fxd5/hSGR HYP9hlQXKTDzgar6GXUKC34Us560PAAfPXS5mlu7m6DpMXn7mbI+RGFqWFMLkajjcOfL Hj3Q== X-Gm-Message-State: AO0yUKUgPvS4lFzdgfBi/652DnwIa4MvpFcoBHIU3KFnRLXjPOn33FhH Ei2DELdr7DXpvl6Pe/udqb06C1rFxKiXMfSvjcUFxQtO X-Received: by 2002:a05:6a20:7349:b0:cc:9b29:f5ff with SMTP id v9-20020a056a20734900b000cc9b29f5ffmr9228819pzc.35.1678068792106; Sun, 05 Mar 2023 18:13:12 -0800 (PST) Received: from stoup.. ([2602:ae:154a:9f01:87cc:49bb:2900:c08b]) by smtp.gmail.com with ESMTPSA id d18-20020a630e12000000b005030136314dsm5048434pgl.71.2023.03.05.18.13.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 18:13:11 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 4/9] accel/tcg: Pass last not end to page_set_flags Date: Sun, 5 Mar 2023 18:13:02 -0800 Message-Id: <20230306021307.1879483-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306021307.1879483-1-richard.henderson@linaro.org> References: <20230306021307.1879483-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1044; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1044.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. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1528 Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- include/exec/cpu-all.h | 2 +- accel/tcg/user-exec.c | 16 +++++++--------- bsd-user/mmap.c | 6 +++--- linux-user/elfload.c | 11 ++++++----- linux-user/mmap.c | 16 ++++++++-------- linux-user/syscall.c | 4 ++-- 6 files changed, 27 insertions(+), 28 deletions(-) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index 7ef6b9a94d..748764459c 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -285,7 +285,7 @@ typedef int (*walk_memory_regions_fn)(void *, target_ulong, 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 end, int flags); +void page_set_flags(target_ulong start, target_ulong last, int flags); void page_reset_target_data(target_ulong start, target_ulong end); 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 7b37fd229e..035f8096b2 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -480,24 +480,22 @@ static bool pageflags_set_clear(target_ulong start, target_ulong last, * The flag PAGE_WRITE_ORG is positioned automatically depending * on PAGE_WRITE. The mmap_lock should already be held. */ -void page_set_flags(target_ulong start, target_ulong end, int flags) +void page_set_flags(target_ulong start, target_ulong last, int flags) { - target_ulong last; bool reset = false; bool inval_tb = false; /* This function should never be called with addresses outside the guest address space. If this assert fires, it probably indicates a missing call to h2g_valid. */ - assert(start < end); - assert(end - 1 <= GUEST_ADDR_MAX); + assert(start <= last); + assert(last <= GUEST_ADDR_MAX); /* Only set PAGE_ANON with new mappings. */ assert(!(flags & PAGE_ANON) || (flags & PAGE_RESET)); assert_memory_lock(); - start = start & TARGET_PAGE_MASK; - end = TARGET_PAGE_ALIGN(end); - last = end - 1; + start &= TARGET_PAGE_MASK; + last |= ~TARGET_PAGE_MASK; if (!(flags & PAGE_VALID)) { flags = 0; @@ -510,7 +508,7 @@ void page_set_flags(target_ulong start, target_ulong end, int flags) } if (!flags || reset) { - page_reset_target_data(start, end); + page_reset_target_data(start, last + 1); inval_tb |= pageflags_unset(start, last); } if (flags) { @@ -518,7 +516,7 @@ void page_set_flags(target_ulong start, target_ulong end, int flags) ~(reset ? 0 : PAGE_STICKY)); } if (inval_tb) { - tb_invalidate_phys_range(start, end); + tb_invalidate_phys_range(start, last + 1); } } diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index e9a330d599..301fc63817 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -118,7 +118,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot) if (ret != 0) goto error; } - page_set_flags(start, start + len, prot | PAGE_VALID); + page_set_flags(start, start + len - 1, prot | PAGE_VALID); mmap_unlock(); return 0; error: @@ -656,7 +656,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, } } the_end1: - page_set_flags(start, start + len, prot | PAGE_VALID); + page_set_flags(start, start + len - 1, prot | PAGE_VALID); the_end: #ifdef DEBUG_MMAP printf("ret=0x" TARGET_ABI_FMT_lx "\n", start); @@ -767,7 +767,7 @@ int target_munmap(abi_ulong start, abi_ulong len) } if (ret == 0) { - page_set_flags(start, start + len, 0); + page_set_flags(start, start + len - 1, 0); } mmap_unlock(); return ret; diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 104c13ec77..a3431d8d62 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -212,7 +212,7 @@ static bool init_guest_commpage(void) exit(EXIT_FAILURE); } page_set_flags(TARGET_VSYSCALL_PAGE, - TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE, + TARGET_VSYSCALL_PAGE | ~TARGET_PAGE_MASK, PAGE_EXEC | PAGE_VALID); return true; } @@ -443,7 +443,7 @@ static bool init_guest_commpage(void) exit(EXIT_FAILURE); } - page_set_flags(commpage, commpage + qemu_host_page_size, + page_set_flags(commpage, commpage | ~qemu_host_page_mask, PAGE_READ | PAGE_EXEC | PAGE_VALID); return true; } @@ -1315,7 +1315,7 @@ static bool init_guest_commpage(void) exit(EXIT_FAILURE); } - page_set_flags(LO_COMMPAGE, LO_COMMPAGE + TARGET_PAGE_SIZE, + page_set_flags(LO_COMMPAGE, LO_COMMPAGE | ~TARGET_PAGE_MASK, PAGE_READ | PAGE_EXEC | PAGE_VALID); return true; } @@ -1727,7 +1727,7 @@ static bool init_guest_commpage(void) * and implement syscalls. Here, simply mark the page executable. * Special case the entry points during translation (see do_page_zero). */ - page_set_flags(LO_COMMPAGE, LO_COMMPAGE + TARGET_PAGE_SIZE, + page_set_flags(LO_COMMPAGE, LO_COMMPAGE | ~TARGET_PAGE_MASK, PAGE_EXEC | PAGE_VALID); return true; } @@ -2199,7 +2199,8 @@ static void zero_bss(abi_ulong elf_bss, abi_ulong last_bss, int prot) /* Ensure that the bss page(s) are valid */ if ((page_get_flags(last_bss-1) & prot) != prot) { - page_set_flags(elf_bss & TARGET_PAGE_MASK, last_bss, prot | PAGE_VALID); + page_set_flags(elf_bss & TARGET_PAGE_MASK, last_bss - 1, + prot | PAGE_VALID); } if (host_start < host_map_start) { diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 547be8dff6..9cf85f4090 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -181,7 +181,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) } } - page_set_flags(start, start + len, page_flags); + page_set_flags(start, start + len - 1, page_flags); ret = 0; error: @@ -640,15 +640,15 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, } page_flags |= PAGE_RESET; if (passthrough_start == passthrough_end) { - page_set_flags(start, start + len, page_flags); + page_set_flags(start, start + len - 1, page_flags); } else { if (start < passthrough_start) { - page_set_flags(start, passthrough_start, page_flags); + page_set_flags(start, passthrough_start - 1, page_flags); } - page_set_flags(passthrough_start, passthrough_end, + page_set_flags(passthrough_start, passthrough_end - 1, page_flags | PAGE_PASSTHROUGH); if (passthrough_end < start + len) { - page_set_flags(passthrough_end, start + len, page_flags); + page_set_flags(passthrough_end, start + len - 1, page_flags); } } the_end: @@ -763,7 +763,7 @@ int target_munmap(abi_ulong start, abi_ulong len) } if (ret == 0) { - page_set_flags(start, start + len, 0); + page_set_flags(start, start + len - 1, 0); } mmap_unlock(); return ret; @@ -849,8 +849,8 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, } else { new_addr = h2g(host_addr); prot = page_get_flags(old_addr); - page_set_flags(old_addr, old_addr + old_size, 0); - page_set_flags(new_addr, new_addr + new_size, + page_set_flags(old_addr, old_addr + old_size - 1, 0); + page_set_flags(new_addr, new_addr + new_size - 1, prot | PAGE_VALID | PAGE_RESET); } mmap_unlock(); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index a6c426d73c..78e14ee875 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4583,7 +4583,7 @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env, } raddr=h2g((unsigned long)host_raddr); - page_set_flags(raddr, raddr + shm_info.shm_segsz, + page_set_flags(raddr, raddr + shm_info.shm_segsz - 1, PAGE_VALID | PAGE_RESET | PAGE_READ | (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE)); @@ -4613,7 +4613,7 @@ static inline abi_long do_shmdt(abi_ulong shmaddr) for (i = 0; i < N_SHM_REGIONS; ++i) { if (shm_regions[i].in_use && shm_regions[i].start == shmaddr) { shm_regions[i].in_use = false; - page_set_flags(shmaddr, shmaddr + shm_regions[i].size, 0); + page_set_flags(shmaddr, shmaddr + shm_regions[i].size - 1, 0); break; } } From patchwork Mon Mar 6 02:13:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 659227 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp1598523wrb; Sun, 5 Mar 2023 18:13:54 -0800 (PST) X-Google-Smtp-Source: AK7set+RjeCmBqx8a8jjsGF5Ej7Kp6vnetmr93HzJbE7mNbJv7isFLt3dI3z6qbiN254u+z+sK1r X-Received: by 2002:a05:6214:1cc8:b0:572:5a3a:f55 with SMTP id g8-20020a0562141cc800b005725a3a0f55mr14527606qvd.33.1678068834482; Sun, 05 Mar 2023 18:13:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678068834; cv=none; d=google.com; s=arc-20160816; b=k1WwRadKtu3rN1HyIw/yAUDxZcTvkWggYpPuDJdc5/wtSlOMom5W3QHFbuHNQ8X+OU 5CHkL81ejil8EYqPolExpPsL3iIswKawEj0Lu+uZDjMZjk9PYeJQMz2V+MiUHPRKuqdf heUH+9KzvdceANL57sdxjpceun5BZ1I1ETi0eKIDmGlMZUz2TZc4Krts4Ef2CvrX0VdL lzMHqHSmhxXj6WKY7HNP28o0PGmymm4MB6FF8jv/tMIA65+35SP8WJferjHKCpcmS+V+ FUD6n98lealNTXVq/dj6wQjbr3G6R4HAVMfXUMHvSpJbaLr7S9pm5DDgaK/3WzisuNCT TScw== 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:to:from :dkim-signature; bh=Klh00VTjYiHdsz8hSod/ulyCtvR28jPMZcquCoiGcz8=; b=WUU9vK46rTf4jtUyd36xZ+vznCIEFajShipF8uy5TuUw+ghUgQYq1nDSdIi8D0Edo0 +Xm4kM62qyD4FTPcXj6nR4RR3mRIy+snPmgfDf3DvknPkitaQSF739KYQ1fwecuDY3Hv gNRiuCWx6UF7kN+BY6mVBf+d1SWjO2sKWXPUnQALBjT8R6U5U6Q2ZJZMhcy8xZP6+MQo lwpqrX94t5sI8IKIjQMCWeZtYOSVpIZVuO4/YwW9OxVtzJ6y2wAnBmAr7hD9mn010U1l eMKZZTePRswFa6mP+Y7JdzwFKQNBrZ38DbNUCUCxJARkGYYS7xiK8xez0eTFJZwl+iQ+ izsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yoDol88z; 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 m8-20020a0c9d08000000b0057e60499693si5718372qvf.42.2023.03.05.18.13.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 05 Mar 2023 18:13:54 -0800 (PST) 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=yoDol88z; 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 1pZ0Lk-0003FK-GB; Sun, 05 Mar 2023 21:13:16 -0500 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 1pZ0Lj-0003Ev-Gj for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:15 -0500 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pZ0Lh-00060k-QH for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:15 -0500 Received: by mail-pj1-x1029.google.com with SMTP id h17-20020a17090aea9100b0023739b10792so7532210pjz.1 for ; Sun, 05 Mar 2023 18:13:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678068793; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Klh00VTjYiHdsz8hSod/ulyCtvR28jPMZcquCoiGcz8=; b=yoDol88z3w+ojWU/TgShyN70KXJFbeFuw+heV/K8nLPT02DLWPPnaHZIGkwmSlllTl o02nzbjWnudxtJ6Q4BUTIQoRLvZJkIuwCQOsUINKYOBxxQpMKAZJ89m+K3NtyVeOC/eL /fSFNd3KSJw+/OrFBZ5Wro/uG5GBMGLeNOfmKP1D4Z6y0hjLmUWgrsa8M+pmUIyLaR9o WmYA+IpkOZBJzlOF+9hf8xE0vHo2OM0iHThZ6ZLvAWIC0ZsdQJ+ELJPMllqqr2ZsMGs/ fkaz7sCgrYRkJs4/22/t85Bnih78XoEKNM4DutuCQxS3V9dZhazj1sinsMmC1qhWd3BS zq5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678068793; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Klh00VTjYiHdsz8hSod/ulyCtvR28jPMZcquCoiGcz8=; b=0ditqXp9mYwRuZY4TmBkM0yv7jdHCRaewnA+1kYJSS98t/IwMutHVbBX4qWbQ9nSPx ICR+g488FoXKxHqWfygLzt4l/teAvpW11HA0BPgHM3Bcw4FN0o34INErEZ2BhP0zqQ/O v4+/fsBwxhcrKh5mbTDzfTut/zCABa/YDuypyVPDTGRannk3yOKSTHw92yscjX53pI3D jckOg92iqgEThrgVZEhRjpEx+mbUEI94FUMAQw6+JyZzZ7UwG/98/9+DxktdrzDsee25 Di1VnHOY7gsp5UzP4/q3SNebhaK5sOXWFLDr59lanO9NId73mWSCLP0b/Wc/UW4ruYNQ MqcQ== X-Gm-Message-State: AO0yUKWnX6wlSKTB8C5H2EG/h910oKlFAfo2XkASFrmjHuMfmR2JbWLg jPfK29I0ln88O1OsP9YSMCFzljf1f3pi+MX/OWD3+Q== X-Received: by 2002:a17:903:492:b0:19e:773b:2215 with SMTP id jj18-20020a170903049200b0019e773b2215mr9317480plb.36.1678068792995; Sun, 05 Mar 2023 18:13:12 -0800 (PST) Received: from stoup.. ([2602:ae:154a:9f01:87cc:49bb:2900:c08b]) by smtp.gmail.com with ESMTPSA id d18-20020a630e12000000b005030136314dsm5048434pgl.71.2023.03.05.18.13.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 18:13:12 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 5/9] accel/tcg: Pass last not end to page_reset_target_data Date: Sun, 5 Mar 2023 18:13:03 -0800 Message-Id: <20230306021307.1879483-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306021307.1879483-1-richard.henderson@linaro.org> References: <20230306021307.1879483-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.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. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- 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 748764459c..a8cb4c905d 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 9cf85f4090..c153277afb 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); } } } From patchwork Mon Mar 6 02:13:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 659232 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp1598691wrb; Sun, 5 Mar 2023 18:14:32 -0800 (PST) X-Google-Smtp-Source: AK7set+E6FIljbeK9m121W8mvgncQY9vhxEEaFRZCVU0k6CDY176O9hZKiYERw+DLWz8BtutcKUL X-Received: by 2002:a05:6214:1c05:b0:56e:b690:9bc5 with SMTP id u5-20020a0562141c0500b0056eb6909bc5mr18650368qvc.19.1678068872683; Sun, 05 Mar 2023 18:14:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678068872; cv=none; d=google.com; s=arc-20160816; b=NCsQrjeega586Ux5HwOYYNA4Adn74Y+1sig53wrgoufN77zp72hMKdCcPDnFryKhAB 2+o9UFH1m6wVLSoi/YVXsu1tZBcpBv4trsK4wxwLmo1OjbWuJwHnWYErypgbMK1Lylwj 1TdYa54pF+QIAZpLdS3YngnU+inUxnFZdymiWZkdyo8wRGskw3GmZhGmrHpvXueWumA9 09A4n4sJkQGorkFWS/UKontNiYC1GwghMHKZnQpyRCof/z3/DDydtWpDNQBaLpKZFI2q nz+XEj9wqIcW/WjAlnbZU8fSoU/GR3CbADVyVGRBeYJFIBkGfWKonKbC5PjFcFkpLMyf So6w== 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:to:from :dkim-signature; bh=E6BOJx4r1pYVT6Z+5FzgOYkiXq4HsL5PEr5po56LIKU=; b=Q9hOwdAgXaQlLg9Bek2e0sTmPaS40kBWQ/2aQ6peRFaGV07Ff+lc1+c35zpFZzWBzI t3pfOI+yQ3j6FUJTOJkAaw2dSO8a/P/u+pwTz6EX7fbPfFPbRqUfuKF9uGmjFC8q3ATv xOlJu7MUf4CVtpkDcmZWDSNlNGXTmQkbqvZLno3WmdiVmNpsSBZDEmvqt+QY3W4r2q0B ywif0adv+e3vr9U/6GxaqFFRK3hrPJp7zjgUipPZ66YnTIvjVbfkZRp0dVXwD8mV7mbM FT65EjgcP3iwZTEZ40SBhD/YSQDVdDSEfwaYJDl3wf4QaUIZrTZH+hgd/Rl5gOPUkR0d 5Nug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TEoGNawG; 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 de39-20020a05620a372700b0073128e8f63esi6465864qkb.534.2023.03.05.18.14.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 05 Mar 2023 18:14:32 -0800 (PST) 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=TEoGNawG; 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 1pZ0Lm-0003KL-1o; Sun, 05 Mar 2023 21:13:18 -0500 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 1pZ0Lk-0003FQ-Lj for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:16 -0500 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pZ0Li-0005zN-Ot for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:16 -0500 Received: by mail-pj1-x1030.google.com with SMTP id m8-20020a17090a4d8800b002377bced051so11776391pjh.0 for ; Sun, 05 Mar 2023 18:13:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678068794; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=E6BOJx4r1pYVT6Z+5FzgOYkiXq4HsL5PEr5po56LIKU=; b=TEoGNawG74Fb/VR3i5ZHWnjlMBzlwP/7llGFD3QLD/3Dk23+mmHIzPcZpFQo9RQpea VbB655ZbOHm85akL0OI1HW/G1CeibN6dUzEqDRT3OeIO39/7VJFauyETzrsi+mx7SVxz csVxkm/cSSGh/TJyypwZnnB9DxeUg6cXmoLnuvJW8flD8rtZyzmLcd1v0rpxFB+Rg2wA C5BsVeqMtJS+cdm6pPQQJZN9mfrGagc5BdRfOJPKVVk0Kc3cjTAr0taEZZX2yhxuCyC5 v1MizcA9nRP9qMOw4WtWTxGiP4uqYFu9edwXWw4I/dvV3rFOrL5sygSrAZcFw9DJIbk2 KW7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678068794; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E6BOJx4r1pYVT6Z+5FzgOYkiXq4HsL5PEr5po56LIKU=; b=KcuqKy71z8RW5KSJWWDGx1WEKniDdQQ3wFW3+dPjMLJ74sFxdg5YE25wZjSi2sZ3Nb JaxHmFkHsR33SfYcDWTkgPCBOXCkP4wPbENJlx/ihW4UmQdyMXZi0UFl4tY6SegOarnA uEPQiC9cSwH9WmN0ZpfnglxkBx8CzC5BihplCXEsHeQ0t77sq4sXyqlRUjbQZPXmDt+p 4dKU52ho+Aw+GWYctSR4P7ph7X8QiD2WBn7D1zIdMaejIYUcV1Ts11VB9za35/nWEy9W XskvDTuxepmCkzET/G6gZVFIZuGD0c78t/lKlB4qK/m7UA3ENXDujPwoQM34Fzp6S4fJ jx+w== X-Gm-Message-State: AO0yUKVcyiMJ60lRcliWgItR/2FfWzH/9LiHofqDbr4Bs3icM85L1bls LDevJ4YISYm1LyORxHfiXW0AvNo+6lXQ3v9aOfOmmw== X-Received: by 2002:a05:6a20:7d9d:b0:cd:91bc:a9af with SMTP id v29-20020a056a207d9d00b000cd91bca9afmr10380897pzj.58.1678068793980; Sun, 05 Mar 2023 18:13:13 -0800 (PST) Received: from stoup.. ([2602:ae:154a:9f01:87cc:49bb:2900:c08b]) by smtp.gmail.com with ESMTPSA id d18-20020a630e12000000b005030136314dsm5048434pgl.71.2023.03.05.18.13.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 18:13:13 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 6/9] accel/tcg: Pass last not end to PAGE_FOR_EACH_TB Date: Sun, 5 Mar 2023 18:13:04 -0800 Message-Id: <20230306021307.1879483-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306021307.1879483-1-richard.henderson@linaro.org> References: <20230306021307.1879483-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1030.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. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- accel/tcg/tb-maint.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c index efefa08ee1..745912e60a 100644 --- a/accel/tcg/tb-maint.c +++ b/accel/tcg/tb-maint.c @@ -125,29 +125,29 @@ static void tb_remove(TranslationBlock *tb) } /* TODO: For now, still shared with translate-all.c for system mode. */ -#define PAGE_FOR_EACH_TB(start, end, pagedesc, T, N) \ - for (T = foreach_tb_first(start, end), \ - N = foreach_tb_next(T, start, end); \ +#define PAGE_FOR_EACH_TB(start, last, pagedesc, T, N) \ + for (T = foreach_tb_first(start, last), \ + N = foreach_tb_next(T, start, last); \ T != NULL; \ - T = N, N = foreach_tb_next(N, start, end)) + T = N, N = foreach_tb_next(N, start, last)) typedef TranslationBlock *PageForEachNext; static PageForEachNext foreach_tb_first(tb_page_addr_t start, - tb_page_addr_t end) + tb_page_addr_t last) { - IntervalTreeNode *n = interval_tree_iter_first(&tb_root, start, end - 1); + IntervalTreeNode *n = interval_tree_iter_first(&tb_root, start, last); return n ? container_of(n, TranslationBlock, itree) : NULL; } static PageForEachNext foreach_tb_next(PageForEachNext tb, tb_page_addr_t start, - tb_page_addr_t end) + tb_page_addr_t last) { IntervalTreeNode *n; if (tb) { - n = interval_tree_iter_next(&tb->itree, start, end - 1); + n = interval_tree_iter_next(&tb->itree, start, last); if (n) { return container_of(n, TranslationBlock, itree); } @@ -318,7 +318,7 @@ struct page_collection { }; typedef int PageForEachNext; -#define PAGE_FOR_EACH_TB(start, end, pagedesc, tb, n) \ +#define PAGE_FOR_EACH_TB(start, last, pagedesc, tb, n) \ TB_FOR_EACH_TAGGED((pagedesc)->first_tb, tb, n, page_next) #ifdef CONFIG_DEBUG_TCG @@ -993,10 +993,11 @@ void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end) { TranslationBlock *tb; PageForEachNext n; + tb_page_addr_t last = end - 1; assert_memory_lock(); - PAGE_FOR_EACH_TB(start, end, unused, tb, n) { + PAGE_FOR_EACH_TB(start, last, unused, tb, n) { tb_phys_invalidate__locked(tb); } } @@ -1028,6 +1029,7 @@ bool tb_invalidate_phys_page_unwind(tb_page_addr_t addr, uintptr_t pc) bool current_tb_modified; TranslationBlock *tb; PageForEachNext n; + tb_page_addr_t last; /* * Without precise smc semantics, or when outside of a TB, @@ -1044,10 +1046,11 @@ bool tb_invalidate_phys_page_unwind(tb_page_addr_t addr, uintptr_t pc) assert_memory_lock(); current_tb = tcg_tb_lookup(pc); + last = addr | ~TARGET_PAGE_MASK; addr &= TARGET_PAGE_MASK; current_tb_modified = false; - PAGE_FOR_EACH_TB(addr, addr + TARGET_PAGE_SIZE, unused, tb, n) { + PAGE_FOR_EACH_TB(addr, last, unused, tb, n) { if (current_tb == tb && (tb_cflags(current_tb) & CF_COUNT_MASK) != 1) { /* @@ -1089,12 +1092,13 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages, bool current_tb_modified = false; TranslationBlock *current_tb = retaddr ? tcg_tb_lookup(retaddr) : NULL; #endif /* TARGET_HAS_PRECISE_SMC */ + tb_page_addr_t last G_GNUC_UNUSED = end - 1; /* * We remove all the TBs in the range [start, end[. * XXX: see if in some cases it could be faster to invalidate all the code */ - PAGE_FOR_EACH_TB(start, end, p, tb, n) { + PAGE_FOR_EACH_TB(start, last, p, tb, n) { /* NOTE: this is subtle as a TB may span two physical pages */ if (n == 0) { /* NOTE: tb_end may be after the end of the page, but From patchwork Mon Mar 6 02:13:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 659228 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp1598532wrb; Sun, 5 Mar 2023 18:13:57 -0800 (PST) X-Google-Smtp-Source: AK7set+5eseeRkkaxxyh9tqulksxCn2B8LF1DIjlYPW7kZrw64IXG338CnHvusl/N0Vx16djqofx X-Received: by 2002:a05:6214:f05:b0:56e:b25f:3602 with SMTP id gw5-20020a0562140f0500b0056eb25f3602mr18117997qvb.43.1678068836937; Sun, 05 Mar 2023 18:13:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678068836; cv=none; d=google.com; s=arc-20160816; b=iFXp5UyIvjIMbI4JDZW0f5VmkikjkbeCMjmN05JYAgKN292MdJW7yGgxheeFuDx1ST bAPKnEfvs7Vz/kvdIgkikDXAvYKi+7fSELjPdwyJcUhhS22IzhnSWEF3g3bQ/BbWC86m MY57n00jHkKBIsrlayoUg+YR8GK7cQJZNbsFKal4l0ns5caemSQz196RFoh0H3iYTRxg 4CYR3bR6XQVk+25eC+POoVtUNGG15DWeciqmiP4SMj1F8MQXCov9r7uOguo+Z4GoKXgo qSqR2+22Tgm4tmgmWmbxhKd/SGObOzama0c/IhYblUggC85rOLzh22asUrKbTy9Vhx8G iAWQ== 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:to:from :dkim-signature; bh=RvcMLtMZSPv7P6lANhDUocXLVd0nBQQsNtPV18yr4k4=; b=SJxp1YybYyX7i9A1YU5WEpxJ6+fgfhobvoBoIj5JTTQ8p5ur0i62Qi2iGM791zvPRT lq2U70X69FyVrFd3qUGi7uL6DfP3CjFYXHU0T27zyMzlSKtPhesb9+DrbP/2f+vJ5egY eAxFUvZCDvm0rSx50N/aXjMqeyHVInp0t4nDwdva4FNk0cttY1u/q8p/PCj2sL8pelyZ zoUflKM70xjeNo57TIHs5snR5HjpuHsI2sqYNHcf35myAIvz/RX+GekX9ioefN16h+OW 0Kdv6cgTXVK0XLvmT1nvPeLFV9Vn0QyuNu6Lk/q1ZdU6gGhdTvZ+PeKrlwoqe2X/YyOJ XZlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wh52Ylg3; 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 k17-20020a0cf291000000b0056c0a6a5ee7si6447086qvl.192.2023.03.05.18.13.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 05 Mar 2023 18:13:56 -0800 (PST) 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=wh52Ylg3; 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 1pZ0Ln-0003NQ-9V; Sun, 05 Mar 2023 21:13:19 -0500 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 1pZ0Ll-0003JB-Nw for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:17 -0500 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pZ0Lk-00062J-5k for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:17 -0500 Received: by mail-pj1-x102c.google.com with SMTP id bo22so8302567pjb.4 for ; Sun, 05 Mar 2023 18:13:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678068795; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=RvcMLtMZSPv7P6lANhDUocXLVd0nBQQsNtPV18yr4k4=; b=wh52Ylg3bwxtArx3aZ6tB+nDnP/KRGtwZkYcDqVIlM7iuD+Ck2gECuAbFMlrKaUfV6 GA42Lbt825aKn2rcDyIxrM7Xdr1X1nhm+wtV4uCaJK1LbkJZVjGJfIyN9UdP1sdkqVVT 7Pn6Z0foUnY0/Kcn+gyYsUyplemWr2Z/ZiSoZgZ7dl1yMuES6DLi03n1C47Q73D3EPmM 5xkfcPymF25VQL1KVV/anPOZ+Okflod3vGdEP+KDqAcJOCvXX3/pE7NgfSppp/zaIDQ9 UFJ/ZvmL7VA8B2YjIoAy/D0EKlhWnl0ts10OK+oFmkEOLme4a9XGf9RdeEqjamWAtHoV CN3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678068795; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RvcMLtMZSPv7P6lANhDUocXLVd0nBQQsNtPV18yr4k4=; b=gfrpmabsASTpW4IQrx+eVRiXod6lrh253nphwP2LlnkI2zDxfjtG/5VVHqx0YI3Er0 iROUGml1PzO6oizFL/imKvcRw43QQo0E5MRMjmmAkfVQYJ1VrliuZ2jUJVB3VVtzQlMn fF4o4i56mm/JIP7LEftkNuaXYj/c7HEleHhtVYiYVd/VY2WIq0N3zukxaxRSNswQTPl3 dMteToRbhBRY0fbor6RznrIxN4ovS1hVcSW/1KguK3TlAESI9x4pXmKI1Fcfd+Ksu56d kvw2H6hKFOvXUsggt6obEezK9PsZnYvn8fi4x4Xrl7MpjA2p0aQk69LeVqjaq34M90BE C5qw== X-Gm-Message-State: AO0yUKXLEcOeeovPcFRZK4UhEC/grWMWmMMxWeGm0yplDQiRzj2cPoaS d0gAuAEL352Hr6rGuzIWWd7d9qaSej6yQTMljHnteA== X-Received: by 2002:a05:6a20:5483:b0:cd:47dc:82b5 with SMTP id i3-20020a056a20548300b000cd47dc82b5mr13278691pzk.21.1678068794870; Sun, 05 Mar 2023 18:13:14 -0800 (PST) Received: from stoup.. ([2602:ae:154a:9f01:87cc:49bb:2900:c08b]) by smtp.gmail.com with ESMTPSA id d18-20020a630e12000000b005030136314dsm5048434pgl.71.2023.03.05.18.13.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 18:13:14 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 7/9] accel/tcg: Pass last not end to page_collection_lock Date: Sun, 5 Mar 2023 18:13:05 -0800 Message-Id: <20230306021307.1879483-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306021307.1879483-1-richard.henderson@linaro.org> References: <20230306021307.1879483-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.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. Fixes a bug in the loop comparision where "<= end" would lock one more page than required. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- accel/tcg/tb-maint.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c index 745912e60a..c4e15c5591 100644 --- a/accel/tcg/tb-maint.c +++ b/accel/tcg/tb-maint.c @@ -509,20 +509,20 @@ static gint tb_page_addr_cmp(gconstpointer ap, gconstpointer bp, gpointer udata) } /* - * Lock a range of pages ([@start,@end[) as well as the pages of all + * Lock a range of pages ([@start,@last]) as well as the pages of all * intersecting TBs. * Locking order: acquire locks in ascending order of page index. */ static struct page_collection *page_collection_lock(tb_page_addr_t start, - tb_page_addr_t end) + tb_page_addr_t last) { struct page_collection *set = g_malloc(sizeof(*set)); tb_page_addr_t index; PageDesc *pd; start >>= TARGET_PAGE_BITS; - end >>= TARGET_PAGE_BITS; - g_assert(start <= end); + last >>= TARGET_PAGE_BITS; + g_assert(start <= last); set->tree = g_tree_new_full(tb_page_addr_cmp, NULL, NULL, page_entry_destroy); @@ -532,7 +532,7 @@ static struct page_collection *page_collection_lock(tb_page_addr_t start, retry: g_tree_foreach(set->tree, page_entry_lock, NULL); - for (index = start; index <= end; index++) { + for (index = start; index <= last; index++) { TranslationBlock *tb; PageForEachNext n; @@ -1152,7 +1152,7 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages, void tb_invalidate_phys_page(tb_page_addr_t addr) { struct page_collection *pages; - tb_page_addr_t start, end; + tb_page_addr_t start, last; PageDesc *p; p = page_find(addr >> TARGET_PAGE_BITS); @@ -1161,9 +1161,9 @@ void tb_invalidate_phys_page(tb_page_addr_t addr) } start = addr & TARGET_PAGE_MASK; - end = start + TARGET_PAGE_SIZE; - pages = page_collection_lock(start, end); - tb_invalidate_phys_page_range__locked(pages, p, start, end, 0); + last = addr | ~TARGET_PAGE_MASK; + pages = page_collection_lock(start, last); + tb_invalidate_phys_page_range__locked(pages, p, start, last + 1, 0); page_collection_unlock(pages); } @@ -1179,7 +1179,7 @@ void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end) struct page_collection *pages; tb_page_addr_t next; - pages = page_collection_lock(start, end); + pages = page_collection_lock(start, end - 1); for (next = (start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; start < end; start = next, next += TARGET_PAGE_SIZE) { @@ -1224,7 +1224,7 @@ void tb_invalidate_phys_range_fast(ram_addr_t ram_addr, { struct page_collection *pages; - pages = page_collection_lock(ram_addr, ram_addr + size); + pages = page_collection_lock(ram_addr, ram_addr + size - 1); tb_invalidate_phys_page_fast__locked(pages, ram_addr, size, retaddr); page_collection_unlock(pages); } From patchwork Mon Mar 6 02:13:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 659234 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp1598737wrb; Sun, 5 Mar 2023 18:14:43 -0800 (PST) X-Google-Smtp-Source: AK7set8v+isDyf40b2nyD4z/rRckoEdR2bTqPgbYpfZH6EfG6WO1vfAjARyc/RJVac5+s1TLEou/ X-Received: by 2002:a05:622a:46:b0:3b8:6a20:675e with SMTP id y6-20020a05622a004600b003b86a20675emr16456058qtw.29.1678068883617; Sun, 05 Mar 2023 18:14:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678068883; cv=none; d=google.com; s=arc-20160816; b=rToz6zyBMIirLP7Epw2Oye+2bYImimvp+YwIPFoTTACyjE63FOCNUtQFrWD9t6aFBg p6wUy5m110M0RmtGokB0zJZaL5EA5c8VOrQD4ADnOQkzX+BV8Q0ZtMaL3BFycMtDTNMF 9QrfG8ylYe/Nw5yiObf/7BN4ZZGnSqTy7hRCHjdQj4Ch2IMqLigFuqCAS7wLbDnNIN3u f2V5i/t3VOSorOMT7i2DZGM897T1D0vS3Kv7wbVsxIPr6flKdUfkS660I43m8101UWQk ISUna9bQi+wUN7NKkP+dAxuArdxw/CnXbkG7ecpilclGSnxtTZ/dpBoLbz+AZs6H8SIQ oAag== 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:to:from :dkim-signature; bh=hueqYlY00i1W4vP3ESdohw7VNMjowjLFHkyPNqqchh8=; b=cOVmgYl7s2gL+LXNJ/yoFIUCxYzpVOAygPot7ZKSaQevxRxUfwSbbS2HNVYUSYbS8M z7LcOliQaIQwBp6f1hmbQ/PSaURDZEAE8SVb58yk/7FDdMhKZasPtv2OJnKItk2ik+jJ NdSTV5ySGEMKEA25kbFhIkrtotUH2CYoj/8Tsw1MseqLwEaIIv8NkgO1TP8d/2yZg6PW t1ExK5DFrP6fu/dKK1NWOCvRqo9KNs3i5IflPzOj15o1Xy8BuVRK9PKv6TcauyhszkmZ aMq/vh9XP2TIFjxMw68mA8pDuHcNyz+jbdi+uKOKUg3Y4NuCC5wvKUeNUEO7ifI2J7rH sgug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L7sEcQ+g; 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 n16-20020a05622a11d000b003bcf7d8df93si6193258qtk.431.2023.03.05.18.14.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 05 Mar 2023 18:14:43 -0800 (PST) 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=L7sEcQ+g; 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 1pZ0Lp-0003PU-8X; Sun, 05 Mar 2023 21:13:21 -0500 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 1pZ0Lm-0003My-Tg for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:18 -0500 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pZ0Ll-00062c-5a for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:18 -0500 Received: by mail-pj1-x102e.google.com with SMTP id cp7-20020a17090afb8700b0023756229427so11733897pjb.1 for ; Sun, 05 Mar 2023 18:13:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678068796; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=hueqYlY00i1W4vP3ESdohw7VNMjowjLFHkyPNqqchh8=; b=L7sEcQ+g15DfEM5vfV2YcrIPLAB7rLnVn+yC5NOreQ3KoxvRVvvrL2hCIiIw3OV674 ecsR2Wu8KYut9J09F1kLtLEEBot/7FcycLpSqmEkRBEi4GiL4BbrEQZGamxVVjNBEg6n zkEfuNNkA0whES8D5VB9gk6wyR4Ti6pppdqHs9T+TWoTTe2NiP9mgigKuId/G95T8hFX nkoWYBDaNXGwlEa1LII08CWCLTPAE775YY6KIJTkYWYf1lJpUAa8W+bkRAHSoclhbWe3 ctQo1AXxHRp/I+nv3YMztoruB3Je4QTOUeIuoIb2rkbmVs+5slXnY2CN7Fv2VvEOXAC/ XQ3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678068796; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hueqYlY00i1W4vP3ESdohw7VNMjowjLFHkyPNqqchh8=; b=PIq47nVlaqCjmMmiljGGLUMtYc3mVIflK02+abeYXxmqAshohEXxRiDOefFsu1xglt ZGM//QKZjM8vljzQnrUA9IFe52malsl0r6aaTKCfgWIJkjrodwlbNRfPahTGCR1GPSY2 g+D/vuqAFQVLde/WnRBr1FCezAQ0ZfmSZW8E3tnX6AU5X5dEKHGVHErL/mnlYwGVxhcS LWlnlfuuBKEhffgg6YrpEy4g5VeACCLb9o2mhv54hG/mW93d2OiwlmAFX9fV/QFPTKJI Lpwf6TTeM96VmOtZZ45bQKAKpnC8aflHrWR+U2HHbDqWeUN+yfBg4VRjEjJcskVwooIc l7UQ== X-Gm-Message-State: AO0yUKUAkydmJlTpvRAS0drPDrpB1LNS0AtUDnFjl8/rIVA8sjI4FbHW PQJWbxyetNXBOiSsIOuZyNzCKSiVBq22K9ago0g48A== X-Received: by 2002:a05:6a20:12d4:b0:cc:beae:c2c2 with SMTP id v20-20020a056a2012d400b000ccbeaec2c2mr11047746pzg.1.1678068795739; Sun, 05 Mar 2023 18:13:15 -0800 (PST) Received: from stoup.. ([2602:ae:154a:9f01:87cc:49bb:2900:c08b]) by smtp.gmail.com with ESMTPSA id d18-20020a630e12000000b005030136314dsm5048434pgl.71.2023.03.05.18.13.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 18:13:15 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 8/9] accel/tcg: Pass last not end to tb_invalidate_phys_page_range__locked Date: Sun, 5 Mar 2023 18:13:06 -0800 Message-Id: <20230306021307.1879483-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306021307.1879483-1-richard.henderson@linaro.org> References: <20230306021307.1879483-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.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. Properly truncate tb_last to the end of the page; the comment about tb_end being past the end of the page being ok is not correct, considering overflow. Signed-off-by: Richard Henderson --- accel/tcg/tb-maint.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c index c4e15c5591..a93c4c3ef7 100644 --- a/accel/tcg/tb-maint.c +++ b/accel/tcg/tb-maint.c @@ -1082,35 +1082,33 @@ bool tb_invalidate_phys_page_unwind(tb_page_addr_t addr, uintptr_t pc) static void tb_invalidate_phys_page_range__locked(struct page_collection *pages, PageDesc *p, tb_page_addr_t start, - tb_page_addr_t end, + tb_page_addr_t last, uintptr_t retaddr) { TranslationBlock *tb; - tb_page_addr_t tb_start, tb_end; PageForEachNext n; #ifdef TARGET_HAS_PRECISE_SMC bool current_tb_modified = false; TranslationBlock *current_tb = retaddr ? tcg_tb_lookup(retaddr) : NULL; #endif /* TARGET_HAS_PRECISE_SMC */ - tb_page_addr_t last G_GNUC_UNUSED = end - 1; /* - * We remove all the TBs in the range [start, end[. + * We remove all the TBs in the range [start, last]. * XXX: see if in some cases it could be faster to invalidate all the code */ PAGE_FOR_EACH_TB(start, last, p, tb, n) { + tb_page_addr_t tb_start, tb_last; + /* NOTE: this is subtle as a TB may span two physical pages */ + tb_start = tb_page_addr0(tb); + tb_last = tb_start + tb->size - 1; if (n == 0) { - /* NOTE: tb_end may be after the end of the page, but - it is not a problem */ - tb_start = tb_page_addr0(tb); - tb_end = tb_start + tb->size; + tb_last = MIN(tb_last, tb_start | ~TARGET_PAGE_MASK); } else { tb_start = tb_page_addr1(tb); - tb_end = tb_start + ((tb_page_addr0(tb) + tb->size) - & ~TARGET_PAGE_MASK); + tb_last = tb_start + (tb_last & ~TARGET_PAGE_MASK); } - if (!(tb_end <= start || tb_start >= end)) { + if (!(tb_last < start || tb_start > last)) { #ifdef TARGET_HAS_PRECISE_SMC if (current_tb == tb && (tb_cflags(current_tb) & CF_COUNT_MASK) != 1) { @@ -1163,7 +1161,7 @@ void tb_invalidate_phys_page(tb_page_addr_t addr) start = addr & TARGET_PAGE_MASK; last = addr | ~TARGET_PAGE_MASK; pages = page_collection_lock(start, last); - tb_invalidate_phys_page_range__locked(pages, p, start, last + 1, 0); + tb_invalidate_phys_page_range__locked(pages, p, start, last, 0); page_collection_unlock(pages); } @@ -1190,7 +1188,7 @@ void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end) continue; } assert_page_locked(pd); - tb_invalidate_phys_page_range__locked(pages, pd, start, bound, 0); + tb_invalidate_phys_page_range__locked(pages, pd, start, bound - 1, 0); } page_collection_unlock(pages); } @@ -1210,7 +1208,7 @@ static void tb_invalidate_phys_page_fast__locked(struct page_collection *pages, } assert_page_locked(p); - tb_invalidate_phys_page_range__locked(pages, p, start, start + len, ra); + tb_invalidate_phys_page_range__locked(pages, p, start, start + len - 1, ra); } /* From patchwork Mon Mar 6 02:13:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 659235 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp1598792wrb; Sun, 5 Mar 2023 18:14:57 -0800 (PST) X-Google-Smtp-Source: AK7set8Iwj3hAZ1LCVSKH/PIpKoZpmV8IacfjPUCRUaiJT6/4PPZ7NNxCzY1vUnO2awqs2PH7deO X-Received: by 2002:ac8:4e86:0:b0:3bf:ca3d:6757 with SMTP id 6-20020ac84e86000000b003bfca3d6757mr16963094qtp.66.1678068897249; Sun, 05 Mar 2023 18:14:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678068897; cv=none; d=google.com; s=arc-20160816; b=Led9FtAKz2FaRwtRMIWq2yYYdl4AT5uqaqgygDvYKPS7hLQA4KHShOL7VKmgyvcJtv Pm9aEhl/FT8b7bIYABSM+TbieUYuOkVH3/mU6Zp4wCTIMeiT2OHGrS/gNh2mhn9u2j/z sccby0yvlmzDSwFKYM0Cqwdw8z0DG+q1igLv5g5CKGIFbyVDTPxnJIOBldjgSCXQ37h2 z+6aN/eTCeRTjj1Tw6ba2tzapJdpNASPRewKrhGZr00415wVxj8tnH1VgS2Mdm4PT4Xo E4C8DhLva28fgvpJcjE1s2ecv30ECGlKZ90rigt4ZgWwydN/V6mazw7BsZ8Dc9TT9vIw 1Gog== 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:to:from :dkim-signature; bh=QVanyJTWx9kYUSCDwvXPA8IbvB2BsZd8rvitNx43raw=; b=EBdVSvGJIoBYHZ8o6P7cDoJqzIyYYQAzVQKccr9uNrQuimefSRrL9N1NtDFoqQI4yC gpq5TdFs5i19Z3I4sF+w1x0jc4LOkfuRj5GuiFFvsQwvO87N8jXWNc912ldZZYPyB+Ew SXJymBet/ENz5sXtik/GgJ/HkrZju/P3ZRwNggcP60E5OFZfr+AczsN0qwoxOEUlviJE Gjwcf3V8IgGu2/iCfI7wnlPum/hqkXOD4d2Oz76X3r6R78ZbnMZG5wjIXIAIubzLBXw/ s2j5rLJxksWcikPYCwJc19JXmf0IbNFtX2Pq67X6lD2C3Hg0UX2vwNvY+inIXJvJFzyE TjGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ayvQl+8Y; 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 x28-20020a05620a0b5c00b00742b61e6693si6079178qkg.308.2023.03.05.18.14.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 05 Mar 2023 18:14:57 -0800 (PST) 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=ayvQl+8Y; 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 1pZ0Lq-0003RK-0k; Sun, 05 Mar 2023 21:13:22 -0500 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 1pZ0Ln-0003Nh-QG for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:19 -0500 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pZ0Ll-00062m-RL for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:19 -0500 Received: by mail-pj1-x102c.google.com with SMTP id ce8-20020a17090aff0800b0023a61cff2c6so6513085pjb.0 for ; Sun, 05 Mar 2023 18:13:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678068796; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=QVanyJTWx9kYUSCDwvXPA8IbvB2BsZd8rvitNx43raw=; b=ayvQl+8YGbvYwzu2VfbWJMzKY8re4mA2CxS2K3aBpu72UB+sqLcOYucprBaDy5ys4H kmLv9nZoKvU3GV4bk5S6rbtM9tflB16OlU+3GgC7gPbNMVEUxsvl1Tsbew7g6JtYhY5a R8YRWJDsvb76J3sw4bZaYeauBSwG7qZEYgM3Zn3RhC/KsyujDfGhfqxTzSyGjPK1tQ5O v3cxxr2j/mwKOXf15QWyw4hH7o3PsQ2gmawAUY54DqzII3sIXEEyScu29zIRPK5kf+ma i6n+2hIKCTpx4YuflWG8sxfLXdTGEt0rJx+rywYP4c2cUlEGKo+fW+zbQNKCuCgkNUuw N2/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678068796; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QVanyJTWx9kYUSCDwvXPA8IbvB2BsZd8rvitNx43raw=; b=NeYKWKsI39uXSv+g2EzRD0ft3tO0caQbkKuk2dq21P+clC7lpTuYNWJdcHzmr3skvi 9kiIvEy5q2uzoLgI7yuFGksiwDNanZMNSmw1iCLzYTQJmO2EBdHMya0Qcpg1sBkS77iX n1VOUk4B6/oIEXensCPYvFbJEL7OE528YFsZrCyY7fAGYlVk2nODGr10GFhDA+PEqnO4 D5dEUNgCxsiOYzYtwHbr0Jdm5Ps5/VmVVcEqLfE9+EsUgj8POPGpDQXA5Bs/Qp/XAsfA sxbbLXFYrYktoEBJiRj+ZPhrid3VWWjFT5YMhJnqUVNljuqXVBE93qybRxYk3Ags8VhE Ybgw== X-Gm-Message-State: AO0yUKUePve9jWExzCDhewZjRXQjZuBHEOwsZZ7bgUq6D1S/yQHHIKwI 7Zk6oTj2FnCFV4/CW3V+DI31/noUfoPrkZi8tdxwpg== X-Received: by 2002:a05:6a20:a021:b0:ad:def6:af3 with SMTP id p33-20020a056a20a02100b000addef60af3mr8494129pzj.57.1678068796563; Sun, 05 Mar 2023 18:13:16 -0800 (PST) Received: from stoup.. ([2602:ae:154a:9f01:87cc:49bb:2900:c08b]) by smtp.gmail.com with ESMTPSA id d18-20020a630e12000000b005030136314dsm5048434pgl.71.2023.03.05.18.13.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 18:13:16 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 9/9] accel/tcg: Pass last not end to tb_invalidate_phys_range Date: Sun, 5 Mar 2023 18:13:07 -0800 Message-Id: <20230306021307.1879483-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306021307.1879483-1-richard.henderson@linaro.org> References: <20230306021307.1879483-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.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. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- include/exec/exec-all.h | 2 +- accel/tcg/tb-maint.c | 31 ++++++++++++++++--------------- accel/tcg/translate-all.c | 2 +- accel/tcg/user-exec.c | 2 +- softmmu/physmem.c | 2 +- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index e09254333d..58d37276d9 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -679,7 +679,7 @@ void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs); #endif void tb_flush(CPUState *cpu); void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr); -void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end); +void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t last); void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr); /* GETPC is the true target of the return instruction that we'll execute. */ diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c index a93c4c3ef7..19f88fd048 100644 --- a/accel/tcg/tb-maint.c +++ b/accel/tcg/tb-maint.c @@ -989,11 +989,10 @@ TranslationBlock *tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc, * Called with mmap_lock held for user-mode emulation. * NOTE: this function must not be called while a TB is running. */ -void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end) +void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t last) { TranslationBlock *tb; PageForEachNext n; - tb_page_addr_t last = end - 1; assert_memory_lock(); @@ -1009,11 +1008,11 @@ void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end) */ void tb_invalidate_phys_page(tb_page_addr_t addr) { - tb_page_addr_t start, end; + tb_page_addr_t start, last; start = addr & TARGET_PAGE_MASK; - end = start + TARGET_PAGE_SIZE; - tb_invalidate_phys_range(start, end); + last = addr | ~TARGET_PAGE_MASK; + tb_invalidate_phys_range(start, last); } /* @@ -1167,28 +1166,30 @@ void tb_invalidate_phys_page(tb_page_addr_t addr) /* * Invalidate all TBs which intersect with the target physical address range - * [start;end[. NOTE: start and end may refer to *different* physical pages. + * [start;last]. NOTE: start and end may refer to *different* physical pages. * 'is_cpu_write_access' should be true if called from a real cpu write * access: the virtual CPU will exit the current TB if code is modified inside * this TB. */ -void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end) +void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t last) { struct page_collection *pages; - tb_page_addr_t next; + tb_page_addr_t index, index_last; - pages = page_collection_lock(start, end - 1); - for (next = (start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; - start < end; - start = next, next += TARGET_PAGE_SIZE) { - PageDesc *pd = page_find(start >> TARGET_PAGE_BITS); - tb_page_addr_t bound = MIN(next, end); + pages = page_collection_lock(start, last); + + index_last = last >> TARGET_PAGE_BITS; + for (index = start >> TARGET_PAGE_BITS; index <= index_last; index++) { + PageDesc *pd = page_find(index); + tb_page_addr_t bound; if (pd == NULL) { continue; } assert_page_locked(pd); - tb_invalidate_phys_page_range__locked(pages, pd, start, bound - 1, 0); + bound = (index << TARGET_PAGE_BITS) | ~TARGET_PAGE_MASK; + bound = MIN(bound, last); + tb_invalidate_phys_page_range__locked(pages, pd, start, bound, 0); } page_collection_unlock(pages); } diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 4b5abc0f44..4500d78a16 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -570,7 +570,7 @@ void tb_check_watchpoint(CPUState *cpu, uintptr_t retaddr) cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags); addr = get_page_addr_code(env, pc); if (addr != -1) { - tb_invalidate_phys_range(addr, addr + 1); + tb_invalidate_phys_range(addr, addr); } } } diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 20b6fc2f6e..a7e0c3e2f4 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -516,7 +516,7 @@ void page_set_flags(target_ulong start, target_ulong last, int flags) ~(reset ? 0 : PAGE_STICKY)); } if (inval_tb) { - tb_invalidate_phys_range(start, last + 1); + tb_invalidate_phys_range(start, last); } } diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 47143edb4f..abebf5b963 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2521,7 +2521,7 @@ static void invalidate_and_set_dirty(MemoryRegion *mr, hwaddr addr, } if (dirty_log_mask & (1 << DIRTY_MEMORY_CODE)) { assert(tcg_enabled()); - tb_invalidate_phys_range(addr, addr + length); + tb_invalidate_phys_range(addr, addr + length - 1); dirty_log_mask &= ~(1 << DIRTY_MEMORY_CODE); } cpu_physical_memory_set_dirty_range(addr, length, dirty_log_mask);