Received: by 2002:ab2:2997:0:b0:1ec:cbc4:63fb with SMTP id n23csp551062lqb; Thu, 29 Feb 2024 08:16:34 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWsJgMi/B/BXr5a1Ij5oxzrJ6AEeRS3Z/x6peXo2ujt8NIn27sxUBWWXYoNPsJLtsoBjuGrnYYMueQWwjiH9h2kjMWPUgmw+lWQ+k8BDg== X-Google-Smtp-Source: AGHT+IGq1J0P4O4jgjHABQf8RjIpdGjyXOVKKdNvyPn/WHBeqhv6IDcFIjnx/+hXal7fIQs376AJ X-Received: by 2002:a0c:f892:0:b0:68f:ef85:47a4 with SMTP id u18-20020a0cf892000000b0068fef8547a4mr2610469qvn.30.1709223394408; Thu, 29 Feb 2024 08:16:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709223394; cv=pass; d=google.com; s=arc-20160816; b=Rdx0cm0fLbNAguxdnqy/AV22Z5NLeg5MYdSzep7kwTyudLhR39dXhESzPVPr293qBE 6qydJpi3uj8q5Ex3tu8d/S8QdFSz8GPMAH4ARVjetDGiVlqtyQBUmsIKsVhO4SQ0LaCy fUzjOBTlWOLnvw1EUbdfBpX3kFnT20ay7AncP6tQb0+DGMX54vNutsEaqWYuT+8188ot Y1c8ZRs614Cj63w8wjhkUdDSbjagMxaBuaZT4hgug5r2jAHAusJvRgJebvHeQSC7GG7a yeMB/nUZ11BCbtHk/+2uAxkRnI7SiF6TR80N9qk5M40fDcvagAIHMSamnGRH0ptBV0F6 cR+Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=NK1oIanmqTW8WZH0kLEYVDI/xueTaYHkdWqNEI0DyFk=; fh=fhdYz0uYWNTsC8zoZ5xK3ZsozVjXIKxdqEpmBC10lvI=; b=ZPUYnyWWHk0txgowtUIJp/OyB4KyXUFbFFAayzCEDPUese5Ow0M3Z92p7zZVM112vi Jt57a2xCyBuEr+/2hJaEd5pXcG12d3m3CCrC7OjHO94/X+REIvSKnx9kS/0yqJ+kYqoR LppUZ6IldQ8jTe5rQTjKRd1YYS/x0+3mNVwiPQvNF2znqfD+Mj5HZFCG34gWqjkBZy0Z yA2vnbK91sAITTxat/hQxqtb++VrMeBkbwOp/YHxdtWrQEray98y+h/kSWPcYE1Vvcg7 ShA2urrsWLQ0VZMTwlZONwF0K6l1XDlvSZxkfcRbjkGgtFs3umkye0gpgU1WoeSq/GU6 tYaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EKV8+0K7; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-87039-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87039-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 11-20020a05621420eb00b0068f731f88c7si1616092qvk.312.2024.02.29.08.16.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:16:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87039-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EKV8+0K7; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-87039-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87039-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1996F1C2211B for ; Thu, 29 Feb 2024 16:16:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E27CD6CC11; Thu, 29 Feb 2024 15:56:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EKV8+0K7" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51EC16CC17 for ; Thu, 29 Feb 2024 15:56:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709222207; cv=none; b=MYe40ybXIo961n3TNR1Gc6lSIVbODrlvuJ27ifb3EqFJ08s5YWYr9HeWB31h/Mrpnc+kmXE8PPYB01WgR5vvSsFrwI/yvtWg1QPE/PtcPvlo6zu/4yi93C+TOh2j4jTX/f92P3VqRwskg5lFFhkcycWwNPI036m4ne/LkLAGroc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709222207; c=relaxed/simple; bh=P2TMqG7h7dnUJpKrrocNNNzpbY0+qjivekQDfKhl2bM=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tTm7NVpdq4Xc+aAK1XdNB79AjU0W/l5hl8eEy29bwADJSQr9bdW6EeBe3rYxbrMs8RnxwamuMr0D8IK6Pbyo6P50EBfJkGXv9CppDJfDpGrfJ6r1cMbt1dfF9uDI/HdOPOXeNFOO5hTbGkfxGrAelK+URZ/gz7uxaeDaiNG8gUM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=EKV8+0K7; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709222204; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NK1oIanmqTW8WZH0kLEYVDI/xueTaYHkdWqNEI0DyFk=; b=EKV8+0K7UILiYBQNvid7MmFlmaaXK5H1RuaQ4i2cv7jAi5ibqyg0WFDLuHr3lkiNCYDZv/ ReqcfsE+A3a8WifpBvUuyalMXtmuB1Y9tx0v2QEhqdAjGIV9h1QnGxzYqUV5zsvmUUbLpQ tbcimpMvaJ+VP8CFIiS6n6eCCP83K+Y= Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-679-goY0b5IJOrOGENJsI6eQGw-1; Thu, 29 Feb 2024 10:56:42 -0500 X-MC-Unique: goY0b5IJOrOGENJsI6eQGw-1 Received: by mail-io1-f72.google.com with SMTP id ca18e2360f4ac-7c79b0aaa86so112779439f.2 for ; Thu, 29 Feb 2024 07:56:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709222201; x=1709827001; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NK1oIanmqTW8WZH0kLEYVDI/xueTaYHkdWqNEI0DyFk=; b=S8A4xHAM0wD1j3sD6vsGhE28Mm5DR231xtqb3tXoAaDHeA4B0qepy5B49cYlYwW6qX 1fm1885+xWRoPuOxJhEBmtGTui3mrTVcidWFn9BnbwimMVOH9IPuh9Qcf5eYIsDKl+qH kQNfsZSdn8d6DPJKOkjVncsoJIbojNh1psQOvC28K/nN/lIvbHBYwIXUNTuhzg4V02Kq 7YH7tGEZv/pGJ73txQtfRqsfGv1nCqO+f0Yi8pziDePZy8ecLJJuiGGI0/qcXAtrciIo bZ3wYqQx9XNxVJ9oPvGU08ZK631g2CyI7k3YPIi5rYdp9DSxeH9e2NzmI0M7YZr+woUA B0Fw== X-Forwarded-Encrypted: i=1; AJvYcCWxE1iQq7pweXe1Snu/D3Ke6zISaoPjMDDEksaxMMAURrNNXYZ4xhWfC7So5pAClSKn37Ur+NznChm95HOXX5V4jLv+r3wo/RHcKNyA X-Gm-Message-State: AOJu0YxYtjPWF9UluMKX9b9WhYKcA4uqX4D0R1o7AtJDgzWPvAZcnlvP FsQGMHZEZwXXpshNmc2OKlNbWaHjXc7cnT4M9zfbwEycHSM/+2hho7h4v7JbHrMSnKLYLnhDaRl B3pfMqTaUnF+iZzRNV3pf1JGUZjN5rTlon/Xzu+zeWzp2bNGRFiUeL0hB0d53vw== X-Received: by 2002:a05:6602:641d:b0:7c7:d3c6:e195 with SMTP id gn29-20020a056602641d00b007c7d3c6e195mr3443311iob.1.1709222201494; Thu, 29 Feb 2024 07:56:41 -0800 (PST) X-Received: by 2002:a05:6602:641d:b0:7c7:d3c6:e195 with SMTP id gn29-20020a056602641d00b007c7d3c6e195mr3443292iob.1.1709222201221; Thu, 29 Feb 2024 07:56:41 -0800 (PST) Received: from redhat.com ([38.15.36.11]) by smtp.gmail.com with ESMTPSA id j13-20020a02a68d000000b00474420a484esm364815jam.98.2024.02.29.07.56.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 07:56:40 -0800 (PST) Date: Thu, 29 Feb 2024 08:56:39 -0700 From: Alex Williamson To: Cc: , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH v1 1/1] vfio/nvgrace-gpu: Convey kvm that the device is wc safe Message-ID: <20240229085639.484b920c.alex.williamson@redhat.com> In-Reply-To: <20240228194801.2299-1-ankita@nvidia.com> References: <20240228194801.2299-1-ankita@nvidia.com> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-redhat-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 28 Feb 2024 19:48:01 +0000 wrote: > From: Ankit Agrawal > > The NVIDIA Grace Hopper GPUs have device memory that is supposed to be > used as a regular RAM. It is accessible through CPU-GPU chip-to-chip > cache coherent interconnect and is present in the system physical > address space. The device memory is split into two regions - termed > as usemem and resmem - in the system physical address space, > with each region mapped and exposed to the VM as a separate fake > device BAR [1]. > > Owing to a hardware defect for Multi-Instance GPU (MIG) feature [2], > there is a requirement - as a workaround - for the resmem BAR to > display uncached memory characteristics. Based on [3], on system with > FWB enabled such as Grace Hopper, the requisite properties > (uncached, unaligned access) can be achieved through a VM mapping (S1) > of NORMAL_NC and host mapping (S2) of MT_S2_FWB_NORMAL_NC. > > KVM currently maps the MMIO region in S2 as MT_S2_FWB_DEVICE_nGnRE by > default. The fake device BARs thus displays DEVICE_nGnRE behavior in the > VM. > > The following table summarizes the behavior for the various S1 and S2 > mapping combinations for systems with FWB enabled [3]. > S1 | S2 | Result > NORMAL_WB | NORMAL_NC | NORMAL_NC > NORMAL_WT | NORMAL_NC | NORMAL_NC > NORMAL_NC | NORMAL_NC | NORMAL_NC > NORMAL_WB | DEVICE_nGnRE | DEVICE_nGnRE > NORMAL_WT | DEVICE_nGnRE | DEVICE_nGnRE > NORMAL_NC | DEVICE_nGnRE | DEVICE_nGnRE > > Recently a change was added that modifies this default behavior and > make KVM map MMIO as MT_S2_FWB_NORMAL_NC when a VMA flag > VM_ALLOW_ANY_UNCACHED is set. Setting S2 as MT_S2_FWB_NORMAL_NC > provides the desired behavior (uncached, unaligned access) for resmem. > > Such setting is extended to the usemem as a middle-of-the-road > setting to take it closer to the desired final system memory > characteristics (cached, unaligned). This will eventually be > fixed with the ongoing proposal [4]. > > To use VM_ALLOW_ANY_UNCACHED flag, the platform must guarantee that > no action taken on the MMIO mapping can trigger an uncontained > failure. The Grace Hopper satisfies this requirement. So set > the VM_ALLOW_ANY_UNCACHED flag in the VMA. > > Applied over next-20240227. > base-commit: 22ba90670a51 > > Link: https://lore.kernel.org/all/20240220115055.23546-4-ankita@nvidia.com/ [1] > Link: https://www.nvidia.com/en-in/technologies/multi-instance-gpu/ [2] > Link: https://developer.arm.com/documentation/ddi0487/latest/ section D8.5.5 [3] > Link: https://lore.kernel.org/all/20230907181459.18145-2-ankita@nvidia.com/ [4] > > Cc: Alex Williamson > Cc: Kevin Tian > Cc: Jason Gunthorpe > Cc: Vikram Sethi > Cc: Zhi Wang > Signed-off-by: Ankit Agrawal > --- > drivers/vfio/pci/nvgrace-gpu/main.c | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/drivers/vfio/pci/nvgrace-gpu/main.c b/drivers/vfio/pci/nvgrace-gpu/main.c > index 25814006352d..5539c9057212 100644 > --- a/drivers/vfio/pci/nvgrace-gpu/main.c > +++ b/drivers/vfio/pci/nvgrace-gpu/main.c > @@ -181,6 +181,24 @@ static int nvgrace_gpu_mmap(struct vfio_device *core_vdev, > > vma->vm_pgoff = start_pfn; > > + /* > + * The VM_ALLOW_ANY_UNCACHED VMA flag is implemented for ARM64, > + * allowing KVM stage 2 device mapping attributes to use Normal-NC > + * rather than DEVICE_nGnRE, which allows guest mappings > + * supporting write-combining attributes (WC). This also > + * unlocks memory-like operations such as unaligned accesses. > + * This setting suits the fake BARs as they are expected to > + * demonstrate such properties within the guest. > + * > + * ARM does not architecturally guarantee this is safe, and indeed > + * some MMIO regions like the GICv2 VCPU interface can trigger > + * uncontained faults if Normal-NC is used. The nvgrace-gpu > + * however is safe in that the platform guarantees that no > + * action taken on the MMIO mapping can trigger an uncontained > + * failure. Hence VM_ALLOW_ANY_UNCACHED is set in the VMA flags. > + */ > + vm_flags_set(vma, VM_ALLOW_ANY_UNCACHED); > + > return 0; > } > The commit log sort of covers it, but this comment doesn't seem to cover why we're setting an uncached attribute to the usemem region which we're specifically mapping as coherent... did we end up giving this flag a really poor name if it's being used here to allow unaligned access? Thanks, Alex