Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp9362lql; Fri, 12 Apr 2024 01:45:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWtN8uRxzx8+RpovbRp55K3z7mNMTI9T35+CrXUSKPRdqSgvN5IHJqHiCKwkYtReTvkhHETN+aIs1T13HOZoY2QvKbcuD7G6NavNxVFFg== X-Google-Smtp-Source: AGHT+IHqpbLbQZiD10DWkDEuVGWdrq3ClLrtgpchWum5zT1bzOO7wGD9pfR1BTDbY+riLYammsmb X-Received: by 2002:ac8:5847:0:b0:436:a18c:7e5d with SMTP id h7-20020ac85847000000b00436a18c7e5dmr225462qth.0.1712911502479; Fri, 12 Apr 2024 01:45:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712911502; cv=pass; d=google.com; s=arc-20160816; b=LbFplabmtadeN+siWlgl7O+djAOIgHlVlYYX//JUkEIVwmCKs6SZGcT44t9NuXE5kB wMeGfiRfaTfC3cC3s0q34BW/KI4TlHy9MNRy4CPNP7nt7ViYqL3zxTcL9MzKeqRsQCfj wkeoRrQDCOL1H0usxo1S31nDteQW6njYHOOzPHBjb6dcwvo+tgeKtKIzuwydPPzO2gWw 9B651QnCddU3V6kaOJzk9blTIXW0pj5/Hy7KWDC6drM6ipc0EPU1BAdHFQ4lKlX7KLkc DsYAAXHFeY9Dy41N5DUl3wwbKx8/xl7+FdVFufz2M6ZBcCo4Zk/ysIpEgdKzk0u5RYvN FWpg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=Mk2t0IbgGgKS3z+46+RnX3v/iQLVCqZ050O8ECXmza0=; fh=NDCPdPn2hiqHaiIRDYQAzsW9PK20CTia4nECGof6enU=; b=h4GenCOandBlp8HaFkfEVCAIPNhaBwV4AaW1XAWdZHDKlrqniXKmBQ2mwZ7sffaGwZ Vj/Q0YcDR53lFueJLnA+EuFcN+jIfgHfLyRoEALHZDrN9bzO93i7ZKtMG5rcChPrp5Qn ntHLi39lkh0Z8ChsTAhTtffK4sfgrLU2dSS/QPE1/QmMMsDruHJj+Ctzdim3c2aFBDNh oNtkEQVWP8rsgtFMrL3b0GsbCqOHOVBmUCX8Af/Hs22qHwZIaJtxe/INUiYypSindQl9 rq7F3EjdtpKaDhj/C5n86bO18rEowbzdMmq81WApk1nv3tPrRsMEOW4rvaHVSMF11E4Y 2Yiw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-142260-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142260-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id e15-20020ac85dcf000000b00434f22928c9si3231385qtx.390.2024.04.12.01.45.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 01:45:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142260-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-142260-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142260-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0ECA41C233C9 for ; Fri, 12 Apr 2024 08:45:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BC53856443; Fri, 12 Apr 2024 08:42:41 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8C90155C3B; Fri, 12 Apr 2024 08:42:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712911361; cv=none; b=UOWYIwu52C0/UiXYmhf2w/qmM/41Bt7tpWmQxADjtyWp5oMsxvReZd49MeM5+Wv9GokAgntAh9g40GDFKtag6pvCYxvntwt9GlwcCDXdh5b7YaWUThtnIda2+w80xdX2fy52O3xft+SRMf8VZ/K8tM2tlDLcXnt/buqHeE1gJ1o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712911361; c=relaxed/simple; bh=agngeU8huUmhG9g9+C9VjdJl0iGtBw5GtJfVp2YcLdU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=f5qnJllfBTpMpZTTOqH6tkchtKzV/rs+MwYww/xPOD8UgFhYj5tawdR3tbFnzdyB0GN0zmb0nHP/vdOM6HC7t3pCyZ+9cnJcYVLhagftPe3imDiNyT1pSn2ANI6zCbMj18d/c2e35vOrWlImullIaMRMEpGh+To3ePfZ+FNy1Cc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 74209339; Fri, 12 Apr 2024 01:43:07 -0700 (PDT) Received: from e112269-lin.cambridge.arm.com (e112269-lin.cambridge.arm.com [10.1.194.51]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1CDD63F6C4; Fri, 12 Apr 2024 01:42:36 -0700 (PDT) From: Steven Price To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Steven Price , 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 Subject: [PATCH v2 07/14] arm64: Make the PHYS_MASK_SHIFT dynamic Date: Fri, 12 Apr 2024 09:42:06 +0100 Message-Id: <20240412084213.1733764-8-steven.price@arm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240412084213.1733764-1-steven.price@arm.com> References: <20240412084056.1733704-1-steven.price@arm.com> <20240412084213.1733764-1-steven.price@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Make the PHYS_MASK_SHIFT dynamic for Realms. This is only is required for masking the PFN from a pte entry. Elsewhere, we could still use the PA bits configured by the kernel. So, this patch: -> renames PHYS_MASK_SHIFT -> MAX_PHYS_SHIFT as supported by the kernel -> Makes PHYS_MASK_SHIFT -> Dynamic value of the (I)PA bit width -> For a realm: reduces phys_mask_shift if the RMM reports a smaller configured size for the guest. Co-developed-by: Suzuki K Poulose Signed-off-by: Suzuki K Poulose Signed-off-by: Steven Price --- arch/arm64/include/asm/kvm_arm.h | 2 +- arch/arm64/include/asm/pgtable-hwdef.h | 4 ++-- arch/arm64/include/asm/pgtable.h | 5 +++++ arch/arm64/kernel/rsi.c | 5 +++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h index e01bb5ca13b7..9944aca348bd 100644 --- a/arch/arm64/include/asm/kvm_arm.h +++ b/arch/arm64/include/asm/kvm_arm.h @@ -398,7 +398,7 @@ * bits in PAR are res0. */ #define PAR_TO_HPFAR(par) \ - (((par) & GENMASK_ULL(52 - 1, 12)) >> 8) + (((par) & GENMASK_ULL(MAX_PHYS_MASK_SHIFT - 1, 12)) >> 8) #define ECN(x) { ESR_ELx_EC_##x, #x } diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index ef207a0d4f0d..90dc292bed5f 100644 --- a/arch/arm64/include/asm/pgtable-hwdef.h +++ b/arch/arm64/include/asm/pgtable-hwdef.h @@ -206,8 +206,8 @@ /* * Highest possible physical address supported. */ -#define PHYS_MASK_SHIFT (CONFIG_ARM64_PA_BITS) -#define PHYS_MASK ((UL(1) << PHYS_MASK_SHIFT) - 1) +#define MAX_PHYS_MASK_SHIFT (CONFIG_ARM64_PA_BITS) +#define MAX_PHYS_MASK ((UL(1) << PHYS_MASK_SHIFT) - 1) #define TTBR_CNP_BIT (UL(1) << 0) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index afdd56d26ad7..f5376bd567a1 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -39,6 +39,11 @@ #include #include +extern unsigned int phys_mask_shift; + +#define PHYS_MASK_SHIFT (phys_mask_shift) +#define PHYS_MASK ((1UL << PHYS_MASK_SHIFT) - 1) + #ifdef CONFIG_TRANSPARENT_HUGEPAGE #define __HAVE_ARCH_FLUSH_PMD_TLB_RANGE diff --git a/arch/arm64/kernel/rsi.c b/arch/arm64/kernel/rsi.c index b93252ed6fc5..159bc428c77b 100644 --- a/arch/arm64/kernel/rsi.c +++ b/arch/arm64/kernel/rsi.c @@ -12,6 +12,8 @@ struct realm_config __attribute((aligned(PAGE_SIZE))) config; unsigned long prot_ns_shared; EXPORT_SYMBOL(prot_ns_shared); +unsigned int phys_mask_shift = CONFIG_ARM64_PA_BITS; + DEFINE_STATIC_KEY_FALSE_RO(rsi_present); EXPORT_SYMBOL(rsi_present); @@ -62,5 +64,8 @@ void __init arm64_rsi_init(void) return; prot_ns_shared = BIT(config.ipa_bits - 1); + if (config.ipa_bits - 1 < phys_mask_shift) + phys_mask_shift = config.ipa_bits - 1; + static_branch_enable(&rsi_present); } -- 2.34.1