Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp598776imm; Fri, 8 Jun 2018 02:00:53 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLE7carK2+Q+D29w2/KjpCaDWY4M4s5Mf6Xv9qRGESlshxub/W22VrcLNy9JyuV/mA64XLG X-Received: by 2002:a17:902:369:: with SMTP id 96-v6mr5758123pld.64.1528448453676; Fri, 08 Jun 2018 02:00:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528448453; cv=none; d=google.com; s=arc-20160816; b=BTvzFRcjxrzR+9rRD7YVk605CXgldW+R9JSA+bxnVB25FNLgkJ8dgdC3vfaG+2Y28l BOWqT/prdLdEbcgP0xLGerP1j08S6Lz9dNz865vTSpTsp3pu5TjkkF6l6ClFJcsU/aQg kT/XXZYCkRsIyfMfBIWc3qJWKdOHb/a7BZq4XHBybso6njNq+9FnYvpOS0Dfvw0kMNR8 Sk8snjveTMAnwqNMIbjhyNMOn1Vq9hhVLwNTcxZoBshLlNtl23IbHUMasBuNpvaaIcxe kLtmaC/t0AIPhRBK6Ze+CaSLK4/GtxTAJaPShODhTr6dh5l9TNmpyIlJXQE5i9AeS4HB iacw== 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:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject:dkim-signature:arc-authentication-results; bh=4uBFP2hS65FbtUc3YZ5P/sJMZzF6S3m1oX1+dLdnPwU=; b=zM9X9Xfu+wn0SEwS3Av2kdoGSqJM2gkcWLMZAxjioShnLueVduhkPd8QFCp0aOF4EG QSqKvEKU9n/X3CdNReVu0A13CC7QzB8trcMneY86uoO3B5vtGffa6sGZcjqSHSscS+kE sGncgutTL37P7Le7fldJBrZHu10mwJ/zoJznkCnQ/QtcSeZGtW89YEjsQHwRj++7t7p7 qJrUcwDihXHnR09Lp7h8XI6oL21v7AiGuURsV6fjy58dzD9r6NEWJgpGCwKuNqqzQ/3B mERCs3oCQCI9EwkGSdNdOgbn++2wgcjinwHZsLP8xLqac45S/2Wt5CGqqwPsKLuEigF3 pdWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gxz3qZ5i; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f2-v6si9516548pgq.165.2018.06.08.02.00.38; Fri, 08 Jun 2018 02:00:53 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gxz3qZ5i; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751133AbeFHI7x (ORCPT + 99 others); Fri, 8 Jun 2018 04:59:53 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:40030 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750977AbeFHI7u (ORCPT ); Fri, 8 Jun 2018 04:59:50 -0400 Received: by mail-pl0-f67.google.com with SMTP id t12-v6so7909974plo.7 for ; Fri, 08 Jun 2018 01:59:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=4uBFP2hS65FbtUc3YZ5P/sJMZzF6S3m1oX1+dLdnPwU=; b=gxz3qZ5i4nd9DW3NkqovUsA5H86Vs1CGWz2+jclcpo5CT7eM7Ieu4Lub//SfFIjAik G76FP9MbSxsYYbdKFdaHp1C7VmgvyxxQah76s4pXbmpkZcIGmJ1pRrF0ZcWWcYYoqNOo iTAshy3OcxGiLKtZcWmo9Mr9VBDNi+dD8YNQVKJQsRVr1WiMTWGlz6lvIxXBDaTIb7Lw cYpNMyisAjtPXTZrrra50ZnHK0jc3gjAKPtvmrIPf5y7IT1LGK4+/XOy9DupDgvZGYc8 keIfdoYOI9/iRKXvBWBXV2Xv2DhegCusoO8mfM2fDSWhOovbnR6fdC6+qARnWP98euwa ys7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=4uBFP2hS65FbtUc3YZ5P/sJMZzF6S3m1oX1+dLdnPwU=; b=oR8nTqmCVUd86uAM4o3bq75acCiS+ZW9k1fz8owy7kONR89c+4sTnjXmg1Ewcjwyby HA7LqOT1jhs/jYPsn2RXS34RRSd79ooPatdMPo4jftqOn+65JuyI+cY7s20vdzDX9R8S OLHkt7LckgebT3mD6vE++7M9cA2yJ3T4cyOn93sDqK36pRIt1lNrX2unxjjMkdSHoed/ ijvSBqvQPDHtjE/7bSHpC9f4J7PJmcIKKXY9c7nBCi9S3i8yE4fBkLtJfhcyyUOLikRU ylwpGhHfPPR0LdATb8iC7qU/ulesA8CDoPyHy29pusXsJsv0nR/LMjpdHk7juHrxSNMn Brvw== X-Gm-Message-State: APt69E2hz8V+SXEqrdHug/c1SdH41956V4jyMw/2/xVMTx5d//JcUUBG PBTzbDo5QtC6jN/dlJw9Ajw= X-Received: by 2002:a17:902:7c84:: with SMTP id y4-v6mr5805502pll.262.1528448390005; Fri, 08 Jun 2018 01:59:50 -0700 (PDT) Received: from [0.0.0.0] (67.216.217.169.16clouds.com. [67.216.217.169]) by smtp.gmail.com with ESMTPSA id d88-v6sm45059475pfb.43.2018.06.08.01.59.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Jun 2018 01:59:49 -0700 (PDT) Subject: Re: [PATCH v2 2/2] KVM: arm/arm64: harden unmap_stage2_ptes in case end is not PAGE_SIZE aligned To: Christoffer Dall 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 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> <20180608083414.GA5097@C02W217FHV2R.local> From: Jia He Message-ID: <42df5a9e-23bc-79ac-3d10-66da9f05c0ca@gmail.com> Date: Fri, 8 Jun 2018 16:59:42 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180608083414.GA5097@C02W217FHV2R.local> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Christoffer I ever sent out the v3 patch set with the single patch 1/2 [link] https://patchwork.kernel.org/patch/10413803/ Sorry,I ping-ed the wrong mail thread ;-). Cheers, Jia On 6/8/2018 4:34 PM, Christoffer Dall Wrote: > 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 >