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=-4.0 required=3.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS 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 2523DC07E9B for ; Tue, 20 Jul 2021 08:26:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0A2EB611EF for ; Tue, 20 Jul 2021 08:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234253AbhGTHp4 (ORCPT ); Tue, 20 Jul 2021 03:45:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:54088 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232313AbhGTHph (ORCPT ); Tue, 20 Jul 2021 03:45:37 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 57EC46101B; Tue, 20 Jul 2021 08:26:13 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1m5l4t-00ET2Y-Cp; Tue, 20 Jul 2021 09:26:11 +0100 Date: Tue, 20 Jul 2021 09:26:10 +0100 Message-ID: <875yx59ysd.wl-maz@kernel.org> From: Marc Zyngier To: Quentin Perret Cc: james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, ardb@kernel.org, qwandor@google.com, tabba@google.com, dbrazdil@google.com, kernel-team@android.com, Yanan Wang Subject: Re: [PATCH 03/14] KVM: arm64: Continue stage-2 map when re-creating mappings In-Reply-To: References: <20210719104735.3681732-1-qperret@google.com> <20210719104735.3681732-4-qperret@google.com> <87lf62jy9z.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: qperret@google.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, ardb@kernel.org, qwandor@google.com, tabba@google.com, dbrazdil@google.com, kernel-team@android.com, wangyanan55@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 19 Jul 2021 14:32:10 +0100, Quentin Perret wrote: > > On Monday 19 Jul 2021 at 13:14:48 (+0100), Marc Zyngier wrote: > > On Mon, 19 Jul 2021 11:47:24 +0100, > > Quentin Perret wrote: > > > > > > The stage-2 map walkers currently return -EAGAIN when re-creating > > > identical mappings or only changing access permissions. This allows to > > > optimize mapping pages for concurrent (v)CPUs faulting on the same > > > page. > > > > > > While this works as expected when touching one page-table leaf at a > > > time, this can lead to difficult situations when mapping larger ranges. > > > Indeed, a large map operation can fail in the middle if an existing > > > mapping is found in the range, even if it has compatible attributes, > > > hence leaving only half of the range mapped. > > > > I'm curious of when this can happen. We normally map a single leaf at > > a time, and we don't have a way to map multiple leaves at once: we > > either use the VMA base size or try to upgrade it to a THP, but the > > result is always a single leaf entry. What changed? > > Nothing _yet_ :-) > > The 'share' hypercall introduced near the end of the series allows to > share multiple physically contiguous pages in one go -- this is mostly > to allow sharing data-structures that are larger than a page. > > So if one of the pages happens to be already mapped by the time the > hypercall is issued, mapping the range with the right SW bits becomes > difficult as kvm_pgtable_stage2_map() will fail halfway through, which > is tricky to handle. > > This patch shouldn't change anything for existing users that only map > things that are nicely aligned at block/page granularity, but should > make the life of new users easier, so that seemed like a win. Right, but this is on a different path, right? Guests can never fault multiple mappings at once, and it takes you a host hypercall to perform this "multiple leaves at once". Is there any way we can restrict this to the hypercall? Or even better, keep the hypercall as a "one page at a time" thing? I can't imagine it being performance critical (it is a once-off, and only used over a rather small region of memory). Then, the called doesn't have to worry about the page already being mapped or not. This would also match the behaviour of what I do on the MMIO side. Or do you anticipate much gain from this being able to use block mappings? > > > > To avoid having to deal with such failures in the caller, don't > > > interrupt the map operation when hitting existing PTEs, but make sure to > > > still return -EAGAIN so that user_mem_abort() can mark the page dirty > > > when needed. > > > > I don't follow you here: if you return -EAGAIN for a writable mapping, > > we don't account for the page to be dirty on the assumption that > > nothing has been mapped. But if there is a way to map more than a > > single entry and to get -EAGAIN at the same time, then we're bound to > > lose data on page eviction. > > > > Can you shed some light on this? > > Sure. For guests, hitting the -EAGAIN case means we've lost the race > with another vCPU that faulted the same page. In this case the other > vCPU either mapped the page RO, which means that our vCPU will then get > a permission fault next time we run it which will lead to the page being > marked dirty, or the other vCPU mapped the page RW in which case it > already marked the page dirty for us and we can safely re-enter the > guest without doing anything else. > > So what I meant by "still return -EAGAIN so that user_mem_abort() can > mark the page dirty when needed" is "make sure to mark the page dirty > only when necessary: if winning the race and marking the page RW, or > in the permission fault path". That is, by keeping the -EAGAIN I want to > make sure we don't mark the page dirty twice. (This might fine, but this > would be new behaviour, and it was not clear that would scale well to > many vCPUs faulting the same page). > > I see how this wording can be highly confusing though, I'll and re-word > for the next version. I indeed found it pretty confusing. A reword would be much appreciated. Thanks, M. -- Without deviation from the norm, progress is not possible. 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=-4.0 required=3.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 32F69C07E95 for ; Tue, 20 Jul 2021 08:26:19 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 9D0FB611F2 for ; Tue, 20 Jul 2021 08:26:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9D0FB611F2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org 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 250AD4A4E5; Tue, 20 Jul 2021 04:26:18 -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 BgqK+2SFrrOr; Tue, 20 Jul 2021 04:26:16 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id D6AE94B0CC; Tue, 20 Jul 2021 04:26:16 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 9A43D4A4E5 for ; Tue, 20 Jul 2021 04:26:15 -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 QwNGMGb4sdrZ for ; Tue, 20 Jul 2021 04:26:14 -0400 (EDT) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 5158E4B0CA for ; Tue, 20 Jul 2021 04:26:14 -0400 (EDT) Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 57EC46101B; Tue, 20 Jul 2021 08:26:13 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1m5l4t-00ET2Y-Cp; Tue, 20 Jul 2021 09:26:11 +0100 Date: Tue, 20 Jul 2021 09:26:10 +0100 Message-ID: <875yx59ysd.wl-maz@kernel.org> From: Marc Zyngier To: Quentin Perret Subject: Re: [PATCH 03/14] KVM: arm64: Continue stage-2 map when re-creating mappings In-Reply-To: References: <20210719104735.3681732-1-qperret@google.com> <20210719104735.3681732-4-qperret@google.com> <87lf62jy9z.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: qperret@google.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, ardb@kernel.org, qwandor@google.com, tabba@google.com, dbrazdil@google.com, kernel-team@android.com, wangyanan55@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Cc: kernel-team@android.com, qwandor@google.com, will@kernel.org, catalin.marinas@arm.com, linux-kernel@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org 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 On Mon, 19 Jul 2021 14:32:10 +0100, Quentin Perret wrote: > > On Monday 19 Jul 2021 at 13:14:48 (+0100), Marc Zyngier wrote: > > On Mon, 19 Jul 2021 11:47:24 +0100, > > Quentin Perret wrote: > > > > > > The stage-2 map walkers currently return -EAGAIN when re-creating > > > identical mappings or only changing access permissions. This allows to > > > optimize mapping pages for concurrent (v)CPUs faulting on the same > > > page. > > > > > > While this works as expected when touching one page-table leaf at a > > > time, this can lead to difficult situations when mapping larger ranges. > > > Indeed, a large map operation can fail in the middle if an existing > > > mapping is found in the range, even if it has compatible attributes, > > > hence leaving only half of the range mapped. > > > > I'm curious of when this can happen. We normally map a single leaf at > > a time, and we don't have a way to map multiple leaves at once: we > > either use the VMA base size or try to upgrade it to a THP, but the > > result is always a single leaf entry. What changed? > > Nothing _yet_ :-) > > The 'share' hypercall introduced near the end of the series allows to > share multiple physically contiguous pages in one go -- this is mostly > to allow sharing data-structures that are larger than a page. > > So if one of the pages happens to be already mapped by the time the > hypercall is issued, mapping the range with the right SW bits becomes > difficult as kvm_pgtable_stage2_map() will fail halfway through, which > is tricky to handle. > > This patch shouldn't change anything for existing users that only map > things that are nicely aligned at block/page granularity, but should > make the life of new users easier, so that seemed like a win. Right, but this is on a different path, right? Guests can never fault multiple mappings at once, and it takes you a host hypercall to perform this "multiple leaves at once". Is there any way we can restrict this to the hypercall? Or even better, keep the hypercall as a "one page at a time" thing? I can't imagine it being performance critical (it is a once-off, and only used over a rather small region of memory). Then, the called doesn't have to worry about the page already being mapped or not. This would also match the behaviour of what I do on the MMIO side. Or do you anticipate much gain from this being able to use block mappings? > > > > To avoid having to deal with such failures in the caller, don't > > > interrupt the map operation when hitting existing PTEs, but make sure to > > > still return -EAGAIN so that user_mem_abort() can mark the page dirty > > > when needed. > > > > I don't follow you here: if you return -EAGAIN for a writable mapping, > > we don't account for the page to be dirty on the assumption that > > nothing has been mapped. But if there is a way to map more than a > > single entry and to get -EAGAIN at the same time, then we're bound to > > lose data on page eviction. > > > > Can you shed some light on this? > > Sure. For guests, hitting the -EAGAIN case means we've lost the race > with another vCPU that faulted the same page. In this case the other > vCPU either mapped the page RO, which means that our vCPU will then get > a permission fault next time we run it which will lead to the page being > marked dirty, or the other vCPU mapped the page RW in which case it > already marked the page dirty for us and we can safely re-enter the > guest without doing anything else. > > So what I meant by "still return -EAGAIN so that user_mem_abort() can > mark the page dirty when needed" is "make sure to mark the page dirty > only when necessary: if winning the race and marking the page RW, or > in the permission fault path". That is, by keeping the -EAGAIN I want to > make sure we don't mark the page dirty twice. (This might fine, but this > would be new behaviour, and it was not clear that would scale well to > many vCPUs faulting the same page). > > I see how this wording can be highly confusing though, I'll and re-word > for the next version. I indeed found it pretty confusing. A reword would be much appreciated. Thanks, M. -- Without deviation from the norm, progress is not possible. _______________________________________________ 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=-5.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 5C09FC07E95 for ; Tue, 20 Jul 2021 08:28:04 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 216146008E for ; Tue, 20 Jul 2021 08:28:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 216146008E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org 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=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ZbqpSj2kiPnqiVjul93JnHfFiqz++j/OGqBc9L8X1kY=; b=e2pY9POgnDH2P7 wJpfunXxxx99wFHWNwQIF1vUMa1oAt0TDWCAhRpvcX+c9OA/wWk7XnehHO4Pbwa2lglkG+Yybt70L g4geDyQsNsG2jJvGj0M4ALlumfF5I9k4adPjVFrUhBjHcpfIRj83CZ+UxPGOWaDg7n75uQp4/+IQv EbTyu4avEIbldEarTp6vm+lT+b0zRd2oR3R6YMn3BE5sza73e6dA16JL1Bgl2AZzqCxMcmH9qnY6T ZmyDzAKFZZ6mQd7nEoCgvUafmG71/tx8Lx593+xyPtfql2ay6mklSqBPawLDNSwlBcjCbgRdaGtPw mYAUBFKrjd2zzAAZbsUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m5l4z-00CDIT-Rl; Tue, 20 Jul 2021 08:26:18 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m5l4v-00CDHk-KG for linux-arm-kernel@lists.infradead.org; Tue, 20 Jul 2021 08:26:15 +0000 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 57EC46101B; Tue, 20 Jul 2021 08:26:13 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1m5l4t-00ET2Y-Cp; Tue, 20 Jul 2021 09:26:11 +0100 Date: Tue, 20 Jul 2021 09:26:10 +0100 Message-ID: <875yx59ysd.wl-maz@kernel.org> From: Marc Zyngier To: Quentin Perret Cc: james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, ardb@kernel.org, qwandor@google.com, tabba@google.com, dbrazdil@google.com, kernel-team@android.com, Yanan Wang Subject: Re: [PATCH 03/14] KVM: arm64: Continue stage-2 map when re-creating mappings In-Reply-To: References: <20210719104735.3681732-1-qperret@google.com> <20210719104735.3681732-4-qperret@google.com> <87lf62jy9z.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: qperret@google.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, ardb@kernel.org, qwandor@google.com, tabba@google.com, dbrazdil@google.com, kernel-team@android.com, wangyanan55@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210720_012613_744591_AEBAC4DD X-CRM114-Status: GOOD ( 49.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 On Mon, 19 Jul 2021 14:32:10 +0100, Quentin Perret wrote: > > On Monday 19 Jul 2021 at 13:14:48 (+0100), Marc Zyngier wrote: > > On Mon, 19 Jul 2021 11:47:24 +0100, > > Quentin Perret wrote: > > > > > > The stage-2 map walkers currently return -EAGAIN when re-creating > > > identical mappings or only changing access permissions. This allows to > > > optimize mapping pages for concurrent (v)CPUs faulting on the same > > > page. > > > > > > While this works as expected when touching one page-table leaf at a > > > time, this can lead to difficult situations when mapping larger ranges. > > > Indeed, a large map operation can fail in the middle if an existing > > > mapping is found in the range, even if it has compatible attributes, > > > hence leaving only half of the range mapped. > > > > I'm curious of when this can happen. We normally map a single leaf at > > a time, and we don't have a way to map multiple leaves at once: we > > either use the VMA base size or try to upgrade it to a THP, but the > > result is always a single leaf entry. What changed? > > Nothing _yet_ :-) > > The 'share' hypercall introduced near the end of the series allows to > share multiple physically contiguous pages in one go -- this is mostly > to allow sharing data-structures that are larger than a page. > > So if one of the pages happens to be already mapped by the time the > hypercall is issued, mapping the range with the right SW bits becomes > difficult as kvm_pgtable_stage2_map() will fail halfway through, which > is tricky to handle. > > This patch shouldn't change anything for existing users that only map > things that are nicely aligned at block/page granularity, but should > make the life of new users easier, so that seemed like a win. Right, but this is on a different path, right? Guests can never fault multiple mappings at once, and it takes you a host hypercall to perform this "multiple leaves at once". Is there any way we can restrict this to the hypercall? Or even better, keep the hypercall as a "one page at a time" thing? I can't imagine it being performance critical (it is a once-off, and only used over a rather small region of memory). Then, the called doesn't have to worry about the page already being mapped or not. This would also match the behaviour of what I do on the MMIO side. Or do you anticipate much gain from this being able to use block mappings? > > > > To avoid having to deal with such failures in the caller, don't > > > interrupt the map operation when hitting existing PTEs, but make sure to > > > still return -EAGAIN so that user_mem_abort() can mark the page dirty > > > when needed. > > > > I don't follow you here: if you return -EAGAIN for a writable mapping, > > we don't account for the page to be dirty on the assumption that > > nothing has been mapped. But if there is a way to map more than a > > single entry and to get -EAGAIN at the same time, then we're bound to > > lose data on page eviction. > > > > Can you shed some light on this? > > Sure. For guests, hitting the -EAGAIN case means we've lost the race > with another vCPU that faulted the same page. In this case the other > vCPU either mapped the page RO, which means that our vCPU will then get > a permission fault next time we run it which will lead to the page being > marked dirty, or the other vCPU mapped the page RW in which case it > already marked the page dirty for us and we can safely re-enter the > guest without doing anything else. > > So what I meant by "still return -EAGAIN so that user_mem_abort() can > mark the page dirty when needed" is "make sure to mark the page dirty > only when necessary: if winning the race and marking the page RW, or > in the permission fault path". That is, by keeping the -EAGAIN I want to > make sure we don't mark the page dirty twice. (This might fine, but this > would be new behaviour, and it was not clear that would scale well to > many vCPUs faulting the same page). > > I see how this wording can be highly confusing though, I'll and re-word > for the next version. I indeed found it pretty confusing. A reword would be much appreciated. Thanks, M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel