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: 11555619 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A4CD913 for ; Mon, 18 May 2020 15:53:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 51D87207D8 for ; Mon, 18 May 2020 15:53:15 +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" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728397AbgERPxN (ORCPT ); Mon, 18 May 2020 11:53:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728267AbgERPxM (ORCPT ); Mon, 18 May 2020 11:53:12 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5103CC061A0C for ; Mon, 18 May 2020 08:53:12 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id n5so50210wmd.0 for ; 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=tYk4lgG4Qr1Xb35Ejkee4gxt9udn9IokIXVVtPZbQN1BNRIOeTGzEUQCqEWbGRYk4W j15LknqAciHIphqbGjXkcgWLbNwajxnbuQB7jMkcd193hgq21DEqMCwU0n/3hx5TDAAF SvGyLpcCNMwBx/LH6wTZ50gK0WEu3BpScKbym1wkTWXqw8IskHkj5sIvzUYKO5Cce+7Q MWOqGyfL9VA2eFh98ldsARTH5ngFjNs4l+zpI/xLqX2tLSBZbGv8DhzvBtYJWOFct1mH zrueKXPWz0f+QsWmp1SbYM3BY64Fi7UvJel7m9QbuRXZj9UKG1qHhCQDINhBqM90qHrV DVkQ== X-Gm-Message-State: AOAM532RmqivNAQgAAtMIEPag/0fHnsu1pTrUXmheHE3Hta0XKHBcl7o y8r/BqwaMwQaWfn0Nmz5h7U= 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 Cc: Peter Maydell , Paolo Bonzini , kvm@vger.kernel.org, qemu-arm@nongnu.org, Richard Henderson , =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= 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 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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é Reviewed-by: Peter Maydell --- 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:03 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: 11555627 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 26DEE739 for ; Mon, 18 May 2020 15:53:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0F05020758 for ; Mon, 18 May 2020 15:53:23 +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="GBNszTaa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728461AbgERPxQ (ORCPT ); Mon, 18 May 2020 11:53:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727050AbgERPxN (ORCPT ); Mon, 18 May 2020 11:53:13 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6724EC061A0C for ; Mon, 18 May 2020 08:53:13 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id m185so25450wme.3 for ; Mon, 18 May 2020 08:53:13 -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=WPXev8+IwguGZ8+5BAOfNLRRppnJCLUsP59v0te4Ye0=; b=GBNszTaaBEoLSKErf6Onp2KjlP2lFLTKTV4hGUyCnOMb7cgyVRocIEAPY8J3mCvb8Z vCLXgoCH3exBUN+Yjhpatnjh2Fa5e1ewx1l3wOj4/SrE8ApiJzbGKFBw2Fk0/ADaP63I bKZiVONe3xodATG6yQv3Mm0gvaazMRU/T7zFjIayETtffjPtUlcgjkmY4YHXL9KjPjUG 8NwSfTHR05vPqYuItDiHZDYMDcHpYzEeXbnyBK2nu5eOha5ZGzFFsSAJhOruzapfQKPz 24y236VkwWStBZHxoh2/GZN2xjsFUq8IM0KPfG/DLwlqaj2FIlz5EX4CG6JWCxKql8/O rSgA== 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=WPXev8+IwguGZ8+5BAOfNLRRppnJCLUsP59v0te4Ye0=; b=Bg/vPV2C128Of0qT69sEReRvrrN+rKmRGMY7Um0HQNjxJ+M14WoGzvyQSF6TwX3kMN 1Bfdhg5plF7vRUu6j9Gh3SY2VzQw9VAStp8XsyLB9VL71la9Nh3ZWyWkmlrCKS9CgniZ I/Ckr90WUjj+xw9v1fRxQG0pT+nJh9YRGlmdIu+77aK6HFH1mae2nCQdqdHG6psqdVy9 4sdmmSlCyuPrtpIoSojaqE8NVUcl3+In6dXSibzMsNMZoHSffqunlVHBvAL4a73kk1U5 dYsCX/bDldyd2iAyjNMJuGgvjnuSwuLr7eswPVUv7QZEpDCuNelXex3lTUx/HRusX00W hBgA== X-Gm-Message-State: AOAM531o5S2soUAHfa97pcmc1pOFEN/+Y5Ny1+VJB/XciCx70tjFYUqF 25JMSu8PuFS2hSYOp2uIXWQ= X-Google-Smtp-Source: ABdhPJzmaRkrF6Y1/DbPQKadJiZELqBF4agH6qtXZaXxgNHiLJ/vIraP/94NcfVxkbXCvsz/IBZspw== X-Received: by 2002:a7b:c8d4:: with SMTP id f20mr60869wml.72.1589817192193; Mon, 18 May 2020 08:53:12 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 08:53:11 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Peter Maydell , Paolo Bonzini , kvm@vger.kernel.org, qemu-arm@nongnu.org, Richard Henderson , =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 2/7] exec: Propagate cpu_memory_rw_debug() error Date: Mon, 18 May 2020 17:53:03 +0200 Message-Id: <20200518155308.15851-3-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 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Do not ignore the MemTxResult error type returned by the address_space_rw() API. Signed-off-by: Philippe Mathieu-Daudé --- include/exec/cpu-all.h | 1 + exec.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index d14374bdd4..fb4e8a8e29 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -413,6 +413,7 @@ void dump_exec_info(void); void dump_opcount_info(void); #endif /* !CONFIG_USER_ONLY */ +/* Returns: 0 on success, -1 on error */ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr, void *ptr, target_ulong len, bool is_write); diff --git a/exec.c b/exec.c index 877b51cc5c..ae5a6944ef 100644 --- a/exec.c +++ b/exec.c @@ -3769,6 +3769,7 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr, while (len > 0) { int asidx; MemTxAttrs attrs; + MemTxResult res; page = addr & TARGET_PAGE_MASK; phys_addr = cpu_get_phys_page_attrs_debug(cpu, page, &attrs); @@ -3781,11 +3782,14 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr, l = len; phys_addr += (addr & ~TARGET_PAGE_MASK); if (is_write) { - address_space_write_rom(cpu->cpu_ases[asidx].as, phys_addr, - attrs, buf, l); + res = address_space_write_rom(cpu->cpu_ases[asidx].as, phys_addr, + attrs, buf, l); } else { - address_space_read(cpu->cpu_ases[asidx].as, phys_addr, attrs, buf, - l); + res = address_space_read(cpu->cpu_ases[asidx].as, phys_addr, + attrs, buf, l); + } + if (res != MEMTX_OK) { + return -1; } len -= l; buf += l; From patchwork Mon May 18 15:53:04 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: 11555631 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 14942913 for ; Mon, 18 May 2020 15:53:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F18B7207D8 for ; Mon, 18 May 2020 15:53:25 +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="nurR+oeq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728267AbgERPxZ (ORCPT ); Mon, 18 May 2020 11:53:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728420AbgERPxP (ORCPT ); Mon, 18 May 2020 11:53:15 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEE0DC05BD0A for ; Mon, 18 May 2020 08:53:14 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id z72so32834wmc.2 for ; Mon, 18 May 2020 08:53:14 -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=bB9pDUjiIlea3U386GXuZY1NOAMaybVFycH+ZuoRiV0=; b=nurR+oeqvO38IlVAvYjrxVv0j0dklv6u3yVTDJ9MjtfJGYrgNsKLWs7v/EuSfT1Fyw 0hekQj/tWlRwGvIoHSlzW9AuZtciTPQcEplw1Pk8G6K0Hbrx+YNLGqJqwsJiwTdGA5Ne v9/csSObyWiXDO8tXRQFSARTVgrKmme1B4xlK6G65N3bOCs9+um2jRul25Bre3/UOTza OGPqc/K941siuivQI1Wp+Y4WrR+at7LjrzQjI27bJrNP8FSbQYpiJjFPWWuWesiUuFfw ukETX0f+LCej7jAyGWg6NyrNnHEv4M8WOryfTbHiRYhmsQGp7mnvZiMDjtMW3y6pEggr wGSA== 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=bB9pDUjiIlea3U386GXuZY1NOAMaybVFycH+ZuoRiV0=; b=No+p//DTF41je92W1dhLOyDoVMiqmNK+t7ulQoNSv3BNyTOFvty9hk7Dlg5kDaylSS WXji4Q+kPcn0/ZLAGWAf4DU2uqy/euCCrpzKwqgx4cbZWNzLPLwxuhUwUuALBXtLlOJ4 eMgosjWZVMb5AwOwuOU1bGp+FApO1aMXR3KwtdtXN3fD5YtJZ6WywxFp4Geug1vcJTbd 2gYVDEB7FqMesAlctohVV9VyKDSMAvskz6U6mbi2Lv0kLYh51vYwL8zAgpKigjYUN8fE 9b4sm3U4Ek+fuFqBFdx8+eLoW5YS/HyGwsaUdSDr+DjtGD4m8VPj6e5K9jKh3O78xCio ustQ== X-Gm-Message-State: AOAM5314QrOi8wuvtfrbOaTeXkcnz71VjnZ4hhaZTgZLW4QFgagvNNyo dflHCzYPIZ++AibtskzP2iZ6u87yBto= X-Google-Smtp-Source: ABdhPJyfeaVjxI8bi3kpjnvht2g384iEYsz/UxrYeBJJDMzC5vFKDJec5j+2beg6JCmhPLXHZGmWsA== X-Received: by 2002:a1c:6884:: with SMTP id d126mr20131549wmc.179.1589817193623; Mon, 18 May 2020 08:53:13 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 08:53:12 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Peter Maydell , Paolo Bonzini , kvm@vger.kernel.org, qemu-arm@nongnu.org, Richard Henderson , =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 3/7] disas: Let disas::read_memory() handler return EIO on error Date: Mon, 18 May 2020 17:53:04 +0200 Message-Id: <20200518155308.15851-4-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 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Both cpu_memory_rw_debug() and address_space_read() return an error on failed transaction. Check the returned value, and return EIO in case of error. Signed-off-by: Philippe Mathieu-Daudé --- disas.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/disas.c b/disas.c index 45285d3f63..c1397d3933 100644 --- a/disas.c +++ b/disas.c @@ -39,9 +39,11 @@ target_read_memory (bfd_vma memaddr, struct disassemble_info *info) { CPUDebug *s = container_of(info, CPUDebug, info); + int r; - cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0); - return 0; + r = cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0); + + return r ? EIO : 0; } /* Print an error message. We can assume that this is in response to @@ -718,10 +720,11 @@ physical_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length, struct disassemble_info *info) { CPUDebug *s = container_of(info, CPUDebug, info); + MemTxResult res; - address_space_read(s->cpu->as, memaddr, MEMTXATTRS_UNSPECIFIED, - myaddr, length); - return 0; + res = address_space_read(s->cpu->as, memaddr, MEMTXATTRS_UNSPECIFIED, + myaddr, length); + return res == MEMTX_OK ? 0 : EIO; } /* Disassembler for the monitor. */ 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: 11555621 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DE9FE739 for ; Mon, 18 May 2020 15:53:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C797620758 for ; Mon, 18 May 2020 15:53:19 +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" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728491AbgERPxR (ORCPT ); Mon, 18 May 2020 11:53:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728301AbgERPxQ (ORCPT ); Mon, 18 May 2020 11:53:16 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 175AFC061A0C for ; Mon, 18 May 2020 08:53:16 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id u188so42432wmu.1 for ; Mon, 18 May 2020 08:53:16 -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=Cy+6osAJMM8IZ7SvfZ8rRCySVJ8+RWbLCct/CGZ1Uqk8MAQF4cTBJKISpngD5obqc+ 6yUR0Tj79mRxvIFMGALylj12t3j5NQmI1P6u8n7bgPVNFu2plo9FXzyN4HpoRAhNusMO rqz9T7qDCWwSqiYMbsoejSKRkP1PM6kUhS9fn9b+4siiTfg0Rk8CnwRBgIoOhoq1vWXg sOpmZkFv3QwAiqxglkm9Y5KAhIncNr1wI731Q0SDq9E3DL7WlzWak3VXmOGiLbkeMJWt AJfJf4n3PMJDJwUqFCENbAc2EUgJG2PEl04QYAPajtl50SkhxWb88q7GamOeFxY03QgY FLbA== X-Gm-Message-State: AOAM533ADu9X/3qs4GUuWIwx0OSJLTubG8OViwv2chp0T8HNrIOFgotn fZGAj1CuTu0n1xEqNosYLMk= 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 Cc: Peter Maydell , Paolo Bonzini , kvm@vger.kernel.org, qemu-arm@nongnu.org, Richard Henderson , =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= 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 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Do not ignore the MemTxResult error type returned by address_space_write(). Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Stefano Garzarella --- 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: 11555625 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8D78113B1 for ; Mon, 18 May 2020 15:53:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 74ECE207E8 for ; Mon, 18 May 2020 15:53:21 +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" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728500AbgERPxU (ORCPT ); Mon, 18 May 2020 11:53:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728493AbgERPxS (ORCPT ); Mon, 18 May 2020 11:53:18 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 841D3C05BD09 for ; Mon, 18 May 2020 08:53:18 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id z4so27452wmi.2 for ; 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=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=BG5RaTet72lIkDFxtuVH9WQA0WJ+1pEuMpgYFRzHyxYbp2FxJINZVcy/X0P1mCWSiT Z0JescQusG+wzAOKfTUUdSu7RS4/EphvpIn+JxxeY9RbKdYA/mxz/cWEjltCfRBnG2Sj LgcOvhjWcjc/qXYaULPOErjth0qfK8z6VCUPwdv6tx4IWemQLcEyUTy5aC4//1XtWnKM 5SkbQWYFXJ204udx8h04k8CAcVOjaw2Ydk40pixXinjfP/tGHvZWJxrOT8M+wLWiYoqC P0+GQh31oWbkZoOeX6UEDa1o+R3kF1d5M3l0ISI4rcNmIq5Q9oqKeF87/6gsgKv4MN8d j4tg== X-Gm-Message-State: AOAM532qu3bDthAzZfvOhUpDJlqvlvlo1T9vhKkeVsEw86TPGDIrr/oC dyhtVjbIovUvyW40ErQqyr8= 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 Cc: Peter Maydell , Paolo Bonzini , kvm@vger.kernel.org, qemu-arm@nongnu.org, Richard Henderson , =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= 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 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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: 11555623 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0A093739 for ; Mon, 18 May 2020 15:53:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E6D3B207ED for ; Mon, 18 May 2020 15:53:20 +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" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728110AbgERPxU (ORCPT ); Mon, 18 May 2020 11:53:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728494AbgERPxT (ORCPT ); Mon, 18 May 2020 11:53:19 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C38AC061A0C for ; Mon, 18 May 2020 08:53:18 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id k13so10387422wrx.3 for ; 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=nzKuJg3kXUJnqFrGBHs4FQpsPZ+jg3Su7zTjS2R13N8v805XiaCk/87PoBsC4aayiX +3Zhp3ZehSJLgDUxepZO3ImQp1woZywWCb2a3zrauGwY7DmDPsIsfu6QT8pQ54jpbKF4 jFlHTalT09P2le4KuhOhl/K07LJve9myjw4EGrOPoYOGEm+cvrFHzy8FVOmqiMFRwoLG vPUAoWUhFvY+JWIwrxhjDn3A5zNkAFTsZHXLgtAHUBcuBdZUOlWlpnjx72i0gmla3AkD Bh2HZXfCFUZOnWqNlZSabx5Z1KFlg568zVrhjeWBJ4Xjz82vTsvam/Y3EjAeC8bHWgF/ SSOw== X-Gm-Message-State: AOAM530WWcX1OEtJHdw/N0Tk69qXmH5i+VDtZ5B4Yc4knA/Al2tPKnqk CaKdaszq/L1tSHWjkcC0i1g= 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 Cc: Peter Maydell , Paolo Bonzini , kvm@vger.kernel.org, qemu-arm@nongnu.org, Richard Henderson , =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= 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 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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"); From patchwork Mon May 18 15:53:08 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: 11555629 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D5B6F739 for ; Mon, 18 May 2020 15:53:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD094207E8 for ; Mon, 18 May 2020 15:53:23 +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="UzUkQrcn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728502AbgERPxX (ORCPT ); Mon, 18 May 2020 11:53:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728421AbgERPxU (ORCPT ); Mon, 18 May 2020 11:53:20 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9D97C061A0C for ; Mon, 18 May 2020 08:53:19 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id z72so33121wmc.2 for ; Mon, 18 May 2020 08:53:19 -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=cD0HVhIueot6xPtNOGreyU0JTmhLcSi0Ka6Qp1Nps5Q=; b=UzUkQrcnedIIS0eyBH/lUMfwWEMl0dN7u8jvYptYKbxkrDH/d7z9FHA5lgbVk4b94O 9YAsA3AZn2b3y23TJXdtQz1KIUNf5Kvipq/cnwubNhPTe53nxW24cMT50ESHX3H4/wcQ izcXRSOCK5zCoYLLjt/KGEQqmZ2xpp7fgYwN6WliyF/fNgU4etLfxeZKj8Dfe4i9Q/Sr k+accbUYJeyeAfmxcwQTfyKvG3PYOmsnm3vdHwfVqIiDFu1ZpptTbNsUCxJf+JeIb1C8 vxCoLsu7zynaFKgFBWTWnh3KBOoSK1a7SAlaqYJ94LEYAqcFAYBIpjyYkeJlDWSWQwVo QmvA== 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=cD0HVhIueot6xPtNOGreyU0JTmhLcSi0Ka6Qp1Nps5Q=; b=m5zhDRlepKZNRhKRDOdN2ZLrCEYw699GYNRyb+kVrfx//sDcREos7wf90M/+XiiUrp 2/lFKPhr1XVoPw/ah0z35XD3x5UH998rqalHdsQH2AKd71yF/8PgluuSla3fxMNN5F5Q jKNxeByS43ojlsHSQHK/Jy9wniYJC8sW5QjRhkqqb6OZA+oLgb3hyaM9NJtLVLf0aUUI d8l0ItmYBW0FcH1OguvIFx1+Xk7Oyu6S2SAFvKtfw/zJfEwZXuh0BHsSnIm8PoCd5jX2 M0Ha+r7EA6QWybkV1ExrcmQv1oAKaWr6Wq9ybGk4JVbyK+T1HWk+4R4YuINrESRZEALW pGfg== X-Gm-Message-State: AOAM530nbGbEWiNY16PFlsBVXwxKKXbKWLajFYcR0aF6UOiXeN4lijp1 vvL915rGNcWBEctsgc3EvzE67sDy160= X-Google-Smtp-Source: ABdhPJzPg4xQnJ1fbHB57rgtpUNAn887oqh+iTpxfl6MyQ6sTjdHGtlxSB7D9n1FDS3I8jeo+FDEwA== X-Received: by 2002:a1c:7e03:: with SMTP id z3mr52303wmc.88.1589817198412; Mon, 18 May 2020 08:53:18 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 08:53:17 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Peter Maydell , Paolo Bonzini , kvm@vger.kernel.org, qemu-arm@nongnu.org, Richard Henderson , =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= Subject: [RFC PATCH v2 7/7] hw/core/loader: Assert loading ROM regions succeeds at reset Date: Mon, 18 May 2020 17:53:08 +0200 Message-Id: <20200518155308.15851-8-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 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org If we are unable to load a blob in a ROM region, we should not ignore it and let the machine boot. Signed-off-by: Philippe Mathieu-Daudé --- RFC: Maybe more polite with user to use hw_error()? --- hw/core/loader.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/core/loader.c b/hw/core/loader.c index 8bbb1797a4..4e046388b4 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -1146,8 +1146,12 @@ static void rom_reset(void *unused) void *host = memory_region_get_ram_ptr(rom->mr); memcpy(host, rom->data, rom->datasize); } else { - address_space_write_rom(rom->as, rom->addr, MEMTXATTRS_UNSPECIFIED, - rom->data, rom->datasize); + MemTxResult res; + + res = address_space_write_rom(rom->as, rom->addr, + MEMTXATTRS_UNSPECIFIED, + rom->data, rom->datasize); + assert(res == MEMTX_OK); } if (rom->isrom) { /* rom needs to be written only once */