Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3317773rwl; Mon, 27 Mar 2023 12:14:06 -0700 (PDT) X-Google-Smtp-Source: AKy350b5+QIXaIcg18MgPn8A7iMIwJuxwew9gtepwwlr2k2yHnL6BBUbB/oSlKz44s9PEWE1krXx X-Received: by 2002:a17:906:3c56:b0:92b:e3f0:275f with SMTP id i22-20020a1709063c5600b0092be3f0275fmr11099398ejg.40.1679944446293; Mon, 27 Mar 2023 12:14:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679944446; cv=none; d=google.com; s=arc-20160816; b=cs3nr/9zDekbeB0LMxDwd1IRg9E4/aWOvz9UabCMCV+o8IIyGOn2X8fXNVV5A3brpG YOPMcyww3fhAjjHr/VA8XynVlXApk37pRh1rxPBWh5Qpo1lcW2eENC0EDA7U3Phg+ya7 xiL+rsYJWoNegoOljqXg7Sp1Iqu1KkTcwrToPcnN1PSrGbPgqKoYlMGhRCrPqmqOcfNm CsVFvCrHISVek5MPxQ60pnZRDNQ2QSq9Pp5JDvLrvBbsWpy7VAiLpvPMskC3BGaQBVWP EUCzHO4UBLb+QpiiqL09GR+qKhsy23foeRc/0gFlS9aWa4KAC+aK/UtxNbToJVR0f4jJ Un6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=S5nrT5ovLtFMhqCn/hfEKBhZ/nY+EX9r5enAJrDgC80=; b=MW584CUroiHs5+V54BI8Md3L3DvLyrwv3Qy0vHjHshIgt/90Xe0Iv63QIeGQmAHo7h L1EcTXnQx9cCKjXwWclnSrxLZgrYCNLNilZ3q18p99yCCwztNgmYczPwAOjMhxXf2TcF euJ5SKM/KF0VOOJ0O7aZGoZ4sJtEtPbnkPyXNAICnL7PSFQ6v/M/rVege0EyKahDAOVe WxoDeEsTzFaE5IhXxeM3DWntR2WaOZU5xxbcUCGVuvOsbhqvFyJ26D32S3igngQyjZxG bFGyx3s3vS/ShKCvD70MJmm3wdn+LAJMLqX2vYvRkv0qpR3sPB1YrDTTIwxfHxkZlOe3 UD+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="i/u9quZX"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ks5-20020a170906f84500b00931857da34dsi25539874ejb.53.2023.03.27.12.13.41; Mon, 27 Mar 2023 12:14:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="i/u9quZX"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232289AbjC0TKB (ORCPT + 99 others); Mon, 27 Mar 2023 15:10:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjC0TKA (ORCPT ); Mon, 27 Mar 2023 15:10:00 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69423170A; Mon, 27 Mar 2023 12:09:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1BC52B818C4; Mon, 27 Mar 2023 19:09:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C28AC433EF; Mon, 27 Mar 2023 19:09:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679944196; bh=md2d2PPOqe1luXPAuVx3FdS34LUYmDoWYP3MNTkgt1w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=i/u9quZXyxBAuvWcTmM1kYd7nwq341KWzTeEB9TErt1tmb2YA5pwR7EYqL88vIc8e RxFMumxUuU3cBQhuHzFg70H13RCkKJF+jzxUE9xJnTpGEVEK4O0E7j63wssG7FTEqo s2ayXeMDdmWOUT7v6/0SOD3n0cjfg4pgtpHXzod+h3g8XS3LhlJx302y8nIXvlmKsD FG6aIzRe7pg+ndJ69hphx0c8BbV80evoMkx0SsXEV9HyVVP3sBUpSm2IzPBadrixf0 eSeToWJhDH5SRML6gClOwv8DzDVyhuqd5tukvtmcZItLO9yDbjOWo/Wi3YVqbpdums /8SSlaR/2sjwg== Date: Mon, 27 Mar 2023 12:09:54 -0700 From: Eric Biggers To: Bjorn Andersson Cc: Abel Vesa , Ulf Hansson , Rob Herring , Krzysztof Kozlowski , Andy Gross , Konrad Dybcio , Manivannan Sadhasivam , Alim Akhtar , Avri Altman , Bart Van Assche , Adrian Hunter , "James E . J . Bottomley" , "Martin K . Petersen" , Herbert Xu , "David S . Miller" , linux-mmc@vger.kernel.org, devicetree@vger.kernel.org, Linux Kernel Mailing List , linux-arm-msm@vger.kernel.org, linux-crypto@vger.kernel.org, linux-scsi@vger.kernel.org Subject: Re: [PATCH v4 4/7] soc: qcom: Make the Qualcomm UFS/SDCC ICE a dedicated driver Message-ID: <20230327190954.GE73752@sol.localdomain> References: <20230327134734.3256974-1-abel.vesa@linaro.org> <20230327134734.3256974-5-abel.vesa@linaro.org> <20230327185358.c4emwquhouq42itf@ripper> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230327185358.c4emwquhouq42itf@ripper> X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 27, 2023 at 11:53:58AM -0700, Bjorn Andersson wrote: > > +int qcom_ice_program_key(struct qcom_ice *ice, > > + u8 algorithm_id, u8 key_size, > > + const u8 crypto_key[], u8 data_unit_size, > > + int slot) > > +{ > > + struct device *dev = ice->dev; > > + union { > > + u8 bytes[AES_256_XTS_KEY_SIZE]; > > + u32 words[AES_256_XTS_KEY_SIZE / sizeof(u32)]; > > + } key; > > + int i; > > + int err; > > + > > + /* Only AES-256-XTS has been tested so far. */ > > + if (algorithm_id != QCOM_ICE_CRYPTO_ALG_AES_XTS || > > + key_size != QCOM_ICE_CRYPTO_KEY_SIZE_256) { > > + dev_err_ratelimited(dev, > > + "Unhandled crypto capability; algorithm_id=%d, key_size=%d\n", > > + algorithm_id, key_size); > > + return -EINVAL; > > + } > > + > > + memcpy(key.bytes, crypto_key, AES_256_XTS_KEY_SIZE); > > + > > + /* > > + * The SCM call byte-swaps the 32-bit words of the key. > > + * So we have to do the same, in order for the final key be correct. > > Does it actually byte swap the words, or is the API just specified to > take the words in big endian format? [Note, this is existing code I wrote that Abel is just moving to a new file.] It doesn't write to the input array, if that is what you are asking. I was thinking of this as one byte swap cancelling out another. But sure, the comment could be simplified to something like the following: /* The SCM call requires that the key words be byte-swapped. */ > How come you memcpy + swap in place, instead of loop over the words and > cpu_to_be32() them into a __be words[] array? > > > + */ > > + for (i = 0; i < ARRAY_SIZE(key.words); i++) > > + __cpu_to_be32s(&key.words[i]); With this approach there is no need to worry about unaligned memory accesses. It could be done with unaligned memory accesses, though, if you prefer that: union { [...] __be32 words[...]; } key; [...] key.words[i] = cpu_to_be32(get_unaligned((__u32 *)crypto_key + i)); - Eric