From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BC3BBC3DA42 for ; Mon, 8 Jul 2024 15:20:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQqA7-0001gT-RP; Mon, 08 Jul 2024 11:20: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 ) id 1sQqA5-0001dJ-Sv for qemu-devel@nongnu.org; Mon, 08 Jul 2024 11:20:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sQq9x-0005FL-38 for qemu-devel@nongnu.org; Mon, 08 Jul 2024 11:20:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720452006; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bcaaCLu5w7lp6KzPabkWFRRuWQszxJCWccT5iuQB5qs=; b=fxnXcjwDGAL0zr+Cw37NochpRwSP/CQM19SFSxjjZdTOXfHXSyOtMNFsq7lu/82H0t0KWk XwUV0bgfaimZhWdcMxjGoI3KsPjAHUYocLTolv/CZje2YUneDRXDwK7zKmo35GXQdnsbSH NNFo5h9q0WrWm6rwk1K//jSGqgQddiA= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-472-WM5nfXwaPEqOE-PqNxODQA-1; Mon, 08 Jul 2024 11:20:05 -0400 X-MC-Unique: WM5nfXwaPEqOE-PqNxODQA-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-52e9a575353so4671902e87.3 for ; Mon, 08 Jul 2024 08:20:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720452002; x=1721056802; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:reply-to:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bcaaCLu5w7lp6KzPabkWFRRuWQszxJCWccT5iuQB5qs=; b=G3ltwJRkrMIzPru9QE1eLeD2ZsjS8rNEp79pOwi1IASVfCtNR3DC7wIVDcLwTAIUWZ cgOGu5r3QtPUDXOI8XI7gZNwpo2scPFZQmENyt4vQItRBdf2PJXdhwStYPeY89yiryQI Fkyti3YKHd+a8Ckc44M/s7jRTTQstVkwT5z0gZIGyLkzgDtj0H/l/51kS61hTZ89n7Ew +bV9kSe3d4hwKpI1wk8F43Sq4bDD6AN9U6E9uJvyH/bOdJwqMh71d10t2LxU0C0/lE0i /Q43TahOoEzqy6iOt1vDaJPR9KH/B40ZsZfMyx0eSIVUOWrUz97nKFIexCeVMGE6TxDO RG5g== X-Forwarded-Encrypted: i=1; AJvYcCXml6y39DlJNQOsgRrI5tySfKD4tqSNVPxfK+pSURmobQtZw5Zya8lIW1LLD4lGSUPovz9JXQbrOfc5cFVr8DLn5v3h3JE= X-Gm-Message-State: AOJu0YxZGTsF7UgwH6srIlSV+/r4awuOzVgHCdnuMzLjd9GdAvFKw2Og vLlPBUiDj28tRdRqzz7PMGo/l+6WO66hQznWSZipdOParRgoBCIVHlOE90MOWJzkl1Ez7DcN4fj AyKLNQzxq2kqS3fh0fTyzIbGj3G0jweK0DDSeevRyMAeCzfu4JwGHDOHkHriq X-Received: by 2002:a05:6512:3e19:b0:52c:e3ad:3fbf with SMTP id 2adb3069b0e04-52ea06bb61amr11019590e87.42.1720452002170; Mon, 08 Jul 2024 08:20:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEoOTuvQ+WzrVCzC+f4J4Qtv/jFh2Ke5EiyfnpJeJ4egSNfrGRGJ+yDLYS7jEqd2wwF8+0dBg== X-Received: by 2002:a05:6512:3e19:b0:52c:e3ad:3fbf with SMTP id 2adb3069b0e04-52ea06bb61amr11019567e87.42.1720452001709; Mon, 08 Jul 2024 08:20:01 -0700 (PDT) Received: from ?IPV6:2a01:e0a:59e:9d80:527b:9dff:feef:3874? ([2a01:e0a:59e:9d80:527b:9dff:feef:3874]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42667720667sm57913105e9.33.2024.07.08.08.20.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 08 Jul 2024 08:20:01 -0700 (PDT) Message-ID: <86fc9221-f24e-4a7f-8a0d-b19102f981f0@redhat.com> Date: Mon, 8 Jul 2024 17:19:59 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 11/19] hw/arm/smmu-common: Support nested translation Content-Language: en-US To: Mostafa Saleh , qemu-arm@nongnu.org, 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 References: <20240701110241.2005222-1-smostafa@google.com> <20240701110241.2005222-12-smostafa@google.com> From: Eric Auger In-Reply-To: <20240701110241.2005222-12-smostafa@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=170.10.133.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: , Reply-To: eric.auger@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Hi Mostafa, On 7/1/24 13:02, Mostafa Saleh wrote: > When nested translation is requested, do the following: > > - Translate stage-1 table address IPA into PA through stage-2. > - Translate stage-1 table walk output (IPA) through stage-2. > - Create a single TLB entry from stage-1 and stage-2 translations > using logic introduced before. > > For stage-1 table translation, the spec (ARM IHI 0070 F.b) says in: > 7.3.12 F_WALK_EABT: > Translation of an IPA for Stage 1 descriptor fetch: > S2 == 1 (stage 2), CLASS == T > So, F_WALK_EABT is used which propagtes to CLASS == TT. > > smmu_ptw() has a new argument SMMUState which include the TLB as > stage-1 table address can be cached in there. > > Also in smmu_ptw() a separate path used for nesting to simplify the > code, although some logic can be combined. > > Signed-off-by: Mostafa Saleh > --- > hw/arm/smmu-common.c | 72 +++++++++++++++++++++++++++++++----- > include/hw/arm/smmu-common.h | 2 +- > 2 files changed, 64 insertions(+), 10 deletions(-) > > diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c > index 24b7d09e2b..71afd486ba 100644 > --- a/hw/arm/smmu-common.c > +++ b/hw/arm/smmu-common.c > @@ -318,6 +318,38 @@ SMMUTransTableInfo *select_tt(SMMUTransCfg *cfg, dma_addr_t iova) > return NULL; > } > > +/* Translate stage-1 table address using stage-2 page table. */ > +static inline int translate_table_addr_ipa(dma_addr_t *table_addr, > + SMMUTransCfg *cfg, > + SMMUPTWEventInfo *info, > + SMMUState *bs) Nit: in general the SMMUState if the 1st arg, as the most global state. > +{ > + dma_addr_t addr = *table_addr; > + SMMUTLBEntry *cached_entry; > + int asid; > + > + /* > + * The translation table walks performed from TTB0 or TTB1 are always > + * performed in IPA space if stage 2 translations are enabled. > + */ > + asid = cfg->asid; > + cfg->stage = SMMU_STAGE_2; > + cfg->asid = -1; > + cached_entry = smmu_translate(bs, cfg, addr, IOMMU_RO, info); > + cfg->asid = asid; > + cfg->stage = SMMU_NESTED; > + > + if (cached_entry) { > + *table_addr = CACHED_ENTRY_TO_ADDR(cached_entry, addr); > + return 0; > + } > + > + info->stage = SMMU_STAGE_2; > + info->type = SMMU_PTW_ERR_WALK_EABT; > + info->addr = addr; so I guess also here the recorded address should be the IOVA (Jean's previous comment)? Eric > + return -EINVAL; > +} > + > /** > * smmu_ptw_64_s1 - VMSAv8-64 Walk of the page tables for a given IOVA > * @cfg: translation config > @@ -333,7 +365,8 @@ SMMUTransTableInfo *select_tt(SMMUTransCfg *cfg, dma_addr_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 = cfg->stage; > @@ -381,6 +414,11 @@ static int smmu_ptw_64_s1(SMMUTransCfg *cfg, > goto error; > } > baseaddr = get_table_pte_address(pte, granule_sz); > + if (cfg->stage == SMMU_NESTED) { > + if (translate_table_addr_ipa(&baseaddr, cfg, info, bs)) { > + goto error; > + } > + } > level++; > continue; > } else if (is_page_pte(pte, level)) { > @@ -568,10 +606,8 @@ error: > * combine S1 and S2 TLB entries into a single entry. > * As a result the S1 entry is overriden with combined data. > */ > -static void __attribute__((unused)) combine_tlb(SMMUTLBEntry *tlbe, > - SMMUTLBEntry *tlbe_s2, > - dma_addr_t iova, > - SMMUTransCfg *cfg) > +static void combine_tlb(SMMUTLBEntry *tlbe, SMMUTLBEntry *tlbe_s2, > + dma_addr_t iova, SMMUTransCfg *cfg) > { > if (tlbe_s2->entry.addr_mask < tlbe->entry.addr_mask) { > tlbe->entry.addr_mask = tlbe_s2->entry.addr_mask; > @@ -596,14 +632,19 @@ static void __attribute__((unused)) combine_tlb(SMMUTLBEntry *tlbe, > * @perm: tentative access type > * @tlbe: returned entry > * @info: ptw event handle > + * @bs: smmu state which includes TLB instance > * > * 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) > { > + int ret; > + SMMUTLBEntry tlbe_s2; > + dma_addr_t ipa; > + > if (cfg->stage == SMMU_STAGE_1) { > - return smmu_ptw_64_s1(cfg, iova, perm, tlbe, info); > + return smmu_ptw_64_s1(cfg, iova, perm, tlbe, info, bs); > } else if (cfg->stage == SMMU_STAGE_2) { > /* > * If bypassing stage 1(or unimplemented), the input address is passed > @@ -621,7 +662,20 @@ int smmu_ptw(SMMUTransCfg *cfg, dma_addr_t iova, IOMMUAccessFlags perm, > return smmu_ptw_64_s2(cfg, iova, perm, tlbe, info); > } > > - g_assert_not_reached(); > + /* SMMU_NESTED. */ > + ret = smmu_ptw_64_s1(cfg, iova, perm, tlbe, info, bs); > + if (ret) { > + return ret; > + } > + > + ipa = CACHED_ENTRY_TO_ADDR(tlbe, iova); > + ret = smmu_ptw_64_s2(cfg, ipa, perm, &tlbe_s2, info); > + if (ret) { > + return ret; > + } > + > + combine_tlb(tlbe, &tlbe_s2, iova, cfg); > + return 0; > } > > SMMUTLBEntry *smmu_translate(SMMUState *bs, SMMUTransCfg *cfg, dma_addr_t addr, > @@ -677,7 +731,7 @@ SMMUTLBEntry *smmu_translate(SMMUState *bs, SMMUTransCfg *cfg, dma_addr_t addr, > } > > cached_entry = g_new0(SMMUTLBEntry, 1); > - status = smmu_ptw(cfg, aligned_addr, flag, cached_entry, info); > + status = smmu_ptw(cfg, aligned_addr, flag, cached_entry, info, bs); > if (status) { > g_free(cached_entry); > return NULL; > diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h > index 1db566d451..cf0fd3ec74 100644 > --- a/include/hw/arm/smmu-common.h > +++ b/include/hw/arm/smmu-common.h > @@ -185,7 +185,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); > > > /*