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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D225D21262 for ; Thu, 17 Oct 2024 09:10:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 09ED56B007B; Thu, 17 Oct 2024 05:10:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 04E476B0082; Thu, 17 Oct 2024 05:10:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E58866B0083; Thu, 17 Oct 2024 05:10:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C801F6B007B for ; Thu, 17 Oct 2024 05:10:06 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D9CC441189 for ; Thu, 17 Oct 2024 09:09:59 +0000 (UTC) X-FDA: 82682521824.20.13FB503 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf05.hostedemail.com (Postfix) with ESMTP id 5EBE810001A for ; Thu, 17 Oct 2024 09:09:46 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=s6+o1hRI; spf=pass (imf05.hostedemail.com: domain of cassel@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=cassel@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729156156; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=qOl5hV0aaLBplTs3iQXUPrJKzqx6zNsFx9SxM0UpUu0=; b=Nw+ygqDkzyR1aG/iSsa7Np0PLj9eBfB2vR+muXRfxAIiH1oqluAN3wMMEWXsVZI3Pw3tCM zbKwk+5uXrVBMuMazCEsNzhC2uOs/StXPu73vm1Esc64GynIFojgOmMCldxEjRnsU/ul4p D9sjg2scBs/AA/dzvdzIo4E4CpRPv6I= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=s6+o1hRI; spf=pass (imf05.hostedemail.com: domain of cassel@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=cassel@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729156156; a=rsa-sha256; cv=none; b=rl85MoaorOTXXQGGWwHG7djI13Ul//+55+2uG2y9NEe8FmuqKq2qlams4491IXT4Szn0Pe sJYXhCzYhNxqnY545AHLbNTIV+E2+6y6MykB1IvD4eo+yGZw0jDbMVvt9Eck3ZApBAupHS fLKK3gqwSUK6ezassZfXkpyHIUKq/M4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 82C4FA43A54; Thu, 17 Oct 2024 09:09:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D52AC4CEC3; Thu, 17 Oct 2024 09:09:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729156203; bh=DMcRV7qpaGp/pdog8ySpOqnvsEfxt/xtWnwiKVscW/Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=s6+o1hRIeBLlFbwcnGqlPWnptVLlqXRvpmUZ1deTnQTpiQ9+my5cvTv441B9ex+WU BKmF2pnbu9r4nw840QVovROLQchDodEZt+XIOZVIgY0YQcXq7HPWnooQRQ9cjktl0E vCZdfGp6Z316Gaj1f3ZcrTHxHQXz82HJxMrjeNWOkvJPpGQ+lT+4bgIhI5JppBXAcZ yg14wDiCjaeERAP8ycJkJu4sZJlB0xAphAbVWykrR9ELhS2AuzgUA86nEDJvaTznfK HsUiqDVs8VdiYthyxWAF/T7fy5XqKp2RwypV1vKHAdGRuBd6x4Hd3PpXIvesEojCnD KuWaVmvTFs9Pw== Date: Thu, 17 Oct 2024 11:09:56 +0200 From: Niklas Cassel To: Ryan Roberts Cc: Andrew Morton , Anshuman Khandual , Ard Biesheuvel , Catalin Marinas , Damien Le Moal , David Hildenbrand , Greg Marsden , Ivan Ivanov , Kalesh Singh , Marc Zyngier , Mark Rutland , Matthias Brugger , Miroslav Benes , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Kees Cook Subject: Re: [RFC PATCH v1 34/57] sata_sil24: Remove PAGE_SIZE compile-time constant assumption Message-ID: References: <20241014105514.3206191-1-ryan.roberts@arm.com> <20241014105912.3207374-1-ryan.roberts@arm.com> <20241014105912.3207374-34-ryan.roberts@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241014105912.3207374-34-ryan.roberts@arm.com> X-Rspam-User: X-Stat-Signature: yo75ojqyrxwpjmsjjxntq8mwrjsz7axn X-Rspamd-Queue-Id: 5EBE810001A X-Rspamd-Server: rspam11 X-HE-Tag: 1729156186-100741 X-HE-Meta: U2FsdGVkX1/AtEL5buVdJobZFpvnRa7mEdlMuOc23dA1oWbP7MxrB9Dim0Kc+zhRxMW27RlFZIVBfUwX/OQWdi8ehqNMjm2itkeHFu07Zb4bTxGeJ/orVoJnieOznGfsm/SHD/r9S7hJHbBuf4tqm+8NTstC8NBu+40g59Qc8ztnHyiYl0YVLtDREMVdO/TCZKPmPkdS2QjxV7e+8UuS4GFy+mwJfpKhp952cU0Q67Xrk2lxHupE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OMjBKlavJi7kxCafGpNHLeL+8eB 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: Hello Ryan, While I realize that this has not always been consistent, please prefix the subject with "ata: ", so that it becomes "ata: sata_sil24: ". On Mon, Oct 14, 2024 at 11:58:41AM +0100, Ryan Roberts wrote: > 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. > > Convert "struct sil24_ata_block" and "struct sil24_atapi_block" to use a > flexible array member for their sge[] array. The previous static size of > SIL24_MAX_SGE depends on PAGE_SIZE so doesn't work for boot-time page > size. > > 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/ata/sata_sil24.c | 46 +++++++++++++++++++--------------------- > 1 file changed, 22 insertions(+), 24 deletions(-) > > diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c > index 72c03cbdaff43..85c6382976626 100644 > --- a/drivers/ata/sata_sil24.c > +++ b/drivers/ata/sata_sil24.c > @@ -42,26 +42,25 @@ struct sil24_sge { > __le32 flags; > }; > > +/* > + * sil24 fetches in chunks of 64bytes. The first block > + * contains the PRB and two SGEs. From the second block, it's > + * consisted of four SGEs and called SGT. Calculate the > + * number of SGTs that fit into one page. > + */ > +#define SIL24_PRB_SZ (sizeof(struct sil24_prb) + 2 * sizeof(struct sil24_sge)) > +#define SIL24_MAX_SGT ((PAGE_SIZE - SIL24_PRB_SZ) / (4 * sizeof(struct sil24_sge))) > + > +/* > + * This will give us one unused SGEs for ATA. This extra SGE > + * will be used to store CDB for ATAPI devices. > + */ > +#define SIL24_MAX_SGE (4 * SIL24_MAX_SGT + 1) > > enum { > SIL24_HOST_BAR = 0, > SIL24_PORT_BAR = 2, > > - /* sil24 fetches in chunks of 64bytes. The first block > - * contains the PRB and two SGEs. From the second block, it's > - * consisted of four SGEs and called SGT. Calculate the > - * number of SGTs that fit into one page. > - */ > - SIL24_PRB_SZ = sizeof(struct sil24_prb) > - + 2 * sizeof(struct sil24_sge), > - SIL24_MAX_SGT = (PAGE_SIZE - SIL24_PRB_SZ) > - / (4 * sizeof(struct sil24_sge)), > - > - /* This will give us one unused SGEs for ATA. This extra SGE > - * will be used to store CDB for ATAPI devices. > - */ > - SIL24_MAX_SGE = 4 * SIL24_MAX_SGT + 1, > - > /* > * Global controller registers (128 bytes @ BAR0) > */ > @@ -244,13 +243,13 @@ enum { > > struct sil24_ata_block { > struct sil24_prb prb; > - struct sil24_sge sge[SIL24_MAX_SGE]; > + struct sil24_sge sge[]; > }; > > struct sil24_atapi_block { > struct sil24_prb prb; > u8 cdb[16]; > - struct sil24_sge sge[SIL24_MAX_SGE]; > + struct sil24_sge sge[]; > }; > > union sil24_cmd_block { > @@ -373,7 +372,7 @@ static struct pci_driver sil24_pci_driver = { > #endif > }; > > -static const struct scsi_host_template sil24_sht = { > +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct scsi_host_template, sil24_sht, { > __ATA_BASE_SHT(DRV_NAME), > .can_queue = SIL24_MAX_CMDS, > .sg_tablesize = SIL24_MAX_SGE, > @@ -382,7 +381,7 @@ static const struct scsi_host_template sil24_sht = { > .sdev_groups = ata_ncq_sdev_groups, > .change_queue_depth = ata_scsi_change_queue_depth, > .device_configure = ata_scsi_device_configure > -}; > +}); > > static struct ata_port_operations sil24_ops = { > .inherits = &sata_pmp_port_ops, > @@ -1193,7 +1192,7 @@ static int sil24_port_start(struct ata_port *ap) > struct device *dev = ap->host->dev; > struct sil24_port_priv *pp; > union sil24_cmd_block *cb; > - size_t cb_size = sizeof(*cb) * SIL24_MAX_CMDS; > + size_t cb_size = PAGE_SIZE * SIL24_MAX_CMDS; > dma_addr_t cb_dma; > > pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); > @@ -1258,7 +1257,6 @@ static void sil24_init_controller(struct ata_host *host) > > static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) > { > - extern int __MARKER__sil24_cmd_block_is_sized_wrongly; > struct ata_port_info pi = sil24_port_info[ent->driver_data]; > const struct ata_port_info *ppi[] = { &pi, NULL }; > void __iomem * const *iomap; > @@ -1266,9 +1264,9 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) > int rc; > u32 tmp; > > - /* cause link error if sil24_cmd_block is sized wrongly */ > - if (sizeof(union sil24_cmd_block) != PAGE_SIZE) > - __MARKER__sil24_cmd_block_is_sized_wrongly = 1; > + /* union sil24_cmd_block must be PAGE_SIZE */ > + BUG_ON(struct_size_t(struct sil24_atapi_block, sge, SIL24_MAX_SGE) != PAGE_SIZE); > + BUG_ON(struct_size_t(struct sil24_ata_block, sge, SIL24_MAX_SGE) > PAGE_SIZE); > > ata_print_version_once(&pdev->dev, DRV_VERSION); > > -- > 2.43.0 > As you might know, there is an effort to annotate all flexible array members with their run-time size information, see commit: dd06e72e68bc ("Compiler Attributes: Add __counted_by macro") I haven't looked at the DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST macro, but since sge[] now becomes a flexible array member, I think it would be nice if it would be possible to somehow use the __counted_by macro. Other than that, this looks good to me. Kind regards, Niklas