From patchwork Fri Mar 17 15:54:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 664551 Delivered-To: patch@linaro.org Received: by 2002:a5d:5602:0:0:0:0:0 with SMTP id l2csp476099wrv; Fri, 17 Mar 2023 08:57:02 -0700 (PDT) X-Google-Smtp-Source: AK7set/Us7guXDFMUbLl2cChQ0TV5Az4onNSQIV/kPS3U2Cdwu5JN7V8j33zy8Sa/M8472lIAQKk X-Received: by 2002:a05:6214:76f:b0:5a3:2f3c:4ee2 with SMTP id f15-20020a056214076f00b005a32f3c4ee2mr36906880qvz.42.1679068621831; Fri, 17 Mar 2023 08:57:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679068621; cv=none; d=google.com; s=arc-20160816; b=s1tjP8dz2l9skBgOctx3H9hNvo5YEVq/RgSKGL31KZxE/1lLariHVzOlWAUF5fPXi0 cQO3pxzUWGwvXBuvDRcMQ/AhWXPs1jhpX0jhatFndVG/3Ur8dXv+760fnsklNqbsCZEO EeTFnPSBqb9wZjBLx80wHX+z1g5i2q4BiWEOQcVfWbpPql3W3t/ga0pzt8oASC5T0VWY KMA65iBUwcrA/CP/BTrgLdbfqYuKH/8GqTSpVPeLzp7kjub7gg6e7A4Op61NWyQSq5DO Z9mzrbLe+BZ09T4hs7VcQa/XPtYHhTNzNLXrU7NYNXAx3dWqxiGKwoTm8v2ohJtYq97l OGkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=askS0DPb36wWSlWBcou6AQU6SXy8h0tFjS5nQCc6vaA=; b=a+09oRxcw0HxK4cEuc7VSJ66CmO8HTpBTlCawVFgAXPjO5BzHKiHyAnfQ7MPNsE8Qo qUjZ0T2O/y/lpqbMNRalOG2f7dBpXNhKjymYnaUYoaepeuTojuXPh1geHgegAXlSNFcx Yc1FpstkFA4Fav14bVvkS7GGiRIyBTOqnaQvBHOteD/OH3mOSxO+YKYQxLLZCkrdSC5/ PiGiJLSj3Iy9joMw/9z7ntti4p3R4MgJgYeDFvr+S5EvEfCLzfPTtxL3BymEb45T0/vf rc9m1fq1tX9Orb7jcRkjavxjl4Ziw/WC4Mq0oZAM8cYdB4U+UQJxk6I7m3k3fR9nByIt hmXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Vfp4xpx/"; 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 q93-20020a0c9166000000b0056e9a79e18asi1590242qvq.148.2023.03.17.08.57.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 17 Mar 2023 08:57:01 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Vfp4xpx/"; 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 1pdCQ6-0002l0-8K; Fri, 17 Mar 2023 11:55:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdCQ4-0002kY-IM for qemu-devel@nongnu.org; Fri, 17 Mar 2023 11:55:04 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdCQ2-0007n4-Jc for qemu-devel@nongnu.org; Fri, 17 Mar 2023 11:55:04 -0400 Received: by mail-pl1-x633.google.com with SMTP id a2so5743343plm.4 for ; Fri, 17 Mar 2023 08:55:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679068499; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=askS0DPb36wWSlWBcou6AQU6SXy8h0tFjS5nQCc6vaA=; b=Vfp4xpx/71EHcr8FctyahoeNr5bWU0tU84bZownV+f77nW87XfsVYEm1nmdoWGcDiS zKqNMtfGxW2DVeU4srp/v+XKtzHYzUm2ULHcKNWChbU6EP/+kU8LrNk903jJoevoR80T Yq5TyLX2wJR4k/2u+566lWIJv0SG/xF7WxprXxTDefl9TaysN0D6kLUCudUX4O542b1A gpuGmZXrMOYHfzlD4fx4Yyn7m60OaTMixarj5fXFgz35Hk+AzWiUDRZSdNlj/oJBby+a PA5rObGnN0t1UqFYkqlL/VtNOM3ibiM6C04zvcy/ZMYrb/o79eQvu+PkSX5ehBrxg9Jj KZVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679068499; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=askS0DPb36wWSlWBcou6AQU6SXy8h0tFjS5nQCc6vaA=; b=7OYLMYmk6b5w3UdUFGDsxpvS8eP1hzrI4dGlMxJ94BxYJXlesSvlVqs3ri2NH2Ngs+ SWjxfiDRyfGvQAwRoSvRorvNsUr/APsYuaXLzcWFGnz8oRYbyTKZnOFVUgBAga7Sl9J2 Zwc7cUAc7/n9S1bcQFlqwbN5gI184xnZXwF6AXyOXvurNMWyrBI9dLxzpu2GQ82DG2cM qx7qYlzPO0JBcH71ZabuJV+JSEi+IFNQjXprEnKKd42DhqRGWMb5cNdj6TzFgfSQaAoC WSQHr9+3wBiUaptxRVpDjXfKMCc9h613Eh/xoZLJX89v0fDauyR/0hwjWhQLAwZk159/ T3YA== X-Gm-Message-State: AO0yUKUsVEQe5uuiAp8Hyj06/glh1UL9sD0+JC9lVjQVLT79/N/33JMR okLxeV7c2RF+OXbOjpVoEWISBX09KIIuezkO38A= X-Received: by 2002:a05:6a20:158e:b0:d4:c806:bdc0 with SMTP id h14-20020a056a20158e00b000d4c806bdc0mr9513037pzj.17.1679068499470; Fri, 17 Mar 2023 08:54:59 -0700 (PDT) Received: from stoup.. (96-82-119-43-static.hfc.comcastbusiness.net. [96.82.119.43]) by smtp.gmail.com with ESMTPSA id s5-20020a656445000000b004fb3e5681cesm1668986pgv.20.2023.03.17.08.54.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 08:54:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org Subject: [PATCH v2 1/9] linux-user: Diagnose misaligned -R size Date: Fri, 17 Mar 2023 08:54:47 -0700 Message-Id: <20230317155455.341843-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230317155455.341843-1-richard.henderson@linaro.org> References: <20230317155455.341843-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.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 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 Reviewed-by: Philippe Mathieu-Daudé --- linux-user/main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/linux-user/main.c b/linux-user/main.c index 4b18461969..39d9bd4d7a 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -793,6 +793,12 @@ int main(int argc, char **argv, char **envp) */ max_reserved_va = MAX_RESERVED_VA(cpu); if (reserved_va != 0) { + if (reserved_va % qemu_host_page_size) { + char *s = size_to_str(qemu_host_page_size); + fprintf(stderr, "Reserved virtual address not aligned mod %s\n", s); + g_free(s); + exit(EXIT_FAILURE); + } if (max_reserved_va && reserved_va > max_reserved_va) { fprintf(stderr, "Reserved virtual address too big\n"); exit(EXIT_FAILURE); From patchwork Fri Mar 17 15:54:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 664553 Delivered-To: patch@linaro.org Received: by 2002:a5d:5602:0:0:0:0:0 with SMTP id l2csp476215wrv; Fri, 17 Mar 2023 08:57:19 -0700 (PDT) X-Google-Smtp-Source: AK7set+XXB5HpSA+9YqZSqXlPg92PahO93xq123Z1UqSfVXFziDT2qcrudialSbTHza52bYVEPx5 X-Received: by 2002:ac8:5b87:0:b0:3b9:bcac:725b with SMTP id a7-20020ac85b87000000b003b9bcac725bmr14892070qta.22.1679068639323; Fri, 17 Mar 2023 08:57:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679068639; cv=none; d=google.com; s=arc-20160816; b=bZqqzz6l69IG4vPt9tDAhuulcN9esSVxVWfqmnfBFT9R8bDbM8xpTN8Ly+4tP4IIDR isnjKBTYC71EbRPArrpYViZZyDA9+5ut1FvpPqU5l+UXe1pfsEG+vaQHKjVM+ZiC7EGz TBQMYAIKZZ/9n9vZjHSe7YULQPzgf71/Bkqp4nP1yaQiEt2xm4ZUDWS93d4Vq/tclpKH rHV+yEKzrjJ+je+v+Esi9/CuwuCaKBN97bVzO+ygMFjYCzriZCVojrT7AzKGPYnd/LDZ /92UR4dT/hTXYwTkQ5OaQYaI5XMv0wWVvxmbdWKB5wW7+EqxMOXAkd0QSazM8cYTSaXm tyIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1Yi3XUo5Vyf7hVJ/JS7sYht8qm15aoRnWJkMV/b7vTc=; b=Bo/P+gqFjZqt9oR+MrWfqKnWiaaiQdGyqoCGdW1TT7ZqhZPhCahn07yEt8O3hKETcv frEllsNozVYbAJHGYAIGSea67TM4fP1+L3DApolLBfpsAqj7grKsAuQ9hcUu/qSJj5FJ BTdKYpJZKfzcy9avEddxq5fy7TDuFr9logy+NA2aiMzxoFU1+PdbbQaCI8bbzxw1/rmR 83hEY4ERwBRtL4j6HBt7NM0Hc7mg+i+KpiU2xfDiIhzJ+m+AytussQWow1FxuZlTlCbI dFglSsFJiqQmkzehMKeNLXbiLCGqSdc0mbcxTygGJlaPETT+K6CuQD91+twtSJHR/7n1 ob+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lYoiECYs; 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 x6-20020ac85f06000000b003c0405ae377si1593582qta.387.2023.03.17.08.57.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 17 Mar 2023 08:57:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lYoiECYs; 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 1pdCQ7-0002lX-8d; Fri, 17 Mar 2023 11:55:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdCQ4-0002ki-RG for qemu-devel@nongnu.org; Fri, 17 Mar 2023 11:55:04 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdCQ3-0007nN-3I for qemu-devel@nongnu.org; Fri, 17 Mar 2023 11:55:04 -0400 Received: by mail-pj1-x1036.google.com with SMTP id d13so5660538pjh.0 for ; Fri, 17 Mar 2023 08:55:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679068501; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1Yi3XUo5Vyf7hVJ/JS7sYht8qm15aoRnWJkMV/b7vTc=; b=lYoiECYsPP4RrlccSMV7O/YZ539XKgDMJwqThJttWV86Y52qxWIsoRY6/FAMruz7sX RPxIa+/8+N320KzecHUWO17pjWzjYCOKgs7jRW/6hDdxYqYryYmurYMvSkNOIRXD0nkD 7Y9NNw/nXoIypDJipltZ8v6z91vDYbsUgjc0J+YGqcnLpoIg/vqczbepMdXk5ovWH3+D swXQRXIH3dLPYqTPJNrXrJze0yyoS3bty92uXmMAcUFHsr3ITlrbq5IXUgGUZF9xxEMB I8/KV55piuM6Ms6SFQ6g37sIjP5l9VNs7Z0NwYQIEz3dnhEnZER1xb2NZccIyHWKb667 7ZlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679068501; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1Yi3XUo5Vyf7hVJ/JS7sYht8qm15aoRnWJkMV/b7vTc=; b=4o0QLSnOo+j3v6ESwz4XcmOP0M0aspUxcl5wN1eTwwIhABcGPmYaGzz7hkChUa7DFc 4jCosZarRQJE/O023MB5AfnuP9+Et3SVN/ttbNzG+Q3ik8BeiszBnPhhzjzG83XC5BxX iQkW8Aam6g/RHBPKLdYeKGWtW3baU9aUqqNMHIGVx8s5T3OMQPt+T58YlUabiOZnLjIj nP0DXoHp0nQym3Sk3YtEWQdfB17Xx8m6wVTqKa36RCpZUsFpgxdFJTjjIx4KZHhPlYsp NChtccCIZNlkdHmvep7fUxZizdnq7e7JYXgT6Yk/Bt3hrGYjXhJOMEeHKGillEYFes0S XeRA== X-Gm-Message-State: AO0yUKUf7H0LH2nGPT51rV01WfnC3//TIXMzhGkCFW2wHqXSFWGY78JM 0qx8zcnpPDvJrbd6w61JaKG3adwwZC1+tH5T+tU= X-Received: by 2002:a05:6a20:3b98:b0:d4:298b:8b8e with SMTP id b24-20020a056a203b9800b000d4298b8b8emr7697097pzh.33.1679068501311; Fri, 17 Mar 2023 08:55:01 -0700 (PDT) Received: from stoup.. (96-82-119-43-static.hfc.comcastbusiness.net. [96.82.119.43]) by smtp.gmail.com with ESMTPSA id s5-20020a656445000000b004fb3e5681cesm1668986pgv.20.2023.03.17.08.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 08:55:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 2/9] linux-user: Rename max_reserved_va in main Date: Fri, 17 Mar 2023 08:54:48 -0700 Message-Id: <20230317155455.341843-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230317155455.341843-1-richard.henderson@linaro.org> References: <20230317155455.341843-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.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_rva, to avoid a conflict with the next patch. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- 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 39d9bd4d7a..165fcb653e 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_rva; bool preserve_argv0; error_init(argv[0]); @@ -791,7 +791,7 @@ 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_rva = MAX_RESERVED_VA(cpu); if (reserved_va != 0) { if (reserved_va % qemu_host_page_size) { char *s = size_to_str(qemu_host_page_size); @@ -799,7 +799,7 @@ int main(int argc, char **argv, char **envp) g_free(s); exit(EXIT_FAILURE); } - if (max_reserved_va && reserved_va > max_reserved_va) { + if (local_max_rva && reserved_va > local_max_rva) { fprintf(stderr, "Reserved virtual address too big\n"); exit(EXIT_FAILURE); } @@ -808,7 +808,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_rva & qemu_host_page_mask; } { From patchwork Fri Mar 17 15:54:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 664552 Delivered-To: patch@linaro.org Received: by 2002:a5d:5602:0:0:0:0:0 with SMTP id l2csp476134wrv; Fri, 17 Mar 2023 08:57:07 -0700 (PDT) X-Google-Smtp-Source: AK7set8BbbBsgcCJAa6A6+hIyp+mr7Zdn6XxcI0KaKtxC6VcDU4RHJuF4Sepr5p/KMBmGWVxrAv1 X-Received: by 2002:ac8:5912:0:b0:3da:19e3:e9fa with SMTP id 18-20020ac85912000000b003da19e3e9famr5762235qty.50.1679068627028; Fri, 17 Mar 2023 08:57:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679068627; cv=none; d=google.com; s=arc-20160816; b=bZiyVQVCmyJI2l7hdMBWWdHVaMBKsS/aa3Oyo/Af+sCyl1haIgo9pFChrOuG2KMxQX LBHAm6lvNCTJrDoinf/FRwcozXXp807Lspi/3MCPNCpm+HuWmF1ObmzVtRzV//R/wt6c k3hK0PluK8z1bfUpcwBc2u9UH8YJogm14NdeJF5t63GCGZkgrwQFwNoOUkg0F5D3fM+T 2lAixYN/MIpEc8sN1yfRAk1yeUymr9aJB5Ph5zS1sI7w+FQr5djV6QakhoErw32tgGKF nHmr/ZKYFihfMR3ps/ubLEpT0sEJ5UubA0PfTxCt0Zp/bfqZp+LNgjp06Wp+F0rqf6Ua ysJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=I9owQss9UZCzsc9lQ+V0tXQtxW2H7zxVA3/hV9MlxPE=; b=pmlcw1NHcryKCoJvVh4vbc1telsBqdSkJSf9a9mvZquOhuhyCdXfi5zcorqzvKmeD3 A2vNCw6Sh84HOm/HB82UxYITM0n/wqxeyhE/ME6Xz+pBHA4WiG01Dtk5aqSb0sk3QDyX dhh/q938tDR+X/Yamq1/OO1vBEvliCAPgxaKeXRK8k6Vp1sqiwgk10LhIrIzUemaAkYu 1hkXlRbnxVXb0Ez1dBO7dnYMt+ik+yW/fn63g+rO5uCwgNydma+z3Rp6Qg0JZZROXt88 RAPMSvHFDyCXBi+rnfGu7CDq/EV8s1rgvz/2Ka3TZo8JmFTp757fC91vPROW86y3QmAv 3oJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Km6f5Pkm; 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 l10-20020a05622a050a00b003bd16479330si1756933qtx.724.2023.03.17.08.57.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 17 Mar 2023 08:57:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Km6f5Pkm; 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 1pdCQ8-0002mA-Ez; Fri, 17 Mar 2023 11:55:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdCQ7-0002lO-36 for qemu-devel@nongnu.org; Fri, 17 Mar 2023 11:55:07 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdCQ4-0007st-2b for qemu-devel@nongnu.org; Fri, 17 Mar 2023 11:55:06 -0400 Received: by mail-pl1-x62b.google.com with SMTP id p20so5705028plw.13 for ; Fri, 17 Mar 2023 08:55:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679068502; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=I9owQss9UZCzsc9lQ+V0tXQtxW2H7zxVA3/hV9MlxPE=; b=Km6f5Pkmy+fpVzAVVLrr07bG55DSh0o0A6/yGjcDFtKeAdIsTJy+SH5KRzkRHdB+Ey 2cQhFne9hfi4sztLc5WiXL9HYwBHfOLZTBRiHr4Mt6wV/T2qJFYZci52K4rWtaw9UxzA ZAFQUsOBIUU8D4TZ+pRWznorRW4L6155Gvc+sA1FtfSocAEjCDXUALgqkDXUfKsXhK+V 6b0laCaEqzYLv0Cp1Z2Yve9QzeXm3+Bptu/TYMMmDn050cI2nkOcmaOxJUYuQVz2F3Kv AdKmK0VsoXQKHmQ2yc+0/qOqZ5gpdF3XZ3o0ZCHo/546TyISKeDgVZ+9+28DSHpOmljf agqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679068502; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I9owQss9UZCzsc9lQ+V0tXQtxW2H7zxVA3/hV9MlxPE=; b=WaUA/GxidPQeLxrpLhbW6Vlqi3/rsXzFuy2Tq+BUZkmQ1SBK6E7Iqa9+ciaRcxoPmG q6v+SFQp5stQnRTDT0Z2ye9kaxv4BXtXBzrSEnWn6g75hPyGAQgio8Y6hdHRZJSHDv8d vZhGIsSBDR2QBojeqSoDeG/SSLgV/bvv6AUcQOlD8CN1DJY18cQwnkdGVLkWB3v4XMxp 1YUhf62o2oclrrdGKOtGQZ9sPQ/oSxhXhB2HrplH8cw8ikDXq9BB1bgU5ZiYh9MeGOP+ 3alvvQNoEDr4+jevqekwJB74pQTuBN5WEpvv7q8dsbAOM5pUQvSllPILZZeXTBOdKDHf aqlg== X-Gm-Message-State: AO0yUKW91eO2m8mqdqvGjcx/1SEVOUIx0rLMBsuERZmhFpak/WWmb6ck M/0IGYyB5Qq0Cjs8gq7dgYkZ8VsnRY3Tg4zxryk= X-Received: by 2002:a17:902:da91:b0:1a1:818b:8cca with SMTP id j17-20020a170902da9100b001a1818b8ccamr9681774plx.43.1679068502495; Fri, 17 Mar 2023 08:55:02 -0700 (PDT) Received: from stoup.. (96-82-119-43-static.hfc.comcastbusiness.net. [96.82.119.43]) by smtp.gmail.com with ESMTPSA id s5-20020a656445000000b004fb3e5681cesm1668986pgv.20.2023.03.17.08.55.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 08:55:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org Subject: [PATCH v2 3/9] include/exec: Replace reserved_va with max_reserved_va Date: Fri, 17 Mar 2023 08:54:49 -0700 Message-Id: <20230317155455.341843-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230317155455.341843-1-richard.henderson@linaro.org> References: <20230317155455.341843-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.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 Reviewed-by: Philippe Mathieu-Daudé --- include/exec/cpu-all.h | 11 ++++++++++- linux-user/arm/target_cpu.h | 2 +- bsd-user/main.c | 10 +++------- bsd-user/mmap.c | 4 ++-- linux-user/elfload.c | 21 +++++++++++---------- linux-user/main.c | 27 +++++++++++++-------------- linux-user/mmap.c | 4 ++-- 7 files changed, 42 insertions(+), 37 deletions(-) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index 2eb1176538..51b6e8594e 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -152,6 +152,15 @@ static inline void tswap64s(uint64_t *s) */ extern uintptr_t guest_base; extern bool have_guest_base; + +/* + * 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 reserved_va; /* @@ -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 (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 89f225dead..babc3b009b 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -68,13 +68,9 @@ 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 @@ -466,7 +462,7 @@ int main(int argc, char **argv) envlist_free(envlist); if (reserved_va) { - mmap_next_start = reserved_va; + mmap_next_start = reserved_va + 1; } { diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index d6c5a344c9..d35650e562 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -234,7 +234,7 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size, size = HOST_PAGE_ALIGN(size) + alignment; end_addr = start + size; if (end_addr > reserved_va) { - end_addr = reserved_va; + end_addr = 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 = reserved_va + 1; addr = end_addr - qemu_host_page_size; looped = 1; continue; diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 150d1d4503..bb2001bf30 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -207,7 +207,7 @@ static bool init_guest_commpage(void) * has specified -R reserved_va, which would trigger an assert(). */ if (reserved_va != 0 && - TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE >= reserved_va) { + TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE - 1 > reserved_va) { error_report("Cannot allocate vsyscall page"); exit(EXIT_FAILURE); } @@ -2499,10 +2499,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 (guest_hiaddr - 1 > 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, + reserved_va); exit(EXIT_FAILURE); } } else { @@ -2523,7 +2524,7 @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr, if (reserved_va) { guest_loaddr = (guest_base >= mmap_min_addr ? 0 : mmap_min_addr - guest_base); - guest_hiaddr = reserved_va; + guest_hiaddr = reserved_va + 1; } /* Reserve the address space for the binary, or reserved_va. */ @@ -2750,15 +2751,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 > 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, 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, reserved_va + 1, align); /* osdep.h defines this as 0 if it's missing */ flags |= MAP_FIXED_NOREPLACE; @@ -2766,17 +2767,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, 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)", 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, reserved_va + 1); } void probe_guest_base(const char *image_name, abi_ulong guest_loaddr, diff --git a/linux-user/main.c b/linux-user/main.c index 165fcb653e..c1d17a1900 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -109,11 +109,9 @@ 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 @@ -379,7 +377,9 @@ static void handle_arg_reserved_va(const char *arg) { char *p; int shift = 0; - reserved_va = strtoul(arg, &p, 0); + unsigned long val; + + val = strtoul(arg, &p, 0); switch (*p) { case 'k': case 'K': @@ -393,10 +393,10 @@ static void handle_arg_reserved_va(const char *arg) break; } if (shift) { - unsigned long unshifted = reserved_va; + unsigned long unshifted = val; p++; - reserved_va <<= shift; - if (reserved_va >> shift != unshifted) { + val <<= shift; + if (val >> shift != unshifted) { fprintf(stderr, "Reserved virtual address too big\n"); exit(EXIT_FAILURE); } @@ -405,6 +405,8 @@ static void handle_arg_reserved_va(const char *arg) fprintf(stderr, "Unrecognised -R size suffix '%s'\n", p); exit(EXIT_FAILURE); } + /* The representation is size - 1, with 0 remaining "default". */ + reserved_va = val ? val - 1 : 0; } static void handle_arg_singlestep(const char *arg) @@ -793,7 +795,7 @@ int main(int argc, char **argv, char **envp) */ local_max_rva = MAX_RESERVED_VA(cpu); if (reserved_va != 0) { - if (reserved_va % qemu_host_page_size) { + if ((reserved_va + 1) % qemu_host_page_size) { char *s = size_to_str(qemu_host_page_size); fprintf(stderr, "Reserved virtual address not aligned mod %s\n", s); g_free(s); @@ -804,11 +806,8 @@ int main(int argc, char **argv, char **envp) 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_rva & qemu_host_page_mask; + /* MAX_RESERVED_VA + 1 is a large power of 2, so is aligned. */ + reserved_va = local_max_rva; } { diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 28135c9e6a..cf14930c30 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -283,7 +283,7 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size, end_addr = start + size; if (start > reserved_va - size) { /* Start at the top of the address space. */ - end_addr = ((reserved_va - size) & -align) + size; + end_addr = ((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 = ((reserved_va + 1 - size) & -align) + size; looped = true; } else { prot = page_get_flags(addr); From patchwork Fri Mar 17 15:54:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 664546 Delivered-To: patch@linaro.org Received: by 2002:a5d:5602:0:0:0:0:0 with SMTP id l2csp475449wrv; Fri, 17 Mar 2023 08:55:31 -0700 (PDT) X-Google-Smtp-Source: AK7set89ZkGdV/MG4WIqXpXkAW1ziKDsORydNm0Lp+1uWUgk8/o+2re7FvmJS34n+rNCqxhzK7V/ X-Received: by 2002:a05:622a:13ce:b0:3dc:6cf8:a974 with SMTP id p14-20020a05622a13ce00b003dc6cf8a974mr284634qtk.31.1679068531663; Fri, 17 Mar 2023 08:55:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679068531; cv=none; d=google.com; s=arc-20160816; b=jX5J4aA4Xt5TRh0nklsD3Tu3/iQJEsCFt5q4OvdaVZvWu8rewgJ+kmJW8O+yKU0Hzc adyrRna25UBNDVIDdtJkOFdsYNe+L6EiXFwDw4sreJxKj/5vJStuxEXkCsByFhO5BrET i5IEDgSLl0gHo0Rdx0FqaWEEOK5DoXaUNFO0fMCYo8k172CS0s3JWfmw671MEVZcAoMW mUnBnF426eCRY+RCSQO5epSAYZEvwg08CzRVPVEIgumwuEEAAe610RDoXLqpTF13wYCa thWsoo976DlQG1BhQSrqxU5PIGOMqinD6JRh2gjfAZhaZJVx5V0oNF39aAiLjSO7Eib5 p6tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=meugAyBTSueH3oE13gYo/cUR3KSAPAiW361uLsyfNwE=; b=ignBoc9cwcJXoMw5uIbGw8z7hrkhuVq1t9Q/CCDtkn/1mWCha5XBlHVY12K89LPavw MDF0DPP/QKHAbinBW2q+/538gkgNHEY6M9ZZi6AGJFrwvDONT4Q8l+nDMyLVedK7mID3 bgnq5acJWtRyC0BygrsQuoutgHzeRWHCinIV/8yyntyiPafbdsN2oqmLge4h4f+oXtB5 0WQ0R+49U2TxkHM1hg4Aa5pQbbZMU3Lg3jW4oUI5g6yQ3qHBkM4kwYhICUM4dFzJXnP8 euK7rAFrOhzVWuHSEmT7lMVKowVDunLkqJkC0bguCN2yIEEYRhljyQFzSIOg/PED+MbN yQfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iR4jXrPh; 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 p141-20020a374293000000b0073b84a0ab04si1785095qka.651.2023.03.17.08.55.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 17 Mar 2023 08:55:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iR4jXrPh; 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 1pdCQ9-0002mZ-DT; Fri, 17 Mar 2023 11:55:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdCQ7-0002lv-KV for qemu-devel@nongnu.org; Fri, 17 Mar 2023 11:55:07 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdCQ4-0007xw-VS for qemu-devel@nongnu.org; Fri, 17 Mar 2023 11:55:07 -0400 Received: by mail-pg1-x533.google.com with SMTP id y19so3163310pgk.5 for ; Fri, 17 Mar 2023 08:55:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679068503; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=meugAyBTSueH3oE13gYo/cUR3KSAPAiW361uLsyfNwE=; b=iR4jXrPhUXA2Z0ly4pfMxtGLwDIeln0EmI2TM0nCL5AiDfOxCU8ZimdyR4KT9Vp3td At25uZZulkN4vXubStFZpKvK+SQmex96nBK7LKOeJAgaj3pvSW3PkO1InjxJForDQGBh Z5JadvyXKShZZSdFUKQoCM/oKGk/hh3qCYZQxY1/cjBN4RfWMGs71Prz2s80sDvQXYpe tC6I9h39jmZWVFze5ka4dwYn1lIdALYbJFSn3jHND/rhpdFX8DGeZNwt5hpJbPVHU+rt 5pRaGCbFzgJntCOU4YYZK/fqAcoU4ir2RnyOuQR1zcrLMZqTs861GftuhTQ5kv1vYtXw PpNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679068503; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=meugAyBTSueH3oE13gYo/cUR3KSAPAiW361uLsyfNwE=; b=C+BFJtKnizac7pPeQjqsyiprZTdgbyGpQ+QzEWnfqtAwgLaRibDMRBtAwImKTax+dl XnK4Nu45sDHu3H51RqnH4YTbRGo8zRCoX5R8v2B0EiKUshs+zj0QxXZXpZhoIXIkLqEk aE9w0uv6Rm2SkFXPHj7ME8Qpg44breqf9ISzzaZPtX8VL41Aw/4AKhybSWRfz3iOeb/k aaDkzzkSa20zf05dC4ipJMtLgbvf5p+nLRHo8v3gBgvLd4WHtoGG4XLi4Z5nu9TnB1+h HaxnzRL9rrnsAPKh2emBbDV/Z+F7DuEW5bPAHp1wLoQpz69iZsMZ7fFgK8fcc5VbRq3s IwFQ== X-Gm-Message-State: AO0yUKXq+Jkbyll6bw3GdY/zWeix+D9Q4JVY6rGPEbZqNj7RtY45/u/p wY7XLmbZTKlU4/i1Ii/jGthhDmXGChD/ZcVzZ/s= X-Received: by 2002:aa7:8f37:0:b0:625:d875:5987 with SMTP id y23-20020aa78f37000000b00625d8755987mr7503986pfr.6.1679068503432; Fri, 17 Mar 2023 08:55:03 -0700 (PDT) Received: from stoup.. (96-82-119-43-static.hfc.comcastbusiness.net. [96.82.119.43]) by smtp.gmail.com with ESMTPSA id s5-20020a656445000000b004fb3e5681cesm1668986pgv.20.2023.03.17.08.55.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 08:55:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 4/9] accel/tcg: Pass last not end to page_set_flags Date: Fri, 17 Mar 2023 08:54:50 -0700 Message-Id: <20230317155455.341843-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230317155455.341843-1-richard.henderson@linaro.org> References: <20230317155455.341843-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x533.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 Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- 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 51b6e8594e..db38418d93 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 d35650e562..565b9f97ed 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 bb2001bf30..b068676340 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; } @@ -2208,7 +2208,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 cf14930c30..9c70f51d97 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 24cea6fb6a..7fbc664e83 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4594,7 +4594,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)); @@ -4624,7 +4624,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 Fri Mar 17 15:54:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 664554 Delivered-To: patch@linaro.org Received: by 2002:a5d:5602:0:0:0:0:0 with SMTP id l2csp476277wrv; Fri, 17 Mar 2023 08:57:25 -0700 (PDT) X-Google-Smtp-Source: AK7set9GalJWThTqekP+Gr9h0mEXu0qofzZFDw0jvjdqc9xGCrUKdGj2jPwmDU/v/uA8zp3zrIsc X-Received: by 2002:a05:6214:20c7:b0:5a3:725e:425c with SMTP id 7-20020a05621420c700b005a3725e425cmr44615295qve.2.1679068645786; Fri, 17 Mar 2023 08:57:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679068645; cv=none; d=google.com; s=arc-20160816; b=BJIRkz3F9kPrH5nkLWtxYKzxQmzvr0YYsdWaPYrP4FbFX/B1mWNVM3l+4OujzO5QgE HERBMugtB2keRn+fqPpG6Q2ay2hjpj4vcfIgYrJlLnlCwu2gNN10YgQkmJZBIlx+Q+32 8qbZU3TlpxJtFlJvVlaQjFBdDs4sQEAR/USkSAMvZy0ISwcPDFJOEREq2Hvr2449k7KX 9ItTO3IcwAYt1UVAQcF1rqSrtiCkuX/+m4bkZ6dmE0Z4ZVAa9xP+5qqX5M2NdKjo9ZiS HyApJs/uhz9gJWRwFx65R3vUOvgO9g7UO4uPUoq1qLV77WZQ5AKGScKy0tfoPMvM17wB AIpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VkbFN5DIOfLGyePi4iUQTqaZQlnmOIVGGAwI9RXEItE=; b=DRLzatuQf7j5TR4yuGNPr5EnpoMuj8xqbRvA0837VupDiP1gCaqciG4Z0JKRlunHj5 ym+nGZo4FyBWet1DFdz6xTnl84cNvMr+huzu1hBqU2BcLrmZFWp2sHNrf3TJ98YfZCzk HvUZ1SqBOuZibXg3wbw87rml2FzrnhjTeHqxEifAbfkyamjqOJYBuDXc5KdbH0s3TInJ nszD6jSLb7lmu1mjSRG1zz6FZlKA26QQkoh2B43juf7hwpc31Ff+8ORmEbRRunE3UA+Z yz3hOFLpPQ4Deun3z1S7gXwRb3CJkaRMsr8Mm0aMNNp3WiMzNKZKNz1ddWfY5FczJq2E BU8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WwLjmKIO; 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 64-20020a370443000000b00728570fe69asi2002519qke.281.2023.03.17.08.57.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 17 Mar 2023 08:57:25 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WwLjmKIO; 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 1pdCQA-0002mz-Kl; Fri, 17 Mar 2023 11:55:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdCQ8-0002mR-Vh for qemu-devel@nongnu.org; Fri, 17 Mar 2023 11:55:09 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdCQ6-0007yP-6r for qemu-devel@nongnu.org; Fri, 17 Mar 2023 11:55:08 -0400 Received: by mail-pj1-x102d.google.com with SMTP id o6-20020a17090a9f8600b0023f32869993so5663114pjp.1 for ; Fri, 17 Mar 2023 08:55:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679068504; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VkbFN5DIOfLGyePi4iUQTqaZQlnmOIVGGAwI9RXEItE=; b=WwLjmKIOhpaLzbX7LLaeGfdDtv+w4ip4iD0RV7NTl3UtaMmbhIgrFXTEAx5HSoIVOM zgLBDtxITSdz3XfGxadJEiZdwJtlv/EzZKQes3WspGXDduId2ro+duAIgj6Ts3kChkku w8+QIoFIccPnpAWwwrNmjGxoNnQnOQRLYyQcboTxW9M6NqJZp9//aONM9kc2bcBVlQJM /WGXIvka5OTuV+U2NvWlMJCP/VT0Yo5ZHaXBJT7W44JFoC9WNn2DouE618bJMinIdv6W aygqSJdRJw72AuIvGx/mmhK1ftihQHPu08Olx2AYCSIOhsQl9gkQM7AS0MalfZ18woJr PtfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679068504; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VkbFN5DIOfLGyePi4iUQTqaZQlnmOIVGGAwI9RXEItE=; b=XHrUXMT4MUQUCm9aFGSA3ghmaxcrxop0Az74aqm7qa/I6jmp51B8lNfUMU+H9BJs0X odVimiK5IdBgpvNlkdh0HjY2jr1PFlgm0YZDnqCw0W1zJtNGpxroEdt5HduGtcGhHyj9 jw3R/ayNEs0cZiKufR7NPgemqqVIJpG6d7y27u0hd/viMEfcNnc5XYT96QQyGcGdv0P9 vM8dtsj+lFf4tiV2xOduaIGOAfaKfHGQsxYS7OhUxRshHuK8L5Tesfs2dENOmGMB2VTU Cf2Za684ksARMsR+SC35kiX0G2siWpCM0mnU2y0oUX7P7wHMb48dxAs5KC+7OIW8+f8A OIbw== X-Gm-Message-State: AO0yUKU506/q9LhosE349WI6Jb21eY0I8NEcuP9kKxVrUoZp8pnI46JM NMAaHpRE+8CTrM2cr/bUatIXtDRNlBgPmHt1aAY= X-Received: by 2002:a05:6a20:8984:b0:d3:626b:976b with SMTP id h4-20020a056a20898400b000d3626b976bmr7487435pzg.26.1679068504437; Fri, 17 Mar 2023 08:55:04 -0700 (PDT) Received: from stoup.. (96-82-119-43-static.hfc.comcastbusiness.net. [96.82.119.43]) by smtp.gmail.com with ESMTPSA id s5-20020a656445000000b004fb3e5681cesm1668986pgv.20.2023.03.17.08.55.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 08:55:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 5/9] accel/tcg: Pass last not end to page_reset_target_data Date: Fri, 17 Mar 2023 08:54:51 -0700 Message-Id: <20230317155455.341843-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230317155455.341843-1-richard.henderson@linaro.org> References: <20230317155455.341843-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Pass the address of the last byte to be changed, rather than the first address past the last byte. This avoids overflow when the last page of the address space is involved. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- include/exec/cpu-all.h | 2 +- accel/tcg/user-exec.c | 11 +++++------ linux-user/mmap.c | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index db38418d93..981c295de9 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -286,7 +286,7 @@ int walk_memory_regions(void *, walk_memory_regions_fn); int page_get_flags(target_ulong address); void page_set_flags(target_ulong start, target_ulong last, int flags); -void page_reset_target_data(target_ulong start, target_ulong end); +void page_reset_target_data(target_ulong start, target_ulong last); int page_check_range(target_ulong start, target_ulong len, int flags); /** diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 035f8096b2..20b6fc2f6e 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -508,7 +508,7 @@ void page_set_flags(target_ulong start, target_ulong last, int flags) } if (!flags || reset) { - page_reset_target_data(start, last + 1); + page_reset_target_data(start, last); inval_tb |= pageflags_unset(start, last); } if (flags) { @@ -814,15 +814,14 @@ typedef struct TargetPageDataNode { static IntervalTreeRoot targetdata_root; -void page_reset_target_data(target_ulong start, target_ulong end) +void page_reset_target_data(target_ulong start, target_ulong last) { IntervalTreeNode *n, *next; - target_ulong last; assert_memory_lock(); - start = start & TARGET_PAGE_MASK; - last = TARGET_PAGE_ALIGN(end) - 1; + start &= TARGET_PAGE_MASK; + last |= ~TARGET_PAGE_MASK; for (n = interval_tree_iter_first(&targetdata_root, start, last), next = n ? interval_tree_iter_next(n, start, last) : NULL; @@ -885,7 +884,7 @@ void *page_get_target_data(target_ulong address) return t->data[(page - region) >> TARGET_PAGE_BITS]; } #else -void page_reset_target_data(target_ulong start, target_ulong end) { } +void page_reset_target_data(target_ulong start, target_ulong last) { } #endif /* TARGET_PAGE_DATA_SIZE */ /* The softmmu versions of these helpers are in cputlb.c. */ diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 9c70f51d97..0aa8ae7356 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -946,7 +946,7 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice) if (can_passthrough_madvise(start, end)) { ret = get_errno(madvise(g2h_untagged(start), len, advice)); if ((advice == MADV_DONTNEED) && (ret == 0)) { - page_reset_target_data(start, start + len); + page_reset_target_data(start, start + len - 1); } } } From patchwork Fri Mar 17 15:54:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 664548 Delivered-To: patch@linaro.org Received: by 2002:a5d:5602:0:0:0:0:0 with SMTP id l2csp475531wrv; Fri, 17 Mar 2023 08:55:40 -0700 (PDT) X-Google-Smtp-Source: AK7set+FgRMNjqWgdyxuAf5S9/HwULFx7nLvjg7bzuVeUIFj2ARQ0bzME9tjBamH36wBgdxEm33T X-Received: by 2002:a05:6214:258f:b0:5a3:fffa:f600 with SMTP id fq15-20020a056214258f00b005a3fffaf600mr37797239qvb.26.1679068540697; Fri, 17 Mar 2023 08:55:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679068540; cv=none; d=google.com; s=arc-20160816; b=kHO0oJHTuqm1reOQPYFFElwI8OMlIP7zb8ZpcUJfGJ/68yD+zaAHY0KKJrruDoPHc1 a+cfWN3M14GP3I8UvKOOEt3zeryT3o6jmms7bpOb9L3tsePt+UYvvDJ+fnJjVXOdlUwK P5QNOzQSzJkPdem/tXm8G0yc7e+qKvxRiseOOJ8qDb33chaKBtMCSiftbdidPqUgpcL7 F1WJ1bCJjjn6LY/MZv5XTRvLYexZ6js2pImu4pg3zAoWMKImYtFrg64gWyQlftrrrkLB kkK4CHEXZoN8MOXqSa3bY3bpcDniGMWifXnVlXtrtUVNZTn35hKPhzYsuBF/lHzww8ys 8+Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oPbJjioypis0BlpLlmson9HA/Y6srBTH0pbyV6CP7q4=; b=x4y1L3O7g24VvL/OW7stb8y55ihqI2zH69b2qsZj8dLn6wDDu4HdXm1SeZ4Oob+rBJ tjZ8IxdaezPgo3M/sQevJlBW9Q6Sgiz1u3MEwCDTL8t7qFg7btzGJa5gUM9K3RNBj72o wB2aGWQ2zNo5NNEkk9DkMyk7KSVkG6GDOjCcmoceIZ6jyTEuOKG71/VYzE8VQIJBZpmv mddNa8ffPTE5J8/6Wp6IBKVHW6FHow8EFVRDohHOCmM6LrKbx9xFeV0JHW6pvSg5qjdG lZpPei70z1+WjTw2jMphsj87HDF2D4/H7YPxahaV6eNuV0qcbyFq2HYqiStJ/gZtJSiD Pbqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BF0CyX6j; 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 c124-20020a379a82000000b007463cdd2a59si1633355qke.675.2023.03.17.08.55.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 17 Mar 2023 08:55:40 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BF0CyX6j; 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 1pdCQB-0002nG-7Z; Fri, 17 Mar 2023 11:55:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdCQA-0002mr-A3 for qemu-devel@nongnu.org; Fri, 17 Mar 2023 11:55:10 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdCQ8-0007yc-2R for qemu-devel@nongnu.org; Fri, 17 Mar 2023 11:55:10 -0400 Received: by mail-pg1-x52b.google.com with SMTP id t83so3152793pgb.11 for ; Fri, 17 Mar 2023 08:55:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679068505; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oPbJjioypis0BlpLlmson9HA/Y6srBTH0pbyV6CP7q4=; b=BF0CyX6j9na4LCuKnZVVYA/P8IrEMgckmlwkIMmkJS4NB2E6H/O+Fbp3PAmarVBDjW f/lMjOY/4Ff2ReYqg/uG5E7xCfV2Uh7TP5jrkzKYujwhUJj4JYbCs7sLP92WJ0l8dv7w PJ//aDby+cEsfwrA/zE6Xvio9ZynBdVhwjDwbAYyRjB3VERZ4NKg5mueNNCAeKmvX8aN uh/UggaLeaw716gHmlBDMuAxuH1Or/JRkWOR2j1rqlwmtFwBSLxmsKVzXaDjQhExUnt8 S6XvBk4pfWcp1w7FMtpRiqoRWFHB6vki11ETc79cZoRRSa9LZ+0hO7Rsy8SRAAtv5ub4 UKOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679068505; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oPbJjioypis0BlpLlmson9HA/Y6srBTH0pbyV6CP7q4=; b=eZ6wEECDweDv/dnHVrUDGnr65HYWURzEYreOL5tIbHg2b1f6VnhakXIgur1eSSZ/0s Rv6f+bak2elKRqZUI6aXxJ/997QLOuNfIbCtfo2gheuLzkou/V+trj160iCmcT401uhh S4TKMV72Mh2yUmWVKP+z1Fh2k8szj7AGqOJdrEOVp/KdE2OUnk1Wx1XrkALKQ8CdxsmH 28vRcOKWIF8nE/TdNyTs75Q0O0PVRF2gRcykylbxyG9DTWwgHy+nWJEuvEx1XJzvVXIV 7P5kJcBHy/EPzVX3eJp/x1GoAt4DYYJYPA5xgGHOs1DY4xhV/e+On5UBWEp9caqTZPqA bKqg== X-Gm-Message-State: AO0yUKVRmoALkkWa1Cx/Pukm4PUkApBVQMDUlzxgHyIFwjI3abhhQxjd XsDmUby34dJQo7Ifr+UVrKEz2PAlyOMN5ZNZODU= X-Received: by 2002:a62:3896:0:b0:626:26f:5e4b with SMTP id f144-20020a623896000000b00626026f5e4bmr4256885pfa.1.1679068505564; Fri, 17 Mar 2023 08:55:05 -0700 (PDT) Received: from stoup.. (96-82-119-43-static.hfc.comcastbusiness.net. [96.82.119.43]) by smtp.gmail.com with ESMTPSA id s5-20020a656445000000b004fb3e5681cesm1668986pgv.20.2023.03.17.08.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 08:55:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 6/9] accel/tcg: Pass last not end to PAGE_FOR_EACH_TB Date: Fri, 17 Mar 2023 08:54:52 -0700 Message-Id: <20230317155455.341843-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230317155455.341843-1-richard.henderson@linaro.org> References: <20230317155455.341843-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Pass the address of the last byte to be changed, rather than the first address past the last byte. This avoids overflow when the last page of the address space is involved. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- 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 7246c1c46b..2c2e887196 100644 --- a/accel/tcg/tb-maint.c +++ b/accel/tcg/tb-maint.c @@ -126,29 +126,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); } @@ -319,7 +319,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 @@ -994,10 +994,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); } } @@ -1029,6 +1030,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, @@ -1045,10 +1047,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) { /* @@ -1090,12 +1093,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 Fri Mar 17 15:54:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 664549 Delivered-To: patch@linaro.org Received: by 2002:a5d:5602:0:0:0:0:0 with SMTP id l2csp475730wrv; Fri, 17 Mar 2023 08:56:05 -0700 (PDT) X-Google-Smtp-Source: AK7set/zCK/TcPjVHAKdRAr5MiNu3bQlbUbarigPTWyptUW5LUU0uim2a4IGvCvgcPA7XEWU9rK5 X-Received: by 2002:a05:622a:493:b0:3bf:d372:a5bf with SMTP id p19-20020a05622a049300b003bfd372a5bfmr13508064qtx.45.1679068565184; Fri, 17 Mar 2023 08:56:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679068565; cv=none; d=google.com; s=arc-20160816; b=mlParp9n0aabpqca7obgvLAp+qN5wm03Jhc65bBYVVYf0rAyc+GBhvTM+xR07mJBcp Q5Xt3kt0YFL7CAHLXTXNw99RWhVmjF8hmjcWspS0y6fZ5tfWWTG8lUYOUJC5t/liSoy/ 4aRR37ScZPzeoiWj/AQQy6lpT0Fe20kVpmJYoseh5STadaonfZPbsd38TcPFh93FsCm8 gJEvYVP7I83NTG0u4x/M06QCaGu2EIfGSRgpVwDTs8UcUphtMfMlNaOJBGgmaN2rHpTB cOQk7sU8DwKkY2G9N+yMiRvmquAc6EWRwm/A/hvnZph2vCRlEC62fc5UuiyQwpot3rC8 bwag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kaO7GmK/787xWdgYWzb+qwyj7A2GGcvimGihRVSOyho=; b=N9r13DyZU6EKKUQ0Ubb22liQqD4lWmFkisU09WVaCaNG7zelrKpRrRVlMoE1C5tujC ywRZhddeiw1XcgrkTghwI6Si/cwlwEP8oe/h8U6hssGT3lkEmcv9FlCG8+634V8jka/5 2aRrcuzRzLXnGO7jmmfZKuNwsQPXt3GBnaUPHwLXl5JZOPaX3wO8tM7geE+arhqmpYEF tlKSP4/j0Tu9ps9dVnGCt2YAUaY7N05ycTQ8XAvoUr5XJqotrZ5t/WmHvW388wkMfUeC ZzW8u91QMNYZKuO/dyEfZdu24D+TpNc2HdFVLq4bj/Beprux3TLXY9UX6ZQyD6MAIwjh 7uAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HYQjrp+S; 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 z8-20020a05622a028800b003b860983963si1971426qtw.207.2023.03.17.08.56.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 17 Mar 2023 08:56:05 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HYQjrp+S; 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 1pdCQG-0002o7-UP; Fri, 17 Mar 2023 11:55:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdCQB-0002nV-IJ for qemu-devel@nongnu.org; Fri, 17 Mar 2023 11:55:11 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdCQ9-0007yy-8y for qemu-devel@nongnu.org; Fri, 17 Mar 2023 11:55:11 -0400 Received: by mail-pj1-x1031.google.com with SMTP id y2so5630551pjg.3 for ; Fri, 17 Mar 2023 08:55:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679068507; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kaO7GmK/787xWdgYWzb+qwyj7A2GGcvimGihRVSOyho=; b=HYQjrp+SgBS9jCJF+eUtgtMLq20HKfIq1bqk8Co83YZVvyHoe0GaFwTyyRzBlRkusp qqNQhD3nVdH2vUFS0qjR5vfZ1E7cMP7AdXsK4FAAqBOUymKmh66FKPkx74wJc0Ia03Hl /P8QpFf+HBwTwFV28wO326X+le0KKp6fBOM0hbFQE6wSh6/X5Rz5daD9aIwsatIrqDQz y5osIgVCImJCRGp0q7UTta8OlDyiZf0SfU5zjKMoTapN0pHBLlemcxl0vrfj6/IJdW3E vIde0yBs4qZ+yphqyH3+SVRNBWGlFGo7jCgndr9C68hf5h8YtZ89fQna8TTg96xsfrgW /JRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679068507; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kaO7GmK/787xWdgYWzb+qwyj7A2GGcvimGihRVSOyho=; b=LwEgfkMOlQlZmUR1hPXdGmRtMzjzXxazl4Q12ssXZ0OgzXdW2tlHJ3+xnLBOKzhtHu BRfkg6TENQ4B0apjuntwRMT7r+Z7yd56nw2nup8LO/jjSmre2Ar3gH8WhMl20zBBYteR qLd8ilCdrfA599b2EDKpf57zXOAjO09Lmr8gQbz7QyCA9KKDxqLNzvv7B2Fv9X0qrlcj 2ugSOzQJ7gEILyVOMOMsJ5o+qyBXdckkqSsFNkUMQ0Oc5z9NU5zJ83xIAqsxWmgDvJPE fxMDBEYiaesyq8Mf3uFtP5d/M7gC+a8j7YV/Ef3PAvyrZ8jewTxlwZMEc+tMCQxDN/zf KC/Q== X-Gm-Message-State: AO0yUKVhwIV7x4PZ/QbFaBO7BxslzBWoZkXxkAetwqJIroU5xOwFLZP9 FBc/euQpR4lpm/KNr3x0ieCqKofboTtpLc3P0LQ= X-Received: by 2002:a05:6a20:491c:b0:d5:3818:6427 with SMTP id ft28-20020a056a20491c00b000d538186427mr8514332pzb.9.1679068506814; Fri, 17 Mar 2023 08:55:06 -0700 (PDT) Received: from stoup.. (96-82-119-43-static.hfc.comcastbusiness.net. [96.82.119.43]) by smtp.gmail.com with ESMTPSA id s5-20020a656445000000b004fb3e5681cesm1668986pgv.20.2023.03.17.08.55.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 08:55:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 7/9] accel/tcg: Pass last not end to page_collection_lock Date: Fri, 17 Mar 2023 08:54:53 -0700 Message-Id: <20230317155455.341843-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230317155455.341843-1-richard.henderson@linaro.org> References: <20230317155455.341843-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.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. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- 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 2c2e887196..cc23f7fa45 100644 --- a/accel/tcg/tb-maint.c +++ b/accel/tcg/tb-maint.c @@ -510,20 +510,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); @@ -533,7 +533,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; @@ -1153,7 +1153,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); @@ -1162,9 +1162,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); } @@ -1180,7 +1180,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) { @@ -1225,7 +1225,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 Fri Mar 17 15:54:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 664550 Delivered-To: patch@linaro.org Received: by 2002:a5d:5602:0:0:0:0:0 with SMTP id l2csp476040wrv; Fri, 17 Mar 2023 08:56:52 -0700 (PDT) X-Google-Smtp-Source: AK7set+3zBLDg6CzgxdrAEOVcq+UGUMWpjmbXnsFG9suaI4d870q9FtWjIoq9QF9mK+W/ZHhLPlx X-Received: by 2002:ac8:4e93:0:b0:3b8:6ae9:b10d with SMTP id 19-20020ac84e93000000b003b86ae9b10dmr13535615qtp.2.1679068612484; Fri, 17 Mar 2023 08:56:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679068612; cv=none; d=google.com; s=arc-20160816; b=GctANEt8/DHWg+0Oj+zl6OUVXi5DGVjw57q0N7zqBH+M+Yfn3O3PpSEOfJf7Qwt17Q C4+DXxupJ63en8CCnBUDcVJdptnkXNrTlCLSkB9lEnTq2Eb2hTC2H4TBSCcm3UO/S39d PalMf2+7dPqGYWG3fCsqlADA2WOn7/rOgQigZ/iXi/DXOvk6euXaWf1wGnIZm3HpDwXb FcrmxwFGyaPKjYRBFRkOCpXYY1tPZbBILTf5oVN4JmGSZLRUBpCaPNaqMBzGRyE6L1wJ T9q/r08Ln6Vuqpx70AIGa6Z6GT0MRUPaR8krK8QZG949ed2HUWa+D0Gzsmtab/hQVQUS 4fTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wsQ/JfArB2BnOMGVj/Z41DP1gayMJPyf6K8wTYkX29M=; b=bg3gcNo3dM/7LkYQzPAlMHDDwC5i4qivk0Z+kLbqJMaDmdcgwJfMxBexNlYwUN0iIG laNKoll7BPsQb9yzNhrNrgcfiQh4HpLCo2gEjJFFdra8T/eQwpXCpg8dYvWGZo7jf9TL OlRZSbTPF1QkrfzFpNoHulO/ehXjdUF+ONrTMQXfb9a5IMbFEkSWaefQ+t15vOigueii 9OjzHezTlsGaxFb1I4+yiSJOU4kSRiwmf/I6uo2FZBKiCmAo83qLXDYVZmglgKQtwa/E Och948cmn6lT2FfvWaVycR6EHhUX2sC0H0ThH6oYfTCJU3rB50hLuZIcybzIq4oVdTif diCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YUu6MXo4; 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 bq13-20020a05620a468d00b007459d841420si1893510qkb.606.2023.03.17.08.56.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 17 Mar 2023 08:56:52 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YUu6MXo4; 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 1pdCQH-0002od-MI; Fri, 17 Mar 2023 11:55:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdCQB-0002nX-Mp for qemu-devel@nongnu.org; Fri, 17 Mar 2023 11:55:11 -0400 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 1pdCQ9-0007zO-Jw for qemu-devel@nongnu.org; Fri, 17 Mar 2023 11:55:11 -0400 Received: by mail-pj1-x1029.google.com with SMTP id x11so3712773pja.5 for ; Fri, 17 Mar 2023 08:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679068508; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wsQ/JfArB2BnOMGVj/Z41DP1gayMJPyf6K8wTYkX29M=; b=YUu6MXo4K0YQ65YfkNr4WeIACGfGVoZk+BdtENPQ9FeV45Td811XmU8CP6QdNd3nEY g94uXYXrBfcIS6sKwoLGwGEKxS46/YDZXkeWQauNe1Ou4trqJK6l44NBa7KzLHVRixl3 dzExDpzhMLsc/0CgQsZXatyJNbwyyAyrnNIeQZwJzURpJPEOvq4iR5mXMG5oRxMIc7Gx dY7YpHzWrZUL+XSl3TySjC+Y9xyHzubU1DQRxhwvCNUpzobN9hDGpyEEWy+O6uA0SBhs scKqKwzH7Q0heZfdjMs4WmB0U37xFKc8N1A4pE4gOpF8W8Cy5i+DgzKPp7JLE9oQ4dei ZKIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679068508; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wsQ/JfArB2BnOMGVj/Z41DP1gayMJPyf6K8wTYkX29M=; b=JWO07zVh2EDJsAHHtPGv6SktwMfxvluweVSZf8Z0p5NeeHK2iNagCIGrG4dDEX8RHz okK2ixjnUb/SZbL56xxzB3RAcpkJdgL5+iTZ4r/bKY0PDpLdtObsEFqxn9F7cwmiuSCw KiuaouveqtK0cZjIhYxzcP0oJ1HKvibbiVI/V5rCJiaowud5wyKwgrTvYv74zkM4/bGj dEi4ZqSF9qImpcb0vwzekNd6gwLtNxN/s9Ctx3h+d/V8+sqgP3CV/PBp4tzP01i4/A7P ZYVHx70Tn5nkKGuvcT/Zk4qh0P07amKRIj4yqLJufD5D8oH5XDGQx5KNukRWscTb15ma H1qw== X-Gm-Message-State: AO0yUKWfAMc5N8aAYyXg7sth5bpQoGUTEpupzzK1XfpUKbz3GZz31V8C zw+h8OflnLTW/LymAE63MLBbLLz9SAG/NzadVP0= X-Received: by 2002:a05:6a20:7d8b:b0:cd:49a4:305d with SMTP id v11-20020a056a207d8b00b000cd49a4305dmr9376219pzj.11.1679068507852; Fri, 17 Mar 2023 08:55:07 -0700 (PDT) Received: from stoup.. (96-82-119-43-static.hfc.comcastbusiness.net. [96.82.119.43]) by smtp.gmail.com with ESMTPSA id s5-20020a656445000000b004fb3e5681cesm1668986pgv.20.2023.03.17.08.55.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 08:55:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org Subject: [PATCH v2 8/9] accel/tcg: Pass last not end to tb_invalidate_phys_page_range__locked Date: Fri, 17 Mar 2023 08:54:54 -0700 Message-Id: <20230317155455.341843-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230317155455.341843-1-richard.henderson@linaro.org> References: <20230317155455.341843-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. 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 Reviewed-by: Philippe Mathieu-Daudé --- 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 cc23f7fa45..99c0e708ba 100644 --- a/accel/tcg/tb-maint.c +++ b/accel/tcg/tb-maint.c @@ -1083,35 +1083,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) { @@ -1164,7 +1162,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); } @@ -1191,7 +1189,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); } @@ -1211,7 +1209,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 Fri Mar 17 15:54:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 664547 Delivered-To: patch@linaro.org Received: by 2002:a5d:5602:0:0:0:0:0 with SMTP id l2csp475463wrv; Fri, 17 Mar 2023 08:55:33 -0700 (PDT) X-Google-Smtp-Source: AK7set/5c6zf4hiYPiSJ45OjaTAACNDU8b0QfO/acDtWm/3/O5uePEu5WbKv+H6XMLIKeBq+qm5g X-Received: by 2002:a05:622a:488:b0:3bf:bb1f:3c2b with SMTP id p8-20020a05622a048800b003bfbb1f3c2bmr14273160qtx.6.1679068533202; Fri, 17 Mar 2023 08:55:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679068533; cv=none; d=google.com; s=arc-20160816; b=lyrCuuoo15qXlyae6KCsscA7EehZMmA2ScPQ4h7T2WRG6IsKfzLLKdYpps2q1gL1A4 2vMRUl0cTmAK5ZZGZOHpLrmRK0gUgwbJCxZ8VgRPF+E2egCOC82odZwZNDO58IVB5tvb Y0KkKHrmNfBZtQa/fk++d993IAxyhum/KXfxehJNyVJa+kMPbvUzz1jeryUyf2CWFQ2S CaN2vLF5P3eZEfv/t4bNMCdq0i+XXnN4BNqZKGp9EARmIWRp4wwtPxQyBUU14GZwzvio aoLIO6y5upOVcM7VYnwYglA5FoRIexmZzmedmzT/wM4gDMxrLpSewfo0+P9QsN3Bj4BR gq1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FoOAy6sYxfpMkOKGvtTEobimDr21c7ilUlCZwoIl1E8=; b=hh9i8IIUtqLkFWW/+rsWmqh9jdlLvHaqYr7Wi/Q+kTxBoVoQDuPaZARXlpQGnylqp/ CXi6mb1Cyb4xigP13cAGh5PSWrUNdovo1jfS7eJZTDQtRlePCdn1o7BjbSOmZayTje/f +kKOCPklepsXqUTTwkKz5qQF9oifea3hRT4bxlh0jONZXZQTi7Z1qTADGT6T1F3tS3/s WGUudbYyEAa0Wj1dxV9vVRJ5MDEINwElMP0YPAXV4X08p4Z9ogZNkF35h08BT2wVn/+K xbl9T0BNWVoF/OajnNTzTyM7nP+ygtqUvtkf6Md3zwUh94/NDRTe7mjw2oofVIJ4xKW+ J26g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BdwfWsSP; 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 a21-20020a05622a02d500b003d450c061d6si1702085qtx.559.2023.03.17.08.55.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 17 Mar 2023 08:55:33 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BdwfWsSP; 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 1pdCQG-0002o2-U1; Fri, 17 Mar 2023 11:55:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdCQC-0002nn-5M for qemu-devel@nongnu.org; Fri, 17 Mar 2023 11:55:12 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdCQA-0007zo-AN for qemu-devel@nongnu.org; Fri, 17 Mar 2023 11:55:11 -0400 Received: by mail-pg1-x52c.google.com with SMTP id z18so3151848pgj.13 for ; Fri, 17 Mar 2023 08:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679068509; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FoOAy6sYxfpMkOKGvtTEobimDr21c7ilUlCZwoIl1E8=; b=BdwfWsSPpWevEc6LMk1peAbYTKc0Ywa2V96iEExvLWOvyi3YsmqwogHcUzP5NH7pU/ YxX9wCbNeCKZp4czAxxPpDC/qXqJ6yKrhwex+dpHnxT0FEaz4b2TK+6uanJjeW58u7B6 dSjfbySWrbYTSeYtfyHWZhIbOoYYgpAeAG3cquYs8qO1upZFPgvQfwto8EW7ONeRHqL0 D3rSEYJPaDrIXDmCLcGavRXyBrnFSx9PsT/E9D3OGFY6pIiLUrF1SWYCGhjJnxR6/MX5 teVNiYqgoU7Jv3tcBx1vhwR3DgMVrdEprbWY5KLaZ5EOKoxLGPgN2CdypaVGpFWGcJdp +JEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679068509; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FoOAy6sYxfpMkOKGvtTEobimDr21c7ilUlCZwoIl1E8=; b=wdqClTRFWWtrNTO2WDdjwpGPxyird9hV68OWyt9hFAkP8yS18+jY4mp7U3zi2xlLml s08Ul4dZeo1lxLOKATYm7ouC6oekGSmm0QrmxNCScWo64xKeGbTpm7bix7Xmp8j6zmSE qN0KfbMTuVa7cxmc1GSNpZOe6fQd4wN0F4Sio/9xA5HdEpbANKXPHKvbOGZvzpy9+1Mw l3y9r/E7IG2u7IHt04/d5Y9WD1f7Bok/sQO6z++jN1FKoB2rzzU7ccV7uCEyMs+AyXjE BxemJgjJdIrl6ksw2Eq0Ur1aqI9WVeo+Uk2Kauie4hK+gsU/IGHRJ6rLYSuwzLJm9PXc i1yQ== X-Gm-Message-State: AO0yUKUHES/1Hyq9vwEwpkHlNrVjklg8itBVT+Oi6GaYLju7jg2WbUSV f6OLF+pHU8PHZl8fvaJgOrt8WImrhdN7ld5vrBk= X-Received: by 2002:a62:5481:0:b0:625:4ba5:d0ef with SMTP id i123-20020a625481000000b006254ba5d0efmr6793309pfb.21.1679068508835; Fri, 17 Mar 2023 08:55:08 -0700 (PDT) Received: from stoup.. (96-82-119-43-static.hfc.comcastbusiness.net. [96.82.119.43]) by smtp.gmail.com with ESMTPSA id s5-20020a656445000000b004fb3e5681cesm1668986pgv.20.2023.03.17.08.55.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 08:55:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 9/9] accel/tcg: Pass last not end to tb_invalidate_phys_range Date: Fri, 17 Mar 2023 08:54:55 -0700 Message-Id: <20230317155455.341843-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230317155455.341843-1-richard.henderson@linaro.org> References: <20230317155455.341843-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Pass the address of the last byte to be changed, rather than the first address past the last byte. This avoids overflow when the last page of the address space is involved. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- include/exec/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 ad9eb6067b..ecded1f112 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -678,7 +678,7 @@ void tb_invalidate_phys_addr(target_ulong addr); void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs); #endif 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 99c0e708ba..3192346b03 100644 --- a/accel/tcg/tb-maint.c +++ b/accel/tcg/tb-maint.c @@ -990,11 +990,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(); @@ -1010,11 +1009,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); } /* @@ -1168,28 +1167,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 74deb18bd0..5b13281119 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -572,7 +572,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 fb412a56e1..322e781676 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2527,7 +2527,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);