Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp833070rdg; Fri, 13 Oct 2023 02:29:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG/tWo1urpZldfc9O+eLyFNzdh0X7Y4+0+bKIDbTouRipoPJnStTJ8g3cfBtgGaWNl3j+bc X-Received: by 2002:a05:6a21:a58f:b0:169:cd02:65e9 with SMTP id gd15-20020a056a21a58f00b00169cd0265e9mr31115181pzc.33.1697189398248; Fri, 13 Oct 2023 02:29:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697189398; cv=none; d=google.com; s=arc-20160816; b=AjzcjmgaLZQuvuBN8cGipXcssUtUCPoGBSLAzy6EKfDvl7gTnAGBbQPsncBJo/Kdj/ oZVPJESD97/HhhFZaHizY5S6FVa9Wp1HMCq3fDme6SRNLrxXuyM9ENIrd7ehBI8wQbGn nWxUw8oxbybb9WkAFDhsfO68GmF041FNYBgHVgoSkrp6cAelhIz/0ADf6NWjhHz9lJGq M5o2j6lXB2EUrabnUCfmDpJmcqK4Ok6zsSnDgWUjn03+4fKsbKb70EGXWRoAnia8k+fN VUjZoEXJgmlbZoeClc1jsNY3ZdqrtwQAuGkkFf3/8/uzbzODkSShm8b1YacIXMlKu08B rgJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=y7+MRnXo7Mj1uSrB84r5+mLO22LF8JjgCAv2rFOirqU=; fh=10K+fIoA4tSC1+OqRth9DXOttzjE+U3XgycKcu2PfjY=; b=RGs6UAbv3+Tm2p3uWUJYYvI3ONqnMcv8mtirY6ezWqTbl5Co6VB3VuNK/8aRjcC+33 OhHOwC1AAGqxKuQg/XFK3GDv5pGTuJatQFRdVO0VrPMBO6agmLf8TPc1XBMjEGaCqCfa udMcbWyVvT65kX4tnXJsrB9sALpBWfM6HOKLQR+MTzTToBrIqo52F6AqbCYUqYUnCJXa CjJKvwdwSeJmjPZqRZuRsa0MDZOz+FCVnYPiEjehY0iHnkjIF47vMuSmhbuDBXTDJ7ro NjaN70QZnVwg7d+HgxPtRU/7bPHGot4W4FkjLhzJKQRrRBOJv3Vdo+FgzRHrjta8HxD2 uxGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QaoND89a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id t14-20020a1709027fce00b001c9af74feaesi4075733plb.215.2023.10.13.02.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 02:29:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QaoND89a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 870CE81C46C9; Fri, 13 Oct 2023 02:29:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230475AbjJMJ3p (ORCPT + 99 others); Fri, 13 Oct 2023 05:29:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230480AbjJMJ3o (ORCPT ); Fri, 13 Oct 2023 05:29:44 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F126C9 for ; Fri, 13 Oct 2023 02:29:42 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7E27C433C7; Fri, 13 Oct 2023 09:29:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697189381; bh=2Rtv1hzWn9/y5luZPHjn/Ic4VtigUzkY4Y2DYOUlc8U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QaoND89a9vi3ZXr6GSrmL8UktsMjOiSrY0ZwSAOnirchlhVifYz9y9EGAj4vFUt8h WeAMvzDB1iv7KJQq0vSvyFfXupghD1FVRTOhUSoLgNR9tPX2jGw+fT4kGHRjFvRufi PQXMYXA2UCk6PXyaigXfP9TNjz4sQjwHjU3Uf94QfUa/kaYMkcSPf4Fenr0mUiHE4c lrUGr2bUcGKkejYqt9LrTvQ1MwQuDuEaA+CCkHg263bVGKA2eynMYMWK1TdEMdk8XX KM7637wC5U2JqHdcz8pDhIGnYwnzH9f2elCzpCktDdfAn0snExum2Z2A1ZQTntPxP5 dknYMH/Mxq7gA== Date: Fri, 13 Oct 2023 10:29:35 +0100 From: Will Deacon To: Catalin Marinas Cc: Lorenzo Pieralisi , Jason Gunthorpe , ankita@nvidia.com, maz@kernel.org, oliver.upton@linux.dev, aniketa@nvidia.com, cjia@nvidia.com, kwankhede@nvidia.com, targupta@nvidia.com, vsethi@nvidia.com, acurrid@nvidia.com, apopple@nvidia.com, jhubbard@nvidia.com, danw@nvidia.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1 2/2] KVM: arm64: allow the VM to select DEVICE_* and NORMAL_NC for IO memory Message-ID: <20231013092934.GA13524@willie-the-truck> References: <20231012123541.GB11824@willie-the-truck> <20231012144807.GA12374@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 13 Oct 2023 02:29:55 -0700 (PDT) On Thu, Oct 12, 2023 at 06:26:01PM +0100, Catalin Marinas wrote: > On Thu, Oct 12, 2023 at 03:48:08PM +0100, Will Deacon wrote: > > Claiming back the device also seems strange if the guest has been using > > non-cacheable accesses since I think you could get write merging and > > reordering with subsequent device accesses trying to reset the device. > > True. Not sure we have a good story here (maybe reinvent the DWB barrier ;)). We do have a good story for this part: use Device-nGnRE! > > > So, for now I'd only relax this if we know there's RAM(-like) on the > > > other side and won't trigger some potentially uncontainable errors as a > > > result. > > > > I guess my wider point is that I'm not convinced that non-cacheable is > > actually much better and I think we're going way off the deep end looking > > at what particular implementations do and trying to justify to ourselves > > that non-cacheable is safe, even though it's still a normal memory type > > at the end of the day. > > Is this about Device vs NC or Device/NC vs Normal Cacheable? The > justification for the former has been summarised in Lorenzo's write-up. > How the hardware behaves, it depends a lot on the RAS implementation. > The BSA has some statements but not sure it covers everything. I don't know how to be more clear, but I'm asking why Normal-NC is the right memory type to use. Jason's explanation on the other thread about how it's basically the only option with FWB (with some hand-waving about why Normal-cacheable isn't safe) will have to do, but it needs to be in the commit message. The host maps MMIO with Device-nGnRE. Allowing a guest to map it as Normal surely means the host is going to need additional logic to deal with that? We briefly discussed claiming back a device above and I'm not convinced that the code we have for doing that today will work correctly if the guest has issued a bunch of Normal-NC stores prior to the device being unmapped. Could we change these patches so that the memory type of the stage-1 VMA in the VMM is reflected in the stage-2? In other words, continue to use Device mappings at stage-2 for I/O but relax to Normal-NC if that's how the VMM has it mapped? > Things can go wrong but that's not because Device does anything better. > Given the RAS implementation, external aborts caused on Device memory > (e.g. wrong size access) is uncontainable. For Normal NC it can be > contained (I can dig out the reasoning behind this if you want, IIUC > something to do with not being able to cancel an already issued Device > access since such accesses don't allow speculation due to side-effects; > for Normal NC, it's just about the software not getting the data). I really think these details belong in the commit message. > > Obviously, it's up to Marc and Oliver if they want to do this, but I'm > > wary without an official statement from Arm to say that Normal-NC is > > correct. There's mention of such a statement in the cover letter: > > > > > We hope ARM will publish information helping platform designers > > > follow these guidelines. > > > > but imo we shouldn't merge this without either: > > > > (a) _Architectural_ guidance (as opposed to some random whitepaper or > > half-baked certification scheme). > > Well, you know the story, the architects will probably make it a SoC or > integration issue, PCIe etc., not something that can live in the Arm > ARM. The best we could get is more recommendations in the RAS spec > around containment but not for things that might happen outside the CPU, > e.g. PCIe root complex. The Arm ARM _does_ mention PCI config space when talking about early write acknowledgement, so there's some precedence for providing guidance around which memory types to use. > > - or - > > > > (b) A concrete justification based on the current architecture as to > > why Normal-NC is the right thing to do for KVM. > > To put it differently, we don't have any strong arguments why Device is > the right thing to do. We chose Device based on some understanding > software people had about how the hardware behaves, which apparently > wasn't entirely correct (and summarised by Lorenzo). I think we use Device because that's what the host uses in its stage-1 and mismatched aliases are bad. Will