Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp1213961ybd; Wed, 26 Jun 2019 13:21:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqxcDpIhSVxo1TyDeV1hK1I+BRnMRVtH1BbiojRSIjfmI9/bzZjQwboRvoKr8jkFhcMPoGy8 X-Received: by 2002:a17:902:ba8b:: with SMTP id k11mr7585482pls.107.1561580487544; Wed, 26 Jun 2019 13:21:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561580487; cv=none; d=google.com; s=arc-20160816; b=a8HjgpKe1si/eaVhBQuAZfjM7ZxIOuooAQ4aOTi9nEi8ybJ5QDu/Jb0PsD0JueCPQx jlJ3WpohKgtFt+adBpVGqsZLCUwlJxU7hHraCGxj03UXAT1p6zj8jcAzqoQWsAOQwdkr wpBYgyaaI74szX0V4+dNazlvarQ2un2yTzMZmB/JNTp1ThF5CTomeVuo598Muh4wwati wdD1c0ZKC0UGZzIl7Nn5KYnL5wk7QH4aMEPTrKcDe2sMN0Gw2VKk370DeLivnjoLfPY6 6UULyVRbL8OmxzjotG8EFVepWHEG1JaOaE7xNTYA5pYtdhoxd6AF44BAjw5lz6o50WzK DnYA== 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; bh=v0tyHUeIG8bex7yXr6c9aenMZW4wdC3eZUM4Yn7Jvnc=; b=UJE7gbZ6t53Mh4jDQvrxIH0AkRh3bVFiJ1F6vriOjdWc7boj/YYECFH765aR+vASe7 JqhJd9VvkNlQsEqv3h9lu7UbdyjTf385jO65ZQyWcqt7GA5y7gRPGQHgC6P+QBNh16/j Rgdh+9RC48h+o5sa7osMlRdz87OfUHHd6c+4ILlDzTjoyViy8+tAvMKrzyceVIp47qc7 60LYP0nB1q1WhEoviugIo70QCYCm1sZ2mcsGtWpGLnsI7rONpGoLf5QVd8Ah5nPgiAEV pfalvSYRo53NqWYBf9tLg9JjSR8SkmUXJPA1mp5e5foCDWPiNpZx7oIhYMDlBavXgW0i lkfA== 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 e12si40461pgs.34.2019.06.26.13.21.11; Wed, 26 Jun 2019 13:21:27 -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 S1726523AbfFZUU0 (ORCPT + 99 others); Wed, 26 Jun 2019 16:20:26 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:50285 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726357AbfFZUUZ (ORCPT ); Wed, 26 Jun 2019 16:20:25 -0400 Received: from p5b06daab.dip0.t-ipconnect.de ([91.6.218.171] helo=nanos) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1hgEOk-00064v-BB; Wed, 26 Jun 2019 22:20:06 +0200 Date: Wed, 26 Jun 2019 22:20:05 +0200 (CEST) From: Thomas Gleixner To: Fenghua Yu cc: Ingo Molnar , Borislav Petkov , H Peter Anvin , Peter Zijlstra , Andrew Morton , Dave Hansen , Paolo Bonzini , Radim Krcmar , Christopherson Sean J , Ashok Raj , Tony Luck , Dan Williams , Xiaoyao Li , Sai Praneeth Prakhya , Ravi V Shankar , linux-kernel , x86 , kvm@vger.kernel.org Subject: Re: [PATCH v9 09/17] x86/split_lock: Handle #AC exception for split lock In-Reply-To: <1560897679-228028-10-git-send-email-fenghua.yu@intel.com> Message-ID: References: <1560897679-228028-1-git-send-email-fenghua.yu@intel.com> <1560897679-228028-10-git-send-email-fenghua.yu@intel.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 18 Jun 2019, Fenghua Yu wrote: > + > +static atomic_t split_lock_debug; > + > +void split_lock_disable(void) > +{ > + /* Disable split lock detection on this CPU */ > + this_cpu_and(msr_test_ctl_cached, ~MSR_TEST_CTL_SPLIT_LOCK_DETECT); > + wrmsrl(MSR_TEST_CTL, this_cpu_read(msr_test_ctl_cached)); > + > + /* > + * Use the atomic variable split_lock_debug to ensure only the > + * first CPU hitting split lock issue prints one single complete > + * warning. This also solves the race if the split-lock #AC fault > + * is re-triggered by NMI of perf context interrupting one > + * split-lock warning execution while the original WARN_ONCE() is > + * executing. > + */ > + if (atomic_cmpxchg(&split_lock_debug, 0, 1) == 0) { > + WARN_ONCE(1, "split lock operation detected\n"); > + atomic_set(&split_lock_debug, 0); What's the purpose of this atomic_set()? > +dotraplinkage void do_alignment_check(struct pt_regs *regs, long error_code) > +{ > + unsigned int trapnr = X86_TRAP_AC; > + char str[] = "alignment check"; > + int signr = SIGBUS; > + > + RCU_LOCKDEP_WARN(!rcu_is_watching(), "entry code didn't wake RCU"); > + > + if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) == NOTIFY_STOP) > + return; > + > + cond_local_irq_enable(regs); > + if (!user_mode(regs) && static_cpu_has(X86_FEATURE_SPLIT_LOCK_DETECT)) { > + /* > + * Only split locks can generate #AC from kernel mode. > + * > + * The split-lock detection feature is a one-shot > + * debugging facility, so we disable it immediately and > + * print a warning. > + * > + * This also solves the instruction restart problem: we > + * return the faulting instruction right after this it we return the faulting instruction ... to the store so we get our deposit back :) the fault handler returns to the faulting instruction which will be then executed without .... Don't try to impersonate code, cpus or whatever. It doesn't make sense and confuses people. > + * will be executed without generating another #AC fault > + * and getting into an infinite loop, instead it will > + * continue without side effects to the interrupted > + * execution context. That last part 'instead .....' is redundant. It's entirely clear from the above that the faulting instruction is reexecuted .... Please write concise comments and do try to repeat the same information with a different painting. > + * > + * Split-lock detection will remain disabled after this, > + * until the next reboot. > + */ > + split_lock_disable(); > + > + return; > + } > + > + /* Handle #AC generated in any other cases. */ > + do_trap(X86_TRAP_AC, SIGBUS, "alignment check", regs, > + error_code, BUS_ADRALN, NULL); > +} > + > #ifdef CONFIG_VMAP_STACK > __visible void __noreturn handle_stack_overflow(const char *message, > struct pt_regs *regs, > -- > 2.19.1 > >