From patchwork Fri Apr 10 03:41:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 1268929 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=aa7zJ2Fi; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48z3jr1lGsz9sSG for ; Fri, 10 Apr 2020 13:42:24 +1000 (AEST) Received: from localhost ([::1]:58170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMkYf-0001gi-HE for incoming@patchwork.ozlabs.org; Thu, 09 Apr 2020 23:42:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47836) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jMkYE-0001dD-1Y for qemu-devel@nongnu.org; Thu, 09 Apr 2020 23:41:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jMkYD-0007w0-04 for qemu-devel@nongnu.org; Thu, 09 Apr 2020 23:41:53 -0400 Received: from mail-qv1-xf42.google.com ([2607:f8b0:4864:20::f42]:35059) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jMkYC-0007vn-S3 for qemu-devel@nongnu.org; Thu, 09 Apr 2020 23:41:52 -0400 Received: by mail-qv1-xf42.google.com with SMTP id q73so444197qvq.2 for ; Thu, 09 Apr 2020 20:41:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=F6qfRA9Zsk5PQPX5NBdmVChOrunOXGYYK7OugFpAebY=; b=aa7zJ2Fi2mXZEEyWeiG4y/CMjIJpfclxqnDw7qWm39zDwF/tTHNWb9Fm4/otfsrc9c uxOvomv4FK7udCvyXkSgOkrV5HLko1JnScSTPmb72EGXf0NIkpRSbxedBGlpkjPvV9Jk tWAssqihOWAgUyFKSxxmXOCRJgPoWlRpFZUiIHT0oAeQz8XEeKedcze57KwGyDPvI0kU LB+EdD81vCDF15WHQwzaSsneWXSIS71F1vWx9ldyN/K42NNFRAMVceFXX5aAsLOyyd5R 5qal+auYiFvNr5gs2+QbT146DX2TD0uyF2TGHKUs3BJhKjV3/0KxKnkgSSjQwbSQkDoi 8ZqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=F6qfRA9Zsk5PQPX5NBdmVChOrunOXGYYK7OugFpAebY=; b=Uv2LCyOYMtzOEys4G/aJLRtTSbgkwqOm9FHaMF9V2Js7sDPFQF+eIm+8ZmvcEy3Bc2 fu+WXz1a7EV9mKzow1iIxwcUU7mdWPw+EMpjgJt0SK0omd1wqUxhEeeUt1E0VoYZoHhI lSmj/7c5OUsBubu/Lxh/b8q+Z9m+bCQEum5od0Ps/4eOzGLq7e7M4+GP2PndVafDmioa ll0XFsds4XB8Ftb3iZXQsT5sYGys7HxEce7Ny+GaMybuXifjyzNJfldd9PGLrgOs42rW RXVTY/zecTgGnxOP90NQNASPQghI8sDdfvTC6xFSW+KDn+EHn3n+4GPa2HEGyYEb0LeG d78g== X-Gm-Message-State: AGi0PubG72/H29GvTGWRkZZblR0CXP1Ke0//s06jTgMQtBjQ//UaIzYq ByQIIVRxOiCo9dOyP96pPSVoqh9NEzg= X-Google-Smtp-Source: APiQypJDNebDsH2LEr2FtkHUpVTrN3oiMCRvfOsIv4OdflsPtWQdM3kt64IWOp2jn4uTUTL7/rnQ1w== X-Received: by 2002:a0c:f4ca:: with SMTP id o10mr3310777qvm.18.1586490112178; Thu, 09 Apr 2020 20:41:52 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id l9sm725784qth.60.2020.04.09.20.41.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Apr 2020 20:41:51 -0700 (PDT) Subject: [PATCH v19 QEMU 4/4] memory: Do not allow direct write access to rom_device regions From: Alexander Duyck To: pbonzini@redhat.com, david@redhat.com, mst@redhat.com Date: Thu, 09 Apr 2020 20:41:50 -0700 Message-ID: <20200410034150.24738.98143.stgit@localhost.localdomain> In-Reply-To: <20200410033729.24738.22879.stgit@localhost.localdomain> References: <20200410033729.24738.22879.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::f42 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: virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Alexander Duyck According to the documentation in memory.h a ROM memory region will be backed by RAM for reads, but is supposed to go through a callback for writes. Currently we were not checking for the existence of the rom_device flag when determining if we could perform a direct write or not. To correct that add a check to memory_region_is_direct so that if the memory region has the rom_device flag set we will return false for all checks where is_write is set. Signed-off-by: Alexander Duyck --- include/exec/memory.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 1614d9a02c0c..e000bd2f97b2 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2351,8 +2351,8 @@ void address_space_write_cached_slow(MemoryRegionCache *cache, static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) { if (is_write) { - return memory_region_is_ram(mr) && - !mr->readonly && !memory_region_is_ram_device(mr); + return memory_region_is_ram(mr) && !mr->readonly && + !mr->rom_device && !memory_region_is_ram_device(mr); } else { return (memory_region_is_ram(mr) && !memory_region_is_ram_device(mr)) || memory_region_is_romd(mr);