From patchwork Wed Dec 20 17:14:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 122488 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp5892936qgn; Wed, 20 Dec 2017 09:48:20 -0800 (PST) X-Google-Smtp-Source: ACJfBouup2pe/VsRGrdSW4ad8rylf56j1fIdUdwNrgtpT0ORsi+k/eIFtTHxadTVahCGStsbO+cN X-Received: by 10.37.161.131 with SMTP id a3mr5785375ybi.303.1513792100911; Wed, 20 Dec 2017 09:48:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513792100; cv=none; d=google.com; s=arc-20160816; b=yCKfUrAw7YV/+Kxp3UX+Ow4xeSN7J3zmqodmCmD3p5wlf9+M09qaXDXgORFsHuy1Ej coda7NWMls44MK/baU3JVcUTxmijKZym0CENnB2dNyJN+oTHgxPS0+cw+KJunayjDzEQ fqnkaflGhgs+VBV5qpNddqGYGT5HZEXDGn/xCKQhKaT/NEFinFoEdXUFAn8tSkNYnARO 9iPi5yqAn+yFpoy8ESXJSS7opjFGeXjNKjAscCTjdeNaITnjAVOIn15a3VuYawZKHYUK +PMRnJu2/bCKwf61nCbfyKemdrfhlbALtbU+apKbXmMo+fq4ueEVvwX5LjR8PumxCT78 zY9A== 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:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=odyuUt0Aj/fq2kfpbleAvgaIgCxEoUpONkdTAR6BzQg=; b=Tk0+76cmTt2HTaX9AcdYqzkaVK8WNerLPrPi3WQoIeVp0tU+RcEBIPaaSQ0S6B3evx W7GcPeZIVVZkr8rIxglOnape3HxO4rHhZC6+NsIH7lh9oiKSW01jU/AIcNTCeXV1NYk9 sMxVsrVrfaN/hsndm+fHfcvzHH8aN/u3jsGW4WQHUjf3AUXH225eR8pblHRJjiBEbvj9 MYRSmTq4qBROBZLUC4iEx+8PNIZr1qyAQuF+Z1gAzkn6cjPajo59/ao+vMRUE+eG4J6t CW8CYUXlXNSKnIYi7LGtiaw2PBS7+l061hBHopAULoKtYM9hffAPgssG6V9+PUJl319Q Md5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=gfLTsLXM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v67si1811430ybe.494.2017.12.20.09.48.20 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Dec 2017 09:48:20 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=gfLTsLXM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:60734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRiTa-00061A-Dc for patch@linaro.org; Wed, 20 Dec 2017 12:48:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56530) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRhyU-0004mg-Qv for qemu-devel@nongnu.org; Wed, 20 Dec 2017 12:16:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRhyQ-0007IJ-Rj for qemu-devel@nongnu.org; Wed, 20 Dec 2017 12:16:10 -0500 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:41770) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eRhyQ-0007Ht-LZ for qemu-devel@nongnu.org; Wed, 20 Dec 2017 12:16:06 -0500 Received: by mail-wm0-x244.google.com with SMTP id g75so11357961wme.0 for ; Wed, 20 Dec 2017 09:16:06 -0800 (PST) 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; bh=odyuUt0Aj/fq2kfpbleAvgaIgCxEoUpONkdTAR6BzQg=; b=gfLTsLXMc2aUOBOtT9BM2AkE2JGjlj9icIK7XlYQ3O9Jk89fHs51pktNNIZ2Y3xhES rcqxCA4lNpyhE8o4pD57eweGhgKxP6N3BPz0tgxZJ2Q+EVkcTTrcISGsg33GxLtqzBTr GJxXiNNB5Je5/F/yft4hlLqj9wDMEQKW64sKn4jRBtwKpTOBgD7tdthuuCQ1HumMuGsg isZJUOu0nPKicL9Xxj2+UyUZNp+VFAVdEN2/dY9zs+zQzOPOrJ8CEp9aOg2KjbJ5SeKT SrhrAekER2j3fJKZer34QVFepoDKlH38QVT2tk1+Cm7kZKzKHq1K4P6fUPtJKCZW4Ofo gJ4w== 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; bh=odyuUt0Aj/fq2kfpbleAvgaIgCxEoUpONkdTAR6BzQg=; b=uRtA5EaXU1WiRoAxhSN9d8VgeUvS19Vs25R7BTKhxjj5frnKMZfoW74D54N1mEnVKi V+//jWnWVSsrAjR/HCw1Z7HGSZsLVlL+PpDr16iZ+P01e2s9wDOs6LsnGuhlmobgmsrI MVq6wHtoBbGm+i8NoLNboVKlZxqKaQbGHUVYVVqfzI7Q1iSa9LueCwZFmCki53Lbv2mf 0e82trEtK+LVsN8xoN6L0SOaxKTD+MVcOPWCudYBjEBD7fqD6XOOqC7UaBOyViBhPYxZ wdWxt2zPmQn7UzEf8XRR+h7lqRnpUbxkDw9Eby5fpbOpF4EaWlYa6HKEt7YKzzjylgQR OeYg== X-Gm-Message-State: AKGB3mJi9H0Lr+aqIXeirjmtdbNwJuRR51r9oQxuIUiwnDXu6W7cqre6 PcnZUAgyVCTQdC1uEV0U87BCbTc7 X-Received: by 10.28.149.203 with SMTP id x194mr7315535wmd.145.1513790165251; Wed, 20 Dec 2017 09:16:05 -0800 (PST) Received: from 640k.lan (dynamic-adsl-78-12-251-125.clienti.tiscali.it. [78.12.251.125]) by smtp.gmail.com with ESMTPSA id f125sm2751101wme.45.2017.12.20.09.16.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Dec 2017 09:16:04 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 20 Dec 2017 18:14:41 +0100 Message-Id: <1513790098-9815-30-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1513790098-9815-1-git-send-email-pbonzini@redhat.com> References: <1513790098-9815-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [PULL 29/46] exec: Don't reuse unassigned_mem_ops for io_mem_rom 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: Peter Maydell Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell We set up the io_mem_rom special memory region using the unassigned_mem_ops structure; this is then used when a guest tries to write to ROM. This is incorrect, because the behaviour of unassigned memory may be different from that of ROM for writes. In particular, on some architectures writing to unassigned memory generates a guest exception, whereas writing to ROM is generally ignored. Use a special readonly_mem_ops for this purpose instead, so writes to ROM are ignored for all guest CPUs. Signed-off-by: Peter Maydell Message-Id: <1513187549-2435-2-git-send-email-peter.maydell@linaro.org> Signed-off-by: Paolo Bonzini --- exec.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) -- 1.8.3.1 diff --git a/exec.c b/exec.c index 6b5828e..4722e52 100644 --- a/exec.c +++ b/exec.c @@ -2725,6 +2725,37 @@ static uint16_t dummy_section(PhysPageMap *map, FlatView *fv, MemoryRegion *mr) return phys_section_add(map, §ion); } +static void readonly_mem_write(void *opaque, hwaddr addr, + uint64_t val, unsigned size) +{ + /* Ignore any write to ROM. */ +} + +static bool readonly_mem_accepts(void *opaque, hwaddr addr, + unsigned size, bool is_write) +{ + return is_write; +} + +/* This will only be used for writes, because reads are special cased + * to directly access the underlying host ram. + */ +static const MemoryRegionOps readonly_mem_ops = { + .write = readonly_mem_write, + .valid.accepts = readonly_mem_accepts, + .endianness = DEVICE_NATIVE_ENDIAN, + .valid = { + .min_access_size = 1, + .max_access_size = 8, + .unaligned = false, + }, + .impl = { + .min_access_size = 1, + .max_access_size = 8, + .unaligned = false, + }, +}; + MemoryRegion *iotlb_to_region(CPUState *cpu, hwaddr index, MemTxAttrs attrs) { int asidx = cpu_asidx_from_attrs(cpu, attrs); @@ -2737,7 +2768,8 @@ MemoryRegion *iotlb_to_region(CPUState *cpu, hwaddr index, MemTxAttrs attrs) static void io_mem_init(void) { - memory_region_init_io(&io_mem_rom, NULL, &unassigned_mem_ops, NULL, NULL, UINT64_MAX); + memory_region_init_io(&io_mem_rom, NULL, &readonly_mem_ops, + NULL, NULL, UINT64_MAX); memory_region_init_io(&io_mem_unassigned, NULL, &unassigned_mem_ops, NULL, NULL, UINT64_MAX);