From patchwork Thu Jan 12 05:50:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 9512147 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 620A6601E7 for ; Thu, 12 Jan 2017 05:51:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51B8D285DC for ; Thu, 12 Jan 2017 05:51:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4549E28634; Thu, 12 Jan 2017 05:51:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D3E14285DC for ; Thu, 12 Jan 2017 05:51:19 +0000 (UTC) Received: from localhost ([::1]:59908 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cRYIA-00061F-7o for patchwork-qemu-devel@patchwork.kernel.org; Thu, 12 Jan 2017 00:51:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cRYHY-0005yb-Dt for qemu-devel@nongnu.org; Thu, 12 Jan 2017 00:50:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cRYHV-0001Ux-5N for qemu-devel@nongnu.org; Thu, 12 Jan 2017 00:50:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58924) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cRYHU-0001Uk-VY for qemu-devel@nongnu.org; Thu, 12 Jan 2017 00:50:37 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1D3C0C057FA7; Thu, 12 Jan 2017 05:50:36 +0000 (UTC) Received: from pxdev.xzpeter.org (ovpn-8-25.pek2.redhat.com [10.72.8.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 520DB19CB0; Thu, 12 Jan 2017 05:50:32 +0000 (UTC) Date: Thu, 12 Jan 2017 13:50:27 +0800 From: Peter Xu To: Paolo Bonzini Message-ID: <20170112055027.GK4450@pxdev.xzpeter.org> References: <1482307137-5106-1-git-send-email-peterx@redhat.com> <1482307137-5106-2-git-send-email-peterx@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 12 Jan 2017 05:50:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: Re: [Qemu-devel] [PATCH v2 1/2] memory: provide common macros for mtree_print_mr() 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: marcandre.lureau@gmail.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Jan 11, 2017 at 06:21:46PM +0100, Paolo Bonzini wrote: > > > On 21/12/2016 08:58, Peter Xu wrote: > > - mr->romd_mode ? 'R' : '-', > > - !mr->readonly && !(mr->rom_device && mr->romd_mode) ? 'W' > > - : '-', > > + MR_CHAR_RD(mr), > > + MR_CHAR_WR(mr), > > An alternative definition could be > > memory_access_is_direct(mr, false) ? 'R' : '-' > memory_access_is_direct(mr, true) ? 'W' : '-' > > for MR_CHAR_RD and MR_CHAR_WR. With this change, I think the small code > duplication in the "? :" operator is tolerable and the code is clearer. memory_access_is_direct() will check against whether mr is RAM, is that what we want here? In that case we'll get most of the regions as "--" as long as they are not RAM, while in fact IMHO we should want to know the rw permission for all cases. How about I add one more patch at the beginning to provide some more memory_region_is_*() helpers (meanwhile refactor memory_access_is_direct() a bit), like: --------8<-------- Then, I can throw away MR_CHAR_* macros and use: memory_access_is_readable(mr, false) ? 'R' : '-' memory_access_is_writable(mr, true) ? 'W' : '-' Do you like this approach? -- peterx diff --git a/include/exec/memory.h b/include/exec/memory.h index bec9756..50974c8 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1619,14 +1619,27 @@ MemTxResult address_space_read_full(AddressSpace *as, hwaddr addr, MemTxAttrs attrs, uint8_t *buf, int len); void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr); +static inline bool memory_region_is_readable(MemoryRegion *mr) +{ + return mr->rom_device ? mr->romd_mode : true; +} + +static inline bool memory_region_is_writable(MemoryRegion *mr) +{ + return !mr->rom_device && !mr->readonly; +} + +static inline bool memory_region_is_direct(MemoryRegion *mr) +{ + return memory_region_is_ram(mr) && !memory_region_is_ram_device(mr); +} + 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_direct(mr) && memory_region_is_writable(mr); } else { - return (memory_region_is_ram(mr) && !memory_region_is_ram_device(mr)) || - memory_region_is_romd(mr); + return memory_region_is_direct(mr) && memory_region_is_readable(mr); } } -------->8--------