From patchwork Fri Feb 12 18:48:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 381865 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp3190285jah; Fri, 12 Feb 2021 11:11:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJwaawCCI+mqiXg7JXIdJXxcdq9Ca2pJ5c16/Q5VVzpS6z00JFI8TFc6ECz5zPp+oHsu6ry4 X-Received: by 2002:a25:268c:: with SMTP id m134mr6320007ybm.253.1613157090169; Fri, 12 Feb 2021 11:11:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613157090; cv=none; d=google.com; s=arc-20160816; b=YnRoDoUtxE2fpL4aujAOM5ejNkupFiFvtigsApwqbzjTls+hWeD/d0XlTvdeGrn3vl /RyAgl6bFMTf/glAYV5bqLJiyc+FXdrjs4ERohE2+Mal6M3CKkMdMWdswTphduYhACgB v3Q0d4mIa63JL9HgtzK3UnrwDM7P73INX6W6eDOU5KuxACCQ+roWTHOXTA8VugaDOVzC HAd3jOfSvtICbz1T6zJl8Qkch4lb3bCB0EEuAoaVncQSozO3Q3T5wduztxS4pKUPGP33 iZE9DQBYgaFCf+8JMkigVBtZYs9gR3gHsBoQZZ90Pu9JC+I6c0T1SyjXD9Bc+OO52FXW WESQ== 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=ch6p0n2lq/t8EpS2QR/TzUItBZtqRgmNxCQ2fBsn7Kg=; b=krB6cpBJRFXCwKHGNdzgbrS58FQmlzL2TSzcAMnnoBhG1K4oLRfD4YJ6wzGm79gF26 s8YwVpEsk91NKtqsd/5qVPxCbfKaIjPHNo2Yz59HsVLRjNc2P64wltx/qMxzmVsfARCd YUopSSvi2NxwbdfVUHGA1axafMG+BWYNDjlcBLv6YYIe2zYSABnFeEXTa3xXS6a1j/WX 7yElW646CwnNHJE3r9kIOfaoWzpr9Zh8UL6sWm21xMD/FQ8cTXPfYygg9JZruwfoWNyX y8bRXo1zgw3Mq8XzN2ZAKWjb3a9VEM8cFQWBUXJdPjCgn9+sT9vDAqi7ecPlASvL6BSR GvDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J8Vy1Pgq; 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 e17si1604359ybn.368.2021.02.12.11.11.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Feb 2021 11:11:30 -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=J8Vy1Pgq; 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]:57566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lAdqi-0003ix-JS for patch@linaro.org; Fri, 12 Feb 2021 14:11:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39534) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lAdVX-0001mL-6G for qemu-devel@nongnu.org; Fri, 12 Feb 2021 13:49:35 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:36329) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lAdVO-0007ps-Nu for qemu-devel@nongnu.org; Fri, 12 Feb 2021 13:49:34 -0500 Received: by mail-pl1-x630.google.com with SMTP id e9so327683plh.3 for ; Fri, 12 Feb 2021 10:49:26 -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=ch6p0n2lq/t8EpS2QR/TzUItBZtqRgmNxCQ2fBsn7Kg=; b=J8Vy1Pgq6mnzhXkriN8kz+WDoUwbEzT7beUh165ZlTLDQOaHvibR/UpTRW4j1W0fXy oovTTuaj7I/8RLq8NBgUXNCxiJKeMWRgTtR0PYJC0G39DIjrC0daVkCdkCMSDVdk5F1U WWfncKdivSqLcYoB3v8gR6rDtE609JKMvHIDZYj+iUNnXx/SVwCawZTETBDOBTY92RpK A7/jiNkF3HdZJJeARD0DHpsJzVIIyFleOdJpQ/et2CteR9TCzS2EnZSF0GvTz66J82tB rhKT+SrLgx8cXlpaweeW82xYtxrmd4OTKLqZk+XNCCslwd4MQmPX9u0ZU+9zUe9DVlL9 jXPA== 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=ch6p0n2lq/t8EpS2QR/TzUItBZtqRgmNxCQ2fBsn7Kg=; b=rA3g7Lwnv/8HescpXSGYac8GN1rW7URIr6zE/ag+/+e7oBBu3U1Ub8ztLtNXk0A88z iOHuT0By4xLDwEuyQNR0AtKgkkNcw993w43ZkB8iODLR5Vt6gD/K7zqzH7GqFD+hueKn BzalgoQFsQ0r8hZUGg68QpQrWiwRM8R8OTY2itW7ndwcebRhD2qDr3zoRBiM0ewIxBvy Wd0wCmzOY2UuehLf5nxZPSCWhH21eo7ye+SKPzMPXscjJj68znYGCvc6whL8qKu8uKfU mZ4z6UHgfGfJs0V8Z3D7b4eg3LxC2+2tUmwYrWnRAla06KFt04VeKPFAIbdCp+FgoJW1 ToOQ== X-Gm-Message-State: AOAM532P6FWgXASSGOnXdOQTeLA742d4qPE7exsBAoY+FEtRDS0zDcET cD2eRpmPGBQsZCYtNkXt+57AGGkZ5YPjDQ== X-Received: by 2002:a17:90b:a58:: with SMTP id gw24mr3963764pjb.143.1613155765248; Fri, 12 Feb 2021 10:49:25 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Feb 2021 10:49:24 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v7 17/31] linux-user: Move lock_user et al out of line Date: Fri, 12 Feb 2021 10:48:48 -0800 Message-Id: <20210212184902.1251044-18-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::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.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.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" These functions are not small, except for unlock_user without debugging enabled. Move them out of line, and add missing braces on the way. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/qemu.h | 45 ++++++------------------------------------- linux-user/uaccess.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 39 deletions(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 82eabb73f8..36b58bd840 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -640,57 +640,24 @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len); /* Lock an area of guest memory into the host. If copy is true then the host area will have the same contents as the guest. */ -static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy) -{ - if (!access_ok_untagged(type, guest_addr, len)) { - return NULL; - } -#ifdef DEBUG_REMAP - { - void *addr; - addr = g_malloc(len); - if (copy) - memcpy(addr, g2h(guest_addr), len); - else - memset(addr, 0, len); - return addr; - } -#else - return g2h_untagged(guest_addr); -#endif -} +void *lock_user(int type, abi_ulong guest_addr, long len, int copy); /* Unlock an area of guest memory. The first LEN bytes must be flushed back to guest memory. host_ptr = NULL is explicitly allowed and does nothing. */ -static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, - long len) -{ - #ifdef DEBUG_REMAP - if (!host_ptr) - return; - if (host_ptr == g2h_untagged(guest_addr)) - return; - if (len > 0) - memcpy(g2h_untagged(guest_addr), host_ptr, len); - g_free(host_ptr); +static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, long len) +{ } +#else +void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); #endif -} /* Return the length of a string in target memory or -TARGET_EFAULT if access error. */ abi_long target_strlen(abi_ulong gaddr); /* Like lock_user but for null terminated strings. */ -static inline void *lock_user_string(abi_ulong guest_addr) -{ - abi_long len; - len = target_strlen(guest_addr); - if (len < 0) - return NULL; - return lock_user(VERIFY_READ, guest_addr, (long)(len + 1), 1); -} +void *lock_user_string(abi_ulong guest_addr); /* Helper macros for locking/unlocking a target struct. */ #define lock_user_struct(type, host_ptr, guest_addr, copy) \ diff --git a/linux-user/uaccess.c b/linux-user/uaccess.c index e215ecc2a6..bba012ed15 100644 --- a/linux-user/uaccess.c +++ b/linux-user/uaccess.c @@ -4,6 +4,52 @@ #include "qemu.h" +void *lock_user(int type, abi_ulong guest_addr, long len, int copy) +{ + if (!access_ok_untagged(type, guest_addr, len)) { + return NULL; + } +#ifdef DEBUG_REMAP + { + void *addr; + addr = g_malloc(len); + if (copy) { + memcpy(addr, g2h(guest_addr), len); + } else { + memset(addr, 0, len); + } + return addr; + } +#else + return g2h_untagged(guest_addr); +#endif +} + +#ifdef DEBUG_REMAP +void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); +{ + if (!host_ptr) { + return; + } + if (host_ptr == g2h_untagged(guest_addr)) { + return; + } + if (len > 0) { + memcpy(g2h_untagged(guest_addr), host_ptr, len); + } + g_free(host_ptr); +} +#endif + +void *lock_user_string(abi_ulong guest_addr) +{ + abi_long len = target_strlen(guest_addr); + if (len < 0) { + return NULL; + } + return lock_user(VERIFY_READ, guest_addr, (long)(len + 1), 1); +} + /* copy_from_user() and copy_to_user() are usually used to copy data * buffers between the target and host. These internally perform * locking/unlocking of the memory.