From patchwork Mon May 18 15:53:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 282466 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47778C433E1 for ; Mon, 18 May 2020 15:54:45 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 165C320758 for ; Mon, 18 May 2020 15:54:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kCSqrZiB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 165C320758 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:38658 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jai6G-0005Qk-5X for qemu-devel@archiver.kernel.org; Mon, 18 May 2020 11:54:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jai4p-00031x-Dd; Mon, 18 May 2020 11:53:15 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:53827) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jai4n-000050-5c; Mon, 18 May 2020 11:53:15 -0400 Received: by mail-wm1-x342.google.com with SMTP id k12so20655wmj.3; Mon, 18 May 2020 08:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WSFyr6f19aP4N4MMJJARifgNu7cVe5tnytMgFa4vhLY=; b=kCSqrZiBJYfTvK6U7vz3nNDXw8i72uTGkX8UjayRNSx1b87A6HZyN0RCp9RgEzIN0G qWNlCkhAfu32BYTwCLRdc01DpTLebfKGRZENxPGloToarBft+JLovARNHt3Zm5JpiOFb VAmXclSfNHTPsASzzd+5Vo/Ib/iqvhUsdfDPO8VIutjrO5t7FrU6hlXCXcT5h2jVueTR s/m9n5HsKERdFsQ7+K4XiY/S9K6T8aned4oF9+6DsGouHBcACygZhGM0HhzemufQ8c0m 1SMjBI0ljkR3A+dajrtCahHCwr35VD8FFfX24g9to1COczOsGSx8MST9/AnK7B7azqah +gGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=WSFyr6f19aP4N4MMJJARifgNu7cVe5tnytMgFa4vhLY=; b=IyqvI/YZLqxQPn8Qh5cqL6AKWJ1tEd6ydygB8L0Ho6QmyGNh1EmTIhYLJ9ZdUDh1Uw Q7Sh9OsLZtEUnb9xOdqvcT3qyRwCd5OGWe+PYhB7KGRBNK3wSDoO+M0U0NE1KBiErS9e UFji4QXFnXXCoCB5v69ca3ws0neZQ3YZhIZ32Mc6gicsVLFg6Ar48AifxGRE3mlH4FNS POWZSreS94CsHT1nWbqUr3qR2YItc98a4NYfZVAJFQQ52b8DN9q7nJeBtCZthTFZMaFz U6Qv4BdhK7ZRzgHWJFeoLq+Pe395q5cDZuFyK42iM3uvGh8qbEWksY+YVSA0o+V1f/tp sYZg== X-Gm-Message-State: AOAM532ONNXtLkJ53AomqufL97VllhP27sH7lrypSD/xfmqMGAbOTG4O ObCJBfxPRERQSaNPCum1ydXr8ZhoNko= X-Google-Smtp-Source: ABdhPJwFmlOQ4JYI++JR9ixqC4zYUF4jca3lwFeihkNHUxT11OuH2+k/On4eJQV74FyKNuuQu/d9Dg== X-Received: by 2002:a7b:cf15:: with SMTP id l21mr32568wmg.172.1589817191110; Mon, 18 May 2020 08:53:11 -0700 (PDT) Received: from x1w.redhat.com (17.red-88-21-202.staticip.rima-tde.net. [88.21.202.17]) by smtp.gmail.com with ESMTPSA id 7sm17647462wra.50.2020.05.18.08.53.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 08:53:10 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v2 1/7] exec: Let address_space_read/write_cached() propagate MemTxResult Date: Mon, 18 May 2020 17:53:02 +0200 Message-Id: <20200518155308.15851-2-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200518155308.15851-1-f4bug@amsat.org> References: <20200518155308.15851-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::342; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x342.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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 , kvm@vger.kernel.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Both address_space_read_cached_slow() and address_space_write_cached_slow() return a MemTxResult type. Do not discard it, return it to the caller. Signed-off-by: Philippe Mathieu-Daudé --- include/exec/memory.h | 19 +++++++++++-------- exec.c | 16 ++++++++-------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index e000bd2f97..5e8c009169 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2343,10 +2343,11 @@ void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr); /* Internal functions, part of the implementation of address_space_read_cached * and address_space_write_cached. */ -void address_space_read_cached_slow(MemoryRegionCache *cache, - hwaddr addr, void *buf, hwaddr len); -void address_space_write_cached_slow(MemoryRegionCache *cache, - hwaddr addr, const void *buf, hwaddr len); +MemTxResult address_space_read_cached_slow(MemoryRegionCache *cache, + hwaddr addr, void *buf, hwaddr len); +MemTxResult address_space_write_cached_slow(MemoryRegionCache *cache, + hwaddr addr, const void *buf, + hwaddr len); static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) { @@ -2411,15 +2412,16 @@ MemTxResult address_space_read(AddressSpace *as, hwaddr addr, * @buf: buffer with the data transferred * @len: length of the data transferred */ -static inline void +static inline MemTxResult address_space_read_cached(MemoryRegionCache *cache, hwaddr addr, void *buf, hwaddr len) { assert(addr < cache->len && len <= cache->len - addr); if (likely(cache->ptr)) { memcpy(buf, cache->ptr + addr, len); + return MEMTX_OK; } else { - address_space_read_cached_slow(cache, addr, buf, len); + return address_space_read_cached_slow(cache, addr, buf, len); } } @@ -2431,15 +2433,16 @@ address_space_read_cached(MemoryRegionCache *cache, hwaddr addr, * @buf: buffer with the data transferred * @len: length of the data transferred */ -static inline void +static inline MemTxResult address_space_write_cached(MemoryRegionCache *cache, hwaddr addr, const void *buf, hwaddr len) { assert(addr < cache->len && len <= cache->len - addr); if (likely(cache->ptr)) { memcpy(cache->ptr + addr, buf, len); + return MEMTX_OK; } else { - address_space_write_cached_slow(cache, addr, buf, len); + return address_space_write_cached_slow(cache, addr, buf, len); } } diff --git a/exec.c b/exec.c index 5162f0d12f..877b51cc5c 100644 --- a/exec.c +++ b/exec.c @@ -3716,7 +3716,7 @@ static inline MemoryRegion *address_space_translate_cached( /* Called from RCU critical section. address_space_read_cached uses this * out of line function when the target is an MMIO or IOMMU region. */ -void +MemTxResult address_space_read_cached_slow(MemoryRegionCache *cache, hwaddr addr, void *buf, hwaddr len) { @@ -3726,15 +3726,15 @@ address_space_read_cached_slow(MemoryRegionCache *cache, hwaddr addr, l = len; mr = address_space_translate_cached(cache, addr, &addr1, &l, false, MEMTXATTRS_UNSPECIFIED); - flatview_read_continue(cache->fv, - addr, MEMTXATTRS_UNSPECIFIED, buf, len, - addr1, l, mr); + return flatview_read_continue(cache->fv, + addr, MEMTXATTRS_UNSPECIFIED, buf, len, + addr1, l, mr); } /* Called from RCU critical section. address_space_write_cached uses this * out of line function when the target is an MMIO or IOMMU region. */ -void +MemTxResult address_space_write_cached_slow(MemoryRegionCache *cache, hwaddr addr, const void *buf, hwaddr len) { @@ -3744,9 +3744,9 @@ address_space_write_cached_slow(MemoryRegionCache *cache, hwaddr addr, l = len; mr = address_space_translate_cached(cache, addr, &addr1, &l, true, MEMTXATTRS_UNSPECIFIED); - flatview_write_continue(cache->fv, - addr, MEMTXATTRS_UNSPECIFIED, buf, len, - addr1, l, mr); + return flatview_write_continue(cache->fv, + addr, MEMTXATTRS_UNSPECIFIED, buf, len, + addr1, l, mr); } #define ARG1_DECL MemoryRegionCache *cache From patchwork Mon May 18 15:53:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 282464 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D2EEC433DF for ; Mon, 18 May 2020 15:57:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EC15620758 for ; Mon, 18 May 2020 15:57:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IOBfw97b" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EC15620758 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jai9J-0003eF-Ka for qemu-devel@archiver.kernel.org; Mon, 18 May 2020 11:57:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52616) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jai4r-00037m-Ho; Mon, 18 May 2020 11:53:17 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:37537) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jai4q-00005l-O8; Mon, 18 May 2020 11:53:17 -0400 Received: by mail-wm1-x342.google.com with SMTP id z72so32918wmc.2; Mon, 18 May 2020 08:53:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YgUO7urc8a2H2l0AjA6/YcXX+FHCC3nhZ10cz3IJGT0=; b=IOBfw97bri/HK4rNN8hBH3fS/bLjGzm8A0H/8IkZ8BNpXTH5MWOLMb3YVIeMZKbemA 3ANvreACUxm3uKFDJZEe4MA+7GDtRxgdRAvLMjOBMc7JlM5setDqR+rAAjGrhOViOGZF 2Wqfu4cYar/pwmzsrnDNSa2HYymGPUjbGygmgHP6rSFAaV7KZ4Aj7Zf8fLfG4mjSdzoj O0xMbKFIM8aKXXnAyWz+2OWRz7ivmrJrmm2ilOqTEom06SGkiN9a0F3K1QeVvnWoTdEt L9ra6YC/35hRflgOsBpof5I6H7BbRnEo+uNLoC00Y9tDyfK0lemm9ge5tj8eq1k8Vg70 hyyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=YgUO7urc8a2H2l0AjA6/YcXX+FHCC3nhZ10cz3IJGT0=; b=UzYfulLDKakKYiCKJDekG3GwUxyRJTRwUIsxadnAnl5wETx+j2LbnJ31pdSS8YCog4 AkVSOst2BQYsLGKHk8O1Dc2IDHPedYGsveoABrnOEzqthETAqWTKSxtuenoW4HZD1K0/ GXuCII8KiWI4axtw2zhJgp0DGgGew/0+Z/iQeJyuZV1OcYZoo8Od3iSHAPXLFHVCPIRD RugRDY3lcze75ZAp7+DdwY0pcfJjJKyoK0f5XQ2dnBXBoG4sy3ulOq6ShhvRMqPnuV0G Iu2Ii804OZRQ8GeioKY/Hn9wCm1AmVLTtGZeSGOVw1KPx/ustNkZhQiU+6LYXqWnV8bj cCNQ== X-Gm-Message-State: AOAM53088fCRomxqjHHrq2pL0OxUDNzIAp7xZBCbbFGtQewC1nU2QYiH MhH+Vo52aB6ncJ4Se3QqjUqLF8YDSYA= X-Google-Smtp-Source: ABdhPJyG3gmRwNj2wCtQakz1KaSpc4CoE3n4quosHaeNbq9NCRoNUZ4NxGqjRfI4JksaALSu8mA24w== X-Received: by 2002:a1c:4cb:: with SMTP id 194mr42967wme.124.1589817194856; Mon, 18 May 2020 08:53:14 -0700 (PDT) Received: from x1w.redhat.com (17.red-88-21-202.staticip.rima-tde.net. [88.21.202.17]) by smtp.gmail.com with ESMTPSA id 7sm17647462wra.50.2020.05.18.08.53.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 08:53:14 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v2 4/7] hw/elf_ops: Do not ignore write failures when loading ELF Date: Mon, 18 May 2020 17:53:05 +0200 Message-Id: <20200518155308.15851-5-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200518155308.15851-1-f4bug@amsat.org> References: <20200518155308.15851-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::342; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x342.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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 , kvm@vger.kernel.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Do not ignore the MemTxResult error type returned by address_space_write(). Signed-off-by: Philippe Mathieu-Daudé --- include/hw/elf_ops.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h index 398a4a2c85..6fdff3dced 100644 --- a/include/hw/elf_ops.h +++ b/include/hw/elf_ops.h @@ -553,9 +553,14 @@ static int glue(load_elf, SZ)(const char *name, int fd, rom_add_elf_program(label, mapped_file, data, file_size, mem_size, addr, as); } else { - address_space_write(as ? as : &address_space_memory, - addr, MEMTXATTRS_UNSPECIFIED, - data, file_size); + MemTxResult res; + + res = address_space_write(as ? as : &address_space_memory, + addr, MEMTXATTRS_UNSPECIFIED, + data, file_size); + if (res != MEMTX_OK) { + goto fail; + } } } From patchwork Mon May 18 15:53:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 282463 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD90AC433DF for ; Mon, 18 May 2020 15:59:33 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 84FEC20758 for ; Mon, 18 May 2020 15:59:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Flh1kB0g" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 84FEC20758 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:35082 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jaiAu-00077p-Ng for qemu-devel@archiver.kernel.org; Mon, 18 May 2020 11:59:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jai4s-0003BJ-Og; Mon, 18 May 2020 11:53:18 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:53828) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jai4r-00006S-Uh; Mon, 18 May 2020 11:53:18 -0400 Received: by mail-wm1-x342.google.com with SMTP id k12so20927wmj.3; Mon, 18 May 2020 08:53:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AnPjL1oCKd4/b0PMNN6nSj2GzQNIyIXoJD4PkkEccRM=; b=Flh1kB0guv4yAbKeDYrp5crvlMR5ihhTkgC4sUeRwuaqgo7GD0MKjJWTUa6Hw2L8xS CIsyCqO5AvcZ8OwqPdLT8OmZa/ij6U5deh3S8uaWtf/VidtkoeX+VHIABeeardCArTHX XNSnRdTy+EpyBchdo7vAMIvPG9o1VFjX+MkOHh1KL+C8pX1vZ0yVTp7rYBokW9sBGV7p uaLB7O6eaQG+1utdhsPZlItO485bABIknYR8tYuO+twhZvT1wOLhGP6aF/ija6iTfvyZ QkiXHLZ+FGIYWRNLOIOko72PY6W/2aVr6hJAQD/zFfc6NyNFkhqADfHmd5GIQxeXeG49 +otg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=AnPjL1oCKd4/b0PMNN6nSj2GzQNIyIXoJD4PkkEccRM=; b=SnddOz38SngJwdoBAbwWbehQvMLxqtvxOeVIIoMmaflu9hLQDieyNIcVeoNyHyNQKt PZuBgIx2dx2XCdf0i3wgW7zNhcAtpHYnmgDTJuUyi6wIMPfeKz/ArtCgpRZuRzsAmAk8 RhkTAIY4fk70QELvgV3fbIbaxouFdDWCc2j4ZnOAZbXh/13VzEzrvDX4cmWNvpzpDyQM Zhu1b3KN2NCeuOpgpNo3Oi/bV41t7jtO6lqR+yNSb6ZwHwQYagXKFyLUyHWS+yx0QaHG lunAQwG0rwvtKCTGOgD9tbLLEngPB0l03GCrsJ/jNqMJt3YjfinIabAypjU5QlXCYjUe WXRw== X-Gm-Message-State: AOAM532YjEGDH1y49Y9AhgWjM88zvO9gQJvF8OOktLe2OFEQM6A5qxhx glGxwb5Zo29u3GCZVH8SDXPWiXlIPVs= X-Google-Smtp-Source: ABdhPJz/PtyrwAQIbRp4mpLoU+mt0aZlERs2l79lSNvZZ5pevIUK5/V9XwfG5nxxlERMi6Y3l+3eOA== X-Received: by 2002:a1c:3187:: with SMTP id x129mr24994wmx.27.1589817196118; Mon, 18 May 2020 08:53:16 -0700 (PDT) Received: from x1w.redhat.com (17.red-88-21-202.staticip.rima-tde.net. [88.21.202.17]) by smtp.gmail.com with ESMTPSA id 7sm17647462wra.50.2020.05.18.08.53.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 08:53:15 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v2 5/7] hw/arm/boot: Abort if set_kernel_args() fails Date: Mon, 18 May 2020 17:53:06 +0200 Message-Id: <20200518155308.15851-6-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200518155308.15851-1-f4bug@amsat.org> References: <20200518155308.15851-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::342; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x342.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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 , kvm@vger.kernel.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" If a address_space_write() fails while calling set_kernel_args(), the guest kernel will boot using crap data. Avoid that by aborting if this ever occurs. Signed-off-by: Philippe Mathieu-Daudé --- hw/arm/boot.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index fef4072db1..7cc271034c 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -291,7 +291,8 @@ static inline bool have_dtb(const struct arm_boot_info *info) #define WRITE_WORD(p, value) do { \ address_space_stl_notdirty(as, p, value, \ - MEMTXATTRS_UNSPECIFIED, NULL); \ + MEMTXATTRS_UNSPECIFIED, &result); \ + assert(result == MEMTX_OK); \ p += 4; \ } while (0) @@ -300,6 +301,7 @@ static void set_kernel_args(const struct arm_boot_info *info, AddressSpace *as) int initrd_size = info->initrd_size; hwaddr base = info->loader_start; hwaddr p; + MemTxResult result; p = base + KERNEL_ARGS_ADDR; /* ATAG_CORE */ @@ -326,8 +328,9 @@ static void set_kernel_args(const struct arm_boot_info *info, AddressSpace *as) int cmdline_size; cmdline_size = strlen(info->kernel_cmdline); - address_space_write(as, p + 8, MEMTXATTRS_UNSPECIFIED, - info->kernel_cmdline, cmdline_size + 1); + result = address_space_write(as, p + 8, MEMTXATTRS_UNSPECIFIED, + info->kernel_cmdline, cmdline_size + 1); + assert(result == MEMTX_OK); cmdline_size = (cmdline_size >> 2) + 1; WRITE_WORD(p, cmdline_size + 2); WRITE_WORD(p, 0x54410009); @@ -341,8 +344,9 @@ static void set_kernel_args(const struct arm_boot_info *info, AddressSpace *as) atag_board_len = (info->atag_board(info, atag_board_buf) + 3) & ~3; WRITE_WORD(p, (atag_board_len + 8) >> 2); WRITE_WORD(p, 0x414f4d50); - address_space_write(as, p, MEMTXATTRS_UNSPECIFIED, - atag_board_buf, atag_board_len); + result = address_space_write(as, p, MEMTXATTRS_UNSPECIFIED, + atag_board_buf, atag_board_len); + assert(result == MEMTX_OK); p += atag_board_len; } /* ATAG_END */ @@ -357,6 +361,7 @@ static void set_kernel_args_old(const struct arm_boot_info *info, const char *s; int initrd_size = info->initrd_size; hwaddr base = info->loader_start; + MemTxResult result; /* see linux/include/asm-arm/setup.h */ p = base + KERNEL_ARGS_ADDR; @@ -419,7 +424,9 @@ static void set_kernel_args_old(const struct arm_boot_info *info, } s = info->kernel_cmdline; if (s) { - address_space_write(as, p, MEMTXATTRS_UNSPECIFIED, s, strlen(s) + 1); + result = address_space_write(as, p, MEMTXATTRS_UNSPECIFIED, + s, strlen(s) + 1); + assert(result == MEMTX_OK); } else { WRITE_WORD(p, 0); } From patchwork Mon May 18 15:53:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 282465 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75021C433DF for ; Mon, 18 May 2020 15:56:44 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3B8F320758 for ; Mon, 18 May 2020 15:56:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="egYB1Vpd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B8F320758 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49386 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jai8B-0001Od-Dq for qemu-devel@archiver.kernel.org; Mon, 18 May 2020 11:56:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52630) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jai4u-0003Gi-Mq; Mon, 18 May 2020 11:53:20 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:43678) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jai4t-00006f-A7; Mon, 18 May 2020 11:53:20 -0400 Received: by mail-wr1-x443.google.com with SMTP id i15so12425723wrx.10; Mon, 18 May 2020 08:53:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MwRjIJKrjZvOQLKRDS7bp2j+HXuefv0dlJUo1+WtTjQ=; b=egYB1VpdfFdcLU33RJfphrswTKxeIP4BjafZIjlthVmO7DNr1l7McScI+IvtmLndG9 WjD9LpiJcPgoH1MQBUkML5lgSFY7x3NaGka7xlkROcXaUy0M0SBcrXd5T4VzdZLNz/tc JPL6wSS5HtdO9ff8Wg6X7bJESUkg8Ef8SEfUZKgdpq2BBN6kuw95k/w84PQl6K2QTuQC IfkMkWm7skqibMMRLPYi373AjZVNZgP9ah9kIfJgJMlSEaP6vC7XibL1zckb5Buz9xo2 NTkPmJYYngauoD6KSjjGbIr3/BaenDgDt52tGVYYC0VdUp9L+LhUZnZUisxS9bM1br6K NHqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=MwRjIJKrjZvOQLKRDS7bp2j+HXuefv0dlJUo1+WtTjQ=; b=OVhAN4A7VXJCGXmqnREoWY1LvSbuojT9QzZn6Y9fcxA19BnN9ziPb3lxzrVvT8iYWM 3ae2YPRD+5wHbkI5ahZjcRIN48r52ySMCnHxJCvn2goOWyVgK42KhonVwGXqDofzOYNs 8cMGrF3qTXJMVPFM1aW+A6UFcjucqgK+V10bD3zBtPAdOll9R61eh22h7LeYx/S3pApP aYYK+t7cRmoGgVNvkH47oMiwxhF8e2YmDJsTBLl3wPyax863+PKWK+tqvFua+zvdiWo4 bha864oieXXP31hd0TYgYd6zs5mmng0J66S0A9oRGRPpq5biVZ2NAQaJ11KqWe8oY8m8 M+jw== X-Gm-Message-State: AOAM533rn9X8wOIXaj5rEwJkcBEwC+MzCbYSuNeBbKVKAlU/WEf44KzS KRR8Rwd6EsZ/BIgfYdLM/NB8pDW6Pq4= X-Google-Smtp-Source: ABdhPJz1bQDAMP2DFoPgL6gHBe6UaVxFp/cuSu6npvqkdthflrPa4uaDYx8RUUQurNbZEJssxkBzSA== X-Received: by 2002:a5d:6144:: with SMTP id y4mr21050664wrt.185.1589817197210; Mon, 18 May 2020 08:53:17 -0700 (PDT) Received: from x1w.redhat.com (17.red-88-21-202.staticip.rima-tde.net. [88.21.202.17]) by smtp.gmail.com with ESMTPSA id 7sm17647462wra.50.2020.05.18.08.53.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 08:53:16 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 6/7] accel/kvm: Let KVM_EXIT_MMIO return error Date: Mon, 18 May 2020 17:53:07 +0200 Message-Id: <20200518155308.15851-7-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200518155308.15851-1-f4bug@amsat.org> References: <20200518155308.15851-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::443; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x443.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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 , kvm@vger.kernel.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Give the hypervisor a possibility to catch any error occuring during KVM_EXIT_MMIO. Signed-off-by: Philippe Mathieu-Daudé --- RFC because maybe we simply want to ignore this error instead --- accel/kvm/kvm-all.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index d06cc04079..8dbcb8fda3 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2357,6 +2357,7 @@ int kvm_cpu_exec(CPUState *cpu) do { MemTxAttrs attrs; + MemTxResult res; if (cpu->vcpu_dirty) { kvm_arch_put_registers(cpu, KVM_PUT_RUNTIME_STATE); @@ -2429,12 +2430,12 @@ int kvm_cpu_exec(CPUState *cpu) case KVM_EXIT_MMIO: DPRINTF("handle_mmio\n"); /* Called outside BQL */ - address_space_rw(&address_space_memory, - run->mmio.phys_addr, attrs, - run->mmio.data, - run->mmio.len, - run->mmio.is_write); - ret = 0; + res = address_space_rw(&address_space_memory, + run->mmio.phys_addr, attrs, + run->mmio.data, + run->mmio.len, + run->mmio.is_write); + ret = res == MEMTX_OK ? 0 : -1; break; case KVM_EXIT_IRQ_WINDOW_OPEN: DPRINTF("irq_window_open\n");