Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4213049rwo; Tue, 25 Jul 2023 02:26:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlEbyHGAGzO+LcUdkvO4AOCUvRFqqcta7ICsIvHHfokAwCGkVLlr40Z1JDmRcrVr4XbWfxQl X-Received: by 2002:a50:ef0e:0:b0:522:4dd0:de72 with SMTP id m14-20020a50ef0e000000b005224dd0de72mr896876eds.27.1690277169071; Tue, 25 Jul 2023 02:26:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690277169; cv=none; d=google.com; s=arc-20160816; b=rikAXJ7Bf2eAGbDNpJgf3zC3ekrDzsqboO1wlcMl5kVqhDZb+6zeV+LRbZ6u9MI7/G 7JvNrNt57/UWhOyPouw/EYtr0oN4x0B9DknJzfzB8gctAlGdCU497XhxhoQpDD19gAeq HCoBnwr32yyMBpbunn9RBiPeuYwjMMD9CeTgkyUSptW8BD/JIMVpGC1yrD/hiYRsbNVc fWVcZuRSZQk861Hk4kmfy1K8rqqyMOsjYVCdRf5EapNCzJ7osCSs7Zltie7RJSBNuUGA LL/hOFAhe/+r3KiSZ6hSS9J8EdQEHMv4QSoNwPoUIGg+u3x/1B9gOwi+/Isly/YFd1xl 1DpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=7Xc+x3bm0aDx5lBbs4AFmDsPjM7vKL6WtyoQNR4tK/E=; fh=ucXRdlOt/+eFAA5C1Eh9QBU621onYzbuet03KRgLuI0=; b=yEie44gs0Oq5dptUcAuX+YQjbmlFc1X+zt4R7W6HQtbLzV/tOblM+pUwlapEh9gg8E /BQeNwe1/9OB5jK/Y2TWAON65IYnqHVnXrPZjTnVZdMx2WRDU6Fbq6A9EaNFQiHpQrBI Up/Wut1m3kq8xsf7K+8SNbjteFpNyZcGkJZP3sOT7NUCHkyAS2Kk/gEev9NPRsR7AYy1 /NkKpOaBI9WWeFnFLFwFMmf7PsrUIk3hRMlMdBgXPEqZXvHYlqm51wGqlind5ygNGvUA ov77h4/esRV+RNrZk513l9krwR/LWPNexDA6ydcrCuCVDqY6lY5bRfymWZR0dP8Nj23r gT5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=dUBWqyHb; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i16-20020a056402055000b0052228b42848si3453654edx.60.2023.07.25.02.25.44; Tue, 25 Jul 2023 02:26:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@suse.de header.s=susede2_rsa header.b=dUBWqyHb; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230460AbjGYH2Z (ORCPT + 99 others); Tue, 25 Jul 2023 03:28:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232554AbjGYH13 (ORCPT ); Tue, 25 Jul 2023 03:27:29 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 893B7E0; Tue, 25 Jul 2023 00:26:59 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 29D9C1F8B3; Tue, 25 Jul 2023 07:26:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1690270018; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7Xc+x3bm0aDx5lBbs4AFmDsPjM7vKL6WtyoQNR4tK/E=; b=dUBWqyHbQwKYt2wSpE/zBet21VuJXKX0vml+r+fr2TY7T0eNHKfjOMemkdeLEOF3L8t7tD 6HYrViDDuEocyARFPTuFhzfMHOJHE0vbuvYbxVmAqeI6bwngqbxoa0Tjnd/7Qcg3CuRNh0 kHIUixZr03XkU2opCeRtl5ZU0EyhlpM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1690270018; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7Xc+x3bm0aDx5lBbs4AFmDsPjM7vKL6WtyoQNR4tK/E=; b=fPskUvashiZyTcb/ryCu/ZVCVXchmvSf2JCtlKNdPCRNZFa5H3oOqKqkTxEVVkooX0Rx2q Y4nZGIVy99swIbAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9CED513487; Tue, 25 Jul 2023 07:26:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id /chyJUF5v2SZFAAAMHmgww (envelope-from ); Tue, 25 Jul 2023 07:26:57 +0000 Date: Tue, 25 Jul 2023 09:26:57 +0200 Message-ID: <87bkg0v4ce.wl-tiwai@suse.de> From: Takashi Iwai To: Wesley Cheng Cc: , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH v4 18/32] sound: usb: Introduce QC USB SND offloading support In-Reply-To: <20230725023416.11205-19-quic_wcheng@quicinc.com> References: <20230725023416.11205-1-quic_wcheng@quicinc.com> <20230725023416.11205-19-quic_wcheng@quicinc.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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-kernel@vger.kernel.org On Tue, 25 Jul 2023 04:34:02 +0200, Wesley Cheng wrote: > > --- a/sound/usb/Kconfig > +++ b/sound/usb/Kconfig > @@ -165,6 +165,21 @@ config SND_BCD2000 > To compile this driver as a module, choose M here: the module > will be called snd-bcd2000. > > +config QC_USB_AUDIO_OFFLOAD > + tristate "Qualcomm Audio Offload driver" > + depends on QCOM_QMI_HELPERS > + select SND_PCM So the driver can be enabled without CONFIG_SND_USB_AUDIO? It makes little sense without it. Or is it set so intentionally for testing purpose? About the code: > +/* Offloading IOMMU management */ > +static unsigned long uaudio_get_iova(unsigned long *curr_iova, > + size_t *curr_iova_size, struct list_head *head, size_t size) > +{ > + struct iova_info *info, *new_info = NULL; > + struct list_head *curr_head; > + unsigned long va = 0; > + size_t tmp_size = size; > + bool found = false; > + > + if (size % PAGE_SIZE) { > + dev_err(uaudio_qdev->dev, "size %zu is not page size multiple\n", > + size); > + goto done; This can be easily triggered by user-space as it's passed directly from the mmap call, and it implies that you can fill up the messages easily. It's safer to make it debug message or add the rate limit. Ditto for other error messages. > +static void disable_audio_stream(struct snd_usb_substream *subs) > +{ > + struct snd_usb_audio *chip = subs->stream->chip; > + > + if (subs->data_endpoint || subs->sync_endpoint) { > + close_endpoints(chip, subs); > + > + mutex_lock(&chip->mutex); > + subs->cur_audiofmt = NULL; > + mutex_unlock(&chip->mutex); > + } Now looking at this and... > +static int enable_audio_stream(struct snd_usb_substream *subs, > + snd_pcm_format_t pcm_format, > + unsigned int channels, unsigned int cur_rate, > + int datainterval) > +{ ... this implementation, I wonder whether it'd be better to modify and export snd_usb_hw_params() snd snd_usb_hw_free() to fit with qcom driver. Then you can avoid lots of open code. In general, if you see a direct use of chip->mutex, it can be often done better in a different form. The use of an internal lock or such from an external driver is always fragile and error-prone. Also, the current open-code misses the potential race against the disconnection during the operation. In snd-usb-audio, it protects with snd_usb_lock_shutdown() and snd_usb_unlock_shutdown() pairs. > +static int __init qc_usb_audio_offload_init(void) > +{ > + struct uaudio_qmi_svc *svc; > + int ret; > + > + ret = snd_usb_register_platform_ops(&offload_ops); > + if (ret < 0) > + return ret; Registering the ops at the very first opens a potential access to the uninitialized stuff. Imagine a suspend happens right after this point. As the ops is already registered, it'll enter to the suspend_cb callback and straight to Oops. > +static void __exit qc_usb_audio_offload_exit(void) > +{ > + struct uaudio_qmi_svc *svc = uaudio_svc; > + > + qmi_handle_release(svc->uaudio_svc_hdl); > + flush_workqueue(svc->uaudio_wq); > + destroy_workqueue(svc->uaudio_wq); > + kfree(svc); > + uaudio_svc = NULL; > + snd_usb_unregister_platform_ops(); Similarly, the unregister order has to be careful, too. thanks, Takashi