Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1563949ybg; Thu, 11 Jun 2020 13:10:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4Wq5CzAXvjqdldKV7HQ2YzyiEfGvtwRDwDmPkNCCz4vWU/AjS/bwtJV9coxIruJMnBZ7N X-Received: by 2002:a05:6402:1814:: with SMTP id g20mr3886619edy.197.1591906226429; Thu, 11 Jun 2020 13:10:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591906226; cv=none; d=google.com; s=arc-20160816; b=q1v8JMRqMNAW2v8zuXXR0Qq7/ZqSqKHz9vRtCNSI4+2Ti5RhhwoXF0XrJdF/C7f+p1 Zf7pWQo/4zmiAa3ZalzIT5Khyr04v+rvnvfbkSGWRH3JGoJecTXu35W0+UUtVPfTXNBh P5GAXbUaeOllfoLcEI2OA2LFWPWj+3zlR86U3Ew+PxgEHuZakzHsOBpKt3wuFjYaXU0X FuvSJQmUd797e/KMvhcdARX2aI2gfAoSfNO0O6UldA2zlXqJo4PZ+xRNemcUqJV1FbOi CRJgjJkCksayAcU6e7Q+TUd8QJ8DBBb7KXPGw0eYIoQD6Km0hvbImPi6J3DADLkCRSAT WR1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=qARvwf693xBRNl1VlWzwavSivQ9sYO1lqX5q74rCOLw=; b=0itugc3T2bm/xSl7fD3CLSIvFo3Lvik60qMzwKc4+nACsJs/XftpasD+qwZu1MGvf6 Sg0aODLt2Q5TJjVOEiENoeHNB9cCzOnnlaJVZss+VQLjLhJdlKJXb2Q1/dG0Q18bsokO TP84j1tp4Pznz40309+GjMx2KqDJJXJnebio6KWqQGKZ62FV15Jw2QP1boL3PoN11PZf FomIwr0wlRer02qVfw+EsBMh6gAFQvAgIdrfsC735b0DZg032Kb5aVzYrhe0JYYpwxjc 5eQ3yctdj1CWOuCVC+RqZo2nahzyIS0eSoHvC/VOO9dtLdJ7SN2whNR2ZKb8RvRPCB5r M39w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NifLkEO9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id md20si2615883ejb.203.2020.06.11.13.10.03; Thu, 11 Jun 2020 13:10:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NifLkEO9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726940AbgFKRha (ORCPT + 99 others); Thu, 11 Jun 2020 13:37:30 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:20565 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726813AbgFKRha (ORCPT ); Thu, 11 Jun 2020 13:37:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591897048; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qARvwf693xBRNl1VlWzwavSivQ9sYO1lqX5q74rCOLw=; b=NifLkEO9qjDxRyD4Gl5k9DprKflITZJkndiVqP56eH1EFeejKfM0/8xtjuer7JkpuR/6CJ PBSpcAz5hzDUgQczWEdDGqyZJZJ62XlFscvjhTxAvouGMtHZi6GDL+ZceL2pFAGF32g/Oo tnECK/cjl2IqNBxCdY7b6S/SrT8WFwE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-145-oC86CCcHPn6iGBvzdtU87g-1; Thu, 11 Jun 2020 13:37:24 -0400 X-MC-Unique: oC86CCcHPn6iGBvzdtU87g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4FBB81B18BC5; Thu, 11 Jun 2020 17:37:21 +0000 (UTC) Received: from prarit.bos.redhat.com (prarit-guest.7a2m.lab.eng.bos.redhat.com [10.16.222.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D5051A8EA; Thu, 11 Jun 2020 17:37:20 +0000 (UTC) Subject: Re: [PATCH v2] x86/split_lock: Sanitize userspace and guest error output To: Sean Christopherson Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Tony Luck , "Peter Zijlstra (Intel)" , Rahul Tanwar , Xiaoyao Li , Ricardo Neri , Dave Hansen References: <20200608122114.13043-1-prarit@redhat.com> <20200608171552.GB8223@linux.intel.com> From: Prarit Bhargava Message-ID: Date: Thu, 11 Jun 2020 13:37:19 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20200608171552.GB8223@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/8/20 1:15 PM, Sean Christopherson wrote: > On Mon, Jun 08, 2020 at 08:21:14AM -0400, Prarit Bhargava wrote: >> diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c >> index 166d7c355896..e02ec81fe1eb 100644 >> --- a/arch/x86/kernel/cpu/intel.c >> +++ b/arch/x86/kernel/cpu/intel.c >> @@ -1074,10 +1074,17 @@ static void split_lock_init(void) >> split_lock_verify_msr(sld_state != sld_off); >> } >> >> -static void split_lock_warn(unsigned long ip) >> +static bool split_lock_warn(unsigned long ip, int fatal_no_warn) >> { >> - pr_warn_ratelimited("#AC: %s/%d took a split_lock trap at address: 0x%lx\n", >> - current->comm, current->pid, ip); >> + if (fatal_no_warn) >> + return false; > > This misses the point Xiaoyao was making. If EFLAGS.AC=1 then the #AC is a > legacy alignment check fault and should not be treated as a split-lock #AC. > The basic premise of the patch makes sense, but the end result is confusing > because incorporating "fatal" and the EFLAGS.AC state into split_lock_warn() > bastardizes both the "split_lock" and "warn" aspects of the function. > > E.g. something like this yields the same net effect, it's just organized > differently. If so desired, the "bogus" message could be dropped via > Xiaoyao's prep patch[*] so that this change would only affect the sld_fatal > messages. > > [*] https://lkml.kernel.org/r/20200509110542.8159-3-xiaoyao.li@intel.com > > Sean, I will just take your patch to make things easy. I will add you as a Signed-off-by. /me is testing the patch right now P. > diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c > index 23fd5f319908..1aad0b8e394c 100644 > --- a/arch/x86/kernel/cpu/intel.c > +++ b/arch/x86/kernel/cpu/intel.c > @@ -1071,11 +1071,14 @@ static void split_lock_init(void) > split_lock_verify_msr(sld_state != sld_off); > } > > -static void split_lock_warn(unsigned long ip) > +static bool handle_split_lock(unsigned long ip) > { > pr_warn_ratelimited("#AC: %s/%d took a split_lock trap at address: 0x%lx\n", > current->comm, current->pid, ip); > > + if (sld_state != sld_warn) > + return false; > + > /* > * Disable the split lock detection for this task so it can make > * progress and set TIF_SLD so the detection is re-enabled via > @@ -1083,18 +1086,13 @@ static void split_lock_warn(unsigned long ip) > */ > sld_update_msr(false); > set_tsk_thread_flag(current, TIF_SLD); > + return true; > } > > bool handle_guest_split_lock(unsigned long ip) > { > - if (sld_state == sld_warn) { > - split_lock_warn(ip); > + if (handle_split_lock(ip)) > return true; > - } > - > - pr_warn_once("#AC: %s/%d %s split_lock trap at address: 0x%lx\n", > - current->comm, current->pid, > - sld_state == sld_fatal ? "fatal" : "bogus", ip); > > current->thread.error_code = 0; > current->thread.trap_nr = X86_TRAP_AC; > @@ -1105,10 +1103,10 @@ EXPORT_SYMBOL_GPL(handle_guest_split_lock); > > bool handle_user_split_lock(struct pt_regs *regs, long error_code) > { > - if ((regs->flags & X86_EFLAGS_AC) || sld_state == sld_fatal) > + if (regs->flags & X86_EFLAGS_AC) > return false; > - split_lock_warn(regs->ip); > - return true; > + > + return handle_split_lock(regs->ip); > } > > /* > > >> + >> + pr_warn_ratelimited("#AC: %s/%d %ssplit_lock trap at address: 0x%lx\n", >> + current->comm, current->pid, >> + sld_state == sld_fatal ? "fatal " : "", ip); >> + >> + if (sld_state == sld_fatal) >> + return false; >> >> /* >> * Disable the split lock detection for this task so it can make >> @@ -1086,18 +1093,13 @@ static void split_lock_warn(unsigned long ip) >> */ >> sld_update_msr(false); >> set_tsk_thread_flag(current, TIF_SLD); >> + return true; >> } >> >> bool handle_guest_split_lock(unsigned long ip) >> { >> - if (sld_state == sld_warn) { >> - split_lock_warn(ip); >> + if (split_lock_warn(ip, 0)) >> return true; >> - } >> - >> - pr_warn_once("#AC: %s/%d %s split_lock trap at address: 0x%lx\n", >> - current->comm, current->pid, >> - sld_state == sld_fatal ? "fatal" : "bogus", ip); >> >> current->thread.error_code = 0; >> current->thread.trap_nr = X86_TRAP_AC; >> @@ -1108,10 +1110,7 @@ EXPORT_SYMBOL_GPL(handle_guest_split_lock); >> >> bool handle_user_split_lock(struct pt_regs *regs, long error_code) >> { >> - if ((regs->flags & X86_EFLAGS_AC) || sld_state == sld_fatal) >> - return false; >> - split_lock_warn(regs->ip); >> - return true; >> + return split_lock_warn(regs->ip, regs->flags & X86_EFLAGS_AC); >> } >> >> /* >> -- >> 2.21.3 >> >