From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 2002:a19:5205:0:0:0:0:0 with SMTP id m5csp144867lfb; Tue, 24 Aug 2021 12:46:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxt74OVUwSWR6NldG2PcMUvnzyllBaeCmm/oYbzLB1Oc90459hBdSoMQvRxcj2h04hEXJgy X-Received: by 2002:a92:b749:: with SMTP id c9mr27825495ilm.160.1629834415441; Tue, 24 Aug 2021 12:46:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629834415; cv=none; d=google.com; s=arc-20160816; b=TKm3P7vdaLOtJPNMUR7xKdXlOcPlwSAJLqob7YYLVdBPrbsV84e8TP1b1cLj9KS4+f m0FebNlnCkikiRfTz9DNVNcjiR6nOQbfv6TmpoMk2BR2QRZIKjVjZf1cVh6BntKSd3cm +AnN5SuOmzMYU6Cx3joN4azTSBsqF0+qGXqt3JI1kDBmUlr1DwkM10hK01H2Jy6e8ZfW xi9Y+TlCC8G4cB1aa2MISxW2mAA181i6dUE+M1/Mv6gtHaw6HIRsWkZb7JWEVCmQdMit dYcUJgK+6W3ycjj84aiNGFalEKd/j/d8Lo3uWFnSP/fzFLaIyJisKl7AMg3T2Dca5nYH /IGA== 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:content-disposition:in-reply-to :mime-version:references:message-id:subject:to:from:date :dkim-signature; bh=5zD4QlhRM6Lo31cWQWvm/7PEflQtifZyIKIe0LDHdR4=; b=eR8cCcwaxxWJY97HZz/IldCIDyjDM8z26TrG5MFl4LG7dNRESFlIkZwBdgot1GPH75 Dt76xUhItg+U9gmX/F6qIDrF6fGPO545OnFJCbJJIPsrgUw4haa3pN8HXdNuy+t3ZC5g bSeqSju3IZKS1coN82xMIufu++s1kEqn1STYhfXS4ZKtsEJubKG7EGs7pTJ/Fbe/yrrN 3VqAP+HtmPm4ty7NRvIpB6SW4el3vnIsXeWAqjObzFXRh/0HVd6PcuJQADl9wzAk/0Vc alSUSzd/E5renOY4EQ1fvzXbZH/vu57YCxPCPTfgdtgVxLllwXAnS9Gnrdo2znscOHyR xjVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=dodooZXq; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=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. [209.51.188.17]) by mx.google.com with ESMTPS id q14si23046001ilo.128.2021.08.24.12.46.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Aug 2021 12:46:55 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=dodooZXq; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:51204 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mIcNq-0001jA-P2 for alex.bennee@linaro.org; Tue, 24 Aug 2021 15:46:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIcN8-00011R-JL for qemu-devel@nongnu.org; Tue, 24 Aug 2021 15:46:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41823) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIcN2-00045C-3n for qemu-devel@nongnu.org; Tue, 24 Aug 2021 15:46:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629834362; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=5zD4QlhRM6Lo31cWQWvm/7PEflQtifZyIKIe0LDHdR4=; b=dodooZXqEJOqKNRtgjzGaAhkrDQgLg29L18JwVUy20848xPAkWoPPH81OWVOwAIfzQoIky 7OAclkmRGqTOCZE53R2OqoSXt6twHohcFJv29VnI/Lnn/rPrLz2dPb/IVL60L+amUqYb7o RwE8VRydbe5XTScc1mTLcMTOtQ143z8= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-417-1fowIPGePi2h1H5pEOEVXQ-1; Tue, 24 Aug 2021 15:34:36 -0400 X-MC-Unique: 1fowIPGePi2h1H5pEOEVXQ-1 Received: by mail-qk1-f198.google.com with SMTP id 70-20020a370b49000000b003d2f5f0dcc6so15101069qkl.9 for ; Tue, 24 Aug 2021 12:34:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=5zD4QlhRM6Lo31cWQWvm/7PEflQtifZyIKIe0LDHdR4=; b=FdMQkASagOvSBtiUixM5SsxW5gxmOXxND5kuJS62VbojeQCVkQXUMErbCWAKv5Nxuq enJlhD8cb8dllXXrjuH01KM4kWRbMl0P+ZwkrO4NVoxZqsKJNLdj8aYfs2D7la1/7hax Q1bqnMh6yTVA2cMa5E5UCfMJQvcyArWzvhk/GEzkfDYIemudbs3l3ZyDe6V79fRkQQNF U58ZIeJrkbLQ4O8Z4EryOrn4EIH6PKvsYfg4/TJwlBHOAcz7TB4xhaoZSAsn8h925vB4 TvmSa1AISAgneZ11jdi0S5xBxo5HkTRtudTh2hxhFsqg8h5DnN5LJjtK2i0AP9Ecj5vQ 3Zxw== X-Gm-Message-State: AOAM531e9vaI7FSq+GhqrtrQJL9vCOseSLSAadQRyrmid8H9n4DLIVeJ q4LHruMNJaC0LIHoDQDecDEA7Syil8LU9GRGlr6ebeypr+qB9FaaBQZ2VyYhScd/k7zeenW3+Qu c9bwrSGIIHJW17V4= X-Received: by 2002:a05:6214:21ac:: with SMTP id t12mr2741140qvc.53.1629833676207; Tue, 24 Aug 2021 12:34:36 -0700 (PDT) X-Received: by 2002:a05:6214:21ac:: with SMTP id t12mr2741108qvc.53.1629833675999; Tue, 24 Aug 2021 12:34:35 -0700 (PDT) Received: from t490s ([2607:fea8:56a3:500::d413]) by smtp.gmail.com with ESMTPSA id n11sm1279203qkk.17.2021.08.24.12.34.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 12:34:35 -0700 (PDT) Date: Tue, 24 Aug 2021 15:34:33 -0400 From: Peter Xu To: Gerd Hoffmann , Peter Maydell Subject: Re: [RFC PATCH v2 0/5] physmem: Have flaview API check bus permission from MemTxAttrs argument Message-ID: References: <20210823164157.751807-1-philmd@redhat.com> <20210824120153.altqys6jjiuxh35p@sirius.home.kraxel.org> MIME-Version: 1.0 In-Reply-To: <20210824120153.altqys6jjiuxh35p@sirius.home.kraxel.org> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.747, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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 , David Hildenbrand , Jason Wang , Li Qiang , QEMU Developers , Qiuhao Li , Alexander Bulekov , qemu-arm , Stefan Hajnoczi , Paolo Bonzini , "Edgar E . Iglesias" , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-devel" X-TUID: op7BPpMjnvXt Hi, Peter, Gerd, On Tue, Aug 24, 2021 at 02:01:53PM +0200, Gerd Hoffmann wrote: > Hi, > > > I was vaguely tossing an idea around in the back of my mind > > about whether you could have a flag on devices that marked > > them as "this device is currently involved in IO", such that > > you could then just fail the last DMA (or qemu_irq_set, or > > whatever) that would complete the loop back to a device that > > was already doing IO. But that would need a lot of thinking > > through to figure out if it's feasible, and it's probably > > a lot of code change. (Thanks for the write-up, Peter; it helps a lot) > > Quick & dirty hack trying the above. Not much code, it is opt-in per > MemoryRegion (so less overhead for devices which already handle all DMA > in a BH), tracks state in DeviceState. Adds a check to a rather hot > code path though. Not tested yet (stopped investigating when I noticed > Philippe tries to fix the same thing with another approach). Not > benchmarked. > > Maybe it helps ... > > take care, > Gerd > > From 80e58a2cd2c630f0bddd9d0eaee71abb7eeb9440 Mon Sep 17 00:00:00 2001 > From: Gerd Hoffmann > Date: Tue, 17 Aug 2021 07:35:37 +0200 > Subject: [PATCH] allow track active mmio handlers > > --- > include/exec/memory.h | 1 + > include/hw/qdev-core.h | 1 + > softmmu/memory.c | 24 ++++++++++++++++++++++-- > 3 files changed, 24 insertions(+), 2 deletions(-) > > diff --git a/include/exec/memory.h b/include/exec/memory.h > index c3d417d317f0..b1883d45e817 100644 > --- a/include/exec/memory.h > +++ b/include/exec/memory.h > @@ -265,6 +265,7 @@ struct MemoryRegionOps { > */ > bool unaligned; > } impl; > + bool block_reenter; > }; > > typedef struct MemoryRegionClass { > diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h > index bafc311bfa1b..4cf281a81fa9 100644 > --- a/include/hw/qdev-core.h > +++ b/include/hw/qdev-core.h > @@ -191,6 +191,7 @@ struct DeviceState { > int instance_id_alias; > int alias_required_for_version; > ResettableState reset; > + bool io_handler_active; > }; > > struct DeviceListener { > diff --git a/softmmu/memory.c b/softmmu/memory.c > index bfedaf9c4dfc..5eb5dd465dd2 100644 > --- a/softmmu/memory.c > +++ b/softmmu/memory.c > @@ -437,7 +437,18 @@ static MemTxResult memory_region_read_accessor(MemoryRegion *mr, > { > uint64_t tmp; > > - tmp = mr->ops->read(mr->opaque, addr, size); > + if (mr->ops->block_reenter) { > + DeviceState *dev = DEVICE(mr->owner); > + if (!dev->io_handler_active) { > + dev->io_handler_active = true; > + tmp = mr->ops->read(mr->opaque, addr, size); > + dev->io_handler_active = false; > + } else { > + tmp = MEMTX_OK; > + } > + } else { > + tmp = mr->ops->read(mr->opaque, addr, size); > + } > if (mr->subpage) { > trace_memory_region_subpage_read(get_cpu_index(), mr, addr, tmp, size); > } else if (trace_event_get_state_backends(TRACE_MEMORY_REGION_OPS_READ)) { > @@ -489,7 +500,16 @@ static MemTxResult memory_region_write_accessor(MemoryRegion *mr, > trace_memory_region_ops_write(get_cpu_index(), mr, abs_addr, tmp, size, > memory_region_name(mr)); > } > - mr->ops->write(mr->opaque, addr, tmp, size); > + if (mr->ops->block_reenter) { > + DeviceState *dev = DEVICE(mr->owner); > + if (!dev->io_handler_active) { > + dev->io_handler_active = true; > + mr->ops->write(mr->opaque, addr, tmp, size); > + dev->io_handler_active = false; > + } > + } else { > + mr->ops->write(mr->opaque, addr, tmp, size); > + } > return MEMTX_OK; > } Can I read this as a better approach if it still allows P2P so things that Paolo and Qiang used to mention will still work? https://lore.kernel.org/qemu-devel/7e4fd726-07e9-dc09-d66b-5692dd51820f@redhat.com/ https://lore.kernel.org/qemu-devel/CAKXe6S+v4z_PYbZ6MMzEZk7Q0Qc+q9tzL+a8918U_-XR=aj7RA@mail.gmail.com/ Can we do that similarly for qemu_set_irq() and friends but based on IRQState? Thanks, -- Peter Xu