From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796181444; b=uiImm+cLBDy2k75TZMJ8baX4SS99tqW9r6VXb7TETy42TxEssVxAWpPRhzh/+hmMsWDr oISPcnuz5PsyZmUaOFAAXRU4Qa46StnoKq6GRK1EckgJZWaETTeWMkeyFHwRV4PM//R34 UbPcscXV19rs4ImWJcG3FdLjiwRFwSH6F2FhZIEv8JoJie1d8+CuHS6knyWPTbUSKGfFE wl14PnzSHSD97DeKxyobQolepKHHnaimywjuxfRzM9s6n6hNd50SKjCBUnxV9sUcr/6n1 LPPOEFfTMG9s8sfc1Am4RfJz+GIcp8af9HRuHTFoKL55QU6nWRh7FTACBGHsy0UvAVA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796181444; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: 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=qlPz0wSFjF5JvnX69GLWidK73vryMccTRB/wRYieP4esVOgjBySWnFVqKNNuM/4E8R/C N311Qv25qn6J+nOpguyrfd/Z9BB/NTSym6NnVqWNXNA7O2gyYaNM7qAs0amZEqI5IaEsS RpWXXjfcSHE82AAx+uwKTxVCdUnfMEDbF08oK/7Tw6xYjlytIhPfO2XE9xP2Dn2/LX+pk 8YUO6VtyEe7TjNFCoKJWQ6dPbvd9NmEdbTWsuo6unVkNsMyzizbxG5ObHCk+uqM6Fo0if vuBT5ZRFLUdgjrANfSLIpHIjem79os5u/2cNmFnc+b1n5MXSGIuyc5PScJey9vih3Jg== 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.54 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 8E4BF606A681 for ; Wed, 2 Dec 2026 03:17:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8E4BF606A681 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-f54.google.com with SMTP id ffacd0b85a97d-4a3e706b5dfso8026296f8f.2 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=Oa6a+4c309E0zFXqEMCRDCzjAl31euoHHNCQ5bRXcTYBR8jCQqvaxS71PCyXqf3BgW XZo3J2wofs2YQ0haRMcF+QQXSmgLhMqJ16XexYqAv8HJvQL2WnDcKc4RKj2tdnrEpp0e OCiU19KoxV/oxmWvg2Rpf31LLIJhlSiS5lFbjWtpzZq81sueB6TkExEH2BNwRB4E9UuO fSVnEFfTdWGtz+vxg2kUC7Z71bhPa0mDvu1LD6hvSEkK4GTqqpTR5v78YozxAKSOhma5 /elodJnKDywF3JLJTNis39Jh+43ubpaKDJ16MqlZRWVe9bGAkJvq7oPvOd/9mrrixsL2 F9aQ== X-Gm-Message-State: APuU4Z8iDMuB440vng/q7ouWyG4y8wmUFULC9kRmFXAHdXm2HBkuw9Q8 pz7IxFS3Frn+T0uTY2SN9pf31KWuXs0HGikAeQbYy71iDgHmgYvwWAmaS+bIxHHgBZD4yvA9 X-Gm-Gg: AZFdTZf2cqVGOCbf/XPHorpXn/qR7obvffFwheovk2GB+11p5b8nlKhCWggJR2ROwxD hKS3Lo1UKF+E0faAj5vav5qtp2KRMZvHPXlZC+GosDnParfX+XTYtfki12H41/if1usueWlSKFi Hi/SVWMjp4pJAiVrcUU+IUDeVhTRf+i9cufzBsjjJeBN1cMKKGuCp+Cy4hET/bvfHMffdGc3CcB rRayDSynGoRrVULscjy0hzk0uWwBSZO4FQ7ScyYt4NjYMz3vMwQAkFQb0xduSs1fUGWkeVSwISB VM9M6DFGm5b2Na0f7DpYbLupzqLdp1oO9+NkdOldkebL/+E+BzAXr6A4N/IU3lEuVLZC5RdTvE3 eLY4YEgMhLQJ62pREX/pZ/zrqMeoKYU+PtaeOORt93N3HaLqSCINvf8ROGsPSKJY+cMQ95dj3ZO ItgfOiiVmdUIM33b3CrWaTf/PF155pWTnkmPrgCV6UluOPgF2OPU1PycSWzy8LkUM5z0Usc2UGE NecPjWfAWXAivnaIFa3KkpPc+3OmMOczILWQa38ZLNeUtvm+hx/2r5u7Gvwhgd2/20/PTXEPkm5 dxni94UdbTt05iKQ7FJ+KbFq8YPHy8XXJ/fH3uI= 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-kernel@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);