Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2445394pxb; Sun, 17 Apr 2022 23:29:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFeIUbKsulEgWzQpa4D19GcsUlU1km5cRk4vzNxh2Q2PIfUZEKqd+/4NCD03Tuomx6flMA X-Received: by 2002:a17:90b:4d8f:b0:1cd:9c29:e411 with SMTP id oj15-20020a17090b4d8f00b001cd9c29e411mr11523154pjb.119.1650263388968; Sun, 17 Apr 2022 23:29:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650263388; cv=none; d=google.com; s=arc-20160816; b=rglf6BV0QNfIAsZVUtcogeCbn44ILhRTDf+5YGI6bjA2NihbbimCvve/bsUSQu2Nni hFMc4Z8nL/7nqe+w7H3uGukoOG5nwERDShLLRiHAUJe6CD2gMrk6kpwijIZT2h0g0ter T9OfX5l8aRpaPKrHspozEh24mvmG2wwjD/ltit2FxVktPASlItc3KvqLvau5KhNtiIqS 2Ylg5Bd6e5xFonzORy56DbhZUuap+DlDh0kgSmEVH5nKuuzQ4yT7qX0ove20JzjgC/S8 LMZLWCoySqJa8E8XK6m4/g7c998TM81q7tAthJpYGw/Wl4Kerp3gCPT6MI3Ei3x2IhId 8JlA== 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=0aIxTVJTnwc0HR10Tm1eJzt7lYUS1pB6ImTKy29yBsI=; b=MPNrGNMXTbb90A9d3f5cxw9Ux7ubGwfKx209cVJoaJfQC0Sl9NOTi1UZYkfDwpxFqm Fu3pcWzfa9o74Mee3U9F1+dos4xX+DnhPed1F9TfshMAuYoVLV8+U+lC5MtE/wKDlKkf yJZoApQ9dLSU48dfTBtfNWjPVO/JB99W55xjDODcSw0KJtFD3lDBbnQ8mFUBIt9lM7FN HK/bCPxUXAybFW8QukTS4gZ2/wXOoqtAtjb3YnL9RT4b7ubcuDM3+zfOMKcdBgxkVQN/ WO+3e0nQaT0HtdWT0XHLCyByS6PrulITUuMnnONBYnfxwRAo7DrhetxWHwQqFknVt0HV iM4Q== 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:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mh9-20020a17090b4ac900b001cb6eb55244si12030885pjb.93.2022.04.17.23.29.34; Sun, 17 Apr 2022 23:29:48 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233657AbiDQIlY (ORCPT + 99 others); Sun, 17 Apr 2022 04:41:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbiDQIlX (ORCPT ); Sun, 17 Apr 2022 04:41:23 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9162E63F5 for ; Sun, 17 Apr 2022 01:38:48 -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 425A3B80AAD for ; Sun, 17 Apr 2022 08:38:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8B32C385A4; Sun, 17 Apr 2022 08:38:43 +0000 (UTC) Date: Sun, 17 Apr 2022 09:38:40 +0100 From: Catalin Marinas To: Herbert Xu Cc: Ard Biesheuvel , 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=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 Sun, Apr 17, 2022 at 04:11:22PM +0800, Herbert Xu wrote: > On Fri, Apr 15, 2022 at 01:31:32PM +0100, Catalin Marinas wrote: > > > > This needs a clarification. For the above structure, kmalloc() will > > return a 128-byte aligned pointer since sizeof(x) is a multiple of 128. > > The potential problem is if you have something like: > > > > kmalloc(sizeof(struct x) + 64); > > > > The above could end up as a kmalloc(192) which is available with an > > ARCH_KMALLOC_MINALIGN of 64. If that's a real use-case, I can change the > > slab patch to not create the 192 (or 48 if we go for an even smaller > > ARCH_KMALLOC_MINALIGN) caches and we'd always have ARCH_DMA_MINALIGN > > guarantee if the structure itself is correctly aligned. No lying to the > > compiler. > > Yes I suppose that should work: > > 1) Enlarge each crypto API object so that they're >= 128 bytes; I don't think we need to do anything here. A structure like: struct x { char y; char z[] CRYPTO_MINALIGN_ATTR; }; is already of size 128. Without CRYPTO_MINALIGN_ATTR, its size would be 1 but otherwise the whole structure inherits the alignment of its member and this translates into an aligned size. > 2) Modify kmalloc so that for sizes >= 128 bytes they're padded > to multiples of 128. This doesn't look like a hack, we want to honour the power of 2 alignments. -- Catalin