From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E7BB043A9F; Wed, 7 Feb 2024 15:31:32 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 898DD40295; Wed, 7 Feb 2024 15:31:32 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 85D8B40279 for ; Wed, 7 Feb 2024 15:31:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707316291; 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:autocrypt:autocrypt; bh=9jiCz69V9b1lhwsbyGdWZYodQyT+ftY2j6o2r9guyZ0=; b=TLpoEs36ck1HWcFDrHHvCey8blcGISpbEfYGwCWXOtKoPdDsdT1feUTZWoNa887viW14+T Npt8qmmGTy5ebXwjcoYzkZPr5jSw/MFcibzQnijwOXae/AehNwQ8OXyRcVwBsSoTb9dggD l19PnWKkM2cAwY83N1dQRPKnWpwYCvw= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-616-3tZcWL7sPTyLC3dbpBx1Jg-1; Wed, 07 Feb 2024 09:31:29 -0500 X-MC-Unique: 3tZcWL7sPTyLC3dbpBx1Jg-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a26f2da3c7bso43836866b.0 for ; Wed, 07 Feb 2024 06:31:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707316288; x=1707921088; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9jiCz69V9b1lhwsbyGdWZYodQyT+ftY2j6o2r9guyZ0=; b=elLeqA7I82t2qADxEFBZx/5CRg89TAgvRw3Sqxwxtb9M5BVTZzGMBh1t3/RVqrHS+z v7HIiwYGOSCGFhreDEsYcRbz2ZtnPNWo6EozCQwWoJUpBH23/nXbACkS39n2fNntQ30l xlQAeiZEWHfbBJh2tcmSmUvmTxwnaQqoVzp4QWsz0uDDDtGy/JlOxG1S551AG6txOU7n SWmuXf4CR/HkPohm6QoDt1eQcU+pfd/P/KyitpFIe2MXE1cipvI5KofhJZ/V0ZqWGZ/Q POMmWPGGlQugxXCsFKMVH0VIpgbmyFJAeT2UyQgYTMOe8qfrpo5UlOKEfHHdgrFagl3M +Fpg== X-Gm-Message-State: AOJu0YyZIx1FoHHzapDI08KrqzsFX9Fkwit7+dXmkK8TvnEOVP8jWTpP o5TitUbJZg1JtUEZZSPrhg+UpaYcH6+YqhCiTIXaWdF5SuVLmcSB+BdKC1JUnAsWoKkAJwxIDlO /GL6A7145h4rOvzVZsmqeFHef+v2GSeuUjghkrTiT X-Received: by 2002:a17:906:24ce:b0:a38:87a5:58da with SMTP id f14-20020a17090624ce00b00a3887a558damr1082217ejb.22.1707316288224; Wed, 07 Feb 2024 06:31:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IFkfXXhwmvAOPvH/saXTIPLlWGL8GzXkrxyxjnnN0Ve/ox2r3e+xkrvANZDFrxSZ+XKKZYiCQ== X-Received: by 2002:a17:906:24ce:b0:a38:87a5:58da with SMTP id f14-20020a17090624ce00b00a3887a558damr1082200ejb.22.1707316287819; Wed, 07 Feb 2024 06:31:27 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVxdNXyJEVMPgpoAWg0nNCC+JhCVjN2LODb9FHm5YV4kx1Qtly0s6zWeNTiV4gXPteRwCLlqvVQyv7Aptn8pbyh8/jEiZ4e5afpPdF0PZL4aCefdlFfUH3T1aOLrnfravb+jMkH1Lfdbq46vD6x+00dVpda1ssx Received: from [192.168.0.36] ([78.19.106.40]) by smtp.gmail.com with ESMTPSA id rp21-20020a170906d97500b00a3708787ca9sm817198ejb.146.2024.02.07.06.31.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 07 Feb 2024 06:31:27 -0800 (PST) Message-ID: <704e6a66-7e99-4416-a00a-6714629a4809@redhat.com> Date: Wed, 7 Feb 2024 14:31:26 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] ethdev: recommend against using locks in event callbacks To: Ferruh Yigit , David Marchand , dev@dpdk.org Cc: Thomas Monjalon , Andrew Rybchenko References: <20240201084319.2687896-1-david.marchand@redhat.com> <8a1a6acf-0e41-40ac-9c27-9265bc5b706f@redhat.com> <993d5a86-5920-488d-b6a7-a862d028508b@amd.com> From: Kevin Traynor Autocrypt: addr=ktraynor@redhat.com; keydata= xsFNBF2J2awBEADUEPNhgNI+nJNgiTAUcw4YIgVXEoHlsNPyyzG1BEXkWXALy0Y3fNTiw6+r ltWDkF9jzL9kfkecgQ67itGfk1OaBXgSGKuw1PUpxAwX2Bi76LAR6M5OsyGM9TSVVQwARalz hMwRBIZPzPc7or6Pw7jAOJ8SQGJ1Zlp1YJCjrvpe87V1tH/LY8Wnxn/EuoseFmWILAQZAtYS tGjcrAgYn3SPMLR1B0BP5bTBY06vWQjiufH8drenfDnMJAzuBdG1mqjnTqCjULZ3Hunv4xqZ aMnkvL/K5Tj1c12Oe4930EE53LrXIBUltRg5mBudSWHnC7twjH0082HH9f963Z/2UI63SFIT iUvRvAzJYytgy7XnWLQ0+goZBADKYfolOuC0H8VgCaux8u8KFF28Dy+N6TV2KI58jTlyg1Zu l7QwykZpnOkJFiy37Gfbu3YEOzO72cP/S7/A+zvuqkxi63jyEkd+FY99vLt/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reH7 a+VhQ1VTFFQrClA8NmDSPzFeuhru4ryaaDHO+uEB16cNHxHrQtlP/2hts2JM5lwkZRWJ5A57 h8eDEIK5be47T85NVHfuTaboNRmgg1HygVejhGUtt69u/0MVRg/roUTa0FyEbNsvz4qAecyW yWzMcVrcGJDQLC9JLKEpoyUF6gdTKaiDL2Vao4+XRIA3Y57b6MO35a3HuzAv7+i5Z0mnDEJO XxXqTOmKYpMIGexzM/PtuA0712sT1abG9tAJ17ao/B7cqMW5IkKkalemFbWfI2unns4Papvo tk9igVqyp6EJDU98z5TJioCVojwK2laDaoIjTJk9YYv3iwCsqPd5feU= In-Reply-To: <993d5a86-5920-488d-b6a7-a862d028508b@amd.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On 06/02/2024 20:33, Ferruh Yigit wrote: > On 2/1/2024 10:08 AM, Kevin Traynor wrote: >> On 01/02/2024 08:43, David Marchand wrote: >>> As described in a recent bugzilla opened against the net/iavf driver, >>> a driver may call a event callback from other calls of the ethdev API. >>> >>> Nothing guarantees in the ethdev API against such behavior. >>> >>> Add a notice against using locks in those callbacks. >>> >>> Bugzilla ID: 1337 >>> >>> Signed-off-by: David Marchand >>> --- >>> lib/ethdev/rte_ethdev.h | 14 +++++++++++++- >>> 1 file changed, 13 insertions(+), 1 deletion(-) >>> >>> diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h >>> index 21e3a21903..5c6b104fb4 100644 >>> --- a/lib/ethdev/rte_ethdev.h >>> +++ b/lib/ethdev/rte_ethdev.h >>> @@ -4090,7 +4090,19 @@ enum rte_eth_event_type { >>> RTE_ETH_EVENT_MAX /**< max value of this enum */ >>> }; >>> >>> -/** User application callback to be registered for interrupts. */ >>> +/** >>> + * User application callback to be registered for interrupts. >>> + * >>> + * Note: there is no guarantee in the DPDK drivers that a callback won't be >>> + * called in the middle of other parts of the ethdev API. For example, >>> + * imagine that thread A calls rte_eth_dev_start() and as part of this >>> + * call, a RTE_ETH_EVENT_INTR_RESET event gets generated and the >>> + * associated callback is ran on thread A. In that example, if the >>> + * application protects its internal data using locks before calling >>> + * rte_eth_dev_start(), and the callback takes a same lock, a deadlock >>> + * occurs. Because of this, it is highly recommended NOT to take locks in >>> + * those callbacks. >>> + */ >> >> That is a good practical recommendation for an application developer. >> >> I wonder if it should taken further so that the API formally states the >> callback MUST be non-blocking? >> > > Application still can manage the locks in a safe way, but needs to be > aware of above condition and possible deadlock. > Just to explain a bit more, if you look at the original issue in the Bugzilla [0], I think there was an assumption that rte_eth_dev_configure() would not block or deadlock with the eal-intr-thread. So then it was assumed that waiting for the lock in the callback was ok, because rte_eth_dev_configure() would return and callback would obtain the lock. So i'm showing that in this example the lack of a guarantee or clarity or bad assumption about the behavior of rte_eth_dev_configure() made it difficult for an app developer to know if their locks were safe or not. That's why I was thinking about something more formal. > I think above note is sufficient instead of forbidding locks in > callbacks completely. > In the end the difference between "highly recommended NOT to" and "must not" is not much and either way is probably enough to scare someone enough to avoid them. [0] https://bugs.dpdk.org/show_bug.cgi?id=1337#c0