Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796195417; b=4cIRvfEhk5ZFjrF+5LM1VWn6b78w8LT5B6ipfJFQX6iVQqc91j+wuwpbZAmFE2oCcazS +AcbLavAY5JdgIZFkCaBEnWnnLOznGdrp4KNWA6bXjx5xBhPnWGAk6cG7yMsu1ksAA+pK l6aM8yT5zeXxJulWNlP2w5UGj1pX1JrOUwFga2x0EbnftJODdLpB3K2eFI1voo0YMKz+A jodASR1BtyzAXwFuK5qLhX3MjW6FZXQr7flyQ0ZgO8la4QENWVNo8/DzwptCiDYRhcdDQ jb4LzVQGsxEuynrhQipT+0rjV76QgCO2NiHGBXyM3ScIgbsp4/V52DW8gdtn+jfZZaw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796195417; h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:Content-Language:From:Organization: In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=ntNaCTfS3XUTNgXrWPojTO8Fm1Xon9iFjwsslTN6NUo=; b=pdkMfIh/GmtufpxZpS4LyfP2IiPZByW4t2QGV+vARWSyNuVRrbjqZakFJN/HeQ8NhnTL IDF6ueYzdNiqJ24fUyE+Q50mv3fDLLSNzBb6LznYvovcVXtvJhbVXONXWH+KgxnuF7SIW g4j4vG7qqYrbDMP++hsTiiD/mvcw45LA3i5efwIK1WFYyWJZexueHgzGhFSA69e02DMyW uZBCUUGNJ5aqeVLHto5KIi8HMWHiT8iLRRFwiLua31QqCFLva7eLP5hDlg5AJ1bwDn4IK tQ3+Ev/j5F8UKOmVdRC6MbKe5HJhqsnrvtxbOH876l+qef8qXaHHPjwByJkOmDc6FAA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IAjdQfjn; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BD66606A31A; Wed, 2 Dec 2026 07:10:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IAjdQfjn Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A3B01F000C1; Wed, 2 Dec 2026 07:10:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796195416; bh=ntNaCTfS3XUTNgXrWPojTO8Fm1Xon9iFjwsslTN6NUo=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=IAjdQfjnTjb8LYO8zc9vIDIZ4mkW6GdJuefo6+PR789fq5tnKhVA2PkLZnWn5NFw2 1NIkF9DffyrEGxwGRrD4cOBZi/GcltI6yka9lwIjtxqCc1FCvgmssTsh/vhNTDiF5v CMDAgTc817Q8vzNeTilfSH2aYlTlDbAD72KuuUC5SjJBn/Murjrp+Pdoln53Tb7hA1 TsZb2bFjcZz5LEp+ozEt5QOY041L7MmsfCFuud86B4PX893QD8fU8D0f9NFOtlnV9p SwGFojtMNHicoBb68pmyo37E9pqtIOzvG7hSUp8T7FHWCYh7q/S7qoDxOMi2keiyr0 xPH7UkfKU0tmA== Message-ID: Date: Wed, 2 Dec 2026 16:10:14 +0900 X-Mailing-List: linux-ide@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v2 12/13] ata: sata_sil24: Use flexible arrays for the command block SGEs To: Eric Curtin , linux-kernel@vger.kernel.org Cc: Ryan Roberts , Niklas Cassel , linux-ide@vger.kernel.org References: <20261202031647.1690622-1-ericcurtin17@gmail.com> <20261202031647.1690622-13-ericcurtin17@gmail.com> Content-Language: en-US From: Damien Le Moal Organization: Western Digital Research In-Reply-To: <20261202031647.1690622-13-ericcurtin17@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/2/26 12:16, Eric Curtin wrote: > From: Ryan Roberts > > SIL24_MAX_SGE is derived from PAGE_SIZE, so with boot-time page size > selection it is not a compile-time constant and cannot size the sge[] > arrays in struct sil24_ata_block and struct sil24_atapi_block. > > Make sge[] a flexible array in both and move SIL24_MAX_SGT and > SIL24_MAX_SGE out of the enum into macros, since they are no longer > constant. Add SIL24_*_BLOCK_SIZE macros that compute the block sizes > with struct_size_t(), and add sil24_cmd_blk() to index the command block > array, because sizeof(union sil24_cmd_block) is no longer the stride. > Use SIL24_CMD_BLOCK_SIZE for the block stride in sil24_qc_issue() and > for the allocation size in sil24_port_start(). > > Define sil24_sht with DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST() so that its > sg_tablesize is initialised at boot. > > The link-time check that union sil24_cmd_block is exactly PAGE_SIZE > cannot work for a run-time value, so replace it with WARN_ON_ONCE() > checks in sil24_init_one() that fail the probe with -EINVAL. > > Signed-off-by: Ryan Roberts > Signed-off-by: Eric Curtin > --- > drivers/ata/sata_sil24.c | 70 ++++++++++++++++++++++++---------------- > 1 file changed, 43 insertions(+), 27 deletions(-) > > diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c > index 7acd55b17b18..ec420923d866 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[]; This needs a __counted_by() annotation. > }; > > struct sil24_atapi_block { > struct sil24_prb prb; > u8 cdb[16]; > - struct sil24_sge sge[SIL24_MAX_SGE]; > + struct sil24_sge sge[]; Here too. > }; > > union sil24_cmd_block { > @@ -258,6 +257,10 @@ union sil24_cmd_block { > struct sil24_atapi_block atapi; > }; > > +#define SIL24_ATA_BLOCK_SIZE struct_size_t(struct sil24_ata_block, sge, SIL24_MAX_SGE) > +#define SIL24_ATAPI_BLOCK_SIZE struct_size_t(struct sil24_atapi_block, sge, SIL24_MAX_SGE) > +#define SIL24_CMD_BLOCK_SIZE max(SIL24_ATA_BLOCK_SIZE, SIL24_ATAPI_BLOCK_SIZE) > + > static const struct sil24_cerr_info { > unsigned int err_mask, action; > const char *desc; > @@ -322,6 +325,13 @@ struct sil24_port_priv { > int do_port_rst; > }; > > +/* sizeof(union sil24_cmd_block) is not the stride between blocks */ > +static inline union sil24_cmd_block * > +sil24_cmd_blk(struct sil24_port_priv *pp, unsigned int tag) > +{ > + return (void *)((u8 *)pp->cmd_block + tag * SIL24_CMD_BLOCK_SIZE); > +} > + > static void sil24_dev_config(struct ata_device *dev); > static int sil24_scr_read(struct ata_link *link, unsigned sc_reg, u32 *val); > static int sil24_scr_write(struct ata_link *link, unsigned sc_reg, u32 val); > @@ -372,7 +382,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, { I am not familiar with this and a grep in 7.4-rc5 gives nothing about it. What is this? Is it something new in next? > __ATA_BASE_SHT(DRV_NAME), > .can_queue = SIL24_MAX_CMDS, > .sg_tablesize = SIL24_MAX_SGE, > @@ -380,7 +390,7 @@ static const struct scsi_host_template sil24_sht = { > .sdev_groups = ata_ncq_sdev_groups, > .change_queue_depth = ata_scsi_change_queue_depth, > .sdev_configure = ata_scsi_sdev_configure > -}; > +}); > > static struct ata_port_operations sil24_ops = { > .inherits = &sata_pmp_port_ops, > @@ -599,7 +609,7 @@ static int sil24_exec_polled_cmd(struct ata_port *ap, int pmp, > { > void __iomem *port = sil24_port_base(ap); > struct sil24_port_priv *pp = ap->private_data; > - struct sil24_prb *prb = &pp->cmd_block[0].ata.prb; > + struct sil24_prb *prb = &sil24_cmd_blk(pp, 0)->ata.prb; > dma_addr_t paddr = pp->cmd_block_dma; > u32 irq_enabled, irq_mask, irq_stat; > int rc; > @@ -841,7 +851,7 @@ static enum ata_completion_errors sil24_qc_prep(struct ata_queued_cmd *qc) > struct sil24_sge *sge; > u16 ctrl = 0; > > - cb = &pp->cmd_block[sil24_tag(qc->hw_tag)]; > + cb = sil24_cmd_blk(pp, sil24_tag(qc->hw_tag)); > > if (!ata_is_atapi(qc->tf.protocol)) { > prb = &cb->ata.prb; > @@ -889,7 +899,7 @@ static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc) > dma_addr_t paddr; > void __iomem *activate; > > - paddr = pp->cmd_block_dma + tag * sizeof(*pp->cmd_block); > + paddr = pp->cmd_block_dma + tag * SIL24_CMD_BLOCK_SIZE; > activate = port + PORT_CMD_ACTIVATE + tag * 8; > > /* > @@ -1196,7 +1206,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 = SIL24_CMD_BLOCK_SIZE * SIL24_MAX_CMDS; > dma_addr_t cb_dma; > > pp = devm_kzalloc_obj(dev, *pp); > @@ -1261,7 +1271,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; > @@ -1269,9 +1278,16 @@ 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 once taking into account the > + * 'sge' flexible array members in struct sil24_atapi_block and struct > + * sil24_ata_block. > + */ > + if (WARN_ON_ONCE(SIL24_ATAPI_BLOCK_SIZE != PAGE_SIZE)) > + return -EINVAL; > + if (WARN_ON_ONCE(SIL24_ATA_BLOCK_SIZE != > + PAGE_SIZE - sizeof_field(struct sil24_atapi_block, cdb))) > + return -EINVAL; > > ata_print_version_once(&pdev->dev, DRV_VERSION); > -- Damien Le Moal Western Digital Research