From patchwork Fri Feb 12 18:48:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 381876 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp3200749jah; Fri, 12 Feb 2021 11:27:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJzZMRwpG5ccsKRPUZIWbw7FXcBwWKCMfcJQN2k7kNjYMreikUdo31jLKjdKDKVCTmA1Qq0y X-Received: by 2002:a25:6c45:: with SMTP id h66mr5892901ybc.490.1613158059120; Fri, 12 Feb 2021 11:27:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613158059; cv=none; d=google.com; s=arc-20160816; b=QfJ0sa2pk8Xe0a9UDXRTpHfqg7gxt1czvmtVXcEx2+Q1g1b7MlkkYaTWZc7ePqvGJ5 BoX1h0dktUcfmweunUyEeWNsFnU46XB7PjVBvw7ZNZmVXrH3gWiOUjGobp3O/6J1Qiob O2cf1orKqqSuHrstdCNq8pQpPXGgu/rBOJ8E2gzmvqxP4KlzXieyyv8zi34lmDL4+piO i63tWlldBLQvIqo8hhG81Xh/Z3Ci5gIaifSRfFEvOpNFyd2+qW2UDTIvi8zdABpSOH4t aX6AUjY8qkBZBeYNjLbR3qkWK36f/IDZWI8A11TgkE2ff9Mp/ADr1oklV5h5vAC9cYBe zxdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=33PuANLFLZBScZnb9Hs9Trfm1Tvhd5OuXkKzdpb7J3o=; b=okrNySZjLPi7Qk7OE4HxqbqazApXVpGyL5sC0BTATYiL53k2SUhqKq98awHhp5hee+ 7MgVbCpNUDGCqmVS9tm0XCs0r4KHQKGiQvD5d4YXGhdl3cRZd3I25hnOQct5aGZ++ZHJ q4PIOURu3xxaLFqs4zJ//39HxqDQZPZqXAz7JKPblA4cHPGGHhidK7KVMRO0ahz6uOsS mtuShhD/49kcgkBf6rcbAOfOq3EYjKROwKkHctv3jIeDyWL2zpjqr1NCXIktwDacI6Lp jFhk36dAT97U4XiY3tf4pNtrgGGKffPVRoAueKh8dmyTaJnzeVHrodzBNmYPALTEm2Ad x/lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="MRaZru/g"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p9si5382984ybk.386.2021.02.12.11.27.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Feb 2021 11:27:39 -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="MRaZru/g"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lAe6M-0008TN-LZ for patch@linaro.org; Fri, 12 Feb 2021 14:27:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lAdVb-0001uz-Hj for qemu-devel@nongnu.org; Fri, 12 Feb 2021 13:49:39 -0500 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:35005) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lAdVT-0007qS-HM for qemu-devel@nongnu.org; Fri, 12 Feb 2021 13:49:39 -0500 Received: by mail-pl1-x631.google.com with SMTP id g20so332978plo.2 for ; Fri, 12 Feb 2021 10:49:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=33PuANLFLZBScZnb9Hs9Trfm1Tvhd5OuXkKzdpb7J3o=; b=MRaZru/gnVeP0yh991zSqCuHrSY4PDzKRFbgu2CbzDAE2hT3c1cHnlWGd+pjkRojiQ bqrz2gzqoD7cShYRtOidiAtvBwQAYBmxZSjmxRihnx3S4ox/vBKqylPVJ6RNoQBf/VE2 x5ArSjJCRH0mpB2OMejWf0g3zWWWJvER6j4zCH2ok1fS76PZvTxAHfjIzJCcX/vwlu6M VVf3h0GBxQhYN68m6d9Qn1QCwIzcuO/deSnflVIBcGLRPEi5d5UXxtQA4DmGV/nlZ2Mm nfFGqhba4UHpb39JMi0tfvOQIfHkx7PAwwkuxBuz+8p0Oc8D20EX7Y2rTgblnh8ROPBe 8Qxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=33PuANLFLZBScZnb9Hs9Trfm1Tvhd5OuXkKzdpb7J3o=; b=DhzypTby9nsgeCTuUpJdg/mzwCrDFfcf0dtoqpWx+jWaD1lGhbcKfSTxIkjGfBYzzY Zlju5NbPeeta4VPya5ZNzs2wSusSFBKt2q8NnV0C+QrkN9DQHKQ0lx6I/bQw2XBpQNqv moZWTfyijO1Mvlatse3BgjwEptRmFAx68Y5h2aNnOs02Gu3DQxwreWvrWef0iCCvrITN k61uGMvWqLI8bWfgvDU/ORkU6FZyocwpq9xVCvHvorddk3mwIIButiaUGnku+yjRNdR3 Qv/9MhumFIe9tLedTjSLUIyskowFbuiCG88rRcn+r+bgefvSwwMi88Kgkfgw4Yx2ATcp sQ0A== X-Gm-Message-State: AOAM53202Bqwf7iZORQaLcJS9VJQnG9a6l2WIRLmyNT0F6W5dbxxjsu2 5MfjxCSvFsPom4LI5UNP4oYJPsQtHeM0eA== X-Received: by 2002:a17:90a:2f21:: with SMTP id s30mr3839164pjd.5.1613155767288; Fri, 12 Feb 2021 10:49:27 -0800 (PST) Received: from localhost.localdomain (174-21-150-71.tukw.qwest.net. [174.21.150.71]) by smtp.gmail.com with ESMTPSA id k5sm9427618pfi.31.2021.02.12.10.49.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Feb 2021 10:49:26 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v7 19/31] linux-user: Handle tags in lock_user/unlock_user Date: Fri, 12 Feb 2021 10:48:50 -0800 Message-Id: <20210212184902.1251044-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210212184902.1251044-1-richard.henderson@linaro.org> References: <20210212184902.1251044-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Resolve the untagged address once, using thread_cpu. Tidy the DEBUG_REMAP code using glib routines. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/uaccess.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) -- 2.25.1 diff --git a/linux-user/uaccess.c b/linux-user/uaccess.c index 76af6a92b1..c696913016 100644 --- a/linux-user/uaccess.c +++ b/linux-user/uaccess.c @@ -6,36 +6,37 @@ void *lock_user(int type, abi_ulong guest_addr, size_t len, bool copy) { + void *host_addr; + + guest_addr = cpu_untagged_addr(thread_cpu, guest_addr); if (!access_ok_untagged(type, guest_addr, len)) { return NULL; } + host_addr = g2h_untagged(guest_addr); #ifdef DEBUG_REMAP - { - void *addr; - addr = g_malloc(len); - if (copy) { - memcpy(addr, g2h(guest_addr), len); - } else { - memset(addr, 0, len); - } - return addr; + if (copy) { + host_addr = g_memdup(host_addr, len); + } else { + host_addr = g_malloc0(len); } -#else - return g2h_untagged(guest_addr); #endif + return host_addr; } #ifdef DEBUG_REMAP void unlock_user(void *host_ptr, abi_ulong guest_addr, size_t len); { + void *host_ptr_conv; + if (!host_ptr) { return; } - if (host_ptr == g2h_untagged(guest_addr)) { + host_ptr_conv = g2h(thread_cpu, guest_addr); + if (host_ptr == host_ptr_conv) { return; } if (len != 0) { - memcpy(g2h_untagged(guest_addr), host_ptr, len); + memcpy(host_ptr_conv, host_ptr, len); } g_free(host_ptr); }