From patchwork Mon Nov 13 09:17:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10055407 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0FD5060586 for ; Mon, 13 Nov 2017 09:29:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDDCB29333 for ; Mon, 13 Nov 2017 09:29:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2A242933C; Mon, 13 Nov 2017 09:29:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 703F029333 for ; Mon, 13 Nov 2017 09:29:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=WR62DuP5WBss93M6EizeFJisFKtbEnqHNXetdWsb5uA=; b=DAct9FfqUKzgM6tpjtNHpfNvyJ 7cGfawkIC+Mb9CCAIhGxAPUYhzl6jCgT2LDmwMJpKSqMzJ05+weOu7C3cZoTfl47YrPZBsZmqGKft ZleK9QJOsizI3S9wAvEhmDsxtvTwEYJV/nxTRqc4aSW5zI1JRnG+U7kMQpYNsSyAoNEzvYYWuBuD/ C70xmDq3fJ2MrHKPshYBh4gU25tbCK4+WTg9fKcCNNiax2mipg3oSNufFQxO8ktdzEUUTfXSrMx1U F7ZGJ8uSjSVrW5Q3VCPnMfF+R9JsDyxREEeLOUEoW4ZA3v1EISzAbrMCpeYlIzlU10N/VlVQcxutG 27amIzCA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eEB33-00055U-RF; Mon, 13 Nov 2017 09:28:57 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eEAts-0003Fb-VF for linux-arm-kernel@bombadil.infradead.org; Mon, 13 Nov 2017 09:19:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=WWvx5vc+zBcm/fnCoiaikM0qMvvHIgd70Y+J7CEeFMM=; b=mV5/ceOiyYVGweFHi2o5PApth F90MrBsYOUKkMfCRvgNwnkeSX1BxKE0Oqe0otksjrvSSJkVIx0DkktH3YjxpZT9Fo75UiP38FHIqZ 5PhDFgFH+RH/x2aeL6TwIEN/Xtg6yjySkthISxtt+OICiA1QxtS4qcIjsZOx4VFi4CpzEWh8QT19E gr2MVFlTi9+ouSN4iEx+rIk72nO7cYM1pwMi5G8cICGEIDIYUQHK0VZa2cW9kI/6paTy78mE5fDkW lSrf3t8A2NQtU2eb6MPU3XlXfxqmZoU35hcwVqRzzoF7GkgFBMM/bUAA8kBDKXzfcWdh+//5c9szK YueaBzSgw==; Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eEAtI-000786-Ge for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2017 09:18:54 +0000 Received: by mail-wr0-x244.google.com with SMTP id j15so13762370wre.8 for ; Mon, 13 Nov 2017 01:18:31 -0800 (PST) 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=WWvx5vc+zBcm/fnCoiaikM0qMvvHIgd70Y+J7CEeFMM=; b=Z1fMqn6/Cg3R89vFkAG2RxURdPti8fz+0BLxQ9lLrWE06pdMZqvsxGkipiNdJcMXh3 6x3tSPZd8B2xfGSlU1zf99z/4bh1TDY1UdVX57gcij0pmGoDnRc8/1liFZS1DZ9KyKrs n0sUsR8p3suUiR8T1UphkIelCcZexvnKFQK24= 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=WWvx5vc+zBcm/fnCoiaikM0qMvvHIgd70Y+J7CEeFMM=; b=gHP8Em62g/dmb7IfY4EIALw+pGKU2L1SXcah97/dYZYRQIQo0PQoHPQb/2o+k/aW9V i0uXwq9BSZbQ+/W391GsrIUxCNv3Fi/n7O4WbHbFQuFzvBF10GfjMxFZLbV9N6sFTkIG Wa07tmTRD0/pZkZed0BPLpYAniakt6as4a2ita6qg8O82C11UOqvJOMLBz42Bl1bg3KH XuHgPurjlbd1zX8XfwD5Ey9WWPZ6XULK2zgJ+o96KKsV62jpjy8FSe9hlCSVPOiGlDeb 36zGj9cQJP5i3riMhZBQZmn+wUz7n37JTMoap+aALWTb3PP6no/X1s3Cuo0Zd4y2ZrNw IYlQ== X-Gm-Message-State: AJaThX5941LSaHVHecyjAc6gV3+8GpydS1m2uETn+mAH09P/j7VMQmN/ 8aPclNlVxJE/F81FBshEQ00FPg== X-Google-Smtp-Source: AGs4zMYWkUpEeg8lktxjj2KePQFX6nOxGkh1R5gAJqOO2C0Ti7+C8BcIfQu6nkqDDoML2AkwXJmqZQ== X-Received: by 10.223.151.212 with SMTP id t20mr6842075wrb.2.1510564710742; Mon, 13 Nov 2017 01:18:30 -0800 (PST) Received: from localhost.localdomain (xd93dd96b.cust.hiper.dk. [217.61.217.107]) by smtp.gmail.com with ESMTPSA id x63sm9651399wma.39.2017.11.13.01.18.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 Nov 2017 01:18:29 -0800 (PST) From: Christoffer Dall To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PULL 23/27] KVM: arm/arm64: GICv4: Prevent userspace from changing doorbell affinity Date: Mon, 13 Nov 2017 10:17:48 +0100 Message-Id: <20171113091752.10663-24-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171113091752.10663-1-christoffer.dall@linaro.org> References: <20171113091752.10663-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171113_091852_589938_CD973570 X-CRM114-Status: GOOD ( 14.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marc Zyngier , Christoffer Dall , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Marc Zyngier We so far allocate the doorbell interrupts without taking any special measure regarding the affinity of these interrupts. We simply move them around as required when the vcpu gets scheduled on a different CPU. But that's counting without userspace (and the evil irqbalance) that can try and move the VPE interrupt around, causing the ITS code to emit VMOVP commands and remap the doorbell to another redistributor. Worse, this can happen while the vcpu is running, causing all kind of trouble if the VPE is already resident, and we end-up in UNPRED territory. So let's take a definitive action and prevent userspace from messing with us. This is just a matter of adding IRQ_NO_BALANCING to the set of flags we already have, letting the kernel in sole control of the affinity. Acked-by: Christoffer Dall Reviewed-by: Eric Auger Signed-off-by: Marc Zyngier Signed-off-by: Christoffer Dall --- virt/kvm/arm/vgic/vgic-v4.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-v4.c b/virt/kvm/arm/vgic/vgic-v4.c index c9cec01008c2..bf874dd01fc0 100644 --- a/virt/kvm/arm/vgic/vgic-v4.c +++ b/virt/kvm/arm/vgic/vgic-v4.c @@ -23,6 +23,8 @@ #include "vgic.h" +#define DB_IRQ_FLAGS (IRQ_NOAUTOEN | IRQ_DISABLE_UNLAZY | IRQ_NO_BALANCING) + static irqreturn_t vgic_v4_doorbell_handler(int irq, void *info) { struct kvm_vcpu *vcpu = info; @@ -83,7 +85,7 @@ int vgic_v4_init(struct kvm *kvm) * doorbell could kick us out of the guest too * early... */ - irq_set_status_flags(irq, IRQ_NOAUTOEN | IRQ_DISABLE_UNLAZY); + irq_set_status_flags(irq, DB_IRQ_FLAGS); ret = request_irq(irq, vgic_v4_doorbell_handler, 0, "vcpu", vcpu); if (ret) { @@ -121,7 +123,7 @@ void vgic_v4_teardown(struct kvm *kvm) struct kvm_vcpu *vcpu = kvm_get_vcpu(kvm, i); int irq = its_vm->vpes[i]->irq; - irq_clear_status_flags(irq, IRQ_NOAUTOEN | IRQ_DISABLE_UNLAZY); + irq_clear_status_flags(irq, DB_IRQ_FLAGS); free_irq(irq, vcpu); }