From mboxrd@z Thu Jan 1 00:00:00 1970 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=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 5CCAAC433E1 for ; Fri, 21 Aug 2020 11:04:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 427A020738 for ; Fri, 21 Aug 2020 11:04:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728004AbgHULEM (ORCPT ); Fri, 21 Aug 2020 07:04:12 -0400 Received: from mga05.intel.com ([192.55.52.43]:50153 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726118AbgHULEL (ORCPT ); Fri, 21 Aug 2020 07:04:11 -0400 IronPort-SDR: fRbEQ4nk4e9JMPTVyNlX6jWYsfKF6ZENSzlo/Ba5VzRUSve0v1OHhU4i8eK2+/nLidgp6YLeLk b0Wl9uztwiuw== X-IronPort-AV: E=McAfee;i="6000,8403,9719"; a="240329777" X-IronPort-AV: E=Sophos;i="5.76,335,1592895600"; d="scan'208";a="240329777" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2020 04:04:09 -0700 IronPort-SDR: uPIWNjKsgmbTmy5qFnQmjlcXjSPlC9PcnJM8fhrBao6WeY3rUFZ9ULanV04N/M1SeF1IQ6zCSW XOvQ5hAYzzlw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,335,1592895600"; d="scan'208";a="327733294" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga008.jf.intel.com with ESMTP; 21 Aug 2020 04:04:05 -0700 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1k94q3-00AKBu-B3; Fri, 21 Aug 2020 14:04:03 +0300 Date: Fri, 21 Aug 2020 14:04:03 +0300 From: Andy Shevchenko To: Bartosz Golaszewski Cc: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Michal Simek , Greg Kroah-Hartman , Guenter Roeck , linux-iio , Linux ARM , Linux Kernel Mailing List , Bartosz Golaszewski Subject: Re: [PATCH v8 1/3] devres: provide devm_krealloc() Message-ID: <20200821110403.GP1891694@smile.fi.intel.com> References: <20200820185110.17828-1-brgl@bgdev.pl> <20200820185110.17828-2-brgl@bgdev.pl> <20200821081555.GG1891694@smile.fi.intel.com> <20200821105119.GL1891694@smile.fi.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200821105119.GL1891694@smile.fi.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 21, 2020 at 01:51:19PM +0300, Andy Shevchenko wrote: > On Fri, Aug 21, 2020 at 10:59:19AM +0200, Bartosz Golaszewski wrote: > > On Fri, Aug 21, 2020 at 10:35 AM Andy Shevchenko > > wrote: > > > On Thu, Aug 20, 2020 at 08:51:08PM +0200, Bartosz Golaszewski wrote: ... > > > > +static struct devres *to_devres(void *data) > > > > +{ > > > > + return data - ALIGN(sizeof(struct devres), ARCH_KMALLOC_MINALIGN); > > > > +} > > > > + > > > > +static size_t devres_data_size(size_t total_size) > > > > +{ > > > > + return total_size - ALIGN(sizeof(struct devres), ARCH_KMALLOC_MINALIGN); > > > > +} > > The data pointer in struct devres is defined as: > > > > u8 __aligned(ARCH_KMALLOC_MINALIGN) data[]; > > > > And this value (assigned the value of ARCH_DMA_MINALIGN) varies from > > one arch to another. I wasn't really sure if offsetof() would work for > > every case so I went with something very explicit. > > I have checked with a small program simulating to_devres() with your variant, > offsetof() and container_of(). > > The result is this: if MINALIGN < sizeof(long) and since struct is unpacked the > offsetof(), and thus container_of(), gives correct result, while ALIGN() > approach mistakenly moves pointer too back. ... > I think you need to change this to use container_of() and offsetof(). To be clear, there is probably no real problem, except unlikely possible MINALIGN=4 on 64-bit arch, but for sake of the correctness. -- With Best Regards, Andy Shevchenko From mboxrd@z Thu Jan 1 00:00:00 1970 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=-3.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 A96E1C433E1 for ; Fri, 21 Aug 2020 11:05:31 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 76D5D20738 for ; Fri, 21 Aug 2020 11:05:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="r9+ILOKA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 76D5D20738 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=gQ3Vmf62/WJhcYFwjXoYd04nhnD8/X0z0JcrselVFAE=; b=r9+ILOKA9waWmBhUD+noHKPko 6qweLfyydWG751WSQFTWfJhJEJ0f/1FlAS7S9rf6cDHIAtg9ynav2eUpnqLeFzc0QjC2gfFaFaKIg utaDmhQNs0U496K7f/ZXVqWs5Xtbl0BZXrsVO474eeFY5gzoOgwEudo2CeXXiqkbykREpnMCzdXP0 xbb+QWhfli3VXAXObNATMGw5lL/l4Dkymhr4Nbq5XkvJ7Ls2NZOEFfVYnADxMkx+A5W4hcpjZzxXw OFXqxdVNFKCguLTSNGUo6fH3Gg04xwyYmJwlc5dxunAitlkYeEBu5ukmCVwMVEmmEJsZizC+5yczz yC53nXnNA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k94qF-0005N5-9Q; Fri, 21 Aug 2020 11:04:15 +0000 Received: from mga07.intel.com ([134.134.136.100]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k94qC-0005Mb-K6 for linux-arm-kernel@lists.infradead.org; Fri, 21 Aug 2020 11:04:13 +0000 IronPort-SDR: Cmg9iXxsGSQmvLJmnW1koL2s1freyCt63Z8a6aGeKCfSxQyyjtYGY6tRRroCEML/j/PCFB7yXu pCPsB3Bku7eg== X-IronPort-AV: E=McAfee;i="6000,8403,9719"; a="219802792" X-IronPort-AV: E=Sophos;i="5.76,335,1592895600"; d="scan'208";a="219802792" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2020 04:04:08 -0700 IronPort-SDR: uPIWNjKsgmbTmy5qFnQmjlcXjSPlC9PcnJM8fhrBao6WeY3rUFZ9ULanV04N/M1SeF1IQ6zCSW XOvQ5hAYzzlw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,335,1592895600"; d="scan'208";a="327733294" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga008.jf.intel.com with ESMTP; 21 Aug 2020 04:04:05 -0700 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1k94q3-00AKBu-B3; Fri, 21 Aug 2020 14:04:03 +0300 Date: Fri, 21 Aug 2020 14:04:03 +0300 From: Andy Shevchenko To: Bartosz Golaszewski Subject: Re: [PATCH v8 1/3] devres: provide devm_krealloc() Message-ID: <20200821110403.GP1891694@smile.fi.intel.com> References: <20200820185110.17828-1-brgl@bgdev.pl> <20200820185110.17828-2-brgl@bgdev.pl> <20200821081555.GG1891694@smile.fi.intel.com> <20200821105119.GL1891694@smile.fi.intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200821105119.GL1891694@smile.fi.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200821_070412_814815_D81939FD X-CRM114-Status: GOOD ( 20.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linux ARM , Lars-Peter Clausen , linux-iio , Greg Kroah-Hartman , Michal Simek , Linux Kernel Mailing List , Bartosz Golaszewski , Guenter Roeck , Peter Meerwald-Stadler , Hartmut Knaack , Jonathan Cameron Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Aug 21, 2020 at 01:51:19PM +0300, Andy Shevchenko wrote: > On Fri, Aug 21, 2020 at 10:59:19AM +0200, Bartosz Golaszewski wrote: > > On Fri, Aug 21, 2020 at 10:35 AM Andy Shevchenko > > wrote: > > > On Thu, Aug 20, 2020 at 08:51:08PM +0200, Bartosz Golaszewski wrote: ... > > > > +static struct devres *to_devres(void *data) > > > > +{ > > > > + return data - ALIGN(sizeof(struct devres), ARCH_KMALLOC_MINALIGN); > > > > +} > > > > + > > > > +static size_t devres_data_size(size_t total_size) > > > > +{ > > > > + return total_size - ALIGN(sizeof(struct devres), ARCH_KMALLOC_MINALIGN); > > > > +} > > The data pointer in struct devres is defined as: > > > > u8 __aligned(ARCH_KMALLOC_MINALIGN) data[]; > > > > And this value (assigned the value of ARCH_DMA_MINALIGN) varies from > > one arch to another. I wasn't really sure if offsetof() would work for > > every case so I went with something very explicit. > > I have checked with a small program simulating to_devres() with your variant, > offsetof() and container_of(). > > The result is this: if MINALIGN < sizeof(long) and since struct is unpacked the > offsetof(), and thus container_of(), gives correct result, while ALIGN() > approach mistakenly moves pointer too back. ... > I think you need to change this to use container_of() and offsetof(). To be clear, there is probably no real problem, except unlikely possible MINALIGN=4 on 64-bit arch, but for sake of the correctness. -- With Best Regards, Andy Shevchenko _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel