Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp185159lqr; Wed, 5 Jun 2024 03:00:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVRCqabws4s1NqQhXSZw1UnZ3SW1ELMCNPpjR6ma1lxbLtkR0/TeQg2WLAo+FGKr42WETB1C7FTCOfw5cu8WeKz+ddskLI2GnE6xN6PFg== X-Google-Smtp-Source: AGHT+IEPLVGV0SAXHhGezZ16k6OyuOK4ylSg6shgVPVR0wYEvRdibJwkWGNLVyvs6g15O4P+UrPJ X-Received: by 2002:a17:903:32c2:b0:1f6:70b7:2f80 with SMTP id d9443c01a7336-1f6a5a05278mr23781015ad.7.1717581619882; Wed, 05 Jun 2024 03:00:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717581619; cv=pass; d=google.com; s=arc-20160816; b=DDwq3jykOjGwdnps7fhcYtyb+/CYo8Rvmsqhca3arBDXxkFI0sO/w0oIOnFdius0A1 9dCg4JZImnImYQdhO7THQ0SuWZnzOwgufLND4o8DAdDm5D0+U7CAQm23mqR57C/CEq8A 71MIUs11Ubi4BIEhyjaaz8a/u343w+WMV3a1cpA0k4OaOfD9L3DI2cLHLMhmTOLf/7Jl kTXZ2I2WmZubVC8FGFhTN1fF+L/K0Irn8xohcMauXCLMPJjluvWYMezE+r3OGmYAuyrr pz7sUEq5QOqE/ml3v+CdCId8F2/quZffj9nt8i/xIBrSX3IVVCOBplGf+Xe4aNImt4hT VUjA== 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=BT6RawGsNFUBl4y6ZIuz/reLVG3h7mf/BKLXpuX7JpI=; fh=NDCPdPn2hiqHaiIRDYQAzsW9PK20CTia4nECGof6enU=; b=XygG+XLW2chvmcNH972vH6P6ddtsiifxyjgz7mUPX/Zr3z8BeCU+xSB1E7d5zloG6l T2Sit2Rkrf9FjKdqDjarjgv6Qn0LplbLbuUtj5r4rU+nsc4bCz2Uw4N0Y5Q5HVjKQZFg 1O+7dImBlKJCBbyX4/DdwcxXv2cpoQh+eN6TAiXIqMHL1FViiLB9TR/07kZfg7021iZt dWA0swl9Zn2GI6ZCBKyAyEXB4zLe1hSpwojsDDwXB0ZqxfQsm3LdcgNue05rUJ2cFH5g owpStoGRKMKqWuIvlg+mErEDIw8JF2Ct4h4GpGVQO8TTgWiH32ILE+mGi3ziUoPBjYUL 8jFw==; 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-202106-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202106-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f632361fedsi30231555ad.167.2024.06.05.03.00.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 03:00:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202106-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; 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-202106-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202106-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 2FF2AB228EA for ; Wed, 5 Jun 2024 09:33:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 25D24194137; Wed, 5 Jun 2024 09:30:51 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DE641372; Wed, 5 Jun 2024 09:30:47 +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=1717579850; cv=none; b=tRHSJVnb1yC9phhagHxo/nEa4S8npEuPIFf9mAOk2emy+LultuAFulmuNNIu/f0LBBveV5h59fFEgOPWeFXpRzADUMSnamxbovoRpyIPGAJIZFfTcsGE6HfS3vNNgv5V17tqxcCK5oitJ40wNw7SLyHAAgGANmrnAwEDfQ+9abY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717579850; c=relaxed/simple; bh=2VO7wpZijFGEkNF/TLuURVm90HyMHYlnBv5KYkYE97Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kpR3o3b/5hj+zjA8RL8/5HdSNvAVngOXy5XjInc10R5YHDRQ1sIPeZl+BcMXidxoylPw+J/Zon7PKZrOyH9DAFjhPn466Kkgj3m/j+49jRuCWV+Lrfec2PUh9bQh0q0T/nN9UyhjCkaSw19zxY76IrnWoRCJxSCWjRcR5y2ET9c= 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 EDF28DA7; Wed, 5 Jun 2024 02:31:11 -0700 (PDT) Received: from e122027.arm.com (unknown [10.57.39.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3A78B3F792; Wed, 5 Jun 2024 02:30:44 -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 v3 07/14] arm64: Make the PHYS_MASK_SHIFT dynamic Date: Wed, 5 Jun 2024 10:29:59 +0100 Message-Id: <20240605093006.145492-8-steven.price@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605093006.145492-1-steven.price@arm.com> References: <20240605093006.145492-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. For a realm phys_mask_shift is reduced 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 --- v3: Drop the MAX_PHYS_MASK{,_SHIFT} definitions as they are no longer needed. --- arch/arm64/include/asm/pgtable-hwdef.h | 6 ------ arch/arm64/include/asm/pgtable.h | 5 +++++ arch/arm64/kernel/rsi.c | 5 +++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index 9943ff0af4c9..2e3af0693bd8 100644 --- a/arch/arm64/include/asm/pgtable-hwdef.h +++ b/arch/arm64/include/asm/pgtable-hwdef.h @@ -203,12 +203,6 @@ */ #define PTE_S2_MEMATTR(t) (_AT(pteval_t, (t)) << 2) -/* - * Highest possible physical address supported. - */ -#define PHYS_MASK_SHIFT (CONFIG_ARM64_PA_BITS) -#define 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 f8efbc128446..11d614d83317 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 d34e05b339ae..c5c03e8e341a 100644 --- a/arch/arm64/kernel/rsi.c +++ b/arch/arm64/kernel/rsi.c @@ -12,6 +12,8 @@ struct realm_config 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); @@ -72,6 +74,9 @@ 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