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 BC056CD484F for ; Wed, 4 Sep 2024 14:50:08 +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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=j6kEIYFtkOtx+DJY9n3gGx8oC/72d34oJtC4eMa+2Jo=; b=t7YKV8CiPYfs0/cGx8Quy95wl2 TfW6UCD/Cm2y1BuXMFSOB4A0F60Oo86E7uCmL1c+MIelUr99mjKZfnTzNsoIam1WvXhubowKpTD22 t0YC6/klzkjU0koSWxYtChUacChT+a7H0Uosd1+Y8B2vhzeAtxmkey1PW+myWIv50i0rA+H24iih5 NM/zNjbEY/aHlEnr+IbCQKi557fa4OiakDsiUFbj/AVNc3zdzp4/xw+mozTsQ6Ru6nHkaD7RNpP37 aFeENZ/dPiROUGNR7pyXAaJc09/1OYlyLrU7FpUPzUflH8BkiNqIONIq+7O+Z5NcwjJpyr1hJ4B2F X14cgGwA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slrKW-00000004rRm-1n9Z; Wed, 04 Sep 2024 14:49:56 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slrIk-00000004r0w-0KvW for linux-arm-kernel@lists.infradead.org; Wed, 04 Sep 2024 14:48:07 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-42bbd16fcf2so47684375e9.2 for ; Wed, 04 Sep 2024 07:48:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725461283; x=1726066083; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=j6kEIYFtkOtx+DJY9n3gGx8oC/72d34oJtC4eMa+2Jo=; b=mczUmaPVAvvQtmdVKLRNEmNVkH/kG4yG7M2fwdOHzUlHKoAZDNoLy9ZCSkvzdniDzG RJoH04QCAWaiN22FBkzWVVw0bvvEAJjzxPQRRx/kbSDuXbtBOud0/u3GE/LMYLNE99as 61nX653gcceWuHliv4uvSIwuzTR3xFDuNqYGQbtUwOGvDiAOKPEMBgaM4OPq7Qc6sStF weWmuMZqoQeUzMPLPSCp/LdZG7VMA4V/0cdltQoZO1rx2HefJp1IwvZUcyWgaVKpnkJS zq1vYG3OhgKF5VD7C5I4trwuLWgQtVayx8niJMrhDEpbfrnVwnkK6nenxrYd5qWdEVup A30w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725461283; x=1726066083; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=j6kEIYFtkOtx+DJY9n3gGx8oC/72d34oJtC4eMa+2Jo=; b=vQHA3NyfZtK1czKzRfHYh7Y+m2lCA6gqQMgHP3M3/6Me2MIEUleMx1+iWt8RcBa+XR RO0hriyNYA/UIW0HncMiA/cvzcZwU0ZKMlOvrolKZiu0ALvy3HcJ45JGb47RX/dHVpK2 1sDVFwLJ/6fsKXf9M31pZ6HdYoVP+fQKirry/BPPEpb5aSdyo3/v6sWOx6EmDwSCo4/9 M7DiAguYRUtKTEGTFoGdQoB9Pa2dy9tl/3jWpX6CV0TCXrw0TqZ24fAhTBGVLO48vQ0m KjBWlPmbNnD2xUgN6OR21oksUEi8CzfqhfvijkdgZuzeIDm1xN4HNA0MdOzXFILzjZR6 9A5A== X-Forwarded-Encrypted: i=1; AJvYcCUoAz2aFarkpqH+6JMrdhIEB3FAVwndKIAgoAsiC+7CqMfApiGw/vlbXBzqd7NTpbBAuAdNwT0ukvCKpU/Sus9a@lists.infradead.org X-Gm-Message-State: AOJu0Yy+Rvy3tOelmdp6v3zF6UED6hsSKPw8RA1cv1L7FxGxqu5gVZjn 4poTa3q/HjRx2WvYZAlkhY9OrUJ1Ye3CLWFSOhx3jBj3fDxPH5HazHkDZPIbK/E= X-Google-Smtp-Source: AGHT+IHKZyt11Lslz0HlasHPTxHt7BSYAR0Jjt79ONBZBuyaQ3ymGqrpolN3WJVQPOJE6wYCFvw0hQ== X-Received: by 2002:a05:600c:3b8e:b0:426:616e:db8d with SMTP id 5b1f17b1804b1-42bb01b556bmr164929245e9.15.1725461282171; Wed, 04 Sep 2024 07:48:02 -0700 (PDT) Received: from myrica ([2.221.137.100]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb01d300csm218202355e9.15.2024.09.04.07.48.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 07:48:01 -0700 (PDT) Date: Wed, 4 Sep 2024 15:48:21 +0100 From: Jean-Philippe Brucker To: Steven Price 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 Subject: Re: [PATCH v4 21/43] arm64: RME: Runtime faulting of memory Message-ID: <20240904144821.GA223966@myrica> References: <20240821153844.60084-1-steven.price@arm.com> <20240821153844.60084-22-steven.price@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240821153844.60084-22-steven.price@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_074806_171269_2CBD2AB2 X-CRM114-Status: GOOD ( 23.81 ) 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 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() 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))) {