forked from mirrors/linux
		
	scm: optimize put_cmsg()
Calling two copy_to_user() for very small regions has very high overhead. Switch to inlined unsafe_put_user() to save one stac/clac sequence, and avoid copy_to_user(). Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Soheil Hassas Yeganeh <soheil@google.com> Acked-by: Soheil Hassas Yeganeh <soheil@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
		
							parent
							
								
									b6faf160d0
								
							
						
					
					
						commit
						38ebcf5096
					
				
					 1 changed files with 14 additions and 7 deletions
				
			
		|  | @ -228,14 +228,16 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data) | ||||||
| 
 | 
 | ||||||
| 	if (msg->msg_control_is_user) { | 	if (msg->msg_control_is_user) { | ||||||
| 		struct cmsghdr __user *cm = msg->msg_control_user; | 		struct cmsghdr __user *cm = msg->msg_control_user; | ||||||
| 		struct cmsghdr cmhdr; |  | ||||||
| 
 | 
 | ||||||
| 		cmhdr.cmsg_level = level; | 		if (!user_write_access_begin(cm, cmlen)) | ||||||
| 		cmhdr.cmsg_type = type; | 			goto efault; | ||||||
| 		cmhdr.cmsg_len = cmlen; | 
 | ||||||
| 		if (copy_to_user(cm, &cmhdr, sizeof cmhdr) || | 		unsafe_put_user(len, &cm->cmsg_len, efault_end); | ||||||
| 		    copy_to_user(CMSG_USER_DATA(cm), data, cmlen - sizeof(*cm))) | 		unsafe_put_user(level, &cm->cmsg_level, efault_end); | ||||||
| 			return -EFAULT; | 		unsafe_put_user(type, &cm->cmsg_type, efault_end); | ||||||
|  | 		unsafe_copy_to_user(CMSG_USER_DATA(cm), data, | ||||||
|  | 				    cmlen - sizeof(*cm), efault_end); | ||||||
|  | 		user_write_access_end(); | ||||||
| 	} else { | 	} else { | ||||||
| 		struct cmsghdr *cm = msg->msg_control; | 		struct cmsghdr *cm = msg->msg_control; | ||||||
| 
 | 
 | ||||||
|  | @ -249,6 +251,11 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data) | ||||||
| 	msg->msg_control += cmlen; | 	msg->msg_control += cmlen; | ||||||
| 	msg->msg_controllen -= cmlen; | 	msg->msg_controllen -= cmlen; | ||||||
| 	return 0; | 	return 0; | ||||||
|  | 
 | ||||||
|  | efault_end: | ||||||
|  | 	user_write_access_end(); | ||||||
|  | efault: | ||||||
|  | 	return -EFAULT; | ||||||
| } | } | ||||||
| EXPORT_SYMBOL(put_cmsg); | EXPORT_SYMBOL(put_cmsg); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Eric Dumazet
						Eric Dumazet