Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3958650imm; Thu, 17 May 2018 18:54:32 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo4BYG0ry02Sk6DM4q/2Aw4KxvF2sQFh8aFnBY998Yn3uLs2oC5dstlCbJ9wdobF6/l/cMo X-Received: by 2002:a62:de02:: with SMTP id h2-v6mr7373531pfg.205.1526608472193; Thu, 17 May 2018 18:54:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526608472; cv=none; d=google.com; s=arc-20160816; b=onZGy3awAARphLohIlWtXkSzE8yiU1QhzFTpEKG8nA2wsZ4dxJNTWlkk0sCteNZovM eJHogeVm38LUa+PGANxCypq/5bs6FnzKYMPe/evGQyExflWqDhXjDlZMkS9vwZAMs4Q+ 2lX/GlQhD0YvNX7tiJbBJ4MnD9DJGj/zKEHipzLOV1ukvOpu4vK1L49SWzQ5Gl130Awk NkZxoA4B99BpjW1CUrQ5WOucBNfw3M777bWNaj5tkfN14iv0fL60HreIg/3ISKvzFcIy yGG9Tiz26cWD0khaIptDdsHoza1qLtfpuYFBqTmO2uSVoHJS0ynkH0WgVg/Wq5YNj8B7 HXHg== 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=W4YomoKRmHeN0OrN8VA1EiXuy2LDJKd1mSHOAtrxydo=; b=DOjTXpYBJ0yYw+udE6kakgfRWh/16Zx3rMr8a6ILsXpU1BIpuXQpj266dqIFHYZUGc MWAS2mbdea6Zvy3gMidH7Crg5bDHl0HQyNDuMpSEQcvxU+FKamcOvnpp1ovXo+Rc5bdL F1pK7ecutjnVnNv4ijoKx/oC9pwI4TsgEd+ygqm+qfSW74yd2mUYtCgabis0n2wZ5YiD ntNLcwP1PXOJaoUErMiVAmHSl8hSWEqvJikBOPankg4yjEyGDY9yz21tn/i5mVZ8EQJ8 qOfkVDzfr6zbXns8rP7ol9w7DEdamTLtzVmXmtJ9ISXXgVY0AoeD20qHSESJf1NrMbdJ pZfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cDq+zPEs; 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 s66-v6si6538205pfj.164.2018.05.17.18.54.18; Thu, 17 May 2018 18:54:32 -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=cDq+zPEs; 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 S1752044AbeERBwl (ORCPT + 99 others); Thu, 17 May 2018 21:52:41 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:40819 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751695AbeERBwk (ORCPT ); Thu, 17 May 2018 21:52:40 -0400 Received: by mail-pl0-f68.google.com with SMTP id t12-v6so3620389plo.7 for ; Thu, 17 May 2018 18:52:40 -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=W4YomoKRmHeN0OrN8VA1EiXuy2LDJKd1mSHOAtrxydo=; b=cDq+zPEsvBiLs2ra+MD8LOSgRm3cCw9pbKtUMo7HkUye/BdKTEclwdTiGbGAN78gZk c/6KMqN9QIUcsKm+3CVLLGf+IuIAYxrBUFPpcvz2wKJ/ycsoqPodKOl6xazPXC26qapp IzAPG4k8Oobrdt1RusI3Q5iZ1V6qEDbFP2/qmG8GGJ8X1Ih3jhwD/EBphLKUfohZp+mn 2pCXXPAnmbvKSjmZ2PTxQDwibf8kRKERZlKFiJwxLVujq6iGqoovD1IWJ1swJjz6opEL o6i2yt958vLUCOQ4GxVkygA0wNni1h5W37wIPaJYLCru160Qnd1ypC7EanLZYP4eK4xs HPQA== 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=W4YomoKRmHeN0OrN8VA1EiXuy2LDJKd1mSHOAtrxydo=; b=q//LtXtuPRLxsctjwuO6W02aZ0DbufgxpecU+D2VSUSVATlAjRgez3o5pys2LDomTV XalL16Rmq4jWOun8Sj4FZlD9fLbJwMaxFICyykvF+0bduf7iipRr0IYVcmOyEm94FUC2 dzDHwl6ODINg2Hn87cMMAIt7sgQjh51ZFJpy490m3ocawZb2UkwVMhagImxGURFIliBE s9WNiVnZq7C83yJt/Wae4NpM7qg07I/X0eM6Qc9C0ntowr/WO+MXQ1uNMRCfgzabhg82 ArRMGC5bjMNZLH+pkqEpKe/uhGo2PAyVruEYfBJ78qRtceldrgll4RgqomrMCA0wHFAE vJsA== X-Gm-Message-State: ALKqPweCyh1gehZU2cstcMvRxdZLdpijNHf0JzL0OTCP6AXDr2rSELHi ek8vQMljdBOSRpCOInreYD4= X-Received: by 2002:a17:902:780a:: with SMTP id p10-v6mr7500643pll.281.1526608359938; Thu, 17 May 2018 18:52:39 -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 r20-v6sm11920728pff.152.2018.05.17.18.52.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 May 2018 18:52:38 -0700 (PDT) Subject: Re: [PATCH] KVM: arm/arm64: add WARN_ON if size is not PAGE_SIZE aligned in unmap_stage2_range To: Suzuki K Poulose , Christoffer Dall , Marc Zyngier , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Cc: Andrew Morton , Andrea Arcangeli , Claudio Imbrenda , Arvind Yadav , "David S. Miller" , Minchan Kim , Mike Rapoport , Hugh Dickins , "Paul E. McKenney" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, jia.he@hxt-semitech.com References: <1526537487-14804-1-git-send-email-hejianet@gmail.com> <698b0355-d430-86b8-cd09-83c6d9e566f8@arm.com> <25dbb8c1-631f-c810-4d75-349a0b291cf8@arm.com> From: Jia He Message-ID: <551c4ecc-412a-7087-8664-6e4b213bca17@gmail.com> Date: Fri, 18 May 2018 09:52:27 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <25dbb8c1-631f-c810-4d75-349a0b291cf8@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Suzuki On 5/17/2018 11:03 PM, Suzuki K Poulose Wrote: > On 17/05/18 13:46, Jia He wrote: >> Hi Suzuki >> >> On 5/17/2018 4:17 PM, Suzuki K Poulose Wrote: >>> >>> Hi Jia, >>> >>> On 17/05/18 07:11, Jia He wrote: >>>> I ever met a panic under memory pressure tests(start 20 guests and run >>>> memhog in the host). >>> >>> Please avoid using "I" in the commit description and preferably stick to >>> an objective description. >> >> Thanks for the pointing >> >>> >>>> >>>> The root cause might be what I fixed at [1]. But from arm kvm points of >>>> view, it would be better we caught the exception earlier and clearer. >>>> >>>> If the size is not PAGE_SIZE aligned, unmap_stage2_range might unmap the >>>> wrong(more or less) page range. Hence it caused the "BUG: Bad page >>>> state" >>> >>> I don't see why we should ever panic with a "positive" size value. Anyways, >>> the unmap requests must be in units of pages. So this check might be useful. >>> >>> >> >> good question, >> >> After further digging, maybe we need to harden the break condition as below? >> diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c >> index 7f6a944..dac9b2e 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); > > I don't think this change is need as stage2_pgd_addr_end(addr, end) must return > the smaller of the next entry or end. Thus we can't miss "addr" == "end". If it passes addr=202920000,size=fe00 to unmap_stage2_range-> ...->unmap_stage2_ptes unmap_stage2_ptes will get addr=202920000,end=20292fe00 after first while loop addr=202930000, end=20292fe00, then addr!=end Thus it will touch another pages by put_pages() in the 2nd loop. -- Cheers, Jia