From patchwork Fri May 12 23:36:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 761878 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wPmbV2YXrz9s7y for ; Sat, 13 May 2017 09:37:08 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="hCnoFw8U"; dkim-atps=neutral Received: from localhost ([::1]:55661 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9K7M-0006Ln-Oj for incoming@patchwork.ozlabs.org; Fri, 12 May 2017 19:37:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43647) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9K6m-0006LN-S6 for qemu-devel@nongnu.org; Fri, 12 May 2017 19:36:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d9K6k-0007rm-6q for qemu-devel@nongnu.org; Fri, 12 May 2017 19:36:28 -0400 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]:36594) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d9K6j-0007r2-Vm; Fri, 12 May 2017 19:36:26 -0400 Received: by mail-lf0-x243.google.com with SMTP id h4so1189015lfj.3; Fri, 12 May 2017 16:36:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sCjDPYQKWj+P1yzZnsSXmqd4QP6dOWyYcYNIk/6aLc8=; b=hCnoFw8UdUkzBXtK+vrQs89rCauPrQkHkAwFaQDfFVOiprcJ/JVK/mQj3zqC2iinSa ou2VyxiWRmP0Vs6AsIureRI/UeLq9no4DP3LQYGY4NkwzqdRv/SvFYYfVuYNn/jQ8iTp dcn1EusixS2QKSMIZ1tbjfzTg1fRrksXJJxzMZRy252egbAmps0uFHIYY7swXpaly3To r4PdrzbsAArdjgno/afhjRqqCxUAWqEhZWGlXiySHA6Bo4nkzT/xKLQQN7iALlebz/q4 Fn+C5MMDf06ktdX0LPsVsFr81bj3yTt9HaZNMFRaP99lQrh15cQgGW8hl2XUatF6vw8x GKuQ== 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; bh=sCjDPYQKWj+P1yzZnsSXmqd4QP6dOWyYcYNIk/6aLc8=; b=RTUNndO5zNAWKGLteQnNYUI/9o6hT7uyn4bs4lOHuS8EVAoove8yFZv3tOaXAYhMQ8 pDGMQnVG9GkXc+u4D/xQnD2SYYlWbfkKI3LGuAdmV1EFYN3wdwMKOPKoGtVOs42yl4lg cGXrUS1n6mrM+B22u2lCx+f56orRssCmAOZN4Q5VrGwtE+/PtZXCFX/1tuhtXttQu0ht a54JKfJQtH2ykQmdjXQZ7HiTrAYwyGe1UtqfiB27vYxkHaBJjabAxIuf0/9gjD3VjVVg k4HJVhd5zTQIG2iF6XESoeVfXhi7sapbYu3coKQ0631mRqXhhPyFdoxPv+rxJ7iS8XBp QxMA== X-Gm-Message-State: AODbwcBF5dCyOq8ACtSMtBQxcyvcfLN2lCsWKmvHNXC+6VSz+f+sQAro iIZOyudlYJbUIA== X-Received: by 10.25.35.87 with SMTP id j84mr2421541lfj.118.1494632184806; Fri, 12 May 2017 16:36:24 -0700 (PDT) Received: from octofox.metropolis ([5.19.183.212]) by smtp.gmail.com with ESMTPSA id n79sm796790lfi.53.2017.05.12.16.36.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 May 2017 16:36:24 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:36:03 -0700 Message-Id: <1494632164-23799-3-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1494632164-23799-1-git-send-email-jcmvbkbc@gmail.com> References: <1494632164-23799-1-git-send-email-jcmvbkbc@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::243 Subject: [Qemu-devel] [PATCH 2/3] target/xtensa: fix return value of read/write simcalls X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Max Filippov , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Return value of read/write simcalls is not calculated correctly in case of operations crossing page boundary and in case of short reads/writes. Read and write simcalls should return the size of data actually read/written or -1 in case of error. Cc: qemu-stable@nongnu.org Signed-off-by: Max Filippov --- target/xtensa/xtensa-semi.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/target/xtensa/xtensa-semi.c b/target/xtensa/xtensa-semi.c index 98ae28c..ffcaf8d 100644 --- a/target/xtensa/xtensa-semi.c +++ b/target/xtensa/xtensa-semi.c @@ -166,6 +166,7 @@ void HELPER(simcall)(CPUXtensaState *env) uint32_t fd = regs[3]; uint32_t vaddr = regs[4]; uint32_t len = regs[5]; + uint32_t len_done = 0; while (len > 0) { hwaddr paddr = cpu_get_phys_page_debug(cs, vaddr); @@ -174,24 +175,38 @@ void HELPER(simcall)(CPUXtensaState *env) uint32_t io_sz = page_left < len ? page_left : len; hwaddr sz = io_sz; void *buf = cpu_physical_memory_map(paddr, &sz, !is_write); + uint32_t io_done; + bool error = false; if (buf) { vaddr += io_sz; len -= io_sz; - regs[2] = is_write ? + io_done = is_write ? write(fd, buf, io_sz) : read(fd, buf, io_sz); regs[3] = errno_h2g(errno); - cpu_physical_memory_unmap(buf, sz, !is_write, sz); - if (regs[2] == -1) { - break; + if (io_done == -1) { + error = true; + io_done = 0; } + cpu_physical_memory_unmap(buf, sz, !is_write, io_done); } else { - regs[2] = -1; + error = true; regs[3] = TARGET_EINVAL; break; } + if (error) { + if (!len_done) { + len_done = -1; + } + break; + } + len_done += io_done; + if (io_done < io_sz) { + break; + } } + regs[2] = len_done; } break;