From patchwork Fri Sep 19 23:03:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 4940521 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 697549F40F for ; Fri, 19 Sep 2014 23:03:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 92BB3201F4 for ; Fri, 19 Sep 2014 23:03:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D03E7201F2 for ; Fri, 19 Sep 2014 23:03:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756260AbaISXDc (ORCPT ); Fri, 19 Sep 2014 19:03:32 -0400 Received: from mail-ie0-f181.google.com ([209.85.223.181]:39952 "EHLO mail-ie0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751745AbaISXDb (ORCPT ); Fri, 19 Sep 2014 19:03:31 -0400 Received: by mail-ie0-f181.google.com with SMTP id tr6so4458534ieb.12 for ; Fri, 19 Sep 2014 16:03:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=lH8LnzNEB2WX/SXGWP04y/zgcpEF/GTO37S97F7LIkQ=; b=hfAQF/oG8cQCIbllo1Bv3fnLyur7wnhgqVS8H7Aohzafwbzk1jkeagXNGFQtbSqzl+ T2ZytaqK173Gz8ekSA9GzteWJ+M0Ut60+AqOi+GLjfpDeaN05j4Aiz4aNlxCDnXbi1IQ UG3JlSjVnHTFKAfH1okhyPz1cWNhk3T12tTz4M0T+FoMKbhQwk7bPsE3GE5tBEhIuNzd OPgA3Ooj/4LA3gdAh6yUQ5skCDaJpyGF1myTFcEjEv1eLNlWU90g5iTCvuq/cW2LWKIt rnmlGDKtDZdYQ6I5XFFQgOG7LXyEgNmMw5caxE9K8Xm3ysARzfTRFaUhC97Clqc9hkPq L9Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=lH8LnzNEB2WX/SXGWP04y/zgcpEF/GTO37S97F7LIkQ=; b=ItKNArYVYFYQdcnv1+YrtsCvWOs+x1KJl51ouy6ce+C4XxJic3rymdTTfIWZNGld8M 9bXdoNomr5UJSZr6qw8r68jgUT0zTCVxEs+vapamOo/z1HSzWEiCnul34K3ieF/MUacg kjg5/xIyNM7uw08L3tMwi8dWA3tyj5uq/fXhnXxBVyuNBwa4Hvl9aetJ/qiTAS0E9tMA KoNNPiMvSTavrCUCVD/NiXo/uSxmZRYv7TmTf7Zsi/0PNEYfRI/qkJ6EVcls1hh/ClJv vYoZ6lI6VY31FfvGq63BhXAKT5x4a59ldjUOyNtZWoVjaGOEXs7kF2Etejz3sYhS/AB+ 91Cw== X-Gm-Message-State: ALoCoQmJpCBG5KtEwuT5TNZL8MQvc+ktQz+VE2W2LRYdZFYU85vlbs3mWeiRCD23bEO0n5+YdV8p X-Received: by 10.43.155.13 with SMTP id lg13mr4044006icc.15.1411167810717; Fri, 19 Sep 2014 16:03:30 -0700 (PDT) Received: from dmatlack-linux.kir.corp.google.com (dmatlack-linux.kir.corp.google.com [172.31.88.63]) by mx.google.com with ESMTPSA id qd4sm2786267igb.19.2014.09.19.16.03.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 19 Sep 2014 16:03:30 -0700 (PDT) From: David Matlack To: Gleb Natapov , Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: David Matlack Subject: [PATCH] kvm: don't take vcpu mutex for obviously invalid vcpu ioctls Date: Fri, 19 Sep 2014 16:03:25 -0700 Message-Id: <1411167805-2458-1-git-send-email-dmatlack@google.com> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP vcpu ioctls can hang the calling thread if issued while a vcpu is running. If we know ioctl is going to be rejected as invalid anyway, we can fail before trying to take the vcpu mutex. This patch does not change functionality, it just makes invalid ioctls fail faster. Signed-off-by: David Matlack --- virt/kvm/kvm_main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 96ec622..f9234e5 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -52,6 +52,7 @@ #include #include +#include #include #include @@ -1975,6 +1976,9 @@ static long kvm_vcpu_ioctl(struct file *filp, if (vcpu->kvm->mm != current->mm) return -EIO; + if (unlikely(_IOC_TYPE(ioctl) != KVMIO)) + return -EINVAL; + #if defined(CONFIG_S390) || defined(CONFIG_PPC) || defined(CONFIG_MIPS) /* * Special cases: vcpu ioctls that are asynchronous to vcpu execution,