Received: by 10.223.176.46 with SMTP id f43csp40355wra; Fri, 19 Jan 2018 13:27:19 -0800 (PST) X-Google-Smtp-Source: ACJfBot/9y/5hO2Co8y1D6cpIIEIfVNq0GN6DsvzAZZi+TiOSAHjjwK6MRyy/XNmP5dnNbjB6KQt X-Received: by 2002:a17:902:43:: with SMTP id 61-v6mr2223551pla.73.1516397239355; Fri, 19 Jan 2018 13:27:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516397239; cv=none; d=google.com; s=arc-20160816; b=H5wVgD7zsqxz/koA1oCnLVqJvpI+iQOXkcDjX9UDFYEaPY16Qyh5CIiE3gw1iT6GlO Vct9EoO1GasJbBYYYXDE7RZK3orMzSj322G+39Epa9GHTy3+Y39kx2SPa5ZU0tNucjKK qTz/f/6Zq0Xd661gxosD8kDOOnSHYK/0K6nRPcM+65ERRB8NigoOQZUzlIh09cFkcr71 jRtQktYrvNveKIKoQon4plnQVHeP5fg+jAwcoUUGJ7/qbuXEgjnj8CPypQKQrKPvNhgb m16dm3rvPhspkgdDtVodiXm8qTC2//s0eu7uG4VE5X0rSvmvfhNLGzxNygEHZHTDzwqb +fQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=Ufk0YxSEvCc40W25sVaCD85A9TtqQVLcLGznn3cuUbs=; b=N57Ruwmd7kns3dKKovtRZFLWgPUDDiWPVCvP2dDWkL2L2Ho0qnDxRvJR0hgXOWSUGv t8umJiJ4ztEsLnPrXt73k2AMc64kJhtMAG8vCCDhBDLDUuBPF6rv0TcJY7dyA1zQ57ro t9yrrbs0TsTUb4Vr+0ynnt4jFiUIVQ/j1YKeeAIE9sJHFAldeIas6SPAW/3OqhU0Ionn UuOgZO1sBUfMxJC/fQIA4/UoZWLeXnnmcAr/KiiKOjcpwil0Or6YTIsNib7e6rsmVmMx gfp53NGACVh2XN9i2k24ALePA6DlbWPoqBmbLXCGwhSqWvnFHM1na7iziztPDlR7ZM4a ju2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rZ7AswJu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t62si8988031pgt.130.2018.01.19.13.27.04; Fri, 19 Jan 2018 13:27:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rZ7AswJu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756492AbeASVZQ (ORCPT + 99 others); Fri, 19 Jan 2018 16:25:16 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:37285 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754118AbeASVZK (ORCPT ); Fri, 19 Jan 2018 16:25:10 -0500 Received: by mail-lf0-f67.google.com with SMTP id f3so3679685lfe.4 for ; Fri, 19 Jan 2018 13:25:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Ufk0YxSEvCc40W25sVaCD85A9TtqQVLcLGznn3cuUbs=; b=rZ7AswJuwgZJOHbaq9tJ3ER+nARjy5r1IZQzz/QKom23chiG7CDi89Oj4GGzLf7ICr 5dJvi5G6fZalwm0eqmv4QtUPKN/WRkGXEwIsEEgkJLwGtw0cUFDf35gU9WGwhPe4727y 7w2EZp1S48kjmA1XMfm4tRhg8wWEMnFcJHzH/jFM1NgsbEpsFJ0PwHmAkJT3xe6PMtIr jYxTKO244+iEhoOYXqpCEB61EbM3orN6UtcTqKYV0hVUf9dCVgk5+Q2RCl6jL/U1f5nv PbE+84hJ3P7e2ItnXcdZ1SPfpEg2ae4QVGvEoXWK2WJKqY9LKE+fH9MtlvjvMqDpK+pM qEpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Ufk0YxSEvCc40W25sVaCD85A9TtqQVLcLGznn3cuUbs=; b=VXgBnvSKu7kWEqM4S4gA6qd1lJSSNh8zMXXfsj2vPhvS5wrAVahLryt6tbjmZWAjat SRFPhP06hZPuHVD4T8nHLMiyZKUaboUnTmAIrZEsGjkm/QmBV971B6cd6wUb1ttmj9JL +XjAHp84wglSJTF5vj6+86i/CTCIXcgI/sB3lNuvru3v4wTSn7PSIrGp/Yv93inPRWhM +1GX2gpTREr3Xh8if4m1LvIY1E+k5boU+vjHZzt+nuDZCR8dG32ExOtyCBxnYPnGBYum dhOONj7u1YiBjsouL5rneem2TTlJuAFKK1qHAt0+y88cOXwP5whjAsL3qAfZtcr+xY6K 7GCw== X-Gm-Message-State: AKwxytfClNntjViEfqi4x8F5OE/t/unhLJfT3PkQX6CeyLz5xK2yJOci xeiagKR/s6e9W56En6W+WY8= X-Received: by 10.46.49.2 with SMTP id x2mr13694719ljx.102.1516397108722; Fri, 19 Jan 2018 13:25:08 -0800 (PST) Received: from mobilestation ([95.79.164.146]) by smtp.gmail.com with ESMTPSA id a64sm1803806lfa.0.2018.01.19.13.25.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jan 2018 13:25:07 -0800 (PST) Date: Sat, 20 Jan 2018 00:25:16 +0300 From: Serge Semin To: Arnd Bergmann Cc: jdmason@kudzu.us, Dave Jiang , allenbh@gmail.com, "Hook, Gary" , Sergey.Semin@t-platforms.ru, linux-ntb@googlegroups.com, Linux Kernel Mailing List Subject: Re: [PATCH] NTB: ntb_perf: fix cast to restricted __le32 Message-ID: <20180119212516.GA2386@mobilestation> References: <20180119173044.8013-1-fancer.lancer@gmail.com> <20180119210310.GA2284@mobilestation> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180119210310.GA2284@mobilestation> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jan 20, 2018 at 12:03:10AM +0300, Serge Semin wrote: > On Fri, Jan 19, 2018 at 09:42:17PM +0100, Arnd Bergmann wrote: > > On Fri, Jan 19, 2018 at 6:30 PM, Serge Semin wrote: > > > Sparse is whining about the u32 and __le32 mixed usage in the > > > driver. > > > > > > drivers/ntb/test/ntb_perf.c:288:21: warning: cast to restricted __le32 > > > drivers/ntb/test/ntb_perf.c:295:37: warning: incorrect type in argument 4 (different base types) > > > drivers/ntb/test/ntb_perf.c:295:37: expected unsigned int [unsigned] [usertype] val > > > drivers/ntb/test/ntb_perf.c:295:37: got restricted __le32 [usertype] > > > ... > > > > > > The NTB API can't be changed so ntb_spad_*() methods > > > would return either pure __le32 or __be32, since the scratchpad > > > data can have arbitrary endianness in general. In this case we > > > need to forcibly cast all the u32 to be __le32 and vise-versa > > > where it's supposed to be in accordance with the driver logic. > > > > > > > There's got to be a better way to do this than sprinkling lots of __force > > typecasts throughout the code. > > > > It looks like all those casts are about > > ntb_peer_spad_read()/ntb_peer_msg_write() calls, so why not change > > those function prototypes to work on __le32 types? > > > > There should also be some form of documentation regarding why you > > need to swap the data twice, since all the ntb drivers later end up > > doing another cpu_to_le32() on the little-endian data. > > > > Arnd > > Actually the provided patch is the best solution I could come up with. > The thing is, that the methods can't be changed. Those functions are > the part of the NTB API methods used by many drivers. So basically they > are like pci_{read,write}_config_{byte,word,dword}() methods. We can't > change their prototypes only because it's suit some driver. The methods > give an access to the NTB device dummy u32-sized registers, nothing > else. So endianness is the transmitted data settings in this case. > > NTB is the technology to interconnect some two systems with possibly > different endianness (unlike PCI, which interconnect CPU with LE devices). > In this case I'd need to set some agreement up between two systems about > the endianness of the exchanged data like host and network types in > Linux networking. I've chosen the network data to be little-endian, > that's why I needed first to convert them from CPU to le32, then on > remote side convert them back from le32 to CPU. > > If you have any better suggestion how the warning can be fixed, I'd > be glad to stick to it. > > -Sergey > I meant, everything depends on the NTB hardware driver hidden behind the API. If it does back and forth conversions writing/reading data to/from scratchpad registers (using IO methods like write32/read32), then I don't need to worry about data endianness at all and should have discarded le32_to_cpu()/cpu_to_l32() usage. But if it doesn't do it, then ntb_perf driver will be in trouble. So I sticked with the safest solution. Although the final decision is after the subsystem maintainer. -Sergey