From patchwork Thu Feb 22 20:42:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 774897 Delivered-To: patch@linaro.org Received: by 2002:adf:a356:0:b0:33b:4db1:f5b3 with SMTP id d22csp43550wrb; Thu, 22 Feb 2024 12:46:48 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXj1vNvSTQd7ErqH6hkSghuYzxYvnVuafaOT/odNZ7mvn+wzAJ43OGXe9nwzmRbob55mgCzDmBVZrNHUQsSWv4U X-Google-Smtp-Source: AGHT+IHr0c+zRNUPDdCq33PkymBWZabT3KZxI8+3gkWL6DO80D8y+BMDvcomtHPEEEEeu202+fZ0 X-Received: by 2002:a05:6871:588d:b0:21e:c765:6bc4 with SMTP id ok13-20020a056871588d00b0021ec7656bc4mr64383oac.20.1708634808650; Thu, 22 Feb 2024 12:46:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708634808; cv=none; d=google.com; s=arc-20160816; b=O5AL2SyqzO0ONUYXTyDxghzdnanZhpeJWqGJ9iSP6hLQGKhayZedYw5X8cxo8iNIw1 24xRSbB4Ntlz6l3nm5bSd/FA3l1/m/uYJrjLZL09q13IrPXQE1QKC8x7+94vJV9APPGp rHtOsBzdBbrZJgDDxo/A7e/cBmw24FHKDPxWyrKHRI2rIy6+e//F6wgqseT9zgMNTTmV DS9HVr4lRH65fVWOF+v1XwAm4q9kWjsXld+cq1S7g4r5g46mFnklBzIwpJ5B/x7RuMrK S2NXQ89ZHHD6yrLt1FHLqUUneInMek8vJYIrpGzqNzFiEgmQL6zg8r4fbACPEfbeIBrh 7SUg== 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=G2VXMZpzicQ4Dm28fmEM7ZpGthYgfI6UDANYII3bJPA=; fh=H/IsS+LNYM6dBDHt5BZPsM5V9tnyjdUlJ92VVuTs62g=; b=uv5Qj1eS2l7B+TTi7eqWQH75bbMOD5NSt9rRgMRQGdrHSckPHYy5VZld3LEDZiM4Bk VQ3H1Bsk6EohV5JVnslkBy34y30uq8P5ELRhdzC0ch1ENci6STpt1g8R3S0DM69Hl4HC yFK7lInraPLUTlVaCBfPnS3oIdFgvyQ5Ubp40qsCBpXeU5iJb1KW7ps2+/mzglUxDuQ8 hWJMuQ/ivxNFMkejC3eof8lT8ezzlt6wsBzjTvG9hKTzxNToilXTJOQBffBVu7ahvX3H tauqASaqoicTupvlFGc22KqjpywY0ESeAnw718jImC81b7vVGBNPD27SuZ4oHjRQfVoU V0eA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SwfpMlbC; 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 c11-20020a05620a200b00b00785d923c30fsi13696333qka.368.2024.02.22.12.46.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 22 Feb 2024 12:46:48 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SwfpMlbC; 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 1rdFuq-0006yD-8p; Thu, 22 Feb 2024 15:43:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rdFuo-0006xs-QX for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:34 -0500 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFun-0002bl-73 for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:34 -0500 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1d934c8f8f7so520585ad.2 for ; Thu, 22 Feb 2024 12:43:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634612; x=1709239412; darn=nongnu.org; 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=G2VXMZpzicQ4Dm28fmEM7ZpGthYgfI6UDANYII3bJPA=; b=SwfpMlbChj9GimvK00b40lmzlQeHldHj7r499f+741B7BIeowbyP6D6si+/My+1Cfx RmKgqCK/QVkLZ8u5CftMrA4vjSdzIcwXVcRC5lTlBIedSiXBJ8PRiPdsLk2ouekQATc4 Z4lYMeKg/Xkwfq0mQOsDeG2YdondWjStf8SOu7/g0j6sD0QfZoM1aSYk27hf4GA0s6dV QGsZQT8FFMGS4hCwNbzgqEPlV5h+2NfSMqL2rcOwZWgzfbYIbLhW7JPnP9v3eGU2UgZ8 ceZ65KvMKlFg5Bj7NbWD+WZhbvJmAuRp36BZb8yrpg0I8nC3LY3ZzbCTcHuHOPILL4mh tzjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634612; x=1709239412; 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=G2VXMZpzicQ4Dm28fmEM7ZpGthYgfI6UDANYII3bJPA=; b=j3CUbG4GqH3NVvoMfNouqz9Vo43wvUtvudhEIS0J+YdYJnS/LL5Z0Pi3OmsGinynSo vFf65Wt9Q0uTcwbw6qhEPD9xWq5n062VbS6LcAbnOK+gUQmn2NhstvVy/Nbxasi+3XPK w7WNVaSqFAHWUxG81m7yHjgTdtG6nnyCWDbc/t3+IIbEGjieMNrusfpv7wSh4Op1Skxq FS9Sgn8dbcxNpfH4A0mJOXRypxY2xfJ2JkjMQD2mXB4M8di+eXQ//8jQ1G/VYM5gr0gX T4fOL41InaF26ig/tavrhdxJPq9zcrJJ4Hh0OponFfvEtPzE0lfwPw0YtZ+IK/Kq9A0N 9sgA== X-Gm-Message-State: AOJu0YzXh9BAHPcjI5wpiIbgv+RvguIzyLdEc5h/g2jY69aet3C7mSO2 uu+NTVL4C7EpDubDPQorv20yqe8yiVjssq53YbpmHJooWdPNe6p9qSzpn4Cxdcv/R2GmC+xjiOH V X-Received: by 2002:a17:902:6ac8:b0:1d9:f83e:3a54 with SMTP id i8-20020a1709026ac800b001d9f83e3a54mr17359368plt.64.1708634611972; Thu, 22 Feb 2024 12:43:31 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:31 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PULL 04/39] accel/tcg: Remove qemu_host_page_size from page_protect/page_unprotect Date: Thu, 22 Feb 2024 10:42:48 -1000 Message-Id: <20240222204323.268539-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Use qemu_real_host_page_size instead. Except for the final mprotect within page_protect, we already handled host < target page size. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-2-richard.henderson@linaro.org> --- accel/tcg/user-exec.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 68b252cb8e..69b7429e31 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -651,16 +651,17 @@ void page_protect(tb_page_addr_t address) { PageFlagsNode *p; target_ulong start, last; + int host_page_size = qemu_real_host_page_size(); int prot; assert_memory_lock(); - if (qemu_host_page_size <= TARGET_PAGE_SIZE) { + if (host_page_size <= TARGET_PAGE_SIZE) { start = address & TARGET_PAGE_MASK; last = start + TARGET_PAGE_SIZE - 1; } else { - start = address & qemu_host_page_mask; - last = start + qemu_host_page_size - 1; + start = address & -host_page_size; + last = start + host_page_size - 1; } p = pageflags_find(start, last); @@ -671,7 +672,7 @@ void page_protect(tb_page_addr_t address) if (unlikely(p->itree.last < last)) { /* More than one protection region covers the one host page. */ - assert(TARGET_PAGE_SIZE < qemu_host_page_size); + assert(TARGET_PAGE_SIZE < host_page_size); while ((p = pageflags_next(p, start, last)) != NULL) { prot |= p->flags; } @@ -679,7 +680,7 @@ void page_protect(tb_page_addr_t address) if (prot & PAGE_WRITE) { pageflags_set_clear(start, last, 0, PAGE_WRITE); - mprotect(g2h_untagged(start), qemu_host_page_size, + mprotect(g2h_untagged(start), last - start + 1, prot & (PAGE_READ | PAGE_EXEC) ? PROT_READ : PROT_NONE); } } @@ -725,18 +726,19 @@ int page_unprotect(target_ulong address, uintptr_t pc) } #endif } else { + int host_page_size = qemu_real_host_page_size(); target_ulong start, len, i; int prot; - if (qemu_host_page_size <= TARGET_PAGE_SIZE) { + if (host_page_size <= TARGET_PAGE_SIZE) { start = address & TARGET_PAGE_MASK; len = TARGET_PAGE_SIZE; prot = p->flags | PAGE_WRITE; pageflags_set_clear(start, start + len - 1, PAGE_WRITE, 0); current_tb_invalidated = tb_invalidate_phys_page_unwind(start, pc); } else { - start = address & qemu_host_page_mask; - len = qemu_host_page_size; + start = address & -host_page_size; + len = host_page_size; prot = 0; for (i = 0; i < len; i += TARGET_PAGE_SIZE) {