Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp276267rdg; Thu, 12 Oct 2023 05:36:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEgssw1Sy/8mWoCezLxaHqcJ9zfrpKjDyp3F+N1GhX7pCTn4o7ci6r/r51I8QoTSQYmFc8Z X-Received: by 2002:a17:902:bd47:b0:1bc:2188:ef88 with SMTP id b7-20020a170902bd4700b001bc2188ef88mr21111113plx.3.1697114179422; Thu, 12 Oct 2023 05:36:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697114179; cv=none; d=google.com; s=arc-20160816; b=V/w3BpTzzquUGiKU8fiEb6hwQoYRNcM13JWtH2hHzemOImH17OCeY9znQzo1OgiJgk LzmIkTY5flgciJFXGAzT340WzyQQLQK98al6fYIN1FFSMo3u82/qBjt4K8Ilu3PmUVro Z7uaUu8/uK+xJ/b9/Z2qAYeZsJTKXf362SCLju97Gi6/OvtT6ecbprr7yaKB7QjgXIZY Gy3y93DvMDGRup6E2ev3t1qFvk9CcoqAJbklc4uStOlrOCxzCPfahzUBW3Ibtp8UCNjB 07B0XOLzp9ImPY6/XuACfTwm8GQqj3Cxq8F/l1YpYASj6iamLNJwKafzE/xo0Wnk8d97 lYow== 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=HQbC9rWxa6AAHmMWxT/GNrJ8OUg86J4s/6Vh25u4dqM=; fh=HQzHuYYK8zv2YpM9tJAGQXyEic3knOJ7XOE6RcLfxFc=; b=NEtUk9sRX6QOzB1MV8Kv0gEQ2kB7A/awjGVzCskOgGhNfCJSpoo/nGi2x1coSmjdPr AyntgxzijOdGiQWGdMPhXITpfcR5CVDW3iZszXQD8xmi3QGS6BjFNqdq1hfOw/suk0yz OoUWdpE5c9lUL8hFbqONQuBBUcCWdMc2dMPO8Q30CiN2d20FkYjllmz0iAdJMfYRgiiZ 6owntLBfZczM8WItGyxfwnfYOsPE7rqV0CaBQfskwrPU+J8vbQLlGeAjgDXnDHzRXGYZ Ugc96o1qMdbTRAJg0g8lQIffkCRH/6gvRhtiihvLSJuME/2g0T4GIz4aUlpSi2r01tGZ Aadg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XZvoS9CG; 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 s17-20020a170902989100b001c7361b71c9si2022362plp.114.2023.10.12.05.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 05:36:19 -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=XZvoS9CG; 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 CE38E8098E8F; Thu, 12 Oct 2023 05:36:01 -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 S1378383AbjJLMfw (ORCPT + 99 others); Thu, 12 Oct 2023 08:35:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378198AbjJLMfu (ORCPT ); Thu, 12 Oct 2023 08:35:50 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01F41C0 for ; Thu, 12 Oct 2023 05:35:48 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44BC2C433C8; Thu, 12 Oct 2023 12:35:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697114148; bh=gB8zPjeOXQPwfuELYundQoAY/96rhccCXFynL9ryD2Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XZvoS9CGAOVcf6PYMQh+L/pEifbtHxh5jKqFlCbuHw68AockQbpki2L7v6s7FjpUd tHYxnrgxorK6R3EeK0LDrnLBNL+cl/P3TzOO8XO3YCU9Ci1y6qxV3RZyhemh10jG0B Mie57WfYWOh2XPgjnDQ4FyvOQgozkt7C+jbherHEwbLvolY43MM1uTxqibtHwjw/4H SzcUg+x3w0BDQ2BMIl48RLgs3tRji9VCquXi+3p+DM+V214yTXmmO6S+RNlmgOmuls b7s99r9BukUf8/GMqgJNgE73IQ+MsaFNewphhmABRFO19JWwD4gj/YyxvE1sHkmkNA suPmwPXJAaLxA== Date: Thu, 12 Oct 2023 13:35:41 +0100 From: Will Deacon To: Lorenzo Pieralisi Cc: Catalin Marinas , 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: <20231012123541.GB11824@willie-the-truck> References: <20230907181459.18145-1-ankita@nvidia.com> <20230907181459.18145-3-ankita@nvidia.com> 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]); Thu, 12 Oct 2023 05:36:02 -0700 (PDT) On Thu, Oct 05, 2023 at 11:56:55AM +0200, Lorenzo Pieralisi wrote: > On Tue, Sep 26, 2023 at 02:52:13PM +0100, Catalin Marinas wrote: > > [...] > > > Anyway, the text looks fine to me. Thanks for putting it together > > Lorenzo. > > Thanks ! > > > One thing not mentioned here is that pci-vfio still maps such memory as > > Device-nGnRnE in user space and relaxing this potentially creates an > > alias. But such alias is only relevant of both the VMM and the VM try to > > access the same device which I doubt is a realistic scenario. > > A revised log, FWIW: Thanks for putting this together, Lorenzo. Just one thing below: > --- > Currently, KVM for ARM64 maps at stage 2 memory that is > considered device (ie it is not RAM) with DEVICE_nGnRE > memory attributes; this setting overrides (as per the ARM > architecture [1]) any device MMIO mapping present at stage > 1, resulting in a set-up whereby a guest operating system > can't determine device MMIO mapping memory attributes on its > own but it is always overriden by the KVM stage 2 default. > > This set-up does not allow guest operating systems to select > device memory attributes on a page by page basis independently > from KVM stage-2 mappings (refer to [1], "Combining stage 1 and stage > 2 memory type attributes"), which turns out to be an issue in that > guest operating systems (eg Linux) may request to map > devices MMIO regions with memory attributes that guarantee > better performance (eg gathering attribute - that for some > devices can generate larger PCIe memory writes TLPs) > and specific operations (eg unaligned transactions) such as > the NormalNC memory type. > > The default device stage 2 mapping was chosen in KVM > for ARM64 since it was considered safer (ie it would > not allow guests to trigger uncontained failures > ultimately crashing the machine) but this turned out > to be imprecise. > > Failures containability is a property of the platform > and is independent from the memory type used for MMIO > device memory mappings (ie DEVICE_nGnRE memory type is > even more problematic than NormalNC in terms of containability > since eg aborts triggered on loads cannot be made synchronous, > which make them harder to contain); this means that, > regardless of the combined stage1+stage2 mappings a > platform is safe if and only if device transactions cannot trigger > uncontained failures; reworded, the default KVM device > stage 2 memory attributes play no role in making device > assignment safer for a given platform and therefore can > be relaxed. > > For all these reasons, relax the KVM stage 2 device > memory attributes from DEVICE_nGnRE to NormalNC. The reasoning above suggests to me that this should probably just be Normal cacheable, as that is what actually allows the guest to control the attributes. So what is the rationale behind stopping at Normal-NC? Will