Re: question about boot_params global variables

2022-11-20 Thread jim . cromie
On Mon, Nov 14, 2022 at 11:41 AM Saad Masood  wrote:
>
> Hi Jim,
> In C, two global variables with the same name are converted to one global 
> variable (same memory address space).   So, the same variable is referenced 
> with or without the 'extern' keyword.
>
> Thanks,
>
>

thanks Saad,

its nice when a thread reaches a tight conclusion.


>
> Saad
>
> On Mon, Nov 14, 2022 at 11:23 AM  wrote:
>>
>> On Tue, Aug 16, 2022 at 4:10 AM shiyu chou  wrote:
>> >
>> > Hello all:
>> > In arch x86 directory I found two global variables with the same 
>> > name(master branch):
>> > 1.arch/x86/boot/main.c
>> > near line 18: struct boot_params boot_params __attribute__((aligned(16)));
>> > 2.arch/x86/kernel/setup.c
>> > near line 75: struct boot_params boot_params;
>> > Is that wrong to define two global variables with the same name? And when 
>> > use extern to reference the variable,which one did it reference?
>> >
>>
>> hi, did you figure out a satisfactory answer ?
>>
>> what happens when you build with W=1 ?
>>
>>
>> > ___
>> > Kernelnewbies mailing list
>> > Kernelnewbies@kernelnewbies.org
>> > https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>> ___
>> Kernelnewbies mailing list
>> Kernelnewbies@kernelnewbies.org
>> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: question about boot_params global variables

2022-11-14 Thread Saad Masood
Hi Jim,
In C, two global variables with the same name are converted to one
global variable (same memory address space).   So, the same variable is
referenced with or without the 'extern' keyword.

Thanks,



Saad

On Mon, Nov 14, 2022 at 11:23 AM  wrote:

> On Tue, Aug 16, 2022 at 4:10 AM shiyu chou  wrote:
> >
> > Hello all:
> > In arch x86 directory I found two global variables with the same
> name(master branch):
> > 1.arch/x86/boot/main.c
> > near line 18: struct boot_params boot_params
> __attribute__((aligned(16)));
> > 2.arch/x86/kernel/setup.c
> > near line 75: struct boot_params boot_params;
> > Is that wrong to define two global variables with the same name? And
> when use extern to reference the variable,which one did it reference?
> >
>
> hi, did you figure out a satisfactory answer ?
>
> what happens when you build with W=1 ?
>
>
> > ___
> > Kernelnewbies mailing list
> > Kernelnewbies@kernelnewbies.org
> > https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: question about boot_params global variables

2022-11-14 Thread jim . cromie
On Tue, Aug 16, 2022 at 4:10 AM shiyu chou  wrote:
>
> Hello all:
> In arch x86 directory I found two global variables with the same name(master 
> branch):
> 1.arch/x86/boot/main.c
> near line 18: struct boot_params boot_params __attribute__((aligned(16)));
> 2.arch/x86/kernel/setup.c
> near line 75: struct boot_params boot_params;
> Is that wrong to define two global variables with the same name? And when use 
> extern to reference the variable,which one did it reference?
>

hi, did you figure out a satisfactory answer ?

what happens when you build with W=1 ?


> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


question about boot_params global variables

2022-08-16 Thread shiyu chou
Hello all:
In arch x86 directory I found two global variables with the same
name(master branch):
1.arch/x86/boot/main.c
near line 18: struct boot_params boot_params __attribute__((aligned(16)));
2.arch/x86/kernel/setup.c
near line 75: struct boot_params boot_params;
Is that wrong to define two global variables with the same name? And when
use extern to reference the variable,which one did it reference?
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


RE: A question about memblock.reserved

2022-06-28 Thread Chan Kim
Hi Wonhyuk, 
Thank you for the reply (I found it this morning :))
Yes, I saw your blog and it helped. And I later found in a book that this 
memblock puts the kernel image, initrd, page tables, dtb,.. and the 
"reserved-memory" regions from the dtb in its memblock.reserved regions. 
Have a nice day!
Chan Kim

>>-Original Message-
>>From: Wonhyuk Yang 
>>Sent: Friday, June 24, 2022 3:41 PM
>>To: Chan Kim 
>>Cc: kernelnewbies 
>>Subject: Re: A question about memblock.reserved
>>
>>On Thu, Jun 23, 2022 at 2:25 PM Chan Kim  wrote:
>>>
>>> I mm/memblock.c I see this struct memblock memblock which is initialized
>>with empty list.
>>>
>>> static struct memblock_region
>>> memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS]
>>> __initdata_memblock; static struct memblock_region
>>> memblock_reserved_init_regions[INIT_MEMBLOCK_RESERVED_REGIONS]
>>> __initdata_memblock;
>>>
>>> struct memblock memblock __initdata_memblock = {
>>> .memory.regions = memblock_memory_init_regions,
>>> .memory.cnt = 1,/* empty dummy entry */
>>> .memory.max = INIT_MEMBLOCK_REGIONS,
>>> .memory.name= "memory",
>>> .reserved.regions   = memblock_reserved_init_regions,
>>> .reserved.cnt   = 1,/* empty dummy entry */
>>> .reserved.max   = INIT_MEMBLOCK_RESERVED_REGIONS,
>>> .reserved.name  = "reserved",
>>> .bottom_up  = false,
>>> .current_limit  = MEMBLOCK_ALLOC_ANYWHERE,
>>> };
>>>
>>> My question is : we can speicify "reserved-memory" in the device tree.
>>Some drivers use the reserved memory for its own use.
>>> Then, are the 'reserved-memory' regions are put into this
>>memblock.reserved  regions during the boot process?(I mean during dtb
>>parsing).
>>>
>>
>>Yes, reserved memblock is initialized while scanning the fdt.
>>I'll attach some call graph below and I hope it helps you.
>>
>>setup_arch ()
>>  arm64_memblock_init ()
>>early_init_fdt_scan_reserved_mem ()
>>  fdt_init_reserved_mem ()
>>fdt_scan_reserved_mem ()
>>  __reserved_mem_reserve_reg ()
>>early_init_dt_reserve_memory_arch ()
>>  memblock_reserve ()
>>
>>Plus, I written some *scribbled* notes about this in Korean.
>>I don't know if it will help, but I will attach it below.
>>
>>https://kjhg4321.gitbook.io/doodle/





___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: A question about memblock.reserved

2022-06-24 Thread Wonhyuk Yang
On Thu, Jun 23, 2022 at 2:25 PM Chan Kim  wrote:
>
> I mm/memblock.c I see this struct memblock memblock which is initialized with 
> empty list.
>
> static struct memblock_region 
> memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
> static struct memblock_region 
> memblock_reserved_init_regions[INIT_MEMBLOCK_RESERVED_REGIONS] 
> __initdata_memblock;
>
> struct memblock memblock __initdata_memblock = {
> .memory.regions = memblock_memory_init_regions,
> .memory.cnt = 1,/* empty dummy entry */
> .memory.max = INIT_MEMBLOCK_REGIONS,
> .memory.name= "memory",
> .reserved.regions   = memblock_reserved_init_regions,
> .reserved.cnt   = 1,/* empty dummy entry */
> .reserved.max   = INIT_MEMBLOCK_RESERVED_REGIONS,
> .reserved.name  = "reserved",
> .bottom_up  = false,
> .current_limit  = MEMBLOCK_ALLOC_ANYWHERE,
> };
>
> My question is : we can speicify "reserved-memory" in the device tree. Some 
> drivers use the reserved memory for its own use.
> Then, are the 'reserved-memory' regions are put into this memblock.reserved  
> regions during the boot process?(I mean during dtb parsing).
>

Yes, reserved memblock is initialized while scanning the fdt.
I'll attach some call graph below and I hope it helps you.

setup_arch ()
  arm64_memblock_init ()
early_init_fdt_scan_reserved_mem ()
  fdt_init_reserved_mem ()
fdt_scan_reserved_mem ()
  __reserved_mem_reserve_reg ()
early_init_dt_reserve_memory_arch ()
  memblock_reserve ()

Plus, I written some *scribbled* notes about this in Korean.
I don't know if it will help, but I will attach it below.

https://kjhg4321.gitbook.io/doodle/

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


A question about memblock.reserved

2022-06-22 Thread Chan Kim
Hello all,

I mm/memblock.c I see this struct memblock memblock which is initialized
with empty list.

static struct memblock_region
memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
static struct memblock_region
memblock_reserved_init_regions[INIT_MEMBLOCK_RESERVED_REGIONS]
__initdata_memblock;
#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
static struct memblock_region
memblock_physmem_init_regions[INIT_PHYSMEM_REGIONS];
#endif
 
struct memblock memblock __initdata_memblock = {
.memory.regions = memblock_memory_init_regions,
.memory.cnt = 1,/* empty dummy entry */
.memory.max = INIT_MEMBLOCK_REGIONS,
.memory.name= "memory",

.reserved.regions   = memblock_reserved_init_regions,
.reserved.cnt   = 1,/* empty dummy entry */
.reserved.max   = INIT_MEMBLOCK_RESERVED_REGIONS,
.reserved.name  = "reserved",

.bottom_up  = false,
.current_limit  = MEMBLOCK_ALLOC_ANYWHERE,
};

And I guess this struct will be filled during early boot and used during
boot. (I saw somewhere the memory regions are later moved to buddy
allocation system for normal use).
My question is : we can speicify "reserved-memory" in the device tree. Some
drivers use the reserved memory for its own use.
Then, are the 'reserved-memory' regions are put into this memblock.reserved
regions during the boot process?(I mean during dtb parsing).

Thank you!

Chan Kim
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: A question about linux pipes

2022-05-14 Thread Aruna Hewapathirane
> On Fri, May 13, 2022 at 11:46 AM xhighway999 
wrote:
>
> Hi Guys,
> sorry to bother you all. But I have a simple question about Linux Pipes.
> Is the following statement right or wrong:
> "Named pipes can be used to transfer data from one process to multiple
other processes that know the name at the same time (similar to the
behavior of a tee-pipe)."
> For reference, the original German Quote:
> "Named Pipes lassen sich dazu verwenden, um Daten von einem Prozess
gleichzeitig an mehrere andere Prozesse, die den Namen kennen, zu
übertragen (ähnlich dem Verhalten einer tee-Pipe)."
> Thanks in advance !
>
> Sincerely,
> A fellow Linux user.

This will help you to figure out the answer to your question yourself:
https://youtu.be/6lik_f1Vp54

Aruna
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


A question about iommu, passing to the device user data containing pointers

2022-05-01 Thread Chan Kim
Hello linux experts,

I'm almost sure my understanding is correct but hope someone could confirm
me if it's really correct.
Suppose a user program wants to pass to a device some data structures
connected to each other using pointers and the device processes the data
with dma capability(meaning it accesses the memory on its own). Here is a
simple example. I want to add each member of array a and b and put it in
array c and I pass the address of the struct which contains the addresses of
inputs and output arrays. (This is a code for this question and can have
some bugs but it's enough for my question. )  

struct _myargs {
int *a;  // input pointer
int *b;  // input pointer
int *c;  // output pointer
} myargs;

int main()
{
int *a, *b, *c; 
a = malloc(100*sizeof(int));
b = malloc(100*sizeof(int));
c = malloc(100*sizeof(int)); 

... fill inputs ...

myargs.a = a;
myargs.b = b;
myargs.c = c;
...
ioctl(fd, AddIt, );
...
}

 Then, in the driver, I allocate the input and output buffers in kernel
space and I do copy_from_user to copy the input data to kernel space input
buffers. (and later do copy_to_user for the buffer c).   

my_ioctl(struct file *file, unsigned int cmd, unsigned long args_usr)
{
struct _myargs *args_ker;
dma_addr_t args_dev;
int *a_ker, *b_ker, *c_ker;
dma_addr a_dev, b_dev, c_dev;

args = dma_alloc_coherent(dev, sizeof(struct _myargs), _dev,
GFP_KERNEL);

switch(cmd) {
case(AddIt):
copy_from_user(args_ker, args_usr, sizeof(struct _myargs));
ak = dma_alloc_coherent(dev, 100*sizeof(int), _dev, GFP_KERNEL);
bk = dma_alloc_coherent(dev, 100*sizeof(int), _dev, GFP_KERNEL);
ck = dma_alloc_coherent(dev, 100*sizeof(int), _dev, GFP_KERNEL);
copy_from_user(a_ker, args_ker.a, 100*sizeof(int));
copy_from_user(b_ker, args_ker.b, 100*sizeof(int));

args_ker.a = a_dev;
args_ker.b = b_dev;
args_ker.c = c_dev;

writel(dev, _dev, REG_ARGS); // set args
writel(dev, 1, REG_TRIGGER);   // trigger hardware

...
}
}

So the a, b arrays have been copied to kernel space address a_ker and b_ker
but when I pass the args struct to the device, I used virtual io address
(dma_addr_t) a_dev, b_dev and c_dev.  And I want the device hardware to read
the args struct from memory and use the address there to do array addition.
I understand the iommu for the device (if correctly set and initialized)
will do the (io virtual address) -> (device bus address) translation because
the iommu subsystem would have setup the page table for the MMU(for kernel
virtual address) and IOMMU(for io virtual address) for the buffers so that
they can point to the same physical(or bus) address. I'm almost sure this
will work but can't do a test now. Is my understanding correct? can someone
well versed in the linux driver confirm me this approach is correct?




___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


A question about regmap bus

2021-12-07 Thread Clyde Huang31
Hi All,

We have an FPGA device and it is connect to a SOC through the SPI interface.
The communication is using a specific protocol like as bellow.

Read a register:
   <   Bits >
   ++
   |  7   |  6  |  5  |  4  |  3  |  2  |   1   |   0   |
^  |++|+|+|+|+|+|+++|
   | 0  |  0   |   Header (6:0)   | 
   ++
   | 1  |   Header (7:2)  |  Address (1:0)   |
B  ++
y  | 2  |  Address (7:0)   |
t  ++
e  | 3  |Data Count (7:0)  |
s  ++
   | 4  |  Turn-Around-Time (7:0)  |
   ++
   | 5...X   |  X bytes data from the SPI slave |
   ++
   | N-1| Status from the SPI slave   |
   ++
   | N |  CRC from the SPI slave|
v  ++
  
Write a register:
   <   Bits >
   ++
   |  7   |  6  |  5  |  4  |  3  |  2  |   1   |   0   |
^  |++|+|+|+|+|+|+++|
   | 0  |  0   |   Header (6:0)   |
   ++
   | 1  |   Header (7:2) |   Address (1:0)   |
B  ++
y  | 2  |  Address (7:0)   |
t  ++
e  | 3  |Data Count (7:0)  |
s  ++
   |  4...X  |   X bytes data to the SPI slave  |
   ++
   | N-3|  CRC to the SPI slave  | 
   ++
   | N-2|Turn-Around-Time |
   ++
   | N-1| Status from the SPI slave   |
   ++
   | N |  CRC from the SPI slave|
v  ++

The protocol seems like needs a new rebmap bus to support it. Is that right?

I see a similer design in drivers/base/regmap/regmap-spi-avmm.c and know it is 
for Intel Avalon bus. 
A new question is, if the protocol is only for a specific SPI device. 
Should I generate a new regmap bus driver into drivers/base/regmap folder? 
or this regmap bus should implement together with the SPI device driver in the 
same file? 
I found an example is devm_regmap_init() function called in 
drivers/mfd/atmel-hlcdc.c file.

T


___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Question about "barrier()" in the SLUB's fast path

2021-11-11 Thread Wonhyuk Yang
Hi,

Recently, I had difficulty understanding the meaning of the barrier()
in the slab_alloc_node().

The comments are written like this.

/*
* Irqless object alloc/free algorithm used here depends on sequence
* of fetching cpu_slab's data. tid should be fetched before anything
* on c to guarantee that object and page associated with previous tid
* won't be used with current tid. If we fetch tid first, object and
* page could be one associated with next tid and our alloc/free
* request will be failed. In this case, we will retry. So, no problem.
*/
barrier();

Even if we don't fetch tid first, don't we try again by this_cpu_cmpxchg_double?
I'd really appreciate it if you let me know what I missed!

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: A question about staging driver like pi433

2021-08-12 Thread Sidong Yang
On Tue, Aug 10, 2021 at 08:12:46AM +0200, Greg KH wrote:
> On Mon, Aug 09, 2021 at 11:27:13PM +, Sidong Yang wrote:
> > On Mon, Aug 09, 2021 at 08:20:03PM +0200, Greg KH wrote:
> > > On Mon, Aug 09, 2021 at 04:13:28PM +, Sidong Yang wrote:
> > > > Hi all,
> > > > 
> > > > I have a question about staging driver. I'm a newbie kernel developer
> > > > and I tried contributed some patches for staging drivers. In those
> > > > staging drivers, I'm interested in pi433 and wrote some patches for it
> > > > about 2 years ago. and then I tried to go deeper for that. I tried to
> > > > buy pi433 device but I can't. It seems that no longer available. 
> > > > 
> > > > In this case, pi433 should be removed from source tree?
> > > 
> > > Why would it be removed if people still use it?
> > 
> > Yeah, I thought there is no user using this device. I realized that it
> > was bad idea. 
> 
> Is there no one using this?  That's kind of hard to determine, and is
> a problem we have at times :(

I contacted the hardware developer in personal. And He replied positive.
I would get the pi433 device soon. It would be nice that It can be
tested in practice.

Thanks,
Sidong

> 
> thanks,
> 
> greg k-h

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: A question about staging driver like pi433

2021-08-10 Thread Greg KH
On Mon, Aug 09, 2021 at 11:27:13PM +, Sidong Yang wrote:
> On Mon, Aug 09, 2021 at 08:20:03PM +0200, Greg KH wrote:
> > On Mon, Aug 09, 2021 at 04:13:28PM +, Sidong Yang wrote:
> > > Hi all,
> > > 
> > > I have a question about staging driver. I'm a newbie kernel developer
> > > and I tried contributed some patches for staging drivers. In those
> > > staging drivers, I'm interested in pi433 and wrote some patches for it
> > > about 2 years ago. and then I tried to go deeper for that. I tried to
> > > buy pi433 device but I can't. It seems that no longer available. 
> > > 
> > > In this case, pi433 should be removed from source tree?
> > 
> > Why would it be removed if people still use it?
> 
> Yeah, I thought there is no user using this device. I realized that it
> was bad idea. 

Is there no one using this?  That's kind of hard to determine, and is
a problem we have at times :(

thanks,

greg k-h

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: A question about staging driver like pi433

2021-08-09 Thread Sidong Yang
On Mon, Aug 09, 2021 at 08:20:03PM +0200, Greg KH wrote:
> On Mon, Aug 09, 2021 at 04:13:28PM +, Sidong Yang wrote:
> > Hi all,
> > 
> > I have a question about staging driver. I'm a newbie kernel developer
> > and I tried contributed some patches for staging drivers. In those
> > staging drivers, I'm interested in pi433 and wrote some patches for it
> > about 2 years ago. and then I tried to go deeper for that. I tried to
> > buy pi433 device but I can't. It seems that no longer available. 
> > 
> > In this case, pi433 should be removed from source tree?
> 
> Why would it be removed if people still use it?

Yeah, I thought there is no user using this device. I realized that it
was bad idea. 
> 
> > If not, It's okay to send patches for it?

Sure, 

Thanks!
Sidong
> 
> Please do!
> 
> thanks,
> 
> greg k-h

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: A question about staging driver like pi433

2021-08-09 Thread Greg KH
On Mon, Aug 09, 2021 at 04:13:28PM +, Sidong Yang wrote:
> Hi all,
> 
> I have a question about staging driver. I'm a newbie kernel developer
> and I tried contributed some patches for staging drivers. In those
> staging drivers, I'm interested in pi433 and wrote some patches for it
> about 2 years ago. and then I tried to go deeper for that. I tried to
> buy pi433 device but I can't. It seems that no longer available. 
> 
> In this case, pi433 should be removed from source tree?

Why would it be removed if people still use it?

> If not, It's okay to send patches for it?

Please do!

thanks,

greg k-h

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


A question about staging driver like pi433

2021-08-09 Thread Sidong Yang
Hi all,

I have a question about staging driver. I'm a newbie kernel developer
and I tried contributed some patches for staging drivers. In those
staging drivers, I'm interested in pi433 and wrote some patches for it
about 2 years ago. and then I tried to go deeper for that. I tried to
buy pi433 device but I can't. It seems that no longer available. 

In this case, pi433 should be removed from source tree?
If not, It's okay to send patches for it?

Thanks,
Sidong

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


RE: a question about dma_set_mask function

2021-07-22 Thread ckim
 

Further reading down the document, I realized the returned DMA address (=bus
address) is used for setting the dma descriptors or the device register so
that the address value is used for actual DMA.

But I'm still confused for cases of using iommu. 

When the iommu exists for the device, does the dma_alloc function allocates
virtual address range (which can be physically dis-contiguous) instead of
the (physically contiguous) bus address? 

I mean, will the handle value below be pointing to virtual address for {this
process and the device} pair? (virtual to bus address translation being done
by iommu).

dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *handle,
gfp_t gfp)

Any help will be really appreciated.

Thanks!

Chan Kim

 

From: c...@etri.re.kr  
Sent: Thursday, July 22, 2021 4:33 PM
To: kernelnewbies@kernelnewbies.org
Subject: a question about dma_set_mask function

 

Hello,

 

I have a question about DNA (I was reading DMA-API-HOWTO.txt
<https://www.kernel.org/doc/Documentation/DMA-API-HOWTO.txt>  ).

You know regarding DMA, there is cpu virtual address, cpu physical address
and bus address for the device. 

Bus address is converted to cpu physical address using bridge or bus
controller to which the device is attached. 

And for platform device, bus address is equal to the cpu physical address.

 

The DMA-API-HOWTO.txt
<https://www.kernel.org/doc/Documentation/DMA-API-HOWTO.txt>  says 

 

> When dma_set_mask() or dma_set_mask_and_coherent() is successful, and

> returns zero, the kernel saves away this mask you have provided.  The

> kernel will use this information later when you make DMA mappings.

 

So I guess when the driver later requests memory for dma using
dma_map_..(ex. dma_map_single, or dma_map_sg) function, 

the kernel allocates memory and sets up page table and it sets the bus
address in the ranges supported by the dma_mask. 

The virtual address is returned by the function, but where is this 'bus
address' kept? I see a pointer to the struct page in the function argument,
Is it kept in this struct array? Or is the bus address just the physical
address(pfn) in the page table?(I guess so)

And when the device has a separate iommu(like arm64's SMMU), I guess the DMA
virtual address (assigned for dma by the kernel) for the device is first
converted to the bus address by iommu and then the bus address is converted
to physical address by bus bridge. Is my understanding correct?

It's so confusing.. Any explanation or comment will be deeply appreciated.

Thanks!

 

Chan Kim

 

 

 

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


a question about dma_set_mask function

2021-07-22 Thread ckim
Hello,

 

I have a question about DNA (I was reading DMA-API-HOWTO.txt
<https://www.kernel.org/doc/Documentation/DMA-API-HOWTO.txt>  ).

You know regarding DMA, there is cpu virtual address, cpu physical address
and bus address for the device. 

Bus address is converted to cpu physical address using bridge or bus
controller to which the device is attached. 

And for platform device, bus address is equal to the cpu physical address.

 

The DMA-API-HOWTO.txt
<https://www.kernel.org/doc/Documentation/DMA-API-HOWTO.txt>  says 

 

> When dma_set_mask() or dma_set_mask_and_coherent() is successful, and

> returns zero, the kernel saves away this mask you have provided.  The

> kernel will use this information later when you make DMA mappings.

 

So I guess when the driver later requests memory for dma using
dma_map_..(ex. dma_map_single, or dma_map_sg) function, 

the kernel allocates memory and sets up page table and it sets the bus
address in the ranges supported by the dma_mask. 

The virtual address is returned by the function, but where is this 'bus
address' kept? I see a pointer to the struct page in the function argument,
Is it kept in this struct array? Or is the bus address just the physical
address(pfn) in the page table?(I guess so)

And when the device has a separate iommu(like arm64's SMMU), I guess the DMA
virtual address (assigned for dma by the kernel) for the device is first
converted to the bus address by iommu and then the bus address is converted
to physical address by bus bridge. Is my understanding correct?

It's so confusing.. Any explanation or comment will be deeply appreciated.

Thanks!

 

Chan Kim

 

 

 

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Question about the linux switch_to macro parameters

2021-04-22 Thread 武广阔
I read the source code in kernel(kernel/sched.c):


(include/asm-i386/system.h)
My question is that: switch_to is defined as a macro, so I thoutht it will 
expand "=a" (last) as "=a" (prev), if that the last parameter is just for easy 
to read, is that right?___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


RE: question about ioport_map function

2021-03-21 Thread ckim
Oh my question contains discrepancy.

My real question is whether the output of ioport_map is physical or virtual.
(I'm confused)

I know for systems with memory mapped I/O, we can just use
request_mem_region, ioremap (maps to virtual address), plain memory access
for the peripheral. (the page table sets the area as uncacheable because
it's IO devices)

Thanks!

Chan Kim

 

From: c...@etri.re.kr  
Sent: Monday, March 22, 2021 10:28 AM
To: kernelnewbies@kernelnewbies.org
Subject: question about ioport_map function

 

Hello all

>From what I understand, to map io ports to virtual memory, we should use
request_region, ioport_map/unmap and ioread/write functions.

These are for architectures having input, output machine instructions like
x86, x86_64. 

And the return address of ioport_map is physical address.

Is my understanding correct?

Thanks!

Chan Kim

 

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


question about ioport_map function

2021-03-21 Thread ckim
Hello all

>From what I understand, to map io ports to virtual memory, we should use
request_region, ioport_map/unmap and ioread/write functions.

These are for architectures having input, output machine instructions like
x86, x86_64. 

And the return address of ioport_map is physical address.

Is my understanding correct?

Thanks!

Chan Kim

 

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: question about arm64 __primary_switched code

2020-11-29 Thread Wonhyuk Yang
On Mon, Nov 30, 2020 at 10:08 AM  wrote:

> __primary_switched:
> adrpx4, init_thread_union   -- line 1
> add sp, x4, #THREAD_SIZE-- line 2
> adr_l   x5, init_task   -- line 3
> msr sp_el0, x5  // Save thread_info   -- line 4
> adr_l   x8, vectors // load VBAR_EL1 with virtual  -- line5
> msr vbar_el1, x8// vector table address  -- line 6
> isb-- line7
>
> stp xzr, x30, [sp, #-16]!-- line8
> mov x29, sp   -- line9
>
> str_l   x21, __fdt_pointer, x5  // Save FDT pointer   -- line10
>
> line 2 : sp = (x4 + #THREAD_SIZE). looks like setting the stack pointer for 
> the init thread info?

Yes. Setting the stack and it will be used for C code.

> line 4 : sp_el0 = x5.  why set the stack pointer of exeption level0 with the 
> thread_info?

In early time sp_el0 is not used, so it used just for saving some values.

> and is this sp_el0 different from the sp in line 2? (I guess we are now in el 
> 1, so sp means sp_el1 in line 2)

Yes it is different.

> line 5 : x8 = (address of trap vectors) I couldn't find where 'vectors' is 
> defied in the kernel source.

You can find it in the entry.S.

> line 7 : instruction synch barrier. why is it needed here?

I find it was introduced Commit : 2bf31a4a05f5b. Sadly, I can't understand too.

> line 8 : store 0 to [sp - 16], and store x30 at [sp - 8]. I know x30 is used 
> to keep the address to return after function(called function sets PC with 
> x30). But here zero and x30 is saved in the stack. What is it doing here?
> line 9 : and frame pointer (x29) is set with sp. The stack address obtained 
> in line 2 is set to x29. I think the this is the stack start for this frame 
> and sp grows down as stack is used.

It seems like making stack frame. stp with "!" means the preindex.
stp xzr, x30, [sp, #-16]! is same as,

sp = sp - 0x16
*sp = xzr  <- frame
*(sp+0x8) = x30   <- return

> line 10 : I know x21 was keeping the device tree address here, so here the 
> address is stored in a global address __fdt_pointer for later use.  I guess 
> str_l is store-relative-long but I can't figure out how x5(addr of init_task) 
> is used here..

x5 is used as a temporary register.

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


RE: question about arm64 __primary_switched code

2020-11-29 Thread ckim
Hi all,
My question on stackoverflow contained many questions so it was closed (I was 
going to split the questions).
Here I put the original question. I would be really grateful if someone gives 
me some clarification. Thanks!

There are too much to read but too small amount of time always.. so forgive me 
my asking without enough study.   
This is an assembly code from linux arm64 (arch/arm64/kernel/head.S).(kernel 
source 5.4.21)   

__primary_switched:
adrpx4, init_thread_union   -- line 1
add sp, x4, #THREAD_SIZE-- line 2
adr_l   x5, init_task   -- line 3
msr sp_el0, x5  // Save thread_info   -- line 4
adr_l   x8, vectors // load VBAR_EL1 with virtual  -- line5
msr vbar_el1, x8// vector table address  -- line 6
isb-- line7

stp xzr, x30, [sp, #-16]!-- line8
mov x29, sp   -- line9

str_l   x21, __fdt_pointer, x5  // Save FDT pointer   -- line10

I'll try to understand it here..(I have a book that may have some explanation 
for this part, but left it at work.. and I'm home now..)  
line 1 : x4 = (page address of init_thread_union). I found init_thread_union is 
a variable in the kernel linkerscrip.(arch/arm64/kernel/vmlinux.lds.S).   
line 2 : sp = (x4 + #THREAD_SIZE). looks like setting the stack pointer for the 
init thread info?   
line 3 : x5 = (address of init_task), I found init_task is a task_struct for 
init task.(in init/init_task.c). so this is the thread info.   
line 4 : sp_el0 = x5.  why set the stack pointer of exeption level0 with the 
thread_info? and is this sp_el0 different from the sp in line 2? (I guess we 
are now in el 1, so sp means sp_el1 in line 2)
line 5 : x8 = (address of trap vectors) I couldn't find where 'vectors' is 
defied in the kernel source.
line 6 : set the x8 value to vbar_el1 system register.  
line 7 : instruction synch barrier. why is it needed here?  
line 8 : store 0 to [sp - 16], and store x30 at [sp - 8]. I know x30 is used to 
keep the address to return after function(called function sets PC with x30). 
But here zero and x30 is saved in the stack. What is it doing here? 
line 9 : and frame pointer (x29) is set with sp. The stack address obtained in 
line 2 is set to x29. I think the this is the stack start for this frame and sp 
grows down as stack is used.  
line 10 : I know x21 was keeping the device tree address here, so here the 
address is stored in a global address __fdt_pointer for later use.  I guess 
str_l is store-relative-long but I can't figure out how x5(addr of init_task) 
is used here..  
ah.. there are so many questions. Please someone give me the explanation or 
correct my understanding if I'm wrong.  
---

> -Original Message-
> From: Wonhyuk Yang 
> Sent: Monday, November 30, 2020 9:13 AM
> To: c...@etri.re.kr
> Cc: kernelnewbies 
> Subject: Re: question about arm64 __primary_switched code
> 
> On Sun, Nov 29, 2020 at 7:52 PM  wrote:
> >
> > I’ll grateful if someone gives me some comments or answers. (it’s
> > about understanding arm64 assembly code)
> >
> > https://stackoverflow.com/questions/65051120/understanding-arm64-assem
> > bly-adr-l-ldr-l-str-l-in-a-linux-kernel-code?noredirect=1#comment11501
> > 2976_65051120
> >
> 
> Hi,
> Your link doesn't work. Also, I think attaching the contents of the link
> to the mail will make it easier for others to see.





___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: question about arm64 __primary_switched code

2020-11-29 Thread Wonhyuk Yang
On Sun, Nov 29, 2020 at 7:52 PM  wrote:
>
> I’ll grateful if someone gives me some comments or answers. (it’s about 
> understanding arm64 assembly code)
>
> https://stackoverflow.com/questions/65051120/understanding-arm64-assembly-adr-l-ldr-l-str-l-in-a-linux-kernel-code?noredirect=1#comment115012976_65051120
>

Hi,
Your link doesn't work. Also, I think attaching the contents of the
link to the mail
will make it easier for others to see.

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


question about arm64 __primary_switched code

2020-11-29 Thread ckim
Hello,

I have put a question on stackoverflow but nobody answers there yet.

I'll grateful if someone gives me some comments or answers. (it's about
understanding arm64 assembly code)

https://stackoverflow.com/questions/65051120/understanding-arm64-assembly-ad
r-l-ldr-l-str-l-in-a-linux-kernel-code?noredirect=1#comment115012976_6505112
0

Thank you.

Chan

 

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: arm64: Question about barriers with the mmu off

2020-11-17 Thread Wonhyuk Yang
On Tue, Nov 17, 2020 at 3:25 PM Valdis Klētnieks
 wrote:
>
> > > > > dc ivac,x1   // invalidate a cache line that's probably OK
> > > > > str w0,[x1   // and now we do a store that leaves a possibly stale 
> > > > > cache line
>
> > Could you explain me why the store still leaves stale cache?
> > We invalidated the cacheline and store will not make footprint in the cache.
>
> There's a race condition...
>
> Invalidate the cache line  then another CPU manages to fetch the cache 
> line.
> and then we do a store that doesn't update the cache - and the other CPU
> is still looking at the old data.

Oh, I didn't consider that another cpu read with cacheable.
Now I understand why the barrier is here.

Thank you for your help.

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: arm64: Question about barriers with the mmu off

2020-11-16 Thread Valdis Klētnieks
On Tue, 17 Nov 2020 14:08:02 +0900, Wonhyuk Yang said:

> > > > dc ivac,x1   // invalidate a cache line that's probably OK
> > > > str w0,[x1   // and now we do a store that leaves a possibly stale 
> > > > cache line

> Could you explain me why the store still leaves stale cache?
> We invalidated the cacheline and store will not make footprint in the cache.

There's a race condition...

Invalidate the cache line  then another CPU manages to fetch the cache line.
and then we do a store that doesn't update the cache - and the other CPU
is still looking at the old data.



pgptbUaFIadmd.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: arm64: Question about barriers with the mmu off

2020-11-16 Thread Wonhyuk Yang
On Tue, Nov 17, 2020 at 12:45 PM Valdis Klētnieks
 wrote:
>
> > > If you swap them, you get...
> > >
> > > dc ivac,x1   // invalidate a cache line that's probably OK
> > > str w0,[x1   // and now we do a store that leaves a possibly stale cache 
> > > line
> > >
> > > In other words, if you swap them you may leave an un-invalidated
> > > stale cache line.
> >
> > You mean, even if STCLR_EL1.{C, M} is cleared, store doesn't bypass the
> > cache?
>
> That's the problem.  The store bypasses the cache line, and the next reference
> that uses the cache can get stale data. So you have to flush the cache line
> so the next reference has to refresh the cache on the memory read.

Yes, I understood that I have to flush the cache before the cacheable
read(mmu on).
But I'm not fully understand your explanation below.

> > > dc ivac,x1   // invalidate a cache line that's probably OK
> > > str w0,[x1   // and now we do a store that leaves a possibly stale cache 
> > > line

Could you explain me why the store still leaves stale cache?
We invalidated the cacheline and store will not make footprint in the cache.

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: arm64: Question about barriers with the mmu off

2020-11-16 Thread Valdis Klētnieks
On Tue, 17 Nov 2020 12:00:32 +0900, Wonhyuk Yang said:
> > If you swap them, you get...
> >
> > dc ivac,x1   // invalidate a cache line that's probably OK
> > str w0,[x1   // and now we do a store that leaves a possibly stale cache 
> > line
> >
> > In other words, if you swap them you may leave an un-invalidated
> > stale cache line.
>
> You mean, even if STCLR_EL1.{C, M} is cleared, store doesn't bypass the
> cache?

That's the problem.  The store bypasses the cache line, and the next reference
that uses the cache can get stale data. So you have to flush the cache line
so the next reference has to refresh the cache on the memory read.


pgpCkMigPy4aO.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


arm64: Question about barriers with the mmu off

2020-11-16 Thread Wonhyuk Yang
On Tue, Nov 17, 2020 at 11:14 AM Valdis Klētnieks 
wrote:

> If you swap them, you get...
>
> dc ivac,x1   // invalidate a cache line that's probably OK
> str w0,[x1   // and now we do a store that leaves a possibly stale cache
line
>
> In other words, if you swap them you may leave an un-invalidated
> stale cache line.

You mean, even if STCLR_EL1.{C, M} is cleared, store doesn't bypass the
cache?
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: arm64: Question about barriers with the mmu off

2020-11-16 Thread Valdis Klētnieks
On Mon, 16 Nov 2020 20:58:52 +0900, Wonhyuk Yang said:

> str w0, [x1]
So we dirtied the cache line.
> dmb sys
> dc ivac, x1   // Invalidate potentially stale cache line

So we invalidate it.

> Is there any problem, if the dc operation precedes the store operation?

If you swap them, you get...

dc ivac,x1   // invalidate a cache line that's probably OK
str w0,[x1   // and now we do a store that leaves a possibly stale cache line

In other words, if you swap them you may leave an un-invalidated
stale cache line.



pgpnXU6HTtuY3.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


arm64: Question about barriers with the mmu off

2020-11-16 Thread Wonhyuk Yang
Hi, I have a question about dmb barriers in arm64's head.S.
In the head.S, I could see the pattern below several times.

str w0, [x1]
dmb sys
dc ivac, x1   // Invalidate potentially stale cache line

I found that,
Commit(fix cache flushing and barriers in set_cpu_boot_mode_flag)
explained the code.

> This patch reworks the broken flushing code so that we:
>
> (1) Use a DMB to order the strongly-ordered write of the cacheline
> against the subsequent cache-maintenance operation (by-VA
> operations only hazard against normal, cacheable accesses).
>
> (2) Use a single dc ivac instruction to invalidate any clean lines
> containing a stale copy of the line after it has been updated.
> Use a DMB to order the strongly-> ordered write of the cacheline

But I can't  understand why the store operation should precede the
dc operation.

Is there any problem, if the dc operation precedes the store operation?

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: USB Question about devices being reconnected to the host

2020-10-15 Thread Lucas Tanure




On 10/15/20 1:30 PM, Greg KH wrote:

On Thu, Oct 15, 2020 at 01:17:45PM +0100, Lucas Tanure wrote:

Hi,

I'm learning about USB drivers and I would like to know about disconnecting
and reconnecting usb devices.

I can see my probe function being called and also the disconnect function.
But if I reconnect the device there is no call from the kernel to notify my
driver about the device being reconnected.


That's not good, your driver should be told this.


I can also see that the module for my driver was not unloaded, so I dont
understand the life cycle of a USB device.


Modules are never auto-unloaded.


If the module is not unloaded at disconnection and re-loaded for a new
device being connected, how can the driver know the device is there after a
disconnection?


The probe function should be called, are you sure it isn't?

I re-did the test couple more times and I can see now the probe
function being called.

Thanks





Thanks
Lucas

This is my dmesg for the driver at the end of this email:

[   34.706041] usb 1-1.1.2: new high-speed USB device number 5 using dwc_otg
[   34.837647] usb 1-1.1.2: New USB device found, idVendor=04b4,
idProduct=00f1, bcdDevice= 0.00
[   34.837666] usb 1-1.1.2: New USB device strings: Mfr=1, Product=2,
SerialNumber=0
[   34.837679] usb 1-1.1.2: Product: FX3
[   34.837693] usb 1-1.1.2: Manufacturer: Cypress
[   34.902480] usbdev_probe
[   34.902681] usbcore: registered new interface driver My USB Device
[   45.416310] usb 1-1.1.2: USB disconnect, device number 5
[   45.416655] usbdev_disconnect
[   61.326035] usb 1-1.1.2: new high-speed USB device number 6 using dwc_otg
[   61.457674] usb 1-1.1.2: New USB device found, idVendor=04b4,
idProduct=00f1, bcdDevice= 0.00
[   61.457692] usb 1-1.1.2: New USB device strings: Mfr=1, Product=2,
SerialNumber=0
[   61.457706] usb 1-1.1.2: Product: FX3
[   61.457720] usb 1-1.1.2: Manufacturer: Cypress


That is odd, sorry, don't know what to suggest.

greg k-h



___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: USB Question about devices being reconnected to the host

2020-10-15 Thread Greg KH
On Thu, Oct 15, 2020 at 01:17:45PM +0100, Lucas Tanure wrote:
> Hi,
> 
> I'm learning about USB drivers and I would like to know about disconnecting
> and reconnecting usb devices.
> 
> I can see my probe function being called and also the disconnect function.
> But if I reconnect the device there is no call from the kernel to notify my
> driver about the device being reconnected.

That's not good, your driver should be told this.

> I can also see that the module for my driver was not unloaded, so I dont
> understand the life cycle of a USB device.

Modules are never auto-unloaded.

> If the module is not unloaded at disconnection and re-loaded for a new
> device being connected, how can the driver know the device is there after a
> disconnection?

The probe function should be called, are you sure it isn't?


> 
> Thanks
> Lucas
> 
> This is my dmesg for the driver at the end of this email:
> 
> [   34.706041] usb 1-1.1.2: new high-speed USB device number 5 using dwc_otg
> [   34.837647] usb 1-1.1.2: New USB device found, idVendor=04b4,
> idProduct=00f1, bcdDevice= 0.00
> [   34.837666] usb 1-1.1.2: New USB device strings: Mfr=1, Product=2,
> SerialNumber=0
> [   34.837679] usb 1-1.1.2: Product: FX3
> [   34.837693] usb 1-1.1.2: Manufacturer: Cypress
> [   34.902480] usbdev_probe
> [   34.902681] usbcore: registered new interface driver My USB Device
> [   45.416310] usb 1-1.1.2: USB disconnect, device number 5
> [   45.416655] usbdev_disconnect
> [   61.326035] usb 1-1.1.2: new high-speed USB device number 6 using dwc_otg
> [   61.457674] usb 1-1.1.2: New USB device found, idVendor=04b4,
> idProduct=00f1, bcdDevice= 0.00
> [   61.457692] usb 1-1.1.2: New USB device strings: Mfr=1, Product=2,
> SerialNumber=0
> [   61.457706] usb 1-1.1.2: Product: FX3
> [   61.457720] usb 1-1.1.2: Manufacturer: Cypress

That is odd, sorry, don't know what to suggest.

greg k-h

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


USB Question about devices being reconnected to the host

2020-10-15 Thread Lucas Tanure

Hi,

I'm learning about USB drivers and I would like to know about 
disconnecting and reconnecting usb devices.


I can see my probe function being called and also the disconnect 
function. But if I reconnect the device there is no call from the kernel 
to notify my driver about the device being reconnected.


I can also see that the module for my driver was not unloaded, so I dont 
understand the life cycle of a USB device.


If the module is not unloaded at disconnection and re-loaded for a new 
device being connected, how can the driver know the device is there 
after a disconnection?


Thanks
Lucas

This is my dmesg for the driver at the end of this email:

[   34.706041] usb 1-1.1.2: new high-speed USB device number 5 using dwc_otg
[   34.837647] usb 1-1.1.2: New USB device found, idVendor=04b4, 
idProduct=00f1, bcdDevice= 0.00
[   34.837666] usb 1-1.1.2: New USB device strings: Mfr=1, Product=2, 
SerialNumber=0

[   34.837679] usb 1-1.1.2: Product: FX3
[   34.837693] usb 1-1.1.2: Manufacturer: Cypress
[   34.902480] usbdev_probe
[   34.902681] usbcore: registered new interface driver My USB Device
[   45.416310] usb 1-1.1.2: USB disconnect, device number 5
[   45.416655] usbdev_disconnect
[   61.326035] usb 1-1.1.2: new high-speed USB device number 6 using dwc_otg
[   61.457674] usb 1-1.1.2: New USB device found, idVendor=04b4, 
idProduct=00f1, bcdDevice= 0.00
[   61.457692] usb 1-1.1.2: New USB device strings: Mfr=1, Product=2, 
SerialNumber=0

[   61.457706] usb 1-1.1.2: Product: FX3
[   61.457720] usb 1-1.1.2: Manufacturer: Cypress

Driver:

#define DEBUG
#include 
#include 
#include 

static int usbdev_probe(struct usb_interface *intf, const struct 
usb_device_id *id)

{
pr_info("%s", __func__);

return 0;
}

static void usbdev_disconnect(struct usb_interface *intf)
{
pr_info("%s", __func__);
}

static int usbdev_suspend(struct usb_interface *intf, pm_message_t message)
{
pr_err("%s", __func__);
return 0;
}

static int usbdev_resume(struct usb_interface *intf)
{
pr_info("%s", __func__);
return 0;
}

static int usbdev_reset_resume(struct usb_interface *intf)
{
pr_info("%s", __func__);
return 0;
}

static int usbdev_pre_reset(struct usb_interface *intf)
{
pr_info("%s", __func__);
return 0;
}

static int usbdev_post_reset(struct usb_interface *intf)
{
pr_info("%s", __func__);
return 0;
}

static const struct usb_device_id usbdev_id_table[] = {
{ USB_DEVICE(0x04b4, 0x00f1) },
{}
};
MODULE_DEVICE_TABLE(usb, usbdev_id_table);

static struct usb_driver usbdev_driver = {
.name   = "My USB Device",
.probe  = usbdev_probe,
.disconnect = usbdev_disconnect,
.id_table   = usbdev_id_table,
.suspend= usbdev_suspend,
.resume = usbdev_resume,
.reset_resume   = usbdev_reset_resume,
.pre_reset  = usbdev_pre_reset,
.post_reset = usbdev_post_reset,
};

module_usb_driver(usbdev_driver);

MODULE_AUTHOR("Lucas Tanure ");
MODULE_DESCRIPTION("Driver for My USB device");
MODULE_LICENSE("GPL v2");

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about the "Dynamic reserved memory" patch

2020-03-12 Thread 양원혁
 
> On Fri, 13 Mar 2020 12:06:37 +0900,  said:
>
> > In the __reserved_mem_reserve_reg() function, I found something that
> > I couldn't easily understand.
> >
> > To get help, I sent an e-mail to this mailing list.
> >
> > if (first) {
> > fdt_reserved_mem_save_node(node, uname, base, size);
> > first = 0;
> > }
> >
> > I found that fdt_reserved_mem_save_node() is called the regardless of
> > memblock remove/reserve success.
> >
> > I think early_init_dt_reserve_memory_arch() can fail.(ex. for the lack
> > of memblock's region)
> >
> > So I wonder there will be a situation where reserved_mem
> > initialization will be executed without memory reservation.
>
> What you probably missed is that function is wrapped in a #ifdef
> CONFIG_OF_EARLY_FLATTREE - and is called to read in the OF devicetree data and
> save it in a form the kernel can use.
>
> So there usually shouldn't be a problem in reserving memory early in boot,
> unless of course somebody bollixed up a devicetree entry and put in bad values
> for base, size, and nomap.   

But, This is when the early memory allocation is not active. Therefore, if 
memblock's 
region[128] is full, memblock_reserve/remove() can fail.(Of course, there 
should be 
more than 128 reserved memory.)

>However, fdt_reserved_mem_save_node() needs to happen anyhow, because that's
>not initialiing the memory that wasn't actually reserved, it's recording the
>fact that the devicetree had a reserved memory request in it, and that needs to
>be remembered because there's a second pass over the devicetree data later on
>(or so the comments in drivers/of/of_reserved_mem.c tell me).

Yes, fdt_reserved_mem_save_node() just register the reseved memory in the 
reserve_mem.
then, reserved_mem is passed to _reserved_mem_init_node(). But In this 
function, 
If the node is "cma", it will call rmem_cma_setup() and it will initializing 
the cma struct,

So what I was wondering was wouldn't the cma structure be initialized without 
memory 
being reserved?

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about the "Dynamic reserved memory" patch

2020-03-12 Thread Valdis Klētnieks
On Fri, 13 Mar 2020 12:06:37 +0900,  said:

> In the __reserved_mem_reserve_reg() function, I found something that
> I couldn't easily understand.
>
> To get help, I sent an e-mail to this mailing list.

> if (first) {
> fdt_reserved_mem_save_node(node, uname, base, size);
> first = 0;
> }

> I found that fdt_reserved_mem_save_node() is called the regardless of
> memblock remove/reserve success.
>
> I think early_init_dt_reserve_memory_arch() can fail.(ex. for the lack
> of memblock's region)
>
> So I wonder there will be a situation where reserved_mem
> initialization will be executed without memory reservation.

What you probably missed is that function is wrapped in a #ifdef
CONFIG_OF_EARLY_FLATTREE - and is called to read in the OF devicetree data and
save it in a form the kernel can use.

So there usually shouldn't be a problem in reserving memory early in boot,
unless of course somebody bollixed up a devicetree entry and put in bad values
for base, size, and nomap.   If that happens, the pr_info() call will fire and
hopefully notify somebody there's a problem.

However, fdt_reserved_mem_save_node() needs to happen anyhow, because that's
not initialiing the memory that wasn't actually reserved, it's recording the
fact that the devicetree had a reserved memory request in it, and that needs to
be remembered because there's a second pass over the devicetree data later on
(or so the comments in drivers/of/of_reserved_mem.c tell me).

Having said that, it *may* make sense to elevate the pr_info() call to a
pr_err(), to make it *obvious* that something went pear-shaped in the
devicetree. But that's a decision for the devicetree/OF maintainers.



pgpp4av6nK4Wf.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Question about the "Dynamic reserved memory" patch

2020-03-12 Thread 양원혁
Hi. 

Recently, I read about the "Dynamic reserved memory" patch.

In the __reserved_mem_reserve_reg() function, I found something that 
I couldn't easily understand. 

To get help, I sent an e-mail to this mailing list.

I attached the code below.

static int __init __reserved_mem_reserve_reg(unsigned long node,
 const char *uname)
{
int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32);
phys_addr_t base, size;
int len;
const __be32 *prop;
int nomap, first = 1;
prop = of_get_flat_dt_prop(node, "reg", );
if (!prop)
return -ENOENT;
if (len && len % t_len != 0) {
pr_err("Reserved memory: invalid reg property in '%s',skipping 
node.\n",
   uname);
return -EINVAL;
}
nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL;
while (len >= t_len) {
base = dt_mem_next_cell(dt_root_addr_cells, );
size = dt_mem_next_cell(dt_root_size_cells, );
if (size &&
early_init_dt_reserve_memory_arch(base, size, nomap) == 0)
pr_debug("Reserved memory: reserved region for node 
'%s': base %pa, size %ld MiB\n",
uname, , (unsigned long)size / SZ_1M);
else
pr_info("Reserved memory: failed to reserve memory for 
node '%s': base %pa, size %ld MiB\n",
uname, , (unsigned long)size / SZ_1M);
len -= t_len;
if (first) {
fdt_reserved_mem_save_node(node, uname, base, size);
first = 0;
}
}
return 0;
}

I found that fdt_reserved_mem_save_node() is called the regardless of
memblock remove/reserve success.

I think early_init_dt_reserve_memory_arch() can fail.(ex. for the lack
of memblock's region)

So I wonder there will be a situation where reserved_mem
initialization will be executed without memory reservation.

I would appreciate it if you let me know if I missed anything :)
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: newbie-level question about cgroups

2019-07-29 Thread Robert P. J. Day
On Sun, 28 Jul 2019, Valdis Klētnieks wrote:

> On Sun, 28 Jul 2019 15:39:26 -0400, "Robert P. J. Day" said:
>
> >   no point bugging the actual cgroup people about this since it
> > should be simple ... if i need *only* cgroup v2, can i dispense
> > entirely with everything under /sys/fs/cgroup/ other than
> > /sys/fs/cgroup/unified?
>
> There's a whole mess of CONFIG_CGROUP_* variables, feel free to turn
> off those that your system doesn't actually need.
>
> Make sure that you keep a backup kernel in case you turn off
> something you shouldn't have.  In particular, systemd seems to want
> all sorts of cgroups for no reason other than "because they're
> there".

  actually, i just ran across the "cgroup_no_v1=" boot-time parameter:

[KNL] Disable cgroup controllers and named hierarchies in v1
Format: { { controller | "all" | "named" }
  [,{ controller | "all" | "named" }...] }
Like cgroup_disable, but only applies to cgroup v1;
the blacklisted controllers remain available in cgroup2.
"all" blacklists all controllers and "named" disables
named mounts. Specifying both "all" and "named" disables
all v1 hierarchies.

so i guess it's not only possible, it's easy. :-)

rday

-- 


Robert P. J. Day Ottawa, Ontario, CANADA
 http://crashcourse.ca

Twitter:   http://twitter.com/rpjday
LinkedIn:   http://ca.linkedin.com/in/rpjday
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: newbie-level question about cgroups

2019-07-28 Thread Valdis Klētnieks
On Sun, 28 Jul 2019 15:39:26 -0400, "Robert P. J. Day" said:

>   no point bugging the actual cgroup people about this since it should
> be simple ... if i need *only* cgroup v2, can i dispense entirely with
> everything under /sys/fs/cgroup/ other than /sys/fs/cgroup/unified?

There's a whole mess of CONFIG_CGROUP_* variables, feel free to turn off
those that your system doesn't actually need.

Make sure that you keep a backup kernel in case you turn off something you
shouldn't have.  In particular, systemd seems to want all sorts of cgroups for
no reason other than "because they're there".


pgpPWA8ULakAz.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


newbie-level question about cgroups

2019-07-28 Thread Robert P. J. Day


  no point bugging the actual cgroup people about this since it should
be simple ... if i need *only* cgroup v2, can i dispense entirely with
everything under /sys/fs/cgroup/ other than /sys/fs/cgroup/unified?

rday

-- 


Robert P. J. Day Ottawa, Ontario, CANADA
 http://crashcourse.ca

Twitter:   http://twitter.com/rpjday
LinkedIn:   http://ca.linkedin.com/in/rpjday


___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about DMA mapping.

2018-08-31 Thread valdis . kletnieks
On Fri, 31 Aug 2018 08:53:29 +0800, "phind@gmail.com" said:

> Thank for your time, I'm new to linux kernel. I am reading LDD3 chapter
> 15, Dirrect Memory Access section. I see that when I call function
> /dma_map_single/ and /dma_unmap_single/, I need to pass a direction as a
> parameter.

Please note that the LDD is current as of 2.6.10, which is from 2005, and
before git was used to maintain the kernel.

[/usr/src/linux-next] git diff --shortstat v2.6.12 v4.19-rc1
 70553 files changed, 23122660 insertions(+), 4318380 deletions(-)

The *concepts* in LDD3 are still valid.  However, the *exact* APIs
are almost certainly changed by now.

[/usr/src/linux-next] ls -l Documentation/DMA*
-rw-r--r--. 1 source source 34951 Jul 18  2017 Documentation/DMA-API-HOWTO.txt
-rw-rw-r--. 1 source source 28310 Sep  7  2017 Documentation/DMA-API.txt
-rw-r--r--. 1 source source  5209 Jul 18  2017 Documentation/DMA-ISA-LPC.txt
-rw-r--r--. 1 source source  7062 Jul 18  2017 Documentation/DMA-attributes.txt

Start there.


pgpcgeWPGP9dv.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Question about DMA mapping.

2018-08-30 Thread phind....@gmail.com

Hi everyone,

Thank for your time, I'm new to linux kernel. I am reading LDD3 chapter 
15, Dirrect Memory Access section. I see that when I call function 
/dma_map_single/ and /dma_unmap_single/, I need to pass a direction as a 
parameter. I wonder what is purpose of it? Does It relate to something 
like permission? Can I call /dma_map_single /with DMA_BIDIRECTIONAL and 
then call /dma_unmap_single /with DMA_TO_DEVICE? Will it cause any problem?


Thank you very much.


___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about memcpy

2018-07-14 Thread Himanshu Jha
On Mon, Jul 09, 2018 at 12:16:27PM -0400, valdis.kletni...@vt.edu wrote:
> On Mon, 09 Jul 2018 19:34:44 +0530, Himanshu Jha said:
> 
> > I think for these benchmarking stuff, to evaluate the cycles and time
> > correctly you should use the __rdtscp(more info at "AMD64 Architecture
> > Programmer???s Manual Volume 3: General-Purpose and System Instructions"
> > Pg 401)
> 
> Just beware that many Intel (and maybe some AMD) chipsets have a non-constant
> TSC frequency.  Check /proc/cpuinfo for 'constant_tsc' before relying on the 
> value.

How about setting "performance" governor[1] for all CPUs ?
Would that work ? I mean no throttle down, but not sure if we have a
constant cpufreq.

Something like the following script:

for CPUFREQ in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor;
do [ -f $CPUFREQ ] || continue; 
echo -n performance > $CPUFREQ;
done

[1] 
https://www.kernel.org/doc/html/v4.14/admin-guide/pm/cpufreq.html#performance

-- 
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about memcpy

2018-07-13 Thread valdis . kletnieks
On Fri, 13 Jul 2018 11:02:13 +0800, bing zhu said:

> I‘m trying to write a simple fs in user space,if memcpy is slower than
> kernel , i think it's unfair,as for only cpu for my task,
> it's a bit of arbitrary ,i just want my task not interrupted during a
> specific time is that possible ?

Not getting interrupted is an *entirely* different issue than making memcpy 
fast.

Note that in general, systems code should be able to deal with interruptions
during most parts of the code, and locking used and disabling pre-emption for
sections of code that can't deal with being interrupted.  Remember that if your
filesystem code turns off interrupts for long enough, you can start losing
things like I/O completions.  Fortunately for those who write systems code,
the vast majority of interrupts are totally transparent to the vast majority
of the kernel code.

And if you're doing a file system in userspace, you're going to fail to notice
hundreds or even thousands of interrupts happening. If you don't believe me,
'cat /proc/interrupts', and realize that userspace didn't notice *any* of them
happening.



pgpKxTF7O0vLQ.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about memcpy

2018-07-12 Thread bing zhu
I‘m trying to write a simple fs in user space,if memcpy is slower than
kernel , i think it's unfair,as for only cpu for my task,
it's a bit of arbitrary ,i just want my task not interrupted during a
specific time is that possible ?

2018-07-12 22:53 GMT+08:00 Greg KH :

> A: http://en.wikipedia.org/wiki/Top_post
> Q: Were do I find info about this thing called top-posting?
> A: Because it messes up the order in which people normally read text.
> Q: Why is top-posting such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing in e-mail?
>
> A: No.
> Q: Should I include quotations after my reply?
>
> http://daringfireball.net/2007/07/on_top
>
>
> On Thu, Jul 12, 2018 at 10:27:37PM +0800, bing zhu wrote:
> > as for memcpy ,kernel is faster than user ,might because schedule ,can i
> try to
> > make user as fast as kernel ?
>
> You can bind a specific CPU to your userspace task, and have it only run
> that program and not get interupted at all for anything.  That would
> make it as fast as the kernel runs.  Lots of people do that in high
> frequency trading as they don't want the CPU to get in the way of their
> work or response times to the network.
>
> But without doing fancy tricks like that, no.  Think about what an
> operating system does.  It's job is to schedule things that need to be
> done behind the back of your program.  Otherwise there's no need for it,
> right?
>
> good luck!
>
> greg k-h
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about memcpy

2018-07-12 Thread valdis . kletnieks
On Thu, 12 Jul 2018 22:27:37 +0800, bing zhu said:

> as for memcpy ,kernel is faster than user ,might because schedule ,can i
> try to make user as fast as kernel ?

Do you have an actual issue where the difference in speed of these two
things makes a difference?  Or is this primarily a mental curiosity thing?


pgpA1hBztvIuQ.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about memcpy

2018-07-12 Thread Greg KH
A: http://en.wikipedia.org/wiki/Top_post
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

A: No.
Q: Should I include quotations after my reply?

http://daringfireball.net/2007/07/on_top


On Thu, Jul 12, 2018 at 10:27:37PM +0800, bing zhu wrote:
> as for memcpy ,kernel is faster than user ,might because schedule ,can i try 
> to
> make user as fast as kernel ?

You can bind a specific CPU to your userspace task, and have it only run
that program and not get interupted at all for anything.  That would
make it as fast as the kernel runs.  Lots of people do that in high
frequency trading as they don't want the CPU to get in the way of their
work or response times to the network.

But without doing fancy tricks like that, no.  Think about what an
operating system does.  It's job is to schedule things that need to be
done behind the back of your program.  Otherwise there's no need for it,
right?

good luck!

greg k-h

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about memcpy

2018-07-12 Thread bing zhu
as for memcpy ,kernel is faster than user ,might because schedule ,can i
try to make user as fast as kernel ?

2018-07-12 13:34 GMT+08:00 Greg KH :

> On Thu, Jul 12, 2018 at 12:47:12PM +0800, bing zhu wrote:
> > agree! a simple rename would survice.results are the same .kernel is
> faster
> > could anyone help fix this ?
>
> Fix what exactly?
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about memcpy

2018-07-11 Thread Greg KH
On Thu, Jul 12, 2018 at 12:47:12PM +0800, bing zhu wrote:
> agree! a simple rename would survice.results are the same .kernel is faster
> could anyone help fix this ?

Fix what exactly?

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about memcpy

2018-07-11 Thread bing zhu
agree! a simple rename would survice.results are the same .kernel is faster
could anyone help fix this ?

2018-07-11 0:03 GMT+08:00 :

> On Tue, 10 Jul 2018 22:51:34 +0800, bing zhu said:
>
> > Thank you ,I use this func for both kernel and user ,result are same.
> > void *memcpy(void *dest, const void *src, size_t n)
> > {
>
> Might want to use 'void *my_memcpy(..)' instead, just in case the build
> environment plays #define games with you and causes a different memcpy()
> to get invoked instead.
>
> [/usr/src/linux-next] egrep -r '#define\s*memcpy\(' include/ arch/*/include
> arch/arm64/include/asm/string.h:#define memcpy(dst, src, len)
> __memcpy(dst, src, len)
> arch/m68k/include/asm/string.h:#define memcpy(d, s, n)
> __builtin_memcpy(d, s, n)
> arch/sparc/include/asm/string.h:#define memcpy(t, f, n)
> __builtin_memcpy(t, f, n)
> arch/x86/include/asm/string_64.h:#define memcpy(dst, src, len)
>   \
> arch/x86/include/asm/string_64.h:#define memcpy(dst, src, len)
> __memcpy(dst, src, len)
> arch/x86/include/asm/string_32.h:#define memcpy(t, f, n)
>   \
> arch/x86/include/asm/string_32.h:#define memcpy(t, f, n)
> __builtin_memcpy(t, f, n)
> arch/x86/include/asm/string_32.h:#define memcpy(t, f, n)
>   \
> arch/xtensa/include/asm/string.h:#define memcpy(dst, src, len)
> __memcpy(dst, src, len)
>
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about memcpy

2018-07-10 Thread valdis . kletnieks
On Tue, 10 Jul 2018 22:51:34 +0800, bing zhu said:

> Thank you ,I use this func for both kernel and user ,result are same.
> void *memcpy(void *dest, const void *src, size_t n)
> {

Might want to use 'void *my_memcpy(..)' instead, just in case the build
environment plays #define games with you and causes a different memcpy()
to get invoked instead.

[/usr/src/linux-next] egrep -r '#define\s*memcpy\(' include/ arch/*/include
arch/arm64/include/asm/string.h:#define memcpy(dst, src, len) __memcpy(dst, 
src, len)
arch/m68k/include/asm/string.h:#define memcpy(d, s, n) __builtin_memcpy(d, s, n)
arch/sparc/include/asm/string.h:#define memcpy(t, f, n) __builtin_memcpy(t, f, 
n)
arch/x86/include/asm/string_64.h:#define memcpy(dst, src, len)  
\
arch/x86/include/asm/string_64.h:#define memcpy(dst, src, len) __memcpy(dst, 
src, len)
arch/x86/include/asm/string_32.h:#define memcpy(t, f, n)
\
arch/x86/include/asm/string_32.h:#define memcpy(t, f, n) __builtin_memcpy(t, f, 
n)
arch/x86/include/asm/string_32.h:#define memcpy(t, f, n)
\
arch/xtensa/include/asm/string.h:#define memcpy(dst, src, len) __memcpy(dst, 
src, len)



pgp63qxFnoXbQ.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about memcpy

2018-07-10 Thread Greg KH
On Tue, Jul 10, 2018 at 10:51:34PM +0800, bing zhu wrote:
> Thank you ,I use this func for both kernel and user ,result are same.
> void *memcpy(void *dest, const void *src, size_t n)
> {
> long d0, d1, d2;
> asm volatile(
> "rep ; movsq\n\t"
> "movq %4,%%rcx\n\t"
> "rep ; movsb\n\t"
> : "=" (d0), "=" (d1), "=" (d2)
> : "0" (n >> 3), "g" (n & 7), "1" (dest), "2" (src)
> : "memory");
> 
> return dest;
> }
> kernel is indeed faster than user.

Ok, and that is due to the fact that the kernel thread does not get
scheduled, unlike your userspace program.  So this means the kernel is
working as designed :)

greg k-h

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about memcpy

2018-07-10 Thread bing zhu
Thank you ,I use this func for both kernel and user ,result are same.
void *memcpy(void *dest, const void *src, size_t n)
{
long d0, d1, d2;
asm volatile(
"rep ; movsq\n\t"
"movq %4,%%rcx\n\t"
"rep ; movsb\n\t"
: "=" (d0), "=" (d1), "=" (d2)
: "0" (n >> 3), "g" (n & 7), "1" (dest), "2" (src)
: "memory");

return dest;
}
kernel is indeed faster than user.

2018-07-10 14:22 GMT+08:00 Greg KH :

> On Tue, Jul 10, 2018 at 12:50:21PM +0800, bing zhu wrote:
> > I agree !,just i think the problem is still there,memcpy is indeed
> faster in
> > kernel than in user,i've tried both ways .
>
> Make sure you are actually using the same code for memcpy in both
> places.  Do not rely on your libc or the kernel library for such a
> thing, otherwise you are not comparing the same code exactly.
>
> > schedule might be to blame.
>
> Lots of things "might be to blame", but first off, try to work out
> exactly what you are trying to test, and why, and work on that.
>
> good luck!
>
> greg k-h
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about memcpy

2018-07-10 Thread Greg KH
On Tue, Jul 10, 2018 at 12:50:21PM +0800, bing zhu wrote:
> I agree !,just i think the problem is still there,memcpy is indeed faster in
> kernel than in user,i've tried both ways .

Make sure you are actually using the same code for memcpy in both
places.  Do not rely on your libc or the kernel library for such a
thing, otherwise you are not comparing the same code exactly.

> schedule might be to blame.

Lots of things "might be to blame", but first off, try to work out
exactly what you are trying to test, and why, and work on that.

good luck!

greg k-h

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about memcpy

2018-07-09 Thread bing zhu
I agree !,just i think the problem is still there,memcpy is indeed faster
in kernel than in user,i've tried both ways .
schedule might be to blame.

2018-07-09 22:04 GMT+08:00 Himanshu Jha :

> Hi Bing,
>
> On Sun, Jul 08, 2018 at 10:03:48PM +0800, bing zhu wrote:
> > void *p = malloc(4096 * max);
> > start = usec();
> > for (i = 0; i < max; i++) {
> > memcpy(p + i * 4096, page, 4096);
> > }
> > end = usec();
> > printf("%s : %d time use %lu us \n", __func__, max,end - start);
> >
> > static unsigned long usec(void)
> > {
> > struct timeval tv;
> > gettimeofday(, 0);
> > return (unsigned long)tv.tv_sec * 100 + tv.tv_usec;
> > }
>
> I think for these benchmarking stuff, to evaluate the cycles and time
> correctly you should use the __rdtscp(more info at "AMD64 Architecture
> Programmer’s Manual Volume 3: General-Purpose and System Instructions"
> Pg 401)
>
> Userspace:
> --
> #include 
> #include 
> #include 
> #include 
>
> volatile unsigned sink;
> unsigned int junk;
>
> int main (void)
> {
> clock_t start = clock();
> register uint64_t t=__rdtscp();
>
> for(size_t i=0; i<1000; ++i)
> sink++;
>
> t=__rdtscp()-t;
> clock_t end = clock();
> double cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
>
> printf("for loop took %f seconds to execute %zu cylces\n", cpu_time_used,
> t);
> }
> -
>
> Kernelspace:
> If you want to dig more:
> https://www.intel.com/content/dam/www/public/us/en/
> documents/white-papers/ia-32-ia-64-benchmark-code-execution-paper.pdf
>
>
> Thanks
> --
> Himanshu Jha
> Undergraduate Student
> Department of Electronics & Communication
> Guru Tegh Bahadur Institute of Technology
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about watchdog

2018-07-09 Thread Ruben Safir
On 07/09/2018 12:17 PM, valdis.kletni...@vt.edu wrote:
> Linux doesn't have a "filesystem bus".


of course not.  i mispoke

-- 
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002

http://www.nylxs.com - Leadership Development in Free Software
http://www.brooklyn-living.com

Being so tracked is for FARM ANIMALS and and extermination camps,
but incompatible with living as a free human being. -RI Safir 2013

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about watchdog

2018-07-09 Thread valdis . kletnieks
On Mon, 09 Jul 2018 09:30:51 -0400, Ruben Safir said:
> On 07/08/2018 04:44 PM, valdis.kletni...@vt.edu wrote:
> > Error while parsing statement.,  What is a "filesystem bus" and when does it
> > issue a HW interrupt?

> You have a hard drive on the system bus and it sends interupts...

That's probably on the PCI or USB buses - Linux doesn't have a "filesystem bus".


pgpg0v7cVqune.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about memcpy

2018-07-09 Thread valdis . kletnieks
On Mon, 09 Jul 2018 19:34:44 +0530, Himanshu Jha said:

> I think for these benchmarking stuff, to evaluate the cycles and time
> correctly you should use the __rdtscp(more info at "AMD64 Architecture
> Programmer’s Manual Volume 3: General-Purpose and System Instructions"
> Pg 401)

Just beware that many Intel (and maybe some AMD) chipsets have a non-constant
TSC frequency.  Check /proc/cpuinfo for 'constant_tsc' before relying on the 
value.



pgpQ1gxUPeraD.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about memcpy

2018-07-09 Thread Himanshu Jha
Hi Bing,

On Sun, Jul 08, 2018 at 10:03:48PM +0800, bing zhu wrote:
> void *p = malloc(4096 * max);
> start = usec();
> for (i = 0; i < max; i++) {
> memcpy(p + i * 4096, page, 4096);
> }
> end = usec();
> printf("%s : %d time use %lu us \n", __func__, max,end - start);
> 
> static unsigned long usec(void)
> {
> struct timeval tv;
> gettimeofday(, 0);
> return (unsigned long)tv.tv_sec * 100 + tv.tv_usec;
> }

I think for these benchmarking stuff, to evaluate the cycles and time
correctly you should use the __rdtscp(more info at "AMD64 Architecture
Programmer’s Manual Volume 3: General-Purpose and System Instructions"
Pg 401)

Userspace:
--
#include 
#include 
#include 
#include 

volatile unsigned sink;
unsigned int junk;

int main (void)
{
clock_t start = clock();
register uint64_t t=__rdtscp();

for(size_t i=0; i<1000; ++i)
sink++;

t=__rdtscp()-t;
clock_t end = clock();
double cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;

printf("for loop took %f seconds to execute %zu cylces\n", cpu_time_used, t);
}
-

Kernelspace:
If you want to dig more:
https://www.intel.com/content/dam/www/public/us/en/documents/white-papers/ia-32-ia-64-benchmark-code-execution-paper.pdf


Thanks
-- 
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about watchdog

2018-07-09 Thread Ruben Safir
On 07/08/2018 04:44 PM, valdis.kletni...@vt.edu wrote:
> Error while parsing statement.,  What is a "filesystem bus" and when does it
> issue a HW interrupt?


You have a hard drive on the system bus and it sends interupts...
Not to mention other devices like network cards, GPUs, Firewire, express
PCI and PLP, and even the CPU and LUNA

All these hard peices demand attention and send interupts on the system bus

http://www.nylxs.com/docs/journal_2_2015.pdf

-- 
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002

http://www.nylxs.com - Leadership Development in Free Software
http://www.brooklyn-living.com

Being so tracked is for FARM ANIMALS and and extermination camps,
but incompatible with living as a free human being. -RI Safir 2013

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Re: Question about memcpy

2018-07-09 Thread bing zhu
in kernel you should use this func:
static unsigned long usec(void)
{
struct timeval tv;
do_gettimeofday();
return (unsigned long)tv.tv_sec * 100 + tv.tv_usec;
}


2018-07-09 15:54 GMT+08:00 袁建鹏 :

> can you show all code kernel and userspace ?
>
> Kernel compile options are optimized, very different from userspace.
>
> you can use the same object (memcpy.o) to link userspace program and
> kernel module.
>
> -原始邮件-
> *发件人:*"bing zhu" 
> *发送时间:*2018-07-08 22:03:48 (星期日)
> *收件人:* "Valdis Kletnieks" 
> *抄送:* kernelnewbies@kernelnewbies.org
> *主题:* Re: Question about memcpy
>
> void *p = malloc(4096 * max);
> start = usec();
> for (i = 0; i < max; i++) {
> memcpy(p + i * 4096, page, 4096);
> }
> end = usec();
> printf("%s : %d time use %lu us \n", __func__, max,end - start);
>
> static unsigned long usec(void)
> {
> struct timeval tv;
> gettimeofday(, 0);
> return (unsigned long)tv.tv_sec * 100 + tv.tv_usec;
> }
>
>
> I'm don't think it's really precise but i did notice a difference ,
>
> 2018-07-08 2:44 GMT+08:00 :
>
>> On Sat, 07 Jul 2018 19:36:47 +0800, bing zhu said:
>>
>> > and in user space i do the same thing,I noticed that kernel is faster
>> than
>> > user ,
>>
>> How did you measure the times? Doing this right is actually harder than
>> it looks...
>>
>
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Re: Question about memcpy

2018-07-09 Thread 袁建鹏
can you show all code kernel and userspace ?

Kernel compile options are optimized, very different from userspace.

you can use the same object (memcpy.o) to link userspace program and kernel 
module.

-原始邮件-
发件人:"bing zhu" 
发送时间:2018-07-08 22:03:48 (星期日)
收件人: "Valdis Kletnieks" 
抄送: kernelnewbies@kernelnewbies.org
主题: Re: Question about memcpy


void *p = malloc(4096 * max);
start = usec();
for (i = 0; i < max; i++) {
memcpy(p + i * 4096, page, 4096);
}
end = usec();
printf("%s : %d time use %lu us \n", __func__, max,end - start);


static unsigned long usec(void)
{
struct timeval tv;
gettimeofday(, 0);
return (unsigned long)tv.tv_sec * 100 + tv.tv_usec;
}




I'm don't think it's really precise but i did notice a difference ,


2018-07-08 2:44 GMT+08:00 :
On Sat, 07 Jul 2018 19:36:47 +0800, bing zhu said:

> and in user space i do the same thing,I noticed that kernel is faster than
> user ,

How did you measure the times? Doing this right is actually harder than it 
looks...


___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about watchdog

2018-07-08 Thread valdis . kletnieks
On Sun, 08 Jul 2018 15:46:32 -0400, Ruben Safir said:

> What are you saying?  That is the filesystem bus sends a HW interupt on

Error while parsing statement.,  What is a "filesystem bus" and when does it
issue a HW interrupt?


pgpAXjJvARBym.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about watchdog

2018-07-08 Thread Ruben Safir
On Mon, Jul 02, 2018 at 10:29:30AM +0200, Greg KH wrote:
> On Mon, Jul 02, 2018 at 08:58:16AM +0100, Justin Skists wrote:
> > 
> > > On 01 July 2018 at 13:44 bing zhu  wrote:
> > > 
> > > 
> > > Dear Sir/Ma'am
> > > Thank you for your time ,i'm a student new to linux kernel.at present ,i'd
> > > like to create a kernel thread
> > > say use kthread_create func ,my question is :how can i make this thread to
> > > run on a cpu and never get switched or scheduled , there is a
> > > while(1).structure in that thread i need it to do work . at present i
> > > comes with errors like "NMI watchdog: BUG: soft lockup - CPU#0 stuck for
> > > 23s! [test thread :1881]",i understand there is a watchdog but is there
> > > anyway i can feed the dog myself and let my thread have cpu as much as i
> > > want ?
> > 
> > Yowsers! Why would you want to do that? The whole idea of a watchdog is
> > to prevent threads hogging the CPU for a long time. Linux is a multi-user,
> > multi-process, pre-emptive operating system. It needs to share. :-)
> 
> Not true, Linux can take a cpu, remove itself from it, and run a single
> process if needed, just fine.  It's a great operating system for such a
> thing.
> 
> You just have to use the apis we have for this already, it's been
> possible to do this for many years now.
> 
> As for why you would want to do this within the kernel itself, well, I
> can understand that need for some situations, and it is possible to do
> as well, just use the correct api and all is fine (no, I can't remember
> what it is at the moment, sorry...)
> 
> greg k-h
> 


What are you saying?  That is the filesystem bus sends a HW interupt on
the bus that the scheuler will ignore it and refuse to swap the
executable to handle the HW interupt?


> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

-- 
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com 

DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive 
http://www.coinhangout.com - coins!
http://www.brooklyn-living.com 

Being so tracked is for FARM ANIMALS and and extermination camps, 
but incompatible with living as a free human being. -RI Safir 2013


___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about memcpy

2018-07-08 Thread bing zhu
void *p = malloc(4096 * max);
start = usec();
for (i = 0; i < max; i++) {
memcpy(p + i * 4096, page, 4096);
}
end = usec();
printf("%s : %d time use %lu us \n", __func__, max,end - start);

static unsigned long usec(void)
{
struct timeval tv;
gettimeofday(, 0);
return (unsigned long)tv.tv_sec * 100 + tv.tv_usec;
}


I'm don't think it's really precise but i did notice a difference ,

2018-07-08 2:44 GMT+08:00 :

> On Sat, 07 Jul 2018 19:36:47 +0800, bing zhu said:
>
> > and in user space i do the same thing,I noticed that kernel is faster
> than
> > user ,
>
> How did you measure the times? Doing this right is actually harder than it
> looks...
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about memcpy

2018-07-07 Thread valdis . kletnieks
On Sat, 07 Jul 2018 19:36:47 +0800, bing zhu said:

> and in user space i do the same thing,I noticed that kernel is faster than
> user ,

How did you measure the times? Doing this right is actually harder than it 
looks...


pgpT3oFpml7qt.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about memcpy

2018-07-07 Thread Alex Arvelaez
On Jul 7, 2018 7:37 AM, bing zhu  wrote:
>
> Dear Sir/Ma'am
> Thank you for your time ,i'm a student new to linux kernel.
> I have a question about memcpy,i noticed that memcpy is faster in kernel than 
> in user space
> for example :
> in a module helloworld , i use memcpy to copy a 4096B to a block of memory 
> for like 1 times
> and in user space i do the same thing,I noticed that kernel is faster than 
> user ,
> is it possible that in kernel when i insmod hello it can not be scheduled but 
> in user space it will so kernel is faster?

This makes sense, less context switches.

> is there a possible way that a user task can run a block of code that 
> uninterruptable? No switch ,no schedule ?

I don't think this is possible, Linux is a preemptive kernel.

> Thank you !
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Question about memcpy

2018-07-07 Thread bing zhu
Dear Sir/Ma'am
Thank you for your time ,i'm a student new to linux kernel.
I have a question about memcpy,i noticed that memcpy is faster in kernel
than in user space
for example :
in a module helloworld , i use memcpy to copy a 4096B to a block of memory
for like 1 times
and in user space i do the same thing,I noticed that kernel is faster than
user ,
is it possible that in kernel when i insmod hello it can not be scheduled
but in user space it will so kernel is faster?
is there a possible way that a user task can run a block of code that
uninterruptable? No switch ,no schedule ?
Thank you !
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about watchdog

2018-07-03 Thread valdis . kletnieks
On Tue, 03 Jul 2018 10:28:48 +0800, you said:

> yes ! but there are days when people have to do a real-time work with no
> delay in kernel space ,i think i can feed the dog
> a percpu variable "nmi_touch" looks suspicious,thanks!

1) The Linux kernel community convention is t use 'reply all' so that a copy
goes back to the list, so that all may read, learn, and comment...

2) If you're hanging a CPU with something for long enough to trigger a watchdog
event, you've *already* *broken* real-time processing on that CPU.

Read that second sentence again, and repeat until it sinks in.

If the watchdog is firing for a CPU because you've been running a tight loop
on it for *that* long, *that CPU is by definition not able to do realtime in a 
Linux
context*.



pgpC_GIGOeqnU.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about watchdog

2018-07-02 Thread valdis . kletnieks
On Sun, 01 Jul 2018 20:44:29 +0800, bing zhu said:

> say use kthread_create func ,my question is :how can i make this thread to
> run on a cpu and never get switched or scheduled , there is a
> while(1).structure in that thread i need it to do work

That's almost certainly a result of a poor design.  What problem
were you trying to solve by wrapping a 'while(1)' around in-kernel code?

> comes with errors like "NMI watchdog: BUG: soft lockup - CPU#0 stuck for
> 23s! [test thread :1881]",i understand there is a watchdog but is there
> anyway i can feed the dog myself and let my thread have cpu as much as i
> want ?

There are ways.  But you probably should figure out how to fix your code
so feeding the watchdog isn't needed


pgpOzKYuHSsfl.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about watchdog

2018-07-02 Thread Justin Skists


> On 02 July 2018 at 09:29 Greg KH  wrote:
> 
> 
> On Mon, Jul 02, 2018 at 08:58:16AM +0100, Justin Skists wrote:
> > 
> > > On 01 July 2018 at 13:44 bing zhu  wrote:
> > > 
> > > 
> > > Dear Sir/Ma'am
> > > Thank you for your time ,i'm a student new to linux kernel.at present ,i'd
> > > like to create a kernel thread
> > > say use kthread_create func ,my question is :how can i make this thread to
> > > run on a cpu and never get switched or scheduled , there is a
> > > while(1).structure in that thread i need it to do work . at present i
> > > comes with errors like "NMI watchdog: BUG: soft lockup - CPU#0 stuck for
> > > 23s! [test thread :1881]",i understand there is a watchdog but is there
> > > anyway i can feed the dog myself and let my thread have cpu as much as i
> > > want ?
> > 
> > Yowsers! Why would you want to do that? The whole idea of a watchdog is
> > to prevent threads hogging the CPU for a long time. Linux is a multi-user,
> > multi-process, pre-emptive operating system. It needs to share. :-)
> 
> Not true, Linux can take a cpu, remove itself from it, and run a single
> process if needed, just fine.  It's a great operating system for such a
> thing.

Hmm. Interesting. Looks like I've got more reading to do. :-)


Thanks,
Justin.

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about watchdog

2018-07-02 Thread Greg KH
On Mon, Jul 02, 2018 at 08:58:16AM +0100, Justin Skists wrote:
> 
> > On 01 July 2018 at 13:44 bing zhu  wrote:
> > 
> > 
> > Dear Sir/Ma'am
> > Thank you for your time ,i'm a student new to linux kernel.at present ,i'd
> > like to create a kernel thread
> > say use kthread_create func ,my question is :how can i make this thread to
> > run on a cpu and never get switched or scheduled , there is a
> > while(1).structure in that thread i need it to do work . at present i
> > comes with errors like "NMI watchdog: BUG: soft lockup - CPU#0 stuck for
> > 23s! [test thread :1881]",i understand there is a watchdog but is there
> > anyway i can feed the dog myself and let my thread have cpu as much as i
> > want ?
> 
> Yowsers! Why would you want to do that? The whole idea of a watchdog is
> to prevent threads hogging the CPU for a long time. Linux is a multi-user,
> multi-process, pre-emptive operating system. It needs to share. :-)

Not true, Linux can take a cpu, remove itself from it, and run a single
process if needed, just fine.  It's a great operating system for such a
thing.

You just have to use the apis we have for this already, it's been
possible to do this for many years now.

As for why you would want to do this within the kernel itself, well, I
can understand that need for some situations, and it is possible to do
as well, just use the correct api and all is fine (no, I can't remember
what it is at the moment, sorry...)

greg k-h

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about watchdog

2018-07-02 Thread Justin Skists


> On 01 July 2018 at 13:44 bing zhu  wrote:
> 
> 
> Dear Sir/Ma'am
> Thank you for your time ,i'm a student new to linux kernel.at present ,i'd
> like to create a kernel thread
> say use kthread_create func ,my question is :how can i make this thread to
> run on a cpu and never get switched or scheduled , there is a
> while(1).structure in that thread i need it to do work . at present i
> comes with errors like "NMI watchdog: BUG: soft lockup - CPU#0 stuck for
> 23s! [test thread :1881]",i understand there is a watchdog but is there
> anyway i can feed the dog myself and let my thread have cpu as much as i
> want ?

Yowsers! Why would you want to do that? The whole idea of a watchdog is
to prevent threads hogging the CPU for a long time. Linux is a multi-user,
multi-process, pre-emptive operating system. It needs to share. :-)

If you really need a thread to hog the processor, indefinitely, then you're
probably using the wrong OS. Use the correct tool for the job. Or explore
"cpusets". Or maybe rebuild the kernel with soft watchdog turned off.


Justin.

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about watchdog

2018-07-01 Thread Ruben Safir
On 07/01/2018 08:44 AM, bing zhu wrote:
> my question is :how can i make this thread to
> run on a cpu and never get switched or scheduled ,


it is a preemptive multitasking kernel

-- 
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com

DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive
http://www.coinhangout.com - coins!
http://www.brooklyn-living.com

Being so tracked is for FARM ANIMALS and and extermination camps,
but incompatible with living as a free human being. -RI Safir 2013

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Question about watchdog

2018-07-01 Thread bing zhu
Dear Sir/Ma'am
Thank you for your time ,i'm a student new to linux kernel.at present ,i'd
like to create a kernel thread
say use kthread_create func ,my question is :how can i make this thread to
run on a cpu and never get switched or scheduled , there is a
while(1).structure in that thread i need it to do work . at present i
comes with errors like "NMI watchdog: BUG: soft lockup - CPU#0 stuck for
23s! [test thread :1881]",i understand there is a watchdog but is there
anyway i can feed the dog myself and let my thread have cpu as much as i
want ?
thanks again ,any information would be great !
best wishes!
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about mmap

2018-06-15 Thread Mulyadi Santosa
On Mon, Jun 11, 2018 at 7:47 PM, bing zhu  wrote:

> Dear Sir/Ma'am
> How can i map a kernel virtual address to a user process's same virtual
> address ?is it possible ?
> thank you for your time
> best wishes!
>
>
Dear Bing

Just to clarify, what do you mean by "user process' same virtual address"?


> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>


-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com


Virus-free.
www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about mmap

2018-06-12 Thread Seunguk Shin
Dear Bing Zhu,

You can remap kernel memory to userspace using remap_pfn_range.

Thank you.
Best regards,
Seunguk Shin

-- Original Message --
From: "bing zhu" mailto:zhubohon...@gmail.com>>
To: kernelnewbies@kernelnewbies.org<mailto:kernelnewbies@kernelnewbies.org>
Sent: 6/11/2018 9:47:55 PM
Subject: Question about mmap

Dear Sir/Ma'am
How can i map a kernel virtual address to a user process's same virtual address 
?is it possible ?
thank you for your time
best wishes!
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Question about mmap

2018-06-11 Thread bing zhu
Dear Sir/Ma'am
How can i map a kernel virtual address to a user process's same virtual
address ?is it possible ?
thank you for your time
best wishes!
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: A question about function split_mem_range

2018-03-25 Thread valdis . kletnieks
On Sun, 25 Mar 2018 22:32:42 +0800, Hao Lee said:

> In arch/x86/mm/init.c, there is a function called split_mem_range[0].
> Its logic is very complicated and I can't figure out what it does. I
> have added some debug statements in this function to print all
> variable, but I still can't understand it. I have also searched it on
> Google and couldn't find any helpful articles. Could someone give me
> some help about what on earth this function does? Many thanks!

Step 0: kernel functions are usually given somewhat descriptive names.
So what can we guess based on the function name?  That it performs some
sort of slicing and dicing of a memory range...

Step 1:  Use what you already know about the function. For example, it's under
arch/x86 - which means it has architecture dependencies. It's marked 'static
__meminit' - which means that (a) there's no direct calls from other files, and
(b) there probably isn't a call through an address pointer (because this code
may get freed and the memory reclaimed after __miminit is done).  And indeed,
'git grep' (or "grep -r') confirms the only other use is also in mm/init.c (and 
we
see no sign of an _mem_range() so it can't be called via pointer passed
elsewhere).

Step 2: look at the call site in init_memory_swapping(), which provides us this
nice block comment:

/*
 * Setup the direct mapping of the physical memory at PAGE_OFFSET.
 * This runs before bootmem is initialized and gets pages directly from
 * the physical memory. To access them they are temporarily mapped.
 */

Step 3: look at the code around the call site:

memset(mr, 0, sizeof(mr));
nr_range = split_mem_range(mr, 0, start, end);

for (i = 0; i < nr_range; i++)
ret = kernel_physical_mapping_init(mr[i].start, mr[i].end,
   mr[i].page_size_mask);

So  before the call, mr[] is a whole lot of zeros.  After the call, the array
has a series of start/end/mask entries suitable for setting up a temporary
physical mapping.

>From this we can conclude that split_mem_range() is a helper function that
takes a range (for example "starting at the 0M address line and ending at the
512M address line") and returns a list of suitable ranges for mappings, while
applying some rules like "Don't use a hugepage for the first 4M on 32-bit".  So
what comes back is an array that basically says something like "Use a 4K page
at 0, a 4K page at 4K, a 4K at 8/12/... up to "4K at (2M-4))", a 2M hugepage at
2M, 4M... 508M. Or something else suitable for the kernel config (32/64 bit,
etc, look at the #ifdefs to figure out exactly what it does for a given address
location)

 (Actual  start and end are whatever the rest of the kernel decides, I couldn't
be bothered to chase down code that has a pr_debug() to print the numbers out
for anybody who care).



pgpJN0WLAWjE7.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


A question about function split_mem_range

2018-03-25 Thread Hao Lee
Hi,

I'm currently reading the memory management source code and get stuck
on a function.

In arch/x86/mm/init.c, there is a function called split_mem_range[0].
Its logic is very complicated and I can't figure out what it does. I
have added some debug statements in this function to print all
variable, but I still can't understand it. I have also searched it on
Google and couldn't find any helpful articles. Could someone give me
some help about what on earth this function does? Many thanks!

[0] 
https://github.com/torvalds/linux/blob/bcfc1f4554662d8f2429ac8bd96064a59c149754/arch/x86/mm/init.c#L325

Regards,
Hao Lee

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: A question about decompressing kernel on boot

2018-02-25 Thread ????
Hi Hao Lee,
Really appreciate your help.
:-)
Regards,
Larry






-- Original --
From:  "haolee.swjtu"<haolee.sw...@gmail.com>;
Date:  Mon, Feb 26, 2018 00:17 AM
To:  ""<losemyhea...@foxmail.com>;
Cc:  "kernelnewbies"<kernelnewbies@kernelnewbies.org>; 
Subject:  Re: A question about decompressing kernel on boot




 
leaq(_bss-8)(%rip), %rsi
 
leaq(_bss-8)(%rbx), %rdi
 
movq$_bss /* - $startup_32 */, %rcx
 
shrq$3, %rcx
 
std
 
rep movsq
 
cld
 
 
 
The movsq instruction copys 8 bytes each time and for the first time it will 
copy [_bss-8, _bss) to the new location. If we don't minus 8, the data in 
[_bss, _bss+8) will also be copied on the first execution of movsq. Obviously, 
we don't want to copy the bss section.
 

 Regards,
 Hao Lee___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: A question about decompressing kernel on boot

2018-02-25 Thread haolee.swjtu

	leaq	(_bss-8)(%rip), %rsi

	leaq	(_bss-8)(%rbx), %rdi

	movq	$_bss /* - $startup_32 */, %rcx

	shrq	$3, %rcx

	std

	rep	movsq

	cld


The movsq instruction copys 8 bytes each time and for the first time it will copy [_bss-8, _bss) to the new location. If we don't minus 8, the data in [_bss, _bss+8) will also be copied on the first execution of movsq. Obviously, we don't want to copy the bss section.

Regards,
Hao Lee___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


A question about decompressing kernel on boot

2018-02-25 Thread ????
Hi list,



In the source code arch/x86/boot/compressed/head_64.S, it described
how compressed kernel is copied from the origin place to another pointed by rbx 
register.


But I'm confused about the copying code, why it needs to minus 8 from _bss when 
calculating
_bss original and new addresses.


This is the source code.
/*
 * Copy the compressed kernel to the end of our buffer
 * where decompression in place becomes safe.
 */
pushq   %rsi
leaq(_bss-8)(%rip), %rsi
leaq(_bss-8)(%rbx), %rdi
movq$_bss /* - $startup_32 */, %rcx
shrq$3, %rcx
std
rep movsq
cld
popq%rsi


Thanks,
Larry___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about uprobes

2017-04-07 Thread Mulyadi Santosa
On Thursday, April 6, 2017, W. Michael Petullo  wrote:

> >> I am writing some software that monitors a guest VM using
> virtual-machine
> >> introspection and "hijacks" system calls under certain conditions. For
> >> example, the program might inject an int3/breakpoint into the guest
> >> kernel at the entry point to sys_open. When the breakpoint is hit, the
> >> program might set the guest instruction pointer to the address to which
> >> sys_open would have itself returned and set register RAX to some desired
> >> error-code return value.
> >>
> >> The problem I am encountering is that for some reason the process is
> >> triggering a "uprobe ... failed to handle uretprobe" message from the
> >> guest kernel.  I do not yet know enough about uprobes to understand what
> >> might be causing this. Is there something in procedures such as sys_open
> >> which must execute to prevent the error which causes the kernel to print
> >> this message?
>
> >> What vm  hypervisor do you use?
>
> We are using Xen + libvmi.
>
> I have continued to read the kernel sources, and as best as I can
> understand it the kernel installs uprobe instrumentation if it detects
> a software breakpoint. Our program does not reinject the software
> breakpoints it services back into the guest, so I am still trying to
> figure out why uprobes seems to get triggered.
>
> --
> Mike
>
> :wq
>

I am not really into xen, but afaik both guest and host xen kernel is
modified in order to facilitate hypercall

Thus, i suggest you study first how hypercall works

Regards,

Mulyadi


-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about uprobes

2017-04-06 Thread W. Michael Petullo
>> I am writing some software that monitors a guest VM using virtual-machine
>> introspection and "hijacks" system calls under certain conditions. For
>> example, the program might inject an int3/breakpoint into the guest
>> kernel at the entry point to sys_open. When the breakpoint is hit, the
>> program might set the guest instruction pointer to the address to which
>> sys_open would have itself returned and set register RAX to some desired
>> error-code return value.
>>
>> The problem I am encountering is that for some reason the process is
>> triggering a "uprobe ... failed to handle uretprobe" message from the
>> guest kernel.  I do not yet know enough about uprobes to understand what
>> might be causing this. Is there something in procedures such as sys_open
>> which must execute to prevent the error which causes the kernel to print
>> this message?

>> What vm  hypervisor do you use?

We are using Xen + libvmi.

I have continued to read the kernel sources, and as best as I can
understand it the kernel installs uprobe instrumentation if it detects
a software breakpoint. Our program does not reinject the software
breakpoints it services back into the guest, so I am still trying to
figure out why uprobes seems to get triggered.

-- 
Mike

:wq

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about uprobes

2017-04-06 Thread Mulyadi Santosa
On Thursday, April 6, 2017, W. Michael Petullo  wrote:

> I am writing some software that monitors a guest VM using virtual-machine
> introspection and "hijacks" system calls under certain conditions. For
> example, the program might inject an int3/breakpoint into the guest
> kernel at the entry point to sys_open. When the breakpoint is hit, the
> program might set the guest instruction pointer to the address to which
> sys_open would have itself returned and set register RAX to some desired
> error-code return value.
>
> The problem I am encountering is that for some reason the process is
> triggering a "uprobe ... failed to handle uretprobe" message from the
> guest kernel.  I do not yet know enough about uprobes to understand what
> might be causing this. Is there something in procedures such as sys_open
> which must execute to prevent the error which causes the kernel to print
> this message?
>
>
> What vm  hypervisor do you use?

Regards,

Mulyadi


-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Question about uprobes

2017-04-05 Thread W. Michael Petullo
I am writing some software that monitors a guest VM using virtual-machine
introspection and "hijacks" system calls under certain conditions. For
example, the program might inject an int3/breakpoint into the guest
kernel at the entry point to sys_open. When the breakpoint is hit, the
program might set the guest instruction pointer to the address to which
sys_open would have itself returned and set register RAX to some desired
error-code return value.

The problem I am encountering is that for some reason the process is
triggering a "uprobe ... failed to handle uretprobe" message from the
guest kernel.  I do not yet know enough about uprobes to understand what
might be causing this. Is there something in procedures such as sys_open
which must execute to prevent the error which causes the kernel to print
this message?

-- 
Mike

:wq

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: [mm subsystem] A question about function page_table_range_init_count()

2017-03-21 Thread Rik van Riel
On Wed, 2017-03-15 at 22:12 +0800, Hao Lee wrote:
> Hi, all
> 
> I encounter a problem when I read the source code of kernel 4.9.9.
> 
> In arch/x86/mm/init_32.c, at line 125 [1], there is a function named
> page_table_range_init_count(...). I have analyzed some codes and find
> its two parameters are PKMAP_BASE and FIXADDR_START.
> 
> Between Line 141 and Line 150, there is a for loop and I don't know
> what it means, especially Line 144-Line147.
> 
> Could someone can give me some tips. Thanks a lot!
> 
The code iterates over the virtual memory addresses
specified, and counts the number of pmds (second level
page tables) that will be needed to map that address
space.

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


[mm subsystem] A question about function page_table_range_init_count()

2017-03-15 Thread Hao Lee
Hi, all

I encounter a problem when I read the source code of kernel 4.9.9.

In arch/x86/mm/init_32.c, at line 125 [1], there is a function named
page_table_range_init_count(...). I have analyzed some codes and find its
two parameters are PKMAP_BASE and FIXADDR_START.

Between Line 141 and Line 150, there is a for loop and I don't know what it
means, especially Line 144-Line147.

Could someone can give me some tips. Thanks a lot!

Here is the code:
[1]  http://lxr.free-electrons.com/source/arch/x86/mm/init_32.c?v=4.9#L125

Hao Lee
Thanks.
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


question about nopage sample code

2017-02-22 Thread Ali Aminian
in ldd3 no page is implemented as the code posted below (page 428).
can someone explain why should we subtract vma->vm_start?

struct page *simple_vma_nopage(struct vm_area_struct *vma,
unsigned long address, int *type)
{
struct page *pageptr;
unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
unsigned long physaddr = address - vma->vm_start + offset;  // why
should we subtract vma->vm_start ?
unsigned long pageframe = physaddr >> PAGE_SHIFT;

if (!pfn_valid(pageframe))
return NOPAGE_SIGBUS;
pageptr = pfn_to_page(pageframe);
get_page(pageptr);
if (type)
*type = VM_FAULT_MINOR;
return pageptr;

}

thank you
Ali Aminian.

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: A question about priority search tree in kernel 2.6.24

2017-02-11 Thread Greg KH
On Sat, Feb 11, 2017 at 11:42:39PM +0800, Hao Lee wrote:
> Hi, all
> 
> Recently I'm reading "Professional Linux Kernel Architecture" while 
> referencing
> the source code of kernel 2.6.24 and I have a question about priority search
> tree.

2.6.24 is _very_ very very old, and obsolete and insecure.  Never use it
for anything.  Including trying to understand code, if you just want to
read stuff, please start with 4.9 at the oldest.

good luck!

greg k-h

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


A question about priority search tree in kernel 2.6.24

2017-02-11 Thread Hao Lee
Hi, all

Recently I'm reading "Professional Linux Kernel Architecture" while
referencing the source code of kernel 2.6.24 and I have a question about
priority search tree.

In prio_tree_init function (
http://lxr.free-electrons.com/source/lib/prio_tree.c?v=2.6.24#L71),  array
index_bits_to_maxindex is initialized to 1,3,7,15,31...2^(i+1)-1. I don't
know why it is initialized to these numbers and what is the relationship
between index_bits_to_maxindex and prio_tree_root->index_bits.

Could someone help me? Many Thanks!

Regards,
Hao Lee.
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Question about object-based reverse mapping

2017-01-01 Thread Hao Lee
Hi, all

I'm currently reading "Understanding the Linux Kernel (3rd)" and I
have a question about "object-based reverse mapping".

This is the Figure 17-1 on page 683 : http://imgur.com/R0OtIJh

As this figure shows, many vm_area_struct are in the anon_vma’s list
and they share some page frames.

The index field in page struct represents the offset of virtual
address within the virtual memory area. What I want to know is what
would happen when a page frame is shared by several vm_area_struct.

If two virtual memory areas share the same page frame, it seems that
page->index would be overridden because there are two vma and the
variable index would be assigned two times. How the linux kernel
prevent it happening.

Thanks.
Hao Lee

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: A question about kprobe/kretprobe and kmalloc/kzalloc

2016-12-21 Thread zerons
Sorry, I thought I solved the problem. Using `kzalloc` doesn't work
all the time, I need to add `sleep(1)` in the test case after each
syscall, like

perf_event_open(...);
sleep(1);
ioctl(...);
sleep(1);
ioctl(...);
sleep(1);
read(...);

I have tried these:
1) with `sleep(1)`, both kprobe and kretprobe are enabled
2) without `sleep(1)`, both kprobe and kretprobe are enabled
3) without `sleep(1)`, disable pre_handler of kprobe
4) same as 1), after the first run, comment the `sleep(1)` lines,
and run the test again

and 1) 3) 4) look fine,


On 12/21/2016 07:35 PM, zerons wrote:
> Hi everyone.
> 
> I wrote a kernel module to test something. The module
> uses kprobe and kretprobe, here is a bug I met today.
> 
> The pre_handler of kprobe, calls `do_something`. The probed
> instructions are in the middle of a function.
> The entry_handler of kretprobe, also calls `do_something`.
> `do_something` calls `kmalloc`+`memset`.
> 
> Back to userspace, when I have all the functions probed,
> then the test program cause a high CPU usage, and the
> keyboard doesn't work. The system does not panic when
> I set softlockup_panic=1.
> 
> If `do_something` is called by entry_handler of kretprobe,
> the module works fine.
> The bug happens when `do_something` called by the pre_handler
> of kprobe.
> 
> So I use "#if 0" to locate the bug. It turns out to
> be `kmalloc`+`memset`. When I change that to `kzalloc`,
> problem solved.
> 
> Then I get confused.
> `kzalloc` just calls `kmalloc` with a `__GFP_ZERO`.
> Why the bug only happens when pre_handler of kprobe gets called?
> 
> Is it necessary to post the source code here? Thanks.
> 

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


A question about kprobe/kretprobe and kmalloc/kzalloc

2016-12-21 Thread zerons
Hi everyone.

I wrote a kernel module to test something. The module
uses kprobe and kretprobe, here is a bug I met today.

The pre_handler of kprobe, calls `do_something`. The probed
instructions are in the middle of a function.
The entry_handler of kretprobe, also calls `do_something`.
`do_something` calls `kmalloc`+`memset`.

Back to userspace, when I have all the functions probed,
then the test program cause a high CPU usage, and the
keyboard doesn't work. The system does not panic when
I set softlockup_panic=1.

If `do_something` is called by entry_handler of kretprobe,
the module works fine.
The bug happens when `do_something` called by the pre_handler
of kprobe.

So I use "#if 0" to locate the bug. It turns out to
be `kmalloc`+`memset`. When I change that to `kzalloc`,
problem solved.

Then I get confused.
`kzalloc` just calls `kmalloc` with a `__GFP_ZERO`.
Why the bug only happens when pre_handler of kprobe gets called?

Is it necessary to post the source code here? Thanks.

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Fwd: Question about arp caches

2016-11-30 Thread Anupam Kapoor
On Wed, Nov 30, 2016 at 1:46 PM, Yisu Peng  wrote:

> So, how is the kernel check those staled arp entries? Or, what is the
> mechanism that the kernel uses to find the out of date entries?


​ok sure, well, each neighbor entry (struct neighbour) has a 'timer' (which
is created during neighbor creation i.e. during neigh_alloc(...)). this
timer gets 'serviced' by '​neigh_timer_handler(...)', which is the per
neighbor garbage collector handler.

when the state of the neighbor becomes NUD_FAILED, the neighbor is
collected via invokation of 'neigh_release(...)' as indicated earlier.

​--
kind regards
anupam​

In the beginning was the lambda, and the lambda was with Emacs, and Emacs
was the lambda.
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Fwd: Question about arp caches

2016-11-30 Thread Yisu Peng
Sorry, seems I didn't make question clear. Maybe let me ask another 
question to help with this. So, how is the kernel check those staled arp 
entries? Or, what is the mechanism that the kernel uses to find the out 
of date entries?


Thanks,

Yisu


On 11/30/2016 1:41 AM, Anupam Kapoor wrote:

FYI

-- Forwarded message -
From: Anupam Kapoor <anupam.kap...@gmail.com 
<mailto:anupam.kap...@gmail.com>>

Date: Tue, 29 Nov 2016 at 1:25 PM
Subject: Re: Question about arp caches
To: Shawn Peng <yisup...@gmail.com <mailto:yisup...@gmail.com>>


​On Tue, Nov 29, 2016 at 12:49 PM, Shawn Peng <yisup...@gmail.com 
<mailto:yisup...@gmail.com>>wrote:


I find a lot references of the function neigh_release(), can you
direct me to the one that releases a staled arp entry?


​neigh_destroy(...) is probably what you are looking for.

--
kind regards
anupam​



--
In the beginning was the lambda, and the lambda was with Emacs, and 
Emacs was the lambda.



___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Fwd: Question about arp caches

2016-11-29 Thread Anupam Kapoor
FYI

-- Forwarded message -
From: Anupam Kapoor <anupam.kap...@gmail.com>
Date: Tue, 29 Nov 2016 at 1:25 PM
Subject: Re: Question about arp caches
To: Shawn Peng <yisup...@gmail.com>


​On Tue, Nov 29, 2016 at 12:49 PM, Shawn Peng <yisup...@gmail.com> wrote:

I find a lot references of the function neigh_release(), can you direct me
to the one that releases a staled arp entry?


​neigh_destroy(...) is probably what you are looking for.

--
kind regards
anupam​



-- 
In the beginning was the lambda, and the lambda was with Emacs, and Emacs
was the lambda.
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Question about arp caches

2016-11-28 Thread Shawn Peng
I find a lot references of the function neigh_release(), can you direct 
me to the one that releases a staled arp entry? Thanks.



On 11/29/2016 12:50 AM, Anupam Kapoor wrote:


On Tue, Nov 29, 2016 at 10:40 AM, Shawn Peng > wrote:


I'm reading the code about arp protocol. It seems like the kernel uses
the neigh_table structure to keep track of caches, right?

​yes.​

There should
be some code that remove the stale entries in the cache, but I didn't
find the code that does this job. Does anyone have an idea?

​look at neigh_release(...) and neigh_destroy(...). basically, 
neigh_release(...) decrements the reference count of a neighbor, and 
neigh_destroy(...) frees it when this reference count reaches zero.​



​--
kind regards
anupam​


In the beginning was the lambda, and the lambda was with Emacs, and 
Emacs was the lambda.


___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


  1   2   3   >