Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796181445; b=iBIhU/sxyNmGI6G5p90sMeDhcX/d3Vcv6qJJqUpIvMkgbU5erUYFTX5xTzButmUfMIL+ RX9bKHfaLM7vV2diMxknVKyhAZh6DiBLvdtlAMkQ0ZOD0BqEJs6fCQ4n9LKCOdff1ErqN ICUMVUeH98OlVenZ9oci2Glv0R+N8RNNWF9ft3KEC/3Yztpkd6b5FviONn3KM4XIOJxhy OV8g1sQVNyABqw0pXJzj6csvtTINKplAqmvZVtRtb4gZrUqzjdjnc8sVRzYXTDtyPtmm2 rwhqKav7jLIfN2zMod6Swx6bMcbFGWptUQ+8eCZnfKNwe5gu1EB1Dv/kUnshwMA6H/w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796181445; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=RmNfuc/l11q5Bu8PPQXi9kiIphtqtA56/HwSdH7UkKU=; b=rvbp8S7Bp3uEjVQ71Dur6m9o93CjDZaGfbRNux6DkLoDiGtyVbags24fgieR9TanE5SZ P+6A2VRwQxz/i5rjXfxx6qK2lAU1SjV20Fz0fbBi4s5ERzwOzH3u1Lkh2x7Huzp+5HGih QxEBDfisozuww0PD/Ishzd9KSRP0EsCoNKgGCmkOb5UC0EZ9wjWRVdN94w/WNNSgsPUH5 eyTciPgzjHNFC1BfKPHaWS4215Zm1lHfGX0FVraKzmsss8J4sykO7nt9DhBjeCM8SasRM OFdoGLSzg59wFalJeoqmeLKgBkd1DzZ15xjISLRvxWja0FqiFGaZr4bLE+Jiq8kJFnA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="v5TquOT/"; arc=none smtp.remote-ip=209.85.221.48 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 987B260A381F for ; Wed, 2 Dec 2026 03:17:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 987B260A381F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=v5TquOT/ Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-490d59c3f0aso5740033f8f.1 for ; Tue, 01 Dec 2026 19:17:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796181443; x=1796786243; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=RmNfuc/l11q5Bu8PPQXi9kiIphtqtA56/HwSdH7UkKU=; b=v5TquOT/w6BvM1uSWQ8f7DaSJ7xEOdAcw8A0oastCOb24J21g0ut+HwJjkTRWxhU7H Ll2E6MySVXUhQoo5jyxxpH8atL8oKYOvdJqboXH8Z4QFnDWStpgdSyci9fu3D9g/bZxP CkJvOk7ByLVhG1usiugh9PPJlhCwoNpdWepiF58QLjwqHFIj6GUwyc7IaLjnskD0Mv4l ONqgnxJW36D1ySoIF5JU5qffuXDyXXSZPGA0ThSrf9k4y0OvWVvNx0lGjw7hukoscRJ+ nH1dvdt18ONnX1ew2KfY+PUBc1aORXKKAdcZuBGrIBry95LQ647JsMK9Sf/qklRAIyLk 6Udw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796181443; x=1796786243; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=RmNfuc/l11q5Bu8PPQXi9kiIphtqtA56/HwSdH7UkKU=; b=v1ccDDio71OmJIj7+hGGQWteMtYVNYC8lVMUK6wnpHPW9xEXbCuc2lYi4ArudHEFne dqb+17ZJ7dyFzkS9vaFv/vrGC5Ju958dsNpQpB4Y/kP6L1TV66jRyBBbUUu0RZvoX3am 2ujBo6Wyi6jLCWlwX3IDtxlBVa2Vdm7czRwHohwuMqvXMX1HjraesSmuinOlC9yCTyO9 Lbk/QcUdY1VPBBYnpOaXwxsNcHLbeBgKgrA4iOStv+lBc3OHrX7YZw8qgcAJtUyTbotn QL11xQyFeXHhcgKchjbcxXj94w4ZDpTo1TJjiQ76bwF44V6O9usYLBKKQAg64yd5fmPK 7F4Q== X-Forwarded-Encrypted: i=1; AL+hErGUrNH6wHPTCDTWxuBYePUWZY4BXizI22YAEReXoBFDJYp4oTd/6EkCLI4ymsku49X7HS9LpladHng=@vger.kernel.org X-Gm-Message-State: APuU4Z9xDdOYrChR3zceV3SwYtLv9ccMusWt2ikb2j1SYy8ndihE1d3d jjOnPPzSJR/ptLZvQxzqEebHx+OU9rXn7IVh3vfzrOrnJSoEx1XPXpvh X-Gm-Gg: AZFdTZf32SHg/jhsr5wvY7kNf9PcqNpENn9FpaD5zAvFCNALekxDw0boR47Jro1x2R+ ZjFrs4VcT0l02fk5/nV7tDk15lrc12+xENQpA/+K1EJOP2JJ5ywd0H4EQFNMkf/GD8V0Ahpeq6x tgiHXfZGcVcO89GWzJHDDXwj8L+Rvn5sOFTFPiKrXYSAGzoa9xKarNunPlxLwDfFvxwAVhGHc/K wUiBXtriXybxSrQyhjq9RqCF4Jt0+hO14WN7tBxMg5lNz2eegtp2fiVR5u2MCd4PxN7y8cNCNFO 0fI8qmhuE4BhAjLe/DhpsEMCAow5ROWmjHBIVLLXW2ZBHpvhiOZ2tieBY67tzX1u00SbPfEihbO QR4BhCt5uXHZssl/VOVnI4kREkH63oyeJtS71P9sr6SbDXCJKIaktJGHCUQBbg078WHXkAOGyNH YSPUjxo7gKe/6MYELClBkCYm1jrZ0L3UwwY5KaH45zwNuRKSKA3iY5i+rzLbzgOL54qOlM2y6o2 NwZMJ0q5tyTFmH8XWEx9l8W5lIhRNswR58PVQCkPuxqRNiPQ59jsYgPwJVwQIl2bAY5/ATS26oX vstbk8ZmxwmOYv9JFGGlRSj+MaWsZKgzLEILQ8E= X-Received: by 2002:a05:6000:2b85:b0:4cb:7c18:892b with SMTP id ffacd0b85a97d-4cb7c188d69mr2682731f8f.51.1796181442996; Tue, 01 Dec 2026 19:17:22 -0800 (PST) Received: from NULL.Home.net ([2001:8a0:7280:4000:12d:c3b9:cecc:8966]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4b34e9c3ffesm61468691f8f.19.2026.12.01.19.17.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 19:17:22 -0800 (PST) From: Eric Curtin To: linux-kernel@vger.kernel.org Cc: Ryan Roberts , Damien Le Moal , Niklas Cassel , linux-ide@vger.kernel.org Subject: [RFC PATCH v2 12/13] ata: sata_sil24: Use flexible arrays for the command block SGEs Date: Wed, 2 Dec 2026 03:16:33 +0000 Message-ID: <20261202031647.1690622-13-ericcurtin17@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261202031647.1690622-1-ericcurtin17@gmail.com> References: <20261202031647.1690622-1-ericcurtin17@gmail.com> 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 Content-Transfer-Encoding: 8bit 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[]; }; 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 { @@ -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, { __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);