From nobody Fri May 17 07:47:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1712585437; cv=none; d=zohomail.com; s=zohoarc; b=gjzSWAyp3EBB212Atc7PFBBOoRAo+YnVhv/kMJNdy3aMIPoN6J0hvUeq7pioaWfw8OpagpYIbUC+fiFCDCQsrz5c9L4F14SlQxcjICG9yzC0uGxpe9t0pc2RgVmxDDySrGJ2kLUH4XEb0h7ueyWVCbGmdNABqrn4gyyDqpOUaNo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712585437; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BCpk0bqjnQgYw45bmFeRBdeibilZssgbLzBrwwIszIA=; b=NvDnMrnf0rsugbARRaiSQeyt3rkmC25xeJDHzK0bJaro18Ad13PhgrTkwEnW3K2miGFY7JcKDeWVdYo2nD7wtcUx3igyEHS+th1UqdlSvNFSJ/FTHvhrIqdxlSVU0JXnQpdQ1TEEnyqRoFOIJeUyBX6J2DCsVzWi7aKs6PRL6bk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1712585437115554.4662168036314; Mon, 8 Apr 2024 07:10:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtpgN-0006wl-7e; Mon, 08 Apr 2024 10:09:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3fvoTZggKCvktnptubgbhpphmf.dpnrfnv-efwfmopohov.psh@flex--smostafa.bounces.google.com>) id 1rtpgK-0006vv-QD for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:08 -0400 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3fvoTZggKCvktnptubgbhpphmf.dpnrfnv-efwfmopohov.psh@flex--smostafa.bounces.google.com>) id 1rtpgH-0001JF-O6 for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:08 -0400 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-60cc8d4e1a4so75563977b3.3 for ; Mon, 08 Apr 2024 07:09:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712585342; x=1713190142; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BCpk0bqjnQgYw45bmFeRBdeibilZssgbLzBrwwIszIA=; b=D+fK6fn+4w0LwLvWnZUHMGuuYVDSNGVxgebW4/ReTugO0cacubPjKCWceV2rmq6biV Pty2ap6ENWQrY86MobkvNBIv+Va2Ling8se56nFpicU+i00RaxXu6SEklEXeJCk8z/VR MyRRFwFJ3sFkFmlkJTnh49spYY1U3uR7Mgy0uKAyFunwJoVcqBbrFZBM4Zf0oIM1pJWA O+XcirUHwXZqJ2UH0nnIU+I3CY7OmZpoxzPXyzDmttFjlEkhmWaIbJv+fdZ23cQi8mJl CA14E3RcGKRFSjGZnSBDafwlV9ZwC8fkpxvZ40bqcYh73Un5d/CQJQtc4ViQkoUZW+Y1 9c9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712585342; x=1713190142; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BCpk0bqjnQgYw45bmFeRBdeibilZssgbLzBrwwIszIA=; b=QHsO8/3W59gFZ52gi0pUvxELvplB1LCjAU0nMQ5JNMLrTKsJikuwCoV8/rTQGCDUOg R5o75yVqPGU5FE0Y/NTA+2CLiHAmpRJ62K0qK4BwlZJ0GhuD8ynwhaY3jMLuDmkp39Lx EgH/K9YHuPqIbjXamYoWI9KtzgWATevZdaES1QhSjezMpya9VXOcVdcVJxv2/fhnaGzF mKFUf8G9IJZLohS/niNESj8JAlB9+W6ybMZJxSlGwAtijg7Sf68LAuFHy9sKZyWvhUpc Y7wT6VM4XLuMrD4Ye+KzMTY0HP0GZpZ8URsa/SW9O+gIF312yzjV5hkWfMAcoidN0PWG /l/g== X-Forwarded-Encrypted: i=1; AJvYcCUWyWcZ2dj7PYoFDfy29RYW7ao/RSpqBL+G+f1d32ueFEQizQGfij11EvQ/giZToPdZdyZImZO/CQ+lwzEqYqTx8itH2rI= X-Gm-Message-State: AOJu0YxQKjIl71xatHJyB9psvF5m3RSfHFvKIz43ra8XnmkZhJk6vadk XU4W095H8BZtaDIecr72D6kSwyBKgB2VuGB7ai5ld75n7eB44J5hSN6oWdbzJSGHF2gtfTk5zI9 Cjko2a08rkw== X-Google-Smtp-Source: AGHT+IHQ4jTTdpvQf+yX8IXPSjHwTo5O55siDyTFjW+nkl/JR5ZcB9Tiubk7sEaO7hp1ovpWE+u7ZjdkhOGxxw== X-Received: from mostafa.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:333c]) (user=smostafa job=sendgmr) by 2002:a81:7b54:0:b0:618:24ca:381f with SMTP id w81-20020a817b54000000b0061824ca381fmr44771ywc.8.1712585342258; Mon, 08 Apr 2024 07:09:02 -0700 (PDT) Date: Mon, 8 Apr 2024 14:08:06 +0000 In-Reply-To: <20240408140818.3799590-1-smostafa@google.com> Mime-Version: 1.0 References: <20240408140818.3799590-1-smostafa@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240408140818.3799590-2-smostafa@google.com> Subject: [RFC PATCH v2 01/13] hw/arm/smmu: Use enum for SMMU stage From: Mostafa Saleh To: qemu-arm@nongnu.org, eric.auger@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Cc: jean-philippe@linaro.org, alex.bennee@linaro.org, maz@kernel.org, nicolinc@nvidia.com, julien@xen.org, richard.henderson@linaro.org, marcin.juszkiewicz@linaro.org, Mostafa Saleh 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=2607:f8b0:4864:20::114a; envelope-from=3fvoTZggKCvktnptubgbhpphmf.dpnrfnv-efwfmopohov.psh@flex--smostafa.bounces.google.com; helo=mail-yw1-x114a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1712585438437100006 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, translation stage is represented as an int, where 1 is stage-1 a= nd 2 is stage-2, when nested is added, 3 would be confusing to represent nesti= ng, so we use an enum instead. While keeping the same values, this is useful for: - Doing tricks with bit masks, where BIT(0) is stage-1 and BIT(1) is stage-2 and both is nested. - Tracing, as stage is printed as int. Signed-off-by: Mostafa Saleh Reviewed-by: Eric Auger --- hw/arm/smmu-common.c | 14 +++++++------- hw/arm/smmuv3.c | 15 ++++++++------- include/hw/arm/smmu-common.h | 11 +++++++++-- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index 4caedb4998..3a7c350aca 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -304,7 +304,7 @@ static int smmu_ptw_64_s1(SMMUTransCfg *cfg, SMMUTLBEntry *tlbe, SMMUPTWEventInfo *info) { dma_addr_t baseaddr, indexmask; - int stage =3D cfg->stage; + SMMUStage stage =3D cfg->stage; SMMUTransTableInfo *tt =3D select_tt(cfg, iova); uint8_t level, granule_sz, inputsize, stride; =20 @@ -392,7 +392,7 @@ static int smmu_ptw_64_s1(SMMUTransCfg *cfg, info->type =3D SMMU_PTW_ERR_TRANSLATION; =20 error: - info->stage =3D 1; + info->stage =3D SMMU_STAGE_1; tlbe->entry.perm =3D IOMMU_NONE; return -EINVAL; } @@ -415,7 +415,7 @@ static int smmu_ptw_64_s2(SMMUTransCfg *cfg, dma_addr_t ipa, IOMMUAccessFlags perm, SMMUTLBEntry *tlbe, SMMUPTWEventInfo *info) { - const int stage =3D 2; + const SMMUStage stage =3D SMMU_STAGE_2; int granule_sz =3D cfg->s2cfg.granule_sz; /* ARM DDI0487I.a: Table D8-7. */ int inputsize =3D 64 - cfg->s2cfg.tsz; @@ -513,7 +513,7 @@ static int smmu_ptw_64_s2(SMMUTransCfg *cfg, info->type =3D SMMU_PTW_ERR_TRANSLATION; =20 error: - info->stage =3D 2; + info->stage =3D SMMU_STAGE_2; tlbe->entry.perm =3D IOMMU_NONE; return -EINVAL; } @@ -532,9 +532,9 @@ error: int smmu_ptw(SMMUTransCfg *cfg, dma_addr_t iova, IOMMUAccessFlags perm, SMMUTLBEntry *tlbe, SMMUPTWEventInfo *info) { - if (cfg->stage =3D=3D 1) { + if (cfg->stage =3D=3D SMMU_STAGE_1) { return smmu_ptw_64_s1(cfg, iova, perm, tlbe, info); - } else if (cfg->stage =3D=3D 2) { + } else if (cfg->stage =3D=3D SMMU_STAGE_2) { /* * If bypassing stage 1(or unimplemented), the input address is pa= ssed * directly to stage 2 as IPA. If the input address of a transacti= on @@ -543,7 +543,7 @@ int smmu_ptw(SMMUTransCfg *cfg, dma_addr_t iova, IOMMUA= ccessFlags perm, */ if (iova >=3D (1ULL << cfg->oas)) { info->type =3D SMMU_PTW_ERR_ADDR_SIZE; - info->stage =3D 1; + info->stage =3D SMMU_STAGE_1; tlbe->entry.perm =3D IOMMU_NONE; return -EINVAL; } diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 9eb56a70f3..50e5a72d54 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -34,7 +34,8 @@ #include "smmuv3-internal.h" #include "smmu-internal.h" =20 -#define PTW_RECORD_FAULT(cfg) (((cfg)->stage =3D=3D 1) ? (cfg)->record_f= aults : \ +#define PTW_RECORD_FAULT(cfg) (((cfg)->stage =3D=3D SMMU_STAGE_1) ? \ + (cfg)->record_faults : \ (cfg)->s2cfg.record_faults) =20 /** @@ -402,7 +403,7 @@ static bool s2_pgtable_config_valid(uint8_t sl0, uint8_= t t0sz, uint8_t gran) =20 static int decode_ste_s2_cfg(SMMUTransCfg *cfg, STE *ste) { - cfg->stage =3D 2; + cfg->stage =3D SMMU_STAGE_2; =20 if (STE_S2AA64(ste) =3D=3D 0x0) { qemu_log_mask(LOG_UNIMP, @@ -678,7 +679,7 @@ static int decode_cd(SMMUTransCfg *cfg, CD *cd, SMMUEve= ntInfo *event) =20 /* we support only those at the moment */ cfg->aa64 =3D true; - cfg->stage =3D 1; + cfg->stage =3D SMMU_STAGE_1; =20 cfg->oas =3D oas2bits(CD_IPS(cd)); cfg->oas =3D MIN(oas2bits(SMMU_IDR5_OAS), cfg->oas); @@ -762,7 +763,7 @@ static int smmuv3_decode_config(IOMMUMemoryRegion *mr, = SMMUTransCfg *cfg, return ret; } =20 - if (cfg->aborted || cfg->bypassed || (cfg->stage =3D=3D 2)) { + if (cfg->aborted || cfg->bypassed || (cfg->stage =3D=3D SMMU_STAGE_2))= { return 0; } =20 @@ -882,7 +883,7 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegion= *mr, hwaddr addr, goto epilogue; } =20 - if (cfg->stage =3D=3D 1) { + if (cfg->stage =3D=3D SMMU_STAGE_1) { /* Select stage1 translation table. */ tt =3D select_tt(cfg, addr); if (!tt) { @@ -919,7 +920,7 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegion= *mr, hwaddr addr, * nesting is not supported. So it is sufficient to check the * translation stage to know the TLB stage for now. */ - event.u.f_walk_eabt.s2 =3D (cfg->stage =3D=3D 2); + event.u.f_walk_eabt.s2 =3D (cfg->stage =3D=3D SMMU_STAGE_2); if (PTW_RECORD_FAULT(cfg)) { event.type =3D SMMU_EVT_F_PERMISSION; event.u.f_permission.addr =3D addr; @@ -935,7 +936,7 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegion= *mr, hwaddr addr, =20 if (smmu_ptw(cfg, aligned_addr, flag, cached_entry, &ptw_info)) { /* All faults from PTW has S2 field. */ - event.u.f_walk_eabt.s2 =3D (ptw_info.stage =3D=3D 2); + event.u.f_walk_eabt.s2 =3D (ptw_info.stage =3D=3D SMMU_STAGE_2); g_free(cached_entry); switch (ptw_info.type) { case SMMU_PTW_ERR_WALK_EABT: diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h index 5ec2e6c1a4..b3c881f0ee 100644 --- a/include/hw/arm/smmu-common.h +++ b/include/hw/arm/smmu-common.h @@ -49,8 +49,15 @@ typedef enum { SMMU_PTW_ERR_PERMISSION, /* Permission fault */ } SMMUPTWEventType; =20 +/* SMMU Stage */ +typedef enum { + SMMU_STAGE_1 =3D 1, + SMMU_STAGE_2, + SMMU_NESTED, +} SMMUStage; + typedef struct SMMUPTWEventInfo { - int stage; + SMMUStage stage; SMMUPTWEventType type; dma_addr_t addr; /* fetched address that induced an abort, if any */ } SMMUPTWEventInfo; @@ -88,7 +95,7 @@ typedef struct SMMUS2Cfg { */ typedef struct SMMUTransCfg { /* Shared fields between stage-1 and stage-2. */ - int stage; /* translation stage */ + SMMUStage stage; /* translation stage */ bool disabled; /* smmu is disabled */ bool bypassed; /* translation is bypassed */ bool aborted; /* translation is aborted */ --=20 2.44.0.478.gd926399ef9-goog From nobody Fri May 17 07:47:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1712585518; cv=none; d=zohomail.com; s=zohoarc; b=iOCrbVTgaO2FClEhaoz9o6nbo5UzB/ZbpYcip3QkoFenwFEIZifNKtuVEbQpEfb1HdUyVnF/PnwjiZnP4M12zrew5XC2UqJdVLgDEWggWdHss664vq2nOLFvpWwzUISRB+AoWZ3gLUXhF9fa4Ud/hmwLQN/K1TrgcpNVJSrqe5o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712585518; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=R4YaXIvOkGVLITuL9p1CVWc9nnAfJHD4q+gC5uvDj9c=; b=oBsbhQfS2bN6Ala+oUldzngZ2e8/Rzv+JkIvOywpgY1NZOWGeljqw1RL6EPV4yts8ZQW/wvdc8CwgidrDvlrsmZ+1GNrOutzOJAyrHe7KU3KYpMJXqvZxLuHpFFrveMQmUnfGeWbH/eiDzzaKeA7H2ilozH2U6RGARFjiF3kAFQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1712585518762626.6193695693435; Mon, 8 Apr 2024 07:11:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtpgX-0006z8-Bw; Mon, 08 Apr 2024 10:09:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3gPoTZggKCvsvprvwdidjrrjoh.frpthpx-ghyhoqrqjqx.ruj@flex--smostafa.bounces.google.com>) id 1rtpgP-0006xh-2p for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:13 -0400 Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3gPoTZggKCvsvprvwdidjrrjoh.frpthpx-ghyhoqrqjqx.ruj@flex--smostafa.bounces.google.com>) id 1rtpgI-0001Jx-Qh for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:12 -0400 Received: by mail-wr1-x44a.google.com with SMTP id ffacd0b85a97d-343e46df264so1707140f8f.1 for ; Mon, 08 Apr 2024 07:09:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712585345; x=1713190145; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=R4YaXIvOkGVLITuL9p1CVWc9nnAfJHD4q+gC5uvDj9c=; b=NkOl/eCJTJYQ/msE60OjnfwaDbz4sTjo0ZyKnjaMIpOVQFvtoNWfZXglWz3HTGNYcv LNY1jdX2P6s/98gpUVdHw8yDGUFiujICMElnAHwWhdkppiWgr4RXP2nVnjxMIJoianiG o5rPF6o8hD+vAOolaKDy2KsnyenP0C1pPgRDMQ6bFQa26S/B98x+jNhzyueLoS9TBrN+ A7EV7Z+1DD2pAr3xi2MAeWy+5cvQy1i/MMkj4HqJyuxzauBNQQvDLyCgVbOnBSBTRbb7 ulM5HVsNIdTdGzoL7in1F+nDRJrLEVfQ/ceNOVCPtLGdo+oy8RKdnQDK74p3xDhkC9GX 9hxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712585345; x=1713190145; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=R4YaXIvOkGVLITuL9p1CVWc9nnAfJHD4q+gC5uvDj9c=; b=viMYbxjmT/IPTl6hE2GOZdeSuYkoEwrh1uo1HkDrOBAHZfqlJsIexbAQzo/crGB+F/ sDoGV7RRBiKeXrnpJ/5px4Ha3FOZiSWYp1l3P9KGdDBwCNYaAaQiLODpXQgy8d/Ohx5k /0WqMk/U+gqWo/ynwHDRSMaOTayoKI5ZyeyUR935FXIWwLqiNI9dCGrvGj9gaqzTWimK cGMV6E9n4BeA27l577bGFf7Rq96CzgdUkBIerwTgEDnkVXYJJkEyLy/hzS5AZQxx4gRf u1gIbRi25aj7ymxRP/6o9Wry35oeFvpmKyK5c3yMBI4oIVTm8wxyWqMcWupBTHoCM211 JnWw== X-Forwarded-Encrypted: i=1; AJvYcCVQbrGxIUIzHMsjfBepcR3UbnUwKBFgs80a/H0RxosTiHO7l3QaOFaYBUHC94l9z0wNZGhX75gBTpS3j72RQbrSjJ5q2yw= X-Gm-Message-State: AOJu0YztHtDqYMxYVqXwkxdUD769mjWO66UXX1Cb6r9N1CAhQsQQPKBy jGvolWyKLSajoDwHHw86Jov0v73h+S74BbGFJwgZaSb09uQegruOVcaFnp0WK9xwjGbQE4NQUdD VvmH8z/bigg== X-Google-Smtp-Source: AGHT+IEVC1iuEuvPKWbdIOgEAgfS+vpjPNIpqOhwQK1r3sV1ug3BgEGBPeCZnh84UW04DaohHAc1DWkhK8oHag== X-Received: from mostafa.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:333c]) (user=smostafa job=sendgmr) by 2002:adf:b601:0:b0:343:b9e4:77d6 with SMTP id f1-20020adfb601000000b00343b9e477d6mr19951wre.11.1712585344489; Mon, 08 Apr 2024 07:09:04 -0700 (PDT) Date: Mon, 8 Apr 2024 14:08:07 +0000 In-Reply-To: <20240408140818.3799590-1-smostafa@google.com> Mime-Version: 1.0 References: <20240408140818.3799590-1-smostafa@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240408140818.3799590-3-smostafa@google.com> Subject: [RFC PATCH v2 02/13] hw/arm/smmu: Split smmuv3_translate() From: Mostafa Saleh To: qemu-arm@nongnu.org, eric.auger@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Cc: jean-philippe@linaro.org, alex.bennee@linaro.org, maz@kernel.org, nicolinc@nvidia.com, julien@xen.org, richard.henderson@linaro.org, marcin.juszkiewicz@linaro.org, Mostafa Saleh 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=2a00:1450:4864:20::44a; envelope-from=3gPoTZggKCvsvprvwdidjrrjoh.frpthpx-ghyhoqrqjqx.ruj@flex--smostafa.bounces.google.com; helo=mail-wr1-x44a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1712585520960100006 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" smmuv3_translate() does everything from STE/CD parsing to TLB lookup and PTW. Soon, when nesting is supported, stage-1 data (tt, CD) needs to be translated using stage-2. Split smmuv3_translate() to 3 functions: - smmu_translate(): in smmu-common.c, which does the TLB lookup, PTW, TLB insertion, all the functions are already there, this just puts them together. This also simplifies the code as it consolidates event generation in case of TLB lookup permission failure or in TT selection. - smmuv3_do_translate(): in smmuv3.c, Calls smmu_translate() and does the event population in case of errors. - smmuv3_translate(), now calls smmuv3_do_translate() for translation while the rest is the same. Also, add stage in trace_smmuv3_translate_success() Signed-off-by: Mostafa Saleh Reviewed-by: Eric Auger --- hw/arm/smmu-common.c | 59 ++++++++++++ hw/arm/smmuv3.c | 175 +++++++++++++---------------------- hw/arm/trace-events | 2 +- include/hw/arm/smmu-common.h | 8 ++ 4 files changed, 133 insertions(+), 111 deletions(-) diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index 3a7c350aca..20630eb670 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -554,6 +554,65 @@ int smmu_ptw(SMMUTransCfg *cfg, dma_addr_t iova, IOMMU= AccessFlags perm, g_assert_not_reached(); } =20 +SMMUTLBEntry *smmu_translate(SMMUState *bs, SMMUTransCfg *cfg, dma_addr_t = addr, + IOMMUAccessFlags flag, SMMUPTWEventInfo *info) +{ + uint64_t page_mask, aligned_addr; + SMMUTLBEntry *cached_entry =3D NULL; + SMMUTransTableInfo *tt; + int status; + + /* + * Combined attributes used for TLB lookup, as only one stage is suppo= rted, + * it will hold attributes based on the enabled stage. + */ + SMMUTransTableInfo tt_combined; + + if (cfg->stage =3D=3D SMMU_STAGE_1) { + /* Select stage1 translation table. */ + tt =3D select_tt(cfg, addr); + if (!tt) { + info->type =3D SMMU_PTW_ERR_TRANSLATION; + info->stage =3D SMMU_STAGE_1; + return NULL; + } + tt_combined.granule_sz =3D tt->granule_sz; + tt_combined.tsz =3D tt->tsz; + + } else { + /* Stage2. */ + tt_combined.granule_sz =3D cfg->s2cfg.granule_sz; + tt_combined.tsz =3D cfg->s2cfg.tsz; + } + + /* + * TLB lookup looks for granule and input size for a translation stage, + * as only one stage is supported right now, choose the right values + * from the configuration. + */ + page_mask =3D (1ULL << tt_combined.granule_sz) - 1; + aligned_addr =3D addr & ~page_mask; + + cached_entry =3D smmu_iotlb_lookup(bs, cfg, &tt_combined, aligned_addr= ); + if (cached_entry) { + if ((flag & IOMMU_WO) && !(cached_entry->entry.perm & IOMMU_WO)) { + info->type =3D SMMU_PTW_ERR_PERMISSION; + info->stage =3D cfg->stage; + return NULL; + } + return cached_entry; + } + + cached_entry =3D g_new0(SMMUTLBEntry, 1); + status =3D smmu_ptw(cfg, aligned_addr, flag, cached_entry, info); + if (status) { + g_free(cached_entry); + return NULL; + } + smmu_iotlb_insert(bs, cfg, cached_entry); + return cached_entry; +} + /** * The bus number is used for lookup when SID based invalidation occurs. * In that case we lazily populate the SMMUPciBus array from the bus hash diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 50e5a72d54..f081ff0cc4 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -827,6 +827,67 @@ static void smmuv3_flush_config(SMMUDevice *sdev) g_hash_table_remove(bc->configs, sdev); } =20 +/* Do translation with TLB lookup. */ +static SMMUTranslationStatus smmuv3_do_translate(SMMUv3State *s, hwaddr ad= dr, + SMMUTransCfg *cfg, + SMMUEventInfo *event, + IOMMUAccessFlags flag, + SMMUTLBEntry **out_entry) +{ + SMMUPTWEventInfo ptw_info =3D {}; + SMMUState *bs =3D ARM_SMMU(s); + SMMUTLBEntry *cached_entry =3D NULL; + + cached_entry =3D smmu_translate(bs, cfg, addr, flag, &ptw_info); + if (!cached_entry) { + /* All faults from PTW has S2 field. */ + event->u.f_walk_eabt.s2 =3D (ptw_info.stage =3D=3D SMMU_STAGE_2); + switch (ptw_info.type) { + case SMMU_PTW_ERR_WALK_EABT: + event->type =3D SMMU_EVT_F_WALK_EABT; + event->u.f_walk_eabt.addr =3D addr; + event->u.f_walk_eabt.rnw =3D flag & 0x1; + event->u.f_walk_eabt.class =3D 0x1; + event->u.f_walk_eabt.addr2 =3D ptw_info.addr; + break; + case SMMU_PTW_ERR_TRANSLATION: + if (PTW_RECORD_FAULT(cfg)) { + event->type =3D SMMU_EVT_F_TRANSLATION; + event->u.f_translation.addr =3D addr; + event->u.f_translation.rnw =3D flag & 0x1; + } + break; + case SMMU_PTW_ERR_ADDR_SIZE: + if (PTW_RECORD_FAULT(cfg)) { + event->type =3D SMMU_EVT_F_ADDR_SIZE; + event->u.f_addr_size.addr =3D addr; + event->u.f_addr_size.rnw =3D flag & 0x1; + } + break; + case SMMU_PTW_ERR_ACCESS: + if (PTW_RECORD_FAULT(cfg)) { + event->type =3D SMMU_EVT_F_ACCESS; + event->u.f_access.addr =3D addr; + event->u.f_access.rnw =3D flag & 0x1; + } + break; + case SMMU_PTW_ERR_PERMISSION: + if (PTW_RECORD_FAULT(cfg)) { + event->type =3D SMMU_EVT_F_PERMISSION; + event->u.f_permission.addr =3D addr; + event->u.f_permission.rnw =3D flag & 0x1; + } + break; + default: + g_assert_not_reached(); + } + return SMMU_TRANS_ERROR; + } + *out_entry =3D cached_entry; + return SMMU_TRANS_SUCCESS; +} + +/* Entry point to SMMU, does everything. */ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegion *mr, hwaddr addr, IOMMUAccessFlags flag, int iommu_idx) { @@ -836,12 +897,7 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegio= n *mr, hwaddr addr, SMMUEventInfo event =3D {.type =3D SMMU_EVT_NONE, .sid =3D sid, .inval_ste_allowed =3D false}; - SMMUPTWEventInfo ptw_info =3D {}; SMMUTranslationStatus status; - SMMUState *bs =3D ARM_SMMU(s); - uint64_t page_mask, aligned_addr; - SMMUTLBEntry *cached_entry =3D NULL; - SMMUTransTableInfo *tt; SMMUTransCfg *cfg =3D NULL; IOMMUTLBEntry entry =3D { .target_as =3D &address_space_memory, @@ -850,11 +906,7 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegio= n *mr, hwaddr addr, .addr_mask =3D ~(hwaddr)0, .perm =3D IOMMU_NONE, }; - /* - * Combined attributes used for TLB lookup, as only one stage is suppo= rted, - * it will hold attributes based on the enabled stage. - */ - SMMUTransTableInfo tt_combined; + SMMUTLBEntry *cached_entry =3D NULL; =20 qemu_mutex_lock(&s->mutex); =20 @@ -883,105 +935,7 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegi= on *mr, hwaddr addr, goto epilogue; } =20 - if (cfg->stage =3D=3D SMMU_STAGE_1) { - /* Select stage1 translation table. */ - tt =3D select_tt(cfg, addr); - if (!tt) { - if (cfg->record_faults) { - event.type =3D SMMU_EVT_F_TRANSLATION; - event.u.f_translation.addr =3D addr; - event.u.f_translation.rnw =3D flag & 0x1; - } - status =3D SMMU_TRANS_ERROR; - goto epilogue; - } - tt_combined.granule_sz =3D tt->granule_sz; - tt_combined.tsz =3D tt->tsz; - - } else { - /* Stage2. */ - tt_combined.granule_sz =3D cfg->s2cfg.granule_sz; - tt_combined.tsz =3D cfg->s2cfg.tsz; - } - /* - * TLB lookup looks for granule and input size for a translation stage, - * as only one stage is supported right now, choose the right values - * from the configuration. - */ - page_mask =3D (1ULL << tt_combined.granule_sz) - 1; - aligned_addr =3D addr & ~page_mask; - - cached_entry =3D smmu_iotlb_lookup(bs, cfg, &tt_combined, aligned_addr= ); - if (cached_entry) { - if ((flag & IOMMU_WO) && !(cached_entry->entry.perm & IOMMU_WO)) { - status =3D SMMU_TRANS_ERROR; - /* - * We know that the TLB only contains either stage-1 or stage-= 2 as - * nesting is not supported. So it is sufficient to check the - * translation stage to know the TLB stage for now. - */ - event.u.f_walk_eabt.s2 =3D (cfg->stage =3D=3D SMMU_STAGE_2); - if (PTW_RECORD_FAULT(cfg)) { - event.type =3D SMMU_EVT_F_PERMISSION; - event.u.f_permission.addr =3D addr; - event.u.f_permission.rnw =3D flag & 0x1; - } - } else { - status =3D SMMU_TRANS_SUCCESS; - } - goto epilogue; - } - - cached_entry =3D g_new0(SMMUTLBEntry, 1); - - if (smmu_ptw(cfg, aligned_addr, flag, cached_entry, &ptw_info)) { - /* All faults from PTW has S2 field. */ - event.u.f_walk_eabt.s2 =3D (ptw_info.stage =3D=3D SMMU_STAGE_2); - g_free(cached_entry); - switch (ptw_info.type) { - case SMMU_PTW_ERR_WALK_EABT: - event.type =3D SMMU_EVT_F_WALK_EABT; - event.u.f_walk_eabt.addr =3D addr; - event.u.f_walk_eabt.rnw =3D flag & 0x1; - event.u.f_walk_eabt.class =3D 0x1; - event.u.f_walk_eabt.addr2 =3D ptw_info.addr; - break; - case SMMU_PTW_ERR_TRANSLATION: - if (PTW_RECORD_FAULT(cfg)) { - event.type =3D SMMU_EVT_F_TRANSLATION; - event.u.f_translation.addr =3D addr; - event.u.f_translation.rnw =3D flag & 0x1; - } - break; - case SMMU_PTW_ERR_ADDR_SIZE: - if (PTW_RECORD_FAULT(cfg)) { - event.type =3D SMMU_EVT_F_ADDR_SIZE; - event.u.f_addr_size.addr =3D addr; - event.u.f_addr_size.rnw =3D flag & 0x1; - } - break; - case SMMU_PTW_ERR_ACCESS: - if (PTW_RECORD_FAULT(cfg)) { - event.type =3D SMMU_EVT_F_ACCESS; - event.u.f_access.addr =3D addr; - event.u.f_access.rnw =3D flag & 0x1; - } - break; - case SMMU_PTW_ERR_PERMISSION: - if (PTW_RECORD_FAULT(cfg)) { - event.type =3D SMMU_EVT_F_PERMISSION; - event.u.f_permission.addr =3D addr; - event.u.f_permission.rnw =3D flag & 0x1; - } - break; - default: - g_assert_not_reached(); - } - status =3D SMMU_TRANS_ERROR; - } else { - smmu_iotlb_insert(bs, cfg, cached_entry); - status =3D SMMU_TRANS_SUCCESS; - } + status =3D smmuv3_do_translate(s, addr, cfg, &event, flag, &cached_ent= ry); =20 epilogue: qemu_mutex_unlock(&s->mutex); @@ -992,7 +946,8 @@ epilogue: (addr & cached_entry->entry.addr_mask); entry.addr_mask =3D cached_entry->entry.addr_mask; trace_smmuv3_translate_success(mr->parent_obj.name, sid, addr, - entry.translated_addr, entry.perm); + entry.translated_addr, entry.perm, + cfg->stage); break; case SMMU_TRANS_DISABLE: entry.perm =3D flag; diff --git a/hw/arm/trace-events b/hw/arm/trace-events index f1a54a02df..cc12924a84 100644 --- a/hw/arm/trace-events +++ b/hw/arm/trace-events @@ -37,7 +37,7 @@ smmuv3_get_ste(uint64_t addr) "STE addr: 0x%"PRIx64 smmuv3_translate_disable(const char *n, uint16_t sid, uint64_t addr, bool = is_write) "%s sid=3D0x%x bypass (smmu disabled) iova:0x%"PRIx64" is_write= =3D%d" smmuv3_translate_bypass(const char *n, uint16_t sid, uint64_t addr, bool i= s_write) "%s sid=3D0x%x STE bypass iova:0x%"PRIx64" is_write=3D%d" smmuv3_translate_abort(const char *n, uint16_t sid, uint64_t addr, bool is= _write) "%s sid=3D0x%x abort on iova:0x%"PRIx64" is_write=3D%d" -smmuv3_translate_success(const char *n, uint16_t sid, uint64_t iova, uint6= 4_t translated, int perm) "%s sid=3D0x%x iova=3D0x%"PRIx64" translated=3D0x= %"PRIx64" perm=3D0x%x" +smmuv3_translate_success(const char *n, uint16_t sid, uint64_t iova, uint6= 4_t translated, int perm, int stage) "%s sid=3D0x%x iova=3D0x%"PRIx64" tran= slated=3D0x%"PRIx64" perm=3D0x%x stage=3D%d" smmuv3_get_cd(uint64_t addr) "CD addr: 0x%"PRIx64 smmuv3_decode_cd(uint32_t oas) "oas=3D%d" smmuv3_decode_cd_tt(int i, uint32_t tsz, uint64_t ttb, uint32_t granule_sz= , bool had) "TT[%d]:tsz:%d ttb:0x%"PRIx64" granule_sz:%d had:%d" diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h index b3c881f0ee..5944735632 100644 --- a/include/hw/arm/smmu-common.h +++ b/include/hw/arm/smmu-common.h @@ -183,6 +183,14 @@ static inline uint16_t smmu_get_sid(SMMUDevice *sdev) int smmu_ptw(SMMUTransCfg *cfg, dma_addr_t iova, IOMMUAccessFlags perm, SMMUTLBEntry *tlbe, SMMUPTWEventInfo *info); =20 + +/* + * smmu_translate - Look for a translation in TLB, if not, do a PTW. + * Returns NULL on PTW error or incase of TLB permission errors. + */ +SMMUTLBEntry *smmu_translate(SMMUState *bs, SMMUTransCfg *cfg, dma_addr_t = addr, + IOMMUAccessFlags flag, SMMUPTWEventInfo *info= ); + /** * select_tt - compute which translation table shall be used according to * the input iova and translation config and return the TT specific info --=20 2.44.0.478.gd926399ef9-goog From nobody Fri May 17 07:47:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1712585385; cv=none; d=zohomail.com; s=zohoarc; b=gi+/PiUWM6RkN110HJKBRaWNYkySa9Y8Lt+fW87X1oEcWWnMgru3VYHxkhfH36GXJvkOVf6LqZoBJyw7KqQHxOiiWsMOCLDbmbPYCu/zRS/q0GVHVh+OLPXV8bKyScJ1drzigd3SUm7rH+LRAS4nBnSmf66k4eSrSRVkzTLj+2E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712585385; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8Rs5Gq0IJYI0ErVBm5gUmFtCJKGXjPzne5bV3NxRgVI=; b=PxfvUH66wmZiibkegpg5DDlinMkvKcjPCJ1lZhGCqiAUKvNZicxVv+LnB7zSvKfU8vONrdLD79MtAQG1MjlFY1sK5pkzu/BbcFwvJtDyjNK4mlltGjC9IbNllDa5iBQmVdjsTYdt6Qkbb/IkDj6HPg3FLOaQaj1DVMyVUnEqLEc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 171258538542969.88797220708273; Mon, 8 Apr 2024 07:09:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtpgQ-0006xw-07; Mon, 08 Apr 2024 10:09:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3g_oTZggKCv4ysuyzglgmuumrk.iuswks0-jk1krtutmt0.uxm@flex--smostafa.bounces.google.com>) id 1rtpgO-0006xB-7x for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:12 -0400 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3g_oTZggKCv4ysuyzglgmuumrk.iuswks0-jk1krtutmt0.uxm@flex--smostafa.bounces.google.com>) id 1rtpgM-0001MG-9v for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:11 -0400 Received: by mail-wm1-x34a.google.com with SMTP id 5b1f17b1804b1-4147ddecd52so23454775e9.0 for ; Mon, 08 Apr 2024 07:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712585347; x=1713190147; darn=nongnu.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=8Rs5Gq0IJYI0ErVBm5gUmFtCJKGXjPzne5bV3NxRgVI=; b=1UfaZ0NcgakepsQNhCcJnCY1dO3QVsPLg4HChNOXQTO+mCpg8FxOin82JD9Mun182a 0sAJowQ0Bxt/GKc1q0Mj3GSWzCnsEgFMiMVsoLBnUbwnHjhfrLDpBYv750JLrfWnKCur 23BScC6+N/BtXYzCeHHHk2OWI5LP92bIwDjM+YL5oKJB8iG0qMMqZbROaWv6emfWL3/X n/zjKCFtUPX7rAmTLxAPyPIpz/OZdBQ/BB2qaWuC4HeNEwczSmGvJ1AUptcsrd22bNXh lxa1G2gRW7Tjw3Ukub4Wz2JZkP66UxHBLm48anJsUep4+T1pNaXOlc1lk2QoPKDQwJpj zPmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712585347; x=1713190147; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=8Rs5Gq0IJYI0ErVBm5gUmFtCJKGXjPzne5bV3NxRgVI=; b=G8ZceFzQ/l9P+7AL/4J/0TiLhuIt4TTQND4rkWxUtKX18XKPIO3EAJLfoi0BvgER0j BOXpfeilf0UysQSFiA7JOUqMTXo5thTD87SeTH8kgf6WSZP4WfKlxH6qZvVGozvyrMDq lXjA+wwGfndn5835Qml64saVI3wA2v7fIfmzN/DPf2SXufoqfMnrcNTGuT4uJSezENka 4bN3XxftIaKyWUR9OaoutQ+0OoOMQEbGJ3Lfeqg4g0fIypUDWgJGwSdghcZMUVf7PDym Yaxkb/5CpJosPcXfhb94FNTiWhD/kKbHc5FzXGMRYfBbHo44UEi1MYhMug1DVPd89H77 CCTA== X-Forwarded-Encrypted: i=1; AJvYcCXzef1/tN/pkLjN9txTIU+jT/2qRlXPcQyNzH7r4o4f8QN5SGagZGzYRIiDmHo2374lH2rExZRwu62+gfbzX657VYIcIag= X-Gm-Message-State: AOJu0YzebE/u4VDIEvka+hreMg2t0iXRMTP/kyYjmlhU6fvIGoGoF1xC DUdb2g306wQhkkwhnk67GJKWf8R/J/tdUsg6BQIww3QcmxIXLimvcDT0RZZfzDXeD+CtBHkBnz1 woMJNRWGZDQ== X-Google-Smtp-Source: AGHT+IEmUAeykZPkblw7r/hjiEJS0ynYXlgskD+NxTpOMWY2jMoLMkyccMmuLU3Cl1EI/fHm65MU+Gev9tD9Xw== X-Received: from mostafa.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:333c]) (user=smostafa job=sendgmr) by 2002:a05:600c:4203:b0:416:8041:28f4 with SMTP id x3-20020a05600c420300b00416804128f4mr6389wmh.2.1712585347028; Mon, 08 Apr 2024 07:09:07 -0700 (PDT) Date: Mon, 8 Apr 2024 14:08:08 +0000 In-Reply-To: <20240408140818.3799590-1-smostafa@google.com> Mime-Version: 1.0 References: <20240408140818.3799590-1-smostafa@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240408140818.3799590-4-smostafa@google.com> Subject: [RFC PATCH v2 03/13] hw/arm/smmu: Consolidate ASID and VMID types From: Mostafa Saleh To: qemu-arm@nongnu.org, eric.auger@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Cc: jean-philippe@linaro.org, alex.bennee@linaro.org, maz@kernel.org, nicolinc@nvidia.com, julien@xen.org, richard.henderson@linaro.org, marcin.juszkiewicz@linaro.org, Mostafa Saleh 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=2a00:1450:4864:20::34a; envelope-from=3g_oTZggKCv4ysuyzglgmuumrk.iuswks0-jk1krtutmt0.uxm@flex--smostafa.bounces.google.com; helo=mail-wm1-x34a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1712585386204100001 Content-Type: text/plain; charset="utf-8" ASID and VMID used to be uint16_t in the translation config, however, in other contexts they can be int as -1 in case of TLB invalidation, to represent all(don=E2=80=99t care). When stage-2 was added asid was set to -1 in stage-2 and vmid to -1 in stage-1 configs. However, that meant they were set as (65536), this was not an issue as nesting was not supported and no commands/lookup targets both. With nesting, it=E2=80=99s critical to get this right as translation must be tagged correctly with ASID/VMID, and with ASID=3D-1 meaning stage-2. Represent ASID/VMID everywhere as int. Signed-off-by: Mostafa Saleh Reviewed-by: Eric Auger --- hw/arm/smmu-common.c | 10 +++++----- hw/arm/smmuv3.c | 4 ++-- include/hw/arm/smmu-common.h | 14 +++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index 20630eb670..771b9c79a3 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -57,7 +57,7 @@ static gboolean smmu_iotlb_key_equal(gconstpointer v1, gc= onstpointer v2) (k1->vmid =3D=3D k2->vmid); } =20 -SMMUIOTLBKey smmu_get_iotlb_key(uint16_t asid, uint16_t vmid, uint64_t iov= a, +SMMUIOTLBKey smmu_get_iotlb_key(int asid, int vmid, uint64_t iova, uint8_t tg, uint8_t level) { SMMUIOTLBKey key =3D {.asid =3D asid, .vmid =3D vmid, .iova =3D iova, @@ -130,7 +130,7 @@ void smmu_iotlb_inv_all(SMMUState *s) static gboolean smmu_hash_remove_by_asid(gpointer key, gpointer value, gpointer user_data) { - uint16_t asid =3D *(uint16_t *)user_data; + int asid =3D *(int *)user_data; SMMUIOTLBKey *iotlb_key =3D (SMMUIOTLBKey *)key; =20 return SMMU_IOTLB_ASID(*iotlb_key) =3D=3D asid; @@ -139,7 +139,7 @@ static gboolean smmu_hash_remove_by_asid(gpointer key, = gpointer value, static gboolean smmu_hash_remove_by_vmid(gpointer key, gpointer value, gpointer user_data) { - uint16_t vmid =3D *(uint16_t *)user_data; + int vmid =3D *(int *)user_data; SMMUIOTLBKey *iotlb_key =3D (SMMUIOTLBKey *)key; =20 return SMMU_IOTLB_VMID(*iotlb_key) =3D=3D vmid; @@ -191,13 +191,13 @@ void smmu_iotlb_inv_iova(SMMUState *s, int asid, int = vmid, dma_addr_t iova, &info); } =20 -void smmu_iotlb_inv_asid(SMMUState *s, uint16_t asid) +void smmu_iotlb_inv_asid(SMMUState *s, int asid) { trace_smmu_iotlb_inv_asid(asid); g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_asid, &asid); } =20 -inline void smmu_iotlb_inv_vmid(SMMUState *s, uint16_t vmid) +inline void smmu_iotlb_inv_vmid(SMMUState *s, int vmid) { trace_smmu_iotlb_inv_vmid(vmid); g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_vmid, &vmid); diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index f081ff0cc4..897f8fe085 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1235,7 +1235,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s) } case SMMU_CMD_TLBI_NH_ASID: { - uint16_t asid =3D CMD_ASID(&cmd); + int asid =3D CMD_ASID(&cmd); =20 if (!STAGE1_SUPPORTED(s)) { cmd_error =3D SMMU_CERROR_ILL; @@ -1268,7 +1268,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s) break; case SMMU_CMD_TLBI_S12_VMALL: { - uint16_t vmid =3D CMD_VMID(&cmd); + int vmid =3D CMD_VMID(&cmd); =20 if (!STAGE2_SUPPORTED(s)) { cmd_error =3D SMMU_CERROR_ILL; diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h index 5944735632..96eb017e50 100644 --- a/include/hw/arm/smmu-common.h +++ b/include/hw/arm/smmu-common.h @@ -84,7 +84,7 @@ typedef struct SMMUS2Cfg { bool record_faults; /* Record fault events (S2R) */ uint8_t granule_sz; /* Granule page shift (based on S2TG) */ uint8_t eff_ps; /* Effective PA output range (based on S2PS) */ - uint16_t vmid; /* Virtual Machine ID (S2VMID) */ + int vmid; /* Virtual Machine ID (S2VMID) */ uint64_t vttb; /* Address of translation table base (S2TTB) */ } SMMUS2Cfg; =20 @@ -108,7 +108,7 @@ typedef struct SMMUTransCfg { uint64_t ttb; /* TT base address */ uint8_t oas; /* output address width */ uint8_t tbi; /* Top Byte Ignore */ - uint16_t asid; + int asid; SMMUTransTableInfo tt[2]; /* Used by stage-2 only. */ struct SMMUS2Cfg s2cfg; @@ -132,8 +132,8 @@ typedef struct SMMUPciBus { =20 typedef struct SMMUIOTLBKey { uint64_t iova; - uint16_t asid; - uint16_t vmid; + int asid; + int vmid; uint8_t tg; uint8_t level; } SMMUIOTLBKey; @@ -205,11 +205,11 @@ IOMMUMemoryRegion *smmu_iommu_mr(SMMUState *s, uint32= _t sid); SMMUTLBEntry *smmu_iotlb_lookup(SMMUState *bs, SMMUTransCfg *cfg, SMMUTransTableInfo *tt, hwaddr iova); void smmu_iotlb_insert(SMMUState *bs, SMMUTransCfg *cfg, SMMUTLBEntry *ent= ry); -SMMUIOTLBKey smmu_get_iotlb_key(uint16_t asid, uint16_t vmid, uint64_t iov= a, +SMMUIOTLBKey smmu_get_iotlb_key(int asid, int vmid, uint64_t iova, uint8_t tg, uint8_t level); void smmu_iotlb_inv_all(SMMUState *s); -void smmu_iotlb_inv_asid(SMMUState *s, uint16_t asid); -void smmu_iotlb_inv_vmid(SMMUState *s, uint16_t vmid); +void smmu_iotlb_inv_asid(SMMUState *s, int asid); +void smmu_iotlb_inv_vmid(SMMUState *s, int vmid); void smmu_iotlb_inv_iova(SMMUState *s, int asid, int vmid, dma_addr_t iova, uint8_t tg, uint64_t num_pages, uint8_t ttl); =20 --=20 2.44.0.478.gd926399ef9-goog From nobody Fri May 17 07:47:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1712585439; cv=none; d=zohomail.com; s=zohoarc; b=cLUZbpVEpkg2PGepaZo9AQZu4VqaxMGvS5vVZHqyeAzawdCy5klQfiSY6k0r1fS1h0bBOWKksm+bF7HxpdaIzwlOZ273mk0sHh3bSzuVhTMMXcWSnJdwbVP47G3KZ7FFwGzL8ilvS1CC1TbqDmIteSikBWu1O40zmwGBsS9FK4s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712585439; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=I6ATJsy3meUvTXvscx3wXoJMQXTicy2M4jxU0ba4BEQ=; b=YhF48oVNDNuVwvsXUtRZ09px9FpS6DhrLyXb7avu5865SPwmthOu4ogXOQ/i1REKfuo4JD5aguvx4mp+Ro7uuqVCnq7oDWluI9KVgTVh+2qiYhCLKCvei5xgwp868CFjNkqiZsXyYrVX1ZZviePXlZS5sdwSPk4ziLWcN0Wiv7M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1712585439490114.13018976805938; Mon, 8 Apr 2024 07:10:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtpgU-0006zA-2d; Mon, 08 Apr 2024 10:09:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3hfoTZggKCgIuoquvchciqqing.eqosgow-fgxgnpqpipw.qti@flex--smostafa.bounces.google.com>) id 1rtpgP-0006y0-Uy for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:13 -0400 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3hfoTZggKCgIuoquvchciqqing.eqosgow-fgxgnpqpipw.qti@flex--smostafa.bounces.google.com>) id 1rtpgM-0001Mc-To for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:13 -0400 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-617fffab703so19063997b3.0 for ; Mon, 08 Apr 2024 07:09:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712585349; x=1713190149; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=I6ATJsy3meUvTXvscx3wXoJMQXTicy2M4jxU0ba4BEQ=; b=cIth8oyOjlMRcR9R9E4tBIHxpOMmq1L+efBNRb6Oq/m5o59b3eo8Fj1S8LwMJMpmQR cCIuSDTp9mJ1BiqpBHbdpYTJaD18pALWt3DEiwxfhW1u7KhzpSyHCgpBDrP9/uXLxxZj fTbRC9z+7Rfr3aBorA9SQXojMSHx6R8kNU/sHW5toFqrL9xI8k5AySjc7629bJCBtf77 T0QGNhcyahRlx5laxYtBOCvXJK6xG0KIrnmXdsRKjNbgCcqqw5VklwcFSi/7snUgc1Ev aLeQ8y6HBMfoz9IWs3mcIEJbCI4lm/uBO4m43Y3UK/PHRRTsV2BhqAzCOsWMYteWgopA sfGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712585349; x=1713190149; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=I6ATJsy3meUvTXvscx3wXoJMQXTicy2M4jxU0ba4BEQ=; b=KCIMNsvslTfWIpYVcGWwCuasaAhj0/CEpLpywd8qsRc2ttRUDa0wZICAyev0keJkjF B5Yvqg1O/yt6HkfFzuYNJTjt8C6r7kPEoKsyZtU/Trb3DJoq/jJGFizWoGC7Pvo1h8h9 yVFV5FkBDm16seD8lD3Jz+uYQV44Hjf9ijjVYpq+iG9XamJOz7fYqWasJbcbYXzrQocJ kPw43BBCavuvelpxDoruvQE/2AgmN2KnXbemwq63J7W3pi0jS3VPpsgR++VsBzC2BAFa B/iMuHDbaBS0HKYEiBcEjESrfPytffZLpL7cXemwTIl1pATrsCTJRIrSATQMiDLiv6Bx /rOg== X-Forwarded-Encrypted: i=1; AJvYcCWq3HS85pA9eWSGbZRT1veFDjccpsgeWyU7cKuDDvvhvGD6WDNFtTLKwW4tUejivxUfFr+iR/ejKdHoe+pvdXLWH798Sag= X-Gm-Message-State: AOJu0YxULINyQa4kp4+D++pJc+Wq/DEcCUOmeXUSaZicrFf2Rcg39JEb mg51dgOBdxWdhgh6J14mBJfK9bokfhC47Y+tCQQTJsgq2veh0hjAlR8nePvttA9J7IJGwB6IVeQ dLz4QlnkZVA== X-Google-Smtp-Source: AGHT+IFXhj1dMnd9bT4RTIIS37SU46vpA7CZ6O2Z8X347JAcK6N9p9bX08nMAvw66FJ0i9MlUzBFuX5qt0wigg== X-Received: from mostafa.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:333c]) (user=smostafa job=sendgmr) by 2002:a05:6902:1502:b0:dd9:1b94:edb5 with SMTP id q2-20020a056902150200b00dd91b94edb5mr705407ybu.10.1712585349473; Mon, 08 Apr 2024 07:09:09 -0700 (PDT) Date: Mon, 8 Apr 2024 14:08:09 +0000 In-Reply-To: <20240408140818.3799590-1-smostafa@google.com> Mime-Version: 1.0 References: <20240408140818.3799590-1-smostafa@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240408140818.3799590-5-smostafa@google.com> Subject: [RFC PATCH v2 04/13] hw/arm/smmuv3: Translate CD and TT using stage-2 table From: Mostafa Saleh To: qemu-arm@nongnu.org, eric.auger@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Cc: jean-philippe@linaro.org, alex.bennee@linaro.org, maz@kernel.org, nicolinc@nvidia.com, julien@xen.org, richard.henderson@linaro.org, marcin.juszkiewicz@linaro.org, Mostafa Saleh 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=2607:f8b0:4864:20::114a; envelope-from=3hfoTZggKCgIuoquvchciqqing.eqosgow-fgxgnpqpipw.qti@flex--smostafa.bounces.google.com; helo=mail-yw1-x114a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1712585440449100010 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" According to the user manual (ARM IHI 0070 F.b), In "5.2 Stream Table Entry": [51:6] S1ContextPtr If Config[1] =3D=3D 1 (stage 2 enabled), this pointer is an IPA translated= by stage 2 and the programmed value must be within the range of the IAS. In "5.4.1 CD notes": The translation table walks performed from TTB0 or TTB1 are always perform= ed in IPA space if stage 2 translations are enabled. So translate both the CD and the TTBx in this patch if nested translation is requested. Signed-off-by: Mostafa Saleh --- hw/arm/smmuv3.c | 49 ++++++++++++++++++++++++++++++------ include/hw/arm/smmu-common.h | 17 +++++++++++++ 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 897f8fe085..a7cf543acc 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -337,14 +337,36 @@ static int smmu_get_ste(SMMUv3State *s, dma_addr_t ad= dr, STE *buf, =20 } =20 +static SMMUTranslationStatus smmuv3_do_translate(SMMUv3State *s, hwaddr ad= dr, + SMMUTransCfg *cfg, + SMMUEventInfo *event, + IOMMUAccessFlags flag, + SMMUTLBEntry **out_entry); /* @ssid > 0 not supported yet */ -static int smmu_get_cd(SMMUv3State *s, STE *ste, uint32_t ssid, - CD *buf, SMMUEventInfo *event) +static int smmu_get_cd(SMMUv3State *s, STE *ste, SMMUTransCfg *cfg, + uint32_t ssid, CD *buf, SMMUEventInfo *event) { dma_addr_t addr =3D STE_CTXPTR(ste); int ret, i; + SMMUTranslationStatus status; + SMMUTLBEntry *entry; =20 trace_smmuv3_get_cd(addr); + + if (cfg->stage =3D=3D SMMU_NESTED) { + CALL_FUNC_CFG_S2(cfg, status, smmuv3_do_translate, s, addr, + cfg, event, IOMMU_RO, &entry); + /* + * It is not clear what should happen if this fails, so we return = here + * which gets propagated as a translation error. + */ + if (status !=3D SMMU_TRANS_SUCCESS) { + return -EINVAL; + } + + addr =3D CACHED_ENTRY_TO_ADDR(entry, addr); + } + /* TODO: guarantee 64-bit single-copy atomicity */ ret =3D dma_memory_read(&address_space_memory, addr, buf, sizeof(*buf), MEMTXATTRS_UNSPECIFIED); @@ -659,10 +681,13 @@ static int smmu_find_ste(SMMUv3State *s, uint32_t sid= , STE *ste, return 0; } =20 -static int decode_cd(SMMUTransCfg *cfg, CD *cd, SMMUEventInfo *event) +static int decode_cd(SMMUv3State *s, SMMUTransCfg *cfg, + CD *cd, SMMUEventInfo *event) { int ret =3D -EINVAL; int i; + SMMUTranslationStatus status; + SMMUTLBEntry *entry; =20 if (!CD_VALID(cd) || !CD_AARCH64(cd)) { goto bad_cd; @@ -713,6 +738,17 @@ static int decode_cd(SMMUTransCfg *cfg, CD *cd, SMMUEv= entInfo *event) =20 tt->tsz =3D tsz; tt->ttb =3D CD_TTB(cd, i); + + /* Translate the TTBx, from IPA to PA if nesting is enabled. */ + if (cfg->stage =3D=3D SMMU_NESTED) { + CALL_FUNC_CFG_S2(cfg, status, smmuv3_do_translate, s, + tt->ttb, cfg, event, IOMMU_RO, &entry); + /* See smmu_get_cd(). */ + if (status !=3D SMMU_TRANS_SUCCESS) { + return -EINVAL; + } + tt->ttb =3D CACHED_ENTRY_TO_ADDR(entry, tt->ttb); + } if (tt->ttb & ~(MAKE_64BIT_MASK(0, cfg->oas))) { goto bad_cd; } @@ -767,12 +803,12 @@ static int smmuv3_decode_config(IOMMUMemoryRegion *mr= , SMMUTransCfg *cfg, return 0; } =20 - ret =3D smmu_get_cd(s, &ste, 0 /* ssid */, &cd, event); + ret =3D smmu_get_cd(s, &ste, cfg, 0 /* ssid */, &cd, event); if (ret) { return ret; } =20 - return decode_cd(cfg, &cd, event); + return decode_cd(s, cfg, &cd, event); } =20 /** @@ -942,8 +978,7 @@ epilogue: switch (status) { case SMMU_TRANS_SUCCESS: entry.perm =3D cached_entry->entry.perm; - entry.translated_addr =3D cached_entry->entry.translated_addr + - (addr & cached_entry->entry.addr_mask); + entry.translated_addr =3D CACHED_ENTRY_TO_ADDR(cached_entry, addr); entry.addr_mask =3D cached_entry->entry.addr_mask; trace_smmuv3_translate_success(mr->parent_obj.name, sid, addr, entry.translated_addr, entry.perm, diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h index 96eb017e50..2772175115 100644 --- a/include/hw/arm/smmu-common.h +++ b/include/hw/arm/smmu-common.h @@ -37,6 +37,23 @@ #define VMSA_IDXMSK(isz, strd, lvl) ((1ULL << \ VMSA_BIT_LVL(isz, strd, lvl))= - 1) =20 +#define CACHED_ENTRY_TO_ADDR(ent, addr) (ent)->entry.translated_addr = + \ + ((addr) & (ent)->entry.addr_m= ask); + +/* + * From nested context, some functions might need to translate IPA address= es. + * As cfg has SMMU_NESTED, this won't work, this macro calls a function wi= th + * making it a stage-2 cfg and then restore it after. + */ +#define CALL_FUNC_CFG_S2(cfg, ret, fn, ...) ({ \ + int asid =3D cfg->asid;= \ + cfg->stage =3D SMMU_STA= GE_2; \ + cfg->asid =3D -1; \ + ret =3D fn(__VA_ARGS__)= ; \ + cfg->asid =3D asid; \ + cfg->stage =3D SMMU_NES= TED; \ + }) + /* * Page table walk error types */ --=20 2.44.0.478.gd926399ef9-goog From nobody Fri May 17 07:47:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1712585434; cv=none; d=zohomail.com; s=zohoarc; b=XtDw98Vqd7X/vSnWrbFHz73YFlvTZtwHvxa9JSpv85WMMwvptaVyROrRu3yL+b3eQS3Z/1Fpfe7MrJaBye/A1O1ni6f3sUKYEZJxASIDPEuY2qpcWIRIqNVAck1OBhTjsVR0R8/b5b70Cg8x0FO7wP3wExSqYV9gFaoHx1iS9JQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712585434; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=pSWfvyeD9wqAqTJ3MFH1nt/3AYPAupNlsKJNXIiWPoY=; b=GAVP3BCoeGP4bw5L+LXj7qLg8zECSqWStIGGT84yNlySUBfhgoozaCuB1RLgv58uDBvF/7DsUb40p81TQr5lXb88TW7XhUKFIFcfqR4W1+YL/ji5Qo7po4Q7MJ0Ziod1a4DsoQxZ+GGMFcWJ324MrUxq32CJy+2uw87m5a6FycE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1712585434672885.0543430628858; Mon, 8 Apr 2024 07:10:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtpgv-000792-0Z; Mon, 08 Apr 2024 10:09:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3iPoTZggKCgUxrtxyfkflttlqj.htrvjrz-ij0jqstslsz.twl@flex--smostafa.bounces.google.com>) id 1rtpgg-00075a-OP for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:30 -0400 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3iPoTZggKCgUxrtxyfkflttlqj.htrvjrz-ij0jqstslsz.twl@flex--smostafa.bounces.google.com>) id 1rtpgR-0001N3-Lx for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:29 -0400 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-617bd0cf61fso69230237b3.3 for ; Mon, 08 Apr 2024 07:09:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712585352; x=1713190152; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pSWfvyeD9wqAqTJ3MFH1nt/3AYPAupNlsKJNXIiWPoY=; b=kNGvFaF9vkYrV/nt1N5bF64Bnvf6QGGRu3Bnhfayt75c09epuVjCKVkpE9VNO4emLQ 3vrFCcILWOBJ26SD0t39UkO6gTwArQHe93kyOkIUbA+4LGiyozQLI6wHHkBCj2i613iL olgIFihw/XsfnEX0eQ/iYT5v3qeo5tlCA1Op9GOT9m9A0jXcXNZzlEciA2sESE1QMieo tRQtEUXpYfVLTf5Z0gqf1TPsMPAy4R8gjhuYSttaPIXAwSbAdote1ynFxzZtfV+hg/ev 2Iae4FY9y2ylDvuvUR/86MoLPOkNCzidd34lpHMGdPEscEuhAsREmSvm+E5RA7shhswo kwBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712585352; x=1713190152; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pSWfvyeD9wqAqTJ3MFH1nt/3AYPAupNlsKJNXIiWPoY=; b=AHok+Y2QzgvaxUOS2A0tyg9PoEsp/Zeqbu+eh7gOp8ApYOMHJWqttUhUvwsaWxQwGU dkPDbFvnOyGDYg5oMmqWaCEFEMiXHd4Ue8/nGMlLSTbwWn2Y7hoYUl4FdEF/f1IvnQzH zRwjs+aXXF3okGqGCA+Tf6XIRC0pe3NFTmiSqXSvRs7z4yP4jEx3k0nT5e8gW1wymmXc mpvkuvjzLPHsKy8XGMigbMjRCm6JidOnIkAG9R+rbEr19hbN1Bayp84oMLGiJf3gsz9V Ao7H3ZSoC2Ku4yVq9LvnLwP1azIuO4P6XVSC9TQfVtUcpwbHZIdoYu391FNI2G5iB0N1 Frqw== X-Forwarded-Encrypted: i=1; AJvYcCUMSCXWD7iS6Y87qLsG77A/X26/MVzCUExpvU7oZf7kFVfXHed6s822k2vXg+UAoFGxP7bMoWz/01IUCeqHl6GLOqVme4o= X-Gm-Message-State: AOJu0YzikdEoBCZa4400kKdf7IkGCazJHPotPve+qrl+3H7SSF/RjMS+ 0wtzFTTBzqFQnFGsAmYGmaYUW+0UvTck9O60dARDUqUgHI5dlJF0m3YAj+9CedNoIiDrwahHHmS cawbRNPW/3Q== X-Google-Smtp-Source: AGHT+IGQhJCW8NjJVYYTyicGFaMV/HaF215cmoReg9wzzwTkSSgmcm6tgikjeDqiUO+zwlnBKPv9BNBhl03aqA== X-Received: from mostafa.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:333c]) (user=smostafa job=sendgmr) by 2002:a05:6902:1508:b0:dcc:e1a6:aca9 with SMTP id q8-20020a056902150800b00dcce1a6aca9mr2790949ybu.9.1712585352082; Mon, 08 Apr 2024 07:09:12 -0700 (PDT) Date: Mon, 8 Apr 2024 14:08:10 +0000 In-Reply-To: <20240408140818.3799590-1-smostafa@google.com> Mime-Version: 1.0 References: <20240408140818.3799590-1-smostafa@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240408140818.3799590-6-smostafa@google.com> Subject: [RFC PATCH v2 05/13] hw/arm/smmu-common: Support nested translation From: Mostafa Saleh To: qemu-arm@nongnu.org, eric.auger@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Cc: jean-philippe@linaro.org, alex.bennee@linaro.org, maz@kernel.org, nicolinc@nvidia.com, julien@xen.org, richard.henderson@linaro.org, marcin.juszkiewicz@linaro.org, Mostafa Saleh 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=2607:f8b0:4864:20::1149; envelope-from=3iPoTZggKCgUxrtxyfkflttlqj.htrvjrz-ij0jqstslsz.twl@flex--smostafa.bounces.google.com; helo=mail-yw1-x1149.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1712585436427100002 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When nested translation is requested, do the following: - Translate stage-1 IPA using stage-2 to a physical address. - Translate stage-1 PTW walks using stage-2. - Combine both to create a single TLB entry, for that we choose the smallest entry to cache, which means that if the smallest entry comes from stage-2, and stage-2 use different granule, TLB lookup for stage-1 (in nested config) will always miss. Lookup logic is modified for nesting to lookup using stage-2 granule if stage-1 granule missed and they are different. Also, add more visibility in trace points, to make it easier to debug. Signed-off-by: Mostafa Saleh --- hw/arm/smmu-common.c | 153 ++++++++++++++++++++++++++++------- hw/arm/trace-events | 6 +- include/hw/arm/smmu-common.h | 3 +- 3 files changed, 131 insertions(+), 31 deletions(-) diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index 771b9c79a3..2cf27b490b 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -66,8 +66,10 @@ SMMUIOTLBKey smmu_get_iotlb_key(int asid, int vmid, uint= 64_t iova, return key; } =20 -SMMUTLBEntry *smmu_iotlb_lookup(SMMUState *bs, SMMUTransCfg *cfg, - SMMUTransTableInfo *tt, hwaddr iova) +static SMMUTLBEntry *smmu_iotlb_lookup_all_levels(SMMUState *bs, + SMMUTransCfg *cfg, + SMMUTransTableInfo *tt, + hwaddr iova) { uint8_t tg =3D (tt->granule_sz - 10) / 2; uint8_t inputsize =3D 64 - tt->tsz; @@ -88,10 +90,29 @@ SMMUTLBEntry *smmu_iotlb_lookup(SMMUState *bs, SMMUTran= sCfg *cfg, } level++; } + return entry; +} + +SMMUTLBEntry *smmu_iotlb_lookup(SMMUState *bs, SMMUTransCfg *cfg, + SMMUTransTableInfo *tt, hwaddr iova) +{ + SMMUTLBEntry *entry =3D NULL; + + entry =3D smmu_iotlb_lookup_all_levels(bs, cfg, tt, iova); + /* + * For nested translation also use the s2 granule, as the TLB will ins= ert + * the smallest of both, so the entry can be cached with the s2 granul= e. + */ + if (!entry && (cfg->stage =3D=3D SMMU_NESTED) && + (cfg->s2cfg.granule_sz !=3D tt->granule_sz)) { + tt->granule_sz =3D cfg->s2cfg.granule_sz; + entry =3D smmu_iotlb_lookup_all_levels(bs, cfg, tt, iova); + } =20 if (entry) { cfg->iotlb_hits++; trace_smmu_iotlb_lookup_hit(cfg->asid, cfg->s2cfg.vmid, iova, + entry->entry.addr_mask, cfg->iotlb_hits, cfg->iotlb_misses, 100 * cfg->iotlb_hits / (cfg->iotlb_hits + cfg->iotlb_misses)); @@ -117,7 +138,7 @@ void smmu_iotlb_insert(SMMUState *bs, SMMUTransCfg *cfg= , SMMUTLBEntry *new) *key =3D smmu_get_iotlb_key(cfg->asid, cfg->s2cfg.vmid, new->entry.iov= a, tg, new->level); trace_smmu_iotlb_insert(cfg->asid, cfg->s2cfg.vmid, new->entry.iova, - tg, new->level); + tg, new->level, new->entry.translated_addr); g_hash_table_insert(bs->iotlb, key, new); } =20 @@ -286,6 +307,27 @@ SMMUTransTableInfo *select_tt(SMMUTransCfg *cfg, dma_a= ddr_t iova) return NULL; } =20 +/* Return the correct table address based on configuration. */ +static inline int translate_table_s1(dma_addr_t *table_addr, SMMUTransCfg = *cfg, + SMMUPTWEventInfo *info, SMMUState *bs) +{ + dma_addr_t addr =3D *table_addr; + SMMUTLBEntry *cached_entry; + + if (cfg->stage !=3D SMMU_NESTED) { + return 0; + } + + CALL_FUNC_CFG_S2(cfg, cached_entry, smmu_translate, + bs, cfg, addr, IOMMU_RO, info); + + if (cached_entry) { + *table_addr =3D CACHED_ENTRY_TO_ADDR(cached_entry, addr); + return 0; + } + return -EINVAL; +} + /** * smmu_ptw_64_s1 - VMSAv8-64 Walk of the page tables for a given IOVA * @cfg: translation config @@ -301,7 +343,8 @@ SMMUTransTableInfo *select_tt(SMMUTransCfg *cfg, dma_ad= dr_t iova) */ static int smmu_ptw_64_s1(SMMUTransCfg *cfg, dma_addr_t iova, IOMMUAccessFlags perm, - SMMUTLBEntry *tlbe, SMMUPTWEventInfo *info) + SMMUTLBEntry *tlbe, SMMUPTWEventInfo *info, + SMMUState *bs) { dma_addr_t baseaddr, indexmask; SMMUStage stage =3D cfg->stage; @@ -349,6 +392,10 @@ static int smmu_ptw_64_s1(SMMUTransCfg *cfg, goto error; } baseaddr =3D get_table_pte_address(pte, granule_sz); + /* In case of failure, retain stage-2 fault. */ + if (translate_table_s1(&baseaddr, cfg, info, bs)) { + goto error_no_stage; + } level++; continue; } else if (is_page_pte(pte, level)) { @@ -384,7 +431,7 @@ static int smmu_ptw_64_s1(SMMUTransCfg *cfg, tlbe->entry.translated_addr =3D gpa; tlbe->entry.iova =3D iova & ~mask; tlbe->entry.addr_mask =3D mask; - tlbe->entry.perm =3D PTE_AP_TO_PERM(ap); + tlbe->parent_perm =3D tlbe->entry.perm =3D PTE_AP_TO_PERM(ap); tlbe->level =3D level; tlbe->granule =3D granule_sz; return 0; @@ -393,6 +440,7 @@ static int smmu_ptw_64_s1(SMMUTransCfg *cfg, =20 error: info->stage =3D SMMU_STAGE_1; +error_no_stage: tlbe->entry.perm =3D IOMMU_NONE; return -EINVAL; } @@ -505,7 +553,7 @@ static int smmu_ptw_64_s2(SMMUTransCfg *cfg, tlbe->entry.translated_addr =3D gpa; tlbe->entry.iova =3D ipa & ~mask; tlbe->entry.addr_mask =3D mask; - tlbe->entry.perm =3D s2ap; + tlbe->parent_perm =3D tlbe->entry.perm =3D s2ap; tlbe->level =3D level; tlbe->granule =3D granule_sz; return 0; @@ -518,6 +566,28 @@ error: return -EINVAL; } =20 +/* Combine 2 TLB enteries and return in tlbe. */ +static void combine_tlb(SMMUTLBEntry *tlbe, SMMUTLBEntry *tlbe_s2, + dma_addr_t iova, SMMUTransCfg *cfg) +{ + if (cfg->stage =3D=3D SMMU_NESTED) { + tlbe->entry.addr_mask =3D MIN(tlbe->entry.addr_mask, + tlbe_s2->entry.addr_mask); + tlbe->entry.translated_addr =3D CACHED_ENTRY_TO_ADDR(tlbe_s2, + tlbe->entry.translated_addr); + + tlbe->granule =3D MIN(tlbe->granule, tlbe_s2->granule); + tlbe->level =3D MAX(tlbe->level, tlbe_s2->level); + tlbe->entry.iova =3D iova & ~tlbe->entry.addr_mask; + /* parent_perm has s2 perm while perm has s1 perm. */ + tlbe->parent_perm =3D tlbe_s2->entry.perm; + return; + } + + /* That was not nested, use the s2. */ + memcpy(tlbe, tlbe_s2, sizeof(*tlbe)); +} + /** * smmu_ptw - Walk the page tables for an IOVA, according to @cfg * @@ -530,28 +600,59 @@ error: * return 0 on success */ int smmu_ptw(SMMUTransCfg *cfg, dma_addr_t iova, IOMMUAccessFlags perm, - SMMUTLBEntry *tlbe, SMMUPTWEventInfo *info) + SMMUTLBEntry *tlbe, SMMUPTWEventInfo *info, SMMUState *bs) { - if (cfg->stage =3D=3D SMMU_STAGE_1) { - return smmu_ptw_64_s1(cfg, iova, perm, tlbe, info); - } else if (cfg->stage =3D=3D SMMU_STAGE_2) { - /* - * If bypassing stage 1(or unimplemented), the input address is pa= ssed - * directly to stage 2 as IPA. If the input address of a transacti= on - * exceeds the size of the IAS, a stage 1 Address Size fault occur= s. - * For AA64, IAS =3D OAS according to (IHI 0070.E.a) "3.4 Address = sizes" - */ - if (iova >=3D (1ULL << cfg->oas)) { - info->type =3D SMMU_PTW_ERR_ADDR_SIZE; - info->stage =3D SMMU_STAGE_1; - tlbe->entry.perm =3D IOMMU_NONE; - return -EINVAL; + int ret =3D 0; + SMMUTLBEntry tlbe_s2; + dma_addr_t ipa =3D iova; + + if (cfg->stage & SMMU_STAGE_1) { + ret =3D smmu_ptw_64_s1(cfg, iova, perm, tlbe, info, bs); + if (ret) { + return ret; } + /* This is the IPA for next stage.*/ + ipa =3D CACHED_ENTRY_TO_ADDR(tlbe, iova); + } =20 - return smmu_ptw_64_s2(cfg, iova, perm, tlbe, info); + /* + * The address output from the translation causes a stage 1 Address Si= ze + * fault if it exceeds the range of the effective IPA size for the giv= en CD. + * If bypassing stage 1(or unimplemented), the input address is passed + * directly to stage 2 as IPA. If the input address of a transaction + * exceeds the size of the IAS, a stage 1 Address Size fault occurs. + * For AA64, IAS =3D OAS according to (IHI 0070.E.a) "3.4 Address size= s" + */ + if (ipa >=3D (1ULL << cfg->oas)) { + info->type =3D SMMU_PTW_ERR_ADDR_SIZE; + info->stage =3D SMMU_STAGE_1; + tlbe->entry.perm =3D IOMMU_NONE; + return -EINVAL; } =20 - g_assert_not_reached(); + if (cfg->stage & SMMU_STAGE_2) { + ret =3D smmu_ptw_64_s2(cfg, ipa, perm, &tlbe_s2, info); + if (ret) { + return ret; + } + combine_tlb(tlbe, &tlbe_s2, iova, cfg); + } + + return ret; +} + +static int validate_tlb_entry(SMMUTLBEntry *cached_entry, IOMMUAccessFlags= flag, + SMMUPTWEventInfo *info) +{ + if ((flag & IOMMU_WO) && !(cached_entry->entry.perm & + cached_entry->parent_perm & IOMMU_WO)) { + info->type =3D SMMU_PTW_ERR_PERMISSION; + info->stage =3D !(cached_entry->entry.perm & IOMMU_WO) ? + SMMU_STAGE_1 : + SMMU_STAGE_2; + return -EINVAL; + } + return 0; } =20 SMMUTLBEntry *smmu_translate(SMMUState *bs, SMMUTransCfg *cfg, dma_addr_t = addr, @@ -595,16 +696,14 @@ SMMUTLBEntry *smmu_translate(SMMUState *bs, SMMUTrans= Cfg *cfg, dma_addr_t addr, =20 cached_entry =3D smmu_iotlb_lookup(bs, cfg, &tt_combined, aligned_addr= ); if (cached_entry) { - if ((flag & IOMMU_WO) && !(cached_entry->entry.perm & IOMMU_WO)) { - info->type =3D SMMU_PTW_ERR_PERMISSION; - info->stage =3D cfg->stage; + if (validate_tlb_entry(cached_entry, flag, info)) { return NULL; } return cached_entry; } =20 cached_entry =3D g_new0(SMMUTLBEntry, 1); - status =3D smmu_ptw(cfg, aligned_addr, flag, cached_entry, info); + status =3D smmu_ptw(cfg, aligned_addr, flag, cached_entry, info, bs); if (status) { g_free(cached_entry); return NULL; diff --git a/hw/arm/trace-events b/hw/arm/trace-events index cc12924a84..5f23f0b963 100644 --- a/hw/arm/trace-events +++ b/hw/arm/trace-events @@ -15,9 +15,9 @@ smmu_iotlb_inv_asid(uint16_t asid) "IOTLB invalidate asid= =3D%d" smmu_iotlb_inv_vmid(uint16_t vmid) "IOTLB invalidate vmid=3D%d" smmu_iotlb_inv_iova(uint16_t asid, uint64_t addr) "IOTLB invalidate asid= =3D%d addr=3D0x%"PRIx64 smmu_inv_notifiers_mr(const char *name) "iommu mr=3D%s" -smmu_iotlb_lookup_hit(uint16_t asid, uint16_t vmid, uint64_t addr, uint32_= t hit, uint32_t miss, uint32_t p) "IOTLB cache HIT asid=3D%d vmid=3D%d addr= =3D0x%"PRIx64" hit=3D%d miss=3D%d hit rate=3D%d" -smmu_iotlb_lookup_miss(uint16_t asid, uint16_t vmid, uint64_t addr, uint32= _t hit, uint32_t miss, uint32_t p) "IOTLB cache MISS asid=3D%d vmid=3D%d ad= dr=3D0x%"PRIx64" hit=3D%d miss=3D%d hit rate=3D%d" -smmu_iotlb_insert(uint16_t asid, uint16_t vmid, uint64_t addr, uint8_t tg,= uint8_t level) "IOTLB ++ asid=3D%d vmid=3D%d addr=3D0x%"PRIx64" tg=3D%d le= vel=3D%d" +smmu_iotlb_lookup_hit(int asid, uint16_t vmid, uint64_t addr, uint64_t mas= k, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache HIT asid=3D%d vmid= =3D%d addr=3D0x%"PRIx64" mask=3D0x%"PRIx64" hit=3D%d miss=3D%d hit rate=3D%= d" +smmu_iotlb_lookup_miss(int asid, uint16_t vmid, uint64_t addr, uint32_t hi= t, uint32_t miss, uint32_t p) "IOTLB cache MISS asid=3D%d vmid=3D%d addr=3D= 0x%"PRIx64" hit=3D%d miss=3D%d hit rate=3D%d" +smmu_iotlb_insert(int asid, uint16_t vmid, uint64_t addr, uint8_t tg, uint= 8_t level, uint64_t translate_addr) "IOTLB ++ asid=3D%d vmid=3D%d addr=3D0x= %"PRIx64" tg=3D%d level=3D%d translate_addr=3D0x%"PRIx64 =20 # smmuv3.c smmuv3_read_mmio(uint64_t addr, uint64_t val, unsigned size, uint32_t r) "= addr: 0x%"PRIx64" val:0x%"PRIx64" size: 0x%x(%d)" diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h index 2772175115..03ff0f02ba 100644 --- a/include/hw/arm/smmu-common.h +++ b/include/hw/arm/smmu-common.h @@ -91,6 +91,7 @@ typedef struct SMMUTLBEntry { IOMMUTLBEntry entry; uint8_t level; uint8_t granule; + IOMMUAccessFlags parent_perm; } SMMUTLBEntry; =20 /* Stage-2 configuration. */ @@ -198,7 +199,7 @@ static inline uint16_t smmu_get_sid(SMMUDevice *sdev) * pair, according to @cfg translation config */ int smmu_ptw(SMMUTransCfg *cfg, dma_addr_t iova, IOMMUAccessFlags perm, - SMMUTLBEntry *tlbe, SMMUPTWEventInfo *info); + SMMUTLBEntry *tlbe, SMMUPTWEventInfo *info, SMMUState *bs); =20 =20 /* --=20 2.44.0.478.gd926399ef9-goog From nobody Fri May 17 07:47:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1712585519; cv=none; d=zohomail.com; s=zohoarc; b=GfCY5dZege9yZtGHBwVa/IYW/S30aszwtilXB5aDrXePqe5A4MtCSI/Zg8vq+mE4r7hAX0Vbtu/nb5yWTWhN4+9eRmljjQyJaPNxvu4jvpI5nOrt1N4baq4wsRJ2L8kTSeks7V5Bk3cCEEu0nUoBdpMitiu8eFEEMt5RRpyl8zY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712585519; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=92pKf8rxBG8PwjQhN5a+4mjr0DOeod7sAVNPkhgcMv4=; b=VQb+/adqVYIoWgjqKN5hbSSfDBn9KF+NAic+ZayRUoi4tDHYfm/cDxSyGUjwIJtvE0GTzdHjMBmogA8eoLHVMhEM8rd/Ao0VQVqxAmB8x2JtA952Xgb0w8uVDpplQDMTBd3NnjJ0vVcy95UpAy9p9eIZNCoygsjRlo+/nIgp5VI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1712585519055509.63808953462205; Mon, 8 Apr 2024 07:11:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtphV-0007wC-A3; Mon, 08 Apr 2024 10:10:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3ivoTZggKCgcztvz0hmhnvvnsl.jvtxlt1-kl2lsuvunu1.vyn@flex--smostafa.bounces.google.com>) id 1rtpgo-00079c-8l for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:41 -0400 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3ivoTZggKCgcztvz0hmhnvvnsl.jvtxlt1-kl2lsuvunu1.vyn@flex--smostafa.bounces.google.com>) id 1rtpgV-0001NS-2p for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:37 -0400 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-dc693399655so7945956276.1 for ; Mon, 08 Apr 2024 07:09:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712585354; x=1713190154; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=92pKf8rxBG8PwjQhN5a+4mjr0DOeod7sAVNPkhgcMv4=; b=cYU+kd8whg2IdtQwK03j8BoGASZQ7gbTauXyEpqIqXpc1S+Al4gu3WIvqxVml3tk88 VksPTjd/tw0ANxQy5daHBeC/B2PDGv2laG8Hvcw3bTKIUYRF21YN+rqv/u45Cv6uomlT 4rpL5ySn3I24y+atMvOR4gFSTC4jQJgsfsQU2LhZqMwkqxrSYrcCq+CFIxfWR1OGTPUC ruZH193ZWd0SWAIZYVZ4uSWNo4Dv83P+nX6ZjkL7Kv/yCsdZTxnCYZeXzHgG/+kNVOWW Eve45e+1zL9DE2bRJTQPxl+QiCgVLXw3YCL8d+iaEq2TSS1gRnYvoQRz5Ao53BzWEQld o0hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712585354; x=1713190154; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=92pKf8rxBG8PwjQhN5a+4mjr0DOeod7sAVNPkhgcMv4=; b=XGRUTh0M8yYAf3Vk3EJX8WvJuf0EEN8WFJQaVSU0fnC50sXLJj7TJbS1fBBg9hfbIf 1RdrFe+fL5+LaRqMSxIw+VqwA4NUegDogSqJ+8WoKWLyiXMwLsNES8Qx7yEusCN2myH1 3YKY1szlPof0CjTP3bQJJEj7XzgNv0m07xA++yeW+cBuJGCbzeSgu6RtgYhdjobfSoxD nk304cVFbvY3wl4vZz0BCglksHdRxFavXGmXd1X1JmHZpKep06UBEdusopabAx8tGSGi M6oBS2bA+IcU7om+V442xowChXEhazOoKUzsWkC4Cp4f6bGWfRaRNS1Bu0GbVr2QBsH7 huYg== X-Forwarded-Encrypted: i=1; AJvYcCW/H51/Dx9gD5jHb332/wLjr6Wvn2SF/pzGglDl4KqO136RrGVJvKoEWEBmvufL43sLLRYfcFBDbrynxGUySVLpK2Qt9kM= X-Gm-Message-State: AOJu0YxSdomKD2LQXK65VouY+uEjMgSp/Jci2Tn13Mno2V1pFQm3qli4 N1ff8ewwFhTbD2xlgbegjczoOl+s0m/kPEJsx5a6elpGcwcaCsMSUAZ4Q4/HgPKUUziqRzQl55S O6h/nDQnfCg== X-Google-Smtp-Source: AGHT+IEC3Ffqy2fMPOhBoZ+TpT0m8VPrxASVqJkvNBOpS6Svpvf7pl6OkMxqYlyy8N3wPeiGYvQMal65raJS1A== X-Received: from mostafa.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:333c]) (user=smostafa job=sendgmr) by 2002:a05:6902:100a:b0:de0:ecc6:139c with SMTP id w10-20020a056902100a00b00de0ecc6139cmr1506774ybt.11.1712585354338; Mon, 08 Apr 2024 07:09:14 -0700 (PDT) Date: Mon, 8 Apr 2024 14:08:11 +0000 In-Reply-To: <20240408140818.3799590-1-smostafa@google.com> Mime-Version: 1.0 References: <20240408140818.3799590-1-smostafa@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240408140818.3799590-7-smostafa@google.com> Subject: [RFC PATCH v2 06/13] hw/arm/smmu: Support nesting in smmuv3_range_inval() From: Mostafa Saleh To: qemu-arm@nongnu.org, eric.auger@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Cc: jean-philippe@linaro.org, alex.bennee@linaro.org, maz@kernel.org, nicolinc@nvidia.com, julien@xen.org, richard.henderson@linaro.org, marcin.juszkiewicz@linaro.org, Mostafa Saleh 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=2607:f8b0:4864:20::b49; envelope-from=3ivoTZggKCgcztvz0hmhnvvnsl.jvtxlt1-kl2lsuvunu1.vyn@flex--smostafa.bounces.google.com; helo=mail-yb1-xb49.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, T_SPF_HELO_TEMPERROR=0.01, T_SPF_TEMPERROR=0.01, USER_IN_DEF_DKIM_WL=-7.5 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1712585520939100004 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With nesting, we would need to invalidate IPAs without over-invalidating stage-1 IOVAs. This can be done by distinguishing IPAs in the TLBs by having ASID=3D-1. To achieve that, rework the invalidation for IPAs to have a separate function, while for IOVA invalidation ASID=3D-1 means invalidate for all ASIDs. Signed-off-by: Mostafa Saleh Reviewed-by: Eric Auger --- hw/arm/smmu-common.c | 47 ++++++++++++++++++++++++++++++++++++ hw/arm/smmuv3.c | 23 ++++++++++++------ hw/arm/trace-events | 2 +- include/hw/arm/smmu-common.h | 3 ++- 4 files changed, 66 insertions(+), 9 deletions(-) diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index 2cf27b490b..8b9e59b24b 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -184,6 +184,25 @@ static gboolean smmu_hash_remove_by_asid_vmid_iova(gpo= inter key, gpointer value, ((entry->iova & ~info->mask) =3D=3D info->iova); } =20 +static gboolean smmu_hash_remove_by_vmid_ipa(gpointer key, gpointer value, + gpointer user_data) +{ + SMMUTLBEntry *iter =3D (SMMUTLBEntry *)value; + IOMMUTLBEntry *entry =3D &iter->entry; + SMMUIOTLBPageInvInfo *info =3D (SMMUIOTLBPageInvInfo *)user_data; + SMMUIOTLBKey iotlb_key =3D *(SMMUIOTLBKey *)key; + + /* This is a stage-1 address. */ + if (info->asid >=3D 0) { + return false; + } + if (info->vmid !=3D SMMU_IOTLB_VMID(iotlb_key)) { + return false; + } + return ((info->iova & ~entry->addr_mask) =3D=3D entry->iova) || + ((entry->iova & ~info->mask) =3D=3D info->iova); +} + void smmu_iotlb_inv_iova(SMMUState *s, int asid, int vmid, dma_addr_t iova, uint8_t tg, uint64_t num_pages, uint8_t ttl) { @@ -212,6 +231,34 @@ void smmu_iotlb_inv_iova(SMMUState *s, int asid, int v= mid, dma_addr_t iova, &info); } =20 +/* + * Similar to smmu_iotlb_inv_iova(), but for Stage-2, ASID is always -1, + * in Stage-1 invalidation ASID =3D -1, means don't care. + */ +void smmu_iotlb_inv_ipa(SMMUState *s, int vmid, dma_addr_t ipa, uint8_t tg, + uint64_t num_pages, uint8_t ttl) +{ + uint8_t granule =3D tg ? tg * 2 + 10 : 12; + int asid =3D -1; + + if (ttl && (num_pages =3D=3D 1)) { + SMMUIOTLBKey key =3D smmu_get_iotlb_key(asid, vmid, ipa, tg, ttl); + + if (g_hash_table_remove(s->iotlb, &key)) { + return; + } + } + + SMMUIOTLBPageInvInfo info =3D { + .iova =3D ipa, + .vmid =3D vmid, + .mask =3D (num_pages * 1 << granule) - 1}; + + g_hash_table_foreach_remove(s->iotlb, + smmu_hash_remove_by_vmid_ipa, + &info); +} + void smmu_iotlb_inv_asid(SMMUState *s, int asid) { trace_smmu_iotlb_inv_asid(asid); diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index a7cf543acc..17bbd43c13 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1095,7 +1095,7 @@ static void smmuv3_inv_notifiers_iova(SMMUState *s, i= nt asid, int vmid, } } =20 -static void smmuv3_range_inval(SMMUState *s, Cmd *cmd) +static void smmuv3_range_inval(SMMUState *s, Cmd *cmd, SMMUStage stage) { dma_addr_t end, addr =3D CMD_ADDR(cmd); uint8_t type =3D CMD_TYPE(cmd); @@ -1120,9 +1120,13 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cm= d) } =20 if (!tg) { - trace_smmuv3_range_inval(vmid, asid, addr, tg, 1, ttl, leaf); + trace_smmuv3_range_inval(vmid, asid, addr, tg, 1, ttl, leaf, stage= ); smmuv3_inv_notifiers_iova(s, asid, vmid, addr, tg, 1); - smmu_iotlb_inv_iova(s, asid, vmid, addr, tg, 1, ttl); + if (stage =3D=3D SMMU_STAGE_1) { + smmu_iotlb_inv_iova(s, asid, vmid, addr, tg, 1, ttl); + } else { + smmu_iotlb_inv_ipa(s, vmid, addr, tg, 1, ttl); + } return; } =20 @@ -1138,9 +1142,14 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cm= d) uint64_t mask =3D dma_aligned_pow2_mask(addr, end, 64); =20 num_pages =3D (mask + 1) >> granule; - trace_smmuv3_range_inval(vmid, asid, addr, tg, num_pages, ttl, lea= f); + trace_smmuv3_range_inval(vmid, asid, addr, tg, num_pages, + ttl, leaf, stage); smmuv3_inv_notifiers_iova(s, asid, vmid, addr, tg, num_pages); - smmu_iotlb_inv_iova(s, asid, vmid, addr, tg, num_pages, ttl); + if (stage =3D=3D SMMU_STAGE_1) { + smmu_iotlb_inv_iova(s, asid, vmid, addr, tg, num_pages, ttl); + } else { + smmu_iotlb_inv_ipa(s, vmid, addr, tg, num_pages, ttl); + } addr +=3D mask + 1; } } @@ -1299,7 +1308,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s) cmd_error =3D SMMU_CERROR_ILL; break; } - smmuv3_range_inval(bs, &cmd); + smmuv3_range_inval(bs, &cmd, SMMU_STAGE_1); break; case SMMU_CMD_TLBI_S12_VMALL: { @@ -1324,7 +1333,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s) * As currently only either s1 or s2 are supported * we can reuse same function for s2. */ - smmuv3_range_inval(bs, &cmd); + smmuv3_range_inval(bs, &cmd, SMMU_STAGE_2); break; case SMMU_CMD_TLBI_EL3_ALL: case SMMU_CMD_TLBI_EL3_VA: diff --git a/hw/arm/trace-events b/hw/arm/trace-events index 5f23f0b963..f5c361d96e 100644 --- a/hw/arm/trace-events +++ b/hw/arm/trace-events @@ -46,7 +46,7 @@ smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=3D0= x%x - end=3D0x%x" smmuv3_cmdq_cfgi_cd(uint32_t sid) "sid=3D0x%x" smmuv3_config_cache_hit(uint32_t sid, uint32_t hits, uint32_t misses, uint= 32_t perc) "Config cache HIT for sid=3D0x%x (hits=3D%d, misses=3D%d, hit ra= te=3D%d)" smmuv3_config_cache_miss(uint32_t sid, uint32_t hits, uint32_t misses, uin= t32_t perc) "Config cache MISS for sid=3D0x%x (hits=3D%d, misses=3D%d, hit = rate=3D%d)" -smmuv3_range_inval(int vmid, int asid, uint64_t addr, uint8_t tg, uint64_t= num_pages, uint8_t ttl, bool leaf) "vmid=3D%d asid=3D%d addr=3D0x%"PRIx64"= tg=3D%d num_pages=3D0x%"PRIx64" ttl=3D%d leaf=3D%d" +smmuv3_range_inval(int vmid, int asid, uint64_t addr, uint8_t tg, uint64_t= num_pages, uint8_t ttl, bool leaf, int stage) "vmid=3D%d asid=3D%d addr=3D= 0x%"PRIx64" tg=3D%d num_pages=3D0x%"PRIx64" ttl=3D%d leaf=3D%d stage=3D%d" smmuv3_cmdq_tlbi_nh(void) "" smmuv3_cmdq_tlbi_nh_asid(uint16_t asid) "asid=3D%d" smmuv3_cmdq_tlbi_s12_vmid(uint16_t vmid) "vmid=3D%d" diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h index 03ff0f02ba..df166d8477 100644 --- a/include/hw/arm/smmu-common.h +++ b/include/hw/arm/smmu-common.h @@ -230,7 +230,8 @@ void smmu_iotlb_inv_asid(SMMUState *s, int asid); void smmu_iotlb_inv_vmid(SMMUState *s, int vmid); void smmu_iotlb_inv_iova(SMMUState *s, int asid, int vmid, dma_addr_t iova, uint8_t tg, uint64_t num_pages, uint8_t ttl); - +void smmu_iotlb_inv_ipa(SMMUState *s, int vmid, dma_addr_t ipa, uint8_t tg, + uint64_t num_pages, uint8_t ttl); /* Unmap the range of all the notifiers registered to any IOMMU mr */ void smmu_inv_notifiers_all(SMMUState *s); =20 --=20 2.44.0.478.gd926399ef9-goog From nobody Fri May 17 07:47:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1712585466; cv=none; d=zohomail.com; s=zohoarc; b=cyAYgkxwVlGnYTnRqkl9U+oDskR0sP7/GsEiXRDxGBu37VgGKuPSivKvKY/JBf35EfDMllhHGvv8Rf5d3mZSJ/Fh7oV88tHPn8sMtbZaFTsJ1WvfZgFnvJ8kZJZESGmklF/OIH27EIFMKrlVITo8ZCeGJ7juAj5KiFdHmBDMazA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712585466; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Xk+qSFCz47aClMf3taMYzTP5iIVIqYBAuzPN7ynPM4g=; b=MTu0+rlTACW0jgk3qgdxigp3KVCs/fEpLlZfDUa9ZSRDtQwv1emIA7BDLp7leUZeWD3XMe8bpt/jrwdQspniYSoxzn0ulCDu62euTdkDKf5efwOA6LbednsUCNRd2VD/OjxkH2jEUfRlXMwL2nXooDV3PBpvbnahEcdnJa55Ln8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1712585466273160.2067212386828; Mon, 8 Apr 2024 07:11:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtphU-0007pi-G1; Mon, 08 Apr 2024 10:10:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3jPoTZggKCgk1vx12jojpxxpun.lxvznv3-mn4nuwxwpw3.x0p@flex--smostafa.bounces.google.com>) id 1rtpgo-00079b-6N for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:41 -0400 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3jPoTZggKCgk1vx12jojpxxpun.lxvznv3-mn4nuwxwpw3.x0p@flex--smostafa.bounces.google.com>) id 1rtpgU-0001Na-Iq for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:37 -0400 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-615073c8dfbso85623587b3.1 for ; Mon, 08 Apr 2024 07:09:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712585356; x=1713190156; darn=nongnu.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=Xk+qSFCz47aClMf3taMYzTP5iIVIqYBAuzPN7ynPM4g=; b=GVDzR/aDDVmwpMlFDRX7W+/Kl2eD0ioAkrLCF7sVg7jY6aiWEEf0p8sbjUo/YYcz/l WMjrGb5LK/CpYYKMccfswXh3vcJ4MtmxLuisLNWVklEcddPI9oE8HFCupPHK4TjFEmqh pAe/uaj2FRsoJoFGEAadiwNVglt3DdxFVUELQOa5Ih7eR7BT1wshEDhD3OQeOvUsCeYF VyamQeyQx2JOD6czhOsSpyaeKkmz+dVvEUgD5dAu5oLtExg2s/PTrKX+bvU/J9taJFCG E95v0bjVJy7Tw/Ew+CsuqfblCWhYfvizG69/Rk/M4UzlTbJ0SeVVYfnpDIH1NHn3UbC8 f5oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712585356; x=1713190156; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=Xk+qSFCz47aClMf3taMYzTP5iIVIqYBAuzPN7ynPM4g=; b=qpRBKq+oQ4/DOiv5E+Pah08HqurdkdaSDn3VQXeQF1GOHBerVnz5my0EjQBKBnFdKV il7XZtbXKZLcQH/WD/iAbWafSqsUsSNP807DmasOHAa6y+n6Q3zalfMBPDPpfKzzuYEs DpUe9PfFVMsqO1RNgSONfke4MimgtY0ONxlW/msC8n7i1LbTQDRayd4SrNuJGR8yAcYz 3zCY0HTsloLh+b2+iakB+3RlyfoiT8dWvJZGSvv7BrlTCGGmGQOO5poLe4QzSj8oF5ta 6ib9SyLmRLzJkF++hsjJeSYPoZClb+Xmp+WvKYDiO8gBeIcpBNxDAQkt6hYh5nhQfgZD 0peg== X-Forwarded-Encrypted: i=1; AJvYcCWLbCmFOU6E60ERp/iAz/msLOSiIIIBEYrzpMdvdG/3wnMtCfSNu3Hqz16aio3iFWTGfou4JdlZboDaq8WJSYvw38krcAw= X-Gm-Message-State: AOJu0YzXjQPgXNDm7ls0QkdgCb4gQ5LGsOjETpgx9EmCK9x3SRget/as LPqvtUoW8GXVmCUC4i5ITeJFGEzICGUPf75ymSl17lVIOLZu+m+LaKepbHBsKZLFXCUmDz81iSb 52Syva2RYfw== X-Google-Smtp-Source: AGHT+IFgs/376+JhEmHL6mcyoYevX26rq5sUKMzXeA5BtSuWdSMq4mTVB+0Ay68vxPn1y3yrCcvR95XhqTimtw== X-Received: from mostafa.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:333c]) (user=smostafa job=sendgmr) by 2002:a0d:db43:0:b0:615:3262:ffa0 with SMTP id d64-20020a0ddb43000000b006153262ffa0mr2506568ywe.9.1712585356625; Mon, 08 Apr 2024 07:09:16 -0700 (PDT) Date: Mon, 8 Apr 2024 14:08:12 +0000 In-Reply-To: <20240408140818.3799590-1-smostafa@google.com> Mime-Version: 1.0 References: <20240408140818.3799590-1-smostafa@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240408140818.3799590-8-smostafa@google.com> Subject: [RFC PATCH v2 07/13] hw/arm/smmu: Support nesting in the rest of commands From: Mostafa Saleh To: qemu-arm@nongnu.org, eric.auger@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Cc: jean-philippe@linaro.org, alex.bennee@linaro.org, maz@kernel.org, nicolinc@nvidia.com, julien@xen.org, richard.henderson@linaro.org, marcin.juszkiewicz@linaro.org, Mostafa Saleh 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=2607:f8b0:4864:20::114a; envelope-from=3jPoTZggKCgk1vx12jojpxxpun.lxvznv3-mn4nuwxwpw3.x0p@flex--smostafa.bounces.google.com; helo=mail-yw1-x114a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, T_SPF_HELO_TEMPERROR=0.01, T_SPF_TEMPERROR=0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1712585466596100002 Content-Type: text/plain; charset="utf-8" Some commands need rework for nesting, as they used to assume S1 and S2 are mutually exclusive: - CMD_TLBI_NH_ASID: Consider VMID if stage-2 is supported - CMD_TLBI_NH_ALL: Consider VMID if stage-2 is supported, otherwise invalidate everything, this required a new vmid invalidation function for stage-1 only (ASID >=3D 0) Also, rework trace events to reflect the new implementation. Signed-off-by: Mostafa Saleh --- hw/arm/smmu-common.c | 36 +++++++++++++++++++++++++++++------- hw/arm/smmuv3.c | 31 +++++++++++++++++++++++++++++-- hw/arm/trace-events | 6 ++++-- include/hw/arm/smmu-common.h | 3 ++- 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index 8b9e59b24b..b1cf1303c6 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -148,13 +148,14 @@ void smmu_iotlb_inv_all(SMMUState *s) g_hash_table_remove_all(s->iotlb); } =20 -static gboolean smmu_hash_remove_by_asid(gpointer key, gpointer value, - gpointer user_data) +static gboolean smmu_hash_remove_by_asid_vmid(gpointer key, gpointer value, + gpointer user_data) { - int asid =3D *(int *)user_data; + SMMUIOTLBPageInvInfo *info =3D (SMMUIOTLBPageInvInfo *)user_data; SMMUIOTLBKey *iotlb_key =3D (SMMUIOTLBKey *)key; =20 - return SMMU_IOTLB_ASID(*iotlb_key) =3D=3D asid; + return (SMMU_IOTLB_ASID(*iotlb_key) =3D=3D info->asid) && + (SMMU_IOTLB_VMID(*iotlb_key) =3D=3D info->vmid); } =20 static gboolean smmu_hash_remove_by_vmid(gpointer key, gpointer value, @@ -166,6 +167,16 @@ static gboolean smmu_hash_remove_by_vmid(gpointer key,= gpointer value, return SMMU_IOTLB_VMID(*iotlb_key) =3D=3D vmid; } =20 +static gboolean smmu_hash_remove_by_vmid_s1(gpointer key, gpointer value, + gpointer user_data) +{ + int vmid =3D *(int *)user_data; + SMMUIOTLBKey *iotlb_key =3D (SMMUIOTLBKey *)key; + + return (SMMU_IOTLB_VMID(*iotlb_key) =3D=3D vmid) && + (SMMU_IOTLB_ASID(*iotlb_key) >=3D 0); +} + static gboolean smmu_hash_remove_by_asid_vmid_iova(gpointer key, gpointer = value, gpointer user_data) { @@ -259,10 +270,15 @@ void smmu_iotlb_inv_ipa(SMMUState *s, int vmid, dma_a= ddr_t ipa, uint8_t tg, &info); } =20 -void smmu_iotlb_inv_asid(SMMUState *s, int asid) +void smmu_iotlb_inv_asid_vmid(SMMUState *s, int asid, int vmid) { - trace_smmu_iotlb_inv_asid(asid); - g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_asid, &asid); + SMMUIOTLBPageInvInfo info =3D { + .asid =3D asid, + .vmid =3D vmid, + }; + + trace_smmu_iotlb_inv_asid_vmid(asid, vmid); + g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_asid_vmid, &= info); } =20 inline void smmu_iotlb_inv_vmid(SMMUState *s, int vmid) @@ -271,6 +287,12 @@ inline void smmu_iotlb_inv_vmid(SMMUState *s, int vmid) g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_vmid, &vmid); } =20 +inline void smmu_iotlb_inv_vmid_s1(SMMUState *s, int vmid) +{ + trace_smmu_iotlb_inv_vmid_s1(vmid); + g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_vmid_s1, &vm= id); +} + /* VMSAv8-64 Translation */ =20 /** diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 17bbd43c13..ece647b8bf 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1280,25 +1280,52 @@ static int smmuv3_cmdq_consume(SMMUv3State *s) case SMMU_CMD_TLBI_NH_ASID: { int asid =3D CMD_ASID(&cmd); + int vmid =3D -1; =20 if (!STAGE1_SUPPORTED(s)) { cmd_error =3D SMMU_CERROR_ILL; break; } =20 + /* + * VMID is only matched when stage 2 is supported for the Secu= rity + * state corresponding to the command queue that the command w= as + * issued in. + * QEMU ignores the field by setting to -1, similarly to what = STE + * decoding does. And invalidation commands ignore VMID < 0. + */ + if (STAGE2_SUPPORTED(s)) { + vmid =3D CMD_VMID(&cmd); + } + trace_smmuv3_cmdq_tlbi_nh_asid(asid); smmu_inv_notifiers_all(&s->smmu_state); - smmu_iotlb_inv_asid(bs, asid); + smmu_iotlb_inv_asid_vmid(bs, asid, vmid); break; } case SMMU_CMD_TLBI_NH_ALL: + { + int vmid =3D -1; + if (!STAGE1_SUPPORTED(s)) { cmd_error =3D SMMU_CERROR_ILL; break; } + + /* + * If stage-2 is supported, invalidate for this VMID only, oth= erwise + * invalidate the whole thing, see SMMU_CMD_TLBI_NH_ASID() + */ + if (STAGE2_SUPPORTED(s)) { + vmid =3D CMD_VMID(&cmd); + trace_smmuv3_cmdq_tlbi_nh(vmid); + smmu_iotlb_inv_vmid_s1(bs, vmid); + break; + } QEMU_FALLTHROUGH; + } case SMMU_CMD_TLBI_NSNH_ALL: - trace_smmuv3_cmdq_tlbi_nh(); + trace_smmuv3_cmdq_tlbi_nsnh(); smmu_inv_notifiers_all(&s->smmu_state); smmu_iotlb_inv_all(bs); break; diff --git a/hw/arm/trace-events b/hw/arm/trace-events index f5c361d96e..2556f4721a 100644 --- a/hw/arm/trace-events +++ b/hw/arm/trace-events @@ -11,8 +11,9 @@ smmu_ptw_page_pte(int stage, int level, uint64_t iova, u= int64_t baseaddr, uint6 smmu_ptw_block_pte(int stage, int level, uint64_t baseaddr, uint64_t ptead= dr, uint64_t pte, uint64_t iova, uint64_t gpa, int bsize_mb) "stage=3D%d le= vel=3D%d base@=3D0x%"PRIx64" pte@=3D0x%"PRIx64" pte=3D0x%"PRIx64" iova=3D0x= %"PRIx64" block address =3D 0x%"PRIx64" block size =3D %d MiB" smmu_get_pte(uint64_t baseaddr, int index, uint64_t pteaddr, uint64_t pte)= "baseaddr=3D0x%"PRIx64" index=3D0x%x, pteaddr=3D0x%"PRIx64", pte=3D0x%"PRI= x64 smmu_iotlb_inv_all(void) "IOTLB invalidate all" -smmu_iotlb_inv_asid(uint16_t asid) "IOTLB invalidate asid=3D%d" +smmu_iotlb_inv_asid_vmid(int asid, uint16_t vmid) "IOTLB invalidate asid= =3D%d vmid=3D%d" smmu_iotlb_inv_vmid(uint16_t vmid) "IOTLB invalidate vmid=3D%d" +smmu_iotlb_inv_vmid_s1(uint16_t vmid) "IOTLB invalidate vmid=3D%d" smmu_iotlb_inv_iova(uint16_t asid, uint64_t addr) "IOTLB invalidate asid= =3D%d addr=3D0x%"PRIx64 smmu_inv_notifiers_mr(const char *name) "iommu mr=3D%s" smmu_iotlb_lookup_hit(int asid, uint16_t vmid, uint64_t addr, uint64_t mas= k, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache HIT asid=3D%d vmid= =3D%d addr=3D0x%"PRIx64" mask=3D0x%"PRIx64" hit=3D%d miss=3D%d hit rate=3D%= d" @@ -47,7 +48,8 @@ smmuv3_cmdq_cfgi_cd(uint32_t sid) "sid=3D0x%x" smmuv3_config_cache_hit(uint32_t sid, uint32_t hits, uint32_t misses, uint= 32_t perc) "Config cache HIT for sid=3D0x%x (hits=3D%d, misses=3D%d, hit ra= te=3D%d)" smmuv3_config_cache_miss(uint32_t sid, uint32_t hits, uint32_t misses, uin= t32_t perc) "Config cache MISS for sid=3D0x%x (hits=3D%d, misses=3D%d, hit = rate=3D%d)" smmuv3_range_inval(int vmid, int asid, uint64_t addr, uint8_t tg, uint64_t= num_pages, uint8_t ttl, bool leaf, int stage) "vmid=3D%d asid=3D%d addr=3D= 0x%"PRIx64" tg=3D%d num_pages=3D0x%"PRIx64" ttl=3D%d leaf=3D%d stage=3D%d" -smmuv3_cmdq_tlbi_nh(void) "" +smmuv3_cmdq_tlbi_nh(int vmid) "vmid=3D%d" +smmuv3_cmdq_tlbi_nsnh(void) "" smmuv3_cmdq_tlbi_nh_asid(uint16_t asid) "asid=3D%d" smmuv3_cmdq_tlbi_s12_vmid(uint16_t vmid) "vmid=3D%d" smmuv3_config_cache_inv(uint32_t sid) "Config cache INV for sid=3D0x%x" diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h index df166d8477..67db30e85b 100644 --- a/include/hw/arm/smmu-common.h +++ b/include/hw/arm/smmu-common.h @@ -226,8 +226,9 @@ void smmu_iotlb_insert(SMMUState *bs, SMMUTransCfg *cfg= , SMMUTLBEntry *entry); SMMUIOTLBKey smmu_get_iotlb_key(int asid, int vmid, uint64_t iova, uint8_t tg, uint8_t level); void smmu_iotlb_inv_all(SMMUState *s); -void smmu_iotlb_inv_asid(SMMUState *s, int asid); +void smmu_iotlb_inv_asid_vmid(SMMUState *s, int asid, int vmid); void smmu_iotlb_inv_vmid(SMMUState *s, int vmid); +void smmu_iotlb_inv_vmid_s1(SMMUState *s, int vmid); void smmu_iotlb_inv_iova(SMMUState *s, int asid, int vmid, dma_addr_t iova, uint8_t tg, uint64_t num_pages, uint8_t ttl); void smmu_iotlb_inv_ipa(SMMUState *s, int vmid, dma_addr_t ipa, uint8_t tg, --=20 2.44.0.478.gd926399ef9-goog From nobody Fri May 17 07:47:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1712585498; cv=none; d=zohomail.com; s=zohoarc; b=mScO748s9IdbnIVSJGdtThNL8uvCHZ8xFDFqY+WPvXTl1AGhV9I8+4s+OytooYsejUPUuKDs6iBklRHm9BtrrtlQ9O7AEXDPJ+eeg1wDcuXHQNunpJb8negroHndwZ6AJg0PGJJDEIwLCyzvjz5U0LkaiMILdrqH92ECKuH/UVI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712585498; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3HqNDgdJVJw0NA38Rt0khH0xSYdgx1axY3awgliAoN0=; b=PeENcuzdpXo+LQTGxqz1F+vYJfjjwFWM9n4p2ugaxbotldCY9w+i3ojIl1jVGgIfchx6DY4ro2f95VLfM6STz3MHymFDnkAZzDFlZc6DJvJ9vXJ1r8HxxU0mSwyZhWphcks+gv1yIRRQvqgQjDu52nH4A6n48U+mNeE3MUTX3sY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 171258549810467.55610866721668; Mon, 8 Apr 2024 07:11:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtphT-0007kG-Sn; Mon, 08 Apr 2024 10:10:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3jvoTZggKCgs3xz34lqlrzzrwp.nzx1px5-op6pwyzyry5.z2r@flex--smostafa.bounces.google.com>) id 1rtpgi-00076Z-Jl for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:34 -0400 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3jvoTZggKCgs3xz34lqlrzzrwp.nzx1px5-op6pwyzyry5.z2r@flex--smostafa.bounces.google.com>) id 1rtpgZ-0001Np-GV for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:32 -0400 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-dcc05887ee9so5911051276.1 for ; Mon, 08 Apr 2024 07:09:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712585359; x=1713190159; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=3HqNDgdJVJw0NA38Rt0khH0xSYdgx1axY3awgliAoN0=; b=fccCI3fg+ThSBJdvD+HfqPugfWoAFwuqW3atJSyRrTvUAptBjfMmBQg1IQIuMFdB/5 1EjP6ZLQR8OaWPdMHNRbVQKu2iDeGVsZOa5ZX4biX/LnIPGIvfG1BUTTVq1zQKtQi5V6 2WXuDWSkaKkyVU4NF3ovLll6HQXWHN2AaVHnxJuN2tKVBMK1XEZkiyTtBFriCxnK8CRr A/XPTDTa5or3JkYXPNZDR4I56S2SXLnXA95lXUc0gIwZGCdXWCxWk7jUPg/hLPj41gov bm8j34UiAUY3SeL2XpBPN+wHoRRQBmlnctwUk+vNRx32ENVVmE2Sxioe17x70gzkr6sG /MMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712585359; x=1713190159; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3HqNDgdJVJw0NA38Rt0khH0xSYdgx1axY3awgliAoN0=; b=XnfU6ACZWMw64uS84KW5RzGOsRY0HfqGFkNAPEDAR4HG6vUXK3Dlr/DctyAPp3OdRs Ac7FcwxrK1QQXS/sQ1OpAajo7bZlzx8+8JwUzOdj0BLt21y/kXd2g7lfjeKqE8k1XvLX PRjHz3eMJ0vL3U8WXmY3Ddu7rloJOrlnf+VyyrOtTgVvbjx4/p5ZWZyIf60VIYUcGzPX gRXEq73/W+/5rW48WgrkvaEU++b0kP7LBRpp0u5N+vg3Y/36wylW8l6bXtOi5/w8+c5+ ORhovPRuwNIlXPcXeSwhgJXBBLsXZ3R9Ku1Zxuv98rLqMXA7x5QDVUvEy7FjdGmiulZA HeKw== X-Forwarded-Encrypted: i=1; AJvYcCV80q1iiRY1HpQlIuauCwwgl0YFuVHjLoPicku7djBKzOwsH8ZkOTETV6/ZqaQC93hJSkdNr0JM/rCbpt4flz7TrnhEDYM= X-Gm-Message-State: AOJu0Yw1R2N/5shOhT/++LNIvP117OEfsjox+oDJ94Lb05jEDubSKY+T +y5jLvwaWXdEIT3E+swROoW5O53ai7HSmJZ+oQw5fqYx7WZllkfSf7sItilNGMO2NKCaGuKfonx LaqqLQ09vCw== X-Google-Smtp-Source: AGHT+IEWg5K7fM2dcPCvRd9RMsFcEdOBM1qMISm61aHu3BqQA/Rfue4/66wDQOMCL5NYhR7j9lozroVomxR0yg== X-Received: from mostafa.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:333c]) (user=smostafa job=sendgmr) by 2002:a05:6902:727:b0:dcc:8927:7496 with SMTP id l7-20020a056902072700b00dcc89277496mr672950ybt.5.1712585358833; Mon, 08 Apr 2024 07:09:18 -0700 (PDT) Date: Mon, 8 Apr 2024 14:08:13 +0000 In-Reply-To: <20240408140818.3799590-1-smostafa@google.com> Mime-Version: 1.0 References: <20240408140818.3799590-1-smostafa@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240408140818.3799590-9-smostafa@google.com> Subject: [RFC PATCH v2 08/13] hw/arm/smmuv3: Support nested SMMUs in smmuv3_notify_iova() From: Mostafa Saleh To: qemu-arm@nongnu.org, eric.auger@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Cc: jean-philippe@linaro.org, alex.bennee@linaro.org, maz@kernel.org, nicolinc@nvidia.com, julien@xen.org, richard.henderson@linaro.org, marcin.juszkiewicz@linaro.org, Mostafa Saleh 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=2607:f8b0:4864:20::b49; envelope-from=3jvoTZggKCgs3xz34lqlrzzrwp.nzx1px5-op6pwyzyry5.z2r@flex--smostafa.bounces.google.com; helo=mail-yb1-xb49.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1712585498740100006 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" IOMMUTLBEvent only understands IOVA, for stage-2 only SMMUs keep the implementation, while only notify for stage-1 invalidation in case of nesting. Signed-off-by: Mostafa Saleh --- hw/arm/smmuv3.c | 23 +++++++++++++++-------- hw/arm/trace-events | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index ece647b8bf..85b3ac6a9c 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1028,7 +1028,7 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *mr, IOMMUNotifier *n, int asid, int vmid, dma_addr_t iova, uint8_t tg, - uint64_t num_pages) + uint64_t num_pages, int stage) { SMMUDevice *sdev =3D container_of(mr, SMMUDevice, iommu); IOMMUTLBEvent event; @@ -1052,14 +1052,21 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *m= r, return; } =20 - if (STAGE1_SUPPORTED(s)) { + /* + * IOMMUTLBEvent only understands IOVA, for stage-2 only SMMUs + * keep the implementation, while only notify for stage-1 + * invalidation in case of nesting. + */ + if (stage =3D=3D SMMU_STAGE_1) { tt =3D select_tt(cfg, iova); if (!tt) { return; } granule =3D tt->granule_sz; - } else { + } else if (!STAGE1_SUPPORTED(s)) { granule =3D cfg->s2cfg.granule_sz; + } else { + return; } =20 } else { @@ -1078,7 +1085,7 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *mr, /* invalidate an asid/vmid/iova range tuple in all mr's */ static void smmuv3_inv_notifiers_iova(SMMUState *s, int asid, int vmid, dma_addr_t iova, uint8_t tg, - uint64_t num_pages) + uint64_t num_pages, int stage) { SMMUDevice *sdev; =20 @@ -1087,10 +1094,10 @@ static void smmuv3_inv_notifiers_iova(SMMUState *s,= int asid, int vmid, IOMMUNotifier *n; =20 trace_smmuv3_inv_notifiers_iova(mr->parent_obj.name, asid, vmid, - iova, tg, num_pages); + iova, tg, num_pages, stage); =20 IOMMU_NOTIFIER_FOREACH(n, mr) { - smmuv3_notify_iova(mr, n, asid, vmid, iova, tg, num_pages); + smmuv3_notify_iova(mr, n, asid, vmid, iova, tg, num_pages, sta= ge); } } } @@ -1121,7 +1128,7 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cmd= , SMMUStage stage) =20 if (!tg) { trace_smmuv3_range_inval(vmid, asid, addr, tg, 1, ttl, leaf, stage= ); - smmuv3_inv_notifiers_iova(s, asid, vmid, addr, tg, 1); + smmuv3_inv_notifiers_iova(s, asid, vmid, addr, tg, 1, stage); if (stage =3D=3D SMMU_STAGE_1) { smmu_iotlb_inv_iova(s, asid, vmid, addr, tg, 1, ttl); } else { @@ -1144,7 +1151,7 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cmd= , SMMUStage stage) num_pages =3D (mask + 1) >> granule; trace_smmuv3_range_inval(vmid, asid, addr, tg, num_pages, ttl, leaf, stage); - smmuv3_inv_notifiers_iova(s, asid, vmid, addr, tg, num_pages); + smmuv3_inv_notifiers_iova(s, asid, vmid, addr, tg, num_pages, stag= e); if (stage =3D=3D SMMU_STAGE_1) { smmu_iotlb_inv_iova(s, asid, vmid, addr, tg, num_pages, ttl); } else { diff --git a/hw/arm/trace-events b/hw/arm/trace-events index 2556f4721a..53b9d11feb 100644 --- a/hw/arm/trace-events +++ b/hw/arm/trace-events @@ -55,7 +55,7 @@ smmuv3_cmdq_tlbi_s12_vmid(uint16_t vmid) "vmid=3D%d" smmuv3_config_cache_inv(uint32_t sid) "Config cache INV for sid=3D0x%x" smmuv3_notify_flag_add(const char *iommu) "ADD SMMUNotifier node for iommu= mr=3D%s" smmuv3_notify_flag_del(const char *iommu) "DEL SMMUNotifier node for iommu= mr=3D%s" -smmuv3_inv_notifiers_iova(const char *name, uint16_t asid, uint16_t vmid, = uint64_t iova, uint8_t tg, uint64_t num_pages) "iommu mr=3D%s asid=3D%d vmi= d=3D%d iova=3D0x%"PRIx64" tg=3D%d num_pages=3D0x%"PRIx64 +smmuv3_inv_notifiers_iova(const char *name, uint16_t asid, uint16_t vmid, = uint64_t iova, uint8_t tg, uint64_t num_pages, int stage) "iommu mr=3D%s as= id=3D%d vmid=3D%d iova=3D0x%"PRIx64" tg=3D%d num_pages=3D0x%"PRIx64" stage= =3D%d" =20 # strongarm.c strongarm_uart_update_parameters(const char *label, int speed, char parity= , int data_bits, int stop_bits) "%s speed=3D%d parity=3D%c data=3D%d stop= =3D%d" --=20 2.44.0.478.gd926399ef9-goog From nobody Fri May 17 07:47:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1712585505; cv=none; d=zohomail.com; s=zohoarc; b=fCkwk87hQ/lPqYtJIdvUK1bPZ0fcsHqF8ZITKNEBo3H8Bc7ynugbvtulTAv6ItHMyQbPb8U9BUeQqEBhRnSSwbjMAzgkAlAZZ+uTHdBjmuxY/3e6aGRaCgxqWntJxXDjzFL+MqnF/0Kfh3vih0qYPVYMpDioOSq87ucE68WRyWo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712585505; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xWJgvkXsRDlv4QySfPpJRYbrk5xBNLshUoOdVCtmsHg=; b=fBO3MOH9K36PiIrUyq5mW/456QoNGVl63HRoexQAPUreITkCX+WiHmiIvZ8Txk9fG2wUFVdYsGjXIztl755oNOqaQ3j2IqRHd4aOVoqJC3mlIhmnzkEHkcZEvhVU1mCICK4rDp9EgdcNmN5MDecA7AvVpfG5udT8wnaqjrkTdlI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1712585505481664.9360322939622; Mon, 8 Apr 2024 07:11:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtphW-00086t-MG; Mon, 08 Apr 2024 10:10:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3kfoTZggKCg460267otou22uzs.q204s08-rs9sz121u18.25u@flex--smostafa.bounces.google.com>) id 1rtpgp-00079l-9v for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:44 -0400 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3kfoTZggKCg460267otou22uzs.q204s08-rs9sz121u18.25u@flex--smostafa.bounces.google.com>) id 1rtpgc-0001OA-J7 for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:39 -0400 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-dc693399655so7946152276.1 for ; Mon, 08 Apr 2024 07:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712585361; x=1713190161; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xWJgvkXsRDlv4QySfPpJRYbrk5xBNLshUoOdVCtmsHg=; b=VpeCTdPg6r7dy338iWNqg71qNKMC/OrQWATf6b0CGONAfoMFm3aoUp03KEb2S19Rr/ bCnvdLJA7e/WSnqzsapFzBoTxGaxDOs3lqzo4uuYoCYghUTir1D3QnDUayp8frWoMGZe T/cj7rgqxbVYs7ktSTK5xMIrrhiGldO++7yk5Knmj1tMBkRHPC+as9wRT3GIBLfHm5Ki iTAtxZA6NeKmyw1yWou/OY7wxjH1qQdMMElG1iAfqa0dCn3hYiPpk+qyv6AzvnQH9w8l nWcGxD1izi4iDmYsYuuhhGtW8bg57mCsNQIP392v/Hm+niUJkynJqkC4nMJ2eF6YFI/F ytOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712585361; x=1713190161; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xWJgvkXsRDlv4QySfPpJRYbrk5xBNLshUoOdVCtmsHg=; b=L7DEkUc9KNshU+HA7WitrONHZOz1N1UBbOwwNVgG94MnjOux/FWGnwZulPWPfgpDyv 2zjm4osp7Lkifrk6rh4jxMCxKD1Y1mU3YxnzYdcUPvjaDxHLFSIQn9xNxtqWJrNjANwe ayX/gR0WRa1o/ezsOwlpcXZlou52CBpRl5i7IAQod8gmEkuJ76EwC2Tp3gTaDQ/YDXYs BRIIgnUefqyvh1WW63VwB75fSLsh8n1U2Grr4U2fINx4GJAkZFneeyiSAuohQ5LPXxGQ 9jyySAat+MfLgYoz4/EF0qs+oqMdZz8oSgHYbRL5VmioHiDw7l8XXoS72nBiKHBySggC u9KA== X-Forwarded-Encrypted: i=1; AJvYcCWHVUi8+S56SNrQqbe2A/KzxnOp4SMrw3d3AaA8GiDMudZ5aP3l2epcBpxPm1pI1C3aGymGaKX16pz5OWqVE2JJ9Cx6AxI= X-Gm-Message-State: AOJu0YzKr34IxoEn4O/tdtto0wG6qO73yYCfmiibnX2AGJIsPT5pKd15 kcl+EZj8/g6fcqLTGi1xB4d1iuna7zvlRc/xt0AC3DeSjhhKhs3wLAWPGqxgCG1TFB3IXY8klEs qO2UjnJtlqQ== X-Google-Smtp-Source: AGHT+IHQMA3cRcyxEy3dt9h6LYbjHh++lB0rxNHdAwlgj4xEmjt5EGwd6WJA1nFNuPifBMWod0kAcIu9MKBiHA== X-Received: from mostafa.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:333c]) (user=smostafa job=sendgmr) by 2002:a05:6902:726:b0:dcd:3172:7265 with SMTP id l6-20020a056902072600b00dcd31727265mr2744024ybt.8.1712585361014; Mon, 08 Apr 2024 07:09:21 -0700 (PDT) Date: Mon, 8 Apr 2024 14:08:14 +0000 In-Reply-To: <20240408140818.3799590-1-smostafa@google.com> Mime-Version: 1.0 References: <20240408140818.3799590-1-smostafa@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240408140818.3799590-10-smostafa@google.com> Subject: [RFC PATCH v2 09/13] hw/arm/smmuv3: Support and advertise nesting From: Mostafa Saleh To: qemu-arm@nongnu.org, eric.auger@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Cc: jean-philippe@linaro.org, alex.bennee@linaro.org, maz@kernel.org, nicolinc@nvidia.com, julien@xen.org, richard.henderson@linaro.org, marcin.juszkiewicz@linaro.org, Mostafa Saleh 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=2607:f8b0:4864:20::b4a; envelope-from=3kfoTZggKCg460267otou22uzs.q204s08-rs9sz121u18.25u@flex--smostafa.bounces.google.com; helo=mail-yb1-xb4a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1712585506754100002 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Everything is in place, add the last missing bits: - Handle fault checking according to the actual PTW event and not the the translation stage. - Consolidate parsing of STE cfg and setting translation stage. Advertise nesting if stage requested is "nested". Signed-off-by: Mostafa Saleh --- hw/arm/smmuv3.c | 50 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 85b3ac6a9c..da47411410 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -34,9 +34,10 @@ #include "smmuv3-internal.h" #include "smmu-internal.h" =20 -#define PTW_RECORD_FAULT(cfg) (((cfg)->stage =3D=3D SMMU_STAGE_1) ? \ - (cfg)->record_faults : \ - (cfg)->s2cfg.record_faults) +#define PTW_RECORD_FAULT(ptw_info, cfg) (((ptw_info).stage =3D=3D SMMU_STA= GE_1 && \ + (cfg)->record_faults) || \ + ((ptw_info).stage =3D=3D SMMU_STAG= E_2 && \ + (cfg)->s2cfg.record_faults)) =20 /** * smmuv3_trigger_irq - pulse @irq if enabled and update @@ -260,6 +261,9 @@ static void smmuv3_init_regs(SMMUv3State *s) /* Based on sys property, the stages supported in smmu will be adverti= sed.*/ if (s->stage && !strcmp("2", s->stage)) { s->idr[0] =3D FIELD_DP32(s->idr[0], IDR0, S2P, 1); + } else if (s->stage && !strcmp("nested", s->stage)) { + s->idr[0] =3D FIELD_DP32(s->idr[0], IDR0, S1P, 1); + s->idr[0] =3D FIELD_DP32(s->idr[0], IDR0, S2P, 1); } else { s->idr[0] =3D FIELD_DP32(s->idr[0], IDR0, S1P, 1); } @@ -425,8 +429,6 @@ static bool s2_pgtable_config_valid(uint8_t sl0, uint8_= t t0sz, uint8_t gran) =20 static int decode_ste_s2_cfg(SMMUTransCfg *cfg, STE *ste) { - cfg->stage =3D SMMU_STAGE_2; - if (STE_S2AA64(ste) =3D=3D 0x0) { qemu_log_mask(LOG_UNIMP, "SMMUv3 AArch32 tables not supported\n"); @@ -509,6 +511,27 @@ bad_ste: return -EINVAL; } =20 +static void decode_ste_config(SMMUTransCfg *cfg, uint32_t config) +{ + + if (STE_CFG_ABORT(config)) { + cfg->aborted =3D true; + return; + } + if (STE_CFG_BYPASS(config)) { + cfg->bypassed =3D true; + return; + } + + if (STE_CFG_S1_ENABLED(config)) { + cfg->stage =3D SMMU_STAGE_1; + } + + if (STE_CFG_S2_ENABLED(config)) { + cfg->stage |=3D SMMU_STAGE_2; + } +} + /* Returns < 0 in case of invalid STE, 0 otherwise */ static int decode_ste(SMMUv3State *s, SMMUTransCfg *cfg, STE *ste, SMMUEventInfo *event) @@ -525,13 +548,9 @@ static int decode_ste(SMMUv3State *s, SMMUTransCfg *cf= g, =20 config =3D STE_CONFIG(ste); =20 - if (STE_CFG_ABORT(config)) { - cfg->aborted =3D true; - return 0; - } + decode_ste_config(cfg, config); =20 - if (STE_CFG_BYPASS(config)) { - cfg->bypassed =3D true; + if (cfg->aborted || cfg->bypassed) { return 0; } =20 @@ -704,7 +723,6 @@ static int decode_cd(SMMUv3State *s, SMMUTransCfg *cfg, =20 /* we support only those at the moment */ cfg->aa64 =3D true; - cfg->stage =3D SMMU_STAGE_1; =20 cfg->oas =3D oas2bits(CD_IPS(cd)); cfg->oas =3D MIN(oas2bits(SMMU_IDR5_OAS), cfg->oas); @@ -887,28 +905,28 @@ static SMMUTranslationStatus smmuv3_do_translate(SMMU= v3State *s, hwaddr addr, event->u.f_walk_eabt.addr2 =3D ptw_info.addr; break; case SMMU_PTW_ERR_TRANSLATION: - if (PTW_RECORD_FAULT(cfg)) { + if (PTW_RECORD_FAULT(ptw_info, cfg)) { event->type =3D SMMU_EVT_F_TRANSLATION; event->u.f_translation.addr =3D addr; event->u.f_translation.rnw =3D flag & 0x1; } break; case SMMU_PTW_ERR_ADDR_SIZE: - if (PTW_RECORD_FAULT(cfg)) { + if (PTW_RECORD_FAULT(ptw_info, cfg)) { event->type =3D SMMU_EVT_F_ADDR_SIZE; event->u.f_addr_size.addr =3D addr; event->u.f_addr_size.rnw =3D flag & 0x1; } break; case SMMU_PTW_ERR_ACCESS: - if (PTW_RECORD_FAULT(cfg)) { + if (PTW_RECORD_FAULT(ptw_info, cfg)) { event->type =3D SMMU_EVT_F_ACCESS; event->u.f_access.addr =3D addr; event->u.f_access.rnw =3D flag & 0x1; } break; case SMMU_PTW_ERR_PERMISSION: - if (PTW_RECORD_FAULT(cfg)) { + if (PTW_RECORD_FAULT(ptw_info, cfg)) { event->type =3D SMMU_EVT_F_PERMISSION; event->u.f_permission.addr =3D addr; event->u.f_permission.rnw =3D flag & 0x1; --=20 2.44.0.478.gd926399ef9-goog From nobody Fri May 17 07:47:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1712585478; cv=none; d=zohomail.com; s=zohoarc; b=OwdWYjMhhhRupn393R2TJ2dq+PJtr81n7D97NEoysycfusd5klqdxY9EvYa0tZMBUBVTmjrJ9fYNv3B/Rpp/l+HmtmUCi4D3H/VpG/jGrnkV5t5PWt2+uGtw4rjnW8WWqJ7EqXvZGUgRKC8FCiYqmM1t39aRGX9DuhimkCUqOhM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712585478; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0jpBzRSOQx0YT4byKXmmxUIsTrpT0wYz9PuDCeBDXM4=; b=eThUSXmeXrsRtOq/ta6pR6QKttPwV2k7qjc+wQMaCj+szT0rZPziZ8xyET02QgZNMo9JIT9bt6EZjh5JXxIadS9BQaPwwn1bwJImT4esnnNw7rzHZPtM6PzdqPS3dBJoZHjGzKu4XQXj0vQeLpfiODb+dt5+0wjyErPIrgOGd00= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1712585478669382.46801242634433; Mon, 8 Apr 2024 07:11:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtpha-00008M-Bx; Mon, 08 Apr 2024 10:10:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3k_oTZggKChA82489qvqw44w1u.s426u2A-tuBu1343w3A.47w@flex--smostafa.bounces.google.com>) id 1rtpgy-0007GG-9S for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:54 -0400 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3k_oTZggKChA82489qvqw44w1u.s426u2A-tuBu1343w3A.47w@flex--smostafa.bounces.google.com>) id 1rtpgc-0001OS-Th for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:47 -0400 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-dcdc3db67f0so6654547276.1 for ; Mon, 08 Apr 2024 07:09:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712585363; x=1713190163; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=0jpBzRSOQx0YT4byKXmmxUIsTrpT0wYz9PuDCeBDXM4=; b=Ejg+srfB2Llh7Rd7UcbC4p9JCRpZpWYXILgqi5Z/erwXHGgmPVgHhxPF7bLkRkU2X9 khcE8kGSGvld/sV9rSKSCYrrC7OJv53Rbvsy8w3mIZQFWy1MJVH5ll75ecmFERbxBnZE G5m8B66h68uI4MT+3uKqSxZYunCux0aLXq5bp5RqSxmvDPzS40xZiXoc/YXqIEYuaVvw ynVG8Yfe89QovbSvnbYXSrLp97Wj0t4w4+rEaz+1UEhCJ3KOINx6LgzjA+/pSn2U2U/H wIOADU83UO9Rs9oJFrpM8UzgxeFeznZ4wWJj+5e/L7Hh3P6tX3yeSR+YUkqgfxAVj8UX Tnxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712585363; x=1713190163; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0jpBzRSOQx0YT4byKXmmxUIsTrpT0wYz9PuDCeBDXM4=; b=G2f0tTf2AwjI5r4T5U3iWAXk0SQGQsVtvsCPbBCZPoeFq0qNSv0wl+kZQoFRPNdWKX jjpB0t5Gsa/VmrE7lNzp9ACsbeAmbveboLffWGVeYoxy8rH4Z1DP3WZJOZJ4Q89M+e1a rN+nwmcSmHHo4N2VOARSb6Tfe1nNPdVYVs1JCfAUUkWOarxnIdzuQ6ToPuxc7IvRcBRt z8ZvTgN2eVBDh/tCG64D1Kusi9yNyp645SRgp7XyFhPgSoN9UMo2jqUtGkhgGH1NfOJ0 C/+gUZPxYZi9FJYdgyIUliGN57AzyOtcixmbkTniyYlcF+1Qoijr+4VolDIHuLK+ZO3x 8dmw== X-Forwarded-Encrypted: i=1; AJvYcCVWdUSP4KUg+mweZfrtNCIUm5yosDFd9q6JAyHq5B8oDXUKPB1EHUbOp7PL686J7EEqVh+ywJg7SaRhBV1TB3OBDv6BRSI= X-Gm-Message-State: AOJu0Yy+1XI6u52SiZsDcLQ3Aob6av8dgxrj0MFVnkq9XD4f14FXZPkw yUkia3xBHitog5YSacts3o/nsHBNmjKunSZhyr8yASyWO5o1lk4b+r49C9P4gFJDKI/A2sFiX6n mLViDX029iA== X-Google-Smtp-Source: AGHT+IETEqKhx61slYVxF7Pmd96UxbP3g7TDyMwnYPIU/731Btbxiehx4b3mA0OOTFEN8/03TH4D/djrSRoB+Q== X-Received: from mostafa.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:333c]) (user=smostafa job=sendgmr) by 2002:a05:6902:154c:b0:dc2:2e5c:a21d with SMTP id r12-20020a056902154c00b00dc22e5ca21dmr3387695ybu.6.1712585363249; Mon, 08 Apr 2024 07:09:23 -0700 (PDT) Date: Mon, 8 Apr 2024 14:08:15 +0000 In-Reply-To: <20240408140818.3799590-1-smostafa@google.com> Mime-Version: 1.0 References: <20240408140818.3799590-1-smostafa@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240408140818.3799590-11-smostafa@google.com> Subject: [RFC PATCH v2 10/13] hw/arm/smmuv3: Advertise S2FWB From: Mostafa Saleh To: qemu-arm@nongnu.org, eric.auger@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Cc: jean-philippe@linaro.org, alex.bennee@linaro.org, maz@kernel.org, nicolinc@nvidia.com, julien@xen.org, richard.henderson@linaro.org, marcin.juszkiewicz@linaro.org, Mostafa Saleh 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=2607:f8b0:4864:20::b4a; envelope-from=3k_oTZggKChA82489qvqw44w1u.s426u2A-tuBu1343w3A.47w@flex--smostafa.bounces.google.com; helo=mail-yb1-xb4a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1712585480620100002 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" QEMU doesn's support memory attributes, so FWB is NOP, this might change in the future if memory attributre would be supported. Signed-off-by: Mostafa Saleh --- hw/arm/smmuv3.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index da47411410..0e367c70ad 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -287,6 +287,14 @@ static void smmuv3_init_regs(SMMUv3State *s) if (FIELD_EX32(s->idr[0], IDR0, S2P)) { /* XNX is a stage-2-specific feature */ s->idr[3] =3D FIELD_DP32(s->idr[3], IDR3, XNX, 1); + if (FIELD_EX32(s->idr[0], IDR0, S1P)) { + /* + * QEMU doesn's support memory attributes, so FWB is NOP, this + * might change in the future if memory attributre would be + * supported. + */ + s->idr[3] =3D FIELD_DP32(s->idr[3], IDR3, FWB, 1); + } } s->idr[3] =3D FIELD_DP32(s->idr[3], IDR3, RIL, 1); s->idr[3] =3D FIELD_DP32(s->idr[3], IDR3, BBML, 2); --=20 2.44.0.478.gd926399ef9-goog From nobody Fri May 17 07:47:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1712585495; cv=none; d=zohomail.com; s=zohoarc; b=Gj+2k6Sp4UuuYsfVM8xUmLWule3CEhzVOsPGsCIOruKEmkiwSjVRK+s6rOWG38+dXFcPzfrPM6L72t/JoqkGsnqxia1/D+8ZZp+enHM1Ee9xqj5yWI1TOh3mxkNcy3rXTA88d7ll4JedSzdT3guLS9hVVHz6iVF8Rpik9JxWBb8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712585495; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ybhW/iy4MICs+VlDT9t9eZ+iakju4ebPrmZdQI0gVbA=; b=aj6viWWW+SmvRkxJxImniGADsA/mx8DlDlIE0TCAIOWy6kREx54v+vGiyq5FdkSHmmb6D4SU2hmbt5rDSe+oHaefvfKduwvhPdAcX2IpAxhUXDmbPp0vzK8VtVuIybsrMnxNSZuOeHlup6TIjw85XywJMYqIkP9+mI8kEEC71Ps= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17125854956942.092950699444259; Mon, 8 Apr 2024 07:11:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtphV-0007xB-E1; Mon, 08 Apr 2024 10:10:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3lfoTZggKChIA46ABsxsy66y3w.u648w4C-vwDw3565y5C.69y@flex--smostafa.bounces.google.com>) id 1rtpgt-0007Cu-9x for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:44 -0400 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3lfoTZggKChIA46ABsxsy66y3w.u648w4C-vwDw3565y5C.69y@flex--smostafa.bounces.google.com>) id 1rtpge-0001Ok-Tg for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:42 -0400 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-615073c8dfbso85627957b3.1 for ; Mon, 08 Apr 2024 07:09:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712585365; x=1713190165; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ybhW/iy4MICs+VlDT9t9eZ+iakju4ebPrmZdQI0gVbA=; b=DhhGfd2NJhqBAWpr+xTEId1QmN7u2+O5RyCC41Zj2+rpdtMZApsMjlAjTZDVibkk+R 7qU+8vw7qA+x+2sdrvHVASSE1pMPVkYjkpzJAkK+cMxX1NWE6GQi0GGo+855qaJoU10+ zKHWSCDC2F7aXfk1K5zr1dqU2x+uJIBrOd9FDX3lN/GI3lJI0Z8GvKXBUL1F7/bwg6iS gUN+6aWVru20FPXRk48uAZZEyiMh0xhXTMicYF4tyiTrGd4luNBrs07Q1nzjYbcnodZZ 0tL6ODmRl9VK55I6vVrCV+Xt3c9ReZY+Ji9h5TYfAoT5nSI2Zl6toaNgUx9lYN922htb V6iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712585365; x=1713190165; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ybhW/iy4MICs+VlDT9t9eZ+iakju4ebPrmZdQI0gVbA=; b=rfMbvjZQChfwlCw0QYul/3i/t1qmLZbLoGWhjJyYHtsoRGYC3ZNfvehR0KW05olKau MMXiao0EWbNDDUwTNGgMQuuqsxyRRgzDPoXE4Hrdp9jrAusv8/g3PHi5AiACHnOlWHXK c13NiVUAPk0aJSA8sNN20P0aUvqmU1CmN4GYNU+LWFvZb++8ARy6rDLHCrthuQ5KhTZB wK0r1yv1GV95EZf10S5u5dl4jnJxQABqQrbMWjlXwgpR1cXXoHbg5DqaZvbih2Ia+8gw ye8EjI/GB9J+nO4ESp/5CVEmLsnzM7VQMAW5BNQrbENEGmGW6bTZG5LP3g18wguGFJBh JJ3A== X-Forwarded-Encrypted: i=1; AJvYcCVqsPH+Z8aNmUAM9+Vrr+aZ6HvTopA2VO2/KDiT7Xd3BwcnkOG/i/boq9+rIUqh2UT3aP7RpQNQopj6ICts1rUxlxrgrHY= X-Gm-Message-State: AOJu0YxNfQvT6MAQuYIDoMCcCTWm8XP0+jXBhxekKYZRIIC3DcEbIlxC Y8Z2epmzEDL1ovS7t88AUecmwLMS2FZpvP0kIzODslSwBdGMfz9ugeIg1lFWUz7S5lnOdq1jd6H pF+i8DJufJg== X-Google-Smtp-Source: AGHT+IFnwgxxh1J3QIYMp3mLNe0VjOsiEtDzS5yjTC3dpadj/xOuyFqJvAkxo9TXIN2JrLeCjlYP34L4skGI5A== X-Received: from mostafa.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:333c]) (user=smostafa job=sendgmr) by 2002:a5b:944:0:b0:dcd:4286:4498 with SMTP id x4-20020a5b0944000000b00dcd42864498mr407033ybq.6.1712585365574; Mon, 08 Apr 2024 07:09:25 -0700 (PDT) Date: Mon, 8 Apr 2024 14:08:16 +0000 In-Reply-To: <20240408140818.3799590-1-smostafa@google.com> Mime-Version: 1.0 References: <20240408140818.3799590-1-smostafa@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240408140818.3799590-12-smostafa@google.com> Subject: [RFC PATCH v2 11/13] hw/arm/smmu: Refactor SMMU OAS From: Mostafa Saleh To: qemu-arm@nongnu.org, eric.auger@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Cc: jean-philippe@linaro.org, alex.bennee@linaro.org, maz@kernel.org, nicolinc@nvidia.com, julien@xen.org, richard.henderson@linaro.org, marcin.juszkiewicz@linaro.org, Mostafa Saleh 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=2607:f8b0:4864:20::114a; envelope-from=3lfoTZggKChIA46ABsxsy66y3w.u648w4C-vwDw3565y5C.69y@flex--smostafa.bounces.google.com; helo=mail-yw1-x114a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1712585496728100002 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" SMMUv3 OAS is hardcoded to 44 bits, for nested configurations that can be a problem as stage-2 might be shared with the CPU which might have different PARANGE, and according to SMMU manual ARM IHI 0070F.b: 6.3.6 SMMU_IDR5, OAS must match the system physical address size. This patch doesn't change the SMMU OAS, but refactors the code to make it easier to do that: - Rely everywhere on IDR5 for reading OAS instead of using the macro so it is easier just change IDR5 and it propagages correctly. - Remove unused functions/macros: pa_range/MAX_PA Signed-off-by: Mostafa Saleh --- hw/arm/smmu-common.c | 7 ++++--- hw/arm/smmuv3-internal.h | 13 ------------- hw/arm/smmuv3.c | 35 ++++++++++++++++++++++++++++------- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index b1cf1303c6..0710ee6b7d 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -430,7 +430,8 @@ static int smmu_ptw_64_s1(SMMUTransCfg *cfg, inputsize =3D 64 - tt->tsz; level =3D 4 - (inputsize - 4) / stride; indexmask =3D VMSA_IDXMSK(inputsize, stride, level); - baseaddr =3D extract64(tt->ttb, 0, 48); + + baseaddr =3D extract64(tt->ttb, 0, cfg->oas); baseaddr &=3D ~indexmask; =20 while (level < VMSA_LEVELS) { @@ -543,8 +544,8 @@ static int smmu_ptw_64_s2(SMMUTransCfg *cfg, * Get the ttb from concatenated structure. * The offset is the idx * size of each ttb(number of ptes * (sizeof(p= te)) */ - uint64_t baseaddr =3D extract64(cfg->s2cfg.vttb, 0, 48) + (1 << stride= ) * - idx * sizeof(uint64_t); + uint64_t baseaddr =3D extract64(cfg->s2cfg.vttb, 0, cfg->s2cfg.eff_ps)= + + (1 << stride) * idx * sizeof(uint64_t); dma_addr_t indexmask =3D VMSA_IDXMSK(inputsize, stride, level); =20 baseaddr &=3D ~indexmask; diff --git a/hw/arm/smmuv3-internal.h b/hw/arm/smmuv3-internal.h index e4dd11e1e6..b0d7ad6da3 100644 --- a/hw/arm/smmuv3-internal.h +++ b/hw/arm/smmuv3-internal.h @@ -596,19 +596,6 @@ static inline int oas2bits(int oas_field) return -1; } =20 -static inline int pa_range(STE *ste) -{ - int oas_field =3D MIN(STE_S2PS(ste), SMMU_IDR5_OAS); - - if (!STE_S2AA64(ste)) { - return 40; - } - - return oas2bits(oas_field); -} - -#define MAX_PA(ste) ((1 << pa_range(ste)) - 1) - /* CD fields */ =20 #define CD_VALID(x) extract32((x)->word[0], 31, 1) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 0e367c70ad..c377c05379 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -411,10 +411,10 @@ static bool s2t0sz_valid(SMMUTransCfg *cfg) } =20 if (cfg->s2cfg.granule_sz =3D=3D 16) { - return (cfg->s2cfg.tsz >=3D 64 - oas2bits(SMMU_IDR5_OAS)); + return (cfg->s2cfg.tsz >=3D 64 - cfg->s2cfg.eff_ps); } =20 - return (cfg->s2cfg.tsz >=3D MAX(64 - oas2bits(SMMU_IDR5_OAS), 16)); + return (cfg->s2cfg.tsz >=3D MAX(64 - cfg->s2cfg.eff_ps, 16)); } =20 /* @@ -435,8 +435,11 @@ static bool s2_pgtable_config_valid(uint8_t sl0, uint8= _t t0sz, uint8_t gran) return nr_concat <=3D VMSA_MAX_S2_CONCAT; } =20 -static int decode_ste_s2_cfg(SMMUTransCfg *cfg, STE *ste) +static int decode_ste_s2_cfg(SMMUv3State *s, SMMUTransCfg *cfg, + STE *ste) { + uint8_t oas =3D FIELD_EX32(s->idr[5], IDR5, OAS); + if (STE_S2AA64(ste) =3D=3D 0x0) { qemu_log_mask(LOG_UNIMP, "SMMUv3 AArch32 tables not supported\n"); @@ -469,7 +472,15 @@ static int decode_ste_s2_cfg(SMMUTransCfg *cfg, STE *s= te) } =20 /* For AA64, The effective S2PS size is capped to the OAS. */ - cfg->s2cfg.eff_ps =3D oas2bits(MIN(STE_S2PS(ste), SMMU_IDR5_OAS)); + cfg->s2cfg.eff_ps =3D oas2bits(MIN(STE_S2PS(ste), oas)); + /* + * For SMMUv3.1 and later, when OAS =3D=3D IAS =3D=3D 52, the stage 2 = input + * range is further limited to 48 bits unless STE.S2TG indicates a + * 64KB granule. + */ + if (cfg->s2cfg.granule_sz !=3D 16) { + cfg->s2cfg.eff_ps =3D MIN(cfg->s2cfg.eff_ps, 48); + } /* * It is ILLEGAL for the address in S2TTB to be outside the range * described by the effective S2PS value. @@ -545,6 +556,7 @@ static int decode_ste(SMMUv3State *s, SMMUTransCfg *cfg, STE *ste, SMMUEventInfo *event) { uint32_t config; + uint8_t oas =3D FIELD_EX32(s->idr[5], IDR5, OAS); int ret; =20 if (!STE_VALID(ste)) { @@ -588,8 +600,8 @@ static int decode_ste(SMMUv3State *s, SMMUTransCfg *cfg, * Stage-1 OAS defaults to OAS even if not enabled as it would be = used * in input address check for stage-2. */ - cfg->oas =3D oas2bits(SMMU_IDR5_OAS); - ret =3D decode_ste_s2_cfg(cfg, ste); + cfg->oas =3D oas2bits(oas); + ret =3D decode_ste_s2_cfg(s, cfg, ste); if (ret) { goto bad_ste; } @@ -715,6 +727,7 @@ static int decode_cd(SMMUv3State *s, SMMUTransCfg *cfg, int i; SMMUTranslationStatus status; SMMUTLBEntry *entry; + uint8_t oas =3D FIELD_EX32(s->idr[5], IDR5, OAS); =20 if (!CD_VALID(cd) || !CD_AARCH64(cd)) { goto bad_cd; @@ -733,7 +746,7 @@ static int decode_cd(SMMUv3State *s, SMMUTransCfg *cfg, cfg->aa64 =3D true; =20 cfg->oas =3D oas2bits(CD_IPS(cd)); - cfg->oas =3D MIN(oas2bits(SMMU_IDR5_OAS), cfg->oas); + cfg->oas =3D MIN(oas2bits(oas), cfg->oas); cfg->tbi =3D CD_TBI(cd); cfg->asid =3D CD_ASID(cd); cfg->affd =3D CD_AFFD(cd); @@ -762,6 +775,14 @@ static int decode_cd(SMMUv3State *s, SMMUTransCfg *cfg, goto bad_cd; } =20 + /* + * An address greater than 48 bits in size can only be output from= a + * TTD when, in SMMUv3.1 and later, the effective IPS is 52 and a = 64KB + * granule is in use for that translation table + */ + if (tt->granule_sz !=3D 16) { + cfg->oas =3D MIN(cfg->oas, 48); + } tt->tsz =3D tsz; tt->ttb =3D CD_TTB(cd, i); =20 --=20 2.44.0.478.gd926399ef9-goog From nobody Fri May 17 07:47:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1712585469; cv=none; d=zohomail.com; s=zohoarc; b=QDCN8sJTNX7ME49AiJSqA6tp/R4r7pk4p9z7G34qPBdkJQV3veQ38aP3jQMHIqUQSOVn0tvSsnZjva6Jdf/buu0eRhTFYm4qQmWGTaHOLtSneMLYXnlttlTernJFSF0fj4MboUkGZGF0z/ZlvhJDYXEpMh5+kZt/ttrOm9ZiXtw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712585469; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0HFXPBczsaFzwM3/E8nUe7UI7cqODAn7zmH22JOuPig=; b=jnnCZ4TonAjXHlKLj7FqG/4BJUuIrqhnXGXKyVh7MWX1tQrRR5z3j0sSGnyUoaf1moVbJsy5ohDLh3fn3u889bcKX91U5pwUJjtBPIya/o7DwzRCyW7tx7X627AcE6dpqDtVHgYVAXjtj9CTlMvSI+9/X+ZrN6Ti/n4TR8KsfO4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1712585469723125.97284837545453; Mon, 8 Apr 2024 07:11:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtphc-0000PC-KQ; Mon, 08 Apr 2024 10:10:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3l_oTZggKChQC68CDuzu08805y.w86Ay6E-xyFy578707E.8B0@flex--smostafa.bounces.google.com>) id 1rtpgv-0007Fb-Nt for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:49 -0400 Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3l_oTZggKChQC68CDuzu08805y.w86Ay6E-xyFy578707E.8B0@flex--smostafa.bounces.google.com>) id 1rtpgh-0001Ox-44 for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:45 -0400 Received: by mail-wr1-x44a.google.com with SMTP id ffacd0b85a97d-3455cbdea2cso727365f8f.0 for ; Mon, 08 Apr 2024 07:09:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712585367; x=1713190167; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=0HFXPBczsaFzwM3/E8nUe7UI7cqODAn7zmH22JOuPig=; b=yTjpNFWDp7EDhfj/nHTOZLKFUfjwHNbDKpdp70+7wpzkRRM4XqWCa3+NE1AhUb/p+L /vJkP+WnwXqBpCl9bu2AWvTWAIdD/if6PGNj4yhXHbU606j3liZQj3OkHegp2nzmv4Cm BsmLiq2TS7wNpxEMuIXwvxdxxJV+rypSLtW1d8HLKF89YwIYFiwiX8vHxJAMJtnuqd95 3Xg8GgXr5JkX86grFFLbQdaSPPn5TwDK/Ak9XAmUs+R5dIzVvQP7SyCrKo6O0KBLJQ5q m0iX6DcIbWR1i0qeuPzFQi90/h/yO9OctGEzIh7HhGce4rmkpp9YvvhwN8kHZJJSxmWy zvXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712585367; x=1713190167; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0HFXPBczsaFzwM3/E8nUe7UI7cqODAn7zmH22JOuPig=; b=rjEa32J2bq5JV49/6Yk/1QjTRvKxMhZCuiv/1vggqS3Fg+d0Rojb8ZuurLM+RxSRdz ffGLVFVpoHU09s8m1e1CNYzCWxwN4Mhl/KRmIC+uI/9be0955tZmcJwLiEHWKjWkMWH+ iuUdAYFv9UZL/u/Yo9X7bJyDkOEXJvVWsvaw4m9aL7vSfr7koOlkTuwzJgGhq2RerU8o iDC9kJm/FARQUme4ix1Zyx+OBfyaDllc9CS5toC063sTFJyUBOTQagYZBkttPGhaI7tb KiIWDKnGvPU835KEJiEpEoGosV0HmmRguWzXxCZ8taKuG4BbLus7tPA3AHwLlx/2Pu+f AxOA== X-Forwarded-Encrypted: i=1; AJvYcCX2ZdXkIAb8WBsC240mSp+EiP7juZdRgzHSGRoDWzIkePo2elSCPYgRPK7lPWFDCBrumjkB6GMqKEN/rMvQ+vLnzVvAwsY= X-Gm-Message-State: AOJu0YzEnpW/bUBzNp/Q+fEZx1NHLL/K7BTdoE7RsN9o1eqmxDD/k1GG gqQ7ZbmBlIZHFkbuYCIuK8vEvd9B3l31Fcj7KQqZwznqR7mQO0HGqhjwFNOVrAfL5jMOKXwOcRE ZkPiIRyDRzw== X-Google-Smtp-Source: AGHT+IE7kCfdgL08HfEqucyFWrSJbWPjvekE7QrePaAghtRgm0vvVoGNYz6lmTGoMFN28/lVMU0gfGcPCY6egg== X-Received: from mostafa.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:333c]) (user=smostafa job=sendgmr) by 2002:a5d:6f0d:0:b0:343:ecac:5ffc with SMTP id ay13-20020a5d6f0d000000b00343ecac5ffcmr116195wrb.7.1712585367719; Mon, 08 Apr 2024 07:09:27 -0700 (PDT) Date: Mon, 8 Apr 2024 14:08:17 +0000 In-Reply-To: <20240408140818.3799590-1-smostafa@google.com> Mime-Version: 1.0 References: <20240408140818.3799590-1-smostafa@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240408140818.3799590-13-smostafa@google.com> Subject: [RFC PATCH v2 12/13] hw/arm/smmuv3: Add property for OAS From: Mostafa Saleh To: qemu-arm@nongnu.org, eric.auger@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Cc: jean-philippe@linaro.org, alex.bennee@linaro.org, maz@kernel.org, nicolinc@nvidia.com, julien@xen.org, richard.henderson@linaro.org, marcin.juszkiewicz@linaro.org, Mostafa Saleh 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=2a00:1450:4864:20::44a; envelope-from=3l_oTZggKChQC68CDuzu08805y.w86Ay6E-xyFy578707E.8B0@flex--smostafa.bounces.google.com; helo=mail-wr1-x44a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1712585470678100010 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add property that sets the OAS of the SMMU, this in not used in this patch. Signed-off-by: Mostafa Saleh --- hw/arm/smmuv3-internal.h | 3 ++- hw/arm/smmuv3.c | 29 ++++++++++++++++++++++++++++- include/hw/arm/smmuv3.h | 1 + 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/hw/arm/smmuv3-internal.h b/hw/arm/smmuv3-internal.h index b0d7ad6da3..41612bb9ff 100644 --- a/hw/arm/smmuv3-internal.h +++ b/hw/arm/smmuv3-internal.h @@ -105,7 +105,8 @@ REG32(IDR5, 0x14) FIELD(IDR5, VAX, 10, 2); FIELD(IDR5, STALL_MAX, 16, 16); =20 -#define SMMU_IDR5_OAS 4 +#define SMMU_IDR5_OAS_DEF 4 /* 44 bits. */ +#define SMMU_IDR5_OAS_MAX 5 /* 48 bits. */ =20 REG32(IIDR, 0x18) REG32(AIDR, 0x1c) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index c377c05379..a9e35c41b7 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -299,7 +299,9 @@ static void smmuv3_init_regs(SMMUv3State *s) s->idr[3] =3D FIELD_DP32(s->idr[3], IDR3, RIL, 1); s->idr[3] =3D FIELD_DP32(s->idr[3], IDR3, BBML, 2); =20 - s->idr[5] =3D FIELD_DP32(s->idr[5], IDR5, OAS, SMMU_IDR5_OAS); /* 44 b= its */ + /* PTW doesn't support 52 bits. */ + s->oas =3D MIN(s->oas, SMMU_IDR5_OAS_MAX); + s->idr[5] =3D FIELD_DP32(s->idr[5], IDR5, OAS, s->oas); /* 4K, 16K and 64K granule support */ s->idr[5] =3D FIELD_DP32(s->idr[5], IDR5, GRAN4K, 1); s->idr[5] =3D FIELD_DP32(s->idr[5], IDR5, GRAN16K, 1); @@ -1878,11 +1880,34 @@ static const VMStateDescription vmstate_gbpa =3D { } }; =20 +static const VMStateDescription vmstate_oas =3D { + .name =3D "smmuv3/oas", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_INT32(oas, SMMUv3State), + VMSTATE_END_OF_LIST() + } +}; + +static int smmuv3_preload(void *opaque) +{ + SMMUv3State *s =3D opaque; + + /* + * In case it wasn't migrated, use the value used + * by older QEMU. + */ + s->oas =3D SMMU_IDR5_OAS_DEF; + return 0; +} + static const VMStateDescription vmstate_smmuv3 =3D { .name =3D "smmuv3", .version_id =3D 1, .minimum_version_id =3D 1, .priority =3D MIG_PRI_IOMMU, + .pre_load =3D smmuv3_preload, .fields =3D (const VMStateField[]) { VMSTATE_UINT32(features, SMMUv3State), VMSTATE_UINT8(sid_size, SMMUv3State), @@ -1910,6 +1935,7 @@ static const VMStateDescription vmstate_smmuv3 =3D { }, .subsections =3D (const VMStateDescription * const []) { &vmstate_gbpa, + &vmstate_oas, NULL } }; @@ -1922,6 +1948,7 @@ static Property smmuv3_properties[] =3D { * Defaults to stage 1 */ DEFINE_PROP_STRING("stage", SMMUv3State, stage), + DEFINE_PROP_INT32("oas", SMMUv3State, oas, SMMU_IDR5_OAS_DEF), DEFINE_PROP_END_OF_LIST() }; =20 diff --git a/include/hw/arm/smmuv3.h b/include/hw/arm/smmuv3.h index d183a62766..00a9eb4467 100644 --- a/include/hw/arm/smmuv3.h +++ b/include/hw/arm/smmuv3.h @@ -63,6 +63,7 @@ struct SMMUv3State { qemu_irq irq[4]; QemuMutex mutex; char *stage; + int32_t oas; }; =20 typedef enum { --=20 2.44.0.478.gd926399ef9-goog From nobody Fri May 17 07:47:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1712585475; cv=none; d=zohomail.com; s=zohoarc; b=WGaQcgYH91sBNM/ZvXxk5f1/E9k/uJqzH6/5rm0i+eXBTIKKwSfhaJncDZAViemnjscqkTAVAklE8vGrwnRxqEl8ZpkVmPUKmIoiAyaSFffT9rmZRVjJwB4B32UxMbX8Q96P0fB5BYW/x+IHUglI4EPs5725q9aIA0eecGxS594= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712585475; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=AMd8YNfC7PIDLuxaX4315ka/K6CHfBg/CUvv3sbGflM=; b=ck2vpkiMVxjSbvNs5QMuR5gm29tw0cejEpxeJzaCZPeMp+f2FZRB984bEYxv1iGODXG/0PA9MeTo1Jv874dwjdAKKPahr/bFuLa284CPBQ2FcmcmjpyNhabl3jickIWbDE22X7dsWW9405B5wTLj/g91+phBxnzvso68M8fvmNs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1712585475151467.6290482274919; Mon, 8 Apr 2024 07:11:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtphW-00085H-HQ; Mon, 08 Apr 2024 10:10:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3mfoTZggKChYE8AEFw1w2AA270.yA8C08G-z0H079A929G.AD2@flex--smostafa.bounces.google.com>) id 1rtpgy-0007GF-2N for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:54 -0400 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3mfoTZggKChYE8AEFw1w2AA270.yA8C08G-z0H079A929G.AD2@flex--smostafa.bounces.google.com>) id 1rtpgj-0001PJ-MV for qemu-devel@nongnu.org; Mon, 08 Apr 2024 10:09:47 -0400 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-610b96c8ca2so73370057b3.2 for ; Mon, 08 Apr 2024 07:09:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712585369; x=1713190169; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=AMd8YNfC7PIDLuxaX4315ka/K6CHfBg/CUvv3sbGflM=; b=TRywDM2wK6BTL1rXN20MEg6kfmDOY1dhWq9UZou/nC0tq3F0uIVyM1oqc18xrVJiZU twQccS1skSS4KCSpCL7NxubcXW97G6AKOsWOyu8K3m8cKN0dNlUa9ocqKbUT8/HxuUnC 2Q7yccapwwKuV1rcY0sE+X6hwoybaHIbYaf0Rcq7QFyDRKLnEy6TN8lBIKGNg+8XaG1p q2f3TqgOEJB90i7hNRHLo/fx/6zeUEyCcQWqFrLQpMD25Yysshn+lCmZ73rKENtJz2Ag YDaeS5GcZKLUy4IUjO1VyDAn1sQZSX0q2OkQpmDioHgNAmIqXpXgF+sLwpu9RDe5KONE BipQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712585369; x=1713190169; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AMd8YNfC7PIDLuxaX4315ka/K6CHfBg/CUvv3sbGflM=; b=wN2ZEMFAJQrJ3bch4n2O9QG2CCjxKy9usC9kp4y8Kl9W0TnplHjH9x1RbpO8ERYeDR xXU/CbUlhoyNKpNrZDtc+pMYHPsFLmBSly1+Rma0SWwH/ek5ecUJykbiLeaSQD6oYjxP l606OTOOLGnTMVnXQII2ZuS03zFy47TAUE3ZQ0Yh70krvZ+FKKbVeIFpj93+4yZWu69y WeIc3FPt2t3Qzk4Q2dtOvwnVnsBH7Tq+F+4cYrjWQmW3ZVlqqIExgOnFR6o/WGKYvdGU E2GssmbERWortVVXSk8FHR1EBZDPI4JwCVsWvNKK0ZY+RRUgXST9KeQb9SkPq6/hjLQ8 hPXA== X-Forwarded-Encrypted: i=1; AJvYcCUj31/elqVwITACEw+s2A6mtfNZ5HONULPdSEd0FNSSSzOXFRRgZQByYMYxaod1Y0/EWWhHudo0KZJCnSr7ZD7FqW5ZFCg= X-Gm-Message-State: AOJu0YzcNIaac+mJ32rKKK2Cv+doHQEStP2+lTMfbdV/yCDy1x1ASoiA ZMMdQQC/48YF4YWpZ3XqKm8gyALm/8iiTygYeIsJkLtaRgTwX2/N/TqeKLlzFUR5/JCjQiMUoR7 DGUZK/EJnHQ== X-Google-Smtp-Source: AGHT+IGluNUcEdGNO/MW02ClIEjM8uOtannDp473rPxeJGa/ejn0j6js4csqJlN5iWXZrJXEDWT/oAQWrex+Lw== X-Received: from mostafa.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:333c]) (user=smostafa job=sendgmr) by 2002:a0d:d54a:0:b0:615:165b:8dde with SMTP id x71-20020a0dd54a000000b00615165b8ddemr2605640ywd.10.1712585369753; Mon, 08 Apr 2024 07:09:29 -0700 (PDT) Date: Mon, 8 Apr 2024 14:08:18 +0000 In-Reply-To: <20240408140818.3799590-1-smostafa@google.com> Mime-Version: 1.0 References: <20240408140818.3799590-1-smostafa@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240408140818.3799590-14-smostafa@google.com> Subject: [RFC PATCH v2 13/13] hw/arm/virt: Set SMMU OAS based on CPU PARANGE From: Mostafa Saleh To: qemu-arm@nongnu.org, eric.auger@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Cc: jean-philippe@linaro.org, alex.bennee@linaro.org, maz@kernel.org, nicolinc@nvidia.com, julien@xen.org, richard.henderson@linaro.org, marcin.juszkiewicz@linaro.org, Mostafa Saleh 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=2607:f8b0:4864:20::114a; envelope-from=3mfoTZggKChYE8AEFw1w2AA270.yA8C08G-z0H079A929G.AD2@flex--smostafa.bounces.google.com; helo=mail-yw1-x114a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1712585476614100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the new SMMU property to make the SMMU OAS match the CPU PARANGE. That's according to SMMU manual ARM IHI 0070F.b: 6.3.6 SMMU_IDR5, OAS must match the system physical address size. Signed-off-by: Mostafa Saleh --- hw/arm/virt.c | 14 ++++++++++++-- target/arm/cpu.h | 2 ++ target/arm/cpu64.c | 5 +++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 0af1943697..599c0f752b 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -235,6 +235,13 @@ static bool ns_el2_virt_timer_present(void) arm_feature(env, ARM_FEATURE_EL2) && cpu_isar_feature(aa64_vh, cpu= ); } =20 +/* We rely on CPU to define system OAS. */ +static int32_t get_system_oas(void) +{ + ARMCPU *cpu =3D ARM_CPU(qemu_get_cpu(0)); + return cpu_arm_get_oas(cpu); +} + static void create_fdt(VirtMachineState *vms) { MachineState *ms =3D MACHINE(vms); @@ -1340,7 +1347,7 @@ static void create_pcie_irq_map(const MachineState *m= s, } =20 static void create_smmu(const VirtMachineState *vms, - PCIBus *bus) + PCIBus *bus, int32_t oas) { char *node; const char compat[] =3D "arm,smmu-v3"; @@ -1360,6 +1367,9 @@ static void create_smmu(const VirtMachineState *vms, =20 object_property_set_link(OBJECT(dev), "primary-bus", OBJECT(bus), &error_abort); + + qdev_prop_set_uint64(dev, "oas", oas); + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base); for (i =3D 0; i < NUM_SMMU_IRQS; i++) { @@ -1534,7 +1544,7 @@ static void create_pcie(VirtMachineState *vms) =20 switch (vms->iommu) { case VIRT_IOMMU_SMMUV3: - create_smmu(vms, vms->bus); + create_smmu(vms, vms->bus, get_system_oas()); qemu_fdt_setprop_cells(ms->fdt, nodename, "iommu-map", 0x0, vms->iommu_phandle, 0x0, 0x10000); break; diff --git a/target/arm/cpu.h b/target/arm/cpu.h index a5b3d8f7da..14ef1a9d37 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3408,4 +3408,6 @@ static inline target_ulong cpu_untagged_addr(CPUState= *cs, target_ulong x) } #endif =20 +int32_t cpu_arm_get_oas(ARMCPU *cpu); + #endif diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 985b1efe16..08da83c082 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -787,6 +787,11 @@ static const gchar *aarch64_gdb_arch_name(CPUState *cs) return "aarch64"; } =20 +int32_t cpu_arm_get_oas(ARMCPU *cpu) +{ + return FIELD_EX64(cpu->isar.id_aa64mmfr0, ID_AA64MMFR0, PARANGE); +} + static void aarch64_cpu_class_init(ObjectClass *oc, void *data) { CPUClass *cc =3D CPU_CLASS(oc); --=20 2.44.0.478.gd926399ef9-goog