From nobody Mon Dec 1 21:33:23 2025 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C2A12DC359 for ; Fri, 28 Nov 2025 03:37:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764301071; cv=none; b=oMoZfZhDejv1irchb0wOY3y2bucTNlGg6ZyxUR//UNAdAh68uvSo15zOTPNWSdTJsUGGvO99frrqfo+0FGUusIHs6dPJeil+hpyBLfDSRkn0WH8nh5PWQi9VeyB0OghmUaM/dmr2yDoVqWl7N3Wbg1q9tE/ardXwXJUCLjlqMyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764301071; c=relaxed/simple; bh=3b6wIYgewbLW+NSlJo3hwLCgNV7d/iwK2UN4TDIMNug=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:MIME-Version: Content-Type:References; b=fbxZfWHk9zj4vyqMuqHMa9tuqEN1Wzw0ttAZLz8g6Ba86lImiG95Jg/6AboVSDqUjJcmLhiMMl9kyXRVjhf5OyFq9dYHWR3Od8XOp/egnLmJe/Iry2yRddJwZVu5fo9TMIysD/hSYV69VyK8MvwRGv1nssBe+CPd5eqbXJtIv5M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=JjqqYZK/; arc=none smtp.client-ip=203.254.224.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="JjqqYZK/" Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20251128033741epoutp030a91aaa50c36e2ed69034e175f50a580~8Dnfb7QlK2264322643epoutp03A for ; Fri, 28 Nov 2025 03:37:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20251128033741epoutp030a91aaa50c36e2ed69034e175f50a580~8Dnfb7QlK2264322643epoutp03A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1764301062; bh=qi/SRWVOW0xIZ/a8mTLL5M3ulFk+K1NrsEeMRhZKiBs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JjqqYZK/63AJOpx4lZ521YkHLgwzphEi79exd1RyybwBeCNcedVO31dvgLNGFC1WN Zllywk5rj7+BFr5M+ujXb5WiyDRnAbbT96OGH81rVR5hzATmYbe/H96K2bCVpwHRkQ xBUf5qFFs+AG9vBh/ENMl8AiiBeQCGEs3yv2JmaM= Received: from epsnrtp01.localdomain (unknown [182.195.42.153]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPS id 20251128033741epcas5p3d74b0cf8d57100265cfc1b871caf7a9d~8DnfCVGPw3116131161epcas5p3f; Fri, 28 Nov 2025 03:37:41 +0000 (GMT) Received: from epcas5p4.samsung.com (unknown [182.195.38.86]) by epsnrtp01.localdomain (Postfix) with ESMTP id 4dHfBX40Rjz6B9m6; Fri, 28 Nov 2025 03:37:40 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20251128033722epcas5p2d083b5b13b48ceabe95b33585e197d2a~8DnNWEUM82288422884epcas5p2N; Fri, 28 Nov 2025 03:37:22 +0000 (GMT) Received: from testpc12933.samsungds.net (unknown [109.105.129.33]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20251128033721epsmtip25693b18c085a49be62a08699aabe584b~8DnMWf4va1673216732epsmtip2f; Fri, 28 Nov 2025 03:37:21 +0000 (GMT) From: "zheng.gong" To: linux-scsi@vger.kernel.org Cc: avri.altman@wdc.com, bvanassche@acm.org, quic_cang@quicinc.com, alim.akhtar@samsung.com, martin.petersen@oracle.com, ebiggers@kernel.org, linux-kernel@vger.kernel.org, "zheng.gong" Subject: [PATCH v3 1/1] scsi: ufs: crypto: Add ufs_hba_variant_ops::crypto_keyslot_remap Date: Fri, 28 Nov 2025 11:37:09 +0800 Message-ID: <20251128033709.1342579-2-zheng.gong@samsung.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251128033709.1342579-1-zheng.gong@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CMS-MailID: 20251128033722epcas5p2d083b5b13b48ceabe95b33585e197d2a X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P cpgsPolicy: CPGSC10-505,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20251128033722epcas5p2d083b5b13b48ceabe95b33585e197d2a References: <20251112031035.GA2832160@google.com> <20251128033709.1342579-1-zheng.gong@samsung.com> Add a new variant operation crypto_keyslot_remap to allow platform-specific remapping of crypto keyslot indices before sending requests to the UFS controller. This is required on platforms that partition the UFS crypto engine's keyslots among multiple domains (e.g.virtual machines), where each domain has a keyslot offset. To support this, pass the UFS HBA pointer to ufshcd_prepare_lrbp_crypto(), so the callback can access platform context. This functionality is used on Samsung ExynosAuto UFS platforms, where keyslot allocation is per-VM and a runtime offset is applied based on the VM ID. Signed-off-by: zheng.gong --- drivers/ufs/core/ufshcd-crypto.h | 10 ++++++++-- drivers/ufs/core/ufshcd.c | 9 +++++---- include/ufs/ufshcd.h | 6 ++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/ufs/core/ufshcd-crypto.h b/drivers/ufs/core/ufshcd-cry= pto.h index 89bb97c14c15..6dcba6817590 100644 --- a/drivers/ufs/core/ufshcd-crypto.h +++ b/drivers/ufs/core/ufshcd-crypto.h @@ -13,7 +13,8 @@ =20 #ifdef CONFIG_SCSI_UFS_CRYPTO =20 -static inline void ufshcd_prepare_lrbp_crypto(struct request *rq, +static inline void ufshcd_prepare_lrbp_crypto(struct ufs_hba *hba, + struct request *rq, struct ufshcd_lrb *lrbp) { if (!rq || !rq->crypt_keyslot) { @@ -22,6 +23,10 @@ static inline void ufshcd_prepare_lrbp_crypto(struct req= uest *rq, } =20 lrbp->crypto_key_slot =3D blk_crypto_keyslot_index(rq->crypt_keyslot); + + if (hba && hba->vops && hba->vops->crypto_keyslot_remap) + return hba->vops->crypto_keyslot_remap(hba, lrbp); + lrbp->data_unit_num =3D rq->crypt_ctx->bc_dun[0]; } =20 @@ -74,7 +79,8 @@ void ufshcd_crypto_register(struct ufs_hba *hba, struct r= equest_queue *q); =20 #else /* CONFIG_SCSI_UFS_CRYPTO */ =20 -static inline void ufshcd_prepare_lrbp_crypto(struct request *rq, +static inline void ufshcd_prepare_lrbp_crypto(struct ufs_hba *hba, + struct request *rq, struct ufshcd_lrb *lrbp) { } =20 static inline void diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 8339fec975b9..7417c6bec81a 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -2902,20 +2902,21 @@ static void ufshcd_comp_scsi_upiu(struct ufs_hba *h= ba, struct ufshcd_lrb *lrbp) ufshcd_prepare_utp_scsi_cmd_upiu(lrbp, upiu_flags); } =20 -static void __ufshcd_setup_cmd(struct ufshcd_lrb *lrbp, struct scsi_cmnd *= cmd, u8 lun, int tag) +static void __ufshcd_setup_cmd(struct ufs_hba *hba, struct ufshcd_lrb *lrb= p, + struct scsi_cmnd *cmd, u8 lun, int tag) { memset(lrbp->ucd_req_ptr, 0, sizeof(*lrbp->ucd_req_ptr)); =20 lrbp->cmd =3D cmd; lrbp->task_tag =3D tag; lrbp->lun =3D lun; - ufshcd_prepare_lrbp_crypto(cmd ? scsi_cmd_to_rq(cmd) : NULL, lrbp); + ufshcd_prepare_lrbp_crypto(hba, cmd ? scsi_cmd_to_rq(cmd) : NULL, lrbp); } =20 static void ufshcd_setup_scsi_cmd(struct ufs_hba *hba, struct ufshcd_lrb *= lrbp, struct scsi_cmnd *cmd, u8 lun, int tag) { - __ufshcd_setup_cmd(lrbp, cmd, lun, tag); + __ufshcd_setup_cmd(hba, lrbp, cmd, lun, tag); lrbp->intr_cmd =3D !ufshcd_is_intr_aggr_allowed(hba); lrbp->req_abort_skip =3D false; =20 @@ -3083,7 +3084,7 @@ static int ufshcd_queuecommand(struct Scsi_Host *host= , struct scsi_cmnd *cmd) static void ufshcd_setup_dev_cmd(struct ufs_hba *hba, struct ufshcd_lrb *l= rbp, enum dev_cmd_type cmd_type, u8 lun, int tag) { - __ufshcd_setup_cmd(lrbp, NULL, lun, tag); + __ufshcd_setup_cmd(hba, lrbp, NULL, lun, tag); lrbp->intr_cmd =3D true; /* No interrupt aggregation */ hba->dev_cmd.type =3D cmd_type; } diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index 9425cfd9d00e..86b7bcc1da33 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -336,6 +336,10 @@ struct ufs_pwr_mode_info { * @config_esi: called to config Event Specific Interrupt * @config_scsi_dev: called to configure SCSI device parameters * @freq_to_gear_speed: called to map clock frequency to the max supported= gear speed + * @crypto_keyslot_remap: called to adjust the keyslot index before sending + * a request to the UFS controller. This allows the platform to apply a + * hardware-specific keyslot offset or other mapping logic to determine + * the correct keyslot for inline encryption. */ struct ufs_hba_variant_ops { const char *name; @@ -385,6 +389,8 @@ struct ufs_hba_variant_ops { int (*config_esi)(struct ufs_hba *hba); void (*config_scsi_dev)(struct scsi_device *sdev); u32 (*freq_to_gear_speed)(struct ufs_hba *hba, unsigned long freq); + void (*crypto_keyslot_remap)(struct ufs_hba *hba, + struct ufshcd_lrb *lrbp); }; =20 /* clock gating state */ --=20 2.50.1