From patchwork Wed Nov 25 21:13:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Iuliana Prodan \(OSS\)" X-Patchwork-Id: 332470 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AB98C56201 for ; Wed, 25 Nov 2020 21:14:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4846206F9 for ; Wed, 25 Nov 2020 21:14:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="M8Md095U" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731681AbgKYVOK (ORCPT ); Wed, 25 Nov 2020 16:14:10 -0500 Received: from mail-eopbgr130089.outbound.protection.outlook.com ([40.107.13.89]:61059 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731620AbgKYVOJ (ORCPT ); Wed, 25 Nov 2020 16:14:09 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VLEapNHS3FKUkT4cHlvMkJl/mIfJukWfy8ecXQxyg04uo6c/gdwSVpNbw/NTKl4D5ErWStsBpet8lp2Y+kZevWmQOARymXUfD3751N8JFxuUtfsw2f/VL1l4WGMDHR+/81UzK1M1QZkIJdP8Fe/vXuhCLObIuCAvyi4ZO0v3QeHC9JIWTaOUjQqKVwJpATzrzdVAo4tMJiJFxem/ZY4QM0yUuIF5k+dWI/zBjg52M3hUR5e1tA91v3Z9hOsrpAY49O75+afeNvbUG6kPTQtAOKoMQtmJzvdp7CNY0++9ia4t/9vmxGSPaLu4/+lA+m+glZy6z/wsSNzD829ilSWIfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tYKtAFvRxYSZWDwUkMtts25k89Czo+yQlNPH6uXzzV8=; b=Y2vneyZHxFM8gOMYILTxYjSHPr3WwNwy+h6SqkazwRjpYIMmtDhVx4fDaLwryZS1I3u/KpYNQhPy+utM2SvlQc2MB3Ive5IuhJQx8H4rE0YQCKLYxUXVr8Yu5I9ntSOrs09iGlxUsKXFzNbXhI8/zphgRyPSbkngFnSyKhNlRlW1fLJa4zcThKCcfsJZHO8EfpMzc9XmG49Gmyu3e0aN1BmuzYN2FKa84xbJEamEBPpN/RQlgJqXJu6l56zwgMBqweo5rWTx2QgonflPjuDqNLq93DtrGDlxEwVq5fRTKLedLIds/WL57hv2m1cfooIFODpco1GMbOIuNDFbpaAVTw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tYKtAFvRxYSZWDwUkMtts25k89Czo+yQlNPH6uXzzV8=; b=M8Md095UF07A1+hWh2vso9/as6XN3w2mNpFYYERYiVNKuOaywCR+3C1s7ANHGVsE+oM/4UbVe94V7gEi6iBRm6cs7UTPX9LVbPIiAA5qHYWfd7up/uFhsgnDqb9NwGWRMvjBjN+HyPa8vJT6pkuVTDIQ1zhA615cfcp6IE5wSf0= Authentication-Results: gondor.apana.org.au; dkim=none (message not signed) header.d=none; gondor.apana.org.au; dmarc=none action=none header.from=oss.nxp.com; Received: from VI1PR0402MB3712.eurprd04.prod.outlook.com (2603:10a6:803:1c::25) by VI1PR04MB6941.eurprd04.prod.outlook.com (2603:10a6:803:12e::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.22; Wed, 25 Nov 2020 21:14:05 +0000 Received: from VI1PR0402MB3712.eurprd04.prod.outlook.com ([fe80::ade4:e169:1f4a:28c]) by VI1PR0402MB3712.eurprd04.prod.outlook.com ([fe80::ade4:e169:1f4a:28c%4]) with mapi id 15.20.3589.025; Wed, 25 Nov 2020 21:14:05 +0000 From: "Iuliana Prodan (OSS)" To: Herbert Xu , Ard Biesheuvel , "David S. Miller" , Horia Geanta Cc: Aymen Sghaier , Silvano Di Ninno , Franck Lenormand , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-imx , Iuliana Prodan Subject: [RFC PATCH 1/4] crypto: add CRYPTO_TFM_REQ_DMA flag Date: Wed, 25 Nov 2020 23:13:08 +0200 Message-Id: <20201125211311.2179-2-iuliana.prodan@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201125211311.2179-1-iuliana.prodan@oss.nxp.com> References: <20201125211311.2179-1-iuliana.prodan@oss.nxp.com> X-Originating-IP: [83.217.231.2] X-ClientProxiedBy: AM0PR10CA0117.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:e6::34) To VI1PR0402MB3712.eurprd04.prod.outlook.com (2603:10a6:803:1c::25) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lsv15040.swis.ro-buh01.nxp.com (83.217.231.2) by AM0PR10CA0117.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:e6::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.22 via Frontend Transport; Wed, 25 Nov 2020 21:14:03 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 307897c8-1c88-4693-b522-08d891870a01 X-MS-TrafficTypeDiagnostic: VI1PR04MB6941: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pSLW/n9+w9sFUnAWZ9tLGb8s76dTzLePm4FDYQ+MGC2jDTo6FKjosjOycGuFYcXGGhg99PMMjvejBoUqPlVUgtiEGxki7LCzMvU1Bd/hFsQA6vM4oAdJ8myu3KzmLX1WeCatJSGbHHm3aF/v4LNTQqlzN1Mvx4govmXK6qZ84631eG46gA8ZRH8Z/mGp05PO1Ot6QXO1hUbrUyIHsEMws8RiMwtiC/5TTp/Q+tWHeHVwbAKPdjtSlUPI2NT94bFeti9bYHzafwaecwq2G1vmUDHSSXhobO5un8K65fH4TxgmkHnpBd67iJD+D8BMFUF+JJjxgduKsnoXd3J07vDKtw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR0402MB3712.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(39860400002)(376002)(396003)(366004)(136003)(316002)(86362001)(5660300002)(66476007)(66556008)(186003)(52116002)(6512007)(66946007)(26005)(110136005)(54906003)(2906002)(8676002)(6486002)(16526019)(4326008)(83380400001)(8936002)(478600001)(1076003)(6506007)(956004)(2616005); DIR:OUT;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Tenant-Network-Message-Id: 307897c8-1c88-4693-b522-08d891870a01 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3712.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Nov 2020 21:14:04.9270 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: b6q7PHvUka6a9BgFqIfP2k1ERHD4ftlJAedYuvx3zO4+tQZpvV9T0PtHy/Z0R57M2z0unWt02TO50G+dKk/hTA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6941 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Iuliana Prodan The CRYPTO_TFM_REQ_DMA flag can be used by backend implementations to indicate to crypto API the need to allocate GFP_DMA memory for private contexts of the crypto requests. For public key encryption add the needed functions to set/get/clear flags. Signed-off-by: Horia Geanta Signed-off-by: Iuliana Prodan --- include/crypto/aead.h | 4 ++++ include/crypto/akcipher.h | 21 +++++++++++++++++++++ include/crypto/hash.h | 4 ++++ include/crypto/skcipher.h | 4 ++++ include/linux/crypto.h | 1 + 5 files changed, 34 insertions(+) diff --git a/include/crypto/aead.h b/include/crypto/aead.h index fcc12c593ef8..ae2ef87cfb0d 100644 --- a/include/crypto/aead.h +++ b/include/crypto/aead.h @@ -416,6 +416,10 @@ static inline struct aead_request *aead_request_alloc(struct crypto_aead *tfm, { struct aead_request *req; + if (crypto_aead_reqsize(tfm) && + (crypto_aead_get_flags(tfm) & CRYPTO_TFM_REQ_DMA)) + gfp |= GFP_DMA; + req = kmalloc(sizeof(*req) + crypto_aead_reqsize(tfm), gfp); if (likely(req)) diff --git a/include/crypto/akcipher.h b/include/crypto/akcipher.h index 1d3aa252caba..c06c140d1b7a 100644 --- a/include/crypto/akcipher.h +++ b/include/crypto/akcipher.h @@ -158,6 +158,23 @@ static inline unsigned int crypto_akcipher_reqsize(struct crypto_akcipher *tfm) return crypto_akcipher_alg(tfm)->reqsize; } +static inline u32 crypto_akcipher_get_flags(struct crypto_akcipher *tfm) +{ + return crypto_tfm_get_flags(crypto_akcipher_tfm(tfm)); +} + +static inline void crypto_akcipher_set_flags(struct crypto_akcipher *tfm, + u32 flags) +{ + crypto_tfm_set_flags(crypto_akcipher_tfm(tfm), flags); +} + +static inline void crypto_akcipher_clear_flags(struct crypto_akcipher *tfm, + u32 flags) +{ + crypto_tfm_clear_flags(crypto_akcipher_tfm(tfm), flags); +} + static inline void akcipher_request_set_tfm(struct akcipher_request *req, struct crypto_akcipher *tfm) { @@ -193,6 +210,10 @@ static inline struct akcipher_request *akcipher_request_alloc( { struct akcipher_request *req; + if (crypto_akcipher_reqsize(tfm) && + (crypto_akcipher_get_flags(tfm) & CRYPTO_TFM_REQ_DMA)) + gfp |= GFP_DMA; + req = kmalloc(sizeof(*req) + crypto_akcipher_reqsize(tfm), gfp); if (likely(req)) akcipher_request_set_tfm(req, tfm); diff --git a/include/crypto/hash.h b/include/crypto/hash.h index af2ff31ff619..cb28be54569a 100644 --- a/include/crypto/hash.h +++ b/include/crypto/hash.h @@ -599,6 +599,10 @@ static inline struct ahash_request *ahash_request_alloc( { struct ahash_request *req; + if (crypto_ahash_reqsize(tfm) && + (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_REQ_DMA)) + gfp |= GFP_DMA; + req = kmalloc(sizeof(struct ahash_request) + crypto_ahash_reqsize(tfm), gfp); diff --git a/include/crypto/skcipher.h b/include/crypto/skcipher.h index 6a733b171a5d..3c598b56628b 100644 --- a/include/crypto/skcipher.h +++ b/include/crypto/skcipher.h @@ -493,6 +493,10 @@ static inline struct skcipher_request *skcipher_request_alloc( { struct skcipher_request *req; + if (crypto_skcipher_reqsize(tfm) && + (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_REQ_DMA)) + gfp |= GFP_DMA; + req = kmalloc(sizeof(struct skcipher_request) + crypto_skcipher_reqsize(tfm), gfp); diff --git a/include/linux/crypto.h b/include/linux/crypto.h index ef90e07c9635..87d7f0563c13 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h @@ -141,6 +141,7 @@ #define CRYPTO_TFM_REQ_FORBID_WEAK_KEYS 0x00000100 #define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200 #define CRYPTO_TFM_REQ_MAY_BACKLOG 0x00000400 +#define CRYPTO_TFM_REQ_DMA 0x00000800 /* * Miscellaneous stuff.