From nobody Tue May 21 13:54:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1655875893836774.7492376670319; Tue, 21 Jun 2022 22:31:33 -0700 (PDT) Received: from localhost ([::1]:60354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3sxg-0008SI-Go for importer@patchew.org; Wed, 22 Jun 2022 01:31:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3swG-0007Rw-6A; Wed, 22 Jun 2022 01:30:04 -0400 Received: from ozlabs.ru ([107.174.27.60]:57856) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3swD-00052J-Ow; Wed, 22 Jun 2022 01:30:03 -0400 Received: from fstn1-p1.ozlabs.ibm.com. (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 85C3B8218B; Wed, 22 Jun 2022 01:29:56 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-ppc@nongnu.org Cc: Alexey Kardashevskiy , qemu-devel@nongnu.org Subject: [PATCH qemu v2] spapr/ddw: Reset DMA when the last non-default window is removed Date: Wed, 22 Jun 2022 15:29:55 +1000 Message-Id: <20220622052955.1069903-1-aik@ozlabs.ru> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=107.174.27.60; envelope-from=aik@ozlabs.ru; helo=ozlabs.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1655875895161100001 Content-Type: text/plain; charset="utf-8" PAPR+/LoPAPR says: =3D=3D=3D The platform must restore the default DMA window for the PE on a call to the ibm,remove-pe-dma-window RTAS call when all of the following are true: a. The call removes the last DMA window remaining for the PE. b. The DMA window being removed is not the default window =3D=3D=3D This resets DMA as PAPR mandates. Signed-off-by: Alexey Kardashevskiy Reviewed-by: Daniel Henrique Barboza --- Changes: v2: * reverted changes to spapr_tce_table_enable() --- include/hw/ppc/spapr.h | 1 + hw/ppc/spapr_iommu.c | 3 ++- hw/ppc/spapr_pci.c | 1 + hw/ppc/spapr_rtas_ddw.c | 15 +++++++++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 072dda2c7265..4ba2b27b8c4f 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -902,6 +902,7 @@ struct SpaprTceTable { bool bypass; bool need_vfio; bool skipping_replay; + bool def_win; int fd; MemoryRegion root; IOMMUMemoryRegion iommu; diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c index 81e5a1aea3a6..63e34d457a0e 100644 --- a/hw/ppc/spapr_iommu.c +++ b/hw/ppc/spapr_iommu.c @@ -279,7 +279,7 @@ static const VMStateDescription vmstate_spapr_tce_table= _ex =3D { =20 static const VMStateDescription vmstate_spapr_tce_table =3D { .name =3D "spapr_iommu", - .version_id =3D 2, + .version_id =3D 3, .minimum_version_id =3D 2, .pre_save =3D spapr_tce_table_pre_save, .post_load =3D spapr_tce_table_post_load, @@ -292,6 +292,7 @@ static const VMStateDescription vmstate_spapr_tce_table= =3D { VMSTATE_BOOL(bypass, SpaprTceTable), VMSTATE_VARRAY_UINT32_ALLOC(mig_table, SpaprTceTable, mig_nb_table= , 0, vmstate_info_uint64, uint64_t), + VMSTATE_BOOL_V(def_win, SpaprTceTable, 3), =20 VMSTATE_END_OF_LIST() }, diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index b2f5fbef0c83..5e95d7940fc8 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -2067,6 +2067,7 @@ void spapr_phb_dma_reset(SpaprPhbState *sphb) tcet =3D spapr_tce_find_by_liobn(sphb->dma_liobn[0]); spapr_tce_table_enable(tcet, SPAPR_TCE_PAGE_SHIFT, sphb->dma_win_addr, sphb->dma_win_size >> SPAPR_TCE_PAGE_SHIFT); + tcet->def_win =3D true; } =20 static void spapr_phb_reset(DeviceState *qdev) diff --git a/hw/ppc/spapr_rtas_ddw.c b/hw/ppc/spapr_rtas_ddw.c index 13d339c807c1..bb7d91b6d1af 100644 --- a/hw/ppc/spapr_rtas_ddw.c +++ b/hw/ppc/spapr_rtas_ddw.c @@ -215,6 +215,7 @@ static void rtas_ibm_remove_pe_dma_window(PowerPCCPU *c= pu, SpaprPhbState *sphb; SpaprTceTable *tcet; uint32_t liobn; + bool def_win_removed; =20 if ((nargs !=3D 1) || (nret !=3D 1)) { goto param_error_exit; @@ -231,9 +232,23 @@ static void rtas_ibm_remove_pe_dma_window(PowerPCCPU *= cpu, goto param_error_exit; } =20 + def_win_removed =3D tcet->def_win; spapr_tce_table_disable(tcet); trace_spapr_iommu_ddw_remove(liobn); =20 + /* + * PAPR+/LoPAPR says: + * The platform must restore the default DMA window for the PE on a ca= ll + * to the ibm,remove-pe-dma-window RTAS call when all of the following + * are true: + * a. The call removes the last DMA window remaining for the PE. + * b. The DMA window being removed is not the default window + */ + if (spapr_phb_get_active_win_num(sphb) =3D=3D 0 && !def_win_removed) { + spapr_phb_dma_reset(sphb); + trace_spapr_iommu_ddw_reset(sphb->buid, 0); + } + rtas_st(rets, 0, RTAS_OUT_SUCCESS); return; =20 --=20 2.30.2