From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22984C34056 for ; Wed, 19 Feb 2020 19:10:28 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id A2C27208C4 for ; Wed, 19 Feb 2020 19:10:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZyzJ85UZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A2C27208C4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvmarm-bounces@lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id A6E7E4AF15; Wed, 19 Feb 2020 14:10:26 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@redhat.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id peT1b1Ho-OHl; Wed, 19 Feb 2020 14:10:25 -0500 (EST) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 94F214AF17; Wed, 19 Feb 2020 14:10:25 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 181E84AF15 for ; Wed, 19 Feb 2020 14:10:24 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ea9oK9NcyR1l for ; Wed, 19 Feb 2020 14:10:23 -0500 (EST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 0F3BD4AF14 for ; Wed, 19 Feb 2020 14:10:23 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582139422; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LLgaFIYXcSHF8geXp8D1KEQXzRlLaodTECH2wFDsVfY=; b=ZyzJ85UZHSnbh6TGSJWuhL5XOUJaPbmUcOzHsMPIvvhncTaRXVi42+bBdEf6ugLh2vKjUS 2XqlCvJjDlzvOG93cM8GBt0viAo/ZXeNO7NH0L3B6WwcDpidDoFAIKYk6K0UuWbGTLwp8o V64eNEV01H2eUmWn1fLp3gZbugSvgH8= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-48-LeIGpya7PCuX9JYHnBQ2QA-1; Wed, 19 Feb 2020 14:10:20 -0500 Received: by mail-qt1-f200.google.com with SMTP id g26so831701qts.16 for ; Wed, 19 Feb 2020 11:10:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Iu+zDafgQ7GdYGR/n8pxbgWtAD7a9J36y82BGwKTfA0=; b=ZcB5RqUp4plzu43m56EO3O0pA7LG3y5u69lXjyVdn9PFOgFmmmKt0t16IQn3PUTmmC TQLijsICl5J5159g+McDVYAryewjLMiJx1yjnkkswylbeMB79rwTAv1lARBOIeSsajoF xn5VI71fjFOwZkMPmSP+lIdzWujDSqRl6dnvHE9y+hd8EUCvV19GlUQB0TR2lnUpea9p GeHiSzhgckBwJdUFSZBldRBSrKguNYwD2zkPEzOv1h6VFqsE3bpf5EJm5fVbXJ0EVl8y LGXn0VPYepooJ+KXbzqDYaxQmYPtLuPFvnMjDoO+9iXxqz5XyMTJ+bBThZvhov/XE0Yk R1pg== X-Gm-Message-State: APjAAAVox+CiFXxA8OZ6qYBgExxoT5lN2CYkaCTmiMNNkDAUfJD8jQyQ krveMHJS9l9VV7LULM14CFzJA7Ou1shPVa91yYX3cYjNFR0QD7L1bsjNPGpVS6ysybjD/HOevCx LICUxEMj+skkJe/4XrdGxHOKu X-Received: by 2002:aed:29e2:: with SMTP id o89mr23723359qtd.353.1582139419978; Wed, 19 Feb 2020 11:10:19 -0800 (PST) X-Google-Smtp-Source: APXvYqyR4tvaG55rn+oIGW+9DmQY+Q5rgmtUB62N9SOWO2kSCX8x9uyUbBuaGecyF0GgmgJCEJ7bJQ== X-Received: by 2002:aed:29e2:: with SMTP id o89mr23723317qtd.353.1582139419685; Wed, 19 Feb 2020 11:10:19 -0800 (PST) Received: from xz-x1 ([104.156.64.75]) by smtp.gmail.com with ESMTPSA id m95sm453246qte.41.2020.02.19.11.10.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 11:10:19 -0800 (PST) Date: Wed, 19 Feb 2020 14:10:17 -0500 From: Peter Xu To: Sean Christopherson Subject: Re: [PATCH v6 01/22] KVM: x86: Allocate new rmap and large page tracking when moving memslot Message-ID: <20200219191017.GA37550@xz-x1> References: <20200218210736.16432-1-sean.j.christopherson@intel.com> <20200218210736.16432-2-sean.j.christopherson@intel.com> MIME-Version: 1.0 In-Reply-To: <20200218210736.16432-2-sean.j.christopherson@intel.com> X-MC-Unique: LeIGpya7PCuX9JYHnBQ2QA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Cc: Wanpeng Li , kvm@vger.kernel.org, David Hildenbrand , linux-mips@vger.kernel.org, Paul Mackerras , kvmarm@lists.cs.columbia.edu, Janosch Frank , Marc Zyngier , Joerg Roedel , Christian Borntraeger , kvm-ppc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Jim Mattson , Cornelia Huck , linux-kernel@vger.kernel.org, Paolo Bonzini , Vitaly Kuznetsov , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Tue, Feb 18, 2020 at 01:07:15PM -0800, Sean Christopherson wrote: > Reallocate a rmap array and recalcuate large page compatibility when > moving an existing memslot to correctly handle the alignment properties > of the new memslot. The number of rmap entries required at each level > is dependent on the alignment of the memslot's base gfn with respect to > that level, e.g. moving a large-page aligned memslot so that it becomes > unaligned will increase the number of rmap entries needed at the now > unaligned level. > > Not updating the rmap array is the most obvious bug, as KVM accesses > garbage data beyond the end of the rmap. KVM interprets the bad data as > pointers, leading to non-canonical #GPs, unexpected #PFs, etc... > > general protection fault: 0000 [#1] SMP > CPU: 0 PID: 1909 Comm: move_memory_reg Not tainted 5.4.0-rc7+ #139 > Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015 > RIP: 0010:rmap_get_first+0x37/0x50 [kvm] > Code: <48> 8b 3b 48 85 ff 74 ec e8 6c f4 ff ff 85 c0 74 e3 48 89 d8 5b c3 > RSP: 0018:ffffc9000021bbc8 EFLAGS: 00010246 > RAX: ffff00617461642e RBX: ffff00617461642e RCX: 0000000000000012 > RDX: ffff88827400f568 RSI: ffffc9000021bbe0 RDI: ffff88827400f570 > RBP: 0010000000000000 R08: ffffc9000021bd00 R09: ffffc9000021bda8 > R10: ffffc9000021bc48 R11: 0000000000000000 R12: 0030000000000000 > R13: 0000000000000000 R14: ffff88827427d700 R15: ffffc9000021bce8 > FS: 00007f7eda014700(0000) GS:ffff888277a00000(0000) knlGS:0000000000000000 > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > CR2: 00007f7ed9216ff8 CR3: 0000000274391003 CR4: 0000000000162eb0 > Call Trace: > kvm_mmu_slot_set_dirty+0xa1/0x150 [kvm] > __kvm_set_memory_region.part.64+0x559/0x960 [kvm] > kvm_set_memory_region+0x45/0x60 [kvm] > kvm_vm_ioctl+0x30f/0x920 [kvm] > do_vfs_ioctl+0xa1/0x620 > ksys_ioctl+0x66/0x70 > __x64_sys_ioctl+0x16/0x20 > do_syscall_64+0x4c/0x170 > entry_SYSCALL_64_after_hwframe+0x44/0xa9 > RIP: 0033:0x7f7ed9911f47 > Code: <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 21 6f 2c 00 f7 d8 64 89 01 48 > RSP: 002b:00007ffc00937498 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 > RAX: ffffffffffffffda RBX: 0000000001ab0010 RCX: 00007f7ed9911f47 > RDX: 0000000001ab1350 RSI: 000000004020ae46 RDI: 0000000000000004 > RBP: 000000000000000a R08: 0000000000000000 R09: 00007f7ed9214700 > R10: 00007f7ed92149d0 R11: 0000000000000246 R12: 00000000bffff000 > R13: 0000000000000003 R14: 00007f7ed9215000 R15: 0000000000000000 > Modules linked in: kvm_intel kvm irqbypass > ---[ end trace 0c5f570b3358ca89 ]--- > > The disallow_lpage tracking is more subtle. Failure to update results > in KVM creating large pages when it shouldn't, either due to stale data > or again due to indexing beyond the end of the metadata arrays, which > can lead to memory corruption and/or leaking data to guest/userspace. > > Note, the arrays for the old memslot are freed by the unconditional call > to kvm_free_memslot() in __kvm_set_memory_region(). > > Fixes: 05da45583de9b ("KVM: MMU: large page support") > Cc: stable@vger.kernel.org > Signed-off-by: Sean Christopherson Reviewed-by: Peter Xu -- Peter Xu _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm