From patchwork Mon Oct 14 10:58:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13834700 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 682A3D1A443 for ; Mon, 14 Oct 2024 11:01:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA88F6B00BE; Mon, 14 Oct 2024 07:01:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E5A8E6B00BF; Mon, 14 Oct 2024 07:01:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD2E66B00C0; Mon, 14 Oct 2024 07:01:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id AAA336B00BE for ; Mon, 14 Oct 2024 07:01:10 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 49586ABC9B for ; Mon, 14 Oct 2024 11:00:55 +0000 (UTC) X-FDA: 82671915816.29.2751DEC Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf23.hostedemail.com (Postfix) with ESMTP id 0A8CD14002F for ; Mon, 14 Oct 2024 11:01:04 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728903480; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NJ0XCsdELuRevj5tw1yfqEQTo4IwlrxkOoKIOsf10K4=; b=6F5fSw5z6NU7OvBKZTcA4ZhY7aX7StClfp3xs7HnnPYeKc6AA9DNFgl64ymAGbB7U4XKvD OrO+AgYFwcwy9Qc2mTLmTb4tKARxJNsE80qfVHlpE/ole6zQoW+7bSHY7B5IJJ50NpkMyW ntQ3raGB7PBP2/vojEOEuSuvgqD7VAg= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728903480; a=rsa-sha256; cv=none; b=2U76wJQzgDLHyNA4/u+cfOlr8N4eDon4agLPKBKIw//ub82HNkeVdq9Vu1b2pt6Ema3f2Y 3ptUNsO6+Flw7mgQYr/2te3+AZUDGJRrw+ta8tcYTwU8lfiwEBecRSyIYTmDfdkeE+O4tu rmsU4ijVpemuZEQ4slw2ZE+bE4b03dA= 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 C7AA116F8; Mon, 14 Oct 2024 04:01:37 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8A33C3F51B; Mon, 14 Oct 2024 04:01:05 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , Anshuman Khandual , Ard Biesheuvel , Catalin Marinas , David Hildenbrand , Greg Marsden , Ivan Ivanov , Jens Wiklander , Kalesh Singh , Marc Zyngier , Mark Rutland , Matthias Brugger , Miroslav Benes , Will Deacon Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, op-tee@lists.trustedfirmware.org Subject: [RFC PATCH v1 32/57] optee: Remove PAGE_SIZE compile-time constant assumption Date: Mon, 14 Oct 2024 11:58:39 +0100 Message-ID: <20241014105912.3207374-32-ryan.roberts@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241014105912.3207374-1-ryan.roberts@arm.com> References: <20241014105514.3206191-1-ryan.roberts@arm.com> <20241014105912.3207374-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 0A8CD14002F X-Stat-Signature: 9q9rsnk39xfwqgnk8698njt1ksi9ct1d X-Rspam-User: X-HE-Tag: 1728903664-41309 X-HE-Meta: U2FsdGVkX1/RbUwuT54pExggmAa4PivHiuu+0i3BCjN/KnfFZ+WVE3OTjBr0sSB3dVxNqfFi2Pm+8+M7PUZZolCO7EaNtHuzJ6zmPIo1Bpm5lAuUD4PskvkxSUdxLpOxroMR6JA7wy//33e44yd081dOFmCQ0HwJ/KImqyJZx25xAHDAlSCrmcFbix/M0jTBiuBg1pp0+1d8Zea0k8/G4q9ZSh2XalxPSeTa5SkRCSrW+dcl6HuU7N9ovbmrdnN1YmFN6bAVjLPtq6+96JDLynd821XxkLEKyedQI7W0PuZ+EDdBhLp3lILhMHxqPXgcD0CSsbOIDUX/hb1flOz2ov6svRatH2kWlNdjC0JkRd6n4JMKl8yb7PZMwRJcnBYFGcSta1U56/APa4Cz2B34MJrdc3k8z1Fp60QPTnzr06F2EA/pBhbnnNbMjv6aZVjVmcTnwkNiAX7d5cwmHfNQCS/10OXY/Ld9h2S+yyhWW8HYp/UwUpDJiOVFQsEkvbIxiCuk+sOLqvxpG26NuzXyOfBkDxnMvo2xSV7b+EwnMGU52ju0M80BjGWEwB7WVl6Es2ggAUZYQ4R5iti9eIKMNjFAAjadYesoCitAiO3jE1VP6F04KsMIzVGlbO8nwWruPWx80tqU0QetzfZNuoBuLfeMpGDcoLIsxlNR/aQXXBFOH4LHhQNK0W+VH3kTYlSpvMsOvsY3QEz7eOU/Fd14CceokJonYKv7WArGRIzS9EnjrAC1tkEXTMToy4EgT8xu4XKaEcotxjELZAWaAchgiQn/y635uGutuXN+a55slZA7wqWCu0Yv0fUkvhc095YP5GhKO1e1No3uEiqNRVbpGnGlMd898RK3sbJn91NwFe1xRLfVNhqIDuv0ObNyPGpJ94doKXLjiESFiz1BwWCUc7VOhDcgxJ/tZjiQWW144sMRVWDMjvrnSx3bmDnblNyuhT+4L2yasadutglfva4 GoXB5+q1 xPuOhfp/c7juj9AuapxWBRQB0mqfp6yE2phiWnN7mZCv9bCZKfoqwBs8rB5Ud0W66s5ZdZamBYC8xWZOAadnI4z/udIadmnIEFHlMJSw7PHL6jvQhBJuJ2hs8aH8RoFCuwbJSaJ15y3lQ0OZMebR/Vm/S30DF1yDnwzynr4Vr7RYK6F1xFwebO6us4Wr0OTtr1xxRFFBDwXNSVj5VkPJAwOAQw9f1+jxIDQr7 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: To prepare for supporting boot-time page size selection, refactor code to remove assumptions about PAGE_SIZE being compile-time constant. Code intended to be equivalent when compile-time page size is active. Updated BUILD_BUG_ON() to test against limit. Refactored "struct optee_shm_arg_entry" to use a flexible array member for "map", since its length depends on PAGE_SIZE. Signed-off-by: Ryan Roberts --- ***NOTE*** Any confused maintainers may want to read the cover note here for context: https://lore.kernel.org/all/20241014105514.3206191-1-ryan.roberts@arm.com/ drivers/tee/optee/call.c | 7 +++++-- drivers/tee/optee/smc_abi.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/tee/optee/call.c b/drivers/tee/optee/call.c index 16eb953e14bb6..41bd7ace6606e 100644 --- a/drivers/tee/optee/call.c +++ b/drivers/tee/optee/call.c @@ -36,7 +36,7 @@ struct optee_shm_arg_entry { struct list_head list_node; struct tee_shm *shm; - DECLARE_BITMAP(map, MAX_ARG_COUNT_PER_ENTRY); + unsigned long map[]; }; void optee_cq_init(struct optee_call_queue *cq, int thread_count) @@ -271,6 +271,7 @@ struct optee_msg_arg *optee_get_msg_arg(struct tee_context *ctx, struct optee_shm_arg_entry *entry; struct optee_msg_arg *ma; size_t args_per_entry; + size_t entry_sz; u_long bit; u_int offs; void *res; @@ -293,7 +294,9 @@ struct optee_msg_arg *optee_get_msg_arg(struct tee_context *ctx, /* * No entry was found, let's allocate a new. */ - entry = kzalloc(sizeof(*entry), GFP_KERNEL); + entry_sz = struct_size(entry, map, + BITS_TO_LONGS(MAX_ARG_COUNT_PER_ENTRY)); + entry = kzalloc(entry_sz, GFP_KERNEL); if (!entry) { res = ERR_PTR(-ENOMEM); goto out; diff --git a/drivers/tee/optee/smc_abi.c b/drivers/tee/optee/smc_abi.c index 844285d4f03c1..005689380d848 100644 --- a/drivers/tee/optee/smc_abi.c +++ b/drivers/tee/optee/smc_abi.c @@ -418,7 +418,7 @@ static void optee_fill_pages_list(u64 *dst, struct page **pages, int num_pages, * code heavily relies on this assumption, so it is better be * safe than sorry. */ - BUILD_BUG_ON(PAGE_SIZE < OPTEE_MSG_NONCONTIG_PAGE_SIZE); + BUILD_BUG_ON(PAGE_SIZE_MIN < OPTEE_MSG_NONCONTIG_PAGE_SIZE); pages_data = (void *)dst; /*