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 E1420CD4853 for ; Wed, 4 Sep 2024 16:06: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=0Pv4KsoHfWy/mjB0kj65QhoE+iHOu+eKmGElI49BDS4=; b=XRTJ0F8tXKucAyuS8aNOYq6KIE RkUhE88l7AOWGvn0iTdD28TaO2yl8cL+OIiPxw/5FONlfxGaAkSm31JnV4Wjz3Pm5aeFChO3OScRW N8pHIY/uIfU/r5S9hOaVS8e+TGhcto3+OTo6VxWeYI2TBGU4Kb+XwJ6A2XMpiGXBeOlKfnPLjd+KU K5M5h2Q4hT45rvL1/15edadjjjoviIIvGoYwvEwgq/C4T3+gA4I7K9b+Q6Kg/lQPIUMydRlzr9uPu IuDcG4l1xGBlPeTaFeOB8oMqRPAjDtqlkiWOs2+NdAmZOeZdTZiNGkf+ZgM/IDbI7ZXN4jBemx6vF gIu9CtUw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slsWK-00000005AZg-13sE; Wed, 04 Sep 2024 16:06:12 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slsQE-000000058aM-0uIL for linux-arm-kernel@lists.infradead.org; Wed, 04 Sep 2024 15:59:55 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0D8F9FEC; Wed, 4 Sep 2024 09:00:18 -0700 (PDT) Received: from [10.57.75.163] (unknown [10.57.75.163]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 671763F73B; Wed, 4 Sep 2024 08:59:47 -0700 (PDT) Message-ID: <95d8bdc8-95f2-4694-aa9c-b73811ecd1ad@arm.com> Date: Wed, 4 Sep 2024 16:59:45 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 21/43] arm64: RME: Runtime faulting of memory To: Jean-Philippe Brucker Cc: kvm@vger.kernel.org, kvmarm@lists.linux.dev, 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 , Gavin Shan , Shanker Donthineni , Alper Gun References: <20240821153844.60084-1-steven.price@arm.com> <20240821153844.60084-22-steven.price@arm.com> <20240904144821.GA223966@myrica> From: Steven Price Content-Language: en-GB In-Reply-To: <20240904144821.GA223966@myrica> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_085954_380708_30F5EF37 X-CRM114-Status: GOOD ( 20.06 ) 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 04/09/2024 15:48, Jean-Philippe Brucker wrote: > On Wed, Aug 21, 2024 at 04:38:22PM +0100, Steven Price wrote: >> diff --git a/arch/arm64/kvm/rme.c b/arch/arm64/kvm/rme.c >> index 2c4e28b457be..337b3dd1e00c 100644 >> --- a/arch/arm64/kvm/rme.c >> +++ b/arch/arm64/kvm/rme.c >> @@ -627,6 +627,181 @@ static int fold_rtt(struct realm *realm, unsigned long addr, int level) >> return 0; >> } >> >> +static phys_addr_t rtt_get_phys(struct realm *realm, struct rtt_entry *rtt) >> +{ >> + bool lpa2 = realm->params->flags & RMI_REALM_PARAM_FLAG_LPA2; > > At this point realm->params is NULL, cleared by kvm_create_realm() Ah, indeed so. Also LPA2 isn't yet supported (we have no way of setting that flag). Since this code is only called for block mappings (also not yet supported) that explains why I've never seen the issue. Thanks, Steve > Thanks, > Jean > >> + >> + if (lpa2) >> + return rtt->desc & GENMASK(49, 12); >> + return rtt->desc & GENMASK(47, 12); >> +} >> + >> +int realm_map_protected(struct realm *realm, >> + unsigned long base_ipa, >> + struct page *dst_page, >> + unsigned long map_size, >> + struct kvm_mmu_memory_cache *memcache) >> +{ >> + phys_addr_t dst_phys = page_to_phys(dst_page); >> + phys_addr_t rd = virt_to_phys(realm->rd); >> + unsigned long phys = dst_phys; >> + unsigned long ipa = base_ipa; >> + unsigned long size; >> + int map_level; >> + int ret = 0; >> + >> + if (WARN_ON(!IS_ALIGNED(ipa, map_size))) >> + return -EINVAL; >> + >> + switch (map_size) { >> + case PAGE_SIZE: >> + map_level = 3; >> + break; >> + case RME_L2_BLOCK_SIZE: >> + map_level = 2; >> + break; >> + default: >> + return -EINVAL; >> + } >> + >> + if (map_level < RME_RTT_MAX_LEVEL) { >> + /* >> + * A temporary RTT is needed during the map, precreate it, >> + * however if there is an error (e.g. missing parent tables) >> + * this will be handled below. >> + */ >> + realm_create_rtt_levels(realm, ipa, map_level, >> + RME_RTT_MAX_LEVEL, memcache); >> + } >> + >> + for (size = 0; size < map_size; size += PAGE_SIZE) { >> + if (rmi_granule_delegate(phys)) { >> + struct rtt_entry rtt; >> + >> + /* >> + * It's possible we raced with another VCPU on the same >> + * fault. If the entry exists and matches then exit >> + * early and assume the other VCPU will handle the >> + * mapping. >> + */ >> + if (rmi_rtt_read_entry(rd, ipa, RME_RTT_MAX_LEVEL, &rtt)) >> + goto err; >> + >> + /* >> + * FIXME: For a block mapping this could race at level >> + * 2 or 3... currently we don't support block mappings >> + */ >> + if (WARN_ON((rtt.walk_level != RME_RTT_MAX_LEVEL || >> + rtt.state != RMI_ASSIGNED || >> + rtt_get_phys(realm, &rtt) != phys))) { >