From patchwork Fri Sep 8 14:52:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 112093 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp424986qgf; Fri, 8 Sep 2017 07:53:19 -0700 (PDT) X-Received: by 10.101.82.77 with SMTP id q13mr3398450pgp.140.1504882399790; Fri, 08 Sep 2017 07:53:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504882399; cv=none; d=google.com; s=arc-20160816; b=UD7/he2a0X8Bd8iUOZe3hG3MrmaeY2ayVIzr71Tgw/NPIIm4o1VK4u6IDd6auNVxnx aoZGzsYrO3PFXUPEwbIGff4WFxRLsn27S9WHg/cPa6kw7ojDZaZ6lFRl5fHK/QUGMKyg IBhADX3H71ZvLzoT1YHmR4/PEkAzW0VMUcupw5Mp2vuL+TgK6QoLNj+Pa07QDeSU8Tl+ TQQBbgDtIJoXvdeFCOXvBRJQL0F2LZNRGHJcXsKtqbPQ0+xyK5/hgVyXFUj4LzCno1Bg AYMKzfAiIDvpw7Kcgyqyn7TjlhYrxzLdn1Ut02VPstmW/cvUAxQwYn0D2shxzS8b570n COPA== 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=WwmoKGA0IP+2WjdGGjE5LJajTk15PpPL0Z45niQA5kM=; b=eHHbuUw+Pb+OdibFqacwuIgltL5fbUdhFLrmH0Vr4pIp/nCNUtEarLNO3owekE7l7M iaudG377pT2H3XeesOpoLXVRwf2sM7uY09EFcGV6jPGu2nojura0d8R4ThW81DP0UR3i i4COvNo+fAFLSVqmMxUy4kEg2DyNNyHV9zJTTYh90k3/PdoRg5UUYK6klAZcTAVeHBVQ 7iHyNSfvXV6uLM5qYqOWM7v3w9DixPyHfZDFYngFDKAVMpHgOkX6olDmi6jbkuh5GpkG d3P1Qlv6al4nj54K64V0z47+wca46J8KW64l8PEV5/HxvPPWsELRMRtvB9ZaczojbWcb 8EYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a3vn2D4H; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l9si1774659pln.161.2017.09.08.07.53.19; Fri, 08 Sep 2017 07:53:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org header.s=google header.b=a3vn2D4H; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756404AbdIHOxR (ORCPT + 6 others); Fri, 8 Sep 2017 10:53:17 -0400 Received: from mail-pg0-f50.google.com ([74.125.83.50]:35087 "EHLO mail-pg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756263AbdIHOxQ (ORCPT ); Fri, 8 Sep 2017 10:53:16 -0400 Received: by mail-pg0-f50.google.com with SMTP id 188so5228943pgb.2 for ; Fri, 08 Sep 2017 07:53:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WwmoKGA0IP+2WjdGGjE5LJajTk15PpPL0Z45niQA5kM=; b=a3vn2D4HigpEEpxgVy8HhxZveAEGnTpnEOuUCmjnxy6aID0cUqcK3/O6TBQRoozGK9 iaZPglSzIaVhyibLyKabNiufgg0Y2W/n/G2a3O9yu2AztBKohnAZZ7EhpbajYC5h1WIh XcS+TE7poTm7yiAv+XvIRooD9o1R43qKay+Uk= 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=WwmoKGA0IP+2WjdGGjE5LJajTk15PpPL0Z45niQA5kM=; b=QsNwyNS81OgF+1mf8Q/dG1hmOBrBSfs1aK6ijio6sO93cz1xUnZszBzJ9gv58cnIUr zF7zpQuva0VvB+DTTmoldX9zQ3nZlcDQxkuK2q+50uCfV2y63jltdBU/WPOFg+2/oHda r+6ZJ9vl3EoYYndFwnLfQrCeiCB3Z17y/ulmU0GLoGU4ovIbJ/3ju3DBKsPwAZGj7gaQ sqKho+SU0TqV2ik9uXr0miVnpSZ2yZ40fYkIixLQwTYEwK491gD5yn84PqmOiNLGZPmD wswZJIZRvSslBvkSfnKfi25+j5KJZySzWC2hTnLjvdUkzHLLMf3PDSU8tq7qJ1Ps6CRZ xbnw== X-Gm-Message-State: AHPjjUj6+LC2ygq6fwN68lQewjvztGicimkXaBGEQMExrHv5xHGhN7lX AyMtQrf/3zHvcj2w X-Google-Smtp-Source: ADKCNb59AIBLZ6LHKWeNuxLWTJeBMUTDE70Z7CS2BaCK91dpw/JZXgAM6uJBAttlXjgQH4C8zFeBiw== X-Received: by 10.84.129.226 with SMTP id b89mr3674097plb.6.1504882395651; Fri, 08 Sep 2017 07:53:15 -0700 (PDT) Received: from localhost.localdomain ([104.153.224.169]) by smtp.gmail.com with ESMTPSA id x189sm4258160pfx.188.2017.09.08.07.53.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 08 Sep 2017 07:53:14 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Cc: Marc Zyngier , hemk976@gmail.com, Jintack Lim , kvm@vger.kernel.org, Christoffer Dall , stable@vger.kernel.org Subject: [PATCH 2/2] KVM: arm/arm64: Fix vgic_mmio_change_active with PREEMPT_RT Date: Fri, 8 Sep 2017 07:52:19 -0700 Message-Id: <1504882339-42520-3-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504882339-42520-1-git-send-email-christoffer.dall@linaro.org> References: <1504882339-42520-1-git-send-email-christoffer.dall@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Christoffer Dall Getting a per-CPU variable requires a non-preemptible context and we were relying on a normal spinlock to disable preemption as well. This asusmption breaks with PREEMPT_RT and was observed on v4.9 using PREEMPT_RT. This change moves the spinlock tighter around the critical section accessing the IRQ structure protected by the lock and uses a separate preemption disabled section for determining the requesting VCPU. There should be no change in functionality of performance degradation on non-RT. Fixes: 370a0ec18199 ("KVM: arm/arm64: Let vcpu thread modify its own active state") Cc: stable@vger.kernel.org Cc: Jintack Lim Reported-by: Hemanth Kumar Signed-off-by: Christoffer Dall --- virt/kvm/arm/vgic/vgic-mmio.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/virt/kvm/arm/vgic/vgic-mmio.c b/virt/kvm/arm/vgic/vgic-mmio.c index c1e4bdd..7377f97 100644 --- a/virt/kvm/arm/vgic/vgic-mmio.c +++ b/virt/kvm/arm/vgic/vgic-mmio.c @@ -181,7 +181,6 @@ static void vgic_mmio_change_active(struct kvm_vcpu *vcpu, struct vgic_irq *irq, bool new_active_state) { struct kvm_vcpu *requester_vcpu; - spin_lock(&irq->irq_lock); /* * The vcpu parameter here can mean multiple things depending on how @@ -195,8 +194,19 @@ static void vgic_mmio_change_active(struct kvm_vcpu *vcpu, struct vgic_irq *irq, * NULL, which is fine, because we guarantee that no VCPUs are running * when accessing VGIC state from user space so irq->vcpu->cpu is * always -1. + * + * We have to temporarily disable preemption to read the per-CPU + * variable. It doesn't matter if we actually get preempted + * after enabling preemption because we only need to figure out if + * this thread is a running VCPU thread, and in that case for which + * VCPU. If we're migrated the preempt notifiers will migrate the + * running VCPU pointer with us. */ + preempt_disable(); requester_vcpu = kvm_arm_get_running_vcpu(); + preempt_enable(); + + spin_lock(&irq->irq_lock); /* * If this virtual IRQ was written into a list register, we