Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1508313yba; Thu, 4 Apr 2019 12:12:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqyS+HpgMXNxCTHLY4I/RWScaUWgfL7W2lux7++ahT7fvod/t1CrYPe8UhZ44JomW1GoLll2 X-Received: by 2002:a62:6842:: with SMTP id d63mr7893285pfc.9.1554405156979; Thu, 04 Apr 2019 12:12:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554405156; cv=none; d=google.com; s=arc-20160816; b=j7PGOO11DODSGgozzWt3mSL2rrVLnx87WEQgMN3+RgVEH/BVTx5xOAoolcZS4qwpL5 GN0HixNgHJWSl24/WClHi4oRmGnrFAKcyXEUfPTokrJdzI5JPwyrEAT6d3tGKiC1P1ta QRfQIP9/JfxmKm1arOC6CGesthBQyAr1rbdNquDULTO+53qCBJK1d3yjQ4897gHaQ8MP KpTW834SVovwSVwQ5jIWzpA+VToDIrhJZaGd/FzOFY506Hx+98JHdJZxy9I6fO6Adpwp wERGVrgLxKZcLKWMZJkt7SWinEFmTZN1ZIOHKmQBVadDxOvmccWoWipdpIoMIl3hvp4B cOYw== 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=k2arE6k6s4eKRHFstD8cgR9kctWrofvWir5qfqVsTSg=; b=KJuPZasvTBF3JySBSHyIimESm7myE8n6Q+f3zVMzikxyPaiPqM/jw6xw1W44b4D2sH vbeB3ph/rT7ahN3sXd63VhlQd9zDLc1oQaC4nKf5rIZ9qKxWrmm19/eaT3ng8qkTGRVq iq6jUFHQ4SKvHvkYi588QXzSrdBFaGn84dFjS9fHDCUVhJYjcEjX7g93umT3evUuhaFB BMvLh1YEg3HousoG189k4w4lg4CQEA9yfgkkpDBIH2lStkI7Dw4BrVWrlIaspOBazxty nWtHPzKximqOHwtUWZaD/FeQc6C4ldmKkmhIBve80P1Xpp8nxzJQvvSpuW86VQeZUq2C E5uQ== 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 i7si15817226pgl.261.2019.04.04.12.12.21; Thu, 04 Apr 2019 12:12:36 -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 S1730191AbfDDTLh (ORCPT + 99 others); Thu, 4 Apr 2019 15:11:37 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:46283 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729848AbfDDTLg (ORCPT ); Thu, 4 Apr 2019 15:11:36 -0400 Received: from p5492e2fc.dip0.t-ipconnect.de ([84.146.226.252] helo=nanos) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1hC7lf-00006C-IQ; Thu, 04 Apr 2019 21:11:19 +0200 Date: Thu, 4 Apr 2019 21:11:18 +0200 (CEST) From: Thomas Gleixner To: Fenghua Yu cc: Ingo Molnar , Borislav Petkov , H Peter Anvin , Dave Hansen , Paolo Bonzini , Ashok Raj , Peter Zijlstra , Kalle Valo , Xiaoyao Li , Michael Chan , Ravi V Shankar , linux-kernel , x86 , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH v6 14/20] x86/split_lock: Add a sysfs interface to enable/disable split lock detection during run time In-Reply-To: <1554326526-172295-15-git-send-email-fenghua.yu@intel.com> Message-ID: References: <1554326526-172295-1-git-send-email-fenghua.yu@intel.com> <1554326526-172295-15-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 Wed, 3 Apr 2019, Fenghua Yu wrote: > + > +static ssize_t > +split_lock_detect_show(struct device *dev, struct device_attribute *attr, > + char *buf) > +{ > + return sprintf(buf, "%u\n", READ_ONCE(split_lock_detect_val)); Please stop sprinkling READ_ONCE all over the place or can you explain why this is in any way useful? You know what READ/WRITE_ONCE() is for, right? > +} > + > +static ssize_t > +split_lock_detect_store(struct device *dev, struct device_attribute *attr, > + const char *buf, size_t count) > +{ > + u32 val, l, h; > + int cpu, ret; > + > + ret = kstrtou32(buf, 10, &val); > + if (ret) > + return ret; > + > + if (val != DISABLE_SPLIT_LOCK_DETECT && val != ENABLE_SPLIT_LOCK_DETECT) > + return -EINVAL; As this is really a simple boolean you can just use strtobool() and be done with it. > + > + /* > + * Since split lock could be disabled by kernel #AC handler or user > + * may directly change bit 29 in MSR_TEST_CTL, split lock setting on The user can change bit 29 in that MSR? If you talk about /dev/msr then I really do not care. That interface should die. Aside of that your usage of the term 'user' is really misleading and inconsistent all over the place. > + * each CPU may be different from global setting split_lock_detect_val > + * by now. Update MSR on each CPU, so all of CPUs will have same split > + * lock setting. That helps in which way? If #AC was detected in the kernel then 1) It's likely to be switched off again right away 2) The WARN_ONCE() already triggered and will not warn again. So what's the point here, really? If the kernel triggers #AC, game over. Fix the kernel first. If your kernel is clean, then why do you need that knob at all? > + */ > + mutex_lock(&split_lock_detect_mutex); > + > + WRITE_ONCE(split_lock_detect_val, val); Oh well. > + /* > + * Get MSR_TEST_CTL on this CPU, assuming all CPUs have same value > + * in the MSR except split lock detection bit (bit 29). And some day in the future this breaks because MRS_TEST_CTL has some other shiny bits. > + */ > + rdmsr(MSR_TEST_CTL, l, h); > + l = new_sp_test_ctl_val(l); > + /* Update the split lock detection setting on all online CPUs. */ > + for_each_online_cpu(cpu) And what exactly protects the online cpu mask? > + wrmsr_on_cpu(cpu, MSR_TEST_CTL, l, h); Oh well. Instead of just having a function which does: fun() if (ac_...enabled) msr_set_bit() else msr_clear_bit() and invoke that from cpu init code and from here via on_each_cpu() or such? > + mutex_unlock(&split_lock_detect_mutex); > + > + return count; > +} > + > +static DEVICE_ATTR_RW(split_lock_detect); > + > +static int __init split_lock_init(void) > +{ > + int ret; > + > + if (!boot_cpu_has(X86_FEATURE_SPLIT_LOCK_DETECT)) > + return -ENODEV; > + > + ret = device_create_file(cpu_subsys.dev_root, > + &dev_attr_split_lock_detect); > + if (ret) > + return ret; > + > + return 0; What's wrong with: return device_create_file(); ??? Not hard enough to read, right? > +} > + Pointless empty line. > +subsys_initcall(split_lock_init); Thanks, tglx