Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp35911lfe; Fri, 15 Apr 2022 18:12:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZJWqMLKRTmNwVPRVv5kLW+q+9ox6M/zl9rZIF8uhXlNy0UqJuNH0LrtxaSPEjiOpmkrxV X-Received: by 2002:a05:6a00:228b:b0:4fa:e12b:2c7b with SMTP id f11-20020a056a00228b00b004fae12b2c7bmr1404232pfe.79.1650071567731; Fri, 15 Apr 2022 18:12:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650071567; cv=none; d=google.com; s=arc-20160816; b=SvAAmrkTJYoWOvpQgY1blZz2ZZVcXZ9sENYZ+OKbJ5CmrD/W5GoS2JivAamyYDMQ1X kJczD2cTYfjg1ir08VYX/fqwRI/XM9yaxfvon26Snf5yE5SQ5IkM2lkW78ZcuSjr/UzM earCsZrpcAG2WSX5JyOpBmIHbUEtIlyE3ESntaGb1rNvoB9XErXBiW0RPu22tWlC1dLo OfJO1Ce0voflVSGOEK271gcH42tHJsiToSMWrwg7Efxa3jVMNG9FbANf7M1enINgkdez rY7NA53PCiQzBbVtkFi3zEDv0TDTrK7RGzHhKbVfHzzhO3DKh7+kvVbiFLZ3IC4IuNSH VEsQ== 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; bh=cyeXw9XQYQoWDebmYYTovstbP7fpqJ2kMtPJk6kOsDw=; b=rTnAERTNaE4LuhawxrpDT0jUKUoT8r07eH/4FHCFwKXv5rWo9KIBq1sUKAWCph60J7 eunyyWDPt3RnWT4UJsaktr9X2HXeKyXA2ea1H8LoJEJHy3LEPGKlo0dPF+VsU3XrDz69 96oREXzveHkyXrPvJhkq7GjJsJAuxXMN3uypusj45Q4noMKyn1ptecWvQdFsLNWRYDVJ YGoFmVGMUsUPK6oKctThCqch4dN1/z7XEs8xG8r+98h8DgnF5qpLrBT9M+BJlhHP4pZ1 E5CVJd/aQMTPUGtXoNQrGWJQ2IokYgeGye4NTb5NtsNzaT/2DKlDsvEiszkLRC+Z27w4 NVjQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b190-20020a6334c7000000b0039845840ff2si3371584pga.41.2022.04.15.18.12.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 18:12:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8B1331ADB5; Fri, 15 Apr 2022 17:49:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353160AbiDOMVc (ORCPT + 99 others); Fri, 15 Apr 2022 08:21:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241445AbiDOMVb (ORCPT ); Fri, 15 Apr 2022 08:21:31 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5D9EBF969 for ; Fri, 15 Apr 2022 05:19:02 -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 sin.source.kernel.org (Postfix) with ESMTPS id 1C83BCE2C65 for ; Fri, 15 Apr 2022 12:19:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15709C385A6; Fri, 15 Apr 2022 12:18:56 +0000 (UTC) Date: Fri, 15 Apr 2022 13:18:53 +0100 From: Catalin Marinas To: Ard Biesheuvel Cc: Herbert Xu , Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds , Linux Memory Management List , Linux ARM , Linux Kernel Mailing List , "David S. Miller" Subject: Re: [PATCH 07/10] crypto: Use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Fri, Apr 15, 2022 at 10:05:21AM +0200, Ard Biesheuvel wrote: > On Fri, 15 Apr 2022 at 09:52, Herbert Xu wrote: > > On Fri, Apr 15, 2022 at 09:49:12AM +0200, Ard Biesheuvel wrote: > > > I'm not sure I understand what would go wrong if that assumption no > > > longer holds. > > > > It's very simple, we don't do anything to the pointer returned > > by kmalloc before returning it as a tfm or other object with > > an alignment of CRYPTO_MINALIGN. IOW if kmalloc starts returning > > pointers that are not aligned to CRYPTO_MINALIGN then we'd be > > lying to the compiler. > > I guess that should be fixable. GIven that this is about padding > rather than alignment, we could do something like > > struct crypto_request { > union { > struct { > ... fields ... > }; > u8 __padding[ARCH_DMA_MINALIGN]; > }; > void __ctx[] __align(CRYPTO_MINALIGN); > }; > > And then hopefully, we can get rid of the padding once we fix drivers > doing non-cache coherent inbound DMA into those structures. But if we keep CRYPTO_MINALIGN as 128, don't we get the padding automatically? struct crypto_request { ... void *__ctx[] CRYPTO_MINALIGN_ATTR; }; __alignof__(struct crypto_request) == 128; sizeof(struct crypto_request) == N * 128 The same alignment and size is true for a structure like: struct crypto_alg { ... } CRYPTO_MINALIGN_ATTR; Any kmalloc() of sizeof(the above structures) will return a pointer aligned to 128, irrespective of what ARCH_KMALLOC_MINALIGN is. The problem is if you have a structure without any alignment attribute (just ABI default), making its sizeof() smaller than ARCH_DMA_MINALIGN. In this case kmalloc() could return a pointer aligned to something smaller. Is this the case in the crypto code today? I can see it uses the right alignment annotations already, no need for kmalloc() hacks. -- Catalin