Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp496976iog; Wed, 29 Jun 2022 04:43:11 -0700 (PDT) X-Google-Smtp-Source: AGRyM1seE5uLsy2FVbl/3/FsbqG047B8zijrV7+h4zGpUIgoQnVZG20cLFZ/kFmGOy0Q7dIoOCGh X-Received: by 2002:a17:903:1108:b0:16a:a0ab:8f89 with SMTP id n8-20020a170903110800b0016aa0ab8f89mr10074481plh.12.1656502991381; Wed, 29 Jun 2022 04:43:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656502991; cv=none; d=google.com; s=arc-20160816; b=SL9RCQYqLZqF3eC1lZ0U83+UtbZaZZsG362pV9Zv93EcePKew2MaKVzJV3BeiJjeMN 8bgVq195aStzBL3V52Cq0osSjU80gBS94lZAcUgJcH2TU5NyXZAXWvCZHH1j504kPpS6 2c6hfE/flBnl5ecBfFN8ES1mCW0OUrwRn+nO/lrcplB1CIeGWXzfA4iDeiRXZMknyvwR FRDQecV68i/ccHgPV+h7forgGFZrudNNaDxHwQznOrtF7fcKpcIuhe0SlkWqpe1BQau0 MrTmXDA85QVkMj/70tBxfBjV6KY2IuhXtaTzxC04xPSBLZS3T0OpMhNQIgfGgsEYFXgq aLIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=CNxXkwtze2gyLyEUtULoRKSzgQuTYXqXAG+m5bX1wsI=; b=NZYTr8CZfR7l/egv0I6mo0MrRwY53ne5QxJZeD+B3qEjwxjlxm2qZBOSFW9hd9tJh2 dv4tD1//FXjK1yL+27LDNPuWT7HAx2hIGuQ8VKStqmZVpxjxLXefBPlNgGyzP1dXMZss lLUiTxN6p2k2KSx4BfHFcg3NmctklQoKXUA2Gn0NcZ/85HSWFMSGpp77srN+aupdNe65 jwmWLzvSVDKB+4EeHjeY4DEn+9DjASlm/rKgz8jYMwTFJf30l3ngmysFb9OhkXEC5BEB GOGxlDHZbglnNkrj7LDQLIBV+QF59CChcWSPn6T9P3SGiNeR1bWYcmg/6unKJ2tnzZuv MFzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=pDxtBw6x; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e64-20020a636943000000b0040d1fc1bbdcsi22895865pgc.478.2022.06.29.04.43.02; Wed, 29 Jun 2022 04:43:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=pDxtBw6x; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232733AbiF2LlA (ORCPT + 64 others); Wed, 29 Jun 2022 07:41:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231370AbiF2Lk6 (ORCPT ); Wed, 29 Jun 2022 07:40:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E0FA3EF34; Wed, 29 Jun 2022 04:40:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5D5E661ABC; Wed, 29 Jun 2022 11:40:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3387C34114; Wed, 29 Jun 2022 11:40:55 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="pDxtBw6x" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1656502854; 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=CNxXkwtze2gyLyEUtULoRKSzgQuTYXqXAG+m5bX1wsI=; b=pDxtBw6xdDJL3Wa1muwS6frh5fa39fWvP1sX7oh3mCLRkLoOl2XjXA+cp2DpJTNsvwGsZz 1yMqbTi4b/x+ACmJf7e4LY6rncjYZqf9x4DmGI4niqt7DWHdaPHhzADF5LN1K1uCQ38Hdq cmbD5/dY4xsGS8ueptBPRhqTI31Jrbk= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 30260718 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Wed, 29 Jun 2022 11:40:54 +0000 (UTC) Date: Wed, 29 Jun 2022 13:40:52 +0200 From: "Jason A. Donenfeld" To: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= Cc: Herbert Xu , linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, Gregory Erwin , Kalle Valo , Rui Salvaterra , stable@vger.kernel.org Subject: Re: [PATCH v7] ath9k: let sleep be interrupted when unregistering hwrng Message-ID: References: <20220628151840.867592-1-Jason@zx2c4.com> <87pmirakke.fsf@toke.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87pmirakke.fsf@toke.dk> X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Hi Toke, On Wed, Jun 29, 2022 at 11:24:49AM +0200, Toke Høiland-Jørgensen wrote: > > + wait = !(filp->f_flags & O_NONBLOCK); > > + if (wait && cmpxchg(¤t_waiting_reader, NULL, current) != NULL) { > > + err = -EINTR; > > + goto out_unlock_reading; > > + } > > bytes_read = rng_get_data(rng, rng_buffer, > > - rng_buffer_size(), > > - !(filp->f_flags & O_NONBLOCK)); > > + rng_buffer_size(), wait); > > + if (wait && cmpxchg(¤t_waiting_reader, current, NULL) != current) > > + synchronize_rcu(); > > So this synchronize_rcu() is to ensure the hwrng_unregister() thread has > exited the rcu_read_lock() section below? Isn't that a bit... creative... > use of RCU? :) It's to handle the extreeeeemely unlikely race in which hwrng_unregister() does its xchg, and then the thread calling rng_dev_read() entirely exits. In practice, the only way I'm able to trigger this race is by synthetically adding `msleep()` in the right spot. But anyway, for that reason, it's only synchronized if that second cmpxchg indicates that indeed the value was changed out from under us. > Also, synchronize_rcu() can potentially take a while on a busy system, > is it OK to call it while holding the mutex? The reading mutex won't be usable by anything anyway at this point, so I don't think it matters. Jason