Received: by 10.213.65.68 with SMTP id h4csp456535imn; Sat, 17 Mar 2018 10:12:02 -0700 (PDT) X-Google-Smtp-Source: AG47ELuPjOA3DlYUHMtKehquuZ1veEjz0UyeTS1r09P70XaFsPRX7kLOSEqlWVVOCKP6zSBwLmyW X-Received: by 10.99.185.71 with SMTP id v7mr4858417pgo.12.1521306722456; Sat, 17 Mar 2018 10:12:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521306722; cv=none; d=google.com; s=arc-20160816; b=c3IuXag23WSurLWhN5lLd7yaGz59UfQ9DHWoOZoO4iJx2jUOSM28IG8/s4ZsSkxfaR BMjbfQ40JQaPLXtMb7uKe1/pLOU2fRN1gi/4sWAjlZF8gvM0PsvTjUq41iA8c8kext7l 6Uj1kIkuMQ+JQ4M2Ncu3ck0y16HFiBCJh7K/OxARrco+/tPqaGx302X3WvMQirmG/czr zpIrzj0dhXbLY1wjpRczWjy7OywZSBEAc7PaFXzaYQrY0F98tXl784rt1sVrq37bKv/+ N3+SohFwdpy6FLSeyDHY9Q7bhMHlmE0N8omINIVwUfla6Stzi+ufdruOhk+q+CPnze9v MJdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=IdaycAEsutTIBnqIrOI+kPzjQzA1AIcJvluleI6YrvY=; b=DO46k+9N+UFmkot2UbUcFeeZmQMj2R8XhejqAwz/kPl1kJfKmPsOXeMCi5kAmQJyYv B2vmyNYxTbbhiJVNSOoxpXQbiwgTyXVnVVzdhPynbYSp6z22v99ESKIz9eE8Od8MD3kU AQnHQPTScaG/wP4ZT6Qbw8i0OWF6JUoBGoZ0TeRRTaxXMnn+jpIUr70E3XpOTC12rvm4 HuJ6iGb34pms0aLTRWJvkzCHhZz7GdJc5Guoj/E9BADnJIAKvbF8trX6RiTbRXU6XbCr Bry1b7EFg2aW4Yhrsnb8e20QjvpW9+b574DajbhC6X0dpGcYaBasfUMnQoomDWkpLMPL /6Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qeWCJ1VJ; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f14si6880871pgv.494.2018.03.17.10.11.33; Sat, 17 Mar 2018 10:12:02 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=qeWCJ1VJ; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753381AbeCQRKM (ORCPT + 99 others); Sat, 17 Mar 2018 13:10:12 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:40841 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752709AbeCQRKH (ORCPT ); Sat, 17 Mar 2018 13:10:07 -0400 Received: by mail-pl0-f67.google.com with SMTP id ay1-v6so7702356plb.7 for ; Sat, 17 Mar 2018 10:10:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IdaycAEsutTIBnqIrOI+kPzjQzA1AIcJvluleI6YrvY=; b=qeWCJ1VJgl0/Y40N6r3NFTBBmVeFxFwI9mZ7T7zFjXVDyxjOTsbWTaI2N4xdkrztJs Qe/1gIMTPnqPkVwtPyB5CSjPE17q5tKwvBgrvbk6Kn0nwa/8Dg+TbkzZdQ8BYcl64Cud pmWzx89OThWHp/z0bmKuBQtUTqhkDQcUvCQsFjIMkln0Cqvd7uxkCRD9S+eBkf4UXXI8 bCW629TkqN51l2wiXJOZlnkw1htQbfnrpbCUqYTtACxhNE06/OqCxIXldaPpHYxgc3TK 4dJbwHsHvZ1Rqclrja8LxyxnfFADufTR7/EvlBTlDrb0ceg8Gp6bz99WQQAz1i0aLQM1 PysA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IdaycAEsutTIBnqIrOI+kPzjQzA1AIcJvluleI6YrvY=; b=oeE5ELTyBj+WtrY+aqO8RUILddYgsSkOi1hVpluW46wamKNzZSnEXzxGPtJoglx539 U8PSuLbx2MESVgJIXLRYz0j2DJplt6akIF6AswUx5E/IJIRyz3OZtpq/ktwuRWiQDBx1 Ob3QMtdBMwo+LTrFOMp3+YBv77dkDrd8CISDq80RKakGv/W3+wV0lIw0Pko8pCD5oJOj Q6u9ACbCM9v1DktfstyPVC1vAW+alewfKKz7Lidd0K6FF9jDgohc8Xl5EqeFBCzS7ncY KrNR+ZZ/e39V2veimV8e/XINhVyWXwcZc8YK62bF+EEtcrvgvlUF9d62cuLqVSuuPogk iccw== X-Gm-Message-State: AElRT7EGhz55QMbqC2fSdkhYAjwsreqzZcz2QyF94wyrJqe/5SOX9w+e 5wLA0pBe3De4X4bUDOPglMHvJg== X-Received: by 2002:a17:902:887:: with SMTP id 7-v6mr4380613pll.319.1521306606111; Sat, 17 Mar 2018 10:10:06 -0700 (PDT) Received: from localhost ([2620:15c:2c4:201:f5a:7eca:440a:3ead]) by smtp.gmail.com with ESMTPSA id 73sm22982200pfz.165.2018.03.17.10.10.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 17 Mar 2018 10:10:05 -0700 (PDT) From: Eric Dumazet To: x86 Cc: lkml , Eric Dumazet , Eric Dumazet , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Hugh Dickins Subject: [PATCH 2/2] x86, cpuid: allow cpuid_read() to schedule Date: Sat, 17 Mar 2018 10:09:53 -0700 Message-Id: <20180317170953.111610-2-edumazet@google.com> X-Mailer: git-send-email 2.16.2.804.g6dcf76e118-goog In-Reply-To: <20180317170953.111610-1-edumazet@google.com> References: <20180317170953.111610-1-edumazet@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I noticed high latencies caused by a daemon periodically reading various MSR and cpuid on all cpus. KASAN kernels would see ~10ms latencies simply reading one cpuid. Even without KASAN, sending IPI to CPU in deep sleep state or blocking hard IRQ in a a long section, then waiting for the answer can consume hundreds of usec or more. Switching to smp_call_function_single_async() and a completion allows to reschedule and not burn cpu cycles. Signed-off-by: Eric Dumazet Cc: "H. Peter Anvin" Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Hugh Dickins --- arch/x86/kernel/cpuid.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c index 0931a105ffe16cde4640e759efa600b23a756d84..1d300f96df4b316dbe3392c8221467cfd8593272 100644 --- a/arch/x86/kernel/cpuid.c +++ b/arch/x86/kernel/cpuid.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -47,19 +48,27 @@ static struct class *cpuid_class; static enum cpuhp_state cpuhp_cpuid_state; +struct cpuid_regs_done { + struct cpuid_regs regs; + struct completion done; +}; + static void cpuid_smp_cpuid(void *cmd_block) { - struct cpuid_regs *cmd = (struct cpuid_regs *)cmd_block; + struct cpuid_regs_done *cmd = cmd_block; + + cpuid_count(cmd->regs.eax, cmd->regs.ecx, + &cmd->regs.eax, &cmd->regs.ebx, + &cmd->regs.ecx, &cmd->regs.edx); - cpuid_count(cmd->eax, cmd->ecx, - &cmd->eax, &cmd->ebx, &cmd->ecx, &cmd->edx); + complete(&cmd->done); } static ssize_t cpuid_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { char __user *tmp = buf; - struct cpuid_regs cmd; + struct cpuid_regs_done cmd; int cpu = iminor(file_inode(file)); u64 pos = *ppos; ssize_t bytes = 0; @@ -68,19 +77,28 @@ static ssize_t cpuid_read(struct file *file, char __user *buf, if (count % 16) return -EINVAL; /* Invalid chunk size */ + init_completion(&cmd.done); for (; count; count -= 16) { - cmd.eax = pos; - cmd.ecx = pos >> 32; - err = smp_call_function_single(cpu, cpuid_smp_cpuid, &cmd, 1); + call_single_data_t csd = { + .func = cpuid_smp_cpuid, + .info = &cmd, + }; + + cmd.regs.eax = pos; + cmd.regs.ecx = pos >> 32; + + err = smp_call_function_single_async(cpu, &csd); if (err) break; - if (copy_to_user(tmp, &cmd, 16)) { + wait_for_completion(&cmd.done); + if (copy_to_user(tmp, &cmd.regs, 16)) { err = -EFAULT; break; } tmp += 16; bytes += 16; *ppos = ++pos; + reinit_completion(&cmd.done); } return bytes ? bytes : err; -- 2.16.2.804.g6dcf76e118-goog