Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751036AbdGaQqG (ORCPT ); Mon, 31 Jul 2017 12:46:06 -0400 Received: from out03.mta.xmission.com ([166.70.13.233]:52908 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750854AbdGaQqD (ORCPT ); Mon, 31 Jul 2017 12:46:03 -0400 From: ebiederm@xmission.com (Eric W. Biederman) To: Al Viro Cc: Linus Torvalds , Linux Kernel Mailing List , Andy Lutomirski , Oleg Nesterov , Andrei Vagin , Thomas Gleixner , Greg KH , Andrey Vagin , Serge Hallyn , Pavel Emelyanov , Cyrill Gorcunov , Peter Zijlstra , Willy Tarreau , "linux-arch\@vger.kernel.org" , Linux API , Linux Containers , Michael Kerrisk References: <87o9shg7t7.fsf_-_@xmission.com> <20170718140651.15973-7-ebiederm@xmission.com> <878tjlbqpt.fsf@xmission.com> <8760ek5ics.fsf_-_@xmission.com> <20170725013756.GH2063@ZenIV.linux.org.uk> Date: Mon, 31 Jul 2017 11:37:41 -0500 In-Reply-To: <20170725013756.GH2063@ZenIV.linux.org.uk> (Al Viro's message of "Tue, 25 Jul 2017 02:37:57 +0100") Message-ID: <87mv7k1s16.fsf@xmission.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1dcDpI-00012l-F7;;;mid=<87mv7k1s16.fsf@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=67.3.213.87;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18WUQHiO2VD9xS8Jgce+roYpAAvkvmuAKg= X-SA-Exim-Connect-IP: 67.3.213.87 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.5 XMGappySubj_01 Very gappy subject * 0.0 TVD_RCVD_IP Message was received from an IP address * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa05 1397; Body=1 Fuz1=1 Fuz2=1] * 0.1 XMSolicitRefs_0 Weightloss drug * 1.0 T_XMDrugObfuBody_04 obfuscated drug references X-Spam-DCC: XMission; sa05 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: *;Al Viro X-Spam-Relay-Country: X-Spam-Timing: total 5685 ms - load_scoreonly_sql: 0.06 (0.0%), signal_user_changed: 2.9 (0.1%), b_tie_ro: 1.88 (0.0%), parse: 0.92 (0.0%), extract_message_metadata: 14 (0.2%), get_uri_detail_list: 1.93 (0.0%), tests_pri_-1000: 9 (0.2%), tests_pri_-950: 1.17 (0.0%), tests_pri_-900: 1.00 (0.0%), tests_pri_-400: 27 (0.5%), check_bayes: 26 (0.5%), b_tokenize: 9 (0.2%), b_tok_get_all: 9 (0.2%), b_comp_prob: 2.8 (0.0%), b_tok_touch_all: 2.9 (0.1%), b_finish: 0.59 (0.0%), tests_pri_0: 488 (8.6%), check_dkim_signature: 0.67 (0.0%), check_dkim_adsp: 5 (0.1%), tests_pri_500: 5139 (90.4%), poll_dns_idle: 5128 (90.2%), rewrite_mail: 0.00 (0.0%) Subject: Re: Simplfying copy_siginfo_to_user X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2709 Lines: 60 Al Viro writes: 2> On Mon, Jul 24, 2017 at 10:43:34AM -0700, Linus Torvalds wrote: >> On Sat, Jul 22, 2017 at 1:25 PM, Eric W. Biederman >> wrote: >> > I played with some clever changes such as limiting the copy to 48 bytes, >> > disabling the memset and the like but I could not get a strong enough >> > signal to say that any one change removed the extra or a clear part of >> > it 20ns. >> >> What CPU did you use? Because the SMAP bit in particular matters. >> >> The field-by-field copies are extremely slow on modern CPU's that >> implement SMAP, unless you also use the special "unsafe_put_user()" >> code (or the nasty old put_user_ex() code that some of the x86 signal >> code uses). >> >> So one of the advantages of just copy_to_user() ends up being visible >> only on Broadwell+ (or whatever the SMAP cutoff is). > > Guys, could you take a look at vfs.git#work.siginfo? I'd been pretty > much buried lately (and probably will for several more weeks - long-distance > moves *suck*), so that thing got stalled, but it might be worth a > look. There is some good stuff in there. If you don't mind I am going to cherry pick out your unification of struct siginfo and struct compat_siginfo. > The code generated in copy_siginfo_to_user() in it looks reasonably good, > we don't copy more than we need and all copying to userland is done > by copy_to_user() - one call per call of copy_siginfo_to_user(), so > SMAP crap is not an issue. There is actually a core problem with doing things that way. You rely on having the siginfo union member stored in the high bits of si_code. I have just fixed that in my tree and replaced using the high bits with calling the function siginfo_layout. It has been a significant problem storing the union member differently in the kernel than in userspace. It has allowed for some pretty horrendous gaffs in the archictecures changing the meaning of SI_USER when specific signals are delivered over. It has also meant that ptrace siginfo injection and tg_sigqueueinfo have been broken for some signals almost since the interface was added. Without any optimization and just changing the code to be copy_to_user I am seeing a maybe 2% slowdown. Given that no one has seemed to care overly for the performance of signal delivery I suspect an almost unmeasurable slowdown is a reasonable tradeoff for simpler code. > The next thing I hope to do is converting compat side of that thing to > the same; that got stalled. All of that said your precise copying code appears reasonable and quite nice so I may adopt it on the compat side. > Al "Buried in boxes" Viro... Eric "Also Buried in boxes" Biederman