From nobody Sat Jan 22 09:49:09 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 352EC197C6BE; Sat, 22 Jan 2022 09:49:23 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mail.turbocat.net (turbocat.net [IPv6:2a01:4f8:c17:6c4b::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4Jgs0K6GGzz3sMp; Sat, 22 Jan 2022 09:49:21 +0000 (UTC) (envelope-from hps@selasky.org) Received: from [10.36.2.165] (unknown [178.17.145.105]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id 48510260517; Sat, 22 Jan 2022 10:49:19 +0100 (CET) Message-ID: <6b3eabe6-fcdf-e697-1295-e9ec9604ec41@selasky.org> Date: Sat, 22 Jan 2022 10:49:09 +0100 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:91.0) Gecko/20100101 Thunderbird/91.4.1 Subject: Re: git: 02ea6033020e - main - LinuxKPI: Allow spin_lock_irqsave to be called within a critical section Content-Language: en-US To: Vladimir Kondratyev , Konstantin Belousov , Vladimir Kondratyev Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org References: <202201182015.20IKFaWL053942@gitrepo.freebsd.org> <540a6a93-3101-02e8-b86a-50caa19f9653@kondratyev.su> <3f62b9e2-214b-b1d4-f682-9318f77f315d@kondratyev.su> From: Hans Petter Selasky In-Reply-To: <3f62b9e2-214b-b1d4-f682-9318f77f315d@kondratyev.su> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4Jgs0K6GGzz3sMp X-Spamd-Bar: ++ Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of hps@selasky.org designates 2a01:4f8:c17:6c4b::2 as permitted sender) smtp.mailfrom=hps@selasky.org X-Spamd-Result: default: False [2.70 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+a:mail.turbocat.net:c]; NEURAL_SPAM_SHORT(1.00)[1.000]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[selasky.org]; NEURAL_SPAM_MEDIUM(1.00)[1.000]; RCPT_COUNT_FIVE(0.00)[6]; TO_MATCH_ENVRCPT_SOME(0.00)[]; NEURAL_SPAM_LONG(1.00)[1.000]; MLMMJ_DEST(0.00)[dev-commits-src-all,dev-commits-src-main]; FREEMAIL_TO(0.00)[kondratyev.su,gmail.com,freebsd.org]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:24940, ipnet:2a01:4f8::/32, country:DE]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] X-ThisMailContainsUnwantedMimeParts: N On 1/19/22 23:02, Vladimir Kondratyev wrote: > On 19.01.2022 12:50, Hans Petter Selasky wrote: >> On 1/18/22 22:35, Vladimir Kondratyev wrote: >>> >>> Any ideas how to avoid it in a generic way? >> >> Hi, >> >> On a non-SMP system this will lead to deadlock. >> >> Is it possible you can pre-lock this spin lock earlier, so that it is >> already locked, so instead of >> >> while(trylock()); >> >> You have: >> >> assert (trylock() XXX) >> > > Unfortunately, vulnerable functions are called in too many code paths to > patch them all. > >> Or else, >> >> convert this particular lock to a native FreeBSD spinlock mutex. >> > It can be done for wake_up() but not for dma_fence_signal() which > suffers from this problem too. Some code that uses that lock expect it > to be spinlock_t > > I think we can just drop critical section in seqlock-related part of > dma-buf code and replace it with rwlock as kib@ and mjg@ suggested. > Leave seqlock for actual locking to preserve semantics as much as > possible and add rwlock to implement reader's blocking. Following > snippets show code conversion required for this change: > > > Lock seqlock as reader: > > retry: >     seq = read_seqcount_begin(&obj->seq); > > ... reader payload ... > >     if (read_seqcount_retry(&obj->seq, seq)) { > #ifdef __FreeBSD__ >         /* Wait for rwlock to be released by writer */ >         rw_rlock(&obj->rwlock); >         rw_runlock(&obj->rwlock); > #endif >         goto retry; >     } > > > Lock seqlock as writer: > > #ifdef __linux__ >     preempt_disable(); > #elif defined (__FreeBSD__) >     rw_wlock(&obj->rwlock); > #endif >     write_seqcount_begin(&obj->seq); > > ... writer payload ... > >     write_seqcount_end(&obj->seq); > #ifdef __linux__ >     preempt_enable(); > #elif defined (__FreeBSD__) >     rw_wunlock(&obj->rwlock); > #endif > Hi Vladimir, Waiting for a differential revision. --HPS