From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752567AbcGGNkh (ORCPT ); Thu, 7 Jul 2016 09:40:37 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:20211 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752489AbcGGNk2 (ORCPT ); Thu, 7 Jul 2016 09:40:28 -0400 X-IBM-Helo: d06dlp03.portsmouth.uk.ibm.com X-IBM-MailFrom: ldufour@linux.vnet.ibm.com X-IBM-RcptTo: linux-kernel@vger.kernel.org Subject: Re: [v4] powerpc: Export thread_struct.used_vr/used_vsr to user space To: Benjamin Herrenschmidt , Michael Ellerman , Simon Guo References: <3rlZmP39HNz9sXR@ozlabs.org> <577E5534.70300@linux.vnet.ibm.com> <1467897678.27157.45.camel@kernel.crashing.org> Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Paul Mackerras , Kees Cook , Rashmica Gupta From: Laurent Dufour Date: Thu, 7 Jul 2016 15:40:20 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 In-Reply-To: <1467897678.27157.45.camel@kernel.crashing.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16070713-0040-0000-0000-000001FAB723 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16070713-0041-0000-0000-000020E9FFEC Message-Id: <577E5BC4.2020105@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-07-07_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1607070127 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/07/2016 15:21, Benjamin Herrenschmidt wrote: > On Thu, 2016-07-07 at 15:12 +0200, Laurent Dufour wrote: >> >> Basically, CRIU checkpoints the process register's state through the >> ptrace API, and it restores it through a signal frame at restart time. >> This is quite odd but that the way it works on all the CRIU's supported >> architectures. >> >> Obviously everything is done from/in user space, so the sigframe >> building too. >> Since we can't know from user space if the thread has used or not the >> Altivec/VSX registers, since we can't rely on the MSR bits, we always >> dump these registers. > > Right, however is that an issue ? These days with glibc using V{M,S}X > for things like memcpy I would think there is little to gain in trying > to avoid dumping them. > >>> Alternately, when restoring, can you setup the sigframe with the Altivec/VSX >>> fields populated, and the kernel will then load them, regardless of whether >>> they were actually used or not prior to the checkpoint? >> >> In the case of Altivec/VSX fields, we currently force the kernel to >> retrieve them from the signal frame by setting MSR_VEC/MSR_VSX so >> restore_sigcontext() will copy them to the kernel thread's state. > > Yup, that's the way to go. > >> However this doesn't touch to used_vsr and used_vr which may remain at 0. > > That would be a kernel bug. > >> Most of the time this is fine, but in the case a thread which has really >> used those registers is catching a signal just after the restore and >> before it has touched to these registers again (and so set used_vsr/vr), >> these registers will not be pushed in the newly built signal frame since >> setup_sigcontext() check for used_vsr/vr before pushing the registers on >> the stack. >> This may be an issue in the case the thread wants to changed those >> registers (don't ask me why :)) in the stacked signal frame from the >> signal handler since they will not be there... >> >> Being able to get and set the used_vr and used_vsr thread's variables, >> fixes this issue. > > I think the right fix is that if a restore_sigcontext() has the MSR bits set, > it should set the corresponding used_* flag. > > Or is there a reason why that won't work ? I got your point and I agree that most of the time now, the Altivec/VSX registers are used by libc. In that case is there still a need for the lazy Altivec/VSX registers dump in the signal frame ? I'm fine with your proposal, except that every restarted process will have the used_vr/used_vsx turned on after the restart since we can't check if these registers were used or not at checkpoint time. But that may be a minor point... Cheers, Laurent.