Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4302122imm; Fri, 18 May 2018 02:51:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpZ9tFXknhi9i3D/NpQRfpgnH7mc+HU1dYjHZBDKHEXuwPVuqT3CVW1FHp/fcQWEQk+h4bi X-Received: by 2002:a63:8ac4:: with SMTP id y187-v6mr6911327pgd.64.1526637116043; Fri, 18 May 2018 02:51:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526637116; cv=none; d=google.com; s=arc-20160816; b=ox0//+Nbit6UjH66a4bqlS9CvKZ/ugTY37UA45tOUTbQpkFdBKTywWj2WjhKK6E23h wX05i3TR4j2Vk/sKd+TeTOYfX14UjWddX70poAT2mJ/D/QnveBO47o7wnknMsrARx3x4 yrm+IUex6N135D6xBIE4/JN3UPG8K+9IgyBbJOgFMDJBASz9fd8VHfzy9USRtSDxU9ac kNn4q0C5jKe5/Upcn6yF8PYFzGt2MmlxixBdOmrtBbb/ydGXb55odBI6nwfYekthyZzd V+6TrI1+dRqBSVY/+jQ8fX6it6GGkg6LrguouCKc57Px+l7q27UtzCtOaAoSQp2vla48 wC5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject :arc-authentication-results; bh=OyQ6GSu0eJQkjAEcT2tPfuzN/h89WOByTa+mXiVXljY=; b=HSJ0xgta96gjNeTuttBWVYXF7rqqk8py5feBHQVTDVaswCNd3Bur/emjt0LYe7IhF+ NiS2EABpsCHGQvYS9q/TZg758uCITEUU9egmPoDNBbXeNrobwa1laWfVzlXYU+7d7LUE R1EE89cIj1P9a7j9FBVU++jyi0A1OPqOLV3W2XXtt/46huiXO0YbSx1xJ5cbaNhsSnkY RniDLFhWDL2hJnj/SUHTV/sZQOMw1htucs8HyF3f5gDOR4T8E1xG2gaJ2x1rt52Dxlll GbExfHi9Df7Hy/2FlygciJbk6Xk1lCBAGx9lkbmyYN0KYCZ2OqqwQfZumZswSDX5IfM9 /0bg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f16-v6si7279584pfe.291.2018.05.18.02.51.42; Fri, 18 May 2018 02:51:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752608AbeERJuD (ORCPT + 99 others); Fri, 18 May 2018 05:50:03 -0400 Received: from foss.arm.com ([217.140.101.70]:46374 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752541AbeERJse (ORCPT ); Fri, 18 May 2018 05:48:34 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BE9FD1435; Fri, 18 May 2018 02:48:33 -0700 (PDT) Received: from [10.1.206.75] (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 81C543F53D; Fri, 18 May 2018 02:48:32 -0700 (PDT) Subject: Re: [PATCH v2 2/2] KVM: arm/arm64: harden unmap_stage2_ptes in case end is not PAGE_SIZE aligned To: Jia He , Christoffer Dall , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Cc: Suzuki.Poulose@arm.com, linux-kernel@vger.kernel.org, jia.he@hxt-semitech.com References: <1526635630-18917-1-git-send-email-hejianet@gmail.com> <1526635630-18917-2-git-send-email-hejianet@gmail.com> From: Marc Zyngier Organization: ARM Ltd Message-ID: <2185a61e-c157-e177-9bad-83b6f27fd784@arm.com> Date: Fri, 18 May 2018 10:48:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <1526635630-18917-2-git-send-email-hejianet@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 18/05/18 10:27, Jia He wrote: > If it passes addr=0x202920000,size=0xfe00 to unmap_stage2_range-> > ...->unmap_stage2_ptes, unmap_stage2_ptes will get addr=0x202920000, > end=0x20292fe00. After first while loop addr=0x202930000, end=0x20292fe00, > then addr!=end. Thus it will touch another pages by put_pages() in the > 2nd loop. > > This patch fixes it by hardening the break condition of while loop. > > Signed-off-by: jia.he@hxt-semitech.com > --- > v2: newly added > > virt/kvm/arm/mmu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c > index 8dac311..45cd040 100644 > --- a/virt/kvm/arm/mmu.c > +++ b/virt/kvm/arm/mmu.c > @@ -217,7 +217,7 @@ static void unmap_stage2_ptes(struct kvm *kvm, pmd_t *pmd, > > put_page(virt_to_page(pte)); > } > - } while (pte++, addr += PAGE_SIZE, addr != end); > + } while (pte++, addr += PAGE_SIZE, addr < end); > > if (stage2_pte_table_empty(start_pte)) > clear_stage2_pmd_entry(kvm, pmd, start_addr); > I don't think this change is the right thing to do. You get that failure because you're being passed a size that is not a multiple of PAGE_SIZE. That's the mistake. You should ensure that this never happens, rather than changing the page table walkers (which are consistent with the way this kind of code is written in other places of the kernel). As you mentioned in your first patch, the real issue is that KSM is broken, and this is what should be fixed. Thanks, M. -- Jazz is not dead. It just smells funny...