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=-12.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 7224CC433B4 for ; Fri, 23 Apr 2021 01:52:57 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 F3E34613CC for ; Fri, 23 Apr 2021 01:52:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F3E34613CC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=amd-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 483036EB1E; Fri, 23 Apr 2021 01:52:56 +0000 (UTC) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2064.outbound.protection.outlook.com [40.107.243.64]) by gabe.freedesktop.org (Postfix) with ESMTPS id 020916EB1E for ; Fri, 23 Apr 2021 01:52:55 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EfDdV6nYnC/RQjj1ZD5O4+amd4pygbqI1Af5z9zVcXM3eWag9F5rOsOEqBHfbAk4hvGJmClTJKVPLNip8VIiHPq1G0/+bFP7E0Cq8zfcIRjIUr3TgdISQUThHiFxGKawTvNDFBm4k7EuBXFZqfonqhzK2Mjl1mC0ppje2wcWyhKZpBj+4J7hgwiHS25dXX+NCGl1uwTpHf9k91l7jOOPApC9ZYUaKD8b0uedK8+MM0ccUNVbjwAr22ma4NqnelK5EItEfSvI99Pj0sMDceS0mwRFxaXHZa8AsFMf2/N9pZAIEIsAtPB+W2ENfUp64SIzdS72cRHr9sQwumgd+6+JJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7c6ZuPeU8oR3MmAgS8i/gMBRA7c4CM+FULQPaLcVrAQ=; b=TIK7RatRzctXDG03HBmRYEJKSQyzW6vScMNlK+DkWBtTFaV4NKuKTEQ/k2QH984mtrXOSOBdYEPL7DtdEnInSTnVgv/2VGdulX0lrh5MnAv2/y40vBXDIJ0cw7hhXrEitkv7WYuw/4XG8DQYheTgt73us+cfuONQeH3sL5CIjGMeNjGOzuYDPsvUa8Q0QnGh2bZa4jEn5v7nVjHrNn0WG9/dhuQ5lvP9PW3c9hxCwN6TjHEOKHbP/I3O3AB0s2diGcthJp6mnoWc+KPadxDN7QbNDCnJGwZCTcLyvezZEZi8vrZY/v1K+cjbQq+n2R74fgOiuqq0wZ9NUkRXDIdzOw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7c6ZuPeU8oR3MmAgS8i/gMBRA7c4CM+FULQPaLcVrAQ=; b=OvevVyhbGUTAranYMm2AdKVoJpXCTGarW+wa7Ls3wY2IbuN/nQNgIgWuPoaR+JuSVz9IV5Zm8+5zy7iv6lSy0LxYn+FchEmAMcMEqBUAO5lv1std3U/0TsRZIW8La/ebkfSGzoE/8B+QeqGZb8pzQDU0TUh15F6HoLDabrFA6tE= Authentication-Results: amd.com; dkim=none (message not signed) header.d=none;amd.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB2583.namprd12.prod.outlook.com (2603:10b6:4:b3::28) by DM5PR1201MB0201.namprd12.prod.outlook.com (2603:10b6:4:5b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16; Fri, 23 Apr 2021 01:52:52 +0000 Received: from DM5PR12MB2583.namprd12.prod.outlook.com ([fe80::d568:cff1:dc2a:5baa]) by DM5PR12MB2583.namprd12.prod.outlook.com ([fe80::d568:cff1:dc2a:5baa%3]) with mapi id 15.20.4065.020; Fri, 23 Apr 2021 01:52:52 +0000 Subject: Re: [PATCH 4/6] drm/amdgpu: address remove from fault filter To: Felix Kuehling , =?UTF-8?Q?Christian_K=c3=b6nig?= , amd-gfx@lists.freedesktop.org, "Yang, Philip" References: <20210420202122.4701-1-Philip.Yang@amd.com> <20210420202122.4701-4-Philip.Yang@amd.com> <818c1295-2340-a6fe-9b64-e7a5e74d411e@gmail.com> <9ea89549-afb4-ed48-4ff2-0ae740251d59@amd.com> From: philip yang Message-ID: Date: Thu, 22 Apr 2021 21:52:50 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 In-Reply-To: <9ea89549-afb4-ed48-4ff2-0ae740251d59@amd.com> Content-Language: en-CA X-Originating-IP: [165.204.55.251] X-ClientProxiedBy: YTXPR0101CA0024.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b00::37) To DM5PR12MB2583.namprd12.prod.outlook.com (2603:10b6:4:b3::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [172.27.226.38] (165.204.55.251) by YTXPR0101CA0024.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b00::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.21 via Frontend Transport; Fri, 23 Apr 2021 01:52:52 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: db3f4763-2109-4de5-b7ad-08d905fa81a2 X-MS-TrafficTypeDiagnostic: DM5PR1201MB0201: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: l4EzVlYhiaf7HO4ga0c1WXZdwx378xo+r902e4Ho3whYzHW5tpYa0IkGIynR38tFdw1L4tUCN1UpTLf/8FxAPKRpHBwh+8z8foEdSfjb/S9h8swmDQZSmyGB0Qm3ZEE4/RngyT4v7RpKs6yFtskBOPjdomO3h2wWotbfrLMjjjWeDVcFTfwcfDBkIz0C5jJSLPV+mnXHco9ROSJNfXv9KAS2Lk78L/cSg4qYyPpFI0nnUCyRerLPeoS4Z8bQLoXj9ZhUxV46H3dZhyDAEtHR7iM+5GmjQnwH3SQAwzo55p3Tov/bt6NqCQbjGI7yGZvU1mkS3BZ4FJmG4lyyO48ncnSNcCFyTvWLW5/X7Rh6cT3NkfKQ2GNjUu+v0wV4czklCoNC5mZJ3rFi9U9OLqby6XuxPn9e9RmbrUsRd1BOCqAESV/sjtblSxXcU0ZWoaTK/2jIKez+xzs4tjkAZnwD1VMrShIh+IUoEKgf02bacb4kUvUDj+u9Pu0X5AvIW6khYr7hpRFJ1H8ZKq+8fStgK7GojjLc55bMR6ajSJhXHUZMRYj2AYxQ7K5M09GK+jC2s9KEqhCwPSas76rsLRi86MF9ZVBN1L57tDuvsbLPNCHC5zgIGvOkDebBBr7Ku7GEYiKmHI9q8WZWh5no+cHIYIvG3R8ssuaQd5214pWAN8SQNphetciZ/45KQXocyNdzP/AvhRG9b4FvjaZ7fUvWRFQ0jLpX3dOc9iKXW1MEkFI= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR12MB2583.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(39860400002)(366004)(376002)(346002)(136003)(396003)(186003)(38100700002)(6486002)(31686004)(31696002)(16576012)(110136005)(45080400002)(5660300002)(316002)(66476007)(83380400001)(66556008)(6636002)(66946007)(53546011)(8936002)(66574015)(2906002)(26005)(956004)(36756003)(966005)(166002)(16526019)(478600001)(2616005)(8676002)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?YkI3N0U0WkRzZ1ExMEwrZE5IaGtNTFZFdDNaeFJXZkhQYy9wdDVpNG9WM1Nq?= =?utf-8?B?WGhSMUE3bWFzMmVyWkpTenN4bHIzdXdrTmhPTjZVZzNXZ1REWWhPZllQVjA4?= =?utf-8?B?QU1JOHNDZ2MweWtkVDFIN2NWa1lPY2lXNmx2bXMzN0dRdm8vbjdaazdKUGZY?= =?utf-8?B?SS9LVXQrTUNnUGt3MU9Cem1JMFFqOXFLN2xDUXZ5dmxMb0NRLzBaQkpieG9a?= =?utf-8?B?SFhabXN5bzZQM1JLS2drbVlEQXF3SkVTZ0JMYjlWM01WenI4dE9IbU5tZGVy?= =?utf-8?B?aUwzNUdKdHFYYXRkNVZ6ZzZ4TzQzbnFIdnd1VTJBeGUrdGtZdVhxTWV0NXBP?= =?utf-8?B?STMyYzdhQzIrV0tDeXdwK0RUdnZtWEdzdG43SElkWnNmZjFvMjZpck1hUlBq?= =?utf-8?B?WG51VU1TQVVwYjhGMkxoUkk3OHdCSGthMFlrMDdIblNHMXV1dVFHUGtsNFN1?= =?utf-8?B?Wi9mVjlrZHl6OTJPT0tjdjh0Tm9xT1BkQm1YVXkxQ1pLOWNUT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NETWkzQ3IwZ3prc1BEa1hVZ0lq?= =?utf-8?B?RHlWQitRbHRqbnlEVDlnZHFCQlRvQ2tJSVRKNWNhUHhhK3FEVllHcEYybVc1?= =?utf-8?B?NVRHdW9WRzcvWUptMGt1cEJhZE40UnNuZ3BSamJaK0NqblNDV1QyNFRJblBB?= =?utf-8?B?bWp2NjhhWlBya3VJOUYzbjJpUUJVQXV0ZzlqZVZHc0pYMmgxb3NRVTVZMTkv?= =?utf-8?B?KzZVSnMzLzJpbERzOWYxTVB2T2lOSVhPUC9ua1FURlpHN1FxSlZ0VGtQSnRZ?= =?utf-8?B?RGpicENaNlBkNk52NUZ4UmtFeWpGRFIyeFhBeDg5VjJkTGtUVG1BWWk2dnUv?= =?utf-8?Q?DwmkL8fxP23OYOhKLiI+dthRkfGeOp7o4+dwnzF?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: db3f4763-2109-4de5-b7ad-08d905fa81a2 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB2583.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2021 01:52:52.7271 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: oX01OK2Rj8yvEbL3TQ52jJcrt7SRSHWN41CDou2oMViaWxEg8K10nDWMxstz9ek/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0201 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============1066896152==" Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" --===============1066896152== Content-Type: text/html; charset=utf-8 Content-Language: en-CA Content-Transfer-Encoding: 8bit


On 2021-04-21 11:29 a.m., Felix Kuehling wrote:
On 2021-04-21 3:55 a.m., Christian König wrote:
Am 21.04.21 um 03:20 schrieb Felix Kuehling:
Am 2021-04-20 um 4:21 p.m. schrieb Philip Yang:
Add interface to remove address from fault filter ring by resetting
fault ring entry of the fault address timestamp to 0, then future vm
fault on the address will be processed to recover.

Check fault address from fault ring, add address into fault ring and
remove address from fault ring are serialized in same interrupt deferred
work, don't have race condition.

Signed-off-by: Philip Yang <Philip.Yang@amd.com>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 24 ++++++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h |  2 ++
  2 files changed, 26 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
index c39ed9eb0987..338e45fa66cb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
@@ -387,6 +387,30 @@ bool amdgpu_gmc_filter_faults(struct amdgpu_device *adev, uint64_t addr,
      return false;
  }
  +/**
+ * amdgpu_gmc_filter_faults_remove - remove address from VM faults filter
+ *
+ * @adev: amdgpu device structure
+ * @addr: address of the VM fault
+ * @pasid: PASID of the process causing the fault
+ *
+ * Remove the address from fault filter, then future vm fault on this address
+ * will pass to retry fault handler to recover.
+ */
+void amdgpu_gmc_filter_faults_remove(struct amdgpu_device *adev, uint64_t addr,
+                     uint16_t pasid)
+{
+    struct amdgpu_gmc *gmc = &adev->gmc;
+
+    uint64_t key = addr << 4 | pasid;
+    struct amdgpu_gmc_fault *fault;
+    uint32_t hash;
+
+    hash = hash_64(key, AMDGPU_GMC_FAULT_HASH_ORDER);
+    fault = &gmc->fault_ring[gmc->fault_hash[hash].idx];
You need to loop over the fault ring to find a fault with the matching
key since there may be hash collisions.

You also need to make sure you don't break the single link list of keys
with the same hash when you remove an entry. I think the easier way to
remove an entry without breaking this ring+closed hashing structure is
to reset the fault->key rather than the fault->timestamp.

Finally, you need to add locking to the fault ring structure. Currently
it's not protected by any locks because only one thread (the interrupt
handler) accesses it. Now you have another thread that can remove
entries, so you need to protect it with a lock. If you are handling
retry faults, you know that the interrupt handler is really a worker
thread, so you can use a mutex or a spin-lock, but it doesn't need to be
interrupt-safe.

I don't think you need a lock at all.

Just using cmpxchg() to update the key should do it.

Something like this:

        hash = hash_64(key, AMDGPU_GMC_FAULT_HASH_ORDER);
        fault = &gmc->fault_ring[gmc->fault_hash[hash].idx];
        while (fault->timestamp >= stamp) {
                uint64_t tmp;

                cmpxchg(&fault->key, key, 0);

Good idea. Then we should probably use READ_ONCE and WRITE_ONCE to access fault->key in other places.

I will use spinlock to protect fault ring and fault hash table access, as atomic_cmpxchg cannot work for 52bit key and VG20 need access fault ring in interrupt handler and deferred work.

Regards,

Philip


Regards,
  Felix



                tmp = fault->timestamp;
                fault = &gmc->fault_ring[fault->next];

                /* Check if the entry was reused */
                if (fault->timestamp >= tmp)
                        break;
        }

Regards,
Christian.


Regards,
   Felix


+    fault->timestamp = 0;
+}
+
  int amdgpu_gmc_ras_late_init(struct amdgpu_device *adev)
  {
      int r;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
index 9d11c02a3938..498a7a0d5a9e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
@@ -318,6 +318,8 @@ void amdgpu_gmc_agp_location(struct amdgpu_device *adev,
                   struct amdgpu_gmc *mc);
  bool amdgpu_gmc_filter_faults(struct amdgpu_device *adev, uint64_t addr,
                    uint16_t pasid, uint64_t timestamp);
+void amdgpu_gmc_filter_faults_remove(struct amdgpu_device *adev, uint64_t addr,
+                     uint16_t pasid);
  int amdgpu_gmc_ras_late_init(struct amdgpu_device *adev);
  void amdgpu_gmc_ras_fini(struct amdgpu_device *adev);
  int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev);
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7Cfelix.kuehling%40amd.com%7C7d19870014ff40b6d80b08d9049ae8a0%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637545885642357593%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=b0LnO9SQPgYskIRH0vCjKebvh%2FYzFfidRne15q2WIXw%3D&amp;reserved=0

--===============1066896152== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx --===============1066896152==--