linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: Misaligned Access
       [not found]             ` <661a4323-5768-4977-5434-ab644c5418aa@synopsys.com>
@ 2018-11-21 19:41               ` Vineet Gupta
  2018-11-21 20:11                 ` Arnd Bergmann
  0 siblings, 1 reply; 4+ messages in thread
From: Vineet Gupta @ 2018-11-21 19:41 UTC (permalink / raw)
  To: Vitor Soares, Alexey Brodkin, Joao Pinto, Jose Abreu
  Cc: arcml, lkml, Arnd Bergmann

+CC lkml, Arnd : subject matter expert

On 11/21/18 10:06 AM, Vitor Soares wrote:
> I use the follow function to get data from a RX Fifo.
>
>
> static void dw_i3c_master_read_rx_fifo(struct dw_i3c_master *master,
>                         u8 *bytes, int nbytes)
> {
>      readsl(master->regs + RX_TX_DATA_PORT, bytes, nbytes / 4);

So the semantics are reading the same fifo register N times, to get the N words,
hence read*s*l is appropriate. That however expects the buffer to be 4 bytes
aligned, hence your issue. You can't possibly use the reads*b* as we want the

The obvious but crude hack is to use a temp array for readsl and then copy over
using memcpy, but I'm sure there are better ways, @Arnd ? To summarize is issue is
a driver triggering unaligned access due to the misinteraction of API (driver get
an unaligned u8 *) which goes against expectations of io accessor readl  (needed
since the register contents are 4 bytes)


>      if (nbytes & 3) {
>          u32 tmp;
>
>          readsl(master->regs + RX_TX_DATA_PORT, &tmp, 1);
>          memcpy(bytes + (nbytes & ~3), &tmp, nbytes & 3);
>      }
> }
>
>
> and the pointer u8 *bytes is what is unaligned and breaks when inside of 
> realdsl() it does:
>
>      *buf++ = x;
>
>
> Note that the u8 *bytes pointer is the __u8 *buf of the i2c_msg struct.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Misaligned Access
  2018-11-21 19:41               ` Misaligned Access Vineet Gupta
@ 2018-11-21 20:11                 ` Arnd Bergmann
  2018-11-21 20:15                   ` Vineet Gupta
  0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2018-11-21 20:11 UTC (permalink / raw)
  To: Vineet Gupta
  Cc: Vitor Soares, alexey.brodkin, Joao Pinto, jose.abreu,
	open list:SYNOPSYS ARC ARCHITECTURE, Linux Kernel Mailing List

On Wed, Nov 21, 2018 at 8:42 PM Vineet Gupta <vineet.gupta1@synopsys.com> wrote:
>
> +CC lkml, Arnd : subject matter expert
>
> On 11/21/18 10:06 AM, Vitor Soares wrote:
> > I use the follow function to get data from a RX Fifo.
> >
> >
> > static void dw_i3c_master_read_rx_fifo(struct dw_i3c_master *master,
> >                         u8 *bytes, int nbytes)
> > {
> >      readsl(master->regs + RX_TX_DATA_PORT, bytes, nbytes / 4);
>
> So the semantics are reading the same fifo register N times, to get the N words,
> hence read*s*l is appropriate. That however expects the buffer to be 4 bytes
> aligned, hence your issue. You can't possibly use the reads*b* as we want the
>
> The obvious but crude hack is to use a temp array for readsl and then copy over
> using memcpy, but I'm sure there are better ways, @Arnd ? To summarize is issue is
> a driver triggering unaligned access due to the misinteraction of API (driver get
> an unaligned u8 *) which goes against expectations of io accessor readl  (needed
> since the register contents are 4 bytes)

Is this again on ARC or some other architecture that cannot do unaligned
access to normal RAM? On ARMv7 or x86, you should never see a problem
because the CPU handles misaligned writes. On ARMv4/v5, the readsl()
implementation internally aligns the access to the output buffer so it
will work correctly.

      Arnd

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Misaligned Access
  2018-11-21 20:11                 ` Arnd Bergmann
@ 2018-11-21 20:15                   ` Vineet Gupta
  2018-11-21 20:18                     ` Arnd Bergmann
  0 siblings, 1 reply; 4+ messages in thread
From: Vineet Gupta @ 2018-11-21 20:15 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Vitor Soares, alexey.brodkin, Joao Pinto, jose.abreu,
	open list:SYNOPSYS ARC ARCHITECTURE, Linux Kernel Mailing List

On 11/21/18 12:12 PM, Arnd Bergmann wrote:
> On Wed, Nov 21, 2018 at 8:42 PM Vineet Gupta <vineet.gupta1@synopsys.com> wrote:
>> +CC lkml, Arnd : subject matter expert
>>
>> On 11/21/18 10:06 AM, Vitor Soares wrote:
>>> I use the follow function to get data from a RX Fifo.
>>>
>>>
>>> static void dw_i3c_master_read_rx_fifo(struct dw_i3c_master *master,
>>>                         u8 *bytes, int nbytes)
>>> {
>>>      readsl(master->regs + RX_TX_DATA_PORT, bytes, nbytes / 4);
>> So the semantics are reading the same fifo register N times, to get the N words,
>> hence read*s*l is appropriate. That however expects the buffer to be 4 bytes
>> aligned, hence your issue. You can't possibly use the reads*b* as we want the
>>
>> The obvious but crude hack is to use a temp array for readsl and then copy over
>> using memcpy, but I'm sure there are better ways, @Arnd ? To summarize is issue is
>> a driver triggering unaligned access due to the misinteraction of API (driver get
>> an unaligned u8 *) which goes against expectations of io accessor readl  (needed
>> since the register contents are 4 bytes)
> Is this again on ARC or some other architecture that cannot do unaligned
> access to normal RAM? On ARMv7 or x86, you should never see a problem
> because the CPU handles misaligned writes. On ARMv4/v5, the readsl()
> implementation internally aligns the access to the output buffer so it
> will work correctly.

This is indeed on ARC: on ARC700 unaligned access to RAM was never supported and
on HS38x cores, it is configurable, so the API probably needs to support both cases.

Thx,
-Vineet

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Misaligned Access
  2018-11-21 20:15                   ` Vineet Gupta
@ 2018-11-21 20:18                     ` Arnd Bergmann
  0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2018-11-21 20:18 UTC (permalink / raw)
  To: Vineet Gupta
  Cc: Vitor Soares, alexey.brodkin, Joao Pinto, jose.abreu,
	open list:SYNOPSYS ARC ARCHITECTURE, Linux Kernel Mailing List

On Wed, Nov 21, 2018 at 9:15 PM Vineet Gupta <vineet.gupta1@synopsys.com> wrote:
>
> On 11/21/18 12:12 PM, Arnd Bergmann wrote:
> > On Wed, Nov 21, 2018 at 8:42 PM Vineet Gupta <vineet.gupta1@synopsys.com> wrote:
> >> +CC lkml, Arnd : subject matter expert
> >>
> >> On 11/21/18 10:06 AM, Vitor Soares wrote:
> >>> I use the follow function to get data from a RX Fifo.
> >>>
> >>>
> >>> static void dw_i3c_master_read_rx_fifo(struct dw_i3c_master *master,
> >>>                         u8 *bytes, int nbytes)
> >>> {
> >>>      readsl(master->regs + RX_TX_DATA_PORT, bytes, nbytes / 4);
> >> So the semantics are reading the same fifo register N times, to get the N words,
> >> hence read*s*l is appropriate. That however expects the buffer to be 4 bytes
> >> aligned, hence your issue. You can't possibly use the reads*b* as we want the
> >>
> >> The obvious but crude hack is to use a temp array for readsl and then copy over
> >> using memcpy, but I'm sure there are better ways, @Arnd ? To summarize is issue is
> >> a driver triggering unaligned access due to the misinteraction of API (driver get
> >> an unaligned u8 *) which goes against expectations of io accessor readl  (needed
> >> since the register contents are 4 bytes)
> > Is this again on ARC or some other architecture that cannot do unaligned
> > access to normal RAM? On ARMv7 or x86, you should never see a problem
> > because the CPU handles misaligned writes. On ARMv4/v5, the readsl()
> > implementation internally aligns the access to the output buffer so it
> > will work correctly.
>
> This is indeed on ARC: on ARC700 unaligned access to RAM was never supported and
> on HS38x cores, it is configurable, so the API probably needs to support both cases.

Ok, then I think you need to overwrite readsl() with a variant that
uses put_unaligned() instead the plain pointer dereference for the
output.

      Arnd

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-11-21 20:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <13D59CF9CEBAF94592A12E8AE55501350113CD10@DE02WEMBXB.internal.synopsys.com>
     [not found] ` <C2D7FE5348E1B147BCA15975FBA23075012B0B4CD5@US01WEMBX2.internal.synopsys.com>
     [not found]   ` <9ffd1270-ad92-88b7-eb53-85c65fe971dd@synopsys.com>
     [not found]     ` <f8c469e7-9e1d-18d6-4e56-ba4338462048@synopsys.com>
     [not found]       ` <ebe7f165-2901-2885-0583-c7be53329372@synopsys.com>
     [not found]         ` <4881796E12491D4BB15146FE0209CE6468198AC6@DE02WEMBXB.internal.synopsys.com>
     [not found]           ` <C2D7FE5348E1B147BCA15975FBA230750146415496@US01WEMBX2.internal.synopsys.com>
     [not found]             ` <661a4323-5768-4977-5434-ab644c5418aa@synopsys.com>
2018-11-21 19:41               ` Misaligned Access Vineet Gupta
2018-11-21 20:11                 ` Arnd Bergmann
2018-11-21 20:15                   ` Vineet Gupta
2018-11-21 20:18                     ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).