From patchwork Tue Jul 3 21:26:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10505249 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 2D8EA6035E for ; Tue, 3 Jul 2018 21:26:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B2B628B0C for ; Tue, 3 Jul 2018 21:26:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0CA5928B12; Tue, 3 Jul 2018 21:26:30 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B46E28B0C for ; Tue, 3 Jul 2018 21:26:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753085AbeGCV00 (ORCPT ); Tue, 3 Jul 2018 17:26:26 -0400 Received: from mail-am5eur03hn0206.outbound.protection.outlook.com ([104.47.8.206]:62675 "EHLO EUR03-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752910AbeGCV0Z (ORCPT ); Tue, 3 Jul 2018 17:26:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hPikmC9brjhL/9FSbytLqvlCt1FTPCTiCAurtESwJ+o=; b=AC8+bo3i6X8wb3FuSLqlmu2fOI3AmmoAc1yspJBEqdl6Jq07whjEZeWoRWdlt2eBM00XAkH/PTwwOqx82nri+h86jd/TbAx4YkBTZaaU1MbQQH1yu2sm5JsS+degqCV737E9k5cFKeOZJTnjQE7O9BbtlSJxf/6yLEZjWQ49/ik= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Christoffer.Dall@arm.com; Received: from localhost (217.140.96.140) by DB6PR0801MB2040.eurprd08.prod.outlook.com (2603:10a6:4:76::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.906.26; Tue, 3 Jul 2018 21:26:22 +0000 From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Cc: kvm@vger.kernel.org, Marc Zyngier , Eric Auger , Andre Przywara , Christoffer Dall Subject: [PATCH] KVM: arm/arm64: Fix vgic init race Date: Tue, 3 Jul 2018 23:26:15 +0200 Message-Id: <1530653175-11999-1-git-send-email-christoffer.dall@arm.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [217.140.96.140] X-ClientProxiedBy: LO2P265CA0040.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:61::28) To DB6PR0801MB2040.eurprd08.prod.outlook.com (2603:10a6:4:76::21) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5f43f3a1-4825-42bf-ba66-08d5e12ba03d X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600053)(711020)(48565401081)(2017052603328)(7153060)(7193020); SRVR:DB6PR0801MB2040; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB2040; 3:ydB+Bi6t/WV1oSwzfYrR+EMfO0OfDMw4Ght73x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/n9oRmmwn7KWZ6ZkaRXCs5G8awSPda5Nf2ha23U8OfDLadhgQAGS5ewQtF6fzvkHV8bEWwbpiGPMaBsElVfNvvG+lacKOciCrdQ4bnZJAfpXfwiX6xEMifCHtIpxlnqbbdzFih5H/qy/KvG5u+01bU8M8FhfsPcyPwilQrq0vUAIHhwlwVvIFZ3/7qMoXAmegw9XGJzu2j0H/FaEw5ddHdhTDwNbs+6gqa0U7mOE5GVrSgI0kk7hDF0ogqK5gDkYiE3pV9NvV4o+PSMaItyqo8jkc8LtQ8l6jrUwxO/szlW7ki1N7f; 4:DpAIGAaCwcbjsqCpza32TkqcD/lkyWT9FZBW+yBbM5wB86WUoTTmPpkGN6xNGt4ziwx7DPJ/Wj5MXA3SV5mS4eH1x/MmoQ2AP0VW7lFPvZpefByg3MM+9VYJmWghv4DUyMRTL1+BbTCqEzKCsLTbeE8nZMHiSPpsG0SNI/vW0+mSedVD8kIh8KG/THhBOSKNthAiX2+N1rcmtm3XWZaummYFocXAZMZ2udfgj6WJZpXRWkgSc2bATqyGpte0PJJl9pOFczbROXeYHgUcJOLMCFuaTTbUMqSqfUng0ARXLt9rk2+FtrlMM6CfEzsSN6FdP9h/V5z8E9Lvyx56KcHsSvYfUfLVsNiX8IBLr3B+3i12MUhEibkj4cffwy5oNpd7 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(209352067349851)(223705240517415); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3002001)(3231254)(944501410)(52105095)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123558120)(20161123560045)(6072148)(201708071742011)(7699016); SRVR:DB6PR0801MB2040; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0801MB2040; X-Forefront-PRVS: 0722981D2A X-Forefront-Antispam-Report: SFV:SPM; SFS:(10009020)(6069001)(346002)(39860400002)(136003)(376002)(366004)(396003)(40434004)(199004)(189003)(50466002)(44832011)(2906002)(68736007)(2171002)(52116002)(53936002)(26005)(25786009)(51416003)(97736004)(16526019)(186003)(47776003)(6496006)(50226002)(72206003)(386003)(5024004)(48376002)(478600001)(6486002)(81156014)(316002)(81166006)(6116002)(305945005)(8676002)(6666003)(76506005)(8746002)(8936002)(54906003)(86362001)(3846002)(575784001)(7736002)(4326008)(106356001)(486006)(476003)(2616005)(14444005)(36756003)(1857600001)(105586002)(956004)(5660300001)(66066001)(23200700001); DIR:OUT; SFP:1501; SCL:5; SRVR:DB6PR0801MB2040; H:localhost; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB6PR0801MB2040; 23:aZFydFvNDCG8ej0OtBfeH13D/qNwPuiQugFgqhY?= =?us-ascii?Q?6cg/XiYEdUR8cu04J69Ym4f+lQJOmcGcGZwFTdw/PB3PsVDE3/6srZTFhXCt?= =?us-ascii?Q?Sruzew32obXeczDEMzV8XkWb8Rhx6Rdn+QYpcmWj4eYZTorDVvsNsniJYC1X?= =?us-ascii?Q?5xBXkqgQuwZ3RBEe70fZYTPg7/LD03T9uisU7bMZenpk4Gf+IPsg8wEQcsTo?= =?us-ascii?Q?i1b70XzlDiV3KtAPbY10TPFPoPEaCoyVYaCogAps6BKlACmceXop40VoqJ/G?= =?us-ascii?Q?R/70D4nTGjkV2A1lgGA32ETauxabMIt1lDaFdXezWdV+AhR9r+9/rrEQhP2/?= =?us-ascii?Q?aP2U5FCscDQ9nn4Ovpf7aaPq+U6O71gUU4prXsPSN9GFGsEgr/zFIfXhBeH2?= =?us-ascii?Q?YW6Sty/m2alhjnigIb9wWZZFZyIKYpT9RqosM8HCRq+cJCMZ6ptMy62zd3cd?= =?us-ascii?Q?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43AbplfX+MZyLRkAbTG1AqwbdMNq+/Bcss9Dtg7z3zkipiicvhowU0Vcsbl9fFmKqkAXZUTC00sLUKmA==; 5:s7nYq/BuxYL3f5g8290PVW7yX4jziUlRiw+flXdLF95xJpxBSsAp8hcqmopSGDU0IxJDLgRLR3LqdOm/es9aFkuMQCqqMPcLxvPzcg2i3mdaOuZr7h/ZfgVKXaSYw+nhtCkcOYEaXOlZsO+P5GAPp8MhSGf5HiZ2TDebtxF+YRU=; 24:Ark5oi7KRI8hZVuuuGRrefbTXfNrnlC6c9pI6zvluGck9S/nUXD0dLO9Pwt7Z5DYrxglrzlV1QvGCWdKEhwE0Q== SpamDiagnosticOutput: 1:22 X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB2040; 7:QmDnbBiGRmmlWyp3xSVHN4kYrqTiPuk5YiB0IVqMxR2NwonFW+azElXJiGq7iLzNtiCxSZqFRHx9XXRxhX7chSpUOSOrqYDZJnZeCOBsCAO7Oi7CF2Vg49jNVQi9jASlOm2Y0UC/haa451T49Vk+mOeyEbaM3u6l/+x1m30dvBANb8A1/EkDscgo0IFYCGPF6tbbEZ0R40h1QiZyAj5UhmVIS1b7S9iQLukQCEB2/DGwcrPvYIQwx+qSrIEtvxpV X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2018 21:26:22.9234 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5f43f3a1-4825-42bf-ba66-08d5e12ba03d X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB2040 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The vgic_init function can race with kvm_arch_vcpu_create() which does not hold kvm_lock() and we therefore have no synchronization primitives to ensure we're doing the right thing. As the user is trying to initialize or run the VM while at the same time creating more VCPUs, we just have to refuse to initialize the VGIC in this case rather than silently failing with a broken VCPU. Signed-off-by: Christoffer Dall Reviewed-by: Eric Auger --- virt/kvm/arm/vgic/vgic-init.c | 4 ++++ 1 file changed, 4 insertions(+) -- 2.7.4 IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. diff --git a/virt/kvm/arm/vgic/vgic-init.c b/virt/kvm/arm/vgic/vgic-init.c index 9406eaf..c0c0b88 100644 --- a/virt/kvm/arm/vgic/vgic-init.c +++ b/virt/kvm/arm/vgic/vgic-init.c @@ -286,6 +286,10 @@ int vgic_init(struct kvm *kvm) if (vgic_initialized(kvm)) return 0; + /* Are we also in the middle of creating a VCPU? */ + if (kvm->created_vcpus != atomic_read(&kvm->online_vcpus)) + return -EBUSY; + /* freeze the number of spis */ if (!dist->nr_spis) dist->nr_spis = VGIC_NR_IRQS_LEGACY - VGIC_NR_PRIVATE_IRQS;