From patchwork Mon Oct 14 10:58:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13834703 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 6E531D1A43B for ; Mon, 14 Oct 2024 11:01:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0061A6B0099; Mon, 14 Oct 2024 07:01:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF43B6B00C4; Mon, 14 Oct 2024 07:01:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D94356B00C5; Mon, 14 Oct 2024 07:01:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B7C9D6B00C3 for ; Mon, 14 Oct 2024 07:01:20 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DCA9680D98 for ; Mon, 14 Oct 2024 11:01:13 +0000 (UTC) X-FDA: 82671916236.28.B21FF6A Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf03.hostedemail.com (Postfix) with ESMTP id 957BB20007 for ; Mon, 14 Oct 2024 11:01:15 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf03.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728903563; a=rsa-sha256; cv=none; b=IYdr0F55T02dUsI+PBAU6EGFJyBh7b3SBHSr25Me664FOdZXkgsKUhuv0vVhQF+ck8B5B4 HSZ/59T3pqoKU589Y5YRRurVlkb+HDTCszXsat7F94aC1Khe+GyHhC/pgxKKgfSwYMS/Iw jrKvdqmSWVMLKQfa5jlitbqm9+pejo8= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf03.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728903563; 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=5o+gDL2mN3xapmdN2m55fCy14ysHc8+6na6uUa6irXM=; b=LeAMsFxqbCQ3RopKwCFmV/Opq6mmXSjbCnh7xYhv/Dk990vR41XNsN6CF3RJLISX2L5QUN 2XiDVngKs1uffhhUihSvFqle1lQ0PsGbvSy5G+/Nwy9EAoy9y+tZO6X59LLY+6IUzJzxtl 9xxLQYzM6VwQ5IMeDtMazjv5lSPEVJ0= 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 997AD16F8; Mon, 14 Oct 2024 04:01:47 -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 769A53F51B; Mon, 14 Oct 2024 04:01:14 -0700 (PDT) From: Ryan Roberts To: "Michael S. Tsirkin" , Andrew Morton , Anshuman Khandual , Ard Biesheuvel , Catalin Marinas , David Hildenbrand , Dominique Martinet , Eric Van Hensbergen , Greg Marsden , Ivan Ivanov , Jason Wang , Jens Axboe , Kalesh Singh , Latchesar Ionkov , Marc Zyngier , Mark Rutland , Matthias Brugger , Miroslav Benes , Will Deacon Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, v9fs@lists.linux.dev, virtualization@lists.linux.dev Subject: [RFC PATCH v1 35/57] virtio: Remove PAGE_SIZE compile-time constant assumption Date: Mon, 14 Oct 2024 11:58:42 +0100 Message-ID: <20241014105912.3207374-35-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: rspam12 X-Rspamd-Queue-Id: 957BB20007 X-Stat-Signature: pz1jwfz5ssye973gomzd7daisani34kh X-Rspam-User: X-HE-Tag: 1728903675-263350 X-HE-Meta: U2FsdGVkX1/2BK6jHZAAhJ+ugSaBaGSDBt323BbOgkHfKNXZd9TQOv/jALQjQz7H6o4+MlGeg3SGfdkdM47VVgbCiiY5f/jsJ2gUtZorffru8wAUp33rI1KjRZ8rKRcty0DCWhpmibtgvBQM61xXx7wpClAUmLiWjugRnDztVqJXwjnpmRUYzy7kuWddhi5t1HTFp1ZBnGQmg7jS0dFffGmWcNOh1u/WeEGyCOlBvOLtOpDFWpq/F6D0f2PIhhoKsG7TlYTDE9o3rtECvCSQDGHN6/8e5hrDOiKZdMk5WzhyGDQWfdr9cTwCUlET2Zn+SnPnDEK1PX/vbISnxkdm0tHrHJyPxmriZIDsojs4va27ionY7vokqNCcUsd9OvVH93qxQl7sGGY8TL3cQ+IfaMJyhoq8posFwgMiGxXlCE7/PNjxMhqf7Cz3uWztwN5h5yWrMMywAYrRLbDX1RlKuNwbR5YHtltcEqAeprmqGQxcygnJQ2rfPZfuxGShfot47/S2QU8pr4fgN3/DNF5WTkt2oGeySTThnVYfb88mgDsCT0dKtUoOTssumccEDHcjl9V4d5DR04lAZyCerkdngMjePCWlkVgGezxJePbFBZd4Ei5sbKr2WfAAyKsewTWm6Ljr+YFWNADcfz++vsJZJH4rTBjMRsYth26C+NJc7ak4S2RanqvR3Z8VdIsd6swGP4rsIIet6eO6DOojEH4aq6ll3uiaR0siF0wa4Rv4hQfgnDO94e5ykFQ235XF9vCh1gI9x3uJEBFwPWXNIULDqKqDL1JzDqMMuGHj2AszbL+mcnkjPNjSAA4Df6wovN9dJaFafVFMG0qIoVmNg15235QGib5CJl5YnznCOPfOwiFLS/0FvtLu9Jj9GhJccvLfDV1oenZUCPuVgdcunLxgCo87fvHSRSbDE79Cn6KxXIHMRO4GEQ657UIWvWTeE1G1DF8jgY6lww5MPjp020a yEyXFUQU IEF9DRBGBJFtsjCq+d2zP3mZr9CLuEp2oa7vldXT5QIEjyLCPVytXGjjBWbrs6eLRbtJlRq7Ryu8cD2Ne3RluSZm6IpW7CfnPiQHX8FiQewQ6rr1c0m5Q2q2BAb3LZnDdRiYUVoYaaF6nLrys/yrUBT04dZJfJ7QCPgzj6u6ZxmgBUbj49iLXPqjate4O7XqIMVL0EzcR/WkRNqqiZKYHKpsNeMY2CVTsWfRDBKSUU8pP8yKR7X43ToBN0QmpUMi2rldUET+rH5tJDcSNSYvvrod2Lw== 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 multiple BUILD_BUG_ON() instances to test against page size limits. Wrap global variables that are initialized with PAGE_SIZE derived values using DEFINE_GLOBAL_PAGE_SIZE_VAR() so their initialization can be deferred for boot-time page size builds. 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/block/virtio_blk.c | 2 +- drivers/virtio/virtio_balloon.c | 10 ++++++---- net/9p/trans_virtio.c | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 194417abc1053..8a8960b609bc9 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -899,7 +899,7 @@ static ssize_t serial_show(struct device *dev, int err; /* sysfs gives us a PAGE_SIZE buffer */ - BUILD_BUG_ON(PAGE_SIZE < VIRTIO_BLK_ID_BYTES); + BUILD_BUG_ON(PAGE_SIZE_MIN < VIRTIO_BLK_ID_BYTES); buf[VIRTIO_BLK_ID_BYTES] = '\0'; err = virtblk_get_id(disk, buf); diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 54469277ca303..3818d894bd212 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -25,6 +25,7 @@ * page units. */ #define VIRTIO_BALLOON_PAGES_PER_PAGE (unsigned int)(PAGE_SIZE >> VIRTIO_BALLOON_PFN_SHIFT) +#define VIRTIO_BALLOON_PAGES_PER_PAGE_MAX (unsigned int)(PAGE_SIZE_MAX >> VIRTIO_BALLOON_PFN_SHIFT) #define VIRTIO_BALLOON_ARRAY_PFNS_MAX 256 /* Maximum number of (4k) pages to deflate on OOM notifications. */ #define VIRTIO_BALLOON_OOM_NR_PAGES 256 @@ -138,7 +139,7 @@ static u32 page_to_balloon_pfn(struct page *page) { unsigned long pfn = page_to_pfn(page); - BUILD_BUG_ON(PAGE_SHIFT < VIRTIO_BALLOON_PFN_SHIFT); + BUILD_BUG_ON(PAGE_SHIFT_MIN < VIRTIO_BALLOON_PFN_SHIFT); /* Convert pfn from Linux page size to balloon page size. */ return pfn * VIRTIO_BALLOON_PAGES_PER_PAGE; } @@ -228,7 +229,7 @@ static void set_page_pfns(struct virtio_balloon *vb, { unsigned int i; - BUILD_BUG_ON(VIRTIO_BALLOON_PAGES_PER_PAGE > VIRTIO_BALLOON_ARRAY_PFNS_MAX); + BUILD_BUG_ON(VIRTIO_BALLOON_PAGES_PER_PAGE_MAX > VIRTIO_BALLOON_ARRAY_PFNS_MAX); /* * Set balloon pfns pointing at this page. @@ -1042,8 +1043,9 @@ static int virtballoon_probe(struct virtio_device *vdev) * host's base page size. However, it needs more work to report * that value. The hard-coded order would be fine currently. */ -#if defined(CONFIG_ARM64) && defined(CONFIG_ARM64_64K_PAGES) - vb->pr_dev_info.order = 5; +#if defined(CONFIG_ARM64) + if (PAGE_SIZE == SZ_64K) + vb->pr_dev_info.order = 5; #endif err = page_reporting_register(&vb->pr_dev_info); diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c index 0b8086f58ad55..25b8253011cec 100644 --- a/net/9p/trans_virtio.c +++ b/net/9p/trans_virtio.c @@ -786,7 +786,7 @@ static struct virtio_driver p9_virtio_drv = { .remove = p9_virtio_remove, }; -static struct p9_trans_module p9_virtio_trans = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR(struct p9_trans_module, p9_virtio_trans, { .name = "virtio", .create = p9_virtio_create, .close = p9_virtio_close, @@ -804,7 +804,7 @@ static struct p9_trans_module p9_virtio_trans = { .pooled_rbuffers = false, .def = 1, .owner = THIS_MODULE, -}; +}); /* The standard init function */ static int __init p9_virtio_init(void)