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=-6.1 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 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 AF34EC433E2 for ; Fri, 28 Aug 2020 15:42:32 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 35604208D5 for ; Fri, 28 Aug 2020 15:42:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 35604208D5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.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 AC5F74BD7F; Fri, 28 Aug 2020 11:42:31 -0400 (EDT) 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 E6VVtXBkQLnZ; Fri, 28 Aug 2020 11:42:30 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 745D74BCD6; Fri, 28 Aug 2020 11:42:30 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id A90194BBCB for ; Fri, 28 Aug 2020 11:42:29 -0400 (EDT) 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 xEy76s+Cv9xS for ; Fri, 28 Aug 2020 11:42:28 -0400 (EDT) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 94D8D4BA1E for ; Fri, 28 Aug 2020 11:42:28 -0400 (EDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D73C5D6E; Fri, 28 Aug 2020 08:42:27 -0700 (PDT) Received: from [192.168.0.110] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F1F253F71F; Fri, 28 Aug 2020 08:42:26 -0700 (PDT) Subject: Re: [PATCH v3 02/21] KVM: arm64: Add stand-alone page-table walker infrastructure From: Alexandru Elisei To: Will Deacon , kvmarm@lists.cs.columbia.edu References: <20200825093953.26493-1-will@kernel.org> <20200825093953.26493-3-will@kernel.org> <9de812eb-1067-08bf-69cd-eb205dfbda35@arm.com> Message-ID: Date: Fri, 28 Aug 2020 16:43:20 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <9de812eb-1067-08bf-69cd-eb205dfbda35@arm.com> Content-Language: en-US Cc: Marc Zyngier , kernel-team@android.com, linux-arm-kernel@lists.infradead.org, Catalin Marinas 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 Hi, I've had another good look at the code, and I now I can answer some of my own questions. Sorry for the noise! On 8/27/20 5:27 PM, Alexandru Elisei wrote: > [..] > + > + if (!table) { > + data->addr += kvm_granule_size(level); > + goto out; > + } > + > + childp = kvm_pte_follow(pte); > + ret = __kvm_pgtable_walk(data, childp, level + 1); > + if (ret) > + goto out; > + > + if (flags & KVM_PGTABLE_WALK_TABLE_POST) { > We check that ptep is a valid table when we test the KVM_PGTABLE_WALK_TABLE_PRE > flag, why aren't we doing that here? That's because the function goes to out if the leaf visitor didn't turn the leaf entry into a table. > >> + ret = kvm_pgtable_visitor_cb(data, addr, level, ptep, >> + KVM_PGTABLE_WALK_TABLE_POST); >> + } >> + >> +out: >> + return ret; >> +} >> + >> [..] >> +} >> + >> +static int _kvm_pgtable_walk(struct kvm_pgtable_walk_data *data) >> +{ >> + u32 idx; >> + int ret = 0; >> + struct kvm_pgtable *pgt = data->pgt; >> + u64 limit = BIT(pgt->ia_bits); >> + >> + if (data->addr > limit || data->end > limit) >> + return -ERANGE; >> + >> + if (!pgt->pgd) >> + return -EINVAL; >> + >> + for (idx = kvm_pgd_page_idx(data); data->addr < data->end; ++idx) { >> + kvm_pte_t *ptep = &pgt->pgd[idx * PTRS_PER_PTE]; > I'm sorry, but I just don't understand this part: > > - Why do we skip over PTRS_PER_PTE instead of visiting each idx? > > - Why do we use PTRS_PER_PTE instead of PTRS_PER_PGD? > > Would you mind explaining what the loop is doing? > > I also don't see anywhere in the page table walking code where we take into > account that we can have concatenated tables at level 1 or 2, which means we have > more entries than PTRS_PER_P{U,M}D. I think I understand the code better now, __kvm_pgtable_walk will visit all entries in the range ptep[0..PTRS_PER_PTE-1], that's why every iteration we increment by PTRS_PER_PTE. > >> + >> + ret = __kvm_pgtable_walk(data, ptep, pgt->start_level); >> + if (ret) >> + break; >> + } >> + >> + return ret; >> +} >> + >> +int kvm_pgtable_walk(struct kvm_pgtable *pgt, u64 addr, u64 size, >> + struct kvm_pgtable_walker *walker) >> +{ >> + struct kvm_pgtable_walk_data walk_data = { >> + .pgt = pgt, >> + .addr = ALIGN_DOWN(addr, PAGE_SIZE), >> + .end = PAGE_ALIGN(walk_data.addr + size), > [..] > > What happens if addr < PAGE_SIZE - 1? It looks to me that according to the > definition of ALIGN_DOWN, addr will wrap around. My mistake again, ALIGN_DOWN will subtract PAGE_SIZE - 1, but __ALIGN_KERNEL will add PAGE_SIZE - 1, and the result is what we expect (no wrapping around). Thanks, Alex _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm 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=-7.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 0422CC433E6 for ; Fri, 28 Aug 2020 15:44:56 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C62F8208D5 for ; Fri, 28 Aug 2020 15:44:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="A4+44A4f" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C62F8208D5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:References: To:From:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=IbnaKXH1NsDvZ2FGtx9CgL4WsB+WwXn90S4bCbrnahU=; b=A4+44A4fHonhsZSiW+27Ilwmk GlKrhPgvzsQv+ahXELykTayiKz25tVtIfZFo+p9O8/3j6b2llPuZ/dfCbauT0xvNCQZfMxv0m4m45 6bmcSnY5tptaspxe8FhwAdjJ6Dz+atqWuqkH1CBJI0iu0oUsr6wW2bAwGpJ4Yegbb8AGf8rUJU6yT Hs37HuPzaBCw++UV10edN471OXm7b/7VulCnUVS/ieD6gC3x5iu35QKN7pctyZxvBFKYB3GVCipul rwFNRm7oiMsijBiCzG7XUUu1nEVAPhaJxXM7fYfPoBQsrm9GEE6s8Sz+GJ5Zh6rWfw0xY6l0s4IRs fLzvYTD0Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBgWO-0004XJ-HP; Fri, 28 Aug 2020 15:42:32 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBgWL-0004WY-AR for linux-arm-kernel@lists.infradead.org; Fri, 28 Aug 2020 15:42:30 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D73C5D6E; Fri, 28 Aug 2020 08:42:27 -0700 (PDT) Received: from [192.168.0.110] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F1F253F71F; Fri, 28 Aug 2020 08:42:26 -0700 (PDT) Subject: Re: [PATCH v3 02/21] KVM: arm64: Add stand-alone page-table walker infrastructure From: Alexandru Elisei To: Will Deacon , kvmarm@lists.cs.columbia.edu References: <20200825093953.26493-1-will@kernel.org> <20200825093953.26493-3-will@kernel.org> <9de812eb-1067-08bf-69cd-eb205dfbda35@arm.com> Message-ID: Date: Fri, 28 Aug 2020 16:43:20 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <9de812eb-1067-08bf-69cd-eb205dfbda35@arm.com> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200828_114229_444843_D858F48F X-CRM114-Status: GOOD ( 25.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marc Zyngier , kernel-team@android.com, linux-arm-kernel@lists.infradead.org, Catalin Marinas Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, I've had another good look at the code, and I now I can answer some of my own questions. Sorry for the noise! On 8/27/20 5:27 PM, Alexandru Elisei wrote: > [..] > + > + if (!table) { > + data->addr += kvm_granule_size(level); > + goto out; > + } > + > + childp = kvm_pte_follow(pte); > + ret = __kvm_pgtable_walk(data, childp, level + 1); > + if (ret) > + goto out; > + > + if (flags & KVM_PGTABLE_WALK_TABLE_POST) { > We check that ptep is a valid table when we test the KVM_PGTABLE_WALK_TABLE_PRE > flag, why aren't we doing that here? That's because the function goes to out if the leaf visitor didn't turn the leaf entry into a table. > >> + ret = kvm_pgtable_visitor_cb(data, addr, level, ptep, >> + KVM_PGTABLE_WALK_TABLE_POST); >> + } >> + >> +out: >> + return ret; >> +} >> + >> [..] >> +} >> + >> +static int _kvm_pgtable_walk(struct kvm_pgtable_walk_data *data) >> +{ >> + u32 idx; >> + int ret = 0; >> + struct kvm_pgtable *pgt = data->pgt; >> + u64 limit = BIT(pgt->ia_bits); >> + >> + if (data->addr > limit || data->end > limit) >> + return -ERANGE; >> + >> + if (!pgt->pgd) >> + return -EINVAL; >> + >> + for (idx = kvm_pgd_page_idx(data); data->addr < data->end; ++idx) { >> + kvm_pte_t *ptep = &pgt->pgd[idx * PTRS_PER_PTE]; > I'm sorry, but I just don't understand this part: > > - Why do we skip over PTRS_PER_PTE instead of visiting each idx? > > - Why do we use PTRS_PER_PTE instead of PTRS_PER_PGD? > > Would you mind explaining what the loop is doing? > > I also don't see anywhere in the page table walking code where we take into > account that we can have concatenated tables at level 1 or 2, which means we have > more entries than PTRS_PER_P{U,M}D. I think I understand the code better now, __kvm_pgtable_walk will visit all entries in the range ptep[0..PTRS_PER_PTE-1], that's why every iteration we increment by PTRS_PER_PTE. > >> + >> + ret = __kvm_pgtable_walk(data, ptep, pgt->start_level); >> + if (ret) >> + break; >> + } >> + >> + return ret; >> +} >> + >> +int kvm_pgtable_walk(struct kvm_pgtable *pgt, u64 addr, u64 size, >> + struct kvm_pgtable_walker *walker) >> +{ >> + struct kvm_pgtable_walk_data walk_data = { >> + .pgt = pgt, >> + .addr = ALIGN_DOWN(addr, PAGE_SIZE), >> + .end = PAGE_ALIGN(walk_data.addr + size), > [..] > > What happens if addr < PAGE_SIZE - 1? It looks to me that according to the > definition of ALIGN_DOWN, addr will wrap around. My mistake again, ALIGN_DOWN will subtract PAGE_SIZE - 1, but __ALIGN_KERNEL will add PAGE_SIZE - 1, and the result is what we expect (no wrapping around). Thanks, Alex _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel