From patchwork Tue Jan 10 17:39:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 640884 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp2874152pvb; Tue, 10 Jan 2023 11:09:48 -0800 (PST) X-Google-Smtp-Source: AMrXdXssTFo7JNi0OnEIt9yS1HOiBds9SUsaOqh+eo4OJWQjh4JygdW8uxKchP5iya6pKl2lS7E4 X-Received: by 2002:a05:622a:5a09:b0:3ae:a9a8:549b with SMTP id fy9-20020a05622a5a0900b003aea9a8549bmr6190791qtb.50.1673377788658; Tue, 10 Jan 2023 11:09:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673377788; cv=none; d=google.com; s=arc-20160816; b=C3nlxrUbMyDZ2Y/h7ip/KzyREA7rtIZjAXy5fdJpvZkrCGf/f8DqBYCYLtgUPPN6Y2 eavfdeUz1dVrcwXMYte1OBRtRWeUTNUotC1XKqEsOZzMeo0J7LJ+ydcw77vjyRMnU3C+ Ug2NMNCcjfiOGrMCREM+apFo1+l4Y7nHSgxhTcBNhA7J/wkLu+L9CI6PS1A2KRKECyzW scyorvC9JEGls7ZifHDoJCALGrMKQ5lwO+XjnKAmUNyHQnzK82XmNiP+XWplsejrZoc9 bzq0VAhGnoB+nXQMuvUQrT/HPJeEn60nvR3Z0+uhl3iAvuTnjytZoLdl6nLmvnJDixT1 StUQ== 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=/kMBc7kYwawlV6mjDVr7qPyvgsdPKM2HCAFr0iHJ9Nw=; b=aEAyDh2pMGKLcWtWr1e53I4GtqN9GNC6lUVOQAlqPWDvl/UQw5YLmF+CPWDGKRFulx v/Cdlv4pR2ddxxUkJfCpio8dXRi2gD7vrGK3NG9uSyV8NWC1zPV7qt4i8+OQvKeS3LyQ +q+kSwJ+5mYbxUSzhVWbewCi6Y19fOl2fWlW6NT1Rl6LqvPeAF6HRlMuuCNq77WsXqcc 6Zw5ctsDBqxtD/JGouk46NtmON0rOBDaDkLUHyZDtC89fqnvOJMfdhU/fg0gvjBwIsQj 9d6I0ij3aQxQSZUXXkjBFFYwjaeZo/Ftcc1UHV9iJWXIE7mIYorMng9wPoXpQE00yia7 oi1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UHhc0T0r; 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-20020ac853cb000000b003a7f3c46cffsi6688581qtq.716.2023.01.10.11.09.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Jan 2023 11:09: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=UHhc0T0r; 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 1pFIb6-0003Wm-T2; Tue, 10 Jan 2023 12:39:40 -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 1pFIb4-0003TR-D1 for qemu-devel@nongnu.org; Tue, 10 Jan 2023 12:39:38 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pFIb0-0001GY-Kq for qemu-devel@nongnu.org; Tue, 10 Jan 2023 12:39:38 -0500 Received: by mail-wm1-x32f.google.com with SMTP id l26so9370180wme.5 for ; Tue, 10 Jan 2023 09:39:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=/kMBc7kYwawlV6mjDVr7qPyvgsdPKM2HCAFr0iHJ9Nw=; b=UHhc0T0rb4uynWDAFJZnoOJ2P7Smw/qCsCapN9ijSucUCWMGpTbboSlB3VmjlGw2ZM B5c5hEgBRr96sdujQksdakonZDoDHxCnhPVKQ9ElQj1LsUE5dHsWunAnxObAYJXUdcSd Z5OBfCdSDY0GoXDjJbk2cF/bP1PQ6la6cHbrTCE/ny6VIHUmBw4GmhP9EatyfgEazIM0 3q/BL88aRuHbzsYXPSwtOfdOk6DpGnaxo5uLCplmL20hoP6XbDdOjaRqTMcq1p3FXc6k GAp+IlYb334t/AjNuUlrca/YwwlFW92ecZ8gPMBMM5WAgV6sMk2B1HCQO5KwOT0rZ6bW RxBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=/kMBc7kYwawlV6mjDVr7qPyvgsdPKM2HCAFr0iHJ9Nw=; b=IouljP4H5CrW0F2BToYjhWNXJimzCQjZIVMBsh8pas3QrCrWvaV0G5GUundEjdXkhw lYbJToE346NuXZbZizU1PYzeyOV9cYendlsShUVCAsoxWrBEHq9V60aLWFv3VLFwc6H9 bFZMDZLsUgkn7Vy4r8Rw/glzW5YUFFcsrpMOZ/W9S9sJvhN6Lu/peLM3kUoYHUPIMbYc LqRwhB6bHbHyQAnZ14aYyqP5BSCcrGcoNJEVtRx5bFDVFoO/fvFNtVFHTw0R2Dv6EbMD WUCGMbJ+0T/1sjFIB++CN2zQZhhaSi5hLS/u2gKtnWE8o00HvhPRGnYkaFYGVHRquTpw dOAA== X-Gm-Message-State: AFqh2kru5v6cOdtl1nsefBd0J888urx9ujeiP4G/AbHe48HX4+/8/g7b emYDM8I4YItsZXpx5J32uvqZBw== X-Received: by 2002:a05:600c:601e:b0:3c6:e61e:ae71 with SMTP id az30-20020a05600c601e00b003c6e61eae71mr60134889wmb.1.1673372373262; Tue, 10 Jan 2023 09:39:33 -0800 (PST) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id w6-20020adfd4c6000000b0027cb20605e3sm11612410wrk.105.2023.01.10.09.39.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 09:39:32 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 962D81FFC5; Tue, 10 Jan 2023 17:39:24 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Richard Henderson , Alexandre Iooss , Beraldo Leal , Thomas Huth , John Snow , Eduardo Habkost , Elena Ufimtseva , Ed Maste , Yanan Wang , Cleber Rosa , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Li-Wen Hsu , Markus Armbruster , Jagannathan Raman , =?utf-8?q?Daniel_P=2E_Berrang?= =?utf-8?q?=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Michael Roth , Wainer dos Santos Moschetta , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , qemu-arm@nongnu.org, Marcel Apfelbaum , Peter Maydell , Paolo Bonzini , Mahmoud Mandour , John G Johnson , Keith Packard Subject: [PATCH 13/26] semihosting: Write back semihosting data before completion callback Date: Tue, 10 Jan 2023 17:39:09 +0000 Message-Id: <20230110173922.265055-14-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110173922.265055-1-alex.bennee@linaro.org> References: <20230110173922.265055-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32f.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=unavailable 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 From: Keith Packard 'lock_user' allocates a host buffer to shadow a target buffer, 'unlock_user' copies that host buffer back to the target and frees the host memory. If the completion function uses the target buffer, it must be called after unlock_user to ensure the data are present. This caused the arm-compatible TARGET_SYS_READC to fail as the completion function, common_semi_readc_cb, pulled data from the target buffer which would not have been gotten the console data. I decided to fix all instances of this pattern instead of just the console_read function to make things consistent and potentially fix bugs in other cases. Signed-off-by: Keith Packard Reviewed-by: Richard Henderson Message-Id: <20221012014822.1242170-1-keithp@keithp.com> Signed-off-by: Alex Bennée --- semihosting/syscalls.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 5893c760c5..ba28194b59 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -319,11 +319,11 @@ static void host_read(CPUState *cs, gdb_syscall_complete_cb complete, } ret = RETRY_ON_EINTR(read(gf->hostfd, ptr, len)); if (ret == -1) { - complete(cs, -1, errno); unlock_user(ptr, buf, 0); + complete(cs, -1, errno); } else { - complete(cs, ret, 0); unlock_user(ptr, buf, ret); + complete(cs, ret, 0); } } @@ -339,8 +339,8 @@ static void host_write(CPUState *cs, gdb_syscall_complete_cb complete, return; } ret = write(gf->hostfd, ptr, len); - complete(cs, ret, ret == -1 ? errno : 0); unlock_user(ptr, buf, 0); + complete(cs, ret, ret == -1 ? errno : 0); } static void host_lseek(CPUState *cs, gdb_syscall_complete_cb complete, @@ -426,8 +426,8 @@ static void host_stat(CPUState *cs, gdb_syscall_complete_cb complete, ret = -1; } } - complete(cs, ret, err); unlock_user(name, fname, 0); + complete(cs, ret, err); } static void host_remove(CPUState *cs, gdb_syscall_complete_cb complete, @@ -444,8 +444,8 @@ static void host_remove(CPUState *cs, gdb_syscall_complete_cb complete, } ret = remove(p); - complete(cs, ret, ret ? errno : 0); unlock_user(p, fname, 0); + complete(cs, ret, ret ? errno : 0); } static void host_rename(CPUState *cs, gdb_syscall_complete_cb complete, @@ -469,9 +469,9 @@ static void host_rename(CPUState *cs, gdb_syscall_complete_cb complete, } ret = rename(ostr, nstr); - complete(cs, ret, ret ? errno : 0); unlock_user(ostr, oname, 0); unlock_user(nstr, nname, 0); + complete(cs, ret, ret ? errno : 0); } static void host_system(CPUState *cs, gdb_syscall_complete_cb complete, @@ -488,8 +488,8 @@ static void host_system(CPUState *cs, gdb_syscall_complete_cb complete, } ret = system(p); - complete(cs, ret, ret == -1 ? errno : 0); unlock_user(p, cmd, 0); + complete(cs, ret, ret == -1 ? errno : 0); } static void host_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete, @@ -554,8 +554,8 @@ static void staticfile_read(CPUState *cs, gdb_syscall_complete_cb complete, } memcpy(ptr, gf->staticfile.data + gf->staticfile.off, len); gf->staticfile.off += len; - complete(cs, len, 0); unlock_user(ptr, buf, len); + complete(cs, len, 0); } static void staticfile_lseek(CPUState *cs, gdb_syscall_complete_cb complete, @@ -608,8 +608,8 @@ static void console_read(CPUState *cs, gdb_syscall_complete_cb complete, return; } ret = qemu_semihosting_console_read(cs, ptr, len); - complete(cs, ret, 0); unlock_user(ptr, buf, ret); + complete(cs, ret, 0); } static void console_write(CPUState *cs, gdb_syscall_complete_cb complete, @@ -624,8 +624,8 @@ static void console_write(CPUState *cs, gdb_syscall_complete_cb complete, return; } ret = qemu_semihosting_console_write(ptr, len); - complete(cs, ret ? ret : -1, ret ? 0 : EIO); unlock_user(ptr, buf, 0); + complete(cs, ret ? ret : -1, ret ? 0 : EIO); } static void console_fstat(CPUState *cs, gdb_syscall_complete_cb complete,