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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 1E075CD4F4C for ; Sun, 8 Sep 2024 23:55:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=wi0uDfX5sgX+oLv1lO6K16Ep91IJ96aWPDPwqIWLlPg=; b=xmjr8r7k2pqoGxioZtQBddPR7e ax3kyCeLUZUrT+FZM2/Cwbz7Dg1YhvzJBc02j0iWfAwkpFfnEOUTJzfLJFz240tzxejRw6J8U7bS0 9zhqsTJLuNxG26ZVwq4DUpUYUBJ+fWU0+uB0D9hOQiilj3//GsccTv352u2sirCxfrEjo97YbHs1a Z393BN33TBMszaKBI2U8CEb3MRAZPHdT46kUYW05aTSWKOi+t2iakdkASJ9OG6oXSa4ybDhpTZMQl qU7bwfmlmrYpJW21R8CDV/EOIL6cSIaoXMeY+5M1wXs0Ryy9J3xCBi7G3Z2dsSLUksIojOg59C8Zl 5XbRUA1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1snRkG-000000004Yj-3FzU; Sun, 08 Sep 2024 23:55:04 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1snRjG-000000004SQ-1ig6 for linux-arm-kernel@lists.infradead.org; Sun, 08 Sep 2024 23:54:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725839639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wi0uDfX5sgX+oLv1lO6K16Ep91IJ96aWPDPwqIWLlPg=; b=bpttvt7zrlKHG8d1+F84x6ToJ5P7gT+g+m4Ztx73vR6V3PAlLojeDlTh0Tg+Yf48dpgaDj /3yOQwbdQ8R8fiXHcQOXUcmpOCh2SBlTTbAB+mt+j1+0B44IyQe8r5G/8cXLWQ7I4CyR/T jDCi4r9X0XMf3PcxpNQ9XKVhUSK/4go= Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-650-uwGzi4E1NWOi_BsVYBvuuA-1; Sun, 08 Sep 2024 19:53:57 -0400 X-MC-Unique: uwGzi4E1NWOi_BsVYBvuuA-1 Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-2d8b4a23230so4053338a91.0 for ; Sun, 08 Sep 2024 16:53:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725839637; x=1726444437; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wi0uDfX5sgX+oLv1lO6K16Ep91IJ96aWPDPwqIWLlPg=; b=L+j77iOtJa8J7jfMYkpxdm0Mly/oYn48SrkqcQ1Zi6Unitwfm9z0Hl1bal+IxbIFMn 1+XDevoK2baI81iqj/IroUVCwWe47fnxld8BT/EC9ezEauD55k8e992KahwHf5JsM2hr jjOqlA3p9N48JV7BPijfmBAG67XkrmByY7QgImR36ILDBBjSbBxu2AcNucj7zl5mkAgP 6du3c6H9i5zIHFN1CLbI1MCiAoxDb1wVgzjhWSjkrKv4bN23CGO4VJO9c211BIV1IDn0 fc8AHv9r5JLFLeUBIWQTMC1NX8blTvLkeXQWpQDHCxS/nk+lJ+8yzDcJO3HSx5t8C8cw LeRA== X-Forwarded-Encrypted: i=1; AJvYcCWJbx59faRqX9b1zHQ6jXqndHMiyNd5RxLH2vb6Klh3kJBzw2j7eW6wJUq2C/sixzq2DRWNY7bUcyuewsbgoILf@lists.infradead.org X-Gm-Message-State: AOJu0Yw/n8qZwRoE9RU0rQHs6SrvsvYb9Jpr45cHaMai4PfLokoS5/oo K4IQJ8LqTg/8ZrnjwLPOVos0+iY50au6KY4rdsQWNAEdSzFsCyYpADyGbBRHQE5r4jfcIKOKijF hrb9uQ77DNfVu2DiU7lxrUD3JqGFjPzDFAdlus99wxjxP7aCxH1u/7akw1mBbY18Ol7MiwR79 X-Received: by 2002:a17:90b:e8b:b0:2d8:a672:1869 with SMTP id 98e67ed59e1d1-2daffd0bf58mr7417929a91.32.1725839636445; Sun, 08 Sep 2024 16:53:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGnXND6LKMPjrt0KKzz0KFo7SeRMM4AcKKnPnTFybXe+F72ZSBtfd/QDe02gIE0c1lTfUVnXA== X-Received: by 2002:a17:90b:e8b:b0:2d8:a672:1869 with SMTP id 98e67ed59e1d1-2daffd0bf58mr7417893a91.32.1725839635739; Sun, 08 Sep 2024 16:53:55 -0700 (PDT) Received: from [192.168.68.54] ([103.210.27.31]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2db049873b0sm3208257a91.47.2024.09.08.16.53.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 08 Sep 2024 16:53:54 -0700 (PDT) Message-ID: <8ed3b6da-8bd2-4c98-9364-8b14c1baae7f@redhat.com> Date: Mon, 9 Sep 2024 09:53:46 +1000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 07/19] arm64: rsi: Add support for checking whether an MMIO is protected To: Steven Price , kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Suzuki K Poulose , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni , Shanker Donthineni , Alper Gun References: <20240819131924.372366-1-steven.price@arm.com> <20240819131924.372366-8-steven.price@arm.com> <8a675a19-52c1-43c7-b560-fbadce0c5145@arm.com> From: Gavin Shan In-Reply-To: <8a675a19-52c1-43c7-b560-fbadce0c5145@arm.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240908_165402_604812_8B62F0F5 X-CRM114-Status: GOOD ( 28.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 9/6/24 11:55 PM, Steven Price wrote: > On 06/09/2024 05:32, Gavin Shan wrote: >> On 8/19/24 11:19 PM, Steven Price wrote: >>> From: Suzuki K Poulose >>> >>> On Arm CCA, with RMM-v1.0, all MMIO regions are shared. However, in >>> the future, an Arm CCA-v1.0 compliant guest may be run in a lesser >>> privileged partition in the Realm World (with Arm CCA-v1.1 Planes >>> feature). In this case, some of the MMIO regions may be emulated >>> by a higher privileged component in the Realm world, i.e, protected. >>> >>> Thus the guest must decide today, whether a given MMIO region is shared >>> vs Protected and create the stage1 mapping accordingly. On Arm CCA, this >>> detection is based on the "IPA State" (RIPAS == RIPAS_IO). Provide a >>> helper to run this check on a given range of MMIO. >>> >>> Also, provide a arm64 helper which may be hooked in by other solutions. >>> >>> Signed-off-by: Suzuki K Poulose >>> Signed-off-by: Steven Price >>> --- >>> New patch for v5 >>> --- >>>   arch/arm64/include/asm/io.h       |  8 ++++++++ >>>   arch/arm64/include/asm/rsi.h      |  3 +++ >>>   arch/arm64/include/asm/rsi_cmds.h | 21 +++++++++++++++++++++ >>>   arch/arm64/kernel/rsi.c           | 26 ++++++++++++++++++++++++++ >>>   4 files changed, 58 insertions(+) [...] >>> diff --git a/arch/arm64/kernel/rsi.c b/arch/arm64/kernel/rsi.c >>> index e968a5c9929e..381a5b9a5333 100644 >>> --- a/arch/arm64/kernel/rsi.c >>> +++ b/arch/arm64/kernel/rsi.c >>> @@ -67,6 +67,32 @@ void __init arm64_rsi_setup_memory(void) >>>       } >>>   } >>>   +bool arm64_rsi_is_protected_mmio(phys_addr_t base, size_t size) >>> +{ >>> +    enum ripas ripas; >>> +    phys_addr_t end, top; >>> + >>> +    /* Overflow ? */ >>> +    if (WARN_ON(base + size < base)) >>> +        return false; >>> + >>> +    end = ALIGN(base + size, RSI_GRANULE_SIZE); >>> +    base = ALIGN_DOWN(base, RSI_GRANULE_SIZE); >>> + >>> +    while (base < end) { >>> +        if (WARN_ON(rsi_ipa_state_get(base, end, &ripas, &top))) >>> +            break; >>> +        if (WARN_ON(top <= base)) >>> +            break; >>> +        if (ripas != RSI_RIPAS_IO) >>> +            break; >>> +        base = top; >>> +    } >>> + >>> +    return (size && base >= end); >>> +} >> >> I don't understand why @size needs to be checked here. Its initial value >> taken from the input parameter should be larger than zero and its value >> is never updated in the loop. So I'm understanding @size is always larger >> than zero, and the condition would be something like below if I'm correct. > > Yes you are correct. I'm not entirely sure why it was written that way. > The only change dropping 'size' as you suggest is that a zero-sized > region is considered protected. But I'd consider it a bug if this is > called with size=0. I'll drop 'size' here. > The check 'size == 0' could be squeezed to the overflow check if you agree. /* size == 0 or overflow */ if (WARN_ON(base + size) <= base) return false; : return (base >= end); >>        return (base >= end);     /* RSI_RIPAS_IO returned for all >> granules */ >> >> Another issue is @top is always zero with the latest tf-rmm. More details >> are provided below. > > That suggests that you are not actually using the 'latest' tf-rmm ;) > (for some definition of 'latest' which might not be obvious!) > >>>From the cover letter: > >> As mentioned above the new RMM specification means that corresponding >> changes need to be made in the RMM, at this time these changes are still >> in review (see 'topics/rmm-1.0-rel0-rc1'). So you'll need to fetch the >> changes[3] from the gerrit instance until they are pushed to the main >> branch. >> >> [3] https://review.trustedfirmware.org/c/TF-RMM/tf-rmm/+/30485 > > Sorry, I should probably have made this much more prominent in the cover > letter. > > Running something like... > > git fetch https://git.trustedfirmware.org/TF-RMM/tf-rmm.git \ > refs/changes/85/30485/11 > > ... should get you the latest. Hopefully these changes will get merged > to the main branch soon. > My bad. I didn't check the cover letter in time. With this specific TF-RMM branch, I'm able to boot the guest with cca/host-v4 and cca/guest-v5. However, there are messages indicating unhandled system register accesses, as below. # ./start.sh Info: # lkvm run -k Image -m 256 -c 2 --name guest-152 Info: Removed ghost socket file "/root/.lkvm//guest-152.sock". [ rmm ] SMC_RMI_REALM_CREATE 882860000 880856000 > RMI_SUCCESS [ rmm ] SMC_RMI_REC_AUX_COUNT 882860000 > RMI_SUCCESS 10 [ rmm ] SMC_RMI_REC_CREATE 882860000 88bdc5000 88bdc4000 > RMI_SUCCESS [ rmm ] SMC_RMI_REC_CREATE 882860000 88bdd7000 88bdc4000 > RMI_SUCCESS [ rmm ] SMC_RMI_REALM_ACTIVATE 882860000 > RMI_SUCCESS [ rmm ] Unhandled write S2_0_C0_C2_2 [ rmm ] Unhandled write S3_3_C9_C14_0 [ rmm ] SMC_RSI_VERSION 10000 > RSI_SUCCESS 10000 10000 [ rmm ] SMC_RSI_REALM_CONFIG 82b2b000 > RSI_SUCCESS [ rmm ] SMC_RSI_IPA_STATE_SET 80000000 90000000 1 0 > RSI_SUCCESS 90000000 0 [ rmm ] SMC_RSI_IPA_STATE_GET 1000000 1001000 > RSI_SUCCESS 1001000 0 : [ 1.835570] DMA: preallocated 128 KiB GFP_KERNEL|GFP_DMA32 pool for atomic allocations [ 1.865993] audit: initializing netlink subsys (disabled) [ 1.891218] audit: type=2000 audit(0.492:1): state=initialized audit_enabled=0 res=1 [ 1.899066] thermal_sys: Registered thermal governor 'step_wise' [ 1.920869] thermal_sys: Registered thermal governor 'power_allocator' [ 1.944151] cpuidle: using governor menu [ 1.988588] hw-breakpoint: found 16 breakpoint and 16 watchpoint registers. [ rmm ] Unhandled write S2_0_C0_C0_5 [ rmm ] Unhandled write S2_0_C0_C0_4 [ rmm ] Unhandled write S2_0_C0_C1_5 [ rmm ] Unhandled write S2_0_C0_C1_4 [ rmm ] Unhandled write S2_0_C0_C2_5 : [ rmm ] Unhandled write S2_0_C0_C13_6 [ rmm ] Unhandled write S2_0_C0_C14_7 [ rmm ] Unhandled write S2_0_C0_C14_6 [ rmm ] Unhandled write S2_0_C0_C15_7 [ rmm ] Unhandled write S2_0_C0_C15_6 Thanks, Gavin