答复: About the system call named "sys_mount".

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



i have another question about the "SWI" instruction.
when a software interrupt exception occurs, the following actions are performed by the hardware(arm):

R14_svc	=	address of next instruction after the SWI instruction
SPSR_svc	=	CPSR		/* save processer status register */
CPSR[4:0]	=	0b10011		/* Enter Supervisor mode */
CPSR[5]	=	0			/* Execute in ARM state */
							/* CPSR[6] is unchanged */
CPSR[7]	=	1			/* Disable normal interrupts */
							/* CPSR[8] is unchanged */
CPSR[9]	=	CP15_reg1_EEbit		/* Endianness on exception entry */
PC	=	0xFFFF0008

after those actions are finished, ARM is enter the supervisor mode.
at this moment, the sp refered by instruction is the SP_svc register.
the question is what is the value of  SP_svc register currently.
in a other word, where is the stack of supervisor mode.

ENTRY(vector_swi)
	sub	sp, sp, #S_FRAME_SIZE		@ what's the value of SP_svc register at this time?????????
	stmia	sp, {r0 - r12}			@ Calling r0 - r12
	add	r8, sp, #S_PC
	stmdb	r8, {sp, lr}^			@ Calling sp, lr
	mrs	r8, spsr			@ called from non-FIQ mode, so ok.
	str	lr, [sp, #S_PC]			@ Save calling PC
	str	r8, [sp, #S_PSR]		@ Save CPSR
	str	r0, [sp, #S_OLD_R0]		@ Save OLD_R0
	zero_fp
...


-----邮件原件-----
发件人: kernelnewbies-bounce@xxxxxxxxxxxx [mailto:kernelnewbies-bounce@xxxxxxxxxxxx] 代表 付新荣
发送时间: 2009年10月21日 12:19
收件人: Joel Fernandes; Rajat Jain
抄送: kernelnewbies@xxxxxxxxxxxx
主题: 答复: About the system call named "sys_mount".

 
hi all:
the "__get_user_asm_byte" macro  is called by "sys_mount" finally  to copy the paraments from user space.

copy_mount_options->
exact_copy_from_user->
call "__get_user" circularly  for "length" times


the "__get_user_asm_byte" macro is defined as follows:
#define __get_user_asm_byte(x,addr,err)				\
	__asm__ __volatile__(					\
	"1:	ldrbt	%1,[%2],#0\n"				\
	"2:\n"							\
	"	.section .fixup,\"ax\"\n"			\
	"	.align	2\n"					\
	"3:	mov	%0, %3\n"				\
	"	mov	%1, #0\n"				\
	"	b	2b\n"					\
	"	.previous\n"					\
	"	.section __ex_table,\"a\"\n"			\
	"	.align	3\n"					\
	"	.long	1b, 3b\n"				\
	"	.previous"					\
	: "+r" (err), "=&r" (x)					\
	: "r" (addr), "i" (-EFAULT)				\
	: "cc")

#define __get_user(x,ptr)						\
({									\
	long __gu_err = 0;						\
	__get_user_err((x),(ptr),__gu_err);				\
	__gu_err;							\
})

#define __get_user_err(x,ptr,err)					\
do {									\
	unsigned long __gu_addr = (unsigned long)(ptr);			\
	unsigned long __gu_val;						\
	__chk_user_ptr(ptr);						\
	switch (sizeof(*(ptr))) {					\
	case 1:	__get_user_asm_byte(__gu_val,__gu_addr,err);	break;	\
	case 2:	__get_user_asm_half(__gu_val,__gu_addr,err);	break;	\
	case 4:	__get_user_asm_word(__gu_val,__gu_addr,err);	break;	\
	default: (__gu_val) = __get_user_bad();				\
	}								\
	(x) = (__typeof__(*(ptr)))__gu_val;				\
} while (0)



i found your explanation is reasonable, thanks now, i want to find a way to prevent the swap of pages occupied by the "mount" task.

thanks!


the "sys_mount" cpoy the paraments from user space finally
-----邮件原件-----
发件人: Joel Fernandes [mailto:agnel.joel@xxxxxxxxx]
发送时间: 2009年10月21日 10:09
收件人: Rajat Jain
抄送: 付新荣; kernelnewbies@xxxxxxxxxxxx
主题: Re: About the system call named "sys_mount".

Hi Rajat,

So kernel virtual memory is always directly and permanently mapped and never has to fault? Is this for performance or is it because the kernel can't handle its own faults (kernel doesn't want to take responsibility for its own faults!).

Also I would be grateful if you could describe in a sentence or two, how this copy from user to kernel space happens? my guess - it looks up the process's mm_struct and gets the physical location of its pages whether on disk or in physically memory, and then makes a copy of it to kernel space? wouldn't this be slow if the user memory is still on disk?

Also at the time copy_from_user is called, it seems the memory would be uptodate anyway and going to disk wouldn't be required. The user obviously stored something in the memory and the processor would have segfaulted already?

thanks,
-Joel

On Tue, Oct 20, 2009 at 4:08 AM, Rajat Jain <Rajat.Jain@xxxxxxxxxxxx> wrote:
>
> Hi,
>
>> Thank you for your reply.
>> it's interesting, my modified kernel image is run ok on my 
>> hardware(arm926ejs). i test mounting ramfs and nfs, they are all ok.
>> are they occasional?
>>
>> sorry, i don't comprehend  your explanation about it In my opinion, 
>> if it's possible that the content of parameters isn't in memory at 
>> the time of the call, the "sys_mount" can't get them also.
>>
>> could u explain it in detail? Thanks
>
> OK. So here is it. Not all memory used by user space actually needs to 
> be in RAM all the time. It may be swapped out to disk since the actual 
> memory in use in a system is much more than its RAM size. When a piece 
> of memory that is currently swapped out on disk needs to be accessed, 
> it needs to be brought back into RAM memory - this is done by the page 
> fault handler. But consider that the Disk IO is a very slow process, 
> and thus it is relatively a very huge time for the kernel. For this 
> reason, any memory that is accessed by the kernel needs to be locked 
> down in RAM so that it cannot be swapped out.
>
> Secondly, the 4GB virtual address space is split up into user space 
> and kernel space code (3G/1G split generally). User space cannot 
> access kernel space virtual addresses and vice versa. Thus the user 
> space pointer cannot be dereferenced in the kernel.
>
> Thus, any user data that needs to be accessed firstly needs to be 
> copied into kernel address space. This done generally by
> copy_from_user() function or its varians that sys_mount() uses:
>
> exact_copy_from_user((void *)page, data, size); 
> strncpy_from_user(page, filename, len);
>
> Now, how you code works comes as a surprize to me though...
>
> Thanks,
>
> Rajat
>
> --
> To unsubscribe from this list: send an email with "unsubscribe 
> kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at 
> http://kernelnewbies.org/FAQ
>
>
NrybXǧuޙ+a{.n+zޖwn'jbye{zv^mzޖwn'?
��.n��������+%����w�j)p���{.n����z�ޖw�n'���q���b�������v��m�����Y�����


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux