From patchwork Fri Nov 4 16:04:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary R Hook X-Patchwork-Id: 9412775 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E9E486022E for ; Fri, 4 Nov 2016 16:04:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DACE82B189 for ; Fri, 4 Nov 2016 16:04:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF44F2B1BC; Fri, 4 Nov 2016 16:04:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 125252B189 for ; Fri, 4 Nov 2016 16:04:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964845AbcKDQEv (ORCPT ); Fri, 4 Nov 2016 12:04:51 -0400 Received: from mail-by2nam01on0049.outbound.protection.outlook.com ([104.47.34.49]:2836 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S964842AbcKDQEt (ORCPT ); Fri, 4 Nov 2016 12:04:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=9c+lGaFc3+WJq4/jaGXD+jT1pwB/Uje9XCToGddFVMk=; b=ncrV7yip9mZyTEyoutI3EKeZd8bZwvfY2NEP88HeCBh06hwUtxo7Z9YSYhHOF6o2iTYFtNkz1hQXGQq8oh6FEv2xGQJGAVNPlb5MgoFiQgYEEtpebX1dS66A5ltQrUONIOm05E13lNZCUAeOBWTpahf8B3FE8tA1E+NR/WWPAEc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Gary.Hook@amd.com; Received: from [10.236.19.42] (165.204.77.1) by DM5PR12MB1403.namprd12.prod.outlook.com (10.168.238.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.693.12; Fri, 4 Nov 2016 16:04:47 +0000 Subject: [PATCH V2 7/9] crypto: ccp - Enhance RSA support for a v5 CCP From: Gary R Hook To: CC: , , Date: Fri, 4 Nov 2016 11:04:42 -0500 Message-ID: <20161104160442.18155.92936.stgit@taos> In-Reply-To: <20161104160140.18155.75618.stgit@taos> References: <20161104160140.18155.75618.stgit@taos> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR17CA0036.namprd17.prod.outlook.com (10.175.189.22) To DM5PR12MB1403.namprd12.prod.outlook.com (10.168.238.142) X-MS-Office365-Filtering-Correlation-Id: ca39fda8-9ac2-4d88-05dc-08d404cc4d34 X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1403; 2:w/9u765NRBmC0d9ifgkStmEDnBxKIzxaN6QSo2kemIM2RIkDMOxcmN/mVqhonyKPhxwqMdSUKKcxcIaKheLL3i9e3RRWrXjdsxs/RPgm+MKXBwVRsGMkUN4sC3nV74LTfXwGjq/iRa8EcP3Hg8zYbKqx2jlD2HZimGoJ2G5VRvO6VaJ4KgJfFd5bftQDqxIW2FAsprjgKKAMjIPJxnf7vQ==; 3:CNlJpsyomnvEJn6ZpsKmzSngHLGFyEwQTuLm75Z/6Rv+s5ypxrtb9xRU411ZnHeHWRvDJiNkvSo7VSt06yB/rnOsmchnQ9c+94sJdxyVc/UxtB7iiVVOXpCVrawOzMxkY+inG3m6fvy+lTWtLoOi5A==; 25:3vFoboGC5U3oQbcBfEb9AOeH6743300Ecm+pMp3wTjgdAi3284Id60iO8ShGK72oMJO2ieTupp7/GAyL1WCIZF2O0Y5pm4hk6yyqydVgBj16s+H4LZlJDvRqw4ePCY392qSG5pKXDPqh2Feom/mlB3c6sMRs6OXLb3mlKbhttytY83RTDRjRrWiblc9xWaClI7b6Q+a7Ssjn5JetR9kMYeaDwFOqpbdgOrGYZOxF5Ea+h0S7pak1X6Lh3Ze9f1SeWwmOo2g0QgI3Nt6QY/E91sXtTvUBSuH5tVZQfg8JUNsSCFWyZNrzyhODmCvRZyF1D6xUF61U4djJMmRpEA6xq2dOA74UaAtbrvjux3QJjUYk2eOwGpJbaDCijXkJqfaY6qJSB0CtNRiik7dNHbv0bjHxpUBkrm9I40uFT5yLJgusOvnLp0lJUVzbcdCdRWah X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM5PR12MB1403; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1403; 31:PjW9pmn3iMmKzeDQWTb9VN1yHoGeMccj96FJwiwvnnZLK7yY2nYuDx/fWsv3h62K0sbfclolO8/kvn+usByBWyGAcWenuNzXlUKHiovNRipxE/aIe2A6/egB0DHJErqi6x0K/ZgYeMdpLQILoTwA4i97kk8Z+lQvc05DnEdnzGGY3VWyDmxRZ2ZzCqMko416Tja409RLXBembdPqH8cYSAeMSbuSICRVaT51Kxp4ofrVQ0S6IRjihLRJzUzn1c3W; 20:w+W9xc9iMlCi03lEfL1LfkwXNomihtnvuUknaPxvT68xEmWWqafTxOWwNgH1lTs70IwcPmxQWFWEAu5ljCLIyHz9B6n2jdr/5GW/LuK2uTHKSCDyDujXWAUQooCTg7pmmCTP85YpH7848TdlKizRYKlM/DDl2hHRZoaU6g5VmkiqDhR0/vapQIcSrClvMt9g7KunGnT7pah/GrOzzXVEm+vkuXkzu53ibo1I0KSB3VvHtnou9G34BGEy327vZnhtAzsVSAZIM6MTnABJIwQlbOtQ3Cs7ktp7iq9u01F+Jl1kKpqGJ1EYsGUsT8gOZiuuVUxxUlBuqYm6twQYJSOH/QbmGsmmrBJhmQitMJNznLvZFp62Y/D1mMXp9QnMpoMSPDJR4fKdPAYvr+feP7c/Aq93fo52cVGtjyZ8FJD6VP88XGzwp8mM0lu0hXLEsCfTckw5Da6AR2YZsxlLfkNYsdtjcSNQXYzyEA9SZUNvwY7n96HN0OqIEyxPFpUgOAPW X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026); SRVR:DM5PR12MB1403; BCL:0; PCL:0; RULEID:; SRVR:DM5PR12MB1403; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1403; 4:cP7Wxgz1mfr0Bp+bxATTyhZAPbyiHXV923hFtS+bpIT0Rxe8Lg4D3tyJg5yPsYIg/tG/gzLyH67go9Jm5zckgFb+J1qTl8XrDFHxNB+njdm57Q6+1gEAmdozN0mXSrza907SPbI2+E6dO4j4tIkWjZgeF8hE1HVf2osmVcp9Q0VN6QyysNRaQM86eNzfqv5RHGh15yO2lCIqQWmL/sGVVAiJlk4mDoSNchSRy/9P559uqQ9dVV4L0UrNlIKm91Dr6QODxbgd5EyaZTxp/WzZk6gUkP0MSoES1xZwxs1fGXZC8xo9h8IR+9OpEGVJsTka2nVScrt1jMiv5HDLkSr705WMrp+iwaGFLRPzAAXmfnN2lEUIb3KWLmxXb8BCsHeNUgWuA3ltaU4UDISo8oJFn2x2g8GS+sye3P2/4rdZv9F3WqIi6n83oDA3K4RYnO4DY5w6Mt4CLyytRQlnjQ+usQ== X-Forefront-PRVS: 01165471DB X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6049001)(7916002)(199003)(189002)(106356001)(81156014)(229853001)(1076002)(97736004)(50466002)(101416001)(92566002)(4001350100001)(68736007)(2351001)(66066001)(86362001)(105586002)(7736002)(305945005)(81166006)(83506001)(2906002)(19580405001)(97746001)(5660300001)(76176999)(54356999)(50986999)(77096005)(586003)(19580395003)(110136003)(42186005)(23676002)(4326007)(230700001)(47776003)(103116003)(33716001)(3846002)(7846002)(6116002)(189998001)(9686002)(6666003)(6916009)(2950100002)(33646002)(8676002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1403; H:[10.236.19.42]; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTVQUjEyTUIxNDAzOzIzOjlxVkRZL2pjbkZtYVl6N2pHZkVKVnhJR2ZH?= =?utf-8?B?V1pkWGdtUXpPMWFWWm9jUDVENGI3NDJsd0d6dUdlME1kaUpqLzZvL3g1R2FF?= =?utf-8?B?cXdORnArNDkvbjNWZkVrV0c3YWQwS1YrcVZnS3JDWkJFNWplakJTV0tQbHRj?= =?utf-8?B?MERvcVNWM1hpdENNTnE1OWNqeTV0R3FwZDBkY01BLzUyNGtPT09jZFhCWVh3?= =?utf-8?B?OFR6UWhhMk0wSktlSHZjS1Z4U3NaWkJsK01KQVdvdlArNjQ1Y1RCY2ZEang4?= =?utf-8?B?bEFZWTg5MFhib1ZkK2QwalhpeGVCcXVja3JyTmp6MkxnRzd5eGdhNmZtTSta?= =?utf-8?B?MXZHUXpsSTJEdUl0UytwSkNwdUFFcDZLZmljWmlOL0NOTDVFRkQvZnBjTG9l?= =?utf-8?B?TE9DOE9UN1hHZ1FQRzAxai9GVEhyNW9aWGMrKzNrcUk5TnV4c0ZyTVBwTXZH?= =?utf-8?B?Tm5jc0lpd0lkZXJrd04wcFIyK09LRHlPSHJtcldYV1ZTMmx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:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1403; 7:L2i/BumwJGRY4grkFHQ93QBsQmxWm7NT39NOcX6fZDSkKGZH5Cy55cRlVrJdqI8OEbjKWU7D7t0IWV0Wa9k16peG+2L5ahr28ZlkGzfAYlG6Yotby2Mo/d1idDT/YiF8cU2o0v+e6FwvHDFjjLU+xATGz+AUnSKt9DaW7NYtDxVU2y0rZbr2vjvzqqTioT8GPxsdZ4i4dPU3U428AnolAKV3svF2V7i5X7ceiAeIHNBhfmFAQ7CBsan/xNBbpwkUCzQkpii49uU1y7pypRmPnf9zq74+pEPJVx5juvVnHlrYA5+e1oLIC4716Q+eTuGJQcLjN+KEOVRAC8KuFQwk/eNeX4DfDT6+Yt8nd6+pQTU=; 20:97o/G89yyyFm8EFOKN44wgvIEjD1T8W9RtdL90ndf7nRTA8e1MD3ysatNf0q8evZ6PdzJGrYY7dV0cQFA1Ct6SkYOtyp89JpfE1nEfiGIkRQFzA7PJLgs3En6t9U9z8fNWXkNARIdbuEn0EXy24M4dMcrC+Z+YqNBlQ+pvh9p1IyMWQNAZPr62BMqxVTJO8pdQdUnVrvxLBna+Lng/jsSWiqTeP9fMkIG7A5kw0vEHTWxNNBCaFUWjzHzIA75Q8M X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2016 16:04:47.6392 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1403 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Take advantage of the increased RSA key size support in the v5 CCP. Signed-off-by: Gary R Hook --- drivers/crypto/ccp/ccp-crypto-rsa.c | 5 ++ drivers/crypto/ccp/ccp-crypto.h | 1 drivers/crypto/ccp/ccp-dev-v3.c | 1 drivers/crypto/ccp/ccp-dev-v5.c | 10 +++-- drivers/crypto/ccp/ccp-dev.h | 2 + drivers/crypto/ccp/ccp-ops.c | 76 ++++++++++++++++++++++------------- 6 files changed, 61 insertions(+), 34 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/crypto/ccp/ccp-crypto-rsa.c b/drivers/crypto/ccp/ccp-crypto-rsa.c index 6cb6c6f..5e68c8d 100644 --- a/drivers/crypto/ccp/ccp-crypto-rsa.c +++ b/drivers/crypto/ccp/ccp-crypto-rsa.c @@ -45,7 +45,10 @@ static int ccp_rsa_complete(struct crypto_async_request *async_req, int ret) static int ccp_rsa_maxsize(struct crypto_akcipher *tfm) { - return CCP_RSA_MAXMOD; + if (ccp_version() > CCP_VERSION(3, 0)) + return CCP5_RSA_MAXMOD; + else + return CCP_RSA_MAXMOD; } static int ccp_rsa_crypt(struct akcipher_request *req, bool encrypt) diff --git a/drivers/crypto/ccp/ccp-crypto.h b/drivers/crypto/ccp/ccp-crypto.h index aa525e6..76d8b63 100644 --- a/drivers/crypto/ccp/ccp-crypto.h +++ b/drivers/crypto/ccp/ccp-crypto.h @@ -223,6 +223,7 @@ struct ccp_rsa_req_ctx { }; #define CCP_RSA_MAXMOD (4 * 1024 / 8) +#define CCP5_RSA_MAXMOD (16 * 1024 / 8) /***** Common Context Structure *****/ struct ccp_ctx { diff --git a/drivers/crypto/ccp/ccp-dev-v3.c b/drivers/crypto/ccp/ccp-dev-v3.c index 7bc0998..3a55628 100644 --- a/drivers/crypto/ccp/ccp-dev-v3.c +++ b/drivers/crypto/ccp/ccp-dev-v3.c @@ -571,4 +571,5 @@ static irqreturn_t ccp_irq_handler(int irq, void *data) .perform = &ccp3_actions, .bar = 2, .offset = 0x20000, + .rsamax = CCP_RSA_MAX_WIDTH, }; diff --git a/drivers/crypto/ccp/ccp-dev-v5.c b/drivers/crypto/ccp/ccp-dev-v5.c index 05300a9..b31be75 100644 --- a/drivers/crypto/ccp/ccp-dev-v5.c +++ b/drivers/crypto/ccp/ccp-dev-v5.c @@ -421,10 +421,10 @@ static int ccp5_perform_rsa(struct ccp_op *op) CCP5_CMD_DST_HI(&desc) = ccp_addr_hi(&op->dst.u.dma); CCP5_CMD_DST_MEM(&desc) = CCP_MEMTYPE_SYSTEM; - /* Exponent is in LSB memory */ - CCP5_CMD_KEY_LO(&desc) = op->sb_key * LSB_ITEM_SIZE; - CCP5_CMD_KEY_HI(&desc) = 0; - CCP5_CMD_KEY_MEM(&desc) = CCP_MEMTYPE_SB; + /* Key (Exponent) is in external memory */ + CCP5_CMD_KEY_LO(&desc) = ccp_addr_lo(&op->exp.u.dma); + CCP5_CMD_KEY_HI(&desc) = ccp_addr_hi(&op->exp.u.dma); + CCP5_CMD_KEY_MEM(&desc) = CCP_MEMTYPE_SYSTEM; return ccp5_do_cmd(&desc, op->cmd_q); } @@ -1013,6 +1013,7 @@ static void ccp5other_config(struct ccp_device *ccp) .perform = &ccp5_actions, .bar = 2, .offset = 0x0, + .rsamax = CCP5_RSA_MAX_WIDTH, }; const struct ccp_vdata ccpv5b = { @@ -1021,4 +1022,5 @@ static void ccp5other_config(struct ccp_device *ccp) .perform = &ccp5_actions, .bar = 2, .offset = 0x0, + .rsamax = CCP5_RSA_MAX_WIDTH, }; diff --git a/drivers/crypto/ccp/ccp-dev.h b/drivers/crypto/ccp/ccp-dev.h index 830f35e..f2e9bcb 100644 --- a/drivers/crypto/ccp/ccp-dev.h +++ b/drivers/crypto/ccp/ccp-dev.h @@ -193,6 +193,7 @@ #define CCP_SHA_SB_COUNT 1 #define CCP_RSA_MAX_WIDTH 4096 +#define CCP5_RSA_MAX_WIDTH 16384 #define CCP_PASSTHRU_BLOCKSIZE 256 #define CCP_PASSTHRU_MASKSIZE 32 @@ -638,6 +639,7 @@ struct ccp_vdata { const struct ccp_actions *perform; const unsigned int bar; const unsigned int offset; + const unsigned int rsamax; }; extern const struct ccp_vdata ccpv3; diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c index 213a752..f7398e9 100644 --- a/drivers/crypto/ccp/ccp-ops.c +++ b/drivers/crypto/ccp/ccp-ops.c @@ -1282,37 +1282,43 @@ static int ccp_run_rsa_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) unsigned int sb_count, i_len, o_len; int ret; - if (rsa->key_size > CCP_RSA_MAX_WIDTH) + /* Check against the maximum allowable size, in bits */ + if (rsa->key_size > cmd_q->ccp->vdata->rsamax) return -EINVAL; if (!rsa->exp || !rsa->mod || !rsa->src || !rsa->dst) return -EINVAL; - /* The RSA modulus must precede the message being acted upon, so - * it must be copied to a DMA area where the message and the - * modulus can be concatenated. Therefore the input buffer - * length required is twice the output buffer length (which - * must be a multiple of 256-bits). - */ - o_len = ((rsa->key_size + 255) / 256) * 32; - i_len = o_len * 2; - - sb_count = o_len / CCP_SB_BYTES; - memset(&op, 0, sizeof(op)); op.cmd_q = cmd_q; - op.jobid = ccp_gen_jobid(cmd_q->ccp); - op.sb_key = cmd_q->ccp->vdata->perform->sballoc(cmd_q, sb_count); + op.jobid = CCP_NEW_JOBID(cmd_q->ccp); - if (!op.sb_key) - return -EIO; + /* Compute o_len, i_len in bytes. */ + if (cmd_q->ccp->vdata->version < CCP_VERSION(4, 0)) { + /* The RSA modulus must precede the message being acted upon, so + * it must be copied to a DMA area where the message and the + * modulus can be concatenated. Therefore the input buffer + * length required is twice the output buffer length (which + * must be a multiple of 256-bits). sb_count is the + * number of storage block slots required for the modulus + */ + o_len = ((rsa->key_size + 255) / 256) * CCP_SB_BYTES; + i_len = o_len * 2; + sb_count = o_len / CCP_SB_BYTES; + + op.sb_key = cmd_q->ccp->vdata->perform->sballoc(cmd_q, + sb_count); + if (!op.sb_key) + return -EIO; + } else { + /* A version 5 device allows a modulus size that will not fit + * in the LSB, so the command will transfer it from memory. + */ + o_len = rsa->mod_len; + i_len = o_len * 2; /* bytes */ + op.sb_key = cmd_q->sb_key; + } - /* The RSA exponent may span multiple (32-byte) SB entries and must - * be in little endian format. Reverse copy each 32-byte chunk - * of the exponent (En chunk to E0 chunk, E(n-1) chunk to E1 chunk) - * and each byte within that chunk and do not perform any byte swap - * operations on the passthru operation. - */ ret = ccp_init_dm_workarea(&exp, cmd_q, o_len, DMA_TO_DEVICE); if (ret) goto e_sb; @@ -1320,11 +1326,23 @@ static int ccp_run_rsa_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) ret = ccp_reverse_set_dm_area(&exp, 0, rsa->exp, 0, rsa->exp_len); if (ret) goto e_exp; - ret = ccp_copy_to_sb(cmd_q, &exp, op.jobid, op.sb_key, - CCP_PASSTHRU_BYTESWAP_NOOP); - if (ret) { - cmd->engine_error = cmd_q->cmd_error; - goto e_exp; + + if (cmd_q->ccp->vdata->version < CCP_VERSION(4, 0)) { + /* The RSA exponent may span multiple (32-byte) KSB entries and + * must be in little endian format. Reverse copy each 32-byte + * chunk of the exponent (En chunk to E0 chunk, E(n-1) chunk to + * E1 chunk) and each byte within that chunk and do not perform + * any byte swap operations on the passthru operation. + */ + ret = ccp_copy_to_sb(cmd_q, &exp, op.jobid, op.sb_key, + CCP_PASSTHRU_BYTESWAP_NOOP); + if (ret) { + cmd->engine_error = cmd_q->cmd_error; + goto e_exp; + } + } else { + op.exp.u.dma.address = exp.dma.address; + op.exp.u.dma.offset = 0; } /* Concatenate the modulus and the message. Both the modulus and @@ -1364,7 +1382,6 @@ static int ccp_run_rsa_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) cmd->engine_error = cmd_q->cmd_error; goto e_dst; } - ccp_reverse_get_dm_area(&dst.dm_wa, 0, rsa->dst, 0, rsa->mod_len); e_dst: @@ -1377,7 +1394,8 @@ static int ccp_run_rsa_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd) ccp_dm_free(&exp); e_sb: - cmd_q->ccp->vdata->perform->sbfree(cmd_q, op.sb_key, sb_count); + if (cmd_q->ccp->vdata->version < CCP_VERSION(4, 0)) + cmd_q->ccp->vdata->perform->sbfree(cmd_q, op.sb_key, sb_count); return ret; }