Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp918528imm; Fri, 22 Jun 2018 07:30:04 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLTOBRMO+1tq3FbIs3a4lY71pn/YQwPleh4pntUYfQcJA3vH5kio+Lpc93K2PG6y33za/wK X-Received: by 2002:a62:4556:: with SMTP id s83-v6mr2025342pfa.73.1529677804493; Fri, 22 Jun 2018 07:30:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529677804; cv=none; d=google.com; s=arc-20160816; b=kDgSy2FdKjymBX7QyP85ol3pGbuLW2a+k/dRXpWTwwBC1BAANyet3E+wtFkYutdK47 i5b9cDIkQBZsTKvaUlhdmkN+pGQPKEt9UyK7v1mmaOhlEi/S54b5Y8IYYyzsQnupRiD4 L0AI/hxrrSovGxcaEBV4H2e4Hr/upg6m/uy1QgTro7du3ZISodBpWo/pVQTulXrXIbPt D/XaCa4agJFMsiGKvCjBxKHoGlLwO9GmRmPhvFhRoy4ebl3Pq/ZkcTVt7HSNrosYyjyt pbj1tYBHRxG0STF3FhOPIeWloaHpDjuFiZ+AV7SWLjqUa/cLpW4TYVoQ1uz9S3jouIIu gsqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=xWjH/OS3DjWk+jzvZ/BKNlfPTaMdLb2jtCCf20rTVyE=; b=it49+Uw/PXuwx5+DyIJFewRB10uuiYwgSvHeQVWwG9dcRjFLb8Bt2m02qtgzIMgy9Y a32nXDui6AbSV+Y4gyNoAYN2O9Ek/fk8L+cfgZEXPlLIZ8lQ3dNf/XmZere8/Qhqb2kw j3suVj3CcZP0XQmAOeAkWj9Nd541aJtVqCMbA+flRGB+PEWF3LbWWizZ7DLoAFYZ9bHc adhDjSew6h1sDLT3Iw+kfsWd57YAdjwSW2JqrI4tExlG2QWIaN3azDDA9Hm4ukE5BULO JWrG2Yk7WCp1UtRx3tuNI9150HhBeks7uqFk8cS3FoHVCC+jGK+y5Rk9QYZ5UrtJeuYD 2b9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h77-v6si8213539pfa.238.2018.06.22.07.29.40; Fri, 22 Jun 2018 07:30:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933291AbeFVO2u (ORCPT + 99 others); Fri, 22 Jun 2018 10:28:50 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:41809 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751284AbeFVO2t (ORCPT ); Fri, 22 Jun 2018 10:28:49 -0400 Received: from hsi-kbw-5-158-153-52.hsi19.kabel-badenwuerttemberg.de ([5.158.153.52] helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fWN3B-0006WO-C4; Fri, 22 Jun 2018 16:28:33 +0200 Date: Fri, 22 Jun 2018 16:28:32 +0200 (CEST) From: Thomas Gleixner To: "Chang S. Bae" cc: Andy Lutomirski , "H . Peter Anvin" , Ingo Molnar , Andi Kleen , Dave Hansen , Markus T Metzger , Ravi Shankar , LKML Subject: Re: [PATCH v4 1/7] x86/fsgsbase/64: Introduce FS/GS base helper functions In-Reply-To: <1529536506-26237-2-git-send-email-chang.seok.bae@intel.com> Message-ID: References: <1529536506-26237-1-git-send-email-chang.seok.bae@intel.com> <1529536506-26237-2-git-send-email-chang.seok.bae@intel.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 20 Jun 2018, Chang S. Bae wrote: > +void write_fsbase(unsigned long fsbase) > +{ > + /* set the selector to 0 to not confuse __switch_to */ 'to not confuse __switch_to' is not that helpful of a comment as it requires to stare into __switch_to to figure out what might get confused there. Please write it out why this needs to be done in technical terms. > + loadseg(FS, 0); > + wrmsrl(MSR_FS_BASE, fsbase); > +} > + > +void write_inactive_gsbase(unsigned long gsbase) > +{ > + /* set the selector to 0 to not confuse __switch_to */ Ditto > + loadseg(GS, 0); > + wrmsrl(MSR_KERNEL_GS_BASE, gsbase); > +} > + > +unsigned long read_task_fsbase(struct task_struct *task) > +{ > + unsigned long fsbase; > + > + if (task == current) { > + fsbase = read_fsbase(); > + } else { > + /* > + * XXX: This will not behave as expected if called > + * if fsindex != 0. This preserves an existing bug > + * that will be fixed. I'm late to this party, but let me ask the obvious question: Why is the existing bug not fixed as the first patch in the series? We do not preserve bugs when adding new stuff as that makes it a pain to backport the fix. > +int write_task_fsbase(struct task_struct *task, unsigned long fsbase) > +{ > + int cpu; > + > + /* > + * Not strictly needed for fs, but do it for symmetry > + * with gs > + */ > + if (unlikely(fsbase >= TASK_SIZE_MAX)) > + return -EPERM; > + > + cpu = get_cpu(); What's the point of using get_cpu()? There is nothing at all which needs 'cpu' here. The only point is to prevent preemption, then please use preempt_disable() and not some random function which happens to disable preemption underneath. > + task->thread.fsbase = fsbase; > + if (task == current) > + write_fsbase(fsbase); > + task->thread.fsindex = 0; > + put_cpu(); > + > + return 0; > +} > + > +int write_task_gsbase(struct task_struct *task, unsigned long gsbase) > +{ > + int cpu; > + > + if (unlikely(gsbase >= TASK_SIZE_MAX)) > + return -EPERM; > + > + cpu = get_cpu(); Ditto > + task->thread.gsbase = gsbase; > + if (task == current) > + write_inactive_gsbase(gsbase); > + task->thread.gsindex = 0; > + put_cpu(); > + > + return 0; > +} > + > int copy_thread_tls(unsigned long clone_flags, unsigned long sp, > unsigned long arg, struct task_struct *p, unsigned long tls) > { > @@ -618,54 +707,27 @@ static long prctl_map_vdso(const struct vdso_image *image, unsigned long addr) > long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2) > { > int ret = 0; > - int doit = task == current; > - int cpu; > > switch (option) { > - case ARCH_SET_GS: > - if (arg2 >= TASK_SIZE_MAX) > - return -EPERM; > - cpu = get_cpu(); Ah. You copied it from here where it makes no sense either. Copy and paste is useful, but you really want to think about it. > diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c > index e2ee403..c53c2bcf6 100644 > --- a/arch/x86/kernel/ptrace.c > +++ b/arch/x86/kernel/ptrace.c .... > if (child->thread.fsbase != value) > - return do_arch_prctl_64(child, ARCH_SET_FS, value); > + return write_task_fsbase(child, value); This patch wants to be split into: 1) Adding the new functions 2) Convert vdso 3) Convert ptrace _AFTER_ fixing the existing bug. Thanks, tglx