struct timespec64 req_time;
 };
 
+static inline unsigned int hpre_align_sz(void)
+{
+       return ((crypto_dma_align() - 1) | (HPRE_ALIGN_SZ - 1)) + 1;
+}
+
+static inline unsigned int hpre_align_pd(void)
+{
+       return (hpre_align_sz() - 1) & ~(crypto_tfm_ctx_alignment() - 1);
+}
+
 static int hpre_alloc_req_id(struct hpre_ctx *ctx)
 {
        unsigned long flags;
                }
 
                tmp = akcipher_request_ctx(akreq);
-               h_req = PTR_ALIGN(tmp, HPRE_ALIGN_SZ);
+               h_req = PTR_ALIGN(tmp, hpre_align_sz());
                h_req->cb = hpre_rsa_cb;
                h_req->areq.rsa = akreq;
                msg = &h_req->req;
                }
 
                tmp = kpp_request_ctx(kreq);
-               h_req = PTR_ALIGN(tmp, HPRE_ALIGN_SZ);
+               h_req = PTR_ALIGN(tmp, hpre_align_sz());
                h_req->cb = hpre_dh_cb;
                h_req->areq.dh = kreq;
                msg = &h_req->req;
        struct crypto_kpp *tfm = crypto_kpp_reqtfm(req);
        struct hpre_ctx *ctx = kpp_tfm_ctx(tfm);
        void *tmp = kpp_request_ctx(req);
-       struct hpre_asym_request *hpre_req = PTR_ALIGN(tmp, HPRE_ALIGN_SZ);
+       struct hpre_asym_request *hpre_req = PTR_ALIGN(tmp, hpre_align_sz());
        struct hpre_sqe *msg = &hpre_req->req;
        int ret;
 
 {
        struct hpre_ctx *ctx = kpp_tfm_ctx(tfm);
 
-       kpp_set_reqsize(tfm, sizeof(struct hpre_asym_request) + HPRE_ALIGN_SZ);
+       kpp_set_reqsize(tfm, sizeof(struct hpre_asym_request) + hpre_align_pd());
 
        return hpre_ctx_init(ctx, HPRE_V2_ALG_TYPE);
 }
        struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
        struct hpre_ctx *ctx = akcipher_tfm_ctx(tfm);
        void *tmp = akcipher_request_ctx(req);
-       struct hpre_asym_request *hpre_req = PTR_ALIGN(tmp, HPRE_ALIGN_SZ);
+       struct hpre_asym_request *hpre_req = PTR_ALIGN(tmp, hpre_align_sz());
        struct hpre_sqe *msg = &hpre_req->req;
        int ret;
 
        struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
        struct hpre_ctx *ctx = akcipher_tfm_ctx(tfm);
        void *tmp = akcipher_request_ctx(req);
-       struct hpre_asym_request *hpre_req = PTR_ALIGN(tmp, HPRE_ALIGN_SZ);
+       struct hpre_asym_request *hpre_req = PTR_ALIGN(tmp, hpre_align_sz());
        struct hpre_sqe *msg = &hpre_req->req;
        int ret;
 
        }
 
        akcipher_set_reqsize(tfm, sizeof(struct hpre_asym_request) +
-                                 HPRE_ALIGN_SZ);
+                                 hpre_align_pd());
 
        ret = hpre_ctx_init(ctx, HPRE_V2_ALG_TYPE);
        if (ret)
        }
 
        tmp = kpp_request_ctx(req);
-       h_req = PTR_ALIGN(tmp, HPRE_ALIGN_SZ);
+       h_req = PTR_ALIGN(tmp, hpre_align_sz());
        h_req->cb = hpre_ecdh_cb;
        h_req->areq.ecdh = req;
        msg = &h_req->req;
        struct hpre_ctx *ctx = kpp_tfm_ctx(tfm);
        struct device *dev = ctx->dev;
        void *tmp = kpp_request_ctx(req);
-       struct hpre_asym_request *hpre_req = PTR_ALIGN(tmp, HPRE_ALIGN_SZ);
+       struct hpre_asym_request *hpre_req = PTR_ALIGN(tmp, hpre_align_sz());
        struct hpre_sqe *msg = &hpre_req->req;
        int ret;
 
 
        ctx->curve_id = ECC_CURVE_NIST_P192;
 
-       kpp_set_reqsize(tfm, sizeof(struct hpre_asym_request) + HPRE_ALIGN_SZ);
+       kpp_set_reqsize(tfm, sizeof(struct hpre_asym_request) + hpre_align_pd());
 
        return hpre_ctx_init(ctx, HPRE_V3_ECC_ALG_TYPE);
 }
 
        ctx->curve_id = ECC_CURVE_NIST_P256;
 
-       kpp_set_reqsize(tfm, sizeof(struct hpre_asym_request) + HPRE_ALIGN_SZ);
+       kpp_set_reqsize(tfm, sizeof(struct hpre_asym_request) + hpre_align_pd());
 
        return hpre_ctx_init(ctx, HPRE_V3_ECC_ALG_TYPE);
 }
 
        ctx->curve_id = ECC_CURVE_NIST_P384;
 
-       kpp_set_reqsize(tfm, sizeof(struct hpre_asym_request) + HPRE_ALIGN_SZ);
+       kpp_set_reqsize(tfm, sizeof(struct hpre_asym_request) + hpre_align_pd());
 
        return hpre_ctx_init(ctx, HPRE_V3_ECC_ALG_TYPE);
 }
        }
 
        tmp = kpp_request_ctx(req);
-       h_req = PTR_ALIGN(tmp, HPRE_ALIGN_SZ);
+       h_req = PTR_ALIGN(tmp, hpre_align_sz());
        h_req->cb = hpre_curve25519_cb;
        h_req->areq.curve25519 = req;
        msg = &h_req->req;
        struct hpre_ctx *ctx = kpp_tfm_ctx(tfm);
        struct device *dev = ctx->dev;
        void *tmp = kpp_request_ctx(req);
-       struct hpre_asym_request *hpre_req = PTR_ALIGN(tmp, HPRE_ALIGN_SZ);
+       struct hpre_asym_request *hpre_req = PTR_ALIGN(tmp, hpre_align_sz());
        struct hpre_sqe *msg = &hpre_req->req;
        int ret;
 
 {
        struct hpre_ctx *ctx = kpp_tfm_ctx(tfm);
 
-       kpp_set_reqsize(tfm, sizeof(struct hpre_asym_request) + HPRE_ALIGN_SZ);
+       kpp_set_reqsize(tfm, sizeof(struct hpre_asym_request) + hpre_align_pd());
 
        return hpre_ctx_init(ctx, HPRE_V3_ECC_ALG_TYPE);
 }