Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp578833imm; Fri, 8 Jun 2018 01:35:25 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKb2qUa982Nwz30u6MruCyNN/M5/iu0s/oTN8uGcOiT5fZ7JWRbsdQ5t4N4YWtw+n2RkJ6O X-Received: by 2002:a62:c809:: with SMTP id z9-v6mr5024430pff.5.1528446925329; Fri, 08 Jun 2018 01:35:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528446925; cv=none; d=google.com; s=arc-20160816; b=N56pqeO+vnEw6Nmn3AjE/kzGqdGLiY3uZJLv4LcmaP8z7yum+7K5ARcS6dBUT1yG47 /eO3rtgQfVnm3HyCfOnNLgEfRIi3vvN7FvJbShY+h39DgqmU76VzK0bLW+jnl+4+oVqC oA0umj7uS7i5t1y12rOTahjeQncfZwkgGJlJOXuVJhIQ8JshuTGiD3/9eaxfWGXOxgVv QIuL7BvzMn3LK1jNaUv3CqQBpjPJ8h4Uabol/54/cfhbCR/tTDeXzSh0+824kX6nru3T t9WNFtmgnGCOFWBRGZIEygmsYyZ6wvIgUd7eL0vedMc8UCxC3wvhHJfeZI9DG++7HF13 /ZRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=/VdcuMe6abF126z1z43acHYcuq6Tvac+vbnA6Lbxoxo=; b=zMkmTShl0EtYfaMenViOs8mhOdXdkCdfUV1is61zjKFxU+I/IMy4Q0G+Y9/2lsjEKw x/7dYektTNxDvo2e0cLQ2uGinTqeeLA13uIbN109O8gVYvdQNz7h5fwurNy0vPA4PvXH oUZihLlWdWs4Rh5CmAi2jKWjyDFwjTexyq9tpXTnPwQW5D4u1dyqQkm7NBAn8XY94YuE 0DjiZTJSAwgzhvkJAOuof96/LvDKtKNUM793ON+E25DplaAD4ysBcIxdR+1DE+Oc+J12 Hk1UHcOUbjsBi0hjr/VZmgDfQBMU0U15TvTMG2qcye0Sy650BaNv1N/suTOt/siL7lEe vziA== 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 y34-v6si56173533plb.17.2018.06.08.01.35.10; Fri, 08 Jun 2018 01:35:25 -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 S1752793AbeFHIeT (ORCPT + 99 others); Fri, 8 Jun 2018 04:34:19 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:59526 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751571AbeFHIeR (ORCPT ); Fri, 8 Jun 2018 04:34:17 -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 598671529; Fri, 8 Jun 2018 01:34:17 -0700 (PDT) Received: from localhost (unknown [10.37.8.155]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B7B7E3F557; Fri, 8 Jun 2018 01:34:16 -0700 (PDT) Date: Fri, 8 Jun 2018 10:34:14 +0200 From: Christoffer Dall To: Jia He Cc: Marc Zyngier , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, Suzuki.Poulose@arm.com, linux-kernel@vger.kernel.org, jia.he@hxt-semitech.com Subject: Re: [PATCH v2 2/2] KVM: arm/arm64: harden unmap_stage2_ptes in case end is not PAGE_SIZE aligned Message-ID: <20180608083414.GA5097@C02W217FHV2R.local> References: <1526635630-18917-1-git-send-email-hejianet@gmail.com> <1526635630-18917-2-git-send-email-hejianet@gmail.com> <2185a61e-c157-e177-9bad-83b6f27fd784@arm.com> <50c98169-1606-48bf-0489-124adefd2a54@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <50c98169-1606-48bf-0489-124adefd2a54@gmail.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 18, 2018 at 09:04:40PM +0800, Jia He wrote: > > > On 5/18/2018 5:48 PM, Marc Zyngier Wrote: > > 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. > > > Got it, thanks > Should I resend the patch 1/2 without any changes after droping patch 2/2? > That's fine if you trim the commit message to make it look nicer. Also, in the future, please include a cover letter if you send more than one patch to the list. Thanks, -Christoffer